Esempio n. 1
0
void MapCell::LoadObjects(CellSpawns * sp)
{
	if(_loaded == true)
		return;

	_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)->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->Destruct();
						v = NULLVEHICLE;
						continue;
					}

					v->PushToWorld(_mapmgr);
				}
				else
				{
					v->Destruct();
					v = NULLVEHICLE;
				}
			}
			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->Destruct();
						c = NULLCREATURE;
						continue;
					}

					c->PushToWorld(_mapmgr);
				}
				else
				{
					c->Destruct();
					c = NULLCREATURE;
				}
			}
		}
	}

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

			if(go->Load(*i))
			{
				go->PushToWorld(_mapmgr);
				CALL_GO_SCRIPT_EVENT(go, OnSpawn)();
			}
			else
			{
				go->Destruct();
				go = NULLOBJ;
			}
		}
	}
}
Esempio n. 2
0
void WintergraspScript::UpdateWarZones()
{
    uint32 CurrentTime = UNIXTIME;
    for(std::set<SpawnInfo*>::iterator itr = m_WarriorPool.begin(), itr2; itr != m_WarriorPool.end();)
    {
        itr2 = itr++;

        Creature* ctr = (*itr2)->m_Spawn;
        if(ctr == NULL)
            m_WarriorPool.erase(itr2);
        else if(ctr->isDead())
        {
            (*itr2)->RespawnTime = CurrentTime+120;
            (*itr2)->m_Spawn = NULL;
            m_WarriorPool.erase(itr2);
            m_WarriorSoulPool.insert((*itr2));

            ctr->RemoveFromWorld(false, true);
            ctr->Destruct();
        }
    }

    CreatureProto* ctrp = NULL;
    SpawnInfo* spawnInfo = NULL;
    for(std::set<SpawnInfo*>::iterator itr = m_WarriorSoulPool.begin(), itr2; itr != m_WarriorSoulPool.end();)
    {
        itr2 = itr++;

        spawnInfo = (*itr2);
        if(spawnInfo->RespawnTime < CurrentTime)
        {
            ctrp = CreatureProtoStorage.LookupEntry((*itr2)->CreatureEntry);
            if(ctrp == NULL)
                continue;

            float x = Wintergrasp_WarZones[spawnInfo->locationId][spawnInfo->SpawnId].mX, y = Wintergrasp_WarZones[spawnInfo->locationId][spawnInfo->SpawnId].mY,
                z = Wintergrasp_WarZones[spawnInfo->locationId][spawnInfo->SpawnId].mZ, o = Wintergrasp_WarZones[spawnInfo->locationId][spawnInfo->SpawnId].mO;

            if(x == 0.0f || y == 0.0f || z == 0.0f)
                continue;

            spawnInfo->m_Spawn = mgr->CreateCreature(spawnInfo->CreatureEntry);
            if(spawnInfo->m_Spawn == NULL)
                continue;

            spawnInfo->m_Spawn->SetMapId(mgr->GetMapId());
            spawnInfo->m_Spawn->SetInstanceID(mgr->GetInstanceID());

            if(spawnInfo->m_Spawn->Load(ctrp, mgr->iInstanceMode, x, y, z, o))
            {
                if(!spawnInfo->m_Spawn->CanAddToWorld())
                {
                    spawnInfo->m_Spawn->Destruct();
                    spawnInfo->m_Spawn = NULL;
                    continue;
                }

                m_WarriorSoulPool.erase(itr2);
                spawnInfo->m_Spawn->PushToWorld(mgr);
                m_WarriorPool.insert(spawnInfo);
            }
            else
            {
                spawnInfo->m_Spawn->Destruct();
                spawnInfo->m_Spawn = NULL;
            }
        }
    }
}
Esempio n. 3
0
void WintergraspScript::SpawnWarZones(bool apply)
{
    return; // Needs work and more base implementation before it's safe to enable it.

    // This one is simple.
    if(apply)
    {
        Herald("Multiple Battle groups have engaged!");

        uint32 Entry = 0, percent = 100;
        CreatureProto* ctrp = NULL;
        for(uint32 i = 0; i < MAX_BATTLE_ZONES; i++)
        {
            for(uint32 t = 0; t < MAX_UNITS_PER_ZONE/2; t++)
            {
                float x = Wintergrasp_WarZones[i][t].mX, y = Wintergrasp_WarZones[i][t].mY, z = Wintergrasp_WarZones[i][t].mZ, o = Wintergrasp_WarZones[i][t].mO;
                if(x == 0.0f || y == 0.0f || z == 0.0f)
                    continue;

                if(RandomUInt(percent) > (percent/2))
                    Entry = 00000;
                else
                    Entry = 00000;
                percent += 1;

                ctrp = CreatureProtoStorage.LookupEntry(Entry);
                if(ctrp == NULL)
                    continue;

                Creature* ctr = mgr->CreateCreature(Entry);
                if(ctr == NULL)
                    continue;

                ctr->SetMapId(mgr->GetMapId());
                ctr->SetInstanceID(mgr->GetInstanceID());

                if(ctr->Load(ctrp, mgr->iInstanceMode, x, y, z, o))
                {
                    if(!ctr->CanAddToWorld())
                    {
                        ctr->Destruct();
                        continue;
                    }

                    ctr->PushToWorld(mgr);

                    SpawnInfo* spI = new SpawnInfo();
                    spI->CreatureEntry = Entry;
                    spI->RespawnTime = 0;
                    spI->locationId = i;
                    spI->SpawnId = t;
                    spI->m_Spawn = ctr;
                    m_WarriorPool.insert(spI);
                }
                else ctr->Destruct();
            }

            for(uint32 t = MAX_UNITS_PER_ZONE/2; t < MAX_UNITS_PER_ZONE; t++)
            {
                float x = Wintergrasp_WarZones[i][t].mX, y = Wintergrasp_WarZones[i][t].mY, z = Wintergrasp_WarZones[i][t].mZ, o = Wintergrasp_WarZones[i][t].mO;
                if(x == 0.0f || y == 0.0f || z == 0.0f)
                    continue;

                if(RandomUInt(percent) > (percent/2))
                    Entry = 00000;
                else
                    Entry = 00000;
                percent += 1;

                ctrp = CreatureProtoStorage.LookupEntry(Entry);
                if(ctrp == NULL)
                    continue;

                Creature* ctr = mgr->CreateCreature(Entry);
                if(ctr == NULL)
                    continue;

                ctr->SetMapId(mgr->GetMapId());
                ctr->SetInstanceID(mgr->GetInstanceID());

                if(ctr->Load(ctrp, mgr->iInstanceMode, x, y, z, o))
                {
                    if(!ctr->CanAddToWorld())
                    {
                        ctr->Destruct();
                        continue;
                    }

                    ctr->PushToWorld(mgr);

                    SpawnInfo* spI = new SpawnInfo();
                    spI->CreatureEntry = Entry;
                    spI->RespawnTime = 0;
                    spI->locationId = i;
                    spI->SpawnId = t;
                    spI->m_Spawn = ctr;
                    m_WarriorPool.insert(spI);
                }
                else ctr->Destruct();
            }
        }
    }
    else
    {
        m_WarriorSoulPool.clear();
        float x = 0.0f, y = 0.0f;
        for(std::set<SpawnInfo*>::iterator itr = m_WarriorPool.begin(), it2; itr != m_WarriorPool.end();)
        {
            it2 = itr++;
            Creature* ctr = (*it2)->m_Spawn;
            if(ctr != NULL)
            {
                x = ctr->GetPositionX();
                y = ctr->GetPositionY();

                (*it2)->m_Spawn = NULL;
                ctr->RemoveFromWorld(false, true);
                ctr->Destruct();
            }

            delete (*it2);
        }
        m_WarriorPool.clear();
    }
}
Esempio n. 4
0
bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session)
{
    Creature* unit = getSelectedCreature(m_session, false);
    if(!unit)
    {
        SystemMessage(m_session, "You should select a creature.");
        return true;
    }
    else if(unit->IsPet() || unit->IsSummon())
    {
        SystemMessage(m_session, "You can't delete playerpets.");
        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->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);
        }
    }

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

    BlueSystemMessage(m_session, "Deleted creature ID %u", unit->spawnid);

    unit->DeleteFromDB();

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

    MapMgr* unitMgr = unit->GetMapMgr();
    if(unit->m_spawn)
    {
        uint32 cellx = unitMgr->GetPosX(unit->m_spawn->x);
        uint32 celly = unitMgr->GetPosX(unit->m_spawn->y);
        if(cellx <= _sizeX && celly <= _sizeY )
        {
            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++;
                    if((*itr2) == unit->m_spawn)
                    {
                        c->CreatureSpawns.erase(itr2);
                        delete unit->m_spawn;
                        break;
                    }
                }
            }
        }
    }
    unit->RemoveFromWorld(false, true);

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

    m_session->GetPlayer()->SetSelection(NULL);
    return true;
}