AttackAction.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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. bool hilightEnbled = true;
  9. public bool HilightEnabled { get => hilightEnbled; set => hilightEnbled = value; }
  10. public AttackAction(Creature attacker, Creature target) {
  11. Target = target;
  12. Attacker = attacker;
  13. }
  14. private bool actionPerformed;
  15. public bool ActionPerformed { get => actionPerformed; set => actionPerformed = value; }
  16. public IEnumerator PerformAction() {
  17. int chanseToHit = Attacker.PrimaryWeapon.AttackProficiency - Target.Evade;
  18. int attackRoll = Random.Range(1, 100);
  19. string message = Attacker.name + " attacked " + Target.name + " with a chanse to hit " + chanseToHit + " and attack roll " + attackRoll;
  20. if (attackRoll < chanseToHit) {
  21. // hit the attack roll damage;
  22. int damage = Attacker.PrimaryWeapon.RollDamage();
  23. message += " and hit for " + damage + " damage";
  24. Target.TakeDamage(damage);
  25. }
  26. GameManagerScript.GetInstance().LogRow(message);
  27. actionPerformed = true;
  28. yield return new WaitForSeconds(3);
  29. }
  30. }