示例#1
0
void MapCell::LoadEventIdObjects(CellSpawns * sp, uint8 eventId)
{
	Instance * pInstance = _mapmgr->pInstance;

	if(sp)
	{
		if(sp->CreatureSpawns.size())//got creatures
		{
			Vehicle* v;
			Creature* c;
			for(CreatureSpawnList::iterator i = sp->CreatureSpawns.begin(); i != sp->CreatureSpawns.end(); ++i)
			{
				if(pInstance)
				{
					if(pInstance->m_killedNpcs.find((*i)->id) != pInstance->m_killedNpcs.end())
						continue;
				}
				if((*i)->eventid && (*i)->eventid == eventId)
				{
					if(!((*i)->eventinfo->eventchangesflag & EVENTID_FLAG_SPAWN))
						continue;

					if((*i)->vehicle != 0)
					{
						v=_mapmgr->CreateVehicle((*i)->entry);

						v->SetMapId(_mapmgr->GetMapId());
						v->SetInstanceID(_mapmgr->GetInstanceID());
						v->m_loadedFromDB = true;

						if(v->Load(*i, _mapmgr->iInstanceMode, _mapmgr->GetMapInfo()))
						{
							if(!v->CanAddToWorld())
							{
								v->Destructor();
								continue;
							}

							v->PushToWorld(_mapmgr);
						}
						else
						{
							v->Destructor();
						}
					}
					else
					{
						c = _mapmgr->CreateCreature((*i)->entry);

						c->SetMapId(_mapmgr->GetMapId());
						c->SetInstanceID(_mapmgr->GetInstanceID());
						c->m_loadedFromDB = true;

						if(c->Load(*i, _mapmgr->iInstanceMode, _mapmgr->GetMapInfo()))
						{
							if(!c->CanAddToWorld())
							{
								c->Destructor();
								continue;
							}

							c->PushToWorld(_mapmgr);
						}
						else
						{
							c->Destructor();
						}
					}
				}
			}
		}

		if(sp->GOSpawns.size())//got GOs
		{
			GameObject* go;
			for(GOSpawnList::iterator i = sp->GOSpawns.begin(); i != sp->GOSpawns.end(); ++i)
			{
				if((*i)->eventid && (*i)->eventid == eventId)
				{
					if(!((*i)->eventinfo->eventchangesflag & EVENTID_FLAG_SPAWN))
						continue;
					
					go = _mapmgr->CreateGameObject((*i)->entry);
					if(go == NULL)
						continue;

					if(go->Load(*i))
					{
						go->m_loadedFromDB = true;
						go->PushToWorld(_mapmgr);
						CALL_GO_SCRIPT_EVENT(go, OnSpawn)();
					}
					else
					{
						go->Destructor();
					}
				}
			}
		}
	}
}
示例#2
0
void MapCell::LoadObjects(CellSpawns * sp)
{
	_loaded = true;
	Instance * pInstance = _mapmgr->pInstance;

	if(sp->CreatureSpawns.size())//got creatures
	{
		Vehicle* v = NULLVEHICLE;
		Creature* c = NULLCREATURE;
		for(CreatureSpawnList::iterator i=sp->CreatureSpawns.begin();i!=sp->CreatureSpawns.end();i++)
		{
			if(pInstance)
			{
				if(pInstance->m_killedNpcs.find((*i)->id) != pInstance->m_killedNpcs.end())
					continue;

/*				if((*i)->respawnNpcLink && pInstance->m_killedNpcs.find((*i)->respawnNpcLink) != pInstance->m_killedNpcs.end())
					continue;*/
			}
			if(!(*i)->eventid)
			{
				if((*i)->vehicle != 0)
				{
				v =_mapmgr->CreateVehicle((*i)->entry);
				if(v == NULLVEHICLE)
					continue;

					v->SetMapId(_mapmgr->GetMapId());
					v->SetInstanceID(_mapmgr->GetInstanceID());
					v->m_loadedFromDB = true;

					if(v->Load(*i, _mapmgr->iInstanceMode, _mapmgr->GetMapInfo()))
					{
						if(!v->CanAddToWorld())
						{
							v->Destructor();
							v = NULLVEHICLE;
							continue;
						}

						v->PushToWorld(_mapmgr);
					}
					else
					{
						v->Destructor();
					}
				}
				else
				{
					c=_mapmgr->CreateCreature((*i)->entry);
					if(c == NULLCREATURE)
						continue;
	
					c->SetMapId(_mapmgr->GetMapId());
					c->SetInstanceID(_mapmgr->GetInstanceID());
					c->m_loadedFromDB = true;

					if(c->Load(*i, _mapmgr->iInstanceMode, _mapmgr->GetMapInfo()))
					{
						if(!c->CanAddToWorld())
						{
							c->Destructor();
							c = NULLCREATURE;
							continue;
						}

						c->PushToWorld(_mapmgr);
					}
					else
					{
						c->Destructor();
					}
				}
			}
		}
	}

	if(sp->GOSpawns.size())//got GOs
	{
		GameObject* go;
		for(GOSpawnList::iterator i=sp->GOSpawns.begin();i!=sp->GOSpawns.end();i++)
		{
			if(!(*i)->eventid)
			{
				go = _mapmgr->CreateGameObject((*i)->entry);
				if(go == NULL)
					continue;
				if(go->Load(*i))
				{
					go->m_loadedFromDB = true;
					go->PushToWorld(_mapmgr);
					CALL_GO_SCRIPT_EVENT(go, OnSpawn)();
				}
				else
				{
					go->Destructor();
				}
			}
		}
	}
}
示例#3
0
bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session)
{
	uint64 guid = m_session->GetPlayer()->GetSelection();
	if (guid == 0)
	{
		SystemMessage(m_session, "No selection.");
		return true;
	}
	Creature* unit = NULL;

	if(m_session->GetPlayer()->GetMapMgr()->GetVehicle(GET_LOWGUID_PART(guid)))
		unit = m_session->GetPlayer()->GetMapMgr()->GetVehicle(GET_LOWGUID_PART(guid));
	else
		unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid));

	if(!unit)
	{
		SystemMessage(m_session, "You should select a creature.");
		return true;
	}

	if( unit->m_spawn != NULL && !m_session->CanUseCommand('z') )
	{
		SystemMessage(m_session, "You do not have permission to do that. Please contact higher staff for removing of saved spawns.");
		return true;
	}

	if(unit->GetAIInterface()) 
		unit->GetAIInterface()->StopMovement(10000);

	if(unit->IsVehicle())
	{
		Vehicle* veh = TO_VEHICLE(unit);
		for(int i = 0; i < 8; i++)
		{
			if(!veh->GetPassenger(i))
				continue;

			// Remove any players
			if(veh->GetPassenger(i)->IsPlayer())
				veh->RemovePassenger(veh->GetPassenger(i));
			else // Remove any units.
				veh->GetPassenger(i)->RemoveFromWorld(true);
		}
	}

	sGMLog.writefromsession(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f",
		unit->m_spawn ? unit->m_spawn : 0, unit->GetCreatureInfo() ? unit->GetCreatureInfo()->Name : "wtfbbqhax", unit->GetPositionX(), unit->GetPositionY(),
		unit->GetPositionZ());

	BlueSystemMessage(m_session, "Deleted creature ID %u", unit->spawnid);
	
	MapMgr* unitMgr = unit->GetMapMgr();

	unit->DeleteFromDB();

	if(!unit->IsInWorld())
		return true;

	if(unit->m_spawn)
	{
		uint32 cellx=float2int32(((_maxX-unit->m_spawn->x)/_cellSize));
		uint32 celly=float2int32(((_maxY-unit->m_spawn->y)/_cellSize));
		if(cellx <= _sizeX && celly <= _sizeY && unitMgr != NULL)
		{
			CellSpawns * c = unitMgr->GetBaseMap()->GetSpawnsList(cellx, celly);
			if( c != NULL )
			{
				CreatureSpawnList::iterator itr, itr2;
				for(itr = c->CreatureSpawns.begin(); itr != c->CreatureSpawns.end();)
				{
					itr2 = itr;
					++itr;
					if((*itr2) == unit->m_spawn)
					{
						c->CreatureSpawns.erase(itr2);
						delete unit->m_spawn;
						break;
					}
				}
			}
		}
	}
	unit->RemoveFromWorld(false,true);

	if(unit->IsVehicle())
		TO_VEHICLE(unit)->Destructor();
	else
		unit->Destructor();

	return true;
}