Ejemplo n.º 1
0
        private static bool ResolveMove(MoveAction action, EncounterState state)
        {
            Entity actor             = state.GetEntityById(action.ActorId);
            var    positionComponent = state.GetEntityById(action.ActorId).GetComponent <PositionComponent>();
            var    oldPosition       = positionComponent.EncounterPosition;

            if (positionComponent.EncounterPosition == action.TargetPosition)
            {
                GD.PrintErr(string.Format("Entity {0}:{1} tried to move to its current position {2}", actor.EntityName, actor.EntityId, action.TargetPosition));
                return(false);
            }
            else
            {
                state.TeleportEntity(actor, action.TargetPosition, ignoreCollision: false);
                var unitComponent = actor.GetComponent <UnitComponent>();
                if (unitComponent != null)
                {
                    state.GetUnit(unitComponent.UnitId).NotifyEntityMoved(oldPosition, action.TargetPosition);
                }
                // If you go into the retreat zone you insta-die
                if (IsInRetreatZone(state, action.TargetPosition))
                {
                    if (actor.GetComponent <PlayerComponent>() != null)
                    {
                        state.NotifyPlayerRetreat();
                        return(false);
                    }
                    else
                    {
                        ResolveAction(new DestroyAction(action.ActorId), state);
                    }
                }
                return(true);
            }
        }