{"TotalCount":504,"Files":[{"Ident":"facepunch.sandbox","Path":"Builder/BuilderCatalog.cs","FileName":"BuilderCatalog.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"namespace Sandbox;\r\n\r\n/// \u003Csummary\u003EDeterministic, bounded recipes shared by the menu, host, clients and saved games.\u003C/summary\u003E\r\npublic static class BuilderCatalog\r\n{\r\n\tpublic const float Unit = 96f;\r\n\tpublic const string DefaultMaterial = \u0022materials/construction/tiles/generic_tiles.vmat\u0022;\r\n\tpublic static readonly string[] Categories = [\u0022Cubes\u0022, \u0022Plates\u0022, \u0022Triangles\u0022, \u0022Tubes\u0022, \u0022Misc\u0022];\r\n\tpublic enum Shape\r\n\t{\r\n\t\t[Title( \u0022#builder.shape.box\u0022 )] Box,\r\n\t\t[Title( \u0022#builder.shape.boxframe\u0022 )] BoxFrame,\r\n\t\t[Title( \u0022#builder.shape.triangle\u0022 )] Triangle,\r\n\t\t[Title( \u0022#builder.shape.carved\u0022 )] Carved,\r\n\t\t[Title( \u0022#builder.shape.trapezium\u0022 )] Trapezium,\r\n\t\t[Title( \u0022#builder.shape.tube\u0022 )] Tube,\r\n\t\t[Title( \u0022#builder.shape.halfpipe\u0022 )] HalfPipe,\r\n\t\t[Title( \u0022#builder.shape.ring\u0022 )] Ring,\r\n\t\t[Title( \u0022#builder.shape.bend\u0022 )] Bend,\r\n\t\t[Title( \u0022#builder.shape.platehole\u0022 )] PlateHole,\r\n\t\t[Title( \u0022#builder.shape.cone\u0022 )] Cone,\r\n\t\t[Title( \u0022#builder.shape.mirroredcone\u0022 )] MirroredCone,\r\n\t\t[Title( \u0022#builder.shape.sphere\u0022 )] Sphere,\r\n\t\t[Title( \u0022#builder.shape.dome\u0022 )] Dome,\r\n\t\t[Title( \u0022#builder.shape.quarterdome\u0022 )] QuarterDome,\r\n\t\t[Title( \u0022#builder.shape.stairs\u0022 )] Stairs,\r\n\t\t[Title( \u0022#builder.shape.parallelogram\u0022 )] Parallelogram,\r\n\t\t[Title( \u0022#builder.shape.pentagon\u0022 )] Pentagon\r\n\t}\r\n\tpublic sealed record Piece( string Id, string Category, Shape Kind, Vector3 Size, float Angle = 0 );\r\n\tpublic static IReadOnlyList\u003CPiece\u003E All { get; } = Generate();\r\n\tstatic readonly Dictionary\u003Cstring, Piece\u003E ById = All.ToDictionary( x =\u003E x.Id );\r\n\tpublic static Piece Find( string id ) =\u003E id is not null \u0026\u0026 ById.TryGetValue( id, out var piece ) ? piece : null;\r\n\r\n\tstatic List\u003CPiece\u003E Generate()\r\n\t{\r\n\t\tvar pieces = new List\u003CPiece\u003E();\r\n\t\tstring N( float n ) =\u003E n switch { 0.25f =\u003E \u0022025\u0022, 0.5f =\u003E \u002205\u0022, _ =\u003E n.ToString( \u00220.###\u0022, System.Globalization.CultureInfo.InvariantCulture ) };\r\n\t\tvoid Add( string id, string category, Shape shape, float x, float y, float z, float angle = 0 )\r\n\t\t\t=\u003E pieces.Add( new( id, category, shape, new Vector3( x, y, z ), angle ) );\r\n\t\tfloat[] sizes = [0.25f, 0.5f, 1, 2, 3, 4, 8];\r\n\t\tforeach ( var x in sizes )\r\n\t\tforeach ( var y in sizes.Where( y =\u003E y \u003E= x ) )\r\n\t\tforeach ( var z in sizes.Where( z =\u003E z \u003C= x ) )\r\n\t\t\tAdd( $\u0022{N(x)}x{N(y)}x{N(z)}\u0022, \u0022Cubes\u0022, Shape.Box, x, y, z );\r\n\t\tforeach ( var x in sizes )\r\n\t\tforeach ( var y in sizes.Where( y =\u003E y \u003E= x ) )\r\n\t\tforeach ( var z in new[] { 0.0625f, 0.125f } )\r\n\t\t\tAdd( $\u0022plate{N(x)}x{N(y)}{(z \u003C 0.1f ? \u0022a\u0022 : \u0022b\u0022)}\u0022, \u0022Plates\u0022, Shape.Box, x, y, z );\r\n\t\tforeach ( var s in sizes.Where( s =\u003E s \u003E= 0.5f ) )\r\n\t\t\tAdd( $\u0022frame{N(s)}x{N(s)}x{N(s)}\u0022, \u0022Cubes\u0022, Shape.BoxFrame, s, s, s );\r\n\t\tforeach ( var s in sizes )\r\n\t\t{\r\n\t\t\tAdd( $\u0022triangle{N(s)}x{N(s)}\u0022, \u0022Triangles\u0022, Shape.Triangle, s, s, 0.25f );\r\n\t\t\tforeach ( var depth in new[] { 0.25f, 0.5f, 1f }.Where( d =\u003E d \u003C= s ) )\r\n\t\t\t{\r\n\t\t\t\tAdd( $\u0022triangle{N(s)}x{N(s)}x{N(depth)}\u0022, \u0022Triangles\u0022, Shape.Triangle, s, s, depth );\r\n\t\t\t\tAdd( $\u0022trapezium{N(s)}x{N(s)}x{N(depth)}\u0022, \u0022Triangles\u0022, Shape.Trapezium, s, s, depth );\r\n\t\t\t}\r\n\t\t\tif ( s \u003E= 1 ) Add( $\u0022{N(s)}x{N(s)}x1carved025\u0022, \u0022Triangles\u0022, Shape.Carved, s, s, 1 );\r\n\t\t\tforeach ( var length in new[] { 0.25f, 0.5f, 1, 2, 3, 4, 5, 8 } )\r\n\t\t\t{\r\n\t\t\t\tAdd( $\u0022tube{N(s)}x{N(s)}x{N(length)}\u0022, \u0022Tubes\u0022, Shape.Tube, s, s, length );\r\n\t\t\t\tAdd( $\u0022tube{N(s)}x{N(s)}x{N(length)}c\u0022, \u0022Tubes\u0022, Shape.HalfPipe, s, s, length );\r\n\t\t\t}\r\n\t\t\tAdd( $\u0022platehole{N(s)}x{N(s)}a\u0022, \u0022Tubes\u0022, Shape.PlateHole, s, s, 0.125f );\r\n\t\t\tAdd( $\u0022circle{N(s)}x{N(s)}b\u0022, \u0022Tubes\u0022, Shape.Ring, s, s, 0.125f );\r\n\t\t\tforeach ( var angle in new[] { 45, 90, 180 } )\r\n\t\t\t\tAdd( $\u0022tubebend{N(s)}x{N(s)}x{angle}\u0022, \u0022Tubes\u0022, Shape.Bend, s, s, 1, angle );\r\n\t\t\tforeach ( var height in new[] { s / 2, s }.Where( h =\u003E h \u003E= 0.25f ) )\r\n\t\t\t{\r\n\t\t\t\tAdd( $\u0022cone{N(s)}x{N(height)}\u0022, \u0022Misc\u0022, Shape.Cone, s, s, height );\r\n\t\t\t\tAdd( $\u0022cone{N(s)}x{N(height)}mirrored\u0022, \u0022Misc\u0022, Shape.MirroredCone, s, s, height );\r\n\t\t\t}\r\n\t\t\tAdd( $\u0022sphere{N(s)}x{N(s)}\u0022, \u0022Misc\u0022, Shape.Sphere, s, s, s );\r\n\t\t\tAdd( $\u0022shell{N(s)}x{N(s)}a\u0022, \u0022Misc\u0022, Shape.Dome, s, s, s / 2 );\r\n\t\t\tAdd( $\u0022shell{N(s)}x{N(s)}c\u0022, \u0022Misc\u0022, Shape.QuarterDome, s, s, s / 2 );\r\n\t\t\tAdd( $\u0022stair{N(s)}x{N(s)}x{N(s)}\u0022, \u0022Misc\u0022, Shape.Stairs, s, s, s );\r\n\t\t\tAdd( $\u0022para{N(s)}x{N(s)}x1\u0022, \u0022Misc\u0022, Shape.Parallelogram, s, s, 1 );\r\n\t\t\tAdd( $\u0022pent{N(s)}x{N(s)}x1\u0022, \u0022Misc\u0022, Shape.Pentagon, s, s, 1 );\r\n\t\t}\r\n\t\treturn pieces;\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Game/BanSystem/BanSystem.cs","FileName":"BanSystem.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"/// \u003Csummary\u003E\r\n/// Holds a banlist, can ban users\r\n/// \u003C/summary\u003E\r\ninternal sealed class BanSystem : GameObjectSystem\u003CBanSystem\u003E, Component.INetworkListener\r\n{\r\n\tpublic record struct BanEntry( string DisplayName, string Reason );\r\n\r\n\tprivate Dictionary\u003Clong, BanEntry\u003E _bans = new();\r\n\r\n\tpublic BanSystem( Scene scene ) : base( scene )\r\n\t{\r\n\t\t_bans = LocalData.Get\u003CDictionary\u003Clong, BanEntry\u003E\u003E( \u0022bans\u0022, new() ) ?? new();\r\n\t}\r\n\r\n\tbool Component.INetworkListener.AcceptConnection( Connection connection, ref string reason )\r\n\t{\r\n\t\tif ( !_bans.TryGetValue( connection.SteamId, out var entry ) )\r\n\t\t\treturn true;\r\n\r\n\t\treason = $\u0022You\u0027re banned from this server: {entry.Reason}\u0022;\r\n\t\treturn false;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Bans a connected player and kicks them immediately\r\n\t/// \u003C/summary\u003E\r\n\tpublic void Ban( Connection connection, string reason )\r\n\t{\r\n\t\tAssert.True( Networking.IsHost, \u0022Only the host may ban players.\u0022 );\r\n\r\n\t\tvar e = new AdminActionEvent { Action = AdminAction.Ban, SteamId = connection.SteamId, Value = reason };\r\n\t\tif ( !e.Run() ) return;\r\n\t\treason = e.Value;\r\n\r\n\t\t_bans[connection.SteamId] = new BanEntry( connection.DisplayName, reason );\r\n\t\tSave();\r\n\r\n\t\tGameManager.Current.NotifyLocalized( \u0022#server.player_banned\u0022, new()\r\n\t\t{\r\n\t\t\t{ \u0022name\u0022, LocalizedText.Literal( connection.DisplayName ) },\r\n\t\t\t{ \u0022reason\u0022, LocalizedText.Literal( reason ) }\r\n\t\t} );\r\n\r\n\t\tconnection.Kick( $\u0022Banned: {reason}\u0022 );\r\n\t\te.Done();\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Bans a Steam ID by value. Use for pre-banning or banning players who are not currently connected.\r\n\t/// Display name falls back to the Steam ID string.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void Ban( SteamId steamId, string reason )\r\n\t{\r\n\t\tAssert.True( Networking.IsHost, \u0022Only the host may ban players.\u0022 );\r\n\r\n\t\tvar e = new AdminActionEvent { Action = AdminAction.Ban, SteamId = steamId, Value = reason };\r\n\t\tif ( !e.Run() ) return;\r\n\r\n\t\t_bans[steamId] = new BanEntry( steamId.ToString(), e.Value );\r\n\t\tSave();\r\n\t\te.Done();\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Removes the ban for the given Steam ID.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void Unban( SteamId steamId )\r\n\t{\r\n\t\tAssert.True( Networking.IsHost, \u0022Only the host may unban players.\u0022 );\r\n\r\n\t\tvar e = new AdminActionEvent { Action = AdminAction.Unban, SteamId = steamId };\r\n\t\tif ( !e.Run() ) return;\r\n\r\n\t\tif ( _bans.Remove( steamId ) )\r\n\t\t\tSave();\r\n\r\n\t\te.Done();\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Returns true if the given Steam ID is currently banned\r\n\t/// \u003C/summary\u003E\r\n\tpublic bool IsBanned( SteamId steamId ) =\u003E _bans.ContainsKey( steamId );\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Returns a read-only view of all active bans\r\n\t/// \u003C/summary\u003E\r\n\tpublic IReadOnlyDictionary\u003CSteamId, BanEntry\u003E GetBannedList() =\u003E _bans.ToDictionary( x =\u003E (SteamId)x.Key, x =\u003E x.Value );\r\n\r\n\tprivate void Save() =\u003E LocalData.Set( \u0022bans\u0022, _bans );\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// RPC to ban a connected player. Caller must be host or have admin permission.\r\n\t/// \u003C/summary\u003E\r\n\t[Rpc.Host]\r\n\tinternal static void RpcBanPlayer( Connection target, string reason = \u0022Banned\u0022 )\r\n\t{\r\n\t\tif ( !Permissions.Has( Rpc.Caller, Permissions.Admin ) ) return;\r\n\r\n\t\tCurrent.Ban( target, reason );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Bans a player by name or Steam ID. Optionally provide a reason.\r\n\t/// Usage: ban [name|steamid] [reason]\r\n\t/// \u003C/summary\u003E\r\n\t[ConCmd( \u0022ban\u0022 )]\r\n\tinternal static void BanCommand( string target, string reason = \u0022Banned\u0022 )\r\n\t{\r\n\t\tif ( !Networking.IsHost ) return;\r\n\r\n\t\t// Try parsing as a Steam ID (64-bit integer) first\r\n\t\tif ( ulong.TryParse( target, out var steamIdValue ) )\r\n\t\t{\r\n\t\t\tvar steamId = steamIdValue;\r\n\t\t\tvar connection = Connection.All.FirstOrDefault( c =\u003E c.SteamId == steamId );\r\n\r\n\t\t\tif ( connection is not null )\r\n\t\t\t\tCurrent.Ban( connection, reason );\r\n\t\t\telse\r\n\t\t\t\tCurrent.Ban( steamId, reason );\r\n\r\n\t\t\tLog.Info( $\u0022Banned {steamId}: {reason}\u0022 );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// Fall back to partial name match\r\n\t\tvar conn = GameManager.FindPlayerWithName( target );\r\n\t\tif ( conn is not null )\r\n\t\t{\r\n\t\t\tCurrent.Ban( conn, reason );\r\n\t\t\tLog.Info( $\u0022Banned {conn.DisplayName}: {reason}\u0022 );\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLog.Warning( $\u0022Could not find player \u0027{target}\u0027\u0022 );\r\n\t\t}\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Game/ControlSystem/ClientInput.cs","FileName":"ClientInput.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"using System.Text.Json.Serialization;\r\n\r\n/// \u003Csummary\u003E\r\n/// A configurable input for contraptions driven from a seat. This contains no state:\r\n/// it reads the active driver\u0027s connection while \u003Csee cref=\u0022IPlayerControllable.OnControl\u0022/\u003E\r\n/// is running. Wired inputs are ordinary \u003Csee cref=\u0022SignalInputAttribute\u0022/\u003E handlers instead.\r\n/// \u003Cpara\u003E\r\n/// Bound to a raw \u003Csee cref=\u0022Key\u0022/\u003E, which \u003Csee cref=\u0022ControlSystem\u0022/\u003E has the driver report. Saves from before\r\n/// raw keys are bound to an input \u003Csee cref=\u0022Action\u0022/\u003E instead, which still works.\r\n/// \u003C/para\u003E\r\n/// \u003C/summary\u003E\r\npublic struct ClientInput\r\n{\r\n\t/// \u003Csummary\u003E\r\n\t/// The key, or \u003Cc\u003E\u002B\u003C/c\u003E-joined combo, by the names \u003Csee cref=\u0022Input.Keyboard.Down\u0022/\u003E takes.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic string Key { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The input action this was bound to before raw keys. Only used when \u003Csee cref=\u0022Key\u0022/\u003E is empty.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic string Action { get; set; }\r\n\r\n\t[JsonIgnore, Hide]\r\n\tpublic readonly bool HasKey =\u003E !string.IsNullOrWhiteSpace( Key );\r\n\r\n\t[JsonIgnore, Hide]\r\n\tpublic readonly bool IsEnabled =\u003E HasKey || !string.IsNullOrWhiteSpace( Action );\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The individual keys of \u003Csee cref=\u0022Key\u0022/\u003E. Split once per distinct binding and shared - don\u0027t modify it.\r\n\t/// \u003C/summary\u003E\r\n\t[JsonIgnore, Hide]\r\n\tpublic readonly string[] Keys\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tif ( !HasKey ) return [];\r\n\r\n\t\t\tif ( !_splitKeys.TryGetValue( Key, out var keys ) )\r\n\t\t\t{\r\n\t\t\t\tkeys = Key.Split( \u0027\u002B\u0027, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries );\r\n\t\t\t\t_splitKeys[Key] = keys;\r\n\t\t\t}\r\n\r\n\t\t\treturn keys;\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Bindings are a handful of short strings, so this never gets big.\r\n\t/// \u003C/summary\u003E\r\n\tprivate static readonly Dictionary\u003Cstring, string[]\u003E _splitKeys = new();\r\n\r\n\tpublic readonly bool Down() =\u003E HasKey\r\n\t\t? ControlSystem.Current?.KeysDown( ControlContext.Connection, Keys ) == true\r\n\t\t: IsEnabled \u0026\u0026 ControlContext.Connection?.Down( Action ) == true;\r\n\r\n\tpublic readonly bool Pressed() =\u003E HasKey\r\n\t\t? ControlSystem.Current?.KeysPressed( ControlContext.Connection, Keys ) == true\r\n\t\t: IsEnabled \u0026\u0026 ControlContext.Connection?.Pressed( Action ) == true;\r\n\r\n\tpublic readonly bool Released() =\u003E HasKey\r\n\t\t? ControlSystem.Current?.KeysReleased( ControlContext.Connection, Keys ) == true\r\n\t\t: IsEnabled \u0026\u0026 ControlContext.Connection?.Released( Action ) == true;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// How far it\u0027s pushed, 0 to 1: a key\u0027s all the way, a gamepad\u0027s trigger or stick on an action anything between\r\n\t/// (see \u003Csee cref=\u0022Player.ActionAmounts\u0022/\u003E).\r\n\t/// \u003C/summary\u003E\r\n\tpublic readonly float GetAnalog()\r\n\t{\r\n\t\tif ( !Down() ) return 0f;\r\n\t\tif ( HasKey ) return 1f;\r\n\r\n\t\tvar amounts = ControlContext.Player?.ActionAmounts;\r\n\t\treturn amounts is not null \u0026\u0026 amounts.TryGetValue( Action, out var amount ) ? amount : 1f;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Held by the local player - for things that run on the client rather than in the host\u0027s control tick.\r\n\t/// \u003C/summary\u003E\r\n\tpublic readonly bool LocalDown()\r\n\t{\r\n\t\tif ( !HasKey ) return IsEnabled \u0026\u0026 Input.Down( Action );\r\n\r\n\t\tvar keys = Keys;\r\n\t\tif ( keys.Length == 0 ) return false;\r\n\r\n\t\tforeach ( var key in keys )\r\n\t\t{\r\n\t\t\tif ( !Input.Keyboard.Down( key ) ) return false;\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Went down this frame for the local player. See \u003Csee cref=\u0022LocalDown\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tpublic readonly bool LocalPressed()\r\n\t{\r\n\t\tif ( !HasKey ) return IsEnabled \u0026\u0026 Input.Pressed( Action );\r\n\t\tif ( !LocalDown() ) return false;\r\n\r\n\t\tforeach ( var key in Keys )\r\n\t\t{\r\n\t\t\tif ( Input.Keyboard.Pressed( key ) ) return true;\r\n\t\t}\r\n\r\n\t\treturn false;\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Game/Entity/SpotLightEntity.cs","FileName":"SpotLightEntity.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"/// \u003Csummary\u003E\r\n/// A player-controlled spotlight.\r\n/// \u003C/summary\u003E\r\n[Title( \u0022#entity.name.spotlightentity\u0022 )]\r\npublic sealed class SpotLightEntity : Component, IPlayerControllable\r\n{\r\n\t/// \u003Csummary\u003E\r\n\t/// Whether the light is switched on.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.on\u0022 ), Description( \u0022#entity.description.on\u0022 ), ClientEditable, Group( \u0022#entity.group.light\u0022 ), SignalInput( Default = true )]\r\n\tpublic bool On { get; set { field = value; UpdateLight(); } } = true;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Whether the light casts shadows.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.shadows\u0022 ), Description( \u0022#entity.description.shadows\u0022 ), ClientEditable, Group( \u0022#entity.group.light\u0022 )]\r\n\tpublic bool Shadows { get; set { field = value; UpdateLight(); } } = true;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The color of the light.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.color\u0022 ), Description( \u0022#entity.description.color\u0022 ), Range( 0, 1 ), ClientEditable, Group( \u0022#entity.group.light\u0022 )]\r\n\tpublic Color Color { get; set { field = value; UpdateLight(); } }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The brightness of the light.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.brightness\u0022 ), Description( \u0022#entity.description.brightness\u0022 ), Range( 0, 50 ), ClientEditable, Group( \u0022#entity.group.light\u0022 )]\r\n\tpublic float Brightness { get; set { field = value; UpdateLight(); } } = 2;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// How far the light reaches.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.range\u0022 ), Description( \u0022#entity.description.range\u0022 ), Range( 0, 1000 ), ClientEditable, Group( \u0022#entity.group.light\u0022 )]\r\n\tpublic float Radius { get; set { field = value; UpdateLight(); } } = 500;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The outer angle of the spotlight cone.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.angle\u0022 ), Description( \u0022#entity.description.angle\u0022 ), Range( 0, 90 ), ClientEditable, Group( \u0022#entity.group.light\u0022 )]\r\n\tpublic float Angle { get; set { field = value; UpdateLight(); } } = 35;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// How quickly the light fades with distance.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.attenuation\u0022 ), Description( \u0022#entity.description.attenuation\u0022 ), Range( 0, 16 ), ClientEditable, Group( \u0022#entity.group.light\u0022 )]\r\n\tpublic float Attenuation { get; set { field = value; UpdateLight(); } } = 2.4f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The color temperature of the light in Kelvin, 6500 is neutral white.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.temperature\u0022 ), Description( \u0022#entity.description.temperature\u0022 ), Range( 1000, 12000 ), ClientEditable, Group( \u0022#entity.group.light\u0022 )]\r\n\t[SliderGradient( \u0022#ff4400\u0022, \u0022#ff890e\u0022, \u0022#ffb270\u0022, \u0022#ffdabf\u0022, \u0022#ffffff\u0022, \u0022#cadbff\u0022, \u0022#bfd4ff\u0022,\r\n\t\tPositions = new float[] { 0, 1000f / 11000, 2000f / 11000, 3500f / 11000, 0.5f, 9000f / 11000, 1 } )]\r\n\tpublic float Temperature { get; set { field = value; UpdateLight(); } } = 6500;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Whether the light\u0027s brightness is animated.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.animated\u0022 ), Description( \u0022#entity.description.animated\u0022 ), ClientEditable, ToggleGroup( \u0022Animated\u0022, Label = \u0022#entity.group.animation\u0022 )]\r\n\tpublic bool Animated { get; set { field = value; UpdateLight(); } }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The animation the light plays.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.animationpattern\u0022 ), Description( \u0022#entity.description.animationpattern\u0022 ), ClientEditable, ToggleGroup( \u0022Animated\u0022, Label = \u0022#entity.group.animation\u0022 )]\r\n\tpublic LightAnimationPattern AnimationPattern { get; set { field = value; UpdateLight(); } } = LightAnimationPattern.Flicker;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// How fast the animation plays.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.animationspeed\u0022 ), Description( \u0022#entity.description.animationspeed\u0022 ), Range( 0, 10 ), ClientEditable, ToggleGroup( \u0022Animated\u0022, Label = \u0022#entity.group.animation\u0022 )]\r\n\tpublic float AnimationSpeed { get; set { field = value; UpdateLight(); } } = 1;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Shifts the animation in time, so identical lights don\u0027t play in step.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.animationoffset\u0022 ), Description( \u0022#entity.description.animationoffset\u0022 ), Range( 0, 5 ), ClientEditable, ToggleGroup( \u0022Animated\u0022, Label = \u0022#entity.group.animation\u0022 )]\r\n\tpublic float AnimationOffset { get; set { field = value; UpdateLight(); } }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Whether the light\u0027s model casts shadows.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.castshadows\u0022 ), Description( \u0022#entity.description.castshadows\u0022 ), ClientEditable, Group( \u0022#entity.group.rendering\u0022 )]\r\n\tpublic ModelRenderer.ShadowRenderType CastShadows { get; set { field = value; UpdateLight(); } } = ModelRenderer.ShadowRenderType.On;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The input that switches the light on.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.turnon\u0022 ), Description( \u0022#entity.description.turnon\u0022 ), ClientEditable, Group( \u0022#entity.group.state\u0022 )]\r\n\tpublic ClientInput TurnOn { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The input that switches the light off.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.turnoff\u0022 ), Description( \u0022#entity.description.turnoff\u0022 ), ClientEditable, Group( \u0022#entity.group.state\u0022 )]\r\n\tpublic ClientInput TurnOff { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The input that toggles the light.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.toggle\u0022 ), Description( \u0022#entity.description.toggle\u0022 ), ClientEditable, Group( \u0022#entity.group.state\u0022 )]\r\n\tpublic ClientInput Toggle { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The object shown while the light is on.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic GameObject OnGameObject { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The object shown while the light is off.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic GameObject OffGameObject { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Toggles the light when its signal input is triggered.\r\n\t/// \u003C/summary\u003E\r\n\t[SignalInput( Id = nameof( Toggle ) ), Title( \u0022#entity.property.toggle\u0022 )]\r\n\tpublic void ToggleSignal() =\u003E On = !On;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Switches the light on when its signal input is triggered.\r\n\t/// \u003C/summary\u003E\r\n\t[SignalInput( Id = nameof( TurnOn ) ), Title( \u0022#entity.property.turnon\u0022 )]\r\n\tpublic void TurnOnSignal() =\u003E On = true;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Switches the light off when its signal input is triggered.\r\n\t/// \u003C/summary\u003E\r\n\t[SignalInput( Id = nameof( TurnOff ) ), Title( \u0022#entity.property.turnoff\u0022 )]\r\n\tpublic void TurnOffSignal() =\u003E On = false;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Applies the owning player\u0027s light controls.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void OnControl()\r\n\t{\r\n\t\tif ( Toggle.Pressed() ) On = !On;\r\n\t\tif ( TurnOn.Pressed() ) On = true;\r\n\t\tif ( TurnOff.Pressed() ) On = false;\r\n\t}\r\n\r\n\tvoid UpdateLight()\r\n\t{\r\n\t\tOnGameObject?.Enabled = On;\r\n\t\tOffGameObject?.Enabled = !On;\r\n\r\n\t\tforeach ( var renderer in GameObject.GetComponentsInChildren\u003CModelRenderer\u003E( true ) )\r\n\t\t\trenderer.RenderType = CastShadows;\r\n\r\n\t\tif ( GetComponentInChildren\u003CSpotLight\u003E( true ) is not SpotLight light )\r\n\t\t\treturn;\r\n\r\n\t\tlight.Enabled = On;\r\n\r\n\t\tvar color = Color;\r\n\t\tcolor.r *= Brightness;\r\n\t\tcolor.g *= Brightness;\r\n\t\tcolor.b *= Brightness;\r\n\r\n\t\tlight.Shadows = Shadows;\r\n\t\tlight.LightColor = color;\r\n\t\tlight.Temperature = Temperature;\r\n\t\tlight.Radius = Radius;\r\n\t\tlight.Attenuation = Attenuation;\r\n\t\tlight.AnimationEnabled = Animated;\r\n\t\tlight.AnimationPattern = AnimationPattern;\r\n\t\tlight.AnimationSpeed = AnimationSpeed;\r\n\t\tlight.AnimationTimeOffset = AnimationOffset;\r\n\t\tlight.ConeOuter = Angle;\r\n\t\tlight.ConeInner = Angle * 0.5f;\r\n\r\n\t\tNetwork.Refresh();\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Game/IKillSource.cs","FileName":"IKillSource.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"/// \u003Csummary\u003E\r\n/// Implement on any component that can appear as an attacker in the kill feed.\r\n/// Examples: Player, Npc, explosive barrel, turret, whatever the fuck.\r\n/// \u003C/summary\u003E\r\npublic interface IKillSource\r\n{\r\n\t/// \u003Csummary\u003E\r\n\t/// Display name\r\n\t/// \u003C/summary\u003E\r\n\tstring DisplayName { get; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Steam ID for the local \u0022is-me\u0022 highlight. Defaults to 0 (not a player).\r\n\t/// \u003C/summary\u003E\r\n\tlong SteamId =\u003E default;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Entity-type tag passed as \u003Cc\u003EattackerTags\u003C/c\u003E.\r\n\t/// Return an empty string for plain player kills. Examples: \u0022npc\u0022\r\n\t/// \u003C/summary\u003E\r\n\tstring Tags =\u003E \u0022\u0022;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Called on the host when this source kills something.\r\n\t/// Credit kills, update stats, etc. Default is no-op.\r\n\t/// \u003C/summary\u003E\r\n\tvoid OnKill( GameObject victim ) { }\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Game/PostProcessing/EffectSettings.cs","FileName":"EffectSettings.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"using System.Text.Json;\r\n\r\npublic static class EffectSettings\r\n{\r\n\t/// \u003Csummary\u003E\r\n\t/// The settings of an effect component that can be changed, the same ones the Effects panel shows.\r\n\t/// \u003C/summary\u003E\r\n\tpublic static IEnumerable\u003CPropertyDescription\u003E Settings( Component component )\r\n\t{\r\n\t\tvar type = TypeLibrary.GetType( component.GetType() );\r\n\t\tif ( type is null ) return [];\r\n\r\n\t\treturn type.Properties.Where( p =\u003E p.HasAttribute\u003CPropertyAttribute\u003E()\r\n\t\t\t\u0026\u0026 !p.HasAttribute\u003CHideAttribute\u003E()\r\n\t\t\t\u0026\u0026 p.CanWrite\r\n\t\t\t\u0026\u0026 p.Name != nameof( Component.Enabled )\r\n\t\t\t\u0026\u0026 p.PropertyType is not null\r\n\t\t\t\u0026\u0026 !p.PropertyType.IsAssignableTo( typeof( Delegate ) ) );\r\n\t}\r\n\r\n\tstatic string Key( Component component, PropertyDescription property ) =\u003E $\u0022{component.GetType().Name}.{property.Name}\u0022;\r\n\r\n\t// each effect\u0027s prefab values, serialized, so changes can be told apart from defaults\r\n\tstatic readonly Dictionary\u003Cstring, Dictionary\u003Cstring, string\u003E\u003E _defaults = new( StringComparer.OrdinalIgnoreCase );\r\n\r\n\tstatic Dictionary\u003Cstring, string\u003E Defaults( string path )\r\n\t{\r\n\t\tif ( _defaults.TryGetValue( path, out var cached ) ) return cached;\r\n\r\n\t\tvar defaults = new Dictionary\u003Cstring, string\u003E();\r\n\t\tvar prefab = ResourceLibrary.Get\u003CPostProcessResource\u003E( path )?.Prefab?.GetScene();\r\n\t\tforeach ( var component in prefab?.GetComponentsInChildren\u003CComponent\u003E( true ) ?? [] )\r\n\t\t{\r\n\t\t\tforeach ( var property in Settings( component ) )\r\n\t\t\t{\r\n\t\t\t\tif ( Serialize( property.GetValue( component ) ) is { } value )\r\n\t\t\t\t\tdefaults.TryAdd( Key( component, property ), value );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t_defaults[path] = defaults;\r\n\t\treturn defaults;\r\n\t}\r\n\r\n\tpublic static Dictionary\u003Cstring, JsonElement\u003E Capture( string path, IEnumerable\u003CComponent\u003E components )\r\n\t{\r\n\t\tvar values = new Dictionary\u003Cstring, JsonElement\u003E();\r\n\t\tforeach ( var (key, json) in CaptureJson( path, components ) )\r\n\t\t{\r\n\t\t\tusing var document = JsonDocument.Parse( json );\r\n\t\t\tvalues[key] = document.RootElement.Clone();\r\n\t\t}\r\n\r\n\t\treturn values;\r\n\t}\r\n\r\n\tpublic static Dictionary\u003Cstring, string\u003E CaptureJson( string path, IEnumerable\u003CComponent\u003E components )\r\n\t{\r\n\t\tvar defaults = Defaults( path );\r\n\t\tvar values = new Dictionary\u003Cstring, string\u003E();\r\n\r\n\t\tforeach ( var component in components )\r\n\t\t{\r\n\t\t\tforeach ( var property in Settings( component ) )\r\n\t\t\t{\r\n\t\t\t\tvar key = Key( component, property );\r\n\t\t\t\tvar current = Serialize( property.GetValue( component ) );\r\n\t\t\t\tif ( current is not null \u0026\u0026 defaults.GetValueOrDefault( key ) != current )\r\n\t\t\t\t\tvalues[key] = current;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn values;\r\n\t}\r\n\r\n\tpublic static void Apply( string path, IEnumerable\u003CComponent\u003E components, IReadOnlyDictionary\u003Cstring, JsonElement\u003E values )\r\n\t{\r\n\t\t// player effect presets from before keys had the component type saved just the property name\r\n\t\tApply( path, components, key =\u003E\r\n\t\t\tvalues is not null \u0026\u0026 (values.TryGetValue( key, out var stored ) || values.TryGetValue( key[(key.LastIndexOf( \u0027.\u0027 ) \u002B 1)..], out stored ))\r\n\t\t\t\t? stored.GetRawText()\r\n\t\t\t\t: null );\r\n\t}\r\n\r\n\tpublic static void Apply( string path, IEnumerable\u003CComponent\u003E components, Func\u003Cstring, string\u003E storedJson )\r\n\t{\r\n\t\tvar defaults = Defaults( path );\r\n\r\n\t\tforeach ( var component in components )\r\n\t\t{\r\n\t\t\tforeach ( var property in Settings( component ) )\r\n\t\t\t{\r\n\t\t\t\tvar key = Key( component, property );\r\n\t\t\t\tvar raw = storedJson( key ) ?? defaults.GetValueOrDefault( key );\r\n\t\t\t\tif ( raw is null ) continue;\r\n\r\n\t\t\t\ttry\r\n\t\t\t\t{\r\n\t\t\t\t\tif ( Sandbox.Json.Deserialize( raw, property.PropertyType ) is { } value )\r\n\t\t\t\t\t\tproperty.SetValue( component, value );\r\n\t\t\t\t}\r\n\t\t\t\tcatch { }\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstatic string Serialize( object value )\r\n\t{\r\n\t\tif ( value is null ) return null;\r\n\r\n\t\ttry { return Sandbox.Json.Serialize( value ); }\r\n\t\tcatch { return null; }\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Game/Weapon/BaseSandboxWeapon/BaseSandboxWeapon.ViewModel.cs","FileName":"BaseSandboxWeapon.ViewModel.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"public partial class BaseSandboxWeapon\r\n{\r\n\t// The view model lifecycle - creation on equip, the deploy presentation, destruction on holster -\r\n\t// all comes from the engine BaseCombatWeapon.\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"GameLoop/GamePreferences.cs","FileName":"GamePreferences.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"/// \u003Csummary\u003E\r\n/// The local user\u0027s preferences in Deathmatch\r\n/// \u003C/summary\u003E\r\ninternal static partial class GamePreferences\r\n{\r\n\t/// \u003Csummary\u003E\r\n\t/// Enables automatic switching to better weapons on item pickup\r\n\t/// \u003C/summary\u003E\r\n\t[ConVar( \u0022sandbox.autoswitch\u0022, ConVarFlags.UserInfo | ConVarFlags.Saved )]\r\n\tpublic static bool AutoSwitch { get; set; } = true;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The weapon prefab the NPCs we spawn are armed with, empty keeps their own. See \u003Csee cref=\u0022Player.NpcWeapon\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\t[ConVar( \u0022sandbox.npc.weapon\u0022, ConVarFlags.Saved )]\r\n\tpublic static string NpcWeapon { get; set; } = \u0022\u0022;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Enables movement bob, weapon inertia and animation-driven camera motion.\r\n\t/// \u003C/summary\u003E\r\n\t[ConVar( \u0022sandbox.viewbob\u0022, ConVarFlags.Saved )]\r\n\t[Group( \u0022Camera\u0022 )]\r\n\tpublic static bool ViewBobbing { get; set; } = true;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Strength of the camera tilt when moving sideways\r\n\t/// \u003C/summary\u003E\r\n\t[ConVar( \u0022sandbox.viewtilt\u0022, ConVarFlags.Saved, Help = \u0022Sideways camera tilt strength. 0 disables tilt, 1 restores the original strength.\u0022 )]\r\n\t[Range( 0f, 1f ), Step( 0.05f ), Group( \u0022Camera\u0022 )]\r\n\tpublic static float ViewTilt { get; set; } = 0.35f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Intensity of your camera\u0027s screenshake\r\n\t/// \u003C/summary\u003E\r\n\t[ConVar( \u0022sandbox.screenshake\u0022, ConVarFlags.Saved )]\r\n\t[Range( 0.1f, 2f ), Step( 0.1f ), Group( \u0022Camera\u0022 )]\r\n\tpublic static float Screenshake { get; set; } = 0.3f;\r\n\r\n\tpublic static void Reset( string group )\r\n\t{\r\n\t\tforeach ( var property in Game.TypeLibrary.GetType( typeof( GamePreferences ) )?.Properties ?? [] )\r\n\t\t{\r\n\t\t\tif ( property.Group != group || property.GetCustomAttribute\u003CConVarAttribute\u003E() is not { } convar ) continue;\r\n\r\n\t\t\tif ( property.GetCustomAttribute\u003CDefaultValueAttribute\u003E() is { } defaultValue )\r\n\t\t\t\tConsoleSystem.SetValue( convar.Name, defaultValue.Value );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// A colour preference as text. Plain invariant numbers rather than hex, so HDR brightness above 1 survives.\r\n\t/// \u003C/summary\u003E\r\n\tpublic static string ColorText( Color color ) =\u003E string.Create( System.Globalization.CultureInfo.InvariantCulture, $\u0022{color.r},{color.g},{color.b},{color.a}\u0022 );\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// A colour preference, null when it\u0027s empty for the default or can\u0027t be read. Hex from older saves reads too.\r\n\t/// \u003C/summary\u003E\r\n\tpublic static Color? ParseColor( string text ) =\u003E string.IsNullOrWhiteSpace( text ) ? null : Color.Parse( text );\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"GameLoop/IAdminEvents.cs","FileName":"IAdminEvents.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"public enum AdminAction\r\n{\r\n\tKick,\r\n\tBan,\r\n\tUnban,\r\n\tChangeSetting,\r\n\tChangeMap\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Data passed to \u003Csee cref=\u0022Global.IAdminEvents\u0022/\u003E. In \u003Csee cref=\u0022Global.IAdminEvents.OnAdminAction\u0022/\u003E, set\r\n/// \u003Csee cref=\u0022Cancelled\u0022/\u003E to true to stop it, or change \u003Csee cref=\u0022Value\u0022/\u003E to change a reason or map.\r\n/// \u003C/summary\u003E\r\npublic class AdminActionEvent\r\n{\r\n\tpublic AdminAction Action { get; init; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Who did it - the admin who sent it, or the host itself for its own menus and console.\r\n\t/// \u003C/summary\u003E\r\n\tpublic Connection Caller { get; init; } = Rpc.Calling ? Rpc.Caller : Connection.Local;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The player kicked, banned or unbanned. They might not be connected.\r\n\t/// \u003C/summary\u003E\r\n\tpublic SteamId SteamId { get; init; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The setting changed, for \u003Csee cref=\u0022AdminAction.ChangeSetting\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tpublic string Setting { get; init; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The kick or ban reason, the map, or the setting\u0027s new value (which can\u0027t be changed here).\r\n\t/// \u003C/summary\u003E\r\n\tpublic string Value { get; set; }\r\n\r\n\tpublic bool Cancelled { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Fire \u003Csee cref=\u0022Global.IAdminEvents.OnAdminAction\u0022/\u003E, returns false if a listener cancelled it.\r\n\t/// \u003C/summary\u003E\r\n\tinternal bool Run()\r\n\t{\r\n\t\tGame.ActiveScene?.RunEvent\u003CGlobal.IAdminEvents\u003E( x =\u003E x.OnAdminAction( this ) );\r\n\t\treturn !Cancelled;\r\n\t}\r\n\r\n\tinternal void Done() =\u003E Game.ActiveScene?.RunEvent\u003CGlobal.IAdminEvents\u003E( x =\u003E x.OnAdminActionDone( this ) );\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Allows listening to and stopping admin actions - kicks, bans, server settings and map changes. Use it for\r\n/// audit logs or protecting admins from each other. All of these run on the host.\r\n/// \u003C/summary\u003E\r\npublic static partial class Global\r\n{\r\n\tpublic interface IAdminEvents : ISceneEvent\u003CIAdminEvents\u003E\r\n\t{\r\n\t\tvoid OnAdminAction( AdminActionEvent e ) { }\r\n\t\tvoid OnAdminActionDone( AdminActionEvent e ) { }\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Npcs/Combat/CombatNpc.cs","FileName":"CombatNpc.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"using Sandbox.Npcs.Layers;\r\nusing Sandbox.Npcs.Schedules;\r\n\r\nnamespace Sandbox.Npcs.CombatNpc;\r\n\r\n/// \u003Csummary\u003E\r\n/// A combat NPC that searches for players, advances on them, fires in bursts, and repositions.\r\n/// When friendly, can be recruited to follow a player and engages hostile NPCs instead.\r\n/// \u003C/summary\u003E\r\npublic class CombatNpc : Npc, Component.IPressable\r\n{\r\n\tprivate static readonly string[] PainLines =\r\n\t{\r\n\t\t\u0022#npc.speech.combat.pain.1\u0022,\r\n\t\t\u0022#npc.speech.combat.pain.2\u0022,\r\n\t\t\u0022#npc.speech.combat.pain.3\u0022,\r\n\t\t\u0022#npc.speech.combat.pain.4\u0022,\r\n\t\t\u0022#npc.speech.combat.pain.5\u0022,\r\n\t};\r\n\r\n\tprivate static readonly string[] DeathLines =\r\n\t{\r\n\t\t\u0022#npc.speech.combat.death.1\u0022,\r\n\t\t\u0022#npc.speech.combat.death.2\u0022,\r\n\t\t\u0022#npc.speech.combat.death.3\u0022,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// When true, this NPC is friendly to players and will follow them, engaging hostile NPCs.\r\n\t/// When false, this NPC targets players and friendly NPCs.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.npc_friendly\u0022 ), Description( \u0022#entity.description.npc_friendly\u0022 ), ClientEditable, Sync]\r\n\tpublic bool Friendly { get; set; } = false;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The weapon this NPC uses to attack. Its NPC usage decides the engagement range and burst\r\n\t/// cadence - the same soldier fights differently with a shotgun than an SMG.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic BaseSandboxWeapon Weapon { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Weapon prefabs to arm this NPC with - one is picked at random when it spawns, replacing\r\n\t/// \u003Csee cref=\u0022Weapon\u0022/\u003E. Empty keeps the prefab\u0027s weapon.\r\n\t/// \u003C/summary\u003E\r\n\t[Property]\r\n\tpublic List\u003CGameObject\u003E WeaponChoices { get; set; } = [];\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Skill multiplier on the weapon\u0027s NPC spread - 1 is a average shot, lower is more accurate.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic float AimSpreadScale { get; set; } = 1f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Movement speed while engaging an enemy.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Title( \u0022#entity.property.npc_engagespeed\u0022 ), Description( \u0022#entity.description.npc_engagespeed\u0022 ), Group( \u0022#entity.group.balance\u0022 ), Range( 90, 250f ), Step( 1 ), ClientEditable, Sync]\r\n\tpublic float EngageSpeed { get; set; } = 180f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Walking pace while patrolling.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic float PatrolSpeed { get; set; } = 85f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Cautious walking pace - sweeping for a hostile we\u0027ve lost, checking out a noise, strafing to a\r\n\t/// new position. Kept to a walk; only fighting and hot pursuit break into a jog.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic float SearchSpeed { get; set; } = 85f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Each soldier moves up to this much faster or slower than the rest (0.05 = \u00B15%), so a squad\r\n\t/// doesn\u0027t move in lockstep. Keep it small - too much pushes a walk into a jog.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic float SpeedVariation { get; set; } = 0.05f;\r\n\r\n\t// This soldier\u0027s own pace, from SpeedVariation\r\n\tprivate float _speedScale = 1f;\r\n\r\n\tprivate float Pace( float speed ) =\u003E speed * _speedScale;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// How long after the last intel on a hostile (seen, heard or called out) to keep searching for it.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic float SearchTimeout { get; set; } = 8f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Allies of the same faction within this range are told where a spotted hostile is.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic float CalloutRange { get; set; } = 1500f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Wander between random points when there\u0027s nothing going on, instead of holding a post.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic bool Patrols { get; set; }\r\n\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic float PatrolRadius { get; set; } = 400f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// How long the weapon stays up after the last sign of trouble before the NPC relaxes.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic float RelaxDelay { get; set; } = 5f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Seconds (min, max) to react to a fresh contact when caught at ease - weapon lowered.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic Vector2 ReactionTimeRelaxed { get; set; } = new( 1.0f, 1.6f );\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Seconds (min, max) to react to a fresh contact when already alert - weapon up, searching or fighting.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic Vector2 ReactionTimeAlert { get; set; } = new( 0.5f, 0.9f );\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Seconds a weapon dropped on death lies around before it\u0027s removed, if nobody picks it up.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic float DroppedWeaponLifetime { get; set; } = 20f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// How far a friendly NPC will follow a player before stopping.\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Balance\u0022 )]\r\n\tpublic float FollowDistance { get; set; } = 150f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The player this friendly NPC is following, if any.\r\n\t/// \u003C/summary\u003E\r\n\t[Sync]\r\n\tpublic GameObject Leader { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Where we last saw, heard or were told a hostile was. Null when we\u0027ve got nothing to go on.\r\n\t/// \u003C/summary\u003E\r\n\tpublic Vector3? LastKnownPosition { get; private set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Which way that hostile was moving, so a search can head where it was going.\r\n\t/// \u003C/summary\u003E\r\n\tpublic Vector3 LastKnownVelocity { get; private set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Time since \u003Csee cref=\u0022LastKnownPosition\u0022/\u003E was last updated.\r\n\t/// \u003C/summary\u003E\r\n\tpublic TimeSince TimeSinceIntel { get; private set; }\r\n\r\n\tprivate TimeSince _timeSinceCallout;\r\n\r\n\t// The post we hold when nothing\u0027s going on - where and which way we were spawned\r\n\tprivate Vector3 _post;\r\n\tprivate Vector3 _postForward;\r\n\r\n\tprivate TimeSince _timeSinceAlert;\r\n\r\n\t// Contact tracking: when we last saw a hostile, and when the current stretch of contact began\r\n\tprivate TimeSince _timeSinceSawHostile;\r\n\tprivate TimeSince _timeSinceContact;\r\n\tprivate float _contactReaction;\r\n\r\n\t// The last hostile we saw and where, so we notice when it\u0027s dead - and where its body is\r\n\tprivate GameObject _lastSeenHostile;\r\n\tprivate Vector3 _lastSeenPosition;\r\n\tprivate Vector3? _bodyPosition;\r\n\tprivate TimeSince _timeSinceKill;\r\n\r\n\tIPressable.Tooltip? IPressable.GetTooltip( IPressable.Event e )\r\n\t{\r\n\t\tif ( !Friendly )\r\n\t\t\treturn null;\r\n\r\n\t\treturn Leader.IsValid()\r\n\t\t\t? new IPressable.Tooltip( \u0022#npc.action.stop_following\u0022, \u0022person_off\u0022, null )\r\n\t\t\t: new IPressable.Tooltip( \u0022#npc.action.follow\u0022, \u0022follow_the_signs\u0022, null );\r\n\t}\r\n\r\n\tbool IPressable.CanPress( IPressable.Event e ) =\u003E Friendly;\r\n\r\n\tbool IPressable.Press( IPressable.Event e )\r\n\t{\r\n\t\tToggleFollow( e.Source.GameObject );\r\n\t\treturn true;\r\n\t}\r\n\r\n\t[Rpc.Host]\r\n\tprivate void ToggleFollow( GameObject presserObject )\r\n\t{\r\n\t\tif ( !Friendly || !presserObject.IsValid() )\r\n\t\t\treturn;\r\n\r\n\t\tvar player = presserObject.Root.GetComponent\u003CPlayer\u003E();\r\n\t\tif ( !player.IsValid() )\r\n\t\t\treturn;\r\n\r\n\t\tLeader = Leader == player.GameObject ? null : player.GameObject;\r\n\t\tEndCurrentSchedule();\r\n\t}\r\n\r\n\tprotected override void OnValidate()\r\n\t{\r\n\t\tbase.OnValidate();\r\n\r\n\t\t// Runs when the NPC is cloned in, before it\u0027s network spawned - so the chosen gun goes out in\r\n\t\t// its spawn snapshot and every client sees the same one. Not in the editor or the cached\r\n\t\t// prefab itself, not on clients.\r\n\t\tif ( Game.IsPlaying \u0026\u0026 Scene.IsValid() \u0026\u0026 !Scene.IsEditor \u0026\u0026 Scene is not PrefabScene \u0026\u0026 Networking.IsHost \u0026\u0026 !GameObject.Network.Active )\r\n\t\t\tArmWithRandomWeapon();\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Swap the prefab\u0027s weapon for a random one from \u003Csee cref=\u0022WeaponChoices\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tprivate void ArmWithRandomWeapon()\r\n\t{\r\n\t\tif ( WeaponChoices is not { Count: \u003E 0 } )\r\n\t\t\treturn;\r\n\r\n\t\tArmWith( WeaponChoices[Game.Random.Int( 0, WeaponChoices.Count - 1 )] );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The weapons players can pick for the NPCs they spawn\r\n\t/// \u003C/summary\u003E\r\n\tpublic static IEnumerable\u003CScriptedEntity\u003E PickableWeapons =\u003E ResourceLibrary.GetAll\u003CScriptedEntity\u003E().Where( IsPickableWeapon );\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Installed weapons NPCs can fight with: melee and utility weapons have no NPC use set up\r\n\t/// \u003C/summary\u003E\r\n\tstatic bool IsPickableWeapon( ScriptedEntity entity )\r\n\t{\r\n\t\tif ( entity.IsRemote || entity.Prefab is null || (entity.Developer \u0026\u0026 !ServerSettings.ShowDeveloperEntities) )\r\n\t\t\treturn false;\r\n\r\n\t\tif ( !SpawnMenuCategory.Matches( entity.Category, \u0022Weapon\u0022 ) || SpawnMenuCategory.Matches( entity.Category, \u0022Weapon/Melee\u0022 ) || SpawnMenuCategory.Matches( entity.Category, \u0022Weapon/Utility\u0022 ) )\r\n\t\t\treturn false;\r\n\r\n\t\treturn SceneUtility.GetPrefabScene( entity.Prefab )?.GetComponent\u003CBaseSandboxWeapon\u003E( true ) is { UsableByNpcs: true };\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Arm with the weapon a player picked instead of a random one from \u003Csee cref=\u0022WeaponChoices\u0022/\u003E, NPCs with\r\n\t/// a fixed weapon keep it. See \u003Csee cref=\u0022Player.NpcWeapon\u0022/\u003E. Host only, before the NPC is network spawned.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void ArmWithPicked( Player player )\r\n\t{\r\n\t\tvar path = player?.NpcWeapon;\r\n\t\tif ( string.IsNullOrEmpty( path ) || WeaponChoices is not { Count: \u003E 0 } )\r\n\t\t\treturn;\r\n\r\n\t\tvar weapon = ResourceLibrary.GetAll\u003CScriptedEntity\u003E().FirstOrDefault( entity =\u003E entity.Prefab?.ResourcePath == path \u0026\u0026 IsPickableWeapon( entity ) );\r\n\t\tif ( weapon is not null )\r\n\t\t\tArmWith( SceneUtility.GetPrefabScene( weapon.Prefab ) );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Swap the current weapon for one made from a weapon prefab. Host only, before the NPC is network spawned.\r\n\t/// \u003C/summary\u003E\r\n\tprivate void ArmWith( GameObject prefab )\r\n\t{\r\n\t\tif ( !prefab.IsValid() )\r\n\t\t\treturn;\r\n\r\n\t\tvar go = prefab.Clone( new CloneConfig { Parent = GameObject, Transform = global::Transform.Zero, StartEnabled = true } );\r\n\t\tvar weapon = go?.GetComponent\u003CBaseSandboxWeapon\u003E( true );\r\n\t\tif ( !weapon.IsValid() )\r\n\t\t{\r\n\t\t\tgo?.Destroy();\r\n\t\t\tLog.Warning( $\u0022{DisplayName}: \u0027{prefab.Name}\u0027 isn\u0027t a weapon prefab, keeping the default weapon.\u0022 );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tWeapon?.GameObject.DestroyImmediate();\r\n\t\tWeapon = weapon;\r\n\t}\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tbase.OnStart();\r\n\r\n\t\t_speedScale = 1f \u002B Game.Random.Float( -SpeedVariation, SpeedVariation );\r\n\r\n\t\t_post = WorldPosition;\r\n\t\t_postForward = WorldRotation.Forward;\r\n\r\n\t\tif ( Weapon.IsValid() \u0026\u0026 Renderer.IsValid() )\r\n\t\t{\r\n\t\t\tWeapon.CreateWorldModel( Renderer );\r\n\r\n\t\t\t// The weapon says how forgiving it is in NPC hands; we say how good we are with it.\r\n\t\t\tWeapon.SpreadScale = Weapon.Npc.SpreadScale * AimSpreadScale;\r\n\r\n\t\t\tif ( !IsProxy )\r\n\t\t\t\tAnimation.SetHoldType( Weapon.HoldType );\r\n\t\t}\r\n\t}\r\n\r\n\t// Friendly soldiers fight alongside the player; the rest are enemies.\r\n\tpublic override string Faction =\u003E Friendly ? Factions.Ally : Factions.Enemy;\r\n\r\n\tprotected override void SetupRelationships()\r\n\t{\r\n\t\tif ( Friendly )\r\n\t\t{\r\n\t\t\tLikes( Factions.Player );\r\n\t\t\tHates( Factions.Enemy, Factions.Monster );\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tHates( Factions.Player, Factions.Ally, Factions.Citizen );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Remember where a hostile is (and which way it\u0027s heading).\r\n\t/// \u003C/summary\u003E\r\n\tpublic void RememberHostile( Vector3 position, Vector3 velocity )\r\n\t{\r\n\t\tLastKnownPosition = position;\r\n\t\tLastKnownVelocity = velocity;\r\n\t\tTimeSinceIntel = 0;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Keep the last known position fresh from everything we sense, every think -- not just when a\r\n\t/// fight starts -- and tell nearby allies about anything we can see.\r\n\t/// \u003C/summary\u003E\r\n\tprotected override NpcAwareness GatherAwareness()\r\n\t{\r\n\t\tvar awareness = base.GatherAwareness();\r\n\r\n\t\tTrackKill();\r\n\r\n\t\tvar seen = Senses.GetBestTarget();\r\n\t\tif ( seen.IsValid() )\r\n\t\t{\r\n\t\t\t// First sight after a gap is a fresh contact - work out how long it takes us to react\r\n\t\t\tif ( _timeSinceSawHostile \u003E 3f )\r\n\t\t\t{\r\n\t\t\t\t_timeSinceContact = 0;\r\n\t\t\t\t_contactReaction = GetReactionTime( seen );\r\n\t\t\t}\r\n\r\n\t\t\t_timeSinceSawHostile = 0;\r\n\t\t\t_lastSeenHostile = seen;\r\n\t\t\t_lastSeenPosition = seen.WorldPosition;\r\n\t\t\tRememberHostile( seen.WorldPosition, SensesLayer.GetVelocity( seen ) );\r\n\t\t\tCallOut( seen );\r\n\t\t\treturn awareness;\r\n\t\t}\r\n\r\n\t\tif ( Senses.GetHeardHostile() is { } heard \u0026\u0026 heard.IsValid() )\r\n\t\t{\r\n\t\t\tRememberHostile( heard.WorldPosition, SensesLayer.GetVelocity( heard ) );\r\n\t\t}\r\n\t\telse if ( Senses.Disturbance is { } noise \u0026\u0026 noise.Source.IsValid() \u0026\u0026 GetDisposition( noise.Source ) == Disposition.Hostile )\r\n\t\t{\r\n\t\t\t// Heard a hostile shoot -- we know roughly where they are, not where they\u0027re going\r\n\t\t\tif ( TimeSinceIntel \u003E 1f )\r\n\t\t\t\tRememberHostile( noise.Position, Vector3.Zero );\r\n\t\t}\r\n\r\n\t\t// Fresh intel (heard, or an ally\u0027s callout) gets an idle NPC moving\r\n\t\tif ( LastKnownPosition.HasValue \u0026\u0026 TimeSinceIntel \u003C 0.5f )\r\n\t\t\tawareness |= NpcAwareness.HostileIntel;\r\n\r\n\t\treturn awareness;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The last hostile we saw is gone - dead. If we were in the fight, remember where the body is so\r\n\t/// we can walk over and check, and stop hunting it.\r\n\t/// \u003C/summary\u003E\r\n\tprivate void TrackKill()\r\n\t{\r\n\t\tif ( _lastSeenHostile is null || _lastSeenHostile.IsValid() )\r\n\t\t\treturn;\r\n\r\n\t\t_lastSeenHostile = null;\r\n\r\n\t\tif ( _timeSinceSawHostile \u003E 10f )\r\n\t\t\treturn;\r\n\r\n\t\t_bodyPosition = _lastSeenPosition;\r\n\t\t_timeSinceKill = 0;\r\n\r\n\t\t// Intel that still points at it is stale - it\u0027s not going anywhere\r\n\t\tif ( LastKnownPosition is { } lastKnown \u0026\u0026 lastKnown.Distance( _lastSeenPosition ) \u003C 200f )\r\n\t\t\tLastKnownPosition = null;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// How long it takes to react to spotting a hostile: longer when caught at ease (the weapon has\r\n\t/// to come up) than when already alert, plus a little more to pick out something far away.\r\n\t/// \u003C/summary\u003E\r\n\tprivate float GetReactionTime( GameObject hostile )\r\n\t{\r\n\t\tvar range = Animation.WeaponLowered ? ReactionTimeRelaxed : ReactionTimeAlert;\r\n\t\tvar distance = WorldPosition.Distance( hostile.WorldPosition );\r\n\r\n\t\treturn Game.Random.Float( range.x, range.y ) \u002B MathF.Min( 0.6f, distance / 2500f );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Tell allies of our faction nearby where a hostile is. They\u0027ll come and help search, or join\r\n\t/// the fight once they see it themselves.\r\n\t/// \u003C/summary\u003E\r\n\tprivate void CallOut( GameObject hostile )\r\n\t{\r\n\t\tif ( _timeSinceCallout \u003C 1f ) return;\r\n\t\t_timeSinceCallout = 0;\r\n\r\n\t\tvar velocity = SensesLayer.GetVelocity( hostile );\r\n\r\n\t\tforeach ( var ally in Scene.GetAll\u003CCombatNpc\u003E() )\r\n\t\t{\r\n\t\t\tif ( ally == this || ally.Faction != Faction ) continue;\r\n\t\t\tif ( ally.WorldPosition.Distance( WorldPosition ) \u003E CalloutRange ) continue;\r\n\r\n\t\t\t// They can see something themselves -- don\u0027t distract them\r\n\t\t\tif ( ally.Senses.IsValid() \u0026\u0026 ally.Senses.VisibleTargets.Count \u003E 0 ) continue;\r\n\r\n\t\t\tally.RememberHostile( hostile.WorldPosition, velocity );\r\n\t\t}\r\n\t}\r\n\r\n\tpublic override ScheduleBase GetSchedule()\r\n\t{\r\n\t\tvar visible = Senses.GetBestTarget();\r\n\r\n\t\tif ( visible.IsValid() \u0026\u0026 Weapon.IsValid() )\r\n\t\t{\r\n\t\t\tvar engage = GetSchedule\u003CCombatEngageSchedule\u003E();\r\n\t\t\tengage.Target = visible;\r\n\t\t\tengage.Weapon = Weapon;\r\n\t\t\tengage.EngageSpeed = Pace( EngageSpeed );\r\n\r\n\t\t\t// Whatever\u0027s left of the reaction to a fresh contact - nothing once a fight\u0027s under way\r\n\t\t\tengage.ReactionTime = MathF.Max( 0f, _contactReaction - _timeSinceContact );\r\n\t\t\tengage.StrafeSpeed = Pace( SearchSpeed );\r\n\t\t\treturn engage;\r\n\t\t}\r\n\r\n\t\t// Got them - walk over and check the body. No hurry, the fight\u0027s over.\r\n\t\tif ( _bodyPosition is { } body \u0026\u0026 _timeSinceKill \u003C 20f \u0026\u0026 WorldPosition.Distance( body ) \u003E 100f )\r\n\t\t{\r\n\t\t\tvar check = GetSchedule\u003CInvestigateSchedule\u003E();\r\n\t\t\tcheck.Target = body;\r\n\t\t\tcheck.Speed = Pace( PatrolSpeed );\r\n\t\t\treturn check;\r\n\t\t}\r\n\r\n\t\t// Lost them, heard them, or been told where they are -- go hunt. Jog after someone we\u0027ve only\r\n\t\t// just lost sight of; otherwise it\u0027s a careful walk.\r\n\t\tif ( LastKnownPosition.HasValue \u0026\u0026 TimeSinceIntel \u003C SearchTimeout \u0026\u0026 Weapon.IsValid() )\r\n\t\t{\r\n\t\t\tvar search = GetSchedule\u003CCombatSearchSchedule\u003E();\r\n\t\t\tvar hotPursuit = _lastSeenHostile.IsValid() \u0026\u0026 _timeSinceSawHostile \u003C 5f;\r\n\t\t\tsearch.Speed = hotPursuit ? Pace( EngageSpeed ) : Pace( SearchSpeed );\r\n\t\t\tsearch.SweepSpeed = Pace( SearchSpeed );\r\n\t\t\treturn search;\r\n\t\t}\r\n\r\n\t\t// Heard gunfire or some other disturbance but can\u0027t see the source -- go check it out.\r\n\t\tif ( Senses.Disturbance is { } disturbance )\r\n\t\t{\r\n\t\t\tvar investigate = GetSchedule\u003CInvestigateSchedule\u003E();\r\n\t\t\tinvestigate.Target = disturbance.Position;\r\n\t\t\tinvestigate.Speed = Pace( SearchSpeed );\r\n\t\t\treturn investigate;\r\n\t\t}\r\n\r\n\t\t// Combat and investigation above take priority; once clear, resume following our leader.\r\n\t\tif ( Friendly \u0026\u0026 Leader.IsValid() )\r\n\t\t{\r\n\t\t\tvar follow = GetSchedule\u003CFollowSchedule\u003E();\r\n\t\t\tfollow.Target = Leader;\r\n\t\t\tfollow.FollowDistance = FollowDistance;\r\n\t\t\treturn follow;\r\n\t\t}\r\n\r\n\t\t// Nothing going on - patrol if we\u0027re a patroller, otherwise hold our post\r\n\t\tif ( Patrols )\r\n\t\t{\r\n\t\t\tvar patrol = GetSchedule\u003CCombatPatrolSchedule\u003E();\r\n\t\t\tpatrol.PatrolRadius = PatrolRadius;\r\n\t\t\tpatrol.Speed = Pace( PatrolSpeed );\r\n\t\t\treturn patrol;\r\n\t\t}\r\n\r\n\t\tvar idle = GetSchedule\u003CCombatIdleSchedule\u003E();\r\n\t\tidle.Post = _post;\r\n\t\tidle.PostForward = _postForward;\r\n\t\tidle.WalkSpeed = Pace( PatrolSpeed );\r\n\t\treturn idle;\r\n\t}\r\n\r\n\tprotected override void OnPutDown()\r\n\t{\r\n\t\tbase.OnPutDown();\r\n\r\n\t\t// Someone put us here and turned us this way - this is our post now\r\n\t\t_post = WorldPosition;\r\n\t\t_postForward = WorldRotation.Forward;\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tbase.OnUpdate();\r\n\r\n\t\tif ( IsProxy )\r\n\t\t\treturn;\r\n\r\n\t\t// Weapon up while anything\u0027s going on (searching, fighting) and for a while after - at ease otherwise\r\n\t\tif ( ActiveSchedule is { Priority: \u003E= SchedulePriority.Alert } )\r\n\t\t\t_timeSinceAlert = 0;\r\n\r\n\t\tAnimation.WeaponLowered = _timeSinceAlert \u003E RelaxDelay;\r\n\t}\r\n\r\n\tprotected override void OnHurt( in DamageInfo damage )\r\n\t{\r\n\t\tvar attacker = GetAttacker( damage );\r\n\t\tif ( attacker.IsValid() )\r\n\t\t{\r\n\t\t\t// Turn on whoever hurt us, even a former ally, and prioritise them as a target.\r\n\t\t\t// This is the runtime \u0022turn nasty\u0022 path the crime/aggro systems reuse.\r\n\t\t\tSetDisposition( attacker, Disposition.Hostile, priority: 10 );\r\n\r\n\t\t\t// You can tell which way the shot came from -- go after whoever fired it.\r\n\t\t\tRememberHostile( attacker.WorldPosition, SensesLayer.GetVelocity( attacker ) );\r\n\t\t}\r\n\r\n\t\tif ( Health \u003E= 1f \u0026\u0026 Speech.CanSpeak \u0026\u0026 Game.Random.Float() \u003C 0.5f )\r\n\t\t\tSpeech.TrySay( Game.Random.FromArray( PainLines ), 1.5f, tags: [\u0022reaction\u0022, \u0022pain\u0022], priority: 2000 );\r\n\r\n\t\t// React immediately.\r\n\t\tEndCurrentSchedule();\r\n\t}\r\n\r\n\tprotected override void Die( in DamageInfo damage )\r\n\t{\r\n\t\tif ( Speech.CanSpeak )\r\n\t\t\tSpeech.TrySay( Game.Random.FromArray( DeathLines ), 2f, tags: [\u0022reaction\u0022, \u0022death\u0022], priority: 3000 );\r\n\r\n\t\tDropWeapon();\r\n\r\n\t\tbase.Die( damage );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Drop the held weapon into the world where the hand was, so it survives the NPC\u0027s death and can\r\n\t/// be picked up. If nobody takes it within \u003Csee cref=\u0022DroppedWeaponLifetime\u0022/\u003E it\u0027s cleaned up.\r\n\t/// \u003C/summary\u003E\r\n\tprivate void DropWeapon()\r\n\t{\r\n\t\tif ( !Weapon.IsValid() )\r\n\t\t\treturn;\r\n\r\n\t\tvar position = Weapon.WorldModel.IsValid()\r\n\t\t\t? Weapon.WorldModel.WorldPosition\r\n\t\t\t: WorldPosition \u002B Vector3.Up * 32f;\r\n\r\n\t\tvar weapon = Weapon;\r\n\t\tweapon.DropIntoWorld( position, Vector3.Up * 50f );\r\n\r\n\t\t// The timer lives on the weapon - this NPC is about to be destroyed\r\n\t\tweapon.Invoke( DroppedWeaponLifetime, () =\u003E RemoveIfUnclaimed( weapon ) );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Remove a gun we dropped, unless a player has picked it up since. A player who picked it up and\r\n\t/// dropped it again owns it now, so that drop is theirs to keep.\r\n\t/// \u003C/summary\u003E\r\n\tprivate static void RemoveIfUnclaimed( BaseSandboxWeapon weapon )\r\n\t{\r\n\t\tif ( !weapon.IsValid() || weapon.HasOwner || !weapon.IsDropped )\r\n\t\t\treturn;\r\n\r\n\t\tif ( weapon.GetComponent\u003COwnable\u003E()?.Owner is not null )\r\n\t\t\treturn;\r\n\r\n\t\tweapon.GameObject.Destroy();\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Npcs/NpcStimulusSystem.cs","FileName":"NpcStimulusSystem.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"namespace Sandbox.Npcs;\r\n\r\n/// \u003Csummary\u003E\r\n/// The world stimulus bus. Anything can broadcast a \u003Csee cref=\u0022Stimulus\u0022/\u003E (a gunshot, a\r\n/// death, a crime) and nearby NPCs sense it through their \u003Csee cref=\u0022Layers.SensesLayer\u0022/\u003E.\r\n/// This is how the world pushes events at NPCs, rather than NPCs only polling for entities.\r\n/// \u003C/summary\u003E\r\npublic sealed class NpcStimulusSystem : GameObjectSystem\u003CNpcStimulusSystem\u003E\r\n{\r\n\treadonly List\u003CStimulus\u003E _active = new();\r\n\r\n\tpublic NpcStimulusSystem( Scene scene ) : base( scene )\r\n\t{\r\n\t\tListen( Stage.StartUpdate, 0, Prune, \u0022PruneStimuli\u0022 );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Broadcast a stimulus into the world. \u003Cparamref name=\u0022radius\u0022/\u003E is how far it can be\r\n\t/// sensed; \u003Cparamref name=\u0022lifetime\u0022/\u003E is how long it lingers (seconds).\r\n\t/// \u003C/summary\u003E\r\n\tpublic void Broadcast( string kind, Vector3 position, GameObject source = null, float radius = 1024f, float lifetime = 1f )\r\n\t{\r\n\t\t_active.Add( new Stimulus( kind, position, source, radius, Time.Now \u002B lifetime ) );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Active stimuli whose range reaches a position.\r\n\t/// \u003C/summary\u003E\r\n\tpublic IEnumerable\u003CStimulus\u003E Near( Vector3 position )\r\n\t{\r\n\t\tvar now = Time.Now;\r\n\r\n\t\tforeach ( var stimulus in _active )\r\n\t\t{\r\n\t\t\tif ( now \u003E= stimulus.Expiry )\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tif ( (position - stimulus.Position).LengthSquared \u003C= stimulus.Radius * stimulus.Radius )\r\n\t\t\t\tyield return stimulus;\r\n\t\t}\r\n\t}\r\n\r\n\tvoid Prune()\r\n\t{\r\n\t\tvar now = Time.Now;\r\n\r\n\t\tfor ( int i = _active.Count - 1; i \u003E= 0; i-- )\r\n\t\t{\r\n\t\t\tif ( now \u003E= _active[i].Expiry )\r\n\t\t\t\t_active.RemoveAt( i );\r\n\t\t}\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Npcs/Tasks/MoveTo.cs","FileName":"MoveTo.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"using Sandbox.Npcs.Layers;\r\n\r\nnamespace Sandbox.Npcs.Tasks;\r\n\r\n/// \u003Csummary\u003E\r\n/// Task that commands the NavigationLayer to move to a target position or GameObject.\r\n/// When tracking a GameObject, re-evaluates the path periodically.\r\n/// Does not override the NPC\u0027s look target \u2014 but will rotate the body to face the\r\n/// movement direction when the angle would otherwise cause silly walking\r\n/// \u003C/summary\u003E\r\npublic class MoveTo : TaskBase\r\n{\r\n\tpublic Vector3? TargetPosition { get; set; }\r\n\tpublic GameObject TargetObject { get; set; }\r\n\tpublic float StopDistance { get; set; } = 10f;\r\n\tpublic float ReevaluateInterval { get; set; } = 0.5f;\r\n\r\n\t/// \u003Csummary\u003EMovement speed for this task. Null uses the NPC\u0027s configured speed.\u003C/summary\u003E\r\n\tpublic float? Speed { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Keep facing this object while moving instead of turning into the movement\r\n\t/// direction. The NPC backpedals or strafes -- short moves away from someone\r\n\t/// happen without turning our back on them.\r\n\t/// \u003C/summary\u003E\r\n\tpublic GameObject FaceTarget { get; set; }\r\n\r\n\tprivate TimeSince _lastReevaluate;\r\n\r\n\tpublic MoveTo( Vector3 targetPosition, float stopDistance = 10f )\r\n\t{\r\n\t\tTargetPosition = targetPosition;\r\n\t\tStopDistance = stopDistance;\r\n\t}\r\n\r\n\tpublic MoveTo( GameObject targetObject, float stopDistance = 10f )\r\n\t{\r\n\t\tTargetObject = targetObject;\r\n\t\tStopDistance = stopDistance;\r\n\t}\r\n\r\n\tprotected override void OnStart()\r\n\t{\r\n\t\tvar pos = GetTargetPosition();\r\n\t\tif ( !pos.HasValue ) return;\r\n\r\n\t\tNpc.Navigation.MoveTo( pos.Value, StopDistance, Speed, FaceTarget );\r\n\t\t_lastReevaluate = 0;\r\n\t}\r\n\r\n\tprotected override TaskStatus OnUpdate()\r\n\t{\r\n\t\t// Target object destroyed mid-move\r\n\t\tif ( TargetObject is not null \u0026\u0026 !TargetObject.IsValid() )\r\n\t\t\treturn TaskStatus.Failed;\r\n\r\n\t\t// Re-evaluate path for moving targets\r\n\t\tif ( TargetObject.IsValid() \u0026\u0026 _lastReevaluate \u003E ReevaluateInterval )\r\n\t\t{\r\n\t\t\tvar pos = GetTargetPosition();\r\n\t\t\tif ( pos.HasValue )\r\n\t\t\t\tNpc.Navigation.MoveTo( pos.Value, StopDistance, Speed, FaceTarget );\r\n\t\t\t_lastReevaluate = 0;\r\n\t\t}\r\n\r\n\t\treturn Npc.Navigation.GetStatus();\r\n\t}\r\n\r\n\tprotected override void OnEnd()\r\n\t{\r\n\t\tNpc.Navigation.Stop();\r\n\t}\r\n\r\n\tprivate Vector3? GetTargetPosition()\r\n\t{\r\n\t\tif ( TargetObject.IsValid() )\r\n\t\t{\r\n\t\t\t// Navigate to the closest point on the object\u0027s bounds, not its origin.\r\n\t\t\t// This prevents the NPC from trying to walk inside large props.\r\n\t\t\tvar bounds = TargetObject.GetBounds();\r\n\t\t\treturn bounds.ClosestPoint( Npc.WorldPosition );\r\n\t\t}\r\n\r\n\t\treturn TargetPosition;\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Player/Player.ConsoleCommands.cs","FileName":"Player.ConsoleCommands.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"public sealed partial class Player\r\n{\r\n\t/// \u003Csummary\u003E\r\n\t/// Kill yourself\r\n\t/// \u003C/summary\u003E\r\n\t[ConCmd( \u0022kill\u0022 )]\r\n\tpublic static void KillSelf( Connection source )\r\n\t{\r\n\t\tvar player = Player.FindForConnection( source );\r\n\t\tif ( player is null ) return;\r\n\r\n\t\tplayer.KillSelf();\r\n\t}\r\n\r\n\t[Rpc.Host]\r\n\tinternal void KillSelf()\r\n\t{\r\n\t\tif ( Rpc.Caller != Network.Owner ) return;\r\n\r\n\t\tthis.OnDamage( new DamageInfo( float.MaxValue, GameObject, null ) );\r\n\t}\r\n\r\n\t[ConCmd( \u0022god\u0022, ConVarFlags.Server, Help = \u0022Toggle invulnerability\u0022 )]\r\n\tpublic static void God( Connection source )\r\n\t{\r\n\t\tvar player = PlayerData.For( source );\r\n\t\tif ( !player.IsValid() )\r\n\t\t\treturn;\r\n\r\n\t\t// turning it off is always allowed\r\n\t\tif ( !player.IsGodMode \u0026\u0026 !ServerSettings.CanUseGodMode( source ) )\r\n\t\t{\r\n\t\t\tsource.SendLog( LogLevel.Info, \u0022Godmode is disabled on this server\u0022 );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tplayer.IsGodMode = !player.IsGodMode;\r\n\t\tsource.SendLog( LogLevel.Info, player.IsGodMode ? \u0022Godmode enabled\u0022 : \u0022Godmode disabled\u0022 );\r\n\t}\r\n\r\n\t[ConCmd( \u0022noclip\u0022, Help = \u0022Toggle noclip\u0022 )]\r\n\tpublic static void Noclip()\r\n\t{\r\n\t\tFindLocalPlayer()?.ToggleNoclip();\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Switch to another map\r\n\t/// \u003C/summary\u003E\r\n\t[ConCmd( \u0022map\u0022, ConVarFlags.Admin )]\r\n\tpublic static void ChangeMap( string mapName )\r\n\t{\r\n\t\tvar e = new AdminActionEvent { Action = AdminAction.ChangeMap, Value = mapName };\r\n\t\tif ( !e.Run() ) return;\r\n\r\n\t\tLaunchArguments.Map = e.Value;\r\n\t\te.Done();\r\n\t\tGame.Load( Game.Ident, true );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Undo the last action for the calling player\r\n\t/// \u003C/summary\u003E\r\n\t[ConCmd( \u0022undo\u0022, ConVarFlags.Server )]\r\n\tpublic static void RunUndo( Connection source )\r\n\t{\r\n\t\tvar player = Player.FindForConnection( source );\r\n\t\tif ( !player.IsValid() )\r\n\t\t\treturn;\r\n\r\n\t\tplayer.Undo.Undo();\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Player/Player.Static.cs","FileName":"Player.Static.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"public sealed partial class Player : Component, Component.IDamageable, PlayerController.IEvents, Global.ISaveEvents, IKillSource\r\n{\r\n\tprivate static Player LocalPlayer { get; set; }\r\n\tpublic static Player FindLocalPlayer() =\u003E LocalPlayer;\r\n\tpublic static T FindLocalWeapon\u003CT\u003E() where T : BaseSandboxWeapon =\u003E FindLocalPlayer()?.GetComponentInChildren\u003CT\u003E( true );\r\n\tpublic static T FindLocalToolMode\u003CT\u003E() where T : ToolMode =\u003E FindLocalPlayer()?.GetComponentInChildren\u003CT\u003E( true );\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Find a player for this connection\r\n\t/// \u003C/summary\u003E\r\n\tpublic static Player FindForConnection( Connection c )\r\n\t{\r\n\t\treturn Game.ActiveScene.GetAll\u003CPlayer\u003E().FirstOrDefault( x =\u003E x.Network.Owner == c );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Get player from a connection id\r\n\t/// \u003C/summary\u003E\r\n\tpublic static Player For( Guid playerId )\r\n\t{\r\n\t\treturn Game.ActiveScene.GetAll\u003CPlayer\u003E().FirstOrDefault( x =\u003E x.Network.Owner?.Id == playerId );\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Player/PlayerEvent.cs","FileName":"PlayerEvent.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"public struct PlayerDiedParams\r\n{\r\n\tpublic GameObject Attacker { get; set; }\r\n}\r\n\r\npublic struct PlayerDamageParams\r\n{\r\n\tpublic float Damage { get; set; }\r\n\tpublic GameObject Attacker { get; set; }\r\n\tpublic GameObject Weapon { get; set; }\r\n\tpublic TagSet Tags { get; set; }\r\n\tpublic Vector3 Position { get; set; }\r\n\tpublic Vector3 Origin { get; set; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Data passed to pickup events. Set \u003Csee cref=\u0022Cancelled\u0022/\u003E to true to prevent the pickup.\r\n/// \u003C/summary\u003E\r\npublic class PlayerPickupEvent\r\n{\r\n\tpublic Player Player { get; init; }\r\n\tpublic BaseSandboxWeapon Weapon { get; init; }\r\n\tpublic int Slot { get; init; }\r\n\tpublic bool Cancelled { get; set; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Data passed to drop events. Set \u003Csee cref=\u0022Cancelled\u0022/\u003E to true to prevent the drop.\r\n/// \u003C/summary\u003E\r\npublic class PlayerDropEvent\r\n{\r\n\tpublic Player Player { get; init; }\r\n\tpublic BaseSandboxWeapon Weapon { get; init; }\r\n\tpublic bool Cancelled { get; set; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Fired from player\u0027s client when they try to pick up an object, and again on the instance that simulates it before it\u0027s moved for them. Set \u003Csee cref=\u0022Cancelled\u0022/\u003E to true to refuse, or change \u003Csee cref=\u0022MaxMass\u0022/\u003E to let them lift more or less. See \u003Csee cref=\u0022PlayerCarry\u0022/\u003E.\r\n/// \u003C/summary\u003E\r\npublic class PlayerCarryEvent\r\n{\r\n\tpublic Player Player { get; init; }\r\n\tpublic GameObject Target { get; init; }\r\n\tpublic Rigidbody Body { get; init; }\r\n\tpublic float Mass { get; init; }\r\n\tpublic float MaxMass { get; set; }\r\n\tpublic bool Cancelled { get; set; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Data passed to switch weapon events. Set \u003Csee cref=\u0022Cancelled\u0022/\u003E to true to prevent the switch.\r\n/// \u003C/summary\u003E\r\npublic class PlayerSwitchWeaponEvent\r\n{\r\n\tpublic Player Player { get; init; }\r\n\tpublic BaseSandboxWeapon From { get; init; }\r\n\tpublic BaseSandboxWeapon To { get; init; }\r\n\tpublic bool Cancelled { get; set; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Data passed to remove weapon events. Set \u003Csee cref=\u0022Cancelled\u0022/\u003E to true to prevent the removal.\r\n/// \u003C/summary\u003E\r\npublic class PlayerRemoveWeaponEvent\r\n{\r\n\tpublic Player Player { get; init; }\r\n\tpublic BaseSandboxWeapon Weapon { get; init; }\r\n\tpublic bool Cancelled { get; set; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Data passed to slot move events. Set \u003Csee cref=\u0022Cancelled\u0022/\u003E to true to prevent the move.\r\n/// \u003C/summary\u003E\r\npublic class PlayerMoveSlotEvent\r\n{\r\n\tpublic Player Player { get; init; }\r\n\tpublic int FromSlot { get; init; }\r\n\tpublic int ToSlot { get; init; }\r\n\tpublic bool Cancelled { get; set; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Fired on the host when a player sits in a seat, before their weapon is put away. \r\n/// Set \u003Csee cref=\u0022Cancelled\u0022/\u003E to true to let them keep weapons out in it.\r\n/// \u003C/summary\u003E\r\npublic class PlayerSeatHolsterEvent\r\n{\r\n\tpublic Player Player { get; init; }\r\n\tpublic GameObject Seat { get; init; }\r\n\tpublic BaseSandboxWeapon Weapon { get; init; }\r\n\tpublic bool Cancelled { get; set; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Fired on the player\u0027s own machine when they press the flashlight key, before the flashlight toggles. Set\r\n/// \u003Csee cref=\u0022Cancelled\u0022/\u003E to true to keep the key for yourself - a vehicle uses it for its headlights.\r\n/// \u003C/summary\u003E\r\npublic class PlayerFlashlightEvent\r\n{\r\n\tpublic Player Player { get; init; }\r\n\tpublic bool Cancelled { get; set; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Pre-damage event. Fired before damage is applied. Listeners can modify \u003Csee cref=\u0022Damage\u0022/\u003E\r\n/// or set \u003Csee cref=\u0022Cancelled\u0022/\u003E to block damage entirely.\r\n/// \u003C/summary\u003E\r\npublic class PlayerDamageEvent\r\n{\r\n\tpublic Player Player { get; init; }\r\n\tpublic DamageInfo DamageInfo { get; init; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The player behind the damage, can be the victim. Null for the world and NPCs.\r\n\t/// \u003C/summary\u003E\r\n\tpublic Player BlamedPlayer { get; init; }\r\n\r\n\tpublic float Damage { get; set; }\r\n\tpublic bool Cancelled { get; set; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Pre-respawn event. Fired on the host before the player is spawned. Listeners can modify\r\n/// \u003Csee cref=\u0022SpawnLocation\u0022/\u003E to control where the player appears, or set \u003Csee cref=\u0022Cancelled\u0022/\u003E\r\n/// to stop the spawn entirely - for example an addon running its own round loop that wants dead\r\n/// players to wait. A player cancelled after death stays in the observer state; spawn them later\r\n/// with \u003Csee cref=\u0022GameManager.Respawn\u0022/\u003E, which skips this event. This also fires for the first\r\n/// spawn on join, so a listener that cancels there is responsible for giving that connection\r\n/// something to look at.\r\n/// \u003C/summary\u003E\r\npublic class PlayerRespawnEvent\r\n{\r\n\tpublic PlayerData PlayerData { get; init; }\r\n\tpublic Transform SpawnLocation { get; set; }\r\n\tpublic bool Cancelled { get; set; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Fired on the host before a player is given their starter weapons, on spawning without a saved hotbar to restore.\r\n/// Edit \u003Csee cref=\u0022Items\u0022/\u003E to change what they get, or set \u003Csee cref=\u0022Cancelled\u0022/\u003E to true to give nothing.\r\n/// \u003C/summary\u003E\r\npublic class PlayerLoadoutEvent\r\n{\r\n\tpublic Player Player { get; init; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The weapon prefabs to give, in order. Starts as the player prefab\u0027s starting items.\r\n\t/// \u003C/summary\u003E\r\n\tpublic List\u003CGameObject\u003E Items { get; set; }\r\n\r\n\tpublic bool Cancelled { get; set; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Fired when a player kills another player or NPC.\r\n/// \u003C/summary\u003E\r\npublic class PlayerKillEvent\r\n{\r\n\tpublic Player Player { get; init; }\r\n\tpublic GameObject Victim { get; init; }\r\n\tpublic DamageInfo DamageInfo { get; init; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Events fired only to the Player\u0027s own GameObject hierarchy, except \u003Csee cref=\u0022IPlayerEvents.OnMove\u0022/\u003E and the\r\n/// camera events, which go to the whole scene on the machine controlling the local player so UI can listen too.\r\n/// \u003C/summary\u003E\r\npublic static partial class Local\r\n{\r\n\tpublic interface IPlayerEvents : ISceneEvent\u003CIPlayerEvents\u003E\r\n\t{\r\n\t\tvoid OnSpawned() { }\r\n\t\tvoid OnDied( PlayerDiedParams args ) { }\r\n\t\tvoid OnDamage( PlayerDamageParams args ) { }\r\n\t\tvoid OnJump() { }\r\n\t\tvoid OnLand( float distance, Vector3 velocity ) { }\r\n\t\tvoid OnSuicide() { }\r\n\t\tvoid OnPickup( PlayerPickupEvent e ) { }\r\n\t\tvoid OnDrop( PlayerDropEvent e ) { }\r\n\t\tvoid OnSwitchWeapon( PlayerSwitchWeaponEvent e ) { }\r\n\t\tvoid OnRemoveWeapon( PlayerRemoveWeaponEvent e ) { }\r\n\t\tvoid OnMoveSlot( PlayerMoveSlotEvent e ) { }\r\n\t\tvoid OnSeatHolster( PlayerSeatHolsterEvent e ) { }\r\n\t\tvoid OnFlashlight( PlayerFlashlightEvent e ) { }\r\n\t\tvoid OnCarry( PlayerCarryEvent e ) { }\r\n\t\tvoid OnDamaging( PlayerDamageEvent e ) { }\r\n\t\tvoid OnKill( PlayerKillEvent e ) { }\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// Called on the local player\u0027s machine as they look around, sent to the whole scene.\r\n\t\t/// \u003C/summary\u003E\r\n\t\tvoid OnCameraMove( ref Angles angles ) { }\r\n\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// Called on the local player\u0027s machine while their camera is set up, sent to the whole scene.\r\n\t\t/// \u003C/summary\u003E\r\n\t\tvoid OnCameraSetup( CameraComponent camera ) { }\r\n\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// Called on the local player\u0027s machine after their camera is set up, sent to the whole scene.\r\n\t\t/// \u003C/summary\u003E\r\n\t\tvoid OnCameraPostSetup( CameraComponent camera ) { }\r\n\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// Called every tick on the local player\u0027s machine before movement input is applied, sent to the whole scene.\r\n\t\t/// Set \u003Cparamref name=\u0022allowMovement\u0022/\u003E to false to prevent the player from moving with WASD this tick\r\n\t\t/// (e.g. while spinning a physgun-held object).\r\n\t\t/// \u003C/summary\u003E\r\n\t\tvoid OnMove( ref bool allowMovement ) { }\r\n\t}\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Events broadcasted to the entire scene for any player action.\r\n/// \u003C/summary\u003E\r\npublic static partial class Global\r\n{\r\n\tpublic interface IPlayerEvents : ISceneEvent\u003CIPlayerEvents\u003E\r\n\t{\r\n\t\tvoid OnPlayerSpawned( Player player ) { }\r\n\t\tvoid OnPlayerDied( Player player, PlayerDiedParams args ) { }\r\n\t\tvoid OnPlayerDamage( Player player, PlayerDamageParams args ) { }\r\n\t\tvoid OnPlayerJumped( Player player ) { }\r\n\t\tvoid OnPlayerLanded( Player player, float distance, Vector3 velocity ) { }\r\n\t\tvoid OnPlayerSuicide( Player player ) { }\r\n\t\tvoid OnPlayerPickup( PlayerPickupEvent e ) { }\r\n\t\tvoid OnPlayerDrop( PlayerDropEvent e ) { }\r\n\t\tvoid OnPlayerSwitchWeapon( PlayerSwitchWeaponEvent e ) { }\r\n\t\tvoid OnPlayerRemoveWeapon( PlayerRemoveWeaponEvent e ) { }\r\n\t\tvoid OnPlayerMoveSlot( PlayerMoveSlotEvent e ) { }\r\n\t\tvoid OnPlayerSeatHolster( PlayerSeatHolsterEvent e ) { }\r\n\t\tvoid OnPlayerFlashlight( PlayerFlashlightEvent e ) { }\r\n\t\tvoid OnPlayerCarry( PlayerCarryEvent e ) { }\r\n\t\t[Obsolete( \u0022Use Global.IDamageEvents, it covers players and NPCs\u0022 )]\r\n\t\tvoid OnPlayerDamaging( PlayerDamageEvent e ) { }\r\n\t\tvoid OnPlayerRespawning( PlayerRespawnEvent e ) { }\r\n\t\tvoid OnPlayerLoadout( PlayerLoadoutEvent e ) { }\r\n\t\tvoid OnPlayerKill( PlayerKillEvent e ) { }\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Player/PlayerInventory.cs","FileName":"PlayerInventory.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"using Sandbox.Citizen;\r\n\r\npublic sealed partial class PlayerInventory : BaseInventoryComponent, Local.IPlayerEvents\r\n{\r\n\t// MaxSlots, ActiveItem, the active-item enable/disable \u002B equip/holster and the add/remove/drop/\r\n\t// move-slot flows come from the engine BaseInventoryComponent. This adds the sandbox\u0027s events, ammo\r\n\t// merging, notices and undo handling through the engine\u0027s hooks.\r\n\r\n\t[RequireComponent] public Player Player { get; set; }\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// All weapons currently in the inventory, ordered by slot. Narrowing shim over engine Items.\r\n\t/// \u003C/summary\u003E\r\n\tpublic IEnumerable\u003CBaseSandboxWeapon\u003E Weapons =\u003E Items.OfType\u003CBaseSandboxWeapon\u003E();\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The currently active weapon. Narrowing shim over the engine\u0027s \u003Csee cref=\u0022BaseInventoryComponent.ActiveItem\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tpublic BaseSandboxWeapon ActiveWeapon =\u003E ActiveItem as BaseSandboxWeapon;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Returns the weapon in the given slot, or null if the slot is empty.\r\n\t/// \u003C/summary\u003E\r\n\tpublic new BaseSandboxWeapon GetSlot( int slot ) =\u003E base.GetSlot( slot ) as BaseSandboxWeapon;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// A weapon of the same class we already carry, if any. Duplicate handling itself is the\r\n\t/// engine\u0027s (a duplicate donates its magazine to the reserve, see BaseCombatWeapon.OnAdding) - this\r\n\t/// just finds the weapon the donation lands on, for the pickup notices.\r\n\t/// \u003C/summary\u003E\r\n\tprivate BaseSandboxWeapon FindExistingWeapon( BaseSandboxWeapon like )\r\n\t\t=\u003E like.IsValid() ? Weapons.FirstOrDefault( x =\u003E x.GetType() == like.GetType() ) : null;\r\n\r\n\t// FindEmptySlot is inherited from the engine BaseInventoryComponent.\r\n\r\n\t// The default weapons come from the engine\u0027s Loadout feature, configured on the player prefab -\r\n\t// PlayerLoadout calls GiveLoadout() when there\u0027s no saved hotbar to restore.\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Activates the named tool mode, giving and equipping the toolgun first if the player doesn\u0027t have one.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void SetToolMode( string name )\r\n\t{\r\n\t\tif ( !Networking.IsHost )\r\n\t\t{\r\n\t\t\tHostSetToolMode( name );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tif ( !HasWeapon\u003CToolgun\u003E() )\r\n\t\t{\r\n\t\t\tPickup( \u0022weapons/toolgun/toolgun.prefab\u0022, false );\r\n\t\t}\r\n\r\n\t\tvar toolGun = GetWeapon\u003CToolgun\u003E();\r\n\t\tif ( !toolGun.IsValid() ) \r\n\t\t\treturn;\r\n\r\n\t\tSwitchWeapon( toolGun );\r\n\t\ttoolGun.SetToolMode( name );\r\n\t}\r\n\r\n\t[Rpc.Host]\r\n\tprivate void HostSetToolMode( string toolModeName )\r\n\t{\r\n\t\tSetToolMode( toolModeName );\r\n\t}\r\n\r\n\tpublic bool Pickup( string prefabName, bool notice = true ) =\u003E Pickup( prefabName, -1, notice );\r\n\r\n\tpublic bool HasWeapon( GameObject prefab )\r\n\t{\r\n\t\tvar baseCarry = prefab.GetComponent\u003CBaseSandboxWeapon\u003E( true );\r\n\t\tif ( !baseCarry.IsValid() )\r\n\t\t\treturn false;\r\n\r\n\t\treturn Weapons.Where( x =\u003E x.GetType() == baseCarry.GetType() )\r\n\t\t\t.FirstOrDefault()\r\n\t\t\t.IsValid();\r\n\t}\r\n\r\n\tpublic bool HasWeapon\u003CT\u003E() where T : BaseSandboxWeapon\r\n\t{\r\n\t\treturn GetWeapon\u003CT\u003E().IsValid();\r\n\t}\r\n\r\n\tpublic T GetWeapon\u003CT\u003E() where T : BaseSandboxWeapon\r\n\t{\r\n\t\t// Same pick as the first of Items (lowest slot, then slot order), without sorting them all\r\n\t\tT best = null;\r\n\t\tforeach ( var weapon in GetComponentsInChildren\u003CT\u003E( true ) )\r\n\t\t{\r\n\t\t\tif ( weapon.GameObject.IsDestroyed || weapon.Inventory != this ) continue;\r\n\t\t\tif ( best is not null \u0026\u0026 (weapon.Slot, weapon.SlotOrder).CompareTo( (best.Slot, best.SlotOrder) ) \u003E= 0 ) continue;\r\n\r\n\t\t\tbest = weapon;\r\n\t\t}\r\n\r\n\t\treturn best;\r\n\t}\r\n\r\n\tpublic bool Pickup( GameObject prefab, bool notice = true ) =\u003E Pickup( prefab, -1, notice );\r\n\r\n\tpublic bool Pickup( string prefabName, int targetSlot, bool notice = true )\r\n\t{\r\n\t\tif ( !Networking.IsHost )\r\n\t\t\treturn false;\r\n\r\n\t\tvar prefab = GameObject.GetPrefab( prefabName );\r\n\t\tif ( prefab is null )\r\n\t\t{\r\n\t\t\tLog.Warning( $\u0022Prefab not found: {prefabName}\u0022 );\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\treturn Pickup( prefab, targetSlot, notice );\r\n\t}\r\n\r\n\tpublic bool Pickup( GameObject prefab, int targetSlot, bool notice = true )\r\n\t{\r\n\t\tif ( !Networking.IsHost )\r\n\t\t\treturn false;\r\n\r\n\t\t// The engine consumes a duplicate as an ammo donation (see BaseCombatWeapon.OnAdding) - watch the\r\n\t\t// pool so the ammo notice can fire.\r\n\t\tvar existing = FindExistingWeapon( prefab.GetComponent\u003CBaseSandboxWeapon\u003E( true ) );\r\n\t\tvar ammoBefore = existing.IsValid() ? existing.Ammo1 : 0;\r\n\r\n\t\t// Engine pickup: clone, network spawn, parent, slot, ownership. The cancellable pickup event\r\n\t\t// fires from OnAdding; the engine destroys the clone if it\u0027s refused.\r\n\t\tif ( base.Pickup( prefab, targetSlot ) is BaseSandboxWeapon weapon )\r\n\t\t{\r\n\t\t\tif ( notice )\r\n\t\t\t\tOnClientPickup( weapon, given: true );\r\n\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\t// Refused as a duplicate - donated or already topped up, either way it counts as taken.\r\n\t\tif ( existing.IsValid() )\r\n\t\t{\r\n\t\t\tif ( notice \u0026\u0026 existing.Ammo1 \u003E ammoBefore )\r\n\t\t\t{\r\n\t\t\t\tNotifyAmmoPickup( existing.PrimaryAmmoType, existing.Ammo1 - ammoBefore );\r\n\t\t\t\tOnClientPickup( existing, true );\r\n\t\t\t}\r\n\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\treturn false;\r\n\t}\r\n\r\n\tpublic bool Take( BaseSandboxWeapon item, bool includeNotices )\r\n\t{\r\n\t\tif ( !item.IsValid() )\r\n\t\t\treturn false;\r\n\r\n\t\tvar existing = FindExistingWeapon( item );\r\n\t\tvar ammoBefore = existing.IsValid() ? existing.Ammo1 : 0;\r\n\r\n\t\t// Engine add: parent, slot, ownership, disable. The cancellable pickup event fires from\r\n\t\t// OnAdding, and a duplicate donates its magazine to the reserve and is consumed there.\r\n\t\tif ( Add( item ) )\r\n\t\t{\r\n\t\t\t// Remove from undo stacks so the weapon can\u0027t be undone out of our hands\r\n\t\t\tUndoSystem.Current.Remove( item.GameObject );\r\n\r\n\t\t\tif ( includeNotices )\r\n\t\t\t\tOnClientPickup( item );\r\n\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\t// Consumed by the donation - that\u0027s a take too. A refused item stays in the world.\r\n\t\tif ( item.GameObject.IsDestroyed )\r\n\t\t{\r\n\t\t\tif ( includeNotices \u0026\u0026 existing.IsValid() \u0026\u0026 existing.Ammo1 \u003E ammoBefore )\r\n\t\t\t{\r\n\t\t\t\tNotifyAmmoPickup( existing.PrimaryAmmoType, existing.Ammo1 - ammoBefore );\r\n\t\t\t\tOnClientPickup( existing, true );\r\n\t\t\t}\r\n\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\treturn false;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Engine Touch pickup lands here (see \u003Csee cref=\u0022BaseInventoryComponent.PickupMode\u0022/\u003E). Routes into\r\n\t/// \u003Csee cref=\u0022Take\u0022/\u003E, so duplicates donate their ammo and the pickup notices fire. Contraption-\r\n\t/// wired weapons refuse themselves (see \u003Csee cref=\u0022BaseSandboxWeapon\u0022/\u003E\u0027s OnCanPickup).\r\n\t/// \u003C/summary\u003E\r\n\tpublic override void PickupWorldItem( Sandbox.BaseInventoryItem item )\r\n\t{\r\n\t\tif ( !Networking.IsHost )\r\n\t\t{\r\n\t\t\tbase.PickupWorldItem( item );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tif ( item is not BaseSandboxWeapon weapon )\r\n\t\t\treturn;\r\n\r\n\t\tif ( !CanPickupWorldItem( weapon ) )\r\n\t\t\treturn;\r\n\r\n\t\tTake( weapon, true );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Fires the cancellable pickup events before the engine adds an item.\r\n\t/// \u003C/summary\u003E\r\n\tprotected override bool OnAdding( Sandbox.BaseInventoryItem item, int slot )\r\n\t{\r\n\t\tif ( item is not BaseSandboxWeapon weapon )\r\n\t\t\treturn true;\r\n\r\n\t\tvar pickupEvent = new PlayerPickupEvent { Player = Player, Weapon = weapon, Slot = slot };\r\n\t\tLocal.IPlayerEvents.PostToGameObject( Player.GameObject, e =\u003E e.OnPickup( pickupEvent ) );\r\n\t\tGlobal.IPlayerEvents.Post( e =\u003E e.OnPlayerPickup( pickupEvent ) );\r\n\r\n\t\treturn !pickupEvent.Cancelled;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Drops the given weapon from the inventory. The engine holsters it, the weapon throws itself\r\n\t/// into the world (see \u003Csee cref=\u0022BaseSandboxWeapon.OnDrop\u0022/\u003E) and we switch to the best remaining\r\n\t/// weapon. The cancellable drop event fires from \u003Csee cref=\u0022OnDropping\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void Drop( BaseSandboxWeapon weapon )\r\n\t{\r\n\t\tif ( weapon.IsValid() \u0026\u0026 weapon.Owner != Player )\r\n\t\t\treturn;\r\n\r\n\t\tbase.Drop( weapon );\r\n\t}\r\n\r\n\tprotected override bool OnDropping( Sandbox.BaseInventoryItem item )\r\n\t{\r\n\t\tif ( item is not BaseSandboxWeapon weapon )\r\n\t\t\treturn true;\r\n\r\n\t\tvar dropEvent = new PlayerDropEvent { Player = Player, Weapon = weapon };\r\n\t\tLocal.IPlayerEvents.PostToGameObject( Player.GameObject, e =\u003E e.OnDrop( dropEvent ) );\r\n\t\tGlobal.IPlayerEvents.Post( e =\u003E e.OnPlayerDrop( dropEvent ) );\r\n\r\n\t\treturn !dropEvent.Cancelled;\r\n\t}\r\n\r\n\tprivate static SoundEvent AmmoPickupSound = ResourceLibrary.Get\u003CSoundEvent\u003E( \u0022sounds/weapons/ammo_pickup.sound\u0022 );\r\n\tprivate static SoundEvent GunPickupSound = ResourceLibrary.Get\u003CSoundEvent\u003E( \u0022sounds/weapons/gun_pickup.sound\u0022 );\r\n\r\n\t[Rpc.Owner]\r\n\tprivate void OnClientPickup( BaseSandboxWeapon weapon, bool justAmmo = false, bool given = false )\r\n\t{\r\n\t\tif ( !weapon.IsValid() ) return;\r\n\r\n\t\tif ( !justAmmo \u0026\u0026 ShouldAutoswitchTo( weapon, given ) )\r\n\t\t{\r\n\t\t\tSwitchWeapon( weapon );\r\n\t\t}\r\n\r\n\t\tif ( Player.IsLocalPlayer )\r\n\t\t{\r\n\t\t\tGameObject.PlaySound( justAmmo ? AmmoPickupSound : GunPickupSound );\r\n\t\t\tGlobal.IPlayerEvents.Post( e =\u003E e.OnPlayerPickup( new PlayerPickupEvent { Player = Player, Weapon = weapon, Slot = weapon.Slot } ) );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Whether picking up \u003Cparamref name=\u0022item\u0022/\u003E should switch to it. \u003Cparamref name=\u0022given\u0022/\u003E means it was handed over explicitly\r\n\t/// (spawn menu, give): that still honours AutoSwitch and a weapon in use, but skips the value comparison.\r\n\t/// \u003C/summary\u003E\r\n\tprivate bool ShouldAutoswitchTo( BaseSandboxWeapon item, bool given = false )\r\n\t{\r\n\t\tAssert.True( item.IsValid(), \u0022item invalid\u0022 );\r\n\r\n\t\tif ( !ActiveWeapon.IsValid() )\r\n\t\t\treturn true;\r\n\r\n\t\tif ( !GamePreferences.AutoSwitch )\r\n\t\t\treturn false;\r\n\r\n\t\tif ( ActiveWeapon.IsInUse() )\r\n\t\t\treturn false;\r\n\r\n\t\tif ( given )\r\n\t\t\treturn true;\r\n\r\n\t\t// Nothing to fire or load - the engine flags spent guns.\r\n\t\tif ( item.ShouldAvoid )\r\n\t\t\treturn false;\r\n\r\n\t\treturn item.Value \u003E ActiveWeapon.Value;\r\n\t}\r\n\r\n\t// MoveSlot comes from the engine BaseInventoryComponent - the cancellable move event fires from this\r\n\t// hook.\r\n\tprotected override bool OnMovingSlot( int fromSlot, int toSlot )\r\n\t{\r\n\t\tvar moveEvent = new PlayerMoveSlotEvent { Player = Player, FromSlot = fromSlot, ToSlot = toSlot };\r\n\t\tLocal.IPlayerEvents.PostToGameObject( Player.GameObject, e =\u003E e.OnMoveSlot( moveEvent ) );\r\n\t\tGlobal.IPlayerEvents.Post( e =\u003E e.OnPlayerMoveSlot( moveEvent ) );\r\n\r\n\t\treturn !moveEvent.Cancelled;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The weapon the inventory would auto-switch to. The engine\u0027s \u003Csee cref=\u0022BaseInventoryComponent.GetBestItem\u0022/\u003E\r\n\t/// handles the Value ordering and the avoid-empty-guns fallback.\r\n\t/// \u003C/summary\u003E\r\n\tpublic BaseSandboxWeapon GetBestWeapon() =\u003E GetBestItem() as BaseSandboxWeapon;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Asks whether this player may switch to \u003Cparamref name=\u0022weapon\u0022/\u003E (null means holster). Checks the\r\n\t/// weapon\u0027s own \u003Csee cref=\u0022Sandbox.BaseInventoryItem.CanSwitchTo\u0022/\u003E, then fires the cancellable\r\n\t/// switch event on the player and scene-wide, so addons can refuse. Runs wherever it\u0027s called - the\r\n\t/// hotbar uses it client-side to filter, \u003Csee cref=\u0022SwitchWeapon\u0022/\u003E uses it as the gate. Voluntary\r\n\t/// switches are therefore vetoed on the initiating client; the engine\u0027s host path isn\u0027t hookable.\r\n\t/// \u003C/summary\u003E\r\n\tpublic bool CanSwitchTo( BaseSandboxWeapon weapon )\r\n\t{\r\n\t\tif ( weapon.IsValid() \u0026\u0026 !weapon.CanSwitchTo() )\r\n\t\t\treturn false;\r\n\r\n\t\tvar switchEvent = new PlayerSwitchWeaponEvent { Player = Player, From = ActiveWeapon, To = weapon };\r\n\t\tLocal.IPlayerEvents.PostToGameObject( Player.GameObject, e =\u003E e.OnSwitchWeapon( switchEvent ) );\r\n\t\tGlobal.IPlayerEvents.Post( e =\u003E e.OnPlayerSwitchWeapon( switchEvent ) );\r\n\r\n\t\treturn !switchEvent.Cancelled;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Switches to the given weapon after asking \u003Csee cref=\u0022CanSwitchTo\u0022/\u003E. Wraps the engine inventory\u0027s\r\n\t/// \u003Csee cref=\u0022BaseInventoryComponent.Switch\u0022/\u003E, which handles host-routing and the outgoing weapon\u0027s\r\n\t/// holster veto. Forced switches (death, drop, removal) don\u0027t come through here and can\u0027t be vetoed.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void SwitchWeapon( BaseSandboxWeapon weapon, bool allowHolster = false )\r\n\t{\r\n\t\t// Re-selecting the active weapon is a no-op unless it\u0027s a holster toggle\r\n\t\tif ( weapon.IsValid() \u0026\u0026 weapon == ActiveWeapon \u0026\u0026 !allowHolster )\r\n\t\t\treturn;\r\n\r\n\t\t// Toggling the active slot holsters, so the event sees that as switching to nothing\r\n\t\tvar to = weapon == ActiveWeapon ? null : weapon;\r\n\t\tif ( !CanSwitchTo( to ) )\r\n\t\t\treturn;\r\n\r\n\t\tSwitch( weapon, allowHolster );\r\n\t}\r\n\r\n\tpublic void OnControl()\r\n\t{\r\n\t\tif ( Input.Pressed( \u0022drop\u0022 ) \u0026\u0026 ActiveWeapon.IsValid() )\r\n\t\t\tDropActiveWeapon();\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Called by the owning client to drop their currently held weapon.\r\n\t/// \u003C/summary\u003E\r\n\t[Rpc.Host]\r\n\tprivate void DropActiveWeapon()\r\n\t{\r\n\t\tif ( !ActiveWeapon.IsValid() ) return;\r\n\t\tDrop( ActiveWeapon );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Removes a weapon from the inventory and destroys it without dropping it into the world. The\r\n\t/// engine holsters it, destroys it and switches to the best remaining weapon. The cancellable\r\n\t/// remove event fires from \u003Csee cref=\u0022OnRemoving\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void Remove( BaseSandboxWeapon weapon )\r\n\t{\r\n\t\tif ( weapon.IsValid() \u0026\u0026 weapon.Owner != Player )\r\n\t\t\treturn;\r\n\r\n\t\tbase.Remove( weapon );\r\n\t}\r\n\r\n\tprotected override bool OnRemoving( Sandbox.BaseInventoryItem item )\r\n\t{\r\n\t\tif ( item is not BaseSandboxWeapon weapon )\r\n\t\t\treturn true;\r\n\r\n\t\tvar removeEvent = new PlayerRemoveWeaponEvent { Player = Player, Weapon = weapon };\r\n\t\tLocal.IPlayerEvents.PostToGameObject( Player.GameObject, e =\u003E e.OnRemoveWeapon( removeEvent ) );\r\n\t\tGlobal.IPlayerEvents.Post( e =\u003E e.OnPlayerRemoveWeapon( removeEvent ) );\r\n\r\n\t\treturn !removeEvent.Cancelled;\r\n\t}\r\n\r\n\tvoid Local.IPlayerEvents.OnDied( PlayerDiedParams args )\r\n\t{\r\n\t\tif ( ActiveWeapon.IsValid() )\r\n\t\t{\r\n\t\t\tActiveWeapon.OnPlayerDeath( args );\r\n\t\t}\r\n\t}\r\n\r\n\tvoid Local.IPlayerEvents.OnJump()\r\n\t{\r\n\t\tif ( ActiveWeapon.IsValid() )\r\n\t\t{\r\n\t\t\tActiveWeapon.OnJump();\r\n\t\t}\r\n\t}\r\n\r\n\tvoid Local.IPlayerEvents.OnCameraMove( ref Angles angles )\r\n\t{\r\n\t\tif ( !ActiveWeapon.IsValid() ) return;\r\n\r\n\t\tActiveWeapon.OnCameraMove( Player, ref angles );\r\n\t}\r\n\r\n\tvoid Local.IPlayerEvents.OnCameraPostSetup( Sandbox.CameraComponent camera )\r\n\t{\r\n\t\tif ( !ActiveWeapon.IsValid() ) return;\r\n\r\n\t\tActiveWeapon.OnCameraSetup( Player, camera );\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"Spawner/CloudLoadTracker.cs","FileName":"CloudLoadTracker.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"\r\n/// \u003Csummary\u003E\r\n/// Tracks how many spawner payloads are loading on behalf of the local player, so the\r\n/// \u003Csee cref=\u0022CloudLoadRing\u0022/\u003E shows on the client who asked for the spawn - not whoever happens\r\n/// to be doing the loading (usually the host). Call \u003Csee cref=\u0022Track\u0022/\u003E with the requesting connection.\r\n/// \u003C/summary\u003E\r\npublic static class CloudLoadTracker\r\n{\r\n\tstatic int _active;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// True while any spawner requested by the local player is still loading its payload.\r\n\t/// \u003C/summary\u003E\r\n\tpublic static bool IsLoading =\u003E _active \u003E 0;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Show the loading ring for \u003Cparamref name=\u0022owner\u0022/\u003E until \u003Cparamref name=\u0022loading\u0022/\u003E completes.\r\n\t/// A null owner means the local connection.\r\n\t/// \u003C/summary\u003E\r\n\tpublic static void Track( Task\u003Cbool\u003E loading, Connection owner = null )\r\n\t{\r\n\t\tif ( loading is null || loading.IsCompleted ) return;\r\n\r\n\t\tif ( owner is null || owner == Connection.Local )\r\n\t\t{\r\n\t\t\t_active\u002B\u002B;\r\n\t\t\t_ = Untrack( loading, null );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tusing ( Rpc.FilterInclude( owner ) ) Begin();\r\n\t\t_ = Untrack( loading, owner );\r\n\t}\r\n\r\n\tstatic async Task Untrack( Task\u003Cbool\u003E loading, Connection owner )\r\n\t{\r\n\t\ttry\r\n\t\t{\r\n\t\t\tawait loading;\r\n\t\t}\r\n\t\tcatch\r\n\t\t{\r\n\t\t\t// Failures are reported by the spawner; we only care that loading has stopped.\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\tif ( owner is null )\r\n\t\t\t\t_active--;\r\n\t\t\telse\r\n\t\t\t\tusing ( Rpc.FilterInclude( owner ) ) End();\r\n\t\t}\r\n\t}\r\n\r\n\t[Rpc.Broadcast( NetFlags.HostOnly )]\r\n\tstatic void Begin() =\u003E _active\u002B\u002B;\r\n\r\n\t[Rpc.Broadcast( NetFlags.HostOnly )]\r\n\tstatic void End() =\u003E _active = Math.Max( 0, _active - 1 );\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"UI/Components/MixedVirtualGrid.cs","FileName":"MixedVirtualGrid.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"using Microsoft.AspNetCore.Components;\r\n\r\nnamespace Sandbox.UI;\r\n\r\n/// \u003Csummary\u003E\r\n/// Implemented by items that occupy a complete row in a \u003Csee cref=\u0022MixedVirtualGrid\u0022/\u003E.\r\n/// \u003C/summary\u003E\r\npublic interface IMixedVirtualGridFullRow\r\n{\r\n\tbool IsFullRow { get; }\r\n\tfloat Height { get; }\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// A virtual grid that mixes fixed-size tiles with full-width rows.\r\n/// \u003C/summary\u003E\r\npublic class MixedVirtualGrid : BaseVirtualPanel\r\n{\r\n\tprivate readonly record struct Row( int FirstIndex, int Count, float Top, float Height, bool FullWidth );\r\n\r\n\tprivate readonly List\u003CRow\u003E _rows = new();\r\n\tprivate int[] _rowForItem = [];\r\n\tprivate Rect _innerRect;\r\n\tprivate float _viewportHeight;\r\n\tprivate float _totalHeight;\r\n\tprivate float _tileWidth;\r\n\tprivate float _tileHeight;\r\n\tprivate Vector2 _spacing;\r\n\tprivate int _columns = 1;\r\n\tprivate int _geometryHash;\r\n\tprivate int _updateHash;\r\n\tprivate int _dropIndex = -1;\r\n\r\n\t[Parameter] public Vector2 ItemSize { get; set; } = new( 100, 100 );\r\n\t[Parameter] public bool FillWidth { get; set; } = true;\r\n\t[Parameter] public Func\u003CPanelEvent, bool\u003E CanAcceptDrop { get; set; }\r\n\t[Parameter] public Action\u003Cint, PanelEvent\u003E OnDropIndex { get; set; }\r\n\tprivate bool _dragHover;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Builds the cells again, for when they show more than their item, like the tile size.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void RecreateCells()\r\n\t{\r\n\t\tforeach ( var panel in _created.Values )\r\n\t\t\tpanel.Delete( true );\r\n\r\n\t\t_created.Clear();\r\n\t\t_cellData.Clear();\r\n\t\tNeedsRebuild = true;\r\n\t}\r\n\r\n\tprotected override void UpdateLayoutSpacing( Vector2 spacing )\r\n\t{\r\n\t\t_spacing = spacing;\r\n\t}\r\n\r\n\tprotected override bool UpdateLayout()\r\n\t{\r\n\t\tvar geometryHash = HashCode.Combine( Box.RectInner, Box.Rect, ScaleFromScreen, ItemSize, FillWidth, _spacing, _items.Count );\r\n\t\tif ( NeedsRebuild || geometryHash != _geometryHash )\r\n\t\t{\r\n\t\t\t_geometryHash = geometryHash;\r\n\t\t\tRebuildRows();\r\n\t\t}\r\n\r\n\t\tvar updateHash = HashCode.Combine( geometryHash, ScrollOffset.y );\r\n\t\tif ( updateHash == _updateHash ) return false;\r\n\r\n\t\t_updateHash = updateHash;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tprivate void RebuildRows()\r\n\t{\r\n\t\t_rows.Clear();\r\n\t\t_rowForItem = new int[_items.Count];\r\n\t\t_totalHeight = 0f;\r\n\r\n\t\tvar inner = Box.RectInner;\r\n\t\tinner.Position -= Box.Rect.Position;\r\n\t\t_innerRect = inner * ScaleFromScreen;\r\n\t\t_viewportHeight = Box.Rect.Height * ScaleFromScreen;\r\n\r\n\t\tvar nominalWidth = MathF.Max( 1f, ItemSize.x );\r\n\t\tvar nominalHeight = MathF.Max( 1f, ItemSize.y );\r\n\t\tvar stepX = nominalWidth \u002B _spacing.x;\r\n\t\tvar fit = (_innerRect.Width \u002B _spacing.x) / stepX;\r\n\t\t_tileWidth = nominalWidth;\r\n\t\t_tileHeight = nominalHeight;\r\n\r\n\t\tif ( FillWidth )\r\n\t\t{\r\n\t\t\t_columns = Math.Max( 1, (int)MathF.Round( fit ) );\r\n\t\t\t_tileWidth = MathF.Max( 1f, (_innerRect.Width - (_columns - 1) * _spacing.x) / _columns );\r\n\t\t\t_tileHeight = MathF.Max( 1f, _tileWidth * nominalHeight / nominalWidth );\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t_columns = Math.Max( 1, fit.FloorToInt() );\r\n\t\t}\r\n\r\n\t\tvar top = _innerRect.Top;\r\n\t\tvar index = 0;\r\n\t\twhile ( index \u003C _items.Count )\r\n\t\t{\r\n\t\t\tvar fullHeight = FullRowHeight( _items[index] );\r\n\t\t\tif ( fullHeight is not null )\r\n\t\t\t{\r\n\t\t\t\tAddRow( index, 1, top, fullHeight.Value, true );\r\n\t\t\t\ttop \u002B= fullHeight.Value \u002B _spacing.y;\r\n\t\t\t\tindex\u002B\u002B;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\tvar count = 1;\r\n\t\t\twhile ( count \u003C _columns \u0026\u0026 index \u002B count \u003C _items.Count \u0026\u0026 FullRowHeight( _items[index \u002B count] ) is null )\r\n\t\t\t\tcount\u002B\u002B;\r\n\r\n\t\t\tAddRow( index, count, top, _tileHeight, false );\r\n\t\t\ttop \u002B= _tileHeight \u002B _spacing.y;\r\n\t\t\tindex \u002B= count;\r\n\t\t}\r\n\r\n\t\tvar bottomPadding = MathF.Max( 0f, _viewportHeight - _innerRect.Bottom );\r\n\t\t_totalHeight = MathF.Max( 0f, top \u002B bottomPadding );\r\n\t}\r\n\r\n\tprivate static float? FullRowHeight( object item )\r\n\t{\r\n\t\tif ( item is not IMixedVirtualGridFullRow { IsFullRow: true } fullRow ) return null;\r\n\t\tif ( !float.IsFinite( fullRow.Height ) ) return 1f;\r\n\t\treturn MathF.Max( 1f, fullRow.Height );\r\n\t}\r\n\r\n\tprivate void AddRow( int firstIndex, int count, float top, float height, bool fullWidth )\r\n\t{\r\n\t\tvar rowIndex = _rows.Count;\r\n\t\t_rows.Add( new Row( firstIndex, count, top, height, fullWidth ) );\r\n\t\tfor ( var i = 0; i \u003C count; i\u002B\u002B )\r\n\t\t\t_rowForItem[firstIndex \u002B i] = rowIndex;\r\n\t}\r\n\r\n\tprotected override void GetVisibleRange( out int first, out int pastEnd )\r\n\t{\r\n\t\tif ( _rows.Count == 0 )\r\n\t\t{\r\n\t\t\tfirst = 0;\r\n\t\t\tpastEnd = 0;\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tvar visibleTop = ScrollOffset.y * ScaleFromScreen;\r\n\t\tvar visibleBottom = visibleTop \u002B _viewportHeight;\r\n\t\tvar firstRow = _rows.FindIndex( row =\u003E row.Top \u002B row.Height \u003E visibleTop );\r\n\t\tif ( firstRow \u003C 0 ) firstRow = _rows.Count - 1;\r\n\t\tfirstRow = Math.Max( 0, firstRow - 1 );\r\n\r\n\t\tvar pastRow = _rows.FindIndex( firstRow, row =\u003E row.Top \u003E= visibleBottom );\r\n\t\tif ( pastRow \u003C 0 ) pastRow = _rows.Count;\r\n\t\tpastRow = Math.Min( _rows.Count, pastRow \u002B 1 );\r\n\r\n\t\tfirst = _rows[firstRow].FirstIndex;\r\n\t\tvar last = _rows[pastRow - 1];\r\n\t\tpastEnd = last.FirstIndex \u002B last.Count;\r\n\t}\r\n\r\n\tprotected override void PositionPanel( int index, Panel panel )\r\n\t{\r\n\t\tif ( index \u003C 0 || index \u003E= _rowForItem.Length ) return;\r\n\r\n\t\tvar row = _rows[_rowForItem[index]];\r\n\t\tvar column = index - row.FirstIndex;\r\n\t\tvar rect = row.FullWidth\r\n\t\t\t? new Rect( _innerRect.Left, row.Top, _innerRect.Width, row.Height )\r\n\t\t\t: new Rect( _innerRect.Left \u002B column * (_tileWidth \u002B _spacing.x), row.Top, _tileWidth, _tileHeight );\r\n\r\n\t\tpanel.Style.Left = rect.Left;\r\n\t\tpanel.Style.Top = rect.Top;\r\n\t\tpanel.Style.Width = rect.Width;\r\n\t\tpanel.Style.Height = rect.Height;\r\n\t\tpanel.SetClass( \u0022full-row\u0022, row.FullWidth );\r\n\t\tpanel.Style.Dirty();\r\n\t}\r\n\r\n\tprotected override float GetTotalHeight( int itemCount ) =\u003E _totalHeight;\r\n\r\n\tpublic int GetDropIndex( Vector2 viewportPosition )\r\n\t{\r\n\t\tif ( _rows.Count == 0 ) return 0;\r\n\r\n\t\tvar point = (viewportPosition \u002B ScrollOffset) * ScaleFromScreen;\r\n\t\tif ( point.y \u003C _rows[0].Top ) return 0;\r\n\r\n\t\tvar rowIndex = _rows.FindLastIndex( row =\u003E row.Top \u003C= point.y );\r\n\t\tif ( rowIndex \u003C 0 ) return 0;\r\n\r\n\t\tvar row = _rows[rowIndex];\r\n\t\tif ( point.y \u003E row.Top \u002B row.Height )\r\n\t\t\treturn row.FirstIndex \u002B row.Count;\r\n\r\n\t\tif ( row.FullWidth )\r\n\t\t\treturn row.FirstIndex \u002B (point.y \u003E= row.Top \u002B row.Height * 0.5f ? 1 : 0);\r\n\r\n\t\tvar firstCenter = _innerRect.Left \u002B _tileWidth * 0.5f;\r\n\t\tvar slot = ((point.x - firstCenter) / (_tileWidth \u002B _spacing.x)).FloorToInt() \u002B 1;\r\n\t\treturn row.FirstIndex \u002B slot.Clamp( 0, row.Count );\r\n\t}\r\n\r\n\tprotected override void OnDragEnter( PanelEvent e )\r\n\t{\r\n\t\tbase.OnDragEnter( e );\r\n\t\tif ( OnDropIndex is null || CanAcceptDrop?.Invoke( e ) != true ) return;\r\n\r\n\t\t_dragHover = true;\r\n\t\tSetDropIndex( GetDropIndex( MousePosition ) );\r\n\t\te.StopPropagation();\r\n\t}\r\n\r\n\tprotected override void OnDragLeave( PanelEvent e )\r\n\t{\r\n\t\tbase.OnDragLeave( e );\r\n\t\t_dragHover = false;\r\n\t\tClearDropIndex();\r\n\t}\r\n\r\n\tprotected override void OnDrop( PanelEvent e )\r\n\t{\r\n\t\tbase.OnDrop( e );\r\n\t\tif ( OnDropIndex is null || CanAcceptDrop?.Invoke( e ) != true ) return;\r\n\r\n\t\tvar index = GetDropIndex( MousePosition );\r\n\t\t_dragHover = false;\r\n\t\tClearDropIndex();\r\n\t\tOnDropIndex( index, e );\r\n\t\te.StopPropagation();\r\n\t}\r\n\r\n\tpublic override void Tick()\r\n\t{\r\n\t\tbase.Tick();\r\n\t\tif ( !_dragHover ) return;\r\n\t\tif ( CanAcceptDrop?.Invoke( null ) != true )\r\n\t\t{\r\n\t\t\t_dragHover = false;\r\n\t\t\tClearDropIndex();\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tvar edge = 36f;\r\n\t\tif ( MousePosition.y \u003C edge ) ScrollOffset -= new Vector2( 0, 12 );\r\n\t\tif ( MousePosition.y \u003E Box.Rect.Height - edge ) ScrollOffset \u002B= new Vector2( 0, 12 );\r\n\t\tSetDropIndex( GetDropIndex( MousePosition ) );\r\n\t}\r\n\r\n\tprivate void SetDropIndex( int index )\r\n\t{\r\n\t\tif ( _dropIndex == index ) return;\r\n\t\tClearDropIndex();\r\n\t\t_dropIndex = index;\r\n\r\n\t\tif ( index \u003C _items.Count \u0026\u0026 _created.TryGetValue( index, out var before ) )\r\n\t\t\tbefore.AddClass( \u0022drop-before\u0022 );\r\n\t\telse if ( index \u003E 0 \u0026\u0026 _created.TryGetValue( index - 1, out var after ) )\r\n\t\t\tafter.AddClass( \u0022drop-after\u0022 );\r\n\t}\r\n\r\n\tprivate void ClearDropIndex()\r\n\t{\r\n\t\tif ( _dropIndex \u003C 0 ) return;\r\n\t\tforeach ( var panel in _created.Values )\r\n\t\t{\r\n\t\t\tpanel.RemoveClass( \u0022drop-before\u0022 );\r\n\t\t\tpanel.RemoveClass( \u0022drop-after\u0022 );\r\n\t\t}\r\n\t\t_dropIndex = -1;\r\n\t}\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"UI/ContextMenu/IMenuBarEvent.cs","FileName":"IMenuBarEvent.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"/// \u003Csummary\u003E\r\n/// Lets scene components and systems add menus to the strip of settings along the top of the inspect menu,\r\n/// like Garry\u0027s Mod\u0027s context menu bar. Menus are found by title, so several listeners can add to the same one.\r\n/// The built-ins use the order 100 (Client), 200 (NPCs) and 300 (Server); the default of 0 lands before them.\r\n/// \u003C/summary\u003E\r\npublic interface IMenuBarEvent : ISceneEvent\u003CIMenuBarEvent\u003E\r\n{\r\n\tpublic sealed class Event\r\n\t{\r\n\t\tprivate readonly List\u003C(Sandbox.UI.Menu Menu, int Order)\u003E _menus = new();\r\n\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// Menus collected so far, sorted by order. Stable, so menus sharing an order keep insertion order.\r\n\t\t/// \u003C/summary\u003E\r\n\t\tpublic IEnumerable\u003CSandbox.UI.Menu\u003E Menus =\u003E _menus.OrderBy( x =\u003E x.Order ).Select( x =\u003E x.Menu );\r\n\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// Get the menu with this title, or add one. The order only counts when the menu is added.\r\n\t\t/// \u003C/summary\u003E\r\n\t\tpublic Sandbox.UI.Menu GetOrAddMenu( string title, int order = 0 )\r\n\t\t{\r\n\t\t\tvar existing = _menus.FirstOrDefault( x =\u003E x.Menu.Text == title ).Menu;\r\n\t\t\tif ( existing is not null ) return existing;\r\n\r\n\t\t\tvar menu = new Sandbox.UI.Menu( title, null );\r\n\t\t\t_menus.Add( (menu, order) );\r\n\t\t\treturn menu;\r\n\t\t}\r\n\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// Add a checkable row that reads and writes a setting. Its check mark is refreshed every time the menu opens.\r\n\t\t/// \u003C/summary\u003E\r\n\t\tpublic static Sandbox.UI.Menu AddToggle( Sandbox.UI.Menu menu, string text, Func\u003Cbool\u003E get, Action\u003Cbool\u003E set )\r\n\t\t{\r\n\t\t\tvar option = menu.AddOption( text, value =\u003E\r\n\t\t\t{\r\n\t\t\t\t// only write real changes, a refresh of the check mark isn\u0027t the player asking for one\r\n\t\t\t\tif ( value == get() ) return;\r\n\t\t\t\tset( value );\r\n\t\t\t} );\r\n\r\n\t\t\toption.Checked = get();\r\n\t\t\tmenu.AboutToShow \u002B= _ =\u003E option.Checked = get();\r\n\r\n\t\t\treturn option;\r\n\t\t}\r\n\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// A toggle only admins can change, greyed out for everyone else.\r\n\t\t/// \u003C/summary\u003E\r\n\t\tpublic static Sandbox.UI.Menu AddServerToggle( Sandbox.UI.Menu menu, string text, Func\u003Cbool\u003E get, Action\u003Cbool\u003E set )\r\n\t\t{\r\n\t\t\tvar option = AddToggle( menu, text, get, set );\r\n\r\n\t\t\tUpdateAdminOnly();\r\n\t\t\tmenu.AboutToShow \u002B= _ =\u003E UpdateAdminOnly();\r\n\r\n\t\t\tvoid UpdateAdminOnly()\r\n\t\t\t{\r\n\t\t\t\toption.Enabled = ServerSettings.CanEdit;\r\n\t\t\t\toption.Tooltip = ServerSettings.CanEdit ? null : Game.Language.GetPhrase( \u0022spawnmenu.common.admin_only\u0022 );\r\n\t\t\t}\r\n\r\n\t\t\treturn option;\r\n\t\t}\r\n\r\n\t\t[Obsolete( \u0022Use AddServerToggle, admins can change server settings too\u0022 )]\r\n\t\tpublic static Sandbox.UI.Menu AddHostToggle( Sandbox.UI.Menu menu, string text, Func\u003Cbool\u003E get, Action\u003Cbool\u003E set ) =\u003E AddServerToggle( menu, text, get, set );\r\n\t}\r\n\r\n\tvoid PopulateMenuBar( Event e ) { }\r\n}\r\n"},{"Ident":"facepunch.sandbox","Path":"UI/HudSettings/PhysgunSettingsTab.razor","FileName":"PhysgunSettingsTab.razor","PackageType":"game","CodeKind":"Game","AssetVersionId":446139,"IsPrivate":false,"Code":"@using Sandbox;\r\n@using Sandbox.UI;\r\n@inherits Panel\r\n@namespace Sandbox\r\n@attribute [InspectWindow.Tab]\r\n@attribute [Icon( \u0022\uD83D\uDD2B\u0022 )]\r\n@attribute [Title( \u0022#spawnmenu.tab.physgun\u0022 )]\r\n@attribute [Order( 400 )]\r\n\r\n\u003Croot\u003E\r\n    \u003CUISettingsPane Title=@Game.Language.GetPhrase( \u0022spawnmenu.tab.physgun\u0022 )\u003E\r\n        \u003CBody\u003E\r\n            \u003CUISheet Target=\u0022@Settings\u0022 PropertyFilter=\u0022@UISheet.PropertiesAndButtons\u0022 /\u003E\r\n        \u003C/Body\u003E\r\n    \u003C/UISettingsPane\u003E\r\n\u003C/root\u003E\r\n\r\n@code\r\n{\r\n    readonly PhysgunSettings Settings = new();\r\n\r\n    protected override int BuildHash() =\u003E HashCode.Combine( Game.Language.SelectedCode );\r\n\r\n    // Write through the console system so the Saved convars keep their value\r\n    sealed class PhysgunSettings\r\n    {\r\n        //\r\n        // Drawing\r\n        //\r\n        [Button( \u0022#spawnmenu.hud.reset_group\u0022, \u0022refresh\u0022 ), HeaderButton, Group( \u0022#spawnmenu.physgun.group.drawing\u0022 ), Order( 0 )]\r\n        public void ResetDrawing() =\u003E GamePreferences.Reset( \u0022Physgun Drawing\u0022 );\r\n\r\n        [Property, Title( \u0022#spawnmenu.physgun.draw_beams\u0022 ), Group( \u0022#spawnmenu.physgun.group.drawing\u0022 ), Order( 0 )]\r\n        [Description( \u0022#spawnmenu.physgun.draw_beams_description\u0022 )]\r\n        public bool DrawBeams\r\n        {\r\n            get =\u003E GamePreferences.PhysgunBeams;\r\n            set =\u003E ConsoleSystem.SetValue( \u0022sandbox.physgun_beams\u0022, value );\r\n        }\r\n\r\n        [Property, Title( \u0022#spawnmenu.physgun.draw_outline\u0022 ), Group( \u0022#spawnmenu.physgun.group.drawing\u0022 ), Order( 1 )]\r\n        [Description( \u0022#spawnmenu.physgun.draw_outline_description\u0022 )]\r\n        public bool DrawOutline\r\n        {\r\n            get =\u003E GamePreferences.PhysgunOutline;\r\n            set =\u003E ConsoleSystem.SetValue( \u0022sandbox.physgun_outline\u0022, value );\r\n        }\r\n\r\n        [Property, Title( \u0022#spawnmenu.physgun.draw_freeze\u0022 ), Group( \u0022#spawnmenu.physgun.group.drawing\u0022 ), Order( 2 )]\r\n        [Description( \u0022#spawnmenu.physgun.draw_freeze_description\u0022 )]\r\n        public bool DrawFreezeEffect\r\n        {\r\n            get =\u003E GamePreferences.PhysgunFreezeEffect;\r\n            set =\u003E ConsoleSystem.SetValue( \u0022sandbox.physgun_freeze_effect\u0022, value );\r\n        }\r\n\r\n        [Property, Title( \u0022#spawnmenu.physgun.draw_unfreeze\u0022 ), Group( \u0022#spawnmenu.physgun.group.drawing\u0022 ), Order( 3 )]\r\n        [Description( \u0022#spawnmenu.physgun.draw_unfreeze_description\u0022 )]\r\n        public bool DrawUnfreezeEffect\r\n        {\r\n            get =\u003E GamePreferences.PhysgunUnfreezeEffect;\r\n            set =\u003E ConsoleSystem.SetValue( \u0022sandbox.physgun_unfreeze_effect\u0022, value );\r\n        }\r\n\r\n        //\r\n        // Outline\r\n        //\r\n        [Button( \u0022#spawnmenu.hud.reset_group\u0022, \u0022refresh\u0022 ), HeaderButton, Group( \u0022#spawnmenu.physgun.group.outline\u0022 ), Order( 10 )]\r\n        public void ResetOutline() =\u003E GamePreferences.Reset( \u0022Physgun Outline\u0022 );\r\n\r\n        [Property, Title( \u0022#spawnmenu.physgun.outline_width\u0022 ), Group( \u0022#spawnmenu.physgun.group.outline\u0022 ), Order( 10 )]\r\n        [Description( \u0022#spawnmenu.physgun.outline_width_description\u0022 ), Range( 0.05f, 1f ), Step( 0.05f )]\r\n        public float OutlineWidth\r\n        {\r\n            get =\u003E GamePreferences.OutlineWidth;\r\n            set =\u003E ConsoleSystem.SetValue( \u0022sandbox.physgun_outline_width\u0022, value.Clamp( 0.05f, 1f ) );\r\n        }\r\n\r\n        [Property, Title( \u0022#spawnmenu.physgun.obscured_opacity\u0022 ), Group( \u0022#spawnmenu.physgun.group.outline\u0022 ), Order( 11 )]\r\n        [Description( \u0022#spawnmenu.physgun.obscured_opacity_description\u0022 ), Range( 0f, 1f ), Step( 0.05f )]\r\n        public float ObscuredOpacity\r\n        {\r\n            get =\u003E GamePreferences.OutlineObscuredOpacity;\r\n            set =\u003E ConsoleSystem.SetValue( \u0022sandbox.physgun_outline_obscured\u0022, value.Clamp( 0f, 1f ) );\r\n        }\r\n\r\n        //\r\n        // Colors\r\n        //\r\n        [Button( \u0022#spawnmenu.hud.reset_group\u0022, \u0022refresh\u0022 ), HeaderButton, Group( \u0022#spawnmenu.physgun.group.colors\u0022 ), Order( 20 )]\r\n        public void ResetColors() =\u003E GamePreferences.Reset( \u0022Physgun Colors\u0022 );\r\n\r\n        [Property, Title( \u0022#spawnmenu.physgun.beam_color\u0022 ), Group( \u0022#spawnmenu.physgun.group.colors\u0022 ), Order( 20 )]\r\n        [Description( \u0022#spawnmenu.physgun.beam_color_description\u0022 ), ColorUsage( false, true )]\r\n        public Color BeamColor\r\n        {\r\n            get =\u003E GamePreferences.PhysgunColorValue;\r\n            set =\u003E ConsoleSystem.SetValue( \u0022sandbox.physgun_color\u0022, GamePreferences.ColorText( value.WithAlpha( 1 ) ) );\r\n        }\r\n\r\n        [Property, Title( \u0022#spawnmenu.physgun.pull_color\u0022 ), Group( \u0022#spawnmenu.physgun.group.colors\u0022 ), Order( 21 )]\r\n        [Description( \u0022#spawnmenu.physgun.pull_color_description\u0022 ), ColorUsage( false, true )]\r\n        public Color PullColor\r\n        {\r\n            get =\u003E GamePreferences.PhysgunPullColorValue;\r\n            set =\u003E ConsoleSystem.SetValue( \u0022sandbox.physgun_pull_color\u0022, GamePreferences.ColorText( value.WithAlpha( 1 ) ) );\r\n        }\r\n    }\r\n}\r\n"}]}