AttackAction.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using RPG_Fight_Test.Assets.Scripts.Weapons;
  4. using UnityEngine;
  5. public class AttackAction : IAction {
  6. private Creature Target;
  7. private Creature Attacker;
  8. public AttackAction(Creature attacker, Creature target) {
  9. Target = target;
  10. Attacker = attacker;
  11. }
  12. private bool actionPerformed;
  13. public bool ActionPerformed { get => actionPerformed; set => actionPerformed = value; }
  14. public IEnumerator PerformAction() {
  15. int chanseToHit = Attacker.PrimaryWeapon.AttackProficiency - Target.Evade;
  16. int attackRoll = Random.Range(1, 100);
  17. string message = Attacker.name + " attacked " + Target.name + " with a chanse to hit " + chanseToHit + " and attack roll " + attackRoll;
  18. if (attackRoll < chanseToHit) {
  19. // hit the attack roll damage;
  20. int damage = Attacker.PrimaryWeapon.RollDamage();
  21. message += " and hit for " + damage + " damage";
  22. Target.TakeDamage(damage);
  23. }
  24. GameManagerScript.GetInstance().LogRow(message);
  25. actionPerformed = true;
  26. yield return new WaitForSeconds(3);
  27. }
  28. bool IAction.GetHilightEnabled() {
  29. return true;
  30. }
  31. }