From feec74fa6533e020de16b9517885790130769cab Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Fri, 11 Oct 2024 12:24:13 -0700 Subject: [PATCH] Make Doc dodge projectiles during lance state --- Characters/Doc.cs | 7 ++----- Characters/Doc.tscn | 19 ++++++++++++++---- State/Thinker/DashDefensive.cs | 35 ++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/Characters/Doc.cs b/Characters/Doc.cs index 12768aa..8aa2f3f 100644 --- a/Characters/Doc.cs +++ b/Characters/Doc.cs @@ -10,9 +10,6 @@ public partial class Doc : Boss public AnimationPlayer MiscAnimation { get; set; } - [Export] - public Items.Weapons.Sword Lance { get; set; } - [Export] public override bool IsActive { @@ -109,7 +106,7 @@ public partial class Doc : Boss if (name == "Doc") { IsActive = true; - Inventory.SelectedItem = Lance; + Inventory.SelectedItem = GetNode("%DocLance"); } }; @@ -122,7 +119,7 @@ public partial class Doc : Boss if (this.GetWorld().CurrentPlayer.IsAlive && !IsActive) { IsActive = true; - Inventory.SelectedItem = Lance; + Inventory.SelectedItem = GetNode("%DocLance"); } }; } diff --git a/Characters/Doc.tscn b/Characters/Doc.tscn index 181ccad..d8a6260 100644 --- a/Characters/Doc.tscn +++ b/Characters/Doc.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=71 format=3 uid="uid://d2skjvvx6fal0"] +[gd_scene load_steps=72 format=3 uid="uid://d2skjvvx6fal0"] [ext_resource type="Script" path="res://Characters/Doc.cs" id="2_3elet"] [ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="2_5jxom"] @@ -568,14 +568,16 @@ size = Vector2(16, 19) [sub_resource type="CircleShape2D" id="CircleShape2D_8hwat"] radius = 16.0 -[node name="Doc" type="CharacterBody2D" node_paths=PackedStringArray("Lance", "BossStateMachine", "DefaultSelectedItem", "ThinkerStateMachine", "Stats", "Sprite", "Inventory", "StateMachine", "Hurtbox")] +[sub_resource type="CircleShape2D" id="CircleShape2D_kap5k"] +radius = 48.0 + +[node name="Doc" type="CharacterBody2D" node_paths=PackedStringArray("BossStateMachine", "DefaultSelectedItem", "ThinkerStateMachine", "Stats", "Sprite", "Inventory", "StateMachine", "Hurtbox")] y_sort_enabled = true texture_filter = 3 material = SubResource("ShaderMaterial_7n7iy") collision_layer = 10 collision_mask = 17 script = ExtResource("2_3elet") -Lance = NodePath("Inventory/DocLance") BossStateMachine = NodePath("BossStateMachine") BossName = "Doc, The Two-Time" Music = ExtResource("3_qnxmu") @@ -698,8 +700,9 @@ InitialState = NodePath("Attack") script = ExtResource("21_ij3bp") NPC = NodePath("../..") -[node name="DashDefensive" type="Node" parent="ThinkerStateMachine" node_paths=PackedStringArray("NPC")] +[node name="DashDefensive" type="Node" parent="ThinkerStateMachine" node_paths=PackedStringArray("ProjectileDetection", "NPC")] script = ExtResource("20_12htp") +ProjectileDetection = NodePath("../../ProjectileDetection") MaxDistanceToTarget = 256.0 UseItemDistance = 64.0 NPC = NodePath("../..") @@ -820,5 +823,13 @@ offset_bottom = -14.0 [node name="Label" parent="InteractionTrigger/Popup" index="0"] text = "Duel" +[node name="ProjectileDetection" type="Area2D" parent="."] +unique_name_in_owner = true +collision_layer = 0 +collision_mask = 256 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="ProjectileDetection"] +shape = SubResource("CircleShape2D_kap5k") + [editable path="Hurtbox"] [editable path="InteractionTrigger"] diff --git a/State/Thinker/DashDefensive.cs b/State/Thinker/DashDefensive.cs index e0d82a0..8bde545 100644 --- a/State/Thinker/DashDefensive.cs +++ b/State/Thinker/DashDefensive.cs @@ -9,14 +9,49 @@ public partial class DashDefensive : AttackState protected bool _dashedAway = false; protected State.Character.CharacterDashState _dashState; protected float _originalDashModifier; + private Callable _dodgeCallable; + + [Export] + public Area2D ProjectileDetection { get; set; } public override void _Ready() { _dashState = NPC.StateMachine.FindChildOfType(); _originalDashModifier = _dashState.VelocityModifier; + _dodgeCallable = new Callable(this, MethodName.DodgeProjectile); + base._Ready(); } + public override IState Enter(IState prev) + { + ProjectileDetection?.Connect(Area2D.SignalName.AreaEntered, + _dodgeCallable); + + return base.Enter(prev); + } + + public override void Exit(IState prev) + { + ProjectileDetection?.Disconnect(Area2D.SignalName.AreaEntered, + _dodgeCallable); + + base.Exit(prev); + } + + private void DodgeProjectile(Area2D area) + { + if (area is BoundingBoxes.Hitbox hitbox) + { + if (hitbox.GetOwner() is Entities.Projectile projectile) + { + GD.Print("changing direction"); + var direction = projectile.Direction; + DashTo(direction.Rotated(Mathf.Pi / 2)); + } + } + } + public override ThinkerState Think() { Characters.Character bestTarget = NPC.FindBestTarget();