Fixed item ID and its container being lost when throwing items. Pick up the weapon again can not fire the bullet issue.

修复扔出物品时,物品的ID与自身的物品容器丢失。再次捡起武器无法发射子弹的问题。
This commit is contained in:
Cold-Mint 2024-10-05 10:20:55 +08:00
parent b7805c5804
commit e718d78137
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
5 changed files with 33 additions and 23 deletions

View File

@ -4,11 +4,9 @@
[ext_resource type="AudioStream" uid="uid://cak6chjjsu7wo" path="res://sounds/fire.wav" id="4_ffr2k"] [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"] [ext_resource type="Texture2D" uid="uid://bbcjkyrsx88av" path="res://sprites/projectile/curseOfTheUndead.png" id="4_y6nkf"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_obcq2"] [sub_resource type="CircleShape2D" id="CircleShape2D_qgdry"]
size = Vector2(20, 21)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_14m1g"] [sub_resource type="CircleShape2D" id="CircleShape2D_akp3k"]
size = Vector2(20, 20.75)
[node name="curseOfTheUndead" type="RigidBody2D"] [node name="curseOfTheUndead" type="RigidBody2D"]
collision_layer = 8 collision_layer = 8
@ -23,11 +21,11 @@ collision_mask = 102
[node name="CollisionShape2D" type="CollisionShape2D" parent="DamageArea2D"] [node name="CollisionShape2D" type="CollisionShape2D" parent="DamageArea2D"]
position = Vector2(0, -0.5) position = Vector2(0, -0.5)
shape = SubResource("RectangleShape2D_obcq2") shape = SubResource("CircleShape2D_qgdry")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, -0.625) position = Vector2(0, -0.625)
shape = SubResource("RectangleShape2D_14m1g") shape = SubResource("CircleShape2D_akp3k")
[node name="Marker2D" type="Marker2D" parent="."] [node name="Marker2D" type="Marker2D" parent="."]
position = Vector2(65, 0) position = Vector2(65, 0)

View File

@ -9,6 +9,7 @@ using ColdMint.scripts.inventory;
using ColdMint.scripts.utils; using ColdMint.scripts.utils;
using ColdMint.scripts.loot; using ColdMint.scripts.loot;
using ColdMint.scripts.pickable; using ColdMint.scripts.pickable;
using ColdMint.scripts.weapon;
using Godot; using Godot;
using WeaponTemplate = ColdMint.scripts.weapon.WeaponTemplate; using WeaponTemplate = ColdMint.scripts.weapon.WeaponTemplate;
@ -445,6 +446,10 @@ public partial class CharacterTemplate : CharacterBody2D
pickAbleTemplate.Sleeping = true; pickAbleTemplate.Sleeping = true;
} }
if (pickAbleItemNode2D is ProjectileWeapon projectileWeapon)
{
projectileWeapon.UpdateSpellCache();
}
if (_currentItem == null && ItemContainer.GetSelectItem() == item) if (_currentItem == null && ItemContainer.GetSelectItem() == item)
{ {

View File

@ -44,15 +44,6 @@ public partial class Packsack : PickAbleTemplate
GameSceneDepend.DynamicUiGroup?.HideControl(Path); 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() public override void _Ready()
{ {

View File

@ -342,14 +342,14 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
/// <para>Please copy node properties within this function</para> /// <para>Please copy node properties within this function</para>
/// <para>请在此函数内复制节点属性</para> /// <para>请在此函数内复制节点属性</para>
/// </summary> /// </summary>
/// <param name="node"></param> /// <param name="originalNode"></param>
public virtual void CopyAttributes(Node node) public void CopyAttributes(Node originalNode)
{ {
if (node is not PickAbleTemplate pickAbleTemplate) if (originalNode is not PickAbleTemplate originalPickAbleTemplate)
{ {
return; return;
} }
Id = originalPickAbleTemplate.Id;
pickAbleTemplate.Id = Id; SelfItemContainer = originalPickAbleTemplate.SelfItemContainer;
} }
} }

View File

@ -113,11 +113,22 @@ public partial class ProjectileWeapon : WeaponTemplate
{ {
base._Ready(); base._Ready();
_marker2D = GetNode<Marker2D>("Marker2D"); _marker2D = GetNode<Marker2D>("Marker2D");
SelfItemContainer = new UniversalItemContainer(_numberSlots); if (SelfItemContainer == null)
SelfItemContainer.AllowAddingItemByType(Config.ItemType.Spell); {
SelfItemContainer = new UniversalItemContainer(_numberSlots);
SelfItemContainer.AllowAddingItemByType(Config.ItemType.Spell);
}
} }
private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent) /// <summary>
/// <para>Update spell cache</para>
/// <para>更新法术缓存</para>
/// </summary>
/// <remarks>
///<para>This will parse available spells from inside the item container.</para>
///<para>这将从物品容器内解析可用的法术。</para>
/// </remarks>
public void UpdateSpellCache()
{ {
if (SelfItemContainer == null) if (SelfItemContainer == null)
{ {
@ -148,6 +159,11 @@ public partial class ProjectileWeapon : WeaponTemplate
} }
} }
private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent)
{
UpdateSpellCache();
}
public override void _EnterTree() public override void _EnterTree()
{ {
base._EnterTree(); base._EnterTree();