Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Heal.js
Engine.LoadHelperScript("ValueModification.js"); | Engine.LoadHelperScript("ValueModification.js"); | ||||
Engine.LoadHelperScript("Player.js"); | |||||
Engine.LoadComponentScript("interfaces/Formation.js"); | |||||
Engine.LoadComponentScript("interfaces/Heal.js"); | Engine.LoadComponentScript("interfaces/Heal.js"); | ||||
Engine.LoadComponentScript("interfaces/Health.js"); | Engine.LoadComponentScript("interfaces/Health.js"); | ||||
Engine.LoadComponentScript("interfaces/Loot.js"); | Engine.LoadComponentScript("interfaces/Loot.js"); | ||||
Engine.LoadComponentScript("interfaces/Promotion.js"); | Engine.LoadComponentScript("interfaces/Promotion.js"); | ||||
Engine.LoadComponentScript("interfaces/UnitAI.js"); | Engine.LoadComponentScript("interfaces/UnitAI.js"); | ||||
Engine.LoadComponentScript("Heal.js"); | Engine.LoadComponentScript("Heal.js"); | ||||
const entity= 60; | const entity = 60; | ||||
const player = 1; | |||||
let template = { | let template = { | ||||
"Range": 20, | "Range": 20, | ||||
"RangeOverlay" : { | "RangeOverlay" : { | ||||
"LineTexture": "heal_overlay_range.png", | "LineTexture": "heal_overlay_range.png", | ||||
"LineTextureMask": "heal_overlay_range_mask.png", | "LineTextureMask": "heal_overlay_range_mask.png", | ||||
"LineThickness": 0.35 | "LineThickness": 0.35 | ||||
}, | }, | ||||
"HP": 5, | "HP": 5, | ||||
"Rate": 2000, | "Rate": 2000, | ||||
"UnhealableClasses": { "_string": "Cavalry" }, | "UnhealableClasses": { "_string": "Cavalry" }, | ||||
"HealableClasses": { "_string": "Support Infantry" }, | "HealableClasses": { "_string": "Support Infantry" }, | ||||
}; | }; | ||||
AddMock(entity, IID_Ownership, { | |||||
"GetOwner": () => player | |||||
}); | |||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | |||||
"GetPlayerByID": () => player | |||||
}); | |||||
AddMock(player, IID_Player, { | |||||
"GetPlayerID": () => player | |||||
}); | |||||
ApplyValueModificationsToEntity = function(value, stat, ent) | ApplyValueModificationsToEntity = function(value, stat, ent) | ||||
{ | { | ||||
if (ent != entity) | if (ent != entity) | ||||
return stat; | return stat; | ||||
switch (value) | switch (value) | ||||
{ | { | ||||
case "Heal/HP": | case "Heal/HP": | ||||
return stat + 100; | return stat + 100; | ||||
Show All 33 Lines | |||||
let increased; | let increased; | ||||
AddMock(target, IID_Health, { | AddMock(target, IID_Health, { | ||||
"GetMaxHitpoints": () => 700, | "GetMaxHitpoints": () => 700, | ||||
"Increase": amount => { | "Increase": amount => { | ||||
increased = true; | increased = true; | ||||
TS_ASSERT_EQUALS(amount, 5 + 100); | TS_ASSERT_EQUALS(amount, 5 + 100); | ||||
return { "old": 600, "new": 600 + 5 + 100 }; | return { "old": 600, "new": 600 + 5 + 100 }; | ||||
} | }, | ||||
"IsUnhealable": () => false | |||||
}); | }); | ||||
cmpHeal.PerformHeal(target); | cmpHeal.PerformHeal(target); | ||||
TS_ASSERT(increased); | TS_ASSERT(increased); | ||||
let looted; | let looted; | ||||
AddMock(target, IID_Loot, { | AddMock(target, IID_Loot, { | ||||
"GetXp": () => { | "GetXp": () => { | ||||
Show All 21 Lines | AddMock(entity, IID_UnitAI, { | ||||
} | } | ||||
}); | }); | ||||
cmpHeal.OnValueModification({ "component": "Heal", "valueNames": ["Heal/HP"] }); | cmpHeal.OnValueModification({ "component": "Heal", "valueNames": ["Heal/HP"] }); | ||||
TS_ASSERT(!updated); | TS_ASSERT(!updated); | ||||
cmpHeal.OnValueModification({ "component": "Heal", "valueNames": ["Heal/Range"] }); | cmpHeal.OnValueModification({ "component": "Heal", "valueNames": ["Heal/Range"] }); | ||||
TS_ASSERT(updated); | TS_ASSERT(updated); | ||||
// Test CanHeal. | |||||
let targets = [71, 72, 73, 74, 75]; | |||||
for (let target of targets) | |||||
bb: please the linter by choosing another name
Probably a loop isn't the best idea since we need… | |||||
{ | |||||
AddMock(target, IID_Ownership, { | |||||
"GetOwner": () => player | |||||
}); | |||||
if (target == 71) | |||||
AddMock(target, IID_Identity, { | |||||
"GetClassesList": () => ["Infantry", "Hero"] | |||||
}); | |||||
else if (target == 72) | |||||
AddMock(target, IID_Identity, { | |||||
"GetClassesList": () => ["Hero"] | |||||
}); | |||||
else if (target == 73) | |||||
AddMock(target, IID_Identity, { | |||||
"GetClassesList": () => ["Infantry", "Cavalry"] | |||||
}); | |||||
else if (target == 74) | |||||
AddMock(target, IID_Identity, { | |||||
"GetClassesList": () => ["Cavalry"] | |||||
}); | |||||
else if (target == 75) | |||||
AddMock(target, IID_Identity, { | |||||
"GetClassesList": () => ["Infantry"] | |||||
}); | |||||
AddMock(target, IID_Health, { | |||||
"IsUnhealable": () => target == 75 | |||||
}); | |||||
TS_ASSERT_UNEVAL_EQUALS(cmpHeal.CanHeal(target), target == 71); | |||||
} | |||||
bbUnsubmitted Not Done Inline ActionsA test for non allies sounds fun too bb: A test for non allies sounds fun too |
Wildfire Games · Phabricator
please the linter by choosing another name
Probably a loop isn't the best idea since we need custom code anyhow