Items held by the player upon death are also destroyed.

玩家死亡后持有的物品也会被销毁。
This commit is contained in:
Cold-Mint 2024-10-18 14:56:58 +08:00
parent 5ad4c1f09d
commit 1f66376857
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
3 changed files with 33 additions and 23 deletions

View File

@ -35,6 +35,7 @@ offset_top = 215.0
offset_right = 50.5 offset_right = 50.5
offset_bottom = 248.0 offset_bottom = 248.0
grow_horizontal = 2 grow_horizontal = 2
disabled = true
text = "ui_settings" text = "ui_settings"
[node name="levelGraphEditorButton" type="Button" parent="."] [node name="levelGraphEditorButton" type="Button" parent="."]

View File

@ -120,8 +120,11 @@ public interface IItemContainer
/// <para>清理物品</para> /// <para>清理物品</para>
/// </summary> /// </summary>
/// <param name="index"></param> /// <param name="index"></param>
/// <returns></returns> /// <returns>
bool ClearItem(int index); ///<para>Returns the item to be cleaned, or null if the item to be cleaned cannot be found</para>
///<para>返回要清理的物品如果找不到要清理的物品则返回null</para>
/// </returns>
IItem? ClearItem(int index);
/// <summary> /// <summary>
/// <para>ClearAllItems</para> /// <para>ClearAllItems</para>

View File

@ -304,15 +304,16 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
} }
public bool ClearItem(int index) public IItem? ClearItem(int index)
{ {
if (!_itemDictionary.TryGetValue(index, out var item)) if (!_itemDictionary.TryGetValue(index, out var item))
{ {
return false; return null;
} }
var result = _itemDictionary.Remove(index); if (!_itemDictionary.Remove(index))
if (result)
{ {
return null;
}
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
{ {
NewItem = null, NewItem = null,
@ -332,15 +333,20 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
OldItem = null OldItem = null
}); });
} }
} return item;
return result;
} }
public void ClearAllItems() public void ClearAllItems()
{ {
foreach (var itemDictionaryKey in _itemDictionary.Keys) foreach (var itemDictionaryKey in _itemDictionary.Keys)
{ {
ClearItem(itemDictionaryKey); var item = ClearItem(itemDictionaryKey);
if (item == null)
{
continue;
}
item.SelfItemContainer?.ClearAllItems();
item.QueueFreeSelf();
} }
} }