Esempio n. 1
0
        private bool CommandCreateExit(InputData i)
        {
            if (!i.Arguments.Success)
            {
                World.Instance.SendMessage("@wSyntax: map createexit [from room ID = current] <to room ID> \"<command>\"", i.ClientMask);
                return(true);
            }

            uint fromId;
            uint toId;

            if (i.Arguments.Groups[2].Length > 0)
            {
                if (!uint.TryParse(i.Arguments.Groups[1].Value, out fromId) ||
                    !uint.TryParse(i.Arguments.Groups[2].Value.Trim(), out toId))
                {
                    World.Instance.SendMessage("@wSyntax: map createexit [from room ID = current] <to room ID> \"<command>\"", i.ClientMask);
                    return(true);
                }
            }
            else
            {
                fromId = CurrentRoomId;
                if (!uint.TryParse(i.Arguments.Groups[1].Value, out toId))
                {
                    World.Instance.SendMessage("@wSyntax: map createexit [from room ID = current] <to room ID> \"<command>\"", i.ClientMask);
                    return(true);
                }
            }

            Room from = GetRoom(fromId);
            Room to   = GetRoom(toId);

            if (from == null || to == null)
            {
                World.Instance.SendMessage("@wNo such room exists in mapper database.", i.ClientMask);
                return(true);
            }

            char dir = PathfindResult.IsDirectionCommand(i.Arguments.Groups[3].Value);
            Exit e   = new Exit(++_guidExit);

            e.Command = dir != 'x' ? char.ToLower(dir).ToString() : i.Arguments.Groups[3].Value.ToLower();
            e.From    = from;
            e.To      = to;
            e.From.exits.Add(e);
            e.From.UpdateExits();
            IExits[e.Entry] = e;
            World.Instance.SendMessage("@wCreated a new exit (@R" + e.Entry + "@w).", i.ClientMask);
            World.Instance.SendMessage("@wType '@Wmap exit " + e.Entry + "@w' for more information or to edit.", i.ClientMask);
            return(true);
        }
Esempio n. 2
0
        public override void OnEndedPathFind(PathfindResult pr)
        {
            base.OnEndedPathFind(pr);

            foreach (Room x in StartRooms)
            {
                AllRooms.Add(x);
            }

            foreach (Room u in AllRooms)
            {
                _Internal_PathFinder_VisitAll pf = new _Internal_PathFinder_VisitAll((from val in AllRooms where val != u select val).ToArray());
                pf.CanUsePortals      = CanUsePortals;
                pf.CanUseRecalls      = CanUseRecalls;
                pf.CharacterLevel     = CharacterLevel;
                pf.CharacterTier      = CharacterTier;
                pf.IsGlobalQuest      = IsGlobalQuest;
                pf.IsSingleClassTier0 = IsSingleClassTier0;
                pf.OverridePortals    = OverridePortals;
                pf.SkipExits          = SkipExits;
                pf.SkipPortals        = SkipPortals;
                pf.SkipRooms          = SkipRooms;
                pf.StartRooms         = new[] { u };

                PathfindResult p = map.Get(pf);
                if (!p.Success)
                {
                    pr.Success = false;
                    return;
                }

                Costs[u.Entry] = new Dictionary <uint, uint>();
                foreach (Room x in AllRooms)
                {
                    if (x == u)
                    {
                        continue;
                    }

                    if (x.Mapper_OpenBy != null)
                    {
                        Costs[u.Entry][x.Entry] = x.Mapper_OpenCost;
                    }
                    else
                    {
                        pr.Success = false;
                        return;
                    }
                }
            }

            OpenRoom(new[] { StartRooms[0].Entry }, 0);

            uint[] Finish = null;
            int    itr1 = 0, itr2 = 0;

            while (itr1 < _grid.Length)
            {
                if (itr2 >= _grid[itr1].Count)
                {
                    itr2 = 0;
                    _grid[itr1].Clear();
                    itr1++;
                    continue;
                }

                if (OpenRoom(_grid[itr1][itr2], (uint)itr1))
                {
                    Finish = _grid[itr1][itr2];
                    break;
                }

                itr2++;
            }

            if (Finish == null)
            {
                pr.Success = false;
            }
            else
            {
                pr.Cost = itr1;
                pr.Path.Clear();
                pr.Target = map.GetRoom(Finish[Finish.Length - 1]);
                Room u = map.GetRoom(Finish[0]);
                int  j = 1;
                while (u != null && j < Finish.Length)
                {
                    Pathfinder_Entry pf = new Pathfinder_Entry(Finish[j]);
                    pf.StartRooms         = new[] { u };
                    pf.CanUsePortals      = CanUsePortals;
                    pf.CanUseRecalls      = CanUseRecalls;
                    pf.CharacterLevel     = CharacterLevel;
                    pf.CharacterTier      = CharacterTier;
                    pf.IsGlobalQuest      = IsGlobalQuest;
                    pf.IsSingleClassTier0 = IsSingleClassTier0;
                    pf.OverridePortals    = OverridePortals;
                    pf.SkipExits          = SkipExits;
                    pf.SkipPortals        = SkipPortals;
                    pf.SkipRooms          = SkipRooms;

                    PathfindResult p = map.Get(pf);
                    if (!p.Success)
                    {
                        pr.Success = false;
                        return;
                    }

                    pr.Path.AddRange(p.Path);
                    u = map.GetRoom(Finish[j]);
                    j++;
                }
            }
        }
Esempio n. 3
0
        public PathfindResult Get(Pathfinder p)
        {
            if (p.StartRooms != null)
            {
                p.StartRooms = p.StartRooms.Where(val => val != null).ToArray();
            }
            if (p.StartRooms == null || p.StartRooms.Length == 0)
            {
                return new PathfindResult()
                       {
                           Success = false
                       }
            }
            ;

            for (int i = 0; i < _pGridMax; i++)
            {
                _pGrid[i].Clear();
            }
            _pExits[0].Clear();
            _pExits[1].Clear();
            _pGridMax = 0;
            foreach (KeyValuePair <uint, Room> x in IRooms)
            {
                x.Value.Mapper_OpenBy   = null;
                x.Value.Mapper_OpenCost = 0;
            }

            p.OnStartedPathfind();

            if (p.OverridePortals == null)
            {
                foreach (KeyValuePair <uint, Exit> x in IPortals)
                {
                    if (!x.Value.HasFlag("disabled") && CanUsePortal(x.Value, p))
                    {
                        _pExits[!x.Value.HasFlag("recallmechanic") ? 0 : 1].Add(x.Value);
                    }
                }
            }
            else
            {
                foreach (Exit x in p.OverridePortals)
                {
                    if (!x.HasFlag("disabled") && CanUsePortal(x, p))
                    {
                        _pExits[!x.HasFlag("recallmechanic") ? 0 : 1].Add(x);
                    }
                }
            }

            Room Finish = null;

            if (p.StartRooms != null)
            {
                foreach (Room r in p.StartRooms)
                {
                    r.Mapper_OpenCost = uint.MaxValue;
                    if (OpenRoom(r, null, 0, p))
                    {
                        Finish = r;
                        break;
                    }
                }
            }

            int itr1 = 0, itr2 = 0;

            if (Finish == null)
            {
                while (itr1 < _pGrid.Length && itr1 < _pGridMax)
                {
                    if (itr2 >= _pGrid[itr1].Count)
                    {
                        itr2 = 0;
                        itr1++;
                        continue;
                    }

                    if (OpenRoom(_pGrid[itr1][itr2].To, _pGrid[itr1][itr2], (uint)itr1, p))
                    {
                        Finish = _pGrid[itr1][itr2].To;
                        break;
                    }

                    itr2++;
                }
            }

            PathfindResult pr = new PathfindResult();

            pr.Success = Finish != null;
            pr.Cost    = itr1;
            pr.Target  = Finish;
            while (Finish != null && Finish.Mapper_OpenBy != null)
            {
                pr.Path.Insert(0, Finish.Mapper_OpenBy);
                Finish = Finish.Mapper_OpenBy.From;
            }
            pr.Start = pr.Path.Count != 0 ? pr.Path[0].From : Finish;

            p.OnEndedPathFind(pr);
            return(pr);
        }
Esempio n. 4
0
        private bool CommandExit(InputData i)
        {
            //      1        2          3      4
            // @"^(help)?(room\s+\d+)?(\d+)?(\s+.+)?"
            if (i.Arguments.Groups[1].Length != 0)
            {
                World.Instance.SendMessage("@wSyntax:", i.ClientMask);
                World.Instance.SendMessage(string.Format("{0,-20}", "map exit") + " - show exits in current room.", i.ClientMask);
                World.Instance.SendMessage(string.Format("{0,-20}", "map exit help") + " - show this message.", i.ClientMask);
                World.Instance.SendMessage(string.Format("{0,-20}", "map exit room <room ID>") + " - show exits in room.", i.ClientMask);
                World.Instance.SendMessage(string.Format("{0,-20}", "map exit <ID> [option] [value]") + " - change exit options / show information by exit ID.", i.ClientMask);
                World.Instance.SendMessage("", i.ClientMask);
                World.Instance.SendMessage("@wAvailable options for exit:", i.ClientMask);
                World.Instance.SendMessage("@W" + string.Format("{0,-15}", "addflag") + " @w- Add a flag to exit.", i.ClientMask);
                World.Instance.SendMessage("@W" + string.Format("{0,-15}", "removeflag") + " @w- Remove a flag from exit.", i.ClientMask);
                World.Instance.SendMessage("@W" + string.Format("{0,-15}", "command") + " @w- Change command that activates exit.", i.ClientMask);
                World.Instance.SendMessage("@W" + string.Format("{0,-15}", "doorcommand") + " @w- Change command that we use to open door, for example '@Wopen altar@w'. Use clear to remove this field.", i.ClientMask);
                World.Instance.SendMessage("@W" + string.Format("{0,-15}", "cost") + " @w- Change cost of using exit.", i.ClientMask);
                World.Instance.SendMessage("@W" + string.Format("{0,-15}", "minlevel") + " @w- Minimum level required to use exit.", i.ClientMask);
                World.Instance.SendMessage("@W" + string.Format("{0,-15}", "maxlevel") + " @w- Maximum level allowed to use exit.", i.ClientMask);
                World.Instance.SendMessage("@W" + string.Format("{0,-15}", "delete confirm") + " @w- Delete the exit.", i.ClientMask);
                World.Instance.SendMessage("", i.ClientMask);
                World.Instance.SendMessage("@wAvailable default flags:", i.ClientMask);
                World.Instance.SendMessage("@W" + string.Format("{0,-15}", "recallmechanic") + " @w- This exit uses recall mechanic, can't use in norecall (for portals).", i.ClientMask);
                World.Instance.SendMessage("@W" + string.Format("{0,-15}", "door") + " @w- This exit has a door.", i.ClientMask);
                World.Instance.SendMessage("@W" + string.Format("{0,-15}", "nogq") + " @w- Don't use this exit on a global quest (for regular chaos portals).", i.ClientMask);
                World.Instance.SendMessage("@W" + string.Format("{0,-15}", "disabled") + " @w- Don't use this exit ever.", i.ClientMask);
                //World.Instance.SendMessage("@W" + string.Format("{0,-15}", "nopass") + " @w- The door is nopass.", i.ClientMask);
                //World.Instance.SendMessage("@W" + string.Format("{0,-15}", "locked") + " @w- The door is locked.", i.ClientMask);
                //World.Instance.SendMessage("@W" + string.Format("{0,-15}", "pickable") + " @w- Door can be pick locked or bashdoor.", i.ClientMask);
                World.Instance.SendMessage("@wNote: there may be custom flags that are implemented by other plugins / scripts that aren't listed here.", i.ClientMask);
                return(true);
            }

            if (i.Arguments.Groups[2].Length != 0 || (i.Arguments.Groups[2].Length == 0 && i.Arguments.Groups[1].Length == 0 && i.Arguments.Groups[3].Length == 0))
            {
                uint roomId;
                if (i.Arguments.Groups[2].Length != 0)
                {
                    string str = i.Arguments.Groups[2].Value.Substring(4).Trim();
                    if (!uint.TryParse(str, out roomId))
                    {
                        World.Instance.SendMessage("@wInvalid room ID given. Type '@Wmap exit help@w' for syntax.",
                                                   i.ClientMask);
                        return(true);
                    }
                }
                else
                {
                    roomId = CurrentRoomId;
                    if (roomId == uint.MaxValue)
                    {
                        World.Instance.SendMessage("@wYou are in an unknown room.", i.ClientMask);
                        return(true);
                    }
                }

                Room r = GetRoom(roomId);
                if (r == null)
                {
                    World.Instance.SendMessage("@wNo such room in database (@R" + roomId + "@w).", i.ClientMask);
                    return(true);
                }

                World.Instance.SendMessage("@wExits in '@G" + r.Name + "@w' [@Y" + r.Entry + "@w]:", i.ClientMask);
                if (r.exits.Count == 0)
                {
                    World.Instance.SendMessage("@wNo exits found.", i.ClientMask);
                }
                else
                {
                    World.Instance.SendMessage("@WEntry  Command              To", i.ClientMask);
                    World.Instance.SendMessage("@G====== ==================== ========================", i.ClientMask);
                    foreach (Exit e in r.exits)
                    {
                        World.Instance.SendMessage("@Y" + string.Format("{0,-6}", e.Entry) + " @W" + string.Format("{0,-20}", e.Command) + " @w[@Y" + string.Format("{0,6}", e.To.Entry) + "@w] @G" + e.To.Name, i.ClientMask);
                    }
                    World.Instance.SendMessage("", i.ClientMask);
                    World.Instance.SendMessage("@wType '@Wmap exit <exit ID>@w' for more information about an exit.", i.ClientMask);
                    World.Instance.SendMessage("@wOr '@Wmap exit help@w' for syntax.", i.ClientMask);
                }
                return(true);
            }

            if (i.Arguments.Groups[3].Length != 0)
            {
                uint exitId;
                if (!uint.TryParse(i.Arguments.Groups[3].Value, out exitId))
                {
                    World.Instance.SendMessage("@wInvalid exit ID given. Type '@Wmap exit help@w' for syntax.", i.ClientMask);
                    return(true);
                }

                Exit e = GetExit(exitId);
                if (e == null && IPortals.ContainsKey(exitId))
                {
                    e = IPortals[exitId];
                }
                if (e == null)
                {
                    World.Instance.SendMessage("@wNo such exit in database (@R" + exitId + "@w).", i.ClientMask);
                    return(true);
                }

                if (i.Arguments.Groups[4].Length != 0)
                {
                    string key, val;
                    string str = i.Arguments.Groups[4].Value.Trim();
                    if (str.Contains(' '))
                    {
                        key = str.Substring(0, str.IndexOf(' ')).ToLower();
                        val = str.Substring(key.Length).Trim();

                        switch (key)
                        {
                        case "addflag":
                            e.AddFlag(val);
                            break;

                        case "removeflag":
                            e.RemoveFlag(val);
                            break;

                        case "command":
                            val       = val.ToLower();
                            e.Command = PathfindResult.IsDirectionCommand(val) != 'x' ?
                                        PathfindResult.IsDirectionCommand(val).ToString() :
                                        val;
                            break;

                        case "doorcommand":
                            val           = val.ToLower();
                            e.DoorCommand = val != "clear" ? val : null;
                            break;

                        case "cost":
                        {
                            uint u;
                            if (uint.TryParse(val, out u))
                            {
                                e.Cost = u;
                            }
                        } break;

                        case "minlevel":
                        {
                            int lvl;
                            if (int.TryParse(val, out lvl))
                            {
                                e.MinLevel = lvl;
                            }
                        } break;

                        case "maxlevel":
                        {
                            int lvl;
                            if (int.TryParse(val, out lvl))
                            {
                                e.MaxLevel = lvl;
                            }
                        } break;

                        case "delete":
                        {
                            if (val == "confirm")
                            {
                                if (e.HasFlag("portal"))
                                {
                                    IPortals.Remove(e.Entry);
                                    e.To.Area.Portals.Remove(e);
                                }
                                else
                                {
                                    IExits.Remove(e.Entry);
                                    e.From.exits.Remove(e);
                                }
                                World.Instance.SendMessage("@wDeleted exit or portal (@R" + e.Entry + "@w).",
                                                           i.ClientMask);
                                return(true);
                            }
                            World.Instance.SendMessage("@wEnter '@Wmap exit <num> delete confirm@w' to remove the exit.", i.ClientMask);
                        } break;

                        default:
                            World.Instance.SendMessage("@wInvalid key value pair entered '@R" + key + " " + val + "@w'.", i.ClientMask);
                            World.Instance.SendMessage("@wUse '@Wmap exit help@w' to see syntax.", i.ClientMask);
                            break;
                        }
                    }
                }

                World.Instance.SendMessage("@w+----------------------------------------------------------------------+", i.ClientMask);
                World.Instance.SendMessage("@w| @WEntry       @w: @Y" + string.Format("{0,-55}", e.Entry) + "@w|", i.ClientMask);
                if (!e.HasFlag("portal"))
                {
                    World.Instance.SendMessage("@w| @WFrom        @w: @w[@Y" + string.Format("{0,6}", e.From.Entry) + "@w] @G" + Utility.FormatColoredString(!string.IsNullOrEmpty(e.From.Name) ? e.From.Name : "Unknown", -46) + "@w|", i.ClientMask);
                }
                World.Instance.SendMessage("@w| @WTo          @w: @w[@Y" + string.Format("{0,6}", e.To.Entry) + "@w] @G" + Utility.FormatColoredString(!string.IsNullOrEmpty(e.To.Name) ? e.To.Name : "Unknown", -46) + "@w|", i.ClientMask);
                World.Instance.SendMessage("@w| @WCommand     @w: @c" + string.Format("{0,-55}", e.Command) + "@w|", i.ClientMask);
                World.Instance.SendMessage("@w| @WDoor command@w: @c" + string.Format("{0,-55}", !string.IsNullOrEmpty(e.DoorCommand) ? e.DoorCommand : "none") + "@w|", i.ClientMask);
                World.Instance.SendMessage("@w| @WCost        @w: @C" + string.Format("{0,-55}", e.Cost) + "@w|", i.ClientMask);
                StringBuilder strFlags = new StringBuilder();
                if (e.IFlags != null)
                {
                    foreach (string x in e.IFlags)
                    {
                        if (strFlags.Length > 0)
                        {
                            strFlags.Append(", ");
                        }
                        strFlags.Append(x);
                    }
                }

                string[] spl = Utility.WrapColored(strFlags.ToString(), 54, 0);
                for (int j = 0; j < spl.Length; j++)
                {
                    if (j == 0)
                    {
                        World.Instance.SendMessage("@w| @WFlags       @w: " + string.Format("{0,-55}", spl[j]) + "@w|", i.ClientMask);
                    }
                    else
                    {
                        World.Instance.SendMessage("@w|             : " + string.Format("{0,-55}", spl[j]) + "@w|", i.ClientMask);
                    }
                }

                World.Instance.SendMessage("@w| @WMin level   @w: @W" + string.Format("{0,-55}", e.MinLevel) + "@w|", i.ClientMask);
                World.Instance.SendMessage("@w| @WMax level   @w: @W" + string.Format("{0,-55}", e.MaxLevel) + "@w|", i.ClientMask);
                World.Instance.SendMessage("@w+----------------------------------------------------------------------+", i.ClientMask);
                if (i.Arguments.Groups[4].Length == 0)
                {
                    World.Instance.SendMessage("@wSee '@Wmap exit help@w' for information on how to edit this exit.", i.ClientMask);
                }
                return(true);
            }

            World.Instance.SendMessage("0", i.ClientMask);
            return(true);
        }
Esempio n. 5
0
 public virtual void OnEndedPathFind(PathfindResult pr)
 {
 }