IEnumerator playShootingAnimation(float time)
    {
        yield return(new WaitForSeconds(time));

        plantPackedSprite.PlayAnim("beforeShooting");
        StartCoroutine(playRestAnimation(plantPackedSprite.GetAnim("beforeShooting").GetLength()));
    }
    // Update is called once per frame
    void Update()
    {
        if (Time.time - startTime < sprites.GetAnim("Effect").GetDuration())
        {
            sprites.DoAnim("Effect");
        }
        else if (Time.time - startTime > sprites.GetAnim("Effect").GetDuration())
        {
            Destroy(gameObject);
        }

        if (test)
        {
            transform.position = transform.position + new Vector3(0, 0, 0.1f);
            test = false;
        }
        else
        {
            transform.position = transform.position + new Vector3(0, 0, -0.1f);
            test = true;
        }
    }
    void OnParticleCollision(GameObject col)
    {
        //Debug.Log(col.tag);
        if (col.CompareTag("CatapultPlant"))
        {
            // Gettign Packed Sprite of CatapultPlant game object
            plantPackedSprite      = (PackedSprite)(col.transform.parent.GetComponent("PackedSprite"));
            catapultPlantTransform = col.transform.parent.gameObject.transform;

            if (!plantPackedSprite.IsAnimating())
            {
                soundMangScript.Scene_Source.clip = soundMangScript.CatapultPlantSneezeClip;
                soundMangScript.Scene_Source.Play();
                DeactiveColliders();
                StartCoroutine(playShootingAnimation(plantPackedSprite.GetAnim("Sleeping").GetLength()));
            }
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (Time.time - startTime < sprites.GetAnim("Start").GetDuration())
        {
            sprites.DoAnim("Start");
        }
        else if (Time.time - startTime > sprites.GetAnim("Start").GetDuration() + duration &&
                 Time.time - startTime < sprites.GetAnim("Start").GetDuration() + duration +
                 sprites.GetAnim("End").GetDuration())
        {
            sprites.DoAnim("End");
            GetComponent <BoxCollider>().enabled = false;
            if (!control)
            {
                audio.clip   = soundEffectDestroy;
                audio.volume = 0.7f;
                audio.Play();
                control = true;
            }
        }
        else if (Time.time - startTime > sprites.GetAnim("Start").GetDuration() + duration +
                 sprites.GetAnim("End").GetDuration() + 1)
        {
            Destroy(gameObject);
        }

        if (test)
        {
            transform.position = transform.position + new Vector3(0, 0, 0.1f);
            test = false;
        }
        else
        {
            transform.position = transform.position + new Vector3(0, 0, -0.1f);
            test = true;
        }
    }
    private void skillLifeDrainInvoked()
    {
        float preCooldown;

        if (isNearPlayer)
        {
            preCooldown = 0;
        }
        else
        {
            preCooldown = skillTeleport.GetAnim("Departure (L)").GetDuration() +
                          skillTeleport.GetAnim("Arrival (L)").GetDuration();
        }

        float conjurationTime1 = sprites.GetAnim("Casting 1 (L)").GetDuration();
        float conjurationTime2 = 1;

        if (Time.time - lastCastTime < preCooldown + conjurationTime1)
        {
            doAnimToDirection("Casting 1");
        }
        else if (Time.time - lastCastTime < preCooldown + conjurationTime1 + conjurationTime2 * 1 && !magicInterrupted)
        {
            doAnimToDirection("Casting 2");
            skillLifeDrainPlayer.GetComponent <LifeDrainPlayer>().activate();
            skillLifeDrain.DoAnim("Effect");
            float stolenHP;
            if (controlLifeDrain == 0)
            {
                audio.PlayOneShot(sound_drain);
                float stealDamage = 10;
                stolenHP = player.GetComponent <PlayerAttributes>().maxHP *stealDamage / 100;
                player.GetComponent <Controls>().gotDamaged(stolenHP, Controls.Enemy.BossLifeDrain);
                curHP += stolenHP * 1.5f;
                if (curHP > maxHP)
                {
                    curHP = maxHP;
                }
                controlLifeDrain = 1;
                moreSkillsSprite.DoAnim("LifeDrain");
            }
        }
        else if (Time.time - lastCastTime < preCooldown + conjurationTime1 + conjurationTime2 * 2 && !magicInterrupted)
        {
            doAnimToDirection("Casting 2");
            skillLifeDrain.DoAnim("Effect");
            float stolenHP;
            if (controlLifeDrain == 1)
            {
                float stealDamage = 10;
                stolenHP = player.GetComponent <PlayerAttributes>().maxHP *stealDamage / 100;
                player.GetComponent <Controls>().gotDamaged(stolenHP, Controls.Enemy.BossLifeDrain);
                curHP += stolenHP * 1.5f;
                if (curHP > maxHP)
                {
                    curHP = maxHP;
                }
                controlLifeDrain = 2;
                moreSkillsSprite.DoAnim("LifeDrain");
            }
        }
        else if (Time.time - lastCastTime < preCooldown + conjurationTime1 + conjurationTime2 * 3 && !magicInterrupted)
        {
            doAnimToDirection("Casting 2");
            skillLifeDrain.DoAnim("Effect");
            float stolenHP;
            if (controlLifeDrain == 2)
            {
                float stealDamage = 10;
                stolenHP = player.GetComponent <PlayerAttributes>().maxHP *stealDamage / 100;
                player.GetComponent <Controls>().gotDamaged(stolenHP, Controls.Enemy.BossLifeDrain);
                curHP += stolenHP * 1.5f;
                if (curHP > maxHP)
                {
                    curHP = maxHP;
                }
                controlLifeDrain = 3;
                moreSkillsSprite.DoAnim("LifeDrain");
            }
        }
        else
        {
            skillLifeDrain.StopAnim();
            lastCastTime        = -1;
            wasCasting          = false;
            wasCastingLifeDrain = false;
            skillLifeDrainPlayer.GetComponent <LifeDrainPlayer>().desactivate();
            controlLifeDrain = 0;
            doAnimToDirection("Standing");
            curLifeDrainCooldown = lifeDrainCooldown;
            curGlobalCooldown    = globalCooldown;
        }
    }
    void Update()
    {
        decreaseCooldowns();

        if (lastCastTime != -1)
        {
            doAnimToDirection(lastAnimation);

            if (wasCasting)
            {
                if (wasCastingSummon)
                {
                    if (isCentralized)
                    {
                        skillSummonInvoked();
                    }
                    else
                    {
                        if (positionizeSkillInvoked(teleportPoint_central))
                        {
                            skillSummonInvoked();
                        }
                    }
                    return;
                }
                if (wasCastingIcicle)
                {
                    skillIcicleInvoked();
                    return;
                }
                if (wasCastingBlame)
                {
                    if (isCentralized)
                    {
                        skillBlameInvoked();
                    }
                    else
                    {
                        if (positionizeSkillInvoked(teleportPoint_central))
                        {
                            skillBlameInvoked();
                        }
                    }
                    return;
                }
                if (wasCastingCurse)
                {
                    if (isNearPlayer)
                    {
                        skillCurseInvoked();
                    }
                    else
                    {
                        List <GameObject> unsafePoints = unsafeTeleportPoints();
                        int pos = random.Next(0, unsafePoints.Count);
                        if (positionizeSkillInvoked(unsafePoints[pos]))
                        {
                            skillCurseInvoked();
                        }
                    }
                }
                if (wasCastingLifeDrain)
                {
                    if (isNearPlayer)
                    {
                        skillLifeDrainInvoked();
                    }
                    else
                    {
                        List <GameObject> unsafePoints = unsafeTeleportPoints();
                        int pos = random.Next(0, unsafePoints.Count);
                        if (positionizeSkillInvoked(unsafePoints[pos]))
                        {
                            skillLifeDrainInvoked();
                        }
                    }
                }
                if (wasCastingTeleport)
                {
                    skillTeleportInvoked(null);
                    return;
                }
            }
            if (Time.time - lastCastTime > sprites.GetAnim("Hitted (L)").GetDuration() && gotHit)
            {
                gotHit       = false;
                lastCastTime = -1;
            }
            if (Time.time - lastCastTime > sprites.GetAnim("Dead (L)").GetDuration() && isDying)
            {
                sprites.StopAnim();
                sprites.Hide(true);
            }
            if (Time.time - lastCastTime > sound_dying.length && isDying)
            {
                Instantiate(victory);
                for (int i = 0; i < instancedMob.Count; i++)
                {
                    Destroy(instancedMob[i]);
                }
                instancedMob.Clear();
                Destroy(gameObject);
            }
            magicInterrupted = false;
            return;
        }

        if (curHP == 0)
        {
            doAnimToDirection("Dead");
            audio.PlayOneShot(sound_dying);
            Physics.IgnoreCollision(player.GetComponent <CharacterController>().collider, GetComponent <CharacterController>().collider, true);
            lastCastTime = Time.time;
            isDying      = true;
            return;
        }

        if (curGlobalCooldown > 0)
        {
            doAnimToDirection("Standing");
            return;
        }

        if (curLifeDrainCooldown == 0 && curHP < maxHP * 25 / 100)
        {
            wasCasting          = true;
            wasCastingLifeDrain = true;
            lastCastTime        = Time.time;
            if (nearPlayer(gameObject))
            {
                isNearPlayer = true;
            }
            else
            {
                isNearPlayer = false;
            }
        }
        else if (curSummonCooldown == 0)
        {
            wasCasting       = true;
            wasCastingSummon = true;
            lastCastTime     = Time.time;
            if (transform.position == teleportPoint_central.transform.position)
            {
                isCentralized = true;
            }
            else
            {
                isCentralized = false;
            }
        }
        else if (curCurseCooldown == 0)
        {
            wasCasting      = true;
            wasCastingCurse = true;
            lastCastTime    = Time.time;
            if (nearPlayer(gameObject))
            {
                isNearPlayer = true;
            }
            else
            {
                isNearPlayer = false;
            }
        }
        else if (curIcicleCooldown == 0)
        {
            wasCasting       = true;
            wasCastingIcicle = true;
            lastCastTime     = Time.time;
        }
        else if (curBlameCooldown == 0)
        {
            wasCasting      = true;
            wasCastingBlame = true;
            lastCastTime    = Time.time;
            if (transform.position == teleportPoint_central.transform.position)
            {
                isCentralized = true;
            }
            else
            {
                isCentralized = false;
            }
        }
        else if (curTeleportCooldown == 0 && nearPlayer(gameObject))        // there is no cooldown to attack, try to run
        {
            doAnimToDirection("Casting 1");
            wasCasting         = true;
            wasCastingTeleport = true;
            lastCastTime       = Time.time;
            if (currentDirection == Direction.Left)
            {
                skillTeleport.DoAnim("Departure (L)");
            }
            else
            {
                skillTeleport.DoAnim("Departure (R)");
            }
            audio.PlayOneShot(sound_teleport);
        }
        else
        {
            doAnimToDirection("Standing");
        }
    }