added "finish" button to dialogue UI, implementation of many, many trinket's effects, autot-argetting fix on death, added script for particles/player following
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using Invector.vCharacterController.AI.FSMBehaviour;
|
||||
using Beyond;
|
||||
using System;
|
||||
using Invector; // Required for vDamage
|
||||
|
||||
namespace Beyond
|
||||
{
|
||||
@@ -70,14 +71,23 @@ namespace Beyond
|
||||
_playerController = Player.Instance.GetComponent<bThirdPersonController>();
|
||||
if (_playerController == null)
|
||||
{
|
||||
Debug.LogError("AutoTargetting: Could not find bThirdPersonController on Player.Instance! Custom roll rotation may not work correctly.");
|
||||
Debug.LogError("AutoTargetting: Could not find bThirdPersonController on Player.Instance!");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Subscribe to Player Death
|
||||
_playerController.onDead.AddListener(OnPlayerDead);
|
||||
}
|
||||
|
||||
_gameStateManager = GameStateManager.Instance;
|
||||
if (_gameStateManager != null)
|
||||
{
|
||||
_gameStateManager.m_OnStateChanged.AddListener(HandleGameStateChanged);
|
||||
HandleGameStateChanged(_gameStateManager.CurrentState);
|
||||
// Initial check, but avoid running if dead
|
||||
if(_playerController != null && _playerController.currentHealth > 0)
|
||||
{
|
||||
HandleGameStateChanged(_gameStateManager.CurrentState);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -88,11 +98,6 @@ namespace Beyond
|
||||
if (targetLockSystem == null)
|
||||
{
|
||||
targetLockSystem = Player.Instance.GetComponentInChildren<bLockOn>(true);
|
||||
if (targetLockSystem == null)
|
||||
{
|
||||
Debug.LogWarning("AutoTargetting: bLockOn system not found. Auto-lock will be disabled.");
|
||||
autoLockSelectedTarget = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetLockSystem != null)
|
||||
@@ -106,8 +111,13 @@ namespace Beyond
|
||||
{
|
||||
if (_gameStateManager != null) _gameStateManager.m_OnStateChanged.RemoveListener(HandleGameStateChanged);
|
||||
|
||||
StopAndClearAllFadeCoroutines();
|
||||
// Unsubscribe from Player Death
|
||||
if (_playerController != null)
|
||||
{
|
||||
_playerController.onDead.RemoveListener(OnPlayerDead);
|
||||
}
|
||||
|
||||
StopAndClearAllFadeCoroutines();
|
||||
if (_targetingLoopCoroutine != null) StopCoroutine(_targetingLoopCoroutine);
|
||||
|
||||
if (targetLockSystem != null)
|
||||
@@ -120,6 +130,36 @@ namespace Beyond
|
||||
#endregion
|
||||
|
||||
#region Core Logic
|
||||
|
||||
private void OnPlayerDead(GameObject deadObject)
|
||||
{
|
||||
// Immediately clear targets and stop the loop when player dies
|
||||
ClearTarget(false);
|
||||
|
||||
if (_targetingLoopCoroutine != null)
|
||||
{
|
||||
StopCoroutine(_targetingLoopCoroutine);
|
||||
_targetingLoopCoroutine = null;
|
||||
}
|
||||
|
||||
if (targetLockSystem != null)
|
||||
{
|
||||
targetLockSystem.SetLockOn(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetSystem()
|
||||
{
|
||||
ClearTarget(false);
|
||||
_manualSwitchCooldownActive = false;
|
||||
_manualSwitchCooldownTimer = 0f;
|
||||
|
||||
// Restart the loop if we are in combat
|
||||
if (_gameStateManager != null && _gameStateManager.CurrentState == GameStateManager.State.COMBAT)
|
||||
{
|
||||
if (_targetingLoopCoroutine == null) _targetingLoopCoroutine = StartCoroutine(TargetingLoop());
|
||||
}
|
||||
}
|
||||
|
||||
private void StopAndClearAllFadeCoroutines()
|
||||
{
|
||||
@@ -135,6 +175,9 @@ namespace Beyond
|
||||
|
||||
private void HandleGameStateChanged(GameStateManager.State newState)
|
||||
{
|
||||
// Don't start loops if player is dead
|
||||
if (_playerController != null && _playerController.currentHealth <= 0) return;
|
||||
|
||||
if (newState == GameStateManager.State.COMBAT)
|
||||
{
|
||||
if (_targetingLoopCoroutine == null) _targetingLoopCoroutine = StartCoroutine(TargetingLoop());
|
||||
@@ -155,6 +198,11 @@ namespace Beyond
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (_playerController != null && _playerController.currentHealth <= 0)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (_manualSwitchCooldownActive)
|
||||
{
|
||||
_manualSwitchCooldownTimer -= targetingInterval;
|
||||
@@ -174,7 +222,6 @@ namespace Beyond
|
||||
{
|
||||
if (_playerTransform == null || _gameStateManager == null || _manualSwitchCooldownActive) return;
|
||||
|
||||
// Step 1: Always find the absolute best candidate in range right now.
|
||||
vFSMBehaviourController bestCandidate = null;
|
||||
float minDistanceSqr = maxTargetingDistance * maxTargetingDistance;
|
||||
HashSet<vFSMBehaviourController> combatControllers = _gameStateManager.GetActiveCombatcontrollers();
|
||||
@@ -195,13 +242,11 @@ namespace Beyond
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: If the best candidate is different from our current one, switch the highlight.
|
||||
if (CurrentTarget != bestCandidate)
|
||||
{
|
||||
SetNewTarget(bestCandidate);
|
||||
}
|
||||
|
||||
// Step 3: Every update, evaluate and apply the correct lock-on state for the current target.
|
||||
UpdateLockOnState();
|
||||
}
|
||||
|
||||
@@ -209,7 +254,6 @@ namespace Beyond
|
||||
{
|
||||
if (targetLockSystem == null || _playerTransform == null) return;
|
||||
|
||||
// Determine if the target *should* be locked based on distance rules.
|
||||
bool shouldBeLocked = false;
|
||||
if (CurrentTarget != null && (autoLockSelectedTarget || alwaysLockOnInCombat))
|
||||
{
|
||||
@@ -217,21 +261,15 @@ namespace Beyond
|
||||
|
||||
if (targetLockSystem.isLockingOn)
|
||||
{
|
||||
// If already locked, stay locked unless we are beyond the unlock threshold.
|
||||
shouldBeLocked = distanceToTarget <= unlockDistanceThreshold;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If not locked, we only engage the lock if we are within the auto-lock distance.
|
||||
shouldBeLocked = distanceToTarget <= autoLockOnDistance;
|
||||
}
|
||||
}
|
||||
|
||||
// Synchronize the desired state with the lock-on system.
|
||||
Transform desiredLockTarget = shouldBeLocked ? CurrentTarget.transform : null;
|
||||
|
||||
// --- THIS IS THE FIX ---
|
||||
// We now pass the 'shouldBeLocked' boolean to tell the system whether to lock or unlock.
|
||||
targetLockSystem.ManuallySetLockOnTarget(desiredLockTarget, shouldBeLocked);
|
||||
|
||||
if (alwaysLockOnInCombat && desiredLockTarget != null && !targetLockSystem.isLockingOn)
|
||||
@@ -261,11 +299,7 @@ namespace Beyond
|
||||
|
||||
public void ExecuteRotationTowardsCurrentTarget(float deltaTime)
|
||||
{
|
||||
if (_playerController != null && !_playerController.enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_playerController != null && !_playerController.enabled) return;
|
||||
if (CurrentTarget == null || _playerTransform == null) return;
|
||||
|
||||
Vector3 directionToTarget = CurrentTarget.transform.position - _playerTransform.position;
|
||||
@@ -311,6 +345,16 @@ namespace Beyond
|
||||
|
||||
#region Helper Methods
|
||||
|
||||
// --- Restored Method ---
|
||||
public float GetCurrentTargetHealth()
|
||||
{
|
||||
if (CurrentTarget != null && CurrentTarget.aiController != null)
|
||||
{
|
||||
return CurrentTarget.aiController.currentHealth;
|
||||
}
|
||||
return -1f;
|
||||
}
|
||||
|
||||
public bool IsTargetInAngle(Transform sourceTransform, vFSMBehaviourController targetAI, float angleThreshold)
|
||||
{
|
||||
if (targetAI == null || sourceTransform == null) return false;
|
||||
@@ -329,15 +373,6 @@ namespace Beyond
|
||||
return distSqr <= (maxTargetingDistance * maxTargetingDistance);
|
||||
}
|
||||
|
||||
public float GetCurrentTargetHealth()
|
||||
{
|
||||
if (CurrentTarget != null && CurrentTarget.aiController != null)
|
||||
{
|
||||
return CurrentTarget.aiController.currentHealth;
|
||||
}
|
||||
return -1f;
|
||||
}
|
||||
|
||||
public void ClearTarget(bool findNewOneImmediately)
|
||||
{
|
||||
if (targetLockSystem != null)
|
||||
@@ -349,7 +384,7 @@ namespace Beyond
|
||||
|
||||
if (findNewOneImmediately && _gameStateManager != null && _gameStateManager.CurrentState == GameStateManager.State.COMBAT)
|
||||
{
|
||||
if (!_manualSwitchCooldownActive)
|
||||
if (_playerController != null && _playerController.currentHealth > 0 && !_manualSwitchCooldownActive)
|
||||
{
|
||||
UpdateTarget();
|
||||
}
|
||||
@@ -359,7 +394,6 @@ namespace Beyond
|
||||
#endregion
|
||||
|
||||
#region Visuals
|
||||
|
||||
private Renderer[] GetTargetRenderers(vFSMBehaviourController targetController)
|
||||
{
|
||||
if (targetController == null) return new Renderer[0];
|
||||
@@ -399,7 +433,6 @@ namespace Beyond
|
||||
}
|
||||
if (material != null) material.SetColor(materialHighlightPropertyName, toValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user