Fixed an issue where AI could not pick up weapons.
修复AI不能捡起武器的问题。
This commit is contained in:
parent
4e83bca579
commit
4a4d4a0c37
|
@ -15,7 +15,6 @@ _maxDamage = 10
|
||||||
_minDamage = 1
|
_minDamage = 1
|
||||||
_damageType = 2
|
_damageType = 2
|
||||||
Speed = 500.0
|
Speed = 500.0
|
||||||
_enableTracking = true
|
|
||||||
_targetDiesDestroyProjectile = true
|
_targetDiesDestroyProjectile = true
|
||||||
_repelStrength = 2.5
|
_repelStrength = 2.5
|
||||||
|
|
||||||
|
|
|
@ -180,6 +180,7 @@ public sealed partial class AiCharacter : CharacterTemplate
|
||||||
//You must create an item container for the character before you can pick up the item.
|
//You must create an item container for the character before you can pick up the item.
|
||||||
//必须为角色创建物品容器后才能拾起物品。
|
//必须为角色创建物品容器后才能拾起物品。
|
||||||
var universalItemContainer = new UniversalItemContainer(1);
|
var universalItemContainer = new UniversalItemContainer(1);
|
||||||
|
universalItemContainer.AllowAddingItemByType(Config.ItemType.ProjectileWeapon);
|
||||||
ProtectedItemContainer = universalItemContainer;
|
ProtectedItemContainer = universalItemContainer;
|
||||||
//Add initial weapon
|
//Add initial weapon
|
||||||
//添加初始武器
|
//添加初始武器
|
||||||
|
|
|
@ -481,10 +481,10 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
|
|
||||||
if (_currentItem is IItem item)
|
if (_currentItem is IItem item)
|
||||||
{
|
{
|
||||||
item.Use(this, position);
|
return item.Use(this, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
|
|
|
@ -126,7 +126,11 @@ public interface IItem
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="owner">Owner of current item, if any</param>
|
/// <param name="owner">Owner of current item, if any</param>
|
||||||
/// <param name="targetGlobalPosition">Target position, such as the position of the cursor when used by the player</param>
|
/// <param name="targetGlobalPosition">Target position, such as the position of the cursor when used by the player</param>
|
||||||
void Use(Node2D? owner, Vector2 targetGlobalPosition);
|
/// <returns>
|
||||||
|
///<para>Whether it was successfully executed</para>
|
||||||
|
///<para>是否成功被执行了</para>
|
||||||
|
/// </returns>
|
||||||
|
bool Use(Node2D? owner, Vector2 targetGlobalPosition);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>When the item is thrown</para>
|
/// <para>When the item is thrown</para>
|
||||||
|
|
|
@ -18,9 +18,13 @@ public partial class Packsack : PickAbleTemplate
|
||||||
get => Config.ItemType.Packsack;
|
get => Config.ItemType.Packsack;
|
||||||
}
|
}
|
||||||
[Export] public int NumberSlots { get; set; }
|
[Export] public int NumberSlots { get; set; }
|
||||||
public override void Use(Node2D? owner, Vector2 targetGlobalPosition)
|
public override bool Use(Node2D? owner, Vector2 targetGlobalPosition)
|
||||||
{
|
{
|
||||||
GameSceneDepend.DynamicUiGroup?.ShowControl(Path, control =>
|
if (GameSceneDepend.DynamicUiGroup == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return GameSceneDepend.DynamicUiGroup.ShowControl(Path, control =>
|
||||||
{
|
{
|
||||||
if (control is PacksackUi packsackUi)
|
if (control is PacksackUi packsackUi)
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,8 +50,9 @@ public class PlaceholderItem : IItem
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Use(Node2D? owner, Vector2 targetGlobalPosition)
|
public bool Use(Node2D? owner, Vector2 targetGlobalPosition)
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnThrow(Vector2 velocity)
|
public void OnThrow(Vector2 velocity)
|
||||||
|
|
|
@ -182,8 +182,9 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
|
||||||
return Math.Min(freeQuantity, unallocatedQuantity);
|
return Math.Min(freeQuantity, unallocatedQuantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Use(Node2D? owner, Vector2 targetGlobalPosition)
|
public virtual bool Use(Node2D? owner, Vector2 targetGlobalPosition)
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void OnThrow(Vector2 velocity)
|
public virtual void OnThrow(Vector2 velocity)
|
||||||
|
|
|
@ -25,9 +25,9 @@ public abstract partial class WeaponTemplate : PickAbleTemplate
|
||||||
_audioStreamPlayer2D = GetNodeOrNull<AudioStreamPlayer2D>("Marker2D/AudioStreamPlayer2D");
|
_audioStreamPlayer2D = GetNodeOrNull<AudioStreamPlayer2D>("Marker2D/AudioStreamPlayer2D");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Use(Node2D? owner, Vector2 targetGlobalPosition)
|
public override bool Use(Node2D? owner, Vector2 targetGlobalPosition)
|
||||||
{
|
{
|
||||||
Fire(owner, targetGlobalPosition);
|
return Fire(owner, targetGlobalPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,15 +77,16 @@ public abstract partial class WeaponTemplate : PickAbleTemplate
|
||||||
///<para>敌人所在位置</para>
|
///<para>敌人所在位置</para>
|
||||||
/// </param>
|
/// </param>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public void Fire(Node2D? owner, Vector2 enemyGlobalPosition)
|
public bool Fire(Node2D? owner, Vector2 enemyGlobalPosition)
|
||||||
{
|
{
|
||||||
var nowTime = DateTime.Now;
|
var nowTime = DateTime.Now;
|
||||||
//If the present time minus the time of the last fire is less than the interval between fires, it means that the fire cannot be fired yet.
|
//If the present time minus the time of the last fire is less than the interval between fires, it means that the fire cannot be fired yet.
|
||||||
//如果现在时间减去上次开火时间小于开火间隔,说明还不能开火。
|
//如果现在时间减去上次开火时间小于开火间隔,说明还不能开火。
|
||||||
if (_lastFiringTime != null && nowTime - _lastFiringTime < _firingInterval)
|
if (_lastFiringTime != null && nowTime - _lastFiringTime < _firingInterval)
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
_lastFiringTime = nowTime;
|
||||||
var result = DoFire(owner, enemyGlobalPosition);
|
var result = DoFire(owner, enemyGlobalPosition);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
|
@ -96,10 +97,9 @@ public abstract partial class WeaponTemplate : PickAbleTemplate
|
||||||
characterTemplate.AddForce(enemyGlobalPosition.DirectionTo(characterTemplate.GlobalPosition) * _recoilStrength * Config.CellSize);
|
characterTemplate.AddForce(enemyGlobalPosition.DirectionTo(characterTemplate.GlobalPosition) * _recoilStrength * Config.CellSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_audioStreamPlayer2D?.Play();
|
_audioStreamPlayer2D?.Play();
|
||||||
}
|
}
|
||||||
_lastFiringTime = nowTime;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user