Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/common-api/entity.js
Show First 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | if (this.get("Health") !== undefined) | ||||
return this.get("Health/Unhealable") !== "true"; | return this.get("Health/Unhealable") !== "true"; | ||||
return false; | return false; | ||||
}, | }, | ||||
"isRepairable": function() { return this.get("Repairable") !== undefined; }, | "isRepairable": function() { return this.get("Repairable") !== undefined; }, | ||||
"getPopulationBonus": function() { return +this.get("Cost/PopulationBonus"); }, | "getPopulationBonus": function() { return +this.get("Cost/PopulationBonus"); }, | ||||
"armourStrengths": function() { | "resistanceStrengths": function() { | ||||
let armourDamageTypes = this.get("Armour"); | let resistanceTypes = this.get("Resistance"); | ||||
if (!armourDamageTypes) | if (!resistanceTypes || !resistanceTypes.Entity) | ||||
return undefined; | return undefined; | ||||
let armour = {}; | let resistance = {}; | ||||
for (let damageType in armourDamageTypes) | if (resistanceTypes.Entity.Capture) | ||||
if (damageType != "Foundation") | resistance.Capture = +this.get("Resistance/Entity/Capture"); | ||||
bb: Can't we query g_EffectType here? | |||||
armour[damageType] = +armourDamageTypes[damageType]; | |||||
return armour; | if (resistanceTypes.Entity.Damage) | ||||
{ | |||||
resistance.Damage = {}; | |||||
Done Inline Actionsif(!template) Stan: if(!template)
continue ? | |||||
for (let damageType in resistanceTypes.Entity.Damage) | |||||
resistance.Damage[damageType] = +this.get("Resistance/Entity/Damage/" + damageType); | |||||
} | |||||
// ToDo: Resistance to StatusEffects. | |||||
return resistance; | |||||
}, | }, | ||||
"attackTypes": function() { | "attackTypes": function() { | ||||
if (!this.get("Attack")) | if (!this.get("Attack")) | ||||
return undefined; | return undefined; | ||||
let ret = []; | let ret = []; | ||||
for (let type in this.get("Attack")) | for (let type in this.get("Attack")) | ||||
▲ Show 20 Lines • Show All 531 Lines • ▼ Show 20 Lines | m.Entity = m.Class({ | ||||
*/ | */ | ||||
"canAttackTarget": function(target, allowCapture) | "canAttackTarget": function(target, allowCapture) | ||||
{ | { | ||||
let attackTypes = this.get("Attack"); | let attackTypes = this.get("Attack"); | ||||
if (!attackTypes) | if (!attackTypes) | ||||
return false; | return false; | ||||
let canCapture = allowCapture && this.canCapture(target); | let canCapture = allowCapture && this.canCapture(target); | ||||
let armourStrengths = target.get("Armour"); | let health = target.get("Health"); | ||||
if (!armourStrengths) | if (!health) | ||||
return canCapture; | return canCapture; | ||||
for (let type in attackTypes) | for (let type in attackTypes) | ||||
{ | { | ||||
if (type == "Capture" ? !canCapture : target.isInvulnerable()) | if (type == "Capture" ? !canCapture : target.isInvulnerable()) | ||||
continue; | continue; | ||||
let restrictedClasses = this.get("Attack/" + type + "/RestrictedClasses/_string"); | let restrictedClasses = this.get("Attack/" + type + "/RestrictedClasses/_string"); | ||||
if (!restrictedClasses || !MatchesClassList(target.classes(), restrictedClasses)) | if (!restrictedClasses || !MatchesClassList(target.classes(), restrictedClasses)) | ||||
return true; | return true; | ||||
}; | }; | ||||
Lint: ESLintBear (no-extra-semi) Unnecessary semicolon. Lint: ESLintBear (no-extra-semi): `Unnecessary semicolon.` | |||||
Lint: JSHintBear Unnecessary semicolon. Lint: JSHintBear: `Unnecessary semicolon.` | |||||
return false; | return false; | ||||
}, | }, | ||||
"move": function(x, z, queued = false) { | "move": function(x, z, queued = false) { | ||||
Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": x, "z": z, "queued": queued }); | Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": x, "z": z, "queued": queued }); | ||||
return this; | return this; | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | m.Entity = m.Class({ | ||||
"attack": function(unitId, allowCapture = true, queued = false) { | "attack": function(unitId, allowCapture = true, queued = false) { | ||||
Engine.PostCommand(PlayerID, { "type": "attack", "entities": [this.id()], "target": unitId, "allowCapture": allowCapture, "queued": queued }); | Engine.PostCommand(PlayerID, { "type": "attack", "entities": [this.id()], "target": unitId, "allowCapture": allowCapture, "queued": queued }); | ||||
return this; | return this; | ||||
}, | }, | ||||
// moveApart from a point in the opposite direction with a distance dist | // moveApart from a point in the opposite direction with a distance dist | ||||
"moveApart": function(point, dist) { | "moveApart": function(point, dist) { | ||||
if (this.position() !== undefined) { | if (this.position() !== undefined) { | ||||
Lint: ESLintBear (brace-rules/brace-on-same-line) Opening curly brace appears on the same line as controlling statement. Lint: ESLintBear (brace-rules/brace-on-same-line): `Opening curly brace appears on the same line as controlling statement.` | |||||
let direction = [this.position()[0] - point[0], this.position()[1] - point[1]]; | let direction = [this.position()[0] - point[0], this.position()[1] - point[1]]; | ||||
let norm = m.VectorDistance(point, this.position()); | let norm = m.VectorDistance(point, this.position()); | ||||
if (norm === 0) | if (norm === 0) | ||||
direction = [1, 0]; | direction = [1, 0]; | ||||
else | else | ||||
{ | { | ||||
direction[0] /= norm; | direction[0] /= norm; | ||||
direction[1] /= norm; | direction[1] /= norm; | ||||
} | } | ||||
Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": this.position()[0] + direction[0]*dist, "z": this.position()[1] + direction[1]*dist, "queued": false }); | Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": this.position()[0] + direction[0]*dist, "z": this.position()[1] + direction[1]*dist, "queued": false }); | ||||
} | } | ||||
return this; | return this; | ||||
}, | }, | ||||
// Flees from a unit in the opposite direction. | // Flees from a unit in the opposite direction. | ||||
"flee": function(unitToFleeFrom) { | "flee": function(unitToFleeFrom) { | ||||
if (this.position() !== undefined && unitToFleeFrom.position() !== undefined) { | if (this.position() !== undefined && unitToFleeFrom.position() !== undefined) { | ||||
Lint: ESLintBear (brace-rules/brace-on-same-line) Opening curly brace appears on the same line as controlling statement. Lint: ESLintBear (brace-rules/brace-on-same-line): `Opening curly brace appears on the same line as controlling statement.` | |||||
let FleeDirection = [this.position()[0] - unitToFleeFrom.position()[0], | let FleeDirection = [this.position()[0] - unitToFleeFrom.position()[0], | ||||
this.position()[1] - unitToFleeFrom.position()[1]]; | this.position()[1] - unitToFleeFrom.position()[1]]; | ||||
let dist = m.VectorDistance(unitToFleeFrom.position(), this.position()); | let dist = m.VectorDistance(unitToFleeFrom.position(), this.position()); | ||||
FleeDirection[0] = 40 * FleeDirection[0]/dist; | FleeDirection[0] = 40 * FleeDirection[0]/dist; | ||||
FleeDirection[1] = 40 * FleeDirection[1]/dist; | FleeDirection[1] = 40 * FleeDirection[1]/dist; | ||||
Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": this.position()[0] + FleeDirection[0], "z": this.position()[1] + FleeDirection[1], "queued": false }); | Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": this.position()[0] + FleeDirection[0], "z": this.position()[1] + FleeDirection[1], "queued": false }); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | m.Entity = m.Class({ | ||||
"removeGuard": function() { | "removeGuard": function() { | ||||
Engine.PostCommand(PlayerID, { "type": "remove-guard", "entities": [this.id()] }); | Engine.PostCommand(PlayerID, { "type": "remove-guard", "entities": [this.id()] }); | ||||
return this; | return this; | ||||
} | } | ||||
}); | }); | ||||
return m; | return m; | ||||
}(API3); | }(API3); | ||||
Lint: ESLintBear (no-use-before-define) 'API3' was used before it was defined. Lint: ESLintBear (no-use-before-define): `'API3' was used before it was defined.` |
Wildfire Games · Phabricator
Can't we query g_EffectType here?