Exemplo n.º 1
0
        public ISpellHandler Cast(Spell spell, CharacterState caster, Target target, int stacks)
        {
            if (!target.IsValid)
            {
                return(null);
            }

            if (caster == null || !caster.IsAlive)
            {
                return(null);
            }

            Assert.IsNotNull(spell);

            if (target.Type != spell.TargetType)
            {
                Debug.LogWarning($"Can't cast {spell.name}. Invalid target, required type: {spell.TargetType}, got {target.Type}", this);
                return(null);
            }

            var source   = new Target(caster);
            var minRange = spell.MinRange.GetValue(stacks);
            var maxRange = spell.MaxRange.GetValue(stacks);



            if (spell.CheckRangeOnCast && !TargetUtility.IsInRange(source, target, minRange, maxRange))
            {
                Debug.LogWarning($"Can't cast {spell.name}. Out of range", this);
                return(null);
            }

            if (target.Type == TargetType.Character &&
                !TargetUtility.IsValidTeam(caster, target.Character, spell.AffectsTeam))
            {
                Debug.LogWarning($"Can't cast {spell.name}. Invalid team", this);
                return(null);
            }

            var state = new SpellHandler(spell, source, target, stacks);

            _activeSpellStates.Add(state);
            return(state);
        }
Exemplo n.º 2
0
        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
        }