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]
public CharacterStats Stats { get; private set; }
public CharacterStats Stats { get; protected set; }
[Signal]
public delegate void HealthChangedEventHandler(Events.HealthChangedArgs args);
@ -115,7 +115,7 @@ public partial class Character : CharacterBody2D, IFaction
if (Stats is not null)
{
Stats.Stagger += (double time) =>
Stats.Stagger += (double time, float staggerDamage) =>
{
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="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="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://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/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/NPC/Doc/DocTelegraphState.cs" id="7_tfwbh"]
[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")
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")]
script = ExtResource("3_t5jjc")
InitialState = NodePath("Idle")

View File

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

View File

@ -576,7 +576,7 @@ size = Vector2(8, 8)
closed = false
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
texture_filter = 3
material = SubResource("ShaderMaterial_h78y7")
@ -585,7 +585,6 @@ collision_mask = 17
script = ExtResource("1_flygr")
Camera = NodePath("Camera2D")
DirectionMarker = NodePath("Direction2D")
Stats = NodePath("Stats")
Speed = 80.0
Stats = NodePath("Stats")
HandTexture = ExtResource("3_3dqh7")

View File

@ -10,5 +10,7 @@ public interface IParryable
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; }
[Export]
public float BlockForce { get; set; } = 1;
private Tween _currentTween;
private AnimationNodeStateMachinePlayback _playback;
@ -214,7 +217,7 @@ public partial class Sword : Weapon, IParryable
{
// our character was parried
ParryParticles.CloneOnWorld<GpuParticles2D>().EmitOneShot();
Stun();
Stun(otherParryable.BlockForce);
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
/// if they can parry.
/// </summary>
public void Stun()
public void Stun(float blockForce)
{
IsParried = true;
AnimationPlayer.SpeedScale = 0.25f;
Character.Stun(2);
GetNode<AudioStreamPlayer2D>("ParrySound")
Character.Stats.AddStaggerDamage(Damage * blockForce);
// optionally play parry sound
GetNode<AudioStreamPlayer2D>("ParrySound")?
.OnWorld()
.WithPitchDeviation(0.125f)
.PlayOneShot();

View File

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

View File

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

View File

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