Exemple #1
0
    private IEnumerator AttackShield(string spellName)
    {
        Transform currentTarget = MyTarget;

        Spell newSpell = SpellBook.MyInstance.CastSpell(spellName, this);

        if (MyMana.MyCurrentValue >= newSpell.MyManaCost)
        {
            MyAnimator.SetBool("attackShield", true);
            isAttackingShield = true;
            yield return(new WaitForSeconds(newSpell.MyCastTime));             //tempo de cast da magia

            //CastSpell ();

            if (currentTarget != null && InLineOfSight())
            {
                SpellScript s = Instantiate(newSpell.MySpellPrefab, exitPoints [exitIndex].position, Quaternion.identity).GetComponent <SpellScript> ();                  //quaternion não deixar rotacionar

                s.Initialize(currentTarget, newSpell.MyDamage, transform);

                MyMana.MyCurrentValue -= newSpell.MyManaCost;
            }

            StopAttackShield();
        }
    }
 public void EquipSpell(SpellScript spell)
 {
     if (!ListEquippedSpell.Exists(x => x.Code.Equals(spell.Code)))
     {
         ListEquippedSpell.Add(spell);
     }
 }
Exemple #3
0
    /// <summary>
    /// A co routine for attacking
    /// </summary>
    /// <returns></returns>
    private IEnumerator Attack(string spellName)
    {
        Transform currentTarget = MyTarget;

        //Creates a new spell, so that we can use the information form it to cast it in the game
        Spell newSpell = SpellBook.MyInstance.CastSpell(spellName);

        IsAttacking = true;                        //Indicates if we are attacking

        MyAnimator.SetBool("attack", IsAttacking); //Starts the attack animation

        foreach (GearSocket g in gearSockets)
        {
            g.MyAnimator.SetBool("attack", IsAttacking);
        }

        yield return(new WaitForSeconds(newSpell.MyCastTime)); //This is a hardcoded cast time, for debugging

        if (currentTarget != null && InLineOfSight())
        {
            SpellScript s = Instantiate(newSpell.MySpellPrefab, exitPoints[exitIndex].position, Quaternion.identity).GetComponent <SpellScript>();

            s.Initialize(currentTarget, newSpell.MyDamage, transform);
        }

        StopAttack(); //Ends the attack
    }
Exemple #4
0
    /// <summary> Function to Attack (IEnumerator to WaitForSecond Cast Time) </summary>
    private IEnumerator Attack(int spellIndex)
    {
        // Current Target is Last Clicked Target
        Transform currentTarget = MyTarget;
        // Get a new Spell from Spellbook (on Index of Array)
        Spell newSpell = spellBook.CastSpell(spellIndex);

        // Set Character Is Attacking to True to Activate the Attack Layer
        isAttacking = true;
        // Set the Animator to Attack Animation
        myAnimator.SetBool("isAttacking", isAttacking);
        // Cast Time; Wait for Amount of Seconds
        yield return(new WaitForSeconds(newSpell.MyCastTime));

        // Check if Target is Still there & InLine of Sight
        if (currentTarget != null && InLineOfSight())
        {
            // Instantiate a Spell (Get the First Spell, from possible Spell Prefabs, on the Player Pos, with Own Rot)
            SpellScript s = Instantiate(newSpell.MySpellPrefab, gemPoints[gemIndex].position, Quaternion.identity).GetComponent <SpellScript>();
            // Initialize new Spell ( Set target & Damage )
            s.Initialize(currentTarget, newSpell.MyDamage);
        }
        // After cast, Stop Attacking
        StopAttack();
    }
Exemple #5
0
    private void Fire(int index)
    {
        SpellScript.Spell spell = spells[index];
        if (spell != null)
        {
            float manaCost = -spell.ManaCost();
            if (stats.ModifyMana(-10))
            {
                lock (_lock) canFire = false;
                companion.didFire = true;
                StartCoroutine(FireCooldown());
                // create spell instance
                Vector3 startPos = transform.position;
                startPos.y += 0.5f;
                // Put the spell a bit in front of us
                startPos += transform.forward * 0.75f;
                Vector3 rotEuler = transform.rotation.eulerAngles;
                rotEuler.x = 90f;
                GameObject spellObject = Instantiate(emptySpellPrefab, startPos, Quaternion.Euler(rotEuler)) as GameObject;

                // Add the spell effects
                SpellScript spellScript = spellObject.GetComponent <SpellScript>();
                spellScript.spell  = spell;
                spellScript.parent = gameObject;
                castSpells.Add(spellObject);
            }
        }
    }
Exemple #6
0
    public override void Start(SpellScript self)
    {
        base.Start(self);
        // Create rigidbody and move it forward
        Rigidbody boltBody = self.gameObject.AddComponent <Rigidbody>() as Rigidbody;

        boltBody.drag       = 0;
        boltBody.useGravity = false;
        boltBody.velocity   = self.transform.up * forwardVelocity;



        /*
         * // Create bolt collider
         * CapsuleCollider boltCollider = self.gameObject.AddComponent<CapsuleCollider>() as CapsuleCollider;
         * boltCollider.isTrigger = true;
         * boltCollider.radius = 0.25f;
         * boltCollider.height = 0.75f;
         * //*/

        // Create ball effect
        GameObject sphere = GameObject.Instantiate(Resources.Load <GameObject>("sphere"), self.transform);

        // Decay
        self.StartCoroutine("Decay", 3f);
    }
Exemple #7
0
    /// <summary>
    /// Attaque
    /// </summary>
    /// <param name="exitIndex">Index de la position d'attaque</param>
    public void Shoot(int exitIndex)
    {
        // Instantie la flèche
        SpellScript arrow = Instantiate(arrowPrefab, exitPoints[exitIndex].position, Quaternion.identity).GetComponent <SpellScript>();

        // Affecte la cible et les dégâts de la flèche
        arrow.Initialize(MyTarget.MyHitBox, damage, this);
    }
Exemple #8
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Enemy")
     {
         spellScript = gameObject.GetComponent <SpellScript>();
         other.GetComponent <Enemy>().TakeDamage(transform.position, spellScript.damage, spellScript.source, Color.white);
     }
 }
Exemple #9
0
    public override void Start(SpellScript self)
    {
        base.Start(self);
        // Create ball collider
        SphereCollider boltCollider = self.gameObject.AddComponent <SphereCollider>();

        boltCollider.isTrigger = true;
        boltCollider.radius    = 0.75f;
    }
Exemple #10
0
    // public void CastSpellLight(string spellname, int index){

    //     Vector3 mousepos = UtilClass.GetMouseWorldPosition();


    //     float distance = Vector3.Distance(mousepos,transform.position);
    //         if (distance <= lightingRange)
    //             {
    //                 Spell spell = GetSpell(spellname);

    //             if (currentCooldowns[index] <= 0){
    //                 if (player.SpendMana(spell.ManaCost)){
    //                     currentCooldowns[index] = spell.Cooldown;
    //                     castingProgess = true;

    //                     Vector3 origOffset = new Vector3(mousepos.x, mousepos.y + 130f, mousepos.z);
    //                     Vector3 mousedir = (mousepos - origOffset);
    //                     float rotation = UtilClass.GetAngleFromVectorFloat(mousedir);
    //                     LightSpell lightSpell = Instantiate(spell.MySpellPrefab, origOffset, Quaternion.Euler(0,0,rotation)).GetComponent<LightSpell>();
    //                     lightSpell.TargetPos = mousepos;
    //                     lightSpell.source = transform;
    //                     lightSpell.damage = spell.MyDamage;
    //                     lightSpell.Speed = 1f;


    //                     }
    //         }
    //     }
    // }

    private void ActualCast(Spell spell, float rotated, Vector3 mousepos)
    {
        SpellScript spellScript = Instantiate(spell.MySpellPrefab, transform.position + offset[offsetIndex], Quaternion.Euler(0, 0, rotated)).GetComponent <SpellScript>();

        spellScript.TargetPos = mousepos;
        spellScript.source    = transform;
        spellScript.damage    = spell.MyDamage;
        spellScript.Speed     = 3f;
    }
Exemple #11
0
 public Spell(AIUnit owner, SpellRecord record, byte slot, SpellScript script, bool isSummonerSpell)
 {
     this.Owner  = owner;
     this.Record = record;
     this.Slot   = slot;
     this.Script = script;
     this.Script?.Bind(this);
     this.State           = SpellStateEnum.STATE_READY;
     this.IsSummonerSpell = isSummonerSpell;
 }
Exemple #12
0
    public override void Start(SpellScript self)
    {
        base.Start(self);
        // Create ball collider
        SphereCollider boltCollider = self.gameObject.AddComponent <SphereCollider>();

        boltCollider.isTrigger  = true;
        boltCollider.radius     = 0.75f;
        self.transform.position = target.transform.position;
        self.transform.rotation = target.transform.rotation;
    }
Exemple #13
0
    void BasicAttack(int dir, Vector3 mousepos, Vector3 mousedir)
    {
        float rotation = UtilClass.GetAngleFromVectorFloat(mousedir);

        SpellScript basicAttack = Instantiate(GameAssets.i.basicAttack, transform.position + offset[dir], Quaternion.Euler(0, 0, rotation)).GetComponent <SpellScript>();

        basicAttack.TargetPos = mousepos;
        basicAttack.source    = transform;
        basicAttack.damage    = damageAmount;
        basicAttack.Speed     = 3f;
    }
Exemple #14
0
    public static void ShowSpellRange(CellScript center, SpellScript spell)
    {
        // Foreach to set cells to "inSpellRange"
        // If obstacle, ally, ext.. check is spell possible
        // If spell have vision,
        // Then bresenham to check if you can see it
        List <CellScript> cells = new List <CellScript>();
        int distance;

        foreach (CellScript cell in grid)
        {
            distance = center.Distance(cell);
            if (distance <= spell.minRange && distance >= spell.maxRange)
            {
                // Conditions are inversed so we can factorize the code
                if (cell.target == null && !spell.onEmpty)
                {
                    continue;
                }
                switch (cell.target.GetTypeOfTarget())
                {
                case Type.ally: if (!spell.onAlly)
                    {
                        continue;
                    }
                    break;

                case Type.water: if (!spell.onWater)
                    {
                        continue;
                    }
                    break;

                case Type.ennemy: if (!spell.onEnnemy)
                    {
                        continue;
                    }
                    break;

                case Type.obstacle: if (!spell.onObstacle)
                    {
                        continue;
                    }
                    break;
                }
                cell.isInSpellRange = true;
                cells.Add(cell);
            }
        }
        if (spell.needVision)
        {
            BresenhamLine(center, cells);
        }
    }
 public override bool Trigger(SpellScript self, GameObject other)
 {
     if (other.CompareTag("GoodGuy") || other.CompareTag("BadGuy") || other.CompareTag("Player"))
     {
         agent.AddReward(hitScore);
     }
     else
     {
         agent.AddReward(missScore);
     }
     return(false);
 }
Exemple #16
0
    public override void Update(SpellScript self, List <GameObject> others = null)
    {
        Vector3 scale = self.transform.localScale;
        float   inc   = increment * Time.deltaTime;

        scale += new Vector3(inc, inc, inc);
        self.transform.localScale = scale;
        if (scale.x >= maxSize)
        {
            DestroyAndStartChildren(self.gameObject);
        }
    }
Exemple #17
0
    private IEnumerator Attack(string spellName)
    {
        Transform currentTarget = MyTarget;
        Spell     newSpell      = SpellBook.Instance.CastSpell(spellName);

        IsAttacking = true;
        MyAnimator.SetBool("Attack", IsAttacking);
        yield return(new WaitForSeconds(newSpell.MyCastTime)); //test cast time for debugging

        if (MyTarget != null && InLineOfSight())
        {
            SpellScript s = Instantiate(newSpell.MySpellPrefab, exitPoints[exitIndex].position, Quaternion.identity).GetComponent <SpellScript>();
            s.Initialize(currentTarget, newSpell.MyDamage, transform);
        }
        StopAttack();
    }
Exemple #18
0
    private IEnumerator Attack(string spellName)
    {
        int[] numbers;

        Transform currentTarget = MyTarget;

        Spell newSpell = SpellBook.MyInstance.CastSpell(spellName);

        IsAttacking = true;

        MyAnimator.SetBool("Attack", IsAttacking);

        yield return(new WaitForSeconds(newSpell.MyCastTime));

        if (currentTarget != null && InLineOfSight())
        {
            SpellScript s      = Instantiate(newSpell.MySpellPrefab, exitPoints[exitIndex].position, Quaternion.identity).GetComponent <SpellScript>();
            int         damage = newSpell.calcDamage();
            bool        strike = IsStrikeAttack();
            if (strike)
            {
                damage *= 2;
            }

            s.Initialize(currentTarget, damage, newSpell.MySpellNumber, transform);

            numbers = DamageTextManager.MyInstance.seperateNumber(damage);

            for (int i = 0; i < numbers.Length; i++)
            {
                float adj = numbers.Length / 2;

                if (numbers.Length % 2 == 0)
                {
                    adj -= 0.5f;
                }

                Vector3 tmpVector3 = new Vector3(0.4f * (i - adj), 0, 0);

                tmpVector3 += MyTarget.transform.position;

                DamageTextManager.MyInstance.CreateText(tmpVector3, numbers[i], DMGTEXTTYPE.ATTACK, strike);
            }
        }

        StopAttack();
    }
    //Jeremiah's Functions
    private IEnumerator Attack(string spellName)
    {
        Transform currentTarget = MyTarget;

        Spell newSpell = SpellBook.MyInstance.CastSpell(spellName);

        isAttacking = true;
        yield return(new WaitForSeconds(newSpell.MyCastTime));

        if (currentTarget != null)//&& InLineOfSight()
        {
            SpellScript s = Instantiate(newSpell.MySpellPrefab, transform.position, Quaternion.identity).GetComponent <SpellScript>();
            s.Initialize(currentTarget, newSpell.MyDamage);
        }

        StopAttack();
    }
Exemple #20
0
    private IEnumerator Attack(int spellIndex)
    {
        Transform currentTarget = MyTarget; // 防止在施法过程中改变目标
        Spell     newSpell      = spellBook.CastSpell(spellIndex);

        isAttacking = true;
        mAnimator.SetBool("attack", isAttacking);
        yield return(new WaitForSeconds(newSpell.MyCastTime));

        Debug.Log("create" + spellIndex);
        if (currentTarget != null)
        {
            SpellScript s = Instantiate(newSpell.MySpellPrefab, exitPoints[exitIndex].position, Quaternion.identity).GetComponent <SpellScript> ();
            s.Initialize(currentTarget, newSpell.MyDamage);
        }
        StopAttack();
    }
Exemple #21
0
    // Makes the enemy attack the player
    public IEnumerator Attack()
    {
        Spell     newSpell      = SpellBook.Instance.CastSpell("Fire");
        Transform currentTarget = parent.Target;

        parent.IsAttacking = true;

        parent.Animator.SetTrigger("attack");
        //gets attack layer from animator(2)
        yield return(new WaitForSeconds(parent.Animator.GetCurrentAnimatorStateInfo(2).length));

        SpellScript spell = GameObject.Instantiate(newSpell.SpellPrefab, parent.ExitPoints[parent.ExitIndex].position, Quaternion.identity).GetComponent <SpellScript>() as SpellScript;

        //set spell target to players target
        spell.Initialize(currentTarget, newSpell.Damage, parent.transform);

        parent.IsAttacking = false;
    }
Exemple #22
0
    private IEnumerator Attack(int spellIndex)
    {
        Transform currentTarget = MyTarget;
        Spell     spell         = spellbook.CastSpell(spellIndex);

        IsAttacking = true;
        Animator.SetBool("attack", IsAttacking);

        yield return(new WaitForSeconds(spell.CastTime));

        if (currentTarget != null && InLineOfSight())
        {
            SpellScript spellScript = Instantiate(spell.SpellPrefab, exitPoints[exitIndex].position, Quaternion.identity).GetComponent <SpellScript>();
            spellScript.Initialize(currentTarget, spell.Damage);
        }

        StopAttack();
    }
Exemple #23
0
    /// <summary>
    /// A co routine for attacking
    /// </summary>
    /// <returns></returns>
    private IEnumerator AttackRoutine(ICastable castable)
    {
        Transform currentTarget = MyTarget.MyHitbox;

        yield return(actionRoutine = StartCoroutine(ActionRoutine(castable)));

        if (currentTarget != null && InLineOfSight())
        {
            Spell newSpell = SpellBook.MyInstance.GetSpell(castable.MyTitle);

            SpellScript s = Instantiate(newSpell.MySpellPrefab, exitPoints[exitIndex].position, Quaternion.identity).GetComponent <SpellScript>();

            s.Initialize(currentTarget, newSpell.MyDamage, this, newSpell.MyDebuff);

            mana.MyCurrentValue -= newSpell.ManaCost;
        }

        StopAction(); //Ends the attack
    }
Exemple #24
0
    private void AttackLogic(int spellIndex, Spell newSpell, Vector2 currentTarget)
    {
        if (newSpell.MyBasicSpell) //  BASIC SPELL ATTACK CASE
        {
            PlayerLookAtTarget();

            SpellScript s = Instantiate(newSpell.MySpellPrefab, exitPoints[exitIndex].position, Quaternion.identity).GetComponent <SpellScript>();    //instantiate the spell in the exitpoint and get the spellScript
            s.mySpeed(spellBook.spells[spellIndex].MySpeed);
            s.InitilizeV3(Camera.main.ScreenToWorldPoint(Input.mousePosition), newSpell.MyDamage);
        }

        else //INSTANT DROP CASE
        {
            if (newSpell.MyName == "Teleport")
            {
                TelportationAbility();
            }
        }
    }
Exemple #25
0
    private IEnumerator Attack(string spellName)
    {
        Transform currentTarget = MyTarget;
        Spell     newSpell      = SpellBook.MyInstance.CastSpell(spellName);

        animatorSpeed = MyAnimator.speed;

        MyAnimator.speed = 2 / newSpell.MyCastTime;

        yield return(new WaitForSeconds(newSpell.MyCastTime));

        if (currentTarget != null && InLineOfSight(currentTarget))
        {
            SpellScript s = Instantiate(newSpell.MySpellPrefab, exitPoints[MyExitIndex].position, Quaternion.identity).GetComponent <SpellScript>();
            s.Initialize(currentTarget, newSpell.MyDamage, newSpell.MySpeed, newSpell.MySlowEffect, transform);
        }
        MyAnimator.speed = animatorSpeed;
        StopAttack();
    }
Exemple #26
0
    public IEnumerator Attack(int spellIndex)
    {
        if (!isAttacking && !IsMoving && InLineOfSight())
        {
            Transform currentTarget = Target;
            Spell     newSpell      = spellBook.CastSpell(spellIndex);
            isAttacking = true;
            animator.SetBool("attack", isAttacking);
            yield return(new WaitForSeconds(newSpell.CastTime));

            //CastSpell();
            if (currentTarget && InLineOfSight())
            {
                GameObject  spellObj        = Instantiate(newSpell.SpellPrefab, exitPoints[exitIndex].position, Quaternion.identity);
                SpellScript spellController = spellObj.GetComponent <SpellScript>();
                spellController.Fire(Target, newSpell);
            }
            StopAttack();
        }
    }
Exemple #27
0
    private IEnumerator Attack(int spellIndex)
    {
        Transform currentTarget = MyTarget;

        Spell newSpell = spellBook.CastSpell(spellIndex);

        attacking = true;

        myAnimator.SetBool("attack", attacking);

        yield return(new WaitForSeconds(newSpell.CastTime)); // hard coded cast time for debugging

        if (currentTarget != null && InLineOfSight())
        {
            SpellScript s = Instantiate(newSpell.SpellPrefab, exitPoints[(int)exitIndex].position, Quaternion.identity).GetComponent <SpellScript>();

            s.Initialize(currentTarget, newSpell.Damage);
        }

        StopAttack();
    }
Exemple #28
0
    //good for puttign delays
    private IEnumerator Attack(string spellName) //spellindex determines which prefab to use
    {
        Transform currentTarget = MyTarget;      //Made current Target to prevent player from swapping target mid cast
        Spell     newSpell      = SpellBook.MyInstance.CastSpelll(spellName);

        IsAttacking = true;
        MyAnimator.SetBool("attack", IsAttacking);
        foreach (GearSocket g in gearSockets)
        {
            g.MyAnimator.SetBool("attack", IsAttacking);
        }
        yield return(new WaitForSeconds(newSpell.MyCastTime)); //cast time

        if (currentTarget != null && InLineOfSight())          //fix for the bug where the player can still hit enemy even out of sight once cast time is activated
        {
            SpellScript s = Instantiate(newSpell.MySpellPrefab, exitPoints[exitIndex].position, Quaternion.identity).GetComponent <SpellScript>();
            s.Initialize(currentTarget, newSpell.MyDamage, transform);
        }

        StopAttack();
    }
Exemple #29
0
    //----ATTACK AND SPELLS----
    // A co routine for attacking
    private IEnumerator Attack(string spellName)
    {
        Spell     newSpell      = SpellBook.Instance.CastSpell(spellName);
        Transform currentTarget = Target;

        IsAttacking = true;                      //Indicates if we are attacking

        Animator.SetBool("attack", IsAttacking); //Starts the attack animation

        yield return(new WaitForSeconds(newSpell.CastTime));

        //set the players target
        if (currentTarget != null && RaycastSight())
        {
            SpellScript spell = Instantiate(newSpell.SpellPrefab, ExitPoints[ExitIndex].position, Quaternion.identity).GetComponent <SpellScript>();
            //set spell target to players target
            spell.Initialize(currentTarget, newSpell.Damage, transform);
            shield.PlayerCurrentValue -= 5;
        }
        StopAttack(); //Ends the attack
    }
Exemple #30
0
    //helps with attacking
    private IEnumerator Attack(int spellIndex)
    {
        Transform currentTarget = myTarget; //makes it so the player can't change their target mid-attack & stops attack if target dies

        //Creates a new spell so that we can use the information from it to cast the spell in game
        Spell newSpell = spellBook.CastSpell(spellIndex);

        isAttacking = true; //indicates if we are attacking

        myAnimator.SetBool("attack", isAttacking);


        yield return(new WaitForSeconds(newSpell.MyCastTime)); //hardcoded cast time

        if (currentTarget != null && InLineOfSight())
        {
            SpellScript s = Instantiate(newSpell.MySpellPrefab, exitPoints[exitIndex].position, Quaternion.identity).GetComponent <SpellScript>();  //Uses the spell associated with the spellIndex

            s.Initialize(currentTarget, newSpell.MyDamage);
        }

        StopAttack(); //end the current attack
    }