-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathufrmvorrpg.pas
3455 lines (3039 loc) · 82.7 KB
/
ufrmvorrpg.pas
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
unit UFrmVorRpg;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, dateutils, Forms, Controls, Graphics, Dialogs, StdCtrls,
Buttons, ExtCtrls, ComCtrls, TaskManager, DbcEngine, DbcScript, Main;
type
{ TFrmVorRpg }
TFrmVorRpg = class(TForm)
BtnCancel: TBitBtn;
BtnOk: TBitBtn;
CBduelCheckZero: TCheckBox;
CBKickEnable: TCheckBox;
CBXchgEnable: TCheckBox;
CBVorRpgEnable: TCheckBox;
CBduelEnable: TCheckBox;
EdtBaseTime: TLabeledEdit;
EdtDebufMaxTime: TLabeledEdit;
EdtDebufMinTime: TLabeledEdit;
EdtDebufPerc: TLabeledEdit;
EdtKickIn: TLabeledEdit;
EdtDuelKd: TLabeledEdit;
EdtDuelMVipPerc: TLabeledEdit;
EdtXchgMaxCount: TLabeledEdit;
EdtKickOut: TLabeledEdit;
EdtKickPerc: TLabeledEdit;
EdtPercMinusVip: TLabeledEdit;
EdtTimeKd: TLabeledEdit;
EdtduelMaxCount: TLabeledEdit;
EdtXchgMaxTime: TLabeledEdit;
EdtduelMaxTime: TLabeledEdit;
PageCtrl: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
TabSheet5: TTabSheet;
procedure BtnOkClick(Sender:TObject);
procedure BtnCancelClick(Sender:TObject);
procedure BtnCancelKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender:TObject;var Key:Word;Shift:TShiftState);
procedure EdtPercMinusVipKeyPress(Sender:TObject;var Key:char);
procedure EdtPercMinusVipExit(Sender:TObject);
procedure EdtDwExit(Sender: TObject);
procedure EdtDwKeyPress(Sender:TObject;var Key:char);
private
prev_perc:Byte;
prev_dw:DWORD;
FClearTimer:TTimer;
public
Procedure rpg_theif_vip(const s,dst_user,msg:RawByteString);
procedure check_xchg_vip_time;
procedure add2xchgVip(const user,nick:RawByteString);
Procedure vip_time(const user:RawByteString);
procedure catch_vip(const user:RawByteString);
procedure check_duel_time;
procedure add2duel(const user,nick:RawByteString;is_mod:Boolean);
procedure add_to_chat_cmd(PC:TPrivMsgCfg;const user,cmd,param:RawByteString);
Procedure InitCfg;
Procedure LoadCfg;
Procedure Open;
procedure SetClearTimer(m:Boolean);
procedure OnClearProc(Sender:TObject);
procedure OnClearRnd(Sender:TBaseTask);
end;
var
vor_rpg:record
Enable:Boolean;
timeout_cmd:RawByteString;
vor_sucs:TStringList;
TickKd:Int64;
time_kd:DWORD;
xchg:record
Enable:Boolean;
max_count:DWORD;
max_time:DWORD;
exist1_msg,
exist2_msg,
max_msg,
ready_msg,
cancel_msg,
sucs_msg:RawByteString;
end;
duel:record
Enable:Boolean;
check_zero:Boolean;
PERC_MINUS_VIP:Byte;
max_count:DWORD;
max_time:DWORD;
kd_time:DWORD;
any_msg,
exist1_msg,
exist2_msg,
max_msg,
ready_msg,
cancel_msg,
time_msg,
zero_msg:RawByteString;
stand_msg:TStringList;
vip_msg:TStringList;
win_msg:TStringList;
end;
jail_vip:TStringList;
esc_vip:TStringList;
str_vip:TStringList;
norm_vor:TStringList;
minus_vip:TStringList;
time4_vip:TStringList;
neudc_vip:TStringList;
chist_vip:TStringList;
stat_msg:record
lvl_msg,
pts_msg,
stat_msg,
add_msg,
not_msg,
max_msg,
help_msg1,
help_msg2,
help_msg3,
top_msg1,
top_msg2,
on_debuf,
debuf_pr:RawByteString;
end;
calc:record
BASE_TIME:Int64;
MUL_TIME:Double;
DEC_TIME:Double;
MAX_LVL:DWORD;
MAX_LUK:DWORD;
MAX_DEF:DWORD;
MAX_CHR:DWORD;
MAX_STR:DWORD;
MAX_AGL:DWORD;
MUL_EXP:Double;
MUL_LUK:Double;
MUL_DEF:Double;
MUL_STR:Double;
MUL_AGL:Double;
DEC_LUK:Double;
DEC_DEF:Double;
DEC_STR:Double;
DEC_AGL:Double;
PERC_MINUS_VIP:Byte;
end;
debuf:record
PERC:Byte;
MIN_TIME:Int64;
MAX_TIME:Int64;
end;
kick:record
Enable:Boolean;
in_msg:RawByteString;
out_msg:RawByteString;
in_time :Int64;
out_time:Int64;
PERC:Byte;
not_vor:TStringList;
go_kick:TStringList;
go_def:TStringList;
go_esc:TStringList;
end;
end;
FrmVorRpg: TFrmVorRpg;
FGetRpgAll:TSQLScript;
FGetRpgUser1:TSQLScript;
FGetRpgUser2:TSQLScript;
FGetRndUser1:TSQLScript;
FSetRpgUser1:TSQLScript;
FSetRpgUser2:TSQLScript;
type
Pcharacteristic=^Tcharacteristic;
Tcharacteristic=object
STR,LUK,DEF,CHR,AGL:Int64;
Procedure SumTo(var S:Tcharacteristic);
end;
Pdebuf=^Tdebuf;
Tdebuf=object
id:Int64;
chr:Tcharacteristic;
text:RawByteString;
end;
procedure add_debuf(d:Tdebuf);
implementation
uses
ZDbcIntfs,
UAsyncResultSet,
Ulog,UFrmVipParam,
math,
mtRandom,ujson,gset;
{$R *.lfm}
type
PxchgVip=^TxchgVip;
PxchgNode=^TxchgNode;
TxchgNode=record
user:RawByteString;
link:PxchgVip;
end;
TxchgVip=record
src,dst:TxchgNode;
time:Int64;
is_mod:Boolean;
is_zero:Byte;
end;
TxchgNodeCompare=class
class function c(a,b:PxchgNode):boolean; static;
end;
TxchgNodeSet=specialize TSet<PxchgNode,TxchgNodeCompare>;
TRawStrCompare=class
class function c(const a,b:RawByteString):boolean; static;
end;
TRawByteStringSet=specialize TSet<RawByteString,TRawStrCompare>;
TLockScript=class
protected
FStatement:TDbcStatementScript;
Function try_lock:Boolean; virtual; abstract;
procedure unlock; virtual; abstract;
procedure Prepare(FDbcScript:TDbcStatementScript); virtual;
procedure OnFin(ResultSet:TZResultSet); virtual; abstract;
procedure OnUnlock(Sender:TBaseTask);
public
Procedure OnEvent; virtual; abstract;
end;
TDualLockScript=class(TLockScript)
public
user:array[0..1] of RawByteString;
data:array[0..1] of TJson;
Destructor Destroy; override;
protected
Function try_lock:Boolean; override;
procedure unlock; override;
procedure Prepare(FDbcScript:TDbcStatementScript); override;
procedure OnFin(ResultSet:TZResultSet); override;
end;
TOneLockScript=class(TLockScript)
public
user:RawByteString;
data:TJson;
Destructor Destroy; override;
protected
Function try_lock:Boolean; override;
procedure unlock; override;
procedure Prepare(FDbcScript:TDbcStatementScript); override;
procedure OnFin(ResultSet:TZResultSet); override;
end;
TDbcScriptLock=class(TDbcStatementScript)
LS:TLockScript;
Procedure OnFin(Sender:TBaseTask);
procedure Prepare(FS:TLockScript);
function try_start:SizeInt;
end;
Var
LockStr:TRawByteStringSet;
xchgSet:TxchgNodeSet;
duelSet:TxchgNodeSet;
class function TRawStrCompare.c(const a,b:RawByteString):boolean;
begin
Result:=CompareStr(a,b)<0;
end;
class function TxchgNodeCompare.c(a,b:PxchgNode):boolean;
begin
Result:=CompareStr(a^.user,b^.user)<0;
end;
procedure TLockScript.Prepare(FDbcScript:TDbcStatementScript);
begin
FStatement:=FDbcScript;
end;
procedure TLockScript.OnUnlock(Sender:TBaseTask);
begin
unlock;
Free;
end;
//TDualLockScript
Function TDualLockScript.try_lock:Boolean;
begin
Result:=((user[0]='') or (LockStr.NFind(user[0])=nil)) and
((user[1]='') or (LockStr.NFind(user[1])=nil));
if Result then
begin
if (user[0]<>'') then
LockStr.Insert(user[0]);
if (user[1]<>'') then
LockStr.Insert(user[1]);
end;
end;
procedure TDualLockScript.unlock;
begin
LockStr.Delete(user[0]);
LockStr.Delete(user[1]);
end;
procedure TDualLockScript.Prepare(FDbcScript:TDbcStatementScript);
begin
inherited;
FDbcScript.SetSctipt(FGetRpgUser2);
FDbcScript.ExecuteScript;
FDbcScript.Params.SetRawByteString('user1',user[0]);
FDbcScript.Params.SetRawByteString('user2',user[1]);
end;
procedure TDualLockScript.OnFin(ResultSet:TZResultSet);
Var
ms:TStream;
user_f,data_f:SizeInt;
u,d:RawByteString;
i,c:SizeInt;
begin
if ResultSet<>nil then
begin
c:=0;
if ResultSet.Last then
begin
c:=ResultSet.GetRow;
end;
if c>0 then
begin
user_f:=ResultSet.FindColumn('user');
data_f:=ResultSet.FindColumn('data');
For i:=1 to c do
begin
ResultSet.MoveAbsolute(i);
u:=ResultSet.GetRawByteString(user_f);
d:=ResultSet.GetRawByteString(data_f);
if user[0]=u then
begin
ms:=TPCharStream.Create(PAnsiChar(d),Length(d));
data[0]:=Default(TJson);
try
data[0]:=TJson.New(ms);
except
on E:Exception do
begin
DumpExceptionCallStack(E);
end;
end;
FreeAndNil(ms);
end else
if user[1]=u then
begin
ms:=TPCharStream.Create(PAnsiChar(d),Length(d));
data[1]:=Default(TJson);
try
data[1]:=TJson.New(ms);
except
on E:Exception do
begin
DumpExceptionCallStack(E);
end;
end;
FreeAndNil(ms);
end;
end;
end;
end;
OnEvent;
end;
Destructor TDualLockScript.Destroy;
begin
data[0].Free;
data[1].Free;
inherited;
end;
//TDualLockScript
//TOneLockScript
Function TOneLockScript.try_lock:Boolean;
begin
Result:=((user='') or (LockStr.NFind(user)=nil));
if Result then
begin
if (user<>'') then
LockStr.Insert(user);
end;
end;
procedure TOneLockScript.unlock;
begin
LockStr.Delete(user);
end;
procedure TOneLockScript.Prepare(FDbcScript:TDbcStatementScript);
begin
inherited;
FDbcScript.SetSctipt(FGetRpgUser1);
FDbcScript.ExecuteScript;
FDbcScript.Params.SetRawByteString('user1',user);
end;
procedure TOneLockScript.OnFin(ResultSet:TZResultSet);
Var
ms:TStream;
user_f,data_f:SizeInt;
u,d:RawByteString;
i,c:SizeInt;
begin
if ResultSet<>nil then
begin
c:=0;
if ResultSet.Last then
begin
c:=ResultSet.GetRow;
end;
if c>0 then
begin
user_f:=ResultSet.FindColumn('user');
data_f:=ResultSet.FindColumn('data');
For i:=1 to c do
begin
ResultSet.MoveAbsolute(i);
u:=ResultSet.GetRawByteString(user_f);
d:=ResultSet.GetRawByteString(data_f);
if user=u then
begin
ms:=TPCharStream.Create(PAnsiChar(d),Length(d));
data:=Default(TJson);
try
data:=TJson.New(ms);
except
on E:Exception do
begin
DumpExceptionCallStack(E);
end;
end;
FreeAndNil(ms);
end;
end;
end;
end;
OnEvent;
end;
Destructor TOneLockScript.Destroy;
begin
data.Free;
inherited;
end;
//TOneLockScript
Procedure TDbcScriptLock.OnFin(Sender:TBaseTask);
begin
LS.OnFin(ResultSet);
end;
procedure TDbcScriptLock.Prepare(FS:TLockScript);
begin
if (FS=nil) then Exit;
LS:=FS;
Handle.DbcConnection:=DbcThread;
Notify.Add(T_FIN,@OnFin);
LS.Prepare(Self);
end;
function TDbcScriptLock.try_start:SizeInt;
begin
Result:=0;
if LS.try_lock then
begin
Start;
Release;
end else
begin
AsyncFunc(@Self.try_start);
end;
end;
procedure SetDBRpgUser1(Const user1:RawByteString;data1:TJson;N:TNotifyTask);
var
FDbcScript:TDbcStatementScript;
ms:TRawByteStringStream;
d1:RawByteString;
begin
ms:=TRawByteStringStream.Create;
data1.Dump(ms);
d1:=ms.DataString;
FreeAndNil(ms);
FDbcScript:=TDbcStatementScript.Create;
FDbcScript.Handle.DbcConnection:=DbcThread;
FDbcScript.Notify.Add(T_FIN,N);
FDbcScript.SetSctipt(FSetRpgUser1);
FDbcScript.ExecuteScript;
FDbcScript.Params.SetRawByteString('user1',user1);
FDbcScript.Params.SetRawByteString('data1',d1);
FDbcScript.Start;
FDbcScript.Release;
end;
procedure SetDBRpgUser2(Const user1,user2:RawByteString;data1,data2:TJson;N:TNotifyTask);
var
FDbcScript:TDbcStatementScript;
ms:TRawByteStringStream;
d1,d2:RawByteString;
begin
ms:=TRawByteStringStream.Create;
data1.Dump(ms);
d1:=ms.DataString;
ms.Clear;
data2.Dump(ms);
d2:=ms.DataString;
FreeAndNil(ms);
FDbcScript:=TDbcStatementScript.Create;
FDbcScript.Handle.DbcConnection:=DbcThread;
FDbcScript.Notify.Add(T_FIN,N);
FDbcScript.SetSctipt(FSetRpgUser2);
FDbcScript.ExecuteScript;
FDbcScript.Params.SetRawByteString('user1',user1);
FDbcScript.Params.SetRawByteString('data1',d1);
FDbcScript.Params.SetRawByteString('user2',user2);
FDbcScript.Params.SetRawByteString('data2',d2);
FDbcScript.Start;
FDbcScript.Release;
end;
type
TVorScript=class(TDualLockScript)
public
s:RawByteString;
Procedure OnEvent; override;
end;
Procedure TFrmVorRpg.rpg_theif_vip(const s,dst_user,msg:RawByteString);
Var
FDbcScript:TDbcScriptLock;
src_user:RawByteString;
aRow:SizeInt;
FVorScript:TVorScript;
begin
aRow:=FrmMain.getRandomTmpVip(Extract_nick(msg));
if (aRow=-1) then
begin
push_irc_list(vip_rnd.is_empty,[dst_user]);
FrmMain._add_reward_2_log(s,Format(_get_first_cmd(vip_rnd.is_empty),[dst_user]));
Exit;
end;
src_user:=GridVips.FieldValue['user',ARow];
FVorScript:=TVorScript.Create;
FVorScript.user[0]:=dst_user;
FVorScript.user[1]:=src_user;
FVorScript.s:=s;
FDbcScript:=TDbcScriptLock.Create;
FDbcScript.Prepare(FVorScript);
FDbcScript.AsyncFunc(@FDbcScript.try_start);
end;
type
TdebufCompare=class
class function c(const a,b:Tdebuf):boolean; static;
end;
TdebufSet=specialize TSet<Tdebuf,TdebufCompare>;
TUserPoints=object(Tcharacteristic)
EXP,LVL,PTS:Int64;
function GetExpToLvl:Int64;
procedure CheckNewLvl;
procedure CheckMaxPts;
function TryDecAnyPts:Boolean; inline;
function TryDecLvl:Boolean; inline;
function TryDecExp:Boolean;
procedure Load(J:TJson);
procedure Save(var J:TJson);
end;
TPlayer=object
Points:TUserPoints;
Effects:Tcharacteristic;
Function STR:Int64;
Function LUK:Int64;
Function DEF:Int64;
Function CHR:Int64;
Function AGL:Int64;
Function GetLUKPercent:Int64;
Function GetDEFPercent:Int64;
Function GetSTRPercent:Int64;
Function GetESCPercent:Int64;
Function GetAGLPercent:Int64;
Function GetTime:Int64;
procedure IncEXP(val:Int64);
procedure Load(J:TJson);
procedure Save(var J:TJson);
end;
class function TdebufCompare.c(const a,b:Tdebuf):boolean;
begin
Result:=(a.id<b.id);
end;
Procedure Tcharacteristic.SumTo(var S:Tcharacteristic);
begin
S.STR:=S.STR+STR;
S.LUK:=S.LUK+LUK;
S.DEF:=S.DEF+DEF;
S.CHR:=S.CHR+CHR;
S.AGL:=S.AGL+AGL;
end;
function TUserPoints.GetExpToLvl:Int64;
begin
Result:=Trunc((LVL+1)*vor_rpg.calc.MUL_EXP-Log2((LVL+1)));
end;
procedure TUserPoints.CheckNewLvl;
var
need:Int64;
begin
repeat
if (LVL>=vor_rpg.calc.MAX_LVL) then Break;
need:=GetExpToLvl;
if (EXP>=need) then
begin
Inc(LVL);
Inc(PTS);
EXP:=EXP-need;
end else
begin
Break;
end;
until false;
end;
function TUserPoints.TryDecAnyPts:Boolean; inline;
var
RNDM:array of Byte;
procedure tadd(p:Byte;val:Int64);
begin
if (val>0) then
begin
SetLength(RNDM,Length(RNDM)+1);
RNDM[Length(RNDM)-1]:=p;
end;
end;
begin
Result:=False;
if (PTS>0) then
begin
Dec(PTS);
Result:=True;
end else
begin
SetLength(RNDM,0);
tadd(0,STR);
tadd(1,LUK);
tadd(2,DEF);
tadd(3,CHR);
tadd(4,AGL);
if (Length(RNDM)=0) then Exit;
case RNDM[Random(RCT,Length(RNDM))] of
0:Dec(STR);
1:Dec(LUK);
2:Dec(DEF);
3:Dec(CHR);
4:Dec(AGL);
end;
Result:=True;
end;
end;
function TUserPoints.TryDecLvl:Boolean; inline;
begin
Result:=False;
if (LVL>0) then
begin
Result:=TryDecAnyPts;
if Result then
begin
Dec(LVL);
end;
end;
end;
function TUserPoints.TryDecExp:Boolean;
begin
Result:=False;
if (EXP>0) then
begin
Dec(EXP);
Result:=True;
end else
begin
Result:=TryDecLvl;
if Result then
begin
EXP:=GetExpToLvl-1;
end;
end;
end;
procedure TUserPoints.CheckMaxPts;
procedure try_max(var param:Int64;var max:DWORD); inline;
begin
if (param>max) then
begin
PTS:=PTS+(param-max);
param:=max;
end;
end;
begin
if (PTS<0) then PTS:=0;
try_max(LUK,vor_rpg.calc.MAX_LUK);
try_max(DEF,vor_rpg.calc.MAX_DEF);
try_max(CHR,vor_rpg.calc.MAX_CHR);
try_max(AGL,vor_rpg.calc.MAX_AGL);
try_max(STR,vor_rpg.calc.MAX_STR);
end;
Function TPlayer.STR:Int64;
begin
Result:=Points.STR+Effects.STR;
end;
Function TPlayer.LUK:Int64;
begin
Result:=Points.LUK+Effects.LUK;
end;
Function TPlayer.DEF:Int64;
begin
Result:=Points.DEF+Effects.DEF;
end;
Function TPlayer.CHR:Int64;
begin
Result:=Points.CHR+Effects.CHR;
end;
Function TPlayer.AGL:Int64;
begin
Result:=Points.AGL+Effects.AGL;
end;
Function TPlayer.GetLUKPercent:Int64;
var
_LUK:Int64;
begin
_LUK:=LUK;
if (_LUK=0) then Exit(0) else
if (_LUK>0) then
Result:=Trunc(Log2((_LUK+1)*4-2)*vor_rpg.calc.MUL_LUK+vor_rpg.calc.DEC_LUK)
else
Result:=-Trunc(Log2((abs(_LUK)+1)*4-2)*vor_rpg.calc.MUL_LUK+vor_rpg.calc.DEC_LUK);
end;
Function TPlayer.GetDEFPercent:Int64;
var
_DEF:Int64;
begin
_DEF:=DEF;
if (_DEF=0) then Exit(0) else
if (_DEF>0) then
Result:=Trunc(Log2((_DEF+1)*4-2)*vor_rpg.calc.MUL_DEF+vor_rpg.calc.DEC_DEF)
else
Result:=-Trunc(Log2((abs(_DEF)+1)*4-2)*vor_rpg.calc.MUL_DEF+vor_rpg.calc.DEC_DEF);
end;
Function TPlayer.GetSTRPercent:Int64;
var
_STR:Int64;
begin
_STR:=STR;
if (_STR=0) then Exit(0) else
if (_STR>0) then
Result:=Trunc(Log2((_STR+1)*4-2)*vor_rpg.calc.MUL_STR+vor_rpg.calc.DEC_STR)
else
Result:=-Trunc(Log2((abs(_STR)+1)*4-2)*vor_rpg.calc.MUL_STR+vor_rpg.calc.DEC_STR);
end;
Function TPlayer.GetESCPercent:Int64;
var
_AGL:Int64;
begin
_AGL:=AGL;
if (_AGL=0) then Exit(0) else
if (_AGL>0) then
Result:=Trunc(Log2(_AGL*3-2)*vor_rpg.calc.MUL_AGL+vor_rpg.calc.DEC_AGL)
else
Result:=-Trunc(Log2(abs(_AGL)*3-2)*vor_rpg.calc.MUL_AGL+vor_rpg.calc.DEC_AGL);
end;
Function TPlayer.GetAGLPercent:Int64;
var
_AGL:Int64;
begin
_AGL:=AGL;
if (_AGL=0) then Exit(0) else
if (_AGL>0) then
Result:=Trunc(Log2((_AGL+1)*4-2)*vor_rpg.calc.MUL_STR+vor_rpg.calc.DEC_STR)
else
Result:=-Trunc(Log2((abs(_AGL)+1)*4-2)*vor_rpg.calc.MUL_STR+vor_rpg.calc.DEC_STR);
end;
Function TPlayer.GetTime:Int64;
var
_CHR:Int64;
begin
_CHR:=CHR;
if (_CHR=0) then Exit(0) else
if (_CHR>0) then
Result:=Trunc(Log2(_CHR*3-2)*vor_rpg.calc.MUL_TIME+vor_rpg.calc.DEC_TIME)
else
Result:=-Trunc(Log2(abs(_CHR)*3-2)*vor_rpg.calc.MUL_TIME+vor_rpg.calc.DEC_TIME);
end;
procedure TUserPoints.Load(J:TJson);
begin
EXP:=J.Path['points.EXP'].AsInt64(0);
LVL:=J.Path['points.LVL'].AsInt64(0);
PTS:=J.Path['points.PTS'].AsInt64(0);
STR:=J.Path['points.STR'].AsInt64(0);
LUK:=J.Path['points.LUK'].AsInt64(0);
DEF:=J.Path['points.DEF'].AsInt64(0);
CHR:=J.Path['points.CHR'].AsInt64(0);
AGL:=J.Path['points.AGL'].AsInt64(0);
end;
Procedure Save40nul(var J:TJson;const path:RawByteString;val:Int64);
begin
if (val=0) then
begin
J.Delete(path);
end else
begin
J.Values[path]:=val;
end;
end;
procedure TUserPoints.Save(var J:TJson);
begin
Save40nul(J,'points.EXP',EXP);
Save40nul(J,'points.LVL',LVL);
Save40nul(J,'points.PTS',PTS);
Save40nul(J,'points.STR',STR);
Save40nul(J,'points.LUK',LUK);
Save40nul(J,'points.DEF',DEF);
Save40nul(J,'points.CHR',CHR);
Save40nul(J,'points.AGL',AGL);
end;
procedure TPlayer.IncEXP(val:Int64);
begin
Points.EXP:=Points.EXP+val;
Points.CheckNewLvl;
end;
var
debufSet:TdebufSet;
procedure add_debuf(d:Tdebuf);
begin
if (debufSet=nil) then
begin
debufSet:=TdebufSet.Create;
end;
d.id:=debufSet.Size;
debufSet.Insert(d);
end;
function Get_debuf(id:Int64):Tdebuf;
var
Node:debufSet.PNode;
begin
Result:=Default(Tdebuf);
Result.id:=id;
if (debufSet=nil) then Exit;
Node:=debufSet.NFind(Result);
if (Node=nil) then Exit;
Result:=Node^.Data;
end;
function Get_random_debuf_id:Int64;
begin
Result:=-1;
if (debufSet=nil) then Exit;
Result:=Random(RCT,int64(debufSet.Size))
end;
procedure Set_debuf(var J:TJson;id,time:Int64);
Var
instance,item:TJson;
i,C:SizeUint;
new:Int64;
begin
instance:=J.Path['debuf.instance'];
if not instance.isAssigned then
begin
instance:=TJson.New;
instance.SetArray;
J.Path['debuf.instance']:=instance;
end;
C:=instance.Count;
new:=DateTimeToUnix(sysutils.Now,False)+time;
if (C<>0) then
begin
For i:=0 to C-1 do
begin
item:=instance.Item[i];
if (item.Path['id'].AsInt64(0)=id) then
begin
item.Values['time']:=Max(new,item.Path['time'].AsInt64(0));
Exit;
end;
end;
end;
item:=TJson.New;
item.Values['id']:=id;
item.Values['time']:=new;
instance.Add(item);
end;
procedure TPlayer.Load(J:TJson);
Var
instance:TJson;
i,C:SizeUint;
now,time:Int64;
debuf:Tdebuf;
begin
Points.Load(J);
Points.CheckNewLvl;
Points.CheckMaxPts;
Effects:=Default(Tcharacteristic);
instance:=J.Path['debuf.instance'];
C:=instance.Count;
if (C<>0) then