调整拾捡逻辑。

This commit is contained in:
Cold-Mint 2024-07-17 21:53:03 +08:00
parent e895e086cb
commit cc96ac32a4
4 changed files with 38 additions and 72 deletions

View File

@ -81,6 +81,7 @@ log_upload_failed,上传失败,错误代码:{0},剩余{1}条日志待上
log_upload_status,已记录{0}条日志,上传阈值为{1}。,"{0} logs recorded, upload threshold is {1}.",{0}個のログが記録され、アップロード閾値は{1}です。
log_weapon_detected,检测到武器。,Weapon detected.,武器が検出されました。
log_no_weapon_detected,没有检测到武器。,No weapon detected.,武器が検出されません。
log_weapon_lost,武器丢失。,Weapon lost.,武器が失われました。
log_nearest_node_is_null,最近的节点为空。,The nearest node is null.,最も近いノードが空です。
log_node_is_not_WeaponTemplate,节点不是WeaponTemplate。,The node is not a WeaponTemplate.,ードはWeaponTemplateではありません。
log_node_is_not_WeaponTemplate,节点不是WeaponTemplate。,The node is not a WeaponTemplate.,ードはWeaponTemplateではありません。
log_weapon_pick_failed,武器拾取失败。,Weapon pick failed.,武器の拾い上げに失敗しました。
log_weapon_pick_success,武器拾取成功。,Weapon pick success.,武器の拾い上げに成功しました。
1 id zh en ja
81 log_no_weapon_detected 没有检测到武器。 No weapon detected. 武器が検出されません。
82 log_weapon_lost log_nearest_node_is_null 武器丢失。 最近的节点为空。 Weapon lost. The nearest node is null. 武器が失われました。 最も近いノードが空です。
83 log_nearest_node_is_null log_node_is_not_WeaponTemplate 最近的节点为空。 节点不是WeaponTemplate。 The nearest node is null. The node is not a WeaponTemplate. 最も近いノードが空です。 ノードはWeaponTemplateではありません。
log_node_is_not_WeaponTemplate 节点不是WeaponTemplate。 The node is not a WeaponTemplate. ノードはWeaponTemplateではありません。
84 log_weapon_pick_failed 武器拾取失败。 Weapon pick failed. 武器の拾い上げに失敗しました。
85 log_weapon_pick_success 武器拾取成功。 Weapon pick success. 武器の拾い上げに成功しました。
86
87

View File

@ -45,12 +45,7 @@ public sealed partial class AiCharacter : CharacterTemplate
/// <para>在侦察范围内所有的敌人</para>
/// </summary>
private List<CharacterTemplate>? _enemyInTheScoutRange;
/// <summary>
/// <para>Every weapon in the recon area</para>
/// <para>在侦察范围内所有的武器</para>
/// </summary>
private List<WeaponTemplate>? _weaponInTheScoutRange;
/// <summary>
@ -83,13 +78,13 @@ public sealed partial class AiCharacter : CharacterTemplate
/// <para>Exclamation bubble Id</para>
/// <para>感叹气泡Id</para>
/// </summary>
private const int plaintBubbleId = 0;
private const int PlaintBubbleId = 0;
/// <summary>
/// <para>Query bubble Id</para>
/// <para>疑问气泡Id</para>
/// </summary>
private const int queryBubbleId = 1;
private const int QueryBubbleId = 1;
/// <summary>
/// <para>BubbleMarker</para>
@ -113,7 +108,6 @@ public sealed partial class AiCharacter : CharacterTemplate
_enemyInTheAttackRange = new List<CharacterTemplate>();
_enemyInTheScoutRange = new List<CharacterTemplate>();
_weaponInTheScoutRange = new List<WeaponTemplate>();
_screenEnabler2D = GetNode<VisibleOnScreenEnabler2D>("VisibleOnScreenEnabler2D");
_screenEnabler2D.ScreenEntered += () =>
{
@ -134,14 +128,14 @@ public sealed partial class AiCharacter : CharacterTemplate
var plaint = NodeUtils.InstantiatePackedScene<Control>(plaintScene);
if (plaint != null)
{
_bubbleMarker.AddBubble(plaintBubbleId, plaint);
_bubbleMarker.AddBubble(PlaintBubbleId, plaint);
}
using var queryScene = GD.Load<PackedScene>("res://prefab/ui/query.tscn");
var query = NodeUtils.InstantiatePackedScene<Control>(queryScene);
if (query != null)
{
_bubbleMarker.AddBubble(queryBubbleId, query);
_bubbleMarker.AddBubble(QueryBubbleId, query);
}
}
@ -228,12 +222,12 @@ public sealed partial class AiCharacter : CharacterTemplate
/// </summary>
public void DispladyPlaint()
{
_bubbleMarker?.ShowBubble(plaintBubbleId);
_bubbleMarker?.ShowBubble(PlaintBubbleId);
}
public void HidePlaint()
{
_bubbleMarker?.HideBubble(plaintBubbleId);
_bubbleMarker?.HideBubble(PlaintBubbleId);
}
/// <summary>
@ -242,12 +236,12 @@ public sealed partial class AiCharacter : CharacterTemplate
/// </summary>
public void DispladyQuery()
{
_bubbleMarker?.ShowBubble(queryBubbleId);
_bubbleMarker?.ShowBubble(QueryBubbleId);
}
public void HideQuery()
{
_bubbleMarker?.HideBubble(queryBubbleId);
_bubbleMarker?.HideBubble(QueryBubbleId);
}
/// <summary>
@ -268,36 +262,6 @@ public sealed partial class AiCharacter : CharacterTemplate
return _enemyInTheScoutRange.Count > 0;
}
/// <summary>
/// <para>Any weapons found in the recon area</para>
/// <para>侦察范围内是否发现武器</para>
/// </summary>
/// <returns></returns>
public bool ScoutWeaponDetected()
{
if (_weaponInTheScoutRange == null)
{
return false;
}
return _weaponInTheScoutRange.Count > 0;
}
/// <summary>
/// <para>Get weapons in the recon area</para>
/// <para>获取侦察范围内的武器</para>
/// </summary>
/// <returns></returns>
public WeaponTemplate[]? GetWeaponInScoutArea()
{
if (_weaponInTheScoutRange == null)
{
return null;
}
return _weaponInTheScoutRange.ToArray();
}
/// <summary>
/// <para>Get the first enemy in range</para>
/// <para>获取第一个进入侦察范围的敌人</para>
@ -346,11 +310,6 @@ public sealed partial class AiCharacter : CharacterTemplate
/// <param name="node"></param>
private void EnterTheScoutArea(Node node)
{
if (node is WeaponTemplate weaponTemplate)
{
_weaponInTheScoutRange?.Add(weaponTemplate);
}
CanCauseHarmNode(node, (canCause, characterTemplate) =>
{
if (canCause && characterTemplate != null)
@ -372,11 +331,6 @@ public sealed partial class AiCharacter : CharacterTemplate
return;
}
if (node is WeaponTemplate weaponTemplate)
{
_weaponInTheScoutRange?.Remove(weaponTemplate);
}
if (node is CharacterTemplate characterTemplate)
{
_enemyInTheScoutRange?.Remove(characterTemplate);

View File

@ -308,7 +308,7 @@ public partial class CharacterTemplate : CharacterBody2D
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private bool CanPickItem(Node node)
protected bool CanPickItem(Node node)
{
if (_currentItem != null && node == _currentItem)
{
@ -336,7 +336,7 @@ public partial class CharacterTemplate : CharacterBody2D
///<para>Whether successfully picked up</para>
///<para>是否成功拾起</para>
/// </returns>
protected bool PickItem(Node2D? pickAbleItemNode2D)
public bool PickItem(Node2D? pickAbleItemNode2D)
{
//Empty reference checking is implicitly performed here.
//此处隐式的执行了空引用检查。
@ -585,12 +585,12 @@ public partial class CharacterTemplate : CharacterBody2D
if (damageTemplate.Attacker is CharacterTemplate characterTemplate &&
!string.IsNullOrEmpty(characterTemplate.CharacterName))
{
LogCat.LogWithFormat("death_info", LogCat.LogLabel.Default, LogCat.UploadFormat,CharacterName,
LogCat.LogWithFormat("death_info", LogCat.LogLabel.Default, LogCat.UploadFormat, CharacterName,
characterTemplate.CharacterName);
}
else
{
LogCat.LogWithFormat("death_info", LogCat.LogLabel.Default, LogCat.UploadFormat,CharacterName,
LogCat.LogWithFormat("death_info", LogCat.LogLabel.Default, LogCat.UploadFormat, CharacterName,
damageTemplate.Attacker.Name);
}
}

View File

@ -27,26 +27,37 @@ public class LookForWeaponProcessor : StateProcessorTemplate
{
//If the nearest weapon is found, move the character to the weapon.
//如果有最近的武器被找到了,那么将角色移动到武器旁边。
aiCharacter.SetTargetPosition(TargetWeapon.GlobalPosition);
var distance = aiCharacter.GlobalPosition.DistanceTo(TargetWeapon.GlobalPosition);
if (distance < 5)
{
bool pick = aiCharacter.PickItem(TargetWeapon);
if (pick)
{
context.CurrentState = context.PreviousState;
LogCat.Log("weapon_pick_success", LogCat.LogLabel.LookForWeaponProcessor);
}
else
{
LogCat.Log("weapon_pick_failed", LogCat.LogLabel.LookForWeaponProcessor);
TargetWeapon = null;
}
}
else
{
aiCharacter.SetTargetPosition(TargetWeapon.GlobalPosition);
}
return;
}
if (aiCharacter.ScoutWeaponDetected())
if (aiCharacter.GetCanPickedWeapon().Length > 0)
{
//Weapons were found in the character's recon area.
//在角色的侦察范围内发现了武器。
//We search for the nearest weapon.
//我们搜索最近的武器。
LogCat.Log("weapon_detected", LogCat.LogLabel.LookForWeaponProcessor);
var weaponTemplates = aiCharacter.GetWeaponInScoutArea();
if (weaponTemplates == null || weaponTemplates.Length == 0)
{
//The weapon may have been lost or taken by someone else.
//武器可能已丢失,或被他人占用。
LogCat.Log("weapon_lost", LogCat.LogLabel.LookForWeaponProcessor);
return;
}
var weaponTemplates = aiCharacter.GetCanPickedWeapon();
var nodes = new List<Node>();
foreach (var weapon in weaponTemplates)
{