diff --git a/Characters/Doc.tscn b/Characters/Doc.tscn index 8545cf9..cbd6f0e 100644 --- a/Characters/Doc.tscn +++ b/Characters/Doc.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=33 format=3 uid="uid://bt6s40u515jvo"] +[gd_scene load_steps=33 format=3 uid="uid://dsr5kkbthpwpl"] [ext_resource type="Script" path="res://Characters/Doc.cs" id="2_3elet"] [ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="2_5jxom"] @@ -9,7 +9,7 @@ [ext_resource type="Script" path="res://State/NPC/NPCStateMachine.cs" id="6_kjpug"] [ext_resource type="Script" path="res://State/NPC/Doc/DocTelegraphState.cs" id="7_tfwbh"] [ext_resource type="PackedScene" uid="uid://cjgxyhgcyvsv7" path="res://BoundingBoxes/Hurtbox.tscn" id="7_tnve0"] -[ext_resource type="Script" path="res://State/NPC/Doc/DocAttackState.cs" id="8_r4l3q"] +[ext_resource type="Script" path="res://State/NPC/Doc/DocShungiteDartState.cs" id="8_1hoax"] [ext_resource type="Script" path="res://Items/Inventory.cs" id="8_r8ejq"] [ext_resource type="Script" path="res://State/NPC/Doc/DocExitState.cs" id="9_6com1"] [ext_resource type="PackedScene" uid="uid://doiwdphocqlpo" path="res://Entities/ShungiteSpike.tscn" id="9_7kavk"] @@ -237,7 +237,7 @@ AttackState = NodePath("../Attack") NPC = NodePath("../..") [node name="Attack" type="Node" parent="BossStateMachine" node_paths=PackedStringArray("ExitState", "NPC")] -script = ExtResource("8_r4l3q") +script = ExtResource("8_1hoax") Duration = 8.0 AttackDuration = 1.0 Projectile = ExtResource("9_7kavk") diff --git a/State/NPC/Doc/DocAttackState.cs b/State/NPC/Doc/DocAttackState.cs index fdae8a3..aaeac51 100644 --- a/State/NPC/Doc/DocAttackState.cs +++ b/State/NPC/Doc/DocAttackState.cs @@ -1,95 +1,16 @@ using Godot; -using GodotUtilities; -using SupaLidlGame.Entities; namespace SupaLidlGame.State.NPC.Doc; -public partial class DocAttackState : NPCState +public abstract partial class DocAttackState : NPCState { - protected Scenes.Map _map; - protected Utils.World _world; + public abstract double Duration { get; set; } - protected double _currentDuration = 0; - protected double _currentAttackDuration = 0; + public abstract double AttackDuration { get; set; } - [Export] - public double Duration { get; set; } + public abstract PackedScene Projectile { get; set; } - [Export] - public double AttackDuration { get; set; } + public abstract DocExitState ExitState { get; set; } - [Export] - public PackedScene Projectile { get; set; } - - [Export] - public DocExitState ExitState { get; set; } - - private float _intensity = 1; - - public override NPCState Enter(IState previousState) - { - _map = this.GetAncestor(); - _world = this.GetAncestor(); - _currentDuration = Duration; - _currentAttackDuration = AttackDuration; - return null; - } - - public override void Exit(IState nextState) - { - - } - - protected virtual Projectile SpawnProjectile( - Vector2 position, - Vector2 direction) - { - var projectile = _map.SpawnEntity(Projectile); - projectile.Hitbox.Faction = NPC.Faction; - // global position is (from npc to player) * 2 = (2 * npc) - player - //projectile.GlobalPosition = 2 * NPC.GlobalPosition - playerPos; - projectile.GlobalPosition = position; - projectile.Direction = direction; - projectile.GlobalRotation = direction.Angle(); - projectile.Delay = 1 / _intensity; - return projectile; - } - - protected virtual void Attack() - { - var player = _world.CurrentPlayer; - var playerPos = player.GlobalPosition; - Vector2 position1 = 2 * NPC.GlobalPosition - playerPos; - Vector2 position2 = 2 * playerPos - NPC.GlobalPosition; - Vector2 direction1 = position1.DirectionTo(playerPos); - Vector2 direction2 = -direction1; - SpawnProjectile(position1, direction1); - SpawnProjectile(position2, direction2); - _currentAttackDuration = AttackDuration / _intensity; - } - - public override NPCState Process(double delta) - { - if ((_currentDuration -= delta) <= 0) - { - return ExitState; - } - - if (NPC.Health < 500) - { - _intensity = 2; - } - - if (NPC.Health < 250) - { - _intensity = 3; - } - - if ((_currentAttackDuration -= delta) <= 0) - { - Attack(); - } - - return null; - } + protected abstract void Attack(); } diff --git a/State/NPC/Doc/DocShungiteDartState.cs b/State/NPC/Doc/DocShungiteDartState.cs new file mode 100644 index 0000000..5a19af9 --- /dev/null +++ b/State/NPC/Doc/DocShungiteDartState.cs @@ -0,0 +1,95 @@ +using Godot; +using GodotUtilities; +using SupaLidlGame.Entities; + +namespace SupaLidlGame.State.NPC.Doc; + +public partial class DocShungiteDartState : DocAttackState +{ + protected Scenes.Map _map; + protected Utils.World _world; + + protected double _currentDuration = 0; + protected double _currentAttackDuration = 0; + + [Export] + public override double Duration { get; set; } + + [Export] + public override double AttackDuration { get; set; } + + [Export] + public override PackedScene Projectile { get; set; } + + [Export] + public override DocExitState ExitState { get; set; } + + private float _intensity = 1; + + public override NPCState Enter(IState previousState) + { + _map = this.GetAncestor(); + _world = this.GetAncestor(); + _currentDuration = Duration; + _currentAttackDuration = AttackDuration; + return null; + } + + public override void Exit(IState nextState) + { + + } + + protected virtual Projectile SpawnProjectile( + Vector2 position, + Vector2 direction) + { + var projectile = _map.SpawnEntity(Projectile); + projectile.Hitbox.Faction = NPC.Faction; + // global position is (from npc to player) * 2 = (2 * npc) - player + //projectile.GlobalPosition = 2 * NPC.GlobalPosition - playerPos; + projectile.GlobalPosition = position; + projectile.Direction = direction; + projectile.GlobalRotation = direction.Angle(); + projectile.Delay = 1 / _intensity; + return projectile; + } + + protected override void Attack() + { + var player = _world.CurrentPlayer; + var playerPos = player.GlobalPosition; + Vector2 position1 = 2 * NPC.GlobalPosition - playerPos; + Vector2 position2 = 2 * playerPos - NPC.GlobalPosition; + Vector2 direction1 = position1.DirectionTo(playerPos); + Vector2 direction2 = -direction1; + SpawnProjectile(position1, direction1); + SpawnProjectile(position2, direction2); + _currentAttackDuration = AttackDuration / _intensity; + } + + public override NPCState Process(double delta) + { + if ((_currentDuration -= delta) <= 0) + { + return ExitState; + } + + if (NPC.Health < 500) + { + _intensity = 2; + } + + if (NPC.Health < 250) + { + _intensity = 3; + } + + if ((_currentAttackDuration -= delta) <= 0) + { + Attack(); + } + + return null; + } +} diff --git a/State/NPC/Doc/DocShungiteSpikeState.cs b/State/NPC/Doc/DocShungiteSpikeState.cs index 2b23149..b8968bd 100644 --- a/State/NPC/Doc/DocShungiteSpikeState.cs +++ b/State/NPC/Doc/DocShungiteSpikeState.cs @@ -1,10 +1,9 @@ using Godot; -using GodotUtilities; using SupaLidlGame.Entities; namespace SupaLidlGame.State.NPC.Doc; -public partial class DocShungiteSpikeState : DocAttackState +public partial class DocShungiteSpikeState : DocShungiteDartState { private float _intensity = 1;