Index: ps/trunk/binaries/data/mods/public/simulation/components/Auras.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/Auras.js +++ ps/trunk/binaries/data/mods/public/simulation/components/Auras.js @@ -100,9 +100,9 @@ // 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.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 @@ 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; } Index: ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Auras.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Auras.js +++ ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Auras.js @@ -7,6 +7,14 @@ 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 @@ } }; -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 @@ 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 @@ 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("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 @@ 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 @@ 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); });