Beispiel #1
0
    private void ExecuteEvent(PlayerEvent playerEvent)
    {
        switch (playerEvent.GetType().Name)
        {
        case "PlayerMovementEvent":
            ExecuteEvent(playerEvent as PlayerMovementEvent);
            break;

        case "PlayerDroppedItemEvent":
            ExecuteEvent(playerEvent as PlayerDroppedItemEvent);
            break;

        case "PlayerDashStartedEvent":
            ExecuteEvent(playerEvent as PlayerDashStartedEvent);
            break;

        case "PlayerDashStoppedEvent":
            ExecuteEvent(playerEvent as PlayerDashStoppedEvent);
            break;

        case "PlayerQuitEvent":
            ExecuteEvent(playerEvent as PlayerQuitEvent);
            break;
        }
    }
        public ServerEvent Process(PlayerEvent e)
        {
            if (!(e is JoinEvent))
            {
                _logger.LogError("JoinEventProcessor received an event of wrong type: " + e.GetType());
                return(new ErrorEvent("Internal error.", e.SourceId));
            }

            try
            {
                return(new PlayerJoinedEvent(_game.SpawnNewPlayer()));
            }
            catch (GameOvercrowdedException gameOvercrowdedException)
            {
                return(new ErrorEvent(gameOvercrowdedException.Message));
            }
        }
        public ServerEvent Process(PlayerEvent e)
        {
            if (!(e is PlayerActionEvent actionEvent))
            {
                _logger.LogError("AttackEventProcessor received an event of wrong type: " + e.GetType());
                return(new ErrorEvent("Internal error."));
            }

            PlayerState actor;
            PlayerState target;

            try
            {
                actor  = _game.GetPlayerStateById(actionEvent.ActorId);
                target = _game.GetPlayerStateById(actionEvent.TargetId);
            }
            catch (PlayerNotFoundException exception)
            {
                return(new ErrorEvent(exception.Message, actionEvent.ActorId));
            }

            foreach (var rule in _validationRules)
            {
                var validationResult = rule.ValidateAction(actor, target);
                if (!validationResult.IsValid)
                {
                    return(new ErrorEvent(validationResult.ErrorMessage, actionEvent.ActorId));
                }
            }

            var healthChange = CalculateBaseHealthChange();

            if (_transformationRule != null)
            {
                healthChange = _transformationRule.Transform(healthChange, actor, target);
            }

            var newHealth = target.Health + healthChange;

            if (newHealth < 0)
            {
                newHealth = 0;
            }
            else if (newHealth > 1000)
            {
                newHealth = 1000;
            }

            var newState = new PlayerState(target.PlayerId, target.Level, newHealth, target.CombatType, target.Factions, target.Coordinates);

            _game.UpdatePlayerState(newState);
            return(CreateResultEvent(actor, target, healthChange, newHealth));
        }
Beispiel #4
0
        public ServerEvent Process(PlayerEvent e)
        {
            if (!(e is LeaveFactionEvent typedEvent))
            {
                _logger.LogError("LeaveFactionEventProcessor received an event of wrong type: " + e.GetType());
                return(new ErrorEvent("Internal error.", e.SourceId));
            }

            PlayerState player;

            try
            {
                player = _game.GetPlayerStateById(typedEvent.PlayerId);
            }
            catch (PlayerNotFoundException exception)
            {
                return(new ErrorEvent(exception.Message, e.SourceId));
            }

            if (!player.Factions.Contains(typedEvent.FactionId))
            {
                return(new ErrorEvent(string.Format(Constants.Messages.NotInThisFactionTemplate, typedEvent.FactionId), typedEvent.PlayerId));
            }

            player.Factions.Remove(typedEvent.FactionId);
            _game.UpdatePlayerState(player);

            return(new PlayerLeftFactionEvent(player, typedEvent.FactionId));
        }