0ad/binaries/data/mods/public/simulation/components/tests/test_Player.js
wraitii 077c4f2576 Adds a "properties"-property to resources and let mods be able to prevent resources from being bartered, traded and/or tributed.
Patch By: Freagarach
Comments By: elexis, Stan`, Nescio
Reviewed By: wraitii, Angen
Fixes #4370

Differential Revision: https://code.wildfiregames.com/D1846
This was SVN commit r22970.
2019-09-22 14:53:47 +00:00

68 lines
1.6 KiB
JavaScript

Resources = {
"GetCodes": () => ["food", "metal", "stone", "wood"],
"GetTradableCodes": () => ["food", "metal", "stone", "wood"],
"GetBarterableCodes": () => ["food", "metal", "stone", "wood"],
"GetResource": () => ({}),
"BuildSchema": (type) => {
let schema = "";
for (let res of Resources.GetCodes())
schema +=
"<optional>" +
"<element name='" + res + "'>" +
"<ref name='" + type + "'/>" +
"</element>" +
"</optional>";
return "<interleave>" + schema + "</interleave>";
}
};
Engine.LoadHelperScript("ValueModification.js");
Engine.LoadComponentScript("interfaces/Player.js");
Engine.LoadComponentScript("interfaces/ModifiersManager.js");
Engine.LoadComponentScript("Player.js");
var cmpPlayer = ConstructComponent(10, "Player", {
"SpyCostMultiplier": 1,
"BarterMultiplier": {
"Buy": {
"wood": 1.0,
"stone": 1.0,
"metal": 1.0
},
"Sell": {
"wood": 1.0,
"stone": 1.0,
"metal": 1.0
}
},
});
TS_ASSERT_EQUALS(cmpPlayer.GetPopulationCount(), 0);
TS_ASSERT_EQUALS(cmpPlayer.GetPopulationLimit(), 0);
cmpPlayer.SetDiplomacy([-1, 1, 0, 1, -1]);
TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetAllies(), [1, 3]);
TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetEnemies(), [0, 4]);
var diplo = cmpPlayer.GetDiplomacy();
diplo[0] = 1;
TS_ASSERT(cmpPlayer.IsEnemy(0));
diplo = [1, 1, 0];
cmpPlayer.SetDiplomacy(diplo);
diplo[1] = -1;
TS_ASSERT(cmpPlayer.IsAlly(1));
TS_ASSERT_EQUALS(cmpPlayer.GetSpyCostMultiplier(), 1);
TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetBarterMultiplier(), {
"buy": {
"wood": 1.0,
"stone": 1.0,
"metal": 1.0
},
"sell": {
"wood": 1.0,
"stone": 1.0,
"metal": 1.0
}
});