Exemple #1
0
void MapCell::LoadObjects(CellSpawns * sp)
{
    //we still have mobs loaded on cell. There is no point of loading them again
    if (_loaded == true)
        return;

    _loaded = true;
    Instance * pInstance = _mapmgr->pInstance;
    InstanceBossInfoMap *bossInfoMap = objmgr.m_InstanceBossInfoMap[_mapmgr->GetMapId()];

    if (sp->CreatureSpawns.size())//got creatures
    {
        for (CreatureSpawnList::iterator i = sp->CreatureSpawns.begin(); i != sp->CreatureSpawns.end(); i++)
        {
            uint32 respawnTimeOverride = 0;
            if (pInstance)
            {
                if (bossInfoMap != NULL && IS_PERSISTENT_INSTANCE(pInstance))
                {
                    bool skip = false;
                    for (std::set<uint32>::iterator killedNpc = pInstance->m_killedNpcs.begin(); killedNpc != pInstance->m_killedNpcs.end(); ++killedNpc)
                    {
                        // Do not spawn the killed boss.
                        if ((*killedNpc) == (*i)->entry)
                        {
                            skip = true;
                            break;
                        }
                        // Do not spawn the killed boss' trash.
                        InstanceBossInfoMap::const_iterator bossInfo = bossInfoMap->find((*killedNpc));
                        if (bossInfo != bossInfoMap->end() && bossInfo->second->trash.find((*i)->id) != bossInfo->second->trash.end())
                        {
                            skip = true;
                            break;
                        }
                    }
                    if (skip)
                        continue;

                    for (InstanceBossInfoMap::iterator bossInfo = bossInfoMap->begin(); bossInfo != bossInfoMap->end(); ++bossInfo)
                    {
                        if (pInstance->m_killedNpcs.find(bossInfo->second->creatureid) == pInstance->m_killedNpcs.end() && bossInfo->second->trash.find((*i)->id) != bossInfo->second->trash.end())
                        {
                            respawnTimeOverride = bossInfo->second->trashRespawnOverride;
                        }
                    }
                }
                else
                {
                    // No boss information available ... fallback ...
                    if (pInstance->m_killedNpcs.find((*i)->id) != pInstance->m_killedNpcs.end())
                        continue;
                }
            }

            Creature * c = _mapmgr->CreateCreature((*i)->entry);

            c->SetMapId(_mapmgr->GetMapId());
            c->SetInstanceID(_mapmgr->GetInstanceID());
            c->m_loadedFromDB = true;
            if (respawnTimeOverride > 0)
                c->m_respawnTimeOverride = respawnTimeOverride;

            if (c->Load(*i, _mapmgr->iInstanceMode, _mapmgr->GetMapInfo()) && c->CanAddToWorld())
            {
                c->PushToWorld(_mapmgr);
            }
            else
                delete c;//missing proto or smth of that kind
        }
    }

    if (sp->GOSpawns.size())//got GOs
    {
        for (GOSpawnList::iterator i = sp->GOSpawns.begin(); i != sp->GOSpawns.end(); i++)
        {
            GameObject * go = _mapmgr->CreateGameObject((*i)->entry);
            go->SetInstanceID(_mapmgr->GetInstanceID());
            if (go->Load(*i))
            {
                //uint32 state = go->GetUInt32Value(GAMEOBJECT_STATE);

                // FIXME - burlex
                /*
                if(pInstance && pInstance->FindObject((*i)->stateNpcLink))
                {
                go->SetUInt32Value(GAMEOBJECT_STATE, (state ? 0 : 1));
                }*/

                go->m_loadedFromDB = true;
                go->PushToWorld(_mapmgr);
            }
            else
                delete go;//missing proto or smth of that kind
        }
    }
}
Exemple #2
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();
    }
}
Exemple #3
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();
				}
			}
		}
	}
}
Exemple #4
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();
					}
				}
			}
		}
	}
}