Fix duplicating promoting entities in XP trickling structures.

The entity received a value modif. message while promoting, triggering a
second promotion.

Differential revision: https://code.wildfiregames.com/D3918
Fixes: #6162
Comments by: @Angen, @Stan
This was SVN commit r25439.
This commit is contained in:
Freagarach 2021-05-15 05:40:13 +00:00
parent 66c75068bc
commit 6b0802836a
3 changed files with 16 additions and 6 deletions

View File

@ -36,7 +36,6 @@ Promotion.prototype.GetPromotedTemplateName = function()
Promotion.prototype.Promote = function(promotedTemplateName)
{
// If the unit is dead, don't promote it
let cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
if (cmpHealth && cmpHealth.GetHitpoints() == 0)
{
@ -44,8 +43,15 @@ Promotion.prototype.Promote = function(promotedTemplateName)
return;
}
// Save the entity id.
this.promotedUnitEntity = ChangeEntityTemplate(this.entity, promotedTemplateName);
ChangeEntityTemplate(this.entity, promotedTemplateName);
};
/**
* @param {number} entity - The entity ID of the entity that this unit has promoted to.
*/
Promotion.prototype.SetPromotedEntity = function(entity)
{
this.promotedUnitEntity = entity;
};
Promotion.prototype.IncreaseXp = function(amount)

View File

@ -41,12 +41,13 @@ AddMock(SYSTEM_ENTITY, IID_TemplateManager, {
let ChangeEntityTemplate = function(ent, template)
{
let newEnt = ent + 1;
let exp = cmpPromotion.GetCurrentXp();
cmpPromotion = ConstructComponent(newEnt, "Promotion", {
let cmpNewPromotion = ConstructComponent(newEnt, "Promotion", {
"Entity": entTemplates[newEnt],
"RequiredXp": 1000
});
cmpPromotion.IncreaseXp(exp);
cmpPromotion.SetPromotedEntity(newEnt);
cmpNewPromotion.IncreaseXp(cmpPromotion.GetCurrentXp());
cmpPromotion = cmpNewPromotion;
return newEnt;
};
Engine.RegisterGlobal("ChangeEntityTemplate", ChangeEntityTemplate);

View File

@ -77,7 +77,10 @@ function ChangeEntityTemplate(oldEnt, newTemplate)
let cmpPromotion = Engine.QueryInterface(oldEnt, IID_Promotion);
let cmpNewPromotion = Engine.QueryInterface(newEnt, IID_Promotion);
if (cmpPromotion && cmpNewPromotion)
{
cmpPromotion.SetPromotedEntity(newEnt);
cmpNewPromotion.IncreaseXp(cmpPromotion.GetCurrentXp());
}
let cmpResGatherer = Engine.QueryInterface(oldEnt, IID_ResourceGatherer);
let cmpNewResGatherer = Engine.QueryInterface(newEnt, IID_ResourceGatherer);