Exemplo n.º 1
0
 private bool MoveToCell(int cellId)
 {
     if (cellId != Fighter.CellId)
     {
         if (!(IsCellWalkable(cellId)))
         {
             int      num       = -1;
             int      num2      = 5000;
             MapPoint point     = new MapPoint(Fighter.CellId);
             MapPoint point2    = new MapPoint(cellId);
             int      direction = 1;
             while (true)
             {
                 MapPoint nearestCellInDirection = point2.GetNearestCellInDirection(direction, 1);
                 if (IsCellWalkable(nearestCellInDirection.CellId))
                 {
                     int num4 = point.DistanceToCell(nearestCellInDirection);
                     if (num4 < num2)
                     {
                         num2 = num4;
                         num  = nearestCellInDirection.CellId;
                     }
                 }
                 direction = (direction + 2);
                 if (direction > 7)
                 {
                     if (num == -1)
                     {
                         return(false);
                     }
                     cellId = num;
                     break;
                 }
             }
         }
         SimplePathfinder pathfinder = new SimplePathfinder((BlueSheep.Data.D2p.Map)m_Account.Map.Data);
         pathfinder.SetFight(Fighters, Fighter.MovementPoints);
         MovementPath path = pathfinder.FindPath(Fighter.CellId, cellId);
         if (path != null)
         {
             List <UInt32> serverMovement = MapMovementAdapter.GetServerMovement(path);
             //Account.Network.SendToServer(new GameMapMovementRequestMessage(serverMovement.ToList().Select<uint, short>(ui => (short)ui).ToArray(), Account.Game.Map.Id));
             using (BigEndianWriter writer = new BigEndianWriter())
             {
                 GameMapMovementRequestMessage msg = new GameMapMovementRequestMessage(serverMovement.ToList().Select <uint, short>(ui => (short)ui).ToArray(), m_Account.Map.Id);
                 msg.Serialize(writer);
                 writer.Content = m_Account.HumanCheck.hash_function(writer.Content);
                 MessagePackaging pack = new MessagePackaging(writer);
                 pack.Pack((int)msg.ProtocolID);
                 m_Account.SocketManager.Send(pack.Writer.Content);
                 if (m_Account.DebugMode.Checked)
                 {
                     m_Account.Log(new BotTextInformation("[SND] 950 (GameMapMovementRequestMessage)"), 0);
                 }
             }
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        private BFighter NearestMonster()
        {
            MapPoint CharacterPoint = new MapPoint(this.Fighter.CellId);
            BFighter Fighterr       = null;
            int      SavDistance    = -1;

            foreach (BFighter TestFighter in Fighters)
            {
                if (TestFighter.TeamId == Fighter.TeamId || TestFighter.IsAlive == false)
                {
                    continue;
                }
                MapPoint TestFighterPoint = new MapPoint(TestFighter.CellId);
                int      dist             = new SimplePathfinder(m_Account.Map.Data).FindPath(CharacterPoint.CellId, TestFighterPoint.CellId).Cells.Count();
                dist += CharacterPoint.DistanceToCell(TestFighterPoint);
                if (((dist < SavDistance) || (SavDistance == -1)) && TestFighter != this.Fighter)
                {
                    SavDistance = dist;
                    Fighterr    = TestFighter;
                }
            }
            if (Fighterr == null)
            {
                return(null);
            }
            return(Fighterr);
        }
Exemplo n.º 3
0
        protected int DistanceFrom(IFighter fighter)
        {
            var characterPoint   = new MapPoint(Fighter.CellId);
            var testFighterPoint = new MapPoint(fighter.CellId);
            var dist             = new SimplePathfinder((API.Gamedata.D2p.Map)Account.Character.Map.Data)
                                   .FindPath(fighter.CellId, testFighterPoint.CellId).Cells.Count();

            dist += characterPoint.DistanceToCell(testFighterPoint);
            return(dist);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the distance between our player and the specified fighter. Default is the nearest monster.
        /// </summary>
        public int DistanceFrom(BFighter fighter = null)
        {
            if (fighter == null)
            {
                fighter = NearestMonster();
            }
            MapPoint CharacterPoint   = new MapPoint(Fighter.CellId);
            MapPoint TestFighterPoint = new MapPoint(fighter.CellId);
            int      dist             = new SimplePathfinder(m_Account.MapData).FindPath(fighter.CellId, TestFighterPoint.CellId).Cells.Count();

            dist += CharacterPoint.DistanceToCell(TestFighterPoint);
            return(dist);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes the <see cref="UniverseBase{TCoordinates}.Pathfinder"/> engine.
        /// </summary>
        /// <remarks>Is usually called automatically when needed.</remarks>
        private void InitializePathfinding()
        {
            if (Terrain == null)
            {
                return;
            }

            var obstructionMap = new bool[Terrain.Size.X, Terrain.Size.Y];

            MarkUntraversableWaters(obstructionMap);
            Terrain.MarkUntraversableSlopes(obstructionMap, MaxTraversableSlope);
            MarkUnmoveableEntities(obstructionMap);
            Pathfinder = new SimplePathfinder(obstructionMap);
        }
Exemplo n.º 6
0
        public ICellMovement MoveToCell(int cellId)
        {
            if (cellId == Fighter.CellId)
            {
                return(null);
            }
            if (!IsCellWalkable(cellId))
            {
                var num       = -1;
                var num2      = 5000;
                var point     = new MapPoint(Fighter.CellId);
                var point2    = new MapPoint(cellId);
                var direction = 1;
                while (true)
                {
                    var nearestCellInDirection = point2.GetNearestCellInDirection(direction, 1);
                    if (IsCellWalkable(nearestCellInDirection.CellId))
                    {
                        var num4 = point.DistanceToCell(nearestCellInDirection);
                        if (num4 < num2)
                        {
                            num2 = num4;
                            num  = nearestCellInDirection.CellId;
                        }
                    }
                    direction += 2;
                    if (direction <= 7)
                    {
                        continue;
                    }
                    if (num == -1)
                    {
                        return(null);
                    }
                    cellId = num;
                    break;
                }
            }
            var pathfinder = new SimplePathfinder((API.Gamedata.D2p.Map)Account.Character.Map.Data);

            pathfinder.SetFight(Fighters, Fighter.MovementPoints);
            var path = pathfinder.FindPath(Fighter.CellId, cellId);

            return(path == null ? null : new CellMovement(Account, path));
        }
    // Start is called before the first frame update
    void Start()
    {
        SimplePathfinder.Setup(new int2(100, 100));

        SimplePathfinder.GetPath(new int2(0, 0), new int2(99, 99), OnPathResolved);
    }