UnitMgr.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 
  2. using CommonAI.ZoneClient;
  3. using CommonLang;
  4. using System.Collections.Generic;
  5. namespace ET.Client
  6. {
  7. public class UnitMgr : Singleton<UnitMgr>
  8. {
  9. public BattleActor Actor { get; set; }
  10. public uint ActorId
  11. {
  12. get
  13. {
  14. return Actor.Id;
  15. }
  16. }
  17. private HashMap<uint, BattleObject> UnitList = new();
  18. public HashMap<uint, BattleObject>.ValueCollection AllUnits
  19. {
  20. get { return UnitList.Values; }
  21. }
  22. public List<uint> PlayerList = new();
  23. public bool HasUnit(uint unitId)
  24. {
  25. return UnitList.ContainsKey(unitId);
  26. }
  27. public BattleObject GetUnit(uint id)
  28. {
  29. return UnitList.ContainsKey(id) ? UnitList[id] : null;
  30. }
  31. public void PutUnit(ZoneObject zo, BattleObject obj)
  32. {
  33. var id = zo.ObjectID;
  34. if(UnitList.ContainsKey(id))
  35. {
  36. Log.Error($"Already exist unit({id}) @{obj}");
  37. UnitList.Remove(id);
  38. }
  39. UnitList[id] = obj;
  40. if(zo is ZoneUnit zu && zu.Force == 1)
  41. {
  42. PlayerList.Add(id);
  43. }
  44. }
  45. public void RemoveUnit(uint id)
  46. {
  47. UnitList.Remove(id);
  48. PlayerList.Remove(id);
  49. }
  50. public void RecycleUnits()
  51. {
  52. foreach (var kp in UnitList)
  53. {
  54. kp.Value.OnSleep();
  55. }
  56. UnitList.Clear();
  57. PlayerList.Clear();
  58. }
  59. public void Clear()
  60. {
  61. UnitList.Clear();
  62. PlayerList.Clear();
  63. }
  64. }
  65. }