示例#1
0
 public void DoAction()
 {
     if (Locked)
     {
         return;
     }
     if (Timer.Enabled)
     {
         return;
     }
     if (!Launched)
     {
         return;
     }
     Locked = true;
     Logger.Default.Log($"DoAction");
     using (MapMovement movMap = ParseMove())
     {
         if (movMap == null)
         {
             Stop();
             return;
         }
         StartTimer();
         // If Gather on this map and there are resources to be gathered
         if (movMap.Gather && Account.Character.GatherManager.CanGatherOnMap(RessourcesToGather))
         {
             Account.Character.GatherManager.Gather(RessourcesToGather, false);
             return;
         }
         // If Fight on this map and there are mobs to be fighted
         else if (movMap.Fight && Account.Character.Map.Monsters.Count > 0)
         {
             Account.Character.Fight.FightEnded   += Fight_FightEnded;
             Account.Character.Fight.FightStarted += Fight_FightStarted;
             Account.Character.Map.LaunchAttack();
             return;
         }
         else if (movMap.CustomFunction != null && movMap.CustomFunction.Type == DataType.Function)
         {
             script.Call(movMap.CustomFunction); //I think it's better to let the DoAction time out just in case.
             return;
         }
         var mapDir = movMap.GetDirectionEnum(Randomizer);
         if (mapDir == MapDirectionEnum.Invalid) // there is no present movement on the script.
         {
             return;
         }
         else
         {
             IMapChangement mapChangement = Account.Character.Map.ChangeMap(mapDir);
             mapChangement.ChangementFinished += MapChangement_ChangementFinished;
             mapChangement.PerformChangement();
             Locked = true;
         }
     }
 }
示例#2
0
        /// <summary>
        /// Every Map this function has to run in order to do some fancy contitioning with the Trajet.
        /// </summary>
        private MapMovement ParseMove()
        {
            /* Move function */
            DynValue Move = script.Call(script.Globals["move"]);

            if (Move.IsNotNil())
            {
                foreach (var item in Move.Table.Values)
                {
                    MapMovement newMapMov = new MapMovement();
                    DynValue    mapD      = item.Table.Get("map");
                    if (mapD.IsNil())
                    {
                        throw new Exception("map can not be nil.");
                    }

                    string map = mapD.CastToString();
                    if (!map.Contains(','))
                    {
                        double.TryParse(map, out double mapId);
                        newMapMov = new MapMovement(mapId);
                    }
                    else
                    {
                        string[] Pos = map.Split(',');
                        if (!(Pos.Length == 2))
                        {
                            throw new Exception("Problem Parsing coordinates");
                        }
                        if (!int.TryParse(Pos[0], out int posX))
                        {
                            throw new Exception("Cannot obtain posX");
                        }
                        if (!int.TryParse(Pos[1], out int posY))
                        {
                            throw new Exception("Cannot obtain posY");
                        }
                        newMapMov = new MapMovement(posX, posY);
                    }
                    if (newMapMov.MapId == Account.Character.MapId || (newMapMov.PosX == Account.Character.PosX && newMapMov.PosY == Account.Character.PosY))
                    {
                        DynValue pathD          = item.Table.Get("path");
                        DynValue doorD          = item.Table.Get("door");
                        DynValue customFunction = item.Table.Get("custom");

                        if (customFunction.IsNotNil() && customFunction.Type == DataType.Function)
                        {
                            newMapMov.CustomFunction = customFunction;
                        }
                        if (pathD.IsNil() && doorD.IsNil())
                        {
                            Logger.Default.Log($"No path/door on map {(newMapMov.MapId == -1 ? string.Format("{0},{1}", newMapMov.PosX, newMapMov.PosY) : newMapMov.MapId.ToString())}");
                        }

                        if (int.TryParse(pathD.CastToString(), out int pathId))
                        {
                            newMapMov.Path = pathId; // Just the sun thing in the ground.
                        }
                        else if (doorD.IsNotNil())
                        {
                            newMapMov.Door = (int)doorD.Number; // We have to interact.
                        }
                        else if (pathD.IsNotNil())
                        {
                            try
                            {
                                string[] directions = pathD.CastToString().ToLower().Split(',');
                                foreach (var direction in directions)
                                {
                                    switch (direction)
                                    {
                                    case "top":
                                    case "north":
                                    case "up":
                                        newMapMov.AddDirection(MapDirectionEnum.North);
                                        break;

                                    case "bottom":
                                    case "south":
                                    case "down":
                                        newMapMov.AddDirection(MapDirectionEnum.South);
                                        break;

                                    case "left":
                                    case "west":
                                        newMapMov.AddDirection(MapDirectionEnum.West);
                                        break;

                                    case "right":
                                    case "east":
                                        newMapMov.AddDirection(MapDirectionEnum.East);
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                            catch (Exception e) { throw new Exception($"Exception thrown parsing Trajet[{e.Message}]"); }
                        }
                        //We can't really verify this since we are calling a function everytime. Let the user debug it's Script

                        /*
                         * if (newMapMov.MapId > 0) //MapId being used
                         * {
                         *  MapPosition tmp = ObjectDataManager.Instance.Get<MapPosition>((uint)newMapMov.MapId);
                         *  if (ScriptData.Exists(x => x.PosX == tmp.PosX && x.PosY == tmp.PosY) || ScriptData.Exists(x => x.MapId == newMapMov.MapId))
                         *      throw new PathManagerException($"MapId[{newMapMov.MapId}] or Coordinates[{newMapMov.PosX},{newMapMov.PosY}] duplicated.");
                         * }
                         * else if (ScriptData.Exists(x => x.PosX == newMapMov.PosX && x.PosY == newMapMov.PosY))
                         *  throw new PathManagerException($"Coordenates[{newMapMov.PosX},{newMapMov.PosY}] duplicated.");
                         */

                        newMapMov.Gather = item.Table.Get("gather").CastToBool();
                        newMapMov.Fight  = item.Table.Get("fight").CastToBool();
                        return(newMapMov);
                    }
                }
            }
            else
            {
                throw new PathManagerException("move() function not present.");
            }

            Logger.Default.Log($"Could not find Bot's current mapId[{Account.Character.MapId}] or [{Account.Character.PosX},{Account.Character.PosY}].", LogMessageType.Trajet);
            Stop();
            return(default);