public YieldInstruction _MoveToPosition(GroundEntity ent, int x, int y, bool run = false, int speed = 2)
        {
            if (speed < 1)
            {
                DiagManager.Instance.LogInfo("ScriptGround.MoveToPosition(): Got invalid walk speed!");
                return(null);
            }

            if (ent is GroundChar)
            {
                GroundChar   ch         = (GroundChar)ent;
                FrameTick    prevTime   = new FrameTick();
                GroundAction prevAction = ch.GetCurrentAction();
                if (prevAction is WalkToPositionGroundAction)
                {
                    prevTime = prevAction.ActionTime;
                }
                WalkToPositionGroundAction newAction = new WalkToPositionGroundAction(ch.Position, ch.Direction, run, speed, prevTime, new Loc(x, y));
                ch.StartAction(newAction);
                return(new WaitUntil(() =>
                {
                    return newAction.Complete;
                }));
            }
            else
            {
                DiagManager.Instance.LogInfo("ScriptGround.MoveToPosition(): Got invalid entity!");
            }
            return(null);
        }
        private IEnumerator <YieldInstruction> _DoAnimatedTurn(GroundChar curch, int turn, int framedur, bool ccw)
        {
            if (turn == 0)
            {
                yield break;
            }
            var oldact = curch.GetCurrentAction();

            curch.StartAction(new IdleNoAnim(curch.MapLoc, curch.CharDir));
            Dir8 destDir = (Dir8)((8 + turn + (int)curch.CharDir) % 8);

            if (framedur <= 0) //instant turn
            {
                curch.CharDir = destDir;
                yield break;
            }
            else
            {
                while (curch.CharDir != destDir)
                {
                    if (ccw)
                    {
                        curch.CharDir = (Dir8)((7 + (int)curch.CharDir) % 8);
                    }
                    else
                    {
                        curch.CharDir = (Dir8)((1 + (int)curch.CharDir) % 8);
                    }
                    yield return(new WaitForFrames(framedur));
                }
                Debug.Assert(curch.CharDir != Dir8.None, "ScriptGround._DoAnimatedTurn(): Result of turn was none! Something went wrong!");
                oldact.MapLoc  = curch.MapLoc;
                oldact.CharDir = curch.CharDir;
                curch.StartAction(oldact);
                yield break;
            }
        }
Exemple #3
0
        private IEnumerator <YieldInstruction> _DoAnimatedTurn(GroundChar curch, int turn, int framedur)
        {
            if (turn == 0)
            {
                yield break;
            }
            var oldact = curch.GetCurrentAction();

            curch.StartAction(new IdleNoAnim(curch.MapLoc, curch.CharDir));
            if (framedur <= 0) //instant turn
            {
                curch.CharDir = (Dir8)(Math.Abs(turn + (int)curch.CharDir) % 7);
                yield break;
            }
            else
            {
                bool clockwise = turn >= 0;
                int  incr      = (clockwise) ? 1 : -1;
                int  cntdir    = 0;
                int  waitfrms  = framedur / Math.Abs(turn);

                for (; cntdir != turn;
                     curch.CharDir = (((int)curch.CharDir >= 7 && clockwise) ? //allow wrapping around
                                      (Dir8)0 : ((int)curch.CharDir <= 0 && !clockwise) ? (Dir8)7 :
                                      curch.CharDir + incr))
                {
                    cntdir += incr;
                    yield return(new WaitForFrames(waitfrms));
                }
                Debug.Assert(curch.CharDir != Dir8.None, "ScriptGround._DoAnimatedTurn(): Result of turn was none! Something went wrong!");
                oldact.MapLoc  = curch.MapLoc;
                oldact.CharDir = curch.CharDir;
                curch.StartAction(oldact);
                yield break;
            }
        }