Exemplo n.º 1
0
        public new bool Update()
        {
            bool baseResult = base.Update();

            // Check whether the player is currently highlighting its target
            bool highlightedTarget = false;

            if (PlayerUtil.HasHighlighted(player))
            {
                highlightedTarget = PlayerUtil.GetHighlightedObject(player).Equals(target.gameObject);
            }

            if (!baseResult && !highlightedTarget)
            {
                return(false);
            }

            // TODO: face target component before ending
            float facingDif = PlayerUtil.GetAngleFacingDiff(player, target);

            // Logger.Log($"Facing diff: {facingDif}");

            if (facingDif > 40)
            {
                Keyboard.Input input = PlayerUtil.GetInputFacing(player, target);
                // Logger.Log($"Input: {input}");
                Keyboard.Get().SendDown(input);

                return(false);
            }

            Keyboard.Get().StopXMovement();
            Keyboard.Get().StopZMovement();

            Logger.Log("MoveTargetAction done");

            return(true);
        }
Exemplo n.º 2
0
        public bool Update()
        {
            Keyboard.Input release = Keyboard.Input.MOVE_RIGHT;
            Keyboard.Input press   = Keyboard.Input.MOVE_LEFT;

            bool xDone = false;
            bool zDone = false;

            if (!xStuck && Math.Abs(PlayerPos.x - destination.x) > xMargin)
            {
                if (PlayerPos.x < destination.x)
                {
                    release = Keyboard.Input.MOVE_LEFT;
                    press   = Keyboard.Input.MOVE_RIGHT;
                }
                if (Keyboard.Get().IsKeyDown(release))
                {
                    Keyboard.Get().SendUp(release);
                }
                Keyboard.Get().SendDown(press);
            }
            else
            {
                xDone = true;
                Keyboard.Get().StopXMovement();
            }

            if (!zStuck && Math.Abs(PlayerPos.z - destination.z) > zMargin)
            {
                if (PlayerPos.z > destination.z)
                {
                    release = Keyboard.Input.MOVE_UP;
                    press   = Keyboard.Input.MOVE_DOWN;
                }
                else
                {
                    release = Keyboard.Input.MOVE_DOWN;
                    press   = Keyboard.Input.MOVE_UP;
                }
                if (Keyboard.Get().IsKeyDown(release))
                {
                    Keyboard.Get().SendUp(release);
                }
                Keyboard.Get().SendDown(press);
            }
            else
            {
                zDone = true;
                Keyboard.Get().StopZMovement();
            }

            if (!xDone || !zDone)
            {
                // TODO: don't rely on movement stuck, but pathfinding and interaction highlights
                // Only check stuck if in range of destination
                if (stuckStop &&
                    Math.Abs(PlayerPos.x - destination.x) < 2 && Math.Abs(PlayerPos.z - destination.z) < 2)
                {
                    if (stuckCheck == 0)
                    {
//                        Logger.Log($"settings lastX={lastX}, lastZ={lastZ}");
//                        Logger.Log($"pos={Logger.FormatPosition(PlayerPos)}");
                        if (!xDone && Math.Abs(PlayerPos.x - lastX) < 0.0000001)
                        {
//                            Logger.Log("xStuck true");
                            xStuck = true;
                        }
                        if (!zDone && Math.Abs(PlayerPos.z - lastZ) < 0.0000001)
                        {
//                            Logger.Log("zStuck true");
                            zStuck = true;
                        }

                        lastX   = PlayerPos.x;
                        lastZ   = PlayerPos.z;
                        lastRot = player.transform.rotation.eulerAngles.y;

                        stuckCheck = STUCK_TRIES;
                    }
                    else
                    {
                        stuckCheck -= 1;
                    }
                }
                return(false);
            }

            if (xStuck && zStuck)
            {
                //Logger.Log("Movement stuck...");
            }
            else
            {
                //Logger.Log("Destination reached " + "(" + destination.x + ", " + destination.z + ")");
            }

            return(true);
        }