本文整理汇总了C++中Map::GetSpawnMode方法的典型用法代码示例。如果您正苦于以下问题:C++ Map::GetSpawnMode方法的具体用法?C++ Map::GetSpawnMode怎么用?C++ Map::GetSpawnMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map::GetSpawnMode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveObject
static void SaveObject(Player* player, uint32 GObjectID, bool isHex, bool message = false)
{
GameObject* object = GetObjectByGObjectID(player, GObjectID, isHex);
if (!object)
return;
Map* map = player->GetMap();
GameObject* saved = new GameObject;
uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
float x, y, z, o;
object->GetPosition(x, y, z, o);
if (!saved->Create(guidLow, object->GetEntry(), map, object->GetPhaseMask(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
{
delete saved;
return;
}
saved->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), object->GetPhaseMask());
if (!saved->LoadGameObjectFromDB(guidLow, map))
{
delete saved;
return;
}
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
DeleteObject(object/*, isHex ? GObjectID : 0*/); // delete old
std::ostringstream ss;
if(!isHex)
ss << "GOMOVE|SWAP|" << std::dec << GObjectID << std::dec << "||" << guidLow;
else
ss << "GOMOVE|SWAP|" << "0x" << std::hex << GObjectID << std::dec << "||" << guidLow;
SendAddonMessage(player, ss.str().c_str());
}
示例2: HandleNpcAddCommand
//add spawn of creature
static bool HandleNpcAddCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
char* charID = handler->extractKeyFromLink((char*)args,"Hcreature_entry");
if (!charID)
return false;
char* team = strtok(NULL, " ");
int32 teamval = 0;
if (team) {
teamval = atoi(team);
}
if (teamval < 0) {
teamval = 0;
}
uint32 id = atoi(charID);
Player *chr = handler->GetSession()->GetPlayer();
float x = chr->GetPositionX();
float y = chr->GetPositionY();
float z = chr->GetPositionZ();
float o = chr->GetOrientation();
Map *map = chr->GetMap();
if (chr->GetTransport())
{
uint32 tguid = chr->GetTransport()->AddNPCPassenger(0, id, chr->GetTransOffsetX(), chr->GetTransOffsetY(), chr->GetTransOffsetZ(), chr->GetTransOffsetO());
if (tguid > 0)
WorldDatabase.PQuery("INSERT INTO creature_transport (guid, npc_entry, transport_entry, TransOffsetX, TransOffsetY, TransOffsetZ, TransOffsetO) values (%u, %u, %f, %f, %f, %f, %u)", tguid, id, chr->GetTransport()->GetEntry(), chr->GetTransOffsetX(), chr->GetTransOffsetY(), chr->GetTransOffsetZ(), chr->GetTransOffsetO());
return true;
}
Creature* pCreature = new Creature;
if (!pCreature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, (uint32)teamval, x, y, z, o))
{
delete pCreature;
return false;
}
pCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
uint32 db_guid = pCreature->GetDBTableGUIDLow();
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
pCreature->LoadFromDB(db_guid, map);
map->Add(pCreature);
sObjectMgr->AddCreatureToGrid(db_guid, sObjectMgr->GetCreatureData(db_guid));
return true;
}
示例3: HandleWpShowCommand
//.........这里部分代码省略.........
}
do
{
Field* fields = result->Fetch();
uint32 point = fields[0].GetUInt32();
float x = fields[1].GetFloat();
float y = fields[2].GetFloat();
float z = fields[3].GetFloat();
uint32 id = VISUAL_WAYPOINT;
Player* chr = handler->GetSession()->GetPlayer();
Map* map = chr->GetMap();
float o = chr->GetOrientation();
Creature* wpCreature = new Creature;
if (!wpCreature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, 0, x, y, z, o))
{
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id);
delete wpCreature;
return false;
}
// Set "wpguid" column to the visual waypoint
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_WPGUID);
stmt->setInt32(0, int32(wpCreature->GetGUIDLow()));
stmt->setUInt32(1, pathid);
stmt->setUInt32(2, point);
WorldDatabase.Execute(stmt);
wpCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
if (!wpCreature->LoadCreatureFromDB(wpCreature->GetDBTableGUIDLow(), map))
{
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id);
delete wpCreature;
return false;
}
if (target)
{
wpCreature->SetDisplayId(target->GetDisplayId());
wpCreature->SetFloatValue(OBJECT_FIELD_SCALE_X, 0.5f);
wpCreature->SetLevel(point > STRONG_MAX_LEVEL ? STRONG_MAX_LEVEL : point);
}
}
while (result->NextRow());
handler->SendSysMessage("|cff00ff00Showing the current creature's path.|r");
return true;
}
if (show == "first")
{
handler->PSendSysMessage("|cff00ff00DEBUG: wp first, GUID: %u|r", pathid);
QueryResult result = WorldDatabase.PQuery("SELECT position_x, position_y, position_z FROM waypoint_data WHERE point='1' AND id = '%u'", pathid);
if (!result)
{
handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUND, pathid);
handler->SetSentErrorMessage(true);
return false;
}
示例4: HandleWpModifyCommand
//.........这里部分代码省略.........
Creature* wpCreature = NULL;
if (wpGuid != 0)
{
wpCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
wpCreature->CombatStop();
wpCreature->DeleteFromDB();
wpCreature->AddObjectToRemoveList();
}
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_WAYPOINT_DATA);
stmt->setUInt32(0, pathid);
stmt->setUInt32(1, point);
WorldDatabase.Execute(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_POINT);
stmt->setUInt32(0, pathid);
stmt->setUInt32(1, point);
WorldDatabase.Execute(stmt);
handler->PSendSysMessage(LANG_WAYPOINT_REMOVED);
return true;
} // del
if (show == "move" && target)
{
handler->PSendSysMessage("|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff%u|r", pathid);
Player* chr = handler->GetSession()->GetPlayer();
Map* map = chr->GetMap();
{
// wpCreature
Creature* wpCreature = NULL;
// What to do:
// Move the visual spawnpoint
// Respawn the owner of the waypoints
if (wpGuid != 0)
{
wpCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
wpCreature->CombatStop();
wpCreature->DeleteFromDB();
wpCreature->AddObjectToRemoveList();
// re-create
Creature* wpCreature2 = new Creature;
if (!wpCreature2->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), VISUAL_WAYPOINT, 0, 0, chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), chr->GetOrientation()))
{
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete wpCreature2;
return false;
}
wpCreature2->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
//TODO: Should we first use "Create" then use "LoadFromDB"?
if (!wpCreature2->LoadCreatureFromDB(wpCreature2->GetDBTableGUIDLow(), map))
{
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete wpCreature2;
return false;
}
//sMapMgr->GetMap(npcCreature->GetMapId())->Add(wpCreature2);
}
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_POSITION);
stmt->setFloat(0, chr->GetPositionX());
stmt->setFloat(1, chr->GetPositionY());
stmt->setFloat(2, chr->GetPositionZ());
stmt->setUInt32(3, pathid);
stmt->setUInt32(4, point);
WorldDatabase.Execute(stmt);
handler->PSendSysMessage(LANG_WAYPOINT_CHANGED);
}
return true;
} // move
const char *text = arg_str;
if (text == 0)
{
// show_str check for present in list of correct values, no sql injection possible
WorldDatabase.PExecute("UPDATE waypoint_data SET %s=NULL WHERE id='%u' AND point='%u'", show_str, pathid, point); // Query can't be a prepared statement
}
else
{
// show_str check for present in list of correct values, no sql injection possible
std::string text2 = text;
WorldDatabase.EscapeString(text2);
WorldDatabase.PExecute("UPDATE waypoint_data SET %s='%s' WHERE id='%u' AND point='%u'", show_str, text2.c_str(), pathid, point); // Query can't be a prepared statement
}
handler->PSendSysMessage(LANG_WAYPOINT_CHANGED_NO, show_str);
return true;
}
示例5: HandleGameObjectAddCommand
//spawn go
static bool HandleGameObjectAddCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
if (!id)
return false;
uint32 objectId = atol(id);
if (!objectId)
return false;
char* spawntimeSecs = strtok(NULL, " ");
const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId);
if (!objectInfo)
{
handler->PSendSysMessage(LANGUAGE_GAMEOBJECT_NOT_EXIST, objectId);
handler->SetSentErrorMessage(true);
return false;
}
if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
{
// report to DB errors log as in loading case
sLog->outErrorDb("Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", objectId, objectInfo->type, objectInfo->displayId);
handler->PSendSysMessage(LANGUAGE_GAMEOBJECT_HAVE_INVALID_DATA, objectId);
handler->SetSentErrorMessage(true);
return false;
}
Player* player = handler->GetSession()->GetPlayer();
float x = float(player->GetPositionX());
float y = float(player->GetPositionY());
float z = float(player->GetPositionZ());
float o = float(player->GetOrientation());
Map* map = player->GetMap();
GameObject* object = new GameObject;
uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
if (!object->Create(guidLow, objectInfo->entry, map, player->GetPhaseMgr().GetPhaseMaskForSpawn(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
{
delete object;
return false;
}
if (spawntimeSecs)
{
uint32 value = atoi((char*)spawntimeSecs);
object->SetRespawnTime(value);
}
// fill the gameobject data and save to the db
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMgr().GetPhaseMaskForSpawn());
// this will generate a new guid if the object is in an instance
if (!object->LoadGameObjectFromDB(guidLow, map))
{
delete object;
return false;
}
// TODO: is it really necessary to add both the real and DB table guid here ?
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
handler->PSendSysMessage(LANGUAGE_GAMEOBJECT_ADD, objectId, objectInfo->name.c_str(), guidLow, x, y, z);
return true;
}
示例6: HandleGameObjectAddCommand
//spawn go
static bool HandleGameObjectAddCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args,"Hgameobject_entry");
if (!cId)
return false;
uint32 id = atol(cId);
if (!id)
return false;
char* spawntimeSecs = strtok(NULL, " ");
const GameObjectInfo *gInfo = ObjectMgr::GetGameObjectInfo(id);
if (!gInfo)
{
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST,id);
handler->SetSentErrorMessage(true);
return false;
}
if (gInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(gInfo->displayId))
{
// report to DB errors log as in loading case
sLog->outErrorDb("Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.",id, gInfo->type, gInfo->displayId);
handler->PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA,id);
handler->SetSentErrorMessage(true);
return false;
}
Player *chr = handler->GetSession()->GetPlayer();
float x = float(chr->GetPositionX());
float y = float(chr->GetPositionY());
float z = float(chr->GetPositionZ());
float o = float(chr->GetOrientation());
Map *map = chr->GetMap();
GameObject* pGameObj = new GameObject;
uint32 db_lowGUID = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
if (!pGameObj->Create(db_lowGUID, gInfo->id, map, chr->GetPhaseMaskForSpawn(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
{
delete pGameObj;
return false;
}
if (spawntimeSecs)
{
uint32 value = atoi((char*)spawntimeSecs);
pGameObj->SetRespawnTime(value);
//sLog->outDebug(LOG_FILTER_TSCR, "*** spawntimeSecs: %d", value);
}
// fill the gameobject data and save to the db
pGameObj->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()),chr->GetPhaseMaskForSpawn());
// this will generate a new guid if the object is in an instance
if (!pGameObj->LoadFromDB(db_lowGUID, map))
{
delete pGameObj;
return false;
}
map->Add(pGameObj);
// TODO: is it really necessary to add both the real and DB table guid here ?
sObjectMgr->AddGameobjectToGrid(db_lowGUID, sObjectMgr->GetGOData(db_lowGUID));
handler->PSendSysMessage(LANG_GAMEOBJECT_ADD,id,gInfo->name,db_lowGUID,x,y,z);
return true;
}
示例7: CreateInstanceForPlayer
/*
- return the right instance for the object, based on its InstanceId
- create the instance if it's not created already
- the player is not actually added to the instance (only in InstanceMap::Add)
*/
Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player)
{
if (GetId() != mapId || !player)
return NULL;
Map* map = NULL;
uint32 newInstanceId = 0; // instanceId of the resulting map.
if (IsBattlegroundOrArena())
{
// Instantiate or find existing bg map for player. The instance id is set in battlegroundid.
newInstanceId = player->GetBattlegroundId();
if (!newInstanceId)
return NULL;
map = sMapMgr->FindMap(mapId, newInstanceId);
if (!map)
{
if (Battleground* bg = player->GetBattleground())
map = CreateBattleground(newInstanceId, bg);
else
{
player->TeleportToBGEntryPoint();
return NULL;
}
}
}
else
{
InstancePlayerBind* pBind = player->GetBoundInstance(GetId(), player->GetDifficulty(IsRaid()));
InstanceSave* pSave = pBind ? pBind->save : NULL;
// The player's permanent player bind is taken into consideration first, then the player's group bind and finally the solo bind.
if (!pBind || !pBind->perm)
{
InstanceGroupBind* groupBind = NULL;
Group* group = player->GetGroup();
// Use the player's difficulty setting (it may not be the same as the group's).
if (group)
{
groupBind = group->GetBoundInstance(this);
if (groupBind)
pSave = groupBind->save;
}
}
if (pSave)
{
// Solo / permanent / group lock exists.
newInstanceId = pSave->GetInstanceId();
map = FindInstanceMap(newInstanceId);
if (IsRaid())
{
if (player->IsOnDynamicDifficultyMap())
{
// Dynamic Difficulty lock: create an instance that matches the difficulty the player changes to.
if (player->GetDifficulty(IsRaid()) != pSave->GetDifficulty() || map && map->GetSpawnMode() != player->GetDifficulty(IsRaid()))
map = CreateInstance(newInstanceId, pSave, player->GetDifficulty(IsRaid()));
}
else
{
// Shared locks: create an instance to match the current player raid difficulty, if the save and player difficulties don't match.
// We must check for save difficulty going original diff -> new one, and map spawn mode going new -> original, to make sure all cases are handled.
// Although Heroic 10 / 25 Man also theoretically share a cooldown, if you kill a boss on 10 / 25 Heroic you cannot enter any other Heroic size version of the raid (cannot switch).
// Heroic size switching is already handled with no checks needed. The map is created on the save difficulty and you can only switch difficulty dynamically, from inside.
if (pSave->GetDifficulty() == RAID_DIFFICULTY_10MAN_NORMAL || pSave->GetDifficulty() == RAID_DIFFICULTY_25MAN_NORMAL)
{
// Normal. The map is created on the player difficulty.
if (player->GetDifficulty(IsRaid()) != pSave->GetDifficulty() || map && map->GetSpawnMode() != player->GetDifficulty(IsRaid()))
map = CreateInstance(newInstanceId, pSave, player->GetDifficulty(IsRaid()));
}
}
}
// It is possible that the save exists but the map doesn't, create it.
if (!map)
map = CreateInstance(newInstanceId, pSave, pSave->GetDifficulty());
}
else
{
// If no instanceId via group members or instance saves is found, the instance will be created for the first time.
newInstanceId = sMapMgr->GenerateInstanceId();
Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid());
map = FindInstanceMap(newInstanceId);
if (!map)
map = CreateInstance(newInstanceId, NULL, diff);
}
}
return map;
}
示例8: HandleGameObjectAddCommand
//spawn go
static bool HandleGameObjectAddCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
if (!id)
return false;
uint32 objectId = atoul(id);
if (!objectId)
return false;
char* spawntimeSecs = strtok(nullptr, " ");
GameObjectTemplate const* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId);
if (!objectInfo)
{
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, objectId);
handler->SetSentErrorMessage(true);
return false;
}
if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
{
// report to DB errors log as in loading case
TC_LOG_ERROR("sql.sql", "Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", objectId, objectInfo->type, objectInfo->displayId);
handler->PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA, objectId);
handler->SetSentErrorMessage(true);
return false;
}
Player* player = handler->GetSession()->GetPlayer();
Map* map = player->GetMap();
GameObject* object = new GameObject();
ObjectGuid::LowType guidLow = map->GenerateLowGuid<HighGuid::GameObject>();
QuaternionData rot = QuaternionData::fromEulerAnglesZYX(player->GetOrientation(), 0.f, 0.f);
if (!object->Create(guidLow, objectInfo->entry, map, player->GetPhaseMaskForSpawn(), *player, rot, 255, GO_STATE_READY))
{
delete object;
return false;
}
if (spawntimeSecs)
{
int32 value = atoi((char*)spawntimeSecs);
object->SetRespawnTime(value);
}
// fill the gameobject data and save to the db
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn());
guidLow = object->GetSpawnId();
// delete the old object and do a clean load from DB with a fresh new GameObject instance.
// this is required to avoid weird behavior and memory leaks
delete object;
object = new GameObject();
// this will generate a new guid if the object is in an instance
if (!object->LoadFromDB(guidLow, map, true))
{
delete object;
return false;
}
/// @todo is it really necessary to add both the real and DB table guid here ?
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGameObjectData(guidLow));
handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, objectId, objectInfo->name.c_str(), guidLow, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ());
return true;
}
示例9: HandleNpcBotSpawnCommand
//.........这里部分代码省略.........
if (!creInfo)
{
handler->PSendSysMessage("creature %u does not exist!", id);
handler->SetSentErrorMessage(true);
return false;
}
if (!(creInfo->flags_extra & CREATURE_FLAG_EXTRA_NPCBOT))
{
handler->PSendSysMessage("creature %u is not a npcbot!", id);
handler->SetSentErrorMessage(true);
return false;
}
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_NPCBOT_OWNER);
//"SELECT owner FROM character_npcbot WHERE entry = ?", CONNECTION_SYNCH
stmt->setUInt32(0, id);
PreparedQueryResult res1 = CharacterDatabase.Query(stmt);
if (res1)
{
handler->PSendSysMessage("Npcbot %u already exists in `characters_npcbot` table!", id);
handler->SendSysMessage("If you want to replace this bot to new location use '.npc move' command");
handler->SetSentErrorMessage(true);
return false;
}
stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_BY_ID);
//"SELECT guid FROM creature WHERE id = ?", CONNECTION_SYNCH
stmt->setUInt32(0, id);
PreparedQueryResult res2 = WorldDatabase.Query(stmt);
if (res2)
{
handler->PSendSysMessage("Npcbot %u already exists in `creature` table!", id);
handler->SetSentErrorMessage(true);
return false;
}
Player* chr = handler->GetSession()->GetPlayer();
if (chr->GetTransport())
{
handler->SendSysMessage("Cannot spawn bots on transport!");
handler->SetSentErrorMessage(true);
return false;
}
float x = chr->GetPositionX();
float y = chr->GetPositionY();
float z = chr->GetPositionZ();
float o = chr->GetOrientation();
Map* map = chr->GetMap();
if (map->Instanceable())
{
handler->SendSysMessage("Cannot spawn bots in instances!");
handler->SetSentErrorMessage(true);
return false;
}
Creature* creature = new Creature();
if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMgr().GetPhaseMaskForSpawn(), id, 0, 0, x, y, z, o, 0))
{
delete creature;
return false;
}
uint8 roleMask = BOT_ROLE_DPS;
uint8 m_class = creature->GetCreatureTemplate()->trainer_class;
if (!(m_class == CLASS_WARRIOR || m_class == CLASS_ROGUE ||
m_class == CLASS_PALADIN || m_class == CLASS_DEATH_KNIGHT ||
m_class == CLASS_SHAMAN || m_class == BOT_CLASS_BM))
roleMask |= BOT_ROLE_RANGED;
if (m_class == CLASS_PRIEST || m_class == CLASS_DRUID ||
m_class == CLASS_SHAMAN || m_class == CLASS_PALADIN)
roleMask |= BOT_ROLE_HEAL;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_NPCBOT);
//"INSERT INTO characters_npcbot (entry, roles) VALUES (?, ?)", CONNECTION_SYNCH
stmt->setUInt32(0, id);
stmt->setUInt8(1, roleMask);
CharacterDatabase.DirectExecute(stmt);
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMgr().GetPhaseMaskForSpawn());
uint32 db_guid = creature->GetDBTableGUIDLow();
if (!creature->LoadBotCreatureFromDB(db_guid, map))
{
handler->SendSysMessage("Cannot load npcbot from DB!");
handler->SetSentErrorMessage(true);
//return false;
delete creature;
return false;
}
sObjectMgr->AddCreatureToGrid(db_guid, sObjectMgr->GetCreatureData(db_guid));
handler->SendSysMessage("Npcbot successfully spawned.");
return true;
}
示例10: place
static GameObject* place(Player* player, float x, float y, float z, float o, uint32 phase, uint32 guid)
{
// e = !move && entry or move && guid (entryorguid
if (!player || !guid)
return NULL;
phase = 1;
const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(guid);
if(player->GetDistance(x, y, z) > 20)
{
ChatHandler(player->GetSession()).PSendSysMessage("You cant place that object so far away.");
ChatHandler(player->GetSession()).SetSentErrorMessage(true);
return NULL;
}
if (!objectInfo)
{
ChatHandler(player->GetSession()).PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, guid);
ChatHandler(player->GetSession()).SetSentErrorMessage(true);
return NULL;
}
if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
{
// sLog->outErrorDb("Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", e, objectInfo->type, objectInfo->displayId);
ChatHandler(player->GetSession()).PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA, guid);
ChatHandler(player->GetSession()).SetSentErrorMessage(true);
return NULL;
}
Map* map = player->GetMap();
if(player->GetMapId() == 608)
{
ChatHandler(player->GetSession()).PSendSysMessage("Stop! Not so fast. No placing APTs in here.");
ChatHandler(player->GetSession()).SetSentErrorMessage(true);
return NULL;
}
GameObject* object = new GameObject;
uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
if (!object->Create(guidLow, objectInfo->entry, map, phase, x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
{
delete object;
return NULL;
}
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase);
if (!object->LoadGameObjectFromDB(guidLow, map))
{
delete object;
return NULL;
}
// STORE THE ITEM_INSTANCE THAT WAS USED TO SPAWN THIS ITEM!!!
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
uint32 sec = time(NULL);
QueryResult result = WorldDatabase.PQuery("INSERT INTO apt_placed_objects VALUES('%u', '%u')", item_script_apt::itemGuid, guidLow);
result = WorldDatabase.PQuery("INSERT INTO legacy_gameobject VALUES ('%u', '1', '0', '%u')", guidLow, player->GetGUIDLow());
return object;
}
示例11: HandleNpcAddCommand
//add spawn of creature
static bool HandleNpcAddCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
char* charID = handler->extractKeyFromLink((char*)args, "Hcreature_entry");
if (!charID)
return false;
char* team = strtok(NULL, " ");
int32 teamval = 0;
if (team) { teamval = atoi(team); }
if (teamval < 0) { teamval = 0; }
uint32 id = atoi(charID);
Player* chr = handler->GetSession()->GetPlayer();
float x = chr->GetPositionX();
float y = chr->GetPositionY();
float z = chr->GetPositionZ();
float o = chr->GetOrientation();
Map* map = chr->GetMap();
if (chr->GetTransport())
{
uint32 tguid = chr->GetTransport()->AddNPCPassenger(0, id, chr->GetTransOffsetX(), chr->GetTransOffsetY(), chr->GetTransOffsetZ(), chr->GetTransOffsetO());
if (tguid > 0)
{
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_CREATURE_TRANSPORT);
stmt->setInt32(0, int32(tguid));
stmt->setInt32(1, int32(id));
stmt->setInt32(2, int32(chr->GetTransport()->GetEntry()));
stmt->setFloat(3, chr->GetTransOffsetX());
stmt->setFloat(4, chr->GetTransOffsetY());
stmt->setFloat(5, chr->GetTransOffsetZ());
stmt->setFloat(6, chr->GetTransOffsetO());
WorldDatabase.Execute(stmt);
}
return true;
}
Creature* creature = new Creature();
if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, (uint32)teamval, x, y, z, o))
{
delete creature;
return false;
}
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
uint32 db_guid = creature->GetDBTableGUIDLow();
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
if (!creature->LoadCreatureFromDB(db_guid, map))
{
delete creature;
return false;
}
sObjectMgr->AddCreatureToGrid(db_guid, sObjectMgr->GetCreatureData(db_guid));
return true;
}
示例12: HandleGameObjectAddCommand
//spawn go
static bool HandleGameObjectAddCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
if (!id)
return false;
uint32 objectId = atol(id);
if (!objectId)
return false;
if (handler->GetSession()->GetSecurity() == SEC_MODERATOR && handler->GetSession()->GetPlayer()->GetPhaseMask() == 1)
{
handler->SendSysMessage("You cannot permanently spawn in the main phase. Use .modify phase $number to spawn your GameObject, or spawn your GameObject temporarily.");
return true;
}
if (handler->GetSession()->GetSecurity() == SEC_MODERATOR && handler->GetSession()->GetPlayer()->GetPhaseMask() == -1)
{
handler->SendSysMessage("You cannot permanently spawn in the main phase. Use .modify phase $number to spawn your GameObject, or spawn your GameObject temporarily.");
return true;
}
char* spawntimeSecs = strtok(NULL, " ");
const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId);
if (!objectInfo)
{
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, objectId);
handler->SetSentErrorMessage(true);
return false;
}
if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
{
// report to DB errors log as in loading case
TC_LOG_ERROR("sql.sql", "Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", objectId, objectInfo->type, objectInfo->displayId);
handler->PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA, objectId);
handler->SetSentErrorMessage(true);
return false;
}
Player* player = handler->GetSession()->GetPlayer();
float x = float(player->GetPositionX());
float y = float(player->GetPositionY());
float z = float(player->GetPositionZ());
float o = float(player->GetOrientation());
Map* map = player->GetMap();
GameObject* object = new GameObject;
uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
if (!object->Create(guidLow, objectInfo->entry, map, player->GetPhaseMaskForSpawn(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
{
delete object;
return false;
}
if (spawntimeSecs)
{
uint32 value = atoi((char*)spawntimeSecs);
object->SetRespawnTime(value);
}
// fill the gameobject data and save to the db
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn());
// delete the old object and do a clean load from DB with a fresh new GameObject instance.
// this is required to avoid weird behavior and memory leaks
delete object;
object = new GameObject();
// this will generate a new guid if the object is in an instance
if (!object->LoadGameObjectFromDB(guidLow, map))
{
delete object;
return false;
}
/// @todo is it really necessary to add both the real and DB table guid here ?
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, objectId, objectInfo->name.c_str(), guidLow, x, y, z);
return true;
}