138 lines
4.8 KiB
C#
138 lines
4.8 KiB
C#
using Invector;
|
|
using Invector.vCharacterController.AI;
|
|
using Invector.vEventSystems;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
{
|
|
public class bControlAIMelee : vControlAIMelee
|
|
{
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start(); // Call the original start method
|
|
|
|
// Be absolutely certain the NavMeshAgent is not controlling rotation
|
|
if (navMeshAgent)
|
|
{
|
|
navMeshAgent.updateRotation = false;
|
|
Debug.Log("Forcing NavMeshAgent.updateRotation to FALSE.", this.gameObject);
|
|
}
|
|
}
|
|
/*
|
|
/// <summary>
|
|
/// We override the base Rotate method. If our animation has the special tag,
|
|
/// we do nothing and let root motion handle it. Otherwise, we call the
|
|
/// original Invector rotation logic.
|
|
/// </summary>
|
|
/// <param name="targetDirection">The direction the AI wants to look.</param>
|
|
protected override void Rotate(Vector3 targetDirection)
|
|
{
|
|
//return;
|
|
if (IsAnimatorTag("LockRotationToRoot"))
|
|
{
|
|
// Our special turn animation is playing, so we block
|
|
// the AI's attempt to rotate the character manually.
|
|
return;
|
|
}
|
|
// If it's any other animation, let Invector's original code run.
|
|
base.Rotate(targetDirection);
|
|
}
|
|
|
|
/// <summary>
|
|
/// We must also override the second version of the Rotate method that
|
|
/// takes a Quaternion to be thorough.
|
|
/// </summary>
|
|
/// <param name="targetRotation">The rotation the AI wants to have.</param>
|
|
protected override void Rotate(Quaternion targetRotation)
|
|
{
|
|
//return;
|
|
if (IsAnimatorTag("LockRotationToRoot"))
|
|
{
|
|
// Block manual rotation during our turn animation.
|
|
return;
|
|
}
|
|
// Otherwise, run the original code.
|
|
base.Rotate(targetRotation);
|
|
}
|
|
// --- YOUR ORIGINAL OnAnimatorMove CAN NOW BE SIMPLIFIED OR REMOVED ---
|
|
// Your OnAnimatorMove is no longer strictly necessary because we've stopped
|
|
// the conflict at the source. However, leaving it in provides a safety net.
|
|
// It's your choice to keep it or remove it. For now, let's keep it.
|
|
protected override void OnAnimatorMove()
|
|
{
|
|
base.OnAnimatorMove();
|
|
|
|
if (useRootMotion && animator != null && Time.deltaTime != 0)
|
|
{
|
|
transform.rotation = animator.rootRotation;
|
|
}
|
|
}
|
|
*/
|
|
public void ResetAnimationTags()
|
|
{
|
|
if (animatorStateInfos == null)
|
|
{
|
|
return;
|
|
}
|
|
animatorStateInfos.stateInfos.vToList().ForEach(infos => infos.tags.Clear());
|
|
}
|
|
|
|
private new void Update()
|
|
{
|
|
// animatorStateInfos.stateInfos.vToList().ForEach(st => { Debug.Log(st.layer + " " + st.normalizedTime + " " + st.shortPathHash); st.tags.ForEach(tag => Debug.Log(tag)); });
|
|
|
|
base.Update();
|
|
}
|
|
|
|
protected override void OnEnable()
|
|
{
|
|
ResetAnimationTags();
|
|
base.OnEnable();
|
|
}
|
|
|
|
public void SetAttackTimes(float minTime, float maxTime)
|
|
{
|
|
_minAttackTime = minTime;
|
|
_maxAttackTime = maxTime;
|
|
}
|
|
|
|
protected override void TryBlockAttack(vDamage damage)
|
|
{
|
|
if (isAttacking) //we dont want blocking when attacking
|
|
{
|
|
damage.hitReaction = true;
|
|
return;
|
|
}
|
|
//base.TryBlockAttack(damage);
|
|
if (MeleeManager && damage.sender)
|
|
{
|
|
if (isBlocking && MeleeManager.CanBlockAttack(damage.sender.position))
|
|
{
|
|
var fighter = damage.sender.GetComponent<vIMeleeFighter>();
|
|
var damageReduction = MeleeManager.GetDefenseRate();
|
|
if (damageReduction > 0)
|
|
damage.ReduceDamage(damageReduction);
|
|
if (fighter != null && MeleeManager.CanBreakAttack())
|
|
fighter.OnRecoil(MeleeManager.GetDefenseRecoilID());
|
|
MeleeManager.OnDefense();
|
|
}
|
|
else damage.hitReaction = true;
|
|
}
|
|
}
|
|
|
|
protected override void TryApplyRecoil(vIMeleeFighter fighter)
|
|
{
|
|
if (MeleeManager && fighter != null && !isAttacking)
|
|
{
|
|
if (isBlocking && MeleeManager.CanBlockAttack(fighter.transform.position))
|
|
{
|
|
if (MeleeManager.CanBreakAttack())
|
|
fighter.OnRecoil(MeleeManager.GetDefenseRecoilID());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |