This script monitors the NPC's repair progress by:
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class RepairProgression : MonoBehaviour
{
public CarrierElementClass carrierElementClass;
public QuestUIList questUIList;
public QueueSystem queueSystem;
public EntityData selectedNPC;
public SpawnManager spawnManager;
public bool processedSkippedUrgentRepairs = false;
private int missedUrgentNPC = 0;
private Dictionary<int, int> missedUrgentNPCTimes = new Dictionary<int, int>();
private void Update()
{
//CheckMissedUrgentNPCs();
}
//private void CheckMissedUrgentNPCs()
//{
// foreach (var npc in missedUrgentNPCTimes)
// {
// if (npc.Value >= 1) // Check if NPC was missed once
// {
// EntityData repairData = GetRepairByID(npc.Key);
// if (repairData != null && repairData.repairUrgency > 0.8f)
// {
// Debug.Log($"Missed urgent NPC: {npc.Key} - Missed 1 time.");
// }
// }
// }
//}
public void SkippedNPCs(List<int> skippedNPCs)
{
foreach (var npcID in skippedNPCs)
{
//if (!processedSkippedUrgentRepairs)
//{
if (missedUrgentNPCTimes.ContainsKey(npcID))
{
missedUrgentNPCTimes[npcID] += 1;
Debug.Log($"Missed urgent NPC: {npcID} ({missedUrgentNPCTimes[npcID]} times)");
}
else
{
missedUrgentNPCTimes.Add(npcID, 1);
Debug.Log($"Missed urgent NPC: {npcID} (1 time)");
}
//processedSkippedUrgentRepairs = true;
//}
}
}
private EntityData GetRepairByID(int uniqueID)
{
var repairQueue = queueSystem.GetRepairQueue();
foreach (var repair in repairQueue)
{
if (repair.uniqueID == uniqueID)
{
return repair;
}
}
return null;
}
public void CompletedRepair(EntityData repair)
{
if (!questUIList)
{
if (questUIList.repairState == QuestUIList.repairStates.accepted)
{
if (carrierElementClass.repaired)
{
repair.isRepairCompleted = true;
}
}
else if (questUIList.repairState == QuestUIList.repairStates.choose)
{
RepairPending(repair);
}
}
}
public void RepairPending(EntityData repair)
{
if (!questUIList)
{
List<EntityData> repairQueue = queueSystem.GetRepairQueue();
if (repairQueue.Count == 0)
{
repair.repairList = true;
}
else
{
repair.repairList = false;
if (repair.repairUrgency > 0.8f)
{
if (!IsNPCSelected(repair))
{
if (!missedUrgentNPCTimes.ContainsKey(repair.uniqueID))
{
missedUrgentNPCTimes.Add(repair.uniqueID, 1);
missedUrgentNPC++;
Debug.LogError($"{repair.npcName} with repair urgency {repair.repairUrgency} not selected. Count: {missedUrgentNPC}. Times missed: {missedUrgentNPCTimes[repair.uniqueID]}");
}
}
}
}
}
}
private bool IsNPCSelected(EntityData repair)
{
return repair == selectedNPC;
}
public void SetSelectedNPC(EntityData selectedNPCData)
{
selectedNPC = selectedNPCData;
}
}