<commit_before>﻿using UnityEngine;

[CreateAssetMenu (menuName = "AI/Actions/Enemy_Attack")]
public class Action_Attack : Action {

	public override void Init(StateController controller) {
		return;
	}
	
	public override void Act(StateController controller) {		
		
	}
}
<commit_msg>Rewrite Action Attack erased by mistake<commit_after>﻿using UnityEngine;

[CreateAssetMenu (menuName = "AI/Actions/Enemy_Attack")]
public class Action_Attack : Action {
	[SerializeField] float staminaRequired = 2f;
	[SerializeField] float attackDelay     = 1f;
	[SerializeField] float attackDuration  = 1f;
	[SerializeField] float attackDamage    = 1f;
	[SerializeField] float attackRange     = 2f;

	float timer;

	public override void Init(StateController controller) {
		Debug.Log("ATTACK STATAE");
		timer = attackDelay;
		return;
	}
	
	public override void Act(StateController controller) {		
		attackRoutine(controller as Enemy_StateController);
	}

	private void attackRoutine(Enemy_StateController controller) {
		Vector3 targetPosition = controller.chaseTarget.transform.position;
		float distanceFromTarget = getDistanceFromTarget(targetPosition, controller);
		bool hasStamina = controller.characterStatus.stamina.isEnough(staminaRequired);

		if(hasStamina) {
			if(timer >= attackDelay) {
				timer = attackDelay;
				controller.characterStatus.stamina.decrease(staminaRequired);
				performAttack(controller, attackDamage, attackDuration);
				timer = 0f;
			} else {
				timer += Time.deltaTime;
			}
		} else {
			timer = attackDelay;	
		}
	}

	private void performAttack(Enemy_StateController controller, float attackDamage, float attackDuration) {
		controller.anim.SetTrigger("AttackState");
		controller.attackHandler.damage = attackDamage;
		controller.attackHandler.duration = attackDuration;
		controller.attackHandler.hitBox.enabled = true;
	}

	private float getDistanceFromTarget(Vector3 targetPosition, Enemy_StateController controller) {
		Vector3 originPosition = controller.eyes.position;
		Vector3 originToTargetVector = targetPosition - originPosition;
		float distanceFromTarget = originToTargetVector.magnitude;
		
		return distanceFromTarget;
	}
}

{'fraction_non_alphanumeric': 0.08406466512702078, 'fraction_numerical': 0.004618937644341801, 'mean_word_length': 5.296511627906977, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '805254', 'n_tokens_mistral': 691, 'n_tokens_neox': 621, 'n_words': 138}