Fixed an issue where Ai characters could not attack with weapons.
修复Ai角色使用武器无法攻击的问题。
This commit is contained in:
parent
3695a7ef11
commit
5b5a9ae198
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user