예제 #1
0
    public override void CastSpell(Spellbook spellbook, int spellIndex, Vector3 direction)
    {
        ///<summary>
        ///
        ///                                 PROJECTILE SPELLS
        ///
        ///     • Projectile it self only moves forwards until it's reached maxRange
        ///     • Projectiles can have multiple types of effects
        ///         - Projectiles can home towards closest enemy target
        ///         - Projectiles can have OnCollision modifiers that take effect when projectile collides with something (Split, Bounce, etc.)
        ///
        /// </summary>

        direction = spellbook.GetDirection2();
        Quaternion rot  = Quaternion.LookRotation(direction, Vector3.up);
        Projectile proj = Instantiate(this, spellbook.spellPos.position, rot);

        proj.direction = direction;

        foreach (ProjectileCard card in spellbook.spells[spellIndex].cards)
        {
            // add all modifiers to spell
            foreach (ProjectileModifierSO mod in card.projectileModifiers)
            {
                mod.AddSpellComponent(proj.gameObject);
            }
        }
    }
예제 #2
0
    IEnumerator CastBeam(GameObject self, Spellbook spellbook, int spellIndex)
    {
        while (true)
        {
            print("Casting beam");

            Vector3    direction = spellbook.GetDirection2();
            Ray        ray       = new Ray(spellbook.spellPos.position, direction * range);
            RaycastHit hit;

            // if beam hits something do this
            if (Physics.Raycast(ray, out hit))
            {
                Debug.DrawRay(spellbook.spellPos.position, hit.point, Color.green);
                print("Beam hits something");

                // apply beam effects here to target we hit
                if (hit.transform.GetComponent <Rigidbody>() != null)
                {
                    OnCollisionModifier[] collisionMods = GetComponents <OnCollisionModifier>();
                    foreach (OnCollisionModifier mod in collisionMods)
                    {
                        mod.OnCollision(hit.transform.gameObject);
                    }
                }
            }
            else
            {
                Debug.DrawRay(spellbook.spellPos.position, direction * range, Color.red);
            }


            if (Input.GetKeyUp((spellIndex + 1).ToString()) || !Input.GetKey((spellIndex + 1).ToString()))
            {
                print("Beam cast ended");
                break;
            }

            yield return(null);
        }

        spellbook.StopCasting();
        spellbook.SetCooldown();
        Destroy(self);
    }
예제 #3
0
    private IEnumerator Teleport(GameObject go)
    {
        // Record initial state:
        var initialTime     = Time.time;
        var initialPosition = transform.position;
        var initialFov      = Camera.main.fieldOfView;

        Vector3 destination = transform.position + spellbook.GetDirection2() * distance;

        go.GetComponentInChildren <MeshRenderer>().enabled = false;

        // Teleport a little bit each frame:
        while (Time.time < initialTime + duration)
        {
            spellbook.isCasting = true;

            var elapsed = Time.time - initialTime;
            transform.position = Vector3.Lerp(initialPosition, destination, elapsed / totalDuration);
            if (Time.time < initialTime + warpFovDuration)
            {
                // Ease FOV into teleport mode:
                Camera.main.fieldOfView = Mathf.Lerp(initialFov, warpFov, elapsed / warpFovDuration);
            }
            else if (Time.time > initialTime + duration - warpFovDuration)
            {
                // Ease FOV out of teleport mode:
                var easeOutElapsed = elapsed - (duration - warpFovDuration);
                Camera.main.fieldOfView = Mathf.Lerp(warpFov, initialFov, easeOutElapsed / warpFovDuration);
            }
            yield return(null);
        }

        go.GetComponentInChildren <MeshRenderer>().enabled = true;
        spellbook.StopCasting();
        spellbook.SetCooldown();

        Destroy(this);
    }