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>
|
||||
|
@ -50,6 +56,6 @@ public interface ISpell
|
|||
///<para>The velocity of the projectile</para>
|
||||
///<para>抛射体的飞行速度</para>
|
||||
/// </param>
|
||||
void ModifyProjectile(int index,Projectile projectile, ref Vector2 velocity);
|
||||
void ModifyProjectile(int index, Projectile projectile, ref Vector2 velocity);
|
||||
|
||||
}
|
|
@ -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