Ejemplo n.º 1
0
    private void CastSpell(ISpellGesture gesture)
    {
        //If attempting to cast and CurrentSpell isn't activated, activate
        //Otherwise, adjust
        if (gesture.IsCast && !CurrentSpell.IsActive)
        {
            bool success = CurrentSpell.Activate();

            //Failed to activate spell, so return to Adjust state.
            if (!success)
            {
                State = SpellCastingState.Adjust;
                return;
            }

            //If the spell isn't channeled, prepare to cast a new spell
            if (success && !CurrentSpell.IsChanneled)
            {
                CurrentSpell = null;
                SpellElement = SpellElement.None;
                SpellTier    = SpellTier.None;
                State        = SpellCastingState.Select;
            }
            else
            {
                StartCoroutine(MonitorChanneledSpell());
            }
        }
        else
        {
            AdjustSpell(gesture);
        }
    }
Ejemplo n.º 2
0
    private void AdjustSpell(ISpellGesture gesture)
    {
        //Adjust the spell (attribute and aim)
        SpellAttribute?attr = gesture.Attribute;

        if (attr.HasValue)
        {
            bool success = CurrentSpell.AdjustAttribute(attr.Value, gesture.AttributePower);
            if (!success)
            {
                Debug.LogWarning("TODO: 'Failed to adjust attribute' SFX/VFX");
            }
        }
        CurrentSpell.AdjustAim(gesture);

        //Start casting the spell if appropriate
        if (State == SpellCastingState.Adjust && gesture.IsCast)
        {
            State = SpellCastingState.Cast;
            CastSpell(gesture);
        }
    }
Ejemplo n.º 3
0
    private void SelectSpell(ISpellGesture gesture)
    {
        //Extract element and tier from the gesture
        SpellElement?elem = gesture.Element;
        SpellTier?   tier = gesture.Tier;

        //If elem/tier exist, store their value
        SpellElement = elem.GetValueOrDefault(SpellElement);
        SpellTier    = tier.GetValueOrDefault(SpellTier);

        //If an element and tier have been selected, transition to the Adjust state
        if (SpellElement != SpellElement.None && SpellTier != SpellTier.None)
        {
            foreach (Spell spellPrefab in spellPrefabs)
            {
                if (spellPrefab.Element == SpellElement && spellPrefab.Tier == SpellTier)
                {
                    CurrentSpell = Instantiate(spellPrefab, gesture.AttachmentPoint);
                    State        = SpellCastingState.Adjust;
                    AdjustSpell(gesture);
                    break;
                }
            }

            if (CurrentSpell == null)
            {
                Debug.LogWarningFormat(
                    "No spell prefab found for (Element, Tier) = ({0}, {1})",
                    SpellElement.ToString(), SpellTier.ToString()
                    );

                SpellElement = SpellElement.None;
                SpellTier    = SpellTier.None;
            }
        }
    }
Ejemplo n.º 4
0
    public void PublishGesture(ISpellGesture gesture)
    {
        bool spellWasDestroyed = CurrentSpell != null && CurrentSpell.Equals(null);

        //Process cancel gesture.
        //A spell can be canceled at any time.
        if (gesture.IsCancel || spellWasDestroyed)
        {
            State = SpellCastingState.Cancel;
        }

        switch (State)
        {
        case SpellCastingState.None:
            break;

        case SpellCastingState.Select:
            SelectSpell(gesture);
            break;

        case SpellCastingState.Adjust:
            AdjustSpell(gesture);
            break;

        case SpellCastingState.Cast:
            CastSpell(gesture);
            break;

        case SpellCastingState.Cancel:
            CancelSpell();
            break;

        default:
            throw new System.InvalidOperationException("Illegal enum value.");
        }
    }
Ejemplo n.º 5
0
 public void AdjustAim(ISpellGesture gesture)
 {
     Aim = gesture.Aim;
 }