Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/common-api/entity.js
Show First 20 Lines • Show All 735 Lines • ▼ Show 20 Lines | for (let type in this.get("Attack")) | ||||
continue; | continue; | ||||
let restrictedClasses = this.get("Attack/" + type + "/RestrictedClasses/_string"); | let restrictedClasses = this.get("Attack/" + type + "/RestrictedClasses/_string"); | ||||
if (!restrictedClasses || !MatchesClassList([aClass], restrictedClasses)) | if (!restrictedClasses || !MatchesClassList([aClass], restrictedClasses)) | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
}, | }, | ||||
/** | |||||
* Returns true when an entity can attack a target. | |||||
*/ | |||||
"canAttackTarget": function(target) | |||||
{ | |||||
let attackTypes = this.get("Attack"); | |||||
if (!attackTypes) | |||||
return false; | |||||
let canCapture = this.canCapture(target); | |||||
let armourStrengths = target.get("Armour"); | |||||
if (!armourStrengths) | |||||
return canCapture; | |||||
for (let type in attackTypes) | |||||
{ | |||||
if (type != "Capture" && target.isInvulnerable()) | |||||
continue; | |||||
if (type == "Capture" && !canCapture) | |||||
continue; | |||||
// Check if the target is immune to some damage types. | |||||
if (type != "Capture") | |||||
{ | |||||
let attackStrengths = this.attackStrengths(type); | |||||
let canDamage = false; | |||||
for (let damageType in attackStrengths) | |||||
if (attackStrengths[damageType] != 0 && armourStrengths[damageType] != "Infinity") | |||||
{ | |||||
canDamage = true; | |||||
break; | |||||
} | |||||
if (!canDamage) | |||||
continue; | |||||
} | |||||
let restrictedClasses = this.get("Attack/" + type + "/RestrictedClasses/_string"); | |||||
if (!restrictedClasses) | |||||
return true; | |||||
if (!MatchesClassList(target.classes(), restrictedClasses)) | |||||
return true; | |||||
}; | |||||
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; | ||||
}, | }, | ||||
"moveToRange": function(x, z, min, max, queued = false) { | "moveToRange": function(x, z, min, max, queued = false) { | ||||
Engine.PostCommand(PlayerID, { "type": "walk-to-range", "entities": [this.id()], "x": x, "z": z, "min": min, "max": max, "queued": queued }); | Engine.PostCommand(PlayerID, { "type": "walk-to-range", "entities": [this.id()], "x": x, "z": z, "min": min, "max": max, "queued": queued }); | ||||
return this; | return this; | ||||
▲ Show 20 Lines • Show All 194 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator