/
Card.js
1870 lines (1761 loc) · 55.4 KB
/
Card.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
'use strict';
function Card (game,player,zone,pid,side) {
// 引用
this.game = game;
this.player = player;
this.owner = player;
this.zone = zone;
// 状态
this.isFaceup = false;
this.isUp = true;
// 注册
this.game.register(this);
this.game.cards.push(this);
var cid = CardInfo[pid].cid;
var info = CardInfo[cid];
// 基本数据
this.pid = pid;
this._info = info;
this.cid = info.cid;
this.name = info.name;
this.resona = (info.cardType === 'RESONA');
this.type = this.resona? 'SIGNI' : info.cardType;
this.color = info.color.split('/')[0];
this.otherColors = info.color.split('/').slice(1);
this.limitings = info.limiting? info.limiting.split('/') : [];
this.limit = info.limit;
this.level = info.level;
this.power = info.power;
this.classes = info.classes;
this.guardFlag = info.guardFlag;
this.costWhite = info.costWhite;
this.costBlack = info.costBlack;
this.costRed = info.costRed;
this.costBlue = info.costBlue;
this.costGreen = info.costGreen;
this.costColorless = info.costColorless;
this.costCoin = info.costCoin;
this.costAsyn = info.costAsyn;
this.costChange = info.costChange;
this.costChangeAsyn = info.costChangeAsyn;
this.costChangeAfterChoose = info.costChangeAfterChoose;
this.multiEner = info.multiEner;
this.burstIcon = !!info.burstEffect;
this.useCondition = info.useCondition;
this.growCondition = info.growCondition;
this.growActionAsyn = info.growActionAsyn;
this.beforeSummonAsyn = info.beforeSummonAsyn;
// 效果相关的数据
this.getMinEffectCount = info.getMinEffectCount;
this.getMaxEffectCount = info.getMaxEffectCount;
// 魔法效果
this.spellEffects = this.cookEffect(info.spellEffect,'spell',1);
// 技艺效果
this.timmings = info.timmings || [];
this.artsEffects = this.cookEffect(info.artsEffect,'arts',1);
this.encore = info.encore || null;
this.chain = info.chain || null;
this.beforeUseAsyn = info.beforeUseAsyn || null;
// 生命迸发效果
this.burstEffects = this.cookEffect(info.burstEffect,'burst');
// 常时效果(因为内容会被修改,这里用 Object.create 创建不同的引用)
this.constEffects = (info.constEffects || []).map(function (constEffect) {
return Object.create(constEffect)
},this);
// 出场效果
this.startUpEffects = this.cookEffect(info.startUpEffects,'startup');
// 起动效果
this.actionEffects = this.cookEffect(info.actionEffects,'action');
// 是否白板
this.withAbility = !!(this.burstEffects.length ||
this.constEffects.length ||
this.startUpEffects.length ||
this.actionEffects.length ||
this.multiEner ||
this.guardFlag);
// 共鸣相关
this.resonaPhases = concat(info.resonaPhase || []);
this.resonaCondition = info.resonaCondition;
this.resonaAsyn = null;
// CROSS相关
this.crossLeft = info.crossLeft || null;
this.crossRight = info.crossRight || null;
this.crossIcon = !!(info.crossLeft || info.crossRight);
this.crossed = null;
// 双面
if (side) {
this.sideA = info.sideA? side : null;
this.sideB = info.sideB? side : null;
} else {
this.sideA = info.sideA? new Card(game,player,zone,info.sideA,this) : null;
this.sideB = info.sideB? new Card(game,player,zone,info.sideB,this) : null;
}
// Lostorage
this.coin = info.coin || 0;
this.bet = info.bet || 0;
this.betAdvancedAsyn = info.betAdvancedAsyn || null;
this.bettedCost = info.bettedCost || null;
this.rise = info.rise;
this.acce = !!info.acce;
this.acceingCard = null;
this.maxAcceCount = 1;
this.trap = info.trap || null;
this.shadow = false;
this.layer = !!info.layer;
this.layerMarks = [];
// 杂项
this.effectFilters = [];
this.registeredEffects = [];
this.charm = null; // 魅饰卡
this._data = null; // 私有的数据储存,约定: 只能在 CardInfo.js 自身的代码里访问
this.fieldData = {}; // 离场即清空的数据
this.fieldTurnData = {}; // 离场或回合结束即清空的数据
// 时点
this.onMove = new Timming(game);
this.onEnterField = new Timming(game);
this.onLeaveField = new Timming(game); // 常时效果中「离场时」的时点
this.onLeaveField2 = new Timming(game); // 包括被 rise 等而成为卡垫的时点
this.onBurst = new Timming(game);
this.onAttack = new Timming(game);
this.onStartUp = new Timming(game);
this.onPowerChange = new Timming(game);
this.onPowerUpdate = new Timming(game);
this.onBanish = new Timming(game);
this.onAffect = new Timming(game);
this.onUp = new Timming(game);
this.onDown = new Timming(game);
this.onBattle = new Timming(game);
this.onHeaven = new Timming(game);
this.onFreeze = new Timming(game);
this.onChangeSigniZone = new Timming(game);
this.onRised = new Timming(game);
this.onAcced = new Timming(game);
// 附加的属性
this.canNotAttack = false;
this.mustAttack = false;
this.lancer = false;
this.doubleCrash = false;
this.tripleCrash = false;
this.frozen = false;
this.forceSummonZone = false;
this.trashCharmInsteadOfBanish = false;
this.attachedCostColorless = 0; // <星占之巫女 忆·夜>
this.assassin = false;
this.canNotBeBanished = false;
this.abilityLost = false;
this.canNotBeBanishedByEffect = false;
this.canNotBeBouncedByEffect = false;
this.protectingShironakujis = []; // <幻水 蓝鲸>
this.protectingMpps = []; // <コードハート M・P・P>
this.useBikouAsWhiteCost = false; // <启示的天惠 安=FORTH>
this.canNotBeTrashedBySelf = false; // <罗星 星宿一>
this.trashAsWhiteCost = false; // <美しき弦奏 コントラ>
this.summonConditions = []; // <罠砲 タイマーボム>
this._OrichalciaNaturalStone = false; // <罗石 金铜>
this._KosakiPhantomBeast = false; // <幻兽 小御先>
this._MikamuneSmallSword = false; // <小剑 三日月>
this.resonaBanishToTrash = false; // <绿叁游 水滑梯>
this.discardSpellInsteadOfBanish = false; // <核心代号 S・W・T>
this.attackCostColorless = 0; // <黑幻虫 水熊虫>
this.canNotGainAbility = false; // <迷宫代号 金阁>
this.canNotGainAbilityBySelfPlayer = false; // <城堡代号 凡尔赛宫>
this._SnoropNaturalPlantPrincess = false; // <罗植姬 雪花莲>
this._CodeLabyrinthLouvre = null; // <卢浮宫>
this.powerAddProtected = false; // <幻兽 苍龙>
this.powerDecreaseProtected = false; // PR-360
this._GustaftCenterBallista = false; // <弩中砲 グスタフト>
this.colorLost = false; // <侍从 ∞>
this.banishProtections = [];
this.upProtections = [];
this.canAttackAnySigniZone = false;
this.canAttackNearbySigniZone = false;
this.disableBurst = false;
// 注意hasAbility
}
Card.abilityProps = [
'canNotAttack',
'lancer',
'doubleCrash',
'tripleCrash',
'assassin',
'canNotBeBanished',
'canNotBeBanishedByEffect',
'canAttackAnySigniZone',
'canAttackNearbySigniZone',
'trap',
'layer',
];
var mixins = {
acce: {
activatedInEnerZone: true,
useCondition: function () {
return this.player.signis.some(function (signi) {
return signi.canBeAcced();
},this);
},
costChange: function () {
var player = this.source.player;
var obj = Object.create(this);
obj.costChange = null;
var flag = player.signis.some(function (signi) {
return signi.canBeAcced() && signi._2313;
},this);
if (flag) {
obj.costGreen -= 1;
if (obj.costGreen < 0) obj.costGreen = 0;
}
return obj;
},
costChangeAsyn: function () {
var player = this.source.player;
var cost = Object.create(this);
cost.costChange = null;
var reducedCost = Object.create(this);
reducedCost.costGreen -= 1;
if (reducedCost.costGreen < 0) reducedCost.costGreen = 0;
var cards = player.signis.filter(function (signi) {
return signi.canBeAcced();
},this);
if (!player.enoughCost(cost)) {
cards = cards.filter(function (signi) {
return signi._2313;
},this);
}
return player.selectTargetAsyn(cards).callback(this,function (card) {
this.source._data = card;
return (card && card._2313) ? reducedCost : cost;
});
},
actionAsyn: function () {
if (!this._data) return;
this.acceTo(this._data);
},
},
};
Card.prototype.cookEffect = function (rawEffect,type,offset) {
if (!offset) offset = 0;
return concat(rawEffect || []).map(function (eff,idx) {
var effect = Object.create(eff);
effect.source = this;
effect.description = [this.cid,type,idx+offset].join('-');
if (eff.mixin) {
var mixin = mixins[eff.mixin];
for(var prop in mixin) {
effect[prop] = mixin[prop];
}
}
return effect;
},this);
};
Card.prototype.setupConstEffects = function () {
var layerMark = this.gid;
if (this.layer) {
this.game.addConstEffect({
source: this,
createTimming: this.onEnterField,
once: false,
destroyTimming: this.onLeaveField2,
action: function (set,add) {
this.player.signis.forEach(function (signi) {
if (signi.hasClass('怪異')) {
add(signi,'layerMarks',layerMark);
}
});
},
},true);
}
this.constEffects.forEach(function (eff,idx) {
var createTimming,destroyTimming,once;
if (eff.duringGame) {
createTimming = null;
destroyTimming = null;
once = false;
} else if (eff.getCreateTimming) {
createTimming = eff.getCreateTimming.call(this);
destroyTimming = eff.getDestroyTimming.call(this);
once = eff.once;
} else {
createTimming = this.onEnterField;
destroyTimming = this.onLeaveField2;
once = false;
}
var action = eff.action
if (eff.auto) {
// 对于【自】效果,自动添加效果源和效果描述。
var options = Object.create(eff.effect);
if (!options.source) options.source = this;
if (!options.description) options.description = this.cid+'-'+'const-'+idx;
// CardInfo 中提供的是效果描述,而这里创建为效果实例,
// 并暴露在 card.constEffects[i].effect 上,供<験英の応援 #ゴウカク#>之类的效果获取。
var effect = this.game.newEffect(options);
eff.effect = effect;
if (isStr(eff.auto)) {
action = function (set,add) {
add(this,eff.auto,effect);
};
} else {
action = function (set,add) {
eff.auto.call(this,add,effect);
};
}
}
this.game.addConstEffect({
source: this,
createTimming: createTimming,
once: once,
destroyTimming: destroyTimming,
cross: !!eff.cross,
wisdom: eff.wisdom,
fixed: !!eff.fixed,
condition: eff.condition,
action: action,
},true);
if (eff.layer) {
this.player.mainDeck.cards.forEach(function (signi) {
if (signi === this) return;
if (!signi.hasClass('怪異')) return;
this.game.addConstEffect({
source: signi,
createTimming: signi.onEnterField,
once: true,
destroyTimming: signi.onLeaveField2,
cross: false,
wisdom: false,
fixed: false,
condition: function () {
return inArr(layerMark,this.layerMarks) && (!eff.condition || eff.condition.call(this));
},
action: eff.action,
},true);
},this);
}
},this);
};
Card.prototype.setupStartUpEffects = function () {
this.startUpEffects.forEach(function (eff) {
if (this.type === 'SIGNI') {
if (eff.cross) {
eff.condition = function () {
return this.crossed && inArr(this,this.player.signis);
};
} else {
eff.condition = function () {
return inArr(this,this.player.signis);
};
}
}
var effect = new Effect(this.game.effectManager,eff);
this.game.addConstEffect({
source: this,
fixed: true,
action: function (set,add) {
add(this,'onStartUp',effect);
}
},true);
},this);
};
Card.prototype.setupBurstEffects = function () {
this.burstEffects.forEach(function (eff) {
eff.optional = true;
var effect = new Effect(this.game.effectManager,eff);
this.game.addConstEffect({
source: this,
fixed: true,
action: function (set,add) {
add(this,'onBurst',effect);
}
},true);
},this);
};
Card.prototype.setupEffects = function () {
this.setupConstEffects();
this.setupStartUpEffects();
this.setupBurstEffects();
};
Card.prototype.canGrow = function (ignoreCost) {
if (this.type !== 'LRIG') return false;
if (this.player.canNotGrow) return false;
if (this.cid === this.player.lrig.cid) return false;
if (this.growCondition) {
if (!this.growCondition()) {
return false;
}
}
if (!ignoreCost && !this.player.enoughCost(this.getGrowCostObj())) return false;
// LRIG type
if (this.classes.every(function (cls) {
return !this.player.lrig.hasClass(cls) && (cls !== '?'); // <紡ぐ者>
},this)) {
return false;
}
return (this.level <= this.player.lrig.level+1);
};
Card.prototype.getGrowCostObj = function () {
var obj = Object.create(this);
obj.costWhite -= this.player.reducedGrowCostWhite;
obj.costBlack -= this.player.reducedGrowCostBlack;
obj.costRed -= this.player.reducedGrowCostRed;
obj.costBlue -= this.player.reducedGrowCostBlue;
obj.costGreen -= this.player.reducedGrowCostGreen;
obj.costColorless -= this.player.reducedGrowCostColorless;
if (obj.costWhite < 0) obj.costWhite = 0;
if (obj.costBlack < 0) obj.costBlack = 0;
if (obj.costRed < 0) obj.costRed = 0;
if (obj.costBlue < 0) obj.costBlue = 0;
if (obj.costGreen < 0) obj.costGreen = 0;
if (obj.costColorless < 0) obj.costColorless = 0;
return obj;
};
Card.prototype.getChainedCostObj = function (obj) {
if (!obj) {
obj = Object.create(this);
}
if (!this.player.chain) return obj;
obj.costWhite -= this.player.chain.costWhite || 0;
obj.costBlack -= this.player.chain.costBlack || 0;
obj.costRed -= this.player.chain.costRed || 0;
obj.costBlue -= this.player.chain.costBlue || 0;
obj.costGreen -= this.player.chain.costGreen || 0;
obj.costColorless -= this.player.chain.costColorless || 0;
if (obj.costWhite < 0) obj.costWhite = 0;
if (obj.costBlack < 0) obj.costBlack = 0;
if (obj.costRed < 0) obj.costRed = 0;
if (obj.costBlue < 0) obj.costBlue = 0;
if (obj.costGreen < 0) obj.costGreen = 0;
if (obj.costColorless < 0) obj.costColorless = 0;
return obj;
};
Card.prototype.canSummon = function () {
return this.canSummonWith(this.player.signis);
};
Card.prototype.canSummonWith = function (signis) {
// 类型
if (this.type !== 'SIGNI') return false;
// rise
var riseTargets = []
if (this.rise) {
riseTargets = signis.filter(function (signi) {
return this.rise(signi)
},this)
if (!riseTargets.length) return false;
}
// <绿罗植 世界树>
if (this.player.canNotUseColorlessSigni) {
if (this.hasColor('colorless')) {
return false;
}
}
// summonConditions
var flag = this.summonConditions.some(function (condition) {
return !condition.call(this);
},this);
if (flag) return false;
// 限定
if (!this.checkLimiting()) return false;
// 等级限制
if (this.level > this.player.lrig.level) return false;
// SIGNI 数量限制
var length = signis.length;
if (this.rise) length--;
if (length >= this.player.getSigniAmountLimit()) {
return false;
}
// 界限限制
var totalLevel = signis.reduce(function (total,signi) {
return total + signi.level;
},this.level);
if (this.rise) {
// rise 减去等级最高的目标即可
totalLevel -= Math.max.apply(Math,riseTargets.map(function (signi) {
return signi.level;
}));
}
if (totalLevel > this.player.lrig.limit) return false;
// 召唤区限制
var zones = this.player.getSummonZones(signis,this.rise);
if (!zones.length) return false;
// 结束
return true;
};
Card.prototype.getSummonSolution = function (filter,count) {
var cards = this.player.signis.filter(function (card) {
return filter(card) && card.canTrashAsCost();
},this);
// 选项不足
if (cards.length < count) return null;
// 必须全选
if (this.player.signis.length === count) {
if (!this.canSummonWith([])) return null;
return function () {
return Callback.immediately().callback(this,function () {
var signis = this.player.signis.slice();
this.game.trashCards(signis);
return signis;
});
}.bind(this);
}
// 2或3选1
if (count === 1) {
// 遍历
cards = cards.filter(function (card) {
var signis = this.player.signis.filter(function (signi) {
return (signi !== card);
},this);
return this.canSummonWith(signis);
},this);
if (!cards.length) return null;
return function () {
return this.player.selectAsyn('TRASH',cards).callback(this,function (card) {
card.trash();
return [card];
});
}.bind(this);
}
// 3选2
if (count === 2) {
// signis.length === 3;
if (cards.length === 2) {
var signis = this.player.signis.filter(function (signi) {
return !inArr(signi,cards);
},this);
if (!this.canSummonWith(signis)) return null;
return function () {
return Callback.immediately().callback(this,function () {
this.game.trashCards(cards);
return cards;
});
}.bind(this);
}
if (cards.length === 3) {
var cards_left = cards.filter(function (card) {
return this.canSummonWith([card]);
},this);
if (!cards_left.length) return null;
if (cards_left.length === 1) {
cards = cards.filter(function (card) {
return card !== cards_left[0];
},this);
return function () {
return Callback.immediately().callback(this,function () {
this.game.trashCards(cards);
return cards;
});
}.bind(this);
}
if (cards_left.length === 2) {
return function () {
return this.player.selectAsyn('TRASH',cards).callback(this,function (c) {
var cards_trash = [c];
if (inArr(c,cards_left)) {
cards = cards.filter(function (card) {
return !inArr(card,cards_left);
});
} else {
cards = cards_left;
}
return this.player.selectAsyn('TRASH',cards).callback(this,function (c) {
cards_trash.push(c);
this.game.trashCards(cards_trash);
return cards_trash;
});
});
}.bind(this);
}
if (cards_left.length === 3) {
return function () {
return this.player.selectSomeAsyn('TRASH',cards,2,2).callback(this,function (cards) {
this.game.trashCards(cards);
return cards;
});
}.bind(this);
}
}
}
return null;
};
Card.prototype.canAttack = function () {
if (this.attackCostColorless) {
var obj = {
costColorless: this.attackCostColorless
};
if (!this.player.enoughCost(obj)) return false;
}
// <バインド・ウェポンズ>
if (this.type === 'SIGNI') {
var attackCount = this.fieldTurnData.attackCount || 0;
if (attackCount >= this.player.signiAttackCountLimit) return false;
} else {
var lrigAttackCount = this.game.getData(this.player,'lrigAttackCount') || 0;
if (lrigAttackCount >= this.player.lrigAttackCountLimit) return false;
}
// <白羅星 フルムーン>
if (this.type === 'SIGNI') {
var attackCount = this.game.getData(this.player,'signiAttackCount') || 0;
if (attackCount >= this.player.signiTotalAttackCountLimit) return false;
}
return (this.type === 'SIGNI' || this.type === 'LRIG') &&
(this.isUp) &&
(!this.canNotAttack);
};
Card.prototype.canTrashAsCost = function () {
if (this.canNotBeTrashedBySelf) return false;
if (this.player.trashSigniBanned && inArr(this,this.player.signis)) return false;
return true;
};
Card.prototype.canUse = function (timming,ignoreCost) {
if (inArr(this.cid,this.player.bannedCards)) return false;
if (!this.checkLimiting()) return false;
if (this.useCondition && !this.useCondition()) return false;
if (this.type === 'SPELL') {
// <绿罗植 世界树>
if (this.player.canNotUseColorlessSpell) {
if (this.hasColor('colorless')) {
return false;
}
}
if (this.player.spellBanned) return false;
if (ignoreCost) return true;
return this.enoughCost();
}
if (this.type === 'ARTS') {
if (this.player.artsBanned) return false;
if (!inArr(timming,this.timmings)) return false;
if (this.player.oneArtEachTurn && this.game.getData(this.player,'flagArtsUsed')) return false;
// cost 判断
if (ignoreCost) return true;
var cost = this.getChainedCostObj()
if (this.player.enoughCost(cost)) return true;
// bet 相关
if (this.bet && this.bettedCost) {
if (this.bet > this.player.coin) return false; // 避免出现coin不够却可以选择使用技艺。《孤立无炎》
cost = this.getChainedCostObj(this.bettedCost)
if (this.player.enoughCost(cost)) return true;
}
return false;
}
return false;
};
Card.prototype.checkLimiting = function () {
// this.limiting === this.player.lrig.lrigType
if (!this.limitings.length) return true;
if (this.player.ignoreLimitingOfArtsAndSpell) {
if ((this.type === 'SPELL') || (this.type === 'ARTS')) {
return true;
}
}
if (this.player.ignoreLimitingOfLevel5Signi) {
if ((this.type === 'SIGNI') && (this.level === 5)) {
return true;
}
}
return this.limitings.some(function (limiting) {
return inArr(limiting,this.player.lrig.classes);
},this);
};
Card.prototype.enoughCost = function () {
return this.player.enoughCost(this);
};
Card.prototype.hasClass = function (cls) {
return this.classes.some(function (thisClass) {
return thisClass === cls;
},this);
};
// 注意:不保证唯一性
Card.prototype.getColors = function (ignoreColorless) {
var colors = this.otherColors.concat(this.color);
if (this.colorLost) {
colors = ['colorless'];
}
if (ignoreColorless) {
removeFromArr('colorless',colors);
}
if (!this._SnoropNaturalPlantPrincess) return colors;
if (!inArr(this,this.player.signis)) return colors;
this.player.enerZone.cards.forEach(function (card) {
card.otherColors.concat(card.color).forEach(function (color) {
if (color === 'colorless') return;
if (inArr(color,colors)) return;
colors.push(color);
},this);
});
return colors;
};
Card.prototype.hasColor = function (color) {
if (color === 'colorless') {
return !this.getColors(true).length;
}
return inArr(color,this.getColors(true));
};
Card.prototype.hasSameColorWith = function (card) {
var colors = this.getColors(true);
return card.getColors(true).some(function (color) {
return inArr(color,colors);
},this);
};
Card.prototype.hasBurst = function () {
return this.burstIcon || this.onBurst.effects.length;
};
Card.prototype.isEffectFiltered = function (source) {
if (!this.effectFilters.length) return false;
if (!source) source = this.game.getEffectSource();
if (!source) return false;
return this.effectFilters.some(function (filter) {
return !filter.call(this,source);
},this);
};
Card.prototype.up = function () {
if (this.isUp) return false;
if (this.isEffectFiltered()) return false;
this.isUp = true;
this.triggerOnAffect();
this.onUp.trigger({
card: this
});
this.game.output({
type: 'UP_CARD',
content: {card: this}
});
return true;
};
Card.prototype.upAsyn = function () {
if (this.isUp) return Callback.immediately(false);
if (this.isEffectFiltered()) return Callback.immediately(false);
var protections = this.upProtections.filter(function (protection) {
return protection.condition.call(protection.source);
},this);
if (!this.upProtections.length) return Callback.immediately(this.up());
return this.player.selectAsyn('CHOOSE_EFFECT',protections).callback(this,function (protection) {
protection.source.activate();
return protection.actionAsyn.call(protection.source,this);
}).callback(this,function () {
return true;
});
};
Card.prototype.down = function () {
if (!this.isUp) return false;
if (this.isEffectFiltered()) return false;
if (this.player.canNotBeDownedByOpponentEffect) {
var source = this.game.getEffectSource()
if (source && (source.player === this.player.opponent)) {
return false;
}
}
this.game.frameStart();
this.isUp = false;
if (this.hasClass('植物')) {
var count = this.game.getData(this.player,'増武Count') || 0;
this.game.setData(this.player,'増武Count',count+1);
}
this.triggerOnAffect();
this.onDown.trigger({
card: this
});
this.game.frameEnd();
this.game.output({
type: 'DOWN_CARD',
content: {card: this}
});
return true;
};
Card.prototype.faceup = function () {
if (this.isFaceup) return false;
if (this.isEffectFiltered()) return false;
this.isFaceup = true;
this.triggerOnAffect();
this.game.output({
type: 'FACEUP_CARD',
content: {
card: this,
pid: this.pid
}
});
};
Card.prototype.facedown = function () {
if (!this.isFaceup) return false;
if (this.isEffectFiltered()) return false;
this.isFaceup = false;
this.triggerOnAffect();
this.game.output({
type: 'FACEDOWN_CARD',
content: {card: this}
});
};
Card.prototype.moveTo = function (zone,arg) {
// 共鸣
if (this.resona) {
if (!inArr(zone.name,['SigniZone','LrigTrashZone','LrigDeck','ExcludedZone'])) {
zone = this.player.lrigDeck;
arg = {}; // 忽略移动参数
}
}
// <コードアンチ カイヅカ>
if (this.fieldData.excludeWhenLeaveField) {
if (inArr(this,this.player.signis) && zone.name !== 'SigniZone') {
zone = this.player.excludedZone;
}
}
if (arg === undefined) arg = {};
if (arg.up === undefined) arg.up = zone.up;
if (arg.faceup === undefined) arg.faceup = zone.faceup;
if (arg.bottom === undefined) arg.bottom = zone.bottom;
if (arg.isSummon) arg.bottom = false;
var card = this;
// 效果过滤 (不会受到XXX的效果影响)
var source = this.game.getEffectSource();
if (this.isEffectFiltered(source)) return false;
// "不能抽卡,也不能将卡加入手牌"
if (card.player.addCardToHandBanned) {
if ((zone.name === 'HandZone') && (card.zone !== zone)) {
return false;
}
}
// "不能自己将这只 SIGNI 从场上放置到废弃区。"
if (card.canNotBeTrashedBySelf && source && (source.player === card.player)) {
if (inArr(card,card.player.signis) && (zone.name === 'TrashZone')) {
return false;
}
}
// "不能从场上返回手牌。"
if (card.player.canNotBeBounced) {
if (inArr(card,card.player.signis) && (zone.name === 'HandZone')) {
return false;
}
}
// "不能因对战对手的效果从场上返回手牌。"
if (card.player.canNotBeBouncedByEffect && source && (source.player !== card.player)) {
if (inArr(card,card.player.signis) && (zone.name === 'HandZone')) {
return false;
}
}
// 注: 交换 SIGNI 区请用 card.changeSigniZone(zone).
// 以下代码作废.
// 从 SIGNI 区移动到 SIGNI 区的情况比较特殊,单独处理.
// 全部卡片一起移动,不触发任何时点.
// 注意: 这里没考虑转移控制权的情况,目前WX还没有这种效果.
// if ((card.zone.name === 'SigniZone') && (zone.name === 'SigniZone')) {
// var cards = card.zone.cards.slice();
// card.zone.cards.length = 0;
// this.game.packOutputs(function () {
// cards.forEach(function (card) {
// zone.cards.push(card);
// card.zone = zone;
// var msgObj = {
// type: 'MOVE_CARD',
// content: {
// card: card,
// pid: card.isFaceup? card.pid : 0,
// zone: zone,
// up: card.isUp,
// faceup: card.isFaceup,
// bottom: true
// }
// };
// card.player.output(msgObj);
// card.player.opponent.output(msgObj);
// },this);
// },this);
// return;
// }
// 更新 player 的 hands,signis,lrig .
// 同时设置 onEnterField 等时点的事件对象.
var moveEvent = {
card: card,
isSigni: inArr(card,card.player.signis),
power: card.power, // 移动前的力量
isCharm: arg.isCharm || false,
isCrossed: !!card.crossed,
riseTarget: null,
isUp: arg.up,
oldZone: card.zone,
newZone: zone,
resonaArg: arg.resonaArg || null,
isExceedCost: !!arg.isExceedCost,
source: source
};
var enterFieldEvent = null;
var leaveFieldEvent = null;
var lrigChangeEvent = null;
var charm = null;
/* 处理离开区域逻辑 */
if (card.zone.name === 'HandZone') {
// 离开手牌
removeFromArr(card,card.player.hands);
} else if (card.zone.name === 'SigniZone') {
// 离开 SigniZone
if (inArr(card,card.player.signis)) {
// 是 SIGNI
// 以下代码 rise 里复用了,虽然说 DRY 原则,但这里也不太好抽离,养肥了再抽吧(
leaveFieldEvent = moveEvent;
card.frozen = false;
card.fieldData = {};
card.fieldTurnData = {};
charm = card.charm;
card.charm = null;
removeFromArr(card,card.player.signis);
} else {
// 是 SIGNI 下方的卡,比如魅饰卡
// 处理魅饰卡
var signi = card.zone.getSigni();
if (signi && card === signi.charm) {
moveEvent.isCharm = true;
signi.charm = null;
}
// 处理陷阱
if (card === card.zone.trap) {
card.zone.trap = null;
}
// 处理 acce
card.acceingCard = null;
}
}
/* 处理进入区域逻辑 */
if (zone.name === 'HandZone') {
// 进入手牌
zone.player.hands.push(card);
} else if (zone.name === 'SigniZone') {
if (card.zone.name !== 'SigniZone' || zone.player !== card.player) {
// 进入 SIGNI 区
if (arg.isSummon) {
if (card.rise) {
// 被 rise 的卡“离场”
signi = zone.getSigni();
removeFromArr(signi,signi.player.signis);
signi.frozen = false;
signi.fieldData = {};
signi.fieldTurnData = {};
charm = signi.charm;
signi.charm = null;
signi.onLeaveField2.trigger({});
moveEvent.riseTarget = signi;
}
// 出场
enterFieldEvent = moveEvent;
zone.player.signis.push(card);
} else {
// 放置到 SIGNI 下方的卡
// 目前不需要处理
}
}
} else if ((zone.name === 'LrigZone') && !arg.bottom) {
// 进入 LrigZone
lrigChangeEvent = {
oldLrig: zone.player.lrig,
newLrig: card
};