uint32 Transporter::AddNPCPassenger(uint32 tguid, uint32 entry, float x, float y, float z, float o, uint32 anim) { MapMgr* map = GetMapMgr(); CreatureProperties const* creature_properties = sMySQLStore.getCreatureProperties(entry); if (creature_properties == nullptr || map == nullptr) return 0; #if VERSION_STRING != Cata float transporter_x = obj_movement_info.transport_data.relativePosition.x + x; float transporter_y = obj_movement_info.transport_data.relativePosition.y + y; float transporter_z = obj_movement_info.transport_data.relativePosition.z + z; #else float transporter_x = obj_movement_info.getTransportPosition()->x + x; float transporter_y = obj_movement_info.getTransportPosition()->y + y; float transporter_z = obj_movement_info.getTransportPosition()->z + z; #endif Creature* pCreature = map->CreateCreature(entry); pCreature->Create(map->GetMapId(), transporter_x, transporter_y, transporter_z, (std::atan2(transporter_x, transporter_y) + float(M_PI)) + o); pCreature->Load(creature_properties, transporter_x, transporter_y, transporter_z, (std::atan2(transporter_x, transporter_y) + float(M_PI)) + o); pCreature->AddToWorld(map); pCreature->SetUnitMovementFlags(MOVEFLAG_TRANSPORT); #if VERSION_STRING != Cata pCreature->obj_movement_info.transport_data.relativePosition.x = x; pCreature->obj_movement_info.transport_data.relativePosition.y = y; pCreature->obj_movement_info.transport_data.relativePosition.z = z; pCreature->obj_movement_info.transport_data.relativePosition.o = o; pCreature->obj_movement_info.transport_data.transportGuid = getGuid(); #else pCreature->obj_movement_info.setTransportData(getGuid(), x, y, z, o, 0, 0); #endif pCreature->m_transportData.transportGuid = this->getGuid(); pCreature->m_transportData.relativePosition.x = x; pCreature->m_transportData.relativePosition.y = y; pCreature->m_transportData.relativePosition.z = z; pCreature->m_transportData.relativePosition.o = o; if (anim) pCreature->setUInt32Value(UNIT_NPC_EMOTESTATE, anim); if (creature_properties->NPCFLags) pCreature->setUInt32Value(UNIT_NPC_FLAGS, creature_properties->NPCFLags); m_creatureSetMutex.Acquire(); m_NPCPassengerSet.insert(pCreature); m_creatureSetMutex.Release(); if (tguid == 0) { ++currenttguid; tguid = currenttguid; } else currenttguid = std::max(tguid, currenttguid); return tguid; }
Creature* Transporter::AddNPCPassengerInInstance(uint32 entry, float x, float y, float z, float o, uint32 /*anim*/) { MapMgr* map = GetMapMgr(); CreatureProperties const* creature_properties = sMySQLStore.getCreatureProperties(entry); if (creature_properties == nullptr || map == nullptr) return nullptr; #if VERSION_STRING != Cata float transporter_x = obj_movement_info.transport_data.relativePosition.x + x; float transporter_y = obj_movement_info.transport_data.relativePosition.y + y; float transporter_z = obj_movement_info.transport_data.relativePosition.z + z; #else float transporter_x = obj_movement_info.getTransportPosition()->x + x; float transporter_y = obj_movement_info.getTransportPosition()->y + y; float transporter_z = obj_movement_info.getTransportPosition()->z + z; #endif Creature* pCreature = map->CreateCreature(entry); pCreature->Create(map->GetMapId(), transporter_x, transporter_y, transporter_z, (std::atan2(transporter_x, transporter_y) + float(M_PI)) + o); pCreature->Load(creature_properties, transporter_x, transporter_y, transporter_z, (std::atan2(transporter_x, transporter_y) + float(M_PI)) + o); pCreature->AddToWorld(map); pCreature->SetUnitMovementFlags(MOVEFLAG_TRANSPORT); #if VERSION_STRING != Cata pCreature->obj_movement_info.transport_data.relativePosition.x = x; pCreature->obj_movement_info.transport_data.relativePosition.y = y; pCreature->obj_movement_info.transport_data.relativePosition.z = z; pCreature->obj_movement_info.transport_data.relativePosition.o = o; pCreature->obj_movement_info.transport_data.transportGuid = getGuid(); #else pCreature->obj_movement_info.setTransportData(getGuid(), x, y, z, o, 0, 0); #endif pCreature->m_transportData.transportGuid = this->getGuid(); pCreature->m_transportData.relativePosition.x = x; pCreature->m_transportData.relativePosition.y = y; pCreature->m_transportData.relativePosition.z = z; pCreature->m_transportData.relativePosition.o = o; m_creatureSetMutex.Acquire(); m_NPCPassengerSet.insert(pCreature); m_creatureSetMutex.Release(); return pCreature; }
void Vehicle::InstallAccessories() { CreatureProtoVehicle* acc = CreatureProtoVehicleStorage.LookupEntry(GetEntry()); if(acc == NULL) { sLog.outDetail("Vehicle %u has no accessories.", GetEntry()); return; } MapMgr* map = (GetMapMgr() ? GetMapMgr() : sInstanceMgr.GetMapMgr(GetMapId())); if(map == NULL) // Shouldn't ever really happen. return; for(int i = 0; i < 8; i++) { SeatInfo seatinfo = acc->seats[i]; if(!seatinfo.accessoryentry || (seatinfo.accessoryentry == GetEntry())) continue; if(m_vehicleSeats[i] == NULL) { sLog.outDetail("No seatmap for selected seat.\n"); continue; } // Load the Proto CreatureProto* proto = CreatureProtoStorage.LookupEntry(seatinfo.accessoryentry); CreatureInfo* info = CreatureNameStorage.LookupEntry(seatinfo.accessoryentry); if(!proto || !info) { sLog.outError("No proto/info for vehicle accessory %u in vehicle %u", seatinfo.accessoryentry, GetEntry()); continue; } // Remove any passengers. if(m_passengers[i]) RemovePassenger(m_passengers[i]); if(proto->vehicle_entry > 0) { // Create the Vehicle! Vehicle* pass = map->CreateVehicle(seatinfo.accessoryentry); if(pass != NULL && pass) { pass->Load(proto, (IsInInstance() ? map->iInstanceMode : MODE_5PLAYER_NORMAL), GetPositionX()+m_vehicleSeats[i]->m_attachmentOffsetX, GetPositionY()+m_vehicleSeats[i]->m_attachmentOffsetY, GetPositionZ()+m_vehicleSeats[i]->m_attachmentOffsetZ); pass->Init(); pass->m_TransporterGUID = GetGUID(); pass->InitSeats(proto->vehicle_entry); if(pass->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK)) pass->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK); // Accessory AddPassenger(pass, i, true); pass->PushToWorld(map); } } else { // Create the Unit! Creature* pass = map->CreateCreature(seatinfo.accessoryentry); if(pass != NULL) { pass->Load(proto, map->iInstanceMode, GetPositionX()+m_vehicleSeats[i]->m_attachmentOffsetX, GetPositionY()+m_vehicleSeats[i]->m_attachmentOffsetY, GetPositionZ()+m_vehicleSeats[i]->m_attachmentOffsetZ); pass->Init(); pass->m_TransporterGUID = GetGUID(); AddPassenger(pass, i, true); pass->PushToWorld(map); } } } }
void GameEventMgr::ProcessObjectsAndScriptsProc(QueryResultVector & results, uint32 id) { // process scripts if(QueryResult *query = results[0].result) { do { Field * f = query->Fetch(); uint32 mapid = f[1].GetUInt32(); uint32 sql_id = f[2].GetUInt32(); uint8 type = f[3].GetUInt8(); uint32 data1 = f[4].GetUInt32(); uint32 data2 = f[5].GetUInt32(); uint32 data3 = f[6].GetUInt32(); char * say = strdup(f[7].GetString()); DoScript(id, sql_id, type, data1, data2, data3, say, mapid); } while(query->NextRow()); } // waypoints -- the created objects will be deleted automatically by creature class on despawn std::map<uint32, std::map<uint32, std::list<WayPoint *>>> waypoints; if(QueryResult *query = results[1].result) { do { Field * f = query->Fetch(); WayPoint *wp = new WayPoint; //uint32 event = f[0].GetUInt32(); uint32 spawnid = f[1].GetUInt32(); wp->id = f[2].GetUInt32(); wp->x = f[3].GetFloat(); wp->y = f[4].GetFloat(); wp->z = f[5].GetFloat(); wp->waittime = f[6].GetUInt32(); wp->flags = f[7].GetUInt32(); wp->forwardemoteoneshot = f[8].GetBool(); wp->forwardemoteid = f[9].GetUInt32(); wp->backwardemoteoneshot = f[10].GetBool(); wp->backwardemoteid = f[11].GetUInt32(); wp->forwardskinid = f[12].GetUInt32(); wp->backwardskinid = f[13].GetUInt32(); waypoints[id][spawnid].push_back(wp); } while(query->NextRow()); } // creature spawns if(QueryResult *query = results[2].result) { do { Field * f = query->Fetch(); CreatureSpawn spawn; //uint32 event = f[0].GetUInt32(); uint32 spawn_id = f[1].GetUInt32(); spawn.id = 0; spawn.entry = f[2].GetUInt32(); uint32 mapid = f[3].GetUInt32(); spawn.x = f[4].GetFloat(); spawn.y = f[5].GetFloat(); spawn.z = f[6].GetFloat(); spawn.o = f[7].GetFloat(); spawn.form = NULL; spawn.movetype = f[8].GetUInt8(); spawn.displayid = f[9].GetUInt32(); spawn.factionid = f[10].GetUInt32(); spawn.flags = f[11].GetUInt32(); spawn.bytes0 = f[12].GetUInt32(); spawn.bytes1 = f[13].GetUInt32(); spawn.bytes2 = f[14].GetUInt32(); spawn.emote_state = f[15].GetUInt32(); //uint32 npc_respawn_link = f[17].GetUInt32(); spawn.channel_spell = f[17].GetUInt16(); spawn.channel_target_go = f[18].GetUInt32(); spawn.channel_target_creature = f[19].GetUInt32(); spawn.stand_state = f[20].GetUInt16(); spawn.death_state = f[21].GetUInt32(); spawn.MountedDisplayID = f[22].GetUInt32(); spawn.Item1SlotDisplay = f[23].GetUInt32(); spawn.Item2SlotDisplay = f[24].GetUInt32(); spawn.Item3SlotDisplay = f[25].GetUInt32(); spawn.CanFly = f[26].GetUInt32(); spawn.phase = f[27].GetUInt32(); if(spawn.phase == 0) spawn.phase = 0xFFFFFFFF; CreatureProto* proto = CreatureProtoStorage.LookupEntry(spawn.entry); CreatureInfo* info = CreatureNameStorage.LookupEntry(spawn.entry); if(proto == NULL || info == NULL) { continue; } // get mapmgr for spawn MapMgr * mgr = sInstanceMgr.GetMapMgr(mapid); if(mgr == NULL) { // So this is a really interesting situation! Log.Success("GameEvent","Failed to spawn creature spawn %u for event %u on nonexistant map %u", spawn.id, id, mapid); continue; } // spawn the creature //Creature * crt = mgr->GetInterface()->SpawnCreature(&spawn, true); Creature * crt = mgr->CreateCreature(spawn.entry); if(crt == NULL) { // we didnt succeed creating the creature! Print a warning and go on Log.Success("GameEvent","Failed to spawn creature spawn %u for event %u", spawn.id, id); continue; } crt->Load(&spawn, 0, mgr->GetMapInfo()); crt->spawnid = 0; crt->m_spawn = NULL; // add waypoints crt->m_custom_waypoint_map = new WayPointMap(); for(std::list<WayPoint *>::iterator itr = waypoints[id][spawn_id].begin(); itr != waypoints[id][spawn_id].end(); itr++) { // use custom waypoint map, so we avoid saving it to database crt->m_custom_waypoint_map->push_back(*itr); } crt->GetAIInterface()->SetWaypointMap(crt->m_custom_waypoint_map); crt->AddToWorld(mgr); m_creaturespawns[id][mapid].push_back(crt->GetUIdFromGUID()); } while(query->NextRow()); } // gameobject spawns if(QueryResult *query = results[3].result) { do { Field * f = query->Fetch(); GOSpawn spawn; //uint32 event = f[0].GetUInt32(); uint32 spawn_id = f[1].GetUInt32(); // generate new ingame sql id spawn.id = /*objmgr.GenerateCreatureSpawnID()*/0; spawn.entry = f[2].GetUInt32(); uint32 mapid = f[3].GetUInt32(); spawn.x = f[4].GetFloat(); spawn.y = f[5].GetFloat(); spawn.z = f[6].GetFloat(); spawn.facing = f[7].GetFloat(); spawn.o = f[8].GetFloat(); spawn.o1 = f[9].GetFloat(); spawn.o2 = f[10].GetFloat(); spawn.o3 = f[11].GetFloat(); spawn.state = f[12].GetUInt32(); spawn.flags = f[13].GetUInt32(); spawn.faction = f[14].GetUInt32(); spawn.scale = f[15].GetFloat(); //uint32 state_npc_link = fields[16].GetUInt32(); spawn.phase = f[17].GetUInt32(); if(spawn.phase == 0) spawn.phase = 0xFFFFFFFF; spawn.overrides = f[18].GetUInt32(); // get mapmgr for spawn MapMgr * mgr = sInstanceMgr.GetMapMgr(mapid); if(mgr == NULL) { // So this is a really interesting situation! Log.Success("GameEvent","Failed to spawn gameobject spawn %u for event %u on nonexistant map %u", spawn.id, id, mapid); continue; } // spawn the creature GameObject * go = mgr->CreateGameObject(spawn.entry); if(go == NULL) { // we didnt succeed creating the creature! Print a warning and go on Log.Success("GameEvent","Failed to spawn gameobject spawn %u for event %u", spawn.id, id); continue; } go->Load(&spawn); go->m_spawn = NULL; go->AddToWorld(mgr); m_gameobjectspawns[id][mapid].push_back(go->GetUIdFromGUID()); } while(query->NextRow()); } Log.Success("GameEvent","event %u spawned.", id); }
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; }