Пример #1
0
        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);
        }
Пример #2
0
 public YieldInstruction _MoveToPosition(GroundEntity ent, double x, double y, bool run = false)
 {
     if (ent is GroundChar)
     {
         GroundChar ch = (GroundChar)ent;
         ch.StartAction(new WalkToPositionGroundAction(ch.Position, ch.Direction, run, new FrameTick(), new Loc((int)x, (int)y), () => { this.m_actionComplete = true; }));
         return(new WaitUntil(() => { return this.m_actionComplete; }));
     }
     return(null);
 }
Пример #3
0
        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;
            }
        }
Пример #4
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;
            }
        }
Пример #5
0
        public void CharPoseAnim(GroundChar chara, string anim)
        {
            int animIndex = GraphicsManager.Actions.FindIndex((CharFrameType element) => element.Name == anim);

            chara.StartAction(new PoseGroundAction(chara.Position, chara.Direction, animIndex));
        }
Пример #6
0
 public void CharEndAnim(GroundChar chara)
 {
     chara.StartAction(new IdleGroundAction(chara.Position, chara.Direction));
 }
Пример #7
0
        /// <summary>
        /// Set a character's animation
        /// </summary>
        /// <param name="chara"></param>
        /// <param name="anim"></param>
        public void CharSetAnim(GroundChar chara, string anim, bool loop)
        {
            int animIndex = GraphicsManager.Actions.FindIndex((CharFrameType element) => element.Name == anim);

            chara.StartAction(new IdleAnimGroundAction(chara.Position, chara.Direction, animIndex, loop));
        }