Don't send MT_PlayerDefeated and MT_PlayerWon to components of entities who subscribed locally but aren't the playerentity of the affected player, equal to D733.

Besides the performance improvement for that hypothetical case,
it also means OnGlobalPlayerDefeated is used consistently and
an oversight like the one fixed by 2651caa885 might become easier to
notice.

From Differential_Revision: https://code.wildfiregames.com/D1426
Reviewed By: temple
Refs #5099

This was SVN commit r21712.
This commit is contained in:
elexis
2018-04-13 15:52:41 +00:00
parent 2651caa885
commit 65c8b51cd4
5 changed files with 14 additions and 13 deletions
@@ -483,7 +483,7 @@ Auras.prototype.OnGlobalResearchFinished = function(msg)
/**
* Only update playerauras, since units and structures are updated OnOwnershipChanged.
*/
Auras.prototype.OnPlayerDefeated = function(msg)
Auras.prototype.OnGlobalPlayerDefeated = function(msg)
{
if (!Engine.QueryInterface(this.entity, IID_Player))
return;
@@ -310,7 +310,7 @@ Capturable.prototype.OnOwnershipChanged = function(msg)
* When a player is defeated, reassign the cp of non-owned entities to gaia.
* Those owned by the defeated player are dealt with onOwnershipChanged.
*/
Capturable.prototype.OnPlayerDefeated = function(msg)
Capturable.prototype.OnGlobalPlayerDefeated = function(msg)
{
if (!this.cp[msg.playerId])
return;
@@ -497,7 +497,7 @@ Player.prototype.SetState = function(newState, message)
});
}
Engine.BroadcastMessage(won ? MT_PlayerWon : MT_PlayerDefeated, { "playerId": this.playerID });
Engine.PostMessage(this.entity, won ? MT_PlayerWon : MT_PlayerDefeated, { "playerId": this.playerID });
if (message)
{
@@ -23,13 +23,13 @@ global.AuraTemplates = {
}
};
let playerID = [0, 1, 2];
let playerEnt = [10, 11, 12];
let playerState = "active";
let sourceEnt = 20;
let targetEnt = 30;
let auraRange = 40;
let template = { "Identity" : { "Classes" : { "_string" : "CorrectClass OtherClass" } } };
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)
{
@@ -37,7 +37,8 @@ function testAuras(name, test_function)
AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
"GetPlayerByID": idx => playerEnt[idx],
"GetNumPlayers": () => 3
"GetNumPlayers": () => 3,
"GetAllPlayers": () => playerID
});
AddMock(SYSTEM_ENTITY, IID_RangeManager, {
@@ -10,7 +10,7 @@ Engine.LoadComponentScript("interfaces/TerritoryDecay.js");
Engine.LoadComponentScript("interfaces/Timer.js");
Engine.LoadComponentScript("Capturable.js");
let testData = {
var testData = {
"structure": 20,
"playerID": 1,
"regenRate": 2,
@@ -195,6 +195,6 @@ testReduce(testData, 3000, 3, 2000);
// Test defeated player
testCapturable(testData, cmpCapturable => {
cmpCapturable.SetCapturePoints([500, 1000, 0, 250]);
cmpCapturable.OnPlayerDefeated({ "playerId": 3 });
cmpCapturable.OnGlobalPlayerDefeated({ "playerId": 3 });
TS_ASSERT_UNEVAL_EQUALS(cmpCapturable.GetCapturePoints(), [750, 1000, 0, 0]);
});