using CommonAI.ZoneClient; using CommonLang; using System.Collections.Generic; namespace ET.Client { public class UnitMgr : Singleton<UnitMgr> { public BattleActor Actor { get; set; } public uint ActorId { get { return Actor.Id; } } private HashMap<uint, BattleObject> UnitList = new(); public HashMap<uint, BattleObject>.ValueCollection AllUnits { get { return UnitList.Values; } } public List<uint> PlayerList = new(); public bool HasUnit(uint unitId) { return UnitList.ContainsKey(unitId); } public BattleObject GetUnit(uint id) { return UnitList.ContainsKey(id) ? UnitList[id] : null; } public void PutUnit(ZoneObject zo, BattleObject obj) { var id = zo.ObjectID; if(UnitList.ContainsKey(id)) { Log.Error($"Already exist unit({id}) @{obj}"); UnitList.Remove(id); } UnitList[id] = obj; if(zo is ZoneUnit zu && zu.Force == 1) { PlayerList.Add(id); } } public void RemoveUnit(uint id) { UnitList.Remove(id); PlayerList.Remove(id); } public void RecycleUnits() { foreach (var kp in UnitList) { kp.Value.OnSleep(); } UnitList.Clear(); PlayerList.Clear(); } public void Clear() { UnitList.Clear(); PlayerList.Clear(); } } }