Skip to content

Commit

Permalink
[8871] Avoid use StopMoving when creature is already stopped.
Browse files Browse the repository at this point in the history
Some additional code cleanup in related code.
  • Loading branch information
NoFantasy committed Nov 25, 2009
1 parent b9d2db3 commit 14b21d8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 40 deletions.
19 changes: 11 additions & 8 deletions src/game/BattleGroundHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 11 additions & 8 deletions src/game/ItemHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
31 changes: 15 additions & 16 deletions src/game/NPCHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
16 changes: 9 additions & 7 deletions src/game/QuestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (!pCreature->IsStopped())
pCreature->StopMoving();

if(Script->GossipHello( _player, pCreature ) )
if (Script->GossipHello(_player, pCreature))
return;

pCreature->prepareGossipMenu(_player);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "8870"
#define REVISION_NR "8871"
#endif // __REVISION_NR_H__

0 comments on commit 14b21d8

Please sign in to comment.