Fixed an issue where Ai characters could not attack with weapons.

修复Ai角色使用武器无法攻击的问题。
This commit is contained in:
Cold-Mint 2024-10-09 16:51:03 +08:00
parent 3695a7ef11
commit 5b5a9ae198
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
4 changed files with 25 additions and 10 deletions

View File

@ -20,6 +20,12 @@ public interface ISpell
/// <returns></returns>
PackedScene? GetProjectile();
/// <summary>
/// <para>LoadResource</para>
/// <para>加载资源</para>
/// </summary>
void LoadResource();
/// <summary>
/// <para>Modify Weapon</para>
/// <para>修改武器</para>

View File

@ -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
{

View File

@ -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<PackedScene>(_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<PackedScene>(_projectilePath);
}
}
public virtual void ModifyWeapon(ProjectileWeapon projectileWeapon)
{

View File

@ -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();
}
}