diff --git a/binaries/data/mods/public/simulation/components/Promotion.js b/binaries/data/mods/public/simulation/components/Promotion.js index cb0cada0c6..252c7196d7 100644 --- a/binaries/data/mods/public/simulation/components/Promotion.js +++ b/binaries/data/mods/public/simulation/components/Promotion.js @@ -15,7 +15,13 @@ Promotion.prototype.Init = function() Promotion.prototype.GetRequiredXp = function() { - return +(this.template.RequiredXp); + var requiredXp = +this.template.RequiredXp; + + var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager); + if (cmpTechMan) + requiredXp = cmpTechMan.ApplyModifications("Promotion/RequiredXp", requiredXp, this.entity); + + return requiredXp; }; Promotion.prototype.GetCurrentXp = function() @@ -89,18 +95,28 @@ Promotion.prototype.IncreaseXp = function(amount) { this.currentXp += +(amount); - if (this.currentXp >= this.template.RequiredXp) - { + if (this.currentXp >= this.GetRequiredXp()) + { + var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager); + var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); var promotionTemplate = this.template; + var promotedTemplateName; + var requiredXp; + + // We may be able to promote by skipping over multiple templates + // so find the highest level we can reach do { - this.currentXp -= promotionTemplate.RequiredXp; - var promotedTemplateName = promotionTemplate.Entity; - var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); + requiredXp = +promotionTemplate.RequiredXp; + if (cmpTechMan) + requiredXp = cmpTechMan.ApplyModifications("Promotion/RequiredXp", requiredXp, this.entity); + this.currentXp -= requiredXp; + promotedTemplateName = promotionTemplate.Entity; var template = cmpTemplateManager.GetTemplate(promotedTemplateName); - promotionTemplate = template.Promotion || null; + promotionTemplate = template.Promotion; } - while (promotionTemplate != null && this.currentXp >= promotionTemplate.RequiredXp); + while (promotionTemplate && this.currentXp >= requiredXp); + this.Promote(promotedTemplateName); } } diff --git a/binaries/data/mods/public/simulation/components/TerritoryDecay.js b/binaries/data/mods/public/simulation/components/TerritoryDecay.js index 14616f6c5f..63217adc99 100644 --- a/binaries/data/mods/public/simulation/components/TerritoryDecay.js +++ b/binaries/data/mods/public/simulation/components/TerritoryDecay.js @@ -72,7 +72,12 @@ TerritoryDecay.prototype.Decay = function() if (!cmpHealth) return; // error - cmpHealth.Reduce(+this.template.HealthDecayRate); + var decayRate = +this.template.HealthDecayRate; + var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager); + if (cmpTechMan) + decayRate = cmpTechMan.ApplyModifications("TerritoryDecay/HealthDecayRate", decayRate, this.entity); + + cmpHealth.Reduce(Math.round(decayRate)); }; Engine.RegisterComponentType(IID_TerritoryDecay, "TerritoryDecay", TerritoryDecay);