public SubSpellHandler(
            SpellHandler spellHandler,
            SubSpell subSpell,
            Target source,
            Target target)
        {
            Assert.IsTrue(source.IsValid);
            Assert.IsTrue(target.IsValid);
            Assert.IsNotNull(subSpell);
            Assert.IsNotNull(spellHandler);

            SubSpell      = subSpell;
            _spellHandler = spellHandler;
            Source        = source;
            Target        = target;
            _state        = SubSpellState.Started;

            #if DEBUG
            TargetUtility.DebugDrawSourceAndTarget(source, target);
            #endif
        }
Exemple #2
0
        public void CastSubSpell(SubSpell subSpell, Target source, Target target)
        {
            if (!source.IsValid)
            {
                Debug.LogWarning($"Invalid source while casting SubSpell: {subSpell}");
                return;
            }

            if (!target.IsValid)
            {
                Debug.LogWarning($"Invalid target while casting SubSpell: {subSpell}");
                return;
            }

            Assert.IsNotNull(subSpell);

            if (_instances.ContainsKey(subSpell))
            {
                // Max instances of this SubSpell casted
                if (_instances[subSpell] >= subSpell.MaxInstances.GetValue(Stacks))
                {
                    return;
                }

                _instances[subSpell] += 1;
            }
            else
            {
                _instances.Add(subSpell, 1);
            }

            var handler = new SubSpellHandler(this, subSpell, source, target);

            _children.Add(handler);
            Event?.Invoke(this, SpellEvent.SubSpellCasted, handler);
        }