From 0bba89a7858ce091f485e04284f853e1f7f304af Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sun, 6 Aug 2023 17:21:45 +0100 Subject: Reformat --- code/entity/DroppedWeapon.cs | 68 ++++++++++++++++++++++++++------------------ code/entity/Footprint.cs | 36 ++++++++++++----------- 2 files changed, 59 insertions(+), 45 deletions(-) (limited to 'code/entity') diff --git a/code/entity/DroppedWeapon.cs b/code/entity/DroppedWeapon.cs index c540759..46cf67d 100644 --- a/code/entity/DroppedWeapon.cs +++ b/code/entity/DroppedWeapon.cs @@ -1,14 +1,12 @@ -using MurderGame; +using System; +using MurderGame; using Sandbox; -using System; using Sandbox.Component; +using Player = MurderGame.Player; -public partial class DroppedWeapon : AnimatedEntity, IUse +public class DroppedWeapon : AnimatedEntity, IUse { - private int Ammo { get; } - private Type WeaponType { get; } - - public DroppedWeapon(Weapon weapon) : this() + public DroppedWeapon( Weapon weapon ) : this() { Ammo = weapon.Ammo; WeaponType = weapon.GetType(); @@ -16,49 +14,63 @@ public partial class DroppedWeapon : AnimatedEntity, IUse public DroppedWeapon() { - Tags.Add("droppedweapon"); - + Tags.Add( "droppedweapon" ); + var glow = Components.GetOrCreate(); glow.Enabled = true; glow.Width = 0.25f; - glow.Color = new Color( 4f, 50.0f, 70.0f, 1.0f ); - glow.ObscuredColor = new Color( 0, 0, 0, 0); - + glow.Color = new Color( 4f, 50.0f, 70.0f ); + glow.ObscuredColor = new Color( 0, 0, 0, 0 ); + PhysicsEnabled = true; UsePhysicsCollision = true; EnableSelfCollisions = true; EnableSolidCollisions = true; } + private int Ammo { get; } + private Type WeaponType { get; } + + public bool OnUse( Entity user ) + { + if ( user is not Player player ) + { + return false; + } + + Pickup( player ); + return false; + } + + public bool IsUsable( Entity user ) + { + return user is Player { Inventory: { PrimaryWeapon: null, AllowPickup: true } }; + } + public override void StartTouch( Entity other ) { - if ( !Game.IsServer ) return; - if ( !other.Tags.Has( "livingplayer" ) ) return; + if ( !Game.IsServer ) + { + return; + } - var player = (MurderGame.Player)other; + if ( !other.Tags.Has( "livingplayer" ) ) + { + return; + } + + var player = (Player)other; if ( IsUsable( player ) ) { Pickup( player ); } } - public void Pickup( MurderGame.Player player ) + public void Pickup( Player player ) { var instance = TypeLibrary.Create( WeaponType ); instance.Ammo = Ammo; player.Inventory.SetPrimaryWeapon( instance ); Delete(); } - - public bool OnUse( Entity user ) - { - if ( user is not MurderGame.Player player ) return false; - Pickup( player ); - return false; - } - - public bool IsUsable( Entity user ) - { - return user is MurderGame.Player { Inventory: { PrimaryWeapon: null, AllowPickup: true } }; - } } diff --git a/code/entity/Footprint.cs b/code/entity/Footprint.cs index 8941e95..f4b988d 100644 --- a/code/entity/Footprint.cs +++ b/code/entity/Footprint.cs @@ -1,25 +1,24 @@ using System; +using Sandbox; namespace MurderGame; -using Sandbox; // It's just a square with a material slapped onto it. public class Footprint : RenderEntity { + private readonly TimeSince TimeSinceCreated = 0; public Material SpriteMaterial { get; set; } public float SpriteScale { get; set; } = 18f; public bool Enabled { get; set; } = true; - + public Color Color { get; set; } - private TimeSince TimeSinceCreated = 0; - [GameEvent.Tick.Client] public void OnTick() { - if ( !(TimeSinceCreated > Math.Clamp(MurderGame.MaxFootprintTime, 0, 30)) ) + if ( !(TimeSinceCreated > Math.Clamp( MurderGame.MaxFootprintTime, 0, 30 )) ) { return; } @@ -27,28 +26,31 @@ public class Footprint : RenderEntity Enabled = false; Delete(); } - - public override void DoRender(SceneObject obj) + + public override void DoRender( SceneObject obj ) { - if (!Enabled) return; + if ( !Enabled ) + { + return; + } // Allow lights to affect the sprite - Graphics.SetupLighting(obj); + Graphics.SetupLighting( obj ); // Create the vertex buffer for the sprite var vb = new VertexBuffer(); - vb.Init(true); + vb.Init( true ); // Vertex buffers are in local space, so we need the camera position in local space too var normal = new Vector3( 0, 0.01f, 100 ); - var w = normal.Cross(Vector3.Down).Normal; - var h = normal.Cross(w).Normal; - float halfSpriteSize = SpriteScale / 2; + var w = normal.Cross( Vector3.Down ).Normal; + var h = normal.Cross( w ).Normal; + var halfSpriteSize = SpriteScale / 2; // Add a single quad to our vertex buffer - vb.AddQuad(new Ray(default, normal), halfSpriteSize*w, h*halfSpriteSize); - - Graphics.Attributes.Set( "color", Color); - + vb.AddQuad( new Ray( default, normal ), halfSpriteSize * w, h * halfSpriteSize ); + + Graphics.Attributes.Set( "color", Color ); + // Draw the sprite vb.Draw( SpriteMaterial ); } -- cgit v1.2.3-70-g09d2