mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 09:24:29 +00:00
Require 'Resistance' in CanAttack
This was already effectively the case, so this change increases coherence. Accepted By: Freagarach Differential Revision: https://code.wildfiregames.com/D3980 This was SVN commit r25465.
This commit is contained in:
@@ -222,41 +222,45 @@ Attack.prototype.GetRestrictedClasses = function(type)
|
||||
|
||||
Attack.prototype.CanAttack = function(target, wantedTypes)
|
||||
{
|
||||
let cmpFormation = Engine.QueryInterface(target, IID_Formation);
|
||||
const cmpFormation = Engine.QueryInterface(target, IID_Formation);
|
||||
if (cmpFormation)
|
||||
return true;
|
||||
|
||||
let cmpThisPosition = Engine.QueryInterface(this.entity, IID_Position);
|
||||
let cmpTargetPosition = Engine.QueryInterface(target, IID_Position);
|
||||
const cmpThisPosition = Engine.QueryInterface(this.entity, IID_Position);
|
||||
const cmpTargetPosition = Engine.QueryInterface(target, IID_Position);
|
||||
if (!cmpThisPosition || !cmpTargetPosition || !cmpThisPosition.IsInWorld() || !cmpTargetPosition.IsInWorld())
|
||||
return false;
|
||||
|
||||
let cmpIdentity = QueryMiragedInterface(target, IID_Identity);
|
||||
const cmpResistance = QueryMiragedInterface(target, IID_Resistance);
|
||||
if (!cmpResistance)
|
||||
return false;
|
||||
|
||||
const cmpIdentity = QueryMiragedInterface(target, IID_Identity);
|
||||
if (!cmpIdentity)
|
||||
return false;
|
||||
|
||||
let cmpHealth = QueryMiragedInterface(target, IID_Health);
|
||||
let targetClasses = cmpIdentity.GetClassesList();
|
||||
const cmpHealth = QueryMiragedInterface(target, IID_Health);
|
||||
const targetClasses = cmpIdentity.GetClassesList();
|
||||
if (targetClasses.indexOf("Domestic") != -1 && this.template.Slaughter && cmpHealth && cmpHealth.GetHitpoints() &&
|
||||
(!wantedTypes || !wantedTypes.filter(wType => wType.indexOf("!") != 0).length || wantedTypes.indexOf("Slaughter") != -1))
|
||||
return true;
|
||||
|
||||
let cmpEntityPlayer = QueryOwnerInterface(this.entity);
|
||||
let cmpTargetPlayer = QueryOwnerInterface(target);
|
||||
const cmpEntityPlayer = QueryOwnerInterface(this.entity);
|
||||
const cmpTargetPlayer = QueryOwnerInterface(target);
|
||||
if (!cmpTargetPlayer || !cmpEntityPlayer)
|
||||
return false;
|
||||
|
||||
let types = this.GetAttackTypes(wantedTypes);
|
||||
let entityOwner = cmpEntityPlayer.GetPlayerID();
|
||||
let targetOwner = cmpTargetPlayer.GetPlayerID();
|
||||
let cmpCapturable = QueryMiragedInterface(target, IID_Capturable);
|
||||
const types = this.GetAttackTypes(wantedTypes);
|
||||
const entityOwner = cmpEntityPlayer.GetPlayerID();
|
||||
const targetOwner = cmpTargetPlayer.GetPlayerID();
|
||||
const cmpCapturable = QueryMiragedInterface(target, IID_Capturable);
|
||||
|
||||
// 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
|
||||
// reach each other, no matter how close they come.
|
||||
let heightDiff = Math.abs(cmpThisPosition.GetHeightOffset() - cmpTargetPosition.GetHeightOffset());
|
||||
const heightDiff = Math.abs(cmpThisPosition.GetHeightOffset() - cmpTargetPosition.GetHeightOffset());
|
||||
|
||||
for (let type of types)
|
||||
for (const type of types)
|
||||
{
|
||||
if (type != "Capture" && (!cmpEntityPlayer.IsEnemy(targetOwner) || !cmpHealth || !cmpHealth.GetHitpoints()))
|
||||
continue;
|
||||
@@ -267,7 +271,7 @@ Attack.prototype.CanAttack = function(target, wantedTypes)
|
||||
if (heightDiff > this.GetRange(type).max)
|
||||
continue;
|
||||
|
||||
let restrictedClasses = this.GetRestrictedClasses(type);
|
||||
const restrictedClasses = this.GetRestrictedClasses(type);
|
||||
if (!restrictedClasses.length)
|
||||
return true;
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ Engine.LoadComponentScript("interfaces/Capturable.js");
|
||||
Engine.LoadComponentScript("interfaces/ModifiersManager.js");
|
||||
Engine.LoadComponentScript("interfaces/Formation.js");
|
||||
Engine.LoadComponentScript("interfaces/Health.js");
|
||||
Engine.LoadComponentScript("interfaces/Resistance.js");
|
||||
Engine.LoadComponentScript("interfaces/TechnologyManager.js");
|
||||
Engine.LoadComponentScript("Attack.js");
|
||||
|
||||
@@ -173,6 +174,9 @@ function attackComponentTest(defenderClass, isEnemy, test_function)
|
||||
"GetHitpoints": () => 100
|
||||
});
|
||||
|
||||
AddMock(defender, IID_Resistance, {
|
||||
});
|
||||
|
||||
test_function(attacker, cmpAttack, defender);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user