Beispiel #1
0
        public static T GetInstanceAI <T>(WorldObject obj) where T : class
        {
            InstanceMap instance = obj.GetMap().ToInstanceMap();

            if (instance != null && instance.GetInstanceScript() != null)
            {
                return((T)Activator.CreateInstance(typeof(T), new object[] { obj }));
            }

            return(null);
        }
Beispiel #2
0
        static bool HandleInstanceSaveData(StringArguments args, CommandHandler handler)
        {
            Player      player = handler.GetSession().GetPlayer();
            InstanceMap map    = player.GetMap().ToInstanceMap();

            if (map == null)
            {
                handler.SendSysMessage("Map is not a dungeon.");
                return(false);
            }

            if (map.GetInstanceScript() == null)
            {
                handler.SendSysMessage("Map has no instance data.");
                return(false);
            }

            map.GetInstanceScript().SaveToDB();

            return(true);
        }
Beispiel #3
0
        public static T GetInstanceAI <T>(WorldObject obj, string scriptName) where T : class
        {
            InstanceMap instance = obj.GetMap().ToInstanceMap();

            if (instance != null && instance.GetInstanceScript() != null)
            {
                if (instance.GetScriptId() == Global.ObjectMgr.GetScriptId(scriptName))
                {
                    return((T)Activator.CreateInstance(typeof(T), new object[] { obj }));
                }
            }

            return(null);
        }
Beispiel #4
0
        public static T GetInstanceAI <T>(WorldObject obj, string scriptName) where T : class
        {
            InstanceMap instance = obj.GetMap().ToInstanceMap();

            if (instance != null && instance.GetInstanceScript() != null)
            {
                if (instance.GetScriptName() == scriptName)
                {
                    return((T)Activator.CreateInstance(typeof(T), obj));
                }
            }

            return(null);
        }
Beispiel #5
0
        void HandleAreaTrigger(AreaTriggerPkt packet)
        {
            Player player = GetPlayer();

            if (player.IsInFlight())
            {
                Log.outDebug(LogFilter.Network, "HandleAreaTrigger: Player '{0}' (GUID: {1}) in flight, ignore Area Trigger ID:{2}",
                             player.GetName(), player.GetGUID().ToString(), packet.AreaTriggerID);
                return;
            }

            AreaTriggerRecord atEntry = CliDB.AreaTriggerStorage.LookupByKey(packet.AreaTriggerID);

            if (atEntry == null)
            {
                Log.outDebug(LogFilter.Network, "HandleAreaTrigger: Player '{0}' (GUID: {1}) send unknown (by DBC) Area Trigger ID:{2}",
                             player.GetName(), player.GetGUID().ToString(), packet.AreaTriggerID);
                return;
            }

            if (packet.Entered && !player.IsInAreaTriggerRadius(atEntry))
            {
                Log.outDebug(LogFilter.Network, "HandleAreaTrigger: Player '{0}' ({1}) too far, ignore Area Trigger ID: {2}",
                             player.GetName(), player.GetGUID().ToString(), packet.AreaTriggerID);
                return;
            }

            if (player.IsDebugAreaTriggers)
            {
                player.SendSysMessage(packet.Entered ? CypherStrings.DebugAreatriggerEntered : CypherStrings.DebugAreatriggerLeft, packet.AreaTriggerID);
            }

            if (Global.ScriptMgr.OnAreaTrigger(player, atEntry, packet.Entered))
            {
                return;
            }

            if (player.IsAlive())
            {
                List <uint> quests = Global.ObjectMgr.GetQuestsForAreaTrigger(packet.AreaTriggerID);
                if (quests != null)
                {
                    foreach (uint questId in quests)
                    {
                        Quest qInfo = Global.ObjectMgr.GetQuestTemplate(questId);
                        if (qInfo != null && player.GetQuestStatus(questId) == QuestStatus.Incomplete)
                        {
                            foreach (QuestObjective obj in qInfo.Objectives)
                            {
                                if (obj.Type == QuestObjectiveType.AreaTrigger && !player.IsQuestObjectiveComplete(obj))
                                {
                                    player.SetQuestObjectiveData(obj, 1);
                                    player.SendQuestUpdateAddCreditSimple(obj);
                                    break;
                                }
                            }

                            if (player.CanCompleteQuest(questId))
                            {
                                player.CompleteQuest(questId);
                            }
                        }
                    }
                }
            }

            if (Global.ObjectMgr.IsTavernAreaTrigger(packet.AreaTriggerID))
            {
                // set resting flag we are in the inn
                player.GetRestMgr().SetRestFlag(RestFlag.Tavern, atEntry.Id);

                if (Global.WorldMgr.IsFFAPvPRealm())
                {
                    player.RemovePvpFlag(UnitPVPStateFlags.FFAPvp);
                }

                return;
            }
            Battleground bg = player.GetBattleground();

            if (bg)
            {
                bg.HandleAreaTrigger(player, packet.AreaTriggerID, packet.Entered);
            }

            OutdoorPvP pvp = player.GetOutdoorPvP();

            if (pvp != null)
            {
                if (pvp.HandleAreaTrigger(player, packet.AreaTriggerID, packet.Entered))
                {
                    return;
                }
            }

            AreaTriggerStruct at = Global.ObjectMgr.GetAreaTrigger(packet.AreaTriggerID);

            if (at == null)
            {
                return;
            }

            bool teleported = false;

            if (player.GetMapId() != at.target_mapId)
            {
                EnterState denyReason = Global.MapMgr.PlayerCannotEnter(at.target_mapId, player, false);
                if (denyReason != 0)
                {
                    bool reviveAtTrigger = false; // should we revive the player if he is trying to enter the correct instance?
                    switch (denyReason)
                    {
                    case EnterState.CannotEnterNoEntry:
                        Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' attempted to enter map with id {1} which has no entry", player.GetName(), at.target_mapId);
                        break;

                    case EnterState.CannotEnterUninstancedDungeon:
                        Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' attempted to enter dungeon map {1} but no instance template was found", player.GetName(), at.target_mapId);
                        break;

                    case EnterState.CannotEnterDifficultyUnavailable:
                    {
                        Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' attempted to enter instance map {1} but the requested difficulty was not found", player.GetName(), at.target_mapId);
                        MapRecord entry = CliDB.MapStorage.LookupByKey(at.target_mapId);
                        if (entry != null)
                        {
                            player.SendTransferAborted(entry.Id, TransferAbortReason.Difficulty, (byte)player.GetDifficultyID(entry));
                        }
                    }
                    break;

                    case EnterState.CannotEnterNotInRaid:
                        Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' must be in a raid group to enter map {1}", player.GetName(), at.target_mapId);
                        player.SendRaidGroupOnlyMessage(RaidGroupReason.Only, 0);
                        reviveAtTrigger = true;
                        break;

                    case EnterState.CannotEnterCorpseInDifferentInstance:
                        player.SendPacket(new AreaTriggerNoCorpse());
                        Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' does not have a corpse in instance map {1} and cannot enter", player.GetName(), at.target_mapId);
                        break;

                    case EnterState.CannotEnterInstanceBindMismatch:
                    {
                        MapRecord entry = CliDB.MapStorage.LookupByKey(at.target_mapId);
                        if (entry != null)
                        {
                            string mapName = entry.MapName[player.GetSession().GetSessionDbcLocale()];
                            Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' cannot enter instance map '{1}' because their permanent bind is incompatible with their group's", player.GetName(), mapName);
                            // is there a special opcode for this?
                            // @todo figure out how to get player localized difficulty string (e.g. "10 player", "Heroic" etc)
                            player.SendSysMessage(CypherStrings.InstanceBindMismatch, mapName);
                        }
                        reviveAtTrigger = true;
                    }
                    break;

                    case EnterState.CannotEnterTooManyInstances:
                        player.SendTransferAborted(at.target_mapId, TransferAbortReason.TooManyInstances);
                        Log.outDebug(LogFilter.Maps, "MAP: Player '{0}' cannot enter instance map {1} because he has exceeded the maximum number of instances per hour.", player.GetName(), at.target_mapId);
                        reviveAtTrigger = true;
                        break;

                    case EnterState.CannotEnterMaxPlayers:
                        player.SendTransferAborted(at.target_mapId, TransferAbortReason.MaxPlayers);
                        reviveAtTrigger = true;
                        break;

                    case EnterState.CannotEnterZoneInCombat:
                        player.SendTransferAborted(at.target_mapId, TransferAbortReason.ZoneInCombat);
                        reviveAtTrigger = true;
                        break;

                    default:
                        break;
                    }

                    if (reviveAtTrigger) // check if the player is touching the areatrigger leading to the map his corpse is on
                    {
                        if (!player.IsAlive() && player.HasCorpse())
                        {
                            if (player.GetCorpseLocation().GetMapId() == at.target_mapId)
                            {
                                player.ResurrectPlayer(0.5f);
                                player.SpawnCorpseBones();
                            }
                        }
                    }

                    return;
                }

                Group group = player.GetGroup();
                if (group)
                {
                    if (group.IsLFGGroup() && player.GetMap().IsDungeon())
                    {
                        teleported = player.TeleportToBGEntryPoint();
                    }
                }
            }

            if (!teleported)
            {
                WorldSafeLocsEntry entranceLocation = null;
                InstanceSave       instanceSave     = player.GetInstanceSave(at.target_mapId);
                if (instanceSave != null)
                {
                    // Check if we can contact the instancescript of the instance for an updated entrance location
                    Map map = Global.MapMgr.FindMap(at.target_mapId, player.GetInstanceSave(at.target_mapId).GetInstanceId());
                    if (map)
                    {
                        InstanceMap instanceMap = map.ToInstanceMap();
                        if (instanceMap != null)
                        {
                            InstanceScript instanceScript = instanceMap.GetInstanceScript();
                            if (instanceScript != null)
                            {
                                entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceScript.GetEntranceLocation());
                            }
                        }
                    }

                    // Finally check with the instancesave for an entrance location if we did not get a valid one from the instancescript
                    if (entranceLocation == null)
                    {
                        entranceLocation = Global.ObjectMgr.GetWorldSafeLoc(instanceSave.GetEntranceLocation());
                    }
                }

                if (entranceLocation != null)
                {
                    player.TeleportTo(entranceLocation.Loc, TeleportToOptions.NotLeaveTransport);
                }
                else
                {
                    player.TeleportTo(at.target_mapId, at.target_X, at.target_Y, at.target_Z, at.target_Orientation, TeleportToOptions.NotLeaveTransport);
                }
            }
        }
Beispiel #6
0
        static bool HandleInstanceGetBossState(StringArguments args, CommandHandler handler)
        {
            if (args.Empty())
            {
                return(false);
            }

            string param1      = args.NextString();
            string param2      = args.NextString();
            uint   encounterId = 0;
            Player player      = null;

            // Character name must be provided when using this from console.
            if (string.IsNullOrEmpty(param1) || (string.IsNullOrEmpty(param2) && handler.GetSession() == null))
            {
                handler.SendSysMessage(CypherStrings.CmdSyntax);
                return(false);
            }

            if (string.IsNullOrEmpty(param2))
            {
                player = handler.GetSession().GetPlayer();
            }
            else
            {
                if (ObjectManager.NormalizePlayerName(ref param2))
                {
                    player = Global.ObjAccessor.FindPlayerByName(param2);
                }
            }

            if (!player)
            {
                handler.SendSysMessage(CypherStrings.PlayerNotFound);
                return(false);
            }

            InstanceMap map = player.GetMap().ToInstanceMap();

            if (map == null)
            {
                handler.SendSysMessage(CypherStrings.NotDungeon);
                return(false);
            }

            if (map.GetInstanceScript() == null)
            {
                handler.SendSysMessage(CypherStrings.NoInstanceData);
                return(false);
            }

            if (!uint.TryParse(param1, out encounterId))
            {
                return(false);
            }

            if (encounterId > map.GetInstanceScript().GetEncounterCount())
            {
                handler.SendSysMessage(CypherStrings.BadValue);
                return(false);
            }

            EncounterState state = map.GetInstanceScript().GetBossState(encounterId);

            handler.SendSysMessage(CypherStrings.CommandInstGetBossState, encounterId, state);
            return(true);
        }