Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 1,420 Lines • ▼ Show 20 Lines | "GuardedAttacked": function(msg) { | ||||
// if we already are targeting another unit still alive, finish with it first | // if we already are targeting another unit still alive, finish with it first | ||||
if (this.order && (this.order.type == "WalkAndFight" || this.order.type == "Attack")) | if (this.order && (this.order.type == "WalkAndFight" || this.order.type == "Attack")) | ||||
if (this.order.data.target != msg.data.attacker && this.TargetIsAlive(msg.data.attacker)) | if (this.order.data.target != msg.data.attacker && this.TargetIsAlive(msg.data.attacker)) | ||||
return; | return; | ||||
var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); | var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); | ||||
var cmpHealth = Engine.QueryInterface(this.isGuardOf, IID_Health); | var cmpHealth = Engine.QueryInterface(this.isGuardOf, IID_Health); | ||||
if (cmpIdentity && cmpIdentity.HasClass("Support") && | if (cmpIdentity && cmpIdentity.HasClass("Support") && | ||||
cmpHealth && cmpHealth.GetHitpoints() < cmpHealth.GetMaxHitpoints()) | cmpHealth && cmpHealth.IsInjured()) | ||||
{ | { | ||||
if (this.CanHeal(this.isGuardOf)) | if (this.CanHeal(this.isGuardOf)) | ||||
this.PushOrderFront("Heal", { "target": this.isGuardOf, "force": false }); | this.PushOrderFront("Heal", { "target": this.isGuardOf, "force": false }); | ||||
else if (this.CanRepair(this.isGuardOf)) | else if (this.CanRepair(this.isGuardOf)) | ||||
this.PushOrderFront("Repair", { "target": this.isGuardOf, "autocontinue": false, "force": false }); | this.PushOrderFront("Repair", { "target": this.isGuardOf, "autocontinue": false, "force": false }); | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 273 Lines • ▼ Show 20 Lines | "GUARD": { | ||||
} | } | ||||
// then check is the target has moved | // then check is the target has moved | ||||
if (this.MoveToTargetRangeExplicit(this.isGuardOf, 0, this.guardRange)) | if (this.MoveToTargetRangeExplicit(this.isGuardOf, 0, this.guardRange)) | ||||
this.SetNextState("ESCORTING"); | this.SetNextState("ESCORTING"); | ||||
else | else | ||||
{ | { | ||||
// if nothing better to do, check if the guarded needs to be healed or repaired | // if nothing better to do, check if the guarded needs to be healed or repaired | ||||
var cmpHealth = Engine.QueryInterface(this.isGuardOf, IID_Health); | var cmpHealth = Engine.QueryInterface(this.isGuardOf, IID_Health); | ||||
if (cmpHealth && (cmpHealth.GetHitpoints() < cmpHealth.GetMaxHitpoints())) | if (cmpHealth && cmpHealth.IsInjured()) | ||||
{ | { | ||||
if (this.CanHeal(this.isGuardOf)) | if (this.CanHeal(this.isGuardOf)) | ||||
this.PushOrderFront("Heal", { "target": this.isGuardOf, "force": false }); | this.PushOrderFront("Heal", { "target": this.isGuardOf, "force": false }); | ||||
else if (this.CanRepair(this.isGuardOf)) | else if (this.CanRepair(this.isGuardOf)) | ||||
this.PushOrderFront("Repair", { "target": this.isGuardOf, "autocontinue": false, "force": false }); | this.PushOrderFront("Repair", { "target": this.isGuardOf, "autocontinue": false, "force": false }); | ||||
} | } | ||||
} | } | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 4,245 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator