Scripts/Commands: Fix guid usage and enhance commands

- 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.
This commit is contained in:
Aokromes
2017-04-02 07:41:03 +02:00
parent e24178406d
commit 2d54defdf0
14 changed files with 301 additions and 174 deletions

View File

@@ -900,22 +900,31 @@ 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)
obj = bounds.first->second;
creature = it->second;
if (it->second->IsAlive())
break;
}
return obj;
return creature;
}
enum SpellLinkType
@@ -1005,9 +1014,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[] =
@@ -1018,7 +1027,7 @@ static char const* const guidKeys[] =
nullptr
};
ObjectGuid ChatHandler::extractGuidFromLink(char* text)
ObjectGuid::LowType ChatHandler::extractLowGuidFromLink(char* text, HighGuid& guidHigh)
{
int type = 0;
@@ -1027,46 +1036,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 = sWorld->GetCharacterGuidByName(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)