Exemplo n.º 1
0
        public static JsonData GetJson(dynamic actionData, string direction, int distance)
        {
            var parsedDirection = SpellHelper.ParseDirection(direction);

            if (!parsedDirection.HasValue)
            {
                throw new SpellException($"Unknown direction: {direction}");
            }
            if (distance <= 0)
            {
                throw new SpellException("Cast distance should be greater than 0.");
            }

            var configuration = GetConfiguration();

            var action = new SpellActionsFactory().GetSpellAction(actionData, null);

            if (action is MoveSpellAction)
            {
                throw new SpellException("Move action cannot be casted on distance from the spell.");
            }

            var manaCost = GetManaCost(action.ManaCost, distance, configuration.ManaCostMultiplier,
                                       configuration.ManaCostPower);

            return(new JsonData(new Dictionary <string, object>
            {
                { "type", ActionType },
                { "action", action.GetJson() },
                { "direction", direction },
                { "distance", distance },
                { "manaCost", manaCost }
            }));
        }