// 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); }
// fill all player invites in provided CalendarInvitesList void CalendarMgr::GetPlayerInvitesList(ObjectGuid const& guid, CalendarInvitesList& calInvList) { for (CalendarEventStore::iterator itr = m_EventStore.begin(); itr != m_EventStore.end(); ++itr) { CalendarEvent* event = &itr->second; if (event->IsGuildAnnouncement()) continue; CalendarInviteMap const* cInvMap = event->GetInviteMap(); CalendarInviteMap::const_iterator ci_itr = cInvMap->begin(); while (ci_itr != cInvMap->end()) { if (ci_itr->second->InviteeGuid == guid) { calInvList.push_back(ci_itr->second); break; } ++ci_itr; } } }
// check if an invitee have not reached invite limit bool CalendarMgr::CanAddInviteTo(ObjectGuid const& guid) { uint32 totalInvites = 0; for (CalendarEventStore::iterator itr = m_EventStore.begin(); itr != m_EventStore.end(); ++itr) { CalendarEvent* event = &itr->second; if (event->IsGuildAnnouncement()) continue; CalendarInviteMap const* cInvMap = event->GetInviteMap(); CalendarInviteMap::const_iterator ci_itr = cInvMap->begin(); while (ci_itr != cInvMap->end()) { if ((ci_itr->second->InviteeGuid == guid) && (++totalInvites >= CALENDAR_MAX_INVITES)) return false; ++ci_itr; } } return true; }