From 95b2259eb4d7362b137d26037f8312b3d80f0244 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sat, 29 Jul 2023 02:55:08 +0100 Subject: Add fall damage --- code/pawn/component/movement/PlayerController.cs | 12 +++++++++++- code/phase/PlayPhase.cs | 16 +++++++++++----- code/phase/WaitPhase.cs | 15 ++++++++++----- code/ui/health/Health.razor | 13 ++++++++++--- 4 files changed, 42 insertions(+), 14 deletions(-) (limited to 'code') diff --git a/code/pawn/component/movement/PlayerController.cs b/code/pawn/component/movement/PlayerController.cs index 885bf84..2c9a9b9 100644 --- a/code/pawn/component/movement/PlayerController.cs +++ b/code/pawn/component/movement/PlayerController.cs @@ -36,8 +36,18 @@ public class PlayerController : EntityComponent { if ( !Grounded ) { - Entity.Velocity = Entity.Velocity.WithZ( 0 ); + var zVel = Entity.Velocity.z; AddEvent( "grounded" ); + Entity.Velocity = Entity.Velocity.WithZ( 0 ); + + if (zVel < -500) + { + var damageInfo = DamageInfo.Generic( Math.Abs((float)(zVel * 0.05)) ); + Entity.TakeDamage( damageInfo ); + Entity.PlaySound( "fall" ); + return; + } + } var sprintMultiplier = TeamOperations.CanSprint( team ) ? (Input.Down( "run" ) ? 2.5f : 1f) : 1f; diff --git a/code/phase/PlayPhase.cs b/code/phase/PlayPhase.cs index b6210b3..8b4ff7f 100644 --- a/code/phase/PlayPhase.cs +++ b/code/phase/PlayPhase.cs @@ -98,18 +98,24 @@ public class PlayPhase : BasePhase [MurderEvent.Kill] public void OnKill(Entity killer, Entity victim) { - if (killer == null || killer is not Player || victim == null || victim is not Player ) + if (killer is not Player && victim is not Player ) { return; } Player victimPlayer = (Player)victim; - Player killerPlayer = (Player)killer; - Team victimTeam = victimPlayer.CurrentTeam; - Team killerTeam = killerPlayer.CurrentTeam; - victimPlayer.CurrentTeam = Team.Spectator; + if (killer == null) + { + Log.Info( victimPlayer + " died mysteriously" ); + return; + } + + + Player killerPlayer = (Player)killer; + Team killerTeam = killerPlayer.CurrentTeam; + Log.Info( victimPlayer + " died to " + killerPlayer ); if (victimTeam != Team.Murderer && killerTeam != Team.Murderer) diff --git a/code/phase/WaitPhase.cs b/code/phase/WaitPhase.cs index 9eab094..6014467 100644 --- a/code/phase/WaitPhase.cs +++ b/code/phase/WaitPhase.cs @@ -52,21 +52,26 @@ public class WaitPhase : BasePhase pawn.Transform = tx; } - pawn.CurrentTeam = Team.Bystander; pawn.Spawn(); - pawn.Respawn(); + RespawnPlayer( pawn ); } else { var pawn = (Player)client.Pawn; - if (pawn.LifeState == LifeState.Dead) + if (pawn.LifeState == LifeState.Dead && pawn.TimeSinceDeath > 3) { - pawn.CurrentTeam = Team.Bystander; - pawn.Respawn(); + RespawnPlayer( pawn ); } } } } + private void RespawnPlayer(Player pawn) + { + pawn.CurrentTeam = Team.Spectator; + pawn.DressFromClient( pawn.Client ); + pawn.Respawn(); + } + public override void HandleClientJoin( ClientJoinedEvent e ) { diff --git a/code/ui/health/Health.razor b/code/ui/health/Health.razor index 3da2c01..c3c6660 100644 --- a/code/ui/health/Health.razor +++ b/code/ui/health/Health.razor @@ -10,12 +10,19 @@ Health { height: 100%; background-color: rgba(0, 0, 0, 0.90); } -.fill { +.colour-bar { height: 100%; - transition: width 0.2s ease-out; +} +.transition-bar { + height: 100%; + transition: width 1s ease-out 0.5s; + position: absolute; + top: 0; + left: 0; } -
+
+
@code { -- cgit v1.2.3-70-g09d2