void GameEventMgr::StartArenaEvents() { for (auto i = 57; i <= 60; ++i) { auto gameEvent = GetEventById(i); if (gameEvent == nullptr) { Log.Error("GameEventMgr", "Missing arena event (id: %u)", i); continue; } if (i - 52 == sWorld.Arena_Season && sWorld.Arena_Progress == 1) gameEvent->SetState(GAMEEVENT_ACTIVE_FORCED); else gameEvent->SetState(GAMEEVENT_INACTIVE_FORCED); } }
// copy event to another date (all invitee is copied too but their status are reseted) void CalendarMgr::CopyEvent(uint64 eventId, time_t newTime, ObjectGuid const& guid) { Player* player = sObjectMgr.GetPlayer(guid); CalendarEvent* event = GetEventById(eventId); if (!event) { SendCalendarCommandResult(player, CALENDAR_ERROR_EVENT_INVALID); return; } CalendarEvent* newEvent = AddEvent(guid, event->Title, event->Description, event->Type, event->Repeatable, CALENDAR_MAX_INVITES, event->DungeonId, newTime, event->UnknownTime, event->Flags); if (!newEvent) return; if (newEvent->IsGuildAnnouncement()) AddInvite(newEvent, guid, guid, CALENDAR_STATUS_CONFIRMED, CALENDAR_RANK_OWNER, "", time(NULL)); else { // copy all invitees, set new owner as the one who make the copy, set invitees status to invited CalendarInviteMap const* cInvMap = event->GetInviteMap(); CalendarInviteMap::const_iterator ci_itr = cInvMap->begin(); while (ci_itr != cInvMap->end()) { const CalendarInvite* invite = ci_itr->second; if (invite->InviteeGuid == guid) { AddInvite(newEvent, guid, invite->InviteeGuid, CALENDAR_STATUS_CONFIRMED, CALENDAR_RANK_OWNER, "", time(NULL)); } else { CalendarModerationRank rank = CALENDAR_RANK_PLAYER; // copy moderator rank if (invite->Rank == CALENDAR_RANK_MODERATOR) rank = CALENDAR_RANK_MODERATOR; AddInvite(newEvent, guid, invite->InviteeGuid, CALENDAR_STATUS_INVITED, rank, "", time(NULL)); } ++ci_itr; } } SendCalendarEvent(player, newEvent, CALENDAR_SENDTYPE_COPY); }
void GameEventMgr::LoadFromDB() { // Clean event_saves from CharacterDB Log.Notice("GameEventMgr", "Start cleaning event_save"); { const char* cleanEventSaveQuery = "DELETE FROM event_save WHERE state<>4"; CharacterDatabase.Execute(cleanEventSaveQuery); } // Loading event_names { const char* loadAllEventsQuery = "SELECT entry, UNIX_TIMESTAMP(start_time), UNIX_TIMESTAMP(end_time), occurence,\ length, holiday, description, world_event, announce\ FROM event_names WHERE entry > 0"; QueryResult* result = WorldDatabase.Query(loadAllEventsQuery); if (!result) { //mGameEvent.clear(); Log.Error("GameEventMgr", "Query failed: %s", loadAllEventsQuery); return; } uint32 pCount = 0; do { Field* field = result->Fetch(); EventNamesQueryResult dbResult; dbResult.entry = field[0].GetUInt32(); dbResult.start_time = field[1].GetUInt32(); dbResult.end_time = field[2].GetUInt32(); dbResult.occurence = field[3].GetUInt32(); dbResult.length = field[4].GetUInt32(); dbResult.holiday_id = HolidayIds(field[5].GetUInt32()); dbResult.description = field[6].GetString(); dbResult.world_event = GameEventState(field[7].GetUInt8()); dbResult.announce = field[8].GetUInt8(); GameEvent gameEvent = GameEvent(dbResult); //if (gameEvent.isValid()) //{ mGameEvents.insert(std::make_pair(dbResult.entry, new GameEvent(dbResult))); Log.Debug("GameEventMgr", "%s, Entry: %u, State: %u, Holiday: %u loaded", dbResult.description.c_str(), dbResult.entry, dbResult.world_event, dbResult.holiday_id); ++pCount; //} //else //{ // Log.Debug("GameEventMgr", "%s game event Entry: %u isn't a world event and has length = 0, thus it can't be used.", dbResult.description.c_str(), dbResult.entry); //} } while (result->NextRow()); delete result; Log.Success("GameEventMgr", "%u events loaded from table event_names", pCount); } // Loading event_saves from CharacterDB Log.Notice("GameEventMgr", "Start loading event_save"); { const char* loadEventSaveQuery = "SELECT event_entry, state, next_start FROM event_save"; bool success = false; QueryResult* result = CharacterDatabase.Query(&success, loadEventSaveQuery); if (!success) { Log.Error("GameEventMgr", "Query failed: %s", loadEventSaveQuery); return; } uint32 pCount = 0; if (result) { do { Field* field = result->Fetch(); uint32 event_id = field[0].GetUInt8(); auto gameEvent = GetEventById(event_id); if (gameEvent == nullptr) { Log.Error("GameEventMgr", "Could not find event for event_save entry %u", event_id); continue; } gameEvent->state = (GameEventState)(field[1].GetUInt8()); gameEvent->nextstart = time_t(field[2].GetUInt32()); ++pCount; } while (result->NextRow()); delete result; } Log.Success("GameEventMgr", "Loaded %u saved events loaded from table event_saves", pCount); } // Loading event_creature from WorldDB Log.Notice("GameEventMgr", "Start loading game event creature spawns"); { const char* loadEventCreatureSpawnsQuery = "SELECT event_entry, id, entry, map, position_x, position_y, position_z, \ orientation, movetype, displayid, faction, flags, bytes0, bytes1, bytes2, \ emote_state, npc_respawn_link, channel_spell, channel_target_sqlid, \ channel_target_sqlid_creature, standstate, death_state, mountdisplayid, \ slot1item, slot2item, slot3item, CanFly, phase, waypoint_group \ FROM event_creature_spawns"; bool success = false; QueryResult* result = WorldDatabase.Query(&success, loadEventCreatureSpawnsQuery); if (!success) { Log.Error("GameEventMgr", "Query failed: %s", loadEventCreatureSpawnsQuery); return; } uint32 pCount = 0; if (result) { do { Field* field = result->Fetch(); uint32 event_id = field[0].GetUInt32(); auto gameEvent = GetEventById(event_id); if (gameEvent == nullptr) { Log.Error("GameEventMgr", "Could not find event for event_creature_spawns entry %u", event_id); continue; } EventCreatureSpawnsQueryResult dbResult; dbResult.event_entry = field[0].GetUInt32(); dbResult.id = field[1].GetUInt32(); dbResult.entry = field[2].GetUInt32(); auto creature_info = sMySQLStore.GetCreatureInfo(dbResult.entry); if (creature_info == nullptr) { Log.Error("GameEventMgr", "Could not create CreatureSpawn for invalid entry %u (missing in table creature_names)", dbResult.entry); continue; } dbResult.map_id = field[3].GetUInt16(); dbResult.position_x = field[4].GetFloat(); dbResult.position_y = field[5].GetFloat(); dbResult.position_z = field[6].GetFloat(); dbResult.orientation = field[7].GetFloat(); dbResult.movetype = field[8].GetUInt8(); dbResult.displayid = field[9].GetUInt32(); dbResult.faction = field[10].GetUInt32(); dbResult.flags = field[11].GetUInt32(); dbResult.bytes0 = field[12].GetUInt32(); dbResult.bytes1 = field[13].GetUInt32(); dbResult.bytes2 = field[14].GetUInt32(); dbResult.emote_state = field[15].GetUInt16(); dbResult.npc_respawn_link = field[16].GetUInt32(); dbResult.channel_spell = field[17].GetUInt32(); dbResult.channel_target_sqlid = field[18].GetUInt32(); dbResult.channel_target_sqlid_creature = field[19].GetUInt32(); dbResult.standstate = field[20].GetUInt8(); dbResult.death_state = field[21].GetUInt8(); dbResult.mountdisplayid = field[22].GetUInt32(); dbResult.slot1item = field[23].GetUInt32(); dbResult.slot2item = field[24].GetUInt32(); dbResult.slot3item = field[25].GetUInt32(); dbResult.CanFly = field[26].GetUInt16(); dbResult.phase = field[27].GetUInt32(); dbResult.waypoint_group = field[28].GetUInt32(); gameEvent->npc_data.push_back(dbResult); ++pCount; //mNPCGuidList.insert(NPCGuidList::value_type(event_id, id)); } while (result->NextRow()); delete result; } Log.Success("GameEventMgr", "%u creature spawns for %u events from table event_creature_spawns loaded.", pCount, mGameEvents.size()); } // Loading event_gameobject from WorldDB Log.Notice("GameEventMgr", "Start loading game event gameobject spawns"); { const char* loadEventGameobjectSpawnsQuery = "SELECT event_entry, id, entry, map, position_x, position_y, \ position_z, facing, orientation1, orientation2, orientation3, \ orientation4, state, flags, faction, scale, respawnNpcLink, phase, \ overrides FROM event_gameobject_spawns"; bool success = false; QueryResult* result = WorldDatabase.Query(&success, loadEventGameobjectSpawnsQuery); if (!success) { Log.Error("GameEventMgr", "Query failed: %s", loadEventGameobjectSpawnsQuery); return; } uint32 pCount = 0; if (result) { do { Field* field = result->Fetch(); uint32 event_id = field[0].GetUInt32(); auto gameEvent = GetEventById(event_id); if (gameEvent == nullptr) { Log.Error("GameEventMgr", "Could not find event for event_gameobject_spawns entry %u", event_id); continue; } EventGameObjectSpawnsQueryResult dbResult; dbResult.event_entry = field[0].GetUInt32(); dbResult.id = field[1].GetUInt32(); dbResult.entry = field[2].GetUInt32(); auto gameobject_info = sMySQLStore.GetGameObjectInfo(dbResult.entry); if (gameobject_info == nullptr) { Log.Error("GameEventMgr", "Could not create GameobjectSpawn for invalid entry %u (missing in table gameobject_names)", dbResult.entry); continue; } dbResult.map_id = field[3].GetUInt32(); dbResult.position_x = field[4].GetFloat(); dbResult.position_y = field[5].GetFloat(); dbResult.position_z = field[6].GetFloat(); dbResult.facing = field[7].GetFloat(); dbResult.orientation1 = field[8].GetFloat(); dbResult.orientation2 = field[9].GetFloat(); dbResult.orientation3 = field[10].GetFloat(); dbResult.orientation4 = field[11].GetFloat(); dbResult.state = field[12].GetUInt32(); dbResult.flags = field[13].GetUInt32(); dbResult.faction = field[14].GetUInt32(); dbResult.scale = field[15].GetFloat(); dbResult.stateNpcLink = field[16].GetFloat(); dbResult.phase = field[17].GetUInt32(); dbResult.overrides = field[18].GetUInt32(); gameEvent->gameobject_data.push_back(dbResult); ++pCount; //mGOBGuidList.insert(GOBGuidList::value_type(event_id, id)); } while (result->NextRow()); delete result; } Log.Success("GameEventMgr", "%u gameobject spawns for %u events from table event_gameobject_spawns loaded.", pCount, mGameEvents.size()); } StartArenaEvents(); }
// load all events and their related invites from invite void CalendarMgr::LoadCalendarsFromDB() { // in case of reload (not yet implemented) m_MaxInviteId = 0; m_MaxEventId = 0; m_EventStore.clear(); sLog.outString("Loading Calendar Events..."); // 0 1 2 3 4 5 6 7 8 QueryResult* eventsQuery = CharacterDatabase.Query("SELECT eventId, creatorGuid, guildId, type, flags, dungeonId, eventTime, title, description FROM calendar_events ORDER BY eventId"); if (!eventsQuery) { BarGoLink bar(1); bar.step(); sLog.outString(); sLog.outString(">> calendar_events table is empty!"); } else { BarGoLink bar(eventsQuery->GetRowCount()); do { Field* field = eventsQuery->Fetch(); bar.step(); uint64 eventId = field[0].GetUInt64(); CalendarEvent& newEvent = m_EventStore[eventId]; newEvent.EventId = eventId; newEvent.CreatorGuid = ObjectGuid(HIGHGUID_PLAYER, field[1].GetUInt32()); newEvent.GuildId = field[2].GetUInt32(); newEvent.Type = CalendarEventType(field[3].GetUInt8()); newEvent.Flags = field[4].GetUInt32(); newEvent.DungeonId = field[5].GetInt32(); newEvent.EventTime = time_t(field[6].GetUInt32()); newEvent.Title = field[7].GetCppString(); newEvent.Description = field[8].GetCppString(); m_MaxEventId = std::max(eventId, m_MaxEventId); } while (eventsQuery->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u events!", uint32(eventsQuery->GetRowCount())); delete eventsQuery; } sLog.outString("Loading Calendar invites..."); // 0 1 2 3 4 5 6 QueryResult* invitesQuery = CharacterDatabase.Query("SELECT inviteId, eventId, inviteeGuid, senderGuid, status, lastUpdateTime, rank FROM calendar_invites ORDER BY inviteId"); if (!invitesQuery) { BarGoLink bar(1); bar.step(); sLog.outString(); if (m_MaxEventId) // An Event was loaded before { // delete all events (no event exist without at least one invite) m_EventStore.clear(); m_MaxEventId = 0; CharacterDatabase.DirectExecute("TRUNCATE TABLE calendar_events"); sLog.outString(">> calendar_invites table is empty, cleared calendar_events table!"); } else sLog.outString(">> calendar_invite table is empty!"); } else { if (m_MaxEventId) { uint64 totalInvites = 0; uint32 deletedInvites = 0; BarGoLink bar(invitesQuery->GetRowCount()); do { Field* field = invitesQuery->Fetch(); uint64 inviteId = field[0].GetUInt64(); uint64 eventId = field[1].GetUInt64(); ObjectGuid inviteeGuid = ObjectGuid(HIGHGUID_PLAYER, field[2].GetUInt32()); ObjectGuid senderGuid = ObjectGuid(HIGHGUID_PLAYER, field[3].GetUInt32()); CalendarInviteStatus status = CalendarInviteStatus(field[4].GetUInt8()); time_t lastUpdateTime = time_t(field[5].GetUInt32()); CalendarModerationRank rank = CalendarModerationRank(field[6].GetUInt8()); CalendarEvent* event = GetEventById(eventId); if (!event) { // delete invite CharacterDatabase.PExecute("DELETE FROM calendar_invites WHERE inviteId =" UI64FMTD, field[0].GetUInt64()); ++deletedInvites; continue; } CalendarInvite* invite = new CalendarInvite(event, inviteId, senderGuid, inviteeGuid, lastUpdateTime, status, rank, ""); event->AddInvite(invite); ++totalInvites; m_MaxInviteId = std::max(inviteId, m_MaxInviteId); } while (invitesQuery->NextRow()); sLog.outString(); sLog.outString(">> Loaded " UI64FMTD " invites! %s", totalInvites, (deletedInvites != 0) ? "(deleted some invites without corresponding event!)" : ""); } else { // delete all invites (no invites exist without events) CharacterDatabase.DirectExecute("TRUNCATE TABLE calendar_invites"); sLog.outString(">> calendar_invites table is cleared! (invites without events found)"); } delete invitesQuery; } sLog.outString(); }