-
Notifications
You must be signed in to change notification settings - Fork 181
/
Player.cs
3488 lines (3024 loc) · 161 KB
/
Player.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -----------------------------------------------------------------------
// <copyright file="Player.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------
namespace Exiled.API.Features
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using Core;
using CustomPlayerEffects;
using DamageHandlers;
using Enums;
using Exiled.API.Features.Core.Interfaces;
using Exiled.API.Features.Doors;
using Exiled.API.Features.Hazards;
using Exiled.API.Features.Items;
using Exiled.API.Features.Pickups;
using Exiled.API.Features.Pools;
using Exiled.API.Features.Roles;
using Exiled.API.Interfaces;
using Exiled.API.Structs;
using Extensions;
using Footprinting;
using global::Scp914;
using Hints;
using Interactables.Interobjects;
using InventorySystem;
using InventorySystem.Disarming;
using InventorySystem.Items;
using InventorySystem.Items.Armor;
using InventorySystem.Items.Firearms;
using InventorySystem.Items.Firearms.Attachments;
using InventorySystem.Items.Firearms.BasicMessages;
using InventorySystem.Items.Usables;
using InventorySystem.Items.Usables.Scp330;
using MapGeneration.Distributors;
using MEC;
using Mirror;
using Mirror.LiteNetLib4Mirror;
using NorthwoodLib;
using PlayerRoles;
using PlayerRoles.FirstPersonControl;
using PlayerRoles.RoleAssign;
using PlayerRoles.Spectating;
using PlayerRoles.Voice;
using PlayerStatsSystem;
using PluginAPI.Core;
using RelativePositioning;
using RemoteAdmin;
using Respawning.NamingRules;
using RoundRestarting;
using UnityEngine;
using Utils;
using Utils.Networking;
using VoiceChat;
using VoiceChat.Playbacks;
using static DamageHandlers.DamageHandlerBase;
using DamageHandlerBase = PlayerStatsSystem.DamageHandlerBase;
using Firearm = Items.Firearm;
using FirearmPickup = Pickups.FirearmPickup;
using HumanRole = Roles.HumanRole;
/// <summary>
/// Represents the in-game player, by encapsulating a <see cref="global::ReferenceHub"/>.
/// </summary>
public class Player : TypeCastObject<Player>, IEntity, IWorldSpace
{
#pragma warning disable SA1401
/// <summary>
/// A list of the player's items.
/// </summary>
internal readonly List<Item> ItemsValue = new(8);
#pragma warning restore SA1401
private readonly HashSet<EActor> componentsInChildren = new();
private ReferenceHub referenceHub;
private CustomHealthStat healthStat;
private Role role;
/// <summary>
/// Initializes a new instance of the <see cref="Player"/> class.
/// </summary>
/// <param name="referenceHub">The <see cref="global::ReferenceHub"/> of the player to be encapsulated.</param>
public Player(ReferenceHub referenceHub)
{
ReferenceHub = referenceHub;
Items = ItemsValue.AsReadOnly();
}
/// <summary>
/// Initializes a new instance of the <see cref="Player"/> class.
/// </summary>
/// <param name="gameObject">The <see cref="UnityEngine.GameObject"/> of the player.</param>
public Player(GameObject gameObject)
{
ReferenceHub = ReferenceHub.GetHub(gameObject);
Items = ItemsValue.AsReadOnly();
}
/// <summary>
/// Finalizes an instance of the <see cref="Player"/> class.
/// </summary>
~Player()
{
DictionaryPool<string, object>.Pool.Return(SessionVariables);
DictionaryPool<RoleTypeId, float>.Pool.Return(FriendlyFireMultiplier);
DictionaryPool<string, Dictionary<RoleTypeId, float>>.Pool.Return(CustomRoleFriendlyFireMultiplier);
}
/// <summary>
/// Gets a <see cref="Dictionary{TKey, TValue}"/> containing all <see cref="Player"/>'s on the server.
/// </summary>
public static Dictionary<GameObject, Player> Dictionary { get; } = new(Server.MaxPlayerCount, new ReferenceHub.GameObjectComparer());
/// <summary>
/// Gets a list of all <see cref="Player"/>'s on the server.
/// </summary>
public static IReadOnlyCollection<Player> List => Dictionary.Values;
/// <summary>
/// Gets a <see cref="Dictionary{TKey, TValue}"/> containing cached <see cref="Player"/> and their user ids.
/// </summary>
public static Dictionary<string, Player> UserIdsCache { get; } = new(20);
/// <inheritdoc/>
public IReadOnlyCollection<EActor> ComponentsInChildren => componentsInChildren;
/// <summary>
/// Gets or sets a <see cref="Dictionary{TKey, TValue}"/> containing cached <see cref="RoleTypeId"/> and their FF multiplier. This is for non-unique roles.
/// </summary>
public Dictionary<RoleTypeId, float> FriendlyFireMultiplier { get; set; } = DictionaryPool<RoleTypeId, float>.Pool.Get();
/// <summary>
/// Gets or sets a <see cref="Dictionary{TKey, TValue}"/> containing cached <see cref="string"/> and their <see cref="Dictionary{TKey, TValue}"/> which is cached Role with FF multiplier. This is for unique custom roles.
/// </summary>
/// <remarks> Consider adding this as object, Dict so that CustomRoles, and Strings can be parsed. </remarks>
public Dictionary<string, Dictionary<RoleTypeId, float>> CustomRoleFriendlyFireMultiplier { get; set; } = DictionaryPool<string, Dictionary<RoleTypeId, float>>.Pool.Get();
/// <summary>
/// Gets or sets a unique custom role that does not adbide to base game for this player. Used in conjunction with <see cref="CustomRoleFriendlyFireMultiplier"/>.
/// </summary>
public string UniqueRole { get; set; } = string.Empty;
/// <summary>
/// Gets the encapsulated <see cref="global::ReferenceHub"/>.
/// </summary>
public ReferenceHub ReferenceHub
{
get => referenceHub;
private set
{
referenceHub = value ?? throw new NullReferenceException("Player's ReferenceHub cannot be null!");
GameObject = value.gameObject;
HintDisplay = value.hints;
Inventory = value.inventory;
CameraTransform = value.PlayerCameraReference;
value.playerStats._dictionarizedTypes[typeof(HealthStat)] = value.playerStats.StatModules[Array.IndexOf(PlayerStats.DefinedModules, typeof(HealthStat))] = healthStat = new CustomHealthStat { Hub = value };
}
}
/// <summary>
/// Gets the <see cref="PlayerRoleManager"/>.
/// </summary>
public PlayerRoleManager RoleManager => ReferenceHub.roleManager;
/// <summary>
/// Gets the player's ammo.
/// </summary>
public Dictionary<ItemType, ushort> Ammo => Inventory.UserInventory.ReserveAmmo;
/// <summary>
/// Gets the encapsulated <see cref="UnityEngine.GameObject"/>.
/// </summary>
public GameObject GameObject { get; private set; }
/// <summary>
/// Gets the <see cref="ReferenceHub"/>'s <see cref="UnityEngine.Transform"/>.
/// </summary>
public Transform Transform => ReferenceHub.transform;
/// <summary>
/// Gets the hint currently watched by the player.
/// </summary>
/// May be <see langword="null"/>.
public Hint CurrentHint { get; internal set; }
/// <summary>
/// Gets a value indicating whether or not the player is viewing a hint.
/// </summary>
public bool HasHint => CurrentHint != null;
/// <summary>
/// Gets the <see cref="ReferenceHub"/>'s <see cref="VoiceModule"/>, can be null.
/// </summary>
public VoiceModuleBase VoiceModule => RoleManager.CurrentRole is IVoiceRole voiceRole ? voiceRole.VoiceModule : null;
/// <summary>
/// Gets the <see cref="ReferenceHub"/>'s <see cref="PersonalRadioPlayback"/>, can be null.
/// </summary>
public PersonalRadioPlayback RadioPlayback => VoiceModule is IRadioVoiceModule radioVoiceModule ? radioVoiceModule.RadioPlayback : null;
/// <summary>
/// Gets the <see cref="Hints.HintDisplay"/> of the player.
/// </summary>
public HintDisplay HintDisplay { get; private set; }
/// <summary>
/// Gets the player's <see cref="InventorySystem.Inventory"/>.
/// </summary>
public Inventory Inventory { get; private set; }
/// <summary>
/// Gets the encapsulated <see cref="ReferenceHub"/>'s <see cref="Transform">PlayerCameraReference</see>.
/// </summary>
public Transform CameraTransform { get; private set; }
/// <summary>
/// Gets or sets the player's <see cref="VcMuteFlags"/>.
/// </summary>
public VcMuteFlags VoiceChatMuteFlags
{
get => VoiceChatMutes.GetFlags(ReferenceHub);
set => VoiceChatMutes.SetFlags(ReferenceHub, value);
}
/// <summary>
/// Gets or sets the player's id.
/// </summary>
public int Id
{
get => ReferenceHub.PlayerId;
set => ReferenceHub._playerId = new(value);
}
/// <summary>
/// Gets the player's user id.
/// </summary>
public string UserId => referenceHub.authManager.UserId;
/// <summary>
/// Gets or sets the player's custom user id.
/// </summary>
[Obsolete("Remove by NW", true)]
public string CustomUserId { get; set; }
/// <summary>
/// Gets the player's user id without the authentication.
/// </summary>
public string RawUserId { get; internal set; }
/// <summary>
/// Gets the player's authentication token.
/// </summary>
public string AuthenticationToken => ReferenceHub.authManager.GetAuthToken();
/// <summary>
/// Gets the player's authentication type.
/// </summary>
public AuthenticationType AuthenticationType
{
get
{
if (string.IsNullOrEmpty(UserId))
return AuthenticationType.Unknown;
return UserId.Substring(UserId.LastIndexOf('@') + 1) switch
{
"steam" => AuthenticationType.Steam,
"discord" => AuthenticationType.Discord,
"northwood" => AuthenticationType.Northwood,
"localhost" => AuthenticationType.LocalHost,
"ID_Dedicated" => AuthenticationType.DedicatedServer,
_ => AuthenticationType.Unknown,
};
}
}
/// <summary>
/// Gets a value indicating whether or not the player is verified.
/// </summary>
/// <remarks>
/// This is always <see langword="false"/> if <c>online_mode</c> is set to <see langword="false"/>.
/// </remarks>
public bool IsVerified { get; internal set; }
/// <summary>
/// Gets or sets a value indicating whether or not the player is a NPC.
/// </summary>
public bool IsNPC { get; set; }
/// <summary>
/// Gets a value indicating whether or not the player has an active CustomName.
/// </summary>
public bool HasCustomName => ReferenceHub.nicknameSync.HasCustomName;
/// <summary>
/// Gets or sets the player's nickname displayed to other player.
/// </summary>
public string DisplayNickname
{
get => ReferenceHub.nicknameSync.DisplayName;
set => ReferenceHub.nicknameSync.DisplayName = value;
}
/// <summary>
/// Gets or sets the player's nickname, if null it sets the original nickname.
/// </summary>
public string CustomName
{
get => ReferenceHub.nicknameSync.Network_displayName ?? Nickname;
set => ReferenceHub.nicknameSync.Network_displayName = value;
}
/// <summary>
/// Gets the player's nickname.
/// </summary>
public string Nickname => ReferenceHub.nicknameSync.Network_myNickSync;
/// <summary>
/// Gets or sets the player's player info area bitmask.
/// This property can be used to hide player name elements, such as the player's name, badges, etc.
/// </summary>
public PlayerInfoArea InfoArea
{
get => ReferenceHub.nicknameSync.Network_playerInfoToShow;
set => ReferenceHub.nicknameSync.Network_playerInfoToShow = value;
}
/// <summary>
/// Gets or sets the player's custom player info string. This string is displayed along with the player's <see cref="InfoArea"/>.
/// </summary>
public string CustomInfo
{
get => ReferenceHub.nicknameSync.Network_customPlayerInfoString;
set
{
// NW Client check.
if (value.Contains('<'))
{
foreach (string token in value.Split('<'))
{
if (token.StartsWith("/", StringComparison.Ordinal) ||
token.StartsWith("b>", StringComparison.Ordinal) ||
token.StartsWith("i>", StringComparison.Ordinal) ||
token.StartsWith("size=", StringComparison.Ordinal) ||
token.Length is 0)
continue;
if (token.StartsWith("color=", StringComparison.Ordinal))
{
if (token.Length < 14 || token[13] != '>')
Log.Error($"Custom info of player {Nickname} has been REJECTED. \nreason: (Bad text reject) \ntoken: {token} \nInfo: {value}");
else if (!Misc.AllowedColors.ContainsValue(token.Substring(6, 7)))
Log.Error($"Custom info of player {Nickname} has been REJECTED. \nreason: (Bad color reject) \ntoken: {token} \nInfo: {value}");
}
else if (token.StartsWith("#", StringComparison.Ordinal))
{
if (token.Length < 8 || token[7] != '>')
Log.Error($"Custom info of player {Nickname} has been REJECTED. \nreason: (Bad text reject) \ntoken: {token} \nInfo: {value}");
else if (!Misc.AllowedColors.ContainsValue(token.Substring(0, 7)))
Log.Error($"Custom info of player {Nickname} has been REJECTED. \nreason: (Bad color reject) \ntoken: {token} \nInfo: {value}");
}
else
{
Log.Error($"Custom info of player {Nickname} has been REJECTED. \nreason: (Bad color reject) \ntoken: {token} \nInfo: {value}");
}
}
}
InfoArea = string.IsNullOrEmpty(value) ? InfoArea & ~PlayerInfoArea.CustomInfo : InfoArea |= PlayerInfoArea.CustomInfo;
ReferenceHub.nicknameSync.Network_customPlayerInfoString = value;
}
}
/// <summary>
/// Gets or sets the range at which this player's info can be viewed by others.
/// </summary>
public float InfoViewRange
{
get => ReferenceHub.nicknameSync.NetworkViewRange;
set => ReferenceHub.nicknameSync.NetworkViewRange = value;
}
/// <summary>
/// Gets the dictionary of the player's session variables.
/// <para>
/// Session variables can be used to save temporary data on players. Data is stored in a <see cref="Dictionary{TKey, TValue}"/>.
/// The key of the data is always a <see cref="string"/>, whereas the value can be any <see cref="object"/>.
/// The data stored in a player's session variables can be accessed by different assemblies; it is recommended to uniquely identify stored data so that it does not conflict with other plugins that may also be using the same name.
/// Data saved with session variables is not being saved on player disconnect. If the data must be saved after the player's disconnects, a database must be used instead.
/// </para>
/// </summary>
public Dictionary<string, object> SessionVariables { get; } = DictionaryPool<string, object>.Pool.Get();
/// <summary>
/// Gets a value indicating whether or not the player has Do Not Track (DNT) enabled. If this value is <see langword="true"/>, data about the player unrelated to server security shouldn't be stored.
/// </summary>
public bool DoNotTrack => ReferenceHub.authManager.DoNotTrack;
/// <summary>
/// Gets a value indicating whether the player is fully connected to the server.
/// </summary>
public bool IsConnected => GameObject != null;
/// <summary>
/// Gets a value indicating whether or not the player has a reserved slot.
/// </summary>
/// <seealso cref="GiveReservedSlot(bool)"/>
/// <seealso cref="AddReservedSlot(string, bool)"/>
public bool HasReservedSlot => ReservedSlot.HasReservedSlot(UserId, out _);
/// <summary>
/// Gets a value indicating whether or not the player is in whitelist.
/// </summary>
/// <remarks>It will always return <see langword="true"/> if a whitelist is disabled on the server.</remarks>
/// <seealso cref="GrantWhitelist(bool)"/>
/// <seealso cref="AddToWhitelist(string, bool)"/>
public bool IsWhitelisted => WhiteList.IsWhitelisted(UserId);
/// <summary>
/// Gets a value indicating whether or not the player has Remote Admin access.
/// </summary>
public bool RemoteAdminAccess => ReferenceHub.serverRoles.RemoteAdmin;
/// <summary>
/// Gets a value indicating whether or not the player has Admin Chat access.
/// </summary>
public bool AdminChatAccess => ReferenceHub.serverRoles.AdminChatPerms;
/// <summary>
/// Gets a value indicating a player's kick power.
/// </summary>
public byte KickPower => ReferenceHub.serverRoles.KickPower;
/// <summary>
/// Gets or sets a value indicating whether or not the player's overwatch is enabled.
/// </summary>
public bool IsOverwatchEnabled
{
get => ReferenceHub.serverRoles.IsInOverwatch;
set => ReferenceHub.serverRoles.IsInOverwatch = value;
}
/// <summary>
/// Gets or sets a value indicating whether or not the player is allowed to enter noclip mode.
/// </summary>
/// <remarks>For forcing the player into noclip mode, see <see cref="FpcRole.IsNoclipEnabled"/>.</remarks>
/// <seealso cref="FpcRole.IsNoclipEnabled"/>
public bool IsNoclipPermitted
{
get => FpcNoclip.IsPermitted(ReferenceHub);
set
{
if (value)
FpcNoclip.PermitPlayer(ReferenceHub);
else
FpcNoclip.UnpermitPlayer(ReferenceHub);
}
}
/// <summary>
/// Gets or sets a value indicating the <see cref="Player"/> that currently has the player cuffed.
/// <para>
/// This value will be <see langword="null"/> if the player is not cuffed. Setting this value to <see langword="null"/> will uncuff the player if they are cuffed.
/// </para>
/// </summary>
public Player Cuffer
{
get => Get(DisarmedPlayers.Entries.FirstOrDefault(entry => entry.DisarmedPlayer == NetworkIdentity.netId).Disarmer);
set
{
for (int i = 0; i < DisarmedPlayers.Entries.Count; i++)
{
if (DisarmedPlayers.Entries[i].DisarmedPlayer == Inventory.netId)
{
DisarmedPlayers.Entries.RemoveAt(i);
break;
}
}
if (value is not null)
{
Inventory.SetDisarmedStatus(value.Inventory);
new DisarmedPlayersListMessage(DisarmedPlayers.Entries).SendToAuthenticated();
}
}
}
/// <summary>
/// Gets or sets the player's position.
/// </summary>
/// <seealso cref="Teleport(Vector3)"/>
/// <seealso cref="Teleport(object)"/>
public Vector3 Position
{
get => Transform.position;
set => ReferenceHub.TryOverridePosition(value, Vector3.zero);
}
/// <summary>
/// Gets or sets the relative player's position.
/// </summary>
/// <remarks>The value will be default if the player's role is not an <see cref="FpcRole"/>.</remarks>
public RelativePosition RelativePosition
{
get => Role is FpcRole fpcRole ? fpcRole.RelativePosition : default;
set => Position = value.Position;
}
/// <summary>
/// Gets or sets the player's rotation.
/// </summary>
/// <returns>Returns the direction the player is looking at.</returns>
public Quaternion Rotation
{
get => Transform.rotation;
set => ReferenceHub.TryOverridePosition(Position, value.eulerAngles);
}
/// <summary>
/// Gets the <see cref="Player"/>'s current movement speed.
/// </summary>
public Vector3 Velocity => ReferenceHub.GetVelocity();
/// <summary>
/// Gets the player's <see cref="Enums.LeadingTeam"/>.
/// </summary>
public LeadingTeam LeadingTeam => Role.Team.GetLeadingTeam();
/// <summary>
/// Gets or sets a value indicating the actual RA permissions.
/// </summary>
public PlayerPermissions RemoteAdminPermissions
{
get => (PlayerPermissions)ReferenceHub.serverRoles.Permissions;
set => ReferenceHub.serverRoles.Permissions = (ulong)value;
}
/// <summary>
/// Gets a <see cref="Roles.Role"/> that is unique to this player and this class. This allows modification of various aspects related to the role solely.
/// <para>
/// The type of the Role is different based on the <see cref="RoleTypeId"/> of the player, and casting should be used to modify the role.
/// <br /><see cref="RoleTypeId.Spectator"/> = <see cref="Roles.SpectatorRole"/>.
/// <br /><see cref="RoleTypeId.Overwatch"/> = <see cref="Roles.OverwatchRole"/>.
/// <br /><see cref="RoleTypeId.None"/> = <see cref="Roles.NoneRole"/>.
/// <br /><see cref="RoleTypeId.Scp049"/> = <see cref="Scp049Role"/>.
/// <br /><see cref="RoleTypeId.Scp0492"/> = <see cref="Scp0492Role"/>.
/// <br /><see cref="RoleTypeId.Scp079"/> = <see cref="Scp079Role"/>.
/// <br /><see cref="RoleTypeId.Scp096"/> = <see cref="Scp096Role"/>.
/// <br /><see cref="RoleTypeId.Scp106"/> = <see cref="Scp106Role"/>.
/// <br /><see cref="RoleTypeId.Scp173"/> = <see cref="Scp173Role"/>.
/// <br /><see cref="RoleTypeId.Scp3114"/> = <see cref="Scp3114Role"/>.
/// <br /><see cref="RoleTypeId.Scp939"/> = <see cref="Scp939Role"/>.
/// <br />If not listed above, the type of Role will be <see cref="HumanRole"/>.
/// </para>
/// <para>
/// If the role object is stored, it may become invalid if the player changes roles. Thus, the <see cref="Role.IsValid"/> property can be checked. If this property is <see langword="false"/>, the role should be discarded and this property should be used again to get the new Role.
/// This role is automatically cached until it changes, and it is recommended to use this property directly rather than storing the property yourself.
/// </para>
/// <para>
/// Roles and RoleTypeIds can be compared directly. <c>Player.Role == RoleTypeId.Scp079</c> is valid and will return <see langword="true"/> if the player is SCP-079. To set the player's role, see <see cref="Role.Set(RoleTypeId, SpawnReason, RoleSpawnFlags)"/>.
/// </para>
/// </summary>
/// <seealso cref="Role.Set(RoleTypeId, SpawnReason, RoleSpawnFlags)"/>
public Role Role
{
get => role ??= Role.Create(RoleManager.CurrentRole);
internal set => role = value;
}
/// <summary>
/// Gets or sets the player's SCP preferences.
/// </summary>
public ScpSpawnPreferences.SpawnPreferences ScpPreferences
{
get
{
if (ScpSpawnPreferences.Preferences.TryGetValue(Connection.connectionId, out ScpSpawnPreferences.SpawnPreferences value))
return value;
return default;
}
set => ScpSpawnPreferences.Preferences[Connection.connectionId] = value;
}
/// <summary>
/// Gets a value indicating whether or not the player is cuffed.
/// </summary>
/// <remarks>Players can be cuffed without another player being the cuffer.</remarks>
public bool IsCuffed => Inventory.IsDisarmed();
/// <summary>
/// Gets a value indicating whether or not the player is reloading a weapon.
/// </summary>
public bool IsReloading => CurrentItem is Firearm firearm && !firearm.Base.AmmoManagerModule.Standby;
/// <summary>
/// Gets a value indicating whether or not the player is aiming with a weapon.
/// </summary>
public bool IsAimingDownWeapon => CurrentItem is Firearm firearm && firearm.Aiming;
/// <summary>
/// Gets a value indicating whether or not the player has enabled weapon's flashlight module.
/// </summary>
public bool HasFlashlightModuleEnabled => CurrentItem is Firearm firearm && firearm.FlashlightEnabled;
/// <summary>
/// Gets a value indicating whether or not the player is jumping.
/// </summary>
public bool IsJumping => Role is FpcRole fpc && fpc.FirstPersonController.FpcModule.Motor.IsJumping;
/// <summary>
/// Gets the player's IP address.
/// </summary>
public string IPAddress => ReferenceHub.networkIdentity.connectionToClient.address;
/// <summary>
/// Gets the player's command sender instance.
/// </summary>
public PlayerCommandSender Sender => ReferenceHub.queryProcessor._sender;
/// <summary>
/// Gets player's <see cref="NetworkConnection"/>.
/// </summary>
public NetworkConnection Connection => ReferenceHub.connectionToClient;
/// <summary>
/// Gets the player's <see cref="Mirror.NetworkIdentity"/>.
/// </summary>
public NetworkIdentity NetworkIdentity => ReferenceHub.networkIdentity;
/// <summary>
/// Gets the player's net ID.
/// </summary>
public uint NetId => ReferenceHub.netId;
/// <summary>
/// Gets a value indicating whether or not the player is the host.
/// </summary>
public bool IsHost => ReferenceHub.isLocalPlayer;
/// <summary>
/// Gets a value indicating whether or not the player is alive.
/// </summary>
public bool IsAlive => !IsDead;
/// <summary>
/// Gets a value indicating whether or not the player is dead.
/// </summary>
public bool IsDead => Role?.IsDead ?? false;
/// <summary>
/// Gets a value indicating whether or not the player's <see cref="RoleTypeId"/> is any NTF rank.
/// Equivalent to checking the player's <see cref="Team"/>.
/// </summary>
public bool IsNTF => Role?.Team is Team.FoundationForces;
/// <summary>
/// Gets a value indicating whether or not the player's <see cref="RoleTypeId"/> is any Chaos rank.
/// Equivalent to checking the player's <see cref="Team"/>.
/// </summary>
public bool IsCHI => Role?.Team is Team.ChaosInsurgency;
/// <summary>
/// Gets a value indicating whether or not the player's <see cref="RoleTypeId"/> is any SCP.
/// Equivalent to checking the player's <see cref="Team"/>.
/// </summary>
public bool IsScp => Role?.Team is Team.SCPs;
/// <summary>
/// Gets a value indicating whether or not the player's <see cref="RoleTypeId"/> is any human rank.
/// </summary>
public bool IsHuman => Role is not null && Role.Is(out HumanRole _);
/// <summary>
/// Gets a value indicating whether or not the player's <see cref="RoleTypeId"/> is equal to <see cref="RoleTypeId.Tutorial"/>.
/// </summary>
public bool IsTutorial => Role?.Type is RoleTypeId.Tutorial;
/// <summary>
/// Gets a value indicating whether or not the player's friendly fire is enabled.
/// <br>This property only determines if this player can deal damage to players on the same team;</br>
/// <br>This player can be damaged by other players on their own team even if this property is <see langword="false"/>.</br>
/// </summary>
public bool IsFriendlyFireEnabled => FriendlyFireMultiplier.Count > 0 || CustomRoleFriendlyFireMultiplier.Count > 0;
/// <summary>
/// Gets or sets the player's scale.
/// </summary>
public Vector3 Scale
{
get => ReferenceHub.transform.localScale;
set
{
if (value == Scale)
return;
try
{
ReferenceHub.transform.localScale = value;
foreach (Player target in List)
Server.SendSpawnMessage?.Invoke(null, new object[] { NetworkIdentity, target.Connection });
}
catch (Exception exception)
{
Log.Error($"{nameof(Scale)} error: {exception}");
}
}
}
/// <summary>
/// Gets or sets a value indicating whether or not the player's bypass mode is enabled.
/// </summary>
public bool IsBypassModeEnabled
{
get => ReferenceHub.serverRoles.BypassMode;
set => ReferenceHub.serverRoles.BypassMode = value;
}
/// <summary>
/// Gets or sets a value indicating whether or not the player is muted.
/// </summary>
/// <remarks>This property will NOT persistently mute and unmute the player. For persistent mutes, see <see cref="Mute(bool)"/> and <see cref="UnMute(bool)"/>.</remarks>
public bool IsMuted
{
get => VoiceChatMutes.QueryLocalMute(UserId, false);
set
{
if (value)
VoiceChatMuteFlags |= VcMuteFlags.LocalRegular;
else
VoiceChatMuteFlags &= ~VcMuteFlags.LocalRegular;
}
}
/// <summary>
/// Gets or sets a value indicating whether or not the player is global muted.
/// </summary>
/// <remarks>This property will NOT persistently mute and unmute the player. For persistent mutes, see <see cref="Mute(bool)"/> and <see cref="UnMute(bool)"/>.</remarks>
public bool IsGlobalMuted
{
get => VoiceChatMutes.Mutes.Contains(UserId) && VoiceChatMuteFlags.HasFlag(VcMuteFlags.GlobalRegular);
set
{
if (value)
VoiceChatMuteFlags |= VcMuteFlags.GlobalRegular;
else
VoiceChatMuteFlags &= ~VcMuteFlags.GlobalRegular;
}
}
/// <summary>
/// Gets or sets a value indicating whether or not the player is intercom muted.
/// </summary>
/// <remarks>This property will NOT persistently mute and unmute the player. For persistent mutes, see <see cref="Mute(bool)"/> and <see cref="UnMute(bool)"/>.</remarks>
public bool IsIntercomMuted
{
get => VoiceChatMutes.QueryLocalMute(UserId, true);
set
{
if (value)
VoiceChatMuteFlags |= VcMuteFlags.LocalIntercom;
else
VoiceChatMuteFlags &= ~VcMuteFlags.LocalIntercom;
}
}
/// <summary>
/// Gets a value indicating whether or not the player is speaking.
/// </summary>
public bool IsSpeaking => VoiceModule != null && VoiceModule.IsSpeaking;
/// <summary>
/// Gets the player's voice color.
/// </summary>
public Color VoiceColor => ReferenceHub.serverRoles.GetVoiceColor();
/// <summary>
/// Gets or sets the player's voice channel.
/// </summary>
public VoiceChatChannel VoiceChannel
{
get => VoiceModule == null ? VoiceChatChannel.None : VoiceModule.CurrentChannel;
set
{
if (VoiceModule == null)
return;
VoiceModule.CurrentChannel = value;
}
}
/// <summary>
/// Gets a value indicating whether or not the player is transmitting on a Radio.
/// </summary>
public bool IsTransmitting => PersonalRadioPlayback.IsTransmitting(ReferenceHub);
/// <summary>
/// Gets or sets a value indicating whether or not the player has godmode enabled.
/// </summary>
public bool IsGodModeEnabled
{
get => ReferenceHub.characterClassManager.GodMode;
set => ReferenceHub.characterClassManager.GodMode = value;
}
/// <summary>
/// Gets the player's unit name.
/// </summary>
public string UnitName => Role.Base is PlayerRoles.HumanRole humanRole ? UnitNameMessageHandler.GetReceived(humanRole.AssignedSpawnableTeam, humanRole.UnitNameId) : string.Empty;
/// <summary>
/// Gets or sets the player's unit id.
/// </summary>
public byte UnitId
{
get => Role.Base is PlayerRoles.HumanRole humanRole ? humanRole.UnitNameId : byte.MinValue;
set => _ = Role.Base is PlayerRoles.HumanRole humanRole ? humanRole.UnitNameId = value : _ = value;
}
/// <summary>
/// Gets or sets the player's health.
/// If the health is greater than the <see cref="MaxHealth"/>, the MaxHealth will also be changed to match the health.
/// </summary>
public float Health
{
get => healthStat.CurValue;
set
{
if (value > MaxHealth)
MaxHealth = value;
healthStat.CurValue = value;
}
}
/// <summary>
/// Gets or sets the player's maximum health.
/// </summary>
public float MaxHealth
{
get => healthStat.MaxValue;
set => healthStat.CustomMaxValue = value;
}
/// <summary>
/// Gets or sets the player's artificial health.
/// If the health is greater than the <see cref="MaxArtificialHealth"/>, it will also be changed to match the artificial health.
/// </summary>
public float ArtificialHealth
{
get => ActiveArtificialHealthProcesses.FirstOrDefault()?.CurrentAmount ?? 0f;
set
{
if (value > MaxArtificialHealth)
MaxArtificialHealth = value;
AhpStat.AhpProcess ahp = ActiveArtificialHealthProcesses.FirstOrDefault();
if (ahp is not null)
ahp.CurrentAmount = value;
}
}
/// <summary>
/// Gets or sets the player's maximum artificial health.
/// </summary>
public float MaxArtificialHealth
{
get => ActiveArtificialHealthProcesses.FirstOrDefault()?.Limit ?? 0f;
set
{
if (!ActiveArtificialHealthProcesses.Any())
AddAhp(value);
AhpStat.AhpProcess ahp = ActiveArtificialHealthProcesses.FirstOrDefault();
if (ahp is not null)
ahp.Limit = value;
}
}
/// <summary>
/// Gets or sets the player's Hume Shield.
/// </summary>
/// <remarks>This value can bypass the role's hume shield maximum. However, this value will only be visible to the end-player as Hume Shield if <see cref="FpcRole.IsHumeShieldedRole"/> is <see langword="true"/>. Otherwise, the game will treat the player as though they have the amount of Hume Shield specified, even though they cannot see it.</remarks>
public float HumeShield
{
get => HumeShieldStat.CurValue;
set => HumeShieldStat.CurValue = value;
}
/// <summary>
/// Gets a <see cref="IEnumerable{T}"/> of all active Artificial Health processes on the player.
/// </summary>
public IEnumerable<AhpStat.AhpProcess> ActiveArtificialHealthProcesses => ReferenceHub.playerStats.GetModule<AhpStat>()._activeProcesses;
/// <summary>
/// Gets the player's <see cref="PlayerStatsSystem.HumeShieldStat"/>.
/// </summary>
public HumeShieldStat HumeShieldStat => ReferenceHub.playerStats.GetModule<HumeShieldStat>();
/// <summary>
/// Gets or sets the item in the player's hand. Value will be <see langword="null"/> if the player is not holding anything.
/// </summary>
/// <seealso cref="DropHeldItem()"/>
public Item CurrentItem
{
get => Item.Get(Inventory.CurInstance);
set
{
if (value is null || value.Type == ItemType.None)
{
Inventory.ServerSelectItem(0);
return;
}
if (!Inventory.UserInventory.Items.TryGetValue(value.Serial, out _))
AddItem(value.Base);
Inventory.ServerSelectItem(value.Serial);
}
}
/// <summary>
/// Gets the armor that the player is currently wearing. Value will be <see langword="null"/> if the player is not wearing any armor.
/// </summary>
public Armor CurrentArmor => Inventory.TryGetBodyArmor(out BodyArmor armor) ? (Armor)Item.Get(armor) : null;
/// <summary>
/// Gets the <see cref="StaminaStat"/> class.
/// </summary>
public StaminaStat StaminaStat => ReferenceHub.playerStats.GetModule<StaminaStat>();
/// <summary>
/// Gets or sets the amount of stamina the player has.
/// </summary>
/// <remarks>This will always be a value between <c>0-1</c>, <c>0</c> representing no stamina and <c>1</c> representing maximum stamina.</remarks>
public float Stamina
{
get => StaminaStat.CurValue;
set => StaminaStat.CurValue = value;
}
/// <summary>
/// Gets a value indicating whether or not the staff bypass is enabled.
/// </summary>
public bool IsStaffBypassEnabled => ReferenceHub.authManager.BypassBansFlagSet;
/// <summary>
/// Gets or sets the player's group name.
/// </summary>
public string GroupName
{
get => ServerStatic.PermissionsHandler._members.TryGetValue(UserId, out string groupName) ? groupName : null;
set => ServerStatic.PermissionsHandler._members[UserId] = value;
}
/// <summary>
/// Gets the current <see cref="Room"/> the player is in.
/// </summary>
public Room CurrentRoom => Room.FindParentRoom(GameObject);
/// <summary>
/// Gets the current zone the player is in.
/// </summary>
public ZoneType Zone => CurrentRoom?.Zone ?? ZoneType.Unspecified;
/// <summary>
/// Gets the current <see cref="Features.Lift"/> the player is in. Can be <see langword="null"/>.
/// </summary>
public Lift Lift => Lift.Get(Position);
/// <summary>
/// Gets all currently active <see cref="StatusEffectBase"> effects</see>.
/// </summary>
/// <seealso cref="EnableEffect(EffectType, float, bool)"/>
/// <seealso cref="EnableEffect(StatusEffectBase, float, bool)"/>
/// <seealso cref="EnableEffect(string, float, bool)"/>
/// <seealso cref="EnableEffect{T}(float, bool)"/>
/// <seealso cref="EnableEffects(IEnumerable{EffectType}, float, bool)"/>
public IEnumerable<StatusEffectBase> ActiveEffects => referenceHub.playerEffectsController.AllEffects.Where(effect => effect.Intensity > 0);
/// <summary>
/// Gets or sets the player's group.
/// </summary>
public UserGroup Group