MapMgr* InstanceMgr::CreateInstance(uint32 instanceType, uint32 mapid) { // shouldn't happen if(mapid >= NUM_MAPS) return NULL; if(!m_maps[mapid]) { _CreateMap(mapid); if(!m_maps[mapid]) return NULL; } MapMgr* ret = new MapMgr(m_maps[mapid], mapid, GenerateInstanceID()); Instance* pInstance = new Instance(); pInstance->m_creation = UNIXTIME; pInstance->m_creatorGroup = 0; pInstance->m_creatorGuid = 0; pInstance->m_difficulty = 0; pInstance->m_expiration = 0; pInstance->m_instanceId = ret->GetInstanceID(); pInstance->m_persistent = false; pInstance->m_mapId = mapid; pInstance->m_mapInfo = WorldMapInfoStorage.LookupEntry(mapid); pInstance->m_mapMgr = ret; m_mapLock.Acquire(); if(m_instances[mapid] == NULL) m_instances[mapid] = new InstanceMap; m_instances[mapid]->insert(make_pair(pInstance->m_instanceId, pInstance)); m_mapLock.Release(); ThreadPool.ExecuteTask(ret); return ret; }
MapMgr* InstanceMgr::ClusterCreateInstance( uint32 mapid, uint32 instanceid ) { // shouldn't happen if( mapid >= NUM_MAPS ) return NULLMAPMGR; MapInfo * info = WorldMapInfoStorage.LookupEntry( mapid ); if( !info ) return NULLMAPMGR; if( !m_maps[mapid] ) { _CreateMap(mapid); if(!m_maps[mapid]) return NULLMAPMGR; } MapMgr* mgr = new MapMgr(m_maps[mapid],mapid,instanceid); if( !mgr ) return NULLMAPMGR; mgr->Init(true); Instance * pInstance = new Instance(); if( !pInstance ) { delete mgr; return NULLMAPMGR; } pInstance->m_creation = UNIXTIME; pInstance->m_creatorGroup = 0; pInstance->m_creatorGuid = 0; pInstance->m_difficulty = 0; pInstance->m_expiration = 0; pInstance->m_instanceId = mgr->GetInstanceID(); pInstance->m_isBattleground = true; pInstance->m_mapId = mapid; pInstance->m_dbcMap = dbcMap.LookupEntry(mapid); pInstance->m_mapInfo = info; pInstance->m_mapMgr = mgr; m_mapLock.Acquire(); InstanceMap * pInstanceMap = new InstanceMap; if( !pInstanceMap ) { m_mapLock.Release(); delete mgr; delete pInstance; return NULLMAPMGR; } if( m_instances[mapid] == NULL ) m_instances[mapid] = pInstanceMap; m_instances[mapid]->insert( make_pair( pInstance->m_instanceId, pInstance ) ); m_mapLock.Release(); ThreadPool.ExecuteTask(format("Map mgr - M%u|I%u", mapid, pInstance->m_instanceId).c_str(), mgr); return mgr; }
MapMgr* InstanceMgr::CreateBattlegroundInstance(uint32 mapid) { // shouldn't happen if( mapid >= NUM_MAPS ) return NULLMAPMGR; if(dbcMap.LookupEntry(mapid) == NULL) return NULLMAPMGR; if(!m_maps[mapid]) { _CreateMap(mapid); if(!m_maps[mapid]) return NULLMAPMGR; } MapMgr* ret = (new MapMgr(m_maps[mapid], mapid, GenerateInstanceID())); ret->Init(true); Instance * pInstance = new Instance(); pInstance->m_creation = UNIXTIME; pInstance->m_creatorGroup = 0; pInstance->m_creatorGuid = 0; pInstance->m_difficulty = MODE_5PLAYER_NORMAL; pInstance->m_expiration = 0; pInstance->m_instanceId = ret->GetInstanceID(); pInstance->m_isBattleground = true; pInstance->m_mapId = mapid; pInstance->m_dbcMap = dbcMap.LookupEntry(mapid); pInstance->m_mapInfo = WorldMapInfoStorage.LookupEntry(mapid); pInstance->m_mapMgr = ret; m_mapLock.Acquire(); if( m_instances[mapid] == NULL ) m_instances[mapid] = new InstanceMap; m_instances[mapid]->insert( make_pair( pInstance->m_instanceId, pInstance ) ); m_mapLock.Release(); ThreadPool.ExecuteTask(format("BattleGround Mgr - M%u|I%u", mapid, pInstance->m_instanceId).c_str(), ret); return ret; }
uint32 WorldCreator::CreateInstance(Group *pGroup, Player *pPlayer, uint32 mapid, uint32 instanceid, uint32 creation, MapMgr ** destptr, uint32 difficulty) { if(pGroup == NULL && pPlayer == NULL && instanceid == 0) { return INSTANCE_ABORT_ERROR; } Map* instance_map = GetMap(mapid); ASSERT(instance_map != NULL); MapMgr * pInstance = instance_map->CreateMapMgrInstance(instanceid); ASSERT(pInstance); if(creation) { pInstance->SetNewExpireTime(creation); } if(pGroup) { pInstance->SetGroupSignature(pGroup->GetID()); pInstance->iInstanceMode = pGroup->GetLeader()->iInstanceType; } if(pPlayer) { pInstance->SetCreator(pPlayer); pInstance->iInstanceMode = pPlayer->iInstanceType; } if(difficulty) { pInstance->iInstanceMode = difficulty; } //Capt: We do not realy need to store this one if we are not doing something with it. sInstanceSavingManager.SaveInstance(pInstance); //first time instance saving holder if(destptr) *destptr = pInstance; return pInstance->GetInstanceID(); }
bool WorldCreator::CheckInstanceForObject(Object *obj, MapInfo *pMapinfo) { WorldPacket data(4); Player *_player = NULL; if(obj->GetTypeId() == TYPEID_PLAYER) { _player = static_cast<Player*>(obj); } if(pMapinfo && _player) { switch(pMapinfo->type) { case INSTANCE_NONRAID: case INSTANCE_RAID: case INSTANCE_MULTIMODE: { //instance creation detection types //case 1, player is inside a group aka not soloing //onoes: leader can be inside a instance already and make a group or its a fresh group, noone inside if(_player->InGroup()) //group created, join leader instance. { Group *pGroup = _player->GetGroup(); if(pGroup) { //check if instance already exists(player solo created instance and made group after) MapMgr *pInstance = sWorldCreator.GetInstanceByGroup(pGroup, _player, pMapinfo); if(pInstance) { //INSTANCE_OK if(pInstance->IsCombatInProgress()) { WorldPacket msg; msg.Initialize(SMSG_AREA_TRIGGER_MESSAGE); msg << uint32(0) << "Encounter in progress." << uint8(0) << uint8(0); _player->GetSession()->SendPacket(&msg); return false; } if(pInstance->GetPlayerCount() >= pMapinfo->playerlimit) { data.Initialize(SMSG_TRANSFER_ABORTED); data << uint32(INSTANCE_ABORT_FULL); _player->GetSession()->SendPacket(&data); return false; } _player->SetInstanceID(pInstance->GetInstanceID()); } else { //group leader didnt made any instance yet, create instance for this group. uint32 id = sWorldCreator.CreateInstance(pGroup, pGroup->GetLeader(), pMapinfo->mapid); // again, NULL might not be 0 //if(id != NULL) if(id != 0) { //INSTANCE CREATED _player->SetInstanceID(id); } else { data.Initialize(SMSG_TRANSFER_ABORTED); data << uint32(INSTANCE_ABORT_ERROR); _player->GetSession()->SendPacket(&data); return false; } } } else { data.Initialize(SMSG_TRANSFER_ABORTED); data << uint32(INSTANCE_ABORT_ERROR); _player->GetSession()->SendPacket(&data); return false; } } else { MapMgr *pInstance = sWorldCreator.GetInstanceByCreator(_player, pMapinfo); if(pInstance) { //INSTANCE_OK if(pInstance->IsCombatInProgress()) { WorldPacket msg; msg.Initialize(SMSG_AREA_TRIGGER_MESSAGE); msg << uint32(0) << "Encounter in progress." << uint8(0) << uint8(0); _player->GetSession()->SendPacket(&msg); return false; } if(pInstance->GetPlayerCount() >= pMapinfo->playerlimit) { data.Initialize(SMSG_TRANSFER_ABORTED); data << uint32(INSTANCE_ABORT_FULL); _player->GetSession()->SendPacket(&data); return false; } _player->SetInstanceID(pInstance->GetInstanceID()); } else { uint32 id2 = sWorldCreator.CreateInstance(NULL, _player, pMapinfo->mapid); //if(id2 != NULL) if(id2 != 0) { _player->SetInstanceID(id2); } else { data.Initialize(SMSG_TRANSFER_ABORTED); data << uint32(INSTANCE_ABORT_ERROR); _player->GetSession()->SendPacket(&data); return false; } } } }break; } } return true; }
int LuaGlobalFunctions_PerformIngameSpawn(lua_State * L) { uint32 spawntype = luaL_checkint(L, 1); uint32 entry = luaL_checkint(L, 2); uint32 map = luaL_checkint(L, 3); float x = CHECK_FLOAT(L, 4); float y = CHECK_FLOAT(L, 5); float z = CHECK_FLOAT(L, 6); float o = CHECK_FLOAT(L, 7); uint32 faction = luaL_checkint(L, 8); //also scale as percentage uint32 duration = luaL_checkint(L, 9); uint32 equip1 = luaL_optint(L, 10, 1); uint32 equip2 = luaL_optint(L, 11, 1); uint32 equip3 = luaL_optint(L, 12, 1); //13: instance id uint32 save = luaL_optint(L, 14, 0); if(x && y && z && entry) { if (spawntype == 1) //Unit { CreatureProto *p = CreatureProtoStorage.LookupEntry(entry); CreatureInfo *i = CreatureNameStorage.LookupEntry(entry); if (p == NULL || i == NULL) RET_NIL(true); MapMgr *mapMgr = sInstanceMgr.GetMapMgr(map); if (mapMgr == NULL) RET_NIL(true); int32 instanceid = luaL_optint(L, 13, mapMgr->GetInstanceID()); CreatureSpawn * sp = new CreatureSpawn(); sp->entry = entry; sp->id = objmgr.GenerateCreatureSpawnID(); sp->x = x; sp->y = y; sp->z = z; sp->o = o; sp->emote_state = 0; sp->flags = 0; sp->factionid = faction; sp->stand_state = 0; sp->phase = 1; sp->vehicle = p->vehicle_entry > 0 ? true : false; sp->Bytes = NULL; sp->ChannelData = NULL; sp->MountedDisplay = NULL; Creature * pCreature = NULL; if(sp->vehicle) { pCreature = TO_CREATURE(mapMgr->CreateVehicle(entry)); TO_VEHICLE(pCreature)->Load(sp, mapMgr->iInstanceMode, NULL); } else { pCreature = mapMgr->CreateCreature(entry); pCreature->Load(sp, mapMgr->iInstanceMode, NULL); } pCreature->m_loadedFromDB = true; pCreature->SetFaction(faction); pCreature->SetInstanceID(instanceid); pCreature->SetMapId(map); pCreature->m_noRespawn = true; pCreature->PushToWorld(mapMgr); if (duration>0) pCreature->Despawn(duration,0); if (save) pCreature->SaveToDB(); Lunar<Unit>::push(L,TO_UNIT(pCreature)); } else if (spawntype == 2) //GO { GameObjectInfo *n = GameObjectNameStorage.LookupEntry(entry); if (n == NULL) RET_NIL(true); MapMgr *mapMgr = sInstanceMgr.GetMapMgr(map); if (mapMgr == NULL) RET_NIL(true); int32 instanceid = luaL_optint(L, 13, mapMgr->GetInstanceID()); GameObject *go = mapMgr->CreateGameObject(entry); go->SetInstanceID(instanceid); go->CreateFromProto(entry,map,x,y,z,o); // Create spawn instance GOSpawn * gs = new GOSpawn; gs->entry = go->GetEntry(); gs->facing = go->GetOrientation(); gs->faction = go->GetFaction(); gs->flags = go->GetUInt32Value(GAMEOBJECT_FLAGS); gs->id = objmgr.GenerateGameObjectSpawnID(); gs->scale = go->GetUInt32Value(OBJECT_FIELD_SCALE_X); gs->x = go->GetPositionX(); gs->y = go->GetPositionY(); gs->z = go->GetPositionZ(); gs->state = go->GetByte(GAMEOBJECT_BYTES_1, 0); gs->phase = 0; go->m_spawn = gs; go->PushToWorld(mapMgr); if (duration) sEventMgr.AddEvent(go,&GameObject::ExpireAndDelete,EVENT_GAMEOBJECT_UPDATE,duration,1,EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT); if (save) go->SaveToDB(); Lunar<GameObject>::push(L,go); } else RET_NIL(true); } else RET_NIL(true); return 1; }