gd: basic weapon and readability refacto
This commit is contained in:
@ -18,7 +18,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
public HealthSystem HealthSystem;
|
||||
public MoveSystem MoveSystem;
|
||||
public TweenQueueSystem TweenQueueSystem;
|
||||
public StateChart PlayerState;
|
||||
public Node3D WeaponRoot;
|
||||
public WeaponSystem WeaponSystem;
|
||||
|
||||
private bool _movementEnabled = true;
|
||||
|
||||
@ -38,82 +39,89 @@ public partial class PlayerController : CharacterBody3D
|
||||
private bool _isAiming;
|
||||
private bool _dashCanceled;
|
||||
|
||||
private StateChart _playerState;
|
||||
private StateChartState _weaponInHand;
|
||||
private StateChartState _aiming;
|
||||
private StateChartState _dashing;
|
||||
private StateChartState _weaponThrown;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
///////////////////////////
|
||||
// Getting components /////
|
||||
///////////////////////////
|
||||
|
||||
// General use stuff
|
||||
TweenQueueSystem = GetNode<TweenQueueSystem>("TweenQueueSystem");
|
||||
// Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D;
|
||||
|
||||
// Camera stuff
|
||||
HeadSystem = GetNode<HeadSystem>("HeadSystem");
|
||||
Bobbing = GetNode<Bobbing>("Bobbing");
|
||||
FieldOfView = GetNode<FieldOfView>("FieldOfView");
|
||||
Camera3D camera = GetNode<Camera3D>("HeadSystem/CameraSmooth/Camera3D");
|
||||
Node3D cameraSmooth = GetNode<Node3D>("HeadSystem/CameraSmooth");
|
||||
ColorRect vignetteRect = GetNode<ColorRect>(
|
||||
"HeadSystem/CameraSmooth/Camera3D/CLVignette(Layer_1)/HealthVignetteRect");
|
||||
ColorRect distortionRect = GetNode<ColorRect>(
|
||||
"HeadSystem/CameraSmooth/Camera3D/CLDistortion(Layer_2)/HealthDistortionRect");
|
||||
ColorRect blurRect = GetNode<ColorRect>("HeadSystem/CameraSmooth/Camera3D/CLBlur(Layer_2)/BlurRect");
|
||||
|
||||
// Movement stuff
|
||||
WeaponRoot = GetNode<Node3D>("WeaponRoot");
|
||||
WeaponSystem = GetNode<WeaponSystem>("WeaponRoot/WeaponSystem");
|
||||
MantleSystem = GetNode<MantleSystem>("MantleSystem");
|
||||
CapsuleCollider = GetNode<CapsuleCollider>("CapsuleCollider");
|
||||
Gravity = GetNode<Gravity>("Gravity");
|
||||
MoveSystem = GetNode<MoveSystem>("MoveSystem");
|
||||
DashSystem = GetNode<DashSystem>("DashSystem");
|
||||
StairsSystem = GetNode<StairsSystem>("StairsSystem");
|
||||
RayCast3D stairsBelowRayCast3D = GetNode<RayCast3D>("StairsBelowRayCast3D");
|
||||
RayCast3D stairsAheadRayCast3D = GetNode<RayCast3D>("StairsAheadRayCast3D");
|
||||
_headCollisionDetectors = new RayCast3D[NUM_OF_HEAD_COLLISION_DETECTORS];
|
||||
for (int i = 0; i < NUM_OF_HEAD_COLLISION_DETECTORS; i++)
|
||||
{
|
||||
_headCollisionDetectors[i] = GetNode<RayCast3D>(
|
||||
"HeadCollisionDetectors/HeadCollisionDetector" + i);
|
||||
}
|
||||
|
||||
// RPG Stuff
|
||||
Stamina = GetNode<Stamina>("Stamina");
|
||||
HealthSystem = GetNode<HealthSystem>("HealthSystem");
|
||||
|
||||
// State management
|
||||
_playerState = StateChart.Of(GetNode("StateChart"));
|
||||
_weaponInHand = StateChartState.Of(GetNode("StateChart/Root/WeaponInHand"));
|
||||
_aiming = StateChartState.Of(GetNode("StateChart/Root/Aiming"));
|
||||
_dashing = StateChartState.Of(GetNode("StateChart/Root/Dashing"));
|
||||
_weaponThrown = StateChartState.Of(GetNode("StateChart/Root/WeaponThrown"));
|
||||
|
||||
///////////////////////////
|
||||
// Initialize components //
|
||||
///////////////////////////
|
||||
|
||||
// General use stuff
|
||||
TweenQueueSystem.Init(this);
|
||||
|
||||
HeadSystem = GetNode<HeadSystem>("HeadSystem");
|
||||
// Camera stuff
|
||||
HeadSystem.Init();
|
||||
Bobbing.Init(camera);
|
||||
FieldOfView.Init(camera);
|
||||
|
||||
// Get the state chart node and wrap it in a StateChart object like so, GetNode doesn't work
|
||||
PlayerState = StateChart.Of(GetNode("%StateChart"));
|
||||
|
||||
// Get the poisoned state node and wrap it in a State object, so we can easily
|
||||
// interact with it from C#.
|
||||
// _poisonedStateChartState = StateChartState.Of(GetNode("%Poisoned"));
|
||||
|
||||
// Getting dependencies of the components (In godot we manage this from upwards to downwards not vice versa)
|
||||
Camera3D camera = GetNode<Camera3D>("HeadSystem/CameraSmooth/Camera3D");
|
||||
Node3D cameraSmooth = GetNode<Node3D>("HeadSystem/CameraSmooth");
|
||||
|
||||
RayCast3D stairsBelowRayCast3D = GetNode<RayCast3D>("StairsBelowRayCast3D");
|
||||
RayCast3D stairsAheadRayCast3D = GetNode<RayCast3D>("StairsAheadRayCast3D");
|
||||
|
||||
// Movement stuff
|
||||
|
||||
// Getting universal setting from GODOT editor to be in sync
|
||||
float gravitySetting = (float)ProjectSettings.GetSetting("physics/3d/default_gravity");
|
||||
|
||||
ColorRect vignetteRect = GetNode<ColorRect>(
|
||||
"HeadSystem/CameraSmooth/Camera3D/CLVignette(Layer_1)/HealthVignetteRect");
|
||||
|
||||
ColorRect distortionRect = GetNode<ColorRect>(
|
||||
"HeadSystem/CameraSmooth/Camera3D/CLDistortion(Layer_2)/HealthDistortionRect");
|
||||
|
||||
ColorRect blurRect = GetNode<ColorRect>("HeadSystem/CameraSmooth/Camera3D/CLBlur(Layer_2)/BlurRect");
|
||||
|
||||
// Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D;
|
||||
|
||||
// Getting components
|
||||
|
||||
Bobbing = GetNode<Bobbing>("Bobbing");
|
||||
Bobbing.Init(camera);
|
||||
|
||||
FieldOfView = GetNode<FieldOfView>("FieldOfView");
|
||||
FieldOfView.Init(camera);
|
||||
|
||||
CapsuleCollider = GetNode<CapsuleCollider>("CapsuleCollider");
|
||||
|
||||
Gravity = GetNode<Gravity>("Gravity");
|
||||
Gravity.Init(gravitySetting);
|
||||
|
||||
MantleSystem = GetNode<MantleSystem>("MantleSystem");
|
||||
MantleSystem.Init(HeadSystem);
|
||||
|
||||
TweenQueueSystem = GetNode<TweenQueueSystem>("TweenQueueSystem");
|
||||
TweenQueueSystem.Init(this);
|
||||
|
||||
MoveSystem = GetNode<MoveSystem>("MoveSystem");
|
||||
var moveSystemParams = new MoveSystem.MoveSystemParameters(this, Gravity, MantleSystem, TweenQueueSystem,
|
||||
HeadSystem, CapsuleCollider);
|
||||
MoveSystem.Init(moveSystemParams);
|
||||
|
||||
Stamina = GetNode<Stamina>("Stamina");
|
||||
Stamina.SetSpeeds(MoveSystem.WalkSpeed, MoveSystem.SprintSpeed);
|
||||
|
||||
StairsSystem = GetNode<StairsSystem>("StairsSystem");
|
||||
StairsSystem.Init(stairsBelowRayCast3D, stairsAheadRayCast3D, cameraSmooth);
|
||||
|
||||
DashSystem = GetNode<DashSystem>("DashSystem");
|
||||
DashSystem.Init(HeadSystem, camera, TweenQueueSystem);
|
||||
DashSystem.DashEnded += OnDashEnded;
|
||||
|
||||
HealthSystem = GetNode<HealthSystem>("HealthSystem");
|
||||
WeaponSystem.Init(HeadSystem, camera, TweenQueueSystem);
|
||||
|
||||
// RPG Stuff
|
||||
HealthSystem.HealthSystemInitParams healthSystemParams = new HealthSystem.HealthSystemInitParams()
|
||||
{
|
||||
Gravity = Gravity,
|
||||
@ -125,6 +133,28 @@ public partial class PlayerController : CharacterBody3D
|
||||
BlurRect = blurRect,
|
||||
};
|
||||
HealthSystem.Init(healthSystemParams);
|
||||
Stamina.SetSpeeds(MoveSystem.WalkSpeed, MoveSystem.SprintSpeed);
|
||||
|
||||
///////////////////////////
|
||||
// Signal setup ///////////
|
||||
///////////////////////////
|
||||
|
||||
DashSystem.DashEnded += OnDashEnded;
|
||||
|
||||
_dashing.StateEntered += OnDashStarted;
|
||||
_weaponThrown.StateEntered += OnWeaponThrown;
|
||||
}
|
||||
|
||||
public void OnDashStarted()
|
||||
{
|
||||
DashSystem.Dash();
|
||||
}
|
||||
|
||||
public void OnWeaponThrown()
|
||||
{
|
||||
var (hasHit, location, collisionPoint, collisionNormal) = DashSystem.DashComputation;
|
||||
var (endWithMantle, dashLocation, mantleLocation) = DashSystem.DashResolve;
|
||||
var weaponThrowVector = dashLocation - Position;
|
||||
}
|
||||
|
||||
public void OnInputMove(Vector3 value)
|
||||
@ -144,30 +174,26 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
public void OnInputAimPressed()
|
||||
{
|
||||
PlayerState.SendEvent("aim_pressed");
|
||||
|
||||
if (_dashCanceled)
|
||||
return;
|
||||
|
||||
DashSystem.PrepareDash();
|
||||
_playerState.SendEvent("aim_pressed");
|
||||
}
|
||||
public void OnInputAimReleased()
|
||||
{
|
||||
PlayerState.SendEvent("aim_released");
|
||||
if (!_dashCanceled)
|
||||
DashSystem.Dash();
|
||||
_dashCanceled = false;
|
||||
_playerState.SendEvent("aim_released");
|
||||
}
|
||||
public void OnInputAimCanceled()
|
||||
{
|
||||
PlayerState.SendEvent("aim_canceled");
|
||||
_dashCanceled = true;
|
||||
_playerState.SendEvent("aim_canceled");
|
||||
DashSystem.CancelDash();
|
||||
}
|
||||
|
||||
public void OnInputHitPressed()
|
||||
{
|
||||
PlayerState.SendEvent("hit_pressed");
|
||||
_playerState.SendEvent("hit_pressed");
|
||||
}
|
||||
|
||||
public void OnDashEnded()
|
||||
{
|
||||
_playerState.SendEvent("dash_ended");
|
||||
}
|
||||
|
||||
public void OnInputJumpPressed()
|
||||
@ -178,19 +204,19 @@ public partial class PlayerController : CharacterBody3D
|
||||
if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead)
|
||||
MoveSystem.Jump(IsOnFloor());
|
||||
}
|
||||
|
||||
public void OnDashEnded()
|
||||
{
|
||||
PlayerState.SendEvent("dash_ended");
|
||||
}
|
||||
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
TweenQueueSystem.ProcessTweens();
|
||||
WeaponRoot.SetRotation(HeadSystem.Rotation);
|
||||
|
||||
var isPlayerDead = HealthSystem.IsDead();
|
||||
var isHeadTouchingCeiling = IsHeadTouchingCeiling();
|
||||
|
||||
TweenQueueSystem.ProcessTweens();
|
||||
|
||||
if (_aiming.Active)
|
||||
DashSystem.PrepareDash();
|
||||
|
||||
var moveAroundParams = new MoveSystem.MoveAroundParameters(
|
||||
delta,
|
||||
_inputMove,
|
||||
|
Reference in New Issue
Block a user