Example #1
0
    public void EnterCoolDown(int fTime, float fPercent)
    {
        if (coolDownSprite != null)
        {
            if (fTime <= 0)
            {
                coolDownSprite.StopAnim();
                isInCooldown = false;
            }
            else
            {
                float maxFrame      = 0;
                float needFrameRate = 0;
                if (coolDownSprite.animations.Length != 0)
                {
                    maxFrame      = coolDownSprite.animations[0].GetFrameCount();
                    needFrameRate = maxFrame / ((float)fTime / 1000);
                    coolDownSprite.animations[0].framerate = needFrameRate;
                }
                int startFrame = 0;
                if (fPercent != 0)
                {
                    startFrame = (int)(fPercent * maxFrame);
                }

                coolDownSprite.PlayAnim(0, startFrame);

                isInCooldown = true;
            }
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (isActive)
     {
         sprites.DoAnim("Effect");
     }
     else
     {
         sprites.StopAnim();
     }
 }
    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");
        }
    }