Differential D2188 Diff 9384 binaries/data/mods/public/simulation/components/tests/test_Promotion.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Promotion.js
Engine.LoadComponentScript("interfaces/Health.js"); | Engine.LoadComponentScript("interfaces/Health.js"); | ||||
Engine.LoadComponentScript("interfaces/ModificationsManager.js"); | |||||
Engine.LoadComponentScript("interfaces/Promotion.js"); | Engine.LoadComponentScript("interfaces/Promotion.js"); | ||||
Engine.LoadComponentScript("interfaces/UnitAI.js"); | Engine.LoadComponentScript("interfaces/UnitAI.js"); | ||||
Engine.LoadComponentScript("ModificationsManager.js"); | |||||
Engine.LoadComponentScript("Promotion.js"); | Engine.LoadComponentScript("Promotion.js"); | ||||
Engine.LoadHelperScript("MultiKeyMap.js"); | |||||
Engine.LoadHelperScript("ValueModification.js"); | |||||
(function testMultipleXPIncrease() | (function testMultipleXPIncrease() | ||||
{ | { | ||||
let ApplyValueModificationsToEntity = (_, val) => val; | |||||
Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); | |||||
Engine.RegisterGlobal("ApplyValueModificationsToTemplate", ApplyValueModificationsToEntity); | |||||
let QueryOwnerInterface = () => ({ "GetPlayerID": () => 2 }); | let QueryOwnerInterface = () => ({ "GetPlayerID": () => 2 }); | ||||
Engine.RegisterGlobal("QueryOwnerInterface", QueryOwnerInterface); | Engine.RegisterGlobal("QueryOwnerInterface", QueryOwnerInterface); | ||||
const ENT_ID = 60; | const ENT_ID = 60; | ||||
let entTemplates = { | let entTemplates = { | ||||
"60": "template_b", | "60": "template_b", | ||||
"61": "template_f", | "61": "template_c", | ||||
"62": "end", | "62": "end", | ||||
}; | }; | ||||
let promote = { | let promote = { | ||||
"template_b": "template_c", | "template_b": "template_c", | ||||
"template_c": "template_d", | "template_c": "template_d", | ||||
"template_d": "template_e", | "template_d": "template_e", | ||||
"template_e": "template_f", | "template_e": "template_f", | ||||
Show All 31 Lines | |||||
TS_ASSERT_EQUALS(cmpPromotion.entity, 61); | TS_ASSERT_EQUALS(cmpPromotion.entity, 61); | ||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 0); | TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 0); | ||||
TS_ASSERT_EQUALS(cmpPromotion.GetRequiredXp(), 1000); | TS_ASSERT_EQUALS(cmpPromotion.GetRequiredXp(), 1000); | ||||
cmpPromotion.IncreaseXp(4200); | cmpPromotion.IncreaseXp(4200); | ||||
TS_ASSERT_EQUALS(cmpPromotion.entity, 62); | TS_ASSERT_EQUALS(cmpPromotion.entity, 62); | ||||
TS_ASSERT_EQUALS(cmpPromotion.template.Entity, "end"); | TS_ASSERT_EQUALS(cmpPromotion.template.Entity, "end"); | ||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 200); | TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 200); | ||||
})(); | })(); | ||||
(function testRankPromotion() | |||||
{ | |||||
let ownerId = 2; | |||||
let entId = 4; | |||||
let modMgr = ConstructComponent(SYSTEM_ENTITY, "ModificationsManager", {}); | |||||
let cmpPromotion = ConstructComponent(entId, "Promotion", { | |||||
"firstPromotion": { | |||||
"@from": 0, | |||||
"@until": 2, | |||||
"RequiredXp": 100, | |||||
"Modifiers": [ | |||||
] | |||||
}, | |||||
}); | |||||
let QueryOwnerEntityID = () => null; | |||||
Engine.RegisterGlobal("QueryOwnerEntityID", QueryOwnerEntityID); | |||||
AddMock(entId, IID_Identity, { | |||||
"GetClassesList": () => ["class_a"] | |||||
}); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 0); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetRequiredXp(), 100); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentLevel(), 0); | |||||
// Promote | |||||
cmpPromotion.IncreaseXp(150); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 50); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentLevel(), 1); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetRequiredXp(), 100); | |||||
// Promote | |||||
cmpPromotion.IncreaseXp(150); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentLevel(), 2); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetRequiredXp(), undefined); | |||||
// Check that increasing more does nothing. | |||||
cmpPromotion.IncreaseXp(150); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentLevel(), 2); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetRequiredXp(), undefined); | |||||
cmpPromotion = ConstructComponent(entId, "Promotion", { | |||||
"firstPromotion": { | |||||
"@from": 0, | |||||
"@until": 2, | |||||
"RequiredXp": 100, | |||||
"Modifiers": [ | |||||
] | |||||
}, | |||||
"secondPromotion": { | |||||
"@from": 2, | |||||
"@until": 5, | |||||
"RequiredXp": 200, | |||||
"Modifiers": { | |||||
"Test-Modifier": { | |||||
"Multiply": 2, | |||||
"Affects": { | |||||
"_string": "class_a class_b", | |||||
} | |||||
} | |||||
} | |||||
}, | |||||
}); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 0); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetRequiredXp(), 100); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentLevel(), 0); | |||||
// Promote | |||||
cmpPromotion.IncreaseXp(150); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 50); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentLevel(), 1); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetRequiredXp(), 100); | |||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test/Modifier", 5, entId), 5); | |||||
// Promote twice | |||||
cmpPromotion.IncreaseXp(250); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentLevel(), 3); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetRequiredXp(), 200); | |||||
cmpPromotion.IncreaseXp(200); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentLevel(), 4); | |||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test/Modifier", 5, entId), 20); | |||||
cmpPromotion.IncreaseXp(200); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentLevel(), 5); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetRequiredXp(), undefined); | |||||
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Test/Modifier", 5, entId), 40); | |||||
})(); |
Wildfire Games · Phabricator