Stop some auras from being applied extra times, don't apply player auras to templates, and fix some linting errors

Differential Revision: https://code.wildfiregames.com/D1430
Comments by: fatherbushido, elexis
This was SVN commit r21785.
This commit is contained in:
temple 2018-04-26 00:35:24 +00:00
parent f7c2785400
commit 583b6ec625
2 changed files with 42 additions and 36 deletions

View File

@ -100,9 +100,9 @@ Auras.prototype.GetRangeOverlays = function()
// Specify default in order not to specify it in about 40 auras
{
"radius": this.GetRange(name),
"texture": "outline_border.png",
"textureMask": "outline_border_mask.png",
"thickness": 0.2
"texture": "outline_border.png",
"textureMask": "outline_border_mask.png",
"thickness": 0.2
});
}
@ -187,7 +187,7 @@ Auras.prototype.IsRangeAura = function(name)
Auras.prototype.IsGlobalAura = function(name)
{
return this.GetType(name) == "global" || this.GetType(name) == "player";
return this.GetType(name) == "global";
};
Auras.prototype.IsPlayerAura = function(name)
@ -242,18 +242,16 @@ Auras.prototype.Clean = function()
if (this.IsGlobalAura(name))
{
this.ApplyTemplateBonus(name, affectedPlayers);
for (let player of affectedPlayers)
{
this.ApplyTemplateBonus(name, affectedPlayers);
if (this.IsPlayerAura(name))
{
let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
let playerEnts = affectedPlayers.map(player => cmpPlayerManager.GetPlayerByID(player));
this.ApplyBonus(name, playerEnts);
}
else
this.ApplyBonus(name, cmpRangeManager.GetEntitiesByPlayer(player));
}
this.ApplyBonus(name, cmpRangeManager.GetEntitiesByPlayer(player));
continue;
}
if (this.IsPlayerAura(name))
{
let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
this.ApplyBonus(name, affectedPlayers.map(p => cmpPlayerManager.GetPlayerByID(p)));
continue;
}

View File

@ -7,6 +7,14 @@ Engine.LoadComponentScript("interfaces/TechnologyManager.js");
Engine.LoadComponentScript("Auras.js");
Engine.LoadComponentScript("AuraManager.js");
var playerID = [0, 1, 2];
var playerEnt = [10, 11, 12];
var playerState = ["active", "active", "active"];
var sourceEnt = 20;
var targetEnt = 30;
var auraRange = 40;
var template = { "Identity": { "Classes": { "_string": "CorrectClass OtherClass" } } };
global.AuraTemplates = {
"Get": name => {
let template = {
@ -23,14 +31,6 @@ global.AuraTemplates = {
}
};
var playerID = [0, 1, 2];
var playerEnt = [10, 11, 12];
var playerState = "active";
var sourceEnt = 20;
var targetEnt = 30;
var auraRange = 40;
var template = { "Identity" : { "Classes" : { "_string" : "CorrectClass OtherClass" } } };
function testAuras(name, test_function)
{
ResetState();
@ -53,16 +53,16 @@ function testAuras(name, test_function)
AddMock(playerEnt[1], IID_Player, {
"IsAlly": id => id == playerID[1] || id == playerID[2],
"IsEnemy": id => id != playerID[1] || id != playerID[2],
"IsEnemy": id => id != playerID[1] || id != playerID[2],
"GetPlayerID": () => playerID[1],
"GetState": () => playerState
"GetState": () => playerState[1]
});
AddMock(playerEnt[2], IID_Player, {
"IsAlly": id => id == playerID[1] || id == playerID[2],
"IsEnemy": id => id != playerID[1] || id != playerID[2],
"GetPlayerID": () => playerID[2],
"GetState": () => playerState
"GetState": () => playerState[2]
});
AddMock(targetEnt, IID_Identity, {
@ -94,15 +94,9 @@ function testAuras(name, test_function)
test_function(name, cmpAuras);
}
testAuras("global", (name, cmpAuras) => {
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 5, targetEnt), 15);
TS_ASSERT_EQUALS(ApplyValueModificationsToTemplate("Component/Value", 5, playerID[1], template), 15);
});
targetEnt = playerEnt[playerID[2]];
testAuras("player", (name, cmpAuras) => {
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 5, targetEnt), 15);
TS_ASSERT_EQUALS(ApplyValueModificationsToTemplate("Component/Value", 5, playerID[1], template), 15);
});
targetEnt = 30;
@ -123,9 +117,9 @@ testAuras("range", (name, cmpAuras) => {
});
testAuras("garrisonedUnits", (name, cmpAuras) => {
cmpAuras.OnGarrisonedUnitsChanged({ "added" : [targetEnt], "removed": [] });
cmpAuras.OnGarrisonedUnitsChanged({ "added": [targetEnt], "removed": [] });
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 5, targetEnt), 15);
cmpAuras.OnGarrisonedUnitsChanged({ "added" : [], "removed": [targetEnt] });
cmpAuras.OnGarrisonedUnitsChanged({ "added": [], "removed": [targetEnt] });
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 5, targetEnt), 5);
});
@ -134,7 +128,7 @@ testAuras("garrison", (name, cmpAuras) => {
cmpAuras.ApplyGarrisonBonus(targetEnt);
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 5, targetEnt), 15);
cmpAuras.RemoveGarrisonBonus(targetEnt);
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 1, targetEnt), 1);
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 5, targetEnt), 5);
});
testAuras("formation", (name, cmpAuras) => {
@ -145,7 +139,21 @@ testAuras("formation", (name, cmpAuras) => {
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 5, targetEnt), 5);
});
playerState = "defeated";
testAuras("global", (name, cmpAuras) => {
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 5, targetEnt), 15);
TS_ASSERT_EQUALS(ApplyValueModificationsToTemplate("Component/Value", 5, playerID[1], template), 15);
TS_ASSERT_EQUALS(ApplyValueModificationsToTemplate("Component/Value", 5, playerID[2], template), 15);
AddMock(sourceEnt, IID_Ownership, {
"GetOwner": () => -1
});
cmpAuras.OnOwnershipChanged({ "from": sourceEnt, "to": -1 });
TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 5, targetEnt), 5);
TS_ASSERT_EQUALS(ApplyValueModificationsToTemplate("Component/Value", 5, playerID[1], template), 5);
TS_ASSERT_EQUALS(ApplyValueModificationsToTemplate("Component/Value", 5, playerID[2], template), 5);
});
playerState[1] = "defeated";
testAuras("global", (name, cmpAuras) => {
cmpAuras.OnGlobalPlayerDefeated({ "playerId": playerID[1] });
TS_ASSERT_EQUALS(ApplyValueModificationsToTemplate("Component/Value", 5, playerID[2], template), 5);
});