using System.Collections;
using System.Collections.Generic;
using RPG_Fight_Test.Assets.Scripts.Weapons;
using UnityEngine;

public class AttackAction : IAction {
    private Creature Target;
    private Creature Attacker;

    public AttackAction(Creature attacker, Creature target) {
        Target = target;
        Attacker = attacker;
    }

    private bool actionPerformed;
    public bool ActionPerformed { get => actionPerformed; set => actionPerformed = value; }

    public IEnumerator PerformAction() {

        int chanseToHit = Attacker.PrimaryWeapon.AttackProficiency - Target.Evade;
        int attackRoll = Random.Range(1, 100);

        string message = Attacker.name + " attacked " + Target.name + " with a chanse to hit " + chanseToHit + " and attack roll " + attackRoll;
        if (attackRoll < chanseToHit) {
            // hit the attack roll damage;
            int damage = Attacker.PrimaryWeapon.RollDamage();
            message += " and hit for " + damage + " damage";
            Target.TakeDamage(damage);
        }
        GameManagerScript.GetInstance().LogRow(message);
        actionPerformed = true;
        yield return new WaitForSeconds(3);
    }
    bool IAction.GetHilightEnabled() {
        return true;
    }
}
