Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Attack.js
Show First 20 Lines • Show All 381 Lines • ▼ Show 20 Lines | if (captureIndex != -1) | ||||
let cmpPlayer = QueryOwnerInterface(this.entity); | let cmpPlayer = QueryOwnerInterface(this.entity); | ||||
if (allowCapture && cmpPlayer && cmpCapturable && cmpCapturable.CanCapture(cmpPlayer.GetPlayerID())) | if (allowCapture && cmpPlayer && cmpCapturable && cmpCapturable.CanCapture(cmpPlayer.GetPlayerID())) | ||||
return "Capture"; | return "Capture"; | ||||
// not capturable, so remove this attack | // not capturable, so remove this attack | ||||
types.splice(captureIndex, 1); | types.splice(captureIndex, 1); | ||||
} | } | ||||
let rangeIndex = types.indexOf("Ranged"); | |||||
if (rangeIndex != -1) | |||||
{ | |||||
let cmpThisPosition = Engine.QueryInterface(this.entity, IID_Position); | |||||
let cmpTargetPosition = Engine.QueryInterface(target, IID_Position); | |||||
if (cmpThisPosition && cmpTargetPosition) { | |||||
let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | |||||
if (cmpUnitMotion && cmpUnitMotion.IsInTargetRange(target, 0, this.template.Ranged.MinRange)) | |||||
types.splice(rangeIndex, 1); | |||||
} | |||||
} | |||||
let isPreferred = className => this.GetPreferredClasses(className).some(isTargetClass); | let isPreferred = className => this.GetPreferredClasses(className).some(isTargetClass); | ||||
return types.sort((a, b) => | return types.sort((a, b) => | ||||
(types.indexOf(a) + (isPreferred(a) ? types.length : 0)) - | (types.indexOf(a) + (isPreferred(a) ? types.length : 0)) - | ||||
(types.indexOf(b) + (isPreferred(b) ? types.length : 0))).pop(); | (types.indexOf(b) + (isPreferred(b) ? types.length : 0))).pop(); | ||||
}; | }; | ||||
Attack.prototype.CompareEntitiesByPreference = function(a, b) | Attack.prototype.CompareEntitiesByPreference = function(a, b) | ||||
▲ Show 20 Lines • Show All 296 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator