Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Attack.js
Engine.LoadHelperScript("Player.js"); | Engine.LoadHelperScript("Player.js"); | ||||
Engine.LoadHelperScript("ValueModification.js"); | Engine.LoadHelperScript("ValueModification.js"); | ||||
Engine.LoadComponentScript("interfaces/Auras.js"); | Engine.LoadComponentScript("interfaces/Auras.js"); | ||||
Engine.LoadComponentScript("interfaces/AuraManager.js"); | Engine.LoadComponentScript("interfaces/AuraManager.js"); | ||||
Engine.LoadComponentScript("interfaces/Capturable.js"); | Engine.LoadComponentScript("interfaces/Capturable.js"); | ||||
Engine.LoadComponentScript("interfaces/TechnologyManager.js"); | Engine.LoadComponentScript("interfaces/TechnologyManager.js"); | ||||
Engine.LoadComponentScript("interfaces/Formation.js"); | Engine.LoadComponentScript("interfaces/Formation.js"); | ||||
Engine.LoadComponentScript("interfaces/Attack.js"); | Engine.LoadComponentScript("interfaces/Attack.js"); | ||||
Engine.LoadComponentScript("Attack.js"); | Engine.LoadComponentScript("Attack.js"); | ||||
let entityID = 903; | let entityID = 903; | ||||
function attackComponentTest(defenderClass, isEnemy, test_function) | function attackComponentTest(defenderClass, isEnemy, test_function) | ||||
{ | { | ||||
ResetState(); | ResetState(); | ||||
bb: Wondering why we need this component/object doesn't seem used | |||||
{ | { | ||||
let playerEnt1 = 5; | let playerEnt1 = 5; | ||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | ||||
"GetPlayerByID": () => playerEnt1 | "GetPlayerByID": () => playerEnt1 | ||||
}); | }); | ||||
AddMock(playerEnt1, IID_Player, { | AddMock(playerEnt1, IID_Player, { | ||||
"GetPlayerID": () => 1, | "GetPlayerID": () => 1, | ||||
"IsEnemy": () => isEnemy | "IsEnemy": () => isEnemy | ||||
}); | }); | ||||
} | } | ||||
let attacker = entityID; | let attacker = entityID; | ||||
AddMock(attacker, IID_Position, { | AddMock(attacker, IID_Position, { | ||||
"IsInWorld": () => true, | "IsInWorld": () => true, | ||||
"GetHeightOffset": () => 5 | "GetHeightOffset": () => 5, | ||||
"GetPosition2D": () => new Vector2D(1, 2) | |||||
}); | }); | ||||
AddMock(attacker, IID_Ownership, { | AddMock(attacker, IID_Ownership, { | ||||
"GetOwner": () => 1 | "GetOwner": () => 1 | ||||
}); | }); | ||||
let cmpAttack = ConstructComponent(attacker, "Attack", { | let cmpAttack = ConstructComponent(attacker, "Attack", { | ||||
"Melee" : { | "Melee" : { | ||||
Show All 19 Lines | let cmpAttack = ConstructComponent(attacker, "Attack", { | ||||
"Ranged" : { | "Ranged" : { | ||||
"Hack": 0, | "Hack": 0, | ||||
"Pierce": 10, | "Pierce": 10, | ||||
"Crush": 0, | "Crush": 0, | ||||
"MinRange": 10, | "MinRange": 10, | ||||
"MaxRange": 80, | "MaxRange": 80, | ||||
"PrepareTime": 300, | "PrepareTime": 300, | ||||
"RepeatTime": 500, | "RepeatTime": 500, | ||||
"ProjectileSpeed": 50, | |||||
"Spread": 2.5, | |||||
"PreferredClasses": { | "PreferredClasses": { | ||||
"_string": "Archer" | "_string": "Archer" | ||||
}, | }, | ||||
"RestrictedClasses": { | "RestrictedClasses": { | ||||
"_string": "Elephant" | "_string": "Elephant" | ||||
}, | |||||
"Splash" : { | |||||
"Shape": "Circular", | |||||
"Range": 10, | |||||
"FriendlyFire": "false", | |||||
"Hack": 0.0, | |||||
"Pierce": 15.0, | |||||
"Crush": 35.0 | |||||
} | } | ||||
}, | }, | ||||
"Capture" : { | "Capture" : { | ||||
"Value": 8, | "Value": 8, | ||||
"MaxRange": 10, | "MaxRange": 10, | ||||
}, | }, | ||||
"Slaughter": {} | "Slaughter": {} | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | TS_ASSERT_UNEVAL_EQUALS(cmpAttack.GetTimers("Ranged"), { | ||||
"prepare": 300, | "prepare": 300, | ||||
"repeat": 500 | "repeat": 500 | ||||
}); | }); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpAttack.GetTimers("Capture"), { | TS_ASSERT_UNEVAL_EQUALS(cmpAttack.GetTimers("Capture"), { | ||||
"prepare": 0, | "prepare": 0, | ||||
"repeat": 1000 | "repeat": 1000 | ||||
}); | }); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpAttack.GetSplashDamage("Ranged"), { "hack": 0, "pierce": 15, "crush": 35, "friendlyFire": false, "shape": "Circular" }); | |||||
}); | }); | ||||
for (let className of ["Infantry", "Cavalry"]) | for (let className of ["Infantry", "Cavalry"]) | ||||
attackComponentTest(className, true, (attacker, cmpAttack, defender) => { | attackComponentTest(className, true, (attacker, cmpAttack, defender) => { | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpAttack.GetAttackBonus("Melee", defender), className == "Cavalry" ? 2 : 1); | TS_ASSERT_UNEVAL_EQUALS(cmpAttack.GetAttackBonus("Melee", defender), className == "Cavalry" ? 2 : 1); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpAttack.GetAttackBonus("Ranged", defender), 1); | TS_ASSERT_UNEVAL_EQUALS(cmpAttack.GetAttackBonus("Ranged", defender), 1); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpAttack.GetAttackBonus("Capture", defender), 1); | TS_ASSERT_UNEVAL_EQUALS(cmpAttack.GetAttackBonus("Capture", defender), 1); | ||||
TS_ASSERT_UNEVAL_EQUALS(cmpAttack.GetAttackBonus("Slaughter", defender), 1); | TS_ASSERT_UNEVAL_EQUALS(cmpAttack.GetAttackBonus("Slaughter", defender), 1); | ||||
Show All 32 Lines | attackComponentTest(defenderClass, true, (attacker, cmpAttack, defender) => { | ||||
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), bestAttack); | ||||
}); | }); | ||||
attackComponentTest(defenderClass, false, (attacker, cmpAttack, defender) => { | attackComponentTest(defenderClass, false, (attacker, cmpAttack, defender) => { | ||||
if (isBuilding) | if (isBuilding) | ||||
AddMock(defender, IID_Capturable, { | AddMock(defender, IID_Capturable, { | ||||
Done Inline ActionsUse arrow function bb: Use arrow function | |||||
"CanCapture": playerID => { | "CanCapture": playerID => { | ||||
TS_ASSERT_EQUALS(playerID, 1); | TS_ASSERT_EQUALS(playerID, 1); | ||||
return true; | return true; | ||||
} | } | ||||
}); | }); | ||||
TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender), isBuilding || defenderClass == "Domestic"); | TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender), isBuilding || defenderClass == "Domestic"); | ||||
TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender, []), isBuilding || defenderClass == "Domestic"); | TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender, []), isBuilding || defenderClass == "Domestic"); | ||||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Wondering why we need this component/object doesn't seem used