From 10ebadcadf13e2c4a4a8d6f8107e6def27f023a9 Mon Sep 17 00:00:00 2001 From: NoFantasy Date: Wed, 25 Nov 2009 12:14:59 +0100 Subject: [PATCH] [8871] Avoid use StopMoving when creature is already stopped. Some additional code cleanup in related code. --- src/game/BattleGroundHandler.cpp | 19 +++++++++++-------- src/game/ItemHandler.cpp | 19 +++++++++++-------- src/game/NPCHandler.cpp | 31 +++++++++++++++---------------- src/game/QuestHandler.cpp | 18 ++++++++++-------- src/shared/revision_nr.h | 2 +- 5 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/game/BattleGroundHandler.cpp b/src/game/BattleGroundHandler.cpp index f6d322989..cb38b33cd 100644 --- a/src/game/BattleGroundHandler.cpp +++ b/src/game/BattleGroundHandler.cpp @@ -32,30 +32,33 @@ #include "Language.h" #include "ScriptCalls.h" -void WorldSession::HandleBattlemasterHelloOpcode( WorldPacket & recv_data ) +void WorldSession::HandleBattlemasterHelloOpcode(WorldPacket & recv_data) { uint64 guid; recv_data >> guid; - sLog.outDebug( "WORLD: Recvd CMSG_BATTLEMASTER_HELLO Message from (GUID: %u TypeId:%u)", GUID_LOPART(guid),GuidHigh2TypeId(GUID_HIPART(guid))); - Creature *unit = GetPlayer()->GetMap()->GetCreature(guid); - if (!unit) + sLog.outDebug("WORLD: Recvd CMSG_BATTLEMASTER_HELLO Message from (GUID: %u TypeId:%u)", GUID_LOPART(guid),GuidHigh2TypeId(GUID_HIPART(guid))); + + Creature *pCreature = GetPlayer()->GetMap()->GetCreature(guid); + + if (!pCreature) return; - if(!unit->isBattleMaster()) // it's not battlemaster + if (!pCreature->isBattleMaster()) // it's not battlemaster return; // Stop the npc if moving - unit->StopMoving(); + if (!pCreature->IsStopped()) + pCreature->StopMoving(); - BattleGroundTypeId bgTypeId = sBattleGroundMgr.GetBattleMasterBG(unit->GetEntry()); + BattleGroundTypeId bgTypeId = sBattleGroundMgr.GetBattleMasterBG(pCreature->GetEntry()); if (bgTypeId == BATTLEGROUND_TYPE_NONE) return; if (!_player->GetBGAccessByLevel(bgTypeId)) { - // temp, must be gossip message... + // temp, must be gossip message... SendNotification(LANG_YOUR_BG_LEVEL_REQ_ERROR); return; } diff --git a/src/game/ItemHandler.cpp b/src/game/ItemHandler.cpp index 23af0d5d6..6f235125e 100644 --- a/src/game/ItemHandler.cpp +++ b/src/game/ItemHandler.cpp @@ -700,29 +700,32 @@ void WorldSession::HandleListInventoryOpcode( WorldPacket & recv_data ) SendListInventory( guid ); } -void WorldSession::SendListInventory( uint64 vendorguid ) +void WorldSession::SendListInventory(uint64 vendorguid) { - sLog.outDebug( "WORLD: Sent SMSG_LIST_INVENTORY" ); + sLog.outDebug("WORLD: Sent SMSG_LIST_INVENTORY"); Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(vendorguid, UNIT_NPC_FLAG_VENDOR); + if (!pCreature) { - sLog.outDebug( "WORLD: SendListInventory - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid)) ); - _player->SendSellError( SELL_ERR_CANT_FIND_VENDOR, NULL, 0, 0); + sLog.outDebug("WORLD: SendListInventory - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid))); + _player->SendSellError(SELL_ERR_CANT_FIND_VENDOR, NULL, 0, 0); return; } // remove fake death - if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) + if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); // Stop the npc if moving - pCreature->StopMoving(); + if (!pCreature->IsStopped()) + pCreature->StopMoving(); VendorItemData const* vItems = pCreature->GetVendorItems(); - if(!vItems) + + if (!vItems) { - _player->SendSellError( SELL_ERR_CANT_FIND_VENDOR, NULL, 0, 0); + _player->SendSellError(SELL_ERR_CANT_FIND_VENDOR, NULL, 0, 0); return; } diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp index 096783e00..8dd54a60a 100644 --- a/src/game/NPCHandler.cpp +++ b/src/game/NPCHandler.cpp @@ -249,37 +249,36 @@ void WorldSession::HandleTrainerBuySpellOpcode( WorldPacket & recv_data ) SendPacket(&data); } -void WorldSession::HandleGossipHelloOpcode( WorldPacket & recv_data ) +void WorldSession::HandleGossipHelloOpcode(WorldPacket & recv_data) { - sLog.outDebug( "WORLD: Received CMSG_GOSSIP_HELLO" ); + sLog.outDebug("WORLD: Received CMSG_GOSSIP_HELLO"); uint64 guid; recv_data >> guid; - Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_NONE); - if (!unit) + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_NONE); + + if (!pCreature) { - sLog.outDebug( "WORLD: HandleGossipHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); + sLog.outDebug("WORLD: HandleGossipHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid))); return; } // remove fake death - if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) + if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); - if( unit->isArmorer() || unit->isCivilian() || unit->isQuestGiver() || unit->isServiceProvider()) - { - unit->StopMoving(); - } + if (!pCreature->IsStopped()) + pCreature->StopMoving(); - if (unit->isSpiritGuide()) - unit->SendAreaSpiritHealerQueryOpcode(_player); + if (pCreature->isSpiritGuide()) + pCreature->SendAreaSpiritHealerQueryOpcode(_player); - if(!Script->GossipHello( _player, unit )) + if (!Script->GossipHello(_player, pCreature)) { - _player->TalkedToCreature(unit->GetEntry(),unit->GetGUID()); - unit->prepareGossipMenu(_player); - unit->sendPreparedGossip(_player); + _player->TalkedToCreature(pCreature->GetEntry(), pCreature->GetGUID()); + pCreature->prepareGossipMenu(_player); + pCreature->sendPreparedGossip(_player); } } diff --git a/src/game/QuestHandler.cpp b/src/game/QuestHandler.cpp index 5409b65d2..72a4c3e50 100644 --- a/src/game/QuestHandler.cpp +++ b/src/game/QuestHandler.cpp @@ -76,28 +76,30 @@ void WorldSession::HandleQuestgiverStatusQueryOpcode( WorldPacket & recv_data ) _player->PlayerTalkClass->SendQuestGiverStatus(questStatus, guid); } -void WorldSession::HandleQuestgiverHelloOpcode( WorldPacket & recv_data ) +void WorldSession::HandleQuestgiverHelloOpcode(WorldPacket & recv_data) { uint64 guid; recv_data >> guid; sLog.outDebug ("WORLD: Received CMSG_QUESTGIVER_HELLO npc = %u", GUID_LOPART(guid)); - Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_NONE); + Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_NONE); + if (!pCreature) { - sLog.outDebug ("WORLD: HandleQuestgiverHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", - GUID_LOPART(guid)); + sLog.outDebug ("WORLD: HandleQuestgiverHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", GUID_LOPART(guid)); return; } // remove fake death - if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) + if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); - // Stop the npc if moving - pCreature->StopMoving(); - if(Script->GossipHello( _player, pCreature ) ) + // Stop the npc if moving + if (!pCreature->IsStopped()) + pCreature->StopMoving(); + + if (Script->GossipHello(_player, pCreature)) return; pCreature->prepareGossipMenu(_player); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index e2b6c5250..7a7b78a9f 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "8870" + #define REVISION_NR "8871" #endif // __REVISION_NR_H__