Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Attack.js
Show First 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | if (this.template[type] && this.template[type].RestrictedClasses && | ||||
this.template[type].RestrictedClasses._string) | this.template[type].RestrictedClasses._string) | ||||
return this.template[type].RestrictedClasses._string.split(/\s+/); | return this.template[type].RestrictedClasses._string.split(/\s+/); | ||||
return []; | return []; | ||||
}; | }; | ||||
Attack.prototype.CanAttack = function(target) | Attack.prototype.CanAttack = function(target) | ||||
{ | { | ||||
let cmpFormation = Engine.QueryInterface(target, IID_Formation); | |||||
if (cmpFormation) | |||||
return true; | |||||
let cmpThisPosition = Engine.QueryInterface(this.entity, IID_Position); | let cmpThisPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
let cmpTargetPosition = Engine.QueryInterface(target, IID_Position); | let cmpTargetPosition = Engine.QueryInterface(target, IID_Position); | ||||
if (!cmpThisPosition || !cmpTargetPosition || !cmpThisPosition.IsInWorld() || !cmpTargetPosition.IsInWorld()) | if (!cmpThisPosition || !cmpTargetPosition || !cmpThisPosition.IsInWorld() || !cmpTargetPosition.IsInWorld()) | ||||
return false; | return false; | ||||
// Check if the relative height difference is larger than the attack range | // Check if the relative height difference is larger than the attack range | ||||
// If the relative height is bigger, it means they will never be able to | // If the relative height is bigger, it means they will never be able to | ||||
// reach each other, no matter how close they come. | // reach each other, no matter how close they come. | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | for (let type of this.GetAttackTypes()) | ||||
ret.min = Math.min(ret.min, range.min); | ret.min = Math.min(ret.min, range.min); | ||||
ret.max = Math.max(ret.max, range.max); | ret.max = Math.max(ret.max, range.max); | ||||
} | } | ||||
return ret; | return ret; | ||||
}; | }; | ||||
Attack.prototype.GetBestAttackAgainst = function(target, allowCapture) | Attack.prototype.GetBestAttackAgainst = function(target, allowCapture) | ||||
{ | { | ||||
let cmpFormation = Engine.QueryInterface(target, IID_Formation); | |||||
if (cmpFormation) | |||||
{ | |||||
// TODO: Formation against formation needs review | |||||
let types = this.GetAttackTypes(); | |||||
return ["Ranged", "Melee", "Capture"].find(attack => types.indexOf(attack) != -1); | |||||
} | |||||
let cmpIdentity = Engine.QueryInterface(target, IID_Identity); | let cmpIdentity = Engine.QueryInterface(target, IID_Identity); | ||||
if (!cmpIdentity) | if (!cmpIdentity) | ||||
return undefined; | return undefined; | ||||
let targetClasses = cmpIdentity.GetClassesList(); | let targetClasses = cmpIdentity.GetClassesList(); | ||||
let isTargetClass = className => targetClasses.indexOf(className) != -1; | let isTargetClass = className => targetClasses.indexOf(className) != -1; | ||||
// Always slaughter domestic animals instead of using a normal attack | // Always slaughter domestic animals instead of using a normal attack | ||||
▲ Show 20 Lines • Show All 282 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator