using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using BITKit; using BITKit.Entities; using UnityEngine; namespace BITFALL.Player.Medical { [CustomType(typeof(IPlayerMedical))] public class PlayerMedicalService : EntityBehavior,IPlayerMedical { public IPlayerMedicalWound GetWound() where T : IPlayerMedicalWoundType, new() { return _wounds[new T()]; } public bool TryGetWound(out IPlayerMedicalWound wound) where T : IPlayerMedicalWoundType, new() { return _wounds.TryGetValue(new T(), out wound); } public void AddOrUpdateWound(IPlayerMedicalWound medical) where T : IPlayerMedicalWoundType, new() { if(_wounds.TryAdd(new T(), medical)) { OnWoundAdded?.Invoke(new T(), medical); } else { _wounds[new T()] = medical; OnWoundChanged?.Invoke(new T(), medical); } } public void RemoveWound() where T : IPlayerMedicalWoundType, new() { RemoveWound(new T()); } public void RemoveWound(IPlayerMedicalWoundType type) { if(_wounds.TryRemove(type, out _)) { OnWoundRemoved?.Invoke(type, null); } } public IDictionary GetAllWounds() { return new Dictionary(_wounds); } public event Action OnWoundChanged; public event Action OnWoundAdded; public event Action OnWoundRemoved; private readonly ConcurrentDictionary _wounds = new(); } }