Core/Misc: Added helper function Unit::SetFullPower * Also renamed Unit::getPowerType and Unit::setPowerType to follow style guidelines
This commit is contained in:
@@ -516,7 +516,7 @@ namespace Game.Entities
|
||||
|
||||
if (HasFlag(UnitFields.Flags2, UnitFlags2.RegeneratePower))
|
||||
{
|
||||
if (getPowerType() == PowerType.Energy)
|
||||
if (GetPowerType() == PowerType.Energy)
|
||||
Regenerate(PowerType.Energy);
|
||||
else
|
||||
RegenerateMana();
|
||||
@@ -1133,10 +1133,10 @@ namespace Game.Entities
|
||||
switch (GetClass())
|
||||
{
|
||||
case Class.Warrior:
|
||||
setPowerType(PowerType.Rage);
|
||||
SetPowerType(PowerType.Rage);
|
||||
break;
|
||||
case Class.Rogue:
|
||||
setPowerType(PowerType.Energy);
|
||||
SetPowerType(PowerType.Energy);
|
||||
break;
|
||||
default:
|
||||
SetMaxPower(PowerType.Mana, (int)mana);
|
||||
@@ -1409,7 +1409,7 @@ namespace Game.Entities
|
||||
else
|
||||
{
|
||||
curhealth = GetMaxHealth();
|
||||
SetPower(PowerType.Mana, GetMaxPower(PowerType.Mana));
|
||||
SetFullPower(PowerType.Mana);
|
||||
}
|
||||
|
||||
SetHealth((m_deathState == DeathState.Alive || m_deathState == DeathState.JustRespawned) ? curhealth : 0);
|
||||
|
||||
@@ -218,7 +218,7 @@ namespace Game.Entities
|
||||
SetByteFlag(UnitFields.Bytes2, UnitBytes2Offsets.PetFlags, (result.Read<bool>(9) ? UnitPetFlags.CanBeAbandoned : UnitPetFlags.CanBeRenamed | UnitPetFlags.CanBeAbandoned));
|
||||
|
||||
SetUInt32Value(UnitFields.Flags, (uint)UnitFlags.PvpAttackable); // this enables popup window (pet abandon, cancel)
|
||||
setPowerType(PowerType.Focus);
|
||||
SetPowerType(PowerType.Focus);
|
||||
break;
|
||||
default:
|
||||
if (!IsPetGhoul())
|
||||
@@ -247,7 +247,7 @@ namespace Game.Entities
|
||||
SetCanModifyStats(true);
|
||||
|
||||
if (getPetType() == PetType.Summon && !current) //all (?) summon pets come with full health when called, but not when they are current
|
||||
SetPower(PowerType.Mana, GetMaxPower(PowerType.Mana));
|
||||
SetFullPower(PowerType.Mana);
|
||||
else
|
||||
{
|
||||
uint savedhealth = result.Read<uint>(10);
|
||||
@@ -256,8 +256,8 @@ namespace Game.Entities
|
||||
setDeathState(DeathState.JustDied);
|
||||
else
|
||||
{
|
||||
SetHealth(savedhealth > GetMaxHealth() ? GetMaxHealth() : savedhealth);
|
||||
SetPower(PowerType.Mana, savedmana > GetMaxPower(PowerType.Mana) ? GetMaxPower(PowerType.Mana) : (int)savedmana);
|
||||
SetHealth(savedhealth);
|
||||
SetPower(PowerType.Mana, (int)savedmana);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -579,7 +579,7 @@ namespace Game.Entities
|
||||
m_focusRegenTimer -= diff;
|
||||
else
|
||||
{
|
||||
switch (getPowerType())
|
||||
switch (GetPowerType())
|
||||
{
|
||||
case PowerType.Focus:
|
||||
Regenerate(PowerType.Focus);
|
||||
@@ -714,7 +714,7 @@ namespace Game.Entities
|
||||
if (!Create(map.GenerateLowGuid(HighGuid.Pet), map, cinfo.Entry))
|
||||
return false;
|
||||
|
||||
setPowerType(PowerType.Focus);
|
||||
SetPowerType(PowerType.Focus);
|
||||
SetUInt32Value(UnitFields.PetNameTimestamp, 0);
|
||||
SetUInt32Value(UnitFields.PetExperience, 0);
|
||||
SetUInt32Value(UnitFields.PetNextLevelExp, (uint)(Global.ObjectMgr.GetXPForLevel(getLevel() + 1) * PetXPFactor));
|
||||
|
||||
@@ -357,7 +357,7 @@ namespace Game.Entities
|
||||
SendActionButtons(1);
|
||||
|
||||
UpdateDisplayPower();
|
||||
PowerType pw = getPowerType();
|
||||
PowerType pw = GetPowerType();
|
||||
if (pw != PowerType.Mana)
|
||||
SetPower(PowerType.Mana, 0); // Mana must be 0 even if it isn't the active power type.
|
||||
|
||||
|
||||
@@ -345,8 +345,8 @@ namespace Game.Entities
|
||||
// apply original stats mods before spell loading or item equipment that call before equip _RemoveStatsMods()
|
||||
UpdateMaxHealth(); // Update max Health (for add bonus from stamina)
|
||||
SetFullHealth();
|
||||
if (getPowerType() == PowerType.Mana)
|
||||
SetPower(PowerType.Mana, GetMaxPower(PowerType.Mana));
|
||||
if (GetPowerType() == PowerType.Mana)
|
||||
SetFullPower(PowerType.Mana);
|
||||
|
||||
// original spells
|
||||
LearnDefaultSkills();
|
||||
@@ -3573,19 +3573,12 @@ namespace Game.Entities
|
||||
{
|
||||
ResurrectPlayer(0.0f, false);
|
||||
|
||||
if (GetMaxHealth() > _resurrectionData.Health)
|
||||
SetHealth(_resurrectionData.Health);
|
||||
else
|
||||
SetFullHealth();
|
||||
|
||||
if (GetMaxPower(PowerType.Mana) > _resurrectionData.Mana)
|
||||
SetPower(PowerType.Mana, (int)_resurrectionData.Mana);
|
||||
else
|
||||
SetPower(PowerType.Mana, GetMaxPower(PowerType.Mana));
|
||||
SetHealth(_resurrectionData.Health);
|
||||
SetPower(PowerType.Mana, (int)_resurrectionData.Mana);
|
||||
|
||||
SetPower(PowerType.Rage, 0);
|
||||
SetPower(PowerType.Energy, GetMaxPower(PowerType.Energy));
|
||||
SetPower(PowerType.Focus, GetMaxPower(PowerType.Focus));
|
||||
SetFullPower(PowerType.Energy);
|
||||
SetFullPower(PowerType.Focus);
|
||||
SetPower(PowerType.LunarPower, 0);
|
||||
|
||||
uint aura = _resurrectionData.Aura;
|
||||
@@ -3921,17 +3914,17 @@ namespace Game.Entities
|
||||
}
|
||||
public void ResetAllPowers()
|
||||
{
|
||||
SetHealth(GetMaxHealth());
|
||||
switch (getPowerType())
|
||||
SetFullHealth();
|
||||
switch (GetPowerType())
|
||||
{
|
||||
case PowerType.Mana:
|
||||
SetPower(PowerType.Mana, GetMaxPower(PowerType.Mana));
|
||||
SetFullPower(PowerType.Mana);
|
||||
break;
|
||||
case PowerType.Rage:
|
||||
SetPower(PowerType.Rage, 0);
|
||||
break;
|
||||
case PowerType.Energy:
|
||||
SetPower(PowerType.Energy, GetMaxPower(PowerType.Energy));
|
||||
SetFullPower(PowerType.Energy);
|
||||
break;
|
||||
case PowerType.RunicPower:
|
||||
SetPower(PowerType.RunicPower, 0);
|
||||
@@ -4484,7 +4477,7 @@ namespace Game.Entities
|
||||
// set health/powers (0- will be set in caller)
|
||||
if (restore_percent > 0.0f)
|
||||
{
|
||||
SetHealth((uint)(GetMaxHealth() * restore_percent));
|
||||
SetHealth((ulong)(GetMaxHealth() * restore_percent));
|
||||
SetPower(PowerType.Mana, (int)(GetMaxPower(PowerType.Mana) * restore_percent));
|
||||
SetPower(PowerType.Rage, 0);
|
||||
SetPower(PowerType.Energy, (int)(GetMaxPower(PowerType.Energy) * restore_percent));
|
||||
@@ -4842,7 +4835,7 @@ namespace Game.Entities
|
||||
pet.SetCreatorGUID(GetGUID());
|
||||
pet.SetUInt32Value(UnitFields.FactionTemplate, getFaction());
|
||||
|
||||
pet.setPowerType(PowerType.Mana);
|
||||
pet.SetPowerType(PowerType.Mana);
|
||||
pet.SetUInt64Value(UnitFields.NpcFlags, (uint)NPCFlags.None);
|
||||
pet.SetUInt32Value(UnitFields.Bytes1, 0);
|
||||
pet.InitStatsForLevel(getLevel());
|
||||
@@ -4858,7 +4851,7 @@ namespace Game.Entities
|
||||
pet.SetUInt32Value(UnitFields.PetExperience, 0);
|
||||
pet.SetUInt32Value(UnitFields.PetNextLevelExp, 1000);
|
||||
pet.SetFullHealth();
|
||||
pet.SetPower(PowerType.Mana, pet.GetMaxPower(PowerType.Mana));
|
||||
pet.SetFullPower(PowerType.Mana);
|
||||
pet.SetUInt32Value(UnitFields.PetNameTimestamp, (uint)Time.UnixTime); // cast can't be helped in this case
|
||||
break;
|
||||
default:
|
||||
@@ -5332,10 +5325,10 @@ namespace Game.Entities
|
||||
|
||||
// set current level health and mana/energy to maximum after applying all mods.
|
||||
SetFullHealth();
|
||||
SetPower(PowerType.Mana, GetMaxPower(PowerType.Mana));
|
||||
SetPower(PowerType.Energy, GetMaxPower(PowerType.Energy));
|
||||
SetFullPower(PowerType.Mana);
|
||||
SetFullPower(PowerType.Energy);
|
||||
if (GetPower(PowerType.Rage) > GetMaxPower(PowerType.Rage))
|
||||
SetPower(PowerType.Rage, GetMaxPower(PowerType.Rage));
|
||||
SetFullPower(PowerType.Rage);
|
||||
SetPower(PowerType.Focus, 0);
|
||||
|
||||
// update level to hunter/summon pet
|
||||
@@ -5914,11 +5907,11 @@ namespace Game.Entities
|
||||
|
||||
// set current level health and mana/energy to maximum after applying all mods.
|
||||
SetFullHealth();
|
||||
SetPower(PowerType.Mana, GetMaxPower(PowerType.Mana));
|
||||
SetPower(PowerType.Energy, GetMaxPower(PowerType.Energy));
|
||||
SetFullPower(PowerType.Mana);
|
||||
SetFullPower(PowerType.Energy);
|
||||
if (GetPower(PowerType.Rage) > GetMaxPower(PowerType.Rage))
|
||||
SetPower(PowerType.Rage, GetMaxPower(PowerType.Rage));
|
||||
SetPower(PowerType.Focus, GetMaxPower(PowerType.Focus));
|
||||
SetFullPower(PowerType.Rage);
|
||||
SetFullPower(PowerType.Focus);
|
||||
SetPower(PowerType.RunicPower, 0);
|
||||
|
||||
// update level to hunter/summon pet
|
||||
|
||||
@@ -79,9 +79,9 @@ namespace Game.Entities
|
||||
case UnitMods.Runes:
|
||||
case UnitMods.RunicPower:
|
||||
case UnitMods.SoulShards:
|
||||
case UnitMods.Eclipse:
|
||||
case UnitMods.LunarPower:
|
||||
case UnitMods.HolyPower:
|
||||
case UnitMods.Alternative:
|
||||
case UnitMods.Alternate:
|
||||
case UnitMods.Maelstrom:
|
||||
case UnitMods.Chi:
|
||||
case UnitMods.Insanity:
|
||||
@@ -413,16 +413,16 @@ namespace Game.Entities
|
||||
public virtual float GetArmorMultiplierForTarget(WorldObject target) { return 1.0f; }
|
||||
|
||||
//Powers
|
||||
public PowerType getPowerType()
|
||||
public PowerType GetPowerType()
|
||||
{
|
||||
return (PowerType)GetUInt32Value(UnitFields.DisplayPower);
|
||||
}
|
||||
public void setPowerType(PowerType newPowerType)
|
||||
public void SetPowerType(PowerType powerType)
|
||||
{
|
||||
if (getPowerType() == newPowerType)
|
||||
if (GetPowerType() == powerType)
|
||||
return;
|
||||
|
||||
SetUInt32Value(UnitFields.DisplayPower, (uint)newPowerType);
|
||||
SetUInt32Value(UnitFields.DisplayPower, (uint)powerType);
|
||||
|
||||
if (IsTypeId(TypeId.Player))
|
||||
{
|
||||
@@ -444,7 +444,7 @@ namespace Game.Entities
|
||||
powerMultiplier = creature.GetCreatureTemplate().ModMana;
|
||||
}
|
||||
|
||||
switch (newPowerType)
|
||||
switch (powerType)
|
||||
{
|
||||
default:
|
||||
case PowerType.Mana:
|
||||
@@ -462,13 +462,13 @@ namespace Game.Entities
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void SetMaxPower(PowerType power, int val)
|
||||
public void SetMaxPower(PowerType powerType, int val)
|
||||
{
|
||||
uint powerIndex = GetPowerIndex(power);
|
||||
uint powerIndex = GetPowerIndex(powerType);
|
||||
if (powerIndex == (int)PowerType.Max || powerIndex >= (int)PowerType.MaxPerClass)
|
||||
return;
|
||||
|
||||
int cur_power = GetPower(power);
|
||||
int cur_power = GetPower(powerType);
|
||||
SetInt32Value(UnitFields.MaxPower + (int)powerIndex, val);
|
||||
|
||||
// group update
|
||||
@@ -485,7 +485,7 @@ namespace Game.Entities
|
||||
}*/
|
||||
|
||||
if (val < cur_power)
|
||||
SetPower(power, val);
|
||||
SetPower(powerType, val);
|
||||
}
|
||||
public void SetPower(PowerType powerType, int val)
|
||||
{
|
||||
@@ -521,30 +521,31 @@ namespace Game.Entities
|
||||
pet.SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER);
|
||||
}*/
|
||||
}
|
||||
public int GetPower(PowerType power)
|
||||
public void SetFullPower(PowerType powerType) { SetPower(powerType, GetMaxPower(powerType)); }
|
||||
public int GetPower(PowerType powerType)
|
||||
{
|
||||
uint powerIndex = GetPowerIndex(power);
|
||||
uint powerIndex = GetPowerIndex(powerType);
|
||||
if (powerIndex == (int)PowerType.Max || powerIndex >= (int)PowerType.MaxPerClass)
|
||||
return 0;
|
||||
|
||||
return GetInt32Value(UnitFields.Power + (int)powerIndex);
|
||||
}
|
||||
public int GetMaxPower(PowerType power)
|
||||
public int GetMaxPower(PowerType powerType)
|
||||
{
|
||||
uint powerIndex = GetPowerIndex(power);
|
||||
uint powerIndex = GetPowerIndex(powerType);
|
||||
if (powerIndex == (int)PowerType.Max || powerIndex >= (int)PowerType.MaxPerClass)
|
||||
return 0;
|
||||
|
||||
return GetInt32Value(UnitFields.MaxPower + (int)powerIndex);
|
||||
}
|
||||
public int GetCreatePowers(PowerType power)
|
||||
public int GetCreatePowers(PowerType powerType)
|
||||
{
|
||||
if (power == PowerType.Mana)
|
||||
if (powerType == PowerType.Mana)
|
||||
return (int)GetCreateMana();
|
||||
|
||||
PowerTypeRecord powerType = Global.DB2Mgr.GetPowerTypeEntry(power);
|
||||
if (powerType != null)
|
||||
return powerType.MaxPower;
|
||||
PowerTypeRecord powerTypeEntry = Global.DB2Mgr.GetPowerTypeEntry(powerType);
|
||||
if (powerTypeEntry != null)
|
||||
return powerTypeEntry.MaxPower;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -560,6 +561,7 @@ namespace Game.Entities
|
||||
|
||||
return Global.DB2Mgr.GetPowerIndexByClass(powerType, _class);
|
||||
}
|
||||
public float GetPowerPct(PowerType powerType) { return GetMaxPower(powerType) != 0 ? 100.0f* GetPower(powerType) / GetMaxPower(powerType) : 0.0f; }
|
||||
|
||||
public void ApplyResilience(Unit victim, ref uint damage)
|
||||
{
|
||||
|
||||
@@ -629,7 +629,7 @@ namespace Game.Entities
|
||||
UpdateAllStats();
|
||||
|
||||
SetFullHealth();
|
||||
SetPower(PowerType.Mana, GetMaxPower(PowerType.Mana));
|
||||
SetFullPower(PowerType.Mana);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ namespace Game.Entities
|
||||
{
|
||||
Unit a = objA.ToUnit();
|
||||
Unit b = objB.ToUnit();
|
||||
float rA = a.GetMaxPower(m_power) != 0 ? a.GetPower(m_power) / (float)a.GetMaxPower(m_power) : 0.0f;
|
||||
float rB = b.GetMaxPower(m_power) != 0 ? b.GetPower(m_power) / (float)b.GetMaxPower(m_power) : 0.0f;
|
||||
float rA = a != null ? a.GetPowerPct(m_power) : 0.0f;
|
||||
float rB = b != null ? b.GetPowerPct(m_power) : 0.0f;
|
||||
return Convert.ToInt32(m_ascending ? rA < rB : rA > rB);
|
||||
}
|
||||
|
||||
|
||||
@@ -944,7 +944,7 @@ namespace Game.Entities
|
||||
}
|
||||
|
||||
// Rage from Damage made (only from direct weapon damage)
|
||||
if (cleanDamage != null && (cleanDamage.attackType == WeaponAttackType.BaseAttack || cleanDamage.attackType == WeaponAttackType.OffAttack) && damagetype == DamageEffectType.Direct && this != victim && getPowerType() == PowerType.Rage)
|
||||
if (cleanDamage != null && (cleanDamage.attackType == WeaponAttackType.BaseAttack || cleanDamage.attackType == WeaponAttackType.OffAttack) && damagetype == DamageEffectType.Direct && this != victim && GetPowerType() == PowerType.Rage)
|
||||
{
|
||||
uint rage = (uint)(GetBaseAttackTime(cleanDamage.attackType) / 1000.0f * 1.75f);
|
||||
if (cleanDamage.attackType == WeaponAttackType.OffAttack)
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace Game.Entities
|
||||
|
||||
// Ghoul pets have energy instead of mana (is anywhere better place for this code?)
|
||||
if (minion.IsPetGhoul())
|
||||
minion.setPowerType(PowerType.Energy);
|
||||
minion.SetPowerType(PowerType.Energy);
|
||||
|
||||
// Send infinity cooldown - client does that automatically but after relog cooldown needs to be set again
|
||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(minion.GetUInt32Value(UnitFields.CreatedBySpell));
|
||||
|
||||
@@ -1651,7 +1651,7 @@ namespace Game.Entities
|
||||
// without this when removing IncreaseMaxHealth aura player may stuck with 1 hp
|
||||
// do not why since in IncreaseMaxHealth currenthealth is checked
|
||||
SetHealth(0);
|
||||
SetPower(getPowerType(), 0);
|
||||
SetPower(GetPowerType(), 0);
|
||||
SetUInt32Value(UnitFields.NpcEmotestate, 0);
|
||||
|
||||
// players in instance don't have ZoneScript, but they have InstanceScript
|
||||
@@ -1969,7 +1969,7 @@ namespace Game.Entities
|
||||
}
|
||||
}
|
||||
|
||||
setPowerType(displayPower);
|
||||
SetPowerType(displayPower);
|
||||
}
|
||||
|
||||
public FactionTemplateRecord GetFactionTemplateEntry()
|
||||
|
||||
@@ -75,9 +75,9 @@ namespace Game.Entities
|
||||
{
|
||||
PowerDisplayRecord powerDisplay = CliDB.PowerDisplayStorage.LookupByKey(_vehicleInfo.PowerDisplayID[0]);
|
||||
if (powerDisplay != null)
|
||||
_me.setPowerType((PowerType)powerDisplay.PowerType);
|
||||
_me.SetPowerType((PowerType)powerDisplay.PowerType);
|
||||
else if (_me.GetClass() == Class.Rogue)
|
||||
_me.setPowerType(PowerType.Energy);
|
||||
_me.SetPowerType(PowerType.Energy);
|
||||
}
|
||||
|
||||
_status = Status.Installed;
|
||||
|
||||
Reference in New Issue
Block a user