From 94a2e78efc72f8343a16e1550bd15f746defe4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=A7=E9=9B=A8=E7=83=A8?= Date: Thu, 13 Jun 2024 03:04:12 +0800 Subject: [PATCH] =?UTF-8?q?Fixed=20all=20the=20bugs=20that=20prevented=20t?= =?UTF-8?q?he=20game=20from=20working,=20added=20static=20item=20registrat?= =?UTF-8?q?ion=20on=20startup=20=E9=98=BB=E7=A2=8D=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E7=9A=84bug=E5=B7=B2=E5=B0=BD=E6=95=B0?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E9=9D=99=E6=80=81=E7=89=A9=E5=93=81=E6=B3=A8?= =?UTF-8?q?=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locals/Weapon.csv | 4 +-- locals/Weapon.en.translation | Bin 494 -> 494 bytes locals/Weapon.ja.translation | Bin 573 -> 573 bytes locals/Weapon.zh.translation | Bin 525 -> 525 bytes scripts/character/CharacterTemplate.cs | 37 +++++++++----------- scripts/inventory/ItemSlotNode.cs | 12 +++---- scripts/inventory/UniversalItemContainer.cs | 6 ++-- scripts/item/IItemStack.cs | 1 + scripts/item/ItemType.cs | 10 +++--- scripts/item/ItemTypeManager.cs | 12 ++++--- scripts/item/SingleItemStack.cs | 19 +++++++--- scripts/loader/uiLoader/MainMenuLoader.cs | 8 +++++ 12 files changed, 64 insertions(+), 45 deletions(-) diff --git a/locals/Weapon.csv b/locals/Weapon.csv index 7bfa22a..7be7cae 100644 --- a/locals/Weapon.csv +++ b/locals/Weapon.csv @@ -1,3 +1,3 @@ id,zh,en,ja -staff_of_the_undead,死灵法杖,StaffOfTheUndead,ネクロポリスの杖です -staff_of_the_undead_desc,发射诅咒,可将敌人转化为邪恶的怪物。,Cast a curse that transforms enemies into evil monsters.,呪いを発射して、敵を邪悪な怪物に変えることができます。 \ No newline at end of file +item_staff_of_the_undead,死灵法杖,StaffOfTheUndead,ネクロポリスの杖です +item_staff_of_the_undead_desc,发射诅咒,可将敌人转化为邪恶的怪物。,Cast a curse that transforms enemies into evil monsters.,呪いを発射して、敵を邪悪な怪物に変えることができます。 \ No newline at end of file diff --git a/locals/Weapon.en.translation b/locals/Weapon.en.translation index 46fb4a6b4c5a33a88bf373fe48e7937b78e55165..3a92161063c4ac7240cf1aa7ee4ab4c4adbbdf9e 100644 GIT binary patch delta 95 zcmaFI{Em5pG$U)KVOD0vWCcbu&;LNc00bbK4M?*Bu>uhD05KyJM~l1<1Tq-}fLIVJ V29o=^YoQ@XObLiBC(mc}2LQQp6hQz0 delta 95 zcmaFI{Em5pG$X5NQEGDWWCcbuPX-|P4+LybniWVZ05J~`GeU9vscqKuhD05KyJM~l1<1Tq=qp%^Cq RbJs#ckXR51PhQ8^4*;dw6u1Ej<&B$t8T9{=%S%J~j^FI(U00D?*1JbNOtN_G3K+Fim(IW2yflLNoD29pu R+_lgUBxVl6lh-lE0|0526O8}> delta 95 zcmeBW>1Ej<&B&TnY*bo2S%J~jlK}|+0|6V9W(Cp;K+FTgj8GhZYTI>QAln>@Vd9c} QAJl+C3?Mn)$?F*70eQa@i2wiq diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs index 75e2fb0..b2531af 100644 --- a/scripts/character/CharacterTemplate.cs +++ b/scripts/character/CharacterTemplate.cs @@ -67,7 +67,7 @@ public partial class CharacterTemplate : CharacterBody2D /// protected virtual void WhenUpdateCurrentItem(Node2D? currentItem) { } - //Define a pick up range + //Define a pickup range //定义一个拾起范围 private Area2D? _pickingArea; @@ -122,7 +122,7 @@ public partial class CharacterTemplate : CharacterBody2D /// protected List? PickingRangeBodiesList; - public Node[] PickingRangeBodies => PickingRangeBodiesList?.ToArray() ?? Array.Empty(); + public Node[] PickingRangeBodies => PickingRangeBodiesList?.ToArray() ?? []; /// /// Resurrected character @@ -155,7 +155,7 @@ public partial class CharacterTemplate : CharacterBody2D } /// - /// Find the nearest item within the pick up area(Does not include items currently held) + /// Find the nearest item within the pickup area(Does not include items currently held) /// 在拾捡范围内查找距离最近的物品(不包括当前持有的物品) /// /// @@ -179,7 +179,7 @@ public partial class CharacterTemplate : CharacterBody2D /// - /// Get all weapons within range of the pick up + /// Get all weapons within range of the pickup /// 获取所有在拾捡范围内的武器 /// /// @@ -401,7 +401,7 @@ public partial class CharacterTemplate : CharacterBody2D { if (targetCamp.Id == playerCamp.Id) { - //If an attack is allowed and you are on the same side, it is displayed as a friendly color (friend damage). + //If an attack is allowed, and you are on the same side, it is displayed as a friendly color (friend damage). //如果允许攻击,且属于同一阵营,则显示为友好颜色(友伤) _healthBar.SetFriendlyTones(); } @@ -537,7 +537,7 @@ public partial class CharacterTemplate : CharacterBody2D /// protected virtual void EnterThePickingRangeBody(Node node) { - if (node is not IItem_New item) + if (node is not IItem_New) { return; } @@ -651,23 +651,20 @@ public partial class CharacterTemplate : CharacterBody2D } } - /// - /// Throw item - /// 抛出物品 - /// - /// - ///Item slot index in item container - ///物品容器内的物品槽位置 - /// - /// - ///The speed to be applied to the item - ///要施加到物品上的速度 - /// - protected void ThrowOneItem(ItemSlotNode itemSlotNode, Vector2 velocity) + /// + /// Throw item + /// 抛出物品 + /// + /// + /// + /// The speed to be applied to the item + /// 要施加到物品上的速度 + /// + private void ThrowOneItem(ItemSlotNode itemSlotNode, Vector2 velocity) { //Pick an item from the item container //从物品容器内取出一个物品 - var item = itemSlotNode?.PickItem(); + var item = itemSlotNode.PickItem(); if (item is not Node2D node2D) { diff --git a/scripts/inventory/ItemSlotNode.cs b/scripts/inventory/ItemSlotNode.cs index 9208cd5..58f8524 100644 --- a/scripts/inventory/ItemSlotNode.cs +++ b/scripts/inventory/ItemSlotNode.cs @@ -62,8 +62,8 @@ public partial class ItemSlotNode : MarginContainer if (_itemStack is null) return null; var result = _itemStack.PickItem(); - if (_itemStack.Quantity == 0) ClearSlot(); - else UpdateAllDisplay(); + if (_itemStack.Quantity == 0) _itemStack = null; + UpdateAllDisplay(); return result; } @@ -82,8 +82,8 @@ public partial class ItemSlotNode : MarginContainer if (_itemStack is null) return null; var result = _itemStack.PickItems(value); - if (_itemStack.Quantity == 0) ClearSlot(); - else UpdateAllDisplay(); + if (_itemStack.Quantity == 0) _itemStack = null; + UpdateAllDisplay(); return result; } @@ -114,8 +114,8 @@ 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) ClearSlot(); - else UpdateAllDisplay(); + if (_itemStack.Quantity == 0) _itemStack = null; + UpdateAllDisplay(); return result; } diff --git a/scripts/inventory/UniversalItemContainer.cs b/scripts/inventory/UniversalItemContainer.cs index 975f837..3de0b44 100644 --- a/scripts/inventory/UniversalItemContainer.cs +++ b/scripts/inventory/UniversalItemContainer.cs @@ -162,17 +162,17 @@ public class UniversalItemContainer : IItemContainer public ItemSlotNode? Match(IItemStack stack) { - throw new NotImplementedException(); + return _itemSlotNodes?.FirstOrDefault(itemSlotNode => itemSlotNode.CanAddItem(stack.GetItem()!)); } public ItemSlotNode? Match(Func predicate) { - throw new NotImplementedException(); + return _itemSlotNodes?.FirstOrDefault(node => predicate(node.GetItemStack())); } public IEnumerable MatchAll(Func predicate) { - throw new NotImplementedException(); + return from node in _itemSlotNodes where predicate(node.GetItemStack()) select node; } diff --git a/scripts/item/IItemStack.cs b/scripts/item/IItemStack.cs index 8507679..40a1a32 100644 --- a/scripts/item/IItemStack.cs +++ b/scripts/item/IItemStack.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using Godot; diff --git a/scripts/item/ItemType.cs b/scripts/item/ItemType.cs index 308370b..395670c 100644 --- a/scripts/item/ItemType.cs +++ b/scripts/item/ItemType.cs @@ -4,22 +4,22 @@ using Godot; namespace ColdMint.scripts.item; -public readonly struct ItemType +public readonly struct ItemType(string id, Func newItemFunc, Texture2D? icon, int maxStackQuantity) { /// /// Item id of this type /// - public string Id { get; init; } + public string Id { get; init; } = id; /// /// A function returns a new item instance of this type /// - public Func NewItemFunc { get; init; } + public Func NewItemFunc { get; init; } = newItemFunc; /// /// Default icon of items of this type /// - public Texture2D? Icon { get; init; } + public Texture2D? Icon { get; init; } = icon; /// /// Max number in item stack of this type /// - public int MaxStackQuantity { get; init; } + public int MaxStackQuantity { get; init; } = maxStackQuantity; } \ No newline at end of file diff --git a/scripts/item/ItemTypeManager.cs b/scripts/item/ItemTypeManager.cs index b8e82ea..c97aefb 100644 --- a/scripts/item/ItemTypeManager.cs +++ b/scripts/item/ItemTypeManager.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using ColdMint.scripts.utils; @@ -10,14 +9,19 @@ namespace ColdMint.scripts.item; public static class ItemTypeManager { // Register items statically here - static ItemTypeManager() { } + public static void StaticRegister() + { + var staffOfTheUndeadScene = ResourceLoader.Load("res://prefab/weapons/staffOfTheUndead.tscn"); + var staffOfTheUndead = new ItemType("staff_of_the_undead", () => staffOfTheUndeadScene.Instantiate(), null, 1); + Register(staffOfTheUndead); + } private static Dictionary Registry { get; } = []; private static Texture2D DefaultTexture { get; } = new PlaceholderTexture2D(); /// - /// Register a item type. + /// Register an item type. /// Return false if the item id already exist. /// /// Whether the registration was successful. diff --git a/scripts/item/SingleItemStack.cs b/scripts/item/SingleItemStack.cs index 839066e..0a31888 100644 --- a/scripts/item/SingleItemStack.cs +++ b/scripts/item/SingleItemStack.cs @@ -31,26 +31,35 @@ public class SingleItemStack(IItem_New item) : IItemStack public IItem_New? GetItem() { - throw new NotImplementedException(); + return Quantity == 1 ? Item : null; } public IItem_New? PickItem() { - throw new NotImplementedException(); + Quantity = 0; + return Item; } public IItemStack? PickItems(int value) { - throw new NotImplementedException(); + if (value == 0) return null; + else + { + Quantity = 0; + return new SingleItemStack(Item); + } } public int RemoveItem(int number) { - throw new NotImplementedException(); + if (number == 0) return 0; + Quantity = 0; + Item.Destroy(); + return Math.Max(number - 1, 0); } public void ClearStack() { - throw new NotImplementedException(); + RemoveItem(1); } } \ No newline at end of file diff --git a/scripts/loader/uiLoader/MainMenuLoader.cs b/scripts/loader/uiLoader/MainMenuLoader.cs index 9dd308d..133d287 100644 --- a/scripts/loader/uiLoader/MainMenuLoader.cs +++ b/scripts/loader/uiLoader/MainMenuLoader.cs @@ -1,12 +1,15 @@ using System; using System.IO; using System.Text; + using ColdMint.scripts.camp; using ColdMint.scripts.deathInfo; using ColdMint.scripts.debug; using ColdMint.scripts.inventory; +using ColdMint.scripts.item; using ColdMint.scripts.map; using ColdMint.scripts.map.roomInjectionProcessor; + using Godot; namespace ColdMint.scripts.loader.uiLoader; @@ -57,6 +60,7 @@ public partial class MainMenuLoader : UiLoaderTemplate testLootList.AddLootEntry(lootEntry); LootListManager.RegisterLootList(testLootList); } + DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler()); MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor()); MapGenerator.RegisterRoomInjectionProcessor(new TimeIntervalRoomInjectorProcessor()); @@ -82,6 +86,10 @@ public partial class MainMenuLoader : UiLoaderTemplate var aborigines = new Camp(Config.CampId.Aborigines); CampManager.AddCamp(aborigines); _gameScene = (PackedScene)GD.Load("res://scenes/game.tscn"); + + //Temp: Register ItemType + //临时:注册物品类型 + ItemTypeManager.StaticRegister(); } public override void InitializeUi()