Example #1
0
bool ChatHandler::HandleAddSpwCommand(const char* args)
{
    char* charID = strtok((char*)args, " ");
    if (!charID)
        return false;

    uint32 id  = atoi(charID);

    Player *chr = m_session->GetPlayer();
    float x = chr->GetPositionX();
    float y = chr->GetPositionY();
    float z = chr->GetPositionZ();
    float o = chr->GetOrientation();

    Creature* pCreature = new Creature(chr);
    if (!pCreature->Create(objmgr.GenerateLowGuid(HIGHGUID_UNIT), chr->GetMapId(), x, y, z, o, id))
    {
        delete pCreature;
        return false;
    }

    pCreature->SaveToDB();

    // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
    pCreature->LoadFromDB(pCreature->GetGUIDLow(), NULL, chr->GetInstanceId());

    pCreature->AddToWorld();
    MapManager::Instance().GetMap(pCreature->GetMapId(), pCreature)->Add(pCreature);

    sLog.outDebug(LANG_ADD_OBJ);

    return true;
}
Example #2
0
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))
        {
            CreatureInfo const *ci = ObjectMgr::GetCreatureTemplate(data->id);
            if (!ci)
                return;

            Creature* pCreature = NULL;
            if (ci->ScriptID)
                pCreature = sScriptMgr->GetCreatureScriptedClass(ci->ScriptID);
            if (pCreature == NULL)
                pCreature = new Creature();

            //sLog->outDebug(LOG_FILTER_POOLSYS, "Spawning creature %u", guid);
            if (!pCreature->LoadFromDB(obj->guid, map))
            {
                delete pCreature;
                return;
            }
            else
                map->Add(pCreature);
        }
    }
}
Example #3
0
bool PoolGroup<Creature>::Spawn1Object(uint32 guid)
{
    CreatureData const* data = objmgr.GetCreatureData(guid);
    if (data)
    {
        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->IsRemovalGrid(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;
}
Example #4
0
void Vehicle::InstallAllAccessories()
{
    if(!GetMap())
       return;

    CreatureDataAddon const *cainfo = GetCreatureAddon();
    if(!cainfo || !cainfo->passengers)
        return;
    for (CreatureDataAddonPassengers const* cPassanger = cainfo->passengers; cPassanger->seat_idx != -1; ++cPassanger)
    {
        // Continue if seat already taken
        if(GetPassenger(cPassanger->seat_idx))
            continue;

        uint32 guid = 0;
        bool isVehicle = false;
        // Set guid and check whatever it is
        if(cPassanger->guid != 0)
            guid = cPassanger->guid;
        else
        {
            CreatureDataAddon const* passAddon;
            passAddon = ObjectMgr::GetCreatureTemplateAddon(cPassanger->entry);
            if(passAddon && passAddon->vehicle_id != 0)
                isVehicle = true;
            else
                guid = sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT);
        }
        // Create it
        Creature *pPassenger = new Creature;
        if(!isVehicle)
        {
            uint32 entry = cPassanger->entry;
            if(entry == 0)
            {
                CreatureData const* data = sObjectMgr.GetCreatureData(guid);
                if(!data)
                    continue;
                entry = data->id;
            }     
            
            if(!pPassenger->Create(guid, GetMap(), GetPhaseMask(), entry, 0))
                continue;
            pPassenger->LoadFromDB(guid, GetMap());
            pPassenger->Relocate(GetPositionX(), GetPositionY(), GetPositionZ());
            GetMap()->Add(pPassenger);
            pPassenger->AIM_Initialize();
        }
        else
            pPassenger = (Creature*)SummonVehicle(cPassanger->entry, GetPositionX(), GetPositionY(), GetPositionZ(), 0);
        // Enter vehicle...
        pPassenger->EnterVehicle(this, cPassanger->seat_idx, true);
        // ...and send update. Without this, client wont show this new creature/vehicle...
        WorldPacket data;
        pPassenger->BuildHeartBeatMsg(&data);
        pPassenger->SendMessageToSet(&data, false);
    }
}
Example #5
0
    //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;
    }
Example #6
0
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);

        // FIXME: pool system must have local state for each instanced map copy
        // Current code preserve existed single state for all instanced map copies way
        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_SAVE_RESPAWN_TIME_IMMEDIATELY) || 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, 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);
            }
        }
    }
}
Example #8
0
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 = sMapMgr->CreateBaseMap(data->spawnPoint.GetMapId());
        // We use spawn coords to spawn
        if (!map->Instanceable() && map->IsGridLoaded(data->spawnPoint))
        {
            Creature* creature = new Creature();
            //TC_LOG_DEBUG("pool", "Spawning creature %u", guid);
            if (!creature->LoadFromDB(obj->guid, map, true, false))
            {
                delete creature;
                return;
            }
        }
    }
}
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.FindMap(data->mapid));
        if(!map)
            return;

        // 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;
            //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(!map->Instanceable() && !instantly)
        {
            sObjectMgr.SaveCreatureRespawnTime(obj->guid,map->GetInstanceId(),time(NULL) + data->spawntimesecs);
        }
    }
}
Example #10
0
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(LOG_FILTER_POOLSYS, "Spawning creature %u", guid);
            if (!creature->LoadFromDB(obj->guid, map))
            {
                delete creature;
                return;
            }
            else
                map->AddToMap(creature);
        }
    }
}
Example #11
0
void PoolGroup<Creature>::Spawn1Object(PoolObject* obj)
{
    if (CreatureData const* data = objmgr.GetCreatureData(obj->guid))
    {
        objmgr.AddCreatureToGrid(obj->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(obj->guid, map))
            {
                delete pCreature;
                return;
            }
            else
                map->Add(pCreature);
        }
    }
}
Example #12
0
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);
}
Example #13
0
	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;
	}
Example #14
0
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);
                }
            }
        }
    }
}
Example #15
0
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)
            if (Map* map = const_cast<Map*>(sMapMgr.FindMap(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
            if (Map* map = const_cast<Map*>(sMapMgr.FindMap(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);
    }
}