Handle aura and production pause on GarrisonedStateChanged message.

This reduces hard-coupling between the components.

Refs. #6081
Differential revision: D3683
Reviewed by: @wraitii
This was SVN commit r25062.
This commit is contained in:
Freagarach 2021-03-16 05:49:36 +00:00
parent 5cbbd570c0
commit 93fe2ffa8a
5 changed files with 21 additions and 20 deletions

View file

@ -505,4 +505,15 @@ Auras.prototype.OnGlobalPlayerDefeated = function(msg)
this.Clean();
};
Auras.prototype.OnGarrisonedStateChanged = function(msg)
{
if (!this.HasGarrisonAura())
return;
if (msg.holderID != INVALID_ENTITY)
this.ApplyGarrisonAura(msg.holderID);
if (msg.olderHolder != INVALID_ENTITY)
this.RemoveGarrisonAura(msg.oldHolder);
};
Engine.RegisterComponentType(IID_Auras, "Auras", Auras);

View file

@ -76,19 +76,12 @@ Garrisonable.prototype.Garrison = function(target, renamed = false)
if (cmpUnitAI)
cmpUnitAI.SetGarrisoned();
let cmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue);
if (cmpProductionQueue)
cmpProductionQueue.PauseProduction();
let cmpAura = Engine.QueryInterface(this.entity, IID_Auras);
if (cmpAura && cmpAura.HasGarrisonAura())
cmpAura.ApplyGarrisonAura(target);
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
if (cmpPosition)
cmpPosition.MoveOutOfWorld();
Engine.PostMessage(this.entity, MT_GarrisonedStateChanged, {
"oldHolder": INVALID_ENTITY,
"holderID": target
});
@ -157,15 +150,8 @@ Garrisonable.prototype.UnGarrison = function(forced = false, renamed = false)
cmpUnitAI.UnsetGarrisoned();
}
let cmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue);
if (cmpProductionQueue)
cmpProductionQueue.UnpauseProduction();
let cmpAura = Engine.QueryInterface(this.entity, IID_Auras);
if (cmpAura && cmpAura.HasGarrisonAura())
cmpAura.RemoveGarrisonAura(this.holder);
Engine.PostMessage(this.entity, MT_GarrisonedStateChanged, {
"oldHolder": this.holder,
"holderID": INVALID_ENTITY
});

View file

@ -967,4 +967,12 @@ ProductionQueue.prototype.OnDisabledTemplatesChanged = function(msg)
this.CalculateEntitiesMap();
};
ProductionQueue.prototype.OnGarrisonedStateChanged = function(msg)
{
if (msg.holderID != INVALID_ENTITY)
this.PauseProduction();
else
this.UnpauseProduction();
};
Engine.RegisterComponentType(IID_ProductionQueue, "ProductionQueue", ProductionQueue);

View file

@ -1,7 +1,5 @@
Engine.LoadComponentScript("interfaces/Auras.js");
Engine.LoadComponentScript("interfaces/Garrisonable.js");
Engine.LoadComponentScript("interfaces/GarrisonHolder.js");
Engine.LoadComponentScript("interfaces/ProductionQueue.js");
Engine.LoadComponentScript("interfaces/UnitAI.js");
Engine.LoadComponentScript("Garrisonable.js");

View file

@ -1,11 +1,9 @@
Engine.LoadHelperScript("ValueModification.js");
Engine.LoadHelperScript("Player.js");
Engine.LoadComponentScript("interfaces/Auras.js");
Engine.LoadComponentScript("interfaces/Garrisonable.js");
Engine.LoadComponentScript("interfaces/GarrisonHolder.js");
Engine.LoadComponentScript("interfaces/Health.js");
Engine.LoadComponentScript("interfaces/ModifiersManager.js");
Engine.LoadComponentScript("interfaces/ProductionQueue.js");
Engine.LoadComponentScript("interfaces/Timer.js");
Engine.LoadComponentScript("interfaces/TurretHolder.js");
Engine.LoadComponentScript("interfaces/UnitAI.js");