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> /// <returns></returns>
PackedScene? GetProjectile(); PackedScene? GetProjectile();
/// <summary>
/// <para>LoadResource</para>
/// <para>加载资源</para>
/// </summary>
void LoadResource();
/// <summary> /// <summary>
/// <para>Modify Weapon</para> /// <para>Modify Weapon</para>
/// <para>修改武器</para> /// <para>修改武器</para>
@ -50,6 +56,6 @@ public interface ISpell
///<para>The velocity of the projectile</para> ///<para>The velocity of the projectile</para>
///<para>抛射体的飞行速度</para> ///<para>抛射体的飞行速度</para>
/// </param> /// </param>
void ModifyProjectile(int index,Projectile projectile, ref Vector2 velocity); void ModifyProjectile(int index, Projectile projectile, ref Vector2 velocity);
} }

View File

@ -13,10 +13,11 @@ public partial class NodeSpawnOnKillCharacterSpell : SpellPickAble
[Export] [Export]
private string? _packedScenePath; private string? _packedScenePath;
private NodeSpawnOnKillCharacterDecorator? _nodeSpawnOnKillCharacterDecorator; private NodeSpawnOnKillCharacterDecorator? _nodeSpawnOnKillCharacterDecorator;
public override void _Ready()
public override void LoadResource()
{ {
base._Ready(); base.LoadResource();
if (!string.IsNullOrEmpty(_packedScenePath)) if (_nodeSpawnOnKillCharacterDecorator == null && !string.IsNullOrEmpty(_packedScenePath))
{ {
_nodeSpawnOnKillCharacterDecorator = new NodeSpawnOnKillCharacterDecorator _nodeSpawnOnKillCharacterDecorator = new NodeSpawnOnKillCharacterDecorator
{ {

View File

@ -29,13 +29,10 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell
} }
private PackedScene? _projectileScene; private PackedScene? _projectileScene;
public override void _Ready() public sealed override void _Ready()
{ {
base._Ready(); base._Ready();
if (!string.IsNullOrEmpty(_projectilePath)) LoadResource();
{
_projectileScene = ResourceLoader.Load<PackedScene>(_projectilePath);
}
} }
public override int ItemType public override int ItemType
@ -48,6 +45,15 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell
return _projectileScene; return _projectileScene;
} }
public virtual void LoadResource()
{
if (_projectileScene == null && !string.IsNullOrEmpty(_projectilePath))
{
_projectileScene = ResourceLoader.Load<PackedScene>(_projectilePath);
}
}
public virtual void ModifyWeapon(ProjectileWeapon projectileWeapon) public virtual void ModifyWeapon(ProjectileWeapon projectileWeapon)
{ {

View File

@ -140,15 +140,17 @@ public partial class ProjectileWeapon : WeaponTemplate
continue; continue;
} }
var item = ItemTypeManager.CreateItem(spellId, this); var item = ItemTypeManager.CreateItem(spellId, this);
if (item == null) if (item is not ISpell spell)
{ {
continue; continue;
} }
spell.LoadResource();
if (SelfItemContainer.CanAddItem(item)) if (SelfItemContainer.CanAddItem(item))
{ {
SelfItemContainer.AddItem(item); SelfItemContainer.AddItem(item);
} }
} }
UpdateSpellCache();
} }
} }