Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Attack.js
Show First 20 Lines • Show All 406 Lines • ▼ Show 20 Lines | Attack.prototype.GetBestAttackAgainst = function(target, allowCapture) | ||||
// Always slaughter domestic animals instead of using a normal attack | // Always slaughter domestic animals instead of using a normal attack | ||||
if (isTargetClass("Domestic") && this.template.Slaughter) | if (isTargetClass("Domestic") && this.template.Slaughter) | ||||
return "Slaughter"; | return "Slaughter"; | ||||
let types = this.GetAttackTypes().filter(type => this.CanAttack(target, [type])); | let types = this.GetAttackTypes().filter(type => this.CanAttack(target, [type])); | ||||
// Check whether the target is capturable and prefer that when it is allowed. | // Check whether the target is capturable and prefer that when it is allowed. | ||||
let captureIndex = types.indexOf("Capture"); | let captureIndex = types.indexOf("Capture"); | ||||
if (captureIndex != -1 && allowCapture) | if (captureIndex != -1) | ||||
{ | |||||
if (allowCapture) | |||||
return "Capture"; | return "Capture"; | ||||
types.splice(captureIndex, 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(); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 297 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator