diff --git a/prefab/roomTemplates/dungeon/chest.tscn b/prefab/roomTemplates/dungeon/chest.tscn index 2206510..4840a71 100644 --- a/prefab/roomTemplates/dungeon/chest.tscn +++ b/prefab/roomTemplates/dungeon/chest.tscn @@ -55,6 +55,7 @@ shape = SubResource("RectangleShape2D_7tsse") [node name="Marker2D" type="Marker2D" parent="."] position = Vector2(260, 87) script = ExtResource("1_y2vgj") +_resPathArray = null [node name="NavigationRegion2D" type="NavigationRegion2D" parent="."] navigation_polygon = SubResource("NavigationPolygon_rh1gx") diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs index 0af663b..be12d1e 100644 --- a/scripts/character/CharacterTemplate.cs +++ b/scripts/character/CharacterTemplate.cs @@ -432,7 +432,7 @@ public partial class CharacterTemplate : CharacterBody2D //您可以在这里补充更多类型对象的捡起状态处理。 if (pickAbleItemNode2D is PickAbleTemplate pickAbleTemplate) { - pickAbleTemplate.LoadingResource(); + pickAbleTemplate.LoadResource(); pickAbleTemplate.Owner = this; pickAbleTemplate.Picked = true; pickAbleTemplate.Freeze = true; @@ -797,7 +797,7 @@ public partial class CharacterTemplate : CharacterBody2D { return; } - pickAbleTemplate.LoadingResource(); + pickAbleTemplate.LoadResource(); pickAbleTemplate.Owner = this; pickAbleTemplate.Picked = false; //Setting an initial speed of 0 for items here prevents the problem of throwing items too fast. diff --git a/scripts/inventory/Packsack.cs b/scripts/inventory/Packsack.cs index 9d8d870..df6bc13 100644 --- a/scripts/inventory/Packsack.cs +++ b/scripts/inventory/Packsack.cs @@ -49,9 +49,9 @@ public partial class Packsack : PickAbleTemplate } - public override void _Ready() + public override void LoadResource() { - base._Ready(); + base.LoadResource(); if (SelfItemContainer == null) { var universalItemContainer = new UniversalItemContainer(NumberSlots); diff --git a/scripts/inventory/ResignationCertificate.cs b/scripts/inventory/ResignationCertificate.cs index 67c7c64..7c2ad5e 100644 --- a/scripts/inventory/ResignationCertificate.cs +++ b/scripts/inventory/ResignationCertificate.cs @@ -18,9 +18,9 @@ public partial class ResignationCertificate : WeaponTemplate Type = Config.DamageType.Magic }; - public override void _Ready() + public override void LoadResource() { - base._Ready(); + base.LoadResource(); _damage.CreateDamage(); _damage.Attacker = this; } diff --git a/scripts/pickable/PickAbleTemplate.cs b/scripts/pickable/PickAbleTemplate.cs index 1747e77..6b28f33 100644 --- a/scripts/pickable/PickAbleTemplate.cs +++ b/scripts/pickable/PickAbleTemplate.cs @@ -1,8 +1,4 @@ using System; -using ColdMint.scripts.camp; -using ColdMint.scripts.character; -using ColdMint.scripts.damage; -using ColdMint.scripts.debug; using ColdMint.scripts.inventory; using ColdMint.scripts.utils; using Godot; @@ -172,20 +168,20 @@ public partial class PickAbleTemplate : RigidBody2D, IItem } private CollisionShape2D? _collisionShape2D; - - + /// /// Whether the resource has been loaded /// 是否已加载过资源了 /// private bool _loadedResource; - public override void _Ready() + public sealed override void _Ready() { - LoadingResource(); + LoadResource(); } + - public void LoadingResource() + public virtual void LoadResource() { if (_loadedResource) { diff --git a/scripts/spell/SpellPickAble.cs b/scripts/spell/SpellPickAble.cs index 555149c..9f4a4e2 100644 --- a/scripts/spell/SpellPickAble.cs +++ b/scripts/spell/SpellPickAble.cs @@ -19,11 +19,6 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell private string? _projectilePath; private PackedScene? _projectileScene; - public sealed override void _Ready() - { - base._Ready(); - LoadResource(); - } public override int ItemType { @@ -35,14 +30,17 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell return _projectileScene; } - public virtual void LoadResource() + + + public override void LoadResource() { + base.LoadResource(); if (_projectileScene == null && !string.IsNullOrEmpty(_projectilePath)) { _projectileScene = ResourceLoader.Load(_projectilePath); } } - + public virtual void ModifyWeapon(ProjectileWeapon projectileWeapon) { diff --git a/scripts/weapon/MeleeWeapon.cs b/scripts/weapon/MeleeWeapon.cs index 54f7508..a395cfc 100644 --- a/scripts/weapon/MeleeWeapon.cs +++ b/scripts/weapon/MeleeWeapon.cs @@ -28,10 +28,10 @@ public partial class MeleeWeapon : WeaponTemplate private readonly List _characterTemplates = [ ]; - public override void _Ready() + + public override void LoadResource() { - base._Ready(); - LogCat.Log("ready", LogCat.LogLabel.MeleeWeapon); + base.LoadResource(); _weaponDamageArea = GetNode("WeaponDamageArea"); _weaponDamageArea.InputPickable = false; _weaponDamageArea.SetCollisionMaskValue(Config.LayerNumber.Player, true); @@ -45,7 +45,6 @@ public partial class MeleeWeapon : WeaponTemplate _damageTemplate.MaxDamage = _maxDamage; _damageTemplate.MinDamage = _minDamage; _damageTemplate.Type = Config.DamageType.Physical; - LogCat.Log("success", LogCat.LogLabel.MeleeWeapon); } private void AreaExited(Node2D node2D) diff --git a/scripts/weapon/ProjectileWeapon.cs b/scripts/weapon/ProjectileWeapon.cs index f6a347f..0256643 100644 --- a/scripts/weapon/ProjectileWeapon.cs +++ b/scripts/weapon/ProjectileWeapon.cs @@ -122,9 +122,9 @@ public partial class ProjectileWeapon : WeaponTemplate get => Config.ItemType.ProjectileWeapon; } - public override void _Ready() + public override void LoadResource() { - base._Ready(); + base.LoadResource(); _marker2D = GetNode("Marker2D"); if (SelfItemContainer == null) { @@ -144,6 +144,8 @@ public partial class ProjectileWeapon : WeaponTemplate { continue; } + //The spell is stored in memory and has not yet been loaded into the node tree. So we call the InvokeLoadResource method to initialize the resource. + //法术保存在内存中,尚未加载到节点树。所以我们调用InvokeLoadResource方法来初始化资源。 spell.LoadResource(); if (SelfItemContainer.CanAddItem(item)) { diff --git a/scripts/weapon/WeaponTemplate.cs b/scripts/weapon/WeaponTemplate.cs index a45a591..0843e65 100644 --- a/scripts/weapon/WeaponTemplate.cs +++ b/scripts/weapon/WeaponTemplate.cs @@ -19,10 +19,10 @@ public abstract partial class WeaponTemplate : PickAbleTemplate /// private AudioStreamPlayer2D? _audioStreamPlayer2D; - public override void _Ready() + public override void LoadResource() { - base._Ready(); - _audioStreamPlayer2D = GetNodeOrNull("Marker2D/AudioStreamPlayer2D"); + base.LoadResource(); + _audioStreamPlayer2D = GetNode("Marker2D/AudioStreamPlayer2D"); } public override bool Use(Node2D? owner, Vector2 targetGlobalPosition)