Example #1
0
        private void DoPlayerSpell(PlayerWitch p, PlayerSpell spell)
        {
            int repeats = p.Action.GetRepeats();

            if (repeats < 1)
            {
                throw new GameException("Repeat can't be zero (on " + spell.Id + ")");
            }
            if (repeats > 1 && !spell.IsRepeatable())
            {
                throw new GameException("Spell " + spell.Id + " is not repeatable");
            }
            if (!spell.IsActive())
            {
                throw new GameException("Spell " + spell.Id + " is exhausted");
            }
            if (!p.CanAfford(spell.Recipe, repeats))
            {
                throw new GameException("Not enough ingredients for spell " + spell.Id);
            }
            if (!p.EnoughSpace(spell.Recipe, repeats))
            {
                throw new GameException("Not enough space in inventory for spell " + spell.Id);
            }

            //do spell
            for (int k = 0; k < repeats; ++k)
            {
                for (int i = 0; i < INGREDIENT_TYPE_COUNT; ++i)
                {
                    p.Inventory.Add(i, spell.GetDelta()[i]);
                }
            }
            spell.Deactivate();

            EventData e = new EventData();

            e.Type      = EventData.PLAYER_SPELL;
            e.PlayerIdx = p.Index;
            e.SpellId   = spell.Id;
            e.Repeats   = repeats;
            _viewerEvents.Add(e);
        }