/// <summary> /// 从包裹里面查询是否有某个物品 /// 返回-1表示没有 /// </summary> public int find(TezComData gameObject) { return(m_Slots.FindIndex((TezInventoryItemSlot slot) => { return slot.item == gameObject; })); }
private TezInventoryItemSlot findSlotStackable(TezComData gameObject) { TezInventoryItemSlot result_slot = null; int result_index = 0; while (result_index < m_Slots.Count) { var slot = m_Slots[result_index]; ///找空格子 if (result_slot == null && slot.item == null) { result_slot = slot; } ///找相同格子 ///可堆叠的物品 ///他们的模板相同 if (slot.item != null && slot.item.templateAs(gameObject)) { result_slot = slot; break; } result_index++; } return(result_slot); }
public void store(int slotIndex, TezComData gameObject, int count) { var slot = m_Slots[slotIndex]; slot.item = gameObject; slot.count += count; onItemAdded?.Invoke(slot); }
public bool store(TezComData gameObject, int count) { if (m_Inventory.tryGet(out var inventory)) { inventory.store(gameObject, count); return(true); } return(false); }
public bool take(TezComData gameObject, int count) { if (m_Inventory.tryGet(out var inventory)) { var index = inventory.find(gameObject); if (index > 0) { inventory.take(index, count); return(true); } } return(false); }
/// <summary> /// 堆叠型加入 /// </summary> public void store(TezComData gameObject, int count) { var stack_max_count = TezDatabaseItemConfig.getConfig(gameObject.category).stackCount; TezInventoryItemSlot result_slot = this.findSlotStackable(gameObject); ///找到空格子 if (result_slot != null) { if (result_slot.item != null) { result_slot.count += count; var remain = result_slot.count - stack_max_count; if (remain > 0) { result_slot.count = stack_max_count; this.store(gameObject, remain); } else { gameObject.close(); } } else { result_slot.item = gameObject; if (count > stack_max_count) { result_slot.count = stack_max_count; this.store(gameObject, count - stack_max_count); } else { result_slot.count = count; } } } ///没有找到空格子 else { result_slot = this.createItemSlot(); result_slot.item = gameObject; result_slot.count = count; result_slot.index = m_Slots.Count; m_Slots.Add(result_slot); } onItemAdded?.Invoke(result_slot); }
/// <summary> /// 存入 /// 不允许堆叠 /// </summary> public void store(TezComData gameObject) { TezInventoryItemSlot result_slot = this.findSlotUnstackable(); ///找到空格子 if (result_slot != null) { result_slot.item = gameObject; result_slot.count = -1; } ///没有找到空格子 else { result_slot = this.createItemSlot(); result_slot.item = gameObject; result_slot.count = -1; result_slot.index = m_Slots.Count; m_Slots.Add(result_slot); } onItemAdded?.Invoke(result_slot); }
/// <summary> /// 存入 /// </summary> public void store(TezComData item, int count) { m_Inventory.store(this.index, item, count); }
public void saveItem(TezComData my_object) { // var ruid = my_object.GUID; }
public override bool calculate(TezComData gameObject) { return(true); }
public abstract bool calculate(TezComData gameObject);
public override bool calculate(TezComData gameObject) { return(m_Function(gameObject)); }