Compare commits

...

2 Commits

9 changed files with 42 additions and 18 deletions

View File

@ -27,7 +27,7 @@ public partial class Character : CharacterBody2D, IFaction
} }
[Export] [Export]
public CharacterStats Stats { get; private set; } public CharacterStats Stats { get; protected set; }
[Signal] [Signal]
public delegate void HealthChangedEventHandler(Events.HealthChangedArgs args); public delegate void HealthChangedEventHandler(Events.HealthChangedArgs args);
@ -115,7 +115,7 @@ public partial class Character : CharacterBody2D, IFaction
if (Stats is not null) if (Stats is not null)
{ {
Stats.Stagger += (double time) => Stats.Stagger += (double time, float staggerDamage) =>
{ {
Stun(time); Stun(time);
}; };

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=68 format=3 uid="uid://d2skjvvx6fal0"] [gd_scene load_steps=70 format=3 uid="uid://d2skjvvx6fal0"]
[ext_resource type="Script" path="res://Characters/Doc.cs" id="2_3elet"] [ext_resource type="Script" path="res://Characters/Doc.cs" id="2_3elet"]
[ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="2_5jxom"] [ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="2_5jxom"]
@ -7,8 +7,10 @@
[ext_resource type="Script" path="res://State/Character/CharacterStateMachine.cs" id="3_t5jjc"] [ext_resource type="Script" path="res://State/Character/CharacterStateMachine.cs" id="3_t5jjc"]
[ext_resource type="Texture2D" uid="uid://dpepm54hjuyga" path="res://Assets/Sprites/Characters/forsen-hand.png" id="4_8lqj6"] [ext_resource type="Texture2D" uid="uid://dpepm54hjuyga" path="res://Assets/Sprites/Characters/forsen-hand.png" id="4_8lqj6"]
[ext_resource type="Script" path="res://State/Character/NPCIdleState.cs" id="4_b35px"] [ext_resource type="Script" path="res://State/Character/NPCIdleState.cs" id="4_b35px"]
[ext_resource type="Script" path="res://Utils/PlayerStats.cs" id="5_a7fiw"]
[ext_resource type="Script" path="res://State/Character/NPCMoveState.cs" id="5_pejsd"] [ext_resource type="Script" path="res://State/Character/NPCMoveState.cs" id="5_pejsd"]
[ext_resource type="Script" path="res://State/NPC/NPCStateMachine.cs" id="6_kjpug"] [ext_resource type="Script" path="res://State/NPC/NPCStateMachine.cs" id="6_kjpug"]
[ext_resource type="Script" path="res://Utils/Values/DoubleValue.cs" id="6_kyulo"]
[ext_resource type="Script" path="res://State/Character/CharacterDashState.cs" id="7_0ks57"] [ext_resource type="Script" path="res://State/Character/CharacterDashState.cs" id="7_0ks57"]
[ext_resource type="Script" path="res://State/NPC/Doc/DocTelegraphState.cs" id="7_tfwbh"] [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="PackedScene" uid="uid://cjgxyhgcyvsv7" path="res://BoundingBoxes/Hurtbox.tscn" id="7_tnve0"]
@ -571,6 +573,12 @@ Inventory = NodePath("Inventory")
StateMachine = NodePath("StateMachine") StateMachine = NodePath("StateMachine")
Hurtbox = NodePath("Hurtbox") Hurtbox = NodePath("Hurtbox")
[node name="Stats" type="Node" parent="."]
script = ExtResource("5_a7fiw")
[node name="StaggerDamage" type="Node" parent="Stats"]
script = ExtResource("6_kyulo")
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("InitialState", "Character")] [node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("InitialState", "Character")]
script = ExtResource("3_t5jjc") script = ExtResource("3_t5jjc")
InitialState = NodePath("Idle") InitialState = NodePath("Idle")

View File

@ -42,7 +42,6 @@ public sealed partial class Player : Character
[Export] [Export]
public AnimationTree AnimationTree { get; private set; } public AnimationTree AnimationTree { get; private set; }
[Export]
public new PlayerStats Stats { get; private set; } public new PlayerStats Stats { get; private set; }
public InteractionRay InteractionRay { get; private set; } public InteractionRay InteractionRay { get; private set; }
@ -54,8 +53,10 @@ public sealed partial class Player : Character
_characterEffects = GetNode<Node2D>("%CharacterEffects"); _characterEffects = GetNode<Node2D>("%CharacterEffects");
_targetTracer = GetNode<TargetTracer>("%TargetTracer"); _targetTracer = GetNode<TargetTracer>("%TargetTracer");
base.Stats = GetNode<PlayerStats>("Stats");
Stats = (PlayerStats)base.Stats;
base._Ready(); base._Ready();
Stats = GetNode<PlayerStats>("Stats");
Inventory.UsedItem += (Items.Item item) => Inventory.UsedItem += (Items.Item item) =>
{ {

View File

@ -576,7 +576,7 @@ size = Vector2(8, 8)
closed = false closed = false
polygon = PackedVector2Array(-3, 0, 2, 0) polygon = PackedVector2Array(-3, 0, 2, 0)
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Camera", "DirectionMarker", "Stats", "Stats", "Sprite", "Inventory", "StateMachine", "Hurtbox")] [node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Camera", "DirectionMarker", "Stats", "Sprite", "Inventory", "StateMachine", "Hurtbox")]
y_sort_enabled = true y_sort_enabled = true
texture_filter = 3 texture_filter = 3
material = SubResource("ShaderMaterial_h78y7") material = SubResource("ShaderMaterial_h78y7")
@ -585,7 +585,6 @@ collision_mask = 17
script = ExtResource("1_flygr") script = ExtResource("1_flygr")
Camera = NodePath("Camera2D") Camera = NodePath("Camera2D")
DirectionMarker = NodePath("Direction2D") DirectionMarker = NodePath("Direction2D")
Stats = NodePath("Stats")
Speed = 80.0 Speed = 80.0
Stats = NodePath("Stats") Stats = NodePath("Stats")
HandTexture = ExtResource("3_3dqh7") HandTexture = ExtResource("3_3dqh7")

View File

@ -10,5 +10,7 @@ public interface IParryable
public ulong ParryTimeOrigin { get; } public ulong ParryTimeOrigin { get; }
public void Stun(); public float BlockForce { get; }
public void Stun(float blockForce);
} }

View File

@ -62,6 +62,9 @@ public partial class Sword : Weapon, IParryable
public ulong ParryTimeOrigin { get; protected set; } public ulong ParryTimeOrigin { get; protected set; }
[Export]
public float BlockForce { get; set; } = 1;
private Tween _currentTween; private Tween _currentTween;
private AnimationNodeStateMachinePlayback _playback; private AnimationNodeStateMachinePlayback _playback;
@ -214,7 +217,7 @@ public partial class Sword : Weapon, IParryable
{ {
// our character was parried // our character was parried
ParryParticles.CloneOnWorld<GpuParticles2D>().EmitOneShot(); ParryParticles.CloneOnWorld<GpuParticles2D>().EmitOneShot();
Stun(); Stun(otherParryable.BlockForce);
if (otherParryable is Sword sword) if (otherParryable is Sword sword)
{ {
@ -235,12 +238,13 @@ public partial class Sword : Weapon, IParryable
/// Stuns the wepaon holder. This is unique to swords and melee weapons /// Stuns the wepaon holder. This is unique to swords and melee weapons
/// if they can parry. /// if they can parry.
/// </summary> /// </summary>
public void Stun() public void Stun(float blockForce)
{ {
IsParried = true; IsParried = true;
AnimationPlayer.SpeedScale = 0.25f; Character.Stats.AddStaggerDamage(Damage * blockForce);
Character.Stun(2);
GetNode<AudioStreamPlayer2D>("ParrySound") // optionally play parry sound
GetNode<AudioStreamPlayer2D>("ParrySound")?
.OnWorld() .OnWorld()
.WithPitchDeviation(0.125f) .WithPitchDeviation(0.125f)
.PlayOneShot(); .PlayOneShot();

View File

@ -25,9 +25,13 @@ public partial class SwordBlockState : WeaponState
private bool _isAlternate = false; private bool _isAlternate = false;
private float _oldBlockForce;
public override WeaponState Enter(IState<WeaponState> prevState) public override WeaponState Enter(IState<WeaponState> prevState)
{ {
Sword.EnableParry(ulong.MaxValue); Sword.EnableParry(ulong.MaxValue);
_oldBlockForce = Sword.BlockForce;
Sword.BlockForce *= 4;
_useDuration = Sword.UseAltTime; _useDuration = Sword.UseAltTime;
_attackDuration = Sword.AttackAltTime; _attackDuration = Sword.AttackAltTime;
@ -55,6 +59,12 @@ public partial class SwordBlockState : WeaponState
public override void Exit(IState<WeaponState> nextState) public override void Exit(IState<WeaponState> nextState)
{ {
if (nextState == IdleState)
{
Sword.AnimationPlayer.Play("RESET");
}
Sword.BlockForce = _oldBlockForce;
Deattack(); Deattack();
HasBlocked = false; HasBlocked = false;
} }
@ -71,7 +81,6 @@ public partial class SwordBlockState : WeaponState
if ((_useDuration -= delta) <= 0) if ((_useDuration -= delta) <= 0)
{ {
Sword.AnimationPlayer.Play("RESET");
return IdleState; return IdleState;
} }

View File

@ -8,7 +8,6 @@ public partial class StunEffect : ColorRect
{ {
Events.EventBus.Instance.PlayerStun += () => Events.EventBus.Instance.PlayerStun += () =>
{ {
GD.Print("PLAYER STUNNED!!!");
GetNode<AnimationPlayer>("AnimationPlayer").Play("tighten"); GetNode<AnimationPlayer>("AnimationPlayer").Play("tighten");
}; };
} }

View File

@ -16,7 +16,7 @@ public partial class CharacterStats : Node
public double MaxStagger { get; set; } = 25; public double MaxStagger { get; set; } = 25;
[Signal] [Signal]
public delegate void StaggerEventHandler(double time); public delegate void StaggerEventHandler(double time, float damage);
public bool ShouldStagger => StaggerDamage.Value >= MaxStagger; public bool ShouldStagger => StaggerDamage.Value >= MaxStagger;
@ -42,10 +42,12 @@ public partial class CharacterStats : Node
public void AddStaggerDamage(float damage) public void AddStaggerDamage(float damage)
{ {
StaggerDamage.Value += damage * StaggerCoefficient; float delta = damage * (float)StaggerCoefficient;
StaggerDamage.Value += delta;
if (StaggerDamage.Value >= MaxStagger) if (StaggerDamage.Value >= MaxStagger)
{ {
EmitSignal(SignalName.Stagger, 1); EmitSignal(SignalName.Stagger, 1, delta);
StaggerDamage.Value = 0;
} }
else else
{ {