Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Attack.js
Show First 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | attackComponentTest(className, true, (attacker, cmpAttack, defender) => { | ||||
TS_ASSERT_UNEVAL_EQUALS(getAttackBonus(attacker, "Slaughter", defender), 1); | TS_ASSERT_UNEVAL_EQUALS(getAttackBonus(attacker, "Slaughter", defender), 1); | ||||
}); | }); | ||||
// CanAttack rejects elephant attack due to RestrictedClasses | // CanAttack rejects elephant attack due to RestrictedClasses | ||||
attackComponentTest("Elephant", true, (attacker, cmpAttack, defender) => { | attackComponentTest("Elephant", true, (attacker, cmpAttack, defender) => { | ||||
TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender), false); | TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender), false); | ||||
}); | }); | ||||
function testGetBestAttackAgainst(defenderClass, bestAttack, isBuilding = false) | function testGetBestAttackAgainst(defenderClass, bestAttack, bestAllyAttack, isBuilding = false) | ||||
{ | { | ||||
attackComponentTest(defenderClass, true, (attacker, cmpAttack, defender) => { | attackComponentTest(defenderClass, true, (attacker, cmpAttack, defender) => { | ||||
if (isBuilding) | if (isBuilding) | ||||
AddMock(defender, IID_Capturable, { | AddMock(defender, IID_Capturable, { | ||||
"CanCapture": playerID => { | "CanCapture": playerID => { | ||||
TS_ASSERT_EQUALS(playerID, 1); | TS_ASSERT_EQUALS(playerID, 1); | ||||
return true; | return true; | ||||
Show All 37 Lines | attackComponentTest(defenderClass, false, (attacker, cmpAttack, defender) => { | ||||
TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender, ["Ranged", "Capture"]), isBuilding); | TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender, ["Ranged", "Capture"]), isBuilding); | ||||
TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender, ["!Ranged", "!Melee"]), isBuilding || defenderClass == "Domestic"); | TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender, ["!Ranged", "!Melee"]), isBuilding || defenderClass == "Domestic"); | ||||
TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender, ["Melee", "!Melee"]), false); | TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender, ["Melee", "!Melee"]), false); | ||||
let allowCapturing = [true]; | let allowCapturing = [true]; | ||||
if (!isBuilding) | if (!isBuilding) | ||||
allowCapturing.push(false); | allowCapturing.push(false); | ||||
let attack; | |||||
if (defenderClass == "Domestic") | |||||
attack = "Slaughter"; | |||||
else if (defenderClass == "Structure") | |||||
attack = "Capture"; | |||||
for (let ac of allowCapturing) | for (let ac of allowCapturing) | ||||
TS_ASSERT_EQUALS(cmpAttack.GetBestAttackAgainst(defender, ac), bestAttack); | TS_ASSERT_EQUALS(cmpAttack.GetBestAttackAgainst(defender, ac), bestAllyAttack); | ||||
}); | }); | ||||
} | } | ||||
testGetBestAttackAgainst("FemaleCitizen", "Melee"); | testGetBestAttackAgainst("FemaleCitizen", "Melee", undefined); | ||||
testGetBestAttackAgainst("Archer", "Ranged"); | testGetBestAttackAgainst("Archer", "Ranged", undefined); | ||||
testGetBestAttackAgainst("Domestic", "Slaughter"); | testGetBestAttackAgainst("Domestic", "Slaughter", "Slaughter"); | ||||
testGetBestAttackAgainst("Structure", "Capture", true); | testGetBestAttackAgainst("Structure", "Capture", "Capture", true); | ||||
function testPredictTimeToTarget(selfPosition, horizSpeed, targetPosition, targetVelocity) | function testPredictTimeToTarget(selfPosition, horizSpeed, targetPosition, targetVelocity) | ||||
{ | { | ||||
ResetState(); | ResetState(); | ||||
let cmpAttack = ConstructComponent(1, "Attack", {}); | let cmpAttack = ConstructComponent(1, "Attack", {}); | ||||
let timeToTarget = cmpAttack.PredictTimeToTarget(selfPosition, horizSpeed, targetPosition, targetVelocity); | let timeToTarget = cmpAttack.PredictTimeToTarget(selfPosition, horizSpeed, targetPosition, targetVelocity); | ||||
if (timeToTarget === false) | if (timeToTarget === false) | ||||
return; | return; | ||||
Show All 26 Lines |
Wildfire Games · Phabricator