コード例 #1
0
        public static void HandleGameMapMovementMessage(Bot bot, GameMapMovementMessage message)
        {
            if (bot.Character == null || bot.Character.Context == null)
            {
                logger.Error("Context is null as processing movement");
                return;
            }

            ContextActor actor      = null;
            bool         fightActor = false;

            if (bot.Character.IsFighting())
            {
                actor = bot.Character.Fight.GetActor(message.actorId);
            }
            if (actor == null)
            {
                actor = bot.Character.Context.GetActor(message.actorId);
            }
            else
            {
                fightActor = true;
            }
            if (actor == null)
            {
                logger.Error("Actor {0} not found (known : {1})", message.actorId, String.Join(",", fightActor ? bot.Character.Fight.Actors : bot.Character.Context.Actors)); // only a log for the moment until context are fully handled
                return;
            }

            // just to update the position. If in fight, better update immediately to be sure that the next action take the mouvement into account
            if (message.keyMovements.Length == 1)
            {
                actor.UpdatePosition(message.keyMovements[0]);
            }
            else
            {
                Path path = Path.BuildFromServerCompressedPath(bot.Character.Map, message.keyMovements);

                if (path.IsEmpty())
                {
                    logger.Warn("Try to start moving with an empty path");
                    return;
                }

                var movement = new MovementBehavior(path, actor.GetAdaptedVelocity(path));
                movement.Start(DateTime.Now + TimeSpan.FromMilliseconds(EstimatedMovementLag));

                actor.NotifyStartMoving(movement);
            }
        }
コード例 #2
0
        public virtual bool NotifyStartMoving(Path path)
        {
            if (path.IsEmpty())
            {
                logger.Warn("Try to start moving with an empty path");
                return(false);
            }

            Movement = new MovementBehavior(path, GetAdaptedVelocity(path));
            Movement.Start();


            return(NotifyStartMoving(Movement));
        }
コード例 #3
0
        public static void HandleGameMapMovementMessage(Bot bot, GameMapMovementMessage message)
        {
            var actor = bot.Character.Context.GetContextActor(message.actorId);

            if (actor == null)
            {
                logger.Error("Actor {0} not found", message.actorId); // only a log for the moment until context are fully handled
            }
            else
            {
                var path = Path.BuildFromServerCompressedPath(bot.Character.Map, message.keyMovements);

                if (path.IsEmpty())
                {
                    logger.Warn("Try to start moving with an empty path");
                    return;
                }

                var movement = new MovementBehavior(path, actor.GetAdaptedVelocity(path));
                movement.Start(DateTime.Now + TimeSpan.FromMilliseconds(EstimatedMovementLag));

                actor.NotifyStartMoving(movement);
            }
        }