public void AgeUp(short years)
{
if (years < 0 || this.Age + years > short.MaxValue)
return;
float life = 0, mana = 0, stamina = 0, str = 0, dex = 0, int_ = 0, will = 0, luck = 0;
var ap = 0;
var oldAge = this.Age;
var newAge = this.Age + years;
while (this.Age < newAge)
{
// Increase age before requestin statUp, we want the stats
// for the next age.
this.Age++;
var statUp = AuraData.StatsAgeUpDb.Find(this.RaceId, this.Age);
if (statUp == null)
{
if ((statUp = AuraData.StatsAgeUpDb.Find(10000, 17)) == null)
{
Log.Error("Creature.AgeUp: No valid age up stats found for race {0}, age {1}.", this.RaceId, this.Age);
}
else
{
// Only warn when creature was a player, we'll let NPCs fall
// back to Human 17 silently.
if (this.IsPlayer)
Log.Warning("Creature.AgeUp: Age up stats missing for race {0}, age {1}. Falling back to Human 17.", this.RaceId, this.Age);
}
}
// Collect bonuses for multi aging
life += statUp.Life;
mana += statUp.Mana;
stamina += statUp.Stamina;
str += statUp.Str;
dex += statUp.Dex;
int_ += statUp.Int;
will += statUp.Will;
luck += statUp.Luck;
ap += statUp.AP;
}
// Apply stat bonuses
this.LifeMaxBase += life;
this.Life += life;
this.ManaMaxBase += mana;
this.Mana += mana;
this.StaminaMaxBase += stamina;
this.Stamina += stamina;
this.StrBase += str;
this.DexBase += dex;
this.IntBase += int_;
this.WillBase += will;
this.LuckBase += luck;
this.AbilityPoints += (short)Math2.Clamp(0, short.MaxValue, ap * ChannelServer.Instance.Conf.World.AgeApRate);
this.LastAging = DateTime.Now;
if (this is Character)
this.Height = Math.Min(1.0f, 1.0f / 7.0f * (this.Age - 10.0f)); // 0 ~ 1.0
// Send stat bonuses
if (life != 0) Send.SimpleAcquireInfo(this, "life", mana);
if (mana != 0) Send.SimpleAcquireInfo(this, "mana", mana);
if (stamina != 0) Send.SimpleAcquireInfo(this, "stamina", stamina);
if (str != 0) Send.SimpleAcquireInfo(this, "str", str);
if (dex != 0) Send.SimpleAcquireInfo(this, "dex", dex);
if (int_ != 0) Send.SimpleAcquireInfo(this, "int", int_);
if (will != 0) Send.SimpleAcquireInfo(this, "will", will);
if (luck != 0) Send.SimpleAcquireInfo(this, "luck", luck);
if (ap != 0) Send.SimpleAcquireInfo(this, "ap", ap);
Send.StatUpdateDefault(this);
// XXX: Replace with effect and notice to allow something to happen past age 25?
Send.AgeUpEffect(this, this.Age);
ChannelServer.Instance.Events.OnCreatureAged(this, oldAge);
}