using System; using System.Linq; using RPGCore.BackpackEquipment.ObjectModules.Content; using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Data; using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Events; using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Objects; using RPGCore.BackpackEquipment.Objects; using RPGCore.Core; using RPGCore.Core.Objects; using UnityEngine; namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment { [RequireComponent(typeof(UnitObject))] [RequireComponent(typeof(ContentModule))] [DisallowMultipleComponent] public class UnitEquipmentModule : ObjectModule, IContentOwner { [SerializeField] private EquipmentSchemaSO _schema; [SerializeField] private WearableObject[] _serializedItems; private WearableObject[] _items; private void Awake() { _items = new WearableObject[_schema.slots.Length]; } private void Start() { InitializeItems(); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void InitializeItems() { // TODO: inicjalizacja serializowanych itemkow + ich eventy } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// public bool CanAdd(ItemObject item, int index) { if (item is not WearableObject wearable) return false; var slot = _schema.slots[index]; if (slot == null) return false; if (!slot.validTypes.Contains(wearable.data.Get().type)) return false; return true; } bool IContentOwner.Add(ItemObject item, int index) { var wearable = (WearableObject)item; parent.events.Invoke(new EquipEvent { unit = parent, wearable = wearable, index = index }); _items[index] = wearable; return true; } bool IContentOwner.Remove(ItemObject item) { var wearable = (WearableObject)item; var index = Array.IndexOf(_items, wearable); parent.events.Invoke(new UnEquipEvent { unit = parent, wearable = wearable, index = index }); _items[index] = null; return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// } }