Example #1
0
        private void OnSlotHandlerStateChanged(int slotIndex, ISpellHandler handler, SpellEvent e, ISubSpellHandler subHandler)
        {
            var slotState = GetSpellSlotState(slotIndex);

            if (e == SpellEvent.StartedFiring)
            {
                slotState.State = SlotState.Firing;
            }
            else if (e == SpellEvent.FinishedFire || e == SpellEvent.Aborted || e == SpellEvent.Ended)
            {
                // If we are ending spell that has not yet started
                if (slotState.State == SlotState.Preparing)
                {
                    slotState.RemainingCooldown = 0.1f;
                }
                else
                {
                    slotState.RemainingCooldown = slotState.Spell.Cooldown.GetValue(slotState.NumStacks);
                }

                // Remove handler from state and start recharging
                slotState.SpellHandler = null;
                slotState.State        = SlotState.Recharging;

                if (NoCooldowns)
                {
                    slotState.RemainingCooldown = 0.1f;
                }
            }
        }
Example #2
0
        private void HandlerOnStateChanged(ISpellHandler handler, SpellEvent e, ISubSpellHandler subHandler)
        {
            // Even when event if from spell that is already not in slot - decrease hp for cast
            if (e == SpellEvent.SubSpellCasted && subHandler != null)
            {
                _characterState.ApplyModifier(
                    ModificationParameter.HpFlat,
                    -subHandler.SubSpell.BloodCost.GetValue(subHandler.Stacks),
                    _characterState,
                    null);
            }


            for (var i = 0; i < SpellSlots.Length; i++)
            {
                if (handler.Equals(SpellSlots[i].SpellHandler))
                {
                    OnSlotHandlerStateChanged(i, handler, e, subHandler);
                    return;
                }
            }

            // If the handler (finished or aborted state) is inactive - unsubscribe
            if (!handler.IsActive)
            {
                // Unsubscribe
                handler.Event -= HandlerOnStateChanged;
            }
        }
Example #3
0
    private void OnSpellEvent(SpellEvent e)
    {
        if (e.powerUp)
        {
            // Spell ON
            switch (e.powerType)
            {
            case Spells.Matrix:
                // Slow down the whole world except the player
                if (GameObject.FindWithTag("Player").GetComponent <ArchetypePlayer>().PowerInfinite)
                {
                    if (GameObject.FindWithTag("Player").GetComponent <ArchetypePlayer>().Matrix <= 0)
                    {
                        GUIManager.Instance.DisplayCurrentSpell("Slow Enemies");
                        MoveSpeed /= 2;
                    }
                }
                else
                {
                    StartCoroutine(SpellMatrixMode());
                }

                break;

            default:

                break;
            }
        }
        else
        {
            // Spell OFF
            switch (e.powerType)
            {
            case Spells.Matrix:

                if (GameObject.FindWithTag("Player").GetComponent <ArchetypePlayer>().Matrix < 1)
                {
                    GUIManager.Instance.HideSpell();
                    MoveSpeed *= 2;
                }


                break;

            default:

                break;
            }
        }
    }
    public void SpellTrigger(int spellId, SpellEvent evt)
    {
        if (!GameSystems.Spell.TryGetActiveSpell(spellId, out var activeSpell))
        {
            Logger.Warn("Trying to run spell event {0} for active spell id {1} which is unknown.",
                        evt, spellId);
            return;
        }

        if (!_scriptAssembly.TryCreateSpellScript(activeSpell.spellEnum, out var spellScript))
        {
            Logger.Warn("Failed to find spell script for spell id {0}", spellId);
            return;
        }

        // The spell effect gives each target a chance to cancel out the entire spell effect
        if (evt == SpellEvent.SpellEffect)
        {
            var cancel = false;
            foreach (var target in activeSpell.Targets)
            {
                if (GameSystems.Script.ExecuteObjectScript(activeSpell.caster, target.Object, spellId,
                                                           ObjScriptEvent.SpellCast) == 0)
                {
                    cancel = true;
                }
            }

            if (cancel)
            {
                return;
            }
        }

        switch (evt)
        {
        case SpellEvent.SpellEffect:
            spellScript.OnSpellEffect(activeSpell);
            break;

        case SpellEvent.BeginSpellCast:
            spellScript.OnBeginSpellCast(activeSpell);
            break;

        case SpellEvent.EndSpellCast:
            spellScript.OnEndSpellCast(activeSpell);
            break;

        case SpellEvent.BeginRound:
            spellScript.OnBeginRound(activeSpell);
            break;

        case SpellEvent.EndRound:
            spellScript.OnEndRound(activeSpell);
            break;

        case SpellEvent.BeginProjectile:
        case SpellEvent.EndProjectile:
            throw new ArgumentException($"This function cannot be used for the projectile events.");

        case SpellEvent.BeginRoundD20Ping:
            spellScript.OnBeginRoundD20Ping(activeSpell);
            break;

        case SpellEvent.EndRoundD20Ping:
            spellScript.OnEndRoundD20Ping(activeSpell);
            break;

        case SpellEvent.AreaOfEffectHit:
            spellScript.OnAreaOfEffectHit(activeSpell);
            break;

        case SpellEvent.SpellStruck:
            spellScript.OnSpellStruck(activeSpell);
            break;

        default:
            throw new ArgumentOutOfRangeException(nameof(evt), evt, null);
        }

        SpellSoundPlay(activeSpell, evt);
    }
    public bool SpellSoundPlay(SpellPacketBody spellPkt, SpellEvent spellEvt)
    {
        if (spellEvt > SpellEvent.SpellStruck)
        {
            return(false);
        }
        int spellSoundType;

        switch (spellEvt)
        {
        case SpellEvent.BeginSpellCast:
            spellSoundType = 0;
            break;

        case SpellEvent.EndSpellCast:
            spellSoundType = 1;
            break;

        case SpellEvent.SpellEffect:
            spellSoundType = 2;
            break;

        case SpellEvent.BeginRound:
            spellSoundType = 3;
            break;

        case SpellEvent.BeginProjectile:
            spellSoundType = 4;
            break;

        case SpellEvent.EndProjectile:
            spellSoundType = 5;
            break;

        case SpellEvent.AreaOfEffectHit:
            spellSoundType = 7;
            break;

        case SpellEvent.SpellStruck:
            spellSoundType = 8;
            break;

        default:
            return(false);
        }

        var        spellSoundId = spellSoundType + 20 * spellPkt.spellEnum + 6000;
        SpellEntry spellEntry   = GameSystems.Spell.GetSpellEntry(spellPkt.spellEnum);
        var        modeTarget   = spellEntry.modeTargetSemiBitmask.GetBaseMode();

        switch (spellEvt)
        {
        case SpellEvent.EndSpellCast:
            GameSystems.SoundGame.PositionalSound(spellSoundId, spellPkt.caster);
            return(true);

        case SpellEvent.SpellEffect:
        case SpellEvent.AreaOfEffectHit:
        case SpellEvent.SpellStruck:
            if (spellPkt.spellEnum == 133)
            {
                // Dispel Magic
                if (spellPkt.Targets.Length > 0)
                {
                    GameSystems.SoundGame.PositionalSound(8660, spellPkt.Targets[0].Object);
                }
                else
                {
                    GameSystems.SoundGame.PositionalSound(8660, spellPkt.aoeCenter.location);
                }

                return(true);
            }

            goto case SpellEvent.BeginRound;

        case SpellEvent.BeginRound:
            switch (modeTarget)
            {
            case UiPickerType.Single:
                if (spellPkt.Targets.Length > 0)
                {
                    GameSystems.SoundGame.PositionalSound(spellSoundId, spellPkt.Targets[0].Object);
                    return(true);
                }

                GameSystems.SoundGame.PositionalSound(spellSoundId, spellPkt.caster);
                break;

            case UiPickerType.Multi:
            case UiPickerType.Cone:

                if (spellPkt.Targets.Length == 0)
                {
                    GameSystems.SoundGame.PositionalSound(spellSoundId, spellPkt.caster);
                    return(true);
                }

                foreach (var target in spellPkt.Targets)
                {
                    GameSystems.SoundGame.PositionalSound(spellSoundId, target.Object);
                }

                break;

            case UiPickerType.Area:
                if (spellPkt.Targets.Length == 0)
                {
                    GameSystems.SoundGame.PositionalSound(spellSoundId, spellPkt.aoeCenter.location);
                    return(true);
                }

                foreach (var target in spellPkt.Targets)
                {
                    GameSystems.SoundGame.PositionalSound(spellSoundId, target.Object);
                }

                break;

            case UiPickerType.Wall:
            case UiPickerType.Location:
                GameSystems.SoundGame.PositionalSound(spellSoundId, spellPkt.aoeCenter.location);
                return(true);

            case UiPickerType.Personal:
            case UiPickerType.InventoryItem:
            case UiPickerType.Ray:
                GameSystems.SoundGame.PositionalSound(spellSoundId, spellPkt.caster);
                return(true);
            }

            return(true);


        case SpellEvent.BeginSpellCast:
            GameSystems.SoundGame.PositionalSound(spellSoundId, spellPkt.caster);
            return(true);

        case SpellEvent.BeginProjectile:
        case SpellEvent.EndProjectile:
            return(true);

        default:
            return(false);
        }
    }
 public void SpellTriggerProjectile(int spellId, SpellEvent evt, GameObject projectile, int projectileIdx)
 {
     throw new NotImplementedException();
 }
Example #7
0
 public void AddEvent(SpellEvent spellEvent)
 {
     events.Add(spellEvent);
 }
    private void OnSpellEvent(SpellEvent e)
    {
        SpellsType = e.powerType;

        if (e.powerUp)
        {
            // Spell ON
            StartCoroutine(SpellComplete(SpellsType));

            switch (SpellsType)
            {
            case Spells.SpeedShoot:
                // Speed up bubble rate
                if (PowerInfinite)
                {
                    if (_speedShoot <= 0)
                    {
                        GUIManager.Instance.DisplayCurrentSpell("Bubble Speedup");
                        GameConfig.numBubblesInterval /= BubbleSpeedIncrease;
                        PoweredUp = true;
                    }
                    else
                    {
                        GameConfig.numBubblesInterval /= BubbleSpeedIncrease;
                    }

                    _speedShoot++;
                }
                else
                {
                    StartCoroutine(SpellBubbleSpeed(PowerTime));
                }

                break;

            case Spells.ScatterShoot:
                // Make those bubbles scatter
                if (PowerInfinite)
                {
                    if (_scatterShoot <= 0)
                    {
                        GUIManager.Instance.DisplayCurrentSpell("Scatter Shot");
                        _scatterShootOn = true;
                        PoweredUp       = true;
                    }

                    _scatterShoot++;
                }
                else
                {
                    StartCoroutine(SpellScatterShoot(PowerTime));
                }
                break;

            case Spells.BigShoot:

                // Make those bubbles bigger
                if (PowerInfinite)
                {
                    if (_bigShoot <= 0)
                    {
                        GUIManager.Instance.DisplayCurrentSpell("Bigger Shoot");
                        Bubble.transform.localScale += new Vector3(BubbleSizeIncrease, BubbleSizeIncrease, 0);
                        PoweredUp = true;
                    }
                    else
                    {
                        Bubble.transform.localScale += new Vector3(BubbleSizeIncrease, BubbleSizeIncrease, 0);
                    }

                    _bigShoot++;
                }
                else
                {
                    StartCoroutine(SpellBigShoot(PowerTime));
                }
                break;

            case Spells.Matrix:

                Matrix++;
                break;
            }
        }
        else
        {
            // Spell OFF

            switch (SpellsType)
            {
            case Spells.SpeedShoot:
                if (_speedShoot <= 0)
                {
                    GUIManager.Instance.HideSpell();
                    GameConfig.numBubblesInterval *= BubbleSpeedIncrease;
                    PoweredUp = false;
                }
                else
                {
                    _speedShoot--;
                    GameConfig.numBubblesInterval *= BubbleSpeedIncrease;
                }


                break;

            case Spells.ScatterShoot:

                if (_scatterShoot <= 0)
                {
                    GUIManager.Instance.HideSpell();
                    _scatterShootOn = false;
                    PoweredUp       = false;
                }
                else
                {
                    _scatterShoot--;
                }

                break;

            case Spells.BigShoot:

                if (_bigShoot <= 0)
                {
                    GUIManager.Instance.HideSpell();
                    Bubble.transform.localScale -= new Vector3(BubbleSizeIncrease, BubbleSizeIncrease, 0);
                    PoweredUp = false;
                }
                else
                {
                    _bigShoot--;
                    Bubble.transform.localScale -= new Vector3(BubbleSizeIncrease, BubbleSizeIncrease, 0);
                }

                break;
            }
        }
    }