From e718d781372d72326d1deb940be24196a7c81828 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Sat, 5 Oct 2024 10:20:55 +0800 Subject: [PATCH] =?UTF-8?q?Fixed=20item=20ID=20and=20its=20container=20bei?= =?UTF-8?q?ng=20lost=20when=20throwing=20items.=20Pick=20up=20the=20weapon?= =?UTF-8?q?=20again=20can=20not=20fire=20the=20bullet=20issue.=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=89=94=E5=87=BA=E7=89=A9=E5=93=81=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=89=A9=E5=93=81=E7=9A=84ID=E4=B8=8E=E8=87=AA=E8=BA=AB?= =?UTF-8?q?=E7=9A=84=E7=89=A9=E5=93=81=E5=AE=B9=E5=99=A8=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E3=80=82=E5=86=8D=E6=AC=A1=E6=8D=A1=E8=B5=B7=E6=AD=A6=E5=99=A8?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=8F=91=E5=B0=84=E5=AD=90=E5=BC=B9=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prefab/magics/curseOfTheUndead.tscn | 10 ++++------ scripts/character/CharacterTemplate.cs | 5 +++++ scripts/inventory/Packsack.cs | 9 --------- scripts/pickable/PickAbleTemplate.cs | 10 +++++----- scripts/weapon/ProjectileWeapon.cs | 22 +++++++++++++++++++--- 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/prefab/magics/curseOfTheUndead.tscn b/prefab/magics/curseOfTheUndead.tscn index f25cbde..6bd1640 100644 --- a/prefab/magics/curseOfTheUndead.tscn +++ b/prefab/magics/curseOfTheUndead.tscn @@ -4,11 +4,9 @@ [ext_resource type="AudioStream" uid="uid://cak6chjjsu7wo" path="res://sounds/fire.wav" id="4_ffr2k"] [ext_resource type="Texture2D" uid="uid://bbcjkyrsx88av" path="res://sprites/projectile/curseOfTheUndead.png" id="4_y6nkf"] -[sub_resource type="RectangleShape2D" id="RectangleShape2D_obcq2"] -size = Vector2(20, 21) +[sub_resource type="CircleShape2D" id="CircleShape2D_qgdry"] -[sub_resource type="RectangleShape2D" id="RectangleShape2D_14m1g"] -size = Vector2(20, 20.75) +[sub_resource type="CircleShape2D" id="CircleShape2D_akp3k"] [node name="curseOfTheUndead" type="RigidBody2D"] collision_layer = 8 @@ -23,11 +21,11 @@ collision_mask = 102 [node name="CollisionShape2D" type="CollisionShape2D" parent="DamageArea2D"] position = Vector2(0, -0.5) -shape = SubResource("RectangleShape2D_obcq2") +shape = SubResource("CircleShape2D_qgdry") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, -0.625) -shape = SubResource("RectangleShape2D_14m1g") +shape = SubResource("CircleShape2D_akp3k") [node name="Marker2D" type="Marker2D" parent="."] position = Vector2(65, 0) diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs index 5258480..b64987b 100644 --- a/scripts/character/CharacterTemplate.cs +++ b/scripts/character/CharacterTemplate.cs @@ -9,6 +9,7 @@ using ColdMint.scripts.inventory; using ColdMint.scripts.utils; using ColdMint.scripts.loot; using ColdMint.scripts.pickable; +using ColdMint.scripts.weapon; using Godot; using WeaponTemplate = ColdMint.scripts.weapon.WeaponTemplate; @@ -445,6 +446,10 @@ public partial class CharacterTemplate : CharacterBody2D pickAbleTemplate.Sleeping = true; } + if (pickAbleItemNode2D is ProjectileWeapon projectileWeapon) + { + projectileWeapon.UpdateSpellCache(); + } if (_currentItem == null && ItemContainer.GetSelectItem() == item) { diff --git a/scripts/inventory/Packsack.cs b/scripts/inventory/Packsack.cs index bfaf81d..88e7a9c 100644 --- a/scripts/inventory/Packsack.cs +++ b/scripts/inventory/Packsack.cs @@ -44,15 +44,6 @@ public partial class Packsack : PickAbleTemplate GameSceneDepend.DynamicUiGroup?.HideControl(Path); } - public override void CopyAttributes(Node node) - { - base.CopyAttributes(node); - if (node is Packsack packsack) - { - SelfItemContainer = packsack.SelfItemContainer; - } - } - public override void _Ready() { diff --git a/scripts/pickable/PickAbleTemplate.cs b/scripts/pickable/PickAbleTemplate.cs index 59e0dca..906c079 100644 --- a/scripts/pickable/PickAbleTemplate.cs +++ b/scripts/pickable/PickAbleTemplate.cs @@ -342,14 +342,14 @@ public partial class PickAbleTemplate : RigidBody2D, IItem /// Please copy node properties within this function /// 请在此函数内复制节点属性 /// - /// - public virtual void CopyAttributes(Node node) + /// + public void CopyAttributes(Node originalNode) { - if (node is not PickAbleTemplate pickAbleTemplate) + if (originalNode is not PickAbleTemplate originalPickAbleTemplate) { return; } - - pickAbleTemplate.Id = Id; + Id = originalPickAbleTemplate.Id; + SelfItemContainer = originalPickAbleTemplate.SelfItemContainer; } } \ No newline at end of file diff --git a/scripts/weapon/ProjectileWeapon.cs b/scripts/weapon/ProjectileWeapon.cs index aa45472..fe73fd0 100644 --- a/scripts/weapon/ProjectileWeapon.cs +++ b/scripts/weapon/ProjectileWeapon.cs @@ -113,11 +113,22 @@ public partial class ProjectileWeapon : WeaponTemplate { base._Ready(); _marker2D = GetNode("Marker2D"); - SelfItemContainer = new UniversalItemContainer(_numberSlots); - SelfItemContainer.AllowAddingItemByType(Config.ItemType.Spell); + if (SelfItemContainer == null) + { + SelfItemContainer = new UniversalItemContainer(_numberSlots); + SelfItemContainer.AllowAddingItemByType(Config.ItemType.Spell); + } } - private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent) + /// + /// Update spell cache + /// 更新法术缓存 + /// + /// + ///This will parse available spells from inside the item container. + ///这将从物品容器内解析可用的法术。 + /// + public void UpdateSpellCache() { if (SelfItemContainer == null) { @@ -148,6 +159,11 @@ public partial class ProjectileWeapon : WeaponTemplate } } + private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent) + { + UpdateSpellCache(); + } + public override void _EnterTree() { base._EnterTree();