void HandleCalendarGetCalendar(CalendarGetCalendar calendarGetCalendar) { ObjectGuid guid = GetPlayer().GetGUID(); long currTime = Time.UnixTime; CalendarSendCalendar packet = new CalendarSendCalendar(); packet.ServerTime = currTime; var invites = Global.CalendarMgr.GetPlayerInvites(guid); foreach (var invite in invites) { CalendarSendCalendarInviteInfo inviteInfo = new CalendarSendCalendarInviteInfo(); inviteInfo.EventID = invite.EventId; inviteInfo.InviteID = invite.InviteId; inviteInfo.InviterGuid = invite.SenderGuid; inviteInfo.Status = invite.Status; inviteInfo.Moderator = invite.Rank; CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(invite.EventId); if (calendarEvent != null) { inviteInfo.InviteType = (byte)(calendarEvent.IsGuildEvent() && calendarEvent.GuildId == _player.GetGuildId() ? 1 : 0); } packet.Invites.Add(inviteInfo); } var playerEvents = Global.CalendarMgr.GetPlayerEvents(guid); foreach (var calendarEvent in playerEvents) { CalendarSendCalendarEventInfo eventInfo; eventInfo.EventID = calendarEvent.EventId; eventInfo.Date = calendarEvent.Date; eventInfo.EventClubID = calendarEvent.GuildId; eventInfo.EventName = calendarEvent.Title; eventInfo.EventType = calendarEvent.EventType; eventInfo.Flags = calendarEvent.Flags; eventInfo.OwnerGuid = calendarEvent.OwnerGuid; eventInfo.TextureID = calendarEvent.TextureId; packet.Events.Add(eventInfo); } foreach (var difficulty in CliDB.DifficultyStorage.Values) { var boundInstances = _player.GetBoundInstances((Difficulty)difficulty.Id); if (boundInstances != null) { foreach (var boundInstance in boundInstances.Values) { if (boundInstance.perm) { CalendarSendCalendarRaidLockoutInfo lockoutInfo; InstanceSave save = boundInstance.save; lockoutInfo.MapID = (int)save.GetMapId(); lockoutInfo.DifficultyID = (uint)save.GetDifficultyID(); lockoutInfo.ExpireTime = save.GetResetTime() - currTime; lockoutInfo.InstanceID = save.GetInstanceId(); // instance save id as unique instance copy id packet.RaidLockouts.Add(lockoutInfo); } } } } SendPacket(packet); }
public InstanceBind BindToInstance(InstanceSave save, bool permanent, BindExtensionState extendState = BindExtensionState.Normal, bool load = false) { if (save != null) { InstanceBind bind = new InstanceBind(); if (m_boundInstances[(int)save.GetDifficultyID()].ContainsKey(save.GetMapId())) { bind = m_boundInstances[(int)save.GetDifficultyID()][save.GetMapId()]; } if (extendState == BindExtensionState.Keep) // special flag, keep the player's current extend state when updating for new boss down { if (save == bind.save) { extendState = bind.extendState; } else { extendState = BindExtensionState.Normal; } } if (!load) { PreparedStatement stmt; if (bind.save != null) { // update the save when the group kills a boss if (permanent != bind.perm || save != bind.save || extendState != bind.extendState) { stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHAR_INSTANCE); stmt.AddValue(0, save.GetInstanceId()); stmt.AddValue(1, permanent); stmt.AddValue(2, extendState); stmt.AddValue(3, GetGUID().GetCounter()); stmt.AddValue(4, bind.save.GetInstanceId()); DB.Characters.Execute(stmt); } } else { stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_CHAR_INSTANCE); stmt.AddValue(0, GetGUID().GetCounter()); stmt.AddValue(1, save.GetInstanceId()); stmt.AddValue(2, permanent); stmt.AddValue(3, extendState); DB.Characters.Execute(stmt); } } if (bind.save != save) { if (bind.save != null) { bind.save.RemovePlayer(this); } save.AddPlayer(this); } if (permanent) { save.SetCanReset(false); } bind.save = save; bind.perm = permanent; bind.extendState = extendState; if (!load) { Log.outDebug(LogFilter.Maps, "Player.BindToInstance: Player '{0}' ({1}) is now bound to map (ID: {2}, Instance {3}, Difficulty {4})", GetName(), GetGUID().ToString(), save.GetMapId(), save.GetInstanceId(), save.GetDifficultyID()); } Global.ScriptMgr.OnPlayerBindToInstance(this, save.GetDifficultyID(), save.GetMapId(), permanent, extendState); m_boundInstances[(int)save.GetDifficultyID()][save.GetMapId()] = bind; return(bind); } return(null); }
// Reset all solo instances and optionally send a message on success for each public void ResetInstances(InstanceResetMethod method, bool isRaid, bool isLegacy) { // method can be INSTANCE_RESET_ALL, INSTANCE_RESET_CHANGE_DIFFICULTY, INSTANCE_RESET_GROUP_JOIN // we assume that when the difficulty changes, all instances that can be reset will be Difficulty difficulty = GetDungeonDifficultyID(); if (isRaid) { if (!isLegacy) { difficulty = GetRaidDifficultyID(); } else { difficulty = GetLegacyRaidDifficultyID(); } } var difficultyDic = m_boundInstances.LookupByKey(difficulty); if (difficultyDic == null) { return; } foreach (var pair in difficultyDic) { InstanceSave p = pair.Value.save; MapRecord entry = CliDB.MapStorage.LookupByKey(difficulty); if (entry == null || entry.IsRaid() != isRaid || !p.CanReset()) { continue; } if (method == InstanceResetMethod.All) { // the "reset all instances" method can only reset normal maps if (entry.InstanceType == MapTypes.Raid || difficulty == Difficulty.Heroic) { continue; } } // if the map is loaded, reset it Map map = Global.MapMgr.FindMap(p.GetMapId(), p.GetInstanceId()); if (map != null && map.IsDungeon()) { if (!map.ToInstanceMap().Reset(method)) { continue; } } // since this is a solo instance there should not be any players inside if (method == InstanceResetMethod.All || method == InstanceResetMethod.ChangeDifficulty) { SendResetInstanceSuccess(p.GetMapId()); } p.DeleteFromDB(); difficultyDic.Remove(pair.Key); // the following should remove the instance save from the manager and delete it as well p.RemovePlayer(this); } }