Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/common-api/entity.js
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | "hasClass": function(name) { | ||||
if (!this._classes) | if (!this._classes) | ||||
this._classes = this.classes(); | this._classes = this.classes(); | ||||
return this._classes && this._classes.indexOf(name) != -1; | return this._classes && this._classes.indexOf(name) != -1; | ||||
}, | }, | ||||
"hasClasses": function(array) { | "hasClasses": function(array) { | ||||
if (!this._classes) | if (!this._classes) | ||||
this._classes = this.classes(); | this._classes = this.classes(); | ||||
if (!this._classes) | return this._classes && MatchesClassList(this._classes, array); | ||||
return false; | |||||
for (let cls of array) | |||||
if (this._classes.indexOf(cls) == -1) | |||||
return false; | |||||
return true; | |||||
}, | }, | ||||
"requiredTech": function() { return this.get("Identity/RequiredTechnology"); }, | "requiredTech": function() { return this.get("Identity/RequiredTechnology"); }, | ||||
"available": function(gameState) { | "available": function(gameState) { | ||||
let techRequired = this.requiredTech(); | let techRequired = this.requiredTech(); | ||||
if (!techRequired) | if (!techRequired) | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | for (let type in attack) | ||||
let bonusClasses = this.get("Attack/" + type + "/Bonuses/" + b + "/Classes"); | let bonusClasses = this.get("Attack/" + type + "/Bonuses/" + b + "/Classes"); | ||||
if (bonusClasses) | if (bonusClasses) | ||||
Classes.push([bonusClasses.split(" "), +this.get("Attack/" + type +"/Bonuses/" + b +"/Multiplier")]); | Classes.push([bonusClasses.split(" "), +this.get("Attack/" + type +"/Bonuses/" + b +"/Multiplier")]); | ||||
} | } | ||||
} | } | ||||
return Classes; | return Classes; | ||||
}, | }, | ||||
// returns true if the entity counters those classes. | // returns true if the entity counters the target entity. | ||||
// TODO: refine using the multiplier | // TODO: refine using the multiplier | ||||
"countersClasses": function(classes) { | "counters": function(target) { | ||||
let attack = this.get("Attack"); | let attack = this.get("Attack"); | ||||
if (!attack) | if (!attack) | ||||
return false; | return false; | ||||
let mcounter = []; | let mcounter = []; | ||||
for (let type in attack) | for (let type in attack) | ||||
{ | { | ||||
let bonuses = this.get("Attack/" + type + "/Bonuses"); | let bonuses = this.get("Attack/" + type + "/Bonuses"); | ||||
if (!bonuses) | if (!bonuses) | ||||
continue; | continue; | ||||
for (let b in bonuses) | for (let b in bonuses) | ||||
{ | { | ||||
let bonusClasses = this.get("Attack/" + type + "/Bonuses/" + b + "/Classes"); | let bonusClasses = this.get("Attack/" + type + "/Bonuses/" + b + "/Classes"); | ||||
if (bonusClasses) | if (bonusClasses) | ||||
mcounter.concat(bonusClasses.split(" ")); | mcounter.concat(bonusClasses.split(" ")); | ||||
} | } | ||||
} | } | ||||
for (let i in classes) | return target.hasClasses(mcounter); | ||||
if (mcounter.indexOf(classes[i]) != -1) | |||||
return true; | |||||
return false; | |||||
}, | }, | ||||
// returns, if it exists, the multiplier from each attack against a given class | // returns, if it exists, the multiplier from each attack against a given class | ||||
"getMultiplierAgainst": function(type, againstClass) { | "getMultiplierAgainst": function(type, againstClass) { | ||||
if (!this.get("Attack/" + type +"")) | if (!this.get("Attack/" + type +"")) | ||||
return undefined; | return undefined; | ||||
let bonuses = this.get("Attack/" + type + "/Bonuses"); | let bonuses = this.get("Attack/" + type + "/Bonuses"); | ||||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | m.Template = m.Class({ | ||||
{ | { | ||||
if (!this.get("Attack/Capture")) | if (!this.get("Attack/Capture")) | ||||
return false; | return false; | ||||
if (!target) | if (!target) | ||||
return true; | return true; | ||||
if (!target.get("Capturable")) | if (!target.get("Capturable")) | ||||
return false; | return false; | ||||
let restrictedClasses = this.get("Attack/Capture/RestrictedClasses/_string"); | let restrictedClasses = this.get("Attack/Capture/RestrictedClasses/_string"); | ||||
return !restrictedClasses || !MatchesClassList(target.classes(), restrictedClasses); | return !restrictedClasses || !target.hasClasses(restrictedClasses); | ||||
}, | }, | ||||
"isCapturable": function() { return this.get("Capturable") !== undefined; }, | "isCapturable": function() { return this.get("Capturable") !== undefined; }, | ||||
"canGuard": function() { return this.get("UnitAI/CanGuard") === "true"; }, | "canGuard": function() { return this.get("UnitAI/CanGuard") === "true"; }, | ||||
"canGarrison": function() { return "Garrisonable" in this._template; }, | "canGarrison": function() { return "Garrisonable" in this._template; }, | ||||
▲ Show 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | 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 || !target.hasClasses(restrictedClasses)) | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
}, | }, | ||||
"move": function(x, z, queued = false, pushFront = false) { | "move": function(x, z, queued = false, pushFront = false) { | ||||
Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": x, "z": z, "queued": queued, "pushFront": pushFront }); | Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": x, "z": z, "queued": queued, "pushFront": pushFront }); | ||||
▲ Show 20 Lines • Show All 219 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator