void PoolGroup<Creature>::Spawn1Object(PoolObject* obj, bool instantly) { if (CreatureData const* data = sObjectMgr.GetCreatureData(obj->guid)) { sObjectMgr.AddCreatureToGrid(obj->guid, data); MapEntry const* mapEntry = sMapStore.LookupEntry(data->mapid); // temporary limit pool system full power work to continents if (mapEntry && !mapEntry->Instanceable()) { // Spawn if necessary (loaded grids only) Map* map = const_cast<Map*>(sMapMgr.FindMap(data->mapid)); // We use spawn coords to spawn if (map && map->IsLoaded(data->posX, data->posY)) { Creature* pCreature = new Creature; //DEBUG_LOG("Spawning creature %u",obj->guid); if (!pCreature->LoadFromDB(obj->guid, map)) { delete pCreature; return; } else { // if new spawn replaces a just despawned creature, not instantly spawn but set respawn timer if(!instantly) { pCreature->SetRespawnTime( pCreature->GetRespawnDelay() ); if (sWorld.getConfig(CONFIG_BOOL_SAVE_RESPAWN_TIME_IMMEDIATLY) || pCreature->IsWorldBoss()) pCreature->SaveRespawnTime(); } map->Add(pCreature); } } // for not loaded grid just update respawn time (avoid work for instances until implemented support) else if(!instantly) { sObjectMgr.SaveCreatureRespawnTime(obj->guid, 0 /*map->GetInstanceId()*/, time(NULL) + data->spawntimesecs); } } } }
void PoolGroup<Creature>::Spawn1Object(MapPersistentState& mapState, PoolObject* obj, bool instantly) { if (CreatureData const* data = sObjectMgr.GetCreatureData(obj->guid)) { MapEntry const* mapEntry = sMapStore.LookupEntry(data->mapid); // for non-instanceable maps pool spawn can be at different map from provided mapState if (MapPersistentState* dataMapState = mapState.GetMapId() == data->mapid ? &mapState : sMapPersistentStateMgr.GetPersistentState(data->mapid, 0)) { dataMapState->AddCreatureToGrid(obj->guid, data); Map* dataMap = dataMapState->GetMap(); // We use spawn coords to spawn if (dataMap && dataMap->IsLoaded(data->posX, data->posY)) { Creature* pCreature = new Creature; //DEBUG_LOG("Spawning creature %u",obj->guid); if (!pCreature->LoadFromDB(obj->guid, dataMap)) { delete pCreature; return; } else { // if new spawn replaces a just despawned creature, not instantly spawn but set respawn timer if(!instantly) { pCreature->SetRespawnTime( pCreature->GetRespawnDelay() ); if (sWorld.getConfig(CONFIG_BOOL_SAVE_RESPAWN_TIME_IMMEDIATELY) || pCreature->IsWorldBoss()) pCreature->SaveRespawnTime(); } dataMap->Add(pCreature); } } // for not loaded grid just update respawn time (avoid work for instances until implemented support) else if(!instantly) { dataMapState->SaveCreatureRespawnTime(obj->guid, time(NULL) + data->spawntimesecs); } } } }
void PoolGroup<GameObject>::Spawn1Object(PoolObject* obj, bool instantly) { if (GameObjectData const* data = sObjectMgr.GetGOData(obj->guid)) { sObjectMgr.AddGameobjectToGrid(obj->guid, data); // Spawn if necessary (loaded grids only) // this base map checked as non-instanced and then only existed Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid)); // We use current coords to unspawn, not spawn coords since creature can have changed grid // (avoid work for instances until implemented support) if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { GameObject* pGameobject = new GameObject; //DEBUG_LOG("Spawning gameobject %u", obj->guid); if (!pGameobject->LoadFromDB(obj->guid, map)) { delete pGameobject; return; } else { if (pGameobject->isSpawnedByDefault()) { // if new spawn replaces a just despawned object, not instantly spawn but set respawn timer if (!instantly) { pGameobject->SetRespawnTime( pGameobject->GetRespawnDelay() ); if (sWorld.getConfig(CONFIG_BOOL_SAVE_RESPAWN_TIME_IMMEDIATLY)) pGameobject->SaveRespawnTime(); } map->Add(pGameobject); } } } // for not loaded grid just update respawn time (avoid work for instances until implemented support) else if (!map->Instanceable() && !instantly) { // for spawned by default object only if (data->spawntimesecs >= 0) sObjectMgr.SaveGORespawnTime(obj->guid,map->GetInstanceId(),time(NULL) + data->spawntimesecs); } } }
const CharInfo& AddCharInfo(wchar_t t) { bUpdated = true; infoByChar.Add(t, (uint32)infos.size()); infos.emplace_back(); CharInfo& ci = infos.back(); FT_Face* pFace = &face; ci.glyphID = FT_Get_Char_Index(*pFace, t); if(ci.glyphID == 0) { pFace = &fallbackFont; ci.glyphID = FT_Get_Char_Index(*pFace, t); } FT_Load_Glyph(*pFace, ci.glyphID, FT_LOAD_DEFAULT); if((*pFace)->glyph->format != FT_GLYPH_FORMAT_BITMAP) { FT_Render_Glyph((*pFace)->glyph, FT_RENDER_MODE_NORMAL); } ci.topOffset = (*pFace)->glyph->bitmap_top; ci.leftOffset = (*pFace)->glyph->bitmap_left; ci.advance = (float)(*pFace)->glyph->advance.x / 64.0f; Image img = ImageRes::Create(Vector2i((*pFace)->glyph->bitmap.width, (*pFace)->glyph->bitmap.rows)); Colori* pDst = img->GetBits(); uint8* pSrc = (*pFace)->glyph->bitmap.buffer; uint32 nLen = (*pFace)->glyph->bitmap.width * (*pFace)->glyph->bitmap.rows; for(uint32 i = 0; i < nLen; i++) { pDst[0].w = pSrc[0]; Reinterpret<VectorBase<uint8, 3>>(pDst[0]) = VectorBase<uint8, 3>(255, 255, 255); pSrc++; pDst++; } uint32 nIndex = spriteMap->AddSegment(img); ci.coords = spriteMap->GetCoords(nIndex); return ci; }
void PoolGroup<GameObject>::Spawn1Object(PoolObject* obj) { if (GameObjectData const* data = sObjectMgr->GetGOData(obj->guid)) { sObjectMgr->AddGameobjectToGrid(obj->guid, data); // Spawn if necessary (loaded grids only) // this base map checked as non-instanced and then only existed Map* map = const_cast<Map*>(sMapMgr->CreateBaseMap(data->mapid)); // We use current coords to unspawn, not spawn coords since creature can have changed grid if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { GameObject* pGameobject = new GameObject; //sLog->outDebug(LOG_FILTER_POOLSYS, "Spawning gameobject %u", guid); if (!pGameobject->LoadFromDB(obj->guid, map)) { delete pGameobject; return; } else { if (pGameobject->isSpawnedByDefault()) map->Add(pGameobject); } } } }
Creature* Transport::AddNPCPassengerInInstance(uint32 entry, float x, float y, float z, float o, uint32 anim) { Map* map = GetMap(); Creature* pCreature = new Creature; if(!pCreature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, GetPhaseMask(), entry, 0, GetGOInfo()->faction, 0, 0, 0, 0)) { delete pCreature; return NULL; } pCreature->SetTransport(this); pCreature->AddUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT); pCreature->m_movementInfo.guid = GetGUID(); pCreature->m_movementInfo.t_pos.Relocate(x, y, z, o); o += GetOrientation(); MapManager::NormalizeOrientation(o); pCreature->Relocate( GetPositionX() + (x * cos(GetOrientation()) + y * sin(GetOrientation() + float(M_PI))), GetPositionY() + (y * cos(GetOrientation()) + x * sin(GetOrientation())), z + GetPositionZ() , o); pCreature->SetHomePosition(pCreature->GetPositionX(), pCreature->GetPositionY(), pCreature->GetPositionZ(), pCreature->GetOrientation()); if(!pCreature->IsPositionValid()) { sLog->outError("Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)", pCreature->GetGUIDLow(), pCreature->GetEntry(), pCreature->GetPositionX(), pCreature->GetPositionY()); delete pCreature; return NULL; } map->Add(pCreature); m_NPCPassengerSet.insert(pCreature); pCreature->setActive(true); sScriptMgr->OnAddCreaturePassenger(this, pCreature); return pCreature; }
FontSize* GetSize(uint32 nSize) { if(m_currentSize != nSize) { FT_Set_Pixel_Sizes(m_face, 0, nSize); m_currentSize = nSize; } if(fallbackFontSize != nSize) { FT_Set_Pixel_Sizes(fallbackFont, 0, nSize); fallbackFontSize = nSize; } auto it = m_sizes.find(nSize); if(it != m_sizes.end()) return it->second; FontSize* pMap = new FontSize(m_gl, m_face); m_sizes.Add(nSize, pMap); return pMap; }
bool PoolGroup<Creature>::Spawn1Object(uint32 guid) { if (CreatureData const* data = objmgr.GetCreatureData(guid)) { objmgr.AddCreatureToGrid(guid, data); // Spawn if necessary (loaded grids only) Map* map = const_cast<Map*>(MapManager::Instance().CreateBaseMap(data->mapid)); // We use spawn coords to spawn if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { Creature* pCreature = new Creature; //sLog.outDebug("Spawning creature %u",guid); if (!pCreature->LoadFromDB(guid, map)) delete pCreature; else map->Add(pCreature); } return true; } return false; }
void PoolGroup<Creature>::Spawn1Object(PoolObject* obj) { if (CreatureData const* data = sObjectMgr->GetCreatureData(obj->guid)) { sObjectMgr->AddCreatureToGrid(obj->guid, data); // Spawn if necessary (loaded grids only) Map* map = const_cast<Map*>(sMapMgr->CreateBaseMap(data->mapid)); // We use spawn coords to spawn if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { Creature* creature = new Creature; //sLog->outDebug("Spawning creature %u",guid); if (!creature->LoadFromDB(obj->guid, map)) { delete creature; return; } else map->Add(creature); } } }
void PoolGroup<Creature>::Spawn1Object(PoolObject* obj, bool instantly) { if (CreatureData const* data = sObjectMgr.GetCreatureData(obj->guid)) { sObjectMgr.AddCreatureToGrid(obj->guid, data); // Spawn if necessary (loaded grids only) Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid)); // We use spawn coords to spawn (avoid work for instances until implemented support) if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { Creature* pCreature = new Creature; //sLog.outDebug("Spawning creature %u",obj->guid); if (!pCreature->LoadFromDB(obj->guid, map)) { delete pCreature; return; } else { // if new spawn replaces a just despawned creature, not instantly spawn but set respawn timer if(!instantly) { pCreature->SetRespawnTime( pCreature->GetRespawnDelay() ); if (sWorld.getConfig(CONFIG_BOOL_SAVE_RESPAWN_TIME_IMMEDIATLY) || pCreature->isWorldBoss()) pCreature->SaveRespawnTime(); } map->Add(pCreature); } } // for not loaded grid just update respawn time (avoid work for instances until implemented support) else if(!map->Instanceable() && !instantly) { sObjectMgr.SaveCreatureRespawnTime(obj->guid,map->GetInstanceId(),time(NULL) + data->spawntimesecs); } } }
int freyja_model__lwo_import(char *filename) { Map<unsigned int, unsigned int> trans; lw_face_t *face; lw_material_t *material; Lwo lwo; float vert[3]; int i, j, v, t; if (lwo.Load(filename)) return -1; freyjaBegin(FREYJA_MODEL); // Start a new mesh freyjaBegin(FREYJA_MESH); // Start a new vertex group freyjaBegin(FREYJA_VERTEX_GROUP); for (i = 0; i < lwo.VertexCount(); i++) { lwo.Vertex(i, vert); // Store vertices in group v = freyjaVertexCreate3f(vert[0], vert[1], vert[2]); #ifdef DEBUG_LWO_VERTS printf("%i = %f %f %f\n", v, vert[0], vert[1], vert[2]); #endif // Generates id translator list trans.Add(i, v); } freyjaEnd(); // FREYJA_GROUP for (i = 0; i < lwo.FaceCount(); i++) { face = lwo.Face(i); if (!face) continue; // Ignore non polygons if (face->index_cnt < 3) continue; // Start a new polygon freyjaBegin(FREYJA_POLYGON); for (j = 0; j < face->index_cnt; j++) { // Store vertices by true id, using translator list freyjaPolygonVertex1i(trans[face->index[j]]); #ifdef DEBUG_LWO_TRANS printf("trans[%i] = %i\n", face->index[j], trans[face->index[j]]); #endif material = lwo.Material(face->material); if (material) { // Generate color by texel hack, store it's index t = freyjaTexCoordCreate2f(material->r, material->g); freyjaPolygonTexCoord1i(t); t = freyjaTexCoordCreate2f(material->b, material->a); freyjaPolygonTexCoord1i(t); } else { t = freyjaTexCoordCreate2f(0.0, 0.0); freyjaPolygonTexCoord1i(t); t = freyjaTexCoordCreate2f(0.0, 0.0); freyjaPolygonTexCoord1i(t); } } freyjaPolygonMaterial1i(0); freyjaEnd(); // FREYJA_POLYGON } freyjaEnd(); // FREYJA_MESH freyjaEnd(); // FREYJA_MODEL return 0; }
bool OutdoorPvPObjective::AddCapturePoint(uint32 entry, uint32 map, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3) { sLog.outDebug("OutdoorPvPObjective: creating capture point %u and capture point creature",entry); // check info existence GameObjectInfo const* goinfo = objmgr.GetGameObjectInfo(entry); if (!goinfo) return false; CreatureInfo const *cinfo = objmgr.GetCreatureTemplate(OPVP_TRIGGER_CREATURE_ENTRY); if(!cinfo) return false; // create capture point creature uint32 displayId = objmgr.ChooseDisplayId(0, cinfo, NULL); uint32 creature_guid = objmgr.GenerateLowGuid(HIGHGUID_UNIT); CreatureData& cdata = objmgr.NewOrExistCreatureData(creature_guid); cdata.id = OPVP_TRIGGER_CREATURE_ENTRY; cdata.mapid = map; cdata.displayid = displayId; cdata.equipmentId = cinfo->equipmentId; cdata.posX = x; cdata.posY = y; cdata.posZ = z; cdata.orientation = o; cdata.spawntimesecs = 1; cdata.spawndist = 0; cdata.currentwaypoint = 0; cdata.curhealth = cinfo->maxhealth; cdata.curmana = cinfo->maxmana; cdata.is_dead = false; cdata.movementType = cinfo->MovementType; cdata.spawnMask = 1; cdata.phaseMask = PHASEMASK_NORMAL; objmgr.AddCreatureToGrid(creature_guid, &cdata); m_CapturePointCreature = MAKE_NEW_GUID(creature_guid, OPVP_TRIGGER_CREATURE_ENTRY, HIGHGUID_UNIT); // create capture point go uint32 guid = objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT); GameObjectData& data = objmgr.NewGOData(guid); data.id = entry; data.mapid = map; data.posX = x; data.posY = y; data.posZ = z; data.orientation = o; data.rotation0 = rotation0; data.rotation1 = rotation1; data.rotation2 = rotation2; data.rotation3 = rotation3; data.spawntimesecs = 1; data.animprogress = 100; data.spawnMask = 1; data.go_state = GO_STATE_READY; data.phaseMask = PHASEMASK_NORMAL; objmgr.AddGameobjectToGrid(guid, &data); m_CapturePoint = MAKE_NEW_GUID(guid, entry, HIGHGUID_GAMEOBJECT); // get the needed values from goinfo m_ShiftMaxPhase = goinfo->raw.data[17]; m_ShiftMaxCaptureSpeed = m_ShiftMaxPhase / float(goinfo->raw.data[16]); m_NeutralValue = goinfo->raw.data[12]; // add to map if map is already loaded Map * pMap = MapManager::Instance().FindMap(map); if(!pMap) return true; // add GO... GameObject * go = new GameObject; if(!go->Create(guid,entry, pMap, PHASEMASK_NORMAL, x,y,z,o,rotation0,rotation1,rotation2,rotation3,100, GO_STATE_READY)) { sLog.outError("OutdoorPvPObjective: Gameobject template %u not found in database.", entry); delete go; } else { go->SetRespawnTime(0); objmgr.SaveGORespawnTime(go->GetDBTableGUIDLow(), 0, 0); //this is useless this isn't spawned through db so it doesn't has dbtableguid (it's just 0) pMap->Add(go); } // add creature... Creature* pCreature = new Creature; if (!pCreature->Create(creature_guid, pMap,PHASEMASK_NORMAL, OPVP_TRIGGER_CREATURE_ENTRY, 0)) { sLog.outError("OutdoorPvPObjective: Can't create creature entry: %u",entry); delete pCreature; } else { pCreature->AIM_Initialize(); pCreature->Relocate(x, y, z, o); if(!pCreature->IsPositionValid()) { sLog.outError("OutdoorPvPObjective: Creature (guidlow %d, entry %d) not added to opvp. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY()); return false; } pMap->Add(pCreature); } return true; }
void XmlMapHandler::ReadLayer(wxXmlNode* root, Map& map) { VerboseLog("Reading a Layer"); wxXmlNode* child = root->GetChildren(); std::string name; uint32_t width; uint32_t height; DrawAttributes attr; std::vector<int32_t> data; while (child) { std::string property = child->GetName().ToStdString(); std::string content = child->GetNodeContent().ToStdString(); VerboseLog("%s Got node %s content %s", __func__, property.c_str(), content.c_str()); Scanner scanner(content); if (property == "Name") { name = content; } else if (property == "Dimensions") { if (!scanner.Next(width)) throw "Could not parse width"; if (!scanner.Next(height)) throw "Could not parse height"; } else if (property == "Data") { while (scanner.HasMoreTokens()) { int32_t element; if (!scanner.Next(element)) throw "Could not parse data"; data.push_back(element); } } else if (property == "Position") { int32_t x, y; if (!scanner.Next(x)) throw "Could not parse position"; if (!scanner.Next(y)) throw "Could not parse position"; attr.SetPosition(x, y); } else if (property == "Origin") { int32_t x, y; if (!scanner.Next(x)) throw "Could not parse origin"; if (!scanner.Next(y)) throw "Could not parse origin"; attr.SetOrigin(x, y); } else if (property == "Scale") { float x, y; if (!scanner.Next(x)) throw "Could not parse scale"; if (!scanner.Next(y)) throw "Could not parse scale"; attr.SetScale(x, y); } else if (property == "Rotation") { float rotation; if (!scanner.Next(rotation)) throw "Could not parse rotation"; attr.SetRotation(rotation); } else if (property == "Opacity") { float opacity; if (!scanner.Next(opacity)) throw "Could not parse opacity"; attr.SetOpacity(opacity); } else if (property == "BlendMode") { uint32_t mode; if (!scanner.Next(mode)) throw "Could not parse blend mode"; attr.SetBlendMode(mode); } else if (property == "BlendColor") { uint32_t color; if (!scanner.Next(color, 16)) throw "Could not parse blend color"; attr.SetBlendColor(color); } else if (property == "Priority") { int32_t priority; if (!scanner.Next(priority)) throw "Could not parser priority"; attr.SetDepth(priority); } else { throw "Unexpected token " + property; } child = child->GetNext(); } if (data.size() != width * height) throw "Incorrect number of tile entries for layer"; map.Add(Layer(name, width, height, data, attr)); VerboseLog("Done Reading Layer"); }
static bool HandleWpShowCommand(ChatHandler* handler, const char* args) { if (!*args) return false; // first arg: on, off, first, last char* show_str = strtok((char*) args, " "); if (!show_str) return false; // second arg: GUID (optional, if a creature is selected) char* guid_str = strtok((char*) NULL, " "); uint32 pathid = 0; Creature* target = handler->getSelectedCreature(); // Did player provide a PathID? if (!guid_str) { // No PathID provided // -> Player must have selected a creature if (!target) { handler->SendSysMessage(LANG_SELECT_CREATURE); handler->SetSentErrorMessage(true); return false; } pathid = target->GetWaypointPath(); } else { // PathID provided // Warn if player also selected a creature // -> Creature selection is ignored <- if (target) handler->SendSysMessage(LANG_WAYPOINT_CREATSELECTED); pathid = atoi((char*) guid_str); } std::string show = show_str; uint32 Maxpoint; //handler->PSendSysMessage("wpshow - show: %s", show); // Show info for the selected waypoint if (show == "info") { // Check if the user did specify a visual waypoint if (target->GetEntry() != VISUAL_WAYPOINT) { handler->PSendSysMessage(LANG_WAYPOINT_VP_SELECT); handler->SetSentErrorMessage(true); return false; } QueryResult result = WorldDatabase.PQuery( "SELECT id, point, delay, move_flag, action, action_chance FROM waypoint_data WHERE wpguid = %u", target->GetGUIDLow()); if (!result) { handler->SendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM); return true; } handler->SendSysMessage("|cff00ffffDEBUG: wp show info:|r"); do { Field *fields = result->Fetch(); pathid = fields[0].GetUInt32(); uint32 point = fields[1].GetUInt32(); uint32 delay = fields[2].GetUInt32(); uint32 flag = fields[3].GetUInt32(); uint32 ev_id = fields[4].GetUInt32(); uint32 ev_chance = fields[5].GetUInt32(); handler->PSendSysMessage( "|cff00ff00Show info: for current point: |r|cff00ffff%u|r|cff00ff00, Path ID: |r|cff00ffff%u|r", point, pathid); handler->PSendSysMessage( "|cff00ff00Show info: delay: |r|cff00ffff%u|r", delay); handler->PSendSysMessage( "|cff00ff00Show info: Move flag: |r|cff00ffff%u|r", flag); handler->PSendSysMessage( "|cff00ff00Show info: Waypoint event: |r|cff00ffff%u|r", ev_id); handler->PSendSysMessage( "|cff00ff00Show info: Event chance: |r|cff00ffff%u|r", ev_chance); } while (result->NextRow()); return true; } if (show == "on") { QueryResult result = WorldDatabase.PQuery( "SELECT point, position_x, position_y, position_z FROM waypoint_data WHERE id = '%u'", pathid); if (!result) { handler->SendSysMessage("|cffff33ffPath no found.|r"); handler->SetSentErrorMessage(true); return false; } handler->PSendSysMessage( "|cff00ff00DEBUG: wp on, PathID: |cff00ffff%u|r", pathid); // Delete all visuals for this NPC QueryResult result2 = WorldDatabase.PQuery( "SELECT wpguid FROM waypoint_data WHERE id = '%u' and wpguid <> 0", pathid); if (result2) { bool hasError = false; do { Field *fields = result2->Fetch(); uint32 wpguid = fields[0].GetUInt32(); Creature* pCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature( MAKE_NEW_GUID(wpguid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); if (!pCreature) { handler->PSendSysMessage(LANG_WAYPOINT_NOTREMOVED, wpguid); hasError = true; WorldDatabase.PExecute( "DELETE FROM creature WHERE guid = '%u'", wpguid); } else { pCreature->CombatStop(); pCreature->DeleteFromDB(); pCreature->AddObjectToRemoveList(); } } while (result2->NextRow()); if (hasError) { handler->PSendSysMessage(LANG_WAYPOINT_TOOFAR1); handler->PSendSysMessage(LANG_WAYPOINT_TOOFAR2); handler->PSendSysMessage(LANG_WAYPOINT_TOOFAR3); } } 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 WorldDatabase.PExecute( "UPDATE waypoint_data SET wpguid = '%u' WHERE id = '%u' and point = '%u'", wpCreature->GetGUIDLow(), pathid, point); wpCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn()); // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells(); wpCreature->LoadFromDB(wpCreature->GetDBTableGUIDLow(), map); map->Add(wpCreature); if (target) { wpCreature->SetDisplayId(target->GetDisplayId()); wpCreature->SetFloatValue(OBJECT_FIELD_SCALE_X, 0.5); 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; } Field *fields = result->Fetch(); float x = fields[0].GetFloat(); float y = fields[1].GetFloat(); float z = fields[2].GetFloat(); uint32 id = VISUAL_WAYPOINT; Player *chr = handler->GetSession()->GetPlayer(); float o = chr->GetOrientation(); Map *map = chr->GetMap(); Creature* pCreature = new Creature; if (!pCreature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map,chr->GetPhaseMaskForSpawn(), id, 0, 0, x, y, z, o)) { handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id); delete pCreature; return false; } pCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn()); pCreature->LoadFromDB(pCreature->GetDBTableGUIDLow(), map); map->Add(pCreature); if (target) { pCreature->SetDisplayId(target->GetDisplayId()); pCreature->SetFloatValue(OBJECT_FIELD_SCALE_X, 0.5); } return true; } if (show == "last") { handler->PSendSysMessage( "|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff%u|r", pathid); QueryResult result = WorldDatabase.PQuery( "SELECT MAX(point) FROM waypoint_data WHERE id = '%u'", pathid); if (result) Maxpoint = (*result)[0].GetUInt32(); else Maxpoint = 0; result = WorldDatabase.PQuery( "SELECT position_x, position_y, position_z FROM waypoint_data WHERE point ='%u' AND id = '%u'", Maxpoint, pathid); if (!result) { handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDLAST, pathid); handler->SetSentErrorMessage(true); return false; } Field *fields = result->Fetch(); float x = fields[0].GetFloat(); float y = fields[1].GetFloat(); float z = fields[2].GetFloat(); uint32 id = VISUAL_WAYPOINT; Player *chr = handler->GetSession()->GetPlayer(); float o = chr->GetOrientation(); Map *map = chr->GetMap(); Creature* pCreature = new Creature; if (!pCreature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map,chr->GetPhaseMaskForSpawn(), id, 0, 0, x, y, z, o)) { handler->PSendSysMessage(LANG_WAYPOINT_NOTCREATED, id); delete pCreature; return false; } pCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn()); pCreature->LoadFromDB(pCreature->GetDBTableGUIDLow(), map); map->Add(pCreature); if (target) { pCreature->SetDisplayId(target->GetDisplayId()); pCreature->SetFloatValue(OBJECT_FIELD_SCALE_X, 0.5); } return true; } if (show == "off") { QueryResult result = WorldDatabase.PQuery( "SELECT guid FROM creature WHERE id = '%u'", 1); if (!result) { handler->SendSysMessage(LANG_WAYPOINT_VP_NOTFOUND); handler->SetSentErrorMessage(true); return false; } bool hasError = false; do { Field *fields = result->Fetch(); uint32 guid = fields[0].GetUInt32(); Creature* pCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature( MAKE_NEW_GUID(guid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); if (!pCreature) { handler->PSendSysMessage(LANG_WAYPOINT_NOTREMOVED, guid); hasError = true; WorldDatabase.PExecute( "DELETE FROM creature WHERE guid = '%u'", guid); } else { pCreature->CombatStop(); pCreature->DeleteFromDB(); pCreature->AddObjectToRemoveList(); } } while (result->NextRow()); // set "wpguid" column to "empty" - no visual waypoint spawned WorldDatabase.PExecute("UPDATE waypoint_data SET wpguid = '0'"); //WorldDatabase.PExecute("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'"); if (hasError) { handler->PSendSysMessage(LANG_WAYPOINT_TOOFAR1); handler->PSendSysMessage(LANG_WAYPOINT_TOOFAR2); handler->PSendSysMessage(LANG_WAYPOINT_TOOFAR3); } handler->SendSysMessage(LANG_WAYPOINT_VP_ALLREMOVED); return true; } handler->PSendSysMessage( "|cffff33ffDEBUG: wpshow - no valid command found|r"); return true; }
void LfgGroup::TeleportPlayer(Player *plr, DungeonInfo *dungeonInfo, uint32 originalDungeonId, bool newPlr) { if(newPlr) { plr->m_lookingForGroup.queuedDungeons.clear(); // must be before remove grom group if (Group *group = plr->GetGroup()) { if (!group->isLfgGroup()) { group->RemoveMember(plr->GetGUID(), 0); if (group->GetMembersCount() == 0) group->Disband(true); } plr->SetGroup(NULL); } plr->UnbindInstance(dungeonInfo->start_map, m_dungeonInfo->isHeroic() ? DUNGEON_DIFFICULTY_HEROIC : DUNGEON_DIFFICULTY_NORMAL); plr->ResetInstances(INSTANCE_RESET_GROUP_JOIN,false); plr->ResetInstances(INSTANCE_RESET_GROUP_JOIN,true); plr->ResetInstances(INSTANCE_RESET_ALL, true); plr->ResetInstances(INSTANCE_RESET_ALL, false); if (plr->getLevel() >= LEVELREQUIREMENT_HEROIC) { if (plr->GetDungeonDifficulty() != GetDungeonDifficulty()) plr->SetDungeonDifficulty(GetDungeonDifficulty()); if (plr->GetRaidDifficulty() != GetRaidDifficulty()) plr->SetRaidDifficulty(GetRaidDifficulty()); } plr->SetGroup(this, 0); plr->SetGroupInvite(NULL); uint32 taxi_start = 0; uint32 taxi_end = 0; uint32 mount_spell = 0; WorldLocation joinLoc; if (!plr->m_taxi.empty()) { taxi_start = plr->m_taxi.GetTaxiSource(); taxi_end = plr->m_taxi.GetTaxiDestination(); joinLoc = WorldLocation(plr->GetMapId(), plr->GetPositionX(), plr->GetPositionY(), plr->GetPositionZ(), plr->GetOrientation()); } else { // Mount spell id storing if (plr->IsMounted()) { Unit::AuraList const& auras = plr->GetAurasByType(SPELL_AURA_MOUNTED); if (!auras.empty()) mount_spell = (*auras.begin())->GetId(); } if(!mount_spell && plr->getClass() == CLASS_DRUID) { Unit::AuraList const& auras = plr->GetAurasByType(SPELL_AURA_MOD_SHAPESHIFT); if (!auras.empty()) mount_spell = (*auras.begin())->GetId(); } //Nearest graveyard if in dungeon if (plr->GetMap()->IsDungeon()) { if (const WorldSafeLocsEntry* entry = sObjectMgr.GetClosestGraveYard(plr->GetPositionX(), plr->GetPositionY(), plr->GetPositionZ(), plr->GetMapId(), plr->GetTeam())) joinLoc = WorldLocation(entry->map_id, entry->x, entry->y, entry->z, 0.f); else joinLoc = plr->GetLocation(); } else joinLoc = plr->GetLocation(); } CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid='%u'", GUID_LOPART(plr->GetGUID())); CharacterDatabase.PExecute("INSERT INTO group_member(groupId,memberGuid,assistant,subgroup,lfg_join_x,lfg_join_y,lfg_join_z,lfg_join_o,lfg_join_map,taxi_start,taxi_end,mount_spell) " "VALUES('%u','%u','%u','%u','%f','%f','%f','%f','%u','%u','%u','%u')", m_Id, GUID_LOPART(plr->GetGUID()), 0, 1, joinLoc.x(), joinLoc.y(), joinLoc.z(), joinLoc.orientation, joinLoc.mapid, taxi_start, taxi_end, mount_spell); //Set info to player plr->m_lookingForGroup.joinLoc = joinLoc; plr->m_lookingForGroup.taxi_start = taxi_start; plr->m_lookingForGroup.taxi_end = taxi_end; plr->m_lookingForGroup.mount_spell = mount_spell; plr->m_lookingForGroup.roles = GetPlayerRole(plr->GetGUID()); if (IsRandom()) plr->CastSpell(plr, LFG_RANDOM_COOLDOWN, true); } // resurrect the player if (!plr->isAlive()) { plr->ResurrectPlayer(1.0f); plr->SpawnCorpseBones(); } // stop taxi flight at port if (plr->isInFlight()) { plr->GetMotionMaster()->MovementExpired(false); plr->GetMotionMaster()->Clear(false, true); plr->GetMotionMaster()->MoveIdle(); plr->m_taxi.ClearTaxiDestinations(); } plr->ScheduleDelayedOperation(DELAYED_LFG_ENTER_DUNGEON); plr->ScheduleDelayedOperation(DELAYED_SAVE_PLAYER); plr->ScheduleDelayedOperation(DELAYED_LFG_CLEAR_LOCKS); if(IsMixed()) { plr->m_lookingForGroup.SetMixedDungeon(dungeonInfo->start_map); if(newPlr) plr->setFaction(sWorld.getConfig(CONFIG_UINT32_TEAM_BG_FACTION_BLUE)); } if (IsInDungeon()) { if(newPlr) { for (GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next()) { Player *player = itr->getSource(); if (!player || player->GetMapId() != GetDungeonInfo()->map) continue; plr->TeleportTo(player->GetLocation()); return; } } plr->TeleportTo(dungeonInfo->start_map, dungeonInfo->start_x, dungeonInfo->start_y, dungeonInfo->start_z, dungeonInfo->start_o); return; } //Must re-add player to reset id... Map *map = plr->GetMap(); if(map->GetId() == dungeonInfo->start_map) { map->Remove(plr, false); map->Add(plr); } plr->TeleportTo(dungeonInfo->start_map, dungeonInfo->start_x, dungeonInfo->start_y, dungeonInfo->start_z, dungeonInfo->start_o); }
void GameEventMgr::GameEventSpawn(int16 event_id) { int32 internal_event_id = mGameEvent.size() + event_id - 1; if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventCreatureGuids.size()) { sLog.outError("GameEventMgr::GameEventSpawn attempt access to out of range mGameEventCreatureGuids element %i (size: " SIZEFMTD ")",internal_event_id,mGameEventCreatureGuids.size()); return; } for (GuidList::iterator itr = mGameEventCreatureGuids[internal_event_id].begin();itr != mGameEventCreatureGuids[internal_event_id].end();++itr) { // Add to correct cell CreatureData const* data = sObjectMgr.GetCreatureData(*itr); if (data) { // negative event id for pool element meaning allow be used in next pool spawn if (event_id < 0) { if (uint16 pool_id = sPoolMgr.IsPartOfAPool<Creature>(*itr)) { // will have chance at next pool update sPoolMgr.SetExcludeObject<Creature>(pool_id, *itr, false); sPoolMgr.UpdatePool<Creature>(pool_id); continue; } } sObjectMgr.AddCreatureToGrid(*itr, data); // Spawn if necessary (loaded grids only) Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid)); // We use spawn coords to spawn if(!map->Instanceable() && map->IsLoaded(data->posX,data->posY)) { Creature* pCreature = new Creature; //DEBUG_LOG("Spawning creature %u",*itr); if (!pCreature->LoadFromDB(*itr, map)) { delete pCreature; } else { map->Add(pCreature); } } } } if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventGameobjectGuids.size()) { sLog.outError("GameEventMgr::GameEventSpawn attempt access to out of range mGameEventGameobjectGuids element %i (size: " SIZEFMTD ")",internal_event_id,mGameEventGameobjectGuids.size()); return; } for (GuidList::iterator itr = mGameEventGameobjectGuids[internal_event_id].begin();itr != mGameEventGameobjectGuids[internal_event_id].end();++itr) { // Add to correct cell GameObjectData const* data = sObjectMgr.GetGOData(*itr); if (data) { // negative event id for pool element meaning allow be used in next pool spawn if (event_id < 0) { if (uint16 pool_id = sPoolMgr.IsPartOfAPool<GameObject>(*itr)) { // will have chance at next pool update sPoolMgr.SetExcludeObject<GameObject>(pool_id, *itr, false); sPoolMgr.UpdatePool<GameObject>(pool_id); continue; } } sObjectMgr.AddGameobjectToGrid(*itr, data); // Spawn if necessary (loaded grids only) // this base map checked as non-instanced and then only existing Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid)); // We use current coords to unspawn, not spawn coords since creature can have changed grid if(!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { GameObject* pGameobject = new GameObject; //DEBUG_LOG("Spawning gameobject %u", *itr); if (!pGameobject->LoadFromDB(*itr, map)) { delete pGameobject; } else { if(pGameobject->isSpawnedByDefault()) map->Add(pGameobject); } } } } if (event_id > 0) { if((size_t)event_id >= mGameEventSpawnPoolIds.size()) { sLog.outError("GameEventMgr::GameEventSpawn attempt access to out of range mGameEventSpawnPoolIds element %i (size: " SIZEFMTD ")", event_id, mGameEventSpawnPoolIds.size()); return; } for (IdList::iterator itr = mGameEventSpawnPoolIds[event_id].begin();itr != mGameEventSpawnPoolIds[event_id].end();++itr) sPoolMgr.SpawnPool(*itr, true); } }
void XmlMapHandler::ReadBackground(wxXmlNode* root, Map& map) { VerboseLog("Reading a background"); wxXmlNode* child = root->GetChildren(); std::string name; std::string filename; int32_t mode; int32_t speedx = 0, speedy = 0; DrawAttributes attr; while (child) { std::string property = child->GetName().ToStdString(); std::string content = child->GetNodeContent().ToStdString(); VerboseLog("%s Got node %s content %s", __func__, property.c_str(), content.c_str()); Scanner scanner(content); if (property == "Name") { name = content; } else if (property == "Filename") { filename = content; } else if (property == "Mode") { if (!scanner.Next(mode)) throw "Could not parse mode"; } else if (property == "Speed") { if (!scanner.Next(speedx)) throw "Could not parse speed"; if (!scanner.Next(speedy)) throw "Could not parse speed"; } else if (property == "Position") { int32_t x, y; if (!scanner.Next(x)) throw "Could not parse position"; if (!scanner.Next(y)) throw "Could not parse position"; attr.SetPosition(x, y); } else if (property == "Origin") { int32_t x, y; if (!scanner.Next(x)) throw "Could not parse origin"; if (!scanner.Next(y)) throw "Could not parse origin"; attr.SetOrigin(x, y); } else if (property == "Scale") { float x, y; if (!scanner.Next(x)) throw "Could not parse scale"; if (!scanner.Next(y)) throw "Could not parse scale"; attr.SetScale(x, y); } else if (property == "Rotation") { float rotation; if (!scanner.Next(rotation)) throw "Could not parse rotation"; attr.SetRotation(rotation); } else if (property == "Opacity") { float opacity; if (!scanner.Next(opacity)) throw "Could not parse opacity"; attr.SetOpacity(opacity); } else if (property == "BlendMode") { uint32_t mode; if (!scanner.Next(mode)) throw "Could not parse blend mode"; attr.SetBlendMode(mode); } else if (property == "BlendColor") { uint32_t color; if (!scanner.Next(color, 16)) throw "Could not parse blend color"; attr.SetBlendColor(color); } else if (property == "Priority") { int32_t priority; if (!scanner.Next(priority)) throw "Could not parser priority"; attr.SetDepth(priority); } else { throw "Unexpected token " + property; } child = child->GetNext(); } map.Add(Background(name, filename, mode, speedx, speedy, attr)); VerboseLog("Done Reading a Background"); }
bool OutdoorPvPSI::HandleDropFlag(Player *plr, uint32 spellId) { if (spellId == SI_SILITHYST_FLAG) { // if it was dropped away from the player's turn-in point, then create a silithyst mound, if it was dropped near the areatrigger, then it was dispelled by the outdoorpvp, so do nothing switch (plr->GetTeam()) { case ALLIANCE: { AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(SI_AREATRIGGER_A); if (atEntry) { // 5.0f is safe-distance if (plr->GetDistance(atEntry->x,atEntry->y,atEntry->z) > 5.0f + atEntry->radius) { // he dropped it further, summon mound GameObject * go = new GameObject; Map * map = plr->GetMap(); if (!map) { delete go; return true; } if (!go->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT),SI_SILITHYST_MOUND, map,plr->GetPositionX(),plr->GetPositionY(),plr->GetPositionZ(),plr->GetOrientation(),0,0,0,0,100,GO_STATE_READY)) { delete go; } else { go->SetRespawnTime(0); map->Add(go); } } } } break; case HORDE: { AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(SI_AREATRIGGER_H); if (atEntry) { WorldLocation tmpWLoc(plr->GetMapId(), atEntry->x, atEntry->y, atEntry->z); // 5.0f is safe-distance if (!plr->IsWithinDistInMap(&tmpWLoc, 5.0f + atEntry->radius)) { // he dropped it further, summon mound GameObject * go = new GameObject; Map * map = plr->GetMap(); if (!map) { delete go; return true; } if (!go->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT),SI_SILITHYST_MOUND, map ,plr->GetPositionX(),plr->GetPositionY(),plr->GetPositionZ(),plr->GetOrientation(),0,0,0,0,100,GO_STATE_READY)) { delete go; } else { go->SetRespawnTime(0); map->Add(go); } } } } break; } return true; } return false; }
static bool HandleWpModifyCommand(ChatHandler* handler, const char* args) { if (!*args) return false; // first arg: add del text emote spell waittime move char* show_str = strtok((char*) args, " "); if (!show_str) { return false; } std::string show = show_str; // Check // Remember: "show" must also be the name of a column! if ((show != "delay") && (show != "action") && (show != "action_chance") && (show != "move_flag") && (show != "del") && (show != "move") && (show != "wpadd")) { return false; } // Next arg is: <PATHID> <WPNUM> <ARGUMENT> char* arg_str = NULL; // Did user provide a GUID // or did the user select a creature? // -> variable lowguid is filled with the GUID of the NPC uint32 pathid = 0; uint32 point = 0; uint32 wpGuid = 0; Creature* target = handler->getSelectedCreature(); if (!target || target->GetEntry() != VISUAL_WAYPOINT) { handler->SendSysMessage( "|cffff33ffERROR: You must select a waypoint.|r"); return false; } // The visual waypoint Creature* wpCreature = NULL; wpGuid = target->GetGUIDLow(); // Did the user select a visual spawnpoint? if (wpGuid) wpCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature( MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT)); // attempt check creature existence by DB data else { handler->PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, wpGuid); return false; } // User did select a visual waypoint? // Check the creature if (wpCreature->GetEntry() == VISUAL_WAYPOINT) { QueryResult result = WorldDatabase.PQuery( "SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid); if (!result) { handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH, target->GetGUIDLow()); // Select waypoint number from database // Since we compare float values, we have to deal with // some difficulties. // Here we search for all waypoints that only differ in one from 1 thousand // (0.001) - There is no other way to compare C++ floats with mySQL floats // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html const char* maxDIFF = "0.01"; result = WorldDatabase.PQuery( "SELECT id, point FROM waypoint_data WHERE (abs(position_x - %f) <= %s) and (abs(position_y - %f) <= %s) and (abs(position_z - %f) <= %s)", wpCreature->GetPositionX(), maxDIFF, wpCreature->GetPositionY(), maxDIFF, wpCreature->GetPositionZ(), maxDIFF); if (!result) { handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, wpGuid); return true; } } do { Field *fields = result->Fetch(); pathid = fields[0].GetUInt32(); point = fields[1].GetUInt32(); } while (result->NextRow()); // We have the waypoint number and the GUID of the "master npc" // Text is enclosed in "<>", all other arguments not arg_str = strtok((char*) NULL, " "); } // Check for argument if (show != "del" && show != "move" && arg_str == NULL) { handler->PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show_str); return false; } if (show == "del" && target) { handler->PSendSysMessage( "|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid); // wpCreature 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(); } WorldDatabase.PExecute( "DELETE FROM waypoint_data WHERE id='%u' AND point='%u'", pathid, point); WorldDatabase.PExecute( "UPDATE waypoint_data SET point=point-1 WHERE id='%u' AND point>'%u'", pathid, point); 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(); wpCreature2->LoadFromDB(wpCreature2->GetDBTableGUIDLow(), map); map->Add(wpCreature2); //sMapMgr->GetMap(npcCreature->GetMapId())->Add(wpCreature2); } WorldDatabase.PExecute( "UPDATE waypoint_data SET position_x = '%f', position_y = '%f', position_z = '%f' where id = '%u' AND point='%u'", chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), pathid, point); 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); } 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); } handler->PSendSysMessage(LANG_WAYPOINT_CHANGED_NO, show_str); return true; }
void WorldSession::HandleMoveWorldportAckOpcode() { // ignore unexpected far teleports if (!GetPlayer()->IsBeingTeleportedFar()) return; // get start teleport coordinates (will used later in fail case) WorldLocation old_loc; GetPlayer()->GetPosition(old_loc); // get the teleport destination WorldLocation& loc = GetPlayer()->GetTeleportDest(); // possible errors in the coordinate validity check (only cheating case possible) if (!MapManager::IsValidMapCoord(loc.mapid, loc.coord_x, loc.coord_y, loc.coord_z, loc.orientation)) { sLog.outError("WorldSession::HandleMoveWorldportAckOpcode: %s was teleported far to a not valid location " "(map:%u, x:%f, y:%f, z:%f) We port him to his homebind instead..", GetPlayer()->GetGuidStr().c_str(), loc.mapid, loc.coord_x, loc.coord_y, loc.coord_z); // stop teleportation else we would try this again and again in LogoutPlayer... GetPlayer()->SetSemaphoreTeleportFar(false); // and teleport the player to a valid place GetPlayer()->TeleportToHomebind(); return; } // get the destination map entry, not the current one, this will fix homebind and reset greeting MapEntry const* mEntry = sMapStore.LookupEntry(loc.mapid); Map* pMap = nullptr; // prevent crash at attempt landing to not existed battleground instance if (mEntry->IsBattleGround()) { if (GetPlayer()->GetBattleGroundId()) pMap = sMapMgr.FindMap(loc.mapid, GetPlayer()->GetBattleGroundId()); if (!pMap) { DETAIL_LOG("WorldSession::HandleMoveWorldportAckOpcode: %s was teleported far to nonexisten battleground instance " " (map:%u, x:%f, y:%f, z:%f) Trying to port him to his previous place..", GetPlayer()->GetGuidStr().c_str(), loc.mapid, loc.coord_x, loc.coord_y, loc.coord_z); GetPlayer()->SetSemaphoreTeleportFar(false); // Teleport to previous place, if cannot be ported back TP to homebind place if (!GetPlayer()->TeleportTo(old_loc)) { DETAIL_LOG("WorldSession::HandleMoveWorldportAckOpcode: %s cannot be ported to his previous place, teleporting him to his homebind place...", GetPlayer()->GetGuidStr().c_str()); GetPlayer()->TeleportToHomebind(); } return; } } InstanceTemplate const* mInstance = ObjectMgr::GetInstanceTemplate(loc.mapid); // reset instance validity, except if going to an instance inside an instance if (GetPlayer()->m_InstanceValid == false && !mInstance) GetPlayer()->m_InstanceValid = true; GetPlayer()->SetSemaphoreTeleportFar(false); // relocate the player to the teleport destination if (!pMap) pMap = sMapMgr.CreateMap(loc.mapid, GetPlayer()); GetPlayer()->SetMap(pMap); GetPlayer()->Relocate(loc.coord_x, loc.coord_y, loc.coord_z, loc.orientation); GetPlayer()->SendInitialPacketsBeforeAddToMap(); // the CanEnter checks are done in TeleporTo but conditions may change // while the player is in transit, for example the map may get full if (!pMap->Add(GetPlayer())) { // if player wasn't added to map, reset his map pointer! GetPlayer()->ResetMap(); DETAIL_LOG("WorldSession::HandleMoveWorldportAckOpcode: %s was teleported far but couldn't be added to map " " (map:%u, x:%f, y:%f, z:%f) Trying to port him to his previous place..", GetPlayer()->GetGuidStr().c_str(), loc.mapid, loc.coord_x, loc.coord_y, loc.coord_z); // Teleport to previous place, if cannot be ported back TP to homebind place if (!GetPlayer()->TeleportTo(old_loc)) { DETAIL_LOG("WorldSession::HandleMoveWorldportAckOpcode: %s cannot be ported to his previous place, teleporting him to his homebind place...", GetPlayer()->GetGuidStr().c_str()); GetPlayer()->TeleportToHomebind(); } return; } // battleground state prepare (in case join to BG), at relogin/tele player not invited // only add to bg group and object, if the player was invited (else he entered through command) if (_player->InBattleGround()) { // cleanup seting if outdated if (!mEntry->IsBattleGround()) { // We're not in BG _player->SetBattleGroundId(0, BATTLEGROUND_TYPE_NONE); // reset destination bg team _player->SetBGTeam(TEAM_NONE); } // join to bg case else if (BattleGround* bg = _player->GetBattleGround()) { if (_player->IsInvitedForBattleGroundInstance(_player->GetBattleGroundId())) bg->AddPlayer(_player); } } GetPlayer()->SendInitialPacketsAfterAddToMap(); // flight fast teleport case if (GetPlayer()->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE) { if (!_player->InBattleGround()) { // short preparations to continue flight FlightPathMovementGenerator* flight = (FlightPathMovementGenerator*)(GetPlayer()->GetMotionMaster()->top()); flight->Reset(*GetPlayer()); return; } // battleground state prepare, stop flight GetPlayer()->GetMotionMaster()->MovementExpired(); GetPlayer()->m_taxi.ClearTaxiDestinations(); } if (mEntry->IsRaid() && mInstance) { if (time_t timeReset = sMapPersistentStateMgr.GetScheduler().GetResetTimeFor(mEntry->MapID)) { uint32 timeleft = uint32(timeReset - time(nullptr)); GetPlayer()->SendInstanceResetWarning(mEntry->MapID, timeleft); } } // mount allow check if (!pMap->IsMountAllowed()) _player->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED); // honorless target if (GetPlayer()->pvpInfo.inPvPEnforcedArea) GetPlayer()->CastSpell(GetPlayer(), 2479, TRIGGERED_OLD_TRIGGERED); // resummon pet GetPlayer()->ResummonPetTemporaryUnSummonedIfAny(); // lets process all delayed operations on successful teleport GetPlayer()->ProcessDelayedOperations(); // notify group after successful teleport if (_player->GetGroup()) _player->SetGroupUpdateFlag(GROUP_UPDATE_FULL); }
void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder) { sLog.outDebug( "WORLD: HandlePlayerLogin" ); uint64 playerGuid = holder->GetGuid(); Player* pCurrChar = new Player(this); //pCurrChar->GetMotionMaster()->Initialize(); if(!pCurrChar->LoadFromDB(GUID_LOPART(playerGuid), holder)) { delete pCurrChar; // delete it manually delete holder; // delete all unprocessed queries m_playerLoading = false; return; } else SetPlayer(pCurrChar); sLog.outDebug("** Adding player %s to Map.", pCurrChar->GetName()); pCurrChar->SendInitialPacketsBeforeAddToMap(); Map* map = MapManager::Instance().GetMap(pCurrChar->GetMapId(), pCurrChar); map->Add(pCurrChar); ObjectAccessor::Instance().AddObject(pCurrChar); pCurrChar->SendInitialPacketsAfterAddToMap(); CharacterDatabase.PExecute("UPDATE characters SET online = 1 WHERE guid = '%u'", pCurrChar->GetGUIDLow()); std::string IP_str = _socket ? _socket->GetRemoteAddress().c_str() : "-"; sLog.outString("** Account: %d (IP: %s) Login Character:[%s] (guid:%u)", GetAccountId(), IP_str.c_str(), pCurrChar->GetName(), pCurrChar->GetGUID()); // pCurrChar->SetInGameTime( getMSTime() ); // sLog.outString("Map '%u' has '%u' Players", pCurrChar->GetMapId(), map->GetPlayersCount()); // Send MOTD { uint32 linecount = 0; std::string str_motd = sWorld.GetMotd(); std::string::size_type pos, nextpos; pos = 0; while( (nextpos = str_motd.find('$',pos)) != std::string::npos ) { if( nextpos != pos ) { ChatHandler(this).SendSysMessage(str_motd.substr(pos,nextpos-pos).c_str()); linecount++; } pos = nextpos+1; } if( pos < str_motd.length() ) { ChatHandler(this).SendSysMessage(str_motd.substr(pos).c_str()); linecount++; } DEBUG_LOG( "WORLD: Sent motd(SMSG_MOTD)" ); } sWorld.UpdateOnlinePlayersFor(pCurrChar); m_playerLoading = false; delete holder; }
void mgtk_tree_set_treeview(int event, GtkTreeView *tree) { gTreeWidgetMap.Add(event, tree); }
//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; }
bool OPvPCapturePoint::AddObject(uint32 type, uint32 entry, uint32 mapId, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3) { GameObjectInfo const* goinfo = sObjectMgr.GetGameObjectInfo(entry); if (!goinfo) return 0; uint32 guid = sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT); GameObjectData& data = sObjectMgr.NewGOData(guid); data.id = entry; data.mapid = mapId; data.posX = x; data.posY = y; data.posZ = z; data.orientation = o; data.rotation0 = rotation0; data.rotation1 = rotation1; data.rotation2 = rotation2; data.rotation3 = rotation3; data.spawntimesecs = 0; data.animprogress = 100; data.spawnMask = 1; data.go_state = GO_STATE_READY; data.phaseMask = PHASEMASK_NORMAL; data.artKit = goinfo->type == GAMEOBJECT_TYPE_CAPTURE_POINT ? 21 : 0; data.dbData = false; Map * map = const_cast<Map*>(sMapMgr.CreateBaseMap(mapId)); if(!map) { sLog.outError("Map (Id: %i) for AddObject cannot be initialized.", mapId); return false; } //SetMap(newMap); sObjectMgr.AddGameobjectToGrid(guid, &data); // Spawn if necessary (loaded grids only) // We use spawn coords to spawn if(!map->Instanceable() && map->IsLoaded(x, y)) { GameObject *go = new GameObject; if (!go->LoadFromDB(guid, map)) { sLog.outError("AddGOData: cannot add gameobject entry %u to map", entry); delete go; return 0; } map->Add(go); } sLog.outDebug("AddGOData: dbguid %u entry %u map %u x %f y %f z %f o %f", guid, entry, mapId, x, y, z, o); //return guid; // if(uint32 guid = sObjectMgr.AddGOData(entry, map, x, y, z, o, 0, rotation0, rotation1, rotation2, rotation3)) if(guid) { AddGO(type, guid, entry); return true; } return false; }
bool OutdoorPvPObjective::AddCreature(uint32 type, uint32 entry, uint32 teamval, uint32 map, float x, float y, float z, float o, uint32 spawntimedelay) { CreatureInfo const *cinfo = objmgr.GetCreatureTemplate(entry); if(!cinfo) { return false; } uint32 displayId = objmgr.ChooseDisplayId(teamval, cinfo, NULL); CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(displayId); if (!minfo) { return false; } else displayId = minfo->modelid; // it can be different (for another gender) uint32 guid = objmgr.GenerateLowGuid(HIGHGUID_UNIT); CreatureData& data = objmgr.NewOrExistCreatureData(guid); data.id = entry; data.mapid = map; data.displayid = displayId; data.equipmentId = cinfo->equipmentId; data.posX = x; data.posY = y; data.posZ = z; data.orientation = o; data.spawntimesecs = spawntimedelay; data.spawndist = 0; data.currentwaypoint = 0; data.curhealth = cinfo->maxhealth; data.curmana = cinfo->maxmana; data.is_dead = false; data.movementType = cinfo->MovementType; data.spawnMask = 1; data.phaseMask = PHASEMASK_NORMAL; objmgr.AddCreatureToGrid(guid, &data); m_Creatures[type] = MAKE_NEW_GUID(guid, entry, HIGHGUID_UNIT); m_CreatureTypes[m_Creatures[type]] = type; Map * pMap = MapManager::Instance().FindMap(map); if(!pMap) return true; Creature* pCreature = new Creature; if (!pCreature->Create(guid, pMap, PHASEMASK_NORMAL, entry, teamval)) { sLog.outError("OutdoorPvPObjective: Can't create creature entry: %u",entry); delete pCreature; return true; } pCreature->AIM_Initialize(); pCreature->Relocate(x, y, z, o); if(!pCreature->IsPositionValid()) { sLog.outError("OutdoorPvPObjective: ERROR: Creature (guidlow %d, entry %d) not added to opvp. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY()); return false; } if(spawntimedelay) pCreature->SetRespawnDelay(spawntimedelay); pMap->Add(pCreature); return true; }
void GameEvent::GameEventSpawn(int16 event_id) { if(max_event_id + event_id >= mGameEventCreatureGuids.size()) { sLog.outError("GameEvent::GameEventSpawn attempt access to out of range mGameEventCreatureGuids element %u (size: %u)",max_event_id + event_id,mGameEventCreatureGuids.size()); return; } for (GuidList::iterator itr = mGameEventCreatureGuids[max_event_id + event_id].begin();itr != mGameEventCreatureGuids[max_event_id + event_id].end();++itr) { // Add to correct cell CreatureData const* data = objmgr.GetCreatureData(*itr); if (data) { objmgr.AddCreatureToGrid(*itr, data); // Spawn if necessary (loaded grids only) Map* map = const_cast<Map*>(MapManager::Instance().GetBaseMap(data->mapid)); // We use spawn coords to spawn if(!map->Instanceable() && !map->IsRemovalGrid(data->spawn_posX,data->spawn_posY)) { Creature* pCreature = new Creature((WorldObject*)NULL); //sLog.outDebug("Spawning creature %u",*itr); if (!pCreature->LoadFromDB(*itr, map->GetInstanceId())) { delete pCreature; } else { map->Add(pCreature); } } } } if(max_event_id + event_id >= mGameEventGameobjectGuids.size()) { sLog.outError("GameEvent::GameEventSpawn attempt access to out of range mGameEventGameobjectGuids element %u (size: %u)",max_event_id + event_id,mGameEventGameobjectGuids.size()); return; } for (GuidList::iterator itr = mGameEventGameobjectGuids[max_event_id + event_id].begin();itr != mGameEventGameobjectGuids[max_event_id + event_id].end();++itr) { // Add to correct cell GameObjectData const* data = objmgr.GetGOData(*itr); if (data) { objmgr.AddGameobjectToGrid(*itr, data); // Spawn if necessary (loaded grids only) // this base map checked as non-instanced and then only existed Map* map = const_cast<Map*>(MapManager::Instance().GetBaseMap(data->mapid)); // We use current coords to unspawn, not spawn coords since creature can have changed grid if(!map->Instanceable() && !map->IsRemovalGrid(data->posX, data->posY)) { GameObject* pGameobject = new GameObject((WorldObject*)NULL); //sLog.outDebug("Spawning gameobject %u", *itr); if (!pGameobject->LoadFromDB(*itr, map->GetInstanceId())) { delete pGameobject; } else { if(pGameobject->isSpawnedByDefault()) map->Add(pGameobject); } } } } }
Corpse* ObjectAccessor::ConvertCorpseForPlayer(uint64 player_guid, bool insignia) { Corpse* corpse = GetCorpseForPlayerGUID(player_guid); if (!corpse) { //in fact this function is called from several places //even when player doesn't have a corpse, not an error //sLog->outError("Try remove corpse that not in map for GUID %ul", player_guid); return NULL; } sLog->outDebug("Deleting Corpse and spawned bones."); Map *map = corpse->FindMap(); // remove corpse from player_guid -> corpse map RemoveCorpse(corpse); // done in removecorpse // remove resurrectable corpse from grid object registry (loaded state checked into call) // do not load the map if it's not loaded //Map *map = sMapMgr->FindMap(corpse->GetMapId(), corpse->GetInstanceId()); //if (map) // map->Remove(corpse, false); // remove corpse from DB corpse->DeleteFromDB(); Corpse* bones = NULL; // create the bones only if the map and the grid is loaded at the corpse's location // ignore bones creating option in case insignia if (map && (insignia || (map->IsBattleGroundOrArena() ? sWorld->getConfig(CONFIG_DEATH_BONES_BG_OR_ARENA) : sWorld->getConfig(CONFIG_DEATH_BONES_WORLD))) && !map->IsRemovalGrid(corpse->GetPositionX(), corpse->GetPositionY())) { // Create bones, don't change Corpse bones = new Corpse; bones->Create(corpse->GetGUIDLow(), map); for (int i = 3; i < CORPSE_END; ++i) // don't overwrite guid and object type bones->SetUInt32Value(i, corpse->GetUInt32Value(i)); bones->SetGrid(corpse->GetGrid()); // bones->m_time = m_time; // don't overwrite time // bones->m_inWorld = m_inWorld; // don't overwrite in-world state // bones->m_type = m_type; // don't overwrite type bones->Relocate(corpse->GetPositionX(), corpse->GetPositionY(), corpse->GetPositionZ(), corpse->GetOrientation()); bones->SetUInt32Value(CORPSE_FIELD_FLAGS, CORPSE_FLAG_UNK2 | CORPSE_FLAG_BONES); bones->SetUInt64Value(CORPSE_FIELD_OWNER, 0); for (int i = 0; i < EQUIPMENT_SLOT_END; ++i) { if (corpse->GetUInt32Value(CORPSE_FIELD_ITEM + i)) bones->SetUInt32Value(CORPSE_FIELD_ITEM + i, 0); } // add bones in grid store if grid loaded where corpse placed map->Add(bones); } // all references to the corpse should be removed at this point delete corpse; return bones; }
Corpse* ObjectAccessor::ConvertCorpseForPlayer(uint64 player_guid, bool insignia /*=false*/) { Corpse* corpse = GetCorpseForPlayerGUID(player_guid); if (!corpse) { //in fact this function is called from several places //even when player doesn't have a corpse, not an error return NULL; } sLog->outStaticDebug("Deleting Corpse and spawned bones."); // Map can be NULL Map* map = corpse->FindMap(); // remove corpse from player_guid -> corpse map and from current map RemoveCorpse(corpse); // remove corpse from DB SQLTransaction trans = CharacterDatabase.BeginTransaction(); corpse->DeleteFromDB(trans); CharacterDatabase.CommitTransaction(trans); Corpse* bones = NULL; // create the bones only if the map and the grid is loaded at the corpse's location // ignore bones creating option in case insignia if (map && (insignia || (map->IsBattlegroundOrArena() ? sWorld->getBoolConfig(CONFIG_DEATH_BONES_BG_OR_ARENA) : sWorld->getBoolConfig(CONFIG_DEATH_BONES_WORLD))) && !map->IsRemovalGrid(corpse->GetPositionX(), corpse->GetPositionY())) { // Create bones, don't change Corpse bones = new Corpse; bones->Create(corpse->GetGUIDLow(), map); for (uint8 i = OBJECT_FIELD_TYPE + 1; i < CORPSE_END; ++i) // don't overwrite guid and object type bones->SetUInt32Value(i, corpse->GetUInt32Value(i)); bones->SetGrid(corpse->GetGrid()); // bones->m_time = m_time; // don't overwrite time // bones->m_type = m_type; // don't overwrite type bones->Relocate(corpse->GetPositionX(), corpse->GetPositionY(), corpse->GetPositionZ(), corpse->GetOrientation()); bones->SetPhaseMask(corpse->GetPhaseMask(), false); bones->SetUInt32Value(CORPSE_FIELD_FLAGS, CORPSE_FLAG_UNK2 | CORPSE_FLAG_BONES); bones->SetUInt64Value(CORPSE_FIELD_OWNER, 0); for (uint8 i = 0; i < EQUIPMENT_SLOT_END; ++i) { if (corpse->GetUInt32Value(CORPSE_FIELD_ITEM + i)) bones->SetUInt32Value(CORPSE_FIELD_ITEM + i, 0); } // add bones in grid store if grid loaded where corpse placed map->Add(bones); } // all references to the corpse should be removed at this point delete corpse; return bones; }
void GameEventMgr::GameEventSpawn(int16 event_id) { int32 internal_event_id = mGameEvent.size() + event_id - 1; if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventCreatureGuids.size()) { sLog.outError("GameEventMgr::GameEventSpawn attempt access to out of range mGameEventCreatureGuids element %i (size: " SIZEFMTD ")",internal_event_id,mGameEventCreatureGuids.size()); return; } for (GuidList::iterator itr = mGameEventCreatureGuids[internal_event_id].begin();itr != mGameEventCreatureGuids[internal_event_id].end();++itr) { // Add to correct cell CreatureData const* data = sObjectMgr.GetCreatureData(*itr); if (data) { sObjectMgr.AddCreatureToGrid(*itr, data); // Spawn if necessary (loaded grids only) Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid)); // We use spawn coords to spawn if(!map->Instanceable() && map->IsLoaded(data->posX,data->posY)) { Creature* pCreature = new Creature; //sLog.outDebug("Spawning creature %u",*itr); if (!pCreature->LoadFromDB(*itr, map)) { delete pCreature; } else { map->Add(pCreature); } } } } if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventGameobjectGuids.size()) { sLog.outError("GameEventMgr::GameEventSpawn attempt access to out of range mGameEventGameobjectGuids element %i (size: " SIZEFMTD ")",internal_event_id,mGameEventGameobjectGuids.size()); return; } for (GuidList::iterator itr = mGameEventGameobjectGuids[internal_event_id].begin();itr != mGameEventGameobjectGuids[internal_event_id].end();++itr) { // Add to correct cell GameObjectData const* data = sObjectMgr.GetGOData(*itr); if (data) { sObjectMgr.AddGameobjectToGrid(*itr, data); // Spawn if necessary (loaded grids only) // this base map checked as non-instanced and then only existed Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid)); // We use current coords to unspawn, not spawn coords since creature can have changed grid if(!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { GameObject* pGameobject = new GameObject; //sLog.outDebug("Spawning gameobject %u", *itr); if (!pGameobject->LoadFromDB(*itr, map)) { delete pGameobject; } else { if(pGameobject->isSpawnedByDefault()) map->Add(pGameobject); } } } } if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventPoolIds.size()) { sLog.outError("GameEventMgr::GameEventSpawn attempt access to out of range mGameEventPoolIds element %i (size: " SIZEFMTD ")",internal_event_id,mGameEventPoolIds.size()); return; } for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin();itr != mGameEventPoolIds[internal_event_id].end();++itr) sPoolMgr.SpawnPool(*itr, true); }
//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()) { if (!map->ToInstanceMap()) { if(chr->GetTransport()->AddNPCPassenger(0, id, chr->GetTransOffsetX(), chr->GetTransOffsetY(), chr->GetTransOffsetZ(), chr->GetTransOffsetO())) { WorldDatabase.PQuery("INSERT INTO creature_transport (guid, transport_entry, npc_entry, TransOffsetX, TransOffsetY, TransOffsetZ, TransOffsetO, emote) values (%u, %u, %u, %f, %f, %f, %f, 0)", 0, chr->GetTransport()->GetEntry(),id, chr->GetTransOffsetX(), chr->GetTransOffsetY(), chr->GetTransOffsetZ(), chr->GetTransOffsetO()); } } else { chr->GetTransport()->AddNPCPassengerInInstance(0, id, chr->GetTransOffsetX(), chr->GetTransOffsetY(), chr->GetTransOffsetZ(), chr->GetTransOffsetO()); WorldDatabase.PQuery("INSERT INTO creature_transport (guid, transport_entry, npc_entry, TransOffsetX, TransOffsetY, TransOffsetZ, TransOffsetO, emote) values (%u, %u, %u, %f, %f, %f, %f, 0)", 0, chr->GetTransport()->GetEntry(),id, 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)); WorldDatabase.PQuery("INSERT INTO creature_spawn (guid, account) values (%u, %u)", db_guid, handler->GetSession()->GetAccountId()); return true; }