Exemple #1
0
        void HandleSetSavedInstanceExtend(SetSavedInstanceExtend setSavedInstanceExtend)
        {
            Player player = GetPlayer();

            if (player)
            {
                InstanceBind instanceBind = player.GetBoundInstance((uint)setSavedInstanceExtend.MapID, (Difficulty)setSavedInstanceExtend.DifficultyID, setSavedInstanceExtend.Extend); // include expired instances if we are toggling extend on
                if (instanceBind == null || instanceBind.save == null || !instanceBind.perm)
                {
                    return;
                }

                BindExtensionState newState;
                if (!setSavedInstanceExtend.Extend || instanceBind.extendState == BindExtensionState.Expired)
                {
                    newState = BindExtensionState.Normal;
                }
                else
                {
                    newState = BindExtensionState.Extended;
                }

                player.BindToInstance(instanceBind.save, true, newState, false);
            }

            /*
             * InstancePlayerBind* instanceBind = GetPlayer().GetBoundInstance(setSavedInstanceExtend.MapID, Difficulty(setSavedInstanceExtend.DifficultyID);
             * if (!instanceBind || !instanceBind.save)
             *  return;
             *
             * InstanceSave* save = instanceBind.save;
             * // http://www.wowwiki.com/Instance_Lock_Extension
             * // SendCalendarRaidLockoutUpdated(save);
             */
        }
Exemple #2
0
        public void SendRaidInfo()
        {
            InstanceInfoPkt instanceInfo = new InstanceInfoPkt();

            long now = Time.UnixTime;

            for (byte i = 0; i < (int)Difficulty.Max; ++i)
            {
                foreach (var pair in m_boundInstances[i])
                {
                    InstanceBind bind = pair.Value;
                    if (bind.perm)
                    {
                        InstanceSave save = pair.Value.save;

                        InstanceLockInfos lockInfos;

                        lockInfos.InstanceID   = save.GetInstanceId();
                        lockInfos.MapID        = save.GetMapId();
                        lockInfos.DifficultyID = (uint)save.GetDifficultyID();
                        if (bind.extendState != BindExtensionState.Extended)
                        {
                            lockInfos.TimeRemaining = (int)(save.GetResetTime() - now);
                        }
                        else
                        {
                            lockInfos.TimeRemaining = (int)(Global.InstanceSaveMgr.GetSubsequentResetTime(save.GetMapId(), save.GetDifficultyID(), save.GetResetTime()) - now);
                        }

                        lockInfos.CompletedMask = 0;
                        Map map = Global.MapMgr.FindMap(save.GetMapId(), save.GetInstanceId());
                        if (map != null)
                        {
                            InstanceScript instanceScript = ((InstanceMap)map).GetInstanceScript();
                            if (instanceScript != null)
                            {
                                lockInfos.CompletedMask = instanceScript.GetCompletedEncounterMask();
                            }
                        }

                        lockInfos.Locked   = bind.extendState != BindExtensionState.Expired;
                        lockInfos.Extended = bind.extendState == BindExtensionState.Extended;

                        instanceInfo.LockList.Add(lockInfos);
                    }
                }
            }

            SendPacket(instanceInfo);
        }
Exemple #3
0
        public void SendInstanceResetWarning(uint mapid, Difficulty difficulty, uint time, bool welcome)
        {
            // type of warning, based on the time remaining until reset
            InstanceResetWarningType type;

            if (welcome)
            {
                type = InstanceResetWarningType.Welcome;
            }
            else if (time > 21600)
            {
                type = InstanceResetWarningType.Welcome;
            }
            else if (time > 3600)
            {
                type = InstanceResetWarningType.WarningHours;
            }
            else if (time > 300)
            {
                type = InstanceResetWarningType.WarningMin;
            }
            else
            {
                type = InstanceResetWarningType.WarningMinSoon;
            }

            RaidInstanceMessage raidInstanceMessage = new RaidInstanceMessage();

            raidInstanceMessage.Type         = type;
            raidInstanceMessage.MapID        = mapid;
            raidInstanceMessage.DifficultyID = difficulty;

            InstanceBind bind = GetBoundInstance(mapid, difficulty);

            if (bind != null)
            {
                raidInstanceMessage.Locked = bind.perm;
            }
            else
            {
                raidInstanceMessage.Locked = false;
            }
            raidInstanceMessage.Extended = false;
            SendPacket(raidInstanceMessage);
        }
Exemple #4
0
        public InstanceSave GetInstanceSave(uint mapid)
        {
            MapRecord    mapEntry = CliDB.MapStorage.LookupByKey(mapid);
            InstanceBind pBind    = GetBoundInstance(mapid, GetDifficultyID(mapEntry));
            InstanceSave pSave    = pBind?.save;

            if (pBind == null || !pBind.perm)
            {
                Group group = GetGroup();
                if (group)
                {
                    InstanceBind groupBind = group.GetBoundInstance(GetDifficultyID(mapEntry), mapid);
                    if (groupBind != null)
                    {
                        pSave = groupBind.save;
                    }
                }
            }

            return(pSave);
        }
Exemple #5
0
        public EnterState PlayerCannotEnter(uint mapid, Player player, bool loginCheck = false)
        {
            MapRecord entry = CliDB.MapStorage.LookupByKey(mapid);

            if (entry == null)
            {
                return(EnterState.CannotEnterNoEntry);
            }

            if (!entry.IsDungeon())
            {
                return(EnterState.CanEnter);
            }

            InstanceTemplate instance = Global.ObjectMgr.GetInstanceTemplate(mapid);

            if (instance == null)
            {
                return(EnterState.CannotEnterUninstancedDungeon);
            }

            Difficulty targetDifficulty = player.GetDifficultyID(entry);
            // Get the highest available difficulty if current setting is higher than the instance allows
            MapDifficultyRecord mapDiff = Global.DB2Mgr.GetDownscaledMapDifficultyData(entry.Id, ref targetDifficulty);

            if (mapDiff == null)
            {
                return(EnterState.CannotEnterDifficultyUnavailable);
            }

            //Bypass checks for GMs
            if (player.IsGameMaster())
            {
                return(EnterState.CanEnter);
            }

            string mapName = entry.MapName[Global.WorldMgr.GetDefaultDbcLocale()];

            Group group = player.GetGroup();

            if (entry.IsRaid() && entry.Expansion() >= (Expansion)WorldConfig.GetIntValue(WorldCfg.Expansion)) // can only enter in a raid group but raids from old expansion don't need a group
            {
                if ((!group || !group.IsRaidGroup()) && WorldConfig.GetBoolValue(WorldCfg.InstanceIgnoreRaid))
                {
                    return(EnterState.CannotEnterNotInRaid);
                }
            }

            if (!player.IsAlive())
            {
                if (player.HasCorpse())
                {
                    // let enter in ghost mode in instance that connected to inner instance with corpse
                    uint corpseMap = player.GetCorpseLocation().GetMapId();
                    do
                    {
                        if (corpseMap == mapid)
                        {
                            break;
                        }

                        InstanceTemplate corpseInstance = Global.ObjectMgr.GetInstanceTemplate(corpseMap);
                        corpseMap = corpseInstance != null ? corpseInstance.Parent : 0;
                    } while (corpseMap != 0);

                    if (corpseMap == 0)
                    {
                        return(EnterState.CannotEnterCorpseInDifferentInstance);
                    }

                    Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' has corpse in instance '{1}' and can enter.", player.GetName(), mapName);
                }
                else
                {
                    Log.outDebug(LogFilter.Maps, "Map.CanPlayerEnter - player '{0}' is dead but does not have a corpse!", player.GetName());
                }
            }

            //Get instance where player's group is bound & its map
            if (!loginCheck && group)
            {
                InstanceBind boundInstance = group.GetBoundInstance(entry);
                if (boundInstance != null && boundInstance.save != null)
                {
                    Map boundMap = FindMap(mapid, boundInstance.save.GetInstanceId());
                    if (boundMap != null)
                    {
                        EnterState denyReason = boundMap.CannotEnter(player);
                        if (denyReason != 0)
                        {
                            return(denyReason);
                        }
                    }
                }
            }
            // players are only allowed to enter 10 instances per hour
            if (entry.IsDungeon() && (player.GetGroup() == null || (player.GetGroup() != null && !player.GetGroup().IsLFGGroup())))
            {
                uint         instaceIdToCheck = 0;
                InstanceSave save             = player.GetInstanceSave(mapid);
                if (save != null)
                {
                    instaceIdToCheck = save.GetInstanceId();
                }

                // instanceId can never be 0 - will not be found
                if (!player.CheckInstanceCount(instaceIdToCheck) && !player.IsDead())
                {
                    return(EnterState.CannotEnterTooManyInstances);
                }
            }

            //Other requirements
            if (player.Satisfy(Global.ObjectMgr.GetAccessRequirement(mapid, targetDifficulty), mapid, true))
            {
                return(EnterState.CanEnter);
            }
            else
            {
                return(EnterState.CannotEnterUnspecifiedReason);
            }
        }
Exemple #6
0
        public bool CheckInstanceValidity(bool isLogin)
        {
            // game masters' instances are always valid
            if (IsGameMaster())
            {
                return(true);
            }

            // non-instances are always valid
            Map map = GetMap();

            if (!map || !map.IsDungeon())
            {
                return(true);
            }

            // raid instances require the player to be in a raid group to be valid
            if (map.IsRaid() && !WorldConfig.GetBoolValue(WorldCfg.InstanceIgnoreRaid))
            {
                if (!GetGroup() || !GetGroup().isRaidGroup())
                {
                    return(false);
                }
            }

            Group group = GetGroup();

            if (group)
            {
                // check if player's group is bound to this instance
                InstanceBind bind = group.GetBoundInstance(map.GetDifficultyID(), map.GetId());
                if (bind == null || bind.save == null || bind.save.GetInstanceId() != map.GetInstanceId())
                {
                    return(false);
                }

                var players = map.GetPlayers();
                if (!players.Empty())
                {
                    foreach (var otherPlayer in players)
                    {
                        if (otherPlayer.IsGameMaster())
                        {
                            continue;
                        }
                        if (!otherPlayer.m_InstanceValid) // ignore players that currently have a homebind timer active
                        {
                            continue;
                        }
                        if (group != otherPlayer.GetGroup())
                        {
                            return(false);
                        }
                    }
                }
            }
            else
            {
                // instance is invalid if we are not grouped and there are other players
                if (map.GetPlayersCountExceptGMs() > 1)
                {
                    return(false);
                }

                // check if the player is bound to this instance
                InstanceBind bind = GetBoundInstance(map.GetId(), map.GetDifficultyID());
                if (bind == null || bind.save == null || bind.save.GetInstanceId() != map.GetInstanceId())
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #7
0
        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);
        }