void Pet::UpdateArmor() { float value = 0.0f; float bonus_armor = 0.0f; UnitMods unitMod = UNIT_MOD_ARMOR; Unit *owner = GetOwner(); // chained, use original owner instead if (owner && owner->GetTypeId() == TYPEID_UNIT && ((Creature*)owner)->GetEntry() == GetEntry()) if (Unit *creator = GetCreator()) owner = creator; // hunter and warlock and shaman pets gain 35% of owner's armor value if (owner && (getPetType() == HUNTER_PET || (getPetType() == SUMMON_PET && (owner->getClass() == CLASS_WARLOCK || owner->getClass() == CLASS_SHAMAN)))) bonus_armor = 0.35f * float(owner->GetArmor()); value = GetModifierValue(unitMod, BASE_VALUE); value *= GetModifierValue(unitMod, BASE_PCT); value += GetStat(STAT_AGILITY); value += GetModifierValue(unitMod, TOTAL_VALUE) + bonus_armor; value *= GetModifierValue(unitMod, TOTAL_PCT); SetArmor(int32(value)); }
void Pet::UpdateAttackPowerAndDamage(bool ranged) { if(ranged) return; float val = 0.0f; float bonusAP = 0.0f; UnitMods unitMod = UNIT_MOD_ATTACK_POWER; if(GetEntry() == 416) // imp's attack power val = GetStat(STAT_STRENGTH) - 10.0f; else val = 2 * GetStat(STAT_STRENGTH) - 20.0f; Unit* owner = GetOwner(); if( owner && owner->GetTypeId()==TYPEID_PLAYER) { if(getPetType() == HUNTER_PET) //hunter pets benefit from owner's attack power { bonusAP = owner->GetTotalAttackPowerValue(RANGED_ATTACK) * 0.22f; SetBonusDamage( int32(owner->GetTotalAttackPowerValue(RANGED_ATTACK) * 0.1287f)); } //demons benefit from warlocks shadow or fire damage else if(getPetType() == SUMMON_PET && owner->getClass() == CLASS_WARLOCK) { int32 fire = int32(owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE)) - owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_FIRE); int32 shadow = int32(owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW)) - owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_SHADOW); int32 maximum = (fire > shadow) ? fire : shadow; if(maximum < 0) maximum = 0; SetBonusDamage( int32(maximum * 0.15f)); bonusAP = maximum * 0.57f; } //water elementals benefit from mage's frost damage else if(getPetType() == SUMMON_PET && owner->getClass() == CLASS_MAGE) { int32 frost = int32(owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FROST)) - owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_FROST); if(frost < 0) frost = 0; SetBonusDamage( int32(frost * 0.4f)); } } SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, val + bonusAP); //in BASE_VALUE of UNIT_MOD_ATTACK_POWER for creatures we store data of meleeattackpower field in DB float base_attPower = GetModifierValue(unitMod, BASE_VALUE) * GetModifierValue(unitMod, BASE_PCT); float attPowerMod = GetModifierValue(unitMod, TOTAL_VALUE); float attPowerMultiplier = GetModifierValue(unitMod, TOTAL_PCT) - 1.0f; //UNIT_FIELD_(RANGED)_ATTACK_POWER field SetInt32Value(UNIT_FIELD_ATTACK_POWER, (int32)base_attPower); //UNIT_FIELD_(RANGED)_ATTACK_POWER_MODS field SetInt32Value(UNIT_FIELD_ATTACK_POWER_MODS, (int32)attPowerMod); //UNIT_FIELD_(RANGED)_ATTACK_POWER_MULTIPLIER field SetFloatValue(UNIT_FIELD_ATTACK_POWER_MULTIPLIER, attPowerMultiplier); //automatically update weapon damage after attack power modification UpdateDamagePhysical(BASE_ATTACK); }
bool Pet::UpdateStats(Stats stat) { if (stat > STAT_SPIRIT) return false; // value = ((base_value * base_pct) + total_value) * total_pct float value = GetTotalStatValue(stat); Unit* owner = GetOwner(); // chained, use original owner instead if (owner && owner->GetTypeId() == TYPEID_UNIT && ((Creature*)owner)->GetEntry() == GetEntry()) { if (Unit* creator = GetCreator()) owner = creator; } if (stat == STAT_STAMINA) { if(owner && owner->GetTypeId() == TYPEID_PLAYER && owner->getClass() == CLASS_WARLOCK) value += float(owner->GetStat(stat)) * 0.75f; else if (owner) value += float(owner->GetStat(stat)) * 0.3f; } // warlock's and mage's pets gain 30% of owner's intellect else if (stat == STAT_INTELLECT && getPetType() == SUMMON_PET) { if (owner && (owner->getClass() == CLASS_WARLOCK || owner->getClass() == CLASS_MAGE)) value += float(owner->GetStat(stat)) * 0.3f; } // deathknight's ghoul gain 100% of owner's strength else if (stat == STAT_STRENGTH && getPetType() == SUMMON_PET) { if (owner && (owner->getClass() == CLASS_DEATH_KNIGHT)) { value += float(owner->GetStat(stat)) * 1.0f; } } SetStat(stat, int32(value)); switch (stat) { case STAT_STRENGTH: UpdateAttackPowerAndDamage(); break; case STAT_AGILITY: UpdateArmor(); break; case STAT_STAMINA: UpdateMaxHealth(); break; case STAT_INTELLECT: UpdateMaxPower(POWER_MANA); break; case STAT_SPIRIT: default: break; } return true; }
void Pet::UpdateDamagePhysical(WeaponAttackType attType) { if (attType > BASE_ATTACK) return; UnitMods unitMod = UNIT_MOD_DAMAGE_MAINHAND; float att_speed = float(GetAttackTime(BASE_ATTACK))/1000.0f; float base_value = GetModifierValue(unitMod, BASE_VALUE) + GetTotalAttackPowerValue(attType)/ 14.0f * att_speed; float base_pct = GetModifierValue(unitMod, BASE_PCT); float total_value = GetModifierValue(unitMod, TOTAL_VALUE); float total_pct = GetModifierValue(unitMod, TOTAL_PCT); float weapon_mindamage = GetWeaponDamageRange(BASE_ATTACK, MINDAMAGE); float weapon_maxdamage = GetWeaponDamageRange(BASE_ATTACK, MAXDAMAGE); // Pet's base damage changes depending on happiness if (getPetType() == HUNTER_PET && attType == BASE_ATTACK) { switch(GetHappinessState()) { case HAPPY: // 125% of normal damage total_pct *= 1.25f; break; case CONTENT: // 100% of normal damage, nothing to modify break; case UNHAPPY: // 75% of normal damage total_pct *= 0.75f; break; } } else if (getPetType() == SUMMON_PET) { Unit* owner = GetOwner(); if (owner && owner->getClass() == CLASS_PRIEST) total_value += 0.3f * owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW); } float mindamage = ((base_value + weapon_mindamage) * base_pct + total_value) * total_pct; float maxdamage = ((base_value + weapon_maxdamage) * base_pct + total_value) * total_pct; SetStatFloatValue(UNIT_FIELD_MINDAMAGE, mindamage); SetStatFloatValue(UNIT_FIELD_MAXDAMAGE, maxdamage); }
void Pet::UpdateResistances(uint32 school) { if(school > SPELL_SCHOOL_NORMAL) { float value = GetTotalAuraModValue(UnitMods(UNIT_MOD_RESISTANCE_START + school)); Unit *owner = GetOwner(); // hunter and warlock pets gain 40% of owner's resistance if(owner && (getPetType() == HUNTER_PET || (getPetType() == SUMMON_PET && owner->getClass() == CLASS_WARLOCK))) value += float(owner->GetResistance(SpellSchools(school))) * 0.4f; SetResistance(SpellSchools(school), int32(value)); } else UpdateArmor(); }
std::string CPetEntity::GetScriptName() { switch (getPetType()) { case PETTYPE_AVATAR: return "avatar"; break; case PETTYPE_WYVERN: return "wyvern"; break; case PETTYPE_JUG_PET: return "jug"; break; case PETTYPE_CHARMED_MOB: return "charmed"; break; case PETTYPE_AUTOMATON: return "automaton"; break; case PETTYPE_ADVENTURING_FELLOW: return "fellow"; break; case PETTYPE_CHOCOBO: return "chocobo"; break; case PETTYPE_TRUST: return GetName(); break; default: return ""; break; } }
void Pet::setDeathState(DeathState s) // overwrite virtual Creature::setDeathState and Unit::setDeathState { Creature::setDeathState(s); if (getDeathState() == CORPSE) { if (getPetType() == HUNTER_PET) { // pet corpse non lootable and non skinnable SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_NONE); RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); //lose happiness when died and not in BG/Arena MapEntry const* mapEntry = sMapStore.LookupEntry(GetMapId()); if (!mapEntry || (mapEntry->map_type != MAP_ARENA && mapEntry->map_type != MAP_BATTLEGROUND)) ModifyPower(POWER_HAPPINESS, -HAPPINESS_LEVEL_SIZE); //SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED); } } else if (getDeathState() == ALIVE) { //RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED); CastPetAuras(true); } }
bool Pet::UpdateStats(Stats stat) { if(stat > STAT_SPIRIT) return false; // value = ((base_value * base_pct) + total_value) * total_pct float value = GetTotalStatValue(stat); Unit *owner = GetOwner(); if (owner) { switch(stat) { case STAT_STAMINA: // warlock's pets gain 75% of owner's stamina if (getPetType() == SUMMON_PET && owner->getClass() == CLASS_WARLOCK) value += owner->GetStat(stat) * 0.75f; else { if (getPetType() == SUMMON_PET || getPetType() == HUNTER_PET || owner->getClass() == CLASS_DEATH_KNIGHT) value += owner->GetStat(stat) * 0.3f; } break; case STAT_INTELLECT: // warlock's and mage's pets gain 30% of owner's intellect if (getPetType() == SUMMON_PET && (owner->getClass() == CLASS_WARLOCK || owner->getClass() == CLASS_MAGE)) value += owner->GetStat(stat) * 0.3f; break; }; } SetStat(stat, int32(value)); switch(stat) { case STAT_STRENGTH: UpdateAttackPowerAndDamage(); break; case STAT_AGILITY: UpdateArmor(); break; case STAT_STAMINA: UpdateMaxHealth(); break; case STAT_INTELLECT: UpdateMaxPower(POWER_MANA); break; case STAT_SPIRIT: default: break; } return true; }
void Pet::UpdateArmor() { float bonus_armor = 0.0f; UnitMods unitMod = UNIT_MOD_ARMOR; Unit* owner = GetOwner(); // hunter and warlock pets gain 35% of owner's armor value if (owner && (getPetType() == HUNTER_PET || (getPetType() == SUMMON_PET && owner->getClass() == CLASS_WARLOCK))) bonus_armor = 0.35f * float(owner->GetArmor()); float value = GetModifierValue(unitMod, BASE_VALUE); value *= GetModifierValue(unitMod, BASE_PCT); value += GetStat(STAT_AGILITY) * 2.0f; value += GetModifierValue(unitMod, TOTAL_VALUE) + bonus_armor; value *= GetModifierValue(unitMod, TOTAL_PCT); SetArmor(int32(value)); }
void Pet::UpdateResistances(uint32 school) { if (school > SPELL_SCHOOL_NORMAL) { float value = GetTotalAuraModValue(UnitMods(UNIT_MOD_RESISTANCE_START + school)); Unit *owner = GetOwner(); // chained, use original owner instead if (owner && owner->GetTypeId() == TYPEID_UNIT && ((Creature*)owner)->GetEntry() == GetEntry()) if (Unit *creator = GetCreator()) owner = creator; // hunter and warlock pets gain 40% of owner's resistance if (owner && (getPetType() == HUNTER_PET || (getPetType() == SUMMON_PET && owner->getClass() == CLASS_WARLOCK))) value += float(owner->GetResistance(SpellSchools(school))) * 0.4f; SetResistance(SpellSchools(school), int32(value)); } else UpdateArmor(); }
bool Pet::UpdateStats(Stats stat) { if (stat > STAT_SPIRIT) return false; // value = ((base_value * base_pct) + total_value) * total_pct float value = GetTotalStatValue(stat); Unit *owner = GetOwner(); if (stat == STAT_STAMINA) { if (owner && (getPetType() == HUNTER_PET || owner->getClass() == CLASS_WARLOCK || owner->getClass() == CLASS_MAGE)) { value += float(owner->GetStat(stat)) * 0.3f; if (getPetType() == HUNTER_PET && owner->HasAura(38297,1)) value += 52; } } //warlock's and mage's pets gain 30% of owner's intellect else if (stat == STAT_INTELLECT && getPetType() == SUMMON_PET) { if (owner && (owner->getClass() == CLASS_WARLOCK || owner->getClass() == CLASS_MAGE)) value += float(owner->GetStat(stat)) * 0.3f; } SetStat(stat, int32(value)); switch (stat) { case STAT_STRENGTH: UpdateAttackPowerAndDamage(); break; case STAT_AGILITY: UpdateArmor(); break; case STAT_STAMINA: UpdateMaxHealth(); break; case STAT_INTELLECT: UpdateMaxPower(POWER_MANA); break; case STAT_SPIRIT: default: break; } return true; }
void Pet::GivePetLevel(uint8 level) { if (!level || level == getLevel()) return; if (getPetType()==HUNTER_PET) { SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0); SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32(sObjectMgr->GetXPForLevel(level)*PET_XP_FACTOR)); } InitStatsForLevel(level); InitLevelupSpellsForLevel(); InitTalentForLevel(); }
void Pet::UpdateDamagePhysical(WeaponAttackType attType) { if(attType > BASE_ATTACK) return; UnitMods unitMod = UNIT_MOD_DAMAGE_MAINHAND; float att_speed = float(GetAttackTime(BASE_ATTACK))/1000.0f; float base_value = GetModifierValue(unitMod, BASE_VALUE) + GetTotalAttackPowerValue(attType)/ 14.0f * att_speed; float base_pct = GetModifierValue(unitMod, BASE_PCT); float total_value = GetModifierValue(unitMod, TOTAL_VALUE); float total_pct = GetModifierValue(unitMod, TOTAL_PCT); float weapon_mindamage = GetWeaponDamageRange(BASE_ATTACK, MINDAMAGE); float weapon_maxdamage = GetWeaponDamageRange(BASE_ATTACK, MAXDAMAGE); int32 ModSpeed = GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKSPEED); base_pct = base_pct * 100.0f/(100.0f+float(ModSpeed)); float mindamage = ((base_value + weapon_mindamage) * base_pct + total_value) * total_pct; float maxdamage = ((base_value + weapon_maxdamage) * base_pct + total_value) * total_pct; // Pet's base damage changes depending on happiness if (getPetType() == HUNTER_PET && attType == BASE_ATTACK) { switch(GetHappinessState()) { case HAPPY: // 125% of normal damage mindamage = mindamage * 1.25; maxdamage = maxdamage * 1.25; break; case CONTENT: // 100% of normal damage, nothing to modify break; case UNHAPPY: // 75% of normal damage mindamage = mindamage * 0.75; maxdamage = maxdamage * 0.75; break; } } SetStatFloatValue(UNIT_FIELD_MINDAMAGE, mindamage); SetStatFloatValue(UNIT_FIELD_MAXDAMAGE, maxdamage); }
void Pet::GivePetXP(uint32 xp) { if (getPetType() != HUNTER_PET) return; if (xp < 1) return; if (!isAlive()) return; uint8 maxlevel = std::min((uint8)sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL), GetOwner()->getLevel()); uint8 petlevel = getLevel(); // If pet is detected to be at, or above(?) the players level, don't hand out XP if (petlevel >= maxlevel) return; uint32 nextLvlXP = GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP); uint32 curXP = GetUInt32Value(UNIT_FIELD_PETEXPERIENCE); uint32 newXP = curXP + xp; // Check how much XP the pet should receive, and hand off have any left from previous levelups while (newXP >= nextLvlXP && petlevel < maxlevel) { // Subtract newXP from amount needed for nextlevel, and give pet the level newXP -= nextLvlXP; ++petlevel; GivePetLevel(petlevel); nextLvlXP = GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP); } // Not affected by special conditions - give it new XP SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, petlevel < maxlevel ? newXP : 0); }
void Pet::UpdateAttackPowerAndDamage(bool ranged) { if (ranged) return; float val = 0.0f; float bonusAP = 0.0f; UnitMods unitMod = UNIT_MOD_ATTACK_POWER; val = (GetStat(STAT_STRENGTH) - 20.0f) * 2; Unit* owner = GetOwner(); // chained, use original owner instead if (owner && owner->GetTypeId() == TYPEID_UNIT && ((Creature*)owner)->GetEntry() == GetEntry()) if (Unit *creator = GetCreator()) owner = creator; if (owner && owner->GetTypeId()==TYPEID_PLAYER) { if (getPetType() == HUNTER_PET) //hunter pets benefit from owner's attack power { float ap_coeff = 0.22f; float sp_coeff = 0.1287f; //Wild Hunt uint32 bonus_id = 0; if (HasSpell(62762)) bonus_id = 62762; else if (HasSpell(62758)) bonus_id = 62758; if (const SpellEntry *bonusProto = sSpellStore.LookupEntry(bonus_id)) { ap_coeff *= 1 + bonusProto->CalculateSimpleValue(EFFECT_INDEX_1) / 100.0f; sp_coeff *= 1 + bonusProto->CalculateSimpleValue(EFFECT_INDEX_1) / 100.0f; } bonusAP = owner->GetTotalAttackPowerValue(RANGED_ATTACK) * ap_coeff; SetBonusDamage( int32(owner->GetTotalAttackPowerValue(RANGED_ATTACK) * sp_coeff)); } else if (getPetType() == SUMMON_PET) { switch(owner->getClass()) { case CLASS_WARLOCK: { //demons benefit from warlocks shadow or fire damage int32 fire = int32(owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE)) - owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_FIRE); int32 shadow = int32(owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW)) - owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_SHADOW); int32 maximum = (fire > shadow) ? fire : shadow; if (maximum < 0) maximum = 0; SetBonusDamage(int32(maximum * 0.15f)); bonusAP = maximum * 0.57f; break; } case CLASS_MAGE: { //water elementals benefit from mage's frost damage int32 frost = int32(owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FROST)) - owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_FROST); if (frost < 0) frost = 0; SetBonusDamage(int32(frost * 0.4f)); break; } case CLASS_SHAMAN: { float coeff = 0.3f; //Glyph of Feral Spirit if (Aura *glyph = owner->GetDummyAura(63271)) coeff += glyph->GetModifier()->m_amount / 100.0f; bonusAP += coeff * owner->GetTotalAttackPowerValue(BASE_ATTACK); break; } case CLASS_DRUID: { //Guessed float coeff = 0.55f; int32 sp = int32(owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_NATURE)) - owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_NATURE); bonusAp += coeff * sp; break; } } } else if (getPetType() == GUARDIAN_PET) if (owner->getClass() == CLASS_DEATH_KNIGHT) bonusAP += owner->GetTotalAttackPowerValue(BASE_ATTACK) * 0.4f; } SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, val + bonusAP); //in BASE_VALUE of UNIT_MOD_ATTACK_POWER for creatures we store data of meleeattackpower field in DB float base_attPower = GetModifierValue(unitMod, BASE_VALUE) * GetModifierValue(unitMod, BASE_PCT); float attPowerMod = GetModifierValue(unitMod, TOTAL_VALUE); float attPowerMultiplier = GetModifierValue(unitMod, TOTAL_PCT) - 1.0f; //UNIT_FIELD_(RANGED)_ATTACK_POWER field SetInt32Value(UNIT_FIELD_ATTACK_POWER, (int32)base_attPower); //UNIT_FIELD_(RANGED)_ATTACK_POWER_MODS field SetInt32Value(UNIT_FIELD_ATTACK_POWER_MODS, (int32)attPowerMod); //UNIT_FIELD_(RANGED)_ATTACK_POWER_MULTIPLIER field SetFloatValue(UNIT_FIELD_ATTACK_POWER_MULTIPLIER, attPowerMultiplier); //automatically update weapon damage after attack power modification UpdateDamagePhysical(BASE_ATTACK); }
void Pet::UpdateDamagePhysical(WeaponAttackType attType) { if (attType > BASE_ATTACK) return; float bonusDamage = 0.0f; if (Unit* owner = GetOwner()) { //force of nature if (GetEntry() == 1964) { int32 spellDmg = int32(owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_NATURE)) - owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_NATURE); if (spellDmg > 0) bonusDamage = spellDmg * 0.09f; } //greater fire elemental else if (GetEntry() == 15438) { if (Unit* shaman = owner->GetOwner()) { int32 spellDmg = int32(shaman->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE)) - shaman->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + SPELL_SCHOOL_FIRE); if (spellDmg > 0) bonusDamage = spellDmg * 0.4f; } } } UnitMods unitMod = UNIT_MOD_DAMAGE_MAINHAND; float att_speed = float(GetAttackTime(BASE_ATTACK))/1000.0f; float base_value = GetModifierValue(unitMod, BASE_VALUE) + GetTotalAttackPowerValue(attType)/ 14.0f * att_speed + bonusDamage; float base_pct = GetModifierValue(unitMod, BASE_PCT); float total_value = GetModifierValue(unitMod, TOTAL_VALUE); float total_pct = GetModifierValue(unitMod, TOTAL_PCT); float weapon_mindamage = GetWeaponDamageRange(BASE_ATTACK, MINDAMAGE); float weapon_maxdamage = GetWeaponDamageRange(BASE_ATTACK, MAXDAMAGE); float mindamage = ((base_value + weapon_mindamage) * base_pct + total_value) * total_pct; float maxdamage = ((base_value + weapon_maxdamage) * base_pct + total_value) * total_pct; // Pet's base damage changes depending on happiness if (getPetType() == HUNTER_PET && attType == BASE_ATTACK) { switch(GetHappinessState()) { case HAPPY: // 125% of normal damage mindamage = mindamage * 1.25; maxdamage = maxdamage * 1.25; break; case CONTENT: // 100% of normal damage, nothing to modify break; case UNHAPPY: // 75% of normal damage mindamage = mindamage * 0.75; maxdamage = maxdamage * 0.75; break; } } SetStatFloatValue(UNIT_FIELD_MINDAMAGE, mindamage); SetStatFloatValue(UNIT_FIELD_MAXDAMAGE, maxdamage); }
bool Pet::UpdateStats(Stats stat) { if(stat > STAT_SPIRIT) return false; // value = ((base_value * base_pct) + total_value) * total_pct float value = GetTotalStatValue(stat); Unit *owner = GetOwner(); if ( stat == STAT_STAMINA ) { if(owner) { float scale_coeff = 0.3f; switch (owner->getClass()) { case CLASS_HUNTER: scale_coeff = 0.4493f; break; case CLASS_WARLOCK: { CreatureInfo const *cinfo = GetCreatureInfo(); CreatureFamily petFamily = (CreatureFamily) cinfo->family; switch (petFamily) { case CREATURE_FAMILY_FELHUNTER: value += float(owner->GetStat(stat)) * 0.7125f; break; case CREATURE_FAMILY_VOIDWALKER: value += float(owner->GetStat(stat)) * 0.825f; break; case CREATURE_FAMILY_FELGUARD: value += float(owner->GetStat(stat)) * 0.825f; break; case CREATURE_FAMILY_SUCCUBUS: value += float(owner->GetStat(stat)) * 0.6825f; break; case CREATURE_FAMILY_IMP: value += float(owner->GetStat(stat)) * 0.63f; break; default: value += float(owner->GetStat(stat)) * 0.3f; break; } break; } case CLASS_DEATH_KNIGHT: scale_coeff = 0.3928f; break; } value += float(owner->GetStat(stat)) * scale_coeff; } } //warlock's and mage's pets gain 30% of owner's intellect else if ( stat == STAT_INTELLECT && getPetType() == SUMMON_PET ) { if(owner && (owner->getClass() == CLASS_WARLOCK || owner->getClass() == CLASS_MAGE) ) value += float(owner->GetStat(stat)) * 0.3f; } SetStat(stat, int32(value)); switch(stat) { case STAT_STRENGTH: UpdateAttackPowerAndDamage(); break; case STAT_AGILITY: UpdateArmor(); break; case STAT_STAMINA: UpdateMaxHealth(); break; case STAT_INTELLECT: UpdateMaxPower(POWER_MANA); break; case STAT_SPIRIT: default: break; } return true; }
bool CPetEntity::isBstPet() { return getPetType()==PETTYPE_JUG_PET || objtype == TYPE_MOB; }
void Pet::SavePetToDB(PetSaveMode mode) { if (!GetEntry()) return; // save only fully controlled creature if (!isControlled()) return; // not save not player pets if (!IS_PLAYER_GUID(GetOwnerGUID())) return; Player* owner = (Player*)GetOwner(); if (!owner) return; // not save pet as current if another pet temporary unsummoned if (mode == PET_SAVE_AS_CURRENT && owner->GetTemporaryUnsummonedPetNumber() && owner->GetTemporaryUnsummonedPetNumber() != m_charmInfo->GetPetNumber()) { // pet will lost anyway at restore temporary unsummoned if (getPetType() == HUNTER_PET) return; // for warlock case mode = PET_SAVE_NOT_IN_SLOT; } uint32 curhealth = GetHealth(); uint32 curmana = GetPower(POWER_MANA); SQLTransaction trans = CharacterDatabase.BeginTransaction(); // save auras before possibly removing them _SaveAuras(trans); // stable and not in slot saves if (mode > PET_SAVE_AS_CURRENT) RemoveAllAuras(); _SaveSpells(trans); _SaveSpellCooldowns(trans); CharacterDatabase.CommitTransaction(trans); // current/stable/not_in_slot if (mode >= PET_SAVE_AS_CURRENT) { uint32 ownerLowGUID = GUID_LOPART(GetOwnerGUID()); std::string name = m_name; CharacterDatabase.EscapeString(name); trans = CharacterDatabase.BeginTransaction(); // remove current data trans->PAppend("DELETE FROM character_pet WHERE owner = '%u' AND id = '%u'", ownerLowGUID, m_charmInfo->GetPetNumber()); // prevent duplicate using slot (except PET_SAVE_NOT_IN_SLOT) if (mode <= PET_SAVE_LAST_STABLE_SLOT) trans->PAppend("UPDATE character_pet SET slot = '%u' WHERE owner = '%u' AND slot = '%u'", PET_SAVE_NOT_IN_SLOT, ownerLowGUID, uint32(mode)); // prevent existence another hunter pet in PET_SAVE_AS_CURRENT and PET_SAVE_NOT_IN_SLOT if (getPetType() == HUNTER_PET && (mode == PET_SAVE_AS_CURRENT || mode > PET_SAVE_LAST_STABLE_SLOT)) trans->PAppend("DELETE FROM character_pet WHERE owner = '%u' AND (slot = '%u' OR slot > '%u')", ownerLowGUID, PET_SAVE_AS_CURRENT, PET_SAVE_LAST_STABLE_SLOT); // save pet std::ostringstream ss; ss << "INSERT INTO character_pet (id, entry, owner, modelid, level, exp, Reactstate, slot, name, renamed, curhealth, curmana, curhappiness, abdata, savetime, CreatedBySpell, PetType) " << "VALUES (" << m_charmInfo->GetPetNumber() << ',' << GetEntry() << ',' << ownerLowGUID << ',' << GetNativeDisplayId() << ',' << uint32(getLevel()) << ',' << GetUInt32Value(UNIT_FIELD_PETEXPERIENCE) << ',' << uint32(GetReactState()) << ',' << uint32(mode) << ", '" << name.c_str() << "', " << uint32(HasByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED) ? 0 : 1) << ',' << curhealth << ',' << curmana << ',' << GetPower(POWER_HAPPINESS) << ", '"; for (uint32 i = ACTION_BAR_INDEX_START; i < ACTION_BAR_INDEX_END; ++i) { ss << uint32(m_charmInfo->GetActionBarEntry(i)->GetType()) << ' ' << uint32(m_charmInfo->GetActionBarEntry(i)->GetAction()) << ' '; }; ss << "', " << time(NULL) << ',' << GetUInt32Value(UNIT_CREATED_BY_SPELL) << ',' << uint32(getPetType()) << ')'; trans->Append(ss.str().c_str()); CharacterDatabase.CommitTransaction(trans); } // delete else { RemoveAllAuras(); DeleteFromDB(m_charmInfo->GetPetNumber()); } }
void Pet::Update(uint32 diff) { if (m_removed) // pet already removed, just wait in remove queue, no updates return; if (m_loading) return; switch (m_deathState) { case CORPSE: { if (getPetType() != HUNTER_PET || m_corpseRemoveTime <= time(NULL)) { Remove(PET_SAVE_NOT_IN_SLOT); //hunters' pets never get removed because of death, NEVER! return; } break; } case ALIVE: { // unsummon pet that lost owner Player* owner = GetOwner(); if (!owner || (!IsWithinDistInMap(owner, GetMap()->GetVisibilityRange()) && !isPossessed()) || (isControlled() && !owner->GetPetGUID())) //if (!owner || (!IsWithinDistInMap(owner, GetMap()->GetVisibilityDistance()) && (owner->GetCharmGUID() && (owner->GetCharmGUID() != GetGUID()))) || (isControlled() && !owner->GetPetGUID())) { Remove(PET_SAVE_NOT_IN_SLOT, true); return; } if (isControlled()) { if (owner->GetPetGUID() != GetGUID()) { sLog->outError("Pet %u is not pet of owner %s, removed", GetEntry(), m_owner->GetName()); Remove(getPetType() == HUNTER_PET?PET_SAVE_AS_DELETED:PET_SAVE_NOT_IN_SLOT); return; } } if (m_duration > 0) { if (uint32(m_duration) > diff) m_duration -= diff; else { Remove(getPetType() != SUMMON_PET ? PET_SAVE_AS_DELETED:PET_SAVE_NOT_IN_SLOT); return; } } //regenerate focus for hunter pets or energy for deathknight's ghoul if (m_regenTimer) { if (m_regenTimer > diff) m_regenTimer -= diff; else { switch (getPowerType()) { case POWER_FOCUS: Regenerate(POWER_FOCUS); m_regenTimer += PET_FOCUS_REGEN_INTERVAL - diff; if (!m_regenTimer) ++m_regenTimer; break; // in creature::update //case POWER_ENERGY: // Regenerate(POWER_ENERGY); // m_regenTimer += CREATURE_REGEN_INTERVAL - diff; // if (!m_regenTimer) ++m_regenTimer; // break; default: m_regenTimer = 0; break; } } } if (getPetType() != HUNTER_PET) break; if (m_happinessTimer <= diff) { LoseHappiness(); m_happinessTimer = 7500; } else m_happinessTimer -= diff; break; } default: break; } Creature::Update(diff); }
bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool current) { m_loading = true; uint32 ownerid = owner->GetGUIDLow(); QueryResult result; if (petnumber) // known petnumber entry 0 1 2(?) 3 4 5 6 7 8 9 10 11 12 13 14 15 16 result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, slot, name, renamed, curhealth, curmana, curhappiness, abdata, savetime, CreatedBySpell, PetType " "FROM character_pet WHERE owner = '%u' AND id = '%u'", ownerid, petnumber); else if (current) // current pet (slot 0) 0 1 2(?) 3 4 5 6 7 8 9 10 11 12 13 14 15 16 result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, slot, name, renamed, curhealth, curmana, curhappiness, abdata, savetime, CreatedBySpell, PetType " "FROM character_pet WHERE owner = '%u' AND slot = '%u'", ownerid, PET_SAVE_AS_CURRENT); else if (petentry) // known petentry entry (unique for summoned pet, but non unique for hunter pet (only from current or not stabled pets) // 0 1 2(?) 3 4 5 6 7 8 9 10 11 12 13 14 15 16 result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, slot, name, renamed, curhealth, curmana, curhappiness, abdata, savetime, CreatedBySpell, PetType " "FROM character_pet WHERE owner = '%u' AND entry = '%u' AND (slot = '%u' OR slot > '%u') ", ownerid, petentry, PET_SAVE_AS_CURRENT, PET_SAVE_LAST_STABLE_SLOT); else // any current or other non-stabled pet (for hunter "call pet") // 0 1 2(?) 3 4 5 6 7 8 9 10 11 12 13 14 15 16 result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, slot, name, renamed, curhealth, curmana, curhappiness, abdata, savetime, CreatedBySpell, PetType " "FROM character_pet WHERE owner = '%u' AND (slot = '%u' OR slot > '%u') ", ownerid, PET_SAVE_AS_CURRENT, PET_SAVE_LAST_STABLE_SLOT); if (!result) { m_loading = false; return false; } Field* fields = result->Fetch(); // update for case of current pet "slot = 0" petentry = fields[1].GetUInt32(); if (!petentry) return false; uint32 summon_spell_id = fields[15].GetUInt32(); SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(summon_spell_id); bool is_temporary_summoned = spellInfo && spellInfo->GetDuration() > 0; // check temporary summoned pets like mage water elemental if (current && is_temporary_summoned) return false; PetType pet_type = PetType(fields[16].GetUInt8()); if (pet_type == HUNTER_PET) { CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(petentry); if (!creatureInfo || !creatureInfo->isTameable(owner->CanTameExoticPets())) return false; } uint32 pet_number = fields[0].GetUInt32(); if (current && owner->IsPetNeedBeTemporaryUnsummoned()) { owner->SetTemporaryUnsummonedPetNumber(pet_number); return false; } Map* map = owner->GetMap(); uint32 guid = sObjectMgr->GenerateLowGuid(HIGHGUID_PET); if (!Create(guid, map, owner->GetPhaseMask(), petentry, pet_number)) return false; float px, py, pz; owner->GetClosePoint(px, py, pz, GetObjectSize(), PET_FOLLOW_DIST, GetFollowAngle()); Relocate(px, py, pz, owner->GetOrientation()); if (!IsPositionValid()) { sLog->outError("Pet (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)", GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY()); return false; } setPetType(pet_type); setFaction(owner->getFaction()); SetUInt32Value(UNIT_CREATED_BY_SPELL, summon_spell_id); CreatureTemplate const* cinfo = GetCreatureInfo(); if (cinfo->type == CREATURE_TYPE_CRITTER) { map->AddToMap(this->ToCreature()); return true; } m_charmInfo->SetPetNumber(pet_number, IsPermanentPetFor(owner)); SetDisplayId(fields[3].GetUInt32()); SetNativeDisplayId(fields[3].GetUInt32()); uint32 petlevel = fields[4].GetUInt16(); SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE); SetName(fields[8].GetString()); switch (getPetType()) { case SUMMON_PET: petlevel = owner->getLevel(); SetUInt32Value(UNIT_FIELD_BYTES_0, 0x800); // class = mage SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); // this enables popup window (pet dismiss, cancel) break; case HUNTER_PET: SetUInt32Value(UNIT_FIELD_BYTES_0, 0x02020100); // class = warrior, gender = none, power = focus SetSheath(SHEATH_STATE_MELEE); SetByteFlag(UNIT_FIELD_BYTES_2, 2, fields[9].GetBool() ? UNIT_CAN_BE_ABANDONED : UNIT_CAN_BE_RENAMED | UNIT_CAN_BE_ABANDONED); SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); // this enables popup window (pet abandon, cancel) SetMaxPower(POWER_HAPPINESS, GetCreatePowers(POWER_HAPPINESS)); SetPower(POWER_HAPPINESS, fields[12].GetUInt32()); setPowerType(POWER_FOCUS); break; default: if (!IsPetGhoul()) sLog->outError("Pet have incorrect type (%u) for pet loading.", getPetType()); break; } SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); // cast can't be helped here SetCreatorGUID(owner->GetGUID()); InitStatsForLevel(petlevel); SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, fields[5].GetUInt32()); SynchronizeLevelWithOwner(); SetReactState(ReactStates(fields[6].GetUInt8())); SetCanModifyStats(true); if (getPetType() == SUMMON_PET && !current) //all (?) summon pets come with full health when called, but not when they are current SetPower(POWER_MANA, GetMaxPower(POWER_MANA)); else { uint32 savedhealth = fields[10].GetUInt32(); uint32 savedmana = fields[11].GetUInt32(); if (!savedhealth && getPetType() == HUNTER_PET) setDeathState(JUST_DIED); else { SetHealth(savedhealth > GetMaxHealth() ? GetMaxHealth() : savedhealth); SetPower(POWER_MANA, savedmana > GetMaxPower(POWER_MANA) ? GetMaxPower(POWER_MANA) : savedmana); } } // set current pet as current // 0=current // 1..MAX_PET_STABLES in stable slot // PET_SAVE_NOT_IN_SLOT(100) = not stable slot (summoning)) if (fields[7].GetUInt8()) { SQLTransaction trans = CharacterDatabase.BeginTransaction(); trans->PAppend("UPDATE character_pet SET slot = '%u' WHERE owner = '%u' AND slot = '%u' AND id <> '%u'", PET_SAVE_NOT_IN_SLOT, ownerid, PET_SAVE_AS_CURRENT, m_charmInfo->GetPetNumber()); trans->PAppend("UPDATE character_pet SET slot = '%u' WHERE owner = '%u' AND id = '%u'", PET_SAVE_AS_CURRENT, ownerid, m_charmInfo->GetPetNumber()); CharacterDatabase.CommitTransaction(trans); } // Send fake summon spell cast - this is needed for correct cooldown application for spells // Example: 46584 - without this cooldown (which should be set always when pet is loaded) isn't set clientside // TODO: pets should be summoned from real cast instead of just faking it? if (summon_spell_id) { WorldPacket data(SMSG_SPELL_GO, (8+8+4+4+2)); data.append(owner->GetPackGUID()); data.append(owner->GetPackGUID()); data << uint8(0); data << uint32(summon_spell_id); data << uint32(256); // CAST_FLAG_UNKNOWN3 data << uint32(0); owner->SendMessageToSet(&data, true); } owner->SetMinion(this, true); map->AddToMap(this->ToCreature()); InitTalentForLevel(); // set original talents points before spell loading uint32 timediff = uint32(time(NULL) - fields[14].GetUInt32()); _LoadAuras(timediff); // load action bar, if data broken will fill later by default spells. if (!is_temporary_summoned) { m_charmInfo->LoadPetActionBar(fields[13].GetString()); _LoadSpells(); InitTalentForLevel(); // re-init to check talent count _LoadSpellCooldowns(); LearnPetPassives(); InitLevelupSpellsForLevel(); CastPetAuras(current); } CleanupActionBar(); // remove unknown spells from action bar after load sLog->outDebug(LOG_FILTER_PETS, "New Pet has guid %u", GetGUIDLow()); owner->PetSpellInitialize(); if (owner->GetGroup()) owner->SetGroupUpdateFlag(GROUP_UPDATE_PET); owner->SendTalentsInfoData(true); if (getPetType() == HUNTER_PET) { result = CharacterDatabase.PQuery("SELECT genitive, dative, accusative, instrumental, prepositional FROM character_pet_declinedname WHERE owner = '%u' AND id = '%u'", owner->GetGUIDLow(), GetCharmInfo()->GetPetNumber()); if (result) { delete m_declinedname; m_declinedname = new DeclinedName; Field* fields2 = result->Fetch(); for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i) { m_declinedname->name[i] = fields2[i].GetString(); } } } //set last used pet number (for use in BG's) if (owner->GetTypeId() == TYPEID_PLAYER && isControlled() && !isTemporarySummoned() && (getPetType() == SUMMON_PET || getPetType() == HUNTER_PET)) owner->ToPlayer()->SetLastPetNumber(pet_number); m_loading = false; return true; }
bool Pet::UpdateStats(Stats stat) { if (stat > STAT_SPIRIT) return false; // value = ((base_value * base_pct) + total_value) * total_pct float value = GetTotalStatValue(stat); CreatureInfo const *cinfo = GetCreatureInfo(); Unit *owner = GetOwner(); // chained, use original owner instead if (owner && owner->GetTypeId() == TYPEID_UNIT && ((Creature*)owner)->GetEntry() == GetEntry()) if (Unit *creator = GetCreator()) owner = creator; if (owner && owner->GetTypeId() == TYPEID_PLAYER) { float scale_coeff = 0.0f; switch(stat) { case STAT_STRENGTH: { if (owner->getClass() == CLASS_DEATH_KNIGHT) { if (getPetType() == SUMMON_PET) { scale_coeff = 0.7f; // Ravenous Dead if (SpellEntry const* spell = ((Player*)owner)->GetKnownTalentRankById(1934)) scale_coeff *= 1.0f + spell->CalculateSimpleValue(EFFECT_INDEX_1) / 100.0f; // Glyph of Ghoul if (Aura *glyph = owner->GetDummyAura(58686)) scale_coeff += glyph->GetModifier()->m_amount / 100.0f; } } break; } case STAT_STAMINA: { scale_coeff = 0.3f; switch (owner->getClass()) { case CLASS_HUNTER: { scale_coeff = 0.45f; //Wild Hunt uint32 bonus_id = 0; if (HasSpell(62762)) bonus_id = 62762; else if (HasSpell(62758)) bonus_id = 62758; if (const SpellEntry *bonusProto = sSpellStore.LookupEntry(bonus_id)) scale_coeff *= 1 + bonusProto->CalculateSimpleValue(EFFECT_INDEX_0) / 100.0f; break; } case CLASS_WARLOCK: { scale_coeff = 0.75f; break; } case CLASS_DEATH_KNIGHT: { if (getPetType() == SUMMON_PET) { // Ravenous Dead if (owner->GetTypeId() == TYPEID_PLAYER) if (SpellEntry const* spell = ((Player*)owner)->GetKnownTalentRankById(1934)) scale_coeff *= 1.0f + spell->CalculateSimpleValue(EFFECT_INDEX_1) / 100.0f; // Glyph of Ghoul if (Aura *glyph = owner->GetDummyAura(58686)) scale_coeff += glyph->GetModifier()->m_amount / 100.0f; } break; } case CLASS_DRUID: { //For treants, use 70% of stamina / 3 treants, guessed scale_coeff = 0.7f / 3.0f; break; } } break; } case STAT_INTELLECT: { //warlock's and mage's pets gain 30% of owner's intellect if (getPetType() == SUMMON_PET) { if (owner && (owner->getClass() == CLASS_WARLOCK || owner->getClass() == CLASS_MAGE) ) scale_coeff = 0.3f; } break; } } value += float(owner->GetStat(stat)) * scale_coeff; } SetStat(stat, int32(value)); switch(stat) { case STAT_STRENGTH: UpdateAttackPowerAndDamage(); break; case STAT_AGILITY: UpdateArmor(); break; case STAT_STAMINA: UpdateMaxHealth(); break; case STAT_INTELLECT: UpdateMaxPower(POWER_MANA); break; case STAT_SPIRIT: default: break; } return true; }