tree based bt debugger
This commit is contained in:
parent
c9967f09d9
commit
b5d5a8f9f3
12 changed files with 271 additions and 19 deletions
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Bt = Dancer.Behavior;
|
||||
|
||||
|
|
@ -6,7 +5,7 @@ namespace Dancer;
|
|||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public sealed partial class Birb : CharacterBody2D, IAttackable,
|
||||
IProvide<IHitboxOwner>, IHitboxOwner
|
||||
IProvide<IHitboxOwner>, IHitboxOwner, Bt.IHasBehaviorTree
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
|
|
@ -26,7 +25,7 @@ public sealed partial class Birb : CharacterBody2D, IAttackable,
|
|||
|
||||
private float _hp;
|
||||
|
||||
private Bt.Tree Tree { get; set; } = null!;
|
||||
public Bt.Tree Tree { get; private set; } = null!;
|
||||
private float TargetVelocity { get; set; }
|
||||
|
||||
private MotionGoal _motionGoal = new MotionGoal.Stop();
|
||||
|
|
@ -46,26 +45,34 @@ public sealed partial class Birb : CharacterBody2D, IAttackable,
|
|||
HealthBar.MinValue = 0f;
|
||||
HealthBar.MaxValue = MaxHp;
|
||||
Tree = CreateTree();
|
||||
SendTreeDebugData();
|
||||
}
|
||||
|
||||
private void SendTreeDebugData()
|
||||
{
|
||||
if (EngineDebugger.IsActive())
|
||||
EngineDebugger.SendMessage("behavior_debug:add_tree",
|
||||
new() { GetInstanceId(), Tree.DebugData });
|
||||
}
|
||||
|
||||
private Bt.Tree CreateTree() => new(
|
||||
new Bt.Selector([
|
||||
new Bt.Sequence([
|
||||
new Bt.Check(() => Target is not null),
|
||||
new Bt.Check(() => Target is not null) { Name = "Has target?" },
|
||||
new Bt.Action(() => FaceToward(Target!.GlobalPosition)),
|
||||
new Bt.Selector([
|
||||
new Bt.MemoSequence([
|
||||
new Bt.Sequence([
|
||||
new Bt.Check(() => StabHitbox.GetOverlappingBodies().Contains(Target)),
|
||||
new Bt.MemoSequence([
|
||||
new Bt.Action(Stop),
|
||||
new Bt.Action(Stop) { Name = "Stop" },
|
||||
new Bt.PlayAnimation("prepare_attack"),
|
||||
new Bt.Delay(0.4) { RandomVariation = 0.2 },
|
||||
]),
|
||||
]),
|
||||
new Bt.PlayAnimation("stab"),
|
||||
new Bt.Action(() => _state = State.Attacking),
|
||||
new Bt.WaitUntil(() => _state is not State.Attacking),
|
||||
new Bt.WaitUntil(() => _state is not State.Attacking) { Name = "Done attacking?" },
|
||||
]),
|
||||
new Bt.MemoSequence([
|
||||
new Bt.Delay(0.1) { RandomVariation = 0.05 },
|
||||
|
|
@ -82,7 +89,7 @@ public sealed partial class Birb : CharacterBody2D, IAttackable,
|
|||
return WalkTo(targetPosition)
|
||||
? Bt.Result.Success
|
||||
: Bt.Result.Running;
|
||||
}),
|
||||
}) { Name = "Walk to target" },
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
|
|
@ -107,6 +114,7 @@ public sealed partial class Birb : CharacterBody2D, IAttackable,
|
|||
public void OnPhysicsProcess(double delta)
|
||||
{
|
||||
Tree.Process(delta);
|
||||
SendTreeDebugData();
|
||||
|
||||
var velocity = Velocity;
|
||||
switch (_motionGoal)
|
||||
|
|
|
|||
|
|
@ -229,6 +229,7 @@ debug_color = Color(0, 0.6, 0.69803923, 0)
|
|||
|
||||
[node name="HealthBar" type="ProgressBar" parent="." unique_id=369348156]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
anchors_preset = 5
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
|
|
@ -239,7 +240,8 @@ offset_bottom = -33.0
|
|||
grow_horizontal = 2
|
||||
theme_override_styles/background = SubResource("StyleBoxFlat_lyo8d")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_ba6cv")
|
||||
value = 50.0
|
||||
max_value = 4.0
|
||||
value = 4.0
|
||||
show_percentage = false
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=695394949]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue