parrying projectiles
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Sync.Primitives;
|
||||
@@ -22,6 +23,7 @@ using Godot;
|
||||
using GodotStateCharts;
|
||||
|
||||
using Movementtests.addons.godot_state_charts.csharp;
|
||||
using Movementtests.forge.abilities;
|
||||
using Movementtests.interfaces;
|
||||
using Movementtests.systems;
|
||||
using Movementtests.player_controller.Scripts;
|
||||
@@ -39,6 +41,8 @@ public record struct EmpoweredActionPayload;
|
||||
public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandler, IDisposable, ITargetable
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
public record struct OnParryPayload(Vector3 ForwardVector);
|
||||
|
||||
#region Dependencies
|
||||
[Dependency]
|
||||
@@ -97,6 +101,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
[Node("CeilingDetector")] public required ShapeCast3D CeilingDetector { get; set; }
|
||||
[Node("DirectGroundDetector")] public required RayCast3D DirectGroundDetector { get; set; }
|
||||
[Node("%WeaponHitbox")] public required Area3D WeaponHitbox { get; set; }
|
||||
[Node("%Parrybox")] public required Area3D Parrybox { get; set; }
|
||||
[Node("SFXPlayer")] public required AudioStreamPlayer3D SfxPlayer { get; set; }
|
||||
[Node("DashDamage")] public required ShapeCast3D DashDamageDetector { get; set; }
|
||||
[Node("SlidingEnemyDetector")] public required Area3D SlidingEnemyDetector { get; set; }
|
||||
@@ -461,6 +466,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
|
||||
// Damage dealing
|
||||
private readonly List<IForgeEntity> _hitEnemies = [];
|
||||
private readonly List<IForgeEntity> _parriedEntities = [];
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -506,8 +512,8 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
_playerRadius = playerShape.Radius;
|
||||
|
||||
// Combat stuff
|
||||
WeaponHitbox.Monitoring = false;
|
||||
WeaponHitbox.BodyEntered += RegisterHitEnnemy;
|
||||
Parrybox.BodyEntered += RegisterParry;
|
||||
|
||||
#region StateManagement
|
||||
|
||||
@@ -569,6 +575,8 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
HeadSystem.Init();
|
||||
HeadSystem.HitboxActivated += OnHitboxActivated;
|
||||
HeadSystem.HitboxDeactivated += OnHitboxDeactivated;
|
||||
HeadSystem.ParryboxActivated += OnParryboxActivated;
|
||||
HeadSystem.ParryboxDeactivated += OnParryboxDeactivated;
|
||||
HeadSystem.StepFoot += OnFootStepped;
|
||||
HeadSystem.DeathAnimationFinished += OnDeathAnimationFinished;
|
||||
|
||||
@@ -1150,6 +1158,9 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
|
||||
var wallHugContactPoint = _onWallRunning.Active ? _currentWallContactPoint : Vector3.Zero;
|
||||
var moveInput = GetGlobalMoveInput();
|
||||
|
||||
WeaponHitbox.SetRotation(HeadSystem.GetGlobalLookRotation());
|
||||
Parrybox.SetRotation(HeadSystem.GetGlobalLookRotation());
|
||||
|
||||
if (_isUsingGamepad)
|
||||
inputLookDir += ComputeAimAssist();
|
||||
@@ -2125,7 +2136,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
if (!HasParry) return;
|
||||
|
||||
var attackToDo = _isEnemyInDashAttackRange ? "dash_parry" : "standard_parry";
|
||||
_playerState.SendEvent(attackToDo);
|
||||
_playerState.SendEvent("standard_parry");
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
@@ -2579,14 +2590,49 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
WeaponHitbox.Monitoring = false;
|
||||
TriggerDamage();
|
||||
}
|
||||
|
||||
public void OnParryboxActivated()
|
||||
{
|
||||
Parrybox.Monitoring = true;
|
||||
}
|
||||
public void OnParryboxDeactivated()
|
||||
{
|
||||
Parrybox.Monitoring = false;
|
||||
TriggerParry();
|
||||
}
|
||||
|
||||
public void RegisterHitEnnemy(Node3D body)
|
||||
{
|
||||
if (body is not IForgeEntity entity) return;
|
||||
_hitEnemies.Add(entity);
|
||||
// return;
|
||||
// if (body is not IDamageable damageable) return;
|
||||
// _hitEnemies.Add(damageable);
|
||||
}
|
||||
public void RegisterParry(Node3D body)
|
||||
{
|
||||
if (body is not IForgeEntity entity) return;
|
||||
_parriedEntities.Add(entity);
|
||||
// TriggerParry();
|
||||
}
|
||||
|
||||
public void TriggerParry()
|
||||
{
|
||||
var payload = new OnProjectileSpawned(
|
||||
Direction: -HeadSystem.GetGlobalForwardVector(),
|
||||
SpeedMultiplier: 100,
|
||||
SpawnOffset: -HeadSystem.GetGlobalForwardVector(),
|
||||
CollisionOverride: WeaponSystem.CollisionMask);
|
||||
foreach (var entity in _parriedEntities.Where(entity => IsInstanceValid(entity as Node)))
|
||||
{
|
||||
Events.Raise(new EventData<OnProjectileSpawned>
|
||||
{
|
||||
EventTags = Tag.RequestTag(TagsManager, "events.player.parry").GetSingleTagContainer()!,
|
||||
Source = this,
|
||||
Payload = payload
|
||||
});
|
||||
|
||||
if (entity is IKillable killable) killable.Kill();
|
||||
else if (entity is Node node) node.QueueFree();
|
||||
}
|
||||
_parriedEntities.Clear();
|
||||
}
|
||||
|
||||
public void TriggerDamage()
|
||||
|
||||
Reference in New Issue
Block a user