-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntityOwner.cs
1577 lines (1330 loc) · 59.2 KB
/
EntityOwner.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Facepunch;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Core.Libraries.Covalence;
using UnityEngine;
namespace Oxide.Plugins
{
[Info ("Entity Owner", "Calytic", "3.2.3")]
[Description ("Modify entity ownership and cupboard/turret authorization")]
class EntityOwner : RustPlugin
{
#region Data & Config
readonly int layerMasks = LayerMask.GetMask ("Construction", "Construction Trigger", "Trigger", "Deployed");
int EntityLimit = 8000;
float DistanceThreshold = 3f;
float CupboardDistanceThreshold = 20f;
bool debug;
#endregion
#region Data Handling & Initialization
Dictionary<string, string> texts = new Dictionary<string, string> {
{"Denied: Permission", "You are not allowed to use this command"},
{"Target: None", "No target found"},
{"Target: Owner", "Owner: {0}"},
{"Target: Limit", "Exceeded entity limit."},
{"Syntax: Owner", "Invalid syntax: /owner"},
{"Syntax: Own", "Invalid Syntax. \n/own type player\nTypes: all/block/storage/cupboard/sign/sleepingbag/plant/oven/door/turret\n/own player"},
{"Syntax: Unown", "Invalid Syntax. \n/unown type player\nTypes: all/block/storage/cupboard/sign/sleepingbag/plant/oven/door/turret\n/unown player"},
{"Syntax: Prod2", "Invalid Syntax. \n/prod2 type \nTypes:\n all/block/entity/storage/cupboard/sign/sleepingbag/plant/oven/door/turret"},
{"Syntax: Auth", "Invalid Syntax. \n/auth turret player\n/auth cupboard player/auth player\n/auth"},
{"Syntax: Deauth", "Invalid Syntax. \n/deauth turret player\n/deauth cupboard player/deauth player\n/deauth"},
{"Ownership: Changing", "Changing ownership.."},
{"Ownership: Removing", "Removing ownership.."},
{"Ownership: New", "New owner of all around is: {0}"},
{"Ownership: New Self", "Owner: You were given ownership of this house and nearby deployables"},
{"Ownership: Count", "Count ({0})"},
{"Ownership: Removed", "Ownership removed"},
{"Ownership: Changed", "Ownership changed"},
{"Entities: None", "No entities found."},
{"Entities: Authorized", "({0}) Authorized"},
{"Entities: Count", "Counted {0} entities ({1}/{2})"},
{"Structure: Prodding","Prodding structure.."},
{"Structure: Condition Percent", "Condition: {0}%"},
{"Player: Unknown Percent", "Unknown: {0}%"},
{"Player: None", "Target player not found"},
{"Cupboards: Prodding", "Prodding cupboards.."},
{"Cupboards: Authorizing", "Authorizing cupboards.."},
{"Cupboards: Authorized", "Authorized {0} on {1} cupboards"},
{"Cupboards: Deauthorizing", "Deauthorizing cupboards.."},
{"Cupboard: Deauthorized", "Deauthorized {0} on {1} cupboards"},
{"Turrets: Authorized", "Authorized {0} on {1} turrets"},
{"Turrets: Authorizing", "Authorizing turrets.."},
{"Turrets: Prodding", "Prodding turrets.."},
{"Turrets: Deauthorized", "Deauthorized {0} on {1} turrets"},
{"Turrets: Deauthorizing", "Deauthorizing turrets.."},
{"Lock: Code", "Code: {0}"}
};
// Loads the default configuration
protected override void LoadDefaultConfig ()
{
Config ["VERSION"] = Version.ToString ();
Config ["EntityLimit"] = 8000;
Config ["DistanceThreshold"] = 3.0f;
Config ["CupboardDistanceThreshold"] = 20f;
Config.Save ();
}
new void LoadDefaultMessages ()
{
lang.RegisterMessages (texts, this);
}
protected void ReloadConfig ()
{
Config ["VERSION"] = Version.ToString ();
// NEW CONFIGURATION OPTIONS HERE
// END NEW CONFIGURATION OPTIONS
PrintToConsole ("Upgrading Configuration File");
SaveConfig ();
}
// Gets a config value of a specific type
T GetConfig<T> (string name, T defaultValue)
{
if (Config [name] == null) {
return defaultValue;
}
return (T)Convert.ChangeType (Config [name], typeof (T));
}
string GetMsg (string key, BasePlayer player = null)
{
return lang.GetMessage (key, this, player == null ? null : player.UserIDString);
}
void OnServerInitialized ()
{
try {
LoadConfig ();
debug = GetConfig ("Debug", false);
EntityLimit = GetConfig ("EntityLimit", 8000);
DistanceThreshold = GetConfig ("DistanceThreshold", 3f);
CupboardDistanceThreshold = GetConfig ("CupboardDistanceThreshold", 20f);
if (DistanceThreshold >= 5) {
PrintWarning ("ALERT: Distance threshold configuration option is ABOVE 5. This may cause serious performance degradation (lag) when using EntityOwner commands");
}
if (!permission.PermissionExists ("entityowner.cancheckowners")) permission.RegisterPermission ("entityowner.cancheckowners", this);
if (!permission.PermissionExists ("entityowner.cancheckcodes")) permission.RegisterPermission ("entityowner.cancheckcodes", this);
if (!permission.PermissionExists ("entityowner.canchangeowners")) permission.RegisterPermission ("entityowner.canchangeowners", this);
if (!permission.PermissionExists ("entityowner.seedetails")) permission.RegisterPermission ("entityowner.seedetails", this);
LoadData ();
} catch (Exception ex) {
PrintError ("OnServerInitialized failed: {0}", ex.Message);
}
}
void LoadData ()
{
if (Config ["VERSION"] == null) {
// FOR COMPATIBILITY WITH INITIAL VERSIONS WITHOUT VERSIONED CONFIG
ReloadConfig ();
} else if (GetConfig ("VERSION", Version.ToString ()) != Version.ToString ()) {
// ADDS NEW, IF ANY, CONFIGURATION OPTIONS
ReloadConfig ();
}
}
[HookMethod ("SendHelpText")]
void SendHelpText (BasePlayer player)
{
var sb = new StringBuilder ();
if (canCheckOwners (player) || canChangeOwners (player)) {
sb.Append ("<size=18>EntityOwner</size> by <color=#ce422b>Calytic</color> at <color=#ce422b>http://rustservers.io</color>\n");
}
if (canCheckOwners (player)) {
sb.Append (" ").Append ("<color=\"#ffd479\">/prod</color> - Check ownership of entity you are looking at").Append ("\n");
sb.Append (" ").Append ("<color=\"#ffd479\">/prod2</color> - Check ownership of entire structure/all deployables").Append ("\n");
sb.Append (" ").Append ("<color=\"#ffd479\">/prod2 block</color> - Check ownership structure only").Append ("\n");
sb.Append (" ").Append ("<color=\"#ffd479\">/prod2 cupboard</color> - Check authorization on all nearby cupboards").Append ("\n");
sb.Append (" ").Append ("<color=\"#ffd479\">/auth</color> - Check authorization list of tool cupboard you are looking at").Append ("\n");
}
if (canChangeOwners (player)) {
sb.Append (" ").Append ("<color=\"#ffd479\">/own [all/block]</color> - Take ownership of entire structure").Append ("\n");
sb.Append (" ").Append ("<color=\"#ffd479\">/own [all/block] PlayerName</color> - Give ownership of entire structure to specified player").Append ("\n");
sb.Append (" ").Append ("<color=\"#ffd479\">/unown [all/block]</color> - Remove ownership from entire structure").Append ("\n");
sb.Append (" ").Append ("<color=\"#ffd479\">/auth PlayerName</color> - Authorize specified player on all nearby cupboards").Append ("\n");
}
SendReply (player, sb.ToString ());
}
#endregion
#region Chat Commands
[ChatCommand ("prod")]
void cmdProd (BasePlayer player, string command, string [] args)
{
if (!canCheckOwners (player)) {
SendReply (player, GetMsg ("Denied: Permission", player));
return;
}
if (args == null || args.Length == 0) {
//var input = serverinput.GetValue(player) as InputState;
//var currentRot = Quaternion.Euler(input.current.aimAngles) * Vector3.forward;
//var target = RaycastAll<BaseEntity>(player.transform.position + new Vector3(0f, 1.5f, 0f), currentRot);
var target = RaycastAll<BaseEntity> (player.eyes.HeadRay ());
if (target is bool) {
SendReply (player, GetMsg ("Target: None", player));
return;
}
if (target is BaseEntity) {
var targetEntity = target as BaseEntity;
var owner = GetOwnerName ((BaseEntity)target);
if (string.IsNullOrEmpty (owner)) {
owner = "N/A";
}
string msg = string.Format (GetMsg ("Target: Owner", player), owner);
if (canSeeDetails (player)) {
msg += "\n<color=#D3D3D3>Name: " + targetEntity.ShortPrefabName + "</color>";
if (targetEntity.skinID > 0) {
msg += "\n<color=#D3D3D3>Skin: " + targetEntity.skinID + "</color>";
}
if (targetEntity.PrefabName != targetEntity.ShortPrefabName) {
msg += "\n<color=#D3D3D3>Prefab: \"" + targetEntity.PrefabName + "\"</color>";
}
msg += "\n<color=#D3D3D3>Outside: " + (targetEntity.IsOutside () ? "Yes" : "No") + "</color>";
}
if (canCheckCodes (player)) {
var baseLock = targetEntity.GetSlot (BaseEntity.Slot.Lock);
if (baseLock is CodeLock) {
CodeLock codeLock = (CodeLock)baseLock;
string keyCode = codeLock.code;
msg += "\n" + string.Format (GetMsg ("Lock: Code", player), keyCode);
}
}
SendReply (player, msg);
}
} else {
SendReply (player, GetMsg ("Syntax: Owner", player));
}
}
[ChatCommand ("own")]
void cmdOwn (BasePlayer player, string command, string [] args)
{
if (!canChangeOwners (player)) {
SendReply (player, GetMsg ("Denied: Permission", player));
return;
}
var massTrigger = false;
string type = null;
ulong target = player.userID; ;
if (args.Length == 0) {
args = new string [1] { "1" };
}
if (args.Length > 2) {
SendReply (player, GetMsg ("Syntax: Own", player));
return;
}
if (args.Length == 1) {
if (type == "all" || type == "storage" || type == "block" || type == "cupboard" || type == "sign" || type == "sleepingbag" || type == "plant" || type == "oven" || type == "door" || type == "turret") {
massTrigger = true;
target = player.userID;
} else if (!string.IsNullOrEmpty (type)) {
target = FindUserIDByPartialName (type);
type = "1";
if (target == 0) {
SendReply (player, GetMsg ("Player: None", player));
} else {
massTrigger = true;
}
} else {
massTrigger = true;
type = "1";
}
} else if (args.Length == 2) {
type = args [0];
target = FindUserIDByPartialName (args [1]);
if (target == 0) {
SendReply (player, GetMsg ("Player: None", player));
} else {
massTrigger = true;
}
}
if (!massTrigger || type == null) return;
switch (type) {
case "1":
BaseEntity entity;
if (TryGetEntity<BaseEntity> (player, out entity)) {
ChangeOwner (entity, target);
SendReply (player, GetMsg ("Ownership: Changed", player));
} else {
SendReply (player, GetMsg ("Target: None", player));
}
break;
case "all":
massChangeOwner<BaseEntity> (player, target);
break;
case "block":
massChangeOwner<BuildingBlock> (player, target);
break;
case "storage":
massChangeOwner<StorageContainer> (player, target);
break;
case "sign":
massChangeOwner<Signage> (player, target);
break;
case "sleepingbag":
massChangeOwner<SleepingBag> (player, target);
break;
case "plant":
massChangeOwner<GrowableEntity> (player, target);
break;
case "oven":
massChangeOwner<BaseOven> (player, target);
break;
case "turret":
massChangeOwner<AutoTurret> (player, target);
break;
case "door":
massChangeOwner<Door> (player, target);
break;
case "cupboard":
massChangeOwner<BuildingPrivlidge> (player, target);
break;
}
}
[ChatCommand ("unown")]
void cmdUnown (BasePlayer player, string command, string [] args)
{
if (!canChangeOwners (player)) {
SendReply (player, GetMsg ("Denied: Permission", player));
return;
}
if (args.Length == 0) {
args = new [] { "1" };
}
if (args.Length > 1) {
SendReply (player, GetMsg ("Syntax: Unown", player));
return;
}
if (args.Length != 1) return;
switch (args [0]) {
case "1":
BaseEntity entity;
if (TryGetEntity<BaseEntity> (player, out entity)) {
RemoveOwner (entity);
SendReply (player, GetMsg ("Ownership: Removed", player));
} else {
SendReply (player, GetMsg ("Target: None", player));
}
break;
case "all":
massChangeOwner<BaseEntity> (player);
break;
case "block":
massChangeOwner<BuildingBlock> (player);
break;
case "storage":
massChangeOwner<StorageContainer> (player);
break;
case "sign":
massChangeOwner<Signage> (player);
break;
case "sleepingbag":
massChangeOwner<SleepingBag> (player);
break;
case "plant":
massChangeOwner<GrowableEntity> (player);
break;
case "oven":
massChangeOwner<BaseOven> (player);
break;
case "turret":
massChangeOwner<AutoTurret> (player);
break;
case "door":
massChangeOwner<Door> (player);
break;
case "cupboard":
massChangeOwner<BuildingPrivlidge> (player);
break;
}
}
[ChatCommand ("auth")]
void cmdAuth (BasePlayer player, string command, string [] args)
{
if (!canChangeOwners (player)) {
SendReply (player, GetMsg ("Denied: Permission", player));
return;
}
var massCupboard = false;
var massTurret = false;
var checkCupboard = false;
var checkTurret = false;
var error = false;
BasePlayer target = null;
if (args.Length > 2) {
error = true;
} else if (args.Length == 1) {
if (args [0] == "cupboard") {
checkCupboard = true;
} else if (args [0] == "turret") {
checkTurret = true;
} else {
massCupboard = true;
target = FindPlayerByPartialName (args [0]);
}
} else if (args.Length == 0) {
checkCupboard = true;
} else if (args.Length == 2) {
if (args [0] == "cupboard") {
massCupboard = true;
target = FindPlayerByPartialName (args [1]);
} else if (args [0] == "turret") {
massTurret = true;
target = FindPlayerByPartialName (args [1]);
} else {
error = true;
}
}
if ((massTurret || massCupboard) && target?.net?.connection == null) {
SendReply (player, GetMsg ("Player: None", player));
return;
}
if (error) {
SendReply (player, GetMsg ("Syntax: Auth", player));
return;
}
if (massCupboard) {
massCupboardAuthorize (player, target);
}
if (checkCupboard) {
var priv = RaycastAll<BuildingPrivlidge> (player.eyes.HeadRay ());
if (priv is bool) {
SendReply (player, GetMsg ("Target: None", player));
return;
}
if (priv is BuildingPrivlidge) {
ProdCupboard (player, (BuildingPrivlidge)priv);
}
}
if (massTurret) {
massTurretAuthorize (player, target);
}
if (checkTurret) {
var turret = RaycastAll<AutoTurret> (player.eyes.HeadRay ());
if (turret is bool) {
SendReply (player, GetMsg ("Target: None", player));
return;
}
if (turret is AutoTurret) {
ProdTurret (player, (AutoTurret)turret);
}
}
}
[ChatCommand ("deauth")]
void cmdDeauth (BasePlayer player, string command, string [] args)
{
if (!canChangeOwners (player)) {
SendReply (player, GetMsg ("Denied: Permission", player));
return;
}
var massCupboard = false;
var massTurret = false;
var error = false;
BasePlayer target = null;
if (args.Length > 2) {
error = true;
} else if (args.Length == 1) {
if (args [0] == "cupboard") {
SendReply (player, "Invalid Syntax. /deauth cupboard PlayerName");
return;
}
if (args [0] == "turret") {
SendReply (player, "Invalid Syntax. /deauth turret PlayerName");
return;
}
massCupboard = true;
target = FindPlayerByPartialName (args [0]);
} else if (args.Length == 0) {
SendReply (player, "Invalid Syntax. /deauth PlayerName\n/deauth turret/cupboard PlayerName");
return;
} else if (args.Length == 2) {
if (args [0] == "cupboard") {
massCupboard = true;
target = FindPlayerByPartialName (args [1]);
} else if (args [0] == "turret") {
massTurret = true;
target = FindPlayerByPartialName (args [1]);
} else {
error = true;
}
}
if ((massTurret || massCupboard) && target?.net?.connection == null) {
SendReply (player, GetMsg ("Player: None", player));
return;
}
if (error) {
SendReply (player, GetMsg ("Syntax: Deauth", player));
return;
}
if (massCupboard) {
massCupboardDeauthorize (player, target);
}
if (massTurret) {
massTurretDeauthorize (player, target);
}
}
[ChatCommand ("prod2")]
void cmdProd2 (BasePlayer player, string command, string [] args)
{
if (!canCheckOwners (player)) {
SendReply (player, GetMsg ("Denied: Permission", player));
return;
}
bool highlight = false;
if (args.Length > 0) {
if (args [0] == "highlight") {
highlight = true;
args = args.Skip (1).ToArray ();
}
if (args.Length == 0) {
massProd<BaseEntity> (player, highlight);
return;
}
switch (args [0]) {
case "all":
args = args.Skip (1).ToArray ();
massProd<BaseEntity> (player, highlight, args);
break;
case "block":
massProd<BuildingBlock> (player, highlight);
break;
case "storage":
massProd<StorageContainer> (player, highlight);
break;
case "sign":
massProd<Signage> (player, highlight);
break;
case "sleepingbag":
massProd<SleepingBag> (player, highlight);
break;
case "plant":
massProd<GrowableEntity> (player, highlight);
break;
case "oven":
massProd<BaseOven> (player, highlight);
break;
case "turret":
massProdTurret (player, highlight);
break;
case "cupboard":
massProdCupboard (player, highlight);
break;
default:
massProd<BaseEntity> (player, highlight, args);
break;
}
} else if (args.Length == 0) {
massProd<BaseEntity> (player);
} else {
SendReply (player, GetMsg ("Syntax: Prod2", player));
}
}
#endregion
#region Permission Checks
bool canCheckOwners (BasePlayer player)
{
if (player == null) return false;
if (player.net.connection.authLevel > 0) return true;
return permission.UserHasPermission (player.UserIDString, "entityowner.cancheckowners");
}
bool canCheckCodes (BasePlayer player)
{
if (player == null) return false;
if (player.net.connection.authLevel > 0) return true;
return permission.UserHasPermission (player.UserIDString, "entityowner.cancheckcodes");
}
bool canSeeDetails (BasePlayer player)
{
if (player == null) return false;
if (player.net.connection.authLevel > 0) return true;
return permission.UserHasPermission (player.UserIDString, "entityowner.seedetails");
}
bool canChangeOwners (BasePlayer player)
{
if (player == null) return false;
if (player.net.connection.authLevel > 0) return true;
return permission.UserHasPermission (player.UserIDString, "entityowner.canchangeowners");
}
#endregion
#region Ownership Methods
bool TryGetEntity<T> (BasePlayer player, out BaseEntity entity) where T : BaseEntity
{
entity = null;
var target = RaycastAll<BaseEntity> (player.eyes.HeadRay ());
if (target is T) {
entity = target as T;
return true;
}
return false;
}
void massChangeOwner<T> (BasePlayer player, ulong target = 0) where T : BaseEntity
{
object entityObject = false;
if (typeof (T) == typeof (BuildingBlock)) {
entityObject = FindBuilding (player.transform.position, DistanceThreshold);
} else {
entityObject = FindEntity (player.transform.position, DistanceThreshold);
}
if (entityObject is bool) {
SendReply (player, GetMsg ("Entities: None", player));
} else {
if (target == 0) {
SendReply (player, GetMsg ("Ownership: Removing", player));
} else {
SendReply (player, GetMsg ("Ownership: Changing", player));
}
var entity = entityObject as T;
var entityList = new HashSet<T> ();
var checkFrom = new List<Vector3> ();
entityList.Add ((T)entity);
checkFrom.Add (entity.transform.position);
var c = 1;
if (target == 0) {
RemoveOwner (entity);
} else {
ChangeOwner (entity, target);
}
var current = 0;
var bbs = 0;
var ebs = 0;
if (entity is BuildingBlock) {
bbs++;
} else {
ebs++;
}
while (true) {
current++;
if (current > EntityLimit) {
if (debug) {
SendReply (player, GetMsg ("Target: Limit", player) + " " + EntityLimit);
}
SendReply (player, string.Format (GetMsg ("Entities: Count", player), c, bbs, ebs));
break;
}
if (current > checkFrom.Count) {
SendReply (player, string.Format (GetMsg ("Entities: Count", player), c, bbs, ebs));
break;
}
var hits = FindEntities<T> (checkFrom [current - 1], DistanceThreshold);
foreach (var entityComponent in hits.ToList ()) {
if (!entityList.Add (entityComponent)) continue;
c++;
checkFrom.Add (entityComponent.transform.position);
if (entityComponent is BuildingBlock) {
bbs++;
} else {
ebs++;
}
if (target == 0) {
RemoveOwner (entityComponent);
} else {
ChangeOwner (entityComponent, target);
}
}
Pool.FreeList (ref hits);
}
if (target == 0) {
SendReply (player, string.Format (GetMsg ("Ownership: New", player), "No one"));
} else {
BasePlayer targetPlayer = BasePlayer.FindByID (target);
if (targetPlayer != null) {
SendReply (player, string.Format (GetMsg ("Ownership: New", player), targetPlayer.displayName));
SendReply (targetPlayer, GetMsg ("Ownership: New Self", player));
} else {
IPlayer pl = covalence.Players.FindPlayerById (target.ToString ());
SendReply (player, string.Format (GetMsg ("Target: Owner", player), pl.Name));
}
}
}
}
void massProd<T> (BasePlayer player, bool highlight = false, params string [] filter) where T : BaseEntity
{
object entityObject = false;
entityObject = FindEntity (player.transform.position, DistanceThreshold);
if (entityObject is bool) {
SendReply (player, GetMsg ("Entities: None", player));
} else {
float health = 0f;
float maxHealth = 0f;
var prodOwners = new Dictionary<ulong, int> ();
var entity = entityObject as BaseEntity;
if (entity.transform == null) {
SendReply (player, GetMsg ("Entities: None", player));
return;
}
SendReply (player, GetMsg ("Structure: Prodding", player));
var entityList = new HashSet<T> ();
var checkFrom = new List<Vector3> ();
if (entity is T) {
entityList.Add ((T)entity);
}
var total = 0;
var skip = false;
if (entity is T) {
if (filter.Length > 0) {
skip = true;
foreach (var f in filter) {
if (entity.name.ToLower ().Contains (f.ToLower ())) {
skip = false;
break;
}
}
}
if (!skip) {
prodOwners.Add (entity.OwnerID, 1);
health += entity.Health ();
maxHealth += entity.MaxHealth ();
total++;
}
}
var current = -1;
var distanceThreshold = DistanceThreshold;
if (typeof (T) != typeof (BuildingBlock) && typeof (T) != typeof (BaseEntity))
distanceThreshold += 30;
while (true) {
current++;
if (current > EntityLimit) {
SendReply (player, GetMsg ("Target: Limit", player) + " " + EntityLimit);
break;
}
if (current > checkFrom.Count) {
break;
}
var hits = FindEntities<T> (checkFrom.Count > 0 ? checkFrom [current - 1] : entity.transform.position, distanceThreshold);
skip = false;
foreach (var fentity in hits) {
if (fentity.transform == null || !entityList.Add (fentity) || fentity.name == "player/player")
continue;
if (filter.Length > 0) {
skip = true;
foreach (var f in filter) {
if (fentity.name.ToLower ().Contains (f.ToLower ())) {
skip = false;
break;
}
}
}
checkFrom.Add (fentity.transform.position);
if (!skip) {
total++;
if (highlight) {
SendHighlight (player, fentity.transform.position);
}
var pid = fentity.OwnerID;
if (prodOwners.ContainsKey (pid)) {
prodOwners [pid]++;
} else {
prodOwners.Add (pid, 1);
}
health += fentity.Health ();
maxHealth += fentity.MaxHealth ();
}
}
Pool.FreeList (ref hits);
}
var unknown = 100;
var msg = string.Empty;
msg = "<size=16>Structure</size>\n";
msg += $"Entities: {total}\n";
if (health > 0 && maxHealth > 0) {
var condition = Mathf.Round (health * 100 / maxHealth);
msg += string.Format (GetMsg ("Structure: Condition Percent", player), condition);
}
SendReply (player, msg);
msg = "<size=16>Ownership</size>\n";
if (total > 0) {
foreach (var kvp in prodOwners) {
var perc = kvp.Value * 100 / total;
if (kvp.Key != 0) {
var n = FindPlayerName (kvp.Key);
msg += $"{n}: {perc}%\n";
unknown -= perc;
}
}
}
if (unknown > 0)
msg += string.Format (GetMsg ("Player: Unknown Percent", player), unknown);
SendReply (player, msg);
}
}
void SendHighlight (BasePlayer player, Vector3 position)
{
player.SendConsoleCommand ("ddraw.sphere", 30f, Color.magenta, position, 2f);
player.SendNetworkUpdateImmediate ();
}
void ProdCupboard (BasePlayer player, BuildingPrivlidge cupboard)
{
List<string> authorizedUsers;
var sb = new StringBuilder ();
if (TryGetCupboardUserNames (cupboard, out authorizedUsers)) {
sb.AppendLine (string.Format (GetMsg ("Entities: Authorized", player), authorizedUsers.Count));
foreach (var n in authorizedUsers)
sb.AppendLine (n);
} else
sb.Append (string.Format (GetMsg ("Target: None", player)));
SendReply (player, sb.ToString ());
}
void ProdTurret (BasePlayer player, AutoTurret turret)
{
List<string> authorizedUsers;
var sb = new StringBuilder ();
if (TryGetTurretUserNames (turret, out authorizedUsers)) {
sb.AppendLine (string.Format (GetMsg ("Entities: Authorized", player), authorizedUsers.Count));
foreach (var n in authorizedUsers)
sb.AppendLine (n);
} else {
sb.Append (string.Format (GetMsg ("Target: None", player)));
}
SendReply (player, sb.ToString ());
}
void massProdCupboard (BasePlayer player, bool highlight = false)
{
object entityObject = false;
entityObject = FindEntity (player.transform.position, DistanceThreshold);
if (entityObject is bool) {
SendReply (player, GetMsg ("Entities: None", player));
} else {
var total = 0;
var prodOwners = new Dictionary<ulong, int> ();
SendReply (player, GetMsg ("Cupboards: Prodding", player));
var entity = entityObject as BaseEntity;
var entityList = new HashSet<BaseEntity> ();
var checkFrom = new List<Vector3> ();
checkFrom.Add (entity.transform.position);
var current = 0;
while (true) {
current++;
if (current > EntityLimit) {
if (debug)
SendReply (player, GetMsg ("Target: Limit", player) + " " + EntityLimit);
SendReply (player, string.Format (GetMsg ("Ownership: Count", player), total));
break;
}
if (current > checkFrom.Count) {
SendReply (player, string.Format (GetMsg ("Ownership: Count", player), total));
break;
}
var entities = FindEntities<BuildingPrivlidge> (checkFrom [current - 1], CupboardDistanceThreshold);
foreach (var e in entities) {
if (!entityList.Add (e)) { continue; }
if (highlight) {
SendHighlight (player, e.transform.position);
}
checkFrom.Add (e.transform.position);
foreach (var pnid in e.authorizedPlayers) {
if (prodOwners.ContainsKey (pnid.userid))
prodOwners [pnid.userid]++;
else
prodOwners.Add (pnid.userid, 1);
}
total++;
}
Pool.FreeList (ref entities);
}
var percs = new Dictionary<ulong, int> ();
var unknown = 100;
if (total > 0) {
foreach (var kvp in prodOwners) {
var perc = kvp.Value * 100 / total;
percs.Add (kvp.Key, perc);
var n = FindPlayerName (kvp.Key);
if (!n.Contains ("Unknown: ")) {
SendReply (player, n + ": " + perc + "%");
unknown -= perc;
}
}
if (unknown > 0)
SendReply (player, string.Format (GetMsg ("Player: Unknown Percent", player), unknown));
}
}
}
void massProdTurret (BasePlayer player, bool highlight = false)
{
object entityObject = false;
entityObject = FindEntity (player.transform.position, DistanceThreshold);
if (entityObject is bool) {
SendReply (player, GetMsg ("Entities: None", player));
} else {
var total = 0;
var prodOwners = new Dictionary<ulong, int> ();
SendReply (player, GetMsg ("Turrets: Prodding", player));
var entity = entityObject as BaseEntity;
var entityList = new HashSet<BaseEntity> ();
var checkFrom = new List<Vector3> ();
checkFrom.Add (entity.transform.position);
var current = 0;
while (true) {
current++;
if (current > EntityLimit) {
if (debug)
SendReply (player, GetMsg ("Target: Limit", player) + " " + EntityLimit);
SendReply (player, string.Format (GetMsg ("Ownership: Count", player), total));
break;
}
if (current > checkFrom.Count) {
SendReply (player, string.Format (GetMsg ("Ownership: Count", player), total));
break;
}