-
Notifications
You must be signed in to change notification settings - Fork 12
/
ZHIPM.Initialize.cs
5153 lines (4668 loc) · 221 KB
/
ZHIPM.Initialize.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 Microsoft.Xna.Framework;
using System.IO.Compression;
using System.Text;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using TerrariaApi.Server;
using TShockAPI;
using TShockAPI.DB;
using TShockAPI.Hooks;
namespace ZHIPlayerManager;
public partial class ZHIPM : TerrariaPlugin
{
/// <summary>
/// 帮助指令方法指令
/// </summary>
/// <param name="args"></param>
private void Help(CommandArgs args)
{
if (args.Parameters.Count != 0)
{
args.Player.SendInfoMessage(GetString("输入 /zhelp 来查看指令帮助"));
}
else
{
args.Player.SendMessage(GetString("输入 /zsave 来备份自己的人物存档\n") +
GetString("输入 /zsaveauto <minute> 来每隔 minute 分钟自动备份自己的人物存档,当 minute 为 0 时关闭该功能\n") +
GetString("输入 /zvisa <num> 来查看自己的人物备份\n") +
GetString("输入 /zvisa name <num> 来查看该玩家的第几个人物备份\n") +
GetString("输入 /zhide kill 来取消 kill + 1 的显示,再次使用启用显示\n") +
GetString("输入 /zhide point 来取消 + 1 $ 的显示,再次使用启用显示\n") +
GetString("输入 /zback <name> 来读取该玩家的人物存档\n") +
GetString("输入 /zback <name> <num> 来读取该玩家的第几个人物存档\n") +
GetString("输入 /zclone <name1> <name2> 将玩家1的人物数据复制给玩家2\n") +
GetString("输入 /zclone <name> 将该玩家的人物数据复制给自己\n") +
GetString("输入 /zmodify help 查看修改玩家数据的指令帮助\n") +
GetString("输入 /vi <name> 来查看该玩家的库存\n") +
GetString("输入 /vid <name> 来查看该玩家的库存,不分类\n") +
GetString("输入 /vs <name> 来查看该玩家的状态\n") +
GetString("输入 /vs me 来查看自己的状态\n") +
GetString("输入 /zfre <name> 来冻结该玩家\n") +
GetString("输入 /zunfre <name> 来解冻该玩家\n") +
GetString("输入 /zunfre all 来解冻所有玩家\n") +
GetString("输入 /zsort help 来查看排序系列指令帮助\n") +
GetString("输入 /zout <name> 来导出该玩家的人物存档\n") +
GetString("输入 /zout all 来导出所有人物的存档并压缩打包\n") +
GetString("输入 /zreset help 来查看zreset系列指令帮助\n") +
GetString("输入 /zban add <name> <reason> 来封禁无论是否在线的玩家,reason 可不填\n") +
GetString("输入 /zban add uuid <uuid> <reason> 来封禁uuid\n") +
GetString("输入 /zban add ip <ip> <reason> 来封禁ip\n") +
GetString("输入 /zclear useless 来清理世界的掉落物品,非城镇或BossNPC,和无用射弹\n") +
GetString("输入 /zclear buff <name> 来清理该玩家的所有Buff\n") +
GetString("输入 /zclear buff all 来清理所有玩家所有Buff\n") +
GetString("输入 /zbpos 来返回上次死亡地点\n") /*+
GetString("输入 /zfind <id> 来查找当前哪些玩家拥有此物品")*/,
TextColor()
);
}
}
/// <summary>
/// 回档指令方法指令
/// </summary>
/// <param name="args"></param>
private void MySSCBack(CommandArgs args)
{
if (args.Parameters.Count == 1)
{
this.MySSCBack2(args, 1);
return;
}
if (args.Parameters.Count == 2)
{
if (!int.TryParse(args.Parameters[1], out var num))
{
args.Player.SendInfoMessage(GetString("输入 /zback <name> 来读取该玩家的最新人物存档\n输入 /zback <name> <num> 来读取该玩家的第几个人物存档"));
return;
}
if (num < 1 || num > config.MaxBackupsPerPlayer)
{
args.Player.SendInfoMessage(GetString($"玩家最多有 {config.MaxBackupsPerPlayer} 个备份存档,范围 1 ~ {config.MaxBackupsPerPlayer},请重新输入"));
return;
}
this.MySSCBack2(args, num);
}
else
{
args.Player.SendInfoMessage(GetString("输入 /zback <name> 来读取该玩家的最新人物存档\n输入 /zback <name> <num> 来读取该玩家的第几个人物存档"));
}
}
/// <summary>
/// 保存指令方法指令
/// </summary>
/// <param name="args"></param>
private void MySSCSave(CommandArgs args)
{
if (args.Parameters.Count != 0)
{
args.Player.SendInfoMessage(GetString("输入 /zsave 来备份自己的人物存档"));
return;
}
if (!args.Player.IsLoggedIn)
{
args.Player.SendInfoMessage(GetString("对象不正确,请检查您的状态,您是否为游戏内玩家?"));
return;
}
if (ZPDataBase.AddZPlayerDB(args.Player))
{
var extraData = edPlayers.Find(x => x.Name == args.Player.Name);
if (extraData != null)
{
ZPExtraDB.WriteExtraDB(extraData);
}
args.Player.SendMessage(GetString("您的备份保存成功!"), new Color(0, 255, 0));
}
else
{
args.Player.SendMessage(GetString("您的备份保存失败!请尝试重进游戏重试"), new Color(255, 0, 0));
}
}
/// <summary>
/// 自动备份指令
/// </summary>
/// <param name="args"></param>
/// <exception cref="NotImplementedException"></exception>
private void MySSCSaveAuto(CommandArgs args)
{
if (!config.EnablePlayerAutoBackup)
{
args.Player.SendMessage(GetString("自动备份被禁用,请联系管理员询问详情"), new Color(255, 0, 0));
return;
}
if (args.Parameters.Count != 1)
{
args.Player.SendInfoMessage(GetString("输入 /zsaveauto [minute] 来每隔 minute 分钟自动备份自己的人物存档,当 minute 为 0 时关闭该功能"));
return;
}
if (!args.Player.IsLoggedIn)
{
args.Player.SendInfoMessage(GetString("对象不正确,请检查您的状态,您是否为游戏内玩家?"));
return;
}
if (int.TryParse(args.Parameters[0], out var num))
{
if (num < 0)
{
args.Player.SendInfoMessage(GetString("数字不合理"));
return;
}
var ex = edPlayers.Find(x => x.Name == args.Player.Name);
if (ex == null)
{
args.Player.SendInfoMessage(GetString("修改失败,请重进服务器重试"));
return;
}
ex.backuptime = num;
if (num != 0)
{
args.Player.SendMessage(GetString($"修改成功,你的存档将每隔{num}分钟自动备份一次,请注意存档覆盖情况,这可能会覆盖你手动备份的部分"), new Color(0, 255, 0));
}
else
{
args.Player.SendMessage(GetString("修改成功,你的自动备份已关"), new Color(0, 255, 0));
}
}
else
{
args.Player.SendInfoMessage(GetString("输入 /zsaveauto [minute] 来每隔 minute 分钟自动备份自己的人物存档,当 minute 为 0 时关闭该功能"));
}
}
/// <summary>
/// 查看我的存档方法指令
/// </summary>
/// <param name="args"></param>
private void ViewMySSCSave(CommandArgs args)
{
//查询本人
if (args.Parameters.Count == 0 || (args.Parameters.Count == 1 && int.TryParse(args.Parameters[0], out var num1)))
{
if (!args.Player.IsLoggedIn)
{
args.Player.SendInfoMessage(GetString("对象不正确,请检查您的状态,您是否为游戏内玩家?"));
return;
}
int slot;
if (args.Parameters.Count == 0)
{
slot = 1;
}
else
{
var num = int.Parse(args.Parameters[0]);
if (num < 1 || num > config.MaxBackupsPerPlayer)
{
args.Player.SendInfoMessage(GetString($"玩家最多有 {config.MaxBackupsPerPlayer} 个备份存档,范围 1 ~ {config.MaxBackupsPerPlayer},请重新输入"));
return;
}
slot = num;
}
var playerData = ZPDataBase.ReadZPlayerDB(args.Player, args.Player.Account.ID, slot);
if (playerData == null || !playerData.exists)
{
args.Player.SendInfoMessage(GetString("您还未备份"));
}
else
{
var items = new Item[NetItem.MaxInventory];
for (var i = 0; i < NetItem.MaxInventory; i++)
{
items[i] = TShock.Utils.GetItemById(playerData.inventory[i].NetId);
items[i].stack = playerData.inventory[i].Stack;
items[i].prefix = playerData.inventory[i].PrefixId;
}
var text = GetItemsString(items, NetItem.MaxInventory);
text = FormatArrangement(text, 30, " ");
var str = GetString($"您的备份[{args.Player.Account.ID} - {slot}]的内容为:\n") + text;
args.Player.SendInfoMessage(str);
}
}
//查询他人
else if (args.Parameters.Count == 1 || (args.Parameters.Count == 2 && int.TryParse(args.Parameters[1], out var num2)))
{
int slot;
if (args.Parameters.Count == 1)
{
slot = 1;
}
else
{
var num = int.Parse(args.Parameters[1]);
if (num < 1 || num > config.MaxBackupsPerPlayer)
{
args.Player.SendInfoMessage(GetString($"玩家最多有 {config.MaxBackupsPerPlayer} 个备份存档,范围 1 ~ {config.MaxBackupsPerPlayer},请重新输入"));
return;
}
slot = num;
}
var ID = -1;
var playerfullname = "";
var list = this.BestFindPlayerByNameOrIndex(args.Parameters[0]);
if (list.Count == 0)
{
args.Player.SendInfoMessage(this.offlineplayer);
var users = TShock.UserAccounts.GetUserAccountsByName(args.Parameters[0], true);
if (users.Count == 1 || (users.Count > 1 && users.Exists(x => x.Name == args.Parameters[0])))
{
if (users.Count == 1)
{
ID = users[0].ID;
playerfullname = users[0].Name;
}
else
{
var temp = users.Find(x => x.Name == args.Parameters[0])!;
ID = temp.ID;
playerfullname = temp.Name;
}
}
else if (users.Count == 0)
{
args.Player.SendInfoMessage(this.noplayer);
return;
}
else
{
args.Player.SendInfoMessage(this.manyplayer);
return;
}
}
else
{
ID = list[0].Account.ID;
playerfullname = list[0].Name;
}
var playerData = ZPDataBase.ReadZPlayerDB(new TSPlayer(-1), ID, slot);
if (playerData == null || !playerData.exists)
{
args.Player.SendInfoMessage(GetString("该玩家还未备份"));
}
else
{
var items = new Item[NetItem.MaxInventory];
for (var i = 0; i < NetItem.MaxInventory; i++)
{
items[i] = TShock.Utils.GetItemById(playerData.inventory[i].NetId);
items[i].stack = playerData.inventory[i].Stack;
items[i].prefix = playerData.inventory[i].PrefixId;
}
var text = "";
if (args.Player.IsLoggedIn)
{
text = GetItemsString(items, NetItem.MaxInventory);
text = FormatArrangement(text, 30, " ");
}
else
{
text = GetItemsString(items, NetItem.MaxInventory, 1);
}
var str = GetString($"玩家[{playerfullname}]备份 [{ID} - {slot}] 的内容为:\n") + text;
args.Player.SendInfoMessage(str);
}
}
else
{
args.Player.SendInfoMessage(GetString("输入 /zvisa [num] 来查看自己的第几个人物备份\n输入 /zvisa name [num] 来查看该玩家的第几个人物备份"));
}
}
/// <summary>
/// 克隆另一个人的数据的方法指令
/// </summary>
/// <param name="args"></param>
private void SSCClone(CommandArgs args)
{
if (args.Parameters.Count == 0 || args.Parameters.Count > 2)
{
args.Player.SendInfoMessage(GetString("输入 /zclone [name1] [name2] 将玩家1的人物数据复制给玩家2\n输入 /zclone [name] 将该玩家的人物数据复制给自己"));
return;
}
if (args.Parameters.Count == 1)
{
if (args.Parameters[0] == args.Player.Name)
{
args.Player.SendMessage(GetString("克隆失败!请不要克隆自己"), new Color(255, 0, 0));
return;
}
if (!args.Player.IsLoggedIn)
{
args.Player.SendInfoMessage(GetString("对象不正确,请检查您的状态,您是否为游戏内玩家?"));
return;
}
var list = this.BestFindPlayerByNameOrIndex(args.Parameters[0]);
//找不到人,查离线
if (list.Count == 0)
{
args.Player.SendInfoMessage(this.offlineplayer);
var user = TShock.UserAccounts.GetUserAccountByName(args.Parameters[0]);
var users = TShock.UserAccounts.GetUserAccountsByName(args.Parameters[0], true);
if (user == null)
{
if (users.Count == 0)
{
args.Player.SendInfoMessage(this.noplayer);
return;
}
if (users.Count > 1)
{
args.Player.SendInfoMessage(this.manyplayer);
return;
}
user = users[0];
}
var playerData = TShock.CharacterDB.GetPlayerData(new TSPlayer(-1), user.ID);
if (this.UpdatePlayerAll(args.Player, playerData))
{
args.Player.SendMessage(GetString($"克隆成功!您已将玩家[{user.Name}]的数据克隆到你身上"), new Color(0, 255, 0));
}
else
{
args.Player.SendMessage(GetString("克隆失败!未在原数据库中查到该玩家,请检查输入是否正确,该玩家是否避免SSC检测,再重新输入"), new Color(255, 0, 0));
}
}
//人太多,舍弃
else if (list.Count > 1)
{
args.Player.SendInfoMessage(this.manyplayer);
return;
}
//一个在线
else
{
var playerData = list[0].PlayerData;
playerData.CopyCharacter(list[0]);
playerData.exists = true;
if (this.UpdatePlayerAll(args.Player, playerData))
{
args.Player.SendMessage(GetString($"克隆成功!您已将玩家[{list[0].Name}]的数据克隆到你身上"), new Color(0, 255, 0));
}
else
{
args.Player.SendMessage(GetString("克隆失败!未在原数据库中查到该玩家,请检查输入是否正确,该玩家是否避免SSC检测,再重新输入"), new Color(255, 0, 0));
}
}
}
if (args.Parameters.Count == 2)
{
var player1 = this.BestFindPlayerByNameOrIndex(args.Parameters[0]);
var player2 = this.BestFindPlayerByNameOrIndex(args.Parameters[1]);
if (player1.Count > 1 || player2.Count > 1)
{
args.Player.SendInfoMessage(this.manyplayer);
return;
}
//都在线的情况
if (player1.Count == 1 && player2.Count == 1)
{
if (player1[0].Name == player2[0].Name)
{
args.Player.SendInfoMessage(GetString("请不要对同一个人进行克隆"));
return;
}
player1[0].PlayerData.CopyCharacter(player1[0]);
player1[0].PlayerData.exists = true;
if (this.UpdatePlayerAll(player2[0], player1[0].PlayerData))
{
if (args.Player.Account.ID != player2[0].Account.ID)
{
args.Player.SendMessage(GetString($"克隆成功!您已将玩家 [{player1[0].Name}] 的数据克隆到 [{player2[0].Name}] 身上"), new Color(0, 255, 0));
}
else
{
player2[0].SendMessage(GetString("克隆成功!已将玩家 [" + player1[0].Name + "] 的数据克隆到你身上"), new Color(0, 255, 0));
}
}
else
{
args.Player.SendMessage(GetString("克隆失败!未在原数据库中查到该玩家,请检查输入是否正确,该玩家是否避免SSC检测,再重新输入"), new Color(255, 0, 0));
}
return;
}
//赋值者不在线,被赋值者在线的情况
if (player1.Count == 0 && player2.Count == 1)
{
args.Player.SendInfoMessage(GetString("玩家1不在线,正在查询离线数据"));
var user1 = TShock.UserAccounts.GetUserAccountByName(args.Parameters[0]);
var user1s = TShock.UserAccounts.GetUserAccountsByName(args.Parameters[0], true);
if (user1 == null)
{
if (user1s.Count == 0)
{
args.Player.SendInfoMessage(GetString("玩家1不存在"));
return;
}
if (user1s.Count > 1)
{
args.Player.SendInfoMessage(GetString("玩家1不唯一"));
return;
}
user1 = user1s[0];
}
var playerData1 = TShock.CharacterDB.GetPlayerData(new TSPlayer(-1), user1.ID);
if (this.UpdatePlayerAll(player2[0], playerData1))
{
if (args.Player.Account.ID != player2[0].Account.ID)
{
args.Player.SendMessage(GetString($"克隆成功!您已将玩家 [{user1.Name}] 的数据克隆到玩家 [{player2[0].Name}]身上"), new Color(0, 255, 0));
}
else
{
player2[0].SendMessage(GetString("克隆成功!已将玩家 [" + user1.Name + "] 的数据克隆到你身上"), new Color(0, 255, 0));
}
}
else
{
args.Player.SendMessage(GetString("克隆失败!未在原数据库中查到该玩家,请检查输入是否正确,该玩家是否避免SSC检测,再重新输入"), new Color(255, 0, 0));
}
return;
}
//赋值者在线,被赋值者不在线的情况
if (player1.Count == 1 && player2.Count == 0)
{
args.Player.SendInfoMessage(GetString("玩家2不在线,正在查询离线数据"));
var user2 = TShock.UserAccounts.GetUserAccountByName(args.Parameters[1]);
var user2s = TShock.UserAccounts.GetUserAccountsByName(args.Parameters[1], true);
if (user2 == null)
{
if (user2s.Count == 0)
{
args.Player.SendInfoMessage(GetString("玩家2不存在"));
return;
}
if (user2s.Count > 1)
{
args.Player.SendInfoMessage(GetString("玩家2不唯一"));
return;
}
user2 = user2s[0];
}
var playerData1 = player1[0].PlayerData;
playerData1.exists = true;
if (this.UpdateTshockDBCharac(user2.ID, playerData1))
{
args.Player.SendMessage(GetString($"克隆成功!您已将玩家 [{player1[0].Name}] 的数据克隆到玩家 [{user2.Name}] 身上"), new Color(0, 255, 0));
}
else
{
args.Player.SendMessage(GetString("克隆失败!未在原数据库中查到该玩家,请检查输入是否正确,该玩家是否避免SSC检测,再重新输入"), new Color(255, 0, 0));
}
return;
}
//都不在线
if (player1.Count == 0 && player2.Count == 0)
{
args.Player.SendInfoMessage(GetString("玩家都不在线,正在查询离线数据"));
var user1 = TShock.UserAccounts.GetUserAccountByName(args.Parameters[0]);
var user1s = TShock.UserAccounts.GetUserAccountsByName(args.Parameters[0], true);
var user2 = TShock.UserAccounts.GetUserAccountByName(args.Parameters[1]);
var user2s = TShock.UserAccounts.GetUserAccountsByName(args.Parameters[1], true);
if (user1 == null)
{
if (user1s.Count == 0)
{
args.Player.SendInfoMessage(GetString("玩家1不存在"));
return;
}
if (user1s.Count > 1)
{
args.Player.SendInfoMessage(GetString("玩家1不唯一"));
return;
}
user1 = user1s[0];
}
if (user2 == null)
{
if (user2s.Count == 0)
{
args.Player.SendInfoMessage(GetString("玩家2不存在"));
return;
}
if (user2s.Count > 1)
{
args.Player.SendInfoMessage(GetString("玩家2不唯一"));
return;
}
user2 = user2s[0];
}
var playerData = TShock.CharacterDB.GetPlayerData(new TSPlayer(-1), user1.ID);
if (this.UpdateTshockDBCharac(user2.ID, playerData))
{
args.Player.SendMessage(GetString($"克隆成功!您已将玩家 [{user1.Name}] 的数据克隆到玩家 [{user2.Name}] 身上"), new Color(0, 255, 0));
}
else
{
args.Player.SendMessage(GetString("克隆失败!未在原数据库中查到该玩家,请检查输入是否正确,该玩家是否避免SSC检测,再重新输入"), new Color(255, 0, 0));
}
}
}
}
/// <summary>
/// 修改人物数据方法指令
/// </summary>
/// <param name="args"></param>
private void SSCModify(CommandArgs args)
{
if (args.Parameters.Count != 1 && args.Parameters.Count != 3)
{
args.Player.SendInfoMessage(GetString("输入 /zmodify help 查看修改玩家数据的指令帮助"));
return;
}
if (args.Parameters.Count == 1)
{
if (args.Parameters[0].Equals("help", StringComparison.OrdinalIgnoreCase))
{
var temp = config.EnablePointTracking ? "\n输入 /zmodify [name] point [num] 来修改玩家点数" : "";
args.Player.SendMessage(
GetString("输入 /zmodify [name] life [num] 来修改玩家的血量\n") +
GetString("输入 /zmodify [name] lifemax [num] 来修改玩家的血量上限\n") +
GetString("输入 /zmodify [name] mana [num] 来修改玩家的魔力\n") +
GetString("输入 /zmodify [name] manamax [num] 来修改玩家的魔力上限\n") +
GetString("输入 /zmodify [name] fish [num] 来修改玩家的渔夫任务数\n") +
GetString("输入 /zmodify [name] torch [0或1] 来关闭或开启火把神增益\n") +
GetString("输入 /zmodify [name] demmon [0或1] 来关闭或开启恶魔心增益\n") +
GetString("输入 /zmodify [name] bread [0或1] 来关闭或开启工匠面包增益\n") +
GetString("输入 /zmodify [name] heart [0或1] 来关闭或开启埃癸斯水晶增益\n") +
GetString("输入 /zmodify [name] fruit [0或1] 来关闭或开启埃癸斯果增益\n") +
GetString("输入 /zmodify [name] pearl [0或1] 来关闭或开启银河珍珠增益\n") +
GetString("输入 /zmodify [name] worm [0或1] 来关闭或开启粘性蠕虫增益\n") +
GetString("输入 /zmodify [name] ambrosia [0或1] 来关闭或开启珍馐增益\n") +
GetString("输入 /zmodify [name] cart [0或1] 来关闭或开启超级矿车增益\n") +
GetString("输入 /zmodify [name] all [0或1] 来关闭或开启所有玩家增益") + temp
, TextColor());
}
else
{
args.Player.SendInfoMessage(GetString("输入 /zmodify help 查看修改玩家数据的指令帮助"));
}
return;
}
if (args.Parameters.Count == 3)
{
//对参数3先判断是不是数据,不是数字结束
if (!int.TryParse(args.Parameters[2], out var num))
{
args.Player.SendInfoMessage(GetString("格式错误!输入 /zmodify help 查看修改玩家数据的指令帮助"));
return;
}
//再判断能不能找到人的情况
var players = this.BestFindPlayerByNameOrIndex(args.Parameters[0]);
if (players.Count > 1)
{
args.Player.SendInfoMessage(this.manyplayer);
return;
}
//在线能找到
if (players.Count == 1)
{
if (args.Parameters[1].Equals("life", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.statLife = num;
players[0].SendData(PacketTypes.PlayerHp, "", players[0].Index);
players[0].SendMessage("您的生命值已被修改为:" + num, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("lifemax", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.statLifeMax = num;
players[0].SendData(PacketTypes.PlayerHp, "", players[0].Index);
players[0].SendMessage(GetString("您的生命上限已被修改为:") + num, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("mana", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.statMana = num;
players[0].SendData(PacketTypes.PlayerMana, "", players[0].Index);
players[0].SendMessage(GetString("您的魔力值已被修改为:") + num, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("manamax", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.statManaMax = num;
players[0].SendData(PacketTypes.PlayerMana, "", players[0].Index);
players[0].SendMessage(GetString("您的魔力上限已被修改为:") + num, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("fish", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.anglerQuestsFinished = num;
players[0].SendData(PacketTypes.NumberOfAnglerQuestsCompleted, "", players[0].Index);
players[0].SendMessage(GetString("您的渔夫任务完成数已被修改为:") + num, new Color(0, 255, 0));
}
else if (config.EnablePointTracking && args.Parameters[1].Equals("point", StringComparison.OrdinalIgnoreCase))
{
var ex = edPlayers.Find(x => x.Name == players[0].Name);
if (ex != null)
{
ex.point = num;
players[0].SendMessage(GetString("您的点数已被修改为:") + num, new Color(0, 255, 0));
}
else
{
args.Player.SendInfoMessage(GetString("不可预料的错误,请重试或让该玩家重进游戏"));
return;
}
}
else if (num != 0 && num != 1)
{
args.Player.SendInfoMessage(GetString("格式错误!输入 /zmodify help 查看修改玩家数据的指令帮助"));
return;
}
else if (args.Parameters[1].Equals("torch", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.unlockedBiomeTorches = num != 0;
players[0].SendData(PacketTypes.PlayerInfo, "", players[0].Index);
players[0].SendMessage(GetString("您的火把神增益开启状态:") + players[0].TPlayer.unlockedBiomeTorches, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("demmon", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.extraAccessory = num != 0;
players[0].SendData(PacketTypes.PlayerInfo, "", players[0].Index);
players[0].SendMessage(GetString("您的恶魔心增益开启状态:") + players[0].TPlayer.extraAccessory, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("bread", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.ateArtisanBread = num != 0;
players[0].SendData(PacketTypes.PlayerInfo, "", players[0].Index);
players[0].SendMessage(GetString("您的工匠面包增益开启状态:") + players[0].TPlayer.ateArtisanBread, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("heart", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.usedAegisCrystal = num != 0;
players[0].SendData(PacketTypes.PlayerInfo, "", players[0].Index);
players[0].SendMessage(GetString("您的埃癸斯水晶增益开启状态:") + players[0].TPlayer.usedAegisCrystal, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("fruit", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.usedAegisFruit = num != 0;
players[0].SendData(PacketTypes.PlayerInfo, "", players[0].Index);
players[0].SendMessage(GetString("您的埃癸斯果增益开启状态:") + players[0].TPlayer.usedAegisFruit, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("star", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.usedArcaneCrystal = num != 0;
players[0].SendData(PacketTypes.PlayerInfo, "", players[0].Index);
players[0].SendMessage(GetString("您的奥术水晶增益开启状态:") + players[0].TPlayer.usedArcaneCrystal, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("pearl", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.usedGalaxyPearl = num != 0;
players[0].SendData(PacketTypes.PlayerInfo, "", players[0].Index);
players[0].SendMessage(GetString("您的银河珍珠增益开启状态:") + players[0].TPlayer.usedGalaxyPearl, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("worm", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.usedGummyWorm = num != 0;
players[0].SendData(PacketTypes.PlayerInfo, "", players[0].Index);
players[0].SendMessage(GetString("您的粘性蠕虫增益开启状态:") + players[0].TPlayer.usedGummyWorm, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("ambrosia", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.usedAmbrosia = num != 0;
players[0].SendData(PacketTypes.PlayerInfo, "", players[0].Index);
players[0].SendMessage(GetString("您的珍馐增益开启状态:") + players[0].TPlayer.usedAmbrosia, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("cart", StringComparison.OrdinalIgnoreCase))
{
players[0].TPlayer.unlockedSuperCart = num != 0;
players[0].SendData(PacketTypes.PlayerInfo, "", players[0].Index);
players[0].SendMessage(GetString("您的超级矿车增益开启状态:") + players[0].TPlayer.unlockedSuperCart, new Color(0, 255, 0));
}
else if (args.Parameters[1].Equals("all", StringComparison.OrdinalIgnoreCase))
{
if (num == 1)
{
players[0].TPlayer.unlockedBiomeTorches = true;
players[0].TPlayer.extraAccessory = true;
players[0].TPlayer.ateArtisanBread = true;
players[0].TPlayer.usedAegisCrystal = true;
players[0].TPlayer.usedAegisFruit = true;
players[0].TPlayer.usedArcaneCrystal = true;
players[0].TPlayer.usedGalaxyPearl = true;
players[0].TPlayer.usedGummyWorm = true;
players[0].TPlayer.usedAmbrosia = true;
players[0].TPlayer.unlockedSuperCart = true;
players[0].SendData(PacketTypes.PlayerInfo, "", players[0].Index);
players[0].SendMessage(GetString("您的所有永久增益均开启"), new Color(0, 255, 0));
}
else if (num == 0)
{
players[0].TPlayer.unlockedBiomeTorches = false;
players[0].TPlayer.extraAccessory = false;
players[0].TPlayer.ateArtisanBread = false;
players[0].TPlayer.usedAegisCrystal = false;
players[0].TPlayer.usedAegisFruit = false;
players[0].TPlayer.usedArcaneCrystal = false;
players[0].TPlayer.usedGalaxyPearl = false;
players[0].TPlayer.usedGummyWorm = false;
players[0].TPlayer.usedAmbrosia = false;
players[0].TPlayer.unlockedSuperCart = false;
players[0].SendData(PacketTypes.PlayerInfo, "", players[0].Index);
players[0].SendMessage(GetString("您的所有永久增益均关闭"), new Color(0, 255, 0));
}
else
{
args.Player.SendInfoMessage(GetString("格式错误!输入 /zmodify help 查看修改玩家数据的指令帮助"));
}
}
args.Player.SendMessage(GetString("修改成功!"), new Color(0, 255, 0));
}
//不在线,修改离线数据
else if (players.Count == 0)
{
args.Player.SendInfoMessage(this.offlineplayer);
var user = TShock.UserAccounts.GetUserAccountByName(args.Parameters[0]);
if (user == null)
{
var users = TShock.UserAccounts.GetUserAccountsByName(args.Parameters[0], true);
if (users.Count == 0)
{
args.Player.SendInfoMessage(this.noplayer);
return;
}
if (users.Count > 1)
{
args.Player.SendInfoMessage(this.manyplayer);
return;
}
user = users[0];
}
try
{
if (args.Parameters[1].Equals("life", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET Health = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("lifemax", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET MaxHealth= @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("mana", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET Mana = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("manamax", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET MaxMana = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("fish", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET questsCompleted = @0 WHERE Account = @1;", num, user.ID);
}
else if (config.EnablePointTracking && args.Parameters[1].Equals("point", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE Zhipm_PlayerExtra SET point = @0 WHERE Account = @1;", num, user.ID);
}
else if (num != 0 && num != 1)
{
args.Player.SendInfoMessage(GetString("格式错误!输入 /zmodify help 查看修改玩家数据的指令帮助"));
return;
}
else if (args.Parameters[1].Equals("torch", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET unlockedBiomeTorches = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("demmon", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET extraSlot = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("bread", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET ateArtisanBread = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("crystal", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET usedAegisCrystal = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("fruit", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET usedAegisFruit = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("arcane", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET usedArcaneCrystal = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("pearl", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET usedGalaxyPearl = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("worm", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET usedGummyWorm = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("ambrosia", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET usedAmbrosia = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("cart", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET unlockedSuperCart = @0 WHERE Account = @1;", num, user.ID);
}
else if (args.Parameters[1].Equals("all", StringComparison.OrdinalIgnoreCase))
{
TShock.DB.Query("UPDATE tsCharacter SET unlockedBiomeTorches = @1, extraSlot = @2, ateArtisanBread = @3, usedAegisCrystal = @4, usedAegisFruit = @5, usedArcaneCrystal = @6, usedGalaxyPearl = @7, usedGummyWorm = @8, usedAmbrosia = @9, unlockedSuperCart = @10 WHERE Account = @0;", user.ID, num, num, num, num, num, num, num, num, num, num);
}
args.Player.SendMessage(GetString("修改成功!"), new Color(0, 255, 0));
}
catch (Exception ex)
{
args.Player.SendMessage(GetString("修改失败!错误:") + ex, new Color(255, 0, 0));
TShock.Log.Error(GetString("修改失败!错误:") + ex);
}
}
}
}
/// <summary>
/// 重置用户备份数据库方法指令
/// </summary>
/// <param name="args"></param>
private void ZResetPlayerDB(CommandArgs args)
{
if (args.Parameters.Count != 1)
{
args.Player.SendInfoMessage(GetString("输入 /zresetdb [name] 来清理该玩家的备份数据\n输入 /zresetdb all 来清理所有玩家的备份数据"));
return;
}
if (args.Parameters[0].Equals("all", StringComparison.OrdinalIgnoreCase))
{
if (ZPDataBase.ClearALLZPlayerDB(ZPDataBase))
{
if (!args.Player.IsLoggedIn)
{
args.Player.SendMessage(GetString("所有玩家的备份数据均已重置"), broadcastColor);
TSPlayer.All.SendMessage(GetString("所有玩家的备份数据均已重置"), broadcastColor);
}
else
{
TSPlayer.All.SendMessage(GetString("所有玩家的备份数据均已重置"), broadcastColor);
}
}
else
{
args.Player.SendMessage(GetString("重置失败"), new Color(255, 0, 0));
}
}
else
{
var list = this.BestFindPlayerByNameOrIndex(args.Parameters[0]);
if (list.Count > 1)
{
args.Player.SendInfoMessage(this.manyplayer);
return;
}
if (list.Count == 1)
{
if (ZPDataBase.ClearZPlayerDB(list[0].Account.ID))
{
args.Player.SendMessage(GetString($"已重置玩家 [ {list[0].Name} ] 的备份数据"), new Color(0, 255, 0));
list[0].SendMessage(GetString("您的备份数据已重置"), broadcastColor);
}
else
{
args.Player.SendMessage(GetString("重置失败"), new Color(255, 0, 0));
}
return;
}
if (list.Count == 0)
{
args.Player.SendInfoMessage(this.offlineplayer);
var user = TShock.UserAccounts.GetUserAccountByName(args.Parameters[0]);
if (user == null)
{
args.Player.SendMessage(this.noplayer, new Color(255, 0, 0));
}
else
{
if (ZPDataBase.ClearZPlayerDB(user.ID))
{
args.Player.SendMessage(GetString($"已重置离线玩家 [ {user.Name} ] 的备份数据"), new Color(0, 255, 0));
}
else
{
args.Player.SendMessage(GetString("重置失败"), new Color(255, 0, 0));
}
}
}
}
}