コード例 #1
0
        protected void Loop()
        {
            var _timer         = new DateTime();
            var _InteractTimer = new DateTime();
            var castTele       = false;
            var tryCount       = 0;

            while (true)
            {
                Thread.Sleep(50);

                if (!game.InGame)
                {
                    continue;
                }

                try
                {
                    if (TPath.Count == 0)
                    {
                        if (doInteract && interactId != 0 && _InteractTimer.MSecToNow() >= 200)
                        {
                            using (var gameSuspender = new GameSuspender(game))
                            {
                                doInteract = false;
                                if (game.GameReady() && !game.IsDead())
                                {
                                    game.Interact(interactId, (UnitType)interactType);
                                }
                                interactId = 0;
                            }
                        }
                        continue;
                    }

                    var End = TPath[TPath.Count - 1];

                    // TODO: check skill for ping

                    if (castTele)
                    {
                        castTele = false;

                        _timer = DateTime.Now;
                        // TODO: check charges

                        using (var gameSuspender = new GameSuspender(game))
                        {
                            if (!game.GameReady() || game.IsDead() || game.IsInTown() || !game.TeleportTo((ushort)TPath[0].X, (ushort)TPath[0].Y))
                            {
                                TPath.Clear();
                                Logger.AutoTele.Log(game, LogType.Warning, "Failed to cast teleport.");
                                continue;
                            }
                        }
                    }

                    if (_timer.MSecToNow() > 500)
                    {
                        if (tryCount >= 5)
                        {
                            Logger.AutoTele.Log(game, LogType.Warning, "Failed to teleport after {0} tries.", tryCount);
                            TPath.Clear();
                            tryCount   = 0;
                            doInteract = false;
                            castTele   = false;
                            continue;
                        }
                        else
                        {
                            ++tryCount;
                            castTele = true;
                        }
                    }

                    if (TeleportPath.CalculateDistance(game.CurrentX, game.CurrentY, TPath[0].X, TPath[0].Y) <= 5)
                    {
                        TPath.RemoveAt(0);
                        castTele = true;
                        tryCount = 0;
                    }

                    if (doInteract)
                    {
                        if (TeleportPath.CalculateDistance(game.CurrentX, game.CurrentY, End.X, End.Y) <= 5)
                        {
                            doInteract     = false;
                            _InteractTimer = DateTime.Now;
                            using (var gameSuspender = new GameSuspender(game))
                            {
                                if (!game.GameReady() || game.IsDead())
                                {
                                    interactId = 0;
                                }
                                else
                                {
                                    interactId = game.MapHandler.GetUnitByXY((uint)End.X, (uint)End.Y, interactRoom);
                                }
                            }
                            TPath.Clear();
                            continue;
                        }
                    }
                }
                catch
                {
                    ///
                }
            }
        }
コード例 #2
0
        protected int MakePath(int x, int y, List <uint> areas, bool MoveThrough)
        {
            uint dwCount = 0;
            var  aPath   = new Point[255];

            var g_collisionMap = game.MapHandler.GetCollisionData(areas.ToArray());

            if (!g_collisionMap.m_map.IsCreated())
            {
                return(0);
            }

            UnitAny unit;

            if (!game.GetPlayerUnit(out unit) || unit.pPath == 0)
            {
                return(0);
            }

            var path = game.Debugger.Read <Path>(unit.pPath);

            var ptStart = new Point(path.xPos, path.yPos);
            var ptEnd   = new Point(x, y);

            if (!g_collisionMap.IsValidAbsLocation(ptStart.X, ptStart.Y))
            {
                return(0);
            }

            if (!g_collisionMap.IsValidAbsLocation(ptEnd.X, ptEnd.Y))
            {
                return(0);
            }

            g_collisionMap.AbsToRelative(ref ptStart);
            g_collisionMap.AbsToRelative(ref ptEnd);

            var matrix = new CMatrix <ushort>();

            if (!g_collisionMap.CopyMapData(matrix))
            {
                return(0);
            }

            var tf = new TeleportPath(matrix.GetData(), matrix.CX, matrix.CY);

            dwCount = tf.FindTeleportPath(ptStart, ptEnd, aPath, 255);
            if (dwCount == 0)
            {
                return(0);
            }

            for (var i = 0; i < dwCount; ++i)
            {
                g_collisionMap.RelativeToAbs(ref aPath[i]);
            }

            if (MoveThrough)
            {
                if (aPath[dwCount - 1].X > aPath[dwCount - 2].X)
                {
                    aPath[dwCount].X = aPath[dwCount - 1].X + 2;
                }
                else
                {
                    aPath[dwCount].X = aPath[dwCount - 1].X - 2;
                }
                if (aPath[dwCount - 1].Y > aPath[dwCount - 2].Y)
                {
                    aPath[dwCount].Y = aPath[dwCount - 1].Y + 2;
                }
                else
                {
                    aPath[dwCount].Y = aPath[dwCount - 1].Y - 2;
                }

                ++dwCount;

                if (TeleportPath.CalculateDistance(aPath[dwCount - 1].X, aPath[dwCount - 1].Y, aPath[dwCount - 3].X, aPath[dwCount - 3].Y) <= (uint)Range.TpRange)
                {
                    aPath[dwCount - 2]   = aPath[dwCount - 1];
                    aPath[dwCount - 1].X = 0;
                    aPath[dwCount - 1].Y = 0;
                    --dwCount;
                }
            }

            TPath.Clear();
            for (var i = 0; i < dwCount; ++i)
            {
                TPath.Add(aPath[i]);
            }

            return((int)dwCount);
        }