Beispiel #1
0
    private IEnumerator AttackRoutine()
    {
        //Debug.Log(gameObject.name + " is Attacking " + AttackTarget.gameObject.name);

        State = CharacterState.Attacking;
        while (Attacking() && InAttackRange() && AttackTarget.Alive())
        {
            (this as Goblin)?.Speak(SoundBank.GoblinSound.Attacking);

            //HIT TARGET
            var damage = Random.Range(1, DMG.GetStatMax()) * OutgoingDmgPct;
            if (AttackTarget.Surprised())
            {
                damage = (int)(damage * AmbushModifier);
            }
            var target = AttackTarget;
            if (!(target.Team && GameManager.Instance.InvincibleMode))
            {
                target.Health -= (int)Mathf.Round(damage * target.IncomingDmgPct);
            }

            if (target.Health <= 0)
            {
                //Debug.Log(name + " killed " + target.name);

                if (this as Goblin)
                {
                    ((Goblin)this).Xp += GameManager.XpKill();
                    if (Team)
                    {
                        Team.OnTeamKill.Invoke();
                    }
                    (this as Goblin)?.Speak(SoundBank.GoblinSound.Laugh);
                }

                break;
            }

            //Debug.Log(gameObject.name + " hit " + AttackTarget.gameObject.name +" for " + Damage + " damage");

            //should be tied to animation maybe?
            yield return(new WaitForSeconds(AttackTime));
        }

        _attackRoutine = null;
    }