mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 04:37:00 +00:00
Lots of cmangos commirs applied
This commit is contained in:
parent
8431568536
commit
18dd18780d
44 changed files with 677 additions and 323 deletions
|
|
@ -411,7 +411,14 @@ bool Creature::UpdateEntry(uint32 Entry, Team team, const CreatureData* data /*=
|
|||
// creatures always have melee weapon ready if any
|
||||
SetSheath(SHEATH_STATE_MELEE);
|
||||
|
||||
SelectLevel(GetCreatureInfo(), preserveHPAndPower ? GetHealthPercent() : 100.0f);
|
||||
if (preserveHPAndPower)
|
||||
{
|
||||
uint32 healthPercent = GetHealthPercent();
|
||||
SelectLevel();
|
||||
SetHealthPercent(healthPercent);
|
||||
}
|
||||
else
|
||||
SelectLevel();
|
||||
|
||||
if (team == HORDE)
|
||||
setFaction(GetCreatureInfo()->FactionHorde);
|
||||
|
|
@ -830,6 +837,9 @@ bool Creature::AIM_Initialize()
|
|||
i_motionMaster.Initialize();
|
||||
i_AI = FactorySelector::selectAI(this);
|
||||
delete oldAI;
|
||||
|
||||
// Handle Spawned Events, also calls Reset()
|
||||
i_AI->JustRespawned();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1241,6 +1251,126 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
|
|||
WorldDatabase.CommitTransaction();
|
||||
}
|
||||
|
||||
void Creature::SelectLevel(uint32 forcedLevel /*= USE_DEFAULT_DATABASE_LEVEL*/)
|
||||
{
|
||||
CreatureInfo const* cinfo = GetCreatureInfo();
|
||||
if (!cinfo)
|
||||
return;
|
||||
|
||||
uint32 rank = IsPet() ? 0 : cinfo->Rank; // TODO :: IsPet probably not needed here
|
||||
|
||||
// level
|
||||
uint32 level = forcedLevel;
|
||||
uint32 const minlevel = cinfo->MinLevel;
|
||||
uint32 const maxlevel = cinfo->MaxLevel;
|
||||
|
||||
if (level == USE_DEFAULT_DATABASE_LEVEL)
|
||||
level = minlevel == maxlevel ? minlevel : urand(minlevel, maxlevel);
|
||||
|
||||
SetLevel(level);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Calculate level dependent stats
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint32 health;
|
||||
uint32 mana;
|
||||
|
||||
if (CreatureClassLvlStats const* cCLS = sObjectMgr.GetCreatureClassLvlStats(level, cinfo->UnitClass, cinfo->Expansion))
|
||||
{
|
||||
// Use Creature Stats to calculate stat values
|
||||
|
||||
// health
|
||||
health = cCLS->BaseHealth * cinfo->HealthMultiplier;
|
||||
|
||||
// mana
|
||||
mana = cCLS->BaseMana * cinfo->PowerMultiplier;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (forcedLevel == USE_DEFAULT_DATABASE_LEVEL || (forcedLevel >= minlevel && forcedLevel <= maxlevel))
|
||||
{
|
||||
// Use old style to calculate stat values
|
||||
float rellevel = maxlevel == minlevel ? 0 : (float(level - minlevel)) / (maxlevel - minlevel);
|
||||
|
||||
// health
|
||||
uint32 minhealth = std::min(cinfo->MaxLevelHealth, cinfo->MinLevelHealth);
|
||||
uint32 maxhealth = std::max(cinfo->MaxLevelHealth, cinfo->MinLevelHealth);
|
||||
health = uint32(minhealth + uint32(rellevel * (maxhealth - minhealth)));
|
||||
|
||||
// mana
|
||||
uint32 minmana = std::min(cinfo->MaxLevelMana, cinfo->MinLevelMana);
|
||||
uint32 maxmana = std::max(cinfo->MaxLevelMana, cinfo->MinLevelMana);
|
||||
mana = minmana + uint32(rellevel * (maxmana - minmana));
|
||||
}
|
||||
else
|
||||
{
|
||||
sLog.outError("Creature::SelectLevel> Error trying to set level(%u) for creature %s without enough data to do it!", level, GetGuidStr().c_str());
|
||||
// probably wrong
|
||||
health = (cinfo->MaxLevelHealth / cinfo->MaxLevel) * level;
|
||||
mana = (cinfo->MaxLevelMana / cinfo->MaxLevel) * level;
|
||||
}
|
||||
}
|
||||
|
||||
health *= _GetHealthMod(rank); // Apply custom config settting
|
||||
if (health < 1)
|
||||
health = 1;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Set values
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// health
|
||||
SetCreateHealth(health);
|
||||
SetMaxHealth(health);
|
||||
SetHealth(health);
|
||||
|
||||
SetModifierValue(UNIT_MOD_HEALTH, BASE_VALUE, float(health));
|
||||
|
||||
// all power types
|
||||
for (int i = POWER_MANA; i <= POWER_RUNIC_POWER; ++i)
|
||||
{
|
||||
uint32 maxValue = 0;
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case POWER_MANA: maxValue = mana; break;
|
||||
case POWER_RAGE: maxValue = 0; break;
|
||||
case POWER_FOCUS: maxValue = POWER_FOCUS_DEFAULT; break;
|
||||
case POWER_ENERGY: maxValue = POWER_ENERGY_DEFAULT * cinfo->PowerMultiplier; break;
|
||||
case POWER_RUNE: maxValue = 0; break;
|
||||
case POWER_RUNIC_POWER: maxValue = 0; break;
|
||||
}
|
||||
|
||||
uint32 value = maxValue;
|
||||
|
||||
// For non regenerating powers set 0
|
||||
if ((i == POWER_ENERGY || i == POWER_MANA) && !IsRegeneratingPower())
|
||||
value = 0;
|
||||
|
||||
// Mana requires an extra field to be set
|
||||
if (i == POWER_MANA)
|
||||
SetCreateMana(value);
|
||||
|
||||
SetMaxPower(Powers(i), maxValue);
|
||||
SetPower(Powers(i), value);
|
||||
SetModifierValue(UnitMods(UNIT_MOD_POWER_START + i), BASE_VALUE, float(value));
|
||||
}
|
||||
|
||||
// damage
|
||||
float damagemod = _GetDamageMod(rank);
|
||||
|
||||
SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, cinfo->MinMeleeDmg * damagemod);
|
||||
SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, cinfo->MaxMeleeDmg * damagemod);
|
||||
|
||||
SetBaseWeaponDamage(OFF_ATTACK, MINDAMAGE, cinfo->MinMeleeDmg * damagemod);
|
||||
SetBaseWeaponDamage(OFF_ATTACK, MAXDAMAGE, cinfo->MaxMeleeDmg * damagemod);
|
||||
|
||||
SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE, cinfo->MinRangedDmg * damagemod);
|
||||
SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE, cinfo->MaxRangedDmg * damagemod);
|
||||
|
||||
SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, cinfo->MeleeAttackPower * damagemod);
|
||||
}
|
||||
|
||||
void Creature::SelectLevel(const CreatureInfo* cinfo, float percentHealth /*= 100.0f*/)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue