Beispiel #1
0
    /*********************** Attack *****************************/
    public string attack(Enemy e)
    {
        //string name = e.typeID;
        /*	if (soundComponent.characterAudio.isPlaying && soundComponent.characterClip < Sounds.SWORD_HIT) {
            soundComponent.stopSound("character");
        }*/
        animatorComponent.SetBool("Attacking", true);
        string message = "Miss! ";

        if(stamina > 0){
            if(GameObject.Find("Health").GetComponent<Image>().isActiveAndEnabled == false){
                this.GetComponent<Tutorial>().showHealthHint();
            }
            e.lastDamage = Time.time;
            float ran = UnityEngine.Random.value;
            float hc = hitChance;

            if (ran <= hc) {
                message = "Hit! ";

                float cc = critChance;
                int tmpdamage = damage;

                /*Critical Hit */
                if (ran <= cc) {

                    tmpdamage *= CRIT_MULT;
                    message = "Critical Hit! ";

                    if (weapon != null){
                        if (weapon.typeID == "Warhammer") {
                            soundComponent.playCharacterSound (Sounds.HAMMER_CRIT);
                        } else {
                            soundComponent.playCharacterSound (Sounds.SWORD_CRIT);
                        }
                    } else {
                        soundComponent.playCharacterSound (Sounds.FISTS_CRIT);
                    }
                } else {
                    /* Non-crit Sounds */

                    if (weapon != null){
                        if (weapon.typeID == "Warhammer") {
                            soundComponent.playCharacterSound (Sounds.HAMMER_HIT);
                        } else {
                            soundComponent.playCharacterSound (Sounds.SWORD_HIT);
                        }
                    } else {
                        soundComponent.playCharacterSound (Sounds.FISTS_HIT);
                    }
                }

                bool dead = e.loseHP(tmpdamage);

                if (weapon != null) {
                    stamina -= weapon.staminaLoss;
                    GameObject.Find("Stamina").GetComponent<Image>().fillAmount = stamina/maxStamina();
                } else {
                    stamina -= STAMINA_LOSS;
                    GameObject.Find("Stamina").GetComponent<Image>().fillAmount = stamina/maxStamina();
                }

                if (dead) {
                    message += " Monster died!\n";
                    message += addXP(e.level * XP_GAIN_PER_MONSTER_LEVEL) + "\n";
                } else {
                    //add Stats to message
                    message += e.getHealth()+"/"+e.getMaxHp();
                }
            } else if (message == "Miss! ") {
                soundComponent.playCharacterSound(Sounds.MISS);
                message += e.getHealth () + "/" + e.getMaxHp ();
            }
        } else {
            soundComponent.playCharacterSound(Sounds.MISS);
        }

        return message;
    }