Change promoted unit health to the same percent of hitpoints as unit had before promotion. Closes #922.
This was SVN commit r9984.
This commit is contained in:
parent
c513b5e35e
commit
0adcad8662
@ -51,6 +51,13 @@ Promotion.prototype.Promote = function(promotedTemplateName)
|
||||
var cmpPromotedUnitOwnership = Engine.QueryInterface(promotedUnitEntity, IID_Ownership);
|
||||
cmpPromotedUnitOwnership.SetOwner(cmpCurrentUnitOwnership.GetOwner());
|
||||
|
||||
// change promoted unit health to the same percent of hitpoints as unit had before promotion
|
||||
var cmpCurrentUnitHealth = Engine.QueryInterface(this.entity, IID_Health);
|
||||
var cmpPromotedUnitHealth = Engine.QueryInterface(promotedUnitEntity, IID_Health);
|
||||
var healthFraction = Math.max(0, Math.min(1, cmpCurrentUnitHealth.GetHitpoints() / cmpCurrentUnitHealth.GetMaxHitpoints()));
|
||||
var promotedUnitHitpoints = Math.round(cmpPromotedUnitHealth.GetMaxHitpoints() * healthFraction);
|
||||
cmpPromotedUnitHealth.SetHitpoints(promotedUnitHitpoints);
|
||||
|
||||
var cmpPromotedUnitPromotion = Engine.QueryInterface(promotedUnitEntity, IID_Promotion);
|
||||
if (cmpPromotedUnitPromotion)
|
||||
cmpPromotedUnitPromotion.IncreaseXp(this.currentXp);
|
||||
|
Loading…
Reference in New Issue
Block a user