diff --git a/locals/Log.csv b/locals/Log.csv
index ec89ed7..e3d70e4 100644
--- a/locals/Log.csv
+++ b/locals/Log.csv
@@ -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ではありません。
\ No newline at end of file
+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.,武器の拾い上げに成功しました。
\ No newline at end of file
diff --git a/scripts/character/AiCharacter.cs b/scripts/character/AiCharacter.cs
index c63eab4..9604870 100644
--- a/scripts/character/AiCharacter.cs
+++ b/scripts/character/AiCharacter.cs
@@ -45,12 +45,7 @@ public sealed partial class AiCharacter : CharacterTemplate
/// 在侦察范围内所有的敌人
///
private List? _enemyInTheScoutRange;
-
- ///
- /// Every weapon in the recon area
- /// 在侦察范围内所有的武器
- ///
- private List? _weaponInTheScoutRange;
+
///
@@ -83,13 +78,13 @@ public sealed partial class AiCharacter : CharacterTemplate
/// Exclamation bubble Id
/// 感叹气泡Id
///
- private const int plaintBubbleId = 0;
+ private const int PlaintBubbleId = 0;
///
/// Query bubble Id
/// 疑问气泡Id
///
- private const int queryBubbleId = 1;
+ private const int QueryBubbleId = 1;
///
/// BubbleMarker
@@ -113,7 +108,6 @@ public sealed partial class AiCharacter : CharacterTemplate
_enemyInTheAttackRange = new List();
_enemyInTheScoutRange = new List();
- _weaponInTheScoutRange = new List();
_screenEnabler2D = GetNode("VisibleOnScreenEnabler2D");
_screenEnabler2D.ScreenEntered += () =>
{
@@ -134,14 +128,14 @@ public sealed partial class AiCharacter : CharacterTemplate
var plaint = NodeUtils.InstantiatePackedScene(plaintScene);
if (plaint != null)
{
- _bubbleMarker.AddBubble(plaintBubbleId, plaint);
+ _bubbleMarker.AddBubble(PlaintBubbleId, plaint);
}
using var queryScene = GD.Load("res://prefab/ui/query.tscn");
var query = NodeUtils.InstantiatePackedScene(queryScene);
if (query != null)
{
- _bubbleMarker.AddBubble(queryBubbleId, query);
+ _bubbleMarker.AddBubble(QueryBubbleId, query);
}
}
@@ -228,12 +222,12 @@ public sealed partial class AiCharacter : CharacterTemplate
///
public void DispladyPlaint()
{
- _bubbleMarker?.ShowBubble(plaintBubbleId);
+ _bubbleMarker?.ShowBubble(PlaintBubbleId);
}
public void HidePlaint()
{
- _bubbleMarker?.HideBubble(plaintBubbleId);
+ _bubbleMarker?.HideBubble(PlaintBubbleId);
}
///
@@ -242,12 +236,12 @@ public sealed partial class AiCharacter : CharacterTemplate
///
public void DispladyQuery()
{
- _bubbleMarker?.ShowBubble(queryBubbleId);
+ _bubbleMarker?.ShowBubble(QueryBubbleId);
}
public void HideQuery()
{
- _bubbleMarker?.HideBubble(queryBubbleId);
+ _bubbleMarker?.HideBubble(QueryBubbleId);
}
///
@@ -268,36 +262,6 @@ public sealed partial class AiCharacter : CharacterTemplate
return _enemyInTheScoutRange.Count > 0;
}
- ///
- /// Any weapons found in the recon area
- /// 侦察范围内是否发现武器
- ///
- ///
- public bool ScoutWeaponDetected()
- {
- if (_weaponInTheScoutRange == null)
- {
- return false;
- }
-
- return _weaponInTheScoutRange.Count > 0;
- }
-
- ///
- /// Get weapons in the recon area
- /// 获取侦察范围内的武器
- ///
- ///
- public WeaponTemplate[]? GetWeaponInScoutArea()
- {
- if (_weaponInTheScoutRange == null)
- {
- return null;
- }
-
- return _weaponInTheScoutRange.ToArray();
- }
-
///
/// Get the first enemy in range
/// 获取第一个进入侦察范围的敌人
@@ -346,11 +310,6 @@ public sealed partial class AiCharacter : CharacterTemplate
///
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);
diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs
index baf6e6f..23f4d4e 100644
--- a/scripts/character/CharacterTemplate.cs
+++ b/scripts/character/CharacterTemplate.cs
@@ -308,7 +308,7 @@ public partial class CharacterTemplate : CharacterBody2D
///
///
///
- private bool CanPickItem(Node node)
+ protected bool CanPickItem(Node node)
{
if (_currentItem != null && node == _currentItem)
{
@@ -336,7 +336,7 @@ public partial class CharacterTemplate : CharacterBody2D
///Whether successfully picked up
///是否成功拾起
///
- 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);
}
}
diff --git a/scripts/stateMachine/StateProcessor/LookForWeaponProcessor.cs b/scripts/stateMachine/StateProcessor/LookForWeaponProcessor.cs
index 1eee7b3..246d58d 100644
--- a/scripts/stateMachine/StateProcessor/LookForWeaponProcessor.cs
+++ b/scripts/stateMachine/StateProcessor/LookForWeaponProcessor.cs
@@ -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();
foreach (var weapon in weaponTemplates)
{