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 }
            }));
        }
Exemplo n.º 2
0
        public ISpellAction Execute(Point position, CodeSpell spell, int lifeTime)
        {
            var result = ExecuteCode(position, spell, lifeTime);

            if (result == null)
            {
                return(new EmptySpellAction());
            }

            var action = new SpellActionsFactory().GetSpellAction(result, spell);

            if (action == null)
            {
                throw new SpellException("Spell returned no action.");
            }

            return(action);
        }
Exemplo n.º 3
0
        private ISpellAction ParseSpellAction(dynamic actionData)
        {
            var factory = new SpellActionsFactory();

            return(factory.GetSpellAction(actionData, spell));
        }