diff options
author | raczman <none@none> | 2010-03-07 15:20:19 +0100 |
---|---|---|
committer | raczman <none@none> | 2010-03-07 15:20:19 +0100 |
commit | 91b8ee104eac7446f9b8cbea7ed9dce641740c8e (patch) | |
tree | 2866b76745089d8066dad65b63e5aff07e92f4f6 | |
parent | aeebe57dc08d8b2d90972f50f00c4a28dd3947ba (diff) |
Added new type-safe cast functions.
This, when properly used, should get rid of most memory corruption issues,
currently, casting types C-style with no checks leads to some abstract crashing.
Functionality is same as with dynamic_cast<>, but with no RTTI check - so when
casting into invalid type you will receive NULL, and most probably crash.
At the same time, i took the liberty to convert most Player* casts to ToPlayer().
Still needs crapload of casts being moved to new facility.
--HG--
branch : trunk
30 files changed, 674 insertions, 663 deletions
diff --git a/src/game/AchievementMgr.cpp b/src/game/AchievementMgr.cpp index 76508b94f63..89272192e7d 100644 --- a/src/game/AchievementMgr.cpp +++ b/src/game/AchievementMgr.cpp @@ -265,9 +265,9 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un case ACHIEVEMENT_CRITERIA_DATA_TYPE_T_PLAYER_CLASS_RACE: if (!target || target->GetTypeId() != TYPEID_PLAYER) return false; - if(classRace.class_id && classRace.class_id != ((Player*)target)->getClass()) + if(classRace.class_id && classRace.class_id != target->ToPlayer()->getClass()) return false; - if(classRace.race_id && classRace.race_id != ((Player*)target)->getRace()) + if(classRace.race_id && classRace.race_id != target->ToPlayer()->getRace()) return false; return true; case ACHIEVEMENT_CRITERIA_DATA_TYPE_T_PLAYER_LESS_HEALTH: @@ -275,10 +275,10 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un return false; return target->GetHealth()*100 <= health.percent*target->GetMaxHealth(); case ACHIEVEMENT_CRITERIA_DATA_TYPE_T_PLAYER_DEAD: - if (!target || target->GetTypeId() != TYPEID_PLAYER || target->isAlive() || ((Player*)target)->GetDeathTimer() == 0) + if (!target || target->GetTypeId() != TYPEID_PLAYER || target->isAlive() || target->ToPlayer()->GetDeathTimer() == 0) return false; // flag set == must be same team, not set == different team - return (((Player*)target)->GetTeam() == source->GetTeam()) == (player_dead.own_team_flag != 0); + return (target->ToPlayer()->GetTeam() == source->GetTeam()) == (player_dead.own_team_flag != 0); case ACHIEVEMENT_CRITERIA_DATA_TYPE_S_AURA: return source->HasAuraEffect(aura.spell_id,aura.effect_idx); case ACHIEVEMENT_CRITERIA_DATA_TYPE_S_AREA: @@ -308,7 +308,7 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un case ACHIEVEMENT_CRITERIA_DATA_TYPE_T_TEAM: if (!target || target->GetTypeId() != TYPEID_PLAYER) return false; - return ((Player*)target)->GetTeam() == team.team; + return target->ToPlayer()->GetTeam() == team.team; case ACHIEVEMENT_CRITERIA_DATA_TYPE_S_DRUNK: return Player::GetDrunkenstateByValue(source->GetDrunkValue()) >= drunk.state; case ACHIEVEMENT_CRITERIA_DATA_TYPE_HOLIDAY: diff --git a/src/game/Creature.h b/src/game/Creature.h index d073901a13d..1d0a2fd560f 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -663,6 +663,7 @@ class Creature : public Unit, public GridObject<Creature> static float _GetDamageMod(int32 Rank); float m_SightDistance, m_CombatDistance; + protected: bool CreateFromProto(uint32 guidlow, uint32 Entry, uint32 vehId, uint32 team, const CreatureData *data = NULL); bool InitEntry(uint32 entry, uint32 team=ALLIANCE, const CreatureData* data=NULL); diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index debcdfb8056..a962c8195eb 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -534,12 +534,12 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 case ACTION_T_QUEST_EVENT: if (Unit* target = GetTargetByType(action.quest_event.target, pActionInvoker)) if (target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->AreaExploredOrEventHappens(action.quest_event.questId); + target->ToPlayer()->AreaExploredOrEventHappens(action.quest_event.questId); break; case ACTION_T_CAST_EVENT: if (Unit* target = GetTargetByType(action.cast_event.target, pActionInvoker)) if (target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->CastedCreatureOrGO(action.cast_event.creatureId, m_creature->GetGUID(), action.cast_event.spellId); + target->ToPlayer()->CastedCreatureOrGO(action.cast_event.creatureId, m_creature->GetGUID(), action.cast_event.spellId); break; case ACTION_T_SET_UNIT_FIELD: { @@ -622,7 +622,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 { if (Unit* Temp = Unit::GetUnit(*m_creature,pActionInvoker->GetGUID())) if (Temp->GetTypeId() == TYPEID_PLAYER) - ((Player*)Temp)->GroupEventHappens(action.quest_event_all.questId,m_creature); + Temp->ToPlayer()->GroupEventHappens(action.quest_event_all.questId,m_creature); } break; case ACTION_T_CAST_EVENT_ALL: @@ -631,7 +631,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 for (std::list<HostilReference*>::iterator i = threatList.begin(); i != threatList.end(); ++i) if (Unit* Temp = Unit::GetUnit(*m_creature,(*i)->getUnitGuid())) if (Temp->GetTypeId() == TYPEID_PLAYER) - ((Player*)Temp)->CastedCreatureOrGO(action.cast_event_all.creatureId, m_creature->GetGUID(), action.cast_event_all.spellId); + Temp->ToPlayer()->CastedCreatureOrGO(action.cast_event_all.creatureId, m_creature->GetGUID(), action.cast_event_all.spellId); break; } case ACTION_T_REMOVEAURASFROMSPELL: diff --git a/src/game/DynamicObject.cpp b/src/game/DynamicObject.cpp index 88d9848d3c2..1e71eb7159d 100644 --- a/src/game/DynamicObject.cpp +++ b/src/game/DynamicObject.cpp @@ -61,7 +61,7 @@ void DynamicObject::RemoveFromWorld() if(Unit *caster = GetCaster()) { if(caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)caster)->SetViewpoint(this, false); + caster->ToPlayer()->SetViewpoint(this, false); } else { diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index 8239b2cccad..8f47aa83a2a 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -253,9 +253,9 @@ void GameObject::Update(uint32 /*p_time*/) UpdateData udata; WorldPacket packet; - BuildValuesUpdateBlockForPlayer(&udata,((Player*)caster)); + BuildValuesUpdateBlockForPlayer(&udata,caster->ToPlayer()); udata.BuildPacket(&packet); - ((Player*)caster)->GetSession()->SendPacket(&packet); + caster->ToPlayer()->GetSession()->SendPacket(&packet); SendCustomAnim(); } @@ -290,7 +290,7 @@ void GameObject::Update(uint32 /*p_time*/) caster->FinishSpell(CURRENT_CHANNELED_SPELL); WorldPacket data(SMSG_FISH_ESCAPED,0); - ((Player*)caster)->GetSession()->SendPacket(&data); + caster->ToPlayer()->GetSession()->SendPacket(&data); } // can be delete m_lootState = GO_JUST_DEACTIVATED; @@ -396,8 +396,8 @@ void GameObject::Update(uint32 /*p_time*/) if(IsBattleGroundTrap && ok->GetTypeId() == TYPEID_PLAYER) { //BattleGround gameobjects case - if(((Player*)ok)->InBattleGround()) - if(BattleGround *bg = ((Player*)ok)->GetBattleGround()) + if(ok->ToPlayer()->InBattleGround()) + if(BattleGround *bg = ok->ToPlayer()->GetBattleGround()) bg->HandleTriggerBuff(GetGUID()); } } @@ -1271,7 +1271,7 @@ void GameObject::Use(Unit* user) return; // accept only use by player from same group for caster except caster itself - if(((Player*)caster)==player || !((Player*)caster)->IsInSameRaidWith(player)) + if(caster->ToPlayer()==player || !caster->ToPlayer()->IsInSameRaidWith(player)) return; AddUniqueUse(player); @@ -1318,7 +1318,7 @@ void GameObject::Use(Unit* user) if( !caster || caster->GetTypeId() != TYPEID_PLAYER ) return; - if(user->GetTypeId() != TYPEID_PLAYER || !((Player*)user)->IsInSameRaidWith((Player*)caster)) + if(user->GetTypeId() != TYPEID_PLAYER || !user->ToPlayer()->IsInSameRaidWith(caster->ToPlayer())) return; } diff --git a/src/game/Level1.cpp b/src/game/Level1.cpp index 9a9c60f245e..d84cb06352a 100644 --- a/src/game/Level1.cpp +++ b/src/game/Level1.cpp @@ -1113,9 +1113,9 @@ bool ChatHandler::HandleModifyHPCommand(const char* args) if (chr->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player*)chr, 0)) return false; - PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink((Player*)chr).c_str(), hp, hpm); - if (chr->GetTypeId() == TYPEID_PLAYER && needReportToTarget((Player*)chr)) - ChatHandler((Player*)chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm); + PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink(chr->ToPlayer()).c_str(), hp, hpm); + if (chr->GetTypeId() == TYPEID_PLAYER && needReportToTarget(chr->ToPlayer())) + ChatHandler(chr->ToPlayer()).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm); chr->SetMaxHealth( hpm ); chr->SetHealth( hp ); @@ -1460,20 +1460,20 @@ bool ChatHandler::HandleModifyTalentCommand (const char* args) // check online security if (HasLowerSecurity((Player*)target, 0)) return false; - ((Player*)target)->SetFreeTalentPoints(tp); - ((Player*)target)->SendTalentsInfoData(false); + target->ToPlayer()->SetFreeTalentPoints(tp); + target->ToPlayer()->SendTalentsInfoData(false); return true; } else if(((Creature*)target)->isPet()) { Unit *owner = target->GetOwner(); - if(owner && owner->GetTypeId() == TYPEID_PLAYER && ((Pet *)target)->IsPermanentPetFor((Player*)owner)) + if(owner && owner->GetTypeId() == TYPEID_PLAYER && ((Pet *)target)->IsPermanentPetFor(owner->ToPlayer())) { // check online security if (HasLowerSecurity((Player*)owner, 0)) return false; ((Pet *)target)->SetFreeTalentPoints(tp); - ((Player*)owner)->SendTalentsInfoData(true); + owner->ToPlayer()->SendTalentsInfoData(true); return true; } } diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index e2bf6c3cfa3..71d789f1d80 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -5284,14 +5284,14 @@ bool ChatHandler::HandleResetTalentsCommand(const char * args) if (!*args && creature && creature->isPet()) { Unit *owner = creature->GetOwner(); - if(owner && owner->GetTypeId() == TYPEID_PLAYER && ((Pet *)creature)->IsPermanentPetFor((Player*)owner)) + if(owner && owner->GetTypeId() == TYPEID_PLAYER && ((Pet *)creature)->IsPermanentPetFor(owner->ToPlayer())) { ((Pet *)creature)->resetTalents(true); - ((Player*)owner)->SendTalentsInfoData(true); + owner->ToPlayer()->SendTalentsInfoData(true); - ChatHandler((Player*)owner).SendSysMessage(LANG_RESET_PET_TALENTS); - if(!m_session || m_session->GetPlayer()!=((Player*)owner)) - PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE,GetNameLink((Player*)owner).c_str()); + ChatHandler(owner->ToPlayer()).SendSysMessage(LANG_RESET_PET_TALENTS); + if(!m_session || m_session->GetPlayer()!=owner->ToPlayer()) + PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE,GetNameLink(owner->ToPlayer()).c_str()); } return true; } diff --git a/src/game/Object.cpp b/src/game/Object.cpp index 40cac8a7891..21c564c6dcb 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -295,11 +295,11 @@ void Object::_BuildMovementUpdate(ByteBuffer * data, uint16 flags) const *data << ((Unit*)this)->GetSpeed( MOVE_PITCH_RATE ); // 0x08000000 - if(GetTypeId() == TYPEID_PLAYER && ((Player*)this)->isInFlight()) + if(GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->isInFlight()) { - WPAssert(((Player*)this)->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE); + //WPAssert(this->ToPlayer()->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE); - FlightPathMovementGenerator *fmg = (FlightPathMovementGenerator*)(((Player*)this)->GetMotionMaster()->top()); + FlightPathMovementGenerator *fmg = (FlightPathMovementGenerator*)(const_cast<Player*>(this->ToPlayer())->GetMotionMaster()->top()); uint32 flags3 = MOVEFLAG_GLIDE; @@ -327,7 +327,7 @@ void Object::_BuildMovementUpdate(ByteBuffer * data, uint16 flags) const Path &path = fmg->GetPath(); float x, y, z; - ((Player*)this)->GetPosition(x, y, z); + this->ToPlayer()->GetPosition(x, y, z); uint32 inflighttime = uint32(path.GetPassedLength(fmg->GetCurrentNode(), x, y, z) * 32); uint32 traveltime = uint32(path.GetTotalLength() * 32); @@ -629,14 +629,14 @@ void Object::_BuildValuesUpdate(uint8 updatetype, ByteBuffer * data, UpdateMask if(index == UNIT_FIELD_BYTES_2) { // Allow targetting opposite faction in party when enabled in config - DEBUG_LOG("-- VALUES_UPDATE: Sending '%s' the blue-group-fix from '%s' (flag)", target->GetName(), ((Player*)this)->GetName()); + DEBUG_LOG("-- VALUES_UPDATE: Sending '%s' the blue-group-fix from '%s' (flag)", target->GetName(), this->ToPlayer()->GetName()); *data << ( m_uint32Values[ index ] & ((UNIT_BYTE2_FLAG_SANCTUARY /*| UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5*/) << 8) ); // this flag is at uint8 offset 1 !! } else { // pretend that all other HOSTILE players have own faction, to allow follow, heal, rezz (trade wont work) uint32 faction = target->getFaction(); - DEBUG_LOG("-- VALUES_UPDATE: Sending '%s' the blue-group-fix from '%s' (faction %u)", target->GetName(), ((Player*)this)->GetName(), faction); + DEBUG_LOG("-- VALUES_UPDATE: Sending '%s' the blue-group-fix from '%s' (faction %u)", target->GetName(), this->ToPlayer()->GetName(), faction); *data << uint32(faction); } } @@ -1487,7 +1487,7 @@ void WorldObject::SendPlaySound(uint32 Sound, bool OnlySelf) WorldPacket data(SMSG_PLAY_SOUND, 4); data << Sound; if (OnlySelf && GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->GetSession()->SendPacket( &data ); + this->ToPlayer()->GetSession()->SendPacket( &data ); else SendMessageToSet( &data, true ); // ToSelf ignored in this case } @@ -1735,7 +1735,7 @@ TempSummon *Map::SummonCreature(uint32 entry, const Position &pos, SummonPropert { phase = summoner->GetPhaseMask(); if(summoner->GetTypeId() == TYPEID_PLAYER) - team = ((Player*)summoner)->GetTeam(); + team = summoner->ToPlayer()->GetTeam(); } TempSummon *summon = NULL; diff --git a/src/game/Object.h b/src/game/Object.h index d54c510a646..9544021a2a0 100644 --- a/src/game/Object.h +++ b/src/game/Object.h @@ -318,6 +318,10 @@ class Object // FG: some hacky helpers void ForceValuesUpdateAtIndex(uint32); + Player* ToPlayer(){ if(GetTypeId() == TYPEID_PLAYER) return reinterpret_cast<Player*>(this); else return NULL; } + const Player* ToPlayer() const { if(GetTypeId() == TYPEID_PLAYER) return (const Player*)((Player*)this); else return NULL; } + Creature* ToCreature(){ if(GetTypeId() == TYPEID_UNIT) return reinterpret_cast<Creature*>(this); else return NULL; } + protected: Object ( ); diff --git a/src/game/OutdoorPvPHP.cpp b/src/game/OutdoorPvPHP.cpp index 20c30cfeda8..fa1b89180a5 100644 --- a/src/game/OutdoorPvPHP.cpp +++ b/src/game/OutdoorPvPHP.cpp @@ -325,8 +325,8 @@ void OutdoorPvPHP::HandleKillImpl(Player *plr, Unit * killed) if(killed->GetTypeId() != TYPEID_PLAYER) return; - if(plr->GetTeam() == ALLIANCE && ((Player*)killed)->GetTeam() != ALLIANCE) + if(plr->GetTeam() == ALLIANCE && killed->ToPlayer()->GetTeam() != ALLIANCE) plr->CastSpell(plr,AlliancePlayerKillReward,true); - else if(plr->GetTeam() == HORDE && ((Player*)killed)->GetTeam() != HORDE) + else if(plr->GetTeam() == HORDE && killed->ToPlayer()->GetTeam() != HORDE) plr->CastSpell(plr,HordePlayerKillReward,true); } diff --git a/src/game/OutdoorPvPNA.cpp b/src/game/OutdoorPvPNA.cpp index 7fd9f3ba118..377940e512d 100644 --- a/src/game/OutdoorPvPNA.cpp +++ b/src/game/OutdoorPvPNA.cpp @@ -31,7 +31,7 @@ OutdoorPvPNA::OutdoorPvPNA() void OutdoorPvPNA::HandleKillImpl(Player *plr, Unit * killed) { - if(killed->GetTypeId() == TYPEID_PLAYER && plr->GetTeam() != ((Player*)killed)->GetTeam()) + if(killed->GetTypeId() == TYPEID_PLAYER && plr->GetTeam() != killed->ToPlayer()->GetTeam()) { plr->KilledMonsterCredit(NA_CREDIT_MARKER,0); // 0 guid, btw it isn't even used in killedmonster function :S if(plr->GetTeam() == ALLIANCE) diff --git a/src/game/OutdoorPvPZM.cpp b/src/game/OutdoorPvPZM.cpp index 0f85b1a58e8..559223a920a 100644 --- a/src/game/OutdoorPvPZM.cpp +++ b/src/game/OutdoorPvPZM.cpp @@ -195,9 +195,9 @@ void OutdoorPvPZM::HandleKillImpl(Player *plr, Unit * killed) if(killed->GetTypeId() != TYPEID_PLAYER) return; - if(plr->GetTeam() == ALLIANCE && ((Player*)killed)->GetTeam() != ALLIANCE) + if(plr->GetTeam() == ALLIANCE && killed->ToPlayer()->GetTeam() != ALLIANCE) plr->CastSpell(plr,ZM_AlliancePlayerKillReward,true); - else if(plr->GetTeam() == HORDE && ((Player*)killed)->GetTeam() != HORDE) + else if(plr->GetTeam() == HORDE && killed->ToPlayer()->GetTeam() != HORDE) plr->CastSpell(plr,ZM_HordePlayerKillReward,true); } diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 981f864136c..6f04823b4f9 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -338,7 +338,7 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool //set last used pet number (for use in BG's) if(owner->GetTypeId() == TYPEID_PLAYER && isControlled() && !isTemporarySummoned() && (getPetType() == SUMMON_PET || getPetType() == HUNTER_PET)) - ((Player*)owner)->SetLastPetNumber(pet_number); + owner->ToPlayer()->SetLastPetNumber(pet_number); m_loading = false; @@ -1523,7 +1523,7 @@ bool Pet::removeSpell(uint32 spell_id, bool learn_prev, bool clear_ab) // need update action bar for last removed rank if (Unit* owner = GetOwner()) if (owner->GetTypeId() == TYPEID_PLAYER) - ((Player*)owner)->PetSpellInitialize(); + owner->ToPlayer()->PetSpellInitialize(); } } @@ -1561,8 +1561,8 @@ bool Pet::resetTalents(bool no_cost) return false; // not need after this call - if (((Player*)owner)->HasAtLoginFlag(AT_LOGIN_RESET_PET_TALENTS)) - ((Player*)owner)->RemoveAtLoginFlag(AT_LOGIN_RESET_PET_TALENTS,true); + if (owner->ToPlayer()->HasAtLoginFlag(AT_LOGIN_RESET_PET_TALENTS)) + owner->ToPlayer()->RemoveAtLoginFlag(AT_LOGIN_RESET_PET_TALENTS,true); CreatureInfo const * ci = GetCreatureInfo(); if (!ci) @@ -1654,8 +1654,8 @@ bool Pet::resetTalents(bool no_cost) void Pet::resetTalentsForAllPetsOf(Player* owner, Pet* online_pet /*= NULL*/) { // not need after this call - if (((Player*)owner)->HasAtLoginFlag(AT_LOGIN_RESET_PET_TALENTS)) - ((Player*)owner)->RemoveAtLoginFlag(AT_LOGIN_RESET_PET_TALENTS,true); + if (owner->ToPlayer()->HasAtLoginFlag(AT_LOGIN_RESET_PET_TALENTS)) + owner->ToPlayer()->RemoveAtLoginFlag(AT_LOGIN_RESET_PET_TALENTS,true); // reset for online if (online_pet) @@ -1743,7 +1743,7 @@ void Pet::InitTalentForLevel() return; if (!m_loading) - ((Player*)owner)->SendTalentsInfoData(true); + owner->ToPlayer()->SendTalentsInfoData(true); } uint32 Pet::resetTalentsCost() const @@ -1894,7 +1894,7 @@ void Pet::CastPetAuras(bool current) if (!owner || owner->GetTypeId() != TYPEID_PLAYER) return; - if (!IsPermanentPetFor((Player*)owner)) + if (!IsPermanentPetFor(owner->ToPlayer())) return; for (PetAuraSet::const_iterator itr = owner->m_petAuras.begin(); itr != owner->m_petAuras.end();) diff --git a/src/game/PetAI.cpp b/src/game/PetAI.cpp index dda4a64abec..44571216aff 100644 --- a/src/game/PetAI.cpp +++ b/src/game/PetAI.cpp @@ -209,10 +209,10 @@ void PetAI::UpdateAI(const uint32 diff) { m_creature->SetInFront(target); if(target && target->GetTypeId() == TYPEID_PLAYER) - m_creature->SendUpdateToPlayer((Player*)target); + m_creature->SendUpdateToPlayer(target->ToPlayer()); if(owner && owner->GetTypeId() == TYPEID_PLAYER) - m_creature->SendUpdateToPlayer((Player*)owner); + m_creature->SendUpdateToPlayer(owner->ToPlayer()); } m_creature->AddCreatureSpellCooldown(spell->m_spellInfo->Id); @@ -236,7 +236,7 @@ void PetAI::UpdateAllies() if(!owner) return; else if(owner->GetTypeId() == TYPEID_PLAYER) - pGroup = ((Player*)owner)->GetGroup(); + pGroup = owner->ToPlayer()->GetGroup(); //only pet and owner/not in group->ok if(m_AllySet.size() == 2 && !pGroup) diff --git a/src/game/PetHandler.cpp b/src/game/PetHandler.cpp index f6d6cf3e2da..404770c16f0 100644 --- a/src/game/PetHandler.cpp +++ b/src/game/PetHandler.cpp @@ -284,7 +284,7 @@ void WorldSession::HandlePetActionHelper(Unit *pet, uint64 guid1, uint16 spellid } if (Unit* powner = pet->GetCharmerOrOwner()) if(powner->GetTypeId() == TYPEID_PLAYER) - pet->SendUpdateToPlayer((Player*)powner); + pet->SendUpdateToPlayer(powner->ToPlayer()); result = SPELL_CAST_OK; } @@ -535,8 +535,8 @@ void WorldSession::HandlePetRename( WorldPacket & recv_data ) pet->SetName(name); Unit *owner = pet->GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_NAME); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup()) + owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_NAME); pet->RemoveByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED); @@ -753,7 +753,7 @@ void WorldSession::HandlePetCastSpellOpcode( WorldPacket& recvPacket ) caster->SendPetCastFail(spellid, result); if(caster->GetTypeId() == TYPEID_PLAYER) { - if(!((Player*)caster)->HasSpellCooldown(spellid)) + if(!caster->ToPlayer()->HasSpellCooldown(spellid)) GetPlayer()->SendClearCooldown(spellid, caster); } else diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 342e48d24ff..5c12feccbe0 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -6378,7 +6378,7 @@ bool Player::RewardHonor(Unit *uVictim, uint32 groupsize, float honor, bool pvpt if(!uVictim || uVictim == this || uVictim->GetTypeId() != TYPEID_PLAYER) return false; - if( GetBGTeam() == ((Player*)uVictim)->GetBGTeam() ) + if( GetBGTeam() == uVictim->ToPlayer()->GetBGTeam() ) return false; return true; @@ -12624,15 +12624,15 @@ void Player::ApplyEnchantment(Item *item, EnchantmentSlot slot, bool apply, bool if (!pEnchant) return; - if (!ignore_condition && pEnchant->EnchantmentCondition && !((Player*)this)->EnchantmentFitsRequirements(pEnchant->EnchantmentCondition, -1)) + if (!ignore_condition && pEnchant->EnchantmentCondition && !this->ToPlayer()->EnchantmentFitsRequirements(pEnchant->EnchantmentCondition, -1)) return; - if ((pEnchant->requiredLevel) > ((Player*)this)->getLevel()) + if ((pEnchant->requiredLevel) > this->ToPlayer()->getLevel()) return; if ((pEnchant->requiredSkill) > 0) { - if ((pEnchant->requiredSkillValue) > (((Player*)this)->GetSkillValue(pEnchant->requiredSkill))) + if ((pEnchant->requiredSkillValue) > (this->ToPlayer()->GetSkillValue(pEnchant->requiredSkill))) return; } @@ -12766,111 +12766,111 @@ void Player::ApplyEnchantment(Item *item, EnchantmentSlot slot, bool apply, bool ApplyStatBuffMod(STAT_STAMINA, enchant_amount, apply); break; case ITEM_MOD_DEFENSE_SKILL_RATING: - ((Player*)this)->ApplyRatingMod(CR_DEFENSE_SKILL, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_DEFENSE_SKILL, enchant_amount, apply); sLog.outDebug("+ %u DEFENCE", enchant_amount); break; case ITEM_MOD_DODGE_RATING: - ((Player*)this)->ApplyRatingMod(CR_DODGE, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_DODGE, enchant_amount, apply); sLog.outDebug("+ %u DODGE", enchant_amount); break; case ITEM_MOD_PARRY_RATING: - ((Player*)this)->ApplyRatingMod(CR_PARRY, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_PARRY, enchant_amount, apply); sLog.outDebug("+ %u PARRY", enchant_amount); break; case ITEM_MOD_BLOCK_RATING: - ((Player*)this)->ApplyRatingMod(CR_BLOCK, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_BLOCK, enchant_amount, apply); sLog.outDebug("+ %u SHIELD_BLOCK", enchant_amount); break; case ITEM_MOD_HIT_MELEE_RATING: - ((Player*)this)->ApplyRatingMod(CR_HIT_MELEE, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_HIT_MELEE, enchant_amount, apply); sLog.outDebug("+ %u MELEE_HIT", enchant_amount); break; case ITEM_MOD_HIT_RANGED_RATING: - ((Player*)this)->ApplyRatingMod(CR_HIT_RANGED, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_HIT_RANGED, enchant_amount, apply); sLog.outDebug("+ %u RANGED_HIT", enchant_amount); break; case ITEM_MOD_HIT_SPELL_RATING: - ((Player*)this)->ApplyRatingMod(CR_HIT_SPELL, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_HIT_SPELL, enchant_amount, apply); sLog.outDebug("+ %u SPELL_HIT", enchant_amount); break; case ITEM_MOD_CRIT_MELEE_RATING: - ((Player*)this)->ApplyRatingMod(CR_CRIT_MELEE, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_CRIT_MELEE, enchant_amount, apply); sLog.outDebug("+ %u MELEE_CRIT", enchant_amount); break; case ITEM_MOD_CRIT_RANGED_RATING: - ((Player*)this)->ApplyRatingMod(CR_CRIT_RANGED, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_CRIT_RANGED, enchant_amount, apply); sLog.outDebug("+ %u RANGED_CRIT", enchant_amount); break; case ITEM_MOD_CRIT_SPELL_RATING: - ((Player*)this)->ApplyRatingMod(CR_CRIT_SPELL, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_CRIT_SPELL, enchant_amount, apply); sLog.outDebug("+ %u SPELL_CRIT", enchant_amount); break; // Values from ITEM_STAT_MELEE_HA_RATING to ITEM_MOD_HASTE_RANGED_RATING are never used // in Enchantments // case ITEM_MOD_HIT_TAKEN_MELEE_RATING: -// ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_MELEE, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_HIT_TAKEN_MELEE, enchant_amount, apply); // break; // case ITEM_MOD_HIT_TAKEN_RANGED_RATING: -// ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_RANGED, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_HIT_TAKEN_RANGED, enchant_amount, apply); // break; // case ITEM_MOD_HIT_TAKEN_SPELL_RATING: -// ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_SPELL, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_HIT_TAKEN_SPELL, enchant_amount, apply); // break; // case ITEM_MOD_CRIT_TAKEN_MELEE_RATING: -// ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_MELEE, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_CRIT_TAKEN_MELEE, enchant_amount, apply); // break; // case ITEM_MOD_CRIT_TAKEN_RANGED_RATING: -// ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_RANGED, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_CRIT_TAKEN_RANGED, enchant_amount, apply); // break; // case ITEM_MOD_CRIT_TAKEN_SPELL_RATING: -// ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_SPELL, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_CRIT_TAKEN_SPELL, enchant_amount, apply); // break; // case ITEM_MOD_HASTE_MELEE_RATING: -// ((Player*)this)->ApplyRatingMod(CR_HASTE_MELEE, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_HASTE_MELEE, enchant_amount, apply); // break; // case ITEM_MOD_HASTE_RANGED_RATING: -// ((Player*)this)->ApplyRatingMod(CR_HASTE_RANGED, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_HASTE_RANGED, enchant_amount, apply); // break; case ITEM_MOD_HASTE_SPELL_RATING: - ((Player*)this)->ApplyRatingMod(CR_HASTE_SPELL, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_HASTE_SPELL, enchant_amount, apply); break; case ITEM_MOD_HIT_RATING: - ((Player*)this)->ApplyRatingMod(CR_HIT_MELEE, enchant_amount, apply); - ((Player*)this)->ApplyRatingMod(CR_HIT_RANGED, enchant_amount, apply); - ((Player*)this)->ApplyRatingMod(CR_HIT_SPELL, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_HIT_MELEE, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_HIT_RANGED, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_HIT_SPELL, enchant_amount, apply); sLog.outDebug("+ %u HIT", enchant_amount); break; case ITEM_MOD_CRIT_RATING: - ((Player*)this)->ApplyRatingMod(CR_CRIT_MELEE, enchant_amount, apply); - ((Player*)this)->ApplyRatingMod(CR_CRIT_RANGED, enchant_amount, apply); - ((Player*)this)->ApplyRatingMod(CR_CRIT_SPELL, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_CRIT_MELEE, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_CRIT_RANGED, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_CRIT_SPELL, enchant_amount, apply); sLog.outDebug("+ %u CRITICAL", enchant_amount); break; // Values ITEM_MOD_HIT_TAKEN_RATING and ITEM_MOD_CRIT_TAKEN_RATING are never used in Enchantment // case ITEM_MOD_HIT_TAKEN_RATING: -// ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_MELEE, enchant_amount, apply); -// ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_RANGED, enchant_amount, apply); -// ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_SPELL, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_HIT_TAKEN_MELEE, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_HIT_TAKEN_RANGED, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_HIT_TAKEN_SPELL, enchant_amount, apply); // break; // case ITEM_MOD_CRIT_TAKEN_RATING: -// ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_MELEE, enchant_amount, apply); -// ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_RANGED, enchant_amount, apply); -// ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_SPELL, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_CRIT_TAKEN_MELEE, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_CRIT_TAKEN_RANGED, enchant_amount, apply); +// this->ToPlayer()->ApplyRatingMod(CR_CRIT_TAKEN_SPELL, enchant_amount, apply); // break; case ITEM_MOD_RESILIENCE_RATING: - ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_MELEE, enchant_amount, apply); - ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_RANGED, enchant_amount, apply); - ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_SPELL, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_CRIT_TAKEN_MELEE, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_CRIT_TAKEN_RANGED, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_CRIT_TAKEN_SPELL, enchant_amount, apply); sLog.outDebug("+ %u RESILIENCE", enchant_amount); break; case ITEM_MOD_HASTE_RATING: - ((Player*)this)->ApplyRatingMod(CR_HASTE_MELEE, enchant_amount, apply); - ((Player*)this)->ApplyRatingMod(CR_HASTE_RANGED, enchant_amount, apply); - ((Player*)this)->ApplyRatingMod(CR_HASTE_SPELL, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_HASTE_MELEE, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_HASTE_RANGED, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_HASTE_SPELL, enchant_amount, apply); sLog.outDebug("+ %u HASTE", enchant_amount); break; case ITEM_MOD_EXPERTISE_RATING: - ((Player*)this)->ApplyRatingMod(CR_EXPERTISE, enchant_amount, apply); + this->ToPlayer()->ApplyRatingMod(CR_EXPERTISE, enchant_amount, apply); sLog.outDebug("+ %u EXPERTISE", enchant_amount); break; case ITEM_MOD_ATTACK_POWER: @@ -13848,7 +13848,7 @@ void Player::AddQuest( Quest const *pQuest, Object *questGiver ) // shared timed quest if(questGiver && questGiver->GetTypeId() == TYPEID_PLAYER) - limittime = ((Player*)questGiver)->getQuestStatusMap()[quest_id].m_timer / IN_MILISECONDS; + limittime = questGiver->ToPlayer()->getQuestStatusMap()[quest_id].m_timer / IN_MILISECONDS; AddTimedQuest( quest_id ); questStatusData.m_timer = limittime * IN_MILISECONDS; @@ -19864,9 +19864,9 @@ bool Player::canSeeOrDetect(Unit const* u, bool detect, bool inVisibleList, bool // including case when player is out of world bool at_same_transport = GetTransport() && u->GetTypeId() == TYPEID_PLAYER - && !GetSession()->PlayerLogout() && !((Player*)u)->GetSession()->PlayerLogout() - && !GetSession()->PlayerLoading() && !((Player*)u)->GetSession()->PlayerLoading() - && GetTransport() == ((Player*)u)->GetTransport(); + && !GetSession()->PlayerLogout() && !u->ToPlayer()->GetSession()->PlayerLogout() + && !GetSession()->PlayerLoading() && !u->ToPlayer()->GetSession()->PlayerLoading() + && GetTransport() == u->ToPlayer()->GetTransport(); // not in world if(!at_same_transport && (!IsInWorld() || !u->IsInWorld())) @@ -19943,14 +19943,14 @@ bool Player::canSeeOrDetect(Unit const* u, bool detect, bool inVisibleList, bool if(isGameMaster()) { if(u->GetTypeId() == TYPEID_PLAYER) - return ((Player*)u)->GetSession()->GetSecurity() <= GetSession()->GetSecurity(); + return u->ToPlayer()->GetSession()->GetSecurity() <= GetSession()->GetSecurity(); else return true; } // player see other player with stealth/invisibility only if he in same group or raid or same team (raid/team case dependent from conf setting) if(!m_mover->canDetectInvisibilityOf(u)) - if(!(u->GetTypeId() == TYPEID_PLAYER && !IsHostileTo(u) && IsGroupVisibleFor(((Player*)u)))) + if(!(u->GetTypeId() == TYPEID_PLAYER && !IsHostileTo(u) && IsGroupVisibleFor(const_cast<Player*>(u->ToPlayer() )))) return false; } @@ -19963,7 +19963,7 @@ bool Player::canSeeOrDetect(Unit const* u, bool detect, bool inVisibleList, bool if(!isAlive()) detect = false; if(m_DetectInvTimer < 300 || !HaveAtClient(u)) - if(!(u->GetTypeId() == TYPEID_PLAYER && !IsHostileTo(u) && IsGroupVisibleFor(((Player*)u)))) + if(!(u->GetTypeId() == TYPEID_PLAYER && !IsHostileTo(u) && IsGroupVisibleFor(const_cast<Player*>(u->ToPlayer())))) if(!detect || !m_mover->canDetectStealthOf(u, GetDistance(u))) return false; } diff --git a/src/game/Player.h b/src/game/Player.h index 556b2dfe864..7b821ac5495 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -2309,6 +2309,7 @@ class Player : public Unit, public GridObject<Player> uint32 GetChampioningFaction() const { return m_ChampioningFaction; } void SetChampioningFaction(uint32 faction) { m_ChampioningFaction = faction; } Spell * m_spellModTakingSpell; + protected: uint32 m_AreaID; uint32 m_regenTimerCount; diff --git a/src/game/QuestHandler.cpp b/src/game/QuestHandler.cpp index d234e063d39..e7b7d82c06f 100644 --- a/src/game/QuestHandler.cpp +++ b/src/game/QuestHandler.cpp @@ -125,7 +125,7 @@ void WorldSession::HandleQuestgiverAcceptQuestOpcode( WorldPacket & recv_data ) // no or incorrect quest giver if(!pObject || (pObject->GetTypeId() != TYPEID_PLAYER && !pObject->hasQuest(quest)) - || (pObject->GetTypeId() == TYPEID_PLAYER && !((Player*)pObject)->CanShareQuest(quest)) + || (pObject->GetTypeId() == TYPEID_PLAYER && !pObject->ToPlayer()->CanShareQuest(quest)) ) { _player->PlayerTalkClass->CloseGossip(); diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 798db319dad..fc454dc03ff 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -211,11 +211,11 @@ void SpellCastTargets::Update(Unit* caster) if(caster->GetTypeId() == TYPEID_PLAYER) { if(m_targetMask & TARGET_FLAG_ITEM) - m_itemTarget = ((Player*)caster)->GetItemByGuid(m_itemTargetGUID); + m_itemTarget = caster->ToPlayer()->GetItemByGuid(m_itemTargetGUID); else if(m_targetMask & TARGET_FLAG_TRADE_ITEM) { // here it is not guid but slot - Player* pTrader = ((Player*)caster)->GetTrader(); + Player* pTrader = caster->ToPlayer()->GetTrader(); if(pTrader && m_itemTargetGUID < TRADE_SLOT_COUNT) m_itemTarget = pTrader->GetItemByGuid(m_itemTargetGUID); } @@ -415,7 +415,7 @@ Spell::Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 origi // wand case if((m_caster->getClassMask() & CLASSMASK_WAND_USERS) != 0 && m_caster->GetTypeId() == TYPEID_PLAYER) { - if(Item* pItem = ((Player*)m_caster)->GetWeaponForAttack(RANGED_ATTACK)) + if(Item* pItem = m_caster->ToPlayer()->GetWeaponForAttack(RANGED_ATTACK)) m_spellSchoolMask = SpellSchoolMask(1 << pItem->GetProto()->Damage[0].DamageType); } } @@ -493,7 +493,7 @@ Spell::Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 origi Spell::~Spell() { if(m_caster && m_caster->GetTypeId() == TYPEID_PLAYER) - assert(((Player*)m_caster)->m_spellModTakingSpell != this); + assert(m_caster->ToPlayer()->m_spellModTakingSpell != this); delete m_spellValue; } @@ -605,7 +605,7 @@ void Spell::SelectSpellTargets() { // clear cooldown at fail if(m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->RemoveSpellCooldown(m_spellInfo->Id, true); + m_caster->ToPlayer()->RemoveSpellCooldown(m_spellInfo->Id, true); SendCastResult(SPELL_FAILED_NO_EDIBLE_CORPSES); finish(false); } @@ -637,9 +637,9 @@ void Spell::SelectSpellTargets() AddUnitTarget(m_caster, i); break; case SPELL_EFFECT_SUMMON_PLAYER: - if(m_caster->GetTypeId() == TYPEID_PLAYER && ((Player*)m_caster)->GetSelection()) + if(m_caster->GetTypeId() == TYPEID_PLAYER && m_caster->ToPlayer()->GetSelection()) { - Player* target = objmgr.GetPlayer(((Player*)m_caster)->GetSelection()); + Player* target = objmgr.GetPlayer(m_caster->ToPlayer()->GetSelection()); if(target) AddUnitTarget(target, i); } @@ -1251,7 +1251,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo *target) if(unit->IsPvP()) { if (m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->UpdatePvP(true); + m_caster->ToPlayer()->UpdatePvP(true); } } @@ -1268,13 +1268,13 @@ SpellMissInfo Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask, bool if (unit->GetTypeId() == TYPEID_PLAYER) { - ((Player*)unit)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET, m_spellInfo->Id); - ((Player*)unit)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2, m_spellInfo->Id); + unit->ToPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET, m_spellInfo->Id); + unit->ToPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2, m_spellInfo->Id); } if(m_caster->GetTypeId() == TYPEID_PLAYER) { - ((Player*)m_caster)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2, m_spellInfo->Id, 0, unit); + m_caster->ToPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2, m_spellInfo->Id, 0, unit); } if( m_caster != unit ) @@ -1320,7 +1320,7 @@ SpellMissInfo Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask, bool { m_caster->SetContestedPvP(); if(m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->UpdatePvP(true); + m_caster->ToPlayer()->UpdatePvP(true); } if( unit->isInCombat() && !(m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_NO_INITIAL_AGGRO) ) { @@ -1576,7 +1576,7 @@ struct ChainHealingOrder : public std::binary_function<const Unit*, const Unit*, /*if (Target == MainTarget) return 0; else*/ if (Target->GetTypeId() == TYPEID_PLAYER && MainTarget->GetTypeId() == TYPEID_PLAYER && - ((Player const*)Target)->IsInSameRaidWith((Player const*)MainTarget)) + Target->ToPlayer()->IsInSameRaidWith(MainTarget->ToPlayer())) { if (Target->GetHealth() == Target->GetMaxHealth()) return 40000; @@ -2110,7 +2110,7 @@ void Spell::SelectEffectTargets(uint32 i, uint32 cur) break; case TARGET_DST_HOME: if(m_caster->GetTypeId() == TYPEID_PLAYER) - m_targets.setDst(((Player*)m_caster)->m_homebindX,((Player*)m_caster)->m_homebindY,((Player*)m_caster)->m_homebindZ, ((Player*)m_caster)->GetOrientation(), ((Player*)m_caster)->m_homebindMapId); + m_targets.setDst(m_caster->ToPlayer()->m_homebindX,m_caster->ToPlayer()->m_homebindY,m_caster->ToPlayer()->m_homebindZ, m_caster->ToPlayer()->GetOrientation(), m_caster->ToPlayer()->m_homebindMapId); break; case TARGET_DST_NEARBY_ENTRY: { @@ -2324,7 +2324,7 @@ void Spell::SelectEffectTargets(uint32 i, uint32 cur) else { if (m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->RemoveSpellCooldown(m_spellInfo->Id,true); + m_caster->ToPlayer()->RemoveSpellCooldown(m_spellInfo->Id,true); SendCastResult(SPELL_FAILED_CANT_DO_THAT_RIGHT_NOW); finish(false); } @@ -2576,7 +2576,7 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect const * triggere if(m_caster->GetTypeId() == TYPEID_UNIT) target = m_caster->getVictim(); else - target = ObjectAccessor::GetUnit(*m_caster, ((Player*)m_caster)->GetSelection()); + target = ObjectAccessor::GetUnit(*m_caster, m_caster->ToPlayer()->GetSelection()); if (target && IsValidSingleTargetSpell(target)) m_targets.setUnitTarget(target); @@ -2654,11 +2654,11 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect const * triggere } if (m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->SetSpellModTakingSpell(this, true); + m_caster->ToPlayer()->SetSpellModTakingSpell(this, true); // Fill cost data (not use power for item casts m_powerCost = m_CastItem ? 0 : CalculatePowerCost(m_spellInfo, m_caster, m_spellSchoolMask); if (m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->SetSpellModTakingSpell(this, false); + m_caster->ToPlayer()->SetSpellModTakingSpell(this, false); SpellCastResult result = CheckCast(true); if(result != SPELL_CAST_OK && !IsAutoRepeat()) //always cast autorepeat dummy for triggering @@ -2761,7 +2761,7 @@ void Spell::cancel() // spell is canceled-take mods and clear list if (m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->RemoveSpellMods(this); + m_caster->ToPlayer()->RemoveSpellMods(this); m_appliedMods.clear(); } break; @@ -2819,7 +2819,7 @@ void Spell::cast(bool skipCheck) { // Set spell which will drop charges for triggered cast spells // if not successfully casted, will be remove in finish(false) - ((Player*)m_caster)->SetSpellModTakingSpell(this, true); + m_caster->ToPlayer()->SetSpellModTakingSpell(this, true); } // triggered cast called from Spell::prepare where it was already checked @@ -2833,10 +2833,10 @@ void Spell::cast(bool skipCheck) //restore spell mods if (m_caster->GetTypeId() == TYPEID_PLAYER) { - ((Player*)m_caster)->RestoreSpellMods(this); + m_caster->ToPlayer()->RestoreSpellMods(this); // cleanup after mod system // triggered spell pointer can be not removed in some cases - ((Player*)m_caster)->SetSpellModTakingSpell(this, false); + m_caster->ToPlayer()->SetSpellModTakingSpell(this, false); } finish(false); SetExecutedCurrently(false); @@ -2853,10 +2853,10 @@ void Spell::cast(bool skipCheck) //restore spell mods if (m_caster->GetTypeId() == TYPEID_PLAYER) { - ((Player*)m_caster)->RestoreSpellMods(this); + m_caster->ToPlayer()->RestoreSpellMods(this); // cleanup after mod system // triggered spell pointer can be not removed in some cases - ((Player*)m_caster)->SetSpellModTakingSpell(this, false); + m_caster->ToPlayer()->SetSpellModTakingSpell(this, false); } finish(false); SetExecutedCurrently(false); @@ -2893,9 +2893,9 @@ void Spell::cast(bool skipCheck) if (m_caster->GetTypeId() == TYPEID_PLAYER) { if (!m_IsTriggeredSpell && m_CastItem) - ((Player*)m_caster)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM, m_CastItem->GetEntry()); + m_caster->ToPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM, m_CastItem->GetEntry()); - ((Player*)m_caster)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL, m_spellInfo->Id); + m_caster->ToPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL, m_spellInfo->Id); } if(!m_IsTriggeredSpell) @@ -2978,7 +2978,7 @@ void Spell::cast(bool skipCheck) } if (m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->SetSpellModTakingSpell(this, false); + m_caster->ToPlayer()->SetSpellModTakingSpell(this, false); SetExecutedCurrently(false); } @@ -3026,7 +3026,7 @@ uint64 Spell::handle_delayed(uint64 t_offset) UpdatePointers(); if (m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->SetSpellModTakingSpell(this, true); + m_caster->ToPlayer()->SetSpellModTakingSpell(this, true); uint64 next_time = 0; @@ -3063,7 +3063,7 @@ uint64 Spell::handle_delayed(uint64 t_offset) } if (m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->SetSpellModTakingSpell(this, false); + m_caster->ToPlayer()->SetSpellModTakingSpell(this, false); // All targets passed - need finish phase if (next_time == 0) @@ -3384,11 +3384,11 @@ void Spell::finish(bool ok) if (m_caster->GetTypeId() == TYPEID_PLAYER) { if (!m_triggeredByAuraSpell) - ((Player*)m_caster)->UpdatePotionCooldown(this); + m_caster->ToPlayer()->UpdatePotionCooldown(this); // triggered spell pointer can be not set in some cases // this is needed for proper apply of triggered spell mods - ((Player*)m_caster)->SetSpellModTakingSpell(this, true); + m_caster->ToPlayer()->SetSpellModTakingSpell(this, true); } // call triggered spell only at successful cast (after clear combo points -> for add some if need) @@ -3400,8 +3400,8 @@ void Spell::finish(bool ok) // mods are taken only on succesfull cast and independantly from targets of the spell if (m_caster->GetTypeId() == TYPEID_PLAYER) { - ((Player*)m_caster)->RemoveSpellMods(this); - ((Player*)m_caster)->SetSpellModTakingSpell(this, false); + m_caster->ToPlayer()->RemoveSpellMods(this); + m_caster->ToPlayer()->SetSpellModTakingSpell(this, false); } // Stop Attack for some spells @@ -3417,7 +3417,7 @@ void Spell::SendCastResult(SpellCastResult result) if (m_caster->GetTypeId() != TYPEID_PLAYER) return; - if(((Player*)m_caster)->GetSession()->PlayerLoading()) // don't send cast results at loading time + if(m_caster->ToPlayer()->GetSession()->PlayerLoading()) // don't send cast results at loading time return; SendCastResult((Player*)m_caster,m_spellInfo,m_cast_count,result); @@ -3598,7 +3598,7 @@ void Spell::SendSpellGo() if ( castFlags & CAST_FLAG_RUNE_LIST ) // rune cooldowns list { uint8 v1 = m_runesState; - uint8 v2 = ((Player*)m_caster)->GetRunesState(); + uint8 v2 = m_caster->ToPlayer()->GetRunesState(); data << uint8(v1); // runes state before data << uint8(v2); // runes state after for (uint8 i = 0; i < MAX_RUNES; ++i) @@ -3640,7 +3640,7 @@ void Spell::WriteAmmoToPacket( WorldPacket * data ) if (m_caster->GetTypeId() == TYPEID_PLAYER) { - Item *pItem = ((Player*)m_caster)->GetWeaponForAttack( RANGED_ATTACK ); + Item *pItem = m_caster->ToPlayer()->GetWeaponForAttack( RANGED_ATTACK ); if(pItem) { ammoInventoryType = pItem->GetProto()->InventoryType; @@ -3648,7 +3648,7 @@ void Spell::WriteAmmoToPacket( WorldPacket * data ) ammoDisplayID = pItem->GetProto()->DisplayInfoID; else { - uint32 ammoID = ((Player*)m_caster)->GetUInt32Value(PLAYER_AMMO_ID); + uint32 ammoID = m_caster->ToPlayer()->GetUInt32Value(PLAYER_AMMO_ID); if(ammoID) { ItemPrototype const *pProto = objmgr.GetItemPrototype( ammoID ); @@ -3964,7 +3964,7 @@ void Spell::SendPlaySpellVisual(uint32 SpellID) WorldPacket data(SMSG_PLAY_SPELL_VISUAL, 8 + 4); data << uint64(m_caster->GetGUID()); data << uint32(SpellID); // spell visual id? - ((Player*)m_caster)->GetSession()->SendPacket(&data); + m_caster->ToPlayer()->GetSession()->SendPacket(&data); } void Spell::TakeCastItem() @@ -4019,7 +4019,7 @@ void Spell::TakeCastItem() if (expendable && withoutCharges) { uint32 count = 1; - ((Player*)m_caster)->DestroyItemCount(m_CastItem, count, true); + m_caster->ToPlayer()->DestroyItemCount(m_CastItem, count, true); // prevent crash at access to deleted m_targets.getItemTarget if(m_CastItem==m_targets.getItemTarget()) @@ -4047,7 +4047,7 @@ void Spell::TakePower() if (ihit->missCondition != SPELL_MISS_NONE) { //lower spell cost on fail (by talent aura) - if(Player *modOwner = ((Player*)m_caster)->GetSpellModOwner()) + if(Player *modOwner = m_caster->ToPlayer()->GetSpellModOwner()) modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_SPELL_COST_REFUND_ON_FAIL, m_powerCost); } break; @@ -4092,7 +4092,7 @@ void Spell::TakeAmmo() { if(m_attackType == RANGED_ATTACK && m_caster->GetTypeId() == TYPEID_PLAYER) { - Item *pItem = ((Player*)m_caster)->GetWeaponForAttack( RANGED_ATTACK ); + Item *pItem = m_caster->ToPlayer()->GetWeaponForAttack( RANGED_ATTACK ); // wands don't have ammo if(!pItem || pItem->IsBroken() || pItem->GetProto()->SubClass==ITEM_SUBCLASS_WEAPON_WAND) @@ -4103,17 +4103,17 @@ void Spell::TakeAmmo() if(pItem->GetMaxStackCount()==1) { // decrease durability for non-stackable throw weapon - ((Player*)m_caster)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_RANGED); + m_caster->ToPlayer()->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_RANGED); } else { // decrease items amount for stackable throw weapon uint32 count = 1; - ((Player*)m_caster)->DestroyItemCount( pItem, count, true); + m_caster->ToPlayer()->DestroyItemCount( pItem, count, true); } } - else if(uint32 ammo = ((Player*)m_caster)->GetUInt32Value(PLAYER_AMMO_ID)) - ((Player*)m_caster)->DestroyItemCount(ammo, 1, true); + else if(uint32 ammo = m_caster->ToPlayer()->GetUInt32Value(PLAYER_AMMO_ID)) + m_caster->ToPlayer()->DestroyItemCount(ammo, 1, true); } } @@ -4346,10 +4346,10 @@ SpellCastResult Spell::CheckCast(bool strict) if(m_caster->GetTypeId() == TYPEID_PLAYER && !(m_spellInfo->Attributes & SPELL_ATTR_PASSIVE)) { //can cast triggered (by aura only?) spells while have this flag - if (!m_IsTriggeredSpell && ((Player*)m_caster)->HasFlag(PLAYER_FLAGS, PLAYER_ALLOW_ONLY_ABILITY)) + if (!m_IsTriggeredSpell && m_caster->ToPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_ALLOW_ONLY_ABILITY)) return SPELL_FAILED_SPELL_IN_PROGRESS; - if (((Player*)m_caster)->HasSpellCooldown(m_spellInfo->Id)) + if (m_caster->ToPlayer()->HasSpellCooldown(m_spellInfo->Id)) { if(m_triggeredByAuraSpell) return SPELL_FAILED_DONT_REPORT; @@ -4360,7 +4360,7 @@ SpellCastResult Spell::CheckCast(bool strict) // only allow triggered spells if at an ended battleground if( !m_IsTriggeredSpell && m_caster->GetTypeId() == TYPEID_PLAYER) - if(BattleGround * bg = ((Player*)m_caster)->GetBattleGround()) + if(BattleGround * bg = m_caster->ToPlayer()->GetBattleGround()) if(bg->GetStatus() == STATUS_WAIT_LEAVE) return SPELL_FAILED_DONT_REPORT; @@ -4425,10 +4425,10 @@ SpellCastResult Spell::CheckCast(bool strict) // cancel autorepeat spells if cast start when moving // (not wand currently autorepeat cast delayed to moving stop anyway in spell update code) - if( m_caster->GetTypeId() == TYPEID_PLAYER && ((Player*)m_caster)->isMoving() ) + if( m_caster->GetTypeId() == TYPEID_PLAYER && m_caster->ToPlayer()->isMoving() ) { // skip stuck spell to allow use it in falling case and apply spell limitations at movement - if( (!((Player*)m_caster)->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_FALLING) || m_spellInfo->Effect[0] != SPELL_EFFECT_STUCK) && + if( (!m_caster->ToPlayer()->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_FALLING) || m_spellInfo->Effect[0] != SPELL_EFFECT_STUCK) && (IsAutoRepeat() || (m_spellInfo->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED) != 0) ) return SPELL_FAILED_MOVING; } @@ -4469,7 +4469,7 @@ SpellCastResult Spell::CheckCast(bool strict) // Not allow banish not self target if (m_spellInfo->Mechanic == MECHANIC_BANISH) if (target->GetTypeId() == TYPEID_UNIT && - !((Player*)m_caster)->isAllowedToLoot((Creature*)target)) + !m_caster->ToPlayer()->isAllowedToLoot((Creature*)target)) return SPELL_FAILED_CANT_CAST_ON_TAPPED; if (m_customAttr & SPELL_ATTR_CU_PICKPOCKET) @@ -4485,7 +4485,7 @@ SpellCastResult Spell::CheckCast(bool strict) { if (target->GetTypeId() == TYPEID_PLAYER) { - if(!((Player*)target)->GetWeaponForAttack(BASE_ATTACK) || !((Player*)target)->IsUseEquipedWeapon(true)) + if(!target->ToPlayer()->GetWeaponForAttack(BASE_ATTACK) || !target->ToPlayer()->IsUseEquipedWeapon(true)) return SPELL_FAILED_TARGET_NO_WEAPONS; } else if (!target->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID)) @@ -4600,7 +4600,7 @@ SpellCastResult Spell::CheckCast(bool strict) // Spell casted only on battleground if ((m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_BATTLEGROUND) && m_caster->GetTypeId() == TYPEID_PLAYER) - if(!((Player*)m_caster)->InBattleGround()) + if(!m_caster->ToPlayer()->InBattleGround()) return SPELL_FAILED_ONLY_BATTLEGROUNDS; // do not allow spells to be cast in arenas @@ -4613,13 +4613,13 @@ SpellCastResult Spell::CheckCast(bool strict) return SPELL_FAILED_NOT_IN_ARENA; // zone check - if(m_caster->GetTypeId() == TYPEID_UNIT || !((Player*)m_caster)->isGameMaster()) + if(m_caster->GetTypeId() == TYPEID_UNIT || !m_caster->ToPlayer()->isGameMaster()) { uint32 zone, area; m_caster->GetZoneAndAreaId(zone,area); SpellCastResult locRes= spellmgr.GetSpellAllowedInLocationError(m_spellInfo,m_caster->GetMapId(),zone,area, - m_caster->GetTypeId() == TYPEID_PLAYER ? ((Player*)m_caster) : NULL); + m_caster->GetTypeId() == TYPEID_PLAYER ? m_caster->ToPlayer() : NULL); if(locRes != SPELL_CAST_OK) return locRes; } @@ -4853,7 +4853,7 @@ SpellCastResult Spell::CheckCast(bool strict) if(m_spellInfo->EffectImplicitTargetA[i] != TARGET_UNIT_PET) break; - Pet* pet = ((Player*)m_caster)->GetPet(); + Pet* pet = m_caster->ToPlayer()->GetPet(); if(!pet) return SPELL_FAILED_NO_PET; @@ -4873,7 +4873,7 @@ SpellCastResult Spell::CheckCast(bool strict) if (m_caster->GetTypeId() != TYPEID_PLAYER) return SPELL_FAILED_BAD_TARGETS; - Pet* pet = ((Player*)m_caster)->GetPet(); + Pet* pet = m_caster->ToPlayer()->GetPet(); if(!pet) return SPELL_FAILED_NO_PET; @@ -4904,7 +4904,7 @@ SpellCastResult Spell::CheckCast(bool strict) if(!foodItem) return SPELL_FAILED_BAD_TARGETS; - Pet* pet = ((Player*)m_caster)->GetPet(); + Pet* pet = m_caster->ToPlayer()->GetPet(); if(!pet) return SPELL_FAILED_NO_PET; @@ -4958,7 +4958,7 @@ SpellCastResult Spell::CheckCast(bool strict) uint32 skill = creature->GetCreatureInfo()->GetRequiredLootSkill(); - int32 skillValue = ((Player*)m_caster)->GetSkillValue(skill); + int32 skillValue = m_caster->ToPlayer()->GetSkillValue(skill); int32 TargetLevel = m_targets.getUnitTarget()->getLevel(); int32 ReqValue = (skillValue < 100 ? (TargetLevel-10) * 10 : TargetLevel * 5); if (ReqValue > skillValue) @@ -4987,8 +4987,8 @@ SpellCastResult Spell::CheckCast(bool strict) return SPELL_FAILED_BAD_TARGETS; // In BattleGround players can use only flags and banners - if( ((Player*)m_caster)->InBattleGround() && - !((Player*)m_caster)->CanUseBattleGroundObject() ) + if( m_caster->ToPlayer()->InBattleGround() && + !m_caster->ToPlayer()->CanUseBattleGroundObject() ) return SPELL_FAILED_TRY_AGAIN; // get the lock entry @@ -5059,7 +5059,7 @@ SpellCastResult Spell::CheckCast(bool strict) if (m_caster->GetTypeId() == TYPEID_PLAYER && m_caster->getClass()==CLASS_WARLOCK) { if (strict) //starting cast, trigger pet stun (cast by pet so it doesn't attack player) - if(Pet* pet = ((Player*)m_caster)->GetPet()) + if(Pet* pet = m_caster->ToPlayer()->GetPet()) pet->CastSpell(pet, 32752, true, NULL, NULL, pet->GetGUID()); } else @@ -5075,11 +5075,11 @@ SpellCastResult Spell::CheckCast(bool strict) { if(m_caster->GetTypeId() != TYPEID_PLAYER) return SPELL_FAILED_BAD_TARGETS; - if(!((Player*)m_caster)->GetSelection()) + if(!m_caster->ToPlayer()->GetSelection()) return SPELL_FAILED_BAD_TARGETS; - Player* target = objmgr.GetPlayer(((Player*)m_caster)->GetSelection()); - if( !target || ((Player*)m_caster) == target || !target->IsInSameRaidWith((Player*)m_caster) ) + Player* target = objmgr.GetPlayer(m_caster->ToPlayer()->GetSelection()); + if( !target || m_caster->ToPlayer() == target || !target->IsInSameRaidWith(m_caster->ToPlayer()) ) return SPELL_FAILED_BAD_TARGETS; // check if our map is dungeon @@ -5098,7 +5098,7 @@ SpellCastResult Spell::CheckCast(bool strict) { //Do not allow to cast it before BG starts. if(m_caster->GetTypeId() == TYPEID_PLAYER) - if(BattleGround const *bg = ((Player*)m_caster)->GetBattleGround()) + if(BattleGround const *bg = m_caster->ToPlayer()->GetBattleGround()) if(bg->GetStatus() != STATUS_IN_PROGRESS) return SPELL_FAILED_TRY_AGAIN; break; @@ -5131,7 +5131,7 @@ SpellCastResult Spell::CheckCast(bool strict) break; } case 61336: - if(m_caster->GetTypeId() != TYPEID_PLAYER || !((Player*)m_caster)->IsInFeralForm()) + if(m_caster->GetTypeId() != TYPEID_PLAYER || !m_caster->ToPlayer()->IsInFeralForm()) return SPELL_FAILED_ONLY_SHAPESHIFT; break; // Wild Growth @@ -5147,7 +5147,7 @@ SpellCastResult Spell::CheckCast(bool strict) if (!target || target->GetTypeId() != TYPEID_PLAYER) return SPELL_FAILED_BAD_TARGETS; - if (!((Player*)m_caster)->IsInSameRaidWith(((Player*)target))) + if (!m_caster->ToPlayer()->IsInSameRaidWith(target->ToPlayer())) return SPELL_FAILED_TARGET_NOT_IN_RAID; break; @@ -5166,7 +5166,7 @@ SpellCastResult Spell::CheckCast(bool strict) return SPELL_FAILED_HIGHLEVEL; // use SMSG_PET_TAME_FAILURE? - if (!target->GetCreatureInfo()->isTameable (((Player*)m_caster)->CanTameExoticPets())) + if (!target->GetCreatureInfo()->isTameable (m_caster->ToPlayer()->CanTameExoticPets())) return SPELL_FAILED_BAD_TARGETS; if(m_caster->GetPetGUID()) @@ -5196,7 +5196,7 @@ SpellCastResult Spell::CheckCast(bool strict) if(m_caster->GetTypeId() != TYPEID_PLAYER) return SPELL_FAILED_NO_PET; - Pet *pet = ((Player*)m_caster)->GetPet(); + Pet *pet = m_caster->ToPlayer()->GetPet(); if(!pet) return SPELL_FAILED_NO_PET; @@ -5241,7 +5241,7 @@ SpellCastResult Spell::CheckCast(bool strict) if (m_caster->IsInWater()) return SPELL_FAILED_ONLY_ABOVEWATER; - if (m_caster->GetTypeId() == TYPEID_PLAYER && ((Player*)m_caster)->GetTransport()) + if (m_caster->GetTypeId() == TYPEID_PLAYER && m_caster->ToPlayer()->GetTransport()) return SPELL_FAILED_NO_MOUNTS_ALLOWED; // Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells @@ -5687,7 +5687,7 @@ SpellCastResult Spell::CheckItems() // if not item target then required item must be equipped else { - if(m_caster->GetTypeId() == TYPEID_PLAYER && !((Player*)m_caster)->HasItemFitToSpellReqirements(m_spellInfo)) + if(m_caster->GetTypeId() == TYPEID_PLAYER && !m_caster->ToPlayer()->HasItemFitToSpellReqirements(m_spellInfo)) return SPELL_FAILED_EQUIPPED_ITEM_CLASS; } @@ -5955,7 +5955,7 @@ SpellCastResult Spell::CheckItems() if(m_caster->GetTypeId() != TYPEID_PLAYER) return SPELL_FAILED_TARGET_NOT_PLAYER; if( m_attackType != RANGED_ATTACK ) break; - Item *pItem = ((Player*)m_caster)->GetWeaponForAttack(m_attackType); + Item *pItem = m_caster->ToPlayer()->GetWeaponForAttack(m_attackType); if(!pItem || pItem->IsBroken()) return SPELL_FAILED_EQUIPPED_ITEM; @@ -5964,14 +5964,14 @@ SpellCastResult Spell::CheckItems() case ITEM_SUBCLASS_WEAPON_THROWN: { uint32 ammo = pItem->GetEntry(); - if( !((Player*)m_caster)->HasItemCount( ammo, 1 ) ) + if( !m_caster->ToPlayer()->HasItemCount( ammo, 1 ) ) return SPELL_FAILED_NO_AMMO; }; break; case ITEM_SUBCLASS_WEAPON_GUN: case ITEM_SUBCLASS_WEAPON_BOW: case ITEM_SUBCLASS_WEAPON_CROSSBOW: { - uint32 ammo = ((Player*)m_caster)->GetUInt32Value(PLAYER_AMMO_ID); + uint32 ammo = m_caster->ToPlayer()->GetUInt32Value(PLAYER_AMMO_ID); if(!ammo) { // Requires No Ammo @@ -6004,7 +6004,7 @@ SpellCastResult Spell::CheckItems() return SPELL_FAILED_NO_AMMO; } - if( !((Player*)m_caster)->HasItemCount( ammo, 1 ) ) + if( !m_caster->ToPlayer()->HasItemCount( ammo, 1 ) ) return SPELL_FAILED_NO_AMMO; }; break; case ITEM_SUBCLASS_WEAPON_WAND: @@ -6041,7 +6041,7 @@ SpellCastResult Spell::CheckItems() // main hand weapon required if(m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_MAIN_HAND) { - Item* item = ((Player*)m_caster)->GetWeaponForAttack(BASE_ATTACK); + Item* item = m_caster->ToPlayer()->GetWeaponForAttack(BASE_ATTACK); // skip spell if no weapon in slot or broken if(!item || item->IsBroken() ) @@ -6055,7 +6055,7 @@ SpellCastResult Spell::CheckItems() // offhand hand weapon required if(m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_REQ_OFFHAND) { - Item* item = ((Player*)m_caster)->GetWeaponForAttack(OFF_ATTACK); + Item* item = m_caster->ToPlayer()->GetWeaponForAttack(OFF_ATTACK); // skip spell if no weapon in slot or broken if(!item || item->IsBroken() ) @@ -6088,7 +6088,7 @@ void Spell::Delayed() // only called in DealDamage() //check pushback reduce int32 delaytime = 500; // spellcasting delay is normally 500ms int32 delayReduce = 100; // must be initialized to 100 for percent modifiers - ((Player*)m_caster)->ApplySpellMod(m_spellInfo->Id, SPELLMOD_NOT_LOSE_CASTING_TIME, delayReduce, this); + m_caster->ToPlayer()->ApplySpellMod(m_spellInfo->Id, SPELLMOD_NOT_LOSE_CASTING_TIME, delayReduce, this); delayReduce += m_caster->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK) - 100; if(delayReduce >= 100) return; @@ -6123,7 +6123,7 @@ void Spell::DelayedChannel() //check pushback reduce int32 delaytime = GetSpellDuration(m_spellInfo) * 25 / 100; // channeling delay is normally 25% of its time per hit int32 delayReduce = 100; // must be initialized to 100 for percent modifiers - ((Player*)m_caster)->ApplySpellMod(m_spellInfo->Id, SPELLMOD_NOT_LOSE_CASTING_TIME, delayReduce, this); + m_caster->ToPlayer()->ApplySpellMod(m_spellInfo->Id, SPELLMOD_NOT_LOSE_CASTING_TIME, delayReduce, this); delayReduce += m_caster->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK) - 100; if(delayReduce >= 100) return; @@ -6164,7 +6164,7 @@ void Spell::UpdatePointers() } if (m_castItemGUID && m_caster->GetTypeId() == TYPEID_PLAYER) - m_CastItem = ((Player*)m_caster)->GetItemByGuid(m_castItemGUID); + m_CastItem = m_caster->ToPlayer()->GetItemByGuid(m_castItemGUID); m_targets.Update(m_caster); } @@ -6246,10 +6246,10 @@ bool Spell::CheckTarget(Unit* target, uint32 eff) //Check player targets and remove if in GM mode or GM invisibility (for not self casting case) if( target != m_caster && target->GetTypeId() == TYPEID_PLAYER) { - if(((Player*)target)->GetVisibility() == VISIBILITY_OFF) + if(target->ToPlayer()->GetVisibility() == VISIBILITY_OFF) return false; - if(((Player*)target)->isGameMaster() && !IsPositiveSpell(m_spellInfo->Id)) + if(target->ToPlayer()->isGameMaster() && !IsPositiveSpell(m_spellInfo->Id)) return false; } @@ -6672,7 +6672,7 @@ SpellCastResult Spell::CanOpenLock(uint32 effIndex, uint32 lockId, SkillType& sk // castitem check: rogue using skeleton keys. the skill values should not be added in this case. skillValue = m_CastItem || m_caster->GetTypeId()!= TYPEID_PLAYER ? - 0 : ((Player*)m_caster)->GetSkillValue(skillId); + 0 : m_caster->ToPlayer()->GetSkillValue(skillId); skillValue += spellSkillBonus; diff --git a/src/game/SpellAuraEffects.cpp b/src/game/SpellAuraEffects.cpp index c352a72ef4f..45d3d576fcf 100644 --- a/src/game/SpellAuraEffects.cpp +++ b/src/game/SpellAuraEffects.cpp @@ -559,7 +559,7 @@ int32 AuraEffect::CalculateAmount(Unit * caster) //4 points: ${($m1+$b1*4+0.03428571*$AP)*7} damage over 14 secs //5 points: ${($m1+$b1*5+0.0375*$AP)*8} damage over 16 secs float AP_per_combo[6] = {0.0f, 0.015f, 0.024f, 0.03f, 0.03428571f, 0.0375f}; - uint8 cp = ((Player*)caster)->GetComboPoints(); + uint8 cp = caster->ToPlayer()->GetComboPoints(); if (cp > 5) cp = 5; amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * AP_per_combo[cp]); } @@ -571,7 +571,7 @@ int32 AuraEffect::CalculateAmount(Unit * caster) if (caster->GetTypeId() != TYPEID_PLAYER) break; - uint8 cp = ((Player*)caster)->GetComboPoints(); + uint8 cp = caster->ToPlayer()->GetComboPoints(); // Idol of Feral Shadows. Cant be handled as SpellMod in SpellAura:Dummy due its dependency from CPs if (AuraEffect const * aurEff = caster->GetAuraEffect(34241,0)) @@ -634,7 +634,7 @@ int32 AuraEffect::CalculateAmount(Unit * caster) if (caster->GetTypeId() == TYPEID_PLAYER) { int32 value = int32((amount*-1)-10); - uint32 defva = uint32(((Player*)caster)->GetSkillValue(SKILL_DEFENSE) + ((Player*)caster)->GetRatingBonusValue(CR_DEFENSE_SKILL)); + uint32 defva = uint32(caster->ToPlayer()->GetSkillValue(SKILL_DEFENSE) + caster->ToPlayer()->GetRatingBonusValue(CR_DEFENSE_SKILL)); if(defva > 400) value += int32((defva-400)*0.15); @@ -933,7 +933,7 @@ void AuraEffect::ApplySpellMod(Unit * target, bool apply) if(!m_spellmod || target->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)target)->AddSpellMod(m_spellmod, apply); + target->ToPlayer()->AddSpellMod(m_spellmod, apply); // Auras with charges do not mod amount of passive auras if (GetBase()->GetCharges()) @@ -1050,7 +1050,7 @@ void AuraEffect::UpdatePeriodic(Unit * caster) if (target->GetTypeId() != TYPEID_PLAYER) break; - if (((Player*)target)->isMoving()) + if (target->ToPlayer()->isMoving()) m_amount = target->CalculateSpellDamage(m_spellProto,m_effIndex,m_baseAmount,target); else --m_amount; @@ -1093,7 +1093,7 @@ void AuraEffect::UpdatePeriodic(Unit * caster) else { // default case - not in arena - if (!((Player*)caster)->InArena()) + if (!caster->ToPlayer()->InArena()) { aurEff->ChangeAmount(GetAmount()); m_isPeriodic = false; @@ -1467,8 +1467,8 @@ void AuraEffect::PeriodicTick(Unit * target, Unit * caster) const // add HoTs to amount healed in bgs if( caster->GetTypeId() == TYPEID_PLAYER ) - if( BattleGround *bg = ((Player*)caster)->GetBattleGround() ) - bg->UpdatePlayerScore(((Player*)caster), SCORE_HEALING_DONE, gain); + if( BattleGround *bg = caster->ToPlayer()->GetBattleGround() ) + bg->UpdatePlayerScore(caster->ToPlayer(), SCORE_HEALING_DONE, gain); target->getHostilRefManager().threatAssist(caster, float(gain) * 0.5f, GetSpellProto()); @@ -1959,11 +1959,11 @@ void AuraEffect::PeriodicDummyTick(Unit * target, Unit * caster) const { if (target->GetTypeId() != TYPEID_PLAYER) return; - if(((Player*)target)->getClass() != CLASS_DEATH_KNIGHT) + if(target->ToPlayer()->getClass() != CLASS_DEATH_KNIGHT) return; // timer expired - remove death runes - ((Player*)target)->RemoveRunesByAuraEffect(this); + target->ToPlayer()->RemoveRunesByAuraEffect(this); } break; } @@ -2409,14 +2409,14 @@ void AuraEffect::HandleShapeshiftBoosts(Unit * target, bool apply) const target->CastSpell(target, itr->first, true, NULL, this); } // Leader of the Pack - if (((Player*)target)->HasSpell(17007)) + if (target->ToPlayer()->HasSpell(17007)) { SpellEntry const *spellInfo = sSpellStore.LookupEntry(24932); if (spellInfo && spellInfo->Stances & (1<<(GetMiscValue()-1))) target->CastSpell(target, 24932, true, NULL, this); } // Improved Barkskin - apply/remove armor bonus due to shapeshift - if (((Player*)target)->HasSpell(63410) || ((Player*)target)->HasSpell(63411)) + if (target->ToPlayer()->HasSpell(63410) || target->ToPlayer()->HasSpell(63411)) { target->RemoveAurasDueToSpell(66530); if (GetMiscValue() == FORM_TRAVEL || GetMiscValue() == FORM_NONE) // "while in Travel Form or while not shapeshifted" @@ -2509,7 +2509,7 @@ void AuraEffect::HandleShapeshiftBoosts(Unit * target, bool apply) const target->RemoveAurasDueToSpell(spellId2); // Improved Barkskin - apply/remove armor bonus due to shapeshift - if (((Player*)target)->HasSpell(63410) || ((Player*)target)->HasSpell(63411)) + if (target->ToPlayer()->HasSpell(63410) || target->ToPlayer()->HasSpell(63411)) { target->RemoveAurasDueToSpell(66530); target->CastSpell(target,66530,true); @@ -2647,7 +2647,7 @@ void AuraEffect::HandleSpiritOfRedemption(AuraApplication const * aurApp, uint8 if(target->GetTypeId() == TYPEID_PLAYER) { // disable breath/etc timers - ((Player*)target)->StopMirrorTimers(); + target->ToPlayer()->StopMirrorTimers(); // set stand state (expected in this form) if(!target->IsStandState()) @@ -2694,15 +2694,15 @@ void AuraEffect::HandlePhase(AuraApplication const * aurApp, uint8 mode, bool ap if(target->GetTypeId() == TYPEID_PLAYER) { // drop flag at invisible in bg - if(((Player*)target)->InBattleGround()) - if(BattleGround *bg = ((Player*)target)->GetBattleGround()) - bg->EventPlayerDroppedFlag((Player*)target); + if(target->ToPlayer()->InBattleGround()) + if(BattleGround *bg = target->ToPlayer()->GetBattleGround()) + bg->EventPlayerDroppedFlag(target->ToPlayer()); // GM-mode have mask 0xFFFFFFFF - if(!((Player*)target)->isGameMaster()) + if(!target->ToPlayer()->isGameMaster()) target->SetPhaseMask((apply) ? GetMiscValue() : PHASEMASK_NORMAL,false); - ((Player*)target)->GetSession()->SendSetPhaseShift((apply) ? GetMiscValue() : PHASEMASK_NORMAL); + target->ToPlayer()->GetSession()->SendSetPhaseShift((apply) ? GetMiscValue() : PHASEMASK_NORMAL); } else target->SetPhaseMask((apply) ? GetMiscValue() : PHASEMASK_NORMAL,false); @@ -2906,7 +2906,7 @@ void AuraEffect::HandleAuraModShapeshift(AuraApplication const * aurApp, uint8 m HandleShapeshiftBoosts(target, apply); if(target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->InitDataForForm(); + target->ToPlayer()->InitDataForForm(); if(target->getClass() == CLASS_DRUID) { @@ -2923,9 +2923,9 @@ void AuraEffect::HandleAuraModShapeshift(AuraApplication const * aurApp, uint8 m if (!shapeInfo->stanceSpell[i]) continue; if (apply) - ((Player*)target)->AddTemporarySpell(shapeInfo->stanceSpell[i]); + target->ToPlayer()->AddTemporarySpell(shapeInfo->stanceSpell[i]); else - ((Player*)target)->RemoveTemporarySpell(shapeInfo->stanceSpell[i]); + target->ToPlayer()->RemoveTemporarySpell(shapeInfo->stanceSpell[i]); } } } @@ -3042,7 +3042,7 @@ void AuraEffect::HandleAuraTransform(AuraApplication const * aurApp, uint8 mode, // for players, start regeneration after 1s (in polymorph fast regeneration case) // only if caster is Player (after patch 2.4.2) if (IS_PLAYER_GUID(GetCasterGUID()) ) - ((Player*)target)->setRegenTimerCount(1*IN_MILISECONDS); + target->ToPlayer()->setRegenTimerCount(1*IN_MILISECONDS); //dismount polymorphed target (after patch 2.4.2) if (target->IsMounted()) @@ -3083,7 +3083,7 @@ void AuraEffect::HandleAuraTransform(AuraApplication const * aurApp, uint8 mode, { uint32 team = 0; if (target->GetTypeId() == TYPEID_PLAYER) - team = ((Player*)target)->GetTeam(); + team = target->ToPlayer()->GetTeam(); uint32 display_id = objmgr.ChooseDisplayId(team,ci); CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id); @@ -3276,8 +3276,8 @@ void AuraEffect::HandleAuraModDisarm(AuraApplication const * aurApp, uint8 mode, // This is between the two because there is a check in _ApplyItemMods // we must make sure that flag is always removed when call that function // refer to DurabilityPointsLoss - if(Item *pItem = ((Player*)target)->GetItemByPos( INVENTORY_SLOT_BAG_0, slot )) - ((Player*)target)->_ApplyItemMods(pItem, slot, !apply); + if(Item *pItem = target->ToPlayer()->GetItemByPos( INVENTORY_SLOT_BAG_0, slot )) + target->ToPlayer()->_ApplyItemMods(pItem, slot, !apply); } if(apply) @@ -3480,7 +3480,7 @@ void AuraEffect::HandleAuraModPetTalentsPoints(AuraApplication const * aurApp, u return; // Recalculate pet talent points - if (Pet *pet = ((Player*)target)->GetPet()) + if (Pet *pet = target->ToPlayer()->GetPet()) pet->InitTalentForLevel(); } @@ -3494,9 +3494,9 @@ void AuraEffect::HandleAuraModSkill(AuraApplication const * aurApp, uint8 mode, uint32 prot = GetSpellProto()->EffectMiscValue[m_effIndex]; int32 points = GetAmount(); - ((Player*)target)->ModifySkillBonus(prot,((apply) ? points: -points),GetAuraType() == SPELL_AURA_MOD_SKILL_TALENT); + target->ToPlayer()->ModifySkillBonus(prot,((apply) ? points: -points),GetAuraType() == SPELL_AURA_MOD_SKILL_TALENT); if(prot == SKILL_DEFENSE) - ((Player*)target)->UpdateDefenseBonusesMod(); + target->ToPlayer()->UpdateDefenseBonusesMod(); } /****************************/ @@ -3521,7 +3521,7 @@ void AuraEffect::HandleAuraMounted(AuraApplication const * aurApp, uint8 mode, b uint32 team = 0; if (target->GetTypeId() == TYPEID_PLAYER) - team = ((Player*)target)->GetTeam(); + team = target->ToPlayer()->GetTeam(); uint32 display_id = objmgr.ChooseDisplayId(team,ci); CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id); @@ -3626,7 +3626,7 @@ void AuraEffect::HandleAuraFeatherFall(AuraApplication const * aurApp, uint8 mod // start fall from current height if(!apply && target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->SetFallInformation(0, target->GetPositionZ()); + target->ToPlayer()->SetFallInformation(0, target->GetPositionZ()); } void AuraEffect::HandleAuraHover(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -3662,7 +3662,7 @@ void AuraEffect::HandleWaterBreathing(AuraApplication const * aurApp, uint8 mode // update timers in client if(target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->UpdateMirrorTimers(); + target->ToPlayer()->UpdateMirrorTimers(); } void AuraEffect::HandleForceMoveForward(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -3843,12 +3843,12 @@ void AuraEffect::HandleModPossessPet(AuraApplication const * aurApp, uint8 mode, return; //seems it may happen that when removing it is no longer owner's pet - //if(((Player*)caster)->GetPet() != target) + //if(caster->ToPlayer()->GetPet() != target) // return; if(apply) { - if(((Player*)caster)->GetPet() != target) + if(caster->ToPlayer()->GetPet() != target) return; target->SetCharmedBy(caster, CHARM_TYPE_POSSESS); @@ -3858,7 +3858,7 @@ void AuraEffect::HandleModPossessPet(AuraApplication const * aurApp, uint8 mode, target->RemoveCharmedBy(caster); // Reinitialize the pet bar and make the pet come back to the owner - ((Player*)caster)->PetSpellInitialize(); + caster->ToPlayer()->PetSpellInitialize(); if(!target->getVictim()) { target->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, target->GetFollowAngle()); @@ -3920,7 +3920,7 @@ void AuraEffect::HandleAuraControlVehicle(AuraApplication const * aurApp, uint8 if (apply) { //if(caster->GetTypeId() == TYPEID_PLAYER) - // if(Pet *pet = ((Player*)caster)->GetPet()) + // if(Pet *pet = caster->ToPlayer()->GetPet()) // pet->Remove(PET_SAVE_AS_CURRENT); caster->EnterVehicle(target->GetVehicleKit(), m_amount - 1); } @@ -4156,10 +4156,10 @@ void AuraEffect::HandleAuraModEffectImmunity(AuraApplication const * aurApp, uin { if(target->GetTypeId() == TYPEID_PLAYER) { - if(((Player*)target)->InBattleGround()) + if(target->ToPlayer()->InBattleGround()) { - if( BattleGround *bg = ((Player*)target)->GetBattleGround() ) - bg->EventPlayerDroppedFlag(((Player*)target)); + if( BattleGround *bg = target->ToPlayer()->GetBattleGround() ) + bg->EventPlayerDroppedFlag(target->ToPlayer()); } else sOutdoorPvPMgr.HandleDropFlag((Player*)target,GetSpellProto()->Id); @@ -4458,7 +4458,7 @@ void AuraEffect::HandleModSpellDamagePercentFromStat(AuraApplication const * aur // Magic damage modifiers implemented in Unit::SpellDamageBonus // This information for client side use only // Recalculate bonus - ((Player*)target)->UpdateSpellDamageAndHealingBonus(); + target->ToPlayer()->UpdateSpellDamageAndHealingBonus(); } void AuraEffect::HandleModSpellHealingPercentFromStat(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -4472,7 +4472,7 @@ void AuraEffect::HandleModSpellHealingPercentFromStat(AuraApplication const * au return; // Recalculate bonus - ((Player*)target)->UpdateSpellDamageAndHealingBonus(); + target->ToPlayer()->UpdateSpellDamageAndHealingBonus(); } void AuraEffect::HandleModSpellDamagePercentFromAttackPower(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -4488,7 +4488,7 @@ void AuraEffect::HandleModSpellDamagePercentFromAttackPower(AuraApplication cons // Magic damage modifiers implemented in Unit::SpellDamageBonus // This information for client side use only // Recalculate bonus - ((Player*)target)->UpdateSpellDamageAndHealingBonus(); + target->ToPlayer()->UpdateSpellDamageAndHealingBonus(); } void AuraEffect::HandleModSpellHealingPercentFromAttackPower(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -4502,7 +4502,7 @@ void AuraEffect::HandleModSpellHealingPercentFromAttackPower(AuraApplication con return; // Recalculate bonus - ((Player*)target)->UpdateSpellDamageAndHealingBonus(); + target->ToPlayer()->UpdateSpellDamageAndHealingBonus(); } void AuraEffect::HandleModHealingDone(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -4516,7 +4516,7 @@ void AuraEffect::HandleModHealingDone(AuraApplication const * aurApp, uint8 mode return; // implemented in Unit::SpellHealingBonus // this information is for client side only - ((Player*)target)->UpdateSpellDamageAndHealingBonus(); + target->ToPlayer()->UpdateSpellDamageAndHealingBonus(); } void AuraEffect::HandleModTotalPercentStat(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -4587,8 +4587,8 @@ void AuraEffect::HandleAuraModExpertise(AuraApplication const * aurApp, uint8 mo if(target->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)target)->UpdateExpertise(BASE_ATTACK); - ((Player*)target)->UpdateExpertise(OFF_ATTACK); + target->ToPlayer()->UpdateExpertise(BASE_ATTACK); + target->ToPlayer()->UpdateExpertise(OFF_ATTACK); } /********************************/ @@ -4606,7 +4606,7 @@ void AuraEffect::HandleModPowerRegen(AuraApplication const * aurApp, uint8 mode, // Update manaregen value if (GetMiscValue() == POWER_MANA) - ((Player*)target)->UpdateManaRegen(); + target->ToPlayer()->UpdateManaRegen(); // other powers are not immediate effects - implemented in Player::Regenerate, Creature::Regenerate } @@ -4622,7 +4622,7 @@ void AuraEffect::HandleModPowerRegenPCT(AuraApplication const * aurApp, uint8 mo // Update manaregen value if (GetMiscValue() == POWER_MANA) - ((Player*)target)->UpdateManaRegen(); + target->ToPlayer()->UpdateManaRegen(); // other powers are not immediate effects - implemented in Player::Regenerate, Creature::Regenerate } @@ -4637,7 +4637,7 @@ void AuraEffect::HandleModManaRegen(AuraApplication const * aurApp, uint8 mode, return; //Note: an increase in regen does NOT cause threat. - ((Player*)target)->UpdateManaRegen(); + target->ToPlayer()->UpdateManaRegen(); } void AuraEffect::HandleAuraModIncreaseHealth(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -4763,7 +4763,7 @@ void AuraEffect::HandleAuraModParryPercent(AuraApplication const * aurApp, uint8 if(target->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)target)->UpdateParryPercentage(); + target->ToPlayer()->UpdateParryPercentage(); } void AuraEffect::HandleAuraModDodgePercent(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -4776,7 +4776,7 @@ void AuraEffect::HandleAuraModDodgePercent(AuraApplication const * aurApp, uint8 if(target->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)target)->UpdateDodgePercentage(); + target->ToPlayer()->UpdateDodgePercentage(); } void AuraEffect::HandleAuraModBlockPercent(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -4789,7 +4789,7 @@ void AuraEffect::HandleAuraModBlockPercent(AuraApplication const * aurApp, uint8 if(target->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)target)->UpdateBlockPercentage(); + target->ToPlayer()->UpdateBlockPercentage(); } void AuraEffect::HandleAuraModRegenInterrupt(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -4802,7 +4802,7 @@ void AuraEffect::HandleAuraModRegenInterrupt(AuraApplication const * aurApp, uin if(target->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)target)->UpdateManaRegen(); + target->ToPlayer()->UpdateManaRegen(); } void AuraEffect::HandleAuraModWeaponCritPercent(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -4816,8 +4816,8 @@ void AuraEffect::HandleAuraModWeaponCritPercent(AuraApplication const * aurApp, return; for (int i = 0; i < MAX_ATTACK; ++i) - if(Item* pItem = ((Player*)target)->GetWeaponForAttack(WeaponAttackType(i), true)) - ((Player*)target)->_ApplyWeaponDependentAuraCritMod(pItem,WeaponAttackType(i),this,apply); + if(Item* pItem = target->ToPlayer()->GetWeaponForAttack(WeaponAttackType(i), true)) + target->ToPlayer()->_ApplyWeaponDependentAuraCritMod(pItem,WeaponAttackType(i),this,apply); // mods must be applied base at equipped weapon class and subclass comparison // with spell->EquippedItemClass and EquippedItemSubClassMask and EquippedItemInventoryTypeMask @@ -4825,9 +4825,9 @@ void AuraEffect::HandleAuraModWeaponCritPercent(AuraApplication const * aurApp, if (GetSpellProto()->EquippedItemClass == -1) { - ((Player*)target)->HandleBaseModValue(CRIT_PERCENTAGE, FLAT_MOD, float (GetAmount()), apply); - ((Player*)target)->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (GetAmount()), apply); - ((Player*)target)->HandleBaseModValue(RANGED_CRIT_PERCENTAGE, FLAT_MOD, float (GetAmount()), apply); + target->ToPlayer()->HandleBaseModValue(CRIT_PERCENTAGE, FLAT_MOD, float (GetAmount()), apply); + target->ToPlayer()->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (GetAmount()), apply); + target->ToPlayer()->HandleBaseModValue(RANGED_CRIT_PERCENTAGE, FLAT_MOD, float (GetAmount()), apply); } else { @@ -4844,8 +4844,8 @@ void AuraEffect::HandleModHitChance(AuraApplication const * aurApp, uint8 mode, if(target->GetTypeId() == TYPEID_PLAYER) { - ((Player*)target)->UpdateMeleeHitChances(); - ((Player*)target)->UpdateRangedHitChances(); + target->ToPlayer()->UpdateMeleeHitChances(); + target->ToPlayer()->UpdateRangedHitChances(); } else { @@ -4862,7 +4862,7 @@ void AuraEffect::HandleModSpellHitChance(AuraApplication const * aurApp, uint8 m Unit * target = aurApp->GetTarget(); if(target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->UpdateSpellHitChances(); + target->ToPlayer()->UpdateSpellHitChances(); else target->m_modSpellHitChance += (apply) ? GetAmount(): (-GetAmount()); } @@ -4875,7 +4875,7 @@ void AuraEffect::HandleModSpellCritChance(AuraApplication const * aurApp, uint8 Unit * target = aurApp->GetTarget(); if(target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->UpdateAllSpellCritChances(); + target->ToPlayer()->UpdateAllSpellCritChances(); else target->m_baseSpellCritChance += (apply) ? GetAmount():-GetAmount(); } @@ -4892,7 +4892,7 @@ void AuraEffect::HandleModSpellCritChanceShool(AuraApplication const * aurApp, u for (int school = SPELL_SCHOOL_NORMAL; school < MAX_SPELL_SCHOOL; ++school) if (GetMiscValue() & (1<<school)) - ((Player*)target)->UpdateSpellCritChance(school); + target->ToPlayer()->UpdateSpellCritChance(school); } void AuraEffect::HandleAuraModCritPct(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -4908,12 +4908,12 @@ void AuraEffect::HandleAuraModCritPct(AuraApplication const * aurApp, uint8 mode return; } - ((Player*)target)->HandleBaseModValue(CRIT_PERCENTAGE, FLAT_MOD, float (GetAmount()), apply); - ((Player*)target)->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (GetAmount()), apply); - ((Player*)target)->HandleBaseModValue(RANGED_CRIT_PERCENTAGE, FLAT_MOD, float (GetAmount()), apply); + target->ToPlayer()->HandleBaseModValue(CRIT_PERCENTAGE, FLAT_MOD, float (GetAmount()), apply); + target->ToPlayer()->HandleBaseModValue(OFFHAND_CRIT_PERCENTAGE, FLAT_MOD, float (GetAmount()), apply); + target->ToPlayer()->HandleBaseModValue(RANGED_CRIT_PERCENTAGE, FLAT_MOD, float (GetAmount()), apply); // included in Player::UpdateSpellCritChance calculation - ((Player*)target)->UpdateAllSpellCritChances(); + target->ToPlayer()->UpdateAllSpellCritChances(); } /********************************/ @@ -5017,7 +5017,7 @@ void AuraEffect::HandleModRating(AuraApplication const * aurApp, uint8 mode, boo for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating) if (GetMiscValue() & (1 << rating)) - ((Player*)target)->ApplyRatingMod(CombatRating(rating), GetAmount(), apply); + target->ToPlayer()->ApplyRatingMod(CombatRating(rating), GetAmount(), apply); } void AuraEffect::HandleModRatingFromStat(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -5033,7 +5033,7 @@ void AuraEffect::HandleModRatingFromStat(AuraApplication const * aurApp, uint8 m // Just recalculate ratings for (uint32 rating = 0; rating < MAX_COMBAT_RATING; ++rating) if (GetMiscValue() & (1 << rating)) - ((Player*)target)->ApplyRatingMod(CombatRating(rating), 0, apply); + target->ToPlayer()->ApplyRatingMod(CombatRating(rating), 0, apply); } /********************************/ @@ -5097,7 +5097,7 @@ void AuraEffect::HandleAuraModRangedAttackPowerOfStatPercent(AuraApplication con // Recalculate bonus if(target->GetTypeId() == TYPEID_PLAYER && !(target->getClassMask() & CLASSMASK_WAND_USERS)) - ((Player*)target)->UpdateAttackPowerAndDamage(true); + target->ToPlayer()->UpdateAttackPowerAndDamage(true); } void AuraEffect::HandleAuraModAttackPowerOfStatPercent(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -5109,7 +5109,7 @@ void AuraEffect::HandleAuraModAttackPowerOfStatPercent(AuraApplication const * a // Recalculate bonus if(target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->UpdateAttackPowerAndDamage(false); + target->ToPlayer()->UpdateAttackPowerAndDamage(false); } void AuraEffect::HandleAuraModAttackPowerOfArmor(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -5121,7 +5121,7 @@ void AuraEffect::HandleAuraModAttackPowerOfArmor(AuraApplication const * aurApp, // Recalculate bonus if(target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->UpdateAttackPowerAndDamage(false); + target->ToPlayer()->UpdateAttackPowerAndDamage(false); } /********************************/ /*** DAMAGE BONUS ***/ @@ -5137,8 +5137,8 @@ void AuraEffect::HandleModDamageDone(AuraApplication const * aurApp, uint8 mode, if(target->GetTypeId() == TYPEID_PLAYER) { for (int i = 0; i < MAX_ATTACK; ++i) - if(Item* pItem = ((Player*)target)->GetWeaponForAttack(WeaponAttackType(i), true)) - ((Player*)target)->_ApplyWeaponDependentAuraDamageMod(pItem,WeaponAttackType(i),this,apply); + if(Item* pItem = target->ToPlayer()->GetWeaponForAttack(WeaponAttackType(i), true)) + target->ToPlayer()->_ApplyWeaponDependentAuraDamageMod(pItem,WeaponAttackType(i),this,apply); } // GetMiscValue() is bitmask of spell schools @@ -5206,7 +5206,7 @@ void AuraEffect::HandleModDamageDone(AuraApplication const * aurApp, uint8 mode, target->ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG+i,GetAmount(),apply); } } - if(Guardian* pet = ((Player*)target)->GetGuardianPet()) + if(Guardian* pet = target->ToPlayer()->GetGuardianPet()) pet->UpdateAttackPowerAndDamage(); } } @@ -5224,8 +5224,8 @@ void AuraEffect::HandleModDamagePercentDone(AuraApplication const * aurApp, uint if(target->GetTypeId() == TYPEID_PLAYER) { for (int i = 0; i < MAX_ATTACK; ++i) - if(Item* pItem = ((Player*)target)->GetWeaponForAttack(WeaponAttackType(i), true)) - ((Player*)target)->_ApplyWeaponDependentAuraDamageMod(pItem,WeaponAttackType(i),this,apply); + if(Item* pItem = target->ToPlayer()->GetWeaponForAttack(WeaponAttackType(i), true)) + target->ToPlayer()->_ApplyWeaponDependentAuraDamageMod(pItem,WeaponAttackType(i),this,apply); } // GetMiscValue() is bitmask of spell schools @@ -5297,7 +5297,7 @@ void AuraEffect::HandleShieldBlockValue(AuraApplication const * aurApp, uint8 mo modType = PCT_MOD; if(target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->HandleBaseModValue(SHIELD_BLOCK_VALUE, modType, float(GetAmount()), apply); + target->ToPlayer()->HandleBaseModValue(SHIELD_BLOCK_VALUE, modType, float(GetAmount()), apply); } /********************************/ @@ -5379,9 +5379,9 @@ void AuraEffect::HandleAuraRetainComboPoints(AuraApplication const * aurApp, uin // combo points was added in SPELL_EFFECT_ADD_COMBO_POINTS handler // remove only if aura expire by time (in case combo points amount change aura removed without combo points lost) - if( !(apply) && GetBase()->GetDuration()==0 && ((Player*)target)->GetComboTarget()) - if(Unit* unit = ObjectAccessor::GetUnit(*target,((Player*)target)->GetComboTarget())) - ((Player*)target)->AddComboPoints(unit, -GetAmount()); + if( !(apply) && GetBase()->GetDuration()==0 && target->ToPlayer()->GetComboTarget()) + if(Unit* unit = ObjectAccessor::GetUnit(*target,target->ToPlayer()->GetComboTarget())) + target->ToPlayer()->AddComboPoints(unit, -GetAmount()); } /*********************************************************/ @@ -5527,7 +5527,7 @@ void AuraEffect::HandleAuraDummy(AuraApplication const * aurApp, uint8 mode, boo break; case 46699: // Requires No Ammo if(target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->RemoveAmmo(); // not use ammo and not allow use + target->ToPlayer()->RemoveAmmo(); // not use ammo and not allow use break; case 49028: GetBase()->SetDuration(GetBase()->GetDuration() + (caster->GetPower(POWER_RUNIC_POWER) * 10)); @@ -5539,7 +5539,7 @@ void AuraEffect::HandleAuraDummy(AuraApplication const * aurApp, uint8 mode, boo break; case 52916: // Honor Among Thieves if(target->GetTypeId() == TYPEID_PLAYER) - if (Unit * spellTarget = ObjectAccessor::GetUnit(*target,((Player*)target)->GetComboTarget())) + if (Unit * spellTarget = ObjectAccessor::GetUnit(*target,target->ToPlayer()->GetComboTarget())) target->CastSpell(spellTarget, 51699, true); break; case 28832: // Mark of Korth'azz @@ -5605,7 +5605,7 @@ void AuraEffect::HandleAuraDummy(AuraApplication const * aurApp, uint8 mode, boo case 2584: // Waiting to Resurrect // Waiting to resurrect spell cancel, we must remove player from resurrect queue if(target->GetTypeId() == TYPEID_PLAYER) - if(BattleGround *bg = ((Player*)target)->GetBattleGround()) + if(BattleGround *bg = target->ToPlayer()->GetBattleGround()) bg->RemovePlayerFromResurrectQueue(target->GetGUID()); break; case 28169: // Mutating Injection @@ -5772,7 +5772,7 @@ void AuraEffect::HandleAuraDummy(AuraApplication const * aurApp, uint8 mode, boo if(apply) owner->CastSpell(owner,8985,true); else - ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true); + owner->ToPlayer()->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true); } break; } @@ -5788,7 +5788,7 @@ void AuraEffect::HandleAuraDummy(AuraApplication const * aurApp, uint8 mode, boo if(apply) owner->CastSpell(owner,19704,true); else - ((Player*)owner)->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true); + owner->ToPlayer()->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true); } break; } @@ -5822,7 +5822,7 @@ void AuraEffect::HandleAuraDummy(AuraApplication const * aurApp, uint8 mode, boo case 57822: FactionID = 1091; break; // The Wyrmrest Accord } } - ((Player*)caster)->SetChampioningFaction(FactionID); + caster->ToPlayer()->SetChampioningFaction(FactionID); break; } // LK Intro VO (1) @@ -5906,7 +5906,7 @@ void AuraEffect::HandleAuraDummy(AuraApplication const * aurApp, uint8 mode, boo // Predatory Strikes if (target->GetTypeId() == TYPEID_PLAYER && GetSpellProto()->SpellIconID == 1563) { - ((Player*)target)->UpdateAttackPowerAndDamage(); + target->ToPlayer()->UpdateAttackPowerAndDamage(); } break; } @@ -5924,11 +5924,11 @@ void AuraEffect::HandleAuraDummy(AuraApplication const * aurApp, uint8 mode, boo { Creature *totem = caster->GetMap()->GetCreature(guid); if (totem && totem->isTotem()) - ((Player*)caster)->CastSpell(totem, 6277, true); + caster->ToPlayer()->CastSpell(totem, 6277, true); } } else - ((Player*)caster)->StopCastingBindSight(); + caster->ToPlayer()->StopCastingBindSight(); return; } break; @@ -6002,24 +6002,24 @@ void AuraEffect::HandleChannelDeathItem(AuraApplication const * aurApp, uint8 mo // Soul Shard only from non-grey units if( GetSpellProto()->EffectItemType[m_effIndex] == 6265 && (target->getLevel() <= Trinity::XP::GetGrayLevel(caster->getLevel()) || - target->GetTypeId() == TYPEID_UNIT && !((Player*)caster)->isAllowedToLoot((Creature*)target)) ) + target->GetTypeId() == TYPEID_UNIT && !caster->ToPlayer()->isAllowedToLoot((Creature*)target)) ) return; //Adding items uint32 noSpaceForCount = 0; uint32 count = m_amount; ItemPosCountVec dest; - uint8 msg = ((Player*)caster)->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, GetSpellProto()->EffectItemType[m_effIndex], count, &noSpaceForCount); + uint8 msg = caster->ToPlayer()->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, GetSpellProto()->EffectItemType[m_effIndex], count, &noSpaceForCount); if( msg != EQUIP_ERR_OK ) { count-=noSpaceForCount; - ((Player*)caster)->SendEquipError( msg, NULL, NULL ); + caster->ToPlayer()->SendEquipError( msg, NULL, NULL ); if (count==0) return; } - Item* newitem = ((Player*)caster)->StoreNewItem(dest, GetSpellProto()->EffectItemType[m_effIndex], true); - ((Player*)caster)->SendNewItem(newitem, count, true, false); + Item* newitem = caster->ToPlayer()->StoreNewItem(dest, GetSpellProto()->EffectItemType[m_effIndex], true); + caster->ToPlayer()->SendNewItem(newitem, count, true, false); } } @@ -6035,7 +6035,7 @@ void AuraEffect::HandleBindSight(AuraApplication const * aurApp, uint8 mode, boo if(!caster || caster->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)caster)->SetViewpoint(target, (apply)); + caster->ToPlayer()->SetViewpoint(target, (apply)); } void AuraEffect::HandleForceReaction(AuraApplication const * aurApp, uint8 mode, bool apply) const diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index b050208d5a9..977e92726ca 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -378,8 +378,8 @@ void Aura::_ApplyForTarget(Unit * target, Unit * caster, AuraApplication * auraA { if (m_spellProto->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE) { - Item* castItem = m_castItemGuid ? ((Player*)caster)->GetItemByGuid(m_castItemGuid) : NULL; - ((Player*)caster)->AddSpellAndCategoryCooldowns(m_spellProto,castItem ? castItem->GetEntry() : 0, NULL,true); + Item* castItem = m_castItemGuid ? caster->ToPlayer()->GetItemByGuid(m_castItemGuid) : NULL; + caster->ToPlayer()->AddSpellAndCategoryCooldowns(m_spellProto,castItem ? castItem->GetEntry() : 0, NULL,true); } } } @@ -401,7 +401,7 @@ void Aura::_UnapplyForTarget(Unit * target, Unit * caster, AuraApplication * aur { if ( GetSpellProto()->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE ) // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases) - ((Player*)caster)->SendCooldownEvent(GetSpellProto()); + caster->ToPlayer()->SendCooldownEvent(GetSpellProto()); } } @@ -844,7 +844,7 @@ void Aura::HandleAuraSpecificMods(AuraApplication const * aurApp, Unit * caster, { case 32474: // Buffeting Winds of Susurrus if(target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->ActivateTaxiPathTo(506, GetId()); + target->ToPlayer()->ActivateTaxiPathTo(506, GetId()); break; case 33572: // Gronn Lord's Grasp, becomes stoned if(GetStackAmount() >= 5 && !target->HasAura(33652)) @@ -852,7 +852,7 @@ void Aura::HandleAuraSpecificMods(AuraApplication const * aurApp, Unit * caster, break; case 60970: // Heroic Fury (remove Intercept cooldown) if(target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->RemoveSpellCooldown(20252, true); + target->ToPlayer()->RemoveSpellCooldown(20252, true); break; } break; @@ -916,8 +916,8 @@ void Aura::HandleAuraSpecificMods(AuraApplication const * aurApp, Unit * caster, if(target->GetTypeId() == TYPEID_PLAYER) if(GameObject* obj = target->GetGameObject(48018)) { - ((Player*)target)->TeleportTo(obj->GetMapId(),obj->GetPositionX(),obj->GetPositionY(),obj->GetPositionZ(),obj->GetOrientation()); - ((Player*)target)->RemoveMovementImpairingAuras(); + target->ToPlayer()->TeleportTo(obj->GetMapId(),obj->GetPositionX(),obj->GetPositionY(),obj->GetPositionZ(),obj->GetOrientation()); + target->ToPlayer()->RemoveMovementImpairingAuras(); } break; } @@ -1093,7 +1093,7 @@ void Aura::HandleAuraSpecificMods(AuraApplication const * aurApp, Unit * caster, { if (removeMode == AURA_REMOVE_BY_DEATH) { - if (caster->GetTypeId() == TYPEID_PLAYER && ((Player*)caster)->isHonorOrXPTarget(target)) + if (caster->GetTypeId() == TYPEID_PLAYER && caster->ToPlayer()->isHonorOrXPTarget(target)) caster->CastSpell(target, 18662, true, NULL, GetEffect(0)); } } @@ -1151,10 +1151,10 @@ void Aura::HandleAuraSpecificMods(AuraApplication const * aurApp, Unit * caster, // check cooldown if (caster->GetTypeId() == TYPEID_PLAYER) { - if (((Player*)caster)->HasSpellCooldown(aura->GetId())) + if (caster->ToPlayer()->HasSpellCooldown(aura->GetId())) break; // and add if needed - ((Player*)caster)->AddSpellCooldown(aura->GetId(), 0, uint32(time(NULL) + 12)); + caster->ToPlayer()->AddSpellCooldown(aura->GetId(), 0, uint32(time(NULL) + 12)); } // effect on caster if (AuraEffect const * aurEff = aura->GetEffect(0)) @@ -1200,7 +1200,7 @@ void Aura::HandleAuraSpecificMods(AuraApplication const * aurApp, Unit * caster, if(caster->GetTypeId() != TYPEID_PLAYER) break; - Player *player = ((Player*)caster); + Player *player = caster->ToPlayer(); // Glyph of Guardian Spirit if(AuraEffect * aurEff = player->GetAuraEffect(63231, 0)) { @@ -1230,11 +1230,11 @@ void Aura::HandleAuraSpecificMods(AuraApplication const * aurApp, Unit * caster, break; if (target->GetTypeId() != TYPEID_PLAYER) break; - if(((Player*)target)->getClass() != CLASS_DEATH_KNIGHT) + if(target->ToPlayer()->getClass() != CLASS_DEATH_KNIGHT) break; // aura removed - remove death runes - ((Player*)target)->RemoveRunesByAuraEffect(GetEffect(0)); + target->ToPlayer()->RemoveRunesByAuraEffect(GetEffect(0)); } switch(GetId()) { diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index 0e5c58a8bb4..c484d370e6e 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -251,7 +251,7 @@ void Spell::EffectResurrectNew(uint32 i) if(!unitTarget->IsInWorld()) return; - Player* pTarget = ((Player*)unitTarget); + Player* pTarget = unitTarget->ToPlayer(); if(pTarget->isRessurectRequested()) // already have one active request return; @@ -307,7 +307,7 @@ void Spell::EffectEnvirinmentalDMG(uint32 i) m_caster->SendSpellNonMeleeDamageLog(m_caster, m_spellInfo->Id, damage, GetSpellSchoolMask(m_spellInfo), absorb, resist, false, 0, false); if(m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->EnvironmentalDamage(DAMAGE_FIRE, damage); + m_caster->ToPlayer()->EnvironmentalDamage(DAMAGE_FIRE, damage); } void Spell::EffectSchoolDMG(uint32 effect_idx) @@ -579,7 +579,7 @@ void Spell::SpellDamageSchoolDmg(uint32 effect_idx) float multiple = ap / 410 + m_spellInfo->DmgMultiplier[effect_idx]; int32 energy = -(m_caster->ModifyPower(POWER_ENERGY, -30)); damage += int32(energy * multiple); - damage += int32(((Player*)m_caster)->GetComboPoints() * ap * 7 / 100); + damage += int32(m_caster->ToPlayer()->GetComboPoints() * ap * 7 / 100); } // Wrath else if (m_spellInfo->SpellFamilyFlags[0] & 0x00000001) @@ -597,7 +597,7 @@ void Spell::SpellDamageSchoolDmg(uint32 effect_idx) if (m_caster->GetTypeId() == TYPEID_PLAYER && (m_spellInfo->SpellFamilyFlags[1] & 0x8)) { // consume from stack dozes not more that have combo-points - if (uint32 combo = ((Player*)m_caster)->GetComboPoints()) + if (uint32 combo = m_caster->ToPlayer()->GetComboPoints()) { // Lookup for Deadly poison (only attacker applied) if (AuraEffect const * aurEff = unitTarget->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_ROGUE, 0x10000, 0, 0, m_caster->GetGUID())) @@ -609,7 +609,7 @@ void Spell::SpellDamageSchoolDmg(uint32 effect_idx) if (doses > combo) doses = combo; // Master Poisoner - Unit::AuraEffectList const& auraList = ((Player*)m_caster)->GetAuraEffectsByType(SPELL_AURA_MOD_AURA_DURATION_BY_DISPEL_NOT_STACK); + Unit::AuraEffectList const& auraList = m_caster->ToPlayer()->GetAuraEffectsByType(SPELL_AURA_MOD_AURA_DURATION_BY_DISPEL_NOT_STACK); for (Unit::AuraEffectList::const_iterator iter = auraList.begin(); iter != auraList.end(); ++iter) { if ((*iter)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_ROGUE && (*iter)->GetSpellProto()->SpellIconID == 1960) @@ -679,7 +679,7 @@ void Spell::SpellDamageSchoolDmg(uint32 effect_idx) if (m_caster->GetTypeId() == TYPEID_PLAYER) { // Add Ammo and Weapon damage plus RAP * 0.1 - Item *item = ((Player*)m_caster)->GetWeaponForAttack(RANGED_ATTACK); + Item *item = m_caster->ToPlayer()->GetWeaponForAttack(RANGED_ATTACK); if (item) { float dmg_min = item->GetProto()->Damage->DamageMin; @@ -688,7 +688,7 @@ void Spell::SpellDamageSchoolDmg(uint32 effect_idx) damage += int32(dmg_min); else damage += irand(int32(dmg_min), int32(dmg_max)); - damage += ((Player*)m_caster)->GetAmmoDPS()*item->GetProto()->Delay*0.001f; + damage += m_caster->ToPlayer()->GetAmmoDPS()*item->GetProto()->Delay*0.001f; } } @@ -960,7 +960,7 @@ void Spell::EffectDummy(uint32 i) { WorldPacket data(SMSG_SPIRIT_HEALER_CONFIRM, 8); data << uint64(unitTarget->GetGUID()); - ((Player*)m_originalCaster)->GetSession()->SendPacket( &data ); + m_originalCaster->ToPlayer()->GetSession()->SendPacket( &data ); } return; } @@ -1232,7 +1232,7 @@ void Spell::EffectDummy(uint32 i) return; ((Creature*)unitTarget)->UpdateEntry(16992); - ((Player*)m_caster)->RewardPlayerAndGroupAtEvent(16992, unitTarget); + m_caster->ToPlayer()->RewardPlayerAndGroupAtEvent(16992, unitTarget); if (unitTarget->IsAIEnabled) ((Creature*)unitTarget)->AI()->AttackStart(m_caster); @@ -1270,7 +1270,7 @@ void Spell::EffectDummy(uint32 i) return; m_caster->RemoveAurasByType(SPELL_AURA_MOUNTED); // Ram for Alliance, Kodo for Horde - if (((Player*)m_caster)->GetTeam() == ALLIANCE) + if (m_caster->ToPlayer()->GetTeam() == ALLIANCE) { if (m_caster->GetSpeedRate(MOVE_RUN) >= 2.0f) // 100% Ram @@ -1281,7 +1281,7 @@ void Spell::EffectDummy(uint32 i) } else { - if (((Player*)m_caster)->GetSpeedRate(MOVE_RUN) >= 2.0f) + if (m_caster->ToPlayer()->GetSpeedRate(MOVE_RUN) >= 2.0f) // 100% Kodo m_caster->CastSpell(m_caster, 49379, true); else @@ -1296,7 +1296,7 @@ void Spell::EffectDummy(uint32 i) return; m_caster->RemoveAurasByType(SPELL_AURA_MOUNTED); // Ram for Horde, Kodo for Alliance - if (((Player*)m_caster)->GetTeam() == HORDE) + if (m_caster->ToPlayer()->GetTeam() == HORDE) { if (m_caster->GetSpeedRate(MOVE_RUN) >= 2.0f) // 100% Ram @@ -1307,7 +1307,7 @@ void Spell::EffectDummy(uint32 i) } else { - if (((Player*)m_caster)->GetSpeedRate(MOVE_RUN) >= 2.0f) + if (m_caster->ToPlayer()->GetSpeedRate(MOVE_RUN) >= 2.0f) // 100% Kodo m_caster->CastSpell(m_caster, 49379, true); else @@ -1331,7 +1331,7 @@ void Spell::EffectDummy(uint32 i) // spell has a 1/3 chance to trigger one of the below if (roll_chance_i(66)) return; - if (((Player*)m_caster)->GetTeam() == ALLIANCE) + if (m_caster->ToPlayer()->GetTeam() == ALLIANCE) { // 1000001 - gnomish binary m_caster->CastSpell(m_caster, 50242, true); @@ -1349,8 +1349,8 @@ void Spell::EffectDummy(uint32 i) if(m_caster->GetTypeId() != TYPEID_PLAYER) return; - if(BattleGround* bg = ((Player*)m_caster)->GetBattleGround()) - bg->EventPlayerDroppedFlag((Player*)m_caster); + if(BattleGround* bg = m_caster->ToPlayer()->GetBattleGround()) + bg->EventPlayerDroppedFlag(m_caster->ToPlayer()); m_caster->CastSpell(m_caster, 30452, true, NULL); return; @@ -1482,7 +1482,7 @@ void Spell::EffectDummy(uint32 i) (GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_FROST) && spellInfo->Id != 11958 && GetSpellRecoveryTime(spellInfo) > 0 ) { - ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first, true); + m_caster->ToPlayer()->RemoveSpellCooldown((itr++)->first, true); } else ++itr; @@ -1715,7 +1715,7 @@ void Spell::EffectDummy(uint32 i) if(m_caster->GetTypeId() != TYPEID_PLAYER) return; - Player *pCaster = ((Player*)m_caster); + Player *pCaster = m_caster->ToPlayer(); Item *item = pCaster->GetWeaponForAttack(OFF_ATTACK); if(!item) @@ -1757,7 +1757,7 @@ void Spell::EffectDummy(uint32 i) SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first); if (spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && (spellInfo->SpellFamilyFlags[1] & SPELLFAMILYFLAG1_ROGUE_COLDB_SHADOWSTEP || spellInfo->SpellFamilyFlags[0] & SPELLFAMILYFLAG_ROGUE_VAN_EVAS_SPRINT)) - ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first,true); + m_caster->ToPlayer()->RemoveSpellCooldown((itr++)->first,true); else ++itr; } @@ -1785,7 +1785,7 @@ void Spell::EffectDummy(uint32 i) data << float(sinf(m_caster->GetOrientation()+M_PI)); data << float(15); data << float(-7.0f); - ((Player*)m_caster)->GetSession()->SendPacket(&data); + m_caster->ToPlayer()->GetSession()->SendPacket(&data); return; } case 23989: // Readiness talent @@ -1794,13 +1794,13 @@ void Spell::EffectDummy(uint32 i) return; // immediately finishes the cooldown on your other Hunter abilities except Bestial Wrath - const SpellCooldowns& cm = ((Player*)m_caster)->GetSpellCooldownMap(); + const SpellCooldowns& cm = m_caster->ToPlayer()->GetSpellCooldownMap(); for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();) { SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first); if (spellInfo->SpellFamilyName == SPELLFAMILY_HUNTER && spellInfo->Id != 23989 && spellInfo->Id != 19574 && GetSpellRecoveryTime(spellInfo) > 0 ) - ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first,true); + m_caster->ToPlayer()->RemoveSpellCooldown((itr++)->first,true); else ++itr; } @@ -1814,7 +1814,7 @@ void Spell::EffectDummy(uint32 i) // break Auto Shot and autohit m_caster->InterruptSpell(CURRENT_AUTOREPEAT_SPELL); m_caster->AttackStop(); - ((Player*)m_caster)->SendAttackSwingCancelAttack(); + m_caster->ToPlayer()->SendAttackSwingCancelAttack(); return; } // Last Stand (pet) @@ -1830,7 +1830,7 @@ void Spell::EffectDummy(uint32 i) if (m_caster->GetTypeId() != TYPEID_PLAYER || !unitTarget) return; - if (Pet *PlrPet = ((Player*)m_caster)->GetPet()) + if (Pet *PlrPet = m_caster->ToPlayer()->GetPet()) PlrPet->CastSpell(unitTarget, m_spellInfo->CalculateSimpleValue(i), true); return; } @@ -2019,7 +2019,7 @@ void Spell::EffectDummy(uint32 i) if (m_caster->GetTypeId() != TYPEID_PLAYER) return; - if (Item *item = ((Player*)m_caster)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND)) + if (Item *item = m_caster->ToPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND)) { // Damage is increased by 25% if your off-hand weapon is enchanted with Flametongue. if (m_caster->GetAuraEffect(SPELL_AURA_DUMMY, SPELLFAMILY_SHAMAN, 0x200000, 0, 0)) @@ -2100,7 +2100,7 @@ void Spell::EffectDummy(uint32 i) triggered = false; } // Remove cooldown - summon spellls have category - ((Player*)m_caster)->RemoveSpellCooldown(m_spellInfo->Id,true); + m_caster->ToPlayer()->RemoveSpellCooldown(m_spellInfo->Id,true); spell_id=48289; } // Raise dead - take reagents and trigger summon spells @@ -2291,7 +2291,7 @@ void Spell::EffectTriggerSpell(uint32 effIndex) // get highest rank of the Stealth spell uint32 spellId = 0; SpellEntry const *spellInfo; - const PlayerSpellMap& sp_list = ((Player*)unitTarget)->GetSpellMap(); + const PlayerSpellMap& sp_list = unitTarget->ToPlayer()->GetSpellMap(); for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr) { // only highest rank is shown in spell book, so simply check if shown in spell book @@ -2314,8 +2314,8 @@ void Spell::EffectTriggerSpell(uint32 effIndex) return; // reset cooldown on it if needed - if (((Player*)unitTarget)->HasSpellCooldown(spellId)) - ((Player*)unitTarget)->RemoveSpellCooldown(spellId); + if (unitTarget->ToPlayer()->HasSpellCooldown(spellId)) + unitTarget->ToPlayer()->RemoveSpellCooldown(spellId); // Push stealth to list because it must be handled after combat remove m_TriggerSpells.push_back(spellInfo); @@ -2411,7 +2411,7 @@ void Spell::EffectTriggerSpell(uint32 effIndex) // Needed by freezing arrow and few other spells if (m_caster->GetTypeId() == TYPEID_PLAYER && m_spellInfo->CategoryRecoveryTime && spellInfo->CategoryRecoveryTime && m_spellInfo->Category == spellInfo->Category) - ((Player*)m_caster)->RemoveSpellCooldown(spellInfo->Id); + m_caster->ToPlayer()->RemoveSpellCooldown(spellInfo->Id); // Note: not exist spells with weapon req. and IsSpellHaveCasterSourceTargets == true // so this just for speedup places in else @@ -2441,7 +2441,7 @@ void Spell::EffectTriggerMissileSpell(uint32 effect_idx) // Needed by freezing arrow and few other spells if (m_caster->GetTypeId() == TYPEID_PLAYER && m_spellInfo->CategoryRecoveryTime && spellInfo->CategoryRecoveryTime && m_spellInfo->Category == spellInfo->Category) - ((Player*)m_caster)->RemoveSpellCooldown(spellInfo->Id); + m_caster->ToPlayer()->RemoveSpellCooldown(spellInfo->Id); float x, y, z; m_targets.m_dstPos.GetPosition(x, y, z); @@ -2469,7 +2469,7 @@ void Spell::EffectJump(uint32 i) else if(m_caster->getVictim()) pTarget = m_caster->getVictim(); else if(m_caster->GetTypeId() == TYPEID_PLAYER) - pTarget = ObjectAccessor::GetUnit(*m_caster, ((Player*)m_caster)->GetSelection()); + pTarget = ObjectAccessor::GetUnit(*m_caster, m_caster->ToPlayer()->GetSelection()); o = pTarget ? pTarget->GetOrientation() : m_caster->GetOrientation(); } @@ -2529,7 +2529,7 @@ void Spell::EffectTeleportUnits(uint32 i) if (mapid == unitTarget->GetMapId()) unitTarget->NearTeleportTo(x, y, z, orientation, unitTarget == m_caster); else if(unitTarget->GetTypeId() == TYPEID_PLAYER) - ((Player*)unitTarget)->TeleportTo(mapid, x, y, z, orientation, unitTarget == m_caster ? TELE_TO_SPELL : 0); + unitTarget->ToPlayer()->TeleportTo(mapid, x, y, z, orientation, unitTarget == m_caster ? TELE_TO_SPELL : 0); // post effects for TARGET_DST_DB switch (m_spellInfo->Id) @@ -2574,7 +2574,7 @@ void Spell::EffectTeleportUnits(uint32 i) case 5: // Transform { - if (((Player*)m_caster)->GetTeam() == ALLIANCE ) + if (m_caster->ToPlayer()->GetTeam() == ALLIANCE ) m_caster->CastSpell(m_caster, 36897, true); else m_caster->CastSpell(m_caster, 36899, true); @@ -2615,7 +2615,7 @@ void Spell::EffectTeleportUnits(uint32 i) case 4: // Transform { - if (((Player*)m_caster)->GetTeam() == ALLIANCE ) + if (m_caster->ToPlayer()->GetTeam() == ALLIANCE ) m_caster->CastSpell(m_caster, 36897, true); else m_caster->CastSpell(m_caster, 36899, true); @@ -3611,7 +3611,7 @@ void Spell::EffectSummonType(uint32 i) ItemPrototype const *proto = m_CastItem->GetProto(); if (proto && proto->RequiredSkill == SKILL_ENGINERING) { - uint16 skill202 = ((Player*)m_caster)->GetSkillValue(SKILL_ENGINERING); + uint16 skill202 = m_caster->ToPlayer()->GetSkillValue(SKILL_ENGINERING); if (skill202) level = skill202/5; } @@ -3658,13 +3658,13 @@ void Spell::EffectSummonType(uint32 i) && properties->Slot >= SUMMON_SLOT_TOTEM && properties->Slot < MAX_TOTEM_SLOT) { - //summon->SendUpdateToPlayer((Player*)m_originalCaster); + //summon->SendUpdateToPlayerm_originalCaster->ToPlayer(); WorldPacket data(SMSG_TOTEM_CREATED, 1+8+4+4); data << uint8(properties->Slot-1); data << uint64(m_originalCaster->GetGUID()); data << uint32(duration); data << uint32(m_spellInfo->Id); - ((Player*)m_originalCaster)->SendDirectMessage(&data); + m_originalCaster->ToPlayer()->SendDirectMessage(&data); } break; } @@ -3891,8 +3891,8 @@ void Spell::EffectDistract(uint32 /*i*/) if (unitTarget->GetTypeId() == TYPEID_PLAYER) { // For players just turn them - ((Player*)unitTarget)->SetPosition(unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), angle, false); - ((Player*)unitTarget)->SendTeleportAckMsg(); + unitTarget->ToPlayer()->SetPosition(unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), angle, false); + unitTarget->ToPlayer()->SendTeleportAckMsg(); } else { @@ -3914,7 +3914,7 @@ void Spell::EffectPickPocket(uint32 /*i*/) // victim have to be alive and humanoid or undead if (unitTarget->isAlive() && (unitTarget->GetCreatureTypeMask() &CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD) != 0) - ((Player*)m_caster)->SendLoot(unitTarget->GetGUID(),LOOT_PICKPOCKETING); + m_caster->ToPlayer()->SendLoot(unitTarget->GetGUID(),LOOT_PICKPOCKETING); } void Spell::EffectAddFarsight(uint32 i) @@ -3941,8 +3941,8 @@ void Spell::EffectAddFarsight(uint32 i) dynObj->GetMap()->Add(dynObj); //grid will also be loaded // Need to update visibility of object for client to accept farsight guid - ((Player*)m_caster)->SetViewpoint(dynObj, true); - //((Player*)m_caster)->UpdateVisibilityOf(dynObj); + m_caster->ToPlayer()->SetViewpoint(dynObj, true); + //m_caster->ToPlayer()->UpdateVisibilityOf(dynObj); } void Spell::EffectTeleUnitsFaceCaster(uint32 i) @@ -3970,8 +3970,8 @@ void Spell::EffectLearnSkill(uint32 i) return; uint32 skillid = m_spellInfo->EffectMiscValue[i]; - uint16 skillval = ((Player*)unitTarget)->GetPureSkillValue(skillid); - ((Player*)unitTarget)->SetSkill(skillid, skillval?skillval:1, damage*75); + uint16 skillval = unitTarget->ToPlayer()->GetPureSkillValue(skillid); + unitTarget->ToPlayer()->SetSkill(skillid, skillval?skillval:1, damage*75); } void Spell::EffectAddHonor(uint32 /*i*/) @@ -3982,8 +3982,8 @@ void Spell::EffectAddHonor(uint32 /*i*/) // not scale value for item based reward (/10 value expected) if (m_CastItem) { - ((Player*)unitTarget)->RewardHonor(NULL, 1, damage/10); - sLog.outError("SpellEffect::AddHonor (spell_id %u) rewards %d honor points (item %u) for player: %u", m_spellInfo->Id, damage/10, m_CastItem->GetEntry(),((Player*)unitTarget)->GetGUIDLow()); + unitTarget->ToPlayer()->RewardHonor(NULL, 1, damage/10); + sLog.outError("SpellEffect::AddHonor (spell_id %u) rewards %d honor points (item %u) for player: %u", m_spellInfo->Id, damage/10, m_CastItem->GetEntry(),unitTarget->ToPlayer()->GetGUIDLow()); return; } @@ -3991,14 +3991,14 @@ void Spell::EffectAddHonor(uint32 /*i*/) if (damage <= 50) { uint32 honor_reward = Trinity::Honor::hk_honor_at_level(unitTarget->getLevel(), damage); - ((Player*)unitTarget)->RewardHonor(NULL, 1, honor_reward); - sLog.outDebug("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (scale) to player: %u", m_spellInfo->Id, honor_reward, ((Player*)unitTarget)->GetGUIDLow()); + unitTarget->ToPlayer()->RewardHonor(NULL, 1, honor_reward); + sLog.outDebug("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (scale) to player: %u", m_spellInfo->Id, honor_reward, unitTarget->ToPlayer()->GetGUIDLow()); } else { //maybe we have correct honor_gain in damage already - ((Player*)unitTarget)->RewardHonor(NULL, 1, damage); - sLog.outError("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (non scale) for player: %u", m_spellInfo->Id, damage, ((Player*)unitTarget)->GetGUIDLow()); + unitTarget->ToPlayer()->RewardHonor(NULL, 1, damage); + sLog.outError("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (non scale) for player: %u", m_spellInfo->Id, damage, unitTarget->ToPlayer()->GetGUIDLow()); } } @@ -4007,8 +4007,8 @@ void Spell::EffectTradeSkill(uint32 /*i*/) if (unitTarget->GetTypeId() != TYPEID_PLAYER) return; // uint32 skillid = m_spellInfo->EffectMiscValue[i]; - // uint16 skillmax = ((Player*)unitTarget)->(skillid); - // ((Player*)unitTarget)->SetSkill(skillid,skillval?skillval:1,skillmax+75); + // uint16 skillmax = unitTarget->ToPlayer()->(skillid); + // unitTarget->ToPlayer()->SetSkill(skillid,skillval?skillval:1,skillmax+75); } void Spell::EffectEnchantItemPerm(uint32 effect_idx) @@ -4304,7 +4304,7 @@ void Spell::EffectTameCreature(uint32 /*i*/) if (m_caster->GetTypeId() == TYPEID_PLAYER) { pet->SavePetToDB(PET_SAVE_AS_CURRENT); - ((Player*)m_caster)->PetSpellInitialize(); + m_caster->ToPlayer()->PetSpellInitialize(); } } @@ -4353,13 +4353,13 @@ void Spell::EffectSummonPet(uint32 i) //owner->GetMap()->Add((Creature*)OldSummon); if (owner->GetTypeId() == TYPEID_PLAYER && OldSummon->isControlled() ) - ((Player*)owner)->PetSpellInitialize(); + owner->ToPlayer()->PetSpellInitialize(); return; } if (owner->GetTypeId() == TYPEID_PLAYER) - ((Player*)owner)->RemovePet(OldSummon,(OldSummon->getPetType()==HUNTER_PET ? PET_SAVE_AS_DELETED : PET_SAVE_NOT_IN_SLOT),false); + owner->ToPlayer()->RemovePet(OldSummon,(OldSummon->getPetType()==HUNTER_PET ? PET_SAVE_AS_DELETED : PET_SAVE_NOT_IN_SLOT),false); else return; } @@ -4508,14 +4508,14 @@ void Spell::SpellDamageWeaponDmg(uint32 i) if (m_spellInfo->SpellFamilyFlags[0] & 0x2000000) { if (m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->AddComboPoints(unitTarget, 1, this); + m_caster->ToPlayer()->AddComboPoints(unitTarget, 1, this); } // Fan of Knives else if (m_spellInfo->SpellFamilyFlags[1] & 0x40000) { // 50% more damage with daggers if (m_caster->GetTypeId() == TYPEID_PLAYER) - if (Item* item = ((Player*)m_caster)->GetWeaponForAttack(m_attackType, true)) + if (Item* item = m_caster->ToPlayer()->GetWeaponForAttack(m_attackType, true)) if (item->GetProto()->SubClass == ITEM_SUBCLASS_WEAPON_DAGGER) totalDamagePercentMod *= 1.5f; } @@ -4575,7 +4575,7 @@ void Spell::SpellDamageWeaponDmg(uint32 i) if(m_spellInfo->SpellFamilyFlags[1] & 0x400) { if(m_caster->GetTypeId() == TYPEID_PLAYER) - ((Player*)m_caster)->AddComboPoints(unitTarget,1, this); + m_caster->ToPlayer()->AddComboPoints(unitTarget,1, this); } // Shred, Maul - Rend and Tear else if (m_spellInfo->SpellFamilyFlags[0] & 0x00008800 && unitTarget->HasAuraState(AURA_STATE_BLEEDING)) @@ -4894,7 +4894,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) if(m_caster->GetTypeId() != TYPEID_PLAYER) return; - Player* plr = ((Player*)m_caster); + Player* plr = m_caster->ToPlayer(); if(plr && plr->GetLastPetNumber()) { PetType NewPetType = (plr->getClass()==CLASS_HUNTER) ? HUNTER_PET : SUMMON_PET; @@ -5204,16 +5204,16 @@ void Spell::EffectScriptEffect(uint32 effIndex) if(!unitTarget) return; - switch(((Player*)unitTarget)->GetBaseSkillValue(762)) + switch(unitTarget->ToPlayer()->GetBaseSkillValue(762)) { case 75: unitTarget->CastSpell(unitTarget, 51621, true); break;; case 150: unitTarget->CastSpell(unitTarget, 48024, true); break; case 225: - if(((Player*)unitTarget)->GetMapId()==571 || ((Player*)unitTarget)->GetMapId()==530) + if(unitTarget->ToPlayer()->GetMapId()==571 || unitTarget->ToPlayer()->GetMapId()==530) unitTarget->CastSpell(unitTarget, 51617, true); break; case 300: - if(((Player*)unitTarget)->GetMapId()==571 || ((Player*)unitTarget)->GetMapId()==530) + if(unitTarget->ToPlayer()->GetMapId()==571 || unitTarget->ToPlayer()->GetMapId()==530) unitTarget->CastSpell(unitTarget, 48023, true); break; default: break; @@ -5227,7 +5227,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) if(unitTarget) { - switch(((Player*)unitTarget)->GetBaseSkillValue(762)) + switch(unitTarget->ToPlayer()->GetBaseSkillValue(762)) { case 75: unitTarget->CastSpell(unitTarget, 42680, true); break;; case 150: case 225: case 300: unitTarget->CastSpell(unitTarget, 42683, true); break; @@ -5248,7 +5248,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) while (bag < 256) { - item = ((Player*)m_caster)->GetItemByPos(bag, slot); + item = m_caster->ToPlayer()->GetItemByPos(bag, slot); if (item && item->GetEntry() == 38587) break; ++slot; if (slot == 39) @@ -5259,8 +5259,8 @@ void Spell::EffectScriptEffect(uint32 effIndex) } if (bag < 256) { - if (((Player*)m_caster)->GetItemByPos(bag,slot)->GetCount() == 1) ((Player*)m_caster)->RemoveItem(bag,slot,true); - else ((Player*)m_caster)->GetItemByPos(bag,slot)->SetCount(((Player*)m_caster)->GetItemByPos(bag,slot)->GetCount()-1); + if (m_caster->ToPlayer()->GetItemByPos(bag,slot)->GetCount() == 1) m_caster->ToPlayer()->RemoveItem(bag,slot,true); + else m_caster->ToPlayer()->GetItemByPos(bag,slot)->SetCount(m_caster->ToPlayer()->GetItemByPos(bag,slot)->GetCount()-1); // Spell 42518 (Braufest - Gratisprobe des Braufest herstellen) m_caster->CastSpell(m_caster, 42518, true); return; @@ -5329,7 +5329,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)unitTarget)->ModifyMoney(5000 * GOLD); + unitTarget->ToPlayer()->ModifyMoney(5000 * GOLD); break; } @@ -5362,7 +5362,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) return; // Remove Taunt cooldown - ((Player*)unitTarget)->RemoveSpellCooldown(355, true); + unitTarget->ToPlayer()->RemoveSpellCooldown(355, true); return; } @@ -5477,7 +5477,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) unitTarget->RemoveAurasByType(SPELL_AURA_MOUNTED); // Triggered spell id dependent of riding skill - if(uint16 skillval = ((Player*)unitTarget)->GetSkillValue(SKILL_RIDING)) + if(uint16 skillval = unitTarget->ToPlayer()->GetSkillValue(SKILL_RIDING)) { if (skillval >= 300) unitTarget->CastSpell(unitTarget, 54727, true); @@ -5495,7 +5495,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) uint32 spellID = m_spellInfo->CalculateSimpleValue(0); uint32 questID = m_spellInfo->CalculateSimpleValue(1); - if (((Player*)unitTarget)->GetQuestStatus(questID) == QUEST_STATUS_COMPLETE && !((Player*)unitTarget)->GetQuestRewardStatus (questID)) + if (unitTarget->ToPlayer()->GetQuestStatus(questID) == QUEST_STATUS_COMPLETE && !unitTarget->ToPlayer()->GetQuestRewardStatus (questID)) unitTarget->CastSpell(unitTarget, spellID, true); return; @@ -5568,7 +5568,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) unitTarget->RemoveAurasByType(SPELL_AURA_MOUNTED); // Triggered spell id dependent of riding skill - if(uint16 skillval = ((Player*)unitTarget)->GetSkillValue(SKILL_RIDING)) + if(uint16 skillval = unitTarget->ToPlayer()->GetSkillValue(SKILL_RIDING)) { if (skillval >= 150) unitTarget->CastSpell(unitTarget, 58999, true); @@ -5582,7 +5582,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) return; // return from top - if (((Player*)unitTarget)->GetAreaId() == 4637) + if (unitTarget->ToPlayer()->GetAreaId() == 4637) unitTarget->CastSpell(unitTarget, 59316, true); // teleport atop else @@ -5601,7 +5601,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) // learn random explicit discovery recipe (if any) if(uint32 discoveredSpell = GetExplicitDiscoverySpell(m_spellInfo->Id, (Player*)m_caster)) - ((Player*)m_caster)->learnSpell(discoveredSpell, false); + m_caster->ToPlayer()->learnSpell(discoveredSpell, false); return; } case 62428: // Load into Catapult @@ -5950,7 +5950,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) if (m_caster->GetTypeId() != TYPEID_PLAYER) return; - if (Pet *PlrPet = ((Player*)m_caster)->GetPet()) + if (Pet *PlrPet = m_caster->ToPlayer()->GetPet()) m_caster->CastSpell(PlrPet, 62305, true); return; } @@ -6152,7 +6152,7 @@ void Spell::EffectSanctuary(uint32 /*i*/) { ((Player *)m_caster)->RemoveAurasByType(SPELL_AURA_MOD_ROOT); // Overkill - if(((Player*)m_caster)->HasSpell(58426)) + if(m_caster->ToPlayer()->HasSpell(58426)) m_caster->CastSpell(m_caster, 58427, true); } } @@ -6299,13 +6299,13 @@ void Spell::EffectSummonPlayer(uint32 /*i*/) float x, y, z; m_caster->GetClosePoint(x, y, z, unitTarget->GetObjectSize()); - ((Player*)unitTarget)->SetSummonPoint(m_caster->GetMapId(),x,y,z); + unitTarget->ToPlayer()->SetSummonPoint(m_caster->GetMapId(),x,y,z); WorldPacket data(SMSG_SUMMON_REQUEST, 8+4+4); data << uint64(m_caster->GetGUID()); // summoner guid data << uint32(m_caster->GetZoneId()); // summoner zone data << uint32(MAX_PLAYER_SUMMON_DELAY*IN_MILISECONDS); // auto decline after msecs - ((Player*)unitTarget)->GetSession()->SendPacket(&data); + unitTarget->ToPlayer()->GetSession()->SendPacket(&data); } static ScriptInfo generateActivateCommand() @@ -6418,7 +6418,7 @@ void Spell::EffectDisEnchant(uint32 /*i*/) p_caster->UpdateCraftSkill(m_spellInfo->Id); - ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(),LOOT_DISENCHANTING); + m_caster->ToPlayer()->SendLoot(itemTarget->GetGUID(),LOOT_DISENCHANTING); // item will be removed at disenchanting end } @@ -6472,13 +6472,13 @@ void Spell::EffectDismissPet(uint32 /*i*/) if(m_caster->GetTypeId() != TYPEID_PLAYER) return; - Pet* pet = ((Player*)m_caster)->GetPet(); + Pet* pet = m_caster->ToPlayer()->GetPet(); // not let dismiss dead pet if(!pet||!pet->isAlive()) return; - ((Player*)m_caster)->RemovePet(pet, PET_SAVE_NOT_IN_SLOT); + m_caster->ToPlayer()->RemovePet(pet, PET_SAVE_NOT_IN_SLOT); } void Spell::EffectSummonObject(uint32 i) @@ -6575,7 +6575,7 @@ void Spell::EffectResurrect(uint32 /*effIndex*/) break; } - Player* pTarget = ((Player*)unitTarget); + Player* pTarget = unitTarget->ToPlayer(); if(pTarget->isRessurectRequested()) // already have one active request return; @@ -6614,13 +6614,13 @@ void Spell::EffectAddExtraAttacks(uint32 /*i*/) void Spell::EffectParry(uint32 /*i*/) { if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER) - ((Player*)unitTarget)->SetCanParry(true); + unitTarget->ToPlayer()->SetCanParry(true); } void Spell::EffectBlock(uint32 /*i*/) { if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER) - ((Player*)unitTarget)->SetCanBlock(true); + unitTarget->ToPlayer()->SetCanBlock(true); } void Spell::EffectLeapForward(uint32 i) @@ -6741,7 +6741,7 @@ void Spell::EffectSelfResurrect(uint32 i) mana = uint32(damage/100.0f*unitTarget->GetMaxPower(POWER_MANA)); } - Player *plr = ((Player*)unitTarget); + Player *plr = unitTarget->ToPlayer(); plr->ResurrectPlayer(0.0f); plr->SetHealth( health ); @@ -6764,15 +6764,15 @@ void Spell::EffectSkinning(uint32 /*i*/) uint32 skill = creature->GetCreatureInfo()->GetRequiredLootSkill(); - ((Player*)m_caster)->SendLoot(creature->GetGUID(),LOOT_SKINNING); + m_caster->ToPlayer()->SendLoot(creature->GetGUID(),LOOT_SKINNING); creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); int32 reqValue = targetLevel < 10 ? 0 : targetLevel < 20 ? (targetLevel-10)*10 : targetLevel*5; - int32 skillValue = ((Player*)m_caster)->GetPureSkillValue(skill); + int32 skillValue = m_caster->ToPlayer()->GetPureSkillValue(skill); // Double chances for elites - ((Player*)m_caster)->UpdateGatherSkill(skill, skillValue, reqValue, creature->isElite() ? 2 : 1 ); + m_caster->ToPlayer()->UpdateGatherSkill(skill, skillValue, reqValue, creature->isElite() ? 2 : 1 ); } void Spell::EffectCharge(uint32 /*i*/) @@ -6872,7 +6872,7 @@ void Spell::EffectSendTaxi(uint32 i) if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)unitTarget)->ActivateTaxiPathTo(m_spellInfo->EffectMiscValue[i],m_spellInfo->Id); + unitTarget->ToPlayer()->ActivateTaxiPathTo(m_spellInfo->EffectMiscValue[i],m_spellInfo->Id); } void Spell::EffectPlayerPull(uint32 i) @@ -6984,7 +6984,7 @@ void Spell::EffectDurabilityDamage(uint32 i) // Possibly its mean -1 all player equipped items and -2 all items if(slot < 0) { - ((Player*)unitTarget)->DurabilityPointsLossAll(damage, (slot < -1)); + unitTarget->ToPlayer()->DurabilityPointsLossAll(damage, (slot < -1)); return; } @@ -6992,8 +6992,8 @@ void Spell::EffectDurabilityDamage(uint32 i) if(slot >= INVENTORY_SLOT_BAG_END) return; - if(Item* item = ((Player*)unitTarget)->GetItemByPos(INVENTORY_SLOT_BAG_0, slot)) - ((Player*)unitTarget)->DurabilityPointsLoss(item, damage); + if(Item* item = unitTarget->ToPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, slot)) + unitTarget->ToPlayer()->DurabilityPointsLoss(item, damage); } void Spell::EffectDurabilityDamagePCT(uint32 i) @@ -7007,7 +7007,7 @@ void Spell::EffectDurabilityDamagePCT(uint32 i) // Possibly its mean -1 all player equipped items and -2 all items if(slot < 0) { - ((Player*)unitTarget)->DurabilityLossAll(double(damage)/100.0f, (slot < -1)); + unitTarget->ToPlayer()->DurabilityLossAll(double(damage)/100.0f, (slot < -1)); return; } @@ -7018,8 +7018,8 @@ void Spell::EffectDurabilityDamagePCT(uint32 i) if(damage <= 0) return; - if(Item* item = ((Player*)unitTarget)->GetItemByPos(INVENTORY_SLOT_BAG_0, slot)) - ((Player*)unitTarget)->DurabilityLoss(item, double(damage)/100.0f); + if(Item* item = unitTarget->ToPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, slot)) + unitTarget->ToPlayer()->DurabilityLoss(item, double(damage)/100.0f); } void Spell::EffectModifyThreatPercent(uint32 /*effIndex*/) @@ -7124,8 +7124,8 @@ void Spell::EffectTransmitted(uint32 effIndex) { if(m_caster->GetTypeId() == TYPEID_PLAYER) { - pGameObj->AddUniqueUse((Player*)m_caster); - m_caster->AddGameObject(pGameObj); // will removed at spell cancel + pGameObj->AddUniqueUse(m_caster->ToPlayer()); + m_caster->AddGameObject(pGameObj); // will removed at spell cancel } break; } @@ -7192,7 +7192,7 @@ void Spell::EffectProspecting(uint32 /*i*/) p_caster->UpdateGatherSkill(SKILL_JEWELCRAFTING, SkillValue, reqSkillValue); } - ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(), LOOT_PROSPECTING); + m_caster->ToPlayer()->SendLoot(itemTarget->GetGUID(), LOOT_PROSPECTING); } void Spell::EffectMilling(uint32 /*i*/) @@ -7214,7 +7214,7 @@ void Spell::EffectMilling(uint32 /*i*/) p_caster->UpdateGatherSkill(SKILL_INSCRIPTION, SkillValue, reqSkillValue); } - ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(), LOOT_MILLING); + m_caster->ToPlayer()->SendLoot(itemTarget->GetGUID(), LOOT_MILLING); } void Spell::EffectSkill(uint32 /*i*/) @@ -7237,9 +7237,9 @@ void Spell::EffectSpiritHeal(uint32 /*i*/) return; //m_spellInfo->EffectBasePoints[i]; == 99 (percent?) - //((Player*)unitTarget)->setResurrect(m_caster->GetGUID(), unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), unitTarget->GetMaxHealth(), unitTarget->GetMaxPower(POWER_MANA)); - ((Player*)unitTarget)->ResurrectPlayer(1.0f); - ((Player*)unitTarget)->SpawnCorpseBones(); + //unitTarget->ToPlayer()->setResurrect(m_caster->GetGUID(), unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), unitTarget->GetMaxHealth(), unitTarget->GetMaxPower(POWER_MANA)); + unitTarget->ToPlayer()->ResurrectPlayer(1.0f); + unitTarget->ToPlayer()->SpawnCorpseBones(); */ } @@ -7250,7 +7250,7 @@ void Spell::EffectSkinPlayerCorpse(uint32 /*i*/) if ( (m_caster->GetTypeId() != TYPEID_PLAYER) || (unitTarget->GetTypeId() != TYPEID_PLAYER) || (unitTarget->isAlive()) ) return; - ((Player*)unitTarget)->RemovedInsignia( (Player*)m_caster ); + unitTarget->ToPlayer()->RemovedInsignia( (Player*)m_caster ); } void Spell::EffectStealBeneficialBuff(uint32 i) @@ -7321,7 +7321,7 @@ void Spell::EffectKillCreditPersonal(uint32 i) if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)unitTarget)->KilledMonsterCredit(m_spellInfo->EffectMiscValue[i], 0); + unitTarget->ToPlayer()->KilledMonsterCredit(m_spellInfo->EffectMiscValue[i], 0); } void Spell::EffectKillCredit(uint32 i) @@ -7337,7 +7337,7 @@ void Spell::EffectKillCredit(uint32 i) } if(creatureEntry) - ((Player*)unitTarget)->RewardPlayerAndGroupAtEvent(creatureEntry, unitTarget); + unitTarget->ToPlayer()->RewardPlayerAndGroupAtEvent(creatureEntry, unitTarget); } void Spell::EffectQuestFail(uint32 i) @@ -7345,7 +7345,7 @@ void Spell::EffectQuestFail(uint32 i) if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)unitTarget)->FailQuest(m_spellInfo->EffectMiscValue[i]); + unitTarget->ToPlayer()->FailQuest(m_spellInfo->EffectMiscValue[i]); } void Spell::EffectActivateRune(uint32 eff_idx) @@ -7359,7 +7359,7 @@ void Spell::EffectActivateRune(uint32 eff_idx) return; // needed later - m_runesState = ((Player*)m_caster)->GetRunesState(); + m_runesState = m_caster->ToPlayer()->GetRunesState(); uint32 count = damage; if (count == 0) count = 1; @@ -7389,7 +7389,7 @@ void Spell::EffectActivateRune(uint32 eff_idx) void Spell::EffectTitanGrip(uint32 /*eff_idx*/) { if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER) - ((Player*)unitTarget)->SetCanTitanGrip(true); + unitTarget->ToPlayer()->SetCanTitanGrip(true); } void Spell::EffectRedirectThreat(uint32 /*i*/) @@ -7437,7 +7437,7 @@ void Spell::SummonGuardian(uint32 i, uint32 entry, SummonPropertiesEntry const * if (m_CastItem && caster->GetTypeId() == TYPEID_PLAYER) if (ItemPrototype const *proto = m_CastItem->GetProto()) if (proto->RequiredSkill == SKILL_ENGINERING) - if (uint16 skill202 = ((Player*)caster)->GetSkillValue(SKILL_ENGINERING)) + if (uint16 skill202 = caster->ToPlayer()->GetSkillValue(SKILL_ENGINERING)) level = skill202/5; //float radius = GetSpellRadiusForFriend(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i])); @@ -7550,7 +7550,7 @@ void Spell::EffectPlayMusic(uint32 i) WorldPacket data(SMSG_PLAY_MUSIC, 4); data << uint32(soundid); - ((Player*)unitTarget)->GetSession()->SendPacket(&data); + unitTarget->ToPlayer()->GetSession()->SendPacket(&data); } void Spell::EffectSpecCount(uint32 /*eff_idx*/) @@ -7558,7 +7558,7 @@ void Spell::EffectSpecCount(uint32 /*eff_idx*/) if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)unitTarget)->UpdateSpecCount(damage); + unitTarget->ToPlayer()->UpdateSpecCount(damage); } void Spell::EffectActivateSpec(uint32 /*eff_idx*/) @@ -7566,7 +7566,7 @@ void Spell::EffectActivateSpec(uint32 /*eff_idx*/) if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)unitTarget)->ActivateSpec(damage-1); // damage is 1 or 2, spec is 0 or 1 + unitTarget->ToPlayer()->ActivateSpec(damage-1); // damage is 1 or 2, spec is 0 or 1 } void Spell::EffectPlayerNotification(uint32 /*eff_idx*/) diff --git a/src/game/SpellHandler.cpp b/src/game/SpellHandler.cpp index 74e29ec0b3c..99de86f96d7 100644 --- a/src/game/SpellHandler.cpp +++ b/src/game/SpellHandler.cpp @@ -314,7 +314,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket) if(mover->GetTypeId() == TYPEID_PLAYER) { // not have spell in spellbook or spell passive and not casted by client - if (!((Player*)mover)->HasActiveSpell (spellId) || IsPassiveSpell(spellId) ) + if (!mover->ToPlayer()->HasActiveSpell (spellId) || IsPassiveSpell(spellId) ) { //cheater? kick? ban? recvPacket.rpos(recvPacket.wpos()); // prevent spam at ignore packet diff --git a/src/game/TemporarySummon.cpp b/src/game/TemporarySummon.cpp index dc4c8800384..5b9f19a2278 100644 --- a/src/game/TemporarySummon.cpp +++ b/src/game/TemporarySummon.cpp @@ -334,7 +334,7 @@ void Guardian::InitSummon() if(m_owner->GetTypeId() == TYPEID_PLAYER && m_owner->GetMinionGUID() == GetGUID() && !m_owner->GetCharmGUID()) - ((Player*)m_owner)->CharmSpellInitialize(); + m_owner->ToPlayer()->CharmSpellInitialize(); } Puppet::Puppet(SummonPropertiesEntry const *properties, Unit *owner) : Minion(properties, owner) diff --git a/src/game/ThreatManager.cpp b/src/game/ThreatManager.cpp index ad22ba6b5c1..8b4ea04718f 100644 --- a/src/game/ThreatManager.cpp +++ b/src/game/ThreatManager.cpp @@ -370,7 +370,7 @@ void ThreatManager::addThreat(Unit* pVictim, float fThreat, SpellSchoolMask scho return; // not to GM - if (!pVictim || (pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->isGameMaster())) + if (!pVictim || (pVictim->GetTypeId() == TYPEID_PLAYER && pVictim->ToPlayer()->isGameMaster())) return; // not to dead and not for dead @@ -406,7 +406,7 @@ void ThreatManager::_addThreat(Unit *pVictim, float fThreat) HostilReference* hostilReference = new HostilReference(pVictim, this, 0); iThreatContainer.addReference(hostilReference); hostilReference->addThreat(fThreat); // now we add the real threat - if(pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->isGameMaster()) + if(pVictim->GetTypeId() == TYPEID_PLAYER && pVictim->ToPlayer()->isGameMaster()) hostilReference->setOnlineOfflineState(false); // GM is always offline } } diff --git a/src/game/Totem.cpp b/src/game/Totem.cpp index 6b277136444..971482050a8 100644 --- a/src/game/Totem.cpp +++ b/src/game/Totem.cpp @@ -59,11 +59,11 @@ void Totem::InitStats(uint32 duration) CreatureInfo const *cinfo = GetCreatureInfo(); if(m_owner->GetTypeId() == TYPEID_PLAYER && cinfo) { - uint32 display_id = objmgr.ChooseDisplayId(((Player*)m_owner)->GetTeam(), cinfo); + uint32 display_id = objmgr.ChooseDisplayId(m_owner->ToPlayer()->GetTeam(), cinfo); CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id); if (minfo) display_id = minfo->modelid; - switch (((Player*)m_owner)->GetTeam()) + switch (m_owner->ToPlayer()->GetTeam()) { case ALLIANCE: display_id = cinfo->Modelid1; @@ -146,9 +146,9 @@ void Totem::UnSummon() Group *pGroup = NULL; if (m_owner->GetTypeId() == TYPEID_PLAYER) { - ((Player*)m_owner)->SendAutoRepeatCancel(this); + m_owner->ToPlayer()->SendAutoRepeatCancel(this); // Not only the player can summon the totem (scripted AI) - pGroup = ((Player*)m_owner)->GetGroup(); + pGroup = m_owner->ToPlayer()->GetGroup(); if (pGroup) { for (GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next()) diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index adee7ab39a3..392cb3ec3f9 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -280,7 +280,7 @@ void Unit::Update(uint32 p_time) bool Unit::haveOffhandWeapon() const { if (GetTypeId() == TYPEID_PLAYER) - return ((Player*)this)->GetWeaponForAttack(OFF_ATTACK,true); + return this->ToPlayer()->GetWeaponForAttack(OFF_ATTACK,true); else return m_canDualWield; } @@ -666,7 +666,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa // some critters required for quests (need normal entry instead possible heroic in any cases) if (GetTypeId() == TYPEID_PLAYER) if (CreatureInfo const* normalInfo = objmgr.GetCreatureTemplate(pVictim->GetEntry())) - ((Player*)this)->KilledMonster(normalInfo,pVictim->GetGUID()); + this->ToPlayer()->KilledMonster(normalInfo,pVictim->GetGUID()); } else pVictim->ModifyHealth(- (int32)damage); @@ -681,10 +681,10 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa // duel ends when player has 1 or less hp bool duel_hasEnded = false; - if (pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->duel && damage >= (health-1)) + if (pVictim->GetTypeId() == TYPEID_PLAYER && pVictim->ToPlayer()->duel && damage >= (health-1)) { // prevent kill only if killed in duel and killed by opponent or opponent controlled creature - if (((Player*)pVictim)->duel->opponent==this || ((Player*)pVictim)->duel->opponent->GetGUID() == GetOwnerGUID()) + if (pVictim->ToPlayer()->duel->opponent==this || pVictim->ToPlayer()->duel->opponent->GetGUID() == GetOwnerGUID()) damage = health-1; duel_hasEnded = true; @@ -692,7 +692,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa if (GetTypeId() == TYPEID_PLAYER && this != pVictim) { - Player *killer = ((Player*)this); + Player *killer = this->ToPlayer(); // in bg, count dmg if victim is also a player if (pVictim->GetTypeId() == TYPEID_PLAYER) @@ -709,7 +709,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa } if (pVictim->GetTypeId() == TYPEID_PLAYER) - ((Player*)pVictim)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_RECEIVED, damage); + pVictim->ToPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_RECEIVED, damage); else if (!pVictim->IsControlledByPlayer()) { //!pVictim->HasFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_OTHER_TAGGER) @@ -725,20 +725,20 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa DEBUG_LOG("DealDamage: victim just died"); if (pVictim->GetTypeId() == TYPEID_PLAYER) - ((Player*)pVictim)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED, health); + pVictim->ToPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED, health); Kill(pVictim, durabilityLoss); //Hook for OnPVPKill Event if (pVictim->GetTypeId() == TYPEID_PLAYER && this->GetTypeId() == TYPEID_PLAYER) { - Player *killer = ((Player*)this); - Player *killed = ((Player*)pVictim); + Player *killer = this->ToPlayer(); + Player *killed = pVictim->ToPlayer(); killer->GetSession()->HandleOnPVPKill(killed); } if (pVictim->GetTypeId() == TYPEID_UNIT && this->GetTypeId() == TYPEID_PLAYER) { - Player *killer = ((Player*)this); + Player *killer = this->ToPlayer(); Creature *pCreature = ((Creature*)pVictim); killer->GetSession()->HandleOnCreatureKill(pCreature); } @@ -748,7 +748,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa DEBUG_LOG("DealDamageAlive"); if (pVictim->GetTypeId() == TYPEID_PLAYER) - ((Player*)pVictim)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED, damage); + pVictim->ToPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED, damage); pVictim->ModifyHealth(- (int32)damage); @@ -772,7 +772,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_DAMAGE))) { EquipmentSlots slot = EquipmentSlots(urand(0,EQUIPMENT_SLOT_END-1)); - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(slot); + pVictim->ToPlayer()->DurabilityPointLossForEquipSlot(slot); } } @@ -789,7 +789,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_DAMAGE))) { EquipmentSlots slot = EquipmentSlots(urand(0,EQUIPMENT_SLOT_END-1)); - ((Player*)this)->DurabilityPointLossForEquipSlot(slot); + this->ToPlayer()->DurabilityPointLossForEquipSlot(slot); } } @@ -1660,7 +1660,7 @@ uint32 Unit::CalcArmorReducedDamage(Unit* pVictim, const uint32 damage, SpellEnt // Cap armor penetration to this number maxArmorPen = std::min(((armor+maxArmorPen)/3),armor); // Figure out how much armor do we ignore - float armorPen = maxArmorPen*((Player*)this)->GetRatingBonusValue(CR_ARMOR_PENETRATION) / 100.0f; + float armorPen = maxArmorPen*this->ToPlayer()->GetRatingBonusValue(CR_ARMOR_PENETRATION) / 100.0f; // Got the value, apply it armor -= armorPen; } @@ -1870,7 +1870,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff { if (!preventDeathSpell && pVictim->GetTypeId() == TYPEID_PLAYER && // Only players - !((Player*)pVictim)->HasSpellCooldown(31231) && // Only if no cooldown + !pVictim->ToPlayer()->HasSpellCooldown(31231) && // Only if no cooldown roll_chance_i((*i)->GetAmount())) // Only if roll { preventDeathSpell = (*i)->GetSpellProto(); @@ -1923,7 +1923,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff int32 remainingHealth = pVictim->GetHealth() - RemainingDamage; uint32 allowedHealth = pVictim->GetMaxHealth() * 0.35f; // If damage kills us - if (remainingHealth <= 0 && !((Player*)pVictim)->HasSpellCooldown(66235)) + if (remainingHealth <= 0 && !pVictim->ToPlayer()->HasSpellCooldown(66235)) { // Cast healing spell, completely avoid damage RemainingDamage = 0; @@ -1938,7 +1938,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff int32 healAmount = pVictim->GetMaxHealth() * (*i)->GetAmount() / 100.0f * pctFromDefense; pVictim->CastCustomSpell(pVictim, 66235, &healAmount, NULL, NULL, true); - ((Player*)pVictim)->AddSpellCooldown(66235,0,time(NULL) + 120); + pVictim->ToPlayer()->AddSpellCooldown(66235,0,time(NULL) + 120); } else if (remainingHealth < allowedHealth) { @@ -2183,7 +2183,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff if (preventDeathSpell->SpellIconID == 2109) { pVictim->CastSpell(pVictim,31231,true); - ((Player*)pVictim)->AddSpellCooldown(31231,0,time(NULL)+60); + pVictim->ToPlayer()->AddSpellCooldown(31231,0,time(NULL)+60); // with health > 10% lost health until health==10%, in other case no losses uint32 health10 = pVictim->GetMaxHealth()/10; RemainingDamage = pVictim->GetHealth() > health10 ? pVictim->GetHealth() - health10 : 0; @@ -2350,7 +2350,7 @@ MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttack { // Reduce dodge chance by attacker expertise rating if (GetTypeId() == TYPEID_PLAYER) - dodge_chance -= int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType)*100); + dodge_chance -= int32(this->ToPlayer()->GetExpertiseDodgeOrParryReduction(attType)*100); else dodge_chance -= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE)*25; @@ -2379,7 +2379,7 @@ MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttack { // Reduce parry chance by attacker expertise rating if (GetTypeId() == TYPEID_PLAYER) - parry_chance -= int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType)*100); + parry_chance -= int32(this->ToPlayer()->GetExpertiseDodgeOrParryReduction(attType)*100); else parry_chance -= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE)*25; @@ -2474,7 +2474,7 @@ uint32 Unit::CalculateDamage(WeaponAttackType attType, bool normalized, bool add float min_damage, max_damage; if (GetTypeId() == TYPEID_PLAYER && (normalized || !addTotalPct)) - ((Player*)this)->CalculateMinMaxDamage(attType,normalized,addTotalPct,min_damage, max_damage); + this->ToPlayer()->CalculateMinMaxDamage(attType,normalized,addTotalPct,min_damage, max_damage); else { switch (attType) @@ -2774,7 +2774,7 @@ SpellMissInfo Unit::MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell) dodgeChance = int32(float(dodgeChance) * GetTotalAuraMultiplier(SPELL_AURA_MOD_ENEMY_DODGE)); // Reduce dodge chance by attacker expertise rating if (GetTypeId() == TYPEID_PLAYER) - dodgeChance -= int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType) * 100.0f); + dodgeChance -= int32(this->ToPlayer()->GetExpertiseDodgeOrParryReduction(attType) * 100.0f); else dodgeChance -= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE)*25; if (dodgeChance < 0) @@ -2790,7 +2790,7 @@ SpellMissInfo Unit::MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell) int32 parryChance = int32(pVictim->GetUnitParryChance()*100.0f) - skillDiff * 4; // Reduce parry chance by attacker expertise rating if (GetTypeId() == TYPEID_PLAYER) - parryChance -= int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType) * 100.0f); + parryChance -= int32(this->ToPlayer()->GetExpertiseDodgeOrParryReduction(attType) * 100.0f); else parryChance -= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE)*25; if (parryChance < 0) @@ -2854,7 +2854,7 @@ SpellMissInfo Unit::MagicSpellHitResult(Unit *pVictim, SpellEntry const *spell) // Decrease hit chance from victim rating bonus if (pVictim->GetTypeId() == TYPEID_PLAYER) - HitChance -= int32(((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL)*100.0f); + HitChance -= int32(pVictim->ToPlayer()->GetRatingBonusValue(CR_HIT_TAKEN_SPELL)*100.0f); if (HitChance < 100) HitChance = 100; @@ -2999,9 +2999,9 @@ SpellMissInfo Unit::SpellHitResult(Unit *pVictim, SpellEntry const *spell, bool if (pVictim->GetTypeId() == TYPEID_PLAYER) { if (attType == RANGED_ATTACK) - misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED); + misschance += pVictim->ToPlayer()->GetRatingBonusValue(CR_HIT_TAKEN_RANGED); else - misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE); + misschance += pVictim->ToPlayer()->GetRatingBonusValue(CR_HIT_TAKEN_MELEE); } // Modify miss chance by victim auras @@ -3029,9 +3029,9 @@ uint32 Unit::GetDefenseSkillValue(Unit const* target) const { // in PvP use full skill instead current skill value uint32 value = (target && target->GetTypeId() == TYPEID_PLAYER) - ? ((Player*)this)->GetMaxSkillValue(SKILL_DEFENSE) - : ((Player*)this)->GetSkillValue(SKILL_DEFENSE); - value += uint32(((Player*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL)); + ? this->ToPlayer()->GetMaxSkillValue(SKILL_DEFENSE) + : this->ToPlayer()->GetSkillValue(SKILL_DEFENSE); + value += uint32(this->ToPlayer()->GetRatingBonusValue(CR_DEFENSE_SKILL)); return value; } else @@ -3181,7 +3181,7 @@ uint32 Unit::GetWeaponSkillValue (WeaponAttackType attType, Unit const* target) uint32 value = 0; if(GetTypeId() == TYPEID_PLAYER) { - Item* item = ((Player*)this)->GetWeaponForAttack(attType,true); + Item* item = this->ToPlayer()->GetWeaponForAttack(attType,true); // feral or unarmed skill only for base attack if (attType != BASE_ATTACK && !item) @@ -3195,15 +3195,15 @@ uint32 Unit::GetWeaponSkillValue (WeaponAttackType attType, Unit const* target) // in PvP use full skill instead current skill value value = (target && target->IsControlledByPlayer()) - ? ((Player*)this)->GetMaxSkillValue(skill) - : ((Player*)this)->GetSkillValue(skill); + ? this->ToPlayer()->GetMaxSkillValue(skill) + : this->ToPlayer()->GetSkillValue(skill); // Modify value from ratings - value += uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL)); + value += uint32(this->ToPlayer()->GetRatingBonusValue(CR_WEAPON_SKILL)); switch (attType) { - case BASE_ATTACK: value += uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND)); break; - case OFF_ATTACK: value += uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND)); break; - case RANGED_ATTACK: value += uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED)); break; + case BASE_ATTACK: value += uint32(this->ToPlayer()->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND)); break; + case OFF_ATTACK: value += uint32(this->ToPlayer()->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND)); break; + case RANGED_ATTACK: value += uint32(this->ToPlayer()->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED)); break; } } else @@ -3405,7 +3405,7 @@ void Unit::InterruptSpell(CurrentSpellTypes spellType, bool withDelayed, bool wi if (spellType == CURRENT_AUTOREPEAT_SPELL) { if(GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->SendAutoRepeatCancel(this); + this->ToPlayer()->SendAutoRepeatCancel(this); } if (spell->getState() != SPELL_STATE_FINISHED) @@ -3592,7 +3592,7 @@ AuraApplication * Unit::_CreateAuraApplication(Aura * aura, uint8 effMask) // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load) if( !isAlive() && !IsDeathPersistentSpell(aurSpellInfo) && - (GetTypeId() != TYPEID_PLAYER || !((Player*)this)->GetSession()->PlayerLoading()) ) + (GetTypeId() != TYPEID_PLAYER || !this->ToPlayer()->GetSession()->PlayerLoading()) ) return NULL; Unit * caster = aura->GetCaster(); @@ -4872,7 +4872,7 @@ void Unit::AddGameObject(GameObject* gameObj) // Need disable spell use for owner if (createBySpell && createBySpell->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE) // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases) - ((Player*)this)->AddSpellAndCategoryCooldowns(createBySpell,0,NULL,true); + this->ToPlayer()->AddSpellAndCategoryCooldowns(createBySpell,0,NULL,true); } } @@ -4902,7 +4902,7 @@ void Unit::RemoveGameObject(GameObject* gameObj, bool del) // Need activate spell use for owner if (createBySpell && createBySpell->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE) // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases) - ((Player*)this)->SendCooldownEvent(createBySpell); + this->ToPlayer()->SendCooldownEvent(createBySpell); } } @@ -5141,7 +5141,7 @@ bool Unit::HandleHasteAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger SpellEntry const *hasteSpell = triggeredByAura->GetSpellProto(); Item* castItem = triggeredByAura->GetBase()->GetCastItemGUID() && GetTypeId() == TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; + ? this->ToPlayer()->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; uint32 triggered_spell_id = 0; Unit* target = pVictim; @@ -5185,7 +5185,7 @@ bool Unit::HandleHasteAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger if ((!target && !spellmgr.IsSrcTargetSpell(triggerEntry)) || (target && target!=this && !target->isAlive())) return false; - if (cooldown && GetTypeId() == TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + if (cooldown && GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->HasSpellCooldown(triggered_spell_id)) return false; if (basepoints0) @@ -5194,7 +5194,7 @@ bool Unit::HandleHasteAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); if (cooldown && GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + this->ToPlayer()->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); return true; } @@ -5204,7 +5204,7 @@ bool Unit::HandleSpellCritChanceAuraProc(Unit *pVictim, uint32 /*damage*/, AuraE SpellEntry const *triggeredByAuraSpell = triggeredByAura->GetSpellProto(); Item* castItem = triggeredByAura->GetBase()->GetCastItemGUID() && GetTypeId() == TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; + ? this->ToPlayer()->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; uint32 triggered_spell_id = 0; Unit* target = pVictim; @@ -5247,7 +5247,7 @@ bool Unit::HandleSpellCritChanceAuraProc(Unit *pVictim, uint32 /*damage*/, AuraE if(!target || target!=this && !target->isAlive()) return false; - if( cooldown && GetTypeId() == TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + if( cooldown && GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->HasSpellCooldown(triggered_spell_id)) return false; if(basepoints0) @@ -5256,7 +5256,7 @@ bool Unit::HandleSpellCritChanceAuraProc(Unit *pVictim, uint32 /*damage*/, AuraE CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); if( cooldown && GetTypeId() == TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + this->ToPlayer()->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); return true; } @@ -5268,7 +5268,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger int32 triggerAmount = triggeredByAura->GetAmount(); Item* castItem = triggeredByAura->GetBase()->GetCastItemGUID() && GetTypeId() == TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; + ? this->ToPlayer()->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; uint32 triggered_spell_id = 0; Unit* target = pVictim; @@ -5495,7 +5495,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger target = this; if (roll_chance_i(10)) - ((Player*)this)->Say("This is Madness!", LANG_UNIVERSAL); + this->ToPlayer()->Say("This is Madness!", LANG_UNIVERSAL); break; } /* @@ -5819,7 +5819,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger if(GetTypeId() != TYPEID_PLAYER) return false; - SpellCooldowns const SpellCDs = ((Player*)this)->GetSpellCooldowns(); + SpellCooldowns const SpellCDs = this->ToPlayer()->GetSpellCooldowns(); // remove cooldowns on all ranks of Frost Nova for (SpellCooldowns::const_iterator itr = SpellCDs.begin(); itr != SpellCDs.end(); itr++) { @@ -5827,7 +5827,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger // Frost Nova if(SpellCDs_entry && SpellCDs_entry->SpellFamilyName == SPELLFAMILY_MAGE && SpellCDs_entry->SpellFamilyFlags[0] & 0x00000040) - ((Player*)this)->RemoveSpellCooldown(SpellCDs_entry->Id, true); + this->ToPlayer()->RemoveSpellCooldown(SpellCDs_entry->Id, true); } break; } @@ -6903,21 +6903,21 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger return false; // custom cooldown processing case - if( cooldown && ((Player*)this)->HasSpellCooldown(dummySpell->Id)) + if( cooldown && this->ToPlayer()->HasSpellCooldown(dummySpell->Id)) return false; if (triggeredByAura->GetBase() && castItem->GetGUID() != triggeredByAura->GetBase()->GetCastItemGUID()) return false; - WeaponAttackType attType = WeaponAttackType(((Player*)this)->GetAttackBySlot(castItem->GetSlot())); + WeaponAttackType attType = WeaponAttackType(this->ToPlayer()->GetAttackBySlot(castItem->GetSlot())); if ((attType != BASE_ATTACK && attType != OFF_ATTACK) || !isAttackReady(attType)) return false; // Now compute real proc chance... uint32 chance = 20; - ((Player*)this)->ApplySpellMod(dummySpell->Id,SPELLMOD_CHANCE_OF_SUCCESS,chance); + this->ToPlayer()->ApplySpellMod(dummySpell->Id,SPELLMOD_CHANCE_OF_SUCCESS,chance); - Item* addWeapon = ((Player*)this)->GetWeaponForAttack(attType == BASE_ATTACK ? OFF_ATTACK : BASE_ATTACK, true); + Item* addWeapon = this->ToPlayer()->GetWeaponForAttack(attType == BASE_ATTACK ? OFF_ATTACK : BASE_ATTACK, true); uint32 enchant_id_add = addWeapon ? addWeapon->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT)) : 0; SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id_add); if (pEnchant && pEnchant->spellid[0] == dummySpell->Id) @@ -6962,7 +6962,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger // apply cooldown before cast to prevent processing itself if( cooldown ) - ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown); + this->ToPlayer()->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown); // Attack Twice for (uint32 i = 0; i<2; ++i ) @@ -7156,7 +7156,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger return false; // custom cooldown processing case - if( cooldown && GetTypeId() == TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(dummySpell->Id)) + if( cooldown && GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->HasSpellCooldown(dummySpell->Id)) return false; uint32 spellId = 0; @@ -7200,18 +7200,18 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger mod->spellId = dummySpell->Id; mod->mask[0] = 0x02; mod->mask[2] = 0x00; - ((Player*)this)->AddSpellMod(mod, true); + this->ToPlayer()->AddSpellMod(mod, true); // Remove cooldown (Chain Lightning - have Category Recovery time) if (procSpell->SpellFamilyFlags[0] & 0x2) - ((Player*)this)->RemoveSpellCooldown(spellId); + this->ToPlayer()->RemoveSpellCooldown(spellId); CastSpell(pVictim, spellId, true, castItem, triggeredByAura); - ((Player*)this)->AddSpellMod(mod, false); + this->ToPlayer()->AddSpellMod(mod, false); if( cooldown && GetTypeId() == TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown); + this->ToPlayer()->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown); return true; } @@ -7410,7 +7410,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger { SpellChainNode const* chain = NULL; // get highest rank of the Death Coil spell - const PlayerSpellMap& sp_list = ((Player*)this)->GetSpellMap(); + const PlayerSpellMap& sp_list = this->ToPlayer()->GetSpellMap(); for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr) { // check if shown in spell book @@ -7510,7 +7510,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger if((!target && !spellmgr.IsSrcTargetSpell(triggerEntry)) || (target && target!=this && !target->isAlive())) return false; - if( cooldown && GetTypeId() == TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + if( cooldown && GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->HasSpellCooldown(triggered_spell_id)) return false; if(basepoints0) @@ -7519,7 +7519,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura, originalCaster); if( cooldown && GetTypeId() == TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + this->ToPlayer()->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); return true; } @@ -7530,7 +7530,7 @@ bool Unit::HandleObsModEnergyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* int32 triggerAmount = triggeredByAura->GetAmount(); Item* castItem = triggeredByAura->GetBase()->GetCastItemGUID() && GetTypeId() == TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; + ? this->ToPlayer()->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; uint32 triggered_spell_id = 0; Unit* target = pVictim; @@ -7569,7 +7569,7 @@ bool Unit::HandleObsModEnergyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* if((!target && !spellmgr.IsSrcTargetSpell(triggerEntry)) || (target && target!=this && !target->isAlive())) return false; - if( cooldown && GetTypeId() == TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + if( cooldown && GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->HasSpellCooldown(triggered_spell_id)) return false; if(basepoints0) CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); @@ -7577,7 +7577,7 @@ bool Unit::HandleObsModEnergyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); if( cooldown && GetTypeId() == TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + this->ToPlayer()->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); return true; } bool Unit::HandleModDamagePctTakenAuraProc(Unit *pVictim, uint32 damage, AuraEffect* triggeredByAura, SpellEntry const * procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown) @@ -7587,7 +7587,7 @@ bool Unit::HandleModDamagePctTakenAuraProc(Unit *pVictim, uint32 damage, AuraEff int32 triggerAmount = triggeredByAura->GetAmount(); Item* castItem = triggeredByAura->GetBase()->GetCastItemGUID() && GetTypeId() == TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; + ? this->ToPlayer()->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; uint32 triggered_spell_id = 0; Unit* target = pVictim; @@ -7626,7 +7626,7 @@ bool Unit::HandleModDamagePctTakenAuraProc(Unit *pVictim, uint32 damage, AuraEff if((!target && !spellmgr.IsSrcTargetSpell(triggerEntry)) || (target && target!=this && !target->isAlive())) return false; - if( cooldown && GetTypeId() == TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + if( cooldown && GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->HasSpellCooldown(triggered_spell_id)) return false; if(basepoints0) @@ -7635,7 +7635,7 @@ bool Unit::HandleModDamagePctTakenAuraProc(Unit *pVictim, uint32 damage, AuraEff CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); if( cooldown && GetTypeId() == TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + this->ToPlayer()->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); return true; } @@ -7699,9 +7699,9 @@ bool Unit::HandleAuraProc(Unit *pVictim, uint32 damage, Aura * triggeredByAura, // Convert recently used Blood Rune to Death Rune if (GetTypeId() == TYPEID_PLAYER) { - if(((Player*)this)->getClass() != CLASS_DEATH_KNIGHT) + if(this->ToPlayer()->getClass() != CLASS_DEATH_KNIGHT) return false; - RuneType rune = ((Player*)this)->GetLastUsedRune(); + RuneType rune = this->ToPlayer()->GetLastUsedRune(); // can't proc from death rune use if (rune == RUNE_DEATH) return false; @@ -7777,7 +7777,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig basepoints0 = triggerAmount; Item* castItem = triggeredByAura->GetBase()->GetCastItemGUID() && GetTypeId() == TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; + ? this->ToPlayer()->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; // Try handle unknown trigger spells if (sSpellStore.LookupEntry(trigger_spell_id) == NULL) @@ -8283,7 +8283,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig // Blade Barrier if (auraSpellInfo->SpellFamilyName == SPELLFAMILY_DEATHKNIGHT && auraSpellInfo->SpellIconID == 85) { - if (this->GetTypeId() != TYPEID_PLAYER || !((Player*)this)->IsBaseRuneSlotsOnCooldown(RUNE_BLOOD)) + if (this->GetTypeId() != TYPEID_PLAYER || !this->ToPlayer()->IsBaseRuneSlotsOnCooldown(RUNE_BLOOD)) return false; } @@ -8294,7 +8294,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig return false; // Howling Blast - ((Player*)this)->RemoveSpellCategoryCooldown(1248, true); + this->ToPlayer()->RemoveSpellCategoryCooldown(1248, true); } // Custom basepoints/target for exist spell @@ -8313,13 +8313,13 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig if(!target) return false; - if( cooldown && GetTypeId() == TYPEID_PLAYER && ((Player*)target)->HasSpellCooldown(trigger_spell_id)) + if( cooldown && GetTypeId() == TYPEID_PLAYER && target->ToPlayer()->HasSpellCooldown(trigger_spell_id)) return false; target->CastSpell(target,trigger_spell_id,true,castItem,triggeredByAura); if( cooldown && GetTypeId() == TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(trigger_spell_id,0,time(NULL) + cooldown); + this->ToPlayer()->AddSpellCooldown(trigger_spell_id,0,time(NULL) + cooldown); return true; } // Cast positive spell on enemy target @@ -8387,7 +8387,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig { // Remove cooldown on Shield Slam if (GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->RemoveSpellCategoryCooldown(1209, true); + this->ToPlayer()->RemoveSpellCategoryCooldown(1209, true); break; } // Maelstrom Weapon @@ -8443,7 +8443,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig { // remove cooldown of Death Grip if (GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->RemoveCategoryCooldown(82); + this->ToPlayer()->RemoveCategoryCooldown(82); return true; } // Savage Defense @@ -8463,7 +8463,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig } } - if( cooldown && GetTypeId() == TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(trigger_spell_id)) + if( cooldown && GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->HasSpellCooldown(trigger_spell_id)) return false; // try detect target manually if not set @@ -8480,7 +8480,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig CastSpell(target,trigger_spell_id,true,castItem,triggeredByAura); if( cooldown && GetTypeId() == TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(trigger_spell_id,0,time(NULL) + cooldown); + this->ToPlayer()->AddSpellCooldown(trigger_spell_id,0,time(NULL) + cooldown); return true; } @@ -8493,7 +8493,7 @@ bool Unit::HandleOverrideClassScriptAuraProc(Unit *pVictim, uint32 damage, AuraE return false; Item* castItem = triggeredByAura->GetBase()->GetCastItemGUID() && GetTypeId() == TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; + ? this->ToPlayer()->GetItemByGuid(triggeredByAura->GetBase()->GetCastItemGUID()) : NULL; uint32 triggered_spell_id = 0; @@ -8572,13 +8572,13 @@ bool Unit::HandleOverrideClassScriptAuraProc(Unit *pVictim, uint32 damage, AuraE return false; } - if( cooldown && GetTypeId() == TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + if( cooldown && GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->HasSpellCooldown(triggered_spell_id)) return false; CastSpell(pVictim, triggered_spell_id, true, castItem, triggeredByAura); if( cooldown && GetTypeId() == TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + this->ToPlayer()->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); return true; } @@ -8589,8 +8589,8 @@ void Unit::setPowerType(Powers new_powertype) if(GetTypeId() == TYPEID_PLAYER) { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE); + if(this->ToPlayer()->GetGroup()) + this->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE); } else if(((Creature*)this)->isPet()) { @@ -8598,8 +8598,8 @@ void Unit::setPowerType(Powers new_powertype) if(pet->isControlled()) { Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup()) + owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE); } } @@ -8636,7 +8636,7 @@ FactionTemplateEntry const* Unit::getFactionTemplateEntry() const if(GetGUID() != guid) { if(GetTypeId() == TYPEID_PLAYER) - sLog.outError("Player %s have invalid faction (faction template id) #%u", ((Player*)this)->GetName(), getFaction()); + sLog.outError("Player %s have invalid faction (faction template id) #%u", this->ToPlayer()->GetName(), getFaction()); else sLog.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature*)this)->GetCreatureInfo()->Entry, getFaction()); guid = GetGUID(); @@ -8733,12 +8733,12 @@ bool Unit::IsHostileTo(Unit const* unit) const // forced reaction if(target_faction->faction) { - if(ReputationRank const* force =((Player*)tester)->GetReputationMgr().GetForcedRankIfAny(target_faction)) + if(ReputationRank const* force =tester->ToPlayer()->GetReputationMgr().GetForcedRankIfAny(target_faction)) return *force <= REP_HOSTILE; // if faction have reputation then hostile state for tester at 100% dependent from at_war state if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) - if(FactionState const* factionState = ((Player*)tester)->GetReputationMgr().GetState(raw_target_faction)) + if(FactionState const* factionState = tester->ToPlayer()->GetReputationMgr().GetState(raw_target_faction)) return (factionState->Flags & FACTION_FLAG_AT_WAR); } } @@ -8748,7 +8748,7 @@ bool Unit::IsHostileTo(Unit const* unit) const // forced reaction if(tester_faction->faction) { - if(ReputationRank const* force = ((Player*)target)->GetReputationMgr().GetForcedRankIfAny(tester_faction)) + if(ReputationRank const* force = target->ToPlayer()->GetReputationMgr().GetForcedRankIfAny(tester_faction)) return *force <= REP_HOSTILE; // apply reputation state @@ -8848,12 +8848,12 @@ bool Unit::IsFriendlyTo(Unit const* unit) const // forced reaction if (target_faction->faction) { - if (ReputationRank const *force =((Player*)tester)->GetReputationMgr().GetForcedRankIfAny(target_faction)) + if (ReputationRank const *force =tester->ToPlayer()->GetReputationMgr().GetForcedRankIfAny(target_faction)) return *force >= REP_FRIENDLY; // if faction have reputation then friendly state for tester at 100% dependent from at_war state if (FactionEntry const *raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) - if (FactionState const *factionState = ((Player*)tester)->GetReputationMgr().GetState(raw_target_faction)) + if (FactionState const *factionState = tester->ToPlayer()->GetReputationMgr().GetState(raw_target_faction)) return !(factionState->Flags & FACTION_FLAG_AT_WAR); } } @@ -8863,7 +8863,7 @@ bool Unit::IsFriendlyTo(Unit const* unit) const // forced reaction if (tester_faction->faction) { - if (ReputationRank const *force =((Player*)target)->GetReputationMgr().GetForcedRankIfAny(tester_faction)) + if (ReputationRank const *force =target->ToPlayer()->GetReputationMgr().GetForcedRankIfAny(tester_faction)) return *force >= REP_FRIENDLY; // apply reputation state @@ -8919,7 +8919,7 @@ bool Unit::Attack(Unit *victim, bool meleeAttack) // nobody can attack GM in GM-mode if(victim->GetTypeId() == TYPEID_PLAYER) { - if(((Player*)victim)->isGameMaster()) + if(victim->ToPlayer()->isGameMaster()) return false; } else @@ -9041,7 +9041,7 @@ void Unit::CombatStop(bool includingCast) AttackStop(); RemoveAllAttackers(); if (GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel + this->ToPlayer()->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel ClearInCombat(); } @@ -9093,7 +9093,7 @@ void Unit::ModifyAuraState(AuraState flag, bool apply) SetFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); if (GetTypeId() == TYPEID_PLAYER) { - PlayerSpellMap const& sp_list = ((Player*)this)->GetSpellMap(); + PlayerSpellMap const& sp_list = this->ToPlayer()->GetSpellMap(); for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr) { if (itr->second->state == PLAYERSPELL_REMOVED || itr->second->disabled) continue; @@ -9315,7 +9315,7 @@ void Unit::SetMinion(Minion *minion, bool apply) // Send infinity cooldown - client does that automatically but after relog cooldown needs to be set again SpellEntry const *spellInfo = sSpellStore.LookupEntry(minion->GetUInt32Value(UNIT_CREATED_BY_SPELL)); if (spellInfo && (spellInfo->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE)) - ((Player*)this)->AddSpellAndCategoryCooldowns(spellInfo, 0, NULL ,true); + this->ToPlayer()->AddSpellAndCategoryCooldowns(spellInfo, 0, NULL ,true); } } else @@ -9351,7 +9351,7 @@ void Unit::SetMinion(Minion *minion, bool apply) SpellEntry const *spellInfo = sSpellStore.LookupEntry(minion->GetUInt32Value(UNIT_CREATED_BY_SPELL)); // Remove infinity cooldown if (spellInfo && (spellInfo->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE)) - ((Player*)this)->SendCooldownEvent(spellInfo); + this->ToPlayer()->SendCooldownEvent(spellInfo); } //if(minion->HasUnitTypeMask(UNIT_MASK_GUARDIAN)) @@ -9384,9 +9384,9 @@ void Unit::SetMinion(Minion *minion, bool apply) if (GetTypeId() == TYPEID_PLAYER && !GetCharmGUID()) { if ((*itr)->isPet()) - ((Player*)this)->PetSpellInitialize(); + this->ToPlayer()->PetSpellInitialize(); else - ((Player*)this)->CharmSpellInitialize(); + this->ToPlayer()->CharmSpellInitialize(); } } break; @@ -9468,7 +9468,7 @@ void Unit::SetCharm(Unit* charm, bool apply) { charm->m_ControlledByPlayer = true; charm->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); - ((Player*)charm)->UpdatePvPState(); + charm->ToPlayer()->UpdatePvPState(); } else if(Player *player = charm->GetCharmerOrOwnerPlayerOrPlayerItself()) { @@ -9504,20 +9504,20 @@ int32 Unit::DealHeal(Unit *pVictim, uint32 addhealth, SpellEntry const *spellPro // overheal = addhealth - gain unit->SendHealSpellLog(pVictim, spellProto->Id, addhealth, addhealth - gain, critical); - if (BattleGround *bg = ((Player*)unit)->GetBattleGround()) + if (BattleGround *bg = unit->ToPlayer()->GetBattleGround()) bg->UpdatePlayerScore((Player*)unit, SCORE_HEALING_DONE, gain); // use the actual gain, as the overheal shall not be counted, skip gain 0 (it ignored anyway in to criteria) if (gain) - ((Player*)unit)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE, gain, 0, pVictim); + unit->ToPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE, gain, 0, pVictim); - ((Player*)unit)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CASTED, addhealth); + unit->ToPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CASTED, addhealth); } if (pVictim->GetTypeId() == TYPEID_PLAYER) { - ((Player*)pVictim)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_HEALING_RECEIVED, gain); - ((Player*)pVictim)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALING_RECEIVED, addhealth); + pVictim->ToPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_HEALING_RECEIVED, gain); + pVictim->ToPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALING_RECEIVED, addhealth); } return gain; @@ -9576,7 +9576,7 @@ void Unit::RemoveAllControlled() { //possessed pet and vehicle if (GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->StopCastingCharm(); + this->ToPlayer()->StopCastingCharm(); while (!m_Controlled.empty()) { @@ -9650,10 +9650,10 @@ Unit* Unit::GetNextRandomRaidMemberOrPet(float radius) /* Player * Unit::GetMoverSource() const { - if (GetTypeId() == TYPEID_PLAYER && ((Player*)this)->m_mover == this) + if (GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->m_mover == this) return (Player*)this; if (Unit *charmer = GetCharmer()) - if (charmer->GetTypeId() == TYPEID_PLAYER && ((Player*)charmer)->m_mover == this) + if (charmer->GetTypeId() == TYPEID_PLAYER && charmer->ToPlayer()->m_mover == this) return (Player*)charmer; return NULL; } @@ -9984,7 +9984,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 // Impurity (dummy effect) if (GetTypeId() == TYPEID_PLAYER) { - PlayerSpellMap playerSpells = ((Player*)this)->GetSpellMap(); + PlayerSpellMap playerSpells = this->ToPlayer()->GetSpellMap(); for (PlayerSpellMap::const_iterator itr = playerSpells.begin(); itr != playerSpells.end(); ++itr) { if (itr->second->state == PLAYERSPELL_REMOVED || itr->second->disabled) @@ -10035,7 +10035,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 { if (pVictim->GetTypeId() != TYPEID_PLAYER) continue; - float mod = ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE)*(-8.0f); + float mod = pVictim->ToPlayer()->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE)*(-8.0f); if (mod < (*i)->GetAmount()) mod = (*i)->GetAmount(); sumNegativeMod += mod; @@ -10195,7 +10195,7 @@ int32 Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask) if (GetTypeId() == TYPEID_PLAYER) { // Base value - DoneAdvertisedBenefit +=((Player*)this)->GetBaseSpellPowerBonus(); + DoneAdvertisedBenefit +=this->ToPlayer()->GetBaseSpellPowerBonus(); // Damage bonus from stats AuraEffectList const& mDamageDoneOfStatPercent = GetAuraEffectsByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT); @@ -10750,7 +10750,7 @@ int32 Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask) if (GetTypeId() == TYPEID_PLAYER) { // Base value - AdvertisedBenefit +=((Player*)this)->GetBaseSpellPowerBonus(); + AdvertisedBenefit +=this->ToPlayer()->GetBaseSpellPowerBonus(); // Healing bonus from stats AuraEffectList const& mHealingDoneOfStatPercent = GetAuraEffectsByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT); @@ -11127,7 +11127,7 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att { if (pVictim->GetTypeId() != TYPEID_PLAYER) continue; - float mod = ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE)*(-8.0f); + float mod = pVictim->ToPlayer()->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE)*(-8.0f); if (mod < (*i)->GetAmount()) mod = (*i)->GetAmount(); TakenTotalMod *= (mod+100.0f)/100.0f; @@ -11293,7 +11293,7 @@ void Unit::Mount(uint32 mount, uint32 VehicleId) // unsummon pet if (GetTypeId() == TYPEID_PLAYER) { - Pet* pet = ((Player*)this)->GetPet(); + Pet* pet = this->ToPlayer()->GetPet(); if (pet) { BattleGround *bg = ((Player *)this)->GetBattleGround(); @@ -11301,7 +11301,7 @@ void Unit::Mount(uint32 mount, uint32 VehicleId) if (bg && bg->isArena()) pet->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED); else - ((Player*)this)->UnsummonPetTemporaryIfAny(); + this->ToPlayer()->UnsummonPetTemporaryIfAny(); } if(VehicleId !=0) @@ -11320,7 +11320,7 @@ void Unit::Mount(uint32 mount, uint32 VehicleId) SendMessageToSet( &data,true ); data.Initialize(SMSG_ON_CANCEL_EXPECTED_RIDE_VEHICLE_AURA, 0); - ((Player*)this)->GetSession()->SendPacket( &data ); + this->ToPlayer()->GetSession()->SendPacket( &data ); } } } @@ -11343,13 +11343,13 @@ void Unit::Unmount() // (it could probably happen when logging in after a previous crash) if (GetTypeId() == TYPEID_PLAYER) { - if (Pet *pPet = ((Player*)this)->GetPet()) + if (Pet *pPet = this->ToPlayer()->GetPet()) { if (pPet && pPet->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED) && !pPet->hasUnitState(UNIT_STAT_STUNNED)) pPet->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED); } else - ((Player*)this)->ResummonPetTemporaryUnSummonedIfAny(); + this->ToPlayer()->ResummonPetTemporaryUnSummonedIfAny(); } if(GetTypeId()==TYPEID_PLAYER && GetVehicleKit()) { @@ -11357,7 +11357,7 @@ void Unit::Unmount() WorldPacket data( SMSG_PLAYER_VEHICLE_DATA, 8+4 ); data.appendPackGUID(GetGUID()); data << uint32(0); - ((Player*)this)->SendMessageToSet(&data, true); + this->ToPlayer()->SendMessageToSet(&data, true); // Remove vehicle class from player RemoveVehicleKit(); } @@ -11373,7 +11373,7 @@ void Unit::SetInCombatWith(Unit* enemy) } //check for duel - if (eOwner->GetTypeId() == TYPEID_PLAYER && ((Player*)eOwner)->duel) + if (eOwner->GetTypeId() == TYPEID_PLAYER && eOwner->ToPlayer()->duel) { Unit const* myOwner = GetCharmerOrOwnerOrSelf(); if (((Player const*)eOwner)->duel->opponent == myOwner) @@ -11403,7 +11403,7 @@ void Unit::CombatStart(Unit* target, bool initialAggro) } Unit *who = target->GetCharmerOrOwnerOrSelf(); if (who->GetTypeId() == TYPEID_PLAYER) - SetContestedPvP((Player*)who); + SetContestedPvP(who->ToPlayer()); Player *me = GetCharmerOrOwnerPlayerOrPlayerItself(); if (me && who->IsPvP() @@ -11473,7 +11473,7 @@ void Unit::ClearInCombat() SetUInt32Value(UNIT_DYNAMIC_FLAGS, ((Creature*)this)->GetCreatureInfo()->dynamicflags); } else - ((Player*)this)->UpdatePotionCooldown(); + this->ToPlayer()->UpdatePotionCooldown(); if (GetTypeId() != TYPEID_PLAYER && ((Creature*)this)->isPet()) { @@ -11671,7 +11671,7 @@ bool Unit::canDetectInvisibilityOf(Unit const* u) const uint32 detectLevel = 0; if (i==6 && GetTypeId() == TYPEID_PLAYER) // special drunk detection case { - detectLevel = ((Player*)this)->GetDrunkValue(); + detectLevel = this->ToPlayer()->GetDrunkValue(); } else { @@ -11916,10 +11916,10 @@ void Unit::SetSpeed(UnitMoveType mtype, float rate, bool forced) { // register forced speed changes for WorldSession::HandleForceSpeedChangeAck // and do it only for real sent packets and use run for run/mounted as client expected - ++((Player*)this)->m_forced_speed_changes[mtype]; + ++this->ToPlayer()->m_forced_speed_changes[mtype]; if (!isInCombat()) - if (Pet* pet = ((Player*)this)->GetPet()) + if (Pet* pet = this->ToPlayer()->GetPet()) pet->SetSpeed(mtype, m_speed_rate[mtype], forced); } @@ -12086,7 +12086,7 @@ void Unit::TauntApply(Unit* taunter) { assert(GetTypeId() == TYPEID_UNIT); - if (!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && ((Player*)taunter)->isGameMaster())) + if (!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && taunter->ToPlayer()->isGameMaster())) return; if (!CanHaveThreatList()) @@ -12112,7 +12112,7 @@ void Unit::TauntFadeOut(Unit *taunter) { assert(GetTypeId() == TYPEID_UNIT); - if (!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && ((Player*)taunter)->isGameMaster())) + if (!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && taunter->ToPlayer()->isGameMaster())) return; if (!CanHaveThreatList()) @@ -12841,8 +12841,8 @@ void Unit::SetLevel(uint8 lvl) SetUInt32Value(UNIT_FIELD_LEVEL, lvl); // group update - if (GetTypeId() == TYPEID_PLAYER && ((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL); + if (GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->GetGroup()) + this->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL); } void Unit::SetHealth(uint32 val) @@ -12863,8 +12863,8 @@ void Unit::SetHealth(uint32 val) // group update if (GetTypeId() == TYPEID_PLAYER) { - if (((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP); + if (this->ToPlayer()->GetGroup()) + this->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP); } else if (((Creature*)this)->isPet()) { @@ -12872,8 +12872,8 @@ void Unit::SetHealth(uint32 val) if (pet->isControlled()) { Unit *owner = GetOwner(); - if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP); + if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup()) + owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP); } } } @@ -12889,8 +12889,8 @@ void Unit::SetMaxHealth(uint32 val) // group update if (GetTypeId() == TYPEID_PLAYER) { - if (((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP); + if (this->ToPlayer()->GetGroup()) + this->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP); } else if (((Creature*)this)->isPet()) { @@ -12898,8 +12898,8 @@ void Unit::SetMaxHealth(uint32 val) if (pet->isControlled()) { Unit *owner = GetOwner(); - if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP); + if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup()) + owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP); } } @@ -12927,8 +12927,8 @@ void Unit::SetPower(Powers power, uint32 val) // group update if (GetTypeId() == TYPEID_PLAYER) { - if (((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER); + if (this->ToPlayer()->GetGroup()) + this->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER); } else if (((Creature*)this)->isPet()) { @@ -12936,8 +12936,8 @@ void Unit::SetPower(Powers power, uint32 val) if (pet->isControlled()) { Unit *owner = GetOwner(); - if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER); + if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup()) + owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER); } // Update the pet's character sheet with happiness damage bonus @@ -12954,8 +12954,8 @@ void Unit::SetMaxPower(Powers power, uint32 val) // group update if (GetTypeId() == TYPEID_PLAYER) { - if (((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER); + if (this->ToPlayer()->GetGroup()) + this->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER); } else if (((Creature*)this)->isPet()) { @@ -12963,8 +12963,8 @@ void Unit::SetMaxPower(Powers power, uint32 val) if (pet->isControlled()) { Unit *owner = GetOwner(); - if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER); + if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup()) + owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER); } } @@ -12979,8 +12979,8 @@ void Unit::ApplyPowerMod(Powers power, uint32 val, bool apply) // group update if (GetTypeId() == TYPEID_PLAYER) { - if (((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER); + if (this->ToPlayer()->GetGroup()) + this->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER); } else if (((Creature*)this)->isPet()) { @@ -12988,8 +12988,8 @@ void Unit::ApplyPowerMod(Powers power, uint32 val, bool apply) if (pet->isControlled()) { Unit *owner = GetOwner(); - if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER); + if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup()) + owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER); } } } @@ -13001,8 +13001,8 @@ void Unit::ApplyMaxPowerMod(Powers power, uint32 val, bool apply) // group update if (GetTypeId() == TYPEID_PLAYER) { - if (((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER); + if (this->ToPlayer()->GetGroup()) + this->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER); } else if (((Creature*)this)->isPet()) { @@ -13010,8 +13010,8 @@ void Unit::ApplyMaxPowerMod(Powers power, uint32 val, bool apply) if (pet->isControlled()) { Unit *owner = GetOwner(); - if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER); + if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup()) + owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER); } } } @@ -13508,7 +13508,7 @@ uint32 createProcExtendMask(SpellNonMeleeDamage *damageInfo, SpellMissInfo missC void Unit::ProcDamageAndSpellFor(bool isVictim, Unit * pTarget, uint32 procFlag, uint32 procExtra, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage, SpellEntry const * procAura) { // Player is loaded now - do not allow passive spell casts to proc - if (GetTypeId() == TYPEID_PLAYER && ((Player*)this)->GetSession()->PlayerLoading()) + if (GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->GetSession()->PlayerLoading()) return; // For melee/ranged based attack need update skills and set some Aura states if victim present if (procFlag & MELEE_BASED_TRIGGER_MASK && pTarget) @@ -13520,11 +13520,11 @@ void Unit::ProcDamageAndSpellFor(bool isVictim, Unit * pTarget, uint32 procFlag, if (procExtra&(PROC_EX_NORMAL_HIT|PROC_EX_MISS|PROC_EX_RESIST)) { if (pTarget->GetTypeId() != TYPEID_PLAYER && pTarget->GetCreatureType() != CREATURE_TYPE_CRITTER) - ((Player*)this)->UpdateCombatSkills(pTarget, attType, isVictim); + this->ToPlayer()->UpdateCombatSkills(pTarget, attType, isVictim); } // Update defence if player is victim and parry/dodge/block else if (isVictim && procExtra&(PROC_EX_DODGE|PROC_EX_PARRY|PROC_EX_BLOCK)) - ((Player*)this)->UpdateCombatSkills(pTarget, attType, MELEE_HIT_DODGE); + this->ToPlayer()->UpdateCombatSkills(pTarget, attType, MELEE_HIT_DODGE); } // If exist crit/parry/dodge/block need update aura state (for victim and attacker) if (procExtra & (PROC_EX_CRITICAL_HIT|PROC_EX_PARRY|PROC_EX_DODGE|PROC_EX_BLOCK)) @@ -13569,7 +13569,7 @@ void Unit::ProcDamageAndSpellFor(bool isVictim, Unit * pTarget, uint32 procFlag, // Overpower on victim dodge if (procExtra&PROC_EX_DODGE && GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_WARRIOR) { - ((Player*)this)->AddComboPoints(pTarget, 1); + this->ToPlayer()->AddComboPoints(pTarget, 1); StartReactiveTimer( REACTIVE_OVERPOWER ); } } @@ -13856,7 +13856,7 @@ void Unit::SendPetCastFail(uint32 spellid, SpellCastResult msg) data << uint8(msg); // uint32 for some reason // uint32 for some reason - ((Player*)owner)->GetSession()->SendPacket(&data); + owner->ToPlayer()->GetSession()->SendPacket(&data); } void Unit::SendPetActionFeedback (uint8 msg) @@ -13867,7 +13867,7 @@ void Unit::SendPetActionFeedback (uint8 msg) WorldPacket data(SMSG_PET_ACTION_FEEDBACK, 1); data << uint8(msg); - ((Player*)owner)->GetSession()->SendPacket(&data); + owner->ToPlayer()->GetSession()->SendPacket(&data); } void Unit::SendPetTalk (uint32 pettalk) @@ -13879,7 +13879,7 @@ void Unit::SendPetTalk (uint32 pettalk) WorldPacket data(SMSG_PET_ACTION_SOUND, 8 + 4); data << uint64(GetGUID()); data << uint32(pettalk); - ((Player*)owner)->GetSession()->SendPacket(&data); + owner->ToPlayer()->GetSession()->SendPacket(&data); } void Unit::SendPetAIReaction(uint64 guid) @@ -13891,7 +13891,7 @@ void Unit::SendPetAIReaction(uint64 guid) WorldPacket data(SMSG_AI_REACTION, 8 + 4); data << uint64(guid); data << uint32(AI_REACTION_AGGRO); - ((Player*)owner)->GetSession()->SendPacket(&data); + owner->ToPlayer()->GetSession()->SendPacket(&data); } ///----------End of Pet responses methods---------- @@ -13948,7 +13948,7 @@ void Unit::SetStandState(uint8 state) { WorldPacket data(SMSG_STANDSTATE_UPDATE, 1); data << (uint8)state; - ((Player*)this)->GetSession()->SendPacket(&data); + this->ToPlayer()->GetSession()->SendPacket(&data); } } @@ -13975,8 +13975,8 @@ void Unit::SetDisplayId(uint32 modelId) if (!pet->isControlled()) return; Unit *owner = GetOwner(); - if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID); + if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup()) + owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID); } } @@ -14004,7 +14004,7 @@ void Unit::ClearAllReactives() if (getClass() == CLASS_HUNTER && HasAuraState(AURA_STATE_HUNTER_PARRY)) ModifyAuraState(AURA_STATE_HUNTER_PARRY, false); if (getClass() == CLASS_WARRIOR && GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->ClearComboPoints(); + this->ToPlayer()->ClearComboPoints(); } void Unit::UpdateReactives( uint32 p_time ) @@ -14032,7 +14032,7 @@ void Unit::UpdateReactives( uint32 p_time ) break; case REACTIVE_OVERPOWER: if (getClass() == CLASS_WARRIOR && GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->ClearComboPoints(); + this->ToPlayer()->ClearComboPoints(); break; default: break; @@ -14215,9 +14215,9 @@ void Unit::UpdateAuraForGroup(uint8 slot) if (pet->isControlled()) { Unit *owner = GetOwner(); - if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup()) { - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS); + owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS); pet->SetAuraUpdateMaskForRaid(slot); } } @@ -14229,7 +14229,7 @@ float Unit::GetAPMultiplier(WeaponAttackType attType, bool normalized) if (!normalized || GetTypeId() != TYPEID_PLAYER) return float(GetAttackTime(attType))/1000.0f; - Item *Weapon = ((Player*)this)->GetWeaponForAttack(attType); + Item *Weapon = this->ToPlayer()->GetWeaponForAttack(attType); if (!Weapon) return 2.4; // fist attack @@ -14283,7 +14283,7 @@ void Unit::AddPetAura(PetAura const* petSpell) return; m_petAuras.insert(petSpell); - if (Pet* pet = ((Player*)this)->GetPet()) + if (Pet* pet = this->ToPlayer()->GetPet()) pet->CastPetAura(petSpell); } @@ -14293,7 +14293,7 @@ void Unit::RemovePetAura(PetAura const* petSpell) return; m_petAuras.erase(petSpell); - if (Pet* pet = ((Player*)this)->GetPet()) + if (Pet* pet = this->ToPlayer()->GetPet()) pet->RemoveAurasDueToSpell(petSpell->GetAura(pet->GetEntry())); } @@ -14365,7 +14365,7 @@ bool Unit::IsTriggeredAtSpellProcEvent(Unit *pVictim, Aura * aura, SpellEntry co // In most cases req get honor or XP from kill if (EventProcFlag & PROC_FLAG_KILL && GetTypeId() == TYPEID_PLAYER) { - bool allow = ((Player*)this)->isHonorOrXPTarget(pVictim); + bool allow = this->ToPlayer()->isHonorOrXPTarget(pVictim); // Shadow Word: Death - can trigger from every kill if (aura->GetId() == 32409) allow = true; @@ -14385,13 +14385,13 @@ bool Unit::IsTriggeredAtSpellProcEvent(Unit *pVictim, Aura * aura, SpellEntry co { Item *item = NULL; if (attType == BASE_ATTACK) - item = ((Player*)this)->GetUseableItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + item = this->ToPlayer()->GetUseableItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); else if (attType == OFF_ATTACK) - item = ((Player*)this)->GetUseableItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); + item = this->ToPlayer()->GetUseableItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); else - item = ((Player*)this)->GetUseableItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_RANGED); + item = this->ToPlayer()->GetUseableItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_RANGED); - if (((Player*)this)->IsInFeralForm()) + if (this->ToPlayer()->IsInFeralForm()) return false; if (!item || item->IsBroken() || item->GetProto()->Class != ITEM_CLASS_WEAPON || !((1<<item->GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) @@ -14400,7 +14400,7 @@ bool Unit::IsTriggeredAtSpellProcEvent(Unit *pVictim, Aura * aura, SpellEntry co else if (spellProto->EquippedItemClass == ITEM_CLASS_ARMOR) { // Check if player is wearing shield - Item *item = ((Player*)this)->GetUseableItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); + Item *item = this->ToPlayer()->GetUseableItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); if (!item || item->IsBroken() || item->GetProto()->Class != ITEM_CLASS_ARMOR || !((1<<item->GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) return false; } @@ -14550,9 +14550,9 @@ void Unit::Kill(Unit *pVictim, bool durabilityLoss) return; // Inform pets (if any) when player kills target) - if (this->GetTypeId() == TYPEID_PLAYER && ((Player*)this)->GetPet()) + if (this->GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->GetPet()) { - Pet *pPet = ((Player*)this)->GetPet(); + Pet *pPet = this->ToPlayer()->GetPet(); if (pPet && pPet->isAlive() && pPet->isControlled()) pPet->AI()->KilledUnit(pVictim); @@ -14606,7 +14606,7 @@ void Unit::Kill(Unit *pVictim, bool durabilityLoss) // save value before aura remove uint32 ressSpellId = pVictim->GetUInt32Value(PLAYER_SELF_RES_SPELL); if (!ressSpellId) - ressSpellId = ((Player*)pVictim)->GetResurrectionSpellId(); + ressSpellId = pVictim->ToPlayer()->GetResurrectionSpellId(); //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers) pVictim->RemoveAllAurasOnDeath(); // restore for use at real death @@ -14632,27 +14632,27 @@ void Unit::Kill(Unit *pVictim, bool durabilityLoss) { // remember victim PvP death for corpse type and corpse reclaim delay // at original death (not at SpiritOfRedemtionTalent timeout) - ((Player*)pVictim)->SetPvPDeath(player != NULL); + pVictim->ToPlayer()->SetPvPDeath(player != NULL); // only if not player and not controlled by player pet. And not at BG - if ((durabilityLoss && !player && !((Player*)pVictim)->InBattleGround()) || (player && sWorld.getConfig(CONFIG_DURABILITY_LOSS_IN_PVP))) + if ((durabilityLoss && !player && !pVictim->ToPlayer()->InBattleGround()) || (player && sWorld.getConfig(CONFIG_DURABILITY_LOSS_IN_PVP))) { DEBUG_LOG("We are dead, losing %u percent durability", sWorld.getRate(RATE_DURABILITY_LOSS_ON_DEATH)); - ((Player*)pVictim)->DurabilityLossAll(sWorld.getRate(RATE_DURABILITY_LOSS_ON_DEATH),false); + pVictim->ToPlayer()->DurabilityLossAll(sWorld.getRate(RATE_DURABILITY_LOSS_ON_DEATH),false); // durability lost message WorldPacket data(SMSG_DURABILITY_DAMAGE_DEATH, 0); - ((Player*)pVictim)->GetSession()->SendPacket(&data); + pVictim->ToPlayer()->GetSession()->SendPacket(&data); } // Call KilledUnit for creatures if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->KilledUnit(pVictim); // last damage from non duel opponent or opponent controlled creature - if (((Player*)pVictim)->duel) + if (pVictim->ToPlayer()->duel) { - ((Player*)pVictim)->duel->opponent->CombatStopWithPets(true); - ((Player*)pVictim)->CombatStopWithPets(true); - ((Player*)pVictim)->DuelComplete(DUEL_INTERUPTED); + pVictim->ToPlayer()->duel->opponent->CombatStopWithPets(true); + pVictim->ToPlayer()->CombatStopWithPets(true); + pVictim->ToPlayer()->DuelComplete(DUEL_INTERUPTED); } } else // creature died @@ -14709,8 +14709,8 @@ void Unit::Kill(Unit *pVictim, bool durabilityLoss) pvp->HandleKill(player, pVictim); //if (pVictim->GetTypeId() == TYPEID_PLAYER) - // if (OutdoorPvP * pvp = ((Player*)pVictim)->GetOutdoorPvP()) - // pvp->HandlePlayerActivityChanged((Player*)pVictim); + // if (OutdoorPvP * pvp = pVictim->ToPlayer()->GetOutdoorPvP()) + // pvp->HandlePlayerActivityChangedpVictim->ToPlayer(); // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill) if (player && player->InBattleGround()) @@ -14728,9 +14728,9 @@ void Unit::Kill(Unit *pVictim, bool durabilityLoss) if (pVictim->GetTypeId() == TYPEID_PLAYER) { if (GetTypeId() == TYPEID_UNIT) - ((Player*)pVictim)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE, GetEntry()); + pVictim->ToPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE, GetEntry()); else if (GetTypeId() == TYPEID_PLAYER && pVictim != this) - ((Player*)pVictim)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER, 1, ((Player*)this)->GetTeam()); + pVictim->ToPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER, 1, this->ToPlayer()->GetTeam()); } } @@ -14892,7 +14892,7 @@ void Unit::SetFeared(bool apply) } if (GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->SetClientControl(this, !apply); + this->ToPlayer()->SetClientControl(this, !apply); } void Unit::SetConfused(bool apply) @@ -14914,7 +14914,7 @@ void Unit::SetConfused(bool apply) } if (GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->SetClientControl(this, !apply); + this->ToPlayer()->SetClientControl(this, !apply); } bool Unit::SetCharmedBy(Unit* charmer, CharmType type) @@ -14936,7 +14936,7 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type) //if (hasUnitState(UNIT_STAT_UNATTACKABLE)) // return false; - if (GetTypeId() == TYPEID_PLAYER && ((Player*)this)->GetTransport()) + if (GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->GetTransport()) { sLog.outCrash("Unit::SetCharmedBy: Player on transport is trying to charm %u", GetEntry()); return false; @@ -14956,15 +14956,15 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type) // Charmer stop charming if (charmer->GetTypeId() == TYPEID_PLAYER) { - ((Player*)charmer)->StopCastingCharm(); - ((Player*)charmer)->StopCastingBindSight(); + charmer->ToPlayer()->StopCastingCharm(); + charmer->ToPlayer()->StopCastingBindSight(); } // Charmed stop charming if (GetTypeId() == TYPEID_PLAYER) { - ((Player*)this)->StopCastingCharm(); - ((Player*)this)->StopCastingBindSight(); + this->ToPlayer()->StopCastingCharm(); + this->ToPlayer()->StopCastingBindSight(); } // StopCastingCharm may remove a possessed pet? @@ -14985,9 +14985,9 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type) } else { - if (((Player*)this)->isAFK()) - ((Player*)this)->ToggleAFK(); - ((Player*)this)->SetClientControl(this, 0); + if (this->ToPlayer()->isAFK()) + this->ToPlayer()->ToggleAFK(); + this->ToPlayer()->SetClientControl(this, 0); } // Pets already have a properly initialized CharmInfo, don't overwrite it. @@ -15006,17 +15006,17 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type) { case CHARM_TYPE_VEHICLE: SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED); - ((Player*)charmer)->SetClientControl(this, 1); - ((Player*)charmer)->SetViewpoint(this, true); - ((Player*)charmer)->VehicleSpellInitialize(); + charmer->ToPlayer()->SetClientControl(this, 1); + charmer->ToPlayer()->SetViewpoint(this, true); + charmer->ToPlayer()->VehicleSpellInitialize(); break; case CHARM_TYPE_POSSESS: addUnitState(UNIT_STAT_POSSESSED); SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED); charmer->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE); - ((Player*)charmer)->SetClientControl(this, 1); - ((Player*)charmer)->SetViewpoint(this, true); - ((Player*)charmer)->PossessSpellInitialize(); + charmer->ToPlayer()->SetClientControl(this, 1); + charmer->ToPlayer()->SetViewpoint(this, true); + charmer->ToPlayer()->PossessSpellInitialize(); break; case CHARM_TYPE_CHARM: if (GetTypeId() == TYPEID_UNIT && charmer->getClass() == CLASS_WARLOCK) @@ -15035,7 +15035,7 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type) SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL)); } } - ((Player*)charmer)->CharmSpellInitialize(); + charmer->ToPlayer()->CharmSpellInitialize(); break; default: case CHARM_TYPE_CONVERT: @@ -15097,7 +15097,7 @@ void Unit::RemoveCharmedBy(Unit *charmer) }*/ } else - ((Player*)this)->SetClientControl(this, 1); + this->ToPlayer()->SetClientControl(this, 1); // If charmer still exists if (!charmer) @@ -15113,12 +15113,12 @@ void Unit::RemoveCharmedBy(Unit *charmer) switch(type) { case CHARM_TYPE_VEHICLE: - ((Player*)charmer)->SetClientControl(charmer, 1); - ((Player*)charmer)->SetViewpoint(this, false); + charmer->ToPlayer()->SetClientControl(charmer, 1); + charmer->ToPlayer()->SetViewpoint(this, false); break; case CHARM_TYPE_POSSESS: - ((Player*)charmer)->SetClientControl(charmer, 1); - ((Player*)charmer)->SetViewpoint(this, false); + charmer->ToPlayer()->SetClientControl(charmer, 1); + charmer->ToPlayer()->SetViewpoint(this, false); charmer->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE); break; case CHARM_TYPE_CHARM: @@ -15143,7 +15143,7 @@ void Unit::RemoveCharmedBy(Unit *charmer) //a guardian should always have charminfo if (charmer->GetTypeId() == TYPEID_PLAYER && this != charmer->GetFirstControlled()) - ((Player*)charmer)->SendRemoveControlBar(); + charmer->ToPlayer()->SendRemoveControlBar(); else if (GetTypeId() == TYPEID_PLAYER || GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isGuardian()) DeleteCharmInfo(); } @@ -15151,7 +15151,7 @@ void Unit::RemoveCharmedBy(Unit *charmer) void Unit::RestoreFaction() { if (GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->setFactionForRace(getRace()); + this->ToPlayer()->setFactionForRace(getRace()); else { if (HasUnitTypeMask(UNIT_MASK_MINION)) @@ -15223,7 +15223,7 @@ bool Unit::IsInPartyWith(Unit const *unit) const return true; if (u1->GetTypeId() == TYPEID_PLAYER && u2->GetTypeId() == TYPEID_PLAYER) - return ((Player*)u1)->IsInSameGroupWith((Player*)u2); + return u1->ToPlayer()->IsInSameGroupWith(u2->ToPlayer()); else return false; } @@ -15239,7 +15239,7 @@ bool Unit::IsInRaidWith(Unit const *unit) const return true; if (u1->GetTypeId() == TYPEID_PLAYER && u2->GetTypeId() == TYPEID_PLAYER) - return ((Player*)u1)->IsInSameRaidWith((Player*)u2); + return u1->ToPlayer()->IsInSameRaidWith(u2->ToPlayer()); else return false; } @@ -15283,11 +15283,11 @@ void Unit::GetPartyMemberInDist(std::list<Unit*> &TagUnitMap, float radius) Unit *owner = GetCharmerOrOwnerOrSelf(); Group *pGroup = NULL; if (owner->GetTypeId() == TYPEID_PLAYER) - pGroup = ((Player*)owner)->GetGroup(); + pGroup = owner->ToPlayer()->GetGroup(); if (pGroup) { - uint8 subgroup = ((Player*)owner)->GetSubGroup(); + uint8 subgroup = owner->ToPlayer()->GetSubGroup(); for (GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next()) { @@ -15320,11 +15320,11 @@ void Unit::GetPartyMembers(std::list<Unit*> &TagUnitMap) Unit *owner = GetCharmerOrOwnerOrSelf(); Group *pGroup = NULL; if (owner->GetTypeId() == TYPEID_PLAYER) - pGroup = ((Player*)owner)->GetGroup(); + pGroup = owner->ToPlayer()->GetGroup(); if (pGroup) { - uint8 subgroup = ((Player*)owner)->GetSubGroup(); + uint8 subgroup = owner->ToPlayer()->GetSubGroup(); for (GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next()) { @@ -15766,7 +15766,7 @@ void Unit::JumpTo(float speedXY, float speedZ, bool forward) data << float(speedXY); // Horizontal speed data << float(-speedZ); // Z Movement speed (vertical) - ((Player*)this)->GetSession()->SendPacket(&data); + this->ToPlayer()->GetSession()->SendPacket(&data); } } @@ -15816,15 +15816,15 @@ void Unit::EnterVehicle(Vehicle *vehicle, int8 seatId) if (GetTypeId() == TYPEID_PLAYER) { - ((Player*)this)->StopCastingCharm(); - ((Player*)this)->StopCastingBindSight(); - ((Player*)this)->Unmount(); - ((Player*)this)->RemoveAurasByType(SPELL_AURA_MOUNTED); + this->ToPlayer()->StopCastingCharm(); + this->ToPlayer()->StopCastingBindSight(); + this->ToPlayer()->Unmount(); + this->ToPlayer()->RemoveAurasByType(SPELL_AURA_MOUNTED); // drop flag at invisible in bg - if(((Player*)this)->InBattleGround()) - if(BattleGround *bg = ((Player*)this)->GetBattleGround()) - bg->EventPlayerDroppedFlag((Player*)this); + if(this->ToPlayer()->InBattleGround()) + if(BattleGround *bg = this->ToPlayer()->GetBattleGround()) + bg->EventPlayerDroppedFlag(this->ToPlayer()); } assert(!m_vehicle); @@ -15841,9 +15841,9 @@ void Unit::EnterVehicle(Vehicle *vehicle, int8 seatId) if (GetTypeId() == TYPEID_PLAYER) { - //((Player*)this)->SetClientControl(vehicle, 1); + //this->ToPlayer()->SetClientControl(vehicle, 1); WorldPacket data(SMSG_ON_CANCEL_EXPECTED_RIDE_VEHICLE_AURA, 0); - ((Player*)this)->GetSession()->SendPacket(&data); + this->ToPlayer()->GetSession()->SendPacket(&data); } } @@ -15908,9 +15908,9 @@ void Unit::ExitVehicle() //Send leave vehicle, not correct if (GetTypeId() == TYPEID_PLAYER) { - //((Player*)this)->SetClientControl(this, 1); - ((Player*)this)->SendTeleportAckMsg(); - ((Player*)this)->SetFallInformation(0, GetPositionZ()); + //this->ToPlayer()->SetClientControl(this, 1); + this->ToPlayer()->SendTeleportAckMsg(); + this->ToPlayer()->SetFallInformation(0, GetPositionZ()); } WorldPacket data; BuildHeartBeatMsg(&data); @@ -16025,7 +16025,7 @@ void Unit::SetFlying(bool apply) void Unit::NearTeleportTo( float x, float y, float z, float orientation, bool casting /*= false*/ ) { if (GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->TeleportTo(GetMapId(), x, y, z, orientation, TELE_TO_NOT_LEAVE_TRANSPORT | TELE_TO_NOT_LEAVE_COMBAT | TELE_TO_NOT_UNSUMMON_PET | (casting ? TELE_TO_SPELL : 0)); + this->ToPlayer()->TeleportTo(GetMapId(), x, y, z, orientation, TELE_TO_NOT_LEAVE_TRANSPORT | TELE_TO_NOT_LEAVE_COMBAT | TELE_TO_NOT_UNSUMMON_PET | (casting ? TELE_TO_SPELL : 0)); else { WorldPacket data; @@ -16187,7 +16187,7 @@ void Unit::StopAttackFaction(uint32 faction_id) // melee and ranged forced attack cancel if (GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->SendAttackSwingCancelAttack(); + this->ToPlayer()->SendAttackSwingCancelAttack(); } } diff --git a/src/game/Unit.h b/src/game/Unit.h index 05c0c493abe..acb7c0fd68d 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -329,6 +329,7 @@ class PetAura; class Minion; class Guardian; class UnitAI; +class Totem; class Transport; class Vehicle; @@ -1849,8 +1850,8 @@ class Unit : public WorldObject static Player* GetPlayer(uint64 guid); static Creature* GetCreature(WorldObject& object, uint64 guid); - MotionMaster* GetMotionMaster() { return &i_motionMaster; } - + MotionMaster* GetMotionMaster(){ return &i_motionMaster; } + bool IsStopped() const { return !(hasUnitState(UNIT_STAT_MOVING)); } void StopMoving(); @@ -1954,6 +1955,10 @@ class Unit : public WorldObject void OutDebugInfo() const; virtual bool isBeingLoaded() const { return false;} + + Pet* ToPet(){ if(isPet()) return reinterpret_cast<Pet*>(this); else return NULL; } + Totem* ToTotem(){ if(isTotem()) return reinterpret_cast<Totem*>(this); else return NULL; } + protected: explicit Unit (); diff --git a/src/game/Vehicle.cpp b/src/game/Vehicle.cpp index 09f1e8c2ade..bf7ecef399a 100644 --- a/src/game/Vehicle.cpp +++ b/src/game/Vehicle.cpp @@ -338,7 +338,7 @@ bool Vehicle::AddPassenger(Unit *unit, int8 seatId) } //if(unit->GetTypeId() == TYPEID_PLAYER) - // ((Player*)unit)->SendTeleportAckMsg(); + // unit->ToPlayer()->SendTeleportAckMsg(); //unit->SendMovementFlagUpdate(); return true; diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp index ddf0c9173bd..cf487b1ca76 100644 --- a/src/game/WorldSession.cpp +++ b/src/game/WorldSession.cpp @@ -329,7 +329,7 @@ void WorldSession::LogoutPlayer(bool Save) if(owner) { if(owner->GetTypeId() == TYPEID_PLAYER) - aset.insert((Player*)owner); + aset.insert(owner->ToPlayer()); } else if((*itr)->GetTypeId() == TYPEID_PLAYER) |