Ejemplo n.º 1
0
    void CheckNewAttack()
    {
        if (PrepareAttack && !WaitForNextInput)
        {
            if (Time.time > AttackTime)
            {
                Attacking = true;
                switch (CombatState)
                {
                case (int)CombatStyle.Melee:
                    if (Time.time > NextMeleeAttack)
                    {
                        float walkspeed = 0;
                        if (CombatFxs.Length > 0 && AudioSource && !AudioSource.isPlaying)
                        {
                            SoundSelector = Random.Range(1, 4);
                            AudioSource.PlayOneShot(CombatFxs[SoundSelector], AudioVolume);
                        }
                        switch (AttackOrder)
                        {
                        case 1:
                            NextMeleeAttack = Time.time + Attack01Swing;
                            NextAttack      = NextMeleeAttack + AttackWait;
                            if (SwordsPanel)
                            {
                                SwordsPanel.GetChild(0).GetComponent <Image>().sprite = FilledSwordSprite;
                            }

                            walkspeed = FirstPersonControlerScript.GetNormalWalkspeed();
                            FirstPersonControlerScript.SetWalkSpeed(walkspeed * 0.80f);

                            Transform HitDec1 = (Transform)Instantiate(HitRegBlock, transform.position + (transform.forward), transform.rotation);
                            HitDec1.transform.parent    = transform;
                            HitDec1.transform.position += new Vector3(0, 0.4f, 0);
                            HitDec1.GetComponent <HitRegistrator>().SetSettings(1, Attack01Swing, AttackPower, transform.forward * propulsionForce);

                            AttackOrder++;
                            WaitForNextInput = true;
                            break;

                        case 2:
                            PlayerAnimator.SetTrigger("AttackMelee01Trigger");
                            AttackPower     = 40f;
                            NextMeleeAttack = Time.time + Attack02Swing;
                            NextAttack      = NextMeleeAttack + AttackWait;
                            if (SwordsPanel)
                            {
                                SwordsPanel.GetChild(1).GetComponent <Image>().sprite = FilledSwordSprite;
                            }

                            walkspeed = FirstPersonControlerScript.GetNormalWalkspeed();
                            FirstPersonControlerScript.SetWalkSpeed(walkspeed * 0.6f);

                            Transform HitDec2 = (Transform)Instantiate(HitRegBlock, transform.position + (transform.forward), transform.rotation);
                            HitDec2.transform.parent    = transform;
                            HitDec2.transform.position += new Vector3(0, 0.4f, 0);
                            HitDec2.GetComponent <HitRegistrator>().SetSettings(1, Attack02Swing, AttackPower, transform.forward * propulsionForce);
                            AttackPower = 45f;
                            AttackOrder++;
                            WaitForNextInput = true;
                            break;

                        case 3:
                            PlayerAnimator.SetTrigger("AttackMelee01Trigger");
                            NextMeleeAttack = Time.time + Attack03Swing;
                            NextAttack      = NextMeleeAttack + AttackWait;
                            if (SwordsPanel)
                            {
                                SwordsPanel.GetChild(2).GetComponent <Image>().sprite = FilledSwordSprite;
                            }

                            walkspeed = FirstPersonControlerScript.GetNormalWalkspeed();
                            FirstPersonControlerScript.SetWalkSpeed(walkspeed * 0.4f);

                            Transform HitDec3 = (Transform)Instantiate(HitRegBlock, transform.position + (transform.forward), transform.rotation);
                            HitDec3.transform.parent    = transform;
                            HitDec3.transform.position += new Vector3(0, 0.4f, 0);
                            HitDec3.GetComponent <HitRegistrator>().SetSettings(1, Attack02Swing, AttackPower, transform.forward * propulsionForce);

                            PrepareAttack    = false;
                            WaitForNextInput = false;
                            break;
                        }
                    }
                    //Debug.Log("Time: " + Time.time + " NextMeleeAttack: " + NextMeleeAttack + " NextAttack: " + NextAttack);
                    break;

                case (int)CombatStyle.Range:
                    if (Time.time > WaitForNextArrow)
                    {
                        if (HoldingDown)
                        {
                            if (SetWalkSpeed)
                            {
                                SetWalkSpeed = false;
                                float NewWalkSpeed = FirstPersonControlerScript.GetNormalWalkspeed();
                                FirstPersonControlerScript.SetWalkSpeed(NewWalkSpeed * 0.33f);
                            }
                            if (BowChargePanel)
                            {
                                if (BowChargePanel.activeSelf == false)
                                {
                                    BowChargePanel.SetActive(true);
                                }
                            }
                            if (BowStrengh < 1)
                            {
                                BowStrengh += 0.01f;
                                if (BowStrengh > 1)
                                {
                                    BowStrengh = 1;
                                }
                            }
                            if (ArrowChargeMeter)
                            {
                                ArrowChargeMeter.fillAmount = BowStrengh;
                            }
                        }
                        else
                        {
                            if (CombatFxs.Length > 0 && AudioSource && !AudioSource.isPlaying)
                            {
                                SoundSelector = Random.Range(4, 6);
                                AudioSource.PlayOneShot(CombatFxs[SoundSelector], AudioVolume);
                            }
                            WaitForNextArrow = Time.time + 0.75f;
                            SetWalkSpeed     = true;
                            PrepareAttack    = false;
                            GameObject Projectile = Instantiate(ArrowPrefab);
                            Projectile.transform.position = ArrowSpawn.position;
                            Projectile.transform.rotation = ArrowSpawn.rotation;

                            Rigidbody rb = Projectile.GetComponent <Rigidbody>();
                            if (BowStrengh < 0.25f)
                            {
                                rb.velocity = (ArrowSpawn.forward * 350) * 0.25f;
                            }
                            else
                            {
                                rb.velocity = (ArrowSpawn.forward * 200) * BowStrengh;
                            }


                            Projectile.GetComponent <HitRegistrator>().SetSettings(2, 10, 10, transform.forward * propulsionForce);
                            if (BowChargePanel)
                            {
                                BowChargePanel.SetActive(false);
                            }
                            BowStrengh = 0;

                            FirstPersonControlerScript.SetSpeedNormal();
                        }
                    }
                    break;

                case (int)CombatStyle.Magic:
                    if (spelldowncool == 1.0f)
                    {
                        int type = currentspell.SpellType;

                        if (PlayerStats.Mana >= currentspell.ManaCost)
                        {
                            if (HoldingDown)
                            {
                                if (SetWalkSpeed)
                                {
                                    SetWalkSpeed = false;
                                    float NewWalkSpeed = FirstPersonControlerScript.GetNormalWalkspeed();
                                    FirstPersonControlerScript.SetWalkSpeed(NewWalkSpeed * 0.45f);
                                }
                                if (MaxCharge == 0)
                                {
                                    MaxCharge = currentspell.CastTime;
                                }
                                if (MagicChargePanel)
                                {
                                    if (MagicChargePanel.activeSelf == false)
                                    {
                                        MagicChargePanel.SetActive(true);
                                        if (CombatFxs.Length > 0 && AudioSource && !AudioSource.isPlaying)
                                        {
                                            SoundSelector = Random.Range(6, 10);
                                            AudioSource.PlayOneShot(CombatFxs[SoundSelector], AudioVolume);
                                        }
                                    }
                                }
                                if (MagicCharged < 1)
                                {
                                    MagicCharged = CurrentCharge / MaxCharge;
                                    if (MagicCharged > 1)
                                    {
                                        MagicCharged = 1;
                                    }
                                }
                                if (MagicChargeMeter)
                                {
                                    MagicChargeMeter.fillAmount = MagicCharged;
                                }
                                if (CurrentCharge < MaxCharge)
                                {
                                    if (!PreAttackSpawned)
                                    {
                                        switch (type)
                                        {
                                        case 1:
                                            GameObject Missle = Instantiate(MagicMisslePrefab);
                                            Missle.transform.parent   = MagicMissleSpawn;
                                            Missle.transform.position = MagicMissleSpawn.position;
                                            Missle.transform.rotation = MagicMissleSpawn.rotation;
                                            Missle.GetComponent <HitRegistrator>().enabled = false;
                                            SpawningMissle   = true;
                                            PreAttackSpawned = true;
                                            break;

                                        case 2:
                                            GameObject AoE = Instantiate(AoEPrefab);
                                            AoE.transform.parent   = MagicAreaOfEffectSpawn;
                                            AoE.transform.position = MagicAreaOfEffectSpawn.position;
                                            AoE.transform.rotation = MagicAreaOfEffectSpawn.rotation;
                                            AoE.GetComponent <HitRegistrator>().enabled = false;
                                            SpawningAoE      = true;
                                            PreAttackSpawned = true;
                                            break;
                                        }
                                    }

                                    if (SpawningMissle)
                                    {
                                        if (MagicMissleSpawn.transform.childCount == 1)
                                        {
                                            Transform Movement = MagicMissleSpawn.transform.GetChild(0);
                                            Movement.localScale += new Vector3(CurrentCharge, CurrentCharge * 0.15f, CurrentCharge);
                                            ApplyCharge          = Movement.lossyScale.x;
                                            //Debug.Log(Movement.localScale);
                                        }
                                    }

                                    if (SpawningAoE)
                                    {
                                        if (MagicAreaOfEffectSpawn.transform.childCount == 1)
                                        {
                                            Transform Movement = MagicAreaOfEffectSpawn.transform.GetChild(0);
                                            Movement.localScale += new Vector3(CurrentCharge, 0, CurrentCharge);
                                            ApplyCharge          = Movement.lossyScale.x;
                                        }
                                    }
                                    CurrentCharge += 0.01f;
                                }
                            }
                            else
                            {
                                if (SpawningAoE)
                                {
                                    Destroy(MagicAreaOfEffectSpawn.transform.GetChild(0).gameObject);
                                }
                                if (SpawningMissle)
                                {
                                    Destroy(MagicMissleSpawn.transform.GetChild(0).gameObject);
                                }
                                SpawningAoE      = false;
                                SpawningMissle   = false;
                                PreAttackSpawned = false;
                                PrepareAttack    = false;
                                SetWalkSpeed     = true;
                                spelldowncool    = 0;
                                MaxCharge        = 0;
                                CurrentCharge    = 0;
                                MagicCharged     = 0;
                                HoldingDown      = false;
                                PlayerStats.ChangeMana(-currentspell.ManaCost);
                                FirstPersonControlerScript.SetSpeedNormal();
                                if (MagicChargePanel)
                                {
                                    MagicChargePanel.SetActive(false);
                                }
                                switch (type)
                                {
                                case 1:
                                    DelayAdd = 0.01f;
                                    GameObject Missle = Instantiate(MagicMisslePrefab);


                                    Missle.transform.position    = MagicMissleSpawn.position;
                                    Missle.transform.rotation    = MagicMissleSpawn.rotation;
                                    Missle.transform.localScale += new Vector3(ApplyCharge, ApplyCharge, ApplyCharge);

                                    Missle.GetComponent <HitRegistrator>().SetSettings(
                                        3,
                                        currentspell,
                                        transform.forward * propulsionForce);
                                    break;

                                case 2:
                                    DelayAdd = 0.005f;
                                    GameObject AoE = Instantiate(AoEPrefab);

                                    AoE.transform.position   = MagicAreaOfEffectSpawn.position;
                                    AoE.transform.rotation   = MagicAreaOfEffectSpawn.rotation;
                                    AoE.transform.localScale = new Vector3(ApplyCharge, 0.05f, ApplyCharge);
                                    AoE.GetComponent <HitRegistrator>().SetSettings(
                                        3,
                                        currentspell);
                                    break;

                                case 3:
                                    PlayerStats.health += currentspell.Change;
                                    break;
                                }
                                CurrentCharge = 0;
                            }
                        }
                    }
                    break;
                }
            }
        }
    }