First project upload
This commit is contained in:
@@ -136,7 +136,7 @@ public class CashSystemAI : MonoBehaviour
|
||||
private float patrolPauseEndTime;
|
||||
|
||||
// Coordination — which bag this AI is targeting (prevents clustering)
|
||||
private CashBag claimedBag;
|
||||
private CashMag claimedBag;
|
||||
|
||||
// ─── Extraction Mode State ───────────────────────────────
|
||||
private CashoutStation myStation;
|
||||
@@ -156,7 +156,7 @@ public class CashSystemAI : MonoBehaviour
|
||||
|
||||
private struct SensedBag
|
||||
{
|
||||
public CashBag bag;
|
||||
public CashMag bag;
|
||||
public float distance;
|
||||
public float score;
|
||||
}
|
||||
@@ -172,7 +172,7 @@ public class CashSystemAI : MonoBehaviour
|
||||
// ─── Static Team Coordination ────────────────────────────
|
||||
|
||||
// Track which bags are claimed by which AI (per team) to prevent clustering
|
||||
private static readonly Dictionary<CashBag, CashSystemAI> _claimedBags = new Dictionary<CashBag, CashSystemAI>();
|
||||
private static readonly Dictionary<CashMag, CashSystemAI> _claimedBags = new Dictionary<CashMag, CashSystemAI>();
|
||||
|
||||
// Track all active CashSystemAI instances per team for role assignment
|
||||
private static readonly List<CashSystemAI> _allAIs = new List<CashSystemAI>(8);
|
||||
@@ -223,12 +223,12 @@ public class CashSystemAI : MonoBehaviour
|
||||
DevLog.Log($"[CashSystemAI] Disabled TeamAIController on {gameObject.name}");
|
||||
}
|
||||
|
||||
var enemyAI = GetComponent<EnemyAIController>();
|
||||
if (enemyAI != null)
|
||||
{
|
||||
enemyAI.enabled = false;
|
||||
DevLog.Log($"[CashSystemAI] Disabled EnemyAIController on {gameObject.name}");
|
||||
}
|
||||
//var enemyAI = GetComponent<EnemyAIController>();
|
||||
//if (enemyAI != null)
|
||||
//{
|
||||
// enemyAI.enabled = false;
|
||||
// DevLog.Log($"[CashSystemAI] Disabled EnemyAIController on {gameObject.name}");
|
||||
//}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -750,7 +750,7 @@ public class CashSystemAI : MonoBehaviour
|
||||
// Only 1 bag and more available? Low urgency to deposit
|
||||
if (bags == 1 && cashCarrier.CanPickUp())
|
||||
{
|
||||
CashBag extraBag = FindBestUnclaimedBag();
|
||||
CashMag extraBag = FindBestUnclaimedBag();
|
||||
if (extraBag != null)
|
||||
score *= 0.3f; // Heavily suppress — go grab another bag first
|
||||
}
|
||||
@@ -834,7 +834,7 @@ public class CashSystemAI : MonoBehaviour
|
||||
// ── 4. COLLECT CASH (Collector bread-and-butter) ──
|
||||
if (cashCarrier != null && cashCarrier.CanPickUp() && !isCarrying)
|
||||
{
|
||||
CashBag bag = FindBestUnclaimedBag();
|
||||
CashMag bag = FindBestUnclaimedBag();
|
||||
if (bag != null)
|
||||
{
|
||||
float dist = Vector3.Distance(transform.position, bag.transform.position);
|
||||
@@ -868,7 +868,7 @@ public class CashSystemAI : MonoBehaviour
|
||||
// Also check if already carrying but can pick up more
|
||||
else if (cashCarrier != null && cashCarrier.CanPickUp() && isCarrying && cashCarrier.BagCount < 3)
|
||||
{
|
||||
CashBag bag = FindBestUnclaimedBag();
|
||||
CashMag bag = FindBestUnclaimedBag();
|
||||
if (bag != null)
|
||||
{
|
||||
float dist = Vector3.Distance(transform.position, bag.transform.position);
|
||||
@@ -970,11 +970,11 @@ public class CashSystemAI : MonoBehaviour
|
||||
private void ScanBags()
|
||||
{
|
||||
sensedBags.Clear();
|
||||
var bags = EntityRegistry<CashBag>.GetAll();
|
||||
var bags = EntityRegistry<CashMag>.GetAll();
|
||||
|
||||
for (int i = 0; i < bags.Count; i++)
|
||||
{
|
||||
CashBag bag = bags[i];
|
||||
CashMag bag = bags[i];
|
||||
if (bag == null) continue;
|
||||
if (!bag.IsAvailable && !bag.IsDropped) continue;
|
||||
|
||||
@@ -1104,12 +1104,12 @@ public class CashSystemAI : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
CashBag bag = currentTarget.GetComponent<CashBag>();
|
||||
CashMag bag = currentTarget.GetComponent<CashMag>();
|
||||
if (bag == null || (!bag.IsAvailable && !bag.IsDropped))
|
||||
{
|
||||
// Bag taken or destroyed — find another
|
||||
UnclaimBag();
|
||||
CashBag newBag = FindBestUnclaimedBag();
|
||||
CashMag newBag = FindBestUnclaimedBag();
|
||||
if (newBag != null)
|
||||
{
|
||||
ClaimBag(newBag);
|
||||
@@ -1144,7 +1144,7 @@ public class CashSystemAI : MonoBehaviour
|
||||
else
|
||||
{
|
||||
// Try to find another nearby bag
|
||||
CashBag next = FindBestUnclaimedBag();
|
||||
CashMag next = FindBestUnclaimedBag();
|
||||
if (next != null && Vector3.Distance(transform.position, next.transform.position) < 15f)
|
||||
{
|
||||
ClaimBag(next);
|
||||
@@ -1384,7 +1384,7 @@ public class CashSystemAI : MonoBehaviour
|
||||
}
|
||||
|
||||
// While patrolling, check for opportunities
|
||||
CashBag bag = FindBestUnclaimedBag();
|
||||
CashMag bag = FindBestUnclaimedBag();
|
||||
if (bag != null)
|
||||
{
|
||||
ClaimBag(bag);
|
||||
@@ -1867,12 +1867,12 @@ public class CashSystemAI : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>Find the best cash bag not claimed by a teammate — uses sensor cache.</summary>
|
||||
private CashBag FindBestUnclaimedBag()
|
||||
private CashMag FindBestUnclaimedBag()
|
||||
{
|
||||
// Build a shortlist of the top-N valid bags, then pick randomly
|
||||
// to spread AI across the map instead of all chasing the same bag.
|
||||
const int TOP_N = 3;
|
||||
CashBag[] candidates = new CashBag[TOP_N];
|
||||
CashMag[] candidates = new CashMag[TOP_N];
|
||||
float[] candidateScores = new float[TOP_N];
|
||||
int found = 0;
|
||||
|
||||
@@ -1881,7 +1881,7 @@ public class CashSystemAI : MonoBehaviour
|
||||
// sensedBags is already sorted by score descending
|
||||
for (int i = 0; i < sensedBags.Count && found < TOP_N; i++)
|
||||
{
|
||||
CashBag bag = sensedBags[i].bag;
|
||||
CashMag bag = sensedBags[i].bag;
|
||||
if (bag == null) continue;
|
||||
if (!bag.IsAvailable && !bag.IsDropped) continue;
|
||||
|
||||
@@ -1921,7 +1921,7 @@ public class CashSystemAI : MonoBehaviour
|
||||
|
||||
// ─── Coordination Helpers ────────────────────────────────
|
||||
|
||||
private void ClaimBag(CashBag bag)
|
||||
private void ClaimBag(CashMag bag)
|
||||
{
|
||||
UnclaimBag();
|
||||
if (bag != null)
|
||||
@@ -1941,7 +1941,7 @@ public class CashSystemAI : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsBagClaimedByTeammate(CashBag bag)
|
||||
private bool IsBagClaimedByTeammate(CashMag bag)
|
||||
{
|
||||
if (!_claimedBags.TryGetValue(bag, out CashSystemAI claimer)) return false;
|
||||
if (claimer == null || claimer == this) return false;
|
||||
|
||||
Reference in New Issue
Block a user