-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_script.js
1455 lines (1171 loc) · 46.5 KB
/
common_script.js
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
//注意:game.$globalLibraryJS
//.import 'level_chain.js' as JSLevelChain //导入另一个js文件
//let jsLevelChain = JSLevelChain; //让外部可访问
//配置
let $config = {
$map: {
opacity: 0.6, //人物遮挡透明度
},
//摇杆
$joystick: {
//位置
$left: 6,
$bottom: 7,
$size: 20,
},
//按钮(数组,前两个是系统的必有)
$buttons: [
{
//位置、颜色
$right: 10,
$bottom: 16,
$size: 6,
$color: 'red',
$opacity: 0.6,
$image: '',
$clicked: function*() {
//if(!GlobalLibraryJS.objectIsEmpty(_private.config.objPauseNames))
// return;
if(game.pause(null))
return;
game.$sys.interact();
},
},
{
$right: 16,
$bottom: 8,
$size: 6,
$color: 'blue',
$opacity: 0.6,
$image: '',
$clicked: function*() {
//if(!GlobalLibraryJS.objectIsEmpty(_private.config.objPauseNames))
// return;
if(game.pause(null))
return;
game.window(1);
//game.window(1, {MaskColor: '#00000000'});
},
},
{
$right: 10,
$bottom: 10,
$size: 6,
$color: 'green',
//按下事件
$clicked: function*() {
if(game.pause(null))
return;
yield game.msg('自定义按键');
},
},
],
//窗口
$window: {
//窗口显示事件
$show: function(newFlags, windowFlags) {
//if(newFlags & 0b1)
// game.showimage('FightScene2.jpg', {$width: -1, $height: -1}, 'aaa');
},
//窗口隐藏事件
$hide: function(newFlags, windowFlags) {
//if(newFlags & 0b1)
// game.delimage('aaa');
},
},
$style: {
//主菜单窗口
$main: {
$maskColor: '#7FFFFFFF',
$borderColor: 'white',
$backgroundColor: '#CF6699FF',
$itemFontSize: 16,
$itemFontColor: 'white',
$itemBackgroundColor1: '#00FFFFFF',
$itemBackgroundColor2: '#66FFFFFF',
$titleFontSize: 16,
$titleBackgroundColor: '#66FFFFFF',
$titleFontColor: 'white',
$itemBorderColor: '#60FFFFFF',
$titleText: '',
},
//系统
$system: {
$maskColor: '#7FFFFFFF',
$borderColor: 'white',
$backgroundColor: '#CF6699FF',
$itemFontSize: 16,
$itemFontColor: 'white',
$itemBackgroundColor1: '#00FFFFFF',
$itemBackgroundColor2: '#66FFFFFF',
$titleFontSize: 16,
$titleBackgroundColor: '#66FFFFFF',
$titleFontColor: 'white',
$itemBorderColor: '#60FFFFFF',
$titleText: '',
},
$say: {
$backgroundColor: '#BF6699FF',
$borderColor: 'white',
$fontSize: 9,
$fontColor: 'white',
},
$talk: {
$name: true,
$avatar: true,
$backgroundColor: '#BF6699FF',
$borderColor: 'white',
$fontSize: 16,
$fontColor: 'white',
$maskColor: 'transparent',
},
$msg: {
$backgroundColor: '#BF6699FF',
$borderColor: 'white',
$fontSize: 16,
$fontColor: 'white',
$maskColor: '#7FFFFFFF',
$type: 0b10,
},
$menu: {
$maskColor: '#7FFFFFFF',
$borderColor: 'white',
$backgroundColor: '#CF6699FF',
$itemHeight: 60,
$titleHeight: 60,
$itemFontSize: 16,
$itemFontColor: 'white',
$itemBackgroundColor1: '#00FFFFFF',
$itemBackgroundColor2: '#66FFFFFF',
$titleFontSize: 16,
$titleBackgroundColor: '#EE00CC99',
$titleFontColor: 'white',
$itemBorderColor: '#60FFFFFF',
},
$input: {
$backgroundColor: '#FFFFFF',
$borderColor: '#60000000',
$fontSize: 16,
$fontColor: 'black',
$titleBackgroundColor: '#EE00CC99',
$titleBorderColor: 'white',
$titleFontSize: 16,
$titleFontColor: 'white',
$maskColor: '#7FFFFFFF',
},
$fight_menu: {
$borderColor: 'white',
$backgroundColor: '#CF6699FF',
$itemHeight: 60,
$titleHeight: 60,
$itemFontSize: 16,
$itemFontColor: 'white',
$itemBackgroundColor1: '#00FFFFFF',
$itemBackgroundColor2: '#66FFFFFF',
$titleFontSize: 16,
$titleBackgroundColor: '#EE00CC99',
$titleFontColor: 'white',
$itemBorderColor: '#60FFFFFF',
},
},
//安卓配置
$android: {
//屏幕旋转规则
$orient: 4,
},
};
//战斗角色
function $Combatant(fightRoleRId, showName) {
//console.debug('[FightScene]$Combatant');
if(!fightRoleRId)
fightRoleRId = '深林孤鹰';
if(!showName)
showName = fightRoleRId;
//属性定义
let properties = {
HP: [200, 200, 200],
//healthHP: 200,
//remainHP: 200,
MP: [200, 200],
//remainMP: 200,
attack: 50,
defense: 50,
//其他属性
power: 50,
luck: 50,
speed: 50,
EXP: 0, //经验
level: 0, //级别
};
//战斗角色名(包含特效)
this.$rid = fightRoleRId;
//this.fightRoleRId = fightRoleRId;
this.$name = showName; //游戏显示名
this.$index = -1; //序号(敌人为-1)
this.$avatar = '';
this.$size = [50, 50];
this.$color = 'white';
//所有属性
this.$properties = properties;
//this.fightSkill = null; //普通攻击
this.$skills = []; //普通攻击 和 技能/魔法 的对象,可以加入其他字段(比如级别,这些字段会覆盖原有的属性)
//this.$goods = []; //携带道具 的(只有敌人有) 对象
this.$equipment = {}; //装备;key为position,value为 道具对象,可以加入其他(比如破损率,这些字段会覆盖原有的属性)
//this.hide = false; //是否隐藏
//战斗属性+道具属性(动态计算),不会存档
this.$$propertiesWithExtra = game.$globalLibraryJS.deepCopyObject(properties);
//战斗属性,不会保存
//注意:这里只是显示需要用到的字段,实际会在fight前重新初始化!!!
this.$$fightData = {
//这个info不要用,系统会战斗时自动初始化
$info: {
$index: -1, //所在队伍下标
$teamID: [0, 1], //0:我方;1:敌人;2:友军。下标:我方、对方、友方
$team: [], //保存队伍对象。下标:己方、对方、友方
$teamSpriteEffect: [],
$spriteEffect: null,
},
$choiceType: -1, //选择的类型(主要是这个来判断!!)。0,普通攻击;1,技能;2,道具;3,休息;4,逃跑;-1为没选择;-2为随机选择普通攻击(倒序开始)
$lastChoiceType: -1,
$attackSkill: undefined, //攻击选择的技能名称(-1为获得普通攻击(倒序),-2为休息,undefined为没选择)
$lastAttackSkill: undefined, //上次技能
$target: undefined, //战斗目标数组[FightRole](-1为全部);
$lastTarget: undefined, //上次目标
//$actionData: ({}), //动作数据;key为动作名,value为特效名
$buffs: ({}), //buffs
//defenseSkill: '', //防御选择
//lastDefenseSkill: '',
};
}
function 属性(p, n=0) {
let ret;
if(game.$globalLibraryJS.isValidNumber(n)) {
if(game.$globalLibraryJS.isString(mappingCombatantProperty[p])) {
this.$properties[mappingCombatantProperty[p]] += n;
ret = this.$properties[mappingCombatantProperty[p]];
}
else if(game.$globalLibraryJS.isArray(mappingCombatantProperty[p])) {
this.$properties[mappingCombatantProperty[p][0]][mappingCombatantProperty[p][1]] += n;
ret = this.$properties[mappingCombatantProperty[p][0]][mappingCombatantProperty[p][1]];
}
}
return ret;
}
function 附加属性(p, n=0) {
let ret;
if(game.$globalLibraryJS.isValidNumber(n)) {
if(game.$globalLibraryJS.isString(mappingCombatantProperty[p])) {
this.$$propertiesWithExtra[mappingCombatantProperty[p]] += n;
ret = this.$$propertiesWithExtra[mappingCombatantProperty[p]];
}
else if(game.$globalLibraryJS.isArray(mappingCombatantProperty[p])) {
this.$$propertiesWithExtra[mappingCombatantProperty[p][0]][mappingCombatantProperty[p][1]] += n;
ret = this.$$propertiesWithExtra[mappingCombatantProperty[p][0]][mappingCombatantProperty[p][1]];
}
}
return ret;
}
$Combatant.prototype.属性 = 属性;
$Combatant.prototype.附加属性 = 附加属性;
//系统显示 和 真实属性 对应
//中文属性索引
let mappingCombatantProperty = {
//系统用到的
'血量': ['HP', 2],
'血量1': ['HP', 1],
'血量2': ['HP', 0],
//其他
'魔法': ['MP', 1],
'魔法2': ['MP', 0],
'攻击': 'attack',
'防御': 'defense',
'灵力': 'power',
'幸运': 'luck',
'速度': 'speed',
'经验': 'EXP',
'级别': 'level',
};
let mappingSystemName = {
'money': '金钱',
}
//显示战斗人物详细信息
let $combatantInfo = function(combatant) {
let tinfo = '';
for(let tp in mappingCombatantProperty) {
//多段值
if(game.$globalLibraryJS.isArray(mappingCombatantProperty[tp])) {
tinfo += (tp + ':' + combatant.$$propertiesWithExtra[mappingCombatantProperty[tp][0]][mappingCombatantProperty[tp][1]] + ' ');
}
//单值
else {
tinfo += (tp + ':' + combatant.$$propertiesWithExtra[mappingCombatantProperty[tp]] + ' ');
}
}
return tinfo;
}
//显示的道具名格式
//flags:image、color、count分别表示是否显示图像、颜色和数量(数量只有可叠加的才显示)
let $showGoodsName = function(goods, flags=null) {
let name = '';
if(flags === undefined || flags === null)
flags = {image: true, color: true, count: true};
if(flags['image'] && goods.$image) {
//let goodsPath = game.$projectpath + game.$gameMakerGlobal.separator + game.$config.strGoodsDirName + game.$gameMakerGlobal.separator;
//game.$globalLibraryJS.showRichTextImage();
name += ' <img src="%1" width="%2" height="%3" style="vertical-align: top;"> '.
//arg(goodsPath + goods.$rid + game.$gameMakerGlobal.separator + goods.$image).
arg(game.$global.toURL(game.$gameMakerGlobal.imageResourceURL(goods.$image))).
arg(goods.$size[0]).
arg(goods.$size[1]);
}
if(flags['color'] && goods.$color)
name += `<font color="${goods.$color}">`;
name += goods.$name;
if(flags['color'] && goods.$color)
name += '</font>';
if(flags['count'] && (goods.$stackable || goods.$count > 1))
name += ` x${goods.$count}`;
return name;
}
//显示的战斗人物名格式
//flags:avatar、color分别表示是否显示头像、颜色
let $showCombatantName = function(combatant, flags=null) {
let name = '';
let fightRolePath = game.$projectpath + game.$gameMakerGlobal.separator + game.$config.strFightRoleDirName + game.$gameMakerGlobal.separator;
if(flags === undefined || flags === null)
flags = {avatar: true, color: true};
if(flags['avatar'] && combatant.$avatar) {
//game.$globalLibraryJS.showRichTextImage();
name += ' <img src="%1" width="%2" height="%3" style="vertical-align: top;"> '.
//arg(fightRolePath + combatant.$rid + game.$gameMakerGlobal.separator + combatant.$avatar).
arg(game.$global.toURL(game.$gameMakerGlobal.imageResourceURL(combatant.$avatar))).
arg(combatant.$size[0]).
arg(combatant.$size[1]);
}
if(flags['color'] && combatant.$color)
name += `<font color="${combatant.$color}">`;
name += combatant.$name;
if(flags['color'] && combatant.$color)
name += '</font>';
return name;
}
//刷新战斗人物
function $refreshCombatant(combatant) {
//只有我方战斗人物才可以升级
if(combatant.$index >= 0)
levelUp(combatant, 0, false);
//战斗时,由于是脚本系统运行,所以必须放在最前才能使血量实时更新
//game.run([function() {
//计算新属性
computeCombatantPropertiesWithExtra(combatant);
//刷新战斗时人物数据
fight.refreshCombatant(combatant);
//}, 'refreshCombatant1'], 0);
}
//直接升level级;为0表示检测是否需要升级;
// fighthero为下标,或战斗角色的name,或战斗角色对象;
function levelUp(combatant, level=0, refresh=true) {
//优先载入战斗角色自己的升级链,如果没有则载入系统的
let levelupscript;
let levelalgorithm;
if(combatant.$commons) {
levelupscript = combatant.levelUpScript;
levelalgorithm = combatant.levelAlgorithm;
}
if(!levelupscript) {
try {
levelupscript = JSLevelChain.commonLevelUpScript;
}
catch(e) {
levelupscript = game.$gameMakerGlobalJS.commonLevelUpScript;
}
}
if(!levelalgorithm) {
try {
levelalgorithm = JSLevelChain.commonLevelAlgorithm;
}
catch(e) {
levelalgorithm = game.$gameMakerGlobalJS.commonLevelAlgorithm;
}
}
//如果需要升级,则计算升级所需要的条件,然后直接达到即可(只增不减);
if(level > 0) {
//game.run(function() {
let result = levelalgorithm(combatant, combatant.$properties.level + level);
for(let r in result) { //提取所有条件并设置为满足
//只增不减
if(combatant.$properties[r] < result[r])
combatant.$properties[r] = result[r];
}
//});
}
//检测升级
game.run([levelupscript(combatant), 'levelupscript']);
//强制刷新
if(refresh)
game.run([function() {
//计算新属性
computeCombatantPropertiesWithExtra(combatant);
//刷新战斗时人物数据
fight.refreshCombatant(combatant);
},'refreshCombatant2']);
}
//计算 combatant 装备后的属性 并返回
//$equipEffectAlgorithm为某道具装备脚本
function computeCombatantPropertiesWithExtra(combatant) {
//累加装备、Buff后的属性
combatant.$$propertiesWithExtra = game.$globalLibraryJS.deepCopyObject(combatant.$properties);
//行走速度改变示例代码
//let 行走速度 = game.gd['$sys_main_roles'][0].MoveSpeed;
//循环装备
for(let tg in combatant.$equipment) {
//跳过为空的
if(!combatant.$equipment[tg])
continue;
let goodsInfo = game.$sys.resources.goods[combatant.$equipment[tg].$rid];
//计算新属性
if(goodsInfo.$equipEffectAlgorithm)
goodsInfo.$equipEffectAlgorithm(combatant.$equipment[tg], combatant);
//这里可以添加判断相关套装和增加的额外属性代码
//行走速度改变示例代码
/*
if(combatant.$equipment[tg].行走速度)
行走速度 += combatant.$equipment[tg].行走速度;
*/
}
//行走速度改变示例代码
//game.hero(0, {$speed: 行走速度});
//遍历所有的buff
if(combatant.$$fightData && combatant.$$fightData.$buffs) {
let buffs = combatant.$$fightData.$buffs;
for(let tbuffsIndex in buffs) {
let tbuff = buffs[tbuffsIndex];
if(tbuff.buffPropertiesEffect) {
tbuff.buffPropertiesEffect(combatant, tbuff);
}
}
}
/*for(let tg of combatant.holdsScript) {
for(let te in tg.holdsScript) {
combatant.$$propertiesWithExtra[te] += tg.holdsScript[te];
}
}*/
//console.debug('combatant.$$propertiesWithExtra', combatant, combatant.$$fightData, combatant.$$propertiesWithExtra);
return combatant.$$propertiesWithExtra;
}
//游戏结束脚本
function *$gameOverScript(params) {
if(params === -1) {
yield game.msg('游戏结束', 60, '', 0, 0b11);
game.$sys.release(false);
game.$sys.init(true, false);
}
}
//通用逃跑算法(目前是整体逃跑,所以 index为 -1)
function $commonRunAwayAlgorithm(team, index) {
return game.$globalLibraryJS.randTarget(1,2);
}
//战斗人物排序算法
function $sortFightAlgorithm(a, b) {
if(a.$$propertiesWithExtra.speed > b.$$propertiesWithExtra.speed)return -1;
if(a.$$propertiesWithExtra.speed < b.$$propertiesWithExtra.speed)return 1;
if(a.$$propertiesWithExtra.speed === b.$$propertiesWithExtra.speed)return 0;
}
//技能效果算法
function $skillEffectAlgorithm(combatant, targetCombatant, Params) {
//if(!Params)
// return;
//if(Params.Skill === 0)
// return;
//let role1 = combatant;
//let role2 = targetCombatant;
//let role1Props = $computeCombatantPropertiesWithExtra(role1);
//let role2Props = $computeCombatantPropertiesWithExtra(role2);
let combatant1Props = combatant.$$propertiesWithExtra;
let combatant2Props = targetCombatant.$$propertiesWithExtra;
let skill = combatant.$$fightData.$attackSkill;
//let skill2 = targetCombatant.$$fightData.$attackSkill;
//这里可以用:combatant.属性('血量'),、targetCombatant.附加属性('防御') 这些中文来编程
//属性表示人物原来属性,附加属性表示人物加上装备和Buff的某个最终属性
//伤害
let harm, t;
if(game.$globalLibraryJS.randTarget(combatant2Props.luck / 5 + combatant2Props.speed / 5)) { //miss各占%20
return [{'HP': [0, 0], Target: targetCombatant}];
}
//计算攻击:攻击-防御
harm = combatant1Props.attack - combatant2Props.defense;
t = combatant1Props.attack;
t = t * game.$globalLibraryJS.random(combatant1Props.power, combatant1Props.power*2) / 1000; //灵力1~2倍 //攻击+灵力效果
harm = harm + t;
t = combatant1Props.attack;
t = t * game.$globalLibraryJS.random(10, combatant1Props.luck/10+1) / 1000 ; //吉运效果 千分之一到十分之一
harm = harm + t;
t = combatant2Props.defense;
t = t * game.$globalLibraryJS.random(combatant2Props.power/2, combatant2Props.power) / 1000; //防御+灵力效果
harm = harm - t;
t = combatant2Props.defense;
t = t * game.$globalLibraryJS.random(10, combatant2Props.luck/10+1) / 1000; //吉运效果
harm = harm - t;
harm = Math.floor(harm);
if(harm <= 0)harm = game.$globalLibraryJS.random(0, 10);
//targetCombatant.$properties.healthHP -= Math.floor(harm / 4);
//targetCombatant.$properties.remainHP -= harm;
//console.debug('damage1');
return [{'HP': [harm, Math.floor(harm / 4)], Target: targetCombatant}];
}
//敌人选择技能算法
function $enemyChoiceSkillAlgorithm(combatant) {
//随机选择技能
let tSkillIndexArray = game.$globalLibraryJS.GetDifferentNumber(0, combatant.$skills.length);
for(let tSkillIndex in tSkillIndexArray) {
let skill = combatant.$skills[tSkillIndexArray[tSkillIndex]];
/*let attackSkill;
if(game.$globalLibraryJS.isString(skill)) {
attackSkill = {$rid: skill};
game.$globalLibraryJS.copyPropertiesToObject(attackSkill, game.$sys.resources.skills[skill].$properties);
}
else {
attackSkill = {$rid: skill.RId};
game.$globalLibraryJS.copyPropertiesToObject(attackSkill, game.$sys.resources.skills[skill.RId].$properties);
game.$globalLibraryJS.copyPropertiesToObject(attackSkill, skill);
}*/
//let checkSkill = game.$sys.resources.commonScripts['common_check_skill'](skill, combatant, 1);
let checkSkill = $commonCheckSkill(skill, combatant, null, 1);
if(checkSkill === true) { //如果技能符合可用
combatant.$$fightData.$choiceType = skill.$type;
combatant.$$fightData.$attackSkill = skill;
return true;
}
}
return false;
}
//combatant获得Buff
//buffCode:12345分别表示 毒乱封眠 属性,params是参数;
// buffCode:
// 1毒:params有BuffName、Round、HarmType(1为直接减harmValue,2为剩余HP的harmValue倍)、HarmValue、Flags;
// 2乱、3封、4眠:BuffName、Round、Flags;
// 5属性:BuffName、Round、Properties、Flags;
// Properties:[属性名, 值, type]:Type为0表示相加,Type为1表示 与属性相乘;
// Flags:实质是决定什么时候运行脚本(见combatantRoundEffects),可表示 毒乱封眠属性 类型,也可以表示 buff类型;
// 比如 毒 是回合开始前执行 buffAnimationEffect,乱封眠 是 combatant 行动前执行 buffAnimationEffect。
// params:
// BuffName:存储的 Buff 名称,如果不同则插入,如果相同则会覆盖;
// Override表示是否覆盖(如果不覆盖,则 Buff名 后加时间戳来防止重复)
function getBuff(combatant, buffCode, params={}) {
let buffName;
let override = (params.Override === undefined ? true : false);
let round = params.Round || 5;
let flags = params.Flags;
switch(buffCode) {
//毒
case 1:
if(!game.$globalLibraryJS.isString(params.BuffName))
params.BuffName = '$$Poison';
buffName = params.BuffName;
if(!override)
buffName += new Date().getTime();
combatant.$$fightData.$buffs[buffName] = {
//回合数
round: round || 5,
//执行脚本,objBuff为 本buff对象
buffAnimationEffect: function*(combatant, objBuff) {
//结算
let harm = 10;
//伤害类型:直接减
if(params.HarmType === 1) {
harm = params.HarmValue;
}
//伤害类型:剩余HP的多少倍
else if(params.HarmType === 2) {
harm = combatant.$properties.HP[0] * params.HarmValue;
}
harm = Math.round(harm);
game.addprops(combatant, {'HP': [-harm, -Math.floor(harm / 4)]});
//刷新人物信息
yield ({Type: 1});
//显示伤害血量
yield ({Type: 30, Interval: 0, Color: 'green', Text: params.BuffName + (-harm), FontSize: 20, Combatant: combatant, Position: undefined});
},
//标记(毒乱封眠 类型,也可以表示buff名,其实就是决定什么时候运行脚本)
flags: flags || 0b1000,
//buff属性效果(只有属性buff有)
buffPropertiesEffect: false, //function (combatant, objBuff){}
}
break;
//乱
case 2:
if(!game.$globalLibraryJS.isString(params.BuffName))
params.BuffName = '$$Confusion';
buffName = params.BuffName;
if(!override)
buffName += new Date().getTime();
combatant.$$fightData.$buffs[buffName] = {
//回合数
round: round || 5,
//执行脚本,objBuff为 本buff对象
buffAnimationEffect: function*(combatant, objBuff) {
//技能为普通攻击的第一个
let skills = fight.getCombatantSkills(combatant, 0b1)[1];
combatant.$$fightData.$attackSkill = skills[0];
//目标为自己
combatant.$$fightData.$target = [combatant];
//显示
yield ({Type: 30, Interval: 0, Color: 'yellow', Text: params.BuffName, FontSize: 20, Combatant: combatant, Position: undefined});
},
//标记(毒乱封眠 类型,也可以表示buff名,其实就是决定什么时候运行脚本)
flags: flags || 0b0100,
//buff属性效果(只有属性buff有)
buffPropertiesEffect: false, //function (combatant, objBuff){}
}
break;
//封
case 3:
if(!game.$globalLibraryJS.isString(params.BuffName))
params.BuffName = '$$Sealing';
buffName = params.BuffName;
if(!override)
buffName += new Date().getTime();
combatant.$$fightData.$buffs[buffName] = {
//回合数
round: round || 5,
//执行脚本,objBuff为 本buff对象
buffAnimationEffect: function*(combatant, objBuff) {
//技能为 普通攻击 的最后一个
let skills = fight.getCombatantSkills(combatant, 0b101)[1];
combatant.$$fightData.$attackSkill = skills.pop();
combatant.$$fightData.$target = null;
//显示
yield ({Type: 30, Interval: 0, Color: 'yellow', Text: params.BuffName, FontSize: 20, Combatant: combatant, Position: undefined});
},
//标记(毒乱封眠 类型,也可以表示buff名,其实就是决定什么时候运行脚本)
flags: flags || 0b0010,
//buff属性效果(只有属性buff有)
buffPropertiesEffect: false, //function (combatant, objBuff){}
}
break;
//眠
case 4:
if(!game.$globalLibraryJS.isString(params.BuffName))
params.BuffName = '$$Sleep';
buffName = params.BuffName;
if(!override)
buffName += new Date().getTime();
combatant.$$fightData.$buffs[buffName] = {
//回合数
round: round || 5,
//执行脚本,objBuff为 本buff对象
buffAnimationEffect: function*(combatant, objBuff) {
combatant.$$fightData.$choiceType = 3;
//combatant.$$fightData.$target = -2;
//显示
yield ({Type: 30, Interval: 0, Color: 'yellow', Text: params.BuffName, FontSize: 20, Combatant: combatant, Position: undefined});
},
//标记(毒乱封眠 类型,也可以表示buff名,其实就是决定什么时候运行脚本)
flags: flags || 0b0001,
//buff属性效果(只有属性buff有)
buffPropertiesEffect: false, //function (combatant, objBuff){}
}
break;
//属性
case 5:
default:
if(!game.$globalLibraryJS.isString(params.BuffName))
params.BuffName = '$$Properties';
buffName = params.BuffName;
if(!override)
buffName += new Date().getTime();
combatant.$$fightData.$buffs[buffName] = {
//回合数
round: round || 5,
//执行脚本,objBuff为 本buff对象
buffAnimationEffect: function*(combatant, objBuff) {
//显示
yield ({Type: 30, Interval: 0, Color: 'yellow', Text: params.BuffName, FontSize: 20, Combatant: combatant, Position: undefined});
},
//标记(毒乱封眠 类型,也可以表示buff名,其实就是决定什么时候运行脚本)
flags: flags || 0b10000,
//buff属性效果(只有属性buff有)
buffPropertiesEffect: function (combatant, objBuff) {
let properties = combatant.$properties;
let propertiesWithExtra = combatant.$$propertiesWithExtra;
for(let tp of params.Properties) {
//如果提升值为百分之
if(tp[2] === 2)
propertiesWithExtra[tp[0]] += (properties[tp[0]] * tp[1]);
//直接加
//if(tp[2] === 1)
else
propertiesWithExtra[tp[0]] += tp[1];
}
}
}
break;
}
$refreshCombatant(combatant);
}
//每个战斗人物(我方、敌方)的回合脚本;
//round为回合数;
//stage:0为回合开始前;1为战斗人物行动前;2为战斗人物行动后;
//返回null表示跳过回合(stage为1时有效)
function $combatantRoundScript(combatant, round, stage) {
if(stage === 0) {
//没血的休息
if(combatant.$properties.HP[0] <= 0) {
combatant.$$fightData.$choiceType = 3;
}
}
if(stage === 1) {
//跳过没血的
if(combatant.$properties.HP[0] <= 0) {
//console.debug('没血');
return null;
}
}
return combatantRoundEffects(combatant, round, stage);
}
//战斗人物回合脚本(主要是剧情和Buff),会在两个阶段分别执行一次;
//round为回合数;
//stage:0为回合开始前;1为战斗人物行动前;
function *combatantRoundEffects(combatant, round, stage) {
let buffs = combatant.$$fightData.$buffs;
/*if(buffs['$$Sleep']) {
return {success: false, msg: '你已经被[眠]'};
}
if(buffs['$$Sealing'] && fightSkillData.$type === 1) {
return {success: false, msg: '你已经被[封]'};
}
if(buffs['$$Confusion']) {
return {success: false, msg: '你已经被[乱]', change: {skill: 0b01, target: [[team1, team2], [-1, -1]]}};
}*/
//遍历所有的buff,每个-1回合
for(let tbuffsIndex in buffs) {
let tbuff = buffs[tbuffsIndex];
//如果是 毒乱封眠(毒在 回合开始前 运行,乱封眠 在 行动开始前运行)
//毒
if(tbuff.flags & 0b1000) {
if(stage === 0) {
if(combatant.$properties.HP[0] > 0 && tbuff.buffAnimationEffect) {
--tbuff.round;
//毒 的 方法和参数
let gen = tbuff.buffAnimationEffect(combatant, tbuff);
for(let tg of gen)
yield tg;
}
}
}
//乱
if(tbuff.flags & 0b0100) {
if(stage === 1) {
if(combatant.$properties.HP[0] > 0 && tbuff.buffAnimationEffect) {
//乱 的 方法和参数
let gen = tbuff.buffAnimationEffect(combatant, tbuff);
for(let tg of gen)
yield tg;
}
}
else if(stage === 2)
--tbuff.round;
}
//封
if(tbuff.flags & 0b0010) {
if(stage === 1) {
if(combatant.$properties.HP[0] > 0 && tbuff.buffAnimationEffect) {
//封 的 方法和参数
let gen = tbuff.buffAnimationEffect(combatant, tbuff);
for(let tg of gen)
yield tg;
}
}
else if(stage === 2)
--tbuff.round;
}
//眠
if(tbuff.flags & 0b0001) {
if(stage === 1) {
if(combatant.$properties.HP[0] > 0 && tbuff.buffAnimationEffect) {
//眠 的 方法和参数
let gen = tbuff.buffAnimationEffect(combatant, tbuff);
for(let tg of gen)
yield tg;
}
}
else if(stage === 2)
--tbuff.round;
}
//其他
if(tbuff.flags & 0b10000) {
if(stage === 1) {
if(combatant.$properties.HP[0] > 0 && tbuff.buffAnimationEffect) {
//其他 的 方法和参数
let gen = tbuff.buffAnimationEffect(combatant, tbuff);
for(let tg of gen)
yield tg;
}
}
else if(stage === 2)
--tbuff.round;
}
//回合-1
//if(stage === 0)
// --tbuff.round;
//如果完毕,删除
if(tbuff.round <= 0) {
delete buffs[tbuffsIndex]; //删除
}
}
}
//检测 技能/攻击 是否可用(有4个阶段会调用:选择时、攻击时、敌人和我方遍历时);
//返回:true表示可以使用;字符串表示不能使用并提示的信息(只有选择时);
//stage为0表示选择时,为1表示选择某战斗角色(我方或敌方,此时targetCombatant不为null,其他情况为null),为10表示战斗中;
function $commonCheckSkill(fightSkill, combatant, targetCombatant, stage) {
let buffs = combatant.$$fightData.$buffs;