change parry to use stagger instead of direct stun
							parent
							
								
									fc5ea41e3a
								
							
						
					
					
						commit
						341f5137eb
					
				|  | @ -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); | ||||
|             }; | ||||
|  |  | |||
|  | @ -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) => | ||||
|         { | ||||
|  |  | |||
|  | @ -10,5 +10,7 @@ public interface IParryable | |||
| 
 | ||||
|     public ulong ParryTimeOrigin { get; } | ||||
| 
 | ||||
|     public void Stun(); | ||||
|     public float BlockForce { get; } | ||||
| 
 | ||||
|     public void Stun(float blockForce); | ||||
| } | ||||
|  |  | |||
|  | @ -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(); | ||||
|  |  | |||
|  | @ -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; | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -8,7 +8,6 @@ public partial class StunEffect : ColorRect | |||
|     { | ||||
|         Events.EventBus.Instance.PlayerStun += () => | ||||
|         { | ||||
|             GD.Print("PLAYER STUNNED!!!"); | ||||
|             GetNode<AnimationPlayer>("AnimationPlayer").Play("tighten"); | ||||
|         }; | ||||
|     } | ||||
|  |  | |||
|  | @ -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 | ||||
|         { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue