Differential D2026 Diff 9444 ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Promotion.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Promotion.js
Engine.LoadComponentScript("interfaces/Guard.js"); | |||||
Engine.LoadComponentScript("interfaces/Health.js"); | Engine.LoadComponentScript("interfaces/Health.js"); | ||||
Engine.LoadComponentScript("interfaces/Promotion.js"); | Engine.LoadComponentScript("interfaces/Promotion.js"); | ||||
Engine.LoadComponentScript("interfaces/ResourceGatherer.js"); | |||||
Engine.LoadComponentScript("interfaces/UnitAI.js"); | Engine.LoadComponentScript("interfaces/UnitAI.js"); | ||||
Engine.LoadComponentScript("Promotion.js"); | Engine.LoadComponentScript("Promotion.js"); | ||||
Engine.RegisterGlobal("MT_EntityRenamed", "entityRenamed"); | |||||
// Test Promote | (function testMultipleXPIncrease() | ||||
{ | |||||
let cmpPromotion = ConstructComponent(60, "Promotion", { | let ApplyValueModificationsToEntity = (_, val) => val; | ||||
"Entity": "infantry_melee_spearman_a", | Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity); | ||||
"RequiredXP": 1000 | Engine.RegisterGlobal("ApplyValueModificationsToTemplate", ApplyValueModificationsToEntity); | ||||
}); | |||||
let QueryOwnerInterface = () => ({ "GetPlayerID": () => 2 }); | |||||
// Health, Position, Ownership, UnitAI are mandatory in the Promotion code | Engine.RegisterGlobal("QueryOwnerInterface", QueryOwnerInterface); | ||||
AddMock(60, IID_Health, { | |||||
"GetHitpoints": () => 102, | const ENT_ID = 60; | ||||
"GetMaxHitpoints": () => 102, | |||||
}); | let entTemplates = { | ||||
"60": "template_b", | |||||
"61": "template_f", | |||||
"62": "end", | |||||
}; | |||||
AddMock(60, IID_Position, { | let promote = { | ||||
"GetPosition2D": () => new Vector2D(1, 0, 0), | "template_b": "template_c", | ||||
"GetRotation": () => new Vector3D(3, 4, 5), | "template_c": "template_d", | ||||
"GetHeightOffset": () => {}, | "template_d": "template_e", | ||||
"IsInWorld": () => true, | "template_e": "template_f", | ||||
"MoveOutOfWorld": () => {} | }; | ||||
}); | |||||
AddMock(60, IID_Ownership, { | AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | ||||
"GetOwner": () => 1, | "GetTemplate": (t) => ({ | ||||
"Promotion": { | |||||
"Entity": promote[t], | |||||
"RequiredXp": 1000 | |||||
}, | |||||
}), | |||||
}); | }); | ||||
AddMock(60, IID_UnitAI, { | let cmpPromotion = ConstructComponent(ENT_ID, "Promotion", { | ||||
"GetHeldPosition": () => {}, | "Entity": "template_b", | ||||
"GetStanceName": () => {}, | "RequiredXp": 1000 | ||||
"GetOrders": () => {}, | |||||
"IsGarrisoned": () => {}, | |||||
"GetWorkOrders": () => {}, | |||||
"IsGuardOf": () => {}, | |||||
}); | }); | ||||
Engine.AddEntity = function(name) | let ChangeEntityTemplate = function(ent, template) | ||||
{ | { | ||||
if (name != "infantry_melee_spearman_a") | cmpPromotion = ConstructComponent(ent + 1, "Promotion", { | ||||
return undefined; | "Entity": entTemplates[ent + 1], | ||||
AddMock(61, IID_Health, { | "RequiredXp": 1000 | ||||
"GetMaxHitpoints": () => 102 * 1.2, | |||||
"SetHitpoints": hp => TS_ASSERT_EQUALS(hp, 102 * 1.2) | |||||
}); | |||||
AddMock(61, IID_Position, { | |||||
"JumpTo": () => {}, | |||||
"SetYRotation": () => {}, | |||||
"SetXZRotation": () => {}, | |||||
"SetHeightOffset": () => {}, | |||||
"IsInWorld": () => true, | |||||
}); | |||||
AddMock(61, IID_Ownership, { | |||||
"SetOwner": id => TS_ASSERT_EQUALS(id, 1), | |||||
}); | |||||
AddMock(61, IID_UnitAI, { | |||||
"Cheer": () => {}, | |||||
"AddOrders": () => {}, | |||||
"SetWorkOrders": () => {}, | |||||
}); | }); | ||||
return 61; | return ent + 1; | ||||
}; | }; | ||||
Engine.RegisterGlobal("ChangeEntityTemplate", ChangeEntityTemplate); | |||||
cmpPromotion.Promote("infantry_melee_spearman_a"); | TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 0); | ||||
cmpPromotion.IncreaseXp(200); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 200); | |||||
cmpPromotion.IncreaseXp(800); | |||||
TS_ASSERT_EQUALS(cmpPromotion.entity, 61); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 0); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetRequiredXp(), 1000); | |||||
cmpPromotion.IncreaseXp(4200); | |||||
TS_ASSERT_EQUALS(cmpPromotion.entity, 62); | |||||
TS_ASSERT_EQUALS(cmpPromotion.template.Entity, "end"); | |||||
TS_ASSERT_EQUALS(cmpPromotion.GetCurrentXp(), 200); | |||||
})(); |
Wildfire Games · Phabricator