Пример #1
0
            public override void Process(CmdTrigger <RealmServerCmdArgs> trigger)
            {
                var chr = trigger.Args.Target as Character;

                var mod   = trigger.Text.NextModifiers();
                var mapid = trigger.Text.NextEnum(MapId.End);

                if (mapid == MapId.End)
                {
                    trigger.Reply("Invalid MapId.");
                    return;
                }

                var mapTemplate = World.GetMapTemplate(mapid);

                if (mapTemplate != null && mapTemplate.IsInstance)
                {
                    uint diffIndex;
                    if (mod.Contains("d"))
                    {
                        diffIndex = trigger.Text.NextUInt();
                        var diff = mapTemplate.GetDifficulty(diffIndex);
                        if (diff == null)
                        {
                            trigger.Reply("Invalid Difficulty: {0}");
                        }
                    }
                    else if (chr != null)
                    {
                        diffIndex = chr.GetInstanceDifficulty(mapTemplate.IsRaid);
                    }
                    else
                    {
                        diffIndex = 0;
                    }
                    var instance = InstanceMgr.CreateInstance(chr, mapTemplate.InstanceTemplate, diffIndex);
                    if (instance != null)
                    {
                        trigger.Reply("Instance created: " + instance);
                        if (mod.Contains("e"))
                        {
                            if (chr != null)
                            {
                                instance.TeleportInside((Character)trigger.Args.Target);
                            }
                        }
                    }
                    else
                    {
                        trigger.Reply("Unable to create Instance of: " + mapTemplate);
                    }
                }
                else
                {
                    trigger.Reply("Invalid MapId.");
                }
            }
Пример #2
0
            public override void Process(CmdTrigger <RealmServerCmdArgs> trigger)
            {
                Character target = trigger.Args.Target as Character;
                string    str    = trigger.Text.NextModifiers();
                MapId     mapID  = trigger.Text.NextEnum(MapId.End);

                if (mapID == MapId.End)
                {
                    trigger.Reply("Invalid MapId.");
                }
                else
                {
                    MapTemplate mapTemplate = World.GetMapTemplate(mapID);
                    if (mapTemplate != null && mapTemplate.IsInstance)
                    {
                        uint num;
                        if (str.Contains("d"))
                        {
                            num = trigger.Text.NextUInt();
                            if (mapTemplate.GetDifficulty(num) == null)
                            {
                                trigger.Reply("Invalid Difficulty: {0}");
                            }
                        }
                        else
                        {
                            num = target == null ? 0U : target.GetInstanceDifficulty(mapTemplate.IsRaid);
                        }

                        BaseInstance instance = InstanceMgr.CreateInstance(target, mapTemplate.InstanceTemplate, num);
                        if (instance != null)
                        {
                            trigger.Reply("Instance created: " + instance);
                            if (!str.Contains("e") || target == null)
                            {
                                return;
                            }
                            instance.TeleportInside((Character)trigger.Args.Target);
                        }
                        else
                        {
                            trigger.Reply("Unable to create Instance of: " + mapTemplate);
                        }
                    }
                    else
                    {
                        trigger.Reply("Invalid MapId.");
                    }
                }
            }
Пример #3
0
        public static NPCSpawnEntry GetNPCSpawnEntry(CmdTrigger <RealmServerCmdArgs> trigger, bool closest, out Map map)
        {
            var           target = trigger.Args.Target;
            NPCSpawnEntry entry;

            map = null;
            if (closest)
            {
                if (target == null)
                {
                    trigger.Reply("Cannot use the -c switch without active Target.");
                    return(null);
                }

                entry = NPCMgr.GetClosestSpawnEntry(target);
                if (entry == null)
                {
                    trigger.Reply("No Spawnpoint found.");
                    return(null);
                }
            }
            else
            {
                var   word = trigger.Text.NextWord();
                NPCId npcId;
                if (!EnumUtil.TryParse(word, out npcId))
                {
                    uint spawnId;
                    uint.TryParse(word, out spawnId);
                    entry = NPCMgr.GetSpawnEntry(spawnId);
                    if (entry == null)
                    {
                        trigger.Reply("Invalid SpawnId: " + spawnId);
                        return(null);
                    }
                }
                else
                {
                    var npcEntry = NPCMgr.GetEntry(npcId);
                    if (npcEntry == null)
                    {
                        trigger.Reply("Entry not found: " + npcId);
                        return(null);
                    }
                    if (npcEntry.SpawnEntries.Count == 0)
                    {
                        trigger.Reply("Entry has no SpawnEntries: " + npcEntry);
                        return(null);
                    }

                    entry = target != null?npcEntry.SpawnEntries.GetClosestSpawnEntry(target) : npcEntry.SpawnEntries.First();
                }
            }

            // found entry - now determine Map
            map = entry.Map;
            if (map == null)
            {
                if (target != null && entry.MapId == target.MapId)
                {
                    // is in same map
                    map = target.Map;
                }
                else
                {
                    // must create Map
                    if (World.IsInstance(entry.MapId))
                    {
                        // create instance
                        map = InstanceMgr.CreateInstance(target as Character, entry.MapId);
                        if (map == null)
                        {
                            trigger.Reply("Failed to create instance: " + entry.MapId);
                            return(null);
                        }
                    }
                    else
                    {
                        trigger.Reply("Cannot spawn NPC for map: " + entry.MapId);
                        return(null);
                    }
                }
            }
            return(entry);
        }
Пример #4
0
        public static NPCSpawnEntry GetNPCSpawnEntry(CmdTrigger <RealmServerCmdArgs> trigger, bool closest, out Map map)
        {
            Unit target = trigger.Args.Target;

            map = null;
            NPCSpawnEntry npcSpawnEntry;

            if (closest)
            {
                if (target == null)
                {
                    trigger.Reply("Cannot use the -c switch without active Target.");
                    return(null);
                }

                npcSpawnEntry = NPCMgr.GetClosestSpawnEntry(target);
                if (npcSpawnEntry == null)
                {
                    trigger.Reply("No Spawnpoint found.");
                    return(null);
                }
            }
            else
            {
                string str = trigger.Text.NextWord();
                NPCId  result1;
                if (!EnumUtil.TryParse(str, out result1))
                {
                    uint result2;
                    uint.TryParse(str, out result2);
                    npcSpawnEntry = NPCMgr.GetSpawnEntry(result2);
                    if (npcSpawnEntry == null)
                    {
                        trigger.Reply("Invalid SpawnId: " + result2);
                        return(null);
                    }
                }
                else
                {
                    NPCEntry entry = NPCMgr.GetEntry(result1);
                    if (entry == null)
                    {
                        trigger.Reply("Entry not found: " + result1);
                        return(null);
                    }

                    if (entry.SpawnEntries.Count == 0)
                    {
                        trigger.Reply("Entry has no SpawnEntries: " + entry);
                        return(null);
                    }

                    npcSpawnEntry = target != null
            ? entry.SpawnEntries.GetClosestSpawnEntry(target)
            : entry.SpawnEntries.First();
                }
            }

            map = npcSpawnEntry.Map;
            if (map == null)
            {
                if (target != null && npcSpawnEntry.MapId == target.MapId)
                {
                    map = target.Map;
                }
                else if (World.IsInstance(npcSpawnEntry.MapId))
                {
                    map = InstanceMgr.CreateInstance(target as Character, npcSpawnEntry.MapId);
                    if (map == null)
                    {
                        trigger.Reply("Failed to create instance: " + npcSpawnEntry.MapId);
                        return(null);
                    }
                }
                else
                {
                    trigger.Reply("Cannot spawn NPC for map: " + npcSpawnEntry.MapId);
                    return(null);
                }
            }

            return(npcSpawnEntry);
        }
Пример #5
0
        /// <summary>
        /// Loads and adds the Character to its Map.
        /// </summary>
        /// <remarks>Called initially from the IO-Context</remarks>
        internal void LoadAndLogin()
        {
            // set Zone *before* Map
            // TODO: Also retrieve Battlegrounds
            m_Map = World.GetMap(m_record);

            InstanceMgr.RetrieveInstances(this);

            AreaCharCount++;                            // Characters are always in active regions

            if (!Role.IsStaff)
            {
                Stunned++;
            }

            var isStaff = Role.IsStaff;

            if (m_Map == null && (!isStaff || (m_Map = InstanceMgr.CreateInstance(this, m_record.MapId)) == null))
            {
                // map does not exist anymore
                Load();
                TeleportToBindLocation();
                AddMessage(InitializeCharacter);
                return;
            }
            else
            {
                Load();
                if (m_Map.IsDisposed ||
                    (m_Map.IsInstance && !isStaff && (m_Map.CreationTime > m_record.LastLogout || !m_Map.CanEnter(this))))
                {
                    // invalid Map or not allowed back in (might be an Instance)
                    m_Map.TeleportOutside(this);

                    AddMessage(InitializeCharacter);
                }
                else
                {
                    m_Map.AddMessage(() =>
                    {
                        // add to map
                        if (m_Map is Battleground)
                        {
                            var bg = (Battleground)m_Map;
                            if (!bg.LogBackIn(this))
                            {
                                // teleport out of BG
                                AddMessage(InitializeCharacter);
                                return;
                            }
                        }

                        m_position = new Vector3(m_record.PositionX,
                                                 m_record.PositionY,
                                                 m_record.PositionZ);

                        m_zone = m_Map.GetZone(m_record.Zone);

                        if (m_zone != null && m_record.JustCreated)
                        {
                            // set initial zone explored automatically
                            SetZoneExplored(m_zone.Id, false);
                        }

                        // during the next Map-wide Character-update, the Character is going to be added to the map
                        // and created/initialized immediately afterwards
                        m_Map.AddObjectNow(this);

                        InitializeCharacter();
                    });
                }
            }
        }