-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzombies.js
8262 lines (8245 loc) · 370 KB
/
zombies.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 CZombies = NewO({
EName: "Zombies",//在继承的僵尸对象中,EName必须严格等于变量名
HP: 270,
Lvl: 1, //僵尸强度级别,普通为1路障2铁桶4撑杆2
NormalGif: 2,
CardGif: 0,
CanDisplay: 1,
StaticGif: 2,
AttackGif: 3,
LostHeadGif: 4,
LostHeadAttackGif: 5,
HeadGif: 6,
DieGif: 7,
width: 166,
height: 144,
beAttackedPointL: 82,
beAttackedPointR: 156,
BreakPoint: 90,
// 僵尸防具类型
// 0表示僵尸无防具;1表示I类防具僵尸,如路障铁桶橄榄球;2表示II类防具僵尸,如读报、铁栅门
Ornaments: 0,
OrnHP: 0,
OShieldHP: 0,
ShieldHP: 0,
OSpeed: 1.6,
Speed: 1.6,
PZ: 1,
SpeedCoefficient: 1, //僵尸速度系数,默认为1,越低僵尸走的越慢(这个东西不受减速或亢奋效果影响,比如减速则最终速度是在减速的速度基础上乘上这个系数
extraDivingDepth: 0, //除了格子默认深度,僵尸额外潜下去(浮上来)的深度
DivingDepth: 0, //僵尸潜下去的实际深度
AKind: 0, //普通僵尸的攻击是0直接啃食,1巨人是秒杀,2篮球车冰车碾压,3篮球车丢篮球,以及其他远程.撑杆第一次是跳跃第二次是啃食
ResistInsta:0.2778,//抵抗爆炸的程度
//是否可以被攻击,为以防万一,尽量不要滥用该属性来判断僵尸是否垂死!
// 实际上囧姨设计该属性的用意是僵尸是否可以触发某些短距离植物(地刺、土豆雷、胆小菇...)的攻击判定
// 而非标记僵尸不可被子弹打中
beAttacked: 1,
isAttacking: 0,
isGoingDie: 0, //僵尸是否垂死
OAttack: 100,
Attack: 100,
LivingArea: 1, //目前所在格子的类型
CanGoThroughWater: true, //可不可以跟着水走
CanAppearFromTomb: true, // 可不可以从墓碑里钻出来
Altitude: 1, // //海拔位置:-1潜地 0潜水 1行走 2跳跃 3植物子弹无法到达的高空飞行
WalkDirection: 0, //僵尸行走方向,0表示向左,1表示向右
FreeSlowTime: 0, //用于标记僵尸是否处于减速状态
FreeVertigoTime: 0,
FreeExcitedTime: 0,
isFloating: 0, //标记僵尸是否处于浮空状态,即是否受战术风扇影响
isCounted: 1, //是否需要纳入死亡统计
isPuppet: 0, //是否是傀儡(非僵尸的僵尸)
CanDiaplay: 1,
DiyConfigs: {}, //后期由其他需要的因素中途添加的变量
WaterShadowGif: null,
CanDrawBlood:true,
// 为僵尸绑定子僵尸,以便在进入关卡的时候一并加载,而不需要再在oS.ZName里添加
// 比如说为巨人绑定抛出去专用的小鬼
// 注意,此属性使用的时候千万要小心,防止出现循环绑定
SubsidiaryZombies: null,
Almanac: {
Dom: null,
Tip: "无",
Weakness: "无",
Speed: "慢",
Story: "无。",
},
AudioArr: ["splat1", "splat2", "splat3", "ignite", "frozen", "chomp", "chomp2", "chompsoft", 'awooga', "zombiesplash", "zombie_entering_water"],
AccessiblePath: (() => { //可由某道路转向某道路
let arr = {};
arr["1_3"] = 1;
for (let i in arr) {
arr[i.reverse()] = 1;
}
for (let i = 0; i < 4; i++) {
arr[`${i}_${i}`] = 1;
}
return arr;
})(),
//获取卡片图片
GetCardImg() {
let self = this;
return "images/Card/" + self.EName.substr(1) + ".webp";
},
//判定僵尸能否走某行
CanPass(R, LF) {
let self = this;
return LF && self.AccessiblePath[oGd.$LF[R] + "_" + LF];
},
//检查当前格子类型不同切换事件
ChkCell_GdType(self) {
let R = self.R;
let C = GetC(self.ZX - (self.beAttackedPointR - self.beAttackedPointL) / 2 * (self.WalkDirection * 2 - 1));
let gdType = oGd.$GdType[R][C];
let oldGdType = self.LivingArea;
let canChangeType = true;
if (oldGdType != gdType) {
if (gdType == 0 || gdType == 1 || gdType == 3) {
if (self.DivingDepth > 0 && self.Altitude != 3) {
self.SetWater(0, R, C, oldGdType);
// 一旦出水,僵尸不再受到水道规则约束
self.ChkActs = self.__proto__.ChkActs;
// 把僵尸从图层实时调整名单中删除
oS.observeZombieLayer && oZombieLayerManager.delZombie(self);
}else{
canChangeType=false;
}
} else if (gdType == 2) {
if (self.DivingDepth<=0 && self.Altitude != 3) {
self.SetWater(oGd.$WaterDepth[R][C] + self.extraDivingDepth, R, C, oldGdType);
}else{
canChangeType=false;
}
}
if(canChangeType){
self.LivingArea = gdType;
}
}
},
/*
当useAnim=false时,该函数为同步函数,不需要考虑异步的问题!
R, C, oldGdType这几个参数在useAnim=false,或者确保僵尸一定不会被bounce的情况下可以不传!
*/
async SetWater(depth, R, C, oldGdType, useAnim = true, toSetWaterStyle = true) {
let self = this;
let oldDepth = self.DivingDepth;
let height = self.height;
const callback_intoWater = () => {
//如果水超过了最高处则潜水
if (depth > self.height) {
self.Altitude = 0;
}
if (depth > self.height / 2) {
self.SpeedCoefficient = 0.7;
}
return true;
};
const callback_outWater = () => {
if (toSetWaterStyle && self.EleShadow.dataset.hasOwnProperty("tmp_cssText")) {
self.EleShadow.style.cssText = self.EleShadow.dataset.tmp_cssText;
delete self.EleShadow.dataset.tmp_cssText;
}
self.SpeedCoefficient = 1;
if (self.Altitude == 0) {
self.Altitude = Number(self.Ele.dataset.tmp_Altitude) ?? 1;
}
delete self.Ele.dataset.tmp_Altitude;
return true;
};
self.DivingDepth = depth;
// 僵尸潜入水中的情况
if (depth > 0) {
// 考虑到从外部调用SetWater的情况,还是手工设置一下僵尸的LivingArea
self.LivingArea = 2;
self.Ele.dataset.tmp_Altitude = self.Altitude;
toSetWaterStyle && self.setWaterStyle_middleWare();
if (useAnim) {
let msg = await self.sinkIntoWaterAnim(self, depth, oldDepth, height);
if (msg) {
return callback_intoWater();
} else {
self.DivingDepth = oldDepth;
self.LivingArea = oldGdType;
self.EleShadow.style.cssText = self.EleShadow.dataset.tmp_cssText;
SetStyle(self.EleBody, {
top: oldDepth,
clip: `rect(0,auto,auto,0)`,
'-webkit-mask-image': ""
});
}
} else {
self.useSinkIntoWaterEffect(self, depth);
return callback_intoWater();
}
}
// 僵尸浮出水中的情况
else if (depth === 0) {
if (useAnim) {
let msg = await self.sinkIntoWaterAnim(self, depth, oldDepth, height);
if (msg) {
return callback_outWater();
}
// 如果浮出水面的动画被中断(例如僵尸死亡或者被弹起)
// 则立即恢复僵尸原本的状态
else {
self.DivingDepth = oldDepth;
self.LivingArea = oldGdType;
self.useSinkIntoWaterEffect(self, oldDepth);
}
} else {
self.useSinkIntoWaterEffect(self, depth);
return callback_outWater();
}
}
return false;
},
setWaterStyle_middleWare() {
const self = this;
const shadowEle = self.EleShadow;
if (!self.WaterShadowGif) {
self.WaterShadowGif = oDynamicPic.require(WaterShadowImg, self.Ele);
}
if (!shadowEle.dataset.hasOwnProperty("tmp_cssText")) {
shadowEle.dataset.tmp_cssText = self.EleShadow.style.cssText;
}
shadowEle.style.cssText = self.EleShadow.dataset.tmp_cssText +
`background:url(${self.WaterShadowGif});`;
self.setWaterStyle(self, shadowEle);
return self;
},
setWaterStyle(self, shadowEle) {
EditCompositeStyle({
ele: shadowEle,
addFuncs: [
["translate", "4px, 20px"]
],
option: 2
});
SetStyle(shadowEle, {
height: "10.625px",
width: "84.375px",
'background-size': "100% 100%",
'z-index': 300
});
},
sinkIntoWaterAnim(self, newDepth, oldDepth, height) {
const id = self.id;
self.isSinkAnimFinished = false;
if (self.EName=="oSnorkelerZombie" && newDepth < oldDepth) oAudioManager.playAudio("snorkel_rise" + Math.floor(1 + Math.random() * 3));
if (newDepth > oldDepth) oAudioManager.playAudio("zombie_entering_water");
return new Promise((resolve) => {
oSym.addTask(1, function d(npx = 1) {
// 这个根号是实现先快后慢的效果 ↓
let delta = Math.sqrt(npx / 50) * (newDepth - oldDepth) + oldDepth;
// 如果发现僵尸被弹起或被取消注册,则立即放弃操作并使僵尸复原
if (self.isFloating || self.HP <= 0) {
return resolve(false);
}
self.useSinkIntoWaterEffect(self, delta);
npx < 50 ? oSym.addTask(1, d, [npx + 1]) : resolve(self.isSinkAnimFinished = true);
});
});
},
// top值表示僵尸下沉/上浮的程度
useSinkIntoWaterEffect(self, top) {
let bottom = self.height - top;
if ($User.LowPerformanceMode) {
SetStyle(self.EleBody, {
top: `${top}px`,
clip: `rect(0,auto,${bottom}px,0)`,
});
} else {
SetStyle(self.EleBody, {
top: `${top}px`,
clip: `rect(0,auto,${bottom + 4}px,0)`,
'-webkit-mask-image': `linear-gradient(black 0px ${bottom - 11}px, transparent ${bottom + 10}px)`
});
}
},
//判定僵尸能否走某个格
CanPassCell: (R, C) => {
let self = this;
let DR = self?.R ?? R;
let DC = self.ZX ? GetC(self.ZX) : C;
return self.AccessiblePath[`${oGd.$GdType[R][C]}_${oGd.$GdType[DR][DC]}`];
},
FangXiang: 'GoLeft',
ChkActs: (o, R, arR, i,stepRatio=1) => o[o.FangXiang](o, R, arR, i,stepRatio), //默认向左走
DeltaDirectionSpeed: { //Speed*这个等于真实速度
'GoLeft': 1,
'GoRight': -1,
'GoUp': 0,
'GoDown': 0
},
HeadTargetPosition: [{
x: 70,
y: 50
}, {
x: 70,
y: 50
}], //头的位置数据
getRealSpeed(self,stepRatio=1){
return self.Speed * self.SpeedCoefficient * stepRatio;
},
getRealSpeedJudge(self,stepRatio,horizontal=1){//horizontal是是否获取水平速度,必须填数字
let speed = self.getRealSpeed(self,stepRatio);
if(self.isAttacking||!(self.DeltaDirectionSpeed[self.FangXiang]*horizontal)){
speed=0;
}
return speed;
},
GoThroughWater(self, R, arR, i,stepRatio=1) {
let C, directions;
if (self.EleBody.style.transform.includes("rotateY(180deg)")) {
C = GetC(self.AttackedRX - (self.beAttackedPointR - self.beAttackedPointL) / 1.1);
} else {
C = Math.Clamp(GetMidC(self.ZX - (self.WalkDirection * 2 - 1) * 50), 0, oS.C + 1);
}
if (self.FangXiang === "GoUp") {
R = Math.Clamp(GetR(self.pixelTop + self.height + 10), 1, oS.R);
} else if (self.FangXiang === "GoDown") {
R = Math.Clamp(GetMidR(self.pixelTop + self.height - 5), 1, oS.R);
}
directions = oGd.$WaterFlowDirection[R][C].split(" ");
// 为防止僵尸在某些特殊水道中出现来回振荡的现象,需要设置岔路口方向的优先级
// Left : Right : Up : Down = 3 : 2 : 1 : 1
directions.includes("Left") && (directions = directions.concat("Left", "Left"));
directions.includes("Right") && (directions = directions.concat("Right"));
let randomDir = directions.random();
if ((R != self.DiyConfigs["Water_CurPos"]?.[0] || C != self.DiyConfigs["Water_CurPos"]?.[1]) && randomDir !== "Static" && randomDir !== "NoWater" && "Go" + randomDir !== self.FangXiang) {
let funs = {
GoLeft() {
self.WalkDirection = 0;
self.EleBody['style']['transform'] = 'rotateY(0deg)';
self.EleBody['style']['transform-origin'] = `0px 0px`;
},
GoRight() {
self.WalkDirection = 1;
SetStyle(self.EleBody, {
'transform': 'rotateY(180deg)',
'transform-origin': `${self.AttackedRX - (self.beAttackedPointR - self.beAttackedPointL) / 3 - self.X}px 0px`,
});
},
GoUp() {
},
GoDown() {
}
};
funs[self.FangXiang = "Go" + randomDir]();
}
self.DiyConfigs["Water_CurPos"] = [R, C];
return self[self.FangXiang](self, self.R, arR, i, stepRatio, true);
},
JudgeAttack(stepRatio=1) {
let self = this;
let ZX = self.ZX;
let crood = self.R + "_";
let C = GetC(ZX);
let G = oGd.$;
let arr = self.JudgeLR(self, crood, C, ZX, G) || self.JudgeSR(self, crood, C, ZX, G);
if(stepRatio*self.Speed>12&&!self.isAttacking&&self.Altitude===1&&self.DeltaDirectionSpeed[self.FangXiang]&&!arr){
arr = self.JudgeLong(self,crood,C,ZX,G,stepRatio);
}
if (arr && self.Altitude === 1) { //地上的僵尸才能检测攻击
!self.isAttacking && (self.isAttacking = 1, self.EleBody.src = self.PicArr[self.AttackGif]); //如果是首次触发攻击,需要更新到攻击状态
self.NormalAttack(...arr); //实施攻击
} else {
//撤销攻击状态
self.isAttacking && (self.isAttacking = 0, self.EleBody.src = self.PicArr[self.NormalGif]);
}
},
//离线判定
JudgeLong(self, R_crood, C, ZX, G,stepRatio=1,diyCheck=null){
let direction = -self.DeltaDirectionSpeed[self.FangXiang];
let Velocity = self.getRealSpeed(self,stepRatio) * direction;
let oriC = GetC(ZX - Velocity);
let curC = oriC;
let tarC = C;
let step = Math.sign(tarC-oriC);
let __flag;
if(tarC>oS.C){
return;
}
do{
if(curC>oS.C){//这个相当于近程判定
curC+=step;
continue;
}
let crood = R_crood + curC + "_";
let z = PKindUpperLimit;
while (z >= 0) {
let plant = G[crood + z];
if (plant && plant.canEat && (diyCheck?diyCheck(self,plant):true)) {
if(direction>0){//向右走
__flag = One_Dimensional_Intersection(self.X + self.beAttackedPointL - Velocity, self.X + self.beAttackedPointR,
plant.AttackedLX, plant.AttackedRX);
}else{
__flag = One_Dimensional_Intersection(self.X + self.beAttackedPointL, self.X + self.beAttackedPointR - Velocity,
plant.AttackedLX, plant.AttackedRX);
}
if(__flag){
if(direction>0){
self.MoveZombieX(self,plant.AttackedLX+0.1 - self.AttackedRX,false);
}else{
self.MoveZombieX(self,-(plant.AttackedRX-0.1 - self.ZX));//向左走是反着的,要加个负号
}
return [self.id, plant.id];
}
}
z--;
}
if(tarC===curC){
return false;
}
curC+=step;
}while(true);
},
JudgeLR(self, crood, C, ZX, G) { //远程判定,普通僵尸的远程是自己前面一格
if (C > 10 || C < 1) {
return;
}
crood += C - 1 + '_';
let z = PKindUpperLimit;
while (z >= 0) {
let plant = G[crood + z];
if (plant && plant.canEat) {
return (One_Dimensional_Intersection(self.X + self.beAttackedPointL, self.X + self.beAttackedPointR,
plant.AttackedLX, plant.AttackedRX) || plant.AttackedRX >= ZX && plant.AttackedLX <=
ZX) ? [self.id, plant.id] : false;
}
z--;
}
},
JudgeSR(self, crood, C, ZX, G) { //近程判定,普通僵尸的近程是自己所在一格
if (C > 9) {
return;
}
crood += C + "_";
let z = PKindUpperLimit;
while (z >= 0) {
let plant = G[crood + z];
if (plant && plant.canEat) {
return (One_Dimensional_Intersection(self.X + self.beAttackedPointL, self.X + self.beAttackedPointR,
plant.AttackedLX, plant.AttackedRX) || plant.AttackedRX >= ZX && plant.AttackedLX <=
ZX) ? [self.id, plant.id] : false;
}
z--;
}
},
NormalAttack(zid, pid) {
oAudioManager.playAudio(["chomp", "chompsoft", 'chomp2'].random());
oSym.addTask(50, _ => {
let self;
if (self = $Z[zid]) {
oAudioManager.playAudio(["chomp", "chompsoft", 'chomp2'].random());
}
});
oSym.addTask(100, _ => {
let self = $Z[zid];
if (self && !self.isGoingDie && self.isNotStaticed()) {
//这里需要再检测一次,否则可能会出现莫名穿过的现象,或者啃的植物不对的现象
let ZX = self.ZX;
let crood = self.R + "_";
let C = GetC(ZX);
let G = oGd.$;
let arr = (self.JudgeLR(self, crood, C, ZX, G) || self.JudgeSR(self, crood, C, ZX, G));
if (arr) {
[zid, pid] = arr;
let plant = $P[pid];
plant && plant.getHurt(self, self.AKind, self.Attack);
}
self.JudgeAttack();
}
});
},
MoveZombieX(self,x,left=true){
if(left){
self.AttackedRX -= x;
self.AttackedLX -= x;
self.ZX = self.AttackedLX;
self.X -= x;
}else{
self.AttackedRX += x;
self.AttackedLX += x;
self.ZX = self.AttackedRX;
self.X += x;
}
},
Paint(o){
SetStyle(o.Ele, {
left: `${o.X}px`
});
},
GoLeft(o, R, arR, i,stepRatio=1) { //向左走
let Speed = o.getRealSpeed(o,stepRatio);
let hookKey = 1;
if (o.isNotStaticed()) { //如果僵尸没有处于冰冻或者等待出场状态
//未临死,未攻击,进行攻击判断
!o.isAttacking && !o.isGoingDie && o.JudgeAttack(stepRatio);
if (!o.isAttacking) {
o.MoveZombieX(o,Speed);
//向左走出屏幕,算作直接死亡,不排序只更新
if (o.AttackedRX < -50) {
oZ.del(arR, i);
o.DisappearDie();
hookKey = 0;
} else { //正常移动僵尸
o.Paint(o);
}
}
}
//检查场地事件
o.ChkCell_GdType(o);
// hookKey的作用:
// hookKey=1, 表示僵尸现在正常存活,需要系统重排oZ.$
// hookKey = 0, 表示僵尸死亡,不需要系统重排oZ.$
return hookKey;
},
GoRight(o, R, arR, i,stepRatio=1) { //往右走的僵尸行动
let Speed;
let rV = 1;
let id = o.id;
if (o.isNotStaticed()) {
//未临死,未攻击,进行攻击判断
!o.isGoingDie && !o.isAttacking && o.JudgeAttack(stepRatio);
if (!o.isAttacking) {
//向右走出屏幕,算作直接死亡,不排序只更新
if (o.X > oS.W) {
oZ.del(arR, i);
o.DisappearDie();
rV = 0;
} else {
o.MoveZombieX(o,(Speed = o.getRealSpeed(o,stepRatio)),false);
o.Paint(o);
}
}
}
//检查场地事件
o.ChkCell_GdType(o);
return rV;
},
GoDown(o, R, arR, i, stepRatio=1, isInWaterPath = false) { //向下走
let rV = 1;
let newR = o.R + 1;
let id = o.id;
if (o.isNotStaticed()) {
!o.isGoingDie && !o.isAttacking && o.JudgeAttack(stepRatio);
if (!o.isAttacking) {
SetStyle(o.Ele, {
top: (o.pixelTop += o.getRealSpeed(o,stepRatio)) + 'px',
});
// 这里需要针对围歼战和水道采用两套判定,原因有二:
// 1. 原先挨炮画的地图和严格按数值对位画出来的镜花水月地图之间是存在一定误差的。
// 2. 围歼战拐弯和水道拐弯的判定实现方式有所差异。
if (
isInWaterPath ?
(o.pixelTop + o.height - (isInWaterPath ? 35 : -10) >= GetY(R)) :
(o.pixelTop + o.height - o.GetDY() >= GetY(newR))
) {
oZ.moveTo(id, o.R, newR);
}
}
}
o.ChkCell_GdType(o);
return rV;
},
GoUp(o, R, arR, i, stepRatio=1, isInWaterPath = false) {
let rV = 1;
let newR = o.R - 1;
let id = o.id;
if (o.isNotStaticed()) {
!o.isGoingDie && !o.isAttacking && o.JudgeAttack(stepRatio);
if (!o.isAttacking) {
SetStyle(o.Ele, {
top: (o.pixelTop -= o.getRealSpeed(o,stepRatio)) + 'px',
});
if (o.pixelTop + o.height <= GetY(newR) + (isInWaterPath ? 0 : o.GetDY())) {
oZ.moveTo(id, o.R, newR);
}
}
}
o.ChkCell_GdType(o);
return rV;
},
GetDY: _ => -10, //返回僵尸相对于格子中点的纵坐标偏移
GetDTop: 0, //僵尸gif跟div的顶部坐标偏移
ChangeR: function(e) { //换行
var h = e.R,
g = e.ar || [],
j = e.CustomTop,
d = this,
q = h - 1,
l,
k = d.id,
m = -1,
f = d.Ele,
n = d.EleBody,
i = GetC(d.ZX),
c;
!g.length && ( //如果没有指定移动行数组,则默认使用上下两行
d.CanPassCell(q, i) && (g[++m] = q), //只有地形跟本行一样才能移动
d.CanPassCell(q += 2, i) && (g[++m] = q)
);
g.length ? ( //可以换行
l = !d.WalkDirection ? -5 : 5,
d.ZX += l,
d.AttackedLX += l,
d.AttackedRX += l,
d.X += l,
q = g[Math.floor(Math.random() * g.length)],
SetStyle(f, {
left: d.X + "px",
top: (d.pixelTop = j == undefined ? GetY(q) - d.height + d.GetDY() : j) + "px",
'z-index': d.zIndex = 3 * q + 1
}),
d.isAttacking && (n.src = d.PicArr[d.NormalGif]),
oZ.moveTo(k, h, q)
) : (
n.src = d.PicArr[d.NormalGif]
);
d.isAttacking = 0;
},
getShadow: self => `left:${self.beAttackedPointL-10}px;top:${self.height-22}px;`,
getDisplayShadow: self => self.getShadow(self),
getCharredCSS(self) {
const body = self.EleBody;
return {
left: self.beAttackedPointL + 6,
top: self.height / 3 + self.DivingDepth / 2,
clip: self.DivingDepth > 0 ? "rect(0px, auto, 95px, 0px)" : "",
};
},
//初始化僵尸的prototype
Init(AppearX, pro, LF, MaxR) {
/*
初始化僵尸的坐标相关数据
o.R:行;o.pixelTop:顶部Y坐标;o.X:左边X坐标(相对于FightingScene);o.ZX:确定僵尸位置的点X坐标,通常是AttackedLX
o.AttackedLX,o.AttackedRX:僵尸左右受攻击点判定坐标;o.beAttackedPointL,o.beAttackedPointR:僵尸左右受攻击点判定坐标距离o.X的偏移距离,受攻击点判定坐标即可根据o.X和偏移距离计算得出
*/
let len = 0;
let o = this;
let ArR = [];
pro.ZX = pro.AttackedLX = AppearX;
pro.X = pro.ZX - pro.beAttackedPointL;
pro.AttackedRX = pro.X + pro.beAttackedPointR;
//能够出现的行数数组ArR
for (let i = 0; i <= MaxR; i++) {
pro.CanPass(i, LF[i]) && ArR.push(i);
}
pro.ArR = ArR; //僵尸能够出现的行数组
//初始化HTML字符数组
pro.ArHTML = [
`<div id="`, //0
`" data-jng-constructor="`, //1
`" style="width:${pro.width}px;height:${pro.height}px;position:absolute;display:`, //2
`;left:`, //3
`px;top:`, //4
`px;z-index:`, //5
`"><div class='Shadow' style="${pro.getShadow(pro)}"></div><img style="position:absolute;clip:rect(0,auto,`, //6
`,0);top:`, //7
`px" src="`, //8
`"></div>` //9
];
Object.hasOwn(pro, 'Almanac') && o.getAlmanacDom(pro);
},
getAlmanacDom(pro) {
if (!pro.Almanac.Dom) {
let ClassAlmanac = CZombies.prototype.Almanac;
for (let i in ClassAlmanac) {
if (!pro.Almanac[i]) {
pro.Almanac[i] = ClassAlmanac[i];
}
}
let _width = pro.displayWidth ?? pro.width;
let _height = pro.displayHeight ?? pro.height;
pro.Almanac.Dom = pro.getDisplayHTML("", 170 - _width / 2, 450 - _height, "1;height:" + _height + "px;width:" + _width + "px", "block", "auto", pro.GetDTop, pro.PicArr[pro.StandGif]);
}
},
getHTML(id, wrapLeft, wrapTop, zIndex, display, clip, top, img) { //渲染僵尸html代码
const self = this,
T = self.ArHTML;
return T[0] + id + T[1] + self.EName + T[2] + display + T[3] + wrapLeft + T[4] + wrapTop + T[5] + zIndex + T[6] + clip + T[7] + top + T[8] + img + T[9];
},
getDisplayHTML(id, wrapLeft, wrapTop, zIndex, display, clip, top, img) {
const self = this;
return `<div id="${id}" data-jng-constructor="${self.EName}" style="width:${self.displayWidth ?? self.width}px;height:${self.displayHeight ?? self.height}px;position:absolute;left:${wrapLeft}px;top:${wrapTop}px;z-index:${zIndex};display:${display};"><div class='Shadow' style="${self.getDisplayShadow(self)}"></div><img style="position:absolute;clip:rect(0,auto,${clip},0);top:${top}px" src="${img}"></div>`;
},
//普通诞生事件,由程序自动调用,在每波刷新
//初始化僵尸样式,编译僵尸html代码
prepareBirth(delayT) {
let self = this;
let id = self.id = "Z_" + Math.random();
let R = self.R = oP.randomGetLine(self.ArR,self.Lvl); //生成僵尸所在行数随机
let top = self.pixelTop = GetY(R) + self.GetDY() - self.height; //计算僵尸顶部坐标
self.zIndex = 3 * R + 1;
self.zIndex_cont = Math.round(self.pixelTop + self.height);
//设置延迟出场时间
if (self.delayT = delayT) {
self.getStatic({
time: Infinity,
type: "SetBody",
forced: true,
useStaticCanvas: false,
usePolling: false,
});
}
return self.getHTML(id, self.X, top, self.zIndex_cont, "none", "auto", self.GetDTop, self.PicArr[self.NormalGif]);
},
//特殊诞生事件,传递自定义的坐标,比如从坟墓出生
CustomBirth(R, C, delayT, clipH) {
const self = this;
const bottomY = GetY(R) + self.GetDY(); //僵尸脚部坐标=当前行下边缘坐标+(-自定义向上偏移)
const pixelTop = bottomY - self.height, //僵尸图像顶端坐标=僵尸脚部坐标-僵尸图片高度
id = self.id = "Z_" + Math.random(),
beAttackedPointL = self.beAttackedPointL,
beAttackedPointR = self.beAttackedPointR;
self.ZX = self.AttackedLX = GetX(C) - (beAttackedPointR - beAttackedPointL) * 0.5;
self.X = self.ZX - beAttackedPointL;
self.AttackedRX = self.X + beAttackedPointR;
self.R = R;
self.pixelTop = pixelTop;
self.zIndex = 3 * R + 1;
self.zIndex_cont = Math.round(self.pixelTop + self.height);
if (self.delayT = delayT) {
// SetBody由于是供底层代码控制僵尸延时出场的,比较特殊
// 所以为了保险起见,定身状态需要手工解除
self.getStatic({
time: Infinity,
type: "SetBody",
useStaticCanvas: false,
forced: true,
usePolling: false,
});
}
return self.getHTML(id, self.X, pixelTop, self.zIndex_cont, "none", clipH || 0, self.GetDTop, self.PicArr[self.NormalGif]);
},
Birth(json = {}) { //唤醒僵尸,注册$Z和oZ
let self = this;
if (!json.dont_set_original_value) { //不设置原始数据,例如OAttack,OSpeed之类,否则默认备份OAttack,OSpeed
self.OAttack = self.Attack;
self.OSpeed = self.Speed;
}
self.HeadTargetPosition = JSON.parse(JSON.stringify(self.HeadTargetPosition)); //深拷贝头部坐标,避免改的时候直接改成prototype的
self.PicArr = self.PicArr.slice(); //复制一份数组,避免中途更改PicArr
self.DiyConfigs = {};
$Z[self.id] = self;
oZ.add(self);
let id = self.id;
let ele = self.Ele = $(id);
self.EleShadow = ele.firstChild;
self.EleBody = ele.childNodes[1];
if(self.ShieldHP > 0){
self.OShieldHP = self.ShieldHP;
let scl = 0.75+0.03*self.OShieldHP;
NewImg(`buff_shield_${Math.random()}`, "images/Zombies/buff_shield.png", (self.getShieldCSS ? self.getShieldCSS(self) : "left:65px;top:"+(60+self.OShieldHP)+"px;") + "z-index:5; transform: scale(" + scl + ");", ele, {
className: 'buff_shield'
});
}
if(oS.ZombieRandomSpeed && !self.isPuppet){
let delta = Math.Clamp(Math.Grandom(0,oS.ZombieRandomSpeed/3),-oS.ZombieRandomSpeed/3,oS.ZombieRandomSpeed/3);
self.Speed+=delta;
self.OSpeed+=delta;
}
self.BirthCallBack(self);
if (self.CanGoThroughWater && oGd.$GdType[self.R][Math.Clamp(GetC(self.ZX), 1, oS.C)] === 2) {
self.ChkActs = self.GoThroughWater;
oS.observeZombieLayer && oZombieLayerManager.addZombie(self);
}
oSym.addTask(self.delayT, _ => {
self.PicArr = self.PicArr.map(pic => oDynamicPic.checkOriginalURL(pic) ? oDynamicPic.require(pic, null, true) : oURL.removeParam(pic, "useDynamicPic"));
IsHttpEnvi && ele.addEventListener("DOMNodeRemoved", (event) => {
if (event.target === ele && (!ele.id || !$(ele.id))) {
setTimeout(self.RemoveDynamicPic.bind(self), 1);
}
});
self.EleBody.src = self.PicArr[self.NormalGif];
});
},
BirthCallBack(self) {
let delayT = self.delayT;
let id = self.id;
let ele = self.Ele = $(id);
self.EleShadow = ele.firstChild;
self.EleBody = ele.childNodes[1];
if (delayT) {
oSym.addTask(delayT, () => {
self.freeStaticEffect(self, "SetBody");
$Z[id] && SetBlock(ele);
});
} else {
SetBlock(ele);
}
},
RemoveDynamicPic() {
const self = this;
const BlobUrlStorage = oDynamicPic.__BlobUrlStorage__;
const ProtoPicArr = self.__proto__.PicArr;
self.PicArr.forEach((pic, idx) => {
let originalURL = ProtoPicArr[idx];
if (/^blob:/.test(pic) && oURL.getParam(originalURL, "forbidRemoving") !== "true") {
oDynamicPic.remove(pic, oURL.removeParam(originalURL));
}
});
},
getCrushed: function(c) {
return true
},
getRaven: function() {
return this.DisappearDie(),
1
},
getShield(self, HP) {
if (self.ShieldHP > 0) return;
self.ShieldHP=self.ShieldHP+HP;
self.OShieldHP = self.ShieldHP;
let ele = self.Ele;
let scl = 0.75 + 0.03 * self.OShieldHP;
NewImg(`buff_shield_${Math.random()}`, "images/Zombies/buff_shield.png", (self.getShieldCSS ? self.getShieldCSS(self) : "left:65px;top:"+(60+self.OShieldHP)+"px;") + "z-index:5; opacity:0; transform: scale(" + (scl * 2) + ");", ele, {
className: 'buff_shield'
});
oEffects.Animate(ele.querySelector('.buff_shield'), {
opacity: 1,
transform: "scale(" + scl + ")"
}, 0.3 / oSym.NowSpeed);
oAudioManager.playAudio("shield_get");
// 兴奋buff可以抵消僵尸的削弱/定身效果
self.freeStaticEffect(self, "All");
if (self.FreeSlowTime || self.FreeVertigoTime || !self.isNotStaticed()) {
self.Speed = self.OSpeed;
self.Attack = self.OAttack;
self.FreeSlowTime = 0;
self.FreeVertigoTime = 0;
ClearChild(...ele.querySelectorAll('.buff_freeze,.buff_vertigo'));
!$User.LowPerformanceMode && EditCompositeStyle({
ele: self.EleBody,
styleName: 'filter',
delFuncs: [
['url', oSVG.getSVG('getSnowPea')]
],
option: 2
});
return;
}
},
getShieldHit(self) {
self.ShieldHP--;
let ele = self.Ele;
let scl = 0.75 + 0.03 * self.OShieldHP;
if (self.ShieldHP <= 0) {
oSym.addTask(100, () => {
oAudioManager.playAudio("shield_dispel");
oEffects.Animate(ele.querySelector('.buff_shield'), {
opacity: 0,
transform: "scale(" + (scl * 1.5) + ")"
}, 0.3 / oSym.NowSpeed, null, ClearChild);
});
} else if (Math.ceil(self.ShieldHP) === Math.ceil(self.OShieldHP / 2)) {
ClearChild(ele.querySelector('.buff_shield'));
NewImg(`buff_shield_${Math.random()}`, "images/Zombies/buff_shield_2.png", (self.getShieldCSS ? self.getShieldCSS(self) : "left:65px;top:" + (60 + self.OShieldHP) + "px;") + "z-index:5; transform: scale(" + scl + ");", ele, {
className: 'buff_shield'
});
}
},
/* 如果僵尸血量大于1800,则扣除血量1800
如果僵尸血量小于1800,则可被炸弹直接炸死 */
getExplosion: function() {
let self = this,
dmg = Math.round(500/self.ResistInsta);
if (self.ShieldHP > 0) {
self.getShieldHit(self);
}
else {self.HP > dmg ? self.HP -= dmg : $Z[self.id] && !self.isGoingDie && self.ExplosionDie();}
},
getThump: function() {
this.DisappearDie()
},
PlayNormalballAudio: function() {
oAudioManager.playAudio("splat" + Math.floor(1 + Math.random() * 3))
},
PlayFireballAudio: function() {
oAudioManager.playAudio("ignite");
},
PlaySlowballAudio: function() {
oAudioManager.playAudio("frozen")
},
/* 僵尸定身效果封装代码 开始 */
// 创建定身用的静态canvas
createStaticCanvas(self, body) {
const Width = body.width;
const Height = body.height;
let canvas = NewEle(self.id + "_StaticBody", "canvas", body.style.cssText, {
"width": Width,
"height": Height,
}, self.Ele);
let ctx = canvas.getContext("2d");
ctx.drawImage(body, 0, 0, Width, Height);
SetNone(body);
self.__TMP_ELEBODY__ = body;
self.EleBody = canvas;
for (let { nodeName, nodeValue } of self.__TMP_ELEBODY__.attributes) {
if (!/id|width|height|style|src/.test(nodeName)) {
canvas.setAttribute(nodeName, nodeValue);
}
}
return canvas;
},
// 定时轮询,实时监控僵尸状态
// 一方面在僵尸死亡时及时强制触发freeStaticEffect(垂死不需要额外监控,通过GoingDie方法触发即可)
// 另一方面,控制canvas贴图和僵尸真正的EleBody(即参数中的bodyElement)同步
pollStaticStation(self, id, bodyElement, lastSrc) {
const draw = (token, canvas) => {
// 如果有更加新的贴图被更新过来,则放弃当前的绘制操作
if (!$Z[id] || token !== self.ChangeBodyImageToken) return;
let ctx = canvas.getContext("2d");
let [width, height] = [canvas.width, canvas.height];
ctx.clearRect(0, 0, width, height);
ctx.drawImage(bodyElement, 0, 0, width, height);
}
if (self.isNotStaticed()) return;
if (!$Z[id]) {
self.freeStaticEffect(self, "All");
} else if ($Z[id] && !self.isGoingDie) {
let newSrc = lastSrc;
let canvas = self.__CanvasBody__;
if (canvas) {
// 如果canvas的src属性被更新,则需要进行同步
if (canvas.src && canvas.src !== lastSrc) {
// 取得更新到canvas元素的src值,将其应用到真正的EleBody上
newSrc = bodyElement.src = canvas.src;
canvas.src = "";
// 监控真正的EleBody的加载状态,以便加载完成后将新贴图绘制到canvas上
let token = self.ChangeBodyImageToken = oSym.Now;
bodyElement.complete ?
draw(token, canvas) :
bodyElement.addEventListener("load", draw.bind(null, token, canvas), {
once: true
});
}
}
// 调用自定义函数更新僵尸糊脸图案(如黄油)的css信息(如有需要的话)
for (let effect of self.StaticEffectList) {
let func = self.__UpdateImgFuncs__[effect];
func && func(self, $(`${id}_StaticEffect_${effect}`), canvas);
}
// 递归实现轮询监控
oSym.addTask($User.LowPerformanceMode ? 3 : 2,
self.pollStaticStation, [self, id, bodyElement, newSrc]);
}
},
// 解除僵尸定身效果
freeStaticEffect(self, type, isNormal = false) {
const list = self.StaticEffectList;
const freeEffect = (type) => {
list.delete(type);
oSym.removeTask(self.__NormalTask__[type]);
ClearChild($(`${self.id}_StaticEffect_${type}`));
self[`Free${type}Time`] = 0;
};
if (self.isNotStaticed() || type !== "All" && !list.has(type)) {
return;
}
if (type === "All") {
for (let _type of list) freeEffect(_type);
} else {
freeEffect(type);
}
// 如果僵尸的所有定身效果都已经解除
// 则清除canvas,恢复僵尸原本的EleBody
let canvas = self.__CanvasBody__;
if (list.size <= 0) {
// 重新显示EleBody
if ($Z[self.id] && canvas) {
let body = self.EleBody = self.__TMP_ELEBODY__;
canvas.src && canvas.src !== body.src && (body.src = canvas.src);
body.style.cssText = canvas.style.cssText;
for (let { nodeName, nodeValue } of canvas.attributes) {
if (!/id|width|height|style|src/.test(nodeName)) {
body.setAttribute(nodeName, nodeValue);
}
}
SetBlock(body);
ClearChild(canvas);
}
delete self.__TMP_ELEBODY__;
delete self.__CanvasBody__;
delete self.__NormalTask__;
}
// 考虑到游戏设计的灵活性,不再对回调函数进行进一步封装!
// 请自行根据需要编写僵尸解除定身后的代码!
let callback = self.__NormalCallback__[type];
callback && callback(self, list.size <= 0, isNormal, list);
},
// 注:imgConfig包含{ src, render, update }
getStatic({time, type, callback, forced = false, usePolling = true, useStaticCanvas = true, imgConfig}) {
let self = this;
let id = self.id;
let body = self.__TMP_ELEBODY__ || self.EleBody;
// StaticEffectList用于标记僵尸处于定身状态
let list = self.StaticEffectList ?? (self.StaticEffectList = new Set());
if (!forced && (!$Z[id] || self.HP < self.BreakPoint || self.isPuppet || self.isGoingDie)) {
return;
}
// 生成canvas,绘制僵尸静态图片
if (!self.__CanvasBody__ && useStaticCanvas) {
self.__CanvasBody__ = self.createStaticCanvas(self, body);
}
// 如果当前僵尸原先未应用定身效果,则需要进行一些初始化
if (list.size <= 0) {
// 初始化属性
self.__UpdateImgFuncs__ = {};
self.__NormalCallback__ = {};
self.__NormalTask__ = {};
// 异步启动监控
usePolling && oSym.addTask(0, self.pollStaticStation, [self, id, body, body.src]);
}
// 如果僵尸当前没有应用这种定身特效
if (!list.has(type)) {
if (imgConfig) {
let {src, render, update} = imgConfig;
render(self, NewImg(`${id}_StaticEffect_${type}`, src, "", self.Ele, {