Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/common-api/entity.js
Show First 20 Lines • Show All 227 Lines • ▼ Show 20 Lines | m.Template = m.Class({ | ||||
}, | }, | ||||
"attackRange": function(type) { | "attackRange": function(type) { | ||||
if (!this.get("Attack/" + type +"")) | if (!this.get("Attack/" + type +"")) | ||||
return undefined; | return undefined; | ||||
return { | return { | ||||
"max": +this.get("Attack/" + type +"/MaxRange"), | "max": +this.get("Attack/" + type +"/MaxRange"), | ||||
"min": +(this.get("Attack/" + type +"/MinRange") || 0) | "min": +(this.get("Attack/" + type +"/MinRange") || 0), | ||||
"elevationBonus": +(this.get("Attack/" + type + "/ElevationBonus") || 0) | |||||
}; | }; | ||||
}, | }, | ||||
"attackStrengths": function(type) { | "attackStrengths": function(type) { | ||||
let attackDamageTypes = this.get("Attack/" + type + "/Damage"); | let attackDamageTypes = this.get("Attack/" + type + "/Damage"); | ||||
if (!attackDamageTypes) | if (!attackDamageTypes) | ||||
return undefined; | return undefined; | ||||
▲ Show 20 Lines • Show All 524 Lines • ▼ Show 20 Lines | "canAttackTarget": function(target, allowCapture) | ||||
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: 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
Unnecessary semicolon.