Exemple #1
0
        public static EngineTick Handle(this IMove move, Dictionary <Guid, IFighterStats> fighters, EngineCalculationValues calculationValues)
        {
            var moveTick = new FighterMoveTick()
            {
                Fighter = move.Actor.AsStruct(),
                Current = move.Actor.GetPosition(),
            };

            if (move.HasEnoughSpeed(calculationValues))
            {
                fighters[move.Actor.Id].Set(move.NextPosition);

                moveTick.Next = move.Actor.GetPosition();
                return(moveTick);
            }

            var distance = move.GetDistance();

            if (distance == 0)
            {
                moveTick.Next = move.Actor.GetPosition();
                return(moveTick);
            }
            else
            {
                var startPosition = move.Actor.GetVector3();
                var endPosition   = move.NextPosition.GetVector3();

                var newPosition = startPosition + (Vector3.Normalize(endPosition - startPosition) * move.Actor.Velocity(calculationValues));

                fighters[move.Actor.Id].Set(newPosition);

                moveTick.Next = move.Actor.GetPosition();
                return(moveTick);
            }
        }