2017-11-17 03:38:51 -08:00
|
|
|
Trigger.prototype.ConquestOwnershipChanged = function(msg)
|
2015-05-07 20:06:14 -07:00
|
|
|
{
|
2018-03-09 13:51:18 -08:00
|
|
|
if (!this.conquestDataInit)
|
2015-05-07 20:06:14 -07:00
|
|
|
return;
|
|
|
|
|
|
2025-05-09 10:44:52 -07:00
|
|
|
for (const query of this.conquestQueries)
|
2018-03-09 13:51:18 -08:00
|
|
|
{
|
|
|
|
|
if (!TriggerHelper.EntityMatchesClassList(msg.entity, query.classFilter))
|
|
|
|
|
continue;
|
2015-05-07 20:06:14 -07:00
|
|
|
|
2018-03-09 13:51:18 -08:00
|
|
|
if (msg.to > 0)
|
|
|
|
|
query.entitiesByPlayer[msg.to].push(msg.entity);
|
2015-05-07 20:06:14 -07:00
|
|
|
|
2018-03-09 13:51:18 -08:00
|
|
|
if (msg.from <= 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-05-09 10:44:52 -07:00
|
|
|
const entities = query.entitiesByPlayer[msg.from];
|
|
|
|
|
const index = entities.indexOf(msg.entity);
|
2017-11-17 03:38:51 -08:00
|
|
|
if (index != -1)
|
|
|
|
|
entities.splice(index, 1);
|
2015-05-07 20:06:14 -07:00
|
|
|
|
2016-06-25 21:40:50 -07:00
|
|
|
if (!entities.length)
|
|
|
|
|
{
|
2025-05-09 10:44:52 -07:00
|
|
|
const cmpPlayer = QueryPlayerIDInterface(msg.from);
|
2016-06-25 21:40:50 -07:00
|
|
|
if (cmpPlayer)
|
2026-03-20 03:32:36 -07:00
|
|
|
cmpPlayer.Defeat(query.defeatReason);
|
2016-06-25 21:40:50 -07:00
|
|
|
}
|
2015-05-07 20:06:14 -07:00
|
|
|
}
|
2016-10-18 05:52:00 -07:00
|
|
|
};
|
2015-05-07 20:06:14 -07:00
|
|
|
|
|
|
|
|
Trigger.prototype.ConquestStartGameCount = function()
|
|
|
|
|
{
|
2018-03-09 13:51:18 -08:00
|
|
|
if (!this.conquestQueries.length)
|
2015-05-07 20:06:14 -07:00
|
|
|
{
|
2018-03-09 13:51:18 -08:00
|
|
|
warn("ConquestStartGameCount: no conquestQueries set");
|
2015-05-07 20:06:14 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-09 10:44:52 -07:00
|
|
|
const cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
|
|
|
|
|
const entitiesByPlayer = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetAllPlayers().map(playerID =>
|
2018-03-09 13:51:18 -08:00
|
|
|
cmpRangeManager.GetEntitiesByPlayer(playerID));
|
2015-05-07 20:06:14 -07:00
|
|
|
|
2025-05-09 10:44:52 -07:00
|
|
|
for (const query of this.conquestQueries)
|
2018-03-09 13:51:18 -08:00
|
|
|
query.entitiesByPlayer = entitiesByPlayer.map(
|
|
|
|
|
ents => ents.filter(
|
|
|
|
|
ent => TriggerHelper.EntityMatchesClassList(ent, query.classFilter)));
|
2015-05-07 20:06:14 -07:00
|
|
|
|
|
|
|
|
this.conquestDataInit = true;
|
2016-06-25 21:40:50 -07:00
|
|
|
};
|
2015-05-07 20:06:14 -07:00
|
|
|
|
2018-03-09 13:51:18 -08:00
|
|
|
Trigger.prototype.ConquestAddVictoryCondition = function(data)
|
|
|
|
|
{
|
|
|
|
|
this.conquestQueries.push(data);
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-10 07:03:51 -07:00
|
|
|
{
|
2025-05-09 10:44:52 -07:00
|
|
|
const cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
|
2017-05-10 07:03:51 -07:00
|
|
|
cmpTrigger.conquestDataInit = false;
|
2018-03-09 13:51:18 -08:00
|
|
|
cmpTrigger.conquestQueries = [];
|
2017-11-17 03:38:51 -08:00
|
|
|
cmpTrigger.RegisterTrigger("OnOwnershipChanged", "ConquestOwnershipChanged", { "enabled": true });
|
|
|
|
|
cmpTrigger.DoAfterDelay(0, "ConquestStartGameCount", null);
|
2017-05-10 07:03:51 -07:00
|
|
|
}
|