-
Notifications
You must be signed in to change notification settings - Fork 12
/
script-skill-parser.js
3555 lines (3420 loc) · 126 KB
/
script-skill-parser.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
let merge_skill = false;
const Attributes = {
/*0: "Fire",
1: "Water",
2: "Wood",
3: "Light",
4: "Dark",
5: "Heart",
6: "Jammer",
7: "Poison",
8: "MPoison",
9: "Bomb",*/
Fire: 0,
Water: 1,
Wood: 2,
Light: 3,
Dark: 4,
Heart: 5,
Jammer: 6,
Poison: 7,
MPoison: 8,
Bomb: 9,
}
Object.entries(Attributes).forEach(([name, oid])=>Attributes[oid] = name)
Attributes.all = function () {
return [
this.Fire,
this.Water,
this.Wood,
this.Light,
this.Dark
];
}
Attributes._6color = function () {
return [
this.Fire,
this.Water,
this.Wood,
this.Light,
this.Dark,
this.Heart
];
}
Attributes.orbs = function () {
return [
this.Fire,
this.Water,
this.Wood,
this.Light,
this.Dark,
this.Heart,
this.Jammer,
this.Poison,
this.MPoison,
this.Bomb,
];
}
//代码来自于 https://www.jianshu.com/p/3644833bca33
function isEqual(obj1,obj2) {
//判断是否是对象或数组
function isObject(obj) {
return typeof obj === 'object' && obj !== null;
}
// 两个数据有任何一个不是对象或数组
if (!isObject(obj1) || !isObject(obj2)) {
// 值类型(注意:参与equal的一般不会是函数)
return obj1 === obj2;
}
// 如果传的两个参数都是同一个对象或数组
if (obj1 === obj2) {
return true;
}
// 两个都是对象或数组,而且不相等
// 1.先比较obj1和obj2的key的个数,是否一样
const obj1Keys = Object.keys(obj1);
const obj2Keys = Object.keys(obj2);
if (obj1Keys.length !== obj2Keys.length) {
return false;
}
// 如果key的个数相等,就是第二步
// 2.以obj1为基准,和obj2依次递归比较
for (let key in obj1) {
// 比较当前key的value --- 递归
const res = isEqual(obj1[key], obj2[key]);
if (!res) {
return false;
}
}
// 3.全相等
return true
}
class Orb
{
attr = null;
//states = {
// enhanced: false, //强化
// locked: false, //锁定
// unmatchable: false, //禁止消除
//}
states = new Set();
constructor(attr = null)
{
this.attr = attr;
}
valueOf() {
return this.attr;
}
}
class Block
{
//states = {
// cloud: false, //云
// roulette: false, //轮盘变化
//}
states = new Set();
}
class BoardSet
{
boards = [];
boardsLabel = [];
node = (()=>{
const div = document.createElement("div");
div.className = "board-set";
return div;
})();
constructor(...boards) {
const boardSet = this;
boardSet.boards.push(...(boards.filter(board=>board instanceof Board)));
boardSet.boards.forEach((board, idx)=>{
boardSet.node.appendChild(board.tableNode);
const span = document.createElement("span");
span.dataset.columnCount = board.columnCount;
span.dataset.rowCount = board.rowCount;
boardSet.boardsLabel.push(span);
boardSet.node.appendChild(span);
if (idx > 0) {
board.tableNode.classList.add(className_displayNone);
}
});
const span = document.createElement("span");
span.className = "show-all-board";
span.onclick = function(){
boardSet.boards.forEach(board=>board.tableNode.classList.remove(className_displayNone));
this.classList.add(className_displayNone);
};
boardSet.node.appendChild(span);
}
valueOf() {
return this.node;
}
}
class Board
{
rowCount = 0;
columnCount = 0;
orbsData = [];
blocksData = [];
tableNode = document.createElement("table");
constructor(def = null, columnCount = 6, rowCount = 5)
{
const intAttr = typeof(def) == "number" ? def : void 0;
this.rowCount = Number(rowCount);
this.columnCount = Number(columnCount);
this.orbsData = new Array(this.rowCount);
this.blocksData = new Array(this.rowCount);
for (let ri=0; ri<this.rowCount; ri++)
{
const orbCol = new Array(this.columnCount), blockCol = new Array(this.columnCount);
for (let ci=0; ci<this.columnCount; ci++)
{
orbCol[ci] = new Orb(intAttr);
blockCol[ci] = new Block();
}
this.orbsData[ri] = orbCol;
this.blocksData[ri] = blockCol;
}
//如果传入的是数组,直接随机分布
if (Array.isArray(def))
{
this.randomFill(def);
}
const table = this.tableNode;
table.boardData = this;
table.className = "board";
for (let ri=0; ri<this.rowCount; ri++)
{
const row = table.insertRow();
for (let ci=0; ci<this.columnCount; ci++)
{
const cell = row.insertCell();
cell.className = "block";
const orbIcon = cell.appendChild(document.createElement('icon'));
orbIcon.className = "orb";
}
}
}
//获取指定行号
getTargetRowIndex(rowIndex)
{
switch (this.rowCount) {
case 6: return rowIndex >= 2 ? rowIndex + 1 : rowIndex;
case 4: return rowIndex >= 3 ? rowIndex - 1 : rowIndex;
case 5: default: return rowIndex;
}
}
//获取指定列号
getTargetColumnIndex(columnIndex)
{
switch (this.columnCount) {
case 7: return columnIndex >= 3 ? columnIndex + 1 : columnIndex;
case 5: return columnIndex >= 3 ? columnIndex - 1 : columnIndex;
case 6: default: return columnIndex;
}
}
setOrbAndBlock(orb, block, attr, state, blockState)
{
if (orb instanceof Orb) {
if (typeof(attr) == 'number' && !orb.states.has('locked'))
orb.attr = attr;
if (typeof(state) == 'string')
orb.states.add(state);
}
if (block instanceof Block && typeof(blockState) == 'string')
block.states.add(blockState);
}
//设定横行
setRows(rows, attr, state, blockState)
{
for (let ri of rows)
{
ri = this.getTargetRowIndex(ri);
const orbsRow = this.orbsData[ri], blocksRow = this.blocksData[ri];
for (let ci=0; ci<this.columnCount; ci++)
{
this.setOrbAndBlock(orbsRow[ci], blocksRow[ci], attr, state, blockState);
}
}
}
//设定竖列
setColumns(cols, attr, state, blockState)
{
for (let ci of cols)
{
ci = this.getTargetColumnIndex(ci);
for (let ri=0; ri<this.rowCount; ri++)
{
const orbsRow = this.orbsData[ri], blocksRow = this.blocksData[ri];
this.setOrbAndBlock(orbsRow[ci], blocksRow[ci], attr, state, blockState);
if (blockState == 'immobility') { //如果是封条,额外添加需要旋转的信息
this.setOrbAndBlock(orbsRow[ci], blocksRow[ci], attr, state, 'rotate');
}
}
}
}
//设定形状
setShape(matrix, attr, state, blockState)
{
//const setOrb = typeof(state) == 'number';
function fillRow(ri, inputRow)
{
const orbsRow = this.orbsData[ri], blocksRow = this.blocksData[ri];
for (let ci of inputRow)
{
ci = this.getTargetColumnIndex(ci);
if (this.columnCount >= 7 && ci == 4)
{
this.setOrbAndBlock(orbsRow[ci - 1], blocksRow[ci - 1], attr, state, blockState);
}
this.setOrbAndBlock(orbsRow[ci], blocksRow[ci], attr, state, blockState);
}
}
for (let i=0; i<matrix.length; i++)
{
let ri = this.getTargetRowIndex(i);
if (this.rowCount >= 6 && ri == 3)
{
fillRow.call(this, ri - 1, matrix[i]);
}
fillRow.call(this, ri, matrix[i]);
}
}
//洗版的填充
randomFill(attrs)
{
if (!Array.isArray(attrs) && typeof(attrs) == 'number')
attrs = [attrs];
//获得随机排列的数据
let attrArray = new Array(this.rowCount * this.columnCount);
//每种颜色至少3个
for (let i=0; i<attrs.length; i++) {
attrArray.fill(attrs[i], i * 3, (i + 1) * 3);
}
//随机填充剩下的
for (let i=attrs.length*3; i<attrArray.length; i++) {
attrArray[i] = attrs.length == 1 ?
attrs[0] :
attrs[Math.floor(Math.random() * attrs.length)];
}
attrArray.shuffle(); //整体随机分布一次
const flatOrbsData = this.orbsData.flat();
flatOrbsData.forEach((orb, idx)=>{
if (!orb.states.has('locked'))
orb.attr = attrArray[idx];
});
}
//生成珠子的填充
generateOrbs(attrs, count, exclude, state)
{
if (!Array.isArray(attrs) && typeof(attrs) == 'number')
attrs = [attrs];
if (!Array.isArray(exclude) && typeof(exclude) == 'number')
exclude = [exclude];
let flatOrbsData = this.orbsData.flat()
if (exclude?.length) flatOrbsData = flatOrbsData.filter(orb=>!exclude.includes(orb.attr));
flatOrbsData.shuffle(); //将所有排除的格子打乱
if (!state) { //未输入状态时,为产生珠子
const attrArray = attrs?.length ? attrs.map(attr=>new Array(count).fill(attr)).flat() : [];
//有属性时,使用产生珠子的长度;如果没有属性时,就保留1个长度,用来添加状态;但是都不能大于排除的宝珠数。
const maxLength = Math.min(attrArray.length, flatOrbsData.length);
//直接填充
for (let i=0; i<maxLength; i++) {
this.setOrbAndBlock(flatOrbsData[i], null, attrArray[i]);
}
} else {
//在板面上查询符合的颜色
flatOrbsData = flatOrbsData.filter(orb=>attrs.includes(orb.attr));
const maxLength = Math.min(count, flatOrbsData.length);
for (let i=0; i<maxLength; i++) {
this.setOrbAndBlock(flatOrbsData[i], null, null, state);
}
}
}
//生成板面状态
generateBlockStates(blockState, count = 1, size = [1,1], position = [0, 0])
{
for (let i=0; i<count; i++) {
let [width, height] = size, [x, y] = position;
if (!x) x = Math.randomInteger(this.columnCount - width); else x--;
if (!y) y = Math.randomInteger(this.rowCount - height); else y--;
for (let hi=0; hi<height; hi++) {
for (let wi=0; wi<width; wi++) {
this.setOrbAndBlock(null, this.blocksData[y+hi][x+wi], null, null, blockState);
}
}
}
}
//导出数组
valueOf()
{
return this.orbsData;
}
//输出表格
refreshTable()
{
const table = this.tableNode;
table.dataset.rowCount = this.rowCount;
table.dataset.columnCount = this.columnCount;
for (let ri=0; ri<this.rowCount; ri++)
{
const orbsRow = this.orbsData[ri], blocksRow = this.blocksData[ri];
const row = table.rows[ri];
for (let ci=0; ci<this.columnCount; ci++)
{
const cell = row.cells[ci], orbIcon = cell.querySelector("icon");
const orbObj = orbsRow[ci], blockObj = blocksRow[ci];
if (orbObj.attr != null)
orbIcon.setAttribute("data-orb-icon", orbObj.attr);
else
orbIcon.removeAttribute("data-orb-icon");
orbIcon.classList.add(...orbObj.states);
cell.classList.add(...blockObj.states);
}
}
return table;
}
}
const SkillValue = {
isLess: function (value) {
if (value.kind === SkillValueKind.Percent) return value.value < 1;
if (value.kind === SkillValueKind.Constant) return value.value < 0;
return false;
}
};
const SkillValueKind = {
Percent: 'mul',
Constant: 'const',
ConstantTo: 'const-to',
xMaxHP: 'mul-maxhp',
xHP: 'mul-hp',
xCHP: 'mul-chp',
xATK: 'mul-atk',
xRCV: 'mul-rcv',
RandomATK: 'random-atk',
HPScale: 'hp-scale',
xTeamHP: 'mul-team-hp',
xTeamATK: 'mul-team-atk',
xTeamRCV: 'mul-team-rcv',
xAwakenings: 'mul-awakenings',
};
const SkillPowerUpKind = {
Multiplier: 'mul',
ScaleAttributes: 'scale-attrs',
ScaleCombos: 'scale-combos',
ScaleMatchLength: 'scale-match-len',
ScaleMatchAttrs: 'scale-match-attrs',
ScaleCross: 'scale-cross',
ScaleRemainOrbs: 'scale-remain-orbs',
ScaleStateKind: 'scale-state-kind',
};
const SkillKinds = {
Error: "error",
Unknown: "unknown",
ActiveTurns: "active-turns",
DelayActiveTurns: "delay-active-turns",
DamageEnemy: "damage-enemy",
Vampire: "vampire",
ReduceDamage: "reduce-damage",
SelfHarm: "self-harm",
Heal: "heal",
AutoHealBuff: "auto-heal-buff",
ChangeOrbs: "change-orbs",
GenerateOrbs: "generate-orbs",
FixedOrbs: "fixed-orbs",
PowerUp: "power-up",
SlotPowerUp: "slot-power-up",
CounterAttack: "counter-attack",
SetOrbState: "set-orb-state",
RateMultiply: "rate-mul",
OrbDropIncrease: "orb-drop-incr",
Resolve: "resolve",
Delay: "delay",
DefenseBreak: "def-break",
MassAttack: "mass-attack",
BoardChange: "board-change",
Unbind: "unbind",
BindSkill: "bind-skill",
RandomSkills: "random-skills",
EvolvedSkills: "evolved-skills",
SkillProviso: "skill-proviso",
ChangeAttribute: "change-attr",
SkillBoost: "skill-boost",
AddCombo: "add-combo",
VoidEnemyBuff: "void-enemy-buff",
Poison: "poison",
CTW: "ctw",
Gravity: "gravity",
FollowAttack: "follow-attack",
FollowAttackFixed: "follow-attack-fixed",
AutoHeal: "auto-heal",
TimeExtend: "time-extend",
DropRefresh: "drop-refresh",
LeaderChange: "leader-change",
MinMatchLength: "min-match-len",
FixedTime: "fixed-time",
Drum: "drum",
AutoPath: "auto-path",
BoardSizeChange: "board-size-change",
NoSkyfall: "no-skyfall",
Henshin: "henshin",
VoidPoison: "void-poison",
SkillProviso: "skill-proviso",
ImpartAwakenings: "impart-awakenings",
ObstructOpponent: "obstruct-opponent",
IncreaseDamageCapacity: "increase-damage-cap",
BoardJammingStates: "board-jamming-states",
RemoveAssist: "remove-assist",
PredictionFalling: "prediction-falling",
BreakingShield: "breaking-shield",
PlayVoice: "play-voice",
}
function skillParser(skillId)
{
function merge(skills)
{
//主动技部分的合并
let activeTurns = skills.filter(skill=>skill.kind == SkillKinds.ActiveTurns);
if (activeTurns.length>1)
{ //把后面的全都合并到第一个
//按回合数拆分组
let diffTurnsGroup = activeTurns.groupBy((a,b)=>a.turns === b.turns);
let diffTurnsSkills = diffTurnsGroup.flatMap(group=>{
if (group.length>1) { //大于一个技能的可以合并
group[0].skills = group.flatMap(s=>s.skills);
// group.reduce((pre,cur)=>{
// pre.skills.push(...cur.skills);
// return pre
// });
let firstSkill = group.shift(); //从筛选中去除第一个
group.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
return [firstSkill];
} else { //1个技能的跳过
return group[0];
}
});
//进行具体技能效果的合并
diffTurnsSkills.forEach(turnsSkill=>{
//破吸部分的合并
let voidBuff = turnsSkill.skills.filter(skill=>skill.kind == SkillKinds.VoidEnemyBuff);
if (voidBuff.length>1)
{ //把后面的全都合并到第一个
voidBuff[0].buffs = voidBuff.flatMap(s=>s.buffs);
voidBuff.shift(); //从筛选中去除第一个
voidBuff.forEach(skill=>turnsSkill.skills.splice(turnsSkill.skills.indexOf(skill),1)); //去掉所有后面的
}
});
}
//解封部分的合并
let unbinds = skills.filter(skill=>skill.kind == SkillKinds.Unbind);
if (unbinds.length>1)
{ //把后面的全都合并到第一个
unbinds.reduce((pre,cur)=>{
pre.normal = pre.normal || cur.normal;
pre.awakenings = pre.awakenings || cur.awakenings;
pre.matches = pre.matches || cur.matches;
return pre
});
unbinds.shift(); //从筛选中去除第一个
unbinds.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
}
let fixedDamages = skills.filter(skill=>skill.kind == SkillKinds.DamageEnemy && skill.attr === 'fixed').filter((skill,idx,arr)=>skill.id==arr[0].id);
if (fixedDamages.length>1)
{ //把后面的全都合并到第一个
fixedDamages[0].times = fixedDamages.length;
fixedDamages.shift(); //从筛选中去除第一个
fixedDamages.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
}
let skillPowerUp = skills.filter(skill=>skill.kind == SkillKinds.PowerUp);
if (skillPowerUp.length > 1 || (skillPowerUp[0] && skillPowerUp[0]?.value?.kind === SkillPowerUpKind.ScaleCross))
{
//合并技能效果
function combinePowerUp(target, source) {
if (source?.additional.length)
{
if (!Array.isArray(target.additional)) target.additional = [];
target.additional.push(...source.additional);
}
if (source.reduceDamage != undefined)
{
if (!target.reduceDamage)
target.reduceDamage = source.reduceDamage;
else if (target.reduceDamage.kind === source.reduceDamage.kind)
target.reduceDamage.value *= source.reduceDamage.value;
}
if (target?.value.baseAtk != undefined && source?.value.baseAtk) target.value.baseAtk *= source.value.baseAtk;
if (target?.value.baseRcv != undefined && source?.value.baseRcv != undefined) target.value.baseRcv *= source.value.baseRcv;
if (target?.value.bonusAtk != undefined && source?.value.bonusAtk != undefined) target.value.bonusAtk += source.value.bonusAtk;
if (target?.value.bonusRcv != undefined && source?.value.bonusRcv != undefined) target.value.bonusRcv += source.value.bonusRcv;
if (target?.value.atk != undefined && source?.value.atk != undefined) target.value.atk *= source.value.atk;
if (target?.value.hp != undefined && source?.value.hp != undefined) target.value.hp *= source.value.hp;
if (target?.value.rcv != undefined && source?.value.rcv != undefined) target.value.rcv *= source.value.rcv;
}
//十字
let scaleCross = skillPowerUp.filter(skill=>skill.value.kind === SkillPowerUpKind.ScaleCross);
function mergeScaleCrossAttr(skill)
{
let crosses = skill.value.crosses;
let atk = crosses[0].atk;
let rcv = crosses[0].rcv;
if (crosses.length >= 2 &&
crosses.every(cross=>cross.atk === atk && cross.rcv === rcv)
) {
crosses[0].attr = Array.from(new Set(crosses.reduce((pre,cur)=>{
pre.push(...cur.attr);
return pre;
}, [])));
skill.value.crosses.splice(1);
}
}
//每个十字技能,先把所有属性合并到自身
scaleCross.forEach(mergeScaleCrossAttr);
//筛选出所有倍率一样的子技能
scaleCross = scaleCross.filter((skill,idx,arr)=>{
let atk = arr[0].value.crosses[0].atk;
let rcv = arr[0].value.crosses[0].rcv;
let crosses = skill.value.crosses;
return crosses.every(cross=>cross.atk === atk && cross.rcv === rcv);
});
//先合并属性倍率
if (scaleCross.length >= 1)
{ //把后面的全都合并到第一个
scaleCross.reduce((pre,cur)=>{
combinePowerUp(pre,cur);
pre.value.crosses = pre.value.crosses.concat(cur.value.crosses);
return pre
});
let _skill = scaleCross.shift(); //从筛选中去除第一个
scaleCross.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
mergeScaleCrossAttr(_skill);
}
//重新找出来十字,合并附加内容
scaleCross = skills.filter(skill=>skill.kind == SkillKinds.PowerUp && skill.value.kind === SkillPowerUpKind.ScaleCross);
scaleCross = scaleCross.filter((skill,idx,arr)=>{
let s0 = arr[0];
let attr0 = s0.value.crosses[0].attr.concat().sort();
let attr1 = skill.value.crosses[0].attr.concat().sort();
return isEqual(skill.condition, s0.condition) &&
isEqual(skill.attrs, s0.attrs) &&
isEqual(skill.types, s0.types) &&
isEqual(attr0, attr1)
;
});
if (scaleCross.length > 1)
{ //把后面的全都合并到第一个
scaleCross.reduce((pre,cur)=>{
combinePowerUp(pre, cur);
return pre
});
scaleCross.shift(); //从筛选中去除第一个
scaleCross.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
}
//长串匹配
let scaleMatchLength = skillPowerUp.filter(skill=>skill.value.kind === SkillPowerUpKind.ScaleMatchLength);
scaleMatchLength = scaleMatchLength.groupBy((a,b)=>{
let av = a.value;
let bv = b.value;
return isEqual(a.condition, b.condition) &&
isEqual(a.attrs, b.attrs) &&
isEqual(a.types, b.types) &&
av.min === bv.min &&
av.max === bv.max &&
(av.matchAll === bv.matchAll || av.attrs.length <= 1) && isEqual(av.attrs, bv.attrs)
;
});
for (let group of scaleMatchLength)
{
if (group.length > 1)
{ //把后面的全都合并到第一个
group.reduce((pre,cur)=>{
combinePowerUp(pre, cur);
return pre
});
group.shift(); //从筛选中去除第一个
group.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
}
}
//多串匹配
let scaleMatchAttrs = skillPowerUp.filter(skill=>skill.value.kind === SkillPowerUpKind.ScaleMatchAttrs);
scaleMatchAttrs = scaleMatchAttrs.filter((skill,idx,arr)=>{
let s0 = arr[0];
let v0 = s0.value;
let v1 = skill.value;
return isEqual(skill.condition, s0.condition) &&
isEqual(skill.attrs, s0.attrs) &&
isEqual(skill.types, s0.types) &&
v0.min === v1.min &&
v0.max === v1.max &&
isEqual(v0.matches, v1.matches)
;
});
if (scaleMatchAttrs.length > 1)
{ //把后面的全都合并到第一个
scaleMatchAttrs.reduce((pre,cur)=>{
combinePowerUp(pre, cur);
return pre
});
scaleMatchAttrs.shift(); //从筛选中去除第一个
scaleMatchAttrs.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
}
//多色匹配
let scaleAttributes = skillPowerUp.filter(skill=>skill.value.kind === SkillPowerUpKind.ScaleAttributes);
scaleAttributes = scaleAttributes.filter((skill,idx,arr)=>{
let s0 = arr[0];
let v0 = s0.value;
let v1 = skill.value;
return isEqual(skill.condition, s0.condition) &&
isEqual(skill.attrs, s0.attrs) &&
isEqual(skill.types, s0.types) &&
v0.min === v1.min &&
v0.max === v1.max &&
isEqual(v0.attrs, v1.attrs)
;
});
if (scaleAttributes.length > 1)
{ //把后面的全都合并到第一个
scaleAttributes.reduce((pre,cur)=>{
combinePowerUp(pre, cur);
return pre
});
scaleAttributes.shift(); //从筛选中去除第一个
scaleAttributes.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
}
//连击数
let scaleCombos = skillPowerUp.filter(skill=>skill.value.kind === SkillPowerUpKind.ScaleCombos);
scaleCombos = scaleCombos.filter((skill,idx,arr)=>{
let s0 = arr[0];
let v0 = s0.value;
let v1 = skill.value;
return isEqual(skill.condition, s0.condition) &&
isEqual(skill.attrs, s0.attrs) &&
isEqual(skill.types, s0.types) &&
v0.min === v1.min &&
v0.max === v1.max
;
});
if (scaleCombos.length > 1)
{ //把后面的全都合并到第一个
scaleCombos.reduce((pre,cur)=>{
combinePowerUp(pre, cur);
return pre
});
scaleCombos.shift(); //从筛选中去除第一个
scaleCombos.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
}
//普通倍率
let multiplier = skillPowerUp.filter(skill=>skill.value.kind === SkillPowerUpKind.Multiplier
&& skill.condition?.LShape);
multiplier = multiplier.filter((skill,idx,arr)=>{
let s0 = arr[0];
return !!skill.condition && isEqual(skill.condition, s0.condition) &&
isEqual(skill.attrs, s0.attrs) &&
isEqual(skill.types, s0.types)
;
});
if (multiplier.length)
{ //把后面的全都合并到第一个
multiplier.reduce((pre,cur)=>{
combinePowerUp(pre, cur);
return pre
});
multiplier.shift(); //从筛选中去除第一个
multiplier.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
}
}
let changeOrbs = skills.filter(skill=>skill.kind == SkillKinds.ChangeOrbs);
if (changeOrbs.length>1)
{ //把后面的全都合并到第一个
changeOrbs.reduce((pre,cur)=>{
pre.changes.push(...cur.changes);
return pre
});
changeOrbs.shift(); //从筛选中去除第一个
changeOrbs.forEach(skill=>skills.splice(skills.indexOf(skill),1)); //去掉所有后面的
}
return skills;
}
const skill = Skills[skillId];
if (!skill) return [];
//此处用apply将这个parser传递到后面解析函数的this里,用于递归解析
const result = skillObjectParsers?.[skill.type]?.apply({ parser: skillParser }, skill.params)
?? { kind: SkillKinds.Unknown }; //没有时返回未知技能
let skills = (Array.isArray(result) ? result : [result]) //确保技能是数组
.filter(Boolean) //去除无效技能
.map(s => ({ id: skillId, type: skill.type, params: skill.params, ...s })); //额外增加技能id、type、原始参数
function splitProvisoSkill(skills)
{
let idx = skills.findIndex(skill=>skill.kind == SkillKinds.SkillProviso); //搜索HP、层数限制技能的位置
if (idx>=0) //如果找到,就拆分成3份
{
return [
skills.slice(0,idx),
skills.slice(idx, idx+1),
skills.slice(idx+1),
];
}else
{
return [skills];
}
}
//技能原始对象的合并,技能显示效果的合并在“function renderSkillEntry”里
if (merge_skill)
{
//将技能拆分成3部分后分别合并技能
let skillsSplit = splitProvisoSkill(skills).map(_skills=>merge(_skills));
//再展平,重新回到一层技能
skills = skillsSplit.flat(1);
}
return skills;
}
const v = {
percent: function(value) {
return { kind: SkillValueKind.Percent, value: (value / 100) ?? 1 };
},
constant: function(value) {
return { kind: SkillValueKind.Constant, value: value ?? 0 };
},
constantTo: function(value) {
return { kind: SkillValueKind.ConstantTo, value: value ?? 1 };
},
xMaxHP: function(value) {
return { kind: SkillValueKind.xMaxHP, value: (value / 100) ?? 1 };
},
xHP: function(value) {
return { kind: SkillValueKind.xHP, value: (value / 100) ?? 1 };
},
xCHP: function(value) {
return { kind: SkillValueKind.xCHP, value: (value / 100) ?? 1 };
},
xShield: function(value) {
return { kind: SkillValueKind.xShield, value: (value / 100) ?? 1 };
},
xATK: function(value) {
return { kind: SkillValueKind.xATK, value: (value / 100) ?? 1 };
},
xRCV: function(value) {
return { kind: SkillValueKind.xRCV, value: (value / 100) ?? 1 };
},
randomATK: function(min, max) {
return { kind: SkillValueKind.RandomATK, min: (min / 100) ?? 1, max: (max / 100) ?? 1, scale: 1 };
},
hpScale: function(min, max, scale) {
return { kind: SkillValueKind.HPScale, min: (min / 100) ?? 1, max: (max / 100) ?? 1, scale: (scale / 100) ?? 1 };
},
xTeamHP: function(value) {
return { kind: SkillValueKind.xTeamHP, value: (value / 100) ?? 1 };
},
xTeamATK: function(attrs, value) {
return { kind: SkillValueKind.xTeamATK, attrs: attrs, value: (value / 100) ?? 1 };
},
xTeamRCV: function(value) {
return { kind: SkillValueKind.xTeamRCV, value: (value / 100) ?? 1 };
},
percentAwakenings: function(awakenings, value) {
return { kind: SkillValueKind.xAwakenings, awakenings: awakenings, value: value };
},
};
const c = {
hp: function (min, max) {
return { hp: { min: min / 100, max: max / 100 } };
},
exact: function (type, value, attrs, multiple = false) {
if (attrs === void 0) { attrs = Attributes.all(); }
return { exact: { type: type, value: value, attrs: attrs, multiple: multiple} };
},
combos: function (min) {
return { combos: { min } };
},
attrs: function (attrs, min) {
return { attrs: { attrs, min} };
},
compo: function (type, ids) {
return { compo: { type: type, ids: ids } };
},
remainOrbs: function (count) { return { remainOrbs: { count: count } }; },
useSkill: function () { return { useSkill: true }; },
multiplayer: function () { return { multiplayer: true }; },
prob: function (percent) { return { prob: percent }; },
LShape: function (attrs) { return { LShape: { attrs: attrs } }; },
heal: function (min) { return { heal: { min: min } }; },
stage: function (min, max) {
return { stage: { min: min ?? 0, max: max ?? 0 } };
},
remainAttrOrbs: function (attrs, min, max) {
return { remainAttrOrbs: { attrs, min, max} };
},
}
const p = {
mul: function (values) {
if (Array.isArray(values)) {
return {
kind: SkillPowerUpKind.Multiplier,
hp: 1,
atk: values[0] / 100,
rcv: values[1] / 100
};
}
else {
return {
kind: SkillPowerUpKind.Multiplier,
hp: (values.hp ?? 100) / 100,
atk: (values.atk ?? 100) / 100,
rcv: (values.rcv ?? 100) / 100
};
}
},
stats: function (value) {
let statTypes = Array.from(arguments).slice(1);
return [
statTypes.indexOf(1) >= 0 ? value : 100,
statTypes.indexOf(2) >= 0 ? value : 100
];
},
scale: function (min, max, baseMul, bonusMul) {
return {
min: min,
max: max ?? min,
baseAtk: (baseMul[0] / 100) ?? 1,
baseRcv: (baseMul[1] / 100) ?? 1,
bonusAtk: (bonusMul[0] / 100) ?? 0,
bonusRcv: (bonusMul[1] / 100) ?? 0
};
},
scaleAttrs: function (attrs, min, max, baseMul, bonusMul) {
return { kind: SkillPowerUpKind.ScaleAttributes, attrs: attrs ,...this.scale(min, max, baseMul, bonusMul) };
},
scaleCombos: function (min, max, baseMul, bonusMul) {
return { kind: SkillPowerUpKind.ScaleCombos ,...this.scale(min, max, baseMul, bonusMul) };
},
scaleMatchLength: function (attrs, min, max, baseMul, bonusMul, matchAll = false) {
return { kind: SkillPowerUpKind.ScaleMatchLength, attrs, matchAll,...this.scale(min, max, baseMul, bonusMul) };
},
scaleMatchAttrs: function (matches, min, max, baseMul, bonusMul) {
const flatMatches = matches.flat(); //当匹配的全是不同颜色时,切换成匹配颜色的技能
if (new Set(flatMatches).size === flatMatches.length)
return this.scaleAttrs(matches, min, max, baseMul, bonusMul);
else
return { kind: SkillPowerUpKind.ScaleMatchAttrs, matches: matches ,...this.scale(min, max, baseMul, bonusMul) };
},
scaleCross: function (crosses) {
return { kind: SkillPowerUpKind.ScaleCross, crosses: crosses.map(cross => ({ ...cross, atk: ((cross.atk ?? 100) / 100), rcv: ((cross.rcv ?? 100) / 100)})) };
},
scaleRemainOrbs: function (max, baseMul, bonusMul) {
return { kind: SkillPowerUpKind.ScaleRemainOrbs ,...this.scale(bonusMul ? 0 : max, max, baseMul, bonusMul) };
},
scaleStateKind: function (awakenings, attrs, types, value) {
return { kind: SkillPowerUpKind.ScaleStateKind, awakenings: awakenings, attrs: attrs, types: types, value: value };
},
scaleMatchLengthTimes: function (attrs, min, exact, bonusMul) {
return { kind: SkillPowerUpKind.ScaleMatchLengthTimes, attrs, min, exact, bonusMul };
},
}
function activeTurns(turns, ...skills) {
return skills.length ? { kind: SkillKinds.ActiveTurns, turns, skills } : null;
}
function delayActiveTurns(turns, ...skills) {
return skills.length ? { kind: SkillKinds.DelayActiveTurns, turns, skills } : null;
}
function damageEnemy(target, attr, damage) {
return { kind: SkillKinds.DamageEnemy, target, attr, damage };
}
function vampire(attr, damageValue, healValue) {
return { kind: SkillKinds.Vampire, attr: attr, damage: damageValue, heal: healValue };
}
function reduceDamage(attrs, percent, condition, prob) {
return { kind: SkillKinds.ReduceDamage, attrs: attrs, percent: percent, condition: condition, prob: prob || 1 };
}
function selfHarm(value) {
return { kind: SkillKinds.SelfHarm, value: value };
}
function heal(value) {
return { kind: SkillKinds.Heal, value: value };
}
function autoHealBuff(value) {
return { kind: SkillKinds.AutoHealBuff, value: value };
}
function fromTo(from, to) {
return { from: from, to: to };
}
function changeOrbs(...changes) {
return { kind: SkillKinds.ChangeOrbs, changes: changes };
}
function generateOrbs(orbs, exclude, count, time) {
return { kind: SkillKinds.GenerateOrbs, orbs: orbs, exclude: exclude, count: count, time: time};
}
function fixedOrbs(...generates) {
return { kind: SkillKinds.FixedOrbs, generates: generates };
}
function powerUp(attrs, types, value, condition = null, reduceDamage = null, additional = [], eachTime = false) {
let targets = attrs?.targets;
if (targets) {attrs = null; types = null;}
return { kind: SkillKinds.PowerUp, targets, attrs, types, condition, value, reduceDamage, additional, eachTime};
}
function slotPowerUp(value, targets) {
return { kind: SkillKinds.SlotPowerUp, value, targets};
}
function counterAttack(attr, prob, value) {
return { kind: SkillKinds.CounterAttack, attr: attr, prob: prob, value: value };
}
function setOrbState(orbs, state, arg) {
return { kind: SkillKinds.SetOrbState, orbs, state, arg};
}
function rateMultiply(value, rate) {
return { kind: SkillKinds.RateMultiply, value: value, rate: rate };
}
function orbDropIncrease(prob, attrs, flag, value) {