From bb44d77805b2d7dd03dcc7276e8a32ed3500eb46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=A7=E9=9B=A8=E7=83=A8?= Date: Fri, 14 Jun 2024 19:12:06 +0800 Subject: [PATCH] =?UTF-8?q?Ban=20Packsack=20nesting=20=E7=A6=81=E6=AD=A2?= =?UTF-8?q?=E8=83=8C=E5=8C=85=E5=B5=8C=E5=A5=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/item/itemStacks/PacksackStack.cs | 26 +++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/scripts/item/itemStacks/PacksackStack.cs b/scripts/item/itemStacks/PacksackStack.cs index b3ff671..a70a22e 100644 --- a/scripts/item/itemStacks/PacksackStack.cs +++ b/scripts/item/itemStacks/PacksackStack.cs @@ -4,7 +4,6 @@ using Godot; namespace ColdMint.scripts.item.itemStacks; - /// /// ItemStack for item. Can add items into pack by stack them to this stack. /// 用于物品的堆栈。可以将物品堆叠到此堆栈中,从而将物品添加到背包中。 @@ -19,13 +18,30 @@ public class PacksackStack(Packsack packsack) : IItemStack public string Name => packsack.Name; public string? Description => packsack.Description; - public bool CanAddItem(IItem item) => packsack.ItemContainer?.CanAddItem(item) ?? false; + //todo: 只拒绝是背包的物品是权宜之计,应该为物品加入一个“是否可以放入背包”的属性来实现这个判断。 + public bool CanAddItem(IItem item) + { + if (item is Packsack) return false; + return packsack.ItemContainer?.CanAddItem(item) ?? false; + } - public bool AddItem(IItem item) => packsack.ItemContainer?.AddItem(item) ?? false; + public bool AddItem(IItem item) + { + if (item is Packsack) return false; + return packsack.ItemContainer?.AddItem(item) ?? false; + } - public int CanTakeFrom(IItemStack itemStack) => packsack.ItemContainer?.CanAddItemStack(itemStack) ?? 0; + public int CanTakeFrom(IItemStack itemStack) + { + if (itemStack.GetItem() is Packsack) return 0; + return packsack.ItemContainer?.CanAddItemStack(itemStack) ?? 0; + } - public bool TakeFrom(IItemStack itemStack) => packsack.ItemContainer?.AddItemStack(itemStack) ?? false; + public bool TakeFrom(IItemStack itemStack) + { + if (itemStack.GetItem() is Packsack) return false; + return packsack.ItemContainer?.AddItemStack(itemStack) ?? false; + } public IItem? GetItem() {