-
Notifications
You must be signed in to change notification settings - Fork 4
/
ZHIPM.Utils.cs
1719 lines (1664 loc) · 87.4 KB
/
ZHIPM.Utils.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.Security.Cryptography;
using System.Text;
using Terraria;
using Terraria.IO;
using Terraria.Localization;
using TerrariaApi.Server;
using TShockAPI;
using TShockAPI.DB;
namespace ZHIPlayerManager
{
public partial class ZHIPM : TerrariaPlugin
{
/// <summary>
/// 同步玩家的人物数据数据,线上类型,仅同步在线玩家,在内存中的数据
/// </summary>
/// <param name="p">你要被同步的玩家</param>
/// <param name="pd">赋值给他的数据</param>
/// <returns></returns>
public bool UpdatePlayerAll(TSPlayer p, PlayerData pd)
{
if (pd == null || !pd.exists)
{
return false;
}
//正常同步
if (pd.currentLoadoutIndex == p.TPlayer.CurrentLoadoutIndex)
{
for (int i = 0; i < NetItem.MaxInventory; i++)
{
if (i < NetItem.InventoryIndex.Item2)
{
p.TPlayer.inventory[i] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.inventory[i].stack = pd.inventory[i].Stack;
p.TPlayer.inventory[i].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.ArmorIndex.Item2)
{
int num = i - NetItem.ArmorIndex.Item1;
p.TPlayer.armor[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.armor[num].stack = pd.inventory[i].Stack;
p.TPlayer.armor[num].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.DyeIndex.Item2)
{
int num2 = i - NetItem.DyeIndex.Item1;
p.TPlayer.dye[num2] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.dye[num2].stack = pd.inventory[i].Stack;
p.TPlayer.dye[num2].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.MiscEquipIndex.Item2)
{
int num3 = i - NetItem.MiscEquipIndex.Item1;
p.TPlayer.miscEquips[num3] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.miscEquips[num3].stack = pd.inventory[i].Stack;
p.TPlayer.miscEquips[num3].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.MiscDyeIndex.Item2)
{
int num4 = i - NetItem.MiscDyeIndex.Item1;
p.TPlayer.miscDyes[num4] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.miscDyes[num4].stack = pd.inventory[i].Stack;
p.TPlayer.miscDyes[num4].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.PiggyIndex.Item2)
{
int num5 = i - NetItem.PiggyIndex.Item1;
p.TPlayer.bank.item[num5] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.bank.item[num5].stack = pd.inventory[i].Stack;
p.TPlayer.bank.item[num5].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.SafeIndex.Item2)
{
int num6 = i - NetItem.SafeIndex.Item1;
p.TPlayer.bank2.item[num6] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.bank2.item[num6].stack = pd.inventory[i].Stack;
p.TPlayer.bank2.item[num6].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.TrashIndex.Item2)
{
p.TPlayer.trashItem = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.trashItem.stack = pd.inventory[i].Stack;
p.TPlayer.trashItem.prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.ForgeIndex.Item2)
{
int num7 = i - NetItem.ForgeIndex.Item1;
p.TPlayer.bank3.item[num7] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.bank3.item[num7].stack = pd.inventory[i].Stack;
p.TPlayer.bank3.item[num7].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.VoidIndex.Item2)
{
int num8 = i - NetItem.VoidIndex.Item1;
p.TPlayer.bank4.item[num8] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.bank4.item[num8].stack = pd.inventory[i].Stack;
p.TPlayer.bank4.item[num8].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.Loadout1Armor.Item2)
{
int num9 = i - NetItem.Loadout1Armor.Item1;
p.TPlayer.Loadouts[0].Armor[num9] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[0].Armor[num9].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[0].Armor[num9].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.Loadout1Dye.Item2)
{
int num10 = i - NetItem.Loadout1Dye.Item1;
p.TPlayer.Loadouts[0].Dye[num10] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[0].Dye[num10].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[0].Dye[num10].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.Loadout2Armor.Item2)
{
int num11 = i - NetItem.Loadout2Armor.Item1;
p.TPlayer.Loadouts[1].Armor[num11] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[1].Armor[num11].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[1].Armor[num11].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.Loadout2Dye.Item2)
{
int num12 = i - NetItem.Loadout2Dye.Item1;
p.TPlayer.Loadouts[1].Dye[num12] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[1].Dye[num12].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[1].Dye[num12].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.Loadout3Armor.Item2)
{
int num13 = i - NetItem.Loadout3Armor.Item1;
p.TPlayer.Loadouts[2].Armor[num13] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[2].Armor[num13].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[2].Armor[num13].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.Loadout3Dye.Item2)
{
int num14 = i - NetItem.Loadout3Dye.Item1;
p.TPlayer.Loadouts[2].Dye[num14] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[2].Dye[num14].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[2].Dye[num14].prefix = pd.inventory[i].PrefixId;
}
p.SendData(PacketTypes.PlayerSlot, "", p.Index, i, pd.inventory[i].PrefixId, 0f, 0);
}
}
//异常同步
else
{
int notselected = 0;
for (int i = 0; i < 3; i++)
{
if (p.TPlayer.CurrentLoadoutIndex != i && pd.currentLoadoutIndex != i)
{
notselected = i;
}
}
for (int i = 0; i < NetItem.MaxInventory; i++)
{
if (i < NetItem.InventoryIndex.Item2)
{
p.TPlayer.inventory[i] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.inventory[i].stack = pd.inventory[i].Stack;
p.TPlayer.inventory[i].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.ArmorIndex.Item2)
{
int num = i - NetItem.ArmorIndex.Item1;
p.TPlayer.Loadouts[pd.currentLoadoutIndex].Armor[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[pd.currentLoadoutIndex].Armor[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[pd.currentLoadoutIndex].Armor[num].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.DyeIndex.Item2)
{
int num = i - NetItem.DyeIndex.Item1;
p.TPlayer.Loadouts[pd.currentLoadoutIndex].Dye[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[pd.currentLoadoutIndex].Dye[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[pd.currentLoadoutIndex].Dye[num].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.MiscEquipIndex.Item2)
{
int num = i - NetItem.MiscEquipIndex.Item1;
p.TPlayer.miscEquips[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.miscEquips[num].stack = pd.inventory[i].Stack;
p.TPlayer.miscEquips[num].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.MiscDyeIndex.Item2)
{
int num = i - NetItem.MiscDyeIndex.Item1;
p.TPlayer.miscDyes[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.miscDyes[num].stack = pd.inventory[i].Stack;
p.TPlayer.miscDyes[num].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.PiggyIndex.Item2)
{
int num = i - NetItem.PiggyIndex.Item1;
p.TPlayer.bank.item[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.bank.item[num].stack = pd.inventory[i].Stack;
p.TPlayer.bank.item[num].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.SafeIndex.Item2)
{
int num = i - NetItem.SafeIndex.Item1;
p.TPlayer.bank2.item[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.bank2.item[num].stack = pd.inventory[i].Stack;
p.TPlayer.bank2.item[num].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.TrashIndex.Item2)
{
p.TPlayer.trashItem = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.trashItem.stack = pd.inventory[i].Stack;
p.TPlayer.trashItem.prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.ForgeIndex.Item2)
{
int num = i - NetItem.ForgeIndex.Item1;
p.TPlayer.bank3.item[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.bank3.item[num].stack = pd.inventory[i].Stack;
p.TPlayer.bank3.item[num].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.VoidIndex.Item2)
{
int num = i - NetItem.VoidIndex.Item1;
p.TPlayer.bank4.item[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.bank4.item[num].stack = pd.inventory[i].Stack;
p.TPlayer.bank4.item[num].prefix = pd.inventory[i].PrefixId;
}
else if (i < NetItem.Loadout1Armor.Item2)
{
int num = i - NetItem.Loadout1Armor.Item1;
if (pd.currentLoadoutIndex != 0)
{
if (notselected == 0)
{
p.TPlayer.Loadouts[0].Armor[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[0].Armor[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[0].Armor[num].prefix = pd.inventory[i].PrefixId;
}
else if (p.TPlayer.CurrentLoadoutIndex != 0)
{
p.TPlayer.Loadouts[0].Armor[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[0].Armor[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[0].Armor[num].prefix = pd.inventory[i].PrefixId;
}
else
{
p.TPlayer.Loadouts[0].Armor[num].TurnToAir(false);
p.TPlayer.armor[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.armor[num].stack = pd.inventory[i].Stack;
p.TPlayer.armor[num].prefix = pd.inventory[i].PrefixId;
}
}
}
else if (i < NetItem.Loadout1Dye.Item2)
{
int num = i - NetItem.Loadout1Dye.Item1;
if (pd.currentLoadoutIndex != 0)
{
if (notselected == 0)
{
p.TPlayer.Loadouts[0].Dye[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[0].Dye[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[0].Dye[num].prefix = pd.inventory[i].PrefixId;
}
else if (p.TPlayer.CurrentLoadoutIndex != 0)
{
p.TPlayer.Loadouts[0].Dye[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[0].Dye[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[0].Dye[num].prefix = pd.inventory[i].PrefixId;
}
else
{
p.TPlayer.Loadouts[0].Dye[num].TurnToAir(false);
p.TPlayer.dye[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.dye[num].stack = pd.inventory[i].Stack;
p.TPlayer.dye[num].prefix = pd.inventory[i].PrefixId;
}
}
}
else if (i < NetItem.Loadout2Armor.Item2)
{
int num = i - NetItem.Loadout2Armor.Item1;
if (pd.currentLoadoutIndex != 1)
{
if (notselected == 1)
{
p.TPlayer.Loadouts[1].Armor[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[1].Armor[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[1].Armor[num].prefix = pd.inventory[i].PrefixId;
}
else if (p.TPlayer.CurrentLoadoutIndex != 1)
{
p.TPlayer.Loadouts[1].Armor[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[1].Armor[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[1].Armor[num].prefix = pd.inventory[i].PrefixId;
}
else
{
p.TPlayer.Loadouts[1].Armor[num].TurnToAir(false);
p.TPlayer.armor[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.armor[num].stack = pd.inventory[i].Stack;
p.TPlayer.armor[num].prefix = pd.inventory[i].PrefixId;
}
}
}
else if (i < NetItem.Loadout2Dye.Item2)
{
int num = i - NetItem.Loadout2Dye.Item1;
if (pd.currentLoadoutIndex != 1)
{
if (notselected == 1)
{
p.TPlayer.Loadouts[1].Dye[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[1].Dye[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[1].Dye[num].prefix = pd.inventory[i].PrefixId;
}
else if (p.TPlayer.CurrentLoadoutIndex != 1)
{
p.TPlayer.Loadouts[1].Dye[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[1].Dye[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[1].Dye[num].prefix = pd.inventory[i].PrefixId;
}
else
{
p.TPlayer.Loadouts[1].Dye[num].TurnToAir(false);
p.TPlayer.dye[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.dye[num].stack = pd.inventory[i].Stack;
p.TPlayer.dye[num].prefix = pd.inventory[i].PrefixId;
}
}
}
else if (i < NetItem.Loadout3Armor.Item2)
{
int num = i - NetItem.Loadout3Armor.Item1;
if (pd.currentLoadoutIndex != 2)
{
if (notselected == 2)
{
p.TPlayer.Loadouts[2].Armor[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[2].Armor[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[2].Armor[num].prefix = pd.inventory[i].PrefixId;
}
else
{
if (p.TPlayer.CurrentLoadoutIndex != 2)
{
p.TPlayer.Loadouts[2].Armor[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[2].Armor[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[2].Armor[num].prefix = pd.inventory[i].PrefixId;
}
else
{
p.TPlayer.Loadouts[2].Armor[num].TurnToAir(false);
p.TPlayer.armor[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.armor[num].stack = pd.inventory[i].Stack;
p.TPlayer.armor[num].prefix = pd.inventory[i].PrefixId;
}
}
}
}
else if (i < NetItem.Loadout3Dye.Item2)
{
int num = i - NetItem.Loadout3Dye.Item1;
if (pd.currentLoadoutIndex != 2)
{
if (notselected == 2)
{
p.TPlayer.Loadouts[2].Dye[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[2].Dye[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[2].Dye[num].prefix = pd.inventory[i].PrefixId;
}
else if (p.TPlayer.CurrentLoadoutIndex != 2)
{
p.TPlayer.Loadouts[2].Dye[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.Loadouts[2].Dye[num].stack = pd.inventory[i].Stack;
p.TPlayer.Loadouts[2].Dye[num].prefix = pd.inventory[i].PrefixId;
}
else
{
p.TPlayer.Loadouts[2].Dye[num].TurnToAir(false);
p.TPlayer.dye[num] = TShock.Utils.GetItemById(pd.inventory[i].NetId);
p.TPlayer.dye[num].stack = pd.inventory[i].Stack;
p.TPlayer.dye[num].prefix = pd.inventory[i].PrefixId;
}
}
}
}
for (int i = 0; i < NetItem.MaxInventory; i++)
{
p.SendData(PacketTypes.PlayerSlot, "", p.Index, i, pd.inventory[i].PrefixId, 0f, 0);
}
}
p.TPlayer.statLife = pd.health;
p.TPlayer.statLifeMax = pd.maxHealth;
p.TPlayer.statMana = pd.mana;
p.TPlayer.statManaMax = pd.maxMana;
p.TPlayer.extraAccessory = pd.extraSlot == 1 ? true : false;
p.TPlayer.skinVariant = pd.skinVariant.Value;
p.TPlayer.hair = pd.hair.Value;
p.TPlayer.hairDye = pd.hairDye;
p.TPlayer.hairColor = pd.hairColor.Value;
p.TPlayer.pantsColor = pd.pantsColor.Value;
p.TPlayer.shirtColor = pd.shirtColor.Value;
p.TPlayer.underShirtColor = pd.underShirtColor.Value;
p.TPlayer.shoeColor = pd.shoeColor.Value;
p.TPlayer.hideVisibleAccessory = pd.hideVisuals;
p.TPlayer.skinColor = pd.skinColor.Value;
p.TPlayer.eyeColor = pd.eyeColor.Value;
p.TPlayer.anglerQuestsFinished = pd.questsCompleted;
p.TPlayer.UsingBiomeTorches = (pd.usingBiomeTorches == 1);
p.TPlayer.happyFunTorchTime = (pd.happyFunTorchTime == 1);
p.TPlayer.unlockedBiomeTorches = (pd.unlockedBiomeTorches == 1);
p.TPlayer.ateArtisanBread = (pd.ateArtisanBread == 1);
p.TPlayer.usedAegisCrystal = (pd.usedAegisCrystal == 1);
p.TPlayer.usedAegisFruit = (pd.usedAegisFruit == 1);
p.TPlayer.usedAegisCrystal = (pd.usedArcaneCrystal == 1);
p.TPlayer.usedGalaxyPearl = (pd.usedGalaxyPearl == 1);
p.TPlayer.usedGummyWorm = (pd.usedGummyWorm == 1);
p.TPlayer.usedAmbrosia = (pd.usedAmbrosia == 1);
p.TPlayer.unlockedSuperCart = (pd.unlockedSuperCart == 1);
p.TPlayer.enabledSuperCart = (pd.enabledSuperCart == 1);
//玩家衣服服装,银河珍珠等属性的同步
p.SendData(PacketTypes.PlayerInfo, "", p.Index, 0f, 0f, 0f, 0);
//生命值同步,包含最大值上限
p.SendData(PacketTypes.PlayerHp, "", p.Index, 0f, 0f, 0f, 0);
//魔力值同步,包括上限
p.SendData(PacketTypes.PlayerMana, "", p.Index, 0f, 0f, 0f, 0);
//钓鱼完成任务数目
p.SendData(PacketTypes.NumberOfAnglerQuestsCompleted, "", p.Index, 0f, 0f, 0f, 0);
//清空玩家的buff
clearAllBuffFromPlayer(p);
return true;
}
/// <summary>
/// 更新玩家的人物属性数据,线下更新类型,写入数据库,不是更新在线的操作
/// </summary>
/// <param name="accid"></param>
/// <param name="pd"></param>
/// <returns></returns>
public bool UpdateTshockDBCharac(int accid, PlayerData pd)
{
if (pd == null || !pd.exists)
{
return false;
}
try
{
PlayerData temp = TShock.CharacterDB.GetPlayerData(new TSPlayer(-1), accid);
if (temp != null && temp.exists)
{
TShock.DB.Query("UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4, spawnX = @6, spawnY = @7, hair = @8, hairDye = @9, hairColor = @10, pantsColor = @11, shirtColor = @12, underShirtColor = @13, shoeColor = @14, hideVisuals = @15, skinColor = @16, eyeColor = @17, questsCompleted = @18, skinVariant = @19, extraSlot = @20, usingBiomeTorches = @21, happyFunTorchTime = @22, unlockedBiomeTorches = @23, currentLoadoutIndex = @24, ateArtisanBread = @25, usedAegisCrystal = @26, usedAegisFruit = @27, usedArcaneCrystal = @28, usedGalaxyPearl = @29, usedGummyWorm = @30, usedAmbrosia = @31, unlockedSuperCart = @32, enabledSuperCart = @33 WHERE Account = @5;", new object[]
{
pd.health,
pd.maxHealth,
pd.mana,
pd.maxMana,
string.Join<NetItem>("~", pd.inventory),
accid,
pd.spawnX,
pd.spawnY,
pd.hair,
pd.hairDye,
TShock.Utils.EncodeColor(pd.hairColor),
TShock.Utils.EncodeColor(pd.pantsColor),
TShock.Utils.EncodeColor(pd.shirtColor),
TShock.Utils.EncodeColor(pd.underShirtColor),
TShock.Utils.EncodeColor(pd.shoeColor),
TShock.Utils.EncodeBoolArray(pd.hideVisuals),
TShock.Utils.EncodeColor(pd.skinColor),
TShock.Utils.EncodeColor(pd.eyeColor),
pd.questsCompleted,
pd.skinVariant,
pd.extraSlot,
pd.usingBiomeTorches,
pd.happyFunTorchTime,
pd.unlockedBiomeTorches,
pd.currentLoadoutIndex,
pd.ateArtisanBread,
pd.usedAegisCrystal,
pd.usedAegisFruit,
pd.usedArcaneCrystal,
pd.usedGalaxyPearl,
pd.usedGummyWorm,
pd.usedAmbrosia,
pd.unlockedSuperCart,
pd.enabledSuperCart
});
}
return true;
}
catch (Exception ex)
{
TShock.Log.Error("错误:UpdateTshockDBCharac " + ex.ToString());
Console.WriteLine("错误:UpdateTshockDBCharac " + ex.ToString());
return false;
}
}
/// <summary>
/// 在线重置一个玩家的人物数据,离线自己删数据库去
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public bool ResetPlayer(TSPlayer p)
{
if (p == null || !p.IsLoggedIn)
{
return false;
}
try
{
p.TPlayer.statLife = TShock.ServerSideCharacterConfig.Settings.StartingHealth;
p.TPlayer.statLifeMax = TShock.ServerSideCharacterConfig.Settings.StartingHealth;
p.TPlayer.statMana = TShock.ServerSideCharacterConfig.Settings.StartingMana;
p.TPlayer.statManaMax = TShock.ServerSideCharacterConfig.Settings.StartingMana;
//完全清理背包
for (int i = 0; i < NetItem.MaxInventory; i++)
{
if (i < NetItem.InventoryIndex.Item2)
{
p.TPlayer.inventory[i].TurnToAir();
}
else if (i < NetItem.ArmorIndex.Item2)
{
int num = i - NetItem.ArmorIndex.Item1;
p.TPlayer.armor[num].TurnToAir();
}
else if (i < NetItem.DyeIndex.Item2)
{
int num = i - NetItem.DyeIndex.Item1;
p.TPlayer.dye[num].TurnToAir();
}
else if (i < NetItem.MiscEquipIndex.Item2)
{
int num = i - NetItem.MiscEquipIndex.Item1;
p.TPlayer.miscEquips[num].TurnToAir();
}
else if (i < NetItem.MiscDyeIndex.Item2)
{
int num = i - NetItem.MiscDyeIndex.Item1;
p.TPlayer.miscDyes[num].TurnToAir();
}
else if (i < NetItem.PiggyIndex.Item2)
{
int num = i - NetItem.PiggyIndex.Item1;
p.TPlayer.bank.item[num].TurnToAir();
}
else if (i < NetItem.SafeIndex.Item2)
{
int num = i - NetItem.SafeIndex.Item1;
p.TPlayer.bank2.item[num].TurnToAir();
}
else if (i < NetItem.TrashIndex.Item2)
{
p.TPlayer.trashItem.TurnToAir();
}
else if (i < NetItem.ForgeIndex.Item2)
{
int num = i - NetItem.ForgeIndex.Item1;
p.TPlayer.bank3.item[num].TurnToAir();
}
else if (i < NetItem.VoidIndex.Item2)
{
int num = i - NetItem.VoidIndex.Item1;
p.TPlayer.bank4.item[num].TurnToAir();
}
else if (i < NetItem.Loadout1Armor.Item2)
{
int num = i - NetItem.Loadout1Armor.Item1;
p.TPlayer.Loadouts[0].Armor[num].TurnToAir();
}
else if (i < NetItem.Loadout1Dye.Item2)
{
int num = i - NetItem.Loadout1Dye.Item1;
p.TPlayer.Loadouts[0].Dye[num].TurnToAir();
}
else if (i < NetItem.Loadout2Armor.Item2)
{
int num = i - NetItem.Loadout2Armor.Item1;
p.TPlayer.Loadouts[1].Armor[num].TurnToAir();
}
else if (i < NetItem.Loadout2Dye.Item2)
{
int num = i - NetItem.Loadout2Dye.Item1;
p.TPlayer.Loadouts[1].Dye[num].TurnToAir();
}
else if (i < NetItem.Loadout3Armor.Item2)
{
int num = i - NetItem.Loadout3Armor.Item1;
p.TPlayer.Loadouts[2].Armor[num].TurnToAir();
}
else if (i < NetItem.Loadout3Dye.Item2)
{
int num = i - NetItem.Loadout3Dye.Item1;
p.TPlayer.Loadouts[2].Dye[num].TurnToAir();
}
p.SendData(PacketTypes.PlayerSlot, "", p.Index, i);
}
//按照ssconfig的配置进行重置
for (int i = 0; i < NetItem.MaxInventory; i++)
{
if (i < NetItem.InventoryIndex.Item2 && i < TShock.ServerSideCharacterConfig.Settings.StartingInventory.Count && TShock.ServerSideCharacterConfig.Settings.StartingInventory[i].NetId != 0)
{
p.TPlayer.inventory[i] = TShock.Utils.GetItemById(TShock.ServerSideCharacterConfig.Settings.StartingInventory[i].NetId);
p.TPlayer.inventory[i].stack = TShock.ServerSideCharacterConfig.Settings.StartingInventory[i].Stack;
p.TPlayer.inventory[i].prefix = TShock.ServerSideCharacterConfig.Settings.StartingInventory[i].PrefixId;
p.SendData(PacketTypes.PlayerSlot, "", p.Index, i, p.TPlayer.inventory[i].prefix, 0f, 0);
}
}
p.TPlayer.unlockedBiomeTorches = false;
p.TPlayer.extraAccessory = false;
p.TPlayer.ateArtisanBread = false;
p.TPlayer.usedAegisCrystal = false;
p.TPlayer.usedAegisFruit = false;
p.TPlayer.usedArcaneCrystal = false;
p.TPlayer.usedGalaxyPearl = false;
p.TPlayer.usedGummyWorm = false;
p.TPlayer.usedAmbrosia = false;
p.TPlayer.unlockedSuperCart = false;
p.SendData(PacketTypes.PlayerInfo, "", p.Index, 0f, 0f, 0f, 0);
p.SendData(PacketTypes.PlayerHp, "", p.Index, 0f, 0f, 0f, 0);
p.SendData(PacketTypes.PlayerMana, "", p.Index, 0f, 0f, 0f, 0);
p.TPlayer.anglerQuestsFinished = 0;
p.SendData(PacketTypes.NumberOfAnglerQuestsCompleted, "", p.Index, 0f, 0f, 0f, 0);
//清理所有buff
clearAllBuffFromPlayer(p);
return true;
}
catch (Exception ex)
{
TShock.Log.Error("错误 ResetPlayer :" + ex.ToString());
Console.WriteLine("错误 ResetPlayer :" + ex.ToString());
return false;
}
}
/// <summary>
/// 返回玩家身上物品的字符串,一般情况slot = items.length
/// </summary>
/// <param name="items"></param>
/// <param name="slots"></param>
/// <param name="Model">0 返回图标文本,1 返回纯文本</param>
/// <returns></returns>
public static string GetItemsString(Item[] items, int slots, int Model = 0)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < slots; i++)
{
Item item = items[i];
if (Model == 0 && !item.IsAir)
{
if (item.prefix != 0)
sb.Append(string.Format("【[i/p{0}:{1}]】 ", item.prefix, item.netID));
else
sb.Append(string.Format("【[i/s{0}:{1}]】 ", item.stack, item.netID));
}
if (Model == 1 && !item.IsAir)
{
if (item.prefix != 0)
sb.Append($"[{Lang.prefix[item.prefix].Value}.{item.Name}]");
else if (item.stack != 1)
sb.Append($"[{item.Name}:{item.stack}]");
else
sb.Append($"[{item.Name}]");
}
}
return sb.ToString();
}
/// <summary>
/// 返回离线玩家身上的字符串,一般情况slot = items.length
/// </summary>
/// <param name="items"></param>
/// <param name="slots"></param>
/// <param name="Model">0 返回图标文本,1 返回纯文本</param>
/// <returns></returns>
public static string GetItemsString(NetItem[] items, int slots, int Model = 0)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < slots; i++)
{
NetItem item = items[i];
if (Model == 0 && item.NetId != 0)
{
if (item.PrefixId != 0)
sb.Append(string.Format("【[i/p{0}:{1}]】 ", item.PrefixId, item.NetId));
else
sb.Append(string.Format("【[i/s{0}:{1}]】 ", item.Stack, item.NetId));
}
if (Model == 1 && item.NetId != 0)
{
if (item.PrefixId != 0)
sb.Append($"[{Lang.prefix[item.PrefixId].Value}.{Lang.GetItemName(item.NetId)}]");
else if (item.Stack != 1)
sb.Append($"[{Lang.GetItemName(item.NetId)}:{item.Stack}]");
else
sb.Append($"[{Lang.GetItemName(item.NetId)}]");
}
}
return sb.ToString();
}
/// <summary>
/// 给出一个字符串和每行几个物品数,返回排列好的字符串,按空格进行分割
/// </summary>
/// <param name="str"> 需要排列的文本 </param>
/// <param name="num"> 一行几个 </param>
/// <param name="block"> </param>
/// <returns></returns>
public static string FormatArrangement(string str, int num, string block = "")
{
if (!string.IsNullOrWhiteSpace(str))
{
List<string> ls = str.Split(' ').ToList();
for (int i = 0; i < ls.Count; i++)
{
if ((i + 1) % (num + 1) == 0)
{
ls.Insert(i, "\n");
}
}
if (block == "")
return string.Join(block, ls);
else
{
StringBuilder sb = new StringBuilder();
foreach (string s in ls)
{
if (s != "\n")
{
sb.Append(s);
sb.Append(block);
}
else
{
sb.AppendLine();
}
}
return sb.ToString();
}
}
else
{
return "";
}
}
/// <summary>
/// 返回随机好看的颜色
/// </summary>
/// <returns></returns>
public static Color TextColor()
{
int r, g, b;
r = Main.rand.Next(60, 255);
g = Main.rand.Next(60, 255);
b = Main.rand.Next(60, 255);
return new Color(r, g, b);
}
/// <summary>
/// 仅仅是回档指令的函数分出的方法,无特殊意义
/// </summary>
/// <param name="args"></param>
/// <param name="slot"></param>
public void MySSCBack2(CommandArgs args, int slot)
{
List<TSPlayer> list = BestFindPlayerByNameOrIndex(args.Parameters[0]);
if (list.Count > 1)
{
args.Player.SendInfoMessage("检测到符合该条件的玩家数目不唯一,请重新输入");
return;
}
//离线回档
if (list.Count == 0)
{
args.Player.SendInfoMessage(offlineplayer);
UserAccount user = TShock.UserAccounts.GetUserAccountByName(args.Parameters[0]);
if (user == null)
{
args.Player.SendInfoMessage(noplayer);
}
else
{
PlayerData playerData = TShock.CharacterDB.GetPlayerData(new TSPlayer(-1), user.ID);
if (playerData == null || !playerData.exists)
{
args.Player.SendInfoMessage("未在原数据库中查到该玩家,请检查输入是否正确,该玩家是否避免SSC检测,再重新输入");
}
else
{
try
{
PlayerData playerData2 = ZPDataBase.ReadZPlayerDB(new TSPlayer(-1), user.ID, slot);
if (playerData2 == null || !playerData2.exists)
{
args.Player.SendMessage("回档失败!未找到 [" + user.ID + "-" + slot + "] 号该备份", new Color(255, 0, 0));
}
else
{
if (UpdateTshockDBCharac(user.ID, playerData2))
{
args.Player.SendMessage($"玩家 [{user.Name}] 回档成功!启用备份 [ {user.ID.ToString() + "-" + slot} ]", new Color(0, 255, 0));
}
else
{
args.Player.SendMessage("回档失败!", new Color(255, 0, 0));
}
}
}
catch (Exception ex)
{
TShock.Log.Error("错误:BackUp " + ex.ToString());
args.Player.SendErrorMessage("错误:BackUp " + ex.ToString());
Console.WriteLine("错误:BackUp " + ex.ToString());
}
}
}
return;
}
//在线回档
if (list.Count == 1)
{
//如果这个人不是管理(无ssc避免),需要同步在线属性UpdatePlayerAll,并且需要原版数据库写入更新才算成功
if (!list[0].HasPermission(Permissions.bypassssc) && UpdatePlayerAll(list[0], ZPDataBase.ReadZPlayerDB(list[0], list[0].Account.ID, slot)) && TShock.CharacterDB.InsertPlayerData(list[0], false))
{
if (args.Player.Index != list[0].Index)
{
args.Player.SendMessage($"玩家 [{list[0].Name}] 回档成功!启用备份 [ {list[0].Account.ID + "-" + slot} ]", new Color(0, 255, 0));
list[0].SendMessage("您已回档成功!", new Color(0, 255, 0));
}
else
{
args.Player.SendMessage($"玩家 [{list[0].Name}] 回档成功!启用备份 [ {list[0].Account.ID + "-" + slot} ]", new Color(0, 255, 0));
}
}
//如果他是管理,那就不用向原版数据写入了
else if (list[0].HasPermission(Permissions.bypassssc) && UpdatePlayerAll(list[0], ZPDataBase.ReadZPlayerDB(list[0], list[0].Account.ID, slot)))
{
if (args.Player.Index != list[0].Index)
{
args.Player.SendMessage($"玩家 [{list[0].Name}] 回档成功!启用备份 [ {list[0].Account.ID + "-" + slot} ]", new Color(0, 255, 0));
list[0].SendMessage("您已回档成功!", new Color(0, 255, 0));
}
else
{
args.Player.SendMessage($"玩家 [{list[0].Name}] 回档成功!启用备份 [ {list[0].Account.ID + "-" + slot} ]", new Color(0, 255, 0));
}
}
else
{
args.Player.SendMessage("回档失败!未备份数据或该玩家未登录", new Color(255, 0, 0));
}
}
}
/// <summary>
/// 将 long 秒数时间转化成 xx小时 xx分钟 xx秒 的字符串
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public string timetostring(long t)
{
long s = t % 60L;
long min = t / 60L;
long h = 0L;
if (min >= 60L)
{
h = min / 60L;
min %= 60L;
}
return $"{h}小时 {min}分钟 {s}秒";
}
/// <summary>
/// 将 long 硬币数转化成 xx铂 xx金 xx银 xx铜 的字符串
/// </summary>
/// <param name="coin"></param>
/// <param name="Model">0代表图标字符串,1代表纯文本</param>
/// <returns></returns>
public string cointostring(long coin, int Model = 0)
{
long copper = coin % 100; //71
coin /= 100;
long silver = coin % 100; //72
coin /= 100;
long gold = coin % 100; //72
coin /= 100;
long platinum = coin; //74
if (Model == 0)
{
return $"{platinum}[i:74] {gold}[i:73] {silver}[i:72] {copper}[i:71]";
}
else
{
return $"{platinum}铂金币 {gold}金币 {silver}银币 {copper}铜币";
}
}
/// <summary>
/// 将 50~1,1~25, 这种类型的 id~击杀数, 字符串转化成对应的字典集合
/// </summary>
/// <param name="killstring"></param>
/// <returns></returns>
public static Dictionary<int, int> killNPCStringToDictionary(string killstring)
{
if (string.IsNullOrWhiteSpace(killstring))
return new Dictionary<int, int>();
Dictionary<int, int> keyValues = new Dictionary<int, int>();
List<string> list1 = new List<string>(killstring.Split(','));
list1.RemoveAll(x => string.IsNullOrWhiteSpace(x));
foreach (string str in list1)
{
List<string> lst = new List<string>(str.Split('~'));
lst.RemoveAll(x => !int.TryParse(x, out int temp));
if (lst.Count == 2)
keyValues.Add(int.Parse(lst[0]), int.Parse(lst[1]));
}
return keyValues;
}
/// <summary>
/// 将字典集合转化成对应的 50~1,1~25, 这种类型的 id~击杀数, 字符串
/// </summary>
/// <param name="keyValues"></param>
/// <returns></returns>
public static string DictionaryToKillNPCString(Dictionary<int, int> keyValues)
{
StringBuilder sb = new StringBuilder();
foreach (var v in keyValues)
{
sb.Append(v.Key.ToString());
sb.Append('~');
sb.Append(v.Value.ToString());
sb.Append(',');
}
return sb.ToString();
}
/// <summary>
/// 将字典转化成 史莱姆王(2),金金鱼(12),宝箱怪(20) 这样的类型
/// </summary>
/// <param name="keyValues"> 数据 </param>
/// <param name="iswrap"> 是否自动换行 </param>
/// <returns></returns>
public static string DictionaryToVSString(Dictionary<int, int> keyValues, bool iswrap = true)
{
StringBuilder sb = new StringBuilder();
int coun = 0;
foreach (var v in keyValues)
{
coun++;
switch (v.Key)//处理一下特殊npc
{
case 592:
sb.Append($"蹦跶{Lang.GetNPCNameValue(v.Key)}({v.Value}),");
break;
case 593:
sb.Append($"游雨{Lang.GetNPCNameValue(v.Key)}({v.Value}),");
break;
case 564:
sb.Append($"T1{Lang.GetNPCNameValue(v.Key)}({v.Value}),");
break;
case 565:
sb.Append($"T3{Lang.GetNPCNameValue(v.Key)}({v.Value}),");
break;
case 576:
sb.Append($"T2{Lang.GetNPCNameValue(v.Key)}({v.Value}),");
break;
case 577:
sb.Append($"T3{Lang.GetNPCNameValue(v.Key)}({v.Value}),");
break;
case 398:
sb.Append("月亮领主(" + v.Value + ")");
break;
default:
sb.Append($"{Lang.GetNPCNameValue(v.Key)}({v.Value}),");
break;
}
if (coun % 10 == 0 && iswrap)//防止一行字数过多卡到屏幕边缘看不见了
sb.AppendLine();
}