From 026c7ff32f90177819455e6143c25214776ddbc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=A7=E9=9B=A8=E7=83=A8?= Date: Wed, 12 Jun 2024 00:51:40 +0800 Subject: [PATCH] Add single item stack type, move the weapon namespace into the item namespace, and I think it's ready to be merged into the new interface --- locals/Slogan.ja.translation | Bin 877 -> 548 bytes project.godot | 1 - scripts/behaviorTree/ai/AiPickNode.cs | 3 +- scripts/character/CharacterTemplate.cs | 46 ++++++------------ scripts/character/Player.cs | 18 ++++--- scripts/inventory/HotBar.cs | 3 +- scripts/item/IItemStack.cs | 25 ++++++++-- scripts/item/ItemType.cs | 8 ++- scripts/item/ItemTypeManager.cs | 7 ++- scripts/item/SingleItemStack.cs | 21 ++++++++ scripts/item/StackType.cs | 8 +++ scripts/{ => item}/weapon/ProjectileWeapon.cs | 4 +- scripts/{ => item}/weapon/WeaponTemplate.cs | 4 +- 13 files changed, 94 insertions(+), 54 deletions(-) create mode 100644 scripts/item/SingleItemStack.cs create mode 100644 scripts/item/StackType.cs rename scripts/{ => item}/weapon/ProjectileWeapon.cs (98%) rename scripts/{ => item}/weapon/WeaponTemplate.cs (99%) diff --git a/locals/Slogan.ja.translation b/locals/Slogan.ja.translation index 16ad9fc68dbbd239ae30c46bcd584be05ea6ee91..5b1b7dfbcf34f9e806cd7d1ce7c71b7a6341f1ba 100644 GIT binary patch literal 548 zcmV+<0^9vkQ$s@n000005C8ya0{{RF0ssIgwJ-f(X#y1x0EQV|L=cga#tHyl40m_qzQ~&20s| z@8)`T3PS)$089X1;3-3KPAU2gEJYCmSz@x9plkzOvC1xxthAMEO6^}TM}r3)<9HGI z1B_+X7O#m#tz?7zV2P|vCBv`aAMgYC1$-RX;HU98TQgc2ZXb3yzv=V34;b>N zd|uaq6+W*+06m}Afj}Ie*98|wNJf4bEiG!AELm%EoOEZf&?Rvjhp1H&vqUg5Kd%Cav4J|J*{ znIbz6eG&j6x}=@%-5ye_QQaCvoQdG%901RnpCV~wqKEgk21|$5u3sT{a~F5+?l>D) zj$`ZMphfv@g>9#E3@6=*^D|_D3x2~JP8T?GIzh)?f5=zEW)^LZiA3*Y5E~K004THo m1DnVG^c}26w|a}tRLcOSE$kCS{hxDZpv0ho-#ll2^Y+Zcz2#fw>%zCAh=;*3&I64(qRO$uaWK*M)@%A`X5#n7bxRCvTQ~I^9L5bs_zNbt+uv6a&wGOJhW`wA))Rau{2m;i%LLyGkD<8i3H~HJyQ`kyOYjxA zAy4o<@GUs5GQ)4;97~qQ% z^9N0GZ+7Ndl+BZSLGDrU@s4I3FK}zSE7-Y6Zkyaf(YH6Zw#YptH|x)H&1*Ss->1Gd zasA(`#0@zuwLT}ltv=4zmyl`RSl?+pUpdate finished items ///更新完成后的物品 /// - protected virtual void WhenUpdateCurrentItem(Node2D? currentItem) - { - } + protected virtual void WhenUpdateCurrentItem(Node2D? currentItem) { } //Define a pick up range //定义一个拾起范围 @@ -210,8 +210,8 @@ public partial class CharacterTemplate : CharacterBody2D base._Ready(); PickingRangeBodiesList = new List(); CharacterName = GetMeta("Name", Name).AsString(); - CampId = GetMeta("CampId", Config.CampId.Default).AsString(); - MaxHp = GetMeta("MaxHp", Config.DefaultMaxHp).AsInt32(); + CampId = GetMeta("CampId", Config.CampId.Default).AsString(); + MaxHp = GetMeta("MaxHp", Config.DefaultMaxHp).AsInt32(); string lootListId = GetMeta("LootListId", string.Empty).AsString(); if (!string.IsNullOrEmpty(lootListId)) { @@ -219,6 +219,7 @@ public partial class CharacterTemplate : CharacterBody2D //如果指定了战利品表,那么获取战利品表。 _lootList = LootListManager.GetLootList(lootListId); } + if (MaxHp <= 0) { //If Max blood volume is 0 or less, set Max blood volume to 10 @@ -317,7 +318,7 @@ public partial class CharacterTemplate : CharacterBody2D { weaponTemplate.Owner = this; weaponTemplate.SetCollisionMaskValue(Config.LayerNumber.Platform, false); - weaponTemplate.SetCollisionMaskValue(Config.LayerNumber.Ground, false); + weaponTemplate.SetCollisionMaskValue(Config.LayerNumber.Ground, false); weaponTemplate.EnableContactInjury = false; weaponTemplate.Sleeping = true; } @@ -467,9 +468,7 @@ public partial class CharacterTemplate : CharacterBody2D _additionalForce = force; } - protected virtual void OnHit(DamageTemplate damageTemplate) - { - } + protected virtual void OnHit(DamageTemplate damageTemplate) { } /// /// Handle the event of character death @@ -599,22 +598,9 @@ public partial class CharacterTemplate : CharacterBody2D /// protected void ThrowItem(int index, int number, Vector2 velocity) { - if (_itemContainer == null) - { - return; - } + var itemSlotNode = _itemContainer?.GetItemSlotNode(index); - var itemSlotNode = _itemContainer.GetItemSlotNode(index); - if (itemSlotNode == null) - { - return; - } - - var item = itemSlotNode.GetItem(); - if (item == null) - { - return; - } + var item = itemSlotNode?.GetItem(); if (item is not Node2D node2D) { @@ -639,7 +625,7 @@ public partial class CharacterTemplate : CharacterBody2D //We cannot immediately resume the physical collision when the weapon is discharged, which will cause the weapon to collide with the ground and platform earlier, preventing the weapon from flying. //仍出武器时,我们不能立即恢复物理碰撞,立即恢复会导致武器更早的与地面和平台碰撞,阻止武器的飞行。 weaponTemplate.EnableContactInjury = true; - weaponTemplate.SetCollisionMaskValue(Config.LayerNumber.Ground, true); + weaponTemplate.SetCollisionMaskValue(Config.LayerNumber.Ground, true); weaponTemplate.SetCollisionMaskValue(Config.LayerNumber.Platform, true); timer.QueueFree(); }; @@ -669,11 +655,11 @@ public partial class CharacterTemplate : CharacterBody2D //在物品容器内移除物品 if (number < 0) { - itemSlotNode.RemoveItem(item.Quantity); + itemSlotNode!.RemoveItem(item.Quantity); } else { - itemSlotNode.RemoveItem(number); + itemSlotNode!.RemoveItem(number); } } @@ -728,7 +714,5 @@ public partial class CharacterTemplate : CharacterBody2D } - protected virtual void HookPhysicsProcess(ref Vector2 velocity, double delta) - { - } + protected virtual void HookPhysicsProcess(ref Vector2 velocity, double delta) { } } \ No newline at end of file diff --git a/scripts/character/Player.cs b/scripts/character/Player.cs index c91571d..0e234cc 100644 --- a/scripts/character/Player.cs +++ b/scripts/character/Player.cs @@ -1,11 +1,13 @@ using System; using System.Text; using System.Threading.Tasks; + using ColdMint.scripts.damage; using ColdMint.scripts.deathInfo; using ColdMint.scripts.map.events; using ColdMint.scripts.utils; -using ColdMint.scripts.weapon; +using ColdMint.scripts.item.weapon; + using Godot; namespace ColdMint.scripts.character; @@ -101,7 +103,7 @@ public partial class Player : CharacterTemplate operationTipBuilder.Append(Config.OperationTipActionColor); operationTipBuilder.Append(']'); operationTipBuilder.Append( - TranslationServerUtils.Translate(InputMap.ActionGetEvents("ui_down")[0].AsText())); + TranslationServerUtils.Translate(InputMap.ActionGetEvents("ui_down")[0].AsText())); operationTipBuilder.Append("[/color]"); operationTipBuilder.Append(TranslationServerUtils.Translate("jump_down")); } @@ -115,7 +117,7 @@ public partial class Player : CharacterTemplate operationTipBuilder.Append(Config.OperationTipActionColor); operationTipBuilder.Append(']'); operationTipBuilder.Append( - TranslationServerUtils.Translate(InputMap.ActionGetEvents("pick_up")[0].AsText())); + TranslationServerUtils.Translate(InputMap.ActionGetEvents("pick_up")[0].AsText())); operationTipBuilder.Append("[/color]"); operationTipBuilder.Append(TranslationServerUtils.Translate("pick_up")); operationTipLabel.Text = operationTipBuilder.ToString(); @@ -139,7 +141,7 @@ public partial class Player : CharacterTemplate operationTipBuilder.Append(Config.OperationTipActionColor); operationTipBuilder.Append(']'); operationTipBuilder.Append( - TranslationServerUtils.Translate(InputMap.ActionGetEvents("use_item")[0].AsText())); + TranslationServerUtils.Translate(InputMap.ActionGetEvents("use_item")[0].AsText())); operationTipBuilder.Append("[/color]"); operationTipBuilder.Append(TranslationServerUtils.Translate("use_item")); operationTipBuilder.Append(TranslationServerUtils.Translate(weaponTemplate.Name)); @@ -243,8 +245,8 @@ public partial class Player : CharacterTemplate } _parabola.Points = CurrentItem == null - ? _emptyVector2Array - : ParabolicUtils.ComputeParabolic(ItemMarker2D.Position, GetThrowVelocity(), Gravity, 0.1f); + ? _emptyVector2Array + : ParabolicUtils.ComputeParabolic(ItemMarker2D.Position, GetThrowVelocity(), Gravity, 0.1f); } @@ -400,8 +402,8 @@ public partial class Player : CharacterTemplate var rotationDegreesNode2D = node2D.RotationDegrees; var rotationDegreesNode2DAbs = Math.Abs(rotationDegreesNode2D); _floatLabel.Position = rotationDegreesNode2DAbs > 90 - ? new Vector2(0, PromptTextDistance) - : new Vector2(0, -PromptTextDistance); + ? new Vector2(0, PromptTextDistance) + : new Vector2(0, -PromptTextDistance); _floatLabel.RotationDegrees = 0 - rotationDegreesNode2D; var label = _floatLabel.GetNode public static IItem_New? NewItem(string id) => - Registry.TryGetValue(id, out var itemType) ? itemType.Getter() : null; + Registry.TryGetValue(id, out var itemType) ? itemType.NewItemFunc() : null; /// /// Get the translated default name of the item type for the given id @@ -54,6 +54,9 @@ public static class ItemTypeManager /// public static Texture2D DefaultIconOf(string id) => Registry.TryGetValue(id, out var itemType) - ? itemType.Texture ?? DefaultTexture + ? itemType.Icon ?? DefaultTexture : DefaultTexture; + + public static int MaxStackQuantityOf(string id) => Registry.TryGetValue(id, out var itemType) ? itemType.MaxStackQuantity : 0; + public static StackType? StackTypeOf(string id) => Registry.TryGetValue(id, out var itemType) ? itemType.StackType : null; } \ No newline at end of file diff --git a/scripts/item/SingleItemStack.cs b/scripts/item/SingleItemStack.cs new file mode 100644 index 0000000..b853990 --- /dev/null +++ b/scripts/item/SingleItemStack.cs @@ -0,0 +1,21 @@ +using ColdMint.scripts.inventory; + +using Godot; + +namespace ColdMint.scripts.item; + +/// +/// Item stack in inventory +/// +//maybe we'd move this into inventory namespace +public readonly struct SingleItemStack(IItem_New item) : IItemStack +{ + public IItem_New Item { get; init; } = item; + + public string Id => Item.Id; + public int MaxQuantity => 1; + public int Quantity => 1; + public Texture2D Icon => Item.Icon; + public string Name => Item.Name; + public string? Description => Item.Description; +} \ No newline at end of file diff --git a/scripts/item/StackType.cs b/scripts/item/StackType.cs new file mode 100644 index 0000000..85998ba --- /dev/null +++ b/scripts/item/StackType.cs @@ -0,0 +1,8 @@ +namespace ColdMint.scripts.item; + +public enum StackType +{ + Common, + Unique, + Unstackable, +} \ No newline at end of file diff --git a/scripts/weapon/ProjectileWeapon.cs b/scripts/item/weapon/ProjectileWeapon.cs similarity index 98% rename from scripts/weapon/ProjectileWeapon.cs rename to scripts/item/weapon/ProjectileWeapon.cs index 71ea042..a66de38 100644 --- a/scripts/weapon/ProjectileWeapon.cs +++ b/scripts/item/weapon/ProjectileWeapon.cs @@ -1,9 +1,11 @@ using System.Collections.Generic; + using ColdMint.scripts.debug; using ColdMint.scripts.projectile; + using Godot; -namespace ColdMint.scripts.weapon; +namespace ColdMint.scripts.item.weapon; /// /// Projectile weapons diff --git a/scripts/weapon/WeaponTemplate.cs b/scripts/item/weapon/WeaponTemplate.cs similarity index 99% rename from scripts/weapon/WeaponTemplate.cs rename to scripts/item/weapon/WeaponTemplate.cs index c3c27be..bf4611f 100644 --- a/scripts/weapon/WeaponTemplate.cs +++ b/scripts/item/weapon/WeaponTemplate.cs @@ -1,11 +1,13 @@ using System; + using ColdMint.scripts.camp; using ColdMint.scripts.character; using ColdMint.scripts.damage; using ColdMint.scripts.inventory; + using Godot; -namespace ColdMint.scripts.weapon; +namespace ColdMint.scripts.item.weapon; /// /// WeaponTemplate