aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Chat/Chat.cpp
diff options
context:
space:
mode:
authorRochet2 <rochet2@post.com>2017-01-08 05:55:22 +0200
committertkrokli <tkrokli@users.noreply.github.com>2017-01-08 04:55:22 +0100
commit117d1c31c99b00269fa73d50d1a5ccf7c49a8450 (patch)
tree59c0ffa808fd374603017143bb99835ebcbba129 /src/server/game/Chat/Chat.cpp
parent3d245fb2dc40d89ecfbe9f924ef9d3d16bc02cda (diff)
Scripts/Commands: Fix guid usage and enhance commands (#18278)
- Fix targeting gameobjects and creatures for .dist and .gps. The old code used DB guid to search from core generated guid lists. - Fix some error messages saying 'no player found' even if creatures and gameobjects and players were searched - Change atoi to atoul when receiving lowguids as string or other uint32 values - Use ObjectGuid::LowType instead of uint32 for lowguid type - Allow .gob info to take in gameobject guid link as well as entry link in addition to gameobject entry and update the documentation of the command - Change .gob delete to post the spawnid (dbguid) instead of the ingame generated guid (which is basically never seen or used by the player in any other commands that I see) - Allow spawntimesecs to be negative when spawning a gameobject - Disable searching by ingame spawn id in commands. (it makes little sense for a user to provide a number which is then attempted to be used as DB guid and non DB guid when both could have a match) - Update .gob turn documentation to tell about possibility to provide orientation in command - Correct the types in .gob add command result trinity_string - Correct the creature search for .npc del - Change .event to .event info - Add .go offset command - Remove the .go command for empty string (no subcommand given) because it just used .go xyz - Extend .gob info to show size, faction, flags and model dimensions - Remove some unnecessary casts - Document .wp show better (first and last were not documented) - Insert spawnid to .wp show info error message - Fix spawntime printing for .gobject target - Fix guid targetting for .npc set movetype - Fix query by spawnid for .wp show info - Fix deleting of existing waypoints when twice doing the command .wp show on - Fix deleting of existing waypoints when doing the command .wp show off - Change wpguid column in DB and in core to uint32, which is what the spawnid type is in core and db.
Diffstat (limited to 'src/server/game/Chat/Chat.cpp')
-rw-r--r--src/server/game/Chat/Chat.cpp72
1 files changed, 36 insertions, 36 deletions
diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp
index ee327ea684b..d486a95c52a 100644
--- a/src/server/game/Chat/Chat.cpp
+++ b/src/server/game/Chat/Chat.cpp
@@ -881,25 +881,30 @@ GameObject* ChatHandler::GetNearbyGameObject()
return obj;
}
-GameObject* ChatHandler::GetObjectGlobalyWithGuidOrNearWithDbGuid(ObjectGuid::LowType lowguid, uint32 entry)
+GameObject* ChatHandler::GetObjectFromPlayerMapByDbGuid(ObjectGuid::LowType lowguid)
{
if (!m_session)
return nullptr;
+ auto bounds = m_session->GetPlayer()->GetMap()->GetGameObjectBySpawnIdStore().equal_range(lowguid);
+ if (bounds.first != bounds.second)
+ return bounds.first->second;
+ return nullptr;
+}
- Player* pl = m_session->GetPlayer();
-
- GameObject* obj = pl->GetMap()->GetGameObject(ObjectGuid(HighGuid::GameObject, entry, lowguid));
-
- if (!obj && sObjectMgr->GetGOData(lowguid)) // guid is DB guid of object
+Creature* ChatHandler::GetCreatureFromPlayerMapByDbGuid(ObjectGuid::LowType lowguid)
+{
+ if (!m_session)
+ return nullptr;
+ // Select the first alive creature or a dead one if not found
+ Creature* creature = nullptr;
+ auto bounds = m_session->GetPlayer()->GetMap()->GetCreatureBySpawnIdStore().equal_range(lowguid);
+ for (auto it = bounds.first; it != bounds.second; ++it)
{
- auto bounds = pl->GetMap()->GetGameObjectBySpawnIdStore().equal_range(lowguid);
- if (bounds.first == bounds.second)
- return nullptr;
-
- return bounds.first->second;
+ creature = it->second;
+ if (it->second->IsAlive())
+ break;
}
-
- return obj;
+ return creature;
}
enum SpellLinkType
@@ -989,9 +994,9 @@ GameTele const* ChatHandler::extractGameTeleFromLink(char* text)
enum GuidLinkType
{
- SPELL_LINK_PLAYER = 0, // must be first for selection in not link case
- SPELL_LINK_CREATURE = 1,
- SPELL_LINK_GAMEOBJECT = 2
+ GUID_LINK_PLAYER = 0, // must be first for selection in not link case
+ GUID_LINK_CREATURE = 1,
+ GUID_LINK_GAMEOBJECT = 2
};
static char const* const guidKeys[] =
@@ -1002,7 +1007,7 @@ static char const* const guidKeys[] =
nullptr
};
-ObjectGuid ChatHandler::extractGuidFromLink(char* text)
+ObjectGuid::LowType ChatHandler::extractLowGuidFromLink(char* text, HighGuid& guidHigh)
{
int type = 0;
@@ -1011,46 +1016,41 @@ ObjectGuid ChatHandler::extractGuidFromLink(char* text)
// |color|Hplayer:name|h[name]|h|r
char* idS = extractKeyFromLink(text, guidKeys, &type);
if (!idS)
- return ObjectGuid::Empty;
+ return 0;
switch (type)
{
- case SPELL_LINK_PLAYER:
+ case GUID_LINK_PLAYER:
{
+ guidHigh = HighGuid::Player;
std::string name = idS;
if (!normalizePlayerName(name))
- return ObjectGuid::Empty;
+ return 0;
if (Player* player = ObjectAccessor::FindPlayerByName(name))
- return player->GetGUID();
+ return player->GetGUID().GetCounter();
if (ObjectGuid guid = sObjectMgr->GetPlayerGUIDByName(name))
- return guid;
+ return guid.GetCounter();
- return ObjectGuid::Empty;
+ return 0;
}
- case SPELL_LINK_CREATURE:
+ case GUID_LINK_CREATURE:
{
+ guidHigh = HighGuid::Unit;
ObjectGuid::LowType lowguid = atoul(idS);
-
- if (CreatureData const* data = sObjectMgr->GetCreatureData(lowguid))
- return ObjectGuid(HighGuid::Unit, data->id, lowguid);
- else
- return ObjectGuid::Empty;
+ return lowguid;
}
- case SPELL_LINK_GAMEOBJECT:
+ case GUID_LINK_GAMEOBJECT:
{
+ guidHigh = HighGuid::GameObject;
ObjectGuid::LowType lowguid = atoul(idS);
-
- if (GameObjectData const* data = sObjectMgr->GetGOData(lowguid))
- return ObjectGuid(HighGuid::GameObject, data->id, lowguid);
- else
- return ObjectGuid::Empty;
+ return lowguid;
}
}
// unknown type?
- return ObjectGuid::Empty;
+ return 0;
}
std::string ChatHandler::extractPlayerNameFromLink(char* text)