-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathminigames.js
4032 lines (3988 loc) · 186 KB
/
minigames.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";
var oMiniGames = {
/*
游戏开局前在场地上摆好植物,然后又如下两种调用方法可以选择:
【方法一】指定植物数量,系统自动选取要保护的植物
这种方法的缺点在于如果场地上有同种植物,但有的要保护有的不需要,则这种方法失效
oMiniGames.ProtectPlants({
'oApple': 1,
'oSunFlower': 3,
})
【方法二】指定植物位置,系统自动选取要保护的植物
oMiniGames.ProtectPlants(void 0, [1, 2], [2, 3])
*/
ProtectPlants(sheet = {},sheetPos=[],callStartGame=true) { //保卫植物关卡
let recordIds = new Set();
let alrdead = false;
//let AppleKillCount = 0;
//事先扫描植物的id并记录
for (let plant of $P) {
if (sheet.hasOwnProperty(plant.EName) || plant.sos) {
plant.sos = 1;
recordIds.add(plant.id);
let tmp = plant.Die;
plant.Die = function(...sth){
let {R, C} = plant;
tmp.call(plant, ...sth);
if (!$P[plant.id]) {
/*if (plant.EName === 'oApple') AppleKillCount++;
if (AppleKillCount >= 5) console.log('Enter the Holy Apple secret boss fight');*/
alrdead = true;
oSym.addTask(150, toOver, [2, R, C]);
}
};
}
}
//自定义坐标表的采入
for (let i in sheetPos){
for(let pkind = 0, G = oGd.$; pkind <= PKindUpperLimit; pkind++) {
let p;
if(p=G[sheetPos[i][0]+"_"+sheetPos[i][1]+"_"+pkind]){
p.sos = 1;
let tmp = p.Die;
p.Die = function(...sth){
let {R, C} = p;
tmp.call(p, ...sth);
if (!$P[p.id]) {
alrdead = true;
oSym.addTask(150, toOver, [2, R, C]);
}
};
}
}
}
function fun() {
let tempSet = new Set(recordIds);
for (let o of $P) {
tempSet.has(o.id) && tempSet.delete(o.id);
}
if (tempSet.size > 0 && !alrdead) {
return toOver(2);
}
if (!alrdead) oSym.addTask(500, fun);
}
if(callStartGame){
oAudioManager.playMusic(oS.StartGameMusic);
SetVisible($("tdShovel"), $("dFlagMeter"), $("dTop"));
oS.InitLawnMover();
oS.ControlFlagmeter && oFlagContent.init({ fullValue: oP.FlagNum-1, curValue: 0 }); //显示进度条
PrepareGrowPlants(function () {
oP.Monitor(oS.Monitor);
BeginCool();
AutoProduceSun(50);
fun();
oSym.addTask(1500, _ => {
oP.AddZombiesFlag();
oS.ControlFlagmeter && oFlagContent.show();
})
});
}else{
addEventListenerRecord('jng-event-startgame', fun,{once:true});
}
},
/* 传送带接口调用说明
arrP:自定义的植物池,默认oS.PName。系统会从中随机抽取植物生成。植物池权重请在此处设置。
createTime:生成卡牌的时间间隔,默认600
moveTime:卡牌每次移动时间间隔,默认5
PriorityP:优先植物顺序数组,"random"代表当前随机,"null"代表当前不出卡牌。如果设置,那么系统将优先按照该顺序来出卡牌。
maxCard:最多可以在传送带上保留多少张卡牌
numLimit (e.g. {'oPeashooter': 5, 'oPuffShroom': 2}): 某个植物最多限制多少张 (equivalent to maxCount in PvZ2 with maxCount Weight Factor = 0), default is Infinity
maxCardCD: when maxCard is reached, wait for a maxCardCD amount of time before allowing the next card to be given (or when the number of cards on conveyor decrease below maxCard)
numLimitCD (e.g. {'oPeashooter': 1500, 'oPuffShroom': 1200}): when numLimit is reached, wait for a numLimitCD amount of time before allowing that plant to appear on the conveyor again (or when the number of plants decrease below numLimit), default is 114514
*/
ConveyorBelt(arrP = oS.PName, createTime = 600, moveTime = 3, priorityP = [], maxCard=10, numLimit = {}, maxCardCD = Infinity, numLimitCD = {}) {
/* 一些初始化 */
let bgDom = NewImg("ConveyorBelt", "images/interface/ConveyorBelt.webp", "z-index:0", $(
'dCardList'));
let conveyorDom = NewImg("Belt", "images/interface/ConveyorInterior.webp", "z-index:-1;left:-160px", $(
'dCardList'));
oEffects.Animate(bgDom,{
left:"0"
},0.2/oSym.NowSpeed,"ease-out");
oEffects.Animate(conveyorDom,{
left:"0"
},0.2/oSym.NowSpeed,"ease-out");
let top = 0;
(function moveBelt() {
if (top > -596) {
conveyorDom.style.top = top-- + "px";
} else {
conveyorDom.style.top = top += 597;
}
oSym.addTask(moveTime, moveBelt);
})();
oAudioManager.playMusic(oS.StartGameMusic);
SetVisible($("tdShovel"), $("dFlagMeter"), $("dTop"));
SetHidden($("dSunNum"));
oS.InitLawnMover();
oS.ControlFlagmeter && oFlagContent.init({ fullValue: oP.FlagNum-1, curValue: 0 }); //显示进度条
/* 重写全局函数 */
let objFun = {
GetChoseCard(b) {
if (oS.Chose > 0) {
return;
}
var a = ArCard.length;
while (a--) {
ArCard[a].DID == b && (oS.ChoseCard = a, a = 0)
}
return oS.ChoseCard
},
ChosePlant(evt, index = null, NavigateOnly = false) {
if(oS.Chose===-1){
CancelShovel();
}
if(oS.Chose===1 || $("MovePlant")){
CancelPlant();
return;
}
oPropUseGUI.navigateProp();
if(index !== null) {
index === -1 && (index = 9); //按0键可以选取第10个植物
if(index + 1 > ArCard.length || index < 0) {
return;
}
if (NavigateOnly) {
oAudioManager.deleteAudio('tap');
oAudioManager.playAudio('tap');
NewImg("CardNavigated", "images/Card/CardNavigated.webp", "width: 100px; height: 120px; top:0px; pointer-events: none;", $(ArCard[index].DID));
return;
}
oS.ChoseCard = index;
}
oS.Chose = 1;
$("MovePlant") && ClearChild($("MovePlant"));
oAudioManager.playAudio("seedlift");
let AC = ArCard[oS.ChoseCard],
evtX = evt.clientX - EDAlloffsetLeft || 60,
evtY = evt.clientY || ArCard[oS.ChoseCard].PixelTop,
pro = AC.PName.prototype;
let MovePlant = NewImg("MovePlant", pro.PicArr[pro.StaticGif],
`left:${evtX}px;top:${evtY + 20 - pro.height}px;z-index:258;`,
EDAll);
SetStyle(MovePlant, pro.ImgStyle);
EditImg(MovePlant.cloneNode(false), "MovePlantAlpha", "", { //克隆一份作为半透图
visibility: "hidden",
opacity: 0.4,
'z-index': 30,
}, FightingScene);
EditCompositeStyle({
ele: MovePlant,
addFuncs: [["translateX", oS.EDAllScrollLeft - pro.width / 2 + "px"]],
option: 2,
});
NewImg("CardSelected", "images/Card/CardSelected.webp", "width: 100px; height: 120px; top:0px; pointer-events: none;", $(AC.DID));
SetAlpha($(AC.DID + 'img'), 0.5); //标记卡牌被选择
SetHidden($("dTitle"));
GroundOnmousemove = GroundOnmousemove1;
},
CancelPlant(navigating = false) {
ClearChild($("MovePlant"), $("MovePlantAlpha"), $("HighlightLane"), $("HighlightLane2"), $("HighlightColumn"), $("CardSelected"));
if (navigating) ClearChild($("CardNavigated"));
oS.Chose = 0;
let AC = ArCard[oS.ChoseCard];
if (AC) {
$(AC.DID).style.backgroundImage = '';
SetAlpha($(AC.DID + 'img'), 100, 1);
}
oS.ChoseCard = "";
GroundOnmousemove = function () {}
},
GrowPlant(data, X, Y, R, C) {
(ZimuRQ.style.display === 'block') && PlaySubtitle();
let index = oS.ChoseCard;
let card = ArCard[index];
let plant = card.PName;
let proto = plant.prototype;
let cardID = card.DID;
if (C > oS.BowlingLimitC && ['oNutBowling', 'oBoomNutBowling', 'oBigWallNut', 'oNutBowlingPay', 'oBoomNutBowlingPay', 'oBigWallNutPay', 'oNutBowling2____'].includes(proto.EName)) {
oAudioManager.playAudio("buzzer");
if(IsMobile||R<1||C<1||C>9){
CancelPlant();
} else {
PlaySubtitle('请把坚果放在分界线左侧!', 700);
}
return false;
}
if (oS.BowlingLimitC < Infinity && C <= oS.BowlingLimitC && plant.prototype.Obj && plant.prototype.EName!="oIThiefZombie") {
oAudioManager.playAudio("buzzer");
if(IsMobile||R<1||C<1||C>9){
CancelPlant();
} else {
PlaySubtitle('把僵尸放置在线的右边!', 700);
}
return false;
}
if (proto.CanGrow(data, R, C)) {
oAudioManager.playAudio(
oGd.$GdType[R][C] === 2 ? "plant_water" : `plant${Math.floor(1+Math.random()*2)}`
);
new plant().Birth(X, Y, R, C, data);
if (!proto.Obj) {
const effectElement = $("imgGrowSoil");
effectElement.src = GrowSoilImg;
SetStyle(effectElement, {
left: X + 85 + "px",
top: Y - 45 + "px",
'z-index': 3 * R + 1,
visibility: "visible",
});
oSym.addTask(100, SetHidden, [effectElement]);
}
ArCard.splice(index, 1);
BeginCardKey();
oS.ChoseCard = "";
oS.Chose = 0;
GroundOnmousemove = () => {}
ClearChild($("MovePlant"), $("MovePlantAlpha"), $(cardID), $(cardID + 'img'));
CancelPlant();
} else {
oAudioManager.playAudio("buzzer");
if (!proto.UndergroundPlant && proto.EName !== 'oLilyPad' && oGd.$GdType[R][C] === 2 && !oGd.$[R + '_' + C + '_0'] && ZimuRQ.style.display !== 'block')
PlaySubtitle("先种一片莲叶",150);
if (!['oLilyPad', 'oFlowerPot'].includes(proto.EName) && oGd.$GdType[R][C] === 3 && !oGd.$[R + '_' + C + '_0'] && ZimuRQ.style.display !== 'block')
PlaySubtitle("先种一个花盆",150);
if(IsMobile||R<1||C<1||C>9){
CancelPlant();
}
}
},
ViewPlantTitle() {},
};
RewriteGlobalVariables(objFun);
/* 传送带逻辑 */
PrepareGrowPlants(() => {
let tmpCardDoms = new Map();
//处理优先植物队列
let index = 0;
//if maxCard is reached, wait until maxCardTimer reaches maxCardCD before allowing the next card to be given
//if numLimit is reached, wait until numLimitTimer reaches numLimitCD before allowing that plant to appear on conveyor again
let maxCardTimer = 0, numLimitTimer = {};
const _priorityP = priorityP.map(o => o === 'random' ? arrP.random() : o);
//生成植物卡牌
(function createNewCard() {
const len = ArCard.length;
if (len < maxCard || maxCardTimer > maxCardCD) {
//一次性最多可以生成十张卡牌
//首先检查优先植物数组中有没有对应项,如果没有就用random随机生成
maxCardTimer = 0;
let ENameStrArr = [];
let availableJson = (()=>{
let tmp = {};
arrP.forEach((i)=>{
ENameStrArr.push(i.prototype.EName);
tmp[i.prototype.EName]=i;
});
return tmp;
})();
//check numLimit of each plant
let json = {}, limitedPlants = new Set();
function StartLimitTimer(plantName) {
if (!numLimitTimer[plantName]) return;
numLimitTimer[plantName]++;
oSym.addTask(1, StartLimitTimer, [plantName]);
};
//check amount of each plant on the lawn
for(let i of $P){
if(!numLimit[i.EName]){continue;}
json[i.EName]=(json[i.EName]??0)+1;
if(!numLimitTimer[i.EName]) numLimitTimer[i.EName] = 0;
if(!numLimitCD[i.EName]) numLimitCD[i.EName] = 114514;
if(json[i.EName]>=numLimit[i.EName] && numLimitTimer[i.EName]<=numLimitCD[i.EName]){
if (!limitedPlants.has(i.EName)) limitedPlants.add(i.EName);
}
}
//continue adding the amount of each plant on the conveyor and check
for(let k=0;k<len;k++){
let i = ArCard[k].PName.prototype;
if(!numLimit[i.EName]){continue;}
json[i.EName]=(json[i.EName]??0)+1;
if(!numLimitTimer[i.EName]) numLimitTimer[i.EName] = 0;
if(!numLimitCD[i.EName]) numLimitCD[i.EName] = 114514;
if(json[i.EName]>=numLimit[i.EName] && numLimitTimer[i.EName]<=numLimitCD[i.EName]){
if (!limitedPlants.has(i.EName)) limitedPlants.add(i.EName);
}
}
for (let plantName in availableJson) {
if (limitedPlants.has(plantName)) {
delete availableJson[plantName];
ENameStrArr = ENameStrArr.filter((TheName) => TheName !== plantName);
if (!numLimitTimer[plantName]) {
numLimitTimer[plantName]++;
oSym.addTask(1, StartLimitTimer, [plantName]);
}
} else {
numLimitTimer[plantName] = 0;
}
}
let obj = _priorityP[index] ? _priorityP[index] : availableJson[ENameStrArr.random()];
if(obj){
let proto = obj.prototype;
if (proto) {
let id = "dCard" + Math.random();
ArCard[len] = {
DID: id,
PName: obj,
PixelTop: 600,
};
let idele = NewEle(id, "div", `position: absolute; top: 600px; width: 100px; height: 120px; cursor: pointer; background-size:100%; clip-path: inset(0 0 60px 0);`, 0, $("dCardList"));
let idimg = NewEle(id + 'img', "div", `background-image:url(${proto.PicArr[proto.CardGif]});background-size:100px 120px;`,
{
onmousedown: event => {
GetChoseCard(id);
ChosePlant(event);
event.stopPropagation();
if (event.cancelable) event.preventDefault();
}
}, idele);
SetEvent(idimg, 'touchstart', event => {
GetChoseCard(id);
ChosePlant(event);
event.stopPropagation();
if (event.cancelable) event.preventDefault();
});
BeginCardKey();
}
}
index++;
} else if (!maxCardTimer) {
function StartTimer() {
if (!maxCardTimer) return;
maxCardTimer++;
oSym.addTask(1, StartTimer);
};
maxCardTimer++;
oSym.addTask(1, StartTimer);
}
oSym.addTask(createTime, createNewCard);
})();
{
(function moveCard() {
let len = ArCard.length;
while (len--) {
let tmp__;
let card = ArCard[len];
// 卡牌没有到达顶端
// 卡牌没有超过最顶端
if (card.PixelTop > 60 * len+5 && card.PixelTop >= 5) {
if(!(tmp__=tmpCardDoms.get(card))){
tmpCardDoms.set(card,tmp__=$(card.DID));
}
tmp__.style.top =
(card.PixelTop = Math.max(7, 60 * len + 7, card.PixelTop - 1)) + "px";
}
}
if(tmpCardDoms.size>150){
tmpCardDoms.clear();
}
oSym.addTask(moveTime, moveCard);
})();
}
ShortcutInstructions();
oP.Monitor();
oP.AddZombiesFlag();
oS.ControlFlagmeter && oFlagContent.show();
});
},
//countdownTime: time before the card disappears
RainWithSeeds(arrP = oS.PName, createTime = 600, moveTime = 5, priorityP = [],countdownTime = 700, autoRainEffect = true,maxCard = 9, numLimit = {}, maxCardCD = Infinity, numLimitCD = {}) {
/* 一些初始化 */
oAudioManager.pauseMusic();
oAudioManager.playMusic(oS.StartGameMusic);
oAudioManager.deleteAudio('rain');
let RainAudio = oAudioManager.playAudio("rain",true, 0.5);
oSym.addTask(1,function l(){
if(RainAudio.currentTime>RainAudio.duration-0.4){
RainAudio.currentTime=0;
}
oSym.addTask(3,l);
});
SetVisible($("tdShovel"), $("dFlagMeter"), $("dTop"));
SetHidden($("dSunNum"));
oS.InitLawnMover();
oS.ControlFlagmeter && oFlagContent.init({ fullValue: oP.FlagNum-1, curValue: 0 }); //显示进度条
oS.ChoseCardObj = void 0;
const getChoseCardIndex = () => {
let len = ArCard.length;
while(len--) {
if(ArCard[len] === oS.ChoseCardObj) {
return len;
}
}
};
/* 重写全局函数 */
let objFun = {
GroundOnmousemove1(event) {
let plant = oS.ChoseCardObj.PName;
let evtX = event.clientX - EDAlloffsetLeft;
let evtY = event.clientY;
if (IsMobile && event.targetTouches) {
let finger = event.targetTouches[0];
[evtX, evtY] = [finger.clientX - EDAlloffsetLeft, finger.clientY];
}
let [[X, C], [Y, R]] = [ChosePlantX(evtX), ChosePlantY(evtY)];
let [data] = GetAP(evtX, evtY, R, C);
let proto = plant.prototype;
let imgAlpha = $("MovePlantAlpha");
SetStyle($("MovePlant"), {
left: `${evtX}px`,
top: `${evtY + 20 - proto.height}px`,
});
if(proto.CanGrow(data, R, C)) {
SetStyle(imgAlpha, {
visibility: "visible",
left: X + 115 + proto.GetDX(proto) + "px",
top: Y - proto.height + proto.GetDY(R, C, data) + "px",
});
PosHighlight(R,C);
} else {
SetHidden(imgAlpha);
ClearChild($("HighlightLane"), $("HighlightLane2"), $("HighlightColumn"));
}
return [evtX, evtY];
},
ChosePlant(evt, obj) {
if(typeof obj !== 'object') {
return;
}
if(oS.Chose===-1){
CancelShovel();
}
if((oS.Chose===1&&!oS.ChoseCardObj)){
CancelPlant();
return;
}
if(oS.ChoseCardObj) return;
evt.stopPropagation();
if (evt.cancelable) evt.preventDefault();
ClearChild($("MovePlant"));
oAudioManager.playAudio("seedlift");
let card = oS.ChoseCardObj = obj;
let evtX = evt.clientX - EDAlloffsetLeft || card.PixelLeft;
let evtY = evt.clientY || card.PixelTop;
let pro = card.PName.prototype;
oS.Chose = 1;
card.hasAnim = false;
card.Ele.style.cssText += 'animation-fill-mode:forwards;animation-iteration-count:0;';
let MovePlant=NewImg("MovePlant", pro.PicArr[pro.StaticGif],
`left:${evtX}px;top:${evtY + 20 - pro.height}px;z-index:258;`,
EDAll);
SetStyle(MovePlant, pro.ImgStyle);
EditImg(MovePlant.cloneNode(false), "MovePlantAlpha", "", { //克隆一份作为半透图
visibility: "hidden",
opacity: 0.4,
'z-index': 30,
}, FightingScene);
EditCompositeStyle({
ele: MovePlant,
addFuncs: [["translateX", oS.EDAllScrollLeft - pro.width / 2 + "px"]],
option: 2,
});
NewImg("CardSelected", "images/Card/CardSelected.webp", "width: 100px; height: 120px; top:0px; pointer-events: none;", card.Ele);
SetAlpha(card.Eleimg, 0.5); //标记卡牌被选择
card.Appeared=true;
SetHidden($("dTitle"));
GroundOnmousemove = GroundOnmousemove1;
},
GrowPlant(data, X, Y, R, C) {
let card = oS.ChoseCardObj;
let plant = card.PName;
let proto = plant.prototype;
let cardID = card.DID;
if (C > oS.BowlingLimitC && ['oNutBowling', 'oBoomNutBowling', 'oBigWallNut', 'oNutBowlingPay', 'oBoomNutBowlingPay', 'oBigWallNutPay', 'oNutBowling2____'].includes(proto.EName)) {
oAudioManager.playAudio("buzzer");
if(IsMobile||R<1||C<1||C>9){
CancelPlant();
} else {
PlaySubtitle('请把坚果放在分界线左侧!', 700);
}
return false;
}
if (oS.BowlingLimitC < Infinity && C <= oS.BowlingLimitC && plant.prototype.Obj && plant.prototype.EName!="oIThiefZombie") {
oAudioManager.playAudio("buzzer");
if(IsMobile||R<1||C<1||C>9){
CancelPlant();
} else {
PlaySubtitle('把僵尸放置在线的右边!', 700);
}
return false;
}
if (proto.CanGrow(data, R, C)) {
oAudioManager.playAudio(
oGd.$GdType[R][C] === 2 ? "plant_water" : `plant${Math.floor(1+Math.random()*2)}`
);
new plant().Birth(X, Y, R, C, data);
if (!proto.Obj) {
const effectElement = $("imgGrowSoil");
effectElement.src = GrowSoilImg;
SetStyle(effectElement, {
left: X + 85 + "px",
top: Y - 45 + "px",
'z-index': 3 * R + 1,
visibility: "visible",
});
oSym.addTask(100, SetHidden, [effectElement]);
}
ArCard.splice(getChoseCardIndex(), 1);
delete oS.ChoseCardObj;
oS.Chose = 0;
GroundOnmousemove = () => {};
ClearChild($("MovePlant"), $("MovePlantAlpha"), card.Eleimg, card.Ele);
card.Eleimg = card.Ele = null;
CancelPlant();
} else {
oAudioManager.playAudio("buzzer");
if (!proto.UndergroundPlant && proto.EName !== 'oLilyPad' && oGd.$GdType[R][C] === 2 && !oGd.$[R + '_' + C + '_0'] && ZimuRQ.style.display !== 'block')
PlaySubtitle("先种一片莲叶",150);
if (!['oLilyPad', 'oFlowerPot'].includes(proto.EName) && oGd.$GdType[R][C] === 3 && !oGd.$[R + '_' + C + '_0'] && ZimuRQ.style.display !== 'block')
PlaySubtitle("先种一个花盆",150);
if(IsMobile||R<1||C<1||C>9){
CancelPlant();
}
}
},
CancelPlant() {
let card = oS.ChoseCardObj;
oS.Chose = 0;
delete oS.ChoseCardObj;
ClearChild($("MovePlant"), $("MovePlantAlpha"), $("HighlightLane"), $("HighlightLane2"), $("HighlightColumn"), $("CardSelected"));
if (card) SetAlpha(card.Eleimg, 100, 1);
GroundOnmousemove = () => {};
},
ViewPlantTitle() {},
};
RewriteGlobalVariables(objFun);
PrepareGrowPlants(() => {
autoRainEffect&&oEffects.BgParticle({style:"z-index:21",url: "images/Props/Effect/Rain.png",timeout:4,move:function(i){
i.left-=4.5*oSym.NowSpeed;
i.top+=6*oSym.NowSpeed;
},size:{
width:140,height:140
}});
//处理优先植物队列
let index = 0;
let maxCardTimer = 0, numLimitTimer = {};
const _priorityP = priorityP.map(o => o === 'random' ? arrP.random() : o);
//生成植物卡牌
(function createNewCard() {
const len = ArCard.length;
if (len < maxCard || maxCardTimer > maxCardCD) {
maxCardTimer = 0;
let ENameStrArr = [];
let availableJson = (()=>{
let tmp = {};
arrP.forEach((i)=>{
ENameStrArr.push(i.prototype.EName);
tmp[i.prototype.EName]=i;
});
return tmp;
})();
//check numLimit of each plant
let json = {}, limitedPlants = new Set();
function StartLimitTimer(plantName) {
if (!numLimitTimer[plantName]) return;
numLimitTimer[plantName]++;
oSym.addTask(1, StartLimitTimer, [plantName]);
};
//check amount of each plant on the lawn
for(let i of $P){
if(!numLimit[i.EName]){continue;}
json[i.EName]=(json[i.EName]??0)+1;
if(!numLimitTimer[i.EName]) numLimitTimer[i.EName] = 0;
if(!numLimitCD[i.EName]) numLimitCD[i.EName] = 114514;
if(json[i.EName]>=numLimit[i.EName] && numLimitTimer[i.EName]<=numLimitCD[i.EName]){
if (!limitedPlants.has(i.EName)) limitedPlants.add(i.EName);
}
}
//continue adding the amount of each plant on the conveyor and check
for(let k=0;k<len;k++){
let i = ArCard[k].PName.prototype;
if(!numLimit[i.EName]){continue;}
json[i.EName]=(json[i.EName]??0)+1;
if(!numLimitTimer[i.EName]) numLimitTimer[i.EName] = 0;
if(!numLimitCD[i.EName]) numLimitCD[i.EName] = 114514;
if(json[i.EName]>=numLimit[i.EName] && numLimitTimer[i.EName]<=numLimitCD[i.EName]){
if (!limitedPlants.has(i.EName)) limitedPlants.add(i.EName);
}
}
for (let plantName in availableJson) {
if (limitedPlants.has(plantName)) {
delete availableJson[plantName];
ENameStrArr = ENameStrArr.filter((TheName) => TheName !== plantName);
if (!numLimitTimer[plantName]) {
numLimitTimer[plantName]++;
oSym.addTask(1, StartLimitTimer, [plantName]);
}
} else {
numLimitTimer[plantName] = 0;
}
}
if(_priorityP?.[index]==="null"){
index++;
}else{
const obj = _priorityP[index] ? _priorityP[index] : availableJson[ENameStrArr.random()];
if (obj) {
const proto = obj.prototype;
const id = "dCard" + Math.random();
const pxleft = 215+Math.random()*600;
const styles = `top:-60px;left:${pxleft}px;width:100px;height:120px;cursor:pointer;clip-path:inset(0 0 60px 0);z-index:253;`;
let Ele = NewEle(id, "div", styles + `position: absolute; background-size:100%;`, 0, EDAll);
let Eleimg = NewEle(id + 'img', 'div', `width:100px;height:120px;background-image:url(${proto.PicArr[proto.CardGif]});background-size:100px 120px;`, {
onmousedown: event => {ChosePlant(event, card);}
}, Ele);
SetEvent(Eleimg, 'touchstart', event => {ChosePlant(event, card);});
let card = ArCard[len] = {
DID: id,
PName: obj,
hasAnim: false,
PixelTop: -60,
EndTop: 110 + Math.random()*440,
Ele,
PixelLeft: pxleft,
Eleimg
};
}
index++;
}
} else if (!maxCardTimer) {
function StartTimer() {
if (!maxCardTimer) return;
maxCardTimer++;
oSym.addTask(1, StartTimer);
};
maxCardTimer++;
oSym.addTask(1, StartTimer);
}
oSym.addTask(createTime, createNewCard);
})();
(function moveCard() {
ArCard.forEach(card => {
if(card.PixelTop <= card.EndTop) {
card.Ele.style.top = (card.PixelTop += Math.max((75-card.PixelTop)/20,1)) + "px";
if(!card.Appeared){
card.Eleimg.style.opacity = Math.min(card.PixelTop/60,1);
if(card.Eleimg.style.opacity==1){
card.Appeared = true;
}
}
return;
}
if(card.hasOwnProperty('countdown')) {
if(oS?.ChoseCardObj?.DID !== card.DID) {
card.countdown -= moveTime;
card.countdown <= 300 && !card.hasAnim && (oEffects.Animate(card.Eleimg, 'CardBlink', 'slow', null, null, null, 'infinite'), card.hasAnim = true);
if(card.countdown <= 0) {
card.Eleimg.onmousedown = null;
card.Eleimg.ontouchstart = null;
oEffects.Animate(card.Ele, {transform: 'scale(0)'}, 0.1, 'linear', ClearChild);
ArCard.delete(card, true);
}
}
} else {
card.countdown = countdownTime;
}
});
oSym.addTask(moveTime, moveCard);
})();
oP.Monitor();
oP.AddZombiesFlag();
oS.ControlFlagmeter && oFlagContent.show();
});
},
DarkRain(time=12,randomRange=10,thunderDelay=4){//黑暗暴雨
let openThundering = true;//用来做是否结束的标志
let FlashMask = NewEle(`DarkRain_Flash_Mask`, "div", "pointer-events:none;position:absolute;z-index:31;left:0px;width:1600px;height:600px;background:#000;opacity:0.4;", 0, EDAll);
let flash_on = 1;
let Mask = NewEle(`DarkRain_Mask`, "div", "pointer-events:none;position:absolute;z-index:31;left:0px;width:1600px;height:600px;background:#000;opacity:0.5;", 0, EDAll);
let canvas = oEffects.BgParticle({style:"z-index:21",url: "images/Props/Effect/Rain.png",timeout:4,move:function(i){
i.left-=4.5*oSym.NowSpeed;
i.top+=6*oSym.NowSpeed;
},size:{
width:140,height:140
}});
if(!$User.LowPerformanceMode){
oSym.addTask(3,function f(){
if(!FlashMask||!openThundering){
return;
}
flash_on^=1;
FlashMask.style.opacity = flash_on*(Math.random()*0.4+0.1);
oSym.addTask(Math.random()*20+3,f);
});
}else{
ClearChild(FlashMask);
}
let RainAudio = oAudioManager.playAudio("rain",true, 0.5);
oSym.addTask(1,function l(){
if(!openThundering){
return;
}
if(RainAudio.currentTime>RainAudio.duration-0.4){
RainAudio.currentTime=0;
}
oSym.addTask(3,l);
});
oEffects.Animate(Mask,{opacity:1},1.5/oSym.NowSpeed,"linear");
oSym.addTask(150,function(){
if(!openThundering){
return;
}
Bright(Math.floor(Math.random()*2)+1);
let thunderStart=function(){
if(!openThundering){
return;
}
oSym.addTask(100*(Math.random()*randomRange+time-randomRange/2),function(){
Bright(Math.floor(Math.random()*2)+1);
thunderStart();
});
removeEventListenerRecord('jng-event-startgame', thunderStart);
}
thunderStart();
});
function Bright(type){
oEffects.Animate(Mask,"bright_thunder"+type,thunderDelay/oSym.NowSpeed,"ease-out");
if(type==2){
let ThunderAudio = oAudioManager.playAudio("thunder", false, 1);
oSym.addTask(thunderDelay*60,function(){
ThunderAudio = oAudioManager.playAudio("thunder");
oAudioManager.modifyAudioVolume(ThunderAudio, 0.5);
});
}else{
let ThunderAudio = oAudioManager.playAudio("thunder", false, 1);
}
}
function closeFunction(){
openThundering = false;
oEffects.StopAllAnims(Mask,true);
FlashMask.style.opacity=0;
oSym.addTask(1,()=>{
oEffects.AudioFadeOut("rain",0,1/oSym.NowSpeed);
oEffects.Animate(canvas,{"opacity":0},1/oSym.NowSpeed,"linear");
oEffects.Animate(Mask,{"opacity":0},1/oSym.NowSpeed,"linear");
});
oSym.addTask(100,()=>{
ClearChild(Mask,FlashMask,canvas);
});
}
return [FlashMask,Mask,closeFunction];
},
//争分夺秒 参数:限时(单位0.01s),惩罚措施,时间和进度条函数关系
LimitedTimeNoCool( time=Infinity, fun, timerBar = null, harderOnTimeout = true) {
if(time!==Infinity){
/* 初始化进度条 */
oFlagContent.init({
fullValue: 1,
curValue: 0,
MeterType: 'LeftBar GreenBar',
HeadType: 'NoneHead',
}).show().update({ curValue: 1, animConfig: {duration: 2} });
}
/* 开屏字幕控制 */
{
let text = [["准备...",60,"80px"], ["布置...",40,"60px"], ["阵型!",100,"90px"]];
let dom = NewEle("","div","left: 507.5px; top: 300px; transform: translateX("+oS.EDAllScrollLeft+"px) translate(-50%, -50%);color:red;font-size:80px;opacity:0;", {
innerText:text[0][0],
id:"dReadySetPlant",
className:"2px_shadow_with_shadow"
},EDAll);
const callback = function(){
let time = 0;
oAudioManager.playAudio("readysetplant");
for(let i = 0;i<text.length;i++){
oSym.addTask(time,()=>{
dom.innerText = text[i][0];
dom.style.opacity = "";
dom.style.fontSize =text[i][2];
EditCompositeStyle({ ele: dom, delFuncs: ['scale'], addFuncs: [["scale", 0.95]], option: 2 });
oSym.addTask(1,()=>{
oEffects.Animate(dom,{
transform: EditCompositeStyle({ele: dom, delFuncs: ['scale'], addFuncs: [["scale", 1.1]]})
},0.3/oSym.NowSpeed,"ease-out");
});
});
time+=text[i][1];
}
oSym.addTask(time,()=>{
ClearChild(dom);
});
};
callback();
};
/* Other */
oAudioManager.playMusic(oS.StartGameMusic);
SetVisible($("tdShovel"), $("dFlagMeter"), $("dTop"));
oS.InitLawnMover();
let clicked = false;
let oldTime = time;
let btn;
RewriteGlobalVariables({
ViewPlantTitle: function(index) { //战斗界面植物标签绘制
if(index === null) return;
let ele = $("dTitle");
let card = ArCard[index];
let plant = card.PName.prototype;
let str;
if (!plant.SpawnLimitReached) {
let speedMultiplier = oS.coolSpeed/0.5 || 1;
str = `${plant.CName}<br>冷却时间:${Math.round(plant.coolTime/speedMultiplier * 10) / 10}秒<br>${plant.Tooltip}`;
} else {
str = `${plant.CName}<br><span style="color:#F00">不能使用</span><br>${plant.Tooltip}`;
}
if(card.Forbidden){
str += '<br><span style="color:#F00">该植物暂不可种植!</span>'
}else{
!card.CDReady && !plant.SpawnLimitReached && (str += '<br><span style="color:#F00">植物正在冷却中...</span>');
!card.SunReady && (str += '<br><span style="color:#F00">你的阳光不足!</span>');
}
ele.innerHTML = str;
SetStyle(ele, {
top: 60 * index + "px",
left: (100+oS.EDAllScrollLeft)+"px",
})
},
ShovelPlant : function(data) {//阳光铲
oAudioManager.playAudio("plant2");
let [plantsArg, pointedPlant] = data;
if(pointedPlant && pointedPlant.isPlant && pointedPlant.canShovel) { //鼠标有指向植物,且植物允许被铲除
//如果指向的是普通植物,或者是没有搭载其他植物的植物容器,则允许铲除
if(pointedPlant.PKind || !(plantsArg[1] || plantsArg[2])) {
let sunNum = pointedPlant.SunNum;
let [r,c]=[pointedPlant.R,pointedPlant.C];
pointedPlant.Die('JNG_TICKET_SuperPower');
if(!$P[pointedPlant.id]){
while(sunNum>50){
let tmp=AppearSun(GetX(c),GetY(r),50,0);
oSym.addTask(100,function(){ClickSun(tmp.id);});
sunNum-=50;
}
let tmp = AppearSun(GetX(c),GetY(r),sunNum,0);
oSym.addTask(100,function(){ClickSun(tmp.id);});
}
oS.MPID = ""; //注销鼠标指向植物
}
}
CancelShovel();
},
});
oMiniGames.GrowWithoutSun(false,function(){
oSym.addTask(30,function(){
btn = NewEle("startFightButton","div",0,{
onclick(){
clicked=true;
FIGHT();
},
innerText:"开始战斗",
onmouseover(){
btn.style.filter = "brightness(110%)";
},
onmouseout(){
btn.style.filter = "";
},
onmousedown(){
btn.style.filter = "brightness(90%)";
}
}, EDAll);
oSym.addTask(200,function(){
SetStyle(btn,{
'pointer-events':"auto",
opacity:"1",
});
//默认所有植物没有任何冷却
for (let obj of ArCard) {
let p = obj.PName.prototype;
p.SunNum <= oS.SunNum && (obj.SunReady = 1, $(obj.DID).childNodes[0].style.top ="0");
obj.CDReady = 1; //标记冷却完成
if(p.Immediately||!p.SunNum){//不许在开局被种植的植物
obj.Forbidden = 1;
$(obj.DID).childNodes[0].style.top ="-60px";
}
}
if(time !== Infinity) {
oSym.addTask(1, function loop() {
time-=2; //刷新时间
let curValue = timerBar ? timerBar(time/oldTime) : (time/oldTime)**1.1;
if(curValue <= 1/3) {
oFlagContent.update({ MeterType: 'LeftBar RedBar', curValue, animConfig: {disabled: true} });
} else if (curValue <= 2/3) {
oFlagContent.update({ MeterType: 'LeftBar BlueBar', curValue, animConfig: {disabled: true} });
} else {
oFlagContent.update({ curValue, animConfig: {disabled: true} });
}
if(time<0) {
FIGHT(true,harderOnTimeout);
} else {
if(!clicked){
oSym.addTask(2,loop);
}
}
});
}
});
});
});
function FIGHT(timeLimited=false,harderOnTimeout=true) {
if(time!==Infinity){
oFlagContent.hide(); //隐藏进度条
}
let gVar = oS.GlobalVariables;
switch(oS.Chose){
case 1:
CancelPlant();
break;
case -1:
CancelShovel();
}
let names = ["ChosePlant","GrowPlant","MonitorCard"];
for (let name of names) {
if(gVar[name]){
window[name] = gVar[name];
delete gVar[name];
}
}
ShovelPlant = gVar.ShovelPlant;
delete gVar.ShovelPlant;
//恢复植物冷却
for (let obj of ArCard) {
obj.PName.prototype.SunNum > oS.SunNum && (obj.SunReady = 0, $(obj.DID).childNodes[0].style.top ="60px");
obj.CDReady = 0;
if(obj.Forbidden){
delete obj.Forbidden;
}
}
BeginCool();
if(timeLimited){
fun&&fun();//惩罚措施
if (harderOnTimeout) {
oEffects.flash();
for(let i in oP.FlagToSumNum.a2){
oP.FlagToSumNum.a2[i]*=2//大波僵尸进攻
}
}
}
oSym.addTask(100, _=> {
oFlagContent.init({ fullValue: oP.FlagNum-1, curValue: 0 });
oP.Monitor(oS.Monitor, oS.UserDefinedFlagFunc);
PrepareGrowPlants(_ => {
oP.AddZombiesFlag();
oS.ControlFlagmeter && oFlagContent.show();
oS.ControlFlagmeter && SetVisible($("dFlagMeterContent"));
},false);
});
ClearChild(btn);
}
},
GrowWithoutSun(AutoControl=true,prepareFun) { //一植千金 争分夺秒的禁用冷却系统
if(AutoControl){
oAudioManager.playMusic(oS.StartGameMusic);
SetVisible($("tdShovel"), $("dFlagMeter"), $("dTop"));
oS.ControlFlagmeter && oFlagContent.init({ fullValue: oP.FlagNum-1, curValue: 0 }); //显示进度条
oS.InitLawnMover();
oS.coolSpeed = Infinity; //change the cooldown to 0s in the title display when hovering a plant card
PrepareGrowPlants(_ => {
oP.Monitor(oS.Monitor, oS.UserDefinedFlagFunc);
//默认所有植物没有任何冷却
for (let obj of ArCard) {
obj.PName.prototype.SunNum <= oS.SunNum && (obj.SunReady = 1, $(obj.DID).childNodes[0].style.top ="0");
obj.CDReady = 1; //标记冷却完成
}
AutoProduceSun(50);
oSym.addTask(1200, _ => {
oP.AddZombiesFlag();