Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Attack.js
Show First 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | if (targetClasses.indexOf("Domestic") != -1 && this.template.Slaughter && cmpHealth && cmpHealth.GetHitpoints() && | ||||
(!wantedTypes || !wantedTypes.filter(wType => wType.indexOf("!") != 0).length || wantedTypes.indexOf("Slaughter") != -1)) | (!wantedTypes || !wantedTypes.filter(wType => wType.indexOf("!") != 0).length || wantedTypes.indexOf("Slaughter") != -1)) | ||||
return true; | return true; | ||||
const cmpEntityPlayer = QueryOwnerInterface(this.entity); | const cmpEntityPlayer = QueryOwnerInterface(this.entity); | ||||
const cmpTargetPlayer = QueryOwnerInterface(target); | const cmpTargetPlayer = QueryOwnerInterface(target); | ||||
if (!cmpTargetPlayer || !cmpEntityPlayer) | if (!cmpTargetPlayer || !cmpEntityPlayer) | ||||
return false; | return false; | ||||
const cmpDiplomacy = QueryOwnerInterface(this.entity, IID_Diplomacy); | |||||
const types = this.GetAttackTypes(wantedTypes); | const types = this.GetAttackTypes(wantedTypes); | ||||
const entityOwner = cmpEntityPlayer.GetPlayerID(); | const entityOwner = cmpEntityPlayer.GetPlayerID(); | ||||
const targetOwner = cmpTargetPlayer.GetPlayerID(); | const targetOwner = cmpTargetPlayer.GetPlayerID(); | ||||
const cmpCapturable = QueryMiragedInterface(target, IID_Capturable); | const cmpCapturable = QueryMiragedInterface(target, IID_Capturable); | ||||
// 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. | ||||
const heightDiff = Math.abs(cmpThisPosition.GetHeightOffset() - cmpTargetPosition.GetHeightOffset()); | const heightDiff = Math.abs(cmpThisPosition.GetHeightOffset() - cmpTargetPosition.GetHeightOffset()); | ||||
for (const type of types) | for (const type of types) | ||||
{ | { | ||||
if (type != "Capture" && (!cmpEntityPlayer.IsEnemy(targetOwner) || !cmpHealth || !cmpHealth.GetHitpoints())) | if (type != "Capture" && (!cmpDiplomacy?.IsEnemy(targetOwner) || !cmpHealth || !cmpHealth.GetHitpoints())) | ||||
continue; | continue; | ||||
if (type == "Capture" && (!cmpCapturable || !cmpCapturable.CanCapture(entityOwner))) | if (type == "Capture" && (!cmpCapturable || !cmpCapturable.CanCapture(entityOwner))) | ||||
Stan: Wonder if we could avoid that check with an else (type == "Capture") | |||||
Not Done Inline ActionsYep, possible. :) Freagarach: Yep, possible. :) | |||||
continue; | continue; | ||||
if (heightDiff > this.GetRange(type).max) | if (heightDiff > this.GetRange(type).max) | ||||
continue; | continue; | ||||
const restrictedClasses = this.GetRestrictedClasses(type); | const restrictedClasses = this.GetRestrictedClasses(type); | ||||
if (!restrictedClasses.length) | if (!restrictedClasses.length) | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 494 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Wonder if we could avoid that check with an else (type == "Capture")