void DoAttack() { CombatEnemy enemy = combatQueue.FirstEnemy(); if (enemy == null) { return; } int hitSkill = (int)statManager.DerivedPrecision(); if (Random.Range(0, hitSkill) < Random.Range(0, enemy.Dodge())) { CombatBubbleSpawner.SpawnBubble( enemy.transform.position, "Missed!", CombatBubbleSpawner.BubbleTypes.Round, Color.gray ); SoundsManager.PlayClip(MissSounds[Random.Range(0, MissSounds.Length)]); return; } int maxDamage = (int)statManager.DerivedDamage(); int damage = Random.Range(maxDamage / 2, maxDamage); bool isCrit = Random.Range(0, 100) < statManager.GetValue(Stats.Critical); if (isCrit) { // TODO: Crit event damage *= 2; } CombatBubbleSpawner.SpawnBubble( enemy.transform.position, damage.ToString(), (isCrit ? CombatBubbleSpawner.BubbleTypes.Spiky : CombatBubbleSpawner.BubbleTypes.Round), (isCrit ? Color.red : Color.white) ); SoundsManager.PlayClip(AttackSounds[Random.Range(0, AttackSounds.Length)]); enemy.TakeDamage(damage); }
// Update is called once per frame void Update() { if (PauseManager.isPaused || CombatPlayer.isDead) { return; } if (hitpoints <= 0) { deathTimer -= Time.deltaTime; if (deathTimer <= 0) { Destroy(gameObject); return; } GetComponent <CanvasGroup>().alpha = deathTimer / 0.5f; this.transform.position = this.transform.position + new Vector3(10, -25) * Time.deltaTime; return; } if (hitpoints >= maxHitpoints) { healthBar.transform.parent.gameObject.SetActive(false); } else { healthBar.transform.parent.gameObject.SetActive(true); healthBar.fillAmount = (float)hitpoints / (float)maxHitpoints; } // Am I at the front of the queue? if (combatQueue.FirstEnemy() == this) { attackCooldown -= Time.deltaTime; if (attackCooldown <= 0) { DoAttack(); attackCooldown = 1.25f; } } }