ThreatManager.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class ThreatManager
  5. {
  6. private Dictionary<int, Threat> threatDict;
  7. private List<Threat> threatList;
  8. public ThreatManager()
  9. {
  10. threatDict = new Dictionary<int, Threat>();
  11. threatList = new List<Threat>();
  12. }
  13. public void AddThreat(int id, float value)
  14. {
  15. if(!threatDict.ContainsKey(id))
  16. {
  17. Threat threat = new Threat(id, value);
  18. threatDict.Add(id, threat);
  19. threatList.Add(threat);
  20. }
  21. threatDict[id].SetValue(value);
  22. }
  23. public void RemoveThreat(int id)
  24. {
  25. if(threatDict.ContainsKey(id))
  26. {
  27. Threat threat = threatDict[id];
  28. threatDict.Remove(id);
  29. threatList.Remove(threat);
  30. }
  31. }
  32. public float GetThreat(int id)
  33. {
  34. if(threatDict.ContainsKey(id))
  35. {
  36. return threatDict[id].GetValue();
  37. }
  38. return 0;
  39. }
  40. public int GetMaxThreatId()
  41. {
  42. int id = -1;
  43. float maxThread = 0;
  44. for(int i=0; i<threatList.Count; i++)
  45. {
  46. Threat threat = threatList[i];
  47. float threatValue = threat.GetValue();
  48. if(threatValue > maxThread)
  49. {
  50. id = threat.id;
  51. maxThread = threatValue;
  52. }
  53. }
  54. return id;
  55. }
  56. }