diff --git a/scripts/behaviorTree/behavior/PatrolBehaviorTree.cs b/scripts/behaviorTree/behavior/PatrolBehaviorTree.cs
index 0fcf75d..ce64f85 100644
--- a/scripts/behaviorTree/behavior/PatrolBehaviorTree.cs
+++ b/scripts/behaviorTree/behavior/PatrolBehaviorTree.cs
@@ -29,7 +29,7 @@ public class PatrolBehaviorTree : BehaviorTreeTemplate
return patrolNode;
}
- protected override string? CreateId()
+ protected override string CreateId()
{
return Config.BehaviorTreeId.Patrol;
}
diff --git a/scripts/character/Player.cs b/scripts/character/Player.cs
index cc8b4b9..6a291f0 100644
--- a/scripts/character/Player.cs
+++ b/scripts/character/Player.cs
@@ -4,8 +4,6 @@ using System.Threading.Tasks;
using ColdMint.scripts.damage;
using ColdMint.scripts.deathInfo;
-using ColdMint.scripts.debug;
-using ColdMint.scripts.inventory;
using ColdMint.scripts.item;
using ColdMint.scripts.map.events;
using ColdMint.scripts.utils;
diff --git a/scripts/inventory/IItemContainer.cs b/scripts/inventory/IItemContainer.cs
index d68cab5..a02e732 100644
--- a/scripts/inventory/IItemContainer.cs
+++ b/scripts/inventory/IItemContainer.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using ColdMint.scripts.item;
diff --git a/scripts/inventory/ItemSlotNode.cs b/scripts/inventory/ItemSlotNode.cs
index 4cf060b..5425825 100644
--- a/scripts/inventory/ItemSlotNode.cs
+++ b/scripts/inventory/ItemSlotNode.cs
@@ -63,7 +63,7 @@ public partial class ItemSlotNode : MarginContainer
if (_itemStack is null) return null;
var result = _itemStack.PickItem();
- if (_itemStack.Quantity == 0) _itemStack = null;
+ if (_itemStack.Empty) _itemStack = null;
UpdateAllDisplay();
return result;
@@ -83,7 +83,7 @@ public partial class ItemSlotNode : MarginContainer
if (_itemStack is null) return null;
var result = _itemStack.PickItems(value);
- if (_itemStack.Quantity == 0) _itemStack = null;
+ if (_itemStack.Empty) _itemStack = null;
UpdateAllDisplay();
return result;
@@ -115,7 +115,7 @@ public partial class ItemSlotNode : MarginContainer
var result = _itemStack.RemoveItem(number);
//If the specified number of items is removed, the number of items is less than or equal to 0. Then we empty the inventory.
//如果移除指定数量的物品后,物品数量小于或等于0。那么我们清空物品栏。
- if (_itemStack.Quantity == 0) _itemStack = null;
+ if (_itemStack.Empty) _itemStack = null;
UpdateAllDisplay();
return result;
diff --git a/scripts/inventory/LootList.cs b/scripts/inventory/LootList.cs
index a16c76e..fe4a924 100644
--- a/scripts/inventory/LootList.cs
+++ b/scripts/inventory/LootList.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
-using System.Linq;
using ColdMint.scripts.debug;
using Godot;
diff --git a/scripts/inventory/LootListManager.cs b/scripts/inventory/LootListManager.cs
index b9bf1eb..0b60dcf 100644
--- a/scripts/inventory/LootListManager.cs
+++ b/scripts/inventory/LootListManager.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
-using ColdMint.scripts.debug;
using ColdMint.scripts.utils;
using Godot;
diff --git a/scripts/inventory/UniversalItemContainer.cs b/scripts/inventory/UniversalItemContainer.cs
index da798f7..8605b03 100644
--- a/scripts/inventory/UniversalItemContainer.cs
+++ b/scripts/inventory/UniversalItemContainer.cs
@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.Linq;
using ColdMint.scripts.character;
-using ColdMint.scripts.debug;
using ColdMint.scripts.item;
using ColdMint.scripts.item.itemStacks;
using ColdMint.scripts.utils;
diff --git a/scripts/item/ICommonItem.cs b/scripts/item/ICommonItem.cs
index 4f50c0e..b223a92 100644
--- a/scripts/item/ICommonItem.cs
+++ b/scripts/item/ICommonItem.cs
@@ -3,13 +3,9 @@
namespace ColdMint.scripts.item;
///
-/// Special item interface that make item common, which means will stack in a
-/// 该特殊的物品接口使得物品成为平凡物品,换言之,将会堆叠在中。
+/// The special item interface makes the item a normal item, in other words, will be stacked in
+/// 该特殊的物品接口使得物品成为普通的物品,换言之,将会堆叠在中。
///
-///
-/// Make this the class itself
-/// 应当为当前类自身
-///
///
///
/// Notice when you implement: To avoid unexpected behavior, unless you understand what you're doing, the method
diff --git a/scripts/item/IItem.cs b/scripts/item/IItem.cs
index fe49c47..c0cafbe 100644
--- a/scripts/item/IItem.cs
+++ b/scripts/item/IItem.cs
@@ -8,23 +8,28 @@ public interface IItem
{
///
/// ID of current item
+ /// 当前项目的ID
///
string Id { get; }
///
/// Icon of current item
+ /// 当前项目的图标
///
Texture2D Icon { get; }
///
/// Display name of current item
+ /// 显示当前Item的名称
///
string Name { get; }
///
/// Description of current item, which may show in inventory
+ /// 当前项目的描述
///
string? Description { get; }
///
/// Execute when current item is used
e.g. when player clicks left mouse button with current item in hand
+ /// 当前项被使用时执行
e.g. 当玩家用鼠标左键点击当前物品时
///
/// Owner of current item, if any
/// Target position, such as the position of the cursor when used by the player
@@ -32,6 +37,7 @@ public interface IItem
///
/// Execute when current item be removed from game.
+ /// 当前物品从游戏中移除时执行。
///
void Destroy();
@@ -67,7 +73,7 @@ public interface IItem
///
///
/// DO NOT use this method to create stack from item, use instead
- /// **不要**使用此方法从一个物品创建堆,请使用 。
+ /// 不要使用此方法从一个物品创建堆,请使用 。
///
///
IItemStack? SpecialStack() => null;
diff --git a/scripts/item/ItemType.cs b/scripts/item/ItemType.cs
index 01ac9b8..3c33da2 100644
--- a/scripts/item/ItemType.cs
+++ b/scripts/item/ItemType.cs
@@ -4,7 +4,7 @@ using Godot;
namespace ColdMint.scripts.item;
-public readonly struct ItemType(string id, Func newItemFunc, Texture2D? icon, int maxStackQuantity)
+public readonly struct ItemType(string id, Func newItemFunc, Texture2D? icon, int maxStackQuantity)
{
///
/// Item id of this type
@@ -15,7 +15,7 @@ public readonly struct ItemType(string id, Func newItemFunc, Texture2D? i
/// A function returns a new item instance of this type
/// 用于创建该类型的物品实例的函数
///
- public Func NewItemFunc { get; init; } = newItemFunc;
+ public Func NewItemFunc { get; init; } = newItemFunc;
///
/// Default icon of items of this type
/// 该类型物品的默认图标
diff --git a/scripts/item/ItemTypeManager.cs b/scripts/item/ItemTypeManager.cs
index 4d35cfa..25089f9 100644
--- a/scripts/item/ItemTypeManager.cs
+++ b/scripts/item/ItemTypeManager.cs
@@ -1,27 +1,34 @@
using System.Collections.Generic;
-
+using ColdMint.scripts.item.weapon;
using ColdMint.scripts.utils;
-
using Godot;
namespace ColdMint.scripts.item;
+///
+/// Item manager
+/// 物品管理器
+///
public static class ItemTypeManager
{
///
- /// Register items statically here
+ /// Register items here
+ /// 在这里注册物品
///
public static void StaticRegister()
{
var staffOfTheUndeadScene = ResourceLoader.Load("res://prefab/weapons/staffOfTheUndead.tscn");
var staffOfTheUndeadIcon = ResourceLoader.Load("res://sprites/weapon/staffOfTheUndead.png");
var staffOfTheUndead =
- new ItemType("staff_of_the_undead", () => staffOfTheUndeadScene.Instantiate(), staffOfTheUndeadIcon, 1);
+ new ItemType("staff_of_the_undead",
+ () => NodeUtils.InstantiatePackedScene(staffOfTheUndeadScene), staffOfTheUndeadIcon,
+ 1);
Register(staffOfTheUndead);
var packsackScene = ResourceLoader.Load("res://prefab/packsacks/packsack.tscn");
var packsackIcon = ResourceLoader.Load("res://sprites/Player.png");
- var packsack = new ItemType("packsack", () => packsackScene.Instantiate(), packsackIcon, 1);
+ var packsack = new ItemType("packsack", () => NodeUtils.InstantiatePackedScene(packsackScene),
+ packsackIcon, 1);
Register(packsack);
}
@@ -30,10 +37,14 @@ public static class ItemTypeManager
///
- /// Register an item type.
- /// Return false if the item id already exist.
+ /// Register an item type.
+ /// Return false if the item id already exist.
+ /// 注册一个物品类型
+ /// 如果项目id已经存在,则返回false。
///
- /// Whether the registration was successful.
+ /// Whether the registration was successful.
+ /// 注册是否成功。
+ ///
public static bool Register(ItemType itemType) => Registry.TryAdd(itemType.Id, itemType);
///
@@ -70,5 +81,15 @@ public static class ItemTypeManager
? itemType.Icon ?? DefaultTexture
: DefaultTexture;
- public static int MaxStackQuantityOf(string id) => Registry.TryGetValue(id, out var itemType) ? itemType.MaxStackQuantity : 0;
+ ///
+ /// Gets the maximum number of stacks for an item
+ /// 获取某个物品的最大堆叠数量
+ ///
+ ///
+ ///id
+ ///物品ID
+ ///
+ ///
+ public static int MaxStackQuantityOf(string id) =>
+ Registry.TryGetValue(id, out var itemType) ? itemType.MaxStackQuantity : 0;
}
\ No newline at end of file
diff --git a/scripts/item/itemStacks/CommonItemStack.cs b/scripts/item/itemStacks/CommonItemStack.cs
index 443790e..1887718 100644
--- a/scripts/item/itemStacks/CommonItemStack.cs
+++ b/scripts/item/itemStacks/CommonItemStack.cs
@@ -1,18 +1,22 @@
using System;
-
using Godot;
namespace ColdMint.scripts.item.itemStacks;
///
-///
-/// one of the basic item stacks, where there is only one instance of an item actually held in the stack,
-/// meaning that all items are identical (or completely random in some ways)
-///
-/// 平凡物品堆,基础物品堆之一,堆中实际保存的物品实例仅有一个,意味着所有物品都完全一致(或某些方面完全随机)
+/// An ordinary item pile, in which only one instance of the item is actually saved.
+/// 普通的物品堆,堆中实际保存的物品实例仅有一个。
///
-///
-///
+///
+///When the method is called in this implementation, the number of internal items is increased by one and new items passed in are destroyed.
+///在此实现下调用方法时,会对内部物品的数量加一,并销毁传递进来的新物品。
+///
+///
+///innerItem
+///内部物品
+///
+///
+///
public class CommonItemStack(ICommonItem innerItem) : IItemStack
{
public int MaxQuantity { get; } = ItemTypeManager.MaxStackQuantityOf(innerItem.Id);
@@ -31,12 +35,18 @@ public class CommonItemStack(ICommonItem innerItem) : IItemStack
{
if (!CanAddItem(item)) return false;
Quantity++;
+ item.Destroy();
return true;
}
public int CanTakeFrom(IItemStack itemStack)
{
- if (itemStack.Empty || !innerItem.CanStackWith(itemStack.GetItem()!)) return 0;
+ var item = itemStack.GetItem();
+ if (item == null)
+ {
+ return 0;
+ }
+ if (itemStack.Empty || !innerItem.CanStackWith(item)) return 0;
return Math.Min(itemStack.Quantity, MaxQuantity - Quantity);
}
@@ -55,10 +65,11 @@ public class CommonItemStack(ICommonItem innerItem) : IItemStack
public IItem? PickItem()
{
- if (Empty) return null;
+ if(Empty) return null;
Quantity--;
- if (Empty) innerItem.Destroy();
- return innerItem.CopyInstance();
+ var result = innerItem.CopyInstance();
+ if(Empty) innerItem.Destroy();
+ return result;
}
public IItemStack? PickItems(int value)
@@ -66,6 +77,10 @@ public class CommonItemStack(ICommonItem innerItem) : IItemStack
if (Empty) return null;
var result = new CommonItemStack(innerItem.CopyInstance());
var n = Math.Min(Quantity, value);
+ if (n < 0)
+ {
+ n = Quantity;
+ }
result.Quantity = n;
Quantity -= n;
if (Empty) innerItem.Destroy();
@@ -75,6 +90,10 @@ public class CommonItemStack(ICommonItem innerItem) : IItemStack
public int RemoveItem(int number)
{
var n = Math.Min(number, Quantity);
+ if (n < 0)
+ {
+ n = Quantity;
+ }
Quantity -= n;
if (Empty) innerItem.Destroy();
return number - n;
diff --git a/scripts/item/itemStacks/IItemStack.cs b/scripts/item/itemStacks/IItemStack.cs
index 34d8fce..5ba7d17 100644
--- a/scripts/item/itemStacks/IItemStack.cs
+++ b/scripts/item/itemStacks/IItemStack.cs
@@ -1,10 +1,10 @@
using System;
-
using Godot;
namespace ColdMint.scripts.item.itemStacks;
///
+/// 物品槽中的物品堆
/// Item stack in an inventory slot
///
public interface IItemStack
@@ -60,13 +60,21 @@ public interface IItemStack
public bool CanAddItem(IItem item);
///
- /// Hold a given item
+ /// Add items to the itemStack
+ /// 添加物品到物品堆内
///
- /// Item to hold by current stack
- /// Whether successful
+ ///
+ ///Items to add
+ ///需要添加的物品
+ ///
+ ///
+ ///Whether successful
+ ///是否成功
+ ///
public bool AddItem(IItem item);
///
+ /// Determines the number of items that can be received from the specified pile
/// 判断能从指定物品堆中接收的物品数量
///
///
@@ -77,19 +85,22 @@ public interface IItemStack
public int CanTakeFrom(IItemStack itemStack);
///
+ /// Move as many items as possible from the specified item pile to the current item pile. Items that have been moved to the current item pile should be removed from the original item pile.
/// 将指定物品堆中尽可能多的物品移动至当前物品堆中,被移入当前堆的物品应从原物品堆中移除。
///
///
+ /// The pile of items that are moved into the current pile
/// 被移入当前堆的物品堆
///
///
+ /// Whether the original stack is empty after the operation
/// 操作结束后原物品堆是否为空
///
public bool TakeFrom(IItemStack itemStack);
///
- /// Get item instance at the top of current stack without removing it from stack
- /// 获取当前物品堆顶部的物品实例而不取出该物品
+ /// Gets an item instance of the current item pile without retrieving the item
+ /// 获取当前物品堆的物品实例而不取出该物品
///
///
///
@@ -152,8 +163,9 @@ public interface IItemStack
item.SpecialStack() ??
ItemTypeManager.MaxStackQuantityOf(item.Id) switch
{
- 1 => new SingleItemStack(item),
- > 1 => item is ICommonItem commonItem ? new CommonItemStack(commonItem) : new UniqueItemStack(item),
- var other => throw new ArgumentException($"item {item} of type '{item.Id}' has unexpected max stack quantity {other}")
+ 1 => new SingleItemStack(item),
+ > 1 => item is ICommonItem commonItem ? new CommonItemStack(commonItem) : new UniqueItemStack(item),
+ var other => throw new ArgumentException(
+ $"item {item} of type '{item.Id}' has unexpected max stack quantity {other}")
};
}
\ No newline at end of file
diff --git a/scripts/item/itemStacks/SingleItemStack.cs b/scripts/item/itemStacks/SingleItemStack.cs
index 61fc628..f573a37 100644
--- a/scripts/item/itemStacks/SingleItemStack.cs
+++ b/scripts/item/itemStacks/SingleItemStack.cs
@@ -5,17 +5,18 @@ using Godot;
namespace ColdMint.scripts.item.itemStacks;
///
-/// One of the basic item stacks, there are always one item in stack
-/// 单身狗物品堆,基础物品堆之一,堆中永远只会有一个物品
+/// One of the basic item stacks, there are always one item in stack(Stack not supported)
+/// 单身狗物品堆,基础物品堆之一,堆中永远只会有一个物品(不支持堆叠)
///
-///
+///
+///
public class SingleItemStack(IItem item) : IItemStack
{
public IItem Item { get; init; } = item;
public int MaxQuantity => 1;
public int Quantity => 1;
- public bool Empty { get; private set; } = false;
+ public bool Empty { get; private set; }
public Texture2D Icon => Item.Icon;
public string Name => Item.Name;
public string? Description => Item.Description;
diff --git a/scripts/item/itemStacks/UniqueItemStack.cs b/scripts/item/itemStacks/UniqueItemStack.cs
index 7f9af3f..4837fe8 100644
--- a/scripts/item/itemStacks/UniqueItemStack.cs
+++ b/scripts/item/itemStacks/UniqueItemStack.cs
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Linq;
-
using Godot;
namespace ColdMint.scripts.item.itemStacks;
@@ -22,6 +20,7 @@ public class UniqueItemStack : IItemStack
MaxQuantity = ItemTypeManager.MaxStackQuantityOf(item.Id);
}
+
private UniqueItemStack(UniqueItemStack from)
{
_items = from._items;
@@ -91,9 +90,10 @@ public class UniqueItemStack : IItemStack
if (value < 0) value = Quantity;
var result = new UniqueItemStack(PickItem()!);
+ //Calculate the amount left to take out
//计算剩余的要取出的数量
var restToMove = Math.Min(value - 1, Quantity);
- for (int i = 0; i < restToMove; i++)
+ for (var i = 0; i < restToMove; i++)
{
result.AddItem(PickItem()!);
}
diff --git a/scripts/item/weapon/ProjectileWeapon.cs b/scripts/item/weapon/ProjectileWeapon.cs
index a8394e0..bef4302 100644
--- a/scripts/item/weapon/ProjectileWeapon.cs
+++ b/scripts/item/weapon/ProjectileWeapon.cs
@@ -1,5 +1,3 @@
-using System.Collections.Generic;
-
using ColdMint.scripts.debug;
using ColdMint.scripts.projectile;
using ColdMint.scripts.utils;
diff --git a/scripts/item/weapon/WeaponTemplate.cs b/scripts/item/weapon/WeaponTemplate.cs
index 77759f1..e05fc82 100644
--- a/scripts/item/weapon/WeaponTemplate.cs
+++ b/scripts/item/weapon/WeaponTemplate.cs
@@ -3,8 +3,6 @@ using System;
using ColdMint.scripts.camp;
using ColdMint.scripts.character;
using ColdMint.scripts.damage;
-using ColdMint.scripts.inventory;
-
using Godot;
namespace ColdMint.scripts.item.weapon;
@@ -116,7 +114,7 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem
//If it leaves the ground or walls.
//如果离开了地面或墙壁。
- if (node is TileMap tileMap)
+ if (node is TileMap)
{
_tileMapNumber--;
if (_tileMapNumber == 0)
@@ -141,7 +139,7 @@ public abstract partial class WeaponTemplate : RigidBody2D, IItem
return;
}
- if (node is TileMap tileMap)
+ if (node is TileMap)
{
_tileMapNumber++;
EnableContactInjury = false;
diff --git a/scripts/loader/uiLoader/GameOverLoaderMenuLoader.cs b/scripts/loader/uiLoader/GameOverLoaderMenuLoader.cs
index b650aee..7cb4f4d 100644
--- a/scripts/loader/uiLoader/GameOverLoaderMenuLoader.cs
+++ b/scripts/loader/uiLoader/GameOverLoaderMenuLoader.cs
@@ -1,5 +1,4 @@
-using System.Threading.Tasks;
-using ColdMint.scripts.map.events;
+using ColdMint.scripts.map.events;
using Godot;
namespace ColdMint.scripts.loader.uiLoader;
diff --git a/scripts/map/AiCharacterSpawn.cs b/scripts/map/AiCharacterSpawn.cs
index ba25f36..7def844 100644
--- a/scripts/map/AiCharacterSpawn.cs
+++ b/scripts/map/AiCharacterSpawn.cs
@@ -1,5 +1,4 @@
using ColdMint.scripts.character;
-using ColdMint.scripts.debug;
using ColdMint.scripts.map.events;
using ColdMint.scripts.utils;
using Godot;
diff --git a/scripts/utils/NodeUtils.cs b/scripts/utils/NodeUtils.cs
index 0a3f37d..5ec5d65 100644
--- a/scripts/utils/NodeUtils.cs
+++ b/scripts/utils/NodeUtils.cs
@@ -2,11 +2,10 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using ColdMint.scripts.debug;
-using ColdMint.scripts.inventory;
+using ColdMint.scripts.item;
using ColdMint.scripts.item.weapon;
using Godot;
-using Packsack = ColdMint.scripts.item.Packsack;
namespace ColdMint.scripts.utils;