From 0bba89a7858ce091f485e04284f853e1f7f304af Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sun, 6 Aug 2023 17:21:45 +0100 Subject: Reformat --- code/weapon/Knife.cs | 16 +++---- code/weapon/Pistol.cs | 8 ++-- code/weapon/Weapon.cs | 103 +++++++++++++++++++++++++++-------------- code/weapon/WeaponViewModel.cs | 8 ++-- 4 files changed, 83 insertions(+), 52 deletions(-) (limited to 'code/weapon') diff --git a/code/weapon/Knife.cs b/code/weapon/Knife.cs index 8ff0bb2..b3bf7f8 100644 --- a/code/weapon/Knife.cs +++ b/code/weapon/Knife.cs @@ -4,23 +4,23 @@ namespace MurderGame; public partial class Knife : Weapon { - public override string ModelPath => "weapons/swb/melee/bayonet/w_bayonet.vmdl"; - public override string ViewModelPath => "weapons/swb/melee/bayonet/v_bayonet.vmdl"; - public override string HandsModelPath => "weapons/swb/hands/rebel/v_hands_rebel.vmdl"; - public override float PrimaryRate => 1.5f; - public Knife() { Ammo = -1; MaxAmmo = -1; } + public override string ModelPath => "weapons/swb/melee/bayonet/w_bayonet.vmdl"; + public override string ViewModelPath => "weapons/swb/melee/bayonet/v_bayonet.vmdl"; + public override string HandsModelPath => "weapons/swb/hands/rebel/v_hands_rebel.vmdl"; + public override float PrimaryRate => 1.5f; + [ClientRpc] - protected virtual void ShootEffects(bool hit) + protected virtual void ShootEffects( bool hit ) { Game.AssertClient(); - - ViewModelEntity?.SetAnimParameter( hit ? "swing" : "swing_miss" , true ); + + ViewModelEntity?.SetAnimParameter( hit ? "swing" : "swing_miss", true ); } public override void PrimaryAttack() diff --git a/code/weapon/Pistol.cs b/code/weapon/Pistol.cs index 4c0c70b..6358b10 100644 --- a/code/weapon/Pistol.cs +++ b/code/weapon/Pistol.cs @@ -4,14 +4,14 @@ namespace MurderGame; public partial class Pistol : Weapon { - public override string ModelPath => "weapons/rust_pistol/rust_pistol.vmdl"; - public override string ViewModelPath => "weapons/rust_pistol/v_rust_pistol.vmdl"; - public Pistol() { MaxAmmo = 1; } + public override string ModelPath => "weapons/rust_pistol/rust_pistol.vmdl"; + public override string ViewModelPath => "weapons/rust_pistol/v_rust_pistol.vmdl"; + [ClientRpc] protected virtual void ShootEffects() { @@ -25,7 +25,7 @@ public partial class Pistol : Weapon public override void PrimaryAttack() { - if (Ammo > 0) + if ( Ammo > 0 ) { --Ammo; ShootEffects(); diff --git a/code/weapon/Weapon.cs b/code/weapon/Weapon.cs index 8eafbc3..2ee5889 100644 --- a/code/weapon/Weapon.cs +++ b/code/weapon/Weapon.cs @@ -1,5 +1,5 @@ -using Sandbox; using System.Collections.Generic; +using Sandbox; namespace MurderGame; @@ -19,14 +19,14 @@ public partial class Weapon : AnimatedEntity public virtual float PrimaryRate => 5f; public virtual float ReloadTime => 3.5f; - [Net, Predicted] public TimeSince TimeSincePrimaryAttack { get; set; } + [Net] [Predicted] public TimeSince TimeSincePrimaryAttack { get; set; } - [Net, Predicted] public TimeSince TimeSinceReload { get; set; } - [Net, Predicted] public TimeUntil TimeUntilReloadComplete { get; set; } - [Net, Predicted] public bool Reloading { get; set; } + [Net] [Predicted] public TimeSince TimeSinceReload { get; set; } + [Net] [Predicted] public TimeUntil TimeUntilReloadComplete { get; set; } + [Net] [Predicted] public bool Reloading { get; set; } - [Net, Predicted] public int Ammo { get; set; } - [Net, Predicted] public int MaxAmmo { get; set; } + [Net] [Predicted] public int Ammo { get; set; } + [Net] [Predicted] public int MaxAmmo { get; set; } public override void Spawn() { @@ -48,11 +48,12 @@ public partial class Weapon : AnimatedEntity public void OnEquip( Player pawn ) { - if (Owner == null) + if ( Owner == null ) { Owner = pawn; SetParent( pawn, true ); } + EnableDrawing = true; CreateViewModel( To.Single( pawn ) ); } @@ -68,7 +69,7 @@ public partial class Weapon : AnimatedEntity public override void Simulate( IClient player ) { Animate(); - if (Reloading && TimeUntilReloadComplete) + if ( Reloading && TimeUntilReloadComplete ) { Reloading = false; Ammo = MaxAmmo; @@ -82,7 +83,7 @@ public partial class Weapon : AnimatedEntity PrimaryAttack(); } } - else if (Input.Down("reload") && !Reloading && Ammo != MaxAmmo) + else if ( Input.Down( "reload" ) && !Reloading && Ammo != MaxAmmo ) { Reload(); Reloading = true; @@ -92,12 +93,18 @@ public partial class Weapon : AnimatedEntity public virtual bool CanPrimaryAttack() { - if ( !Owner.IsValid() || !Input.Down( "attack1" ) ) return false; + if ( !Owner.IsValid() || !Input.Down( "attack1" ) ) + { + return false; + } var rate = PrimaryRate; - if ( rate <= 0 ) return true; + if ( rate <= 0 ) + { + return true; + } - return !Reloading && TimeSincePrimaryAttack > (1 / rate); + return !Reloading && TimeSincePrimaryAttack > 1 / rate; } public virtual void PrimaryAttack() @@ -114,24 +121,29 @@ public partial class Weapon : AnimatedEntity public virtual IEnumerable TraceBullet( Vector3 start, Vector3 end, float radius = 2.0f ) { - bool underWater = Trace.TestPoint( start, "water" ); + var underWater = Trace.TestPoint( start, "water" ); var trace = Trace.Ray( start, end ) - .UseHitboxes() - .WithAnyTags( "solid", "livingplayer", "npc" ) - .Ignore( this ) - .Size( radius ); + .UseHitboxes() + .WithAnyTags( "solid", "livingplayer", "npc" ) + .Ignore( this ) + .Size( radius ); if ( !underWater ) + { trace = trace.WithAnyTags( "water" ); + } var tr = trace.Run(); if ( tr.Hit ) + { yield return tr; + } } - public virtual void ShootBullet( Vector3 pos, Vector3 dir, float spread, float force, float damage, float bulletSize ) + public virtual void ShootBullet( Vector3 pos, Vector3 dir, float spread, float force, float damage, + float bulletSize ) { var forward = dir; forward += (Vector3.Random + Vector3.Random + Vector3.Random + Vector3.Random) * spread * 0.25f; @@ -141,8 +153,15 @@ public partial class Weapon : AnimatedEntity { tr.Surface.DoBulletImpact( tr ); - if ( !Game.IsServer ) continue; - if ( !tr.Entity.IsValid() || !tr.Entity.Tags.Has("player") ) continue; + if ( !Game.IsServer ) + { + continue; + } + + if ( !tr.Entity.IsValid() || !tr.Entity.Tags.Has( "player" ) ) + { + continue; + } using ( Prediction.Off() ) { @@ -163,32 +182,40 @@ public partial class Weapon : AnimatedEntity var ray = Owner.AimRay; ShootBullet( ray.Position, ray.Forward, 0, force, damage, bulletSize ); } - + public virtual bool Melee( float force, float damage ) { var ray = Owner.AimRay; var forward = ray.Forward.Normal; var pos = ray.Position; - bool hit = false; + var hit = false; - foreach (var tr in TraceBullet(pos, pos + forward * 80, 20)) + foreach ( var tr in TraceBullet( pos, pos + forward * 80, 20 ) ) { - tr.Surface.DoBulletImpact(tr); + tr.Surface.DoBulletImpact( tr ); hit = true; - if ( !Game.IsServer ) continue; - if ( !tr.Entity.IsValid() || !tr.Entity.Tags.Has("player") ) continue; + if ( !Game.IsServer ) + { + continue; + } + + if ( !tr.Entity.IsValid() || !tr.Entity.Tags.Has( "player" ) ) + { + continue; + } - using (Prediction.Off()) + using ( Prediction.Off() ) { var damageInfo = DamageInfo.FromBullet( tr.EndPosition, forward.Normal * 100 * force, damage ) - .UsingTraceResult(tr) - .WithAttacker(Owner) - .WithWeapon(this); + .UsingTraceResult( tr ) + .WithAttacker( Owner ) + .WithWeapon( this ); - tr.Entity.TakeDamage(damageInfo); + tr.Entity.TakeDamage( damageInfo ); } } + return hit; } @@ -196,7 +223,10 @@ public partial class Weapon : AnimatedEntity public void CreateViewModel() { DestroyViewModel(); - if ( ViewModelPath == null ) return; + if ( ViewModelPath == null ) + { + return; + } var vm = new WeaponViewModel( this ); vm.Model = Model.Load( ViewModelPath ); @@ -204,13 +234,13 @@ public partial class Weapon : AnimatedEntity vm.Parent = Game.LocalPawn; vm.SetAnimParameter( "deploy", true ); ViewModelEntity = vm; - if (!string.IsNullOrEmpty(HandsModelPath)) + if ( !string.IsNullOrEmpty( HandsModelPath ) ) { HandModelEntity = new BaseViewModel(); HandModelEntity.Owner = Owner; HandModelEntity.EnableViewmodelRendering = true; - HandModelEntity.SetModel(HandsModelPath); - HandModelEntity.SetParent(ViewModelEntity, true); + HandModelEntity.SetModel( HandsModelPath ); + HandModelEntity.SetParent( ViewModelEntity, true ); } } @@ -221,6 +251,7 @@ public partial class Weapon : AnimatedEntity { ViewModelEntity.Delete(); } + if ( HandModelEntity.IsValid() ) { HandModelEntity.Delete(); diff --git a/code/weapon/WeaponViewModel.cs b/code/weapon/WeaponViewModel.cs index 97004fe..a42a6a3 100644 --- a/code/weapon/WeaponViewModel.cs +++ b/code/weapon/WeaponViewModel.cs @@ -2,10 +2,8 @@ using Sandbox; namespace MurderGame; -public partial class WeaponViewModel : BaseViewModel +public class WeaponViewModel : BaseViewModel { - protected Weapon Weapon { get; init; } - public WeaponViewModel( Weapon weapon ) { Weapon = weapon; @@ -13,10 +11,12 @@ public partial class WeaponViewModel : BaseViewModel EnableViewmodelRendering = true; } + protected Weapon Weapon { get; init; } + public override void PlaceViewmodel() { base.PlaceViewmodel(); - Camera.Main.SetViewModelCamera( 80f, 1, 500 ); + Camera.Main.SetViewModelCamera( 80f ); } } -- cgit v1.2.3-70-g09d2