diff --git a/scripts/behaviorTree/BehaviorNode.cs b/scripts/behaviorTree/BehaviorNode.cs
index 03b09a7..f2f8c58 100644
--- a/scripts/behaviorTree/BehaviorNode.cs
+++ b/scripts/behaviorTree/BehaviorNode.cs
@@ -15,11 +15,6 @@ public partial class BehaviorNode : Node2D
InvokeBehaviorTreeNode(true, delta);
}
- // public override void _Process(double delta)
- // {
- // InvokeBehaviorTreeNode(false, delta);
- // }
-
///
/// InvokeBehaviorTreeNode
/// 调用行为树节点
diff --git a/scripts/behaviorTree/IBehaviorTree.cs b/scripts/behaviorTree/IBehaviorTree.cs
index e25a945..074fcb6 100644
--- a/scripts/behaviorTree/IBehaviorTree.cs
+++ b/scripts/behaviorTree/IBehaviorTree.cs
@@ -1,5 +1,9 @@
namespace ColdMint.scripts.behaviorTree;
+///
+/// IBehavior Tree
+/// 行为树
+///
public interface IBehaviorTree
{
string? Id { get; }
diff --git a/scripts/behaviorTree/ai/AiAttackNode.cs b/scripts/behaviorTree/ai/AiAttackNode.cs
index aa145b7..c95111b 100644
--- a/scripts/behaviorTree/ai/AiAttackNode.cs
+++ b/scripts/behaviorTree/ai/AiAttackNode.cs
@@ -3,6 +3,10 @@ using ColdMint.scripts.character;
namespace ColdMint.scripts.behaviorTree.ai;
+///
+/// AI attack node
+/// AI的攻击节点
+///
public class AiAttackNode : BehaviorTreeNodeTemplate
{
public AiCharacter? Character { get; set; }
@@ -29,47 +33,49 @@ public class AiAttackNode : BehaviorTreeNodeTemplate
var selfCamp = CampManager.GetCamp(Character.CampId);
foreach (var node in nodesInTheAttackRange)
{
- if (node is CharacterTemplate characterTemplate)
+ if (node is not CharacterTemplate characterTemplate)
{
- if (node == Character)
- {
- continue;
- }
+ continue;
+ }
+
+ if (node == Character)
+ {
+ continue;
+ }
- var characterCamp = CampManager.GetCamp(characterTemplate.CampId);
- var canCause = CampManager.CanCauseHarm(selfCamp, characterCamp);
- if (!canCause)
- {
- continue;
- }
+ var characterCamp = CampManager.GetCamp(characterTemplate.CampId);
+ var canCause = CampManager.CanCauseHarm(selfCamp, characterCamp);
+ if (!canCause)
+ {
+ continue;
+ }
- if (selfCamp == null || characterCamp == null)
- {
- continue;
- }
+ if (selfCamp == null || characterCamp == null)
+ {
+ continue;
+ }
+
+ if (selfCamp.Id == characterCamp.Id)
+ {
+ //If it is the same side, do not attack, if allowed friend damage, this code will prevent the AI from actively attacking the player.
+ //如果是同一阵营,不攻击,如果允许友伤,这段代码会阻止AI主动攻击玩家。
+ continue;
+ }
- if (selfCamp.Id == characterCamp.Id)
- {
- //如果是同一阵营,不攻击
- continue;
- }
-
- var distance = characterTemplate.GlobalPosition - Character.GlobalPosition;
- var distanceLength = distance.Length();
- if (distanceLength < closestDistance)
- {
- closestDistance = distanceLength;
- closestEnemy = characterTemplate;
- }
+ var distance = characterTemplate.GlobalPosition.DistanceTo(Character.GlobalPosition);
+ if (distance < closestDistance)
+ {
+ closestDistance = distance;
+ closestEnemy = characterTemplate;
}
}
if (closestEnemy != null && Character.AttackObstacleDetection != null)
{
- //There are the closest enemies
- //有距离最近的敌人
- var distance = closestEnemy.GlobalPosition - Character.GlobalPosition;
- Character.AttackObstacleDetection.TargetPosition = distance;
+ //With the nearest enemy and no obstacles
+ //有距离最近的敌人,且没有障碍物
+ var distanceVector2 = closestEnemy.GlobalPosition - Character.GlobalPosition;
+ Character.AttackObstacleDetection.TargetPosition = distanceVector2;
if (Character.AttackObstacleDetection.GetCollider() == null)
{
Character.StopMoving();
diff --git a/scripts/behaviorTree/ai/AiPatrolNode.cs b/scripts/behaviorTree/ai/AiPatrolNode.cs
index cf0e9a5..586abdd 100644
--- a/scripts/behaviorTree/ai/AiPatrolNode.cs
+++ b/scripts/behaviorTree/ai/AiPatrolNode.cs
@@ -4,6 +4,7 @@ using ColdMint.scripts.character;
namespace ColdMint.scripts.behaviorTree.ai;
///
+/// AI patrol node
/// AI巡逻节点
///
public class AiPatrolNode : SelectorNode
diff --git a/scripts/behaviorTree/framework/SequenceNode.cs b/scripts/behaviorTree/framework/SequenceNode.cs
index ba670cf..77904a8 100644
--- a/scripts/behaviorTree/framework/SequenceNode.cs
+++ b/scripts/behaviorTree/framework/SequenceNode.cs
@@ -14,7 +14,7 @@ public class SequenceNode : BehaviorTreeNodeTemplate
/// Check whether all child nodes are executed in sequence
/// 所有子节点是否按顺序执行完毕
///
- bool _complete = true;
+ private bool _complete = true;
public override int Execute(bool isPhysicsProcess, double delta)
{
diff --git a/scripts/camp/Camp.cs b/scripts/camp/Camp.cs
index 5e21b74..841e707 100644
--- a/scripts/camp/Camp.cs
+++ b/scripts/camp/Camp.cs
@@ -8,12 +8,11 @@ namespace ColdMint.scripts.camp;
///
public class Camp
{
- private readonly string _id;
private readonly List _friendlyCampIdList;
public Camp(string id)
{
- _id = id;
+ Id = id;
_friendlyCampIdList = new List();
}
@@ -21,7 +20,7 @@ public class Camp
/// Get camp ID
/// 获取阵营ID
///
- public string Id => _id;
+ public string Id { get; }
///
/// Get camp name
diff --git a/scripts/camp/CampManager.cs b/scripts/camp/CampManager.cs
index 37a1479..6014320 100644
--- a/scripts/camp/CampManager.cs
+++ b/scripts/camp/CampManager.cs
@@ -6,7 +6,7 @@ namespace ColdMint.scripts.camp;
/// Camp manager
/// 阵营管理器
///
-public class CampManager
+public static class CampManager
{
private static readonly Dictionary Camps = new Dictionary();
diff --git a/scripts/character/AiCharacter.cs b/scripts/character/AiCharacter.cs
index 6c0765a..d40e5be 100644
--- a/scripts/character/AiCharacter.cs
+++ b/scripts/character/AiCharacter.cs
@@ -9,7 +9,7 @@ namespace ColdMint.scripts.character;
/// The role played by computers
/// 由电脑扮演的角色
///
-public partial class AiCharacter : CharacterTemplate
+public sealed partial class AiCharacter : CharacterTemplate
{
///
/// How fast the character moves
@@ -67,10 +67,11 @@ public partial class AiCharacter : CharacterTemplate
if (_attackArea != null)
{
+ //If true, the zone will detect objects or areas entering and leaving the zone.
//如果为true,该区域将检测进出该区域的物体或区域。
_attackArea.Monitoring = true;
- //Other regions cannot detect our pick region
- //其他区域不能检测到我们的拾取区域
+ //Other areas can't detect our attack zone
+ //其他区域不能检测到我们的攻击区域
_attackArea.Monitorable = false;
_attackArea.BodyEntered += EnterTheAttackArea;
_attackArea.BodyExited += ExitTheAttackArea;
@@ -83,12 +84,12 @@ public partial class AiCharacter : CharacterTemplate
// _behaviorNode.Root = patrolBehaviorTree.Root;
}
- protected virtual void EnterTheAttackArea(Node node)
+ private void EnterTheAttackArea(Node node)
{
_nodesInTheAttackRange?.Add(node);
}
- protected virtual void ExitTheAttackArea(Node node)
+ private void ExitTheAttackArea(Node node)
{
_nodesInTheAttackRange?.Remove(node);
}
diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs
index a9910a7..019b65a 100644
--- a/scripts/character/CharacterTemplate.cs
+++ b/scripts/character/CharacterTemplate.cs
@@ -6,7 +6,6 @@ using ColdMint.scripts.damage;
using ColdMint.scripts.debug;
using ColdMint.scripts.health;
using ColdMint.scripts.inventory;
-using ColdMint.scripts.map.events;
using ColdMint.scripts.utils;
using ColdMint.scripts.weapon;
using Godot;
@@ -259,16 +258,18 @@ public partial class CharacterTemplate : CharacterBody2D
///
public bool PickItem(Node2D? pickAbleItem)
{
- if (pickAbleItem == null)
+ //Empty reference checking is implicitly performed here.
+ //此处隐式的执行了空引用检查。
+ if (pickAbleItem is not IItem item)
{
return false;
}
-
+
if (_itemContainer == null)
{
return false;
}
-
+
//Get the currently selected node
//拿到当前选择的节点
var itemSlotNode = _itemContainer.GetSelectItemSlotNode();
@@ -277,11 +278,6 @@ public partial class CharacterTemplate : CharacterBody2D
return false;
}
- if (pickAbleItem is not IItem item)
- {
- return false;
- }
-
//First check if we can pick up the item.
//先检查我们能否拾起此物品。
var canPick = _itemContainer.CanAddItem(item);
@@ -368,7 +364,7 @@ public partial class CharacterTemplate : CharacterBody2D
/// Update the role's health bar
/// 更新角色的健康条
///
- private void UpDataHealthBar(DamageTemplate damageTemplate)
+ private void UpDataHealthBar()
{
if (_healthBar == null)
{
@@ -441,7 +437,7 @@ public partial class CharacterTemplate : CharacterBody2D
return true;
}
- UpDataHealthBar(damageTemplate);
+ UpDataHealthBar();
return true;
}
diff --git a/scripts/inventory/HotBar.cs b/scripts/inventory/HotBar.cs
index af07b7f..6dff720 100644
--- a/scripts/inventory/HotBar.cs
+++ b/scripts/inventory/HotBar.cs
@@ -79,7 +79,7 @@ public partial class HotBar : HBoxContainer, IItemContainer
{
_selectIndex = count - 1;
}
-
+
SelectItemSlot(oldSelectIndex, _selectIndex);
}
@@ -223,6 +223,11 @@ public partial class HotBar : HBoxContainer, IItemContainer
///
private void SelectItemSlot(int oldSelectIndex, int newSelectIndex)
{
+ if (oldSelectIndex == newSelectIndex)
+ {
+ return;
+ }
+
if (_itemSlotNodes == null)
{
return;
@@ -286,10 +291,7 @@ public partial class HotBar : HBoxContainer, IItemContainer
{
return false;
}
- else
- {
- return itemSlotNode.SetItem(item);
- }
+ return itemSlotNode.SetItem(item);
}
public ItemSlotNode? GetSelectItemSlotNode()