From 5b5a9ae1986d7d81fb6a1e8aeb05e418ef2d1969 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Wed, 9 Oct 2024 16:51:03 +0800 Subject: [PATCH] =?UTF-8?q?Fixed=20an=20issue=20where=20Ai=20characters=20?= =?UTF-8?q?could=20not=20attack=20with=20weapons.=20=E4=BF=AE=E5=A4=8DAi?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E4=BD=BF=E7=94=A8=E6=AD=A6=E5=99=A8=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=94=BB=E5=87=BB=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/projectile/ISpell.cs | 8 +++++++- scripts/spell/NodeSpawnOnKillCharacterSpell.cs | 7 ++++--- scripts/spell/SpellPickAble.cs | 16 +++++++++++----- scripts/weapon/ProjectileWeapon.cs | 4 +++- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/scripts/projectile/ISpell.cs b/scripts/projectile/ISpell.cs index dc00581..516b5cd 100644 --- a/scripts/projectile/ISpell.cs +++ b/scripts/projectile/ISpell.cs @@ -20,6 +20,12 @@ public interface ISpell /// PackedScene? GetProjectile(); + /// + /// LoadResource + /// 加载资源 + /// + void LoadResource(); + /// /// Modify Weapon /// 修改武器 @@ -50,6 +56,6 @@ public interface ISpell ///The velocity of the projectile ///抛射体的飞行速度 /// - void ModifyProjectile(int index,Projectile projectile, ref Vector2 velocity); + void ModifyProjectile(int index, Projectile projectile, ref Vector2 velocity); } \ No newline at end of file diff --git a/scripts/spell/NodeSpawnOnKillCharacterSpell.cs b/scripts/spell/NodeSpawnOnKillCharacterSpell.cs index 91ffd0f..ce83add 100644 --- a/scripts/spell/NodeSpawnOnKillCharacterSpell.cs +++ b/scripts/spell/NodeSpawnOnKillCharacterSpell.cs @@ -13,10 +13,11 @@ public partial class NodeSpawnOnKillCharacterSpell : SpellPickAble [Export] private string? _packedScenePath; private NodeSpawnOnKillCharacterDecorator? _nodeSpawnOnKillCharacterDecorator; - public override void _Ready() + + public override void LoadResource() { - base._Ready(); - if (!string.IsNullOrEmpty(_packedScenePath)) + base.LoadResource(); + if (_nodeSpawnOnKillCharacterDecorator == null && !string.IsNullOrEmpty(_packedScenePath)) { _nodeSpawnOnKillCharacterDecorator = new NodeSpawnOnKillCharacterDecorator { diff --git a/scripts/spell/SpellPickAble.cs b/scripts/spell/SpellPickAble.cs index 1c7d4ec..5c29345 100644 --- a/scripts/spell/SpellPickAble.cs +++ b/scripts/spell/SpellPickAble.cs @@ -29,13 +29,10 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell } private PackedScene? _projectileScene; - public override void _Ready() + public sealed override void _Ready() { base._Ready(); - if (!string.IsNullOrEmpty(_projectilePath)) - { - _projectileScene = ResourceLoader.Load(_projectilePath); - } + LoadResource(); } public override int ItemType @@ -48,6 +45,15 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell return _projectileScene; } + public virtual void LoadResource() + { + if (_projectileScene == null && !string.IsNullOrEmpty(_projectilePath)) + { + _projectileScene = ResourceLoader.Load(_projectilePath); + } + } + + public virtual void ModifyWeapon(ProjectileWeapon projectileWeapon) { diff --git a/scripts/weapon/ProjectileWeapon.cs b/scripts/weapon/ProjectileWeapon.cs index 6766a1a..f6a347f 100644 --- a/scripts/weapon/ProjectileWeapon.cs +++ b/scripts/weapon/ProjectileWeapon.cs @@ -140,15 +140,17 @@ public partial class ProjectileWeapon : WeaponTemplate continue; } var item = ItemTypeManager.CreateItem(spellId, this); - if (item == null) + if (item is not ISpell spell) { continue; } + spell.LoadResource(); if (SelfItemContainer.CanAddItem(item)) { SelfItemContainer.AddItem(item); } } + UpdateSpellCache(); } }