···6767Licensor receives from making the Licensed Material available under
6868these terms and conditions.
69697070-7170Section 1 -- Definitions.
72717373- a. Adapted Material means material subject to Copyright and Similar
7474- Rights that is derived from or based upon the Licensed Material
7575- and in which the Licensed Material is translated, altered,
7676- arranged, transformed, or otherwise modified in a manner requiring
7777- permission under the Copyright and Similar Rights held by the
7878- Licensor. For purposes of this Public License, where the Licensed
7979- Material is a musical work, performance, or sound recording,
8080- Adapted Material is always produced where the Licensed Material is
8181- synched in timed relation with a moving image.
7272+a. Adapted Material means material subject to Copyright and Similar
7373+Rights that is derived from or based upon the Licensed Material
7474+and in which the Licensed Material is translated, altered,
7575+arranged, transformed, or otherwise modified in a manner requiring
7676+permission under the Copyright and Similar Rights held by the
7777+Licensor. For purposes of this Public License, where the Licensed
7878+Material is a musical work, performance, or sound recording,
7979+Adapted Material is always produced where the Licensed Material is
8080+synched in timed relation with a moving image.
82818383- b. Copyright and Similar Rights means copyright and/or similar rights
8484- closely related to copyright including, without limitation,
8585- performance, broadcast, sound recording, and Sui Generis Database
8686- Rights, without regard to how the rights are labeled or
8787- categorized. For purposes of this Public License, the rights
8888- specified in Section 2(b)(1)-(2) are not Copyright and Similar
8989- Rights.
8282+b. Copyright and Similar Rights means copyright and/or similar rights
8383+closely related to copyright including, without limitation,
8484+performance, broadcast, sound recording, and Sui Generis Database
8585+Rights, without regard to how the rights are labeled or
8686+categorized. For purposes of this Public License, the rights
8787+specified in Section 2(b)(1)-(2) are not Copyright and Similar
8888+Rights.
90899191- c. Effective Technological Measures means those measures that, in the
9292- absence of proper authority, may not be circumvented under laws
9393- fulfilling obligations under Article 11 of the WIPO Copyright
9494- Treaty adopted on December 20, 1996, and/or similar international
9595- agreements.
9090+c. Effective Technological Measures means those measures that, in the
9191+absence of proper authority, may not be circumvented under laws
9292+fulfilling obligations under Article 11 of the WIPO Copyright
9393+Treaty adopted on December 20, 1996, and/or similar international
9494+agreements.
96959797- d. Exceptions and Limitations means fair use, fair dealing, and/or
9898- any other exception or limitation to Copyright and Similar Rights
9999- that applies to Your use of the Licensed Material.
9696+d. Exceptions and Limitations means fair use, fair dealing, and/or
9797+any other exception or limitation to Copyright and Similar Rights
9898+that applies to Your use of the Licensed Material.
10099101101- e. Licensed Material means the artistic or literary work, database,
102102- or other material to which the Licensor applied this Public
103103- License.
100100+e. Licensed Material means the artistic or literary work, database,
101101+or other material to which the Licensor applied this Public
102102+License.
104103105105- f. Licensed Rights means the rights granted to You subject to the
106106- terms and conditions of this Public License, which are limited to
107107- all Copyright and Similar Rights that apply to Your use of the
108108- Licensed Material and that the Licensor has authority to license.
104104+f. Licensed Rights means the rights granted to You subject to the
105105+terms and conditions of this Public License, which are limited to
106106+all Copyright and Similar Rights that apply to Your use of the
107107+Licensed Material and that the Licensor has authority to license.
109108110110- g. Licensor means the individual(s) or entity(ies) granting rights
111111- under this Public License.
109109+g. Licensor means the individual(s) or entity(ies) granting rights
110110+under this Public License.
112111113113- h. NonCommercial means not primarily intended for or directed towards
114114- commercial advantage or monetary compensation. For purposes of
115115- this Public License, the exchange of the Licensed Material for
116116- other material subject to Copyright and Similar Rights by digital
117117- file-sharing or similar means is NonCommercial provided there is
118118- no payment of monetary compensation in connection with the
119119- exchange.
120120-121121- i. Share means to provide material to the public by any means or
122122- process that requires permission under the Licensed Rights, such
123123- as reproduction, public display, public performance, distribution,
124124- dissemination, communication, or importation, and to make material
125125- available to the public including in ways that members of the
126126- public may access the material from a place and at a time
127127- individually chosen by them.
112112+h. NonCommercial means not primarily intended for or directed towards
113113+commercial advantage or monetary compensation. For purposes of
114114+this Public License, the exchange of the Licensed Material for
115115+other material subject to Copyright and Similar Rights by digital
116116+file-sharing or similar means is NonCommercial provided there is
117117+no payment of monetary compensation in connection with the
118118+exchange.
128119129129- j. Sui Generis Database Rights means rights other than copyright
130130- resulting from Directive 96/9/EC of the European Parliament and of
131131- the Council of 11 March 1996 on the legal protection of databases,
132132- as amended and/or succeeded, as well as other essentially
133133- equivalent rights anywhere in the world.
120120+i. Share means to provide material to the public by any means or
121121+process that requires permission under the Licensed Rights, such
122122+as reproduction, public display, public performance, distribution,
123123+dissemination, communication, or importation, and to make material
124124+available to the public including in ways that members of the
125125+public may access the material from a place and at a time
126126+individually chosen by them.
134127135135- k. You means the individual or entity exercising the Licensed Rights
136136- under this Public License. Your has a corresponding meaning.
128128+j. Sui Generis Database Rights means rights other than copyright
129129+resulting from Directive 96/9/EC of the European Parliament and of
130130+the Council of 11 March 1996 on the legal protection of databases,
131131+as amended and/or succeeded, as well as other essentially
132132+equivalent rights anywhere in the world.
137133134134+k. You means the individual or entity exercising the Licensed Rights
135135+under this Public License. Your has a corresponding meaning.
138136139137Section 2 -- Scope.
140138141141- a. License grant.
139139+a. License grant.
142140143141 1. Subject to the terms and conditions of this Public License,
144142 the Licensor hereby grants You a worldwide, royalty-free,
···193191 the Licensor or others designated to receive attribution as
194192 provided in Section 3(a)(1)(A)(i).
195193196196- b. Other rights.
194194+b. Other rights.
197195198196 1. Moral rights, such as the right of integrity, are not
199197 licensed under this Public License, nor are publicity,
···215213 the Licensed Material is used other than for NonCommercial
216214 purposes.
217215218218-219216Section 3 -- License Conditions.
220217221218Your exercise of the Licensed Rights is expressly made subject to the
222219following conditions.
223220224224- a. Attribution.
221221+a. Attribution.
225222226223 1. If You Share the Licensed Material, You must:
227224···265262 information required by Section 3(a)(1)(A) to the extent
266263 reasonably practicable.
267264268268-269265Section 4 -- Sui Generis Database Rights.
270266271267Where the Licensed Rights include Sui Generis Database Rights that
272268apply to Your use of the Licensed Material:
273269274274- a. for the avoidance of doubt, Section 2(a)(1) grants You the right
275275- to extract, reuse, reproduce, and Share all or a substantial
276276- portion of the contents of the database for NonCommercial purposes
277277- only and provided You do not Share Adapted Material;
270270+a. for the avoidance of doubt, Section 2(a)(1) grants You the right
271271+to extract, reuse, reproduce, and Share all or a substantial
272272+portion of the contents of the database for NonCommercial purposes
273273+only and provided You do not Share Adapted Material;
278274279279- b. if You include all or a substantial portion of the database
280280- contents in a database in which You have Sui Generis Database
281281- Rights, then the database in which You have Sui Generis Database
282282- Rights (but not its individual contents) is Adapted Material; and
275275+b. if You include all or a substantial portion of the database
276276+contents in a database in which You have Sui Generis Database
277277+Rights, then the database in which You have Sui Generis Database
278278+Rights (but not its individual contents) is Adapted Material; and
283279284284- c. You must comply with the conditions in Section 3(a) if You Share
285285- all or a substantial portion of the contents of the database.
280280+c. You must comply with the conditions in Section 3(a) if You Share
281281+all or a substantial portion of the contents of the database.
286282287283For the avoidance of doubt, this Section 4 supplements and does not
288284replace Your obligations under this Public License where the Licensed
289285Rights include other Copyright and Similar Rights.
290286291291-292287Section 5 -- Disclaimer of Warranties and Limitation of Liability.
293288294294- a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
295295- EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
296296- AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
297297- ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
298298- IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
299299- WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
300300- PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
301301- ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
302302- KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
303303- ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
304304-305305- b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
306306- TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
307307- NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
308308- INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
309309- COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
310310- USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
311311- ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
312312- DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
313313- IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
289289+a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
290290+EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
291291+AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
292292+ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
293293+IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
294294+WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
295295+PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
296296+ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
297297+KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
298298+ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
314299315315- c. The disclaimer of warranties and limitation of liability provided
316316- above shall be interpreted in a manner that, to the extent
317317- possible, most closely approximates an absolute disclaimer and
318318- waiver of all liability.
300300+b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
301301+TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
302302+NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
303303+INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
304304+COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
305305+USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
306306+ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
307307+DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
308308+IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
319309310310+c. The disclaimer of warranties and limitation of liability provided
311311+above shall be interpreted in a manner that, to the extent
312312+possible, most closely approximates an absolute disclaimer and
313313+waiver of all liability.
320314321315Section 6 -- Term and Termination.
322316323323- a. This Public License applies for the term of the Copyright and
324324- Similar Rights licensed here. However, if You fail to comply with
325325- this Public License, then Your rights under this Public License
326326- terminate automatically.
317317+a. This Public License applies for the term of the Copyright and
318318+Similar Rights licensed here. However, if You fail to comply with
319319+this Public License, then Your rights under this Public License
320320+terminate automatically.
327321328328- b. Where Your right to use the Licensed Material has terminated under
329329- Section 6(a), it reinstates:
322322+b. Where Your right to use the Licensed Material has terminated under
323323+Section 6(a), it reinstates:
330324331325 1. automatically as of the date the violation is cured, provided
332326 it is cured within 30 days of Your discovery of the
···338332 right the Licensor may have to seek remedies for Your violations
339333 of this Public License.
340334341341- c. For the avoidance of doubt, the Licensor may also offer the
342342- Licensed Material under separate terms or conditions or stop
343343- distributing the Licensed Material at any time; however, doing so
344344- will not terminate this Public License.
345345-346346- d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
347347- License.
335335+c. For the avoidance of doubt, the Licensor may also offer the
336336+Licensed Material under separate terms or conditions or stop
337337+distributing the Licensed Material at any time; however, doing so
338338+will not terminate this Public License.
348339340340+d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
341341+License.
349342350343Section 7 -- Other Terms and Conditions.
351344352352- a. The Licensor shall not be bound by any additional or different
353353- terms or conditions communicated by You unless expressly agreed.
354354-355355- b. Any arrangements, understandings, or agreements regarding the
356356- Licensed Material not stated herein are separate from and
357357- independent of the terms and conditions of this Public License.
345345+a. The Licensor shall not be bound by any additional or different
346346+terms or conditions communicated by You unless expressly agreed.
358347348348+b. Any arrangements, understandings, or agreements regarding the
349349+Licensed Material not stated herein are separate from and
350350+independent of the terms and conditions of this Public License.
359351360352Section 8 -- Interpretation.
361353362362- a. For the avoidance of doubt, this Public License does not, and
363363- shall not be interpreted to, reduce, limit, restrict, or impose
364364- conditions on any use of the Licensed Material that could lawfully
365365- be made without permission under this Public License.
354354+a. For the avoidance of doubt, this Public License does not, and
355355+shall not be interpreted to, reduce, limit, restrict, or impose
356356+conditions on any use of the Licensed Material that could lawfully
357357+be made without permission under this Public License.
366358367367- b. To the extent possible, if any provision of this Public License is
368368- deemed unenforceable, it shall be automatically reformed to the
369369- minimum extent necessary to make it enforceable. If the provision
370370- cannot be reformed, it shall be severed from this Public License
371371- without affecting the enforceability of the remaining terms and
372372- conditions.
359359+b. To the extent possible, if any provision of this Public License is
360360+deemed unenforceable, it shall be automatically reformed to the
361361+minimum extent necessary to make it enforceable. If the provision
362362+cannot be reformed, it shall be severed from this Public License
363363+without affecting the enforceability of the remaining terms and
364364+conditions.
373365374374- c. No term or condition of this Public License will be waived and no
375375- failure to comply consented to unless expressly agreed to by the
376376- Licensor.
366366+c. No term or condition of this Public License will be waived and no
367367+failure to comply consented to unless expressly agreed to by the
368368+Licensor.
377369378378- d. Nothing in this Public License constitutes or may be interpreted
379379- as a limitation upon, or waiver of, any privileges and immunities
380380- that apply to the Licensor or You, including from the legal
381381- processes of any jurisdiction or authority.
370370+d. Nothing in this Public License constitutes or may be interpreted
371371+as a limitation upon, or waiver of, any privileges and immunities
372372+that apply to the Licensor or You, including from the legal
373373+processes of any jurisdiction or authority.
382374383375=======================================================================
384376···400392public licenses.
401393402394Creative Commons may be contacted at creativecommons.org.
403403-
···99 property="og:description"
1010 content="Play Plants vs Zombies Modded here for Free - A tower defense game created by PopCap Games and released on May 5, 2009. Click to Play now! Mod by ROBLNET13 on Github."
1111 />
1212- <meta property="og:url" content="https://pvzm.net/game/iframe.html" />
1212+ <meta property="og:url" content="https://pvzm.net/game" />
1313 <meta property="og:site_name" content="ROBLNET13" />
1414 <meta property="og:image" content="https://pvzm.net/game/images/gamethumbnail5.png" />
1515 <meta property="og:image:alt" content="Plants vs. Zombies - MODDED" />
···11+/* eslint-disable complexity */
12var $User = (function () {
22- var b = navigator.platform;
33- var i = navigator.userAgent;
44- var f = b === "Win32" || b === "Windows";
55- var g = b === "Mac68K" || b === "MacPPC" || b === "Macintosh";
66- var d = b === "X11" && !f && !g;
77- var h = f || g || d;
88- var a = "";
99- var c = !!(window.attachEvent && !window.opera);
1010- var e = c && !window.XMLHttpRequest;
1111- var j = location.protocol.toLowerCase() === "http:" ? 1 : 0;
1212- $Random = j ? "#" : "?";
1313- innerText = c
1414- ? function (l, k) {
1515- l.innerText = k;
33+ const platform = navigator.platform;
44+ const userAgent = navigator.userAgent;
55+ const isWin = platform === "Win32" || platform === "Windows";
66+ const isMac = platform === "Mac68K" || platform === "MacPPC" || platform === "Macintosh";
77+ const isUnix = platform === "X11" && !isWin && !isMac;
88+ const isPC = isWin || isMac || isUnix;
99+1010+ const isIE = !!(window.attachEvent && !window.opera);
1111+ const isIE6 = isIE && !window.XMLHttpRequest;
1212+ const isHTTP = location.protocol.toLowerCase() === "http:" ? 1 : 0;
1313+1414+ // Global Random Helper
1515+ $Random = isHTTP ? "#" : "?";
1616+1717+ // Text setting helper based on browser capability
1818+ innerText = isIE
1919+ ? function (element, text) {
2020+ element.innerText = text;
1621 }
1717- : function (l, k) {
1818- l.textContent = k;
2222+ : function (element, text) {
2323+ element.textContent = text;
1924 };
2020- e ? (document.execCommand("BackgroundImageCache", false, true), (ShadowPNG = "")) : (ShadowPNG = "images/interface/plantshadow32.png");
2525+2626+ // PNG fix for IE6
2727+ if (isIE6) {
2828+ document.execCommand("BackgroundImageCache", false, true);
2929+ ShadowPNG = "";
3030+ } else {
3131+ ShadowPNG = "images/interface/plantshadow32.png";
3232+ }
3333+2134 innerHTML = function (element, content) {
2235 if (element) {
2336 element.innerHTML = content;
2437 }
2538 };
3939+2640 return {
2741 Browser: {
2828- IE: c,
2929- IE6: e,
3030- IE9: c && i.indexOf("MSIE 9.0") > 0,
4242+ IE: isIE,
4343+ IE6: isIE6,
4444+ IE9: isIE && userAgent.indexOf("MSIE 9.0") > 0,
3145 Opera: !!window.opera,
3232- WebKit: i.includes("AppleWebKit/"),
3333- Gecko: i.includes("Gecko") && !i.includes("KHTML"),
4646+ WebKit: userAgent.includes("AppleWebKit/"),
4747+ Gecko: userAgent.includes("Gecko") && !userAgent.includes("KHTML"),
3448 },
3549 Server: {
3636- List: [[]],
3737- SpeedURL: "",
3838- DataURL: "",
3939- SpeedInx: 0,
4040- DataInx: 0,
4141- ErrNum: 0,
5050+ URL: "https://backend.pvzm.net",
4251 },
4352 HTML5: (function () {
4453 return !!document.createElement("canvas").getContext;
4554 })(),
4646- System: { Win: f, Mac: g, Unix: d },
4747- Client: { PC: h, Mobile: !h },
4848- HTTP: j,
4949- AuthorWebsite: a,
5555+ System: { Win: isWin, Mac: isMac, Unix: isUnix },
5656+ Client: { PC: isPC, Mobile: !isPC },
5757+ HTTP: isHTTP,
5858+ AuthorWebsite: "",
5059 isAuthorWebsite: false,
5160 Visitor: {
5261 UserName: "",
···6069 },
6170 };
6271})();
7272+6373var oSym = {
6464- // initialize the symbol object
6565- Init(b, a) {
6666- this.Now = 0; // current time
6767- this.Timer = this.execTask = null; // timer and task execution variables
6868- this.TQ = [{ T: 0, f: b, ar: a || [] }]; // task queue, initialized with the first task
6969- this.NowStep = 1; // time step for advancing current time
7070- this.TimeStep = 10; // time interval for timers
7171- this.Start(); // start the symbol object's timers
7474+ // Initialize the symbol object
7575+ Init(callback, args) {
7676+ this.Now = 0; // Current time
7777+ this.Timer = null;
7878+ this.execTask = null;
7979+ // Task Queue: { Time, Function, Arguments }
8080+ this.TQ = [{ T: 0, f: callback, ar: args || [] }];
8181+ this.NowStep = 1; // Time increment step
8282+ this.TimeStep = 10; // Real-time ms per step
8383+ this.Start();
7284 },
7373- // clear all tasks from the queue
8585+ // Clear all tasks
7486 Clear() {
7587 this.TQ.length = 0;
7688 },
7777- // start the symbol object's timers
8989+ // Start timers
7890 Start() {
7991 if (this.Timer == null) {
8080- // only start if not already started
8181- // timer to advance the current time
8282- (function () {
8383- var a = oSym;
9292+ // Timer 1: Advance internal game time (Now)
9393+ (function stepTime() {
8494 try {
8585- a.Now += a.NowStep; // increment current time
8686- } catch (b) {
8787- alert("Timeout to quit the game"); // error handling for timeout
8888- location.reload(); // reload the page
9595+ oSym.Now += oSym.NowStep;
9696+ } catch (e) {
9797+ alert("Timeout to quit the game");
9898+ location.reload();
8999 }
9090- a.Timer = setTimeout(arguments.callee, a.TimeStep); // set next timeout
100100+ oSym.Timer = setTimeout(stepTime, oSym.TimeStep);
91101 })();
9292- // timer to execute tasks from the queue
9393- (function () {
9494- var d = oSym;
9595- var a = d.TQ; // task queue
9696- var c = a.length;
9797- var b; // current task
9898- var e; // task function
9999- while (c--) {
100100- // iterate through tasks in reverse
101101- if (d.Now >= (b = a[c]).T) {
102102- // if task time is due
102102+103103+ // Timer 2: Execute tasks based on game time
104104+ (function runTasks() {
105105+ const sym = oSym;
106106+ const queue = sym.TQ;
107107+ let len = queue.length;
108108+ let task, func;
109109+110110+ // Iterate backwards to allow safe removal
111111+ while (len--) {
112112+ task = queue[len];
113113+ if (sym.Now >= task.T) {
103114 try {
104104- (e = b.f).apply(e, b.ar); // execute task function with arguments
105105- } catch (Reason) {
106106- console.error(Reason); // log any errors during task execution
115115+ func = task.f;
116116+ func.apply(func, task.ar);
117117+ } catch (err) {
118118+ console.error(err);
107119 }
108108- d.removeTask(c); // remove executed task from queue
120120+ sym.removeTask(len);
109121 }
110122 }
111111- d.execTask = setTimeout(arguments.callee, d.TimeStep); // set next timeout for task execution
123123+ sym.execTask = setTimeout(runTasks, sym.TimeStep);
112124 })();
113125 }
114126 },
115115- // stop the symbol object's timers
127127+ // Stop timers
116128 Stop() {
117117- clearTimeout(oSym.Timer); // clear current time timer
118118- clearTimeout(oSym.execTask); // clear task execution timer
119119- oSym.Timer = null; // reset timer variable
120120- oSym.execTask = null; // reset task execution variable
129129+ clearTimeout(oSym.Timer);
130130+ clearTimeout(oSym.execTask);
131131+ oSym.Timer = null;
132132+ oSym.execTask = null;
121133 },
122122- // add a new task to the queue
123123- addTask(b, c, a) {
124124- var d = this.TQ;
125125- // add task with its scheduled time (Now + delay), function, and arguments
126126- d[d.length] = { T: this.Now + b, f: c, ar: a };
134134+ // Add task to queue
135135+ addTask(delay, func, args) {
136136+ const queue = this.TQ;
137137+ queue[queue.length] = {
138138+ T: this.Now + delay,
139139+ f: func,
140140+ ar: args,
141141+ };
127142 return this;
128143 },
129129- // remove a task from the queue by its index
130130- removeTask(a) {
131131- this.TQ.splice(a, 1); // remove task at the given index
144144+ // Remove task by index
145145+ removeTask(index) {
146146+ this.TQ.splice(index, 1);
132147 return this;
133148 },
134149};
150150+135151var oS = {
136152 Version: 5,
137153 W: 880,
138154 H: 600,
139139- C: 9,
155155+ C: 9, // Columns
140156 B: atob,
141157 LawnMowerX: 70,
142158 Lvl: 0,
···145161 SelfVariables: [],
146162 LvlClearFunc: null,
147163 AutoSun: 0,
148148- Init(e, g, b, d) {
149149- var c;
150150- var a = window;
151151- e.LoadMusic ? (PlayMusic(e.LoadMusic), NewAudio({ source: "ChooseYourSeeds", loop: true })) : PlayMusic((e.LoadMusic = "ChooseYourSeeds"));
152152- if (b !== d) {
153153- for (c in b) {
154154- a[c] !== d ? ((this.GlobalVariables[c] = a[c]), (a[c] = b[c])) : (this.LvlVariables[c] = a[c] = b[c]);
164164+165165+ // Initialize Level
166166+ Init(config, prototypeData, savedData, sunNum) {
167167+ const win = window;
168168+169169+ // Handle Music
170170+ if (config.LoadMusic) {
171171+ PlayMusic(config.LoadMusic);
172172+ NewAudio({ source: "ChooseYourSeeds", loop: true });
173173+ } else {
174174+ PlayMusic((config.LoadMusic = "ChooseYourSeeds"));
175175+ }
176176+177177+ // Restore/Save Variables
178178+ if (savedData !== sunNum) {
179179+ for (let key in savedData) {
180180+ if (win[key] !== sunNum) {
181181+ this.GlobalVariables[key] = win[key];
182182+ win[key] = savedData[key];
183183+ } else {
184184+ this.LvlVariables[key] = win[key] = savedData[key];
185185+ }
155186 }
156187 }
188188+189189+ // Reset Global Lists
157190 ArCard = [];
158191 ArPCard = [];
159192 ArSun = [];
160193 $Pn = [];
161194 $Z = [];
162195 $P = [];
196196+197197+ // DOM Element setup
163198 EDAll = $("dAll");
164199 EDPZ = $("dPZ");
165200 EDAlloffsetLeft = EDAll.offsetLeft;
166201 EDNewAll = EDAll.cloneNode(true);
167202 EDNewFlagMeter = $("dFlagMeter").cloneNode(true);
168203 ESSunNum = $("sSunNum");
204204+169205 this.AudioArr = [];
170206 this.MustAllReady = true;
171207 this.LoadAccess = null;
···175211 this.PicNum = this.AccessNum = this.MCID = this.Chose = 0;
176212 this.Monitor = null;
177213 this.UserDefinedFlagFunc = null;
178178- this.SunNum = d;
179179- this.BrainsNum = d;
214214+ this.SunNum = sunNum;
215215+ this.BrainsNum = sunNum; // Logic implies sunNum is passed as argument d
180216 this.HaveFog = 0;
181217182182- var savedAutoSun = localStorage.getItem("JSPVZAutoSun");
218218+ // AutoSun Logic
219219+ const savedAutoSun = localStorage.getItem("JSPVZAutoSun");
183220 if (savedAutoSun !== null) {
184221 this.AutoSun = parseInt(savedAutoSun);
185222 if (this.AutoSun) {
186223 AutoClickSun();
187224 }
188225 }
189189-190190- var checkbox = document.getElementById("cAutoSun");
226226+ const checkbox = document.getElementById("cAutoSun");
191227 if (checkbox) {
192228 checkbox.checked = !!this.AutoSun;
193229 }
194230195195- for (c in e) {
196196- this.SelfVariables.push(c);
197197- this[c] = e[c];
231231+ // Load Config into this object
232232+ for (let key in config) {
233233+ this.SelfVariables.push(key);
234234+ this[key] = config[key];
198235 }
199199- $User.isAuthorWebsite &&
200200- oS.LevelEName !== 0 &&
201201- (ClearChild($("JSPVZAjax")),
236236+237237+ // Save Position Logic
238238+ if ($User.isAuthorWebsite && oS.LevelEName !== 0) {
239239+ ClearChild($("JSPVZAjax"));
202240 NewEle(
203241 "JSPVZAjax",
204242 "script",
···208246 type: "text/javascript",
209247 },
210248 document.body
211211- ));
212212- !this.PicArr && (this.PicArr = []);
213213- !this.PName && (this.PName = []);
214214- !this.ZName && (this.ZName = []);
215215- !this.backgroundImage && (this.backgroundImage = "images/interface/background1.jpg");
216216- !this.LF && (this.LF = [0, 1, 1, 1, 1, 1]);
217217- !this.ZF && (this.ZF = this.LF);
218218- !this.LargeWaveFlag && (this.LargeWaveFlag = {});
219219- !this.StartGameMusic && (this.StartGameMusic = "Grasswalk");
220220- this.ArCard = this.CardKind === d ? e.PName : e.ZName;
221221- this.SunNum === d && (this.SunNum = 50);
222222- this.CanSelectCard === d && (this.CanSelectCard = 1);
223223- this.DKind === d && (this.DKind = 1);
224224- this.StaticCard === d && (this.StaticCard = 1);
225225- this.ShowScroll === d && (this.ShowScroll = true);
226226- this.ProduceSun === d && (this.ProduceSun = true);
227227- this.Coord === d && (this.Coord = 1);
249249+ );
250250+ }
251251+252252+ // Defaults
253253+ if (!this.PicArr) this.PicArr = [];
254254+ if (!this.PName) this.PName = [];
255255+ if (!this.ZName) this.ZName = [];
256256+ if (!this.backgroundImage) this.backgroundImage = "images/interface/background1.jpg";
257257+ if (!this.LF) this.LF = [0, 1, 1, 1, 1, 1]; // Lane types
258258+ if (!this.ZF) this.ZF = this.LF; // Zombie spawn lanes
259259+ if (!this.LargeWaveFlag) this.LargeWaveFlag = {};
260260+ if (!this.StartGameMusic) this.StartGameMusic = "Grasswalk";
261261+262262+ this.ArCard = this.CardKind === sunNum ? config.PName : config.ZName;
263263+264264+ if (this.SunNum === sunNum) this.SunNum = 50;
265265+ if (this.CanSelectCard === sunNum) this.CanSelectCard = 1;
266266+ if (this.DKind === sunNum) this.DKind = 1;
267267+ if (this.StaticCard === sunNum) this.StaticCard = 1;
268268+ if (this.ShowScroll === sunNum) this.ShowScroll = true;
269269+ if (this.ProduceSun === sunNum) this.ProduceSun = true;
270270+ if (this.Coord === sunNum) this.Coord = 1;
271271+272272+ // Initialize Systems
228273 oCoord[this.Coord]();
229229- oP.Init(g);
274274+ oP.Init(prototypeData);
230275 oT.Init(this.R);
231276 oZ.Init(this.R);
232277 oGd.Init();
···234279 this.LoadProgress();
235280 },
236281 LoadTips() {
237237- var b = NewEle("dTips", "div", "position:absolute;color:#fff;top:450px;width:100%;text-align:center;font-size:16px", "", EDAll);
238238- var a = [
282282+ const tipsDiv = NewEle("dTips", "div", "position:absolute;color:#fff;top:450px;width:100%;text-align:center;font-size:16px", "", EDAll);
283283+ const tips = [
239284 "Some zombies wear hats, strong hats.",
240285 "Clicking on Balloonatics gives you extra sun! Get ready for those little suckers at the start of every wave!",
241286 'There have been rumors about "Alien Balloons" wandering around Neighborville and their "Green Glow", but I personally dont believe them.',
···245290 "Sunflowers produce sun.",
246291 "Peashooters shoot peas",
247292 ];
248248- b.innerHTML = '<span style="font-weight:bold"></span><span>' + a[Math.floor(Math.random() * a.length)] + "</span>";
293293+ tipsDiv.innerHTML = `<span style="font-weight:bold"></span><span>${tips[Math.floor(Math.random() * tips.length)]}</span>`;
249294 },
250295 LoadProgress(r, l, a, t, b) {
251296 SetVisible($("dFlagMeter"));
252297 SetHidden($("imgGQJC"));
253253- var p = oS;
254254- var j = [];
255255- var i = p.PicArr;
256256- var k = p.PName;
257257- var s = p.ZName;
258258- var w = 0;
259259- var u = GetX(11);
260260- var g = oGd.$LF;
261261- var c = oGd.$ZF;
262262- var d = oS.R + 1;
263263- var x = $("sFlagMeterTitleF");
264264- var y = $("dFlagMeterTitle");
265265- var e = p.LoadImage;
266266- var h = p.CheckImg;
267267- var f = p.InitPn;
268268- var m;
269269- var q;
298298+299299+ const self = oS;
300300+ const picArr = self.PicArr;
301301+ const pNames = self.PName;
302302+ const zNames = self.ZName;
303303+ const backgroundWidth = GetX(11);
304304+ const zLanes = oGd.$ZF;
305305+ const maxR = oS.R + 1;
306306+ const titleDiv = $("dFlagMeterTitle");
307307+308308+ // Brain and Cleaner Elements
270309 NewImg(0, "images/interface/brain.png", "", ($Pn.oBrains = NewEle(0, "div", "position:absolute")));
271271- switch (p.Coord) {
310310+ switch (self.Coord) {
272311 case 2:
273312 NewImg(0, "images/interface/PoolCleaner.png", "", ($Pn.oPoolCleaner = NewEle(0, "div", "position:absolute")));
313313+ // fallthrough
274314 case 1:
275315 NewImg(0, "images/interface/LawnCleaner.png", "", ($Pn.oLawnCleaner = NewEle(0, "div", "position:absolute")));
276316 break;
277317 }
278278- while (r--) {
279279- a = (l = k[r].prototype).PicArr.slice(0);
280280- Array.prototype.push.apply(i, a);
318318+319319+ // Load Plant Resources
320320+ let i = pNames.length;
321321+ while (i--) {
322322+ let proto = pNames[i].prototype;
323323+ Array.prototype.push.apply(picArr, proto.PicArr.slice(0));
281324 if ($User.HTML5) {
282282- t = l.AudioArr;
283283- b = t.length;
284284- while (b--) {
285285- NewAudio({ source: t[b] });
325325+ let audioArr = proto.AudioArr;
326326+ let audioLen = audioArr.length;
327327+ while (audioLen--) {
328328+ NewAudio({ source: audioArr[audioLen] });
286329 }
287330 }
288331 }
289289- for (r in oS.LargeWaveFlag) {
290290- s[s.length] = oS.FlagZombie || oFlagZombie;
332332+333333+ // Ensure Flag Zombie exists for large waves
334334+ for (let flag in oS.LargeWaveFlag) {
335335+ zNames[zNames.length] = oS.FlagZombie || oFlagZombie;
291336 break;
292337 }
293293- r = s.length;
294294- while (r--) {
295295- Array.prototype.push.apply(i, (l = (q = s[r]).prototype).PicArr.slice(0));
338338+339339+ // Load Zombie Resources and Init
340340+ let j = zNames.length;
341341+ while (j--) {
342342+ let zombieClass = zNames[j];
343343+ let proto = zombieClass.prototype;
344344+ Array.prototype.push.apply(picArr, proto.PicArr.slice(0));
296345 if ($User.HTML5) {
297297- t = l.AudioArr;
298298- b = t.length;
299299- while (b--) {
300300- NewAudio({ source: t[b] });
346346+ let audioArr = proto.AudioArr;
347347+ let audioLen = audioArr.length;
348348+ while (audioLen--) {
349349+ NewAudio({ source: audioArr[audioLen] });
301350 }
302351 }
303303- l.Init.call(q, u, l, c, d);
352352+ proto.Init.call(zombieClass, backgroundWidth, proto, zLanes, maxR);
304353 }
305305- p.PicNum = w += i.length;
306306- r = i.length;
307307- y.setAttribute("title", "");
308308- y.style.cursor = "url(images/interface/Pointer.cur),pointer";
309309- y.onclick = function () {
354354+355355+ self.PicNum = picArr.length;
356356+ let k = picArr.length;
357357+358358+ // Setup Start Click
359359+ titleDiv.setAttribute("title", "");
360360+ titleDiv.style.cursor = "url(images/interface/Pointer.cur),pointer";
361361+ titleDiv.onclick = function () {
310362 oS.MustAllReady = false;
311363 oS.LoadReady(oS);
312364 };
313313- while (r--) {
314314- e(i[r], h);
365365+366366+ // Preload Images
367367+ while (k--) {
368368+ self.LoadImage(picArr[k], self.CheckImg);
315369 }
316316- r = j.length;
370370+317371 oS.LoadAudio();
318372 },
319373 LoadAudio: $User.HTML5
320374 ? function () {
321321- var b = oS.AudioArr;
322322- var a = b.length;
323323- while (a--) {
324324- NewAudio({ source: b[a] });
375375+ let i = oS.AudioArr.length;
376376+ while (i--) {
377377+ NewAudio({ source: oS.AudioArr[i] });
325378 }
326379 }
327380 : function () {},
328328- InitPn(a) {
329329- var b = ($Pn[a[0]] = NewEle(0, "div", "position:absolute"));
330330- NewImg(0, ShadowPNG, a[2], b);
331331- NewImg(0, a[1], "", b);
381381+ InitPn(arr) {
382382+ const ele = ($Pn[arr[0]] = NewEle(0, "div", "position:absolute"));
383383+ NewImg(0, ShadowPNG, arr[2], ele);
384384+ NewImg(0, arr[1], "", ele);
332385 oS.CheckImg();
333386 },
334387 LoadImage: $User.Browser.IE
335335- ? function (b, d, c) {
336336- var a = new Image();
337337- a.onreadystatechange = function () {
338338- a.readyState === "complete" && d(c, 1);
388388+ ? function (src, callback, args) {
389389+ const img = new Image();
390390+ img.onreadystatechange = function () {
391391+ if (img.readyState === "complete") callback(args, 1);
339392 };
340340- a.onerror = function () {
341341- a.onreadystatechange = null;
342342- a.title = b;
343343- d(c, 0);
393393+ img.onerror = function () {
394394+ img.onreadystatechange = null;
395395+ img.title = src;
396396+ callback(args, 0);
344397 };
345345- a.src = b;
398398+ img.src = src;
346399 }
347347- : function (b, d, c) {
348348- var a = new Image();
349349- a.src = b;
350350- a.complete
351351- ? d(c, 1)
352352- : ((a.onload = function () {
353353- a.complete && d(c, 1);
354354- }),
355355- (a.onerror = function () {
356356- a.title = b;
357357- d(c, 0);
358358- }));
400400+ : function (src, callback, args) {
401401+ const img = new Image();
402402+ img.src = src;
403403+ if (img.complete) {
404404+ callback(args, 1);
405405+ } else {
406406+ img.onload = function () {
407407+ if (img.complete) callback(args, 1);
408408+ };
409409+ img.onerror = function () {
410410+ img.title = src;
411411+ callback(args, 0);
412412+ };
413413+ }
359414 },
360415 LoadScript: $User.Browser.IE
361361- ? function (f, c, e, a, d) {
362362- var b = NewEle(f, "script", 0, { type: "text/javascript" });
363363- b.onreadystatechange = function () {
364364- (b.readyState === "loaded" || b.readyState === "complete") && ((b.onreadystatechange = null), e(d, 1));
416416+ ? function (id, src, callback, parent, args) {
417417+ const script = NewEle(id, "script", 0, { type: "text/javascript" });
418418+ script.onreadystatechange = function () {
419419+ if (script.readyState === "loaded" || script.readyState === "complete") {
420420+ script.onreadystatechange = null;
421421+ callback(args, 1);
422422+ }
365423 };
366366- b.onerror = function () {
367367- b.onreadystatechange = null;
368368- e(d, 0);
424424+ script.onerror = function () {
425425+ script.onreadystatechange = null;
426426+ callback(args, 0);
369427 };
370370- b.src = c;
371371- a.appendChild(b);
428428+ script.src = src;
429429+ parent.appendChild(script);
372430 }
373373- : function (f, c, e, a, d) {
374374- var b = NewEle(f, "script", 0, { type: "text/javascript" });
375375- b.onload = function () {
376376- e(d, 1);
431431+ : function (id, src, callback, parent, args) {
432432+ const script = NewEle(id, "script", 0, { type: "text/javascript" });
433433+ script.onload = function () {
434434+ callback(args, 1);
377435 };
378378- b.onerror = function () {
379379- e(d, 0);
436436+ script.onerror = function () {
437437+ callback(args, 0);
380438 };
381381- b.src = c;
382382- a.appendChild(b);
439439+ script.src = src;
440440+ parent.appendChild(script);
383441 },
384442 CheckImg(b, a) {
385385- var c = oS;
386386- if (c.AccessNum > c.PicNum || !c.MustAllReady) {
443443+ const self = oS;
444444+ if (self.AccessNum > self.PicNum || !self.MustAllReady) {
387445 return;
388446 }
389389- b = 139 - (c.AccessNum++ * 140) / c.PicNum - 11;
390390- $("imgFlagHead").style.left = b + "px";
447447+ // Calculate progress bar position
448448+ const pos = 139 - (self.AccessNum++ * 140) / self.PicNum - 11;
449449+ $("imgFlagHead").style.left = pos + "px";
391450 $("sFlagMeterTitleF").innerHTML =
392392- '<span style="cursor:url(images/interface/Pointer.cur),pointer;font-family:Tahoma;color:#fff">Loading...(' +
393393- c.AccessNum +
394394- "/" +
395395- c.PicNum +
396396- ")</span>";
397397- $("imgFlagMeterFull").style.clip = "rect(0,auto,21px," + (b + 11) + "px)";
398398- if (c.AccessNum === c.PicNum) {
399399- oS.Lvl === 0;
400400- if (c.MustAllReady) {
401401- c.LoadReady(c);
451451+ `<span style="cursor:url(images/interface/Pointer.cur),pointer;font-family:Tahoma;color:#fff">Loading...(${self.AccessNum}/${self.PicNum})</span>`;
452452+ $("imgFlagMeterFull").style.clip = "rect(0,auto,21px," + (pos + 11) + "px)";
453453+454454+ if (self.AccessNum === self.PicNum) {
455455+ if (self.MustAllReady) {
456456+ self.LoadReady(self);
402457 }
403458 }
404459 },
405405- LoadReady(f) {
406406- var c = $("dFlagMeterTitle");
407407- if (c.onclick == null) {
408408- return;
409409- }
460460+ LoadReady(config) {
461461+ const titleDiv = $("dFlagMeterTitle");
462462+ if (titleDiv.onclick == null) return;
463463+410464 ClearChild($("dTips"));
411465 oSym.NowStep = $User.Visitor.NowStep;
412466 oSym.TimeStep = $User.Visitor.TimeStep;
413413- c.onclick = null;
414414- c.title = null;
415415- c.style.cursor = "url(images/interface/Cursor.cur),default";
467467+ titleDiv.onclick = null;
468468+ titleDiv.title = null;
469469+ titleDiv.style.cursor = "url(images/interface/Cursor.cur),default";
470470+416471 SetHidden($("dFlagMeterContent"), dFlagMeter);
417472 $("dFlagMeter").style.top = "490px";
418418- // $("dFlagMeter").style.left = "805px"; // not good
419419- // $("dFlagMeter").style.left = (currentLeft + 15) + "px"; // not good either
420420- $("sFlagMeterTitleF").innerHTML = $("dFlagMeterTitleB").innerHTML = f.LevelName;
473473+ $("sFlagMeterTitleF").innerHTML = $("dFlagMeterTitleB").innerHTML = config.LevelName;
421474 $("imgFlagHead").style.left = "139px";
422475 $("imgFlagMeterFull").style.clip = "rect(0,auto,auto,157px)";
423423- delete f.PicArr;
424424- delete f.Coord;
425425- delete f.LF;
426426- delete f.ZF;
427427- var a = {
428428- background: "url(" + f.backgroundImage + ") no-repeat",
476476+477477+ // Cleanup config object
478478+ delete config.PicArr;
479479+ delete config.Coord;
480480+ delete config.LF;
481481+ delete config.ZF;
482482+483483+ const bgStyle = {
484484+ background: "url(" + config.backgroundImage + ") no-repeat",
429485 visibility: "visible",
430486 };
431431- !f.ShowScroll && (a.left = "-115px");
432432- SetStyle($("tGround"), a);
487487+ if (!config.ShowScroll) bgStyle.left = "-115px";
488488+489489+ SetStyle($("tGround"), bgStyle);
433490 $("tGround").innerHTML = oS.GifHTML;
434434- var d = function (h) {
435435- var i = oS;
436436- var g = $User.Visitor;
491491+492492+ const startGame = function (delay) {
493493+ const self = oS;
437494 NewImg("imgGrowSoil", "images/interface/GrowSoil.gif", "visibility:hidden;z-index:50", EDAll);
438495 NewImg("imgGrowSpray", "images/interface/GrowSpray.gif", "visibility:hidden;z-index:50", EDAll);
439439- innerText(ESSunNum, i.SunNum);
496496+ innerText(ESSunNum, self.SunNum);
440497 InitPCard();
441441- i.ShowScroll
442442- ? oSym.addTask(
443443- h === undefined ? 200 : h,
444444- (j) => {
445445- ClearChild(j);
446446- i.ScrollScreen();
447447- },
448448- [NewEle("DivParty", "div", "line-height:50px;color:#FFFFFF;font-size:50px;font-family:Tahoma", {}, EDAll)]
449449- )
450450- : (SetVisible($("dMenu")), AutoSelectCard(), LetsGO());
498498+499499+ if (self.ShowScroll) {
500500+ oSym.addTask(
501501+ delay === undefined ? 200 : delay,
502502+ (div) => {
503503+ ClearChild(div);
504504+ self.ScrollScreen();
505505+ },
506506+ [NewEle("DivParty", "div", "line-height:50px;color:#FFFFFF;font-size:50px;font-family:Tahoma", {}, EDAll)]
507507+ );
508508+ } else {
509509+ SetVisible($("dMenu"));
510510+ AutoSelectCard();
511511+ LetsGO();
512512+ }
451513 };
452452- f.LoadAccess ? f.LoadAccess(d) : d();
514514+515515+ config.LoadAccess ? config.LoadAccess(startGame) : startGame();
453516 },
454517 ScrollScreen() {
455455- (EDAll.scrollLeft += 25) < 500
456456- ? oSym.addTask(2, arguments.callee, [])
457457- : (DisplayZombie(),
458458- SetVisible($("dMenu")),
459459- oS.CanSelectCard ? SetVisible($("dTop"), $("dSelectCard"), $("dCardList")) : (AutoSelectCard(), oSym.addTask(200, oS.ScrollBack, [LetsGO])));
518518+ if ((EDAll.scrollLeft += 25) < 500) {
519519+ oSym.addTask(2, arguments.callee, []);
520520+ } else {
521521+ DisplayZombie();
522522+ SetVisible($("dMenu"));
523523+ if (oS.CanSelectCard) {
524524+ SetVisible($("dTop"), $("dSelectCard"), $("dCardList"));
525525+ } else {
526526+ AutoSelectCard();
527527+ oSym.addTask(200, oS.ScrollBack, [LetsGO]);
528528+ }
529529+ }
460530 },
461461- ScrollBack(a) {
531531+ ScrollBack(callback) {
462532 SetHidden($("dZombie"), $("dSelectCard"), $("dTitle"), $("dCardList"));
463533 $("tGround").style.left = "-115px";
464534 $("dZombie").innerHTML = "";
465465- (function (c) {
466466- var b = EDAll.scrollLeft;
467467- (b -= 25) > 0 ? ((EDAll.scrollLeft = b), oSym.addTask(2, arguments.callee, [c])) : ((EDAll.scrollLeft = 0), c());
468468- })(a);
535535+536536+ (function scrollStep(cb) {
537537+ let scroll = EDAll.scrollLeft;
538538+ if ((scroll -= 25) > 0) {
539539+ EDAll.scrollLeft = scroll;
540540+ oSym.addTask(2, scrollStep, [cb]);
541541+ } else {
542542+ EDAll.scrollLeft = 0;
543543+ cb();
544544+ }
545545+ })(callback);
469546 },
470547};
548548+471549var oCoord = {
550550+ // 5-Row Layout
472551 1() {
473552 oS.R = 5;
474474- ChosePlantX = function (a) {
475475- return Compare(GetC(a), 1, oS.C, GetX);
553553+ ChosePlantX = function (x) {
554554+ return Compare(GetC(x), 1, oS.C, GetX);
476555 };
477477- ChosePlantY = function (a) {
556556+ ChosePlantY = function (y) {
478557 return $SSml(
479479- a,
558558+ y,
480559 [86, 181, 281, 386, 476],
481560 [
482561 [75, 0],
···488567 ]
489568 );
490569 };
491491- GetC = function (a) {
492492- return $SSml(a, [-50, 100, 140, 220, 295, 379, 460, 540, 625, 695, 775, 855, 935], [-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
570570+ GetC = function (x) {
571571+ return $SSml(x, [-50, 100, 140, 220, 295, 379, 460, 540, 625, 695, 775, 855, 935], [-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
493572 };
494494- GetR = function (a) {
495495- return $SSml(a, [86, 181, 281, 386, 476], [0, 1, 2, 3, 4, 5]);
573573+ GetR = function (y) {
574574+ return $SSml(y, [86, 181, 281, 386, 476], [0, 1, 2, 3, 4, 5]);
496575 };
497497- GetX = function (a) {
498498- return $SEql(a, {
576576+ GetX = function (c) {
577577+ return $SEql(c, {
499578 "-2": -50,
500579 "-1": 100,
501580 0: 140,
···512591 11: 950,
513592 });
514593 };
515515- GetY = function (a) {
516516- return $SEql(a, {
517517- 0: 75,
518518- 1: 175,
519519- 2: 270,
520520- 3: 380,
521521- 4: 470,
522522- 5: 575,
523523- });
594594+ GetY = function (r) {
595595+ return $SEql(r, { 0: 75, 1: 175, 2: 270, 3: 380, 4: 470, 5: 575 });
524596 };
525525- GetY1Y2 = function (a) {
526526- return $SEql(a, {
597597+ GetY1Y2 = function (r) {
598598+ return $SEql(r, {
527599 0: [0, 85],
528600 1: [86, 180],
529601 2: [181, 280],
···532604 5: [476, 600],
533605 });
534606 };
535535- GetX1X2 = function (a) {
536536- return $SEql(a, {
607607+ GetX1X2 = function (c) {
608608+ return $SEql(c, {
537609 "-2": [-100, -49],
538610 "-1": [-50, 99],
539611 0: [100, 139],
···555627 let columnWidth = 170;
556628 return [Math.floor(pixelX / rowWidth) + 1, Math.floor(pixelY / columnWidth) + 1];
557629 };
558558- !oS.InitLawnMower &&
559559- (oS.InitLawnMower = function () {
560560- var a = 6;
561561- while (--a) {
562562- CustomSpecial(oLawnCleaner, a, -1);
563563- }
564564- });
630630+ if (!oS.InitLawnMower) {
631631+ oS.InitLawnMower = function () {
632632+ let r = 6;
633633+ while (--r) CustomSpecial(oLawnCleaner, r, -1);
634634+ };
635635+ }
565636 oS.GifHTML = "";
566637 },
638638+ // 6-Row Layout (Pool)
567639 2() {
568640 oS.R = 6;
569569- ChosePlantX = function (a) {
570570- return Compare(GetC(a), 1, oS.C, GetX);
641641+ ChosePlantX = function (x) {
642642+ return Compare(GetC(x), 1, oS.C, GetX);
571643 };
572572- ChosePlantY = function (a) {
644644+ ChosePlantY = function (y) {
573645 return $SSml(
574574- a,
646646+ y,
575647 [86, 171, 264, 368, 440, 532],
576648 [
577649 [75, 0],
···584656 ]
585657 );
586658 };
587587- GetC = function (a) {
588588- return $SSml(a, [-50, 100, 140, 220, 295, 379, 460, 540, 625, 695, 775, 855, 935], [-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
659659+ GetC = function (x) {
660660+ return $SSml(x, [-50, 100, 140, 220, 295, 379, 460, 540, 625, 695, 775, 855, 935], [-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
589661 };
590590- GetR = function (a) {
591591- return $SSml(a, [86, 171, 264, 368, 440, 532], [0, 1, 2, 3, 4, 5, 6]);
662662+ GetR = function (y) {
663663+ return $SSml(y, [86, 171, 264, 368, 440, 532], [0, 1, 2, 3, 4, 5, 6]);
592664 };
593593- GetX = function (a) {
594594- return $SEql(a, {
665665+ GetX = function (c) {
666666+ return $SEql(c, {
595667 "-2": -50,
596668 "-1": 100,
597669 0: 140,
···608680 11: 950,
609681 });
610682 };
611611- GetY = function (a) {
612612- return $SEql(a, {
613613- 0: 75,
614614- 1: 165,
615615- 2: 253,
616616- 3: 355,
617617- 4: 430,
618618- 5: 522,
619619- 6: 587,
620620- });
683683+ GetY = function (r) {
684684+ return $SEql(r, { 0: 75, 1: 165, 2: 253, 3: 355, 4: 430, 5: 522, 6: 587 });
621685 };
622622- GetY1Y2 = function (a) {
623623- return $SEql(a, {
686686+ GetY1Y2 = function (r) {
687687+ return $SEql(r, {
624688 0: [0, 85],
625689 1: [86, 170],
626690 2: [171, 263],
···630694 6: [532, 600],
631695 });
632696 };
633633- GetX1X2 = function (a) {
634634- return $SEql(a, {
697697+ GetX1X2 = function (c) {
698698+ return $SEql(c, {
635699 "-2": [-100, -49],
636700 "-1": [-50, 99],
637701 0: [100, 139],
···648712 11: [950, 1030],
649713 });
650714 };
651651- !oS.InitLawnMower &&
652652- (oS.InitLawnMower = function () {
715715+ if (!oS.InitLawnMower) {
716716+ oS.InitLawnMower = function () {
653717 CustomSpecial(oLawnCleaner, 1, -1);
654718 CustomSpecial(oLawnCleaner, 2, -1);
655719 CustomSpecial(oPoolCleaner, 3, -1);
656720 CustomSpecial(oPoolCleaner, 4, -1);
657721 CustomSpecial(oLawnCleaner, 5, -1);
658722 CustomSpecial(oLawnCleaner, 6, -1);
659659- });
723723+ };
724724+ }
660725 oS.GifHTML = '<img style="position:absolute;left:253px;top:278px" src="">';
661661- !oS.DKind && oGd.MakeFog();
726726+ if (!oS.DKind) oGd.MakeFog();
662727 },
663728};
729729+664730var oP = {
665665- Init(a) {
666666- var r = this;
667667- r.NumZombies = r.FlagZombies = 0;
668668- if (a) {
669669- var l;
670670- for (l in a) {
671671- r[l] = a[l];
731731+ Init(config) {
732732+ const self = this;
733733+ self.NumZombies = self.FlagZombies = 0;
734734+ self.AZ = [];
735735+ self.ArZ = [];
736736+ self.MustShowAtFlag = {};
737737+ if (config) {
738738+ for (let key in config) {
739739+ self[key] = config[key];
672740 }
673673- if (a.AZ) {
674674- var k;
675675- var b = {};
676676- var g;
677677- var c;
678678- var q;
679679- var p;
680680- var d;
681681- var m = [];
682682- var h;
683683- var e;
684684- var n;
685685- r.ArZ = [];
686686- h = (k = r.AZ).sort((i, f) => {
687687- return i[2] - f[2];
688688- }).length;
689689- while (h--) {
690690- c = (n = k[h])[0];
691691- q = n[1];
692692- p = n[2];
693693- while (q--) {
694694- m.push([c, p]);
741741+ if (config.AZ) {
742742+ // Parse AZ (Array Zombies) configuration
743743+ let rawAZ = config.AZ;
744744+ let schedule = {};
745745+ let azList = [];
746746+ let i = rawAZ.sort((a, b) => a[2] - b[2]).length;
747747+748748+ while (i--) {
749749+ let entry = rawAZ[i];
750750+ let zombieType = entry[0];
751751+ let count = entry[1];
752752+ let weight = entry[2];
753753+ let flags = entry[3];
754754+755755+ while (count--) {
756756+ azList.push([zombieType, weight]);
695757 }
696696- if ((d = n[3])) {
697697- e = d.length;
698698- while (e--) {
699699- b[(g = d[e])] ? b[g].push(c) : (b[g] = [c]);
758758+ if (flags) {
759759+ let fLen = flags.length;
760760+ while (fLen--) {
761761+ let flagNum = flags[fLen];
762762+ schedule[flagNum] ? schedule[flagNum].push(zombieType) : (schedule[flagNum] = [zombieType]);
700763 }
701764 }
702765 }
703703- r.AZ = m;
704704- r.MustShowAtFlag = b;
766766+ self.AZ = azList;
767767+ self.MustShowAtFlag = schedule;
705768 }
706769 }
707707- a && a.FlagNum
708708- ? ((r.FlagHeadStep = Math.floor(140 / (a.FlagNum - 1))),
709709- (r.MonPrgs = function () {
710710- var u = oP;
711711- var j;
712712- var i = u.FlagZombies;
713713- var s;
714714- var t;
715715- var f = $User.Visitor;
716716- !--u.NumZombies &&
717717- (i < u.FlagNum
718718- ? ((u.ReadyFlag = ++i), oSym.addTask(500, u.FlagPrgs, []))
719719- : (u.FlagToEnd(),
720720- $User.isAuthorWebsite &&
721721- $User.Visitor.UserName !== "" &&
722722- (ClearChild($("JSPVZAjax")), f.SaveLvl && NewEle("JSPVZAjax", "script", 0, {}, document.body)),
723723- f.SaveLvlCallBack &&
724724- f.SaveLvlCallBack({
725725- UserName: f.UserName,
726726- SunNum: oS.SunNum,
727727- Lvl: s,
728728- T: oSym.Now - oS.StartTime,
729729- }),
730730- !isNaN(Math.floor(s)) &&
731731- ((t = $("dAdventure")),
732732- ($User.Visitor.Progress = ++s),
733733- (t.firstChild.innerHTML = Math.ceil(s / 10)),
734734- (t.childNodes[1].innerHTML = (s -= Math.floor(s / 10) * 10) ? s : s + 1)),
735735- NewEle(
736736- "DivA",
737737- "div",
738738- "position:absolute;width:900px;height:600px;background:#FFF;filter:alpha(opacity=0);opacity:0;z-index:255",
739739- 0,
740740- EDAll
741741- ),
742742- PauseGame($("dMenu0"), 1)));
743743- }))
744744- : (r.MonPrgs = function () {});
745745- (!a || !a.FlagToEnd) &&
746746- (r.FlagToEnd = function () {
770770+771771+ if (config && config.FlagNum) {
772772+ self.FlagHeadStep = Math.floor(140 / (config.FlagNum - 1));
773773+ self.MonPrgs = function () {
774774+ const p = oP;
775775+ let curFlag = p.FlagZombies;
776776+ const user = $User.Visitor;
777777+778778+ if (!--p.NumZombies) {
779779+ if (curFlag < p.FlagNum) {
780780+ p.ReadyFlag = ++curFlag;
781781+ oSym.addTask(500, p.FlagPrgs, []);
782782+ } else {
783783+ p.FlagToEnd();
784784+ if ($User.isAuthorWebsite && $User.Visitor.UserName !== "") {
785785+ ClearChild($("JSPVZAjax"));
786786+ if (user.SaveLvl) {
787787+ NewEle("JSPVZAjax", "script", 0, {}, document.body);
788788+ }
789789+ }
790790+ if (user.SaveLvlCallBack) {
791791+ user.SaveLvlCallBack({
792792+ UserName: user.UserName,
793793+ SunNum: oS.SunNum,
794794+ Lvl: oS.Lvl,
795795+ T: oSym.Now - oS.StartTime,
796796+ });
797797+ }
798798+799799+ // Update Progress Display
800800+ if (!isNaN(Math.floor(oS.Lvl))) {
801801+ let advDiv = $("dAdventure");
802802+ $User.Visitor.Progress = ++oS.Lvl;
803803+ if (advDiv && advDiv.firstChild && advDiv.childNodes && advDiv.childNodes[1]) {
804804+ advDiv.firstChild.innerHTML = Math.ceil(oS.Lvl / 10);
805805+ let subLvl = oS.Lvl - Math.floor(oS.Lvl / 10) * 10;
806806+ advDiv.childNodes[1].innerHTML = subLvl ? subLvl : subLvl + 1;
807807+ }
808808+ }
809809+810810+ NewEle(
811811+ "DivA",
812812+ "div",
813813+ "position:absolute;width:900px;height:600px;background:#FFF;filter:alpha(opacity=0);opacity:0;z-index:255",
814814+ 0,
815815+ EDAll
816816+ );
817817+ PauseGame($("dMenu0"), 1);
818818+ }
819819+ }
820820+ };
821821+ } else {
822822+ self.MonPrgs = function () {};
823823+ }
824824+825825+ if (!config || !config.FlagToEnd) {
826826+ self.FlagToEnd = function () {
747827 NewImg("imgSF", "images/interface/trophy.png", "left:417px;top:233px;z-index:255", EDAll, {
748828 onclick() {
749829 PlayAudio("winmusic");
···753833 ShowNameDiv();
754834 },
755835 });
756756- });
836836+ };
837837+ }
757838 },
758839 Balloon() {
759840 let balloonId = Math.floor(1 + Math.random() * 1000);
···785866 const timeInSec = (ms) => ms / 100;
786867 const toTicks = (ms) => Math.round(ms / timeStep);
787868788788- oP.balloonStyleSheet.insertRule(
789789- `
790790- @keyframes moveLeft${balloonId} {
791791- from { left: 910px; }
792792- to { left: -75px; }
793793- }
794794- `,
795795- oP.balloonStyleSheet.cssRules.length
796796- );
869869+ oP.balloonStyleSheet.insertRule(`@keyframes moveLeft${balloonId} { from { left: 910px; } to { left: -75px; } }`, oP.balloonStyleSheet.cssRules.length);
797870798871 oP.balloonStyleSheet.insertRule(
799799- `
800800- @keyframes bobbing${balloonId} {
801801- 0%, 100% { top: ${randomY}px; }
802802- 50% { top: ${randomY + 10}px; }
803803- }
804804- `,
872872+ `@keyframes bobbing${balloonId} { 0%, 100% { top: ${randomY}px; } 50% { top: ${randomY + 10}px; } }`,
805873 oP.balloonStyleSheet.cssRules.length
806874 );
807875808876 let image = document.createElement("div");
809877 image.style = `
810810- background-image: url(images/Zombies/Balloon/balloonidle.png);
811811- position: absolute;
812812- display: block;
813813- left: 875px;
814814- top: ${randomY}px;
815815- z-index: 999;
816816- width: 154px;
817817- height: 181px;
818818- scale: 0.6038961039;
819819- cursor: url(images/interface/Pointer.cur),pointer;
820820- animation:
821821- spritesheetIdle ${timeInSec(timeStep * 10)}s steps(30) infinite,
822822- moveLeft${balloonId} ${timeInSec(timeStep * 130)}s linear,
823823- bobbing${balloonId} ${timeInSec(timeStep * 20)}s ease-in-out infinite;
824824- `;
878878+ background-image: url(images/Zombies/Balloon/balloonidle.png);
879879+ position: absolute;
880880+ display: block;
881881+ left: 875px;
882882+ top: ${randomY}px;
883883+ z-index: 999;
884884+ width: 154px;
885885+ height: 181px;
886886+ scale: 0.6038961039;
887887+ cursor: url(images/interface/Pointer.cur),pointer;
888888+ animation:
889889+ spritesheetIdle ${timeInSec(timeStep * 10)}s steps(30) infinite,
890890+ moveLeft${balloonId} ${timeInSec(timeStep * 130)}s linear,
891891+ bobbing${balloonId} ${timeInSec(timeStep * 20)}s ease-in-out infinite;
892892+ `;
825893826894 $("dPZ").appendChild(image);
827895828896 image.onclick = function () {
829897 image.onclick = null;
830898 image.style = `
831831- background-image: url(images/Zombies/Balloon/popped.png);
832832- position: absolute;
833833- display: block;
834834- left: ${getAnimatedPosition(image).left}px;
835835- top: ${randomY}px;
836836- z-index: 999;
837837- width: 154px;
838838- height: 181px;
839839- scale: 0.6038961039;
840840- pointer-events: none;
841841- animation: spritesheetPop ${timeInSec(timeStep * 10)}s 1 normal forwards steps(21);
842842- `;
899899+ background-image: url(images/Zombies/Balloon/popped.png);
900900+ position: absolute;
901901+ display: block;
902902+ left: ${getAnimatedPosition(image).left}px;
903903+ top: ${randomY}px;
904904+ z-index: 999;
905905+ width: 154px;
906906+ height: 181px;
907907+ scale: 0.6038961039;
908908+ pointer-events: none;
909909+ animation: spritesheetPop ${timeInSec(timeStep * 10)}s 1 normal forwards steps(21);
910910+ `;
843911844912 image.addEventListener("animationend", () => {
845913 if (endMode === "endOfAnimation") {
846914 image.style = `
847847- background-image: url(images/Zombies/Balloon/popped.png);
848848- background-position-x: -3080px;
849849- position: absolute;
850850- display: block;
851851- left: ${getAnimatedPosition(image).left}px;
852852- top: ${randomY}px;
853853- z-index: 999;
854854- width: 154px;
855855- height: 181px;
856856- scale: 0.6038961039;
857857- pointer-events: none;
858858- `;
915915+ background-image: url(images/Zombies/Balloon/popped.png);
916916+ background-position-x: -3080px;
917917+ position: absolute;
918918+ display: block;
919919+ left: ${getAnimatedPosition(image).left}px;
920920+ top: ${randomY}px;
921921+ z-index: 999;
922922+ width: 154px;
923923+ height: 181px;
924924+ scale: 0.6038961039;
925925+ pointer-events: none;
926926+ `;
859927 endMode = "remove";
860928 } else {
861929 image.parentNode.removeChild(image);
···888956 if (Math.floor(Math.random() * 5) === 1 && $("dSunNum").style.visibility === "") {
889957 oP.Balloon();
890958 }
891891- var g = oP;
892892- var c = oS.LargeWaveFlag;
893893- var e;
894894- var b = g.FlagHeadStep;
895895- var a = g.FlagNum;
959959+ const self = oP;
960960+ const largeFlags = oS.LargeWaveFlag;
961961+ const step = self.FlagHeadStep;
962962+ const totalFlags = self.FlagNum;
963963+896964 SetVisible($("imgGQJC"), $("dFlagMeterContent"));
897897- for (e in c) {
898898- Math.floor(e) < a
899899- ? SetStyle(c[e], {
965965+966966+ for (let flagIdx in largeFlags) {
967967+ Math.floor(flagIdx) < totalFlags
968968+ ? SetStyle(largeFlags[flagIdx], {
900969 visibility: "visible",
901901- left: 150 - (e - 1) * b + "px",
970970+ left: 150 - (flagIdx - 1) * step + "px",
902971 })
903903- : SetVisible(c[e]);
972972+ : SetVisible(largeFlags[flagIdx]);
904973 }
974974+905975 PlayAudio("awooga");
906906- $User.HTML5 &&
907907- (function () {
976976+977977+ if ($User.HTML5) {
978978+ (function playGroans() {
908979 oSym.addTask(
909980 2e3,
910981 function () {
911911- [
912912- function () {
913913- PlayAudio(["groan1", "groan2"][Math.floor(Math.random() * 2)]);
914914- },
915915- function () {
916916- PlayAudio(["groan3", "groan4"][Math.floor(Math.random() * 2)]);
917917- },
918918- function () {
919919- PlayAudio(["groan5", "groan6"][Math.floor(Math.random() * 2)]);
920920- },
921921- function () {
982982+ const randomGroan = [
983983+ () => PlayAudio(["groan1", "groan2"][Math.floor(Math.random() * 2)]),
984984+ () => PlayAudio(["groan3", "groan4"][Math.floor(Math.random() * 2)]),
985985+ () => PlayAudio(["groan5", "groan6"][Math.floor(Math.random() * 2)]),
986986+ () => {
922987 PlayAudio("groan1");
923923- oSym.addTask(
924924- 150,
925925- () => {
926926- PlayAudio("groan5");
927927- },
928928- []
929929- );
988988+ oSym.addTask(150, () => PlayAudio("groan5"), []);
930989 },
931931- function () {
990990+ () => {
932991 PlayAudio("groan2");
933933- oSym.addTask(
934934- 150,
935935- () => {
936936- PlayAudio("groan6");
937937- },
938938- []
939939- );
992992+ oSym.addTask(150, () => PlayAudio("groan6"), []);
940993 },
941941- ][Math.floor(Math.random() * 3)]();
942942- oSym.addTask(2e3, arguments.callee, []);
994994+ ][Math.floor(Math.random() * 3)];
995995+996996+ randomGroan();
997997+ oSym.addTask(2e3, playGroans, []);
943998 },
944999 []
9451000 );
9461001 })();
947947- g.ReadyFlag = 1;
948948- g.FlagPrgs(d);
10021002+ }
10031003+10041004+ self.ReadyFlag = 1;
10051005+ self.FlagPrgs(d);
9491006 },
950950- SelectFlagZombie(j, d) {
951951- var e = oP;
952952- var m = e.ArZ;
953953- var k = e.AZ;
954954- var s = k.length;
955955- var q;
956956- var r;
957957- var i = [];
958958- var g = 0;
959959- var n = oS.LargeWaveFlag[d];
960960- var c = false;
961961- var h = !n ? 150 : (PlayAudio("siren"), (n.style.top = "5px"), --j, (i[g++] = oS.FlagZombie || oFlagZombie), 30);
962962- var p;
963963- var b;
964964- var f = e.MustShowAtFlag;
965965- var a;
966966- while (s--) {
967967- if ((r = (q = k[s])[1]) > d) {
10071007+ SelectFlagZombie(totalLvl, flag) {
10081008+ const self = oP;
10091009+ const az = self.AZ || (self.AZ = []);
10101010+ let azLen = az.length;
10111011+ const zombiesToSpawn = [];
10121012+ let count = 0;
10131013+ const isLargeWave = oS.LargeWaveFlag[flag];
10141014+ let remainingLvl = totalLvl;
10151015+10161016+ const delay = !isLargeWave
10171017+ ? 150
10181018+ : (PlayAudio("siren"), (isLargeWave.style.top = "5px"), --remainingLvl, (zombiesToSpawn[count++] = oS.FlagZombie || oFlagZombie), 30);
10191019+10201020+ const availableZombies = [];
10211021+ let hasNew = false;
10221022+10231023+ // Filter zombies available for this wave
10241024+ while (azLen--) {
10251025+ let entry = az[azLen];
10261026+ let entryFlag = entry[1];
10271027+ if (entryFlag > flag) {
9681028 break;
9691029 } else {
970970- m.push(q[0]);
971971- --k.length;
972972- c = true;
10301030+ availableZombies.push(entry[0]);
10311031+ --az.length;
10321032+ hasNew = true;
9731033 }
9741034 }
975975- c &&
976976- m.sort((t, l) => {
977977- return t.prototype.Lvl - l.prototype.Lvl;
978978- });
979979- if ((a = f[d])) {
980980- s = a.length;
981981- while (s--) {
982982- j -= (i[g++] = a[s]).prototype.Lvl;
10351035+10361036+ if (hasNew) {
10371037+ if (!self.ArZ) self.ArZ = [];
10381038+ self.ArZ.push(...availableZombies);
10391039+ self.ArZ.sort((a, b) => a.prototype.Lvl - b.prototype.Lvl);
10401040+ }
10411041+10421042+ // Add forced zombies for this flag
10431043+ const forcedMap = self.MustShowAtFlag || (self.MustShowAtFlag = {});
10441044+ const forced = forcedMap[flag];
10451045+ if (forced) {
10461046+ let fLen = forced.length;
10471047+ while (fLen--) {
10481048+ remainingLvl -= (zombiesToSpawn[count++] = forced[fLen]).prototype.Lvl;
9831049 }
9841050 }
985985- b = m[(s = (p = m.length) - 1)].prototype.Lvl;
986986- while (j > 0) {
987987- if (s && b > j) {
988988- while (--s && m[s].prototype.Lvl > j) {}
989989- p = s + 1;
990990- b = m[s].prototype.Lvl;
10511051+10521052+ // Fill remaining level with random zombies
10531053+ let zombiePool = self.ArZ;
10541054+ if (!zombiePool || zombiePool.length === 0) {
10551055+ zombiePool = self.ArZ = oS.ZName && oS.ZName.slice ? oS.ZName.slice(0) : [];
10561056+ if (zombiePool.length) zombiePool.sort((a, b) => a.prototype.Lvl - b.prototype.Lvl);
10571057+ }
10581058+ if (!zombiePool.length) {
10591059+ // No available zombies configured; avoid throwing.
10601060+ return;
10611061+ }
10621062+ let poolLen = zombiePool.length;
10631063+ let maxIdx = poolLen - 1;
10641064+ let maxLvl = zombiePool[maxIdx].prototype.Lvl;
10651065+10661066+ while (remainingLvl > 0) {
10671067+ if (maxIdx && maxLvl > remainingLvl) {
10681068+ while (--maxIdx && zombiePool[maxIdx].prototype.Lvl > remainingLvl) {}
10691069+ poolLen = maxIdx + 1;
10701070+ maxLvl = zombiePool[maxIdx].prototype.Lvl;
9911071 }
992992- j -= (i[g++] = m[Math.floor(Math.random() * p)]).prototype.Lvl;
10721072+ remainingLvl -= (zombiesToSpawn[count++] = zombiePool[Math.floor(Math.random() * poolLen)]).prototype.Lvl;
9931073 }
994994- e.NumZombies += g;
995995- e.SetTimeoutZombie(i, h);
10741074+10751075+ self.NumZombies += count;
10761076+ self.SetTimeoutZombie(zombiesToSpawn, delay);
9961077 },
997997- SelectFlagZombie1(d) {
998998- var h = oP;
999999- var c = [];
10001000- var a = 0;
10011001- var g = h.ArZ;
10021002- var f = oS.LargeWaveFlag[h.FlagZombies];
10031003- var e = h.SumToZombie;
10041004- var b = !f ? 150 : ((f.style.top = "5px"), --d, (c[a++] = oS.FlagZombie || oFlagZombie), 30);
10051005- while (d > 0) {
10061006- d -= (c[a++] = g[Math.floor(Math.random() * $SEql(d, e))]).prototype.Lvl;
10781078+ SelectFlagZombie1(lvl) {
10791079+ const self = oP;
10801080+ const zombies = [];
10811081+ let count = 0;
10821082+ const pool = self.ArZ;
10831083+ const isLargeWave = oS.LargeWaveFlag[self.FlagZombies];
10841084+ const sumToZombie = self.SumToZombie;
10851085+ const delay = !isLargeWave ? 150 : ((isLargeWave.style.top = "5px"), --lvl, (zombies[count++] = oS.FlagZombie || oFlagZombie), 30);
10861086+10871087+ while (lvl > 0) {
10881088+ lvl -= (zombies[count++] = pool[Math.floor(Math.random() * $SEql(lvl, sumToZombie))]).prototype.Lvl;
10071089 }
10081008- h.NumZombies += a;
10091009- h.SetTimeoutZombie(c, b);
10901090+ self.NumZombies += count;
10911091+ self.SetTimeoutZombie(zombies, delay);
10101092 },
10111011- SetTimeoutTomZombie(c) {
10121012- var f = [];
10131013- var d = [];
10141014- var e = 0;
10151015- var a = c.length;
10161016- var b;
10171017- var g;
10181018- for (b in oGd.$Tombstones) {
10191019- g = b.split("_");
10201020- d[e] = (f[e] = new c[Math.floor(Math.random() * a)]()).CustomBirth(g[0], g[1], 100);
10211021- ++e;
10931093+ SetTimeoutTomZombie(classes) {
10941094+ const zombieList = [];
10951095+ const protoList = [];
10961096+ let count = 0;
10971097+ const classLen = classes.length;
10981098+10991099+ for (let key in oGd.$Tombstones) {
11001100+ let coords = key.split("_");
11011101+ let zombie = new classes[Math.floor(Math.random() * classLen)]();
11021102+ protoList[count] = zombie;
11031103+ zombieList[count] = zombie.CustomBirth(coords[0], coords[1], 100);
11041104+ ++count;
10221105 }
10231023- this.AppearUP(d, f, e);
11061106+ this.AppearUP(zombieList, protoList, count);
10241107 },
10251025- SetTimeoutWaterZombie(j, b, e, h) {
10261026- var f = oGd.$LF;
10271027- var l = [];
10281028- var c = f.length;
10291029- var m = [];
10301030- var k = [];
10311031- var g = h.length;
10321032- var a;
10331033- var d = b - j + 1;
10341034- while (--c) {
10351035- f[c] === 2 && l.push(c);
11081108+ SetTimeoutWaterZombie(rowStart, rowEnd, count, classes) {
11091109+ const laneTypes = oGd.$LF;
11101110+ const validRows = [];
11111111+ let i = laneTypes.length;
11121112+ while (--i) {
11131113+ if (laneTypes[i] === 2) validRows.push(i);
10361114 }
10371037- a = l.length;
10381038- c = e;
11151115+11161116+ const rowLen = validRows.length;
11171117+ const zombies = [];
11181118+ const protos = [];
11191119+ const classLen = classes.length;
11201120+ const range = rowEnd - rowStart + 1;
11211121+11221122+ let c = count;
10391123 while (c--) {
10401040- k[c] = (m[c] = new h[Math.floor(Math.random() * g)]()).CustomBirth(l[Math.floor(Math.random() * a)], Math.floor(j + Math.random() * d));
11241124+ let zombie = new classes[Math.floor(Math.random() * classLen)]();
11251125+ protos[c] = zombie;
11261126+ zombies[c] = zombie.CustomBirth(validRows[Math.floor(Math.random() * rowLen)], Math.floor(rowStart + Math.random() * range));
10411127 }
10421042- this.AppearUP(k, m, e);
11281128+ this.AppearUP(zombies, protos, count);
10431129 },
10441044- AppearUP(a, c, b) {
10451045- oP.NumZombies += b;
11301130+ AppearUP(htmlList, objList, count) {
11311131+ oP.NumZombies += count;
10461132 asyncInnerHTML(
10471047- a.join(""),
10481048- (h, f) => {
10491049- EDPZ.appendChild(h);
10501050- var e = f.length;
10511051- var g;
10521052- var d;
10531053- while (e--) {
10541054- g = f[e];
10551055- g.Birth.call(g);
10561056- SetBlock(g.Ele);
11331133+ htmlList.join(""),
11341134+ (fragment, list) => {
11351135+ EDPZ.appendChild(fragment);
11361136+ let i = list.length;
11371137+ while (i--) {
11381138+ let zombie = list[i];
11391139+ zombie.Birth.call(zombie);
11401140+ SetBlock(zombie.Ele);
10571141 oSym.addTask(
10581142 10,
10591059- function (l, k, i, j) {
10601060- k = Math.max(k - j, 0);
10611061- SetStyle(l, {
10621062- top: k + "px",
10631063- clip: "rect(0,auto," + (i += j) + "px,0)",
11431143+ function (ele, top, clipHeight, step) {
11441144+ top = Math.max(top - step, 0);
11451145+ SetStyle(ele, {
11461146+ top: top + "px",
11471147+ clip: "rect(0,auto," + (clipHeight += step) + "px,0)",
10641148 });
10651065- k && oSym.addTask(10, arguments.callee, [l, k, i, j]);
11491149+ if (top) oSym.addTask(10, arguments.callee, [ele, top, clipHeight, step]);
10661150 },
10671067- [g.EleBody, (d = g.height), 0, d * 0.1]
11511151+ [zombie.EleBody, zombie.height, 0, zombie.height * 0.1]
10681152 );
10691153 }
10701154 },
10711071- c
11551155+ objList
10721156 );
10731157 },
10741074- SetZombie(j, b, e, h) {
10751075- var f = [];
10761076- var l = [];
10771077- var c = f.length;
10781078- var m = [];
10791079- var k = [];
10801080- var g = h.length;
10811081- var a;
10821082- var d = b - j + 1;
10831083- while (--c) {
10841084- f[c] === 2 && l.push(c);
11581158+ SetZombie(rowStart, rowEnd, count, classes) {
11591159+ // Redundant with SetTimeoutWaterZombie but keeping for legacy compatibility
11601160+ const laneTypes = [];
11611161+ const validRows = [];
11621162+ let i = laneTypes.length;
11631163+ // Logic seems broken in original script (f undefined), fixing assumption it uses oGd.$LF
11641164+ const realLanes = oGd.$LF;
11651165+ let j = realLanes.length;
11661166+ while (--j) {
11671167+ if (realLanes[j] === 2) validRows.push(j);
10851168 }
10861086- a = l.length;
10871087- c = e;
11691169+11701170+ const rowLen = validRows.length;
11711171+ const zombies = [];
11721172+ const protos = [];
11731173+ const classLen = classes.length;
11741174+ const range = rowEnd - rowStart + 1;
11751175+11761176+ let c = count;
10881177 while (c--) {
10891089- k[c] = (m[c] = new h[Math.floor(Math.random() * g)]()).CustomBirth(l[Math.floor(Math.random() * a)], Math.floor(j + Math.random() * d));
11781178+ let zombie = new classes[Math.floor(Math.random() * classLen)]();
11791179+ protos[c] = zombie;
11801180+ zombies[c] = zombie.CustomBirth(validRows[Math.floor(Math.random() * rowLen)], Math.floor(rowStart + Math.random() * range));
10901181 }
10911091- this.AppearUP1(k, m, e);
11821182+ this.AppearUP1(zombies, protos, count);
10921183 },
10931093- AppearUP1(a, c, b) {
10941094- oP.NumZombies += b;
11841184+ AppearUP1(htmlList, objList, count) {
11851185+ oP.NumZombies += count;
10951186 asyncInnerHTML(
10961096- a.join(""),
10971097- (h, f) => {
10981098- EDPZ.appendChild(h);
10991099- var e = f.length;
11001100- var g;
11011101- var d;
11021102- while (e--) {
11031103- g = f[e];
11041104- g.Birth.call(g);
11051105- SetBlock(g.Ele);
11871187+ htmlList.join(""),
11881188+ (fragment, list) => {
11891189+ EDPZ.appendChild(fragment);
11901190+ let i = list.length;
11911191+ while (i--) {
11921192+ let zombie = list[i];
11931193+ zombie.Birth.call(zombie);
11941194+ SetBlock(zombie.Ele);
11061195 oSym.addTask(
11071196 10,
11081108- function (l, k, i, j) {
11091109- k = Math.max(k - j, 0);
11101110- SetStyle(l, {
11111111- top: k + "px",
11121112- clip: "rect(0,auto," + (i += j) + "px,0)",
11971197+ function (ele, top, clipHeight, step) {
11981198+ top = Math.max(top - step, 0);
11991199+ SetStyle(ele, {
12001200+ top: top + "px",
12011201+ clip: "rect(0,auto," + (clipHeight += step) + "px,0)",
11131202 });
11141114- k && oSym.addTask(10, arguments.callee, [l, k, i, j]);
12031203+ if (top) oSym.addTask(10, arguments.callee, [ele, top, clipHeight, step]);
11151204 },
11161116- [g.EleBody, (d = g.height), 0, d * 0.1]
12051205+ [zombie.EleBody, zombie.height, 0, zombie.height * 0.1]
11171206 );
11181207 }
11191208 },
11201120- c
12091209+ objList
11211210 );
11221211 },
11231123- SetTimeoutZombie(b, d) {
11241124- var f = [];
11251125- var c = [];
11261126- var e = 0;
11271127- var g = 0;
11281128- var a = b.length;
11291129- while (e < a) {
11301130- c[e] = (f[e] = new b[e]()).prepareBirth(g);
11311131- g += d;
11321132- ++e;
12121212+ SetTimeoutZombie(zombieList, delay) {
12131213+ const htmlBuffer = [];
12141214+ const zombieObjs = [];
12151215+ let idx = 0;
12161216+ let timeOffset = 0;
12171217+ const len = zombieList.length;
12181218+12191219+ while (idx < len) {
12201220+ const zombie = new zombieList[idx]();
12211221+ htmlBuffer[idx] = zombie.prepareBirth(timeOffset);
12221222+ zombieObjs[idx] = zombie;
12231223+ timeOffset += delay;
12241224+ ++idx;
11331225 }
12261226+11341227 asyncInnerHTML(
11351135- c.join(""),
11361136- (k, j) => {
11371137- EDPZ.appendChild(k);
11381138- var h = j.length;
11391139- while (h--) {
11401140- j[h].Birth();
12281228+ htmlBuffer.join(""),
12291229+ (fragment, list) => {
12301230+ EDPZ.appendChild(fragment);
12311231+ let i = list.length;
12321232+ while (i--) {
12331233+ list[i].Birth();
11411234 }
11421235 },
11431143- f
12361236+ zombieObjs
11441237 );
11451238 },
11461239 FlagPrgs() {
11471147- var f = oP;
11481148- var c = f.FlagZombies;
11491149- var e = f.FlagToSumNum;
11501150- var a = 139 - c * f.FlagHeadStep;
11511151- var d = $SSml(c, e.a1, e.a2);
11521152- var b;
11531153- f.FlagNum > (c = ++f.FlagZombies)
11541154- ? (($("imgFlagHead").style.left = a + "px"),
11551155- ($("imgFlagMeterFull").style.clip = "rect(0,157px,21px," + (a + 11) + "px)"),
11561156- (b = $SEql(c, f.FlagToMonitor)) &&
11571157- oSym.addTask(
11581158- 1690,
11591159- (g) => {
11601160- !g[1] && (g[0](), (g[1] = 1));
11611161- },
11621162- [b]
11631163- ),
12401240+ const self = oP;
12411241+ let curFlag = self.FlagZombies;
12421242+ const flagSum = self.FlagToSumNum;
12431243+ const headPos = 139 - curFlag * self.FlagHeadStep;
12441244+ const lvl = $SSml(curFlag, flagSum.a1, flagSum.a2);
12451245+12461246+ if (self.FlagNum > (curFlag = ++self.FlagZombies)) {
12471247+ $("imgFlagHead").style.left = headPos + "px";
12481248+ $("imgFlagMeterFull").style.clip = "rect(0,157px,21px," + (headPos + 11) + "px)";
12491249+12501250+ // Monitor Flag
12511251+ let monitorFunc = $SEql(curFlag, self.FlagToMonitor);
12521252+ if (monitorFunc) {
11641253 oSym.addTask(
11651165- 1990,
11661166- (g) => {
11671167- var h = oP;
11681168- h.ReadyFlag === g++ && ((h.ReadyFlag = g), h.FlagPrgs());
12541254+ 1690,
12551255+ (args) => {
12561256+ if (!args[1]) {
12571257+ args[0]();
12581258+ args[1] = 1;
12591259+ }
11691260 },
11701170- [c]
11711171- ))
11721172- : (($("imgFlagHead").style.left = "-1px"), ($("imgFlagMeterFull").style.clip = "rect(0,157px,21px,0)"));
11731173- f.SelectFlagZombie.call(f, d, c);
11741174- f.UserDefinedFlagFunc && f.UserDefinedFlagFunc();
12611261+ [monitorFunc]
12621262+ );
12631263+ }
12641264+12651265+ oSym.addTask(
12661266+ 1990,
12671267+ (flag) => {
12681268+ const p = oP;
12691269+ if (p.ReadyFlag === flag++) {
12701270+ p.ReadyFlag = flag;
12711271+ p.FlagPrgs();
12721272+ }
12731273+ },
12741274+ [curFlag]
12751275+ );
12761276+ } else {
12771277+ $("imgFlagHead").style.left = "-1px";
12781278+ $("imgFlagMeterFull").style.clip = "rect(0,157px,21px,0)";
12791279+ }
12801280+12811281+ self.SelectFlagZombie.call(self, lvl, curFlag);
12821282+ if (self.UserDefinedFlagFunc) self.UserDefinedFlagFunc();
11751283 },
11761176- Monitor(a, b) {
11771177- a && a.f.apply(a.f, a.ar);
11781178- oP.UserDefinedFlagFunc = b ? b : null;
11791179- (function () {
12841284+ Monitor(config, userFunc) {
12851285+ if (config) config.f.apply(config.f, config.ar);
12861286+ oP.UserDefinedFlagFunc = userFunc ? userFunc : null;
12871287+12881288+ (function loop() {
11801289 oZ.traversalOf();
11811181- oSym.addTask(10, arguments.callee, []);
12901290+ oSym.addTask(10, loop, []);
11821291 })();
11831292 },
11841293};
12941294+11851295var oGd = {
11861296 Init() {
11871297 this.$ = [];
···11961306 this.$Balloon = new Array(oS.R + 1);
11971307 this.$Fog = [];
11981308 },
11991199- add(c, a, b, d) {
12001200- (b = (d = this.$)[a]) && b.Die();
12011201- d[a] = c;
13091309+ add(obj, c, r, dict) {
13101310+ let old = (dict = this.$)[c];
13111311+ if (old) old.Die();
13121312+ dict[c] = obj;
12021313 },
12031203- del(a) {
12041204- delete this.$[a.R + "_" + a.C + "_" + a.PKind];
13141314+ del(obj) {
13151315+ delete this.$[obj.R + "_" + obj.C + "_" + obj.PKind];
12051316 },
12061317 MakeFog() {
12071207- var d = "";
12081208- var g = (tx = ri = cj = 0);
12091209- var c = oGd.$Fog;
12101210- var b;
12111211- var a = 2 * oS.HaveFog + 3;
12121212- var e = (function () {
12131213- return function (f) {
12141214- var h = $User.Browser.IE && !$User.Browser.IE9;
12151215- d +=
12161216- '<img id="' +
12171217- f +
12181218- '" src="images/interface/fog' +
12191219- Math.floor(Math.random() * 4) +
12201220- "." +
12211221- (h ? "gif" : "png") +
12221222- '" style="left:' +
12231223- g +
12241224- "px;top:" +
12251225- tx +
12261226- 'px">';
12271227- };
12281228- })();
12291229- for (ri = 1, tx = 0; ri < 7; g = 0, ri++) {
12301230- for (ci = 0; ci <= a; ci++) {
12311231- e((c[(b = ri + "_" + ci)] = "Fog" + b));
12321232- g += 35;
13181318+ let html = "";
13191319+ let tx = 0,
13201320+ ri = 0,
13211321+ ci = 0,
13221322+ left = 0;
13231323+ const fogDict = oGd.$Fog;
13241324+ const maxCol = 2 * oS.HaveFog + 3;
13251325+ const isIE = $User.Browser.IE && !$User.Browser.IE9;
13261326+13271327+ const addFog = function (id) {
13281328+ html += `<img id="${id}" src="images/interface/fog${Math.floor(Math.random() * 4)}.${isIE ? "gif" : "png"}" style="left:${left}px;top:${tx}px">`;
13291329+ };
13301330+13311331+ for (ri = 1, tx = 0; ri < 7; left = 0, ri++) {
13321332+ for (ci = 0; ci <= maxCol; ci++) {
13331333+ let key = ri + "_" + ci;
13341334+ fogDict[key] = "Fog" + key;
13351335+ addFog(fogDict[key]);
13361336+ left += 35;
12331337 }
12341338 tx += 90;
12351339 }
12361236- NewEle("dFog", "div", "", { innerHTML: d }, EDAll);
13401340+ NewEle("dFog", "div", "", { innerHTML: html }, EDAll);
12371341 },
12381238- MoveFogLeft(a) {
12391239- (function (c, d, b, e) {
12401240- d -= 50;
12411241- d > b ? ((c.style.left = d + "px"), oSym.addTask(5, arguments.callee, [c, d, b, e])) : ((c.style.left = b + "px"), e && e());
12421242- })($("dFog"), 900, GetX(oS.C - oS.HaveFog) - 30, a);
13421342+ MoveFogLeft(callback) {
13431343+ (function (ele, currentX, limitX, cb) {
13441344+ currentX -= 50;
13451345+ if (currentX > limitX) {
13461346+ ele.style.left = currentX + "px";
13471347+ oSym.addTask(5, arguments.callee, [ele, currentX, limitX, cb]);
13481348+ } else {
13491349+ ele.style.left = limitX + "px";
13501350+ if (cb) cb();
13511351+ }
13521352+ })($("dFog"), 900, GetX(oS.C - oS.HaveFog) - 30, callback);
12431353 },
12441354 MoveFogRight() {
12451245- if (arguments.callee.caller.caller == null) {
12461246- return;
12471247- }
12481248- (function (a, b) {
12491249- (b += 50) < 901 ? ((a.style.left = b + "px"), oSym.addTask(5, arguments.callee, [a, b])) : (a.style.left = "900px");
13551355+ if (arguments.callee.caller.caller == null) return;
13561356+ (function (ele, currentX) {
13571357+ if ((currentX += 50) < 901) {
13581358+ ele.style.left = currentX + "px";
13591359+ oSym.addTask(5, arguments.callee, [ele, currentX]);
13601360+ } else {
13611361+ ele.style.left = "900px";
13621362+ }
12501363 })($("dFog"), GetX(oS.C - oS.HaveFog) - 3);
12511364 },
12521252- GatherFog(d, r, x, t, z) {
12531253- var c = d - x;
12541254- var b = d + x;
12551255- var q = r - t;
12561256- var p = r + t;
12571257- var e = [SetNone, SetBlock][z];
12581258- var w = oS.C;
12591259- var m = oS.R;
12601260- var h = w + 1;
12611261- var g = oS.HaveFog;
12621262- var a = g * 2;
12631263- var k = [];
12641264- var l;
12651265- var j;
12661266- var u;
12671267- var n = function (i) {
12681268- return (i - w) * 2 + a;
13651365+ GatherFog(r, c, rRange, cRange, mode) {
13661366+ // mode 0 = SetNone (clear), 1 = SetBlock (restore)
13671367+ const rowStart = r - rRange;
13681368+ const rowEnd = r + rRange;
13691369+ const colStart = c - cRange;
13701370+ const colEnd = c + cRange;
13711371+ const func = [SetNone, SetBlock][mode];
13721372+13731373+ const cols = oS.C;
13741374+ const rows = oS.R;
13751375+ const maxCol = cols + 1;
13761376+ const fogCount = oS.HaveFog * 2;
13771377+ const list = [];
13781378+13791379+ const mapCol = function (i) {
13801380+ return (i - cols) * 2 + fogCount;
12691381 };
12701270- var s = function (i) {
12711271- return (i - w) * 2 + a - 2;
13821382+ const mapColRev = function (i) {
13831383+ return (i - cols) * 2 + fogCount - 2;
12721384 };
12731273- if (c > 0) {
12741274- l = s(q > 0 ? q + 1 : 1);
12751275- j = n(p > h ? h : p - 1);
13851385+13861386+ // Collect fog elements to modify
13871387+ let i, j;
13881388+13891389+ if (rowStart > 0) {
13901390+ i = mapColRev(colStart > 0 ? colStart + 1 : 1);
13911391+ j = mapCol(colEnd > maxCol ? maxCol : colEnd - 1);
12761392 do {
12771277- l > -1 && k.push("Fog" + c + "_" + l);
12781278- } while (l++ < j);
13931393+ if (i > -1) list.push("Fog" + rowStart + "_" + i);
13941394+ } while (i++ < j);
12791395 }
12801280- if (b <= m) {
12811281- l = s(q > 0 ? q + 1 : 1);
12821282- j = n(p > h ? h : p - 1);
13961396+13971397+ if (rowEnd <= rows) {
13981398+ i = mapColRev(colStart > 0 ? colStart + 1 : 1);
13991399+ j = mapCol(colEnd > maxCol ? maxCol : colEnd - 1);
12831400 do {
12841284- l > -1 && k.push("Fog" + b + "_" + l);
12851285- } while (l++ < j);
14011401+ if (i > -1) list.push("Fog" + rowEnd + "_" + i);
14021402+ } while (i++ < j);
12861403 }
12871287- ++c;
12881288- --b;
12891289- l = s(q < 1 ? 1 : q);
12901290- j = n(p > h ? h : p);
12911291- u = l;
12921292- do {
14041404+14051405+ let curRow = rowStart + 1;
14061406+ let limitRow = rowEnd - 1;
14071407+ let startI = mapColRev(colStart < 1 ? 1 : colStart);
14081408+ let endJ = mapCol(colEnd > maxCol ? maxCol : colEnd);
14091409+14101410+ while (curRow <= limitRow) {
14111411+ i = startI;
12931412 do {
12941294- l > -1 && k.push("Fog" + c + "_" + l);
12951295- } while (l++ <= j);
12961296- l = u;
12971297- } while (c++ < b);
12981298- for (l = 0; l < k.length; e($(k[l])), l++) {}
12991299- if (z) {
13001300- var y = oGd.$Torch;
13011301- var f;
13021302- for (u in y) {
13031303- f = $P[y[u]];
13041304- this.GatherFog(f.R, f.C, 1, 1, 0);
14131413+ if (i > -1) list.push("Fog" + curRow + "_" + i);
14141414+ } while (i++ <= endJ);
14151415+ curRow++;
14161416+ }
14171417+14181418+ for (let k = 0; k < list.length; k++) {
14191419+ func($(list[k]));
14201420+ }
14211421+14221422+ // Recursive clear for Torchwood logic
14231423+ if (mode) {
14241424+ const torches = oGd.$Torch;
14251425+ for (let u in torches) {
14261426+ let p = $P[torches[u]];
14271427+ this.GatherFog(p.R, p.C, 1, 1, 0);
13051428 }
13061429 }
13071430 },
13081431};
14321432+13091433var oZ = {
13101310- Init(b) {
14341434+ Init(rows) {
13111435 this.$ = [];
13121436 this.$R = [];
13131313- var a;
13141314- for (a = b; a; this.$[a] = [], this.$R[a--] = []) {}
14371437+ let i = rows;
14381438+ while (i) {
14391439+ this.$[i] = [];
14401440+ this.$R[i--] = [];
14411441+ }
13151442 },
13161316- add(b, a) {
13171317- (a = oZ.$[b.R]).push(b);
13181318- a.sort((d, c) => {
13191319- return d.AttackedLX - c.AttackedLX;
13201320- });
13211321- a.RefreshTime = oSym.Now;
14431443+ add(zombie, list) {
14441444+ list = oZ.$[zombie.R];
14451445+ list.push(zombie);
14461446+ list.sort((a, b) => a.AttackedLX - b.AttackedLX);
14471447+ list.RefreshTime = oSym.Now;
13221448 },
13231323- getZ0(b, d) {
13241324- if (d < 1 || d > oS.R) {
13251325- return;
13261326- }
13271327- var c = 0;
13281328- var e = this.$[d];
13291329- var f;
13301330- var a = e.length;
13311331- while (c < a && (f = e[c++]).AttackedLX <= b) {
13321332- if (f.PZ && f.HP && f.AttackedRX >= b) {
13331333- return f;
14491449+ getZ0(lx, row) {
14501450+ if (row < 1 || row > oS.R) return;
14511451+ const list = this.$[row];
14521452+ let i = 0,
14531453+ len = list.length,
14541454+ zombie;
14551455+ while (i < len && (zombie = list[i++]).AttackedLX <= lx) {
14561456+ if (zombie.PZ && zombie.HP && zombie.AttackedRX >= lx) {
14571457+ return zombie;
13341458 }
13351459 }
13361460 },
13371337- getZ1(h, b) {
13381338- if (b < 1 || b > oS.R) {
13391339- return;
14611461+ getZ1(rx, row) {
14621462+ if (row < 1 || row > oS.R) return;
14631463+ const list = this.$[row];
14641464+ const rightList = this.$R[row];
14651465+ let sortedList;
14661466+14671467+ if (list.RefreshTime === rightList.RefreshTime) {
14681468+ sortedList = rightList;
14691469+ } else {
14701470+ sortedList = (this.$R[row] = list.slice(0)).sort((a, b) => b.AttackedRX - a.AttackedRX);
14711471+ sortedList.RefreshTime = list.RefreshTime;
13401472 }
13411341- var d = 0;
13421342- var j = this.$[b];
13431343- var f = this.$R[b];
13441344- var g;
13451345- var c;
13461346- var k;
13471347- var e;
13481348- (k = j.RefreshTime) === f.RefreshTime
13491349- ? (g = f)
13501350- : ((g = (this.$R[b] = j.slice(0)).sort((l, i) => {
13511351- return i.AttackedRX - l.AttackedRX;
13521352- })).RefreshTime = k);
13531353- e = g.length;
13541354- while (d < e && (c = g[d++]).AttackedRX >= h) {
13551355- if (c.PZ && c.HP && c.AttackedLX <= h) {
13561356- return c;
14731473+14741474+ let i = 0,
14751475+ len = sortedList.length,
14761476+ zombie;
14771477+ while (i < len && (zombie = sortedList[i++]).AttackedRX >= rx) {
14781478+ if (zombie.PZ && zombie.HP && zombie.AttackedLX <= rx) {
14791479+ return zombie;
13571480 }
13581481 }
13591482 },
13601360- getArZ(e, d, b) {
13611361- var g = 0;
13621362- var l = this.$[b];
13631363- var f = [];
13641364- var k = 0;
13651365- var c;
13661366- var h = l.length;
13671367- var j;
13681368- while (g < h && (j = (c = l[g++]).AttackedLX) < d) {
13691369- c.PZ && c.HP && (j > e || c.AttackedRX > e) && (f[k++] = c);
14831483+ getArZ(lx, rx, row) {
14841484+ const list = this.$[row];
14851485+ const result = [];
14861486+ let i = 0,
14871487+ len = list.length,
14881488+ zombie,
14891489+ zLX;
14901490+ while (i < len && (zLX = (zombie = list[i++]).AttackedLX) < rx) {
14911491+ if (zombie.PZ && zombie.HP && (zLX > lx || zombie.AttackedRX > lx)) {
14921492+ result.push(zombie);
14931493+ }
13701494 }
13711371- return f;
14951495+ return result;
13721496 },
13731373- getRangeLeftZ(e, d, b) {
13741374- if (b < 1 || b > oS.R) {
13751375- return;
13761376- }
13771377- var g = 0;
13781378- var l = this.$[b];
13791379- var f = [];
13801380- var k = 0;
13811381- var c;
13821382- var h = l.length;
13831383- var j;
13841384- while (g < h && (j = (c = l[g++]).AttackedLX) < d) {
13851385- if (c.PZ && c.HP && (j > e || c.AttackedRX > e)) {
13861386- return c;
14971497+ getRangeLeftZ(lx, rx, row) {
14981498+ if (row < 1 || row > oS.R) return;
14991499+ const list = this.$[row];
15001500+ let i = 0,
15011501+ len = list.length,
15021502+ zombie,
15031503+ zLX;
15041504+ while (i < len && (zLX = (zombie = list[i++]).AttackedLX) < rx) {
15051505+ if (zombie.PZ && zombie.HP && (zLX > lx || zombie.AttackedRX > lx)) {
15061506+ return zombie;
13871507 }
13881508 }
13891509 },
13901390- moveTo(g, f, c) {
13911391- var b = this.$[f];
13921392- var a = this.$[c];
13931393- var e = b.length;
13941394- var d;
13951395- while (e--) {
13961396- (o = b[e]).id === g &&
13971397- (b.splice(e, 1),
13981398- (o.R = c),
13991399- a.push(o),
14001400- (a.sort((i, h) => {
14011401- return i.AttackedLX - h.AttackedLX;
14021402- }).RefreshTime = b.RefreshTime =
14031403- oSym.Now),
14041404- (e = 0));
15101510+ moveTo(id, oldR, newR) {
15111511+ const oldList = this.$[oldR];
15121512+ const newList = this.$[newR];
15131513+ let i = oldList.length;
15141514+ while (i--) {
15151515+ let z = oldList[i];
15161516+ if (z.id === id) {
15171517+ oldList.splice(i, 1);
15181518+ z.R = newR;
15191519+ newList.push(z);
15201520+ newList.sort((a, b) => a.AttackedLX - b.AttackedLX);
15211521+ newList.RefreshTime = oldList.RefreshTime = oSym.Now;
15221522+ return;
15231523+ }
14051524 }
14061525 },
14071526 traversalOf() {
14081408- var a;
14091409- var b = this.$;
14101410- var j;
14111411- var l = 0;
14121412- var d = 0;
14131413- var k = 1e3;
14141414- var i;
14151415- var h;
14161416- var f = [
14171417- function (n) {
14181418- d = 1;
14191419- k = i;
15271527+ const zRows = this.$;
15281528+ let needsSort = 0;
15291529+ let needsRef = 0;
15301530+ let maxLX = 1000;
15311531+ let curLX;
15321532+15331533+ // Handlers for zombie status
15341534+ const handlers = [
15351535+ function (z) {
15361536+ // Dead
15371537+ needsRef = 1;
15381538+ maxLX = curLX;
14201539 },
14211421- function (n) {
14221422- (i = n.AttackedLX) > k && (l = d = 1);
14231423- k = i;
15401540+ function (z) {
15411541+ // Alive/Moved
15421542+ if ((curLX = z.AttackedLX) > maxLX) needsSort = needsRef = 1;
15431543+ maxLX = curLX;
14241544 },
14251545 ];
14261426- var e = b.length;
14271427- var m;
14281428- var c;
14291429- var g;
14301430- (function (r) {
14311431- var q = (j = b[r]).length;
14321432- var n = arguments.callee;
14331433- var p = oT.$[r];
14341434- var s = oT.$L[r];
14351435- while (q--) {
14361436- a = j[q];
14371437- a.HP && a.PZ && a.ZX < 901 && oT["chkD" + a.WalkDirection](a, r, p, s);
14381438- !a.HP ? (j.splice(q, 1), f[0](a)) : f[a.ChkActs(a, r, j, q)](a);
15461546+15471547+ // Process rows recursively to avoid blocking
15481548+ (function processRow(r) {
15491549+ const list = zRows[r];
15501550+ let i = list.length;
15511551+ const triggers = oT.$[r];
15521552+ const triggersL = oT.$L[r];
15531553+15541554+ while (i--) {
15551555+ let zombie = list[i];
15561556+ if (zombie.HP && zombie.PZ && zombie.ZX < 901) {
15571557+ oT["chkD" + zombie.WalkDirection](zombie, r, triggers, triggersL);
15581558+ }
15591559+15601560+ if (!zombie.HP) {
15611561+ list.splice(i, 1);
15621562+ handlers[0](zombie);
15631563+ } else {
15641564+ handlers[zombie.ChkActs(zombie, r, list, i)](zombie);
15651565+ }
14391566 }
14401440- l
14411441- ? ((l = d = 0),
14421442- j.sort((u, t) => {
14431443- return u.AttackedLX - t.AttackedLX;
14441444- }),
14451445- (j.RefreshTime = oSym.Now))
14461446- : d && ((d = 0), (j.RefreshTime = oSym.Now));
14471447- --r && oSym.addTask(0, n, [r]);
14481448- })(b.length - 1);
15671567+15681568+ if (needsSort) {
15691569+ needsSort = needsRef = 0;
15701570+ list.sort((a, b) => a.AttackedLX - b.AttackedLX);
15711571+ list.RefreshTime = oSym.Now;
15721572+ } else if (needsRef) {
15731573+ needsRef = 0;
15741574+ list.RefreshTime = oSym.Now;
15751575+ }
15761576+15771577+ if (--r) oSym.addTask(0, processRow, [r]);
15781578+ })(zRows.length - 1);
14491579 },
14501580};
15811581+14511582var oT = {
14521452- Init(b) {
15831583+ Init(rows) {
14531584 this.$ = [];
14541585 this.$L = [];
14551455- for (var a = b; a; ) {
14561456- this.$[a] = [];
14571457- this.$L[a--] = [];
15861586+ let i = rows;
15871587+ while (i) {
15881588+ this.$[i] = [];
15891589+ this.$L[i--] = [];
14581590 }
14591591 },
14601460- add(f, c, g) {
14611461- if (f <= 0 || f > oS.R) {
14621462- return;
15921592+ add(row, triggerBox, id) {
15931593+ if (row <= 0 || row > oS.R) return;
15941594+ const list = this.$[row];
15951595+ // triggerBox: [left, right, type?, id]
15961596+ let i = triggerBox.length;
15971597+ while (i--) {
15981598+ let t = triggerBox[i];
15991599+ list.push([t[0], t[1], t[2], id]);
14631600 }
14641464- var e = this.$[f];
14651465- var d = c.length;
14661466- var b;
14671467- while (d--) {
14681468- b = c[d];
14691469- e.push([b[0], b[1], b[2], g]);
16011601+ list.sort((a, b) => b[1] - a[1]);
16021602+ list.RefreshTime = new Date();
16031603+ },
16041604+ chkD0(zombie, row, triggers, triggersL) {
16051605+ // Check triggers moving Right? (Normal Direction)
16061606+ const attackLX = zombie.AttackedLX;
16071607+ let i = 0;
16081608+ const len = triggers.length;
16091609+ let t;
16101610+ while (i < len) {
16111611+ t = triggers[i];
16121612+ if (!t) {
16131613+ ++i;
16141614+ continue;
16151615+ }
16161616+ if (t[1] < attackLX) {
16171617+ break;
16181618+ }
16191619+ let plant = $P[t[3]];
16201620+ if (plant && plant.canTrigger && t[0] <= attackLX) {
16211621+ plant.TriggerCheck(zombie, t[2], i);
16221622+ }
16231623+ ++i;
14701624 }
14711471- e.sort((i, h) => {
14721472- return h[1] - i[1];
14731473- });
14741474- e.RefreshTime = new Date();
14751625 },
14761476- chkD0(g, e, d, h) {
14771477- var f = g.AttackedLX;
14781478- var c = 0;
14791479- var b;
14801480- var a;
14811481- while (c < d.length && (b = d[c])[1] >= f) {
14821482- (a = $P[b[3]]).canTrigger && b[0] <= f && a.TriggerCheck(g, b[2], c);
14831483- ++c;
16261626+ chkD1(zombie, row, triggers, triggersL) {
16271627+ // Check triggers moving Left?
16281628+ const attackRX = zombie.AttackedRX;
16291629+ let i = 0,
16301630+ t;
16311631+16321632+ // Sync triggersL if stale
16331633+ if (triggers.RefreshTime !== triggersL.RefreshTime) {
16341634+ triggersL = (this.$L[row] = triggers.slice(0)).sort((a, b) => a[0] - b[0]);
16351635+ triggersL.RefreshTime = triggers.RefreshTime;
16361636+ }
16371637+16381638+ while (i < triggersL.length) {
16391639+ t = triggersL[i];
16401640+ if (!t) {
16411641+ ++i;
16421642+ continue;
16431643+ }
16441644+ if (t[0] > attackRX) {
16451645+ break;
16461646+ }
16471647+ let plant = $P[t[3]];
16481648+ if (plant && plant.canTrigger && t[1] >= attackRX) {
16491649+ plant.TriggerCheck(zombie, t[2], i);
16501650+ }
16511651+ ++i;
14841652 }
14851653 },
14861486- chkD1(b, e, c, g) {
14871487- var j = b.AttackedLX;
14881488- var h = b.AttackedRX;
14891489- var f = 0;
14901490- var m;
14911491- var l;
14921492- var d;
14931493- var a;
14941494- var k;
14951495- (l = c.RefreshTime) === g.RefreshTime
14961496- ? (m = g)
14971497- : ((m = (this.$L[e] = c.slice(0)).sort((n, i) => {
14981498- return n[0] - i[0];
14991499- })).RefreshTime = l);
15001500- while (f < m.length && (d = m[f])[0] <= h) {
15011501- (a = $P[d[3]]).canTrigger && d[1] >= h && a.TriggerCheck(b, d[2], f);
15021502- ++f;
16541654+ delP(plant) {
16551655+ const triggers = plant.oTrigger;
16561656+ const id = plant.id;
16571657+ for (let row in triggers) {
16581658+ const list = this.$[row];
16591659+ let i = list.length;
16601660+ while (i--) {
16611661+ if (list[i][3] === id) list.splice(i, 1);
16621662+ }
16631663+ list.RefreshTime = new Date();
15031664 }
15041665 },
15051505- delP(e) {
15061506- var b = e.oTrigger;
15071507- var f = e.id;
15081508- var d;
15091509- var a;
15101510- var c;
15111511- for (d in b) {
15121512- for (c = (a = this.$[d]).length; c--; a[c][3] === f && a.splice(c, 1)) {}
15131513- a.RefreshTime = new Date();
16661666+ indexOf(arr, val) {
16671667+ // Custom regex-based index finder (legacy implementation kept intact)
16681668+ const re = new RegExp(val + ",", "g");
16691669+ const str = (arr.toString() + ",").replace(re, "┢,").replace(/[^,┢]/g, "");
16701670+ let idx = 0,
16711671+ pos = 0;
16721672+ const indices = [];
16731673+ while ((pos = str.indexOf("┢", pos)) > 0) {
16741674+ indices.push((pos++ - idx++ - 2) / 3);
15141675 }
15151515- },
15161516- indexOf(j, d) {
15171517- var f = new RegExp(d + ",", "g");
15181518- var h = (j.toString() + ",").replace(f, "┢,").replace(/[^,┢]/g, "");
15191519- var i = 0;
15201520- var g = 0;
15211521- var b = [];
15221522- for (; (g = h.indexOf("┢", g)) > 0; b.push((g++ - i++ - 2) / 3)) {}
15231523- return b;
16761676+ return indices;
15241677 },
15251678};
15261526-var asyncInnerHTML = function (d, c, a) {
15271527- var b = $n("div");
15281528- var e = document.createDocumentFragment();
15291529- b.innerHTML = d;
15301530- (function (g) {
15311531- var f = arguments.callee;
15321532- g--
15331533- ? (e.appendChild(b.firstChild),
15341534- setTimeout(() => {
15351535- f(g);
15361536- }, 0))
15371537- : c(e, a);
15381538- })(b.childNodes.length);
16791679+16801680+var asyncInnerHTML = function (html, callback, args) {
16811681+ const div = $n("div");
16821682+ const frag = document.createDocumentFragment();
16831683+ div.innerHTML = html;
16841684+16851685+ (function processNodes(count) {
16861686+ if (count--) {
16871687+ frag.appendChild(div.firstChild);
16881688+ setTimeout(() => processNodes(count), 0);
16891689+ } else {
16901690+ callback(frag, args);
16911691+ }
16921692+ })(div.childNodes.length);
15391693};
15401540-var WhichMouseButton = function (a) {
15411541- a = window.event || a;
15421542- var b = $User.Browser;
15431543- return !b.Gecko ? $SEql(a.button, { 1: 1, 0: b.IE ? 2 : 1, 2: 2, default: 1 }) : $SEql(a.which, { 1: 1, 3: 2, default: 1 });
16941694+16951695+var WhichMouseButton = function (e) {
16961696+ e = window.event || e;
16971697+ const b = $User.Browser;
16981698+ // Map buttons to 1 (left), 2 (right), 3 (middle)
16991699+ if (!b.Gecko) {
17001700+ return $SEql(e.button, { 1: 1, 0: b.IE ? 2 : 1, 2: 2, default: 1 });
17011701+ } else {
17021702+ return $SEql(e.which, { 1: 1, 3: 2, default: 1 });
17031703+ }
15441704};
15451545-var GroundOnmousedown = function (i) {
15461546- i = window.event || i;
15471547- var a = ((i.clientX - EDAlloffsetLeft + EBody.scrollLeft || EElement.scrollLeft) * 10) / 9;
15481548- var k = ((i.clientY + EBody.scrollTop || EElement.scrollTop) * 10) / 9;
15491549- var g = ChosePlantX(a);
15501550- var h = ChosePlantY(k);
15511551- var d = g[0];
15521552- var c = h[0];
15531553- var f = h[1];
15541554- var b = g[1];
15551555- var j = GetAP(a, k, f, b);
17051705+17061706+var GroundOnmousedown = function (e) {
17071707+ e = window.event || e;
17081708+ const x = ((e.clientX - EDAlloffsetLeft + EBody.scrollLeft || EElement.scrollLeft) * 10) / 9;
17091709+ const y = ((e.clientY + EBody.scrollTop || EElement.scrollTop) * 10) / 9;
17101710+17111711+ const cellX = ChosePlantX(x);
17121712+ const cellY = ChosePlantY(y);
17131713+ const c = cellX[0];
17141714+ const r = cellY[0];
17151715+ const rType = cellY[1];
17161716+ const cType = cellX[1];
17171717+17181718+ const ap = GetAP(x, y, rType, cType);
17191719+15561720 switch (oS.Chose) {
15571557- case 1:
15581558- WhichMouseButton(i) < 2 ? GrowPlant(j[0], d, c, f, b) : (PlayAudio("tap"), CancelPlant());
17211721+ case 1: // Planting
17221722+ WhichMouseButton(e) < 2 ? GrowPlant(ap[0], c, r, rType, cType) : (PlayAudio("tap"), CancelPlant());
15591723 break;
15601560- case -1:
15611561- WhichMouseButton(i) < 2 ? (PlayAudio("plant2"), ShovelPlant(j)) : (PlayAudio("tap"), CancelShovel());
17241724+ case -1: // Shoveling
17251725+ WhichMouseButton(e) < 2 ? (PlayAudio("plant2"), ShovelPlant(ap)) : (PlayAudio("tap"), CancelShovel());
15621726 }
15631727};
15641564-var GetAP = function (a, h, d, c) {
15651565- var f;
15661566- var i = oGd.$;
15671567- var e;
15681568- var g = [];
15691569- var b;
15701570- for (
15711571- f = 0;
15721572- f < 4;
15731573- g.push((e = i[d + "_" + c + "_" + f++])), e && !(a < e.pixelLeft || a > e.pixelRight || h < e.pixelTop || h > e.pixelBottom) && (b = e)
15741574- ) {}
15751575- return [g, b];
17281728+17291729+var GetAP = function (x, y, r, c) {
17301730+ const grid = oGd.$;
17311731+ let i = 0,
17321732+ plant,
17331733+ result = [],
17341734+ topPlant;
17351735+17361736+ while (i < 4) {
17371737+ plant = grid[r + "_" + c + "_" + i++];
17381738+ if (plant && !(x < plant.pixelLeft || x > plant.pixelRight || y < plant.pixelTop || y > plant.pixelBottom)) {
17391739+ topPlant = plant;
17401740+ }
17411741+ result.push(plant);
17421742+ }
17431743+ return [result, topPlant];
15761744};
15771577-var GroundOnkeydown = function (b) {
15781578- var a = b || window.event;
1579174515801580- if (a.key === "Escape") {
17461746+var GroundOnkeydown = function (e) {
17471747+ e = e || window.event;
17481748+17491749+ if (e.key === "Escape") {
15811750 switch (oS.Chose) {
15821751 case 1:
15831752 CancelPlant();
···15901759 }
1591176015921761 if (!oS.Chose) {
15931593- KeyBoardGrowPlant(a);
17621762+ KeyBoardGrowPlant(e);
15941763 }
15951764};
1596176515971597-var KeyBoardGrowPlant = function (e, a) {
15981598- a = a || 0;
17661766+var KeyBoardGrowPlant = function (e, mode) {
17671767+ mode = mode || 0;
15991768 let plantIndex = -1;
1600176916011601- // Handle top row numbers (Digit0–Digit9)
16021770 if (/^Digit[0-9]$/.test(e.code)) {
16031771 plantIndex = parseInt(e.code.replace("Digit", ""));
16041604- }
16051605-16061606- // Handle numpad numbers (Numpad0–Numpad9)
16071607- else if (/^Numpad[0-9]$/.test(e.code)) {
17721772+ } else if (/^Numpad[0-9]$/.test(e.code)) {
16081773 plantIndex = parseInt(e.code.replace("Numpad", ""));
16091774 }
1610177516111611- if (plantIndex !== -1 && a === 0) {
16121612- // Adjust so 0 = slot 9 (10th slot), 1–9 = slot 0–8
17761776+ if (plantIndex !== -1 && mode === 0) {
16131777 plantIndex = plantIndex === 0 ? 9 : plantIndex - 1;
16141778 ChosePlant({ clientX: 450, clientY: 300 }, plantIndex.toString());
16151779 }
16161780};
1617178116181782var GroundOnmousemove = function () {};
16191619-var GroundOnmousemove1 = function (j) {
16201620- j = window.event || j;
16211621- var d = ((j.clientX - EDAlloffsetLeft + EBody.scrollLeft || EElement.scrollLeft) * 10) / 9;
16221622- var b = ((j.clientY + EBody.scrollTop || EElement.scrollTop) * 10) / 9;
16231623- var k = oS.ChoseCard;
16241624- var h = ChosePlantX(d);
16251625- var i = ChosePlantY(b);
16261626- var f = h[0];
16271627- var c = i[0];
16281628- var g = i[1];
16291629- var a = h[1];
16301630- var m = GetAP(d, b, g, a);
16311631- var l = ArCard[k].PName.prototype;
17831783+17841784+var GroundOnmousemove1 = function (e) {
17851785+ e = window.event || e;
17861786+ const x = ((e.clientX - EDAlloffsetLeft + EBody.scrollLeft || EElement.scrollLeft) * 10) / 9;
17871787+ const y = ((e.clientY + EBody.scrollTop || EElement.scrollTop) * 10) / 9;
17881788+17891789+ const cardIdx = oS.ChoseCard;
17901790+ const cellX = ChosePlantX(x);
17911791+ const cellY = ChosePlantY(y);
17921792+ const c = cellX[0];
17931793+ const r = cellY[0];
17941794+ const rType = cellY[1];
17951795+ const cType = cellX[1];
17961796+17971797+ const ap = GetAP(x, y, rType, cType);
17981798+ const proto = ArCard[cardIdx].PName.prototype;
17991799+16321800 SetStyle($("MovePlant"), {
16331633- left: d - 0.5 * (l.beAttackedPointL + l.beAttackedPointR) + "px",
16341634- top: b + 20 - l.height + "px",
18011801+ left: x - 0.5 * (proto.beAttackedPointL + proto.beAttackedPointR) + "px",
18021802+ top: y + 20 - proto.height + "px",
16351803 });
16361636- l.CanGrow(m[0], g, a)
16371637- ? SetStyle($("MovePlantAlpha"), {
16381638- visibility: "visible",
16391639- left: f + l.GetDX() + "px",
16401640- top: c - l.height + l.GetDY(g, a, m[0]) + "px",
16411641- })
16421642- : SetHidden($("MovePlantAlpha"));
18041804+18051805+ if (proto.CanGrow(ap[0], rType, cType)) {
18061806+ SetStyle($("MovePlantAlpha"), {
18071807+ visibility: "visible",
18081808+ left: c + proto.GetDX() + "px",
18091809+ top: r - proto.height + proto.GetDY(rType, cType, ap[0]) + "px",
18101810+ });
18111811+ } else {
18121812+ SetHidden($("MovePlantAlpha"));
18131813+ }
16431814};
16441644-var GroundOnmousemove2 = function (k) {
16451645- k = window.event || k;
16461646- var d = k.clientX - EDAlloffsetLeft + EBody.scrollLeft || EElement.scrollLeft;
16471647- var b = k.clientY + EBody.scrollTop || EElement.scrollTop;
16481648- var m = oS.ChoseCard;
16491649- var h = ChosePlantX(d);
16501650- var i = ChosePlantY(b);
16511651- var f = h[0];
16521652- var c = i[0];
16531653- var g = i[1];
16541654- var a = h[1];
16551655- var n = GetAP(d, b, g, a);
16561656- var j = n[1];
16571657- var l = j ? j.id : "";
16581658- var p = oS.MPID;
16591659- p !== l && (p && SetAlpha($(p).childNodes[1], 100, 1), (oS.MPID = l) && SetAlpha($(l).childNodes[1], 60, 0.6));
18151815+18161816+var GroundOnmousemove2 = function (e) {
18171817+ e = window.event || e;
18181818+ const x = e.clientX - EDAlloffsetLeft + EBody.scrollLeft || EElement.scrollLeft;
18191819+ const y = e.clientY + EBody.scrollTop || EElement.scrollTop;
18201820+18211821+ const cellX = ChosePlantX(x);
18221822+ const cellY = ChosePlantY(y);
18231823+ const rType = cellY[1];
18241824+ const cType = cellX[1];
18251825+18261826+ const ap = GetAP(x, y, rType, cType);
18271827+ const plant = ap[1];
18281828+ const plantId = plant ? plant.id : "";
18291829+ const prevId = oS.MPID;
18301830+18311831+ if (prevId !== plantId) {
18321832+ if (prevId) SetAlpha($(prevId).childNodes[1], 100, 1);
18331833+ if ((oS.MPID = plantId)) SetAlpha($(plantId).childNodes[1], 60, 0.6);
18341834+ }
18351835+16601836 SetStyle($("tShovel"), {
16611661- left: ((d - 15) * 10) / 9 + "px",
16621662- top: ((b - 16) * 10) / 9 + "px",
18371837+ left: ((x - 15) * 10) / 9 + "px",
18381838+ top: ((y - 16) * 10) / 9 + "px",
16631839 });
16641840};
18411841+16651842var DisplayZombie = function () {
16661843 SetVisible($("bShowHandBook"));
16671667- /* SetVisible($("bMainMenu")); */
16681668- var d = oP.AZ.slice(0);
16691669- var b = d.length;
16701670- var c;
16711671- var g;
16721672- var h = $("dZombie");
16731673- var f = [];
16741674- var e = [];
16751675- var a;
16761676- while (b--) {
16771677- d[b][0].prototype.CanDiaplay === 0 && d.splice(b, 1);
18441844+18451845+ const azCopy = oP.AZ.slice(0);
18461846+ let i = azCopy.length;
18471847+ const zombieDiv = $("dZombie");
18481848+ const positions = [];
18491849+ const htmlList = [];
18501850+18511851+ while (i--) {
18521852+ if (azCopy[i][0].prototype.CanDiaplay === 0) azCopy.splice(i, 1);
16781853 }
16791679- c = b = d.length;
16801680- while (c--) {
16811681- f.push(Math.floor(150 + Math.random() * 444));
18541854+18551855+ let count = (i = azCopy.length);
18561856+ while (count--) {
18571857+ positions.push(Math.floor(150 + Math.random() * 444));
16821858 }
16831683- f.sort((j, i) => {
16841684- return j - i;
16851685- });
16861686- while (b) {
16871687- g = d[(a = Math.floor(Math.random() * b))][0].prototype;
16881688- g.CanDisplay
16891689- ? (d.splice(a, 1),
16901690- (e[b--] = g.getHTML(
16911691- "",
16921692- Math.floor(50 + Math.random() * 201) - g.width * 0.5,
16931693- f[b] - g.height,
16941694- 1,
16951695- "block",
16961696- "auto",
16971697- g.GetDTop,
16981698- g.PicArr[g.StandGif]
16991699- )))
17001700- : --b;
18591859+ positions.sort((a, b) => a - b);
18601860+18611861+ while (i) {
18621862+ let randIdx = Math.floor(Math.random() * i);
18631863+ let proto = azCopy[randIdx][0].prototype;
18641864+18651865+ if (proto.CanDisplay) {
18661866+ azCopy.splice(randIdx, 1);
18671867+ htmlList[i--] = proto.getHTML(
18681868+ "",
18691869+ Math.floor(50 + Math.random() * 201) - proto.width * 0.5,
18701870+ positions[i] - proto.height,
18711871+ 1,
18721872+ "block",
18731873+ "auto",
18741874+ proto.GetDTop,
18751875+ proto.PicArr[proto.StandGif]
18761876+ );
18771877+ } else {
18781878+ --i;
18791879+ }
17011880 }
17021702- asyncInnerHTML(e.join(""), (i) => {
17031703- h.appendChild(i);
18811881+18821882+ asyncInnerHTML(htmlList.join(""), (frag) => {
18831883+ zombieDiv.appendChild(frag);
17041884 });
17051885};
18861886+17061887var AutoSelectCard = function () {
17071707- var c = oS.ArCard;
17081708- var b = -1;
17091709- var a = c.length;
17101710- while (++b < a) {
17111711- SelectCard(c[b].prototype.EName);
18881888+ const cards = oS.ArCard;
18891889+ let i = -1;
18901890+ const len = cards.length;
18911891+ while (++i < len) {
18921892+ SelectCard(cards[i].prototype.EName);
17121893 }
17131894};
18951895+17141896var InitPCard = function () {
17151715- var d = "";
17161716- var f;
17171717- var e = oS.ArCard;
17181718- var a = e.length;
17191719- var b = 0;
17201720- var c;
17211721- while (b < a) {
17221722- f = e[b];
17231723- c = f.prototype;
17241724- if (!c.CanSelect) {
17251725- ++b;
18971897+ let html = "";
18981898+ const cards = oS.ArCard;
18991899+ const len = cards.length;
19001900+ let i = 0;
19011901+19021902+ while (i < len) {
19031903+ let card = cards[i];
19041904+ let proto = card.prototype;
19051905+ if (!proto.CanSelect) {
19061906+ ++i;
17261907 continue;
17271908 }
17281728- ArPCard[(EName = c.EName)] = { Select: 0, PName: f };
17291729- d +=
17301730- '<div class="span1" id="Card' +
17311731- EName +
17321732- '" onmouseout="SetHidden($(\'dTitle\'))" onmousemove="ViewCardTitle(' +
17331733- EName +
17341734- ',event)" onclick="SelectCard(\'' +
17351735- EName +
17361736- '\')"><img src="' +
17371737- c.PicArr[0] +
17381738- '"><span class="span2">' +
17391739- c.SunNum +
17401740- "</span></div>";
17411741- b++ % 6 === 5 && (d += "<br>");
19091909+ let name = proto.EName;
19101910+ ArPCard[name] = { Select: 0, PName: card };
19111911+ html += `<div class="span1" id="Card${name}" onmouseout="SetHidden($('dTitle'))" onmousemove="ViewCardTitle(${name},event)" onclick="SelectCard('${name}')"><img src="${proto.PicArr[0]}"><span class="span2">${proto.SunNum}</span></div>`;
19121912+ if (i++ % 6 === 5) html += "<br>";
17421913 }
17431743- $("dPCard").innerHTML = d;
19141914+ $("dPCard").innerHTML = html;
17441915};
19161916+17451917var InitHandBookPCard = function () {
17461918 PlayAudio("gravebutton");
17471747- var d = "";
17481748- var g;
17491749- var f;
17501750- var e = [
17511751- oPeashooter,
17521752- oSunFlower,
17531753- oCherryBomb,
17541754- oWallNut,
17551755- oPotatoMine,
17561756- oSnowPea,
17571757- oChomper,
17581758- oRepeater,
17591759- oPuffShroom,
17601760- oSunShroom,
17611761- oFumeShroom,
17621762- oGraveBuster,
17631763- oHypnoShroom,
17641764- oScaredyShroom,
17651765- oIceShroom,
17661766- oDoomShroom,
17671767- oLilyPad,
17681768- oSquash,
17691769- oThreepeater,
17701770- oTangleKlep,
17711771- oJalapeno,
17721772- oSpikeweed,
17731773- oTorchwood,
17741774- oTallNut,
17751775- oCactus,
17761776- oPlantern,
17771777- oSplitPea,
17781778- oStarfruit,
17791779- oPumpkinHead,
17801780- oFlowerPot,
17811781- oCoffeeBean,
17821782- oGarlic,
17831783- oSeaShroom,
17841784- oOxygen,
17851785- ostar,
17861786- oTTS,
17871787- oGun,
17881788- oSeaAnemone,
17891789- oGatlingPea,
17901790- oGloomShroom,
17911791- oTwinSunflower,
17921792- oSpikerock,
17931793- oTenManNut,
17941794- oSnowRepeater,
17951795- oCattail,
17961796- oLotusRoot,
17971797- oIceFumeShroom,
17981798- oLaserBean,
17991799- oBigChomper,
18001800- oFlamesMushroom,
18011801- oBalloon,
18021802- ];
18031803- var a = e.length;
18041804- var b = 0;
18051805- var c;
18061806- while (b < a) {
18071807- g = e[b];
18081808- c = g.prototype;
18091809- f = c.EName;
18101810- d += '<div class="span1" onclick="ViewProducePlant(' + f + ')"><img src="' + c.PicArr[0] + '"><div class="span2">' + c.SunNum + "</div></div>";
18111811- b++ % 6 === 5 && (d += "<br>");
19191919+ let html = "";
19201920+ let i = 0;
19211921+ const len = allPlantsArray().length;
19221922+19231923+ while (i < len) {
19241924+ let proto = allPlantsArray()[i].prototype;
19251925+ let name = proto.EName;
19261926+ html += `<div class="span1" onclick="ViewProducePlant(${name})"><img src="${proto.PicArr[0]}"><div class="span2">${proto.SunNum}</div></div>`;
19271927+ if (i++ % 6 === 5) html += "<br>";
18121928 }
18131813- $("dHandBookPCard").innerHTML = d;
18141814- ViewProducePlant(e[0]);
19291929+19301930+ $("dHandBookPCard").innerHTML = html;
19311931+ ViewProducePlant(allPlantsArray()[0]);
18151932 $("dHandBookPZ").className = "WindowFrame Almanac_PlantBack";
18161933 SetVisible($("dHandBookPZ"));
18171934 SetNone($("dHandBookZ"));
18181935 SetBlock($("dHandBookP"));
18191936};
19371937+18201938var InitHandBookZCard = function () {
18211939 PlayAudio("gravebutton");
18221822- var d = "";
18231823- var g;
18241824- var f;
18251825- var e = [
19401940+ let html = "";
19411941+ const zombies = [
18261942 oZombie,
18271943 oConeheadZombie,
18281944 oPoleVaultingZombie,
···18601976 oTrashZombie,
18611977 oLionDanceZombie,
18621978 ];
18631863- var a = e.length;
18641864- var b = 0;
18651865- var c;
18661866- while (b < a) {
18671867- g = e[b];
18681868- c = g.prototype;
18691869- f = c.EName;
18701870- d += '<div class="span1" onclick="ViewProduceZombie(' + f + ')"><img src="' + c.PicArr[0] + '"><div class="span2">' + c.SunNum + "</div></div>";
18711871- b++;
19791979+ let i = 0;
19801980+ const len = zombies.length;
19811981+19821982+ while (i < len) {
19831983+ let proto = zombies[i].prototype;
19841984+ let name = proto.EName;
19851985+ html += `<div class="span1" onclick="ViewProduceZombie(${name})"><img src="${proto.PicArr[0]}"><div class="span2">${proto.SunNum}</div></div>`;
19861986+ i++;
18721987 }
18731873- $("dHandBookZCard").innerHTML = d;
18741874- ViewProduceZombie(e[0]);
19881988+19891989+ $("dHandBookZCard").innerHTML = html;
19901990+ ViewProduceZombie(zombies[0]);
18751991 $("dHandBookPZ").className = "WindowFrame Almanac_ZombieBack";
18761992 SetVisible($("dHandBookPZ"));
18771993 SetNone($("dHandBookP"));
18781994 SetBlock($("dHandBookZ"));
18791995};
19961996+18801997var lastB;
18811881-(ViewProducePlant = function (b) {
18821882- if (lastB !== b) {
18831883- lastB = b;
18841884- var a = b.prototype;
19981998+var ViewProducePlant = function (plantClass) {
19991999+ if (lastB !== plantClass) {
20002000+ lastB = plantClass;
20012001+ const proto = plantClass.prototype;
18852002 PlayAudio("tap");
18861886- $("pHandBookPlant").style.backgroundImage = "url(" + a.PicArr[a.AlmanacGif] + ")";
18871887- $("pHandBookPlant").style.backgroundPosition = a.BookHandPosition || "50% " + (45 + a.height / 4) + "%";
18881888- $("dProducePlant").innerHTML = a.Produce;
18891889- innerText($("dHandBookPlantName"), a.CName);
18901890- innerText($("spSunNum"), a.SunNum);
18911891- innerText($("spCoolTime"), a.coolTime + "s");
18921892- $("pPlantBack").style.background = "url('images/interface/Almanac_Ground" + a.BookHandBack + ".jpg')";
18931893- // $("pPlantBack").style.backgroundPosition = -200 * a.BookHandBack + "px 0";
20032003+ $("pHandBookPlant").style.backgroundImage = "url(" + proto.PicArr[proto.StaticGif] + ")";
20042004+ $("pHandBookPlant").style.backgroundPosition = "50% " + (60 + proto.height / 4) + "%";
20052005+ $("dProducePlant").innerHTML = proto.Produce;
20062006+ innerText($("dHandBookPlantName"), proto.CName);
20072007+ innerText($("spSunNum"), proto.SunNum);
20082008+ innerText($("spCoolTime"), proto.coolTime + "s");
20092009+ $("pPlantBack").style.backgroundPosition = -200 * proto.BookHandBack + "px 0";
20102010+ }
20112011+};
20122012+20132013+var ViewProduceZombie = function (zombieClass) {
20142014+ PlayAudio("tap");
20152015+ const proto = zombieClass.prototype;
20162016+ $("pHandBookZombie").style.background = "url(" + proto.PicArr[proto.StaticGif] + ") no-repeat scroll " + proto.BookHandPosition;
20172017+ $("dProduceZombie").innerHTML = proto.Produce;
20182018+ innerText($("dHandBookZombieName"), proto.CName);
20192019+ $("pZombieBack").style.backgroundPosition = -200 * proto.BookHandBack + "px 0";
20202020+};
20212021+20222022+var ViewCardTitle = function (plantClass, e) {
20232023+ e = e || window.event;
20242024+ const titleDiv = $("dTitle");
20252025+ const proto = plantClass.prototype;
20262026+ let html = proto.CName + "<br>cooldown: " + proto.coolTime + "s<br>";
20272027+20282028+ if (oS.DKind && proto.night) {
20292029+ html += '<span style="color:#F00">Nocturnal - sleeps during the day</span><br>' + proto.Tooltip;
20302030+ } else {
20312031+ html += proto.Tooltip || '<span style="text-align:left">' + proto.Produce + "</span>";
18942032 }
18951895-}),
18961896- (ViewProduceZombie = function (b) {
18971897- PlayAudio("tap");
18981898- var a = b.prototype;
18991899- $("pHandBookZombie").style.background = "url(" + a.PicArr[a.AlmanacGif] + ") no-repeat scroll " + a.BookHandPosition;
19001900- $("dProduceZombie").innerHTML = a.Produce;
19011901- innerText($("dHandBookZombieName"), a.CName);
19021902- $("pZombieBack").style.background = "url('images/interface/Almanac_Ground" + a.BookHandBack + ".jpg')";
19031903- }),
19041904- (ViewCardTitle = function (b, c) {
19051905- c = c || window.event;
19061906- var f = $("dTitle");
19071907- var a = b.prototype;
19081908- f.innerHTML =
19091909- a.CName +
19101910- "<br>cooldown: " +
19111911- a.coolTime +
19121912- "s<br>" +
19131913- (oS.DKind && a.night
19141914- ? '<span style="color:#F00">Nocturnal - sleeps during the day</span><br>' + a.Tooltip
19151915- : a.Tooltip || '<span style="text-align:left">' + a.Produce + "</span>");
19161916- SetStyle(f, {
19171917- left: c.clientX + (EBody.scrollLeft || EElement.scrollLeft) - 3 + "px",
19181918- top: c.clientY + 18 + EBody.scrollTop || EElement.scrollTop + "px",
19191919- visibility: "visible",
19201920- });
19211921- }),
19221922- (ViewGenericMouseover = function (b, c) {
19231923- // b is innerhtml, c is event
19241924- c = c || window.event;
19251925- var a = $("dTitle");
19261926- a.innerHTML = b;
19271927- SetStyle(a, {
19281928- left: c.clientX + (EBody.scrollLeft || EElement.scrollLeft) - 3 + "px",
19291929- top: c.clientY + 18 + (EBody.scrollTop || EElement.scrollTop) + "px",
19301930- visibility: "visible",
19311931- });
19321932- }),
19331933- (SelectCard = function (c) {
19341934- PlayAudio("tap");
19351935- var h = $("Card" + c).childNodes;
19361936- var f = h[0];
19371937- var b = ArPCard[c];
19381938- var i = b.PName.prototype;
19391939- var g;
19401940- var a;
19411941- var j;
19421942- var e = $("btnOK");
19431943- if (!b.Select) {
19441944- if (!(ArPCard.SelNum |= 0)) {
19451945- e.disabled = "";
19461946- e.style.color = "#FC6";
19471947- } else if (ArPCard.SelNum > 9) {
20332033+20342034+ titleDiv.innerHTML = html;
20352035+ SetStyle(titleDiv, {
20362036+ left: e.clientX + (EBody.scrollLeft || EElement.scrollLeft) - 3 + "px",
20372037+ top: e.clientY + 18 + EBody.scrollTop || EElement.scrollTop + "px",
20382038+ visibility: "visible",
20392039+ });
20402040+};
20412041+20422042+var ViewGenericMouseover = function (content, e) {
20432043+ e = e || window.event;
20442044+ const titleDiv = $("dTitle");
20452045+ titleDiv.innerHTML = content;
20462046+ SetStyle(titleDiv, {
20472047+ left: e.clientX + (EBody.scrollLeft || EElement.scrollLeft) - 3 + "px",
20482048+ top: e.clientY + 18 + (EBody.scrollTop || EElement.scrollTop) + "px",
20492049+ visibility: "visible",
20502050+ });
20512051+};
20522052+20532053+var SelectCard = function (name, retry) {
20542054+ PlayAudio("tap");
20552055+ retry |= 0;
20562056+20572057+ const cardDom = $("Card" + name);
20582058+ const btnOK = $("btnOK");
20592059+ const cardObj = ArPCard && ArPCard[name];
20602060+20612061+ if (!cardDom || !btnOK || !cardObj || !cardObj.PName) {
20622062+ if (retry < 50 && typeof oSym !== "undefined" && oSym && typeof oSym.addTask === "function") {
20632063+ oSym.addTask(1, SelectCard, [name, retry + 1]);
20642064+ }
20652065+ return;
20662066+ }
20672067+20682068+ const cardEle = cardDom.childNodes;
20692069+ const imgEle = cardEle && cardEle[0];
20702070+ const proto = cardObj.PName.prototype;
20712071+ if (!imgEle) {
20722072+ return;
20732073+ }
20742074+20752075+ if (!cardObj.Select) {
20762076+ if (!(ArPCard.SelNum |= 0)) {
20772077+ btnOK.disabled = "";
20782078+ btnOK.style.color = "#FC6";
20792079+ } else if (ArPCard.SelNum > 9) {
20802080+ return;
20812081+ }
20822082+ ++ArPCard.SelNum;
20832083+ cardObj.Select = 1;
20842084+20852085+ if (oS.StaticCard) {
20862086+ const cardList = $("dCardList");
20872087+ if (!cardList) {
19482088 return;
19492089 }
19501950- ++ArPCard.SelNum;
19511951- b.Select = 1;
19521952- oS.StaticCard &&
19531953- ((g = NewEle(
19541954- "dCard" + c,
19551955- "div",
19561956- "",
19571957- {
19581958- onclick() {
19591959- SelectCard(c);
19601960- },
20902090+ const newCard = NewEle(
20912091+ "dCard" + name,
20922092+ "div",
20932093+ "",
20942094+ {
20952095+ onclick() {
20962096+ SelectCard(name);
19612097 },
19621962- $("dCardList")
19631963- )),
19641964- NewImg(0, f.src, "width:100px;height:120px", g),
19651965- innerText(NewEle("sSunNum" + c, "span", 0, 0, g), i.SunNum),
19661966- (f.style.filter = "grayscale(1) brightness(1.15)"));
19671967- } else {
19681968- b.Select = 0;
19691969- !--ArPCard.SelNum && ((e.disabled = "disabled"), (e.style.color = "#888"));
19701970- (g = $("dCard" + c)).onclick = null;
19711971- ClearChild(g.firstChild, g.childNodes[1], g.lastChild, g);
19721972- f.style.filter = "grayscale(0) brightness(1)";
20982098+ },
20992099+ cardList
21002100+ );
21012101+ NewImg(0, imgEle.src, "width:100px;height:120px", newCard);
21022102+ innerText(NewEle("sSunNum" + name, "span", 0, 0, newCard), proto.SunNum);
21032103+ imgEle.style.filter = "grayscale(1) brightness(1.15)";
19732104 }
19741974- }),
19751975- (ResetSelectCard = function () {
19761976- var b;
19771977- var a = $("btnOK");
19781978- for (b in ArPCard) {
19791979- ArPCard[b].Select && SelectCard(b);
21052105+ } else {
21062106+ cardObj.Select = 0;
21072107+ if (!--ArPCard.SelNum) {
21082108+ btnOK.disabled = "disabled";
21092109+ btnOK.style.color = "#888";
19802110 }
19811981- a.disabled = "disalbed";
19821982- a.style.color = "#888";
19831983- }),
19841984- (LetsGO = function () {
19851985- var e = $("dCardList");
19861986- var g = 0;
19871987- var k = e.childNodes.length;
19881988- var f;
19891989- var h;
19901990- var l;
19911991- var c;
19921992- var j;
19931993- var a;
19941994- var b = document.body;
19951995- SetStyle($("dTop"), { left: "105px", top: 0 });
19961996- e.style.left = 0;
19971997- SetVisible(e);
19981998- while (g < k) {
19991999- (function (d) {
20002000- f = (j = e.childNodes[d]).id.substr(5);
20012001- l = (h = ArPCard[f].PName).prototype;
20022002- j.onclick = function (i) {
20032003- ChosePlant(i, d);
20042004- };
20052005- j.onmouseover = function () {
20062006- SetVisible($("dTitle"));
20072007- ViewPlantTitle((oS.MCID = d));
20082008- };
20092009- j.onmouseout = function () {
20102010- SetHidden($("dTitle"));
20112011- };
20122012- j.firstChild.style.filter = "grayscale(1) brightness(1.15)";
20132013- (a = j.lastChild).id = "sSunNum" + d;
20142014- innerText(a, l.SunNum);
20152015- ArCard.push({ DID: j.id, CDReady: 0, SunReady: 0, PName: h });
20162016- })(g++);
21112111+ const newCard = $("dCard" + name);
21122112+ if (newCard) {
21132113+ newCard.onclick = null;
21142114+ ClearChild(newCard.firstChild, newCard.childNodes[1], newCard.lastChild, newCard);
20172115 }
20182018- b.onkeydown = function (d) {
20192019- GroundOnkeydown(d);
20202020- };
20212021- b.onmousedown = function (d) {
20222022- GroundOnmousedown(d);
20232023- };
20242024- b.onmousemove = function (d) {
20252025- GroundOnmousemove(d);
20262026- };
20272027- SetVisible(e);
20282028- !oS.BrainsNum && CustomSpecial(oBrains, oS.R - 1, -2);
20292029- (
20302030- oS.StartGame ||
20312031- function () {
20322032- StopMusic();
20332033- PlayMusic((oS.LoadMusic = oS.StartGameMusic));
20342034- NewMusic((oS.LoadMusic = oS.StartGameMusic));
20352035- SetVisible($("tdShovel"), $("dFlagMeter"), $("dTop"));
20362036- oS.InitLawnMower();
20372037- PrepareGrowPlants(() => {
20382038- oP.Monitor(oS.Monitor, oS.UserDefinedFlagFunc);
20392039- BeginCool();
20402040- oS.DKind && AutoProduceSun(25);
20412041- oSym.addTask(
20422042- 1500,
20432043- () => {
20442044- oP.AddZombiesFlag();
20452045- SetVisible($("dFlagMeterContent"));
20462046- },
20472047- []
20482048- );
20492049- });
20502050- }
20512051- )();
20522052- oS.StartTime = oSym.Now;
20532053- }),
20542054- (ViewPlantTitle = function (b) {
20552055- var f = $("dTitle");
20562056- var e = ArCard[b];
20572057- var c = e.PName.prototype;
20582058- var a = c.CName;
20592059- !oS.CardKind && ((a += "<br>cooldown: " + c.coolTime + "s<br>" + c.Tooltip), !e.CDReady && (a += '<br><span style="color:#F00">recharging</span>'));
20602060- !e.SunReady && (a += '<br><span style="color:#F00">not enough sun</span>');
20612061- f.innerHTML = a;
20622062- SetStyle(f, { top: 60 * b + "px", left: EDAlloffsetLeft + 100 + "px" });
20632063- }),
20642064- (BeginCool = function () {
20652065- var b = ArCard.length;
20662066- var c;
20672067- var d;
20682068- var a;
20692069- var e;
20702070- while (b--) {
20712071- a = (c = (d = ArCard[b]).PName.prototype).coolTime;
20722072- e = c.SunNum;
20732073- switch (a) {
20742074- case 0:
20752075- case 7.5:
20762076- d.CDReady = 1;
20772077- e <= oS.SunNum && ((d.SunReady = 1), ($(d.DID).childNodes[0].style.filter = "grayscale(0) brightness(1)"));
20782078- break;
20792079- case 30:
20802080- DoCoolTimer(b, 20);
20812081- break;
20822082- default:
20832083- DoCoolTimer(b, 35);
20842084- }
21162116+ imgEle.style.filter = "grayscale(0) brightness(1)";
21172117+ }
21182118+};
21192119+21202120+var ResetSelectCard = function () {
21212121+ const btnOK = $("btnOK");
21222122+ for (let name in ArPCard) {
21232123+ if (ArPCard[name].Select) SelectCard(name);
21242124+ }
21252125+ btnOK.disabled = "disalbed";
21262126+ btnOK.style.color = "#888";
21272127+};
21282128+21292129+var LetsGO = function () {
21302130+ const cardListDiv = $("dCardList");
21312131+ let i = 0;
21322132+ const len = cardListDiv.childNodes.length;
21332133+ const body = document.body;
21342134+21352135+ SetStyle($("dTop"), { left: "105px", top: 0 });
21362136+ cardListDiv.style.left = 0;
21372137+ SetVisible(cardListDiv);
21382138+21392139+ while (i < len) {
21402140+ (function (idx) {
21412141+ const ele = cardListDiv.childNodes[idx];
21422142+ const name = ele.id.substr(5);
21432143+ const cardData = ArPCard[name].PName;
21442144+ const proto = cardData.prototype;
21452145+21462146+ ele.onclick = function (e) {
21472147+ ChosePlant(e, idx);
21482148+ };
21492149+ ele.onmouseover = function () {
21502150+ SetVisible($("dTitle"));
21512151+ ViewPlantTitle((oS.MCID = idx));
21522152+ };
21532153+ ele.onmouseout = function () {
21542154+ SetHidden($("dTitle"));
21552155+ };
21562156+21572157+ ele.firstChild.style.filter = "grayscale(1) brightness(1.15)";
21582158+ ele.lastChild.id = "sSunNum" + idx;
21592159+ innerText(ele.lastChild, proto.SunNum);
21602160+ ArCard.push({ DID: ele.id, CDReady: 0, SunReady: 0, PName: cardData });
21612161+ })(i++);
21622162+ }
21632163+21642164+ body.onkeydown = function (e) {
21652165+ GroundOnkeydown(e);
21662166+ };
21672167+ body.onmousedown = function (e) {
21682168+ GroundOnmousedown(e);
21692169+ };
21702170+ body.onmousemove = function (e) {
21712171+ GroundOnmousemove(e);
21722172+ };
21732173+21742174+ SetVisible(cardListDiv);
21752175+ if (!oS.BrainsNum) CustomSpecial(oBrains, oS.R - 1, -2);
21762176+21772177+ (
21782178+ oS.StartGame ||
21792179+ function () {
21802180+ StopMusic();
21812181+ PlayMusic((oS.LoadMusic = oS.StartGameMusic));
21822182+ NewMusic((oS.LoadMusic = oS.StartGameMusic));
21832183+ SetVisible($("tdShovel"), $("dFlagMeter"), $("dTop"));
21842184+ oS.InitLawnMower();
21852185+21862186+ PrepareGrowPlants(() => {
21872187+ oP.Monitor(oS.Monitor, oS.UserDefinedFlagFunc);
21882188+ BeginCool();
21892189+ if (oS.DKind) AutoProduceSun(25);
21902190+ oSym.addTask(
21912191+ 1500,
21922192+ () => {
21932193+ oP.AddZombiesFlag();
21942194+ SetVisible($("dFlagMeterContent"));
21952195+ },
21962196+ []
21972197+ );
21982198+ });
20852199 }
20862086- }),
20872087- (ImmediatelyCool = function () {
20882088- var b = ArCard.length;
20892089- var c;
20902090- var d;
20912091- var a;
20922092- var e;
20932093- while (b--) {
20942094- a = (c = (d = ArCard[b]).PName.prototype).coolTime;
20952095- e = c.SunNum;
20962096- d.CDReady = 1;
20972097- d.SunReady = 1;
20982098- $(d.DID).childNodes[0].style.filter = "grayscale(0) brightness(1)";
22002200+ )();
22012201+22022202+ oS.StartTime = oSym.Now;
22032203+};
22042204+22052205+var ViewPlantTitle = function (index) {
22062206+ const titleDiv = $("dTitle");
22072207+ const card = ArCard[index];
22082208+ const proto = card.PName.prototype;
22092209+ let html = proto.CName;
22102210+22112211+ if (!oS.CardKind) {
22122212+ html += "<br>cooldown: " + proto.coolTime + "s<br>" + proto.Tooltip;
22132213+ if (!card.CDReady) html += '<br><span style="color:#F00">recharging</span>';
22142214+ }
22152215+ if (!card.SunReady) {
22162216+ html += '<br><span style="color:#F00">not enough sun</span>';
22172217+ }
22182218+22192219+ titleDiv.innerHTML = html;
22202220+ SetStyle(titleDiv, { top: 60 * index + "px", left: EDAlloffsetLeft + 100 + "px" });
22212221+};
22222222+22232223+var BeginCool = function () {
22242224+ let i = ArCard.length;
22252225+ while (i--) {
22262226+ const card = ArCard[i];
22272227+ const proto = card.PName.prototype;
22282228+ const coolTime = proto.coolTime;
22292229+ const sunCost = proto.SunNum;
22302230+22312231+ switch (coolTime) {
22322232+ case 0:
22332233+ case 7.5:
22342234+ card.CDReady = 1;
22352235+ if (sunCost <= oS.SunNum) {
22362236+ card.SunReady = 1;
22372237+ $(card.DID).childNodes[0].style.filter = "grayscale(0) brightness(1)";
22382238+ }
22392239+ break;
22402240+ case 30:
22412241+ DoCoolTimer(i, 20);
22422242+ break;
22432243+ default:
22442244+ DoCoolTimer(i, 35);
20992245 }
21002100- }),
21012101- (MonitorCard = function (d) {
21022102- var b = ArCard.length;
21032103- var c;
21042104- var a = Number(ESSunNum.innerHTML);
21052105- a !== oS.SunNum && (oS.SunNum = Math.min(a, oS.SunNum));
21062106- if (oS.Chose < 1) {
21072107- while (b--) {
21082108- (c = (d = ArCard[b]).PName.prototype).SunNum > oS.SunNum
21092109- ? (d.SunReady && (d.SunReady = 0), ($(d.DID).childNodes[0].style.filter = "grayscale(1) brightness(1.15)"))
21102110- : (!d.SunReady && (d.SunReady = 1), d.CDReady && ($(d.DID).childNodes[0].style.filter = "grayscale(0) brightness(1)"));
21112111- }
21122112- } else {
21132113- while (b--) {
21142114- (c = (d = ArCard[b]).PName.prototype).SunNum > oS.SunNum ? d.SunReady && (d.SunReady = 0) : !d.SunReady && (d.SunReady = 1);
22462246+ }
22472247+};
22482248+22492249+var ImmediatelyCool = function () {
22502250+ let i = ArCard.length;
22512251+ while (i--) {
22522252+ const card = ArCard[i];
22532253+ card.CDReady = 1;
22542254+ card.SunReady = 1;
22552255+ $(card.DID).childNodes[0].style.filter = "grayscale(0) brightness(1)";
22562256+ }
22572257+};
22582258+22592259+var MonitorCard = function (card) {
22602260+ let i = ArCard.length;
22612261+ const currentSunHTML = Number(ESSunNum.innerHTML);
22622262+22632263+ if (currentSunHTML !== oS.SunNum) {
22642264+ oS.SunNum = Math.min(currentSunHTML, oS.SunNum);
22652265+ }
22662266+22672267+ if (oS.Chose < 1) {
22682268+ while (i--) {
22692269+ card = ArCard[i];
22702270+ let proto = card.PName.prototype;
22712271+22722272+ if (proto.SunNum > oS.SunNum) {
22732273+ if (card.SunReady) card.SunReady = 0;
22742274+ $(card.DID).childNodes[0].style.filter = "grayscale(1) brightness(1.15)";
22752275+ } else {
22762276+ if (!card.SunReady) card.SunReady = 1;
22772277+ if (card.CDReady) $(card.DID).childNodes[0].style.filter = "grayscale(0) brightness(1)";
21152278 }
21162279 }
21172117- ViewPlantTitle(oS.MCID);
21182118- }),
21192119- (DoCoolTimer = function (c, b) {
21202120- var a = $(ArCard[c].DID);
21212121- NewEle("dCD1" + c, "span", "position:absolute;left:22px;top:22px;font-size:18px;font-weight:500;font-family:Verdana;color:#000", "", a);
21222122- NewEle("dCD2" + c, "span", "position:absolute;left:20px;top:20px;font-size:18px;font-weight:500;font-family:Verdana;color:#FF0", "", a);
21232123- (function (d, e) {
21242124- d > 0
21252125- ? (innerText($("dCD1" + e), d), innerText($("dCD2" + e), d), oSym.addTask(50, arguments.callee, [(d - 0.5).toFixed(1), e]))
21262126- : (ClearChild($("dCD1" + e), $("dCD2" + e)), (ArCard[e].CDReady = 1), MonitorCard());
21272127- })(b, c);
21282128- }),
21292129- (ChosePlant = function (h, d) {
21302130- // PlayAudio("seedlift");
21312131- var g = ArCard[(oS.ChoseCard = d)];
21322132- if (!(g.CDReady && g.SunReady)) {
21332133- PlayAudio("buzzer");
21342134- return;
22802280+ } else {
22812281+ while (i--) {
22822282+ card = ArCard[i];
22832283+ let proto = card.PName.prototype;
22842284+ if (proto.SunNum > oS.SunNum) {
22852285+ if (card.SunReady) card.SunReady = 0;
22862286+ } else {
22872287+ if (!card.SunReady) card.SunReady = 1;
22882288+ }
21352289 }
21362136- PlayAudio("seedlift");
21372137- h = window.event || h;
21382138- var b = h.clientX - EDAlloffsetLeft + EBody.scrollLeft || EElement.scrollLeft;
21392139- var a = h.clientY + EBody.scrollTop || EElement.scrollTop;
21402140- var j = g.PName.prototype;
21412141- var e = ArCard.length;
21422142- var f;
21432143- var c = j.PicArr;
21442144- oS.Chose = 1;
21452145- !oS.CardKind
21462146- ? EditImg(
21472147- NewImg(
21482148- "MovePlant",
21492149- c[j.StaticGif],
21502150- "left:" + b - 0.5 * (j.beAttackedPointL + j.beAttackedPointR) + "px;top:" + a + 20 - j.height + "px;z-index:254",
21512151- EDAll
21522152- ).cloneNode(false),
21532153- "MovePlantAlpha",
21542154- "",
21552155- {
21562156- visibility: "hidden",
21572157- filter: "alpha(opacity=40)",
21582158- opacity: 0.4,
21592159- zIndex: 30,
21602160- },
21612161- EDAll
21622162- )
21632163- : (NewImg(
21642164- "MovePlant",
21652165- j.PicArr[j.StandGif],
21662166- "left:" + (b - 0.5 * (j.beAttackedPointL + j.beAttackedPointR)) + "px;top:" + (a + 20 - j.height) + "px;z-index:254",
21672167- EDAll
21682168- ),
21692169- NewImg("MovePlantAlpha", j.PicArr[j.StandGif], "visibility:hidden;filter:alpha(opacity=40);opacity:0.4;z-index:30", EDAll));
21702170- while (e--) {
21712171- $(ArCard[e].DID).childNodes[0].style.filter = "grayscale(1) brightness(1.15)";
22902290+ }
22912291+ ViewPlantTitle(oS.MCID);
22922292+};
22932293+22942294+var DoCoolTimer = function (index, duration) {
22952295+ const ele = $(ArCard[index].DID);
22962296+ NewEle("dCD1" + index, "span", "position:absolute;left:22px;top:22px;font-size:18px;font-weight:500;font-family:Verdana;color:#000", "", ele);
22972297+ NewEle("dCD2" + index, "span", "position:absolute;left:20px;top:20px;font-size:18px;font-weight:500;font-family:Verdana;color:#FF0", "", ele);
22982298+22992299+ (function tick(timeLeft, idx) {
23002300+ if (timeLeft > 0) {
23012301+ innerText($("dCD1" + idx), timeLeft);
23022302+ innerText($("dCD2" + idx), timeLeft);
23032303+ oSym.addTask(50, tick, [(timeLeft - 0.5).toFixed(1), idx]);
23042304+ } else {
23052305+ ClearChild($("dCD1" + idx), $("dCD2" + idx));
23062306+ ArCard[idx].CDReady = 1;
23072307+ MonitorCard();
21722308 }
21732173- SetHidden($("dTitle"));
21742174- GroundOnmousemove = GroundOnmousemove1;
21752175- }),
21762176- (CancelPlant = function () {
21772177- ClearChild($("MovePlant"), $("MovePlantAlpha"));
21782178- oS.Chose = 0;
21792179- MonitorCard();
21802180- GroundOnmousemove = function () {};
21812181- }),
21822182- (ShovelPlant = function (a) {
21832183- PlayAudio("plant2");
21842184- var b = a[0];
21852185- var c = a[1];
21862186- c && (c.PKind || !(b[1] || b[2])) && (c.Die(), (oS.MPID = ""));
21872187- CancelShovel();
21882188- }),
21892189- (ChoseShovel = function (a) {
21902190- PlayAudio("shovel");
21912191- WhichMouseButton(a) < 2 &&
21922192- (SetHidden($("imgShovel")),
23092309+ })(duration, index);
23102310+};
23112311+23122312+var ChosePlant = function (e, index) {
23132313+ const card = ArCard[(oS.ChoseCard = index)];
23142314+ if (!(card.CDReady && card.SunReady)) {
23152315+ PlayAudio("buzzer");
23162316+ return;
23172317+ }
23182318+ PlayAudio("seedlift");
23192319+ e = window.event || e;
23202320+ const x = e.clientX - EDAlloffsetLeft + EBody.scrollLeft || EElement.scrollLeft;
23212321+ const y = e.clientY + EBody.scrollTop || EElement.scrollTop;
23222322+23232323+ const proto = card.PName.prototype;
23242324+ const len = ArCard.length;
23252325+23262326+ oS.Chose = 1;
23272327+23282328+ if (!oS.CardKind) {
23292329+ EditImg(
21932330 NewImg(
21942194- "tShovel",
21952195- "images/interface/Shovel/0.gif",
21962196- "left:" + (a.clientX - 10) + "px;top:" + (a.clientY + document.body.scrollTop - 17) + "px;z-index:1",
23312331+ "MovePlant",
23322332+ proto.PicArr[proto.StaticGif],
23332333+ `left:${x - 0.5 * (proto.beAttackedPointL + proto.beAttackedPointR)}px;top:${y + 20 - proto.height}px;z-index:254`,
21972334 EDAll
21982198- ),
21992199- (oS.Chose = -1),
22002200- (GroundOnmousemove = GroundOnmousemove2),
22012201- StopBubble(a));
22022202- }),
22032203- (CancelShovel = function (a) {
22042204- var b = oS.MPID;
22052205- ClearChild($("tShovel"));
22062206- oS.Chose = 0;
22072207- SetVisible($("imgShovel"));
22082208- b && SetAlpha($(b).childNodes[1], 100, 1);
22092209- GroundOnmousemove = function () {};
22102210- }),
22112211- (StopBubble = function (a) {
22122212- window.event ? (event.cancelBubble = true) : a.stopPropagation();
22132213- }),
22142214- (GrowPlant = function (l, d, c, e, b) {
22152215- var j = oS.ChoseCard;
22162216- var f = ArCard[j];
22172217- var h = f.PName;
22182218- var k = h.prototype;
22192219- var i = k.coolTime;
22202220- var a;
22212221- var g = oGd.$LF[e];
23352335+ ).cloneNode(false),
23362336+ "MovePlantAlpha",
23372337+ "",
23382338+ { visibility: "hidden", filter: "alpha(opacity=40)", opacity: 0.4, zIndex: 30 },
23392339+ EDAll
23402340+ );
23412341+ } else {
23422342+ NewImg(
23432343+ "MovePlant",
23442344+ proto.PicArr[proto.StandGif],
23452345+ `left:${x - 0.5 * (proto.beAttackedPointL + proto.beAttackedPointR)}px;top:${y + 20 - proto.height}px;z-index:254`,
23462346+ EDAll
23472347+ );
23482348+ NewImg("MovePlantAlpha", proto.PicArr[proto.StandGif], "visibility:hidden;filter:alpha(opacity=40);opacity:0.4;z-index:30", EDAll);
23492349+ }
2222235022232223- // Check if the plant can grow at the selected location
22242224- if (k.CanGrow(l, e, b)) {
22252225- // Play planting audio based on soil type
22262226- PlayAudio(g !== 2 ? "plant" + Math.floor(1 + Math.random() * 2) : "plant_water");
23512351+ for (let i = 0; i < len; i++) {
23522352+ $(ArCard[i].DID).childNodes[0].style.filter = "grayscale(1) brightness(1.15)";
23532353+ }
23542354+ SetHidden($("dTitle"));
23552355+ GroundOnmousemove = GroundOnmousemove1;
23562356+};
2227235722282228- // Plant the selected plant at the specified location
22292229- !oS.CardKind
22302230- ? new h().Birth(d, c, e, b, l)
22312231- : asyncInnerHTML(
22322232- (a = new h()).CustomBirth(e, b, 0, "auto"),
22332233- (n, m) => {
22342234- EDPZ.appendChild(n);
22352235- m.Birth();
22362236- },
22372237- a
22382238- );
23582358+var CancelPlant = function () {
23592359+ ClearChild($("MovePlant"), $("MovePlantAlpha"));
23602360+ oS.Chose = 0;
23612361+ MonitorCard();
23622362+ GroundOnmousemove = function () {};
23632363+};
2239236422402240- // Deduct sun points based on plant's cost
22412241- innerText(ESSunNum, (oS.SunNum -= k.SunNum));
23652365+var ShovelPlant = function (data) {
23662366+ PlayAudio("plant2");
23672367+ const plants = data[0];
23682368+ const topPlant = data[1];
23692369+ if (topPlant && (topPlant.PKind || !(plants[1] || plants[2]))) {
23702370+ topPlant.Die();
23712371+ oS.MPID = "";
23722372+ }
23732373+ CancelShovel();
23742374+};
2242237522432243- // Start cooldown timer for the plant
22442244- i && ((f.CDReady = 0), DoCoolTimer(j, k.coolTime));
23762376+var ChoseShovel = function (e) {
23772377+ PlayAudio("shovel");
23782378+ if (WhichMouseButton(e) < 2) {
23792379+ SetHidden($("imgShovel"));
23802380+ NewImg("tShovel", "images/interface/Shovel/0.gif", `left:${e.clientX - 10}px;top:${e.clientY + document.body.scrollTop - 17}px;z-index:1`, EDAll);
23812381+ oS.Chose = -1;
23822382+ GroundOnmousemove = GroundOnmousemove2;
23832383+ StopBubble(e);
23842384+ }
23852385+};
2245238622462246- // Show planting animation
22472247- oSym.addTask(20, SetHidden, [
22482248- SetStyle(g !== 2 ? $("imgGrowSoil") : $("imgGrowSpray"), {
22492249- left: d - 30 + "px",
22502250- top: c - 30 + "px",
22512251- zIndex: 3 * e + 1,
22522252- visibility: "visible",
22532253- }),
22542254- ]);
23872387+var CancelShovel = function (e) {
23882388+ const prevId = oS.MPID;
23892389+ ClearChild($("tShovel"));
23902390+ oS.Chose = 0;
23912391+ SetVisible($("imgShovel"));
23922392+ if (prevId) SetAlpha($(prevId).childNodes[1], 100, 1);
23932393+ GroundOnmousemove = function () {};
23942394+};
23952395+23962396+var StopBubble = function (e) {
23972397+ window.event ? (event.cancelBubble = true) : e.stopPropagation();
23982398+};
23992399+24002400+var GrowPlant = function (plants, c, r, rType, cType) {
24012401+ const cardIdx = oS.ChoseCard;
24022402+ const card = ArCard[cardIdx];
24032403+ const PlantClass = card.PName;
24042404+ const proto = PlantClass.prototype;
24052405+ const coolTime = proto.coolTime;
24062406+ const laneType = oGd.$LF[rType];
2255240722562256- // List of seed plants
22572257- const seedPlants = [
22582258- oSeedPeashooter,
22592259- oSeedSnowPea,
22602260- oSeedSquash,
22612261- oSeedPotatoMine,
22622262- oSeedWallNut,
22632263- oSeedRepeater2,
22642264- oSeedHypnoShroom,
22652265- oSeedPuffShroom,
22662266- oSeedPumpkinHead,
22672267- oSeedPlantern,
22682268- oSeedThreepeater,
22692269- oSeedTallNut,
22702270- oSeedTorchwood,
22712271- oSeedLilyPad,
22722272- oSeedCherryBomb,
22732273- oSeedChomper,
22742274- oSeedRepeater,
22752275- oSeedGarlic,
22762276- oSeedScaredyShroom,
22772277- oSeedBlover,
22782278- oSeedStarfruit,
22792279- oSeedCactus,
22802280- oSeedFumeShroom,
22812281- oSeedDoomShroom,
22822282- oSeedSeaShroom,
22832283- oSeedJalapeno,
22842284- oSeedTangleKelp,
22852285- oSeedIceShroom,
22862286- oSeedGloomShroom,
22872287- ];
22882288- // Check if the chosen plant is a seed variant
22892289- if (seedPlants.includes(h)) {
22902290- // Hide the card instead of removing it
22912291- SetHidden($(f.DID));
22922292- }
24082408+ // Check if the plant can grow at the selected location
24092409+ if (proto.CanGrow(plants, rType, cType)) {
24102410+ // Play planting audio based on soil type
24112411+ PlayAudio(laneType !== 2 ? "plant" + Math.floor(1 + Math.random() * 2) : "plant_water");
24122412+24132413+ // Plant the selected plant at the specified location
24142414+ if (!oS.CardKind) {
24152415+ new PlantClass().Birth(c, r, rType, cType, plants);
24162416+ } else {
24172417+ let tempPlant = new PlantClass();
24182418+ asyncInnerHTML(
24192419+ tempPlant.CustomBirth(rType, cType, 0, "auto"),
24202420+ (ele, instance) => {
24212421+ EDPZ.appendChild(ele);
24222422+ instance.Birth();
24232423+ },
24242424+ tempPlant
24252425+ );
22932426 }
2294242722952295- // Clear plant selection
22962296- CancelPlant();
22972297- });
24282428+ // Deduct sun points
24292429+ innerText(ESSunNum, (oS.SunNum -= proto.SunNum));
2298243022992299-(AutoProduceSun = function (a) {
23002300- // console.log("ROBLNET13 on github")
23012301- AppearSun(GetX(Math.floor(1 + Math.random() * oS.C)), GetY(Math.floor(1 + Math.random() * oS.R)), a, 1);
23022302- oSym.addTask(Math.floor(9 + Math.random() * 3) * 100, AutoProduceSun, [a]);
23032303-}),
23042304- (AppearSun = function (h, f, e, a) {
23052305- var b;
23062306- var d;
23072307- var g = "Sun" + Math.random();
23082308- var c = "cursor:url(images/interface/Pointer.cur),pointer;z-index:25;left:" + h + "px;";
23092309- switch (e) {
23102310- case 25:
23112311- c += "width:78px;height:78px";
23122312- b = 39;
23132313- break;
23142314- case 15:
23152315- c += "width:46px;height:46px";
23162316- b = 23;
23172317- break;
23182318- default:
23192319- c += "width:100px;height:100px";
23202320- b = 55;
24312431+ // Start cooldown
24322432+ if (coolTime) {
24332433+ card.CDReady = 0;
24342434+ DoCoolTimer(cardIdx, coolTime);
23212435 }
23222322- a
23232323- ? ((d = 0), oSym.addTask(10, MoveDropSun, [g, f]))
23242324- : ((d = f - b - 20),
23252325- (c += ";top:" + d + "px"),
23262326- oSym.addTask(
23272327- 1,
23282328- function (q, p, n, j, l, k, m, i) {
23292329- if (ArSun[q] && ArSun[q].C) {
23302330- SetStyle($(q), {
23312331- left: (p += j * k) + "px",
23322332- top: (n += Number(l[0])) + "px",
23332333- });
23342334- l.shift();
23352335- --m;
23362336- m > 0 && (l.length === 0 && (l = [8, 16, 24, 32]), oSym.addTask(i, arguments.callee, [q, p, n, j, l, k, m, ++i]));
23372337- }
23382338- },
23392339- [g, h, d, Math.floor(Math.random() * 4), [-32, -24, -16, -8], [-1, 1][Math.floor(Math.random() * 2)], 8, 2]
23402340- ),
23412341- oSym.addTask(800, DisappearSun, [g], 3));
23422342- ArSun[g] = { id: g, N: e, C: 1, left: h, top: d };
23432343- NewImg(g, "images/interface/Sun.webp", c, EDAll, {
23442344- onclick() {
23452345- ClickSun(this.id);
23462346- },
23472347- });
23482348- oS.AutoSun && oSym.addTask(100, ClickSun, [g]);
23492349- }),
23502350- (MoveDropSun = function (c, b) {
23512351- var a = ArSun[c];
23522352- a && a.C && (a.top < b - 53 ? (($(c).style.top = (a.top += 3) + "px"), oSym.addTask(5, MoveDropSun, [c, b])) : oSym.addTask(800, DisappearSun, [c]));
23532353- }),
23542354- (DisappearSun = function (b) {
23552355- var a = ArSun[b];
23562356- a && a.C && (delete ArSun[b], ClearChild($(b)));
23572357- }),
23582358- (ClickSun = function (b) {
23592359- PlayAudioLegacy("points");
23602360- var a = ArSun[b];
23612361- a && a.C && ((a.C = 0), oSym.addTask(0, MoveClickSun, [b]));
23622362- }),
23632363- (MoveClickSun = function (b) {
23642364- var a = 15;
23652365- var c = ArSun[b];
23662366- var e = 85;
23672367- var i = -20;
23682368- var d = c.left;
23692369- var h = c.top;
23702370- var g = Math.round((d - e) / a);
23712371- var f = Math.round((h - i) / a);
23722372- (function (k, l, n, s, m, r, j, q, p) {
23732373- (m -= q) > n
23742374- ? (SetStyle($(k), { left: m + "px", top: (r -= p) + "px" }), oSym.addTask(j, arguments.callee, [k, l, n, s, m, r, (j += 0.3), q, p]))
23752375- : (SetStyle($(k), { left: n + "px", top: s + "px" }),
23762376- Number(ESSunNum.innerHTML) !== oS.SunNum && (oS.SunNum = Math.min(Number(ESSunNum.innerHTML), oS.SunNum)),
23772377- innerText(ESSunNum, (oS.SunNum = Math.min(oS.SunNum + l.N, 9990))),
23782378- MonitorCard(),
23792379- delete ArSun[k],
23802380- oSym.addTask(20, ClearChild, [$(k)]));
23812381- })(b, c, e, i, d, h, 1, g, f);
23822382- }),
23832383- (AutoClickSun = function () {
23842384- var a;
23852385- var b;
23862386- for (b in ArSun) {
23872387- ArSun[b].C && ClickSun(b);
24362436+24372437+ // Show planting animation
24382438+ oSym.addTask(20, SetHidden, [
24392439+ SetStyle(laneType !== 2 ? $("imgGrowSoil") : $("imgGrowSpray"), {
24402440+ left: c - 30 + "px",
24412441+ top: r - 30 + "px",
24422442+ zIndex: 3 * rType + 1,
24432443+ visibility: "visible",
24442444+ }),
24452445+ ]);
24462446+24472447+ const seedPlants = [
24482448+ oSeedPeashooter,
24492449+ oSeedSnowPea,
24502450+ oSeedSquash,
24512451+ oSeedPotatoMine,
24522452+ oSeedWallNut,
24532453+ oSeedRepeater2,
24542454+ oSeedHypnoShroom,
24552455+ oSeedPuffShroom,
24562456+ oSeedPumpkinHead,
24572457+ oSeedPlantern,
24582458+ oSeedThreepeater,
24592459+ oSeedTallNut,
24602460+ oSeedTorchwood,
24612461+ oSeedLilyPad,
24622462+ oSeedCherryBomb,
24632463+ oSeedChomper,
24642464+ oSeedRepeater,
24652465+ oSeedGarlic,
24662466+ oSeedScaredyShroom,
24672467+ oSeedBlover,
24682468+ oSeedStarfruit,
24692469+ oSeedCactus,
24702470+ oSeedFumeShroom,
24712471+ oSeedDoomShroom,
24722472+ oSeedSeaShroom,
24732473+ oSeedJalapeno,
24742474+ oSeedTangleKelp,
24752475+ oSeedIceShroom,
24762476+ oSeedGloomShroom,
24772477+ ];
24782478+24792479+ if (seedPlants.includes(PlantClass)) {
24802480+ SetHidden($(card.DID));
23882481 }
23892389- }),
23902390- (ShowLargeWave = function (a) {
23912391- PlayAudio("hugewave");
23922392- NewImg("LargeWave", "images/interface/LargeWave.gif", "left:71px;top:249px;width:400px;height:200px;z-index:50", EDAll);
24822482+ }
24832483+24842484+ CancelPlant();
24852485+};
24862486+24872487+var AutoProduceSun = function (amount) {
24882488+ AppearSun(GetX(Math.floor(1 + Math.random() * oS.C)), GetY(Math.floor(1 + Math.random() * oS.R)), amount, 1);
24892489+ oSym.addTask(Math.floor(9 + Math.random() * 3) * 100, AutoProduceSun, [amount]);
24902490+};
24912491+24922492+var AppearSun = function (x, y, amount, isDrop) {
24932493+ let sizeDiff, endTop;
24942494+ const id = "Sun" + Math.random();
24952495+ let style = `cursor:url(images/interface/Pointer.cur),pointer;z-index:25;left:${x}px;`;
24962496+24972497+ switch (amount) {
24982498+ case 25:
24992499+ style += "width:78px;height:78px";
25002500+ sizeDiff = 39;
25012501+ break;
25022502+ case 15:
25032503+ style += "width:46px;height:46px";
25042504+ sizeDiff = 23;
25052505+ break;
25062506+ default:
25072507+ style += "width:100px;height:100px";
25082508+ sizeDiff = 55;
25092509+ }
25102510+25112511+ if (isDrop) {
25122512+ endTop = 0;
25132513+ oSym.addTask(10, MoveDropSun, [id, y]);
25142514+ } else {
25152515+ endTop = y - sizeDiff - 20;
25162516+ style += ";top:" + endTop + "px";
25172517+25182518+ // Parabolic arc movement for produced sun
23932519 oSym.addTask(
23942394- 4,
23952395- function (b, c, d) {
23962396- SetStyle($("LargeWave"), {
23972397- width: (b -= 57.2) + "px",
23982398- height: (c -= 6.8) + "px",
23992399- left: 500 - b * 0.5 + "px",
24002400- top: 300 - c * 0.5 + "px",
24012401- });
24022402- b > 286
24032403- ? oSym.addTask(4, arguments.callee, [b, c, d])
24042404- : (oSym.addTask(
24052405- 460,
24062406- () => {
24072407- ClearChild($("LargeWave"));
24082408- },
24092409- []
24102410- ),
24112411- d && d());
25202520+ 1,
25212521+ function (sunId, curX, curY, xStep, ySteps, dir, stepsLeft, tick) {
25222522+ if (ArSun[sunId] && ArSun[sunId].C) {
25232523+ SetStyle($(sunId), {
25242524+ left: (curX += xStep * dir) + "px",
25252525+ top: (curY += Number(ySteps[0])) + "px",
25262526+ });
25272527+ ySteps.shift();
25282528+ --stepsLeft;
25292529+ if (stepsLeft > 0) {
25302530+ if (ySteps.length === 0) ySteps = [8, 16, 24, 32];
25312531+ oSym.addTask(tick, arguments.callee, [sunId, curX, curY, xStep, ySteps, dir, stepsLeft, ++tick]);
25322532+ }
25332533+ }
24122534 },
24132413- [858, 102, a]
25352535+ [id, x, endTop, Math.floor(Math.random() * 4), [-32, -24, -16, -8], [-1, 1][Math.floor(Math.random() * 2)], 8, 2]
24142536 );
24152415- }),
24162416- (ShowFinalWave = function () {
24172417- var a = function (b) {
24182418- PlayAudio("finalwave");
24192419- NewImg("FinalWave", "images/interface/FinalWave.gif", "left:122px;top:194px;width:756px;height:213px;z-index:50", EDAll);
24202420- oSym.addTask(
24212421- 4,
24222422- function (c, e, d) {
24232423- SetStyle($("FinalWave"), {
24242424- width: (c -= 50.4) + "px",
24252425- height: (e -= 14.2) + "px",
24262426- left: 500 - c * 0.5 + "px",
24272427- top: 300 - e * 0.5 + "px",
24282428- });
24292429- c > 252
24302430- ? oSym.addTask(4, arguments.callee, [c, e, d])
24312431- : oSym.addTask(d, () => {
24322432- ClearChild($("FinalWave"));
24332433- }, []);
24342434- },
24352435- [756, 213, b]
24362436- );
24372437- };
24382438- oP.FlagNum in oS.LargeWaveFlag
24392439- ? ShowLargeWave(() => {
24402440- oSym.addTask(560, a, [150]);
24412441- })
24422442- : a(500);
24432443- }),
24442444- (ShowBOSS = function (a) {
25372537+ oSym.addTask(800, DisappearSun, [id], 3);
25382538+ }
25392539+25402540+ ArSun[id] = { id: id, N: amount, C: 1, left: x, top: endTop };
25412541+ NewImg(id, "images/interface/Sun.webp", style, EDAll, {
25422542+ onclick() {
25432543+ ClickSun(this.id);
25442544+ },
25452545+ });
25462546+25472547+ if (oS.AutoSun) oSym.addTask(100, ClickSun, [id]);
25482548+};
25492549+25502550+var MoveDropSun = function (id, targetY) {
25512551+ const sun = ArSun[id];
25522552+ if (sun && sun.C) {
25532553+ if (sun.top < targetY - 53) {
25542554+ $(id).style.top = (sun.top += 3) + "px";
25552555+ oSym.addTask(5, MoveDropSun, [id, targetY]);
25562556+ } else {
25572557+ oSym.addTask(800, DisappearSun, [id]);
25582558+ }
25592559+ }
25602560+};
25612561+25622562+var DisappearSun = function (id) {
25632563+ const sun = ArSun[id];
25642564+ if (sun && sun.C) {
25652565+ delete ArSun[id];
25662566+ ClearChild($(id));
25672567+ }
25682568+};
25692569+25702570+var ClickSun = function (id) {
25712571+ PlayAudioLegacy("points");
25722572+ const sun = ArSun[id];
25732573+ if (sun && sun.C) {
25742574+ sun.C = 0;
25752575+ oSym.addTask(0, MoveClickSun, [id]);
25762576+ }
25772577+};
25782578+25792579+var MoveClickSun = function (id) {
25802580+ const speed = 15;
25812581+ const sun = ArSun[id];
25822582+ const destX = 85;
25832583+ const destY = -20;
25842584+ const startX = sun.left;
25852585+ const startY = sun.top;
25862586+25872587+ const stepsX = Math.round((startX - destX) / speed);
25882588+ const stepsY = Math.round((startY - destY) / speed);
25892589+25902590+ (function (elId, sunData, dX, dY, curX, curY, stepRate, stepX, stepY) {
25912591+ if ((curX -= stepX) > dX) {
25922592+ SetStyle($(elId), { left: curX + "px", top: (curY -= stepY) + "px" });
25932593+ oSym.addTask(stepRate, arguments.callee, [elId, sunData, dX, dY, curX, curY, (stepRate += 0.3), stepX, stepY]);
25942594+ } else {
25952595+ SetStyle($(elId), { left: dX + "px", top: dY + "px" });
25962596+ if (Number(ESSunNum.innerHTML) !== oS.SunNum) {
25972597+ oS.SunNum = Math.min(Number(ESSunNum.innerHTML), oS.SunNum);
25982598+ }
25992599+ innerText(ESSunNum, (oS.SunNum = Math.min(oS.SunNum + sunData.N, 9990)));
26002600+ MonitorCard();
26012601+ delete ArSun[elId];
26022602+ oSym.addTask(20, ClearChild, [$(elId)]);
26032603+ }
26042604+ })(id, sun, destX, destY, startX, startY, 1, stepsX, stepsY);
26052605+};
26062606+26072607+var AutoClickSun = function () {
26082608+ for (let id in ArSun) {
26092609+ if (ArSun[id].C) ClickSun(id);
26102610+ }
26112611+};
26122612+26132613+var ShowLargeWave = function (callback) {
26142614+ PlayAudio("hugewave");
26152615+ NewImg("LargeWave", "images/interface/LargeWave.gif", "left:71px;top:249px;width:400px;height:200px;z-index:50", EDAll);
26162616+ oSym.addTask(
26172617+ 4,
26182618+ function (w, h, cb) {
26192619+ SetStyle($("LargeWave"), {
26202620+ width: (w -= 57.2) + "px",
26212621+ height: (h -= 6.8) + "px",
26222622+ left: 500 - w * 0.5 + "px",
26232623+ top: 300 - h * 0.5 + "px",
26242624+ });
26252625+ if (w > 286) {
26262626+ oSym.addTask(4, arguments.callee, [w, h, cb]);
26272627+ } else {
26282628+ oSym.addTask(460, () => ClearChild($("LargeWave")), []);
26292629+ if (cb) cb();
26302630+ }
26312631+ },
26322632+ [858, 102, callback]
26332633+ );
26342634+};
26352635+26362636+var ShowFinalWave = function () {
26372637+ const playAnim = function (delay) {
24452638 PlayAudio("finalwave");
24462446- NewImg("ShowBOSS", "images/interface/BOSSWave.gif", "left:71px;top:249px;width:858px;height:102px;z-index:50", EDAll);
26392639+ NewImg("FinalWave", "images/interface/FinalWave.gif", "left:122px;top:194px;width:756px;height:213px;z-index:50", EDAll);
24472640 oSym.addTask(
24482641 4,
24492449- function (b, c, d) {
24502450- SetStyle($("LargeWave"), {
24512451- width: (b -= 57.2) + "px",
24522452- height: (c -= 6.8) + "px",
24532453- left: 500 - b * 0.5 + "px",
24542454- top: 300 - c * 0.5 + "px",
26422642+ function (w, h, duration) {
26432643+ SetStyle($("FinalWave"), {
26442644+ width: (w -= 50.4) + "px",
26452645+ height: (h -= 14.2) + "px",
26462646+ left: 500 - w * 0.5 + "px",
26472647+ top: 300 - h * 0.5 + "px",
24552648 });
24562456- b > 286
24572457- ? oSym.addTask(4, arguments.callee, [b, c, d])
24582458- : (oSym.addTask(
24592459- 460,
24602460- () => {
24612461- ClearChild($("ShowBOSS"));
24622462- },
24632463- []
24642464- ),
24652465- d && d());
26492649+ if (w > 252) {
26502650+ oSym.addTask(4, arguments.callee, [w, h, duration]);
26512651+ } else {
26522652+ oSym.addTask(duration, () => ClearChild($("FinalWave")), []);
26532653+ }
24662654 },
24672467- [858, 102, a]
26552655+ [756, 213, delay]
24682656 );
24692469- }),
24702470- (GameOver = function () {
24712471- PlayAudio("scream");
24722472- NewImg("iGameOver", "images/interface/ZombiesWon.webp", "width:900px;height:600px;z-index:255", EDAll, {
24732473- onclick() {
24742474- SelectModal(oS.Lvl);
24752475- },
24762476- });
24772477- oSym.Stop();
24782478- }),
24792479- (GameOverZombies = function (c, a) {
24802480- var b = oSym;
24812481- StopMusic();
24822482- PlayAudioLegacy("losemusic");
24832483- b.Stop();
24842484- //innerText(c, "Speed");
24852485- SetBlock($("dSurface"), $("dZombieFail"));
24862486- oSym.Stop();
24872487- }),
24882488- (PrepareGrowPlants = function (a) {
24892489- var b = function () {
24902490- PlayAudio("readysetplant");
24912491- oSym.addTask(
24922492- 60,
24932493- (d, c) => {
24942494- var e = d.style;
24952495- e.backgroundPosition = "0 -108px";
24962496- oSym.addTask(
24972497- 40,
24982498- (g, h, f) => {
24992499- h.backgroundPosition = "0 -216px";
25002500- oSym.addTask(
25012501- 100,
25022502- (j, i) => {
25032503- ClearChild(j);
25042504- i();
25052505- },
25062506- [g, f]
25072507- );
25082508- },
25092509- [d, e, c]
25102510- );
25112511- },
25122512- [
25132513- NewEle(
25142514- 0,
25152515- "div",
25162516- "position:absolute;overflow:hidden;background:url(images/interface/PrepareGrowPlants.png) no-repeat;width:255px;height:108px;z-index:50;left:" +
25172517- (oS.W * 0.5 - 77) +
25182518- "px;top:" +
25192519- (oS.H * 0.5 - 54) +
25202520- "px",
25212521- 0,
25222522- EDAll
25232523- ),
25242524- a,
25252525- ]
25262526- );
25272527- };
25282528- oS.HaveFog ? oGd.MoveFogLeft(b) : b();
25292529- }),
25302530- (CustomPlants = function (b, a, c) {
25312531- new ArCard[b].PName().Birth(GetX(c), GetY(a), a, c, []);
25322532- }),
25332533- (CustomSpecial = function (c, b, d, a) {
25342534- let plant = new c();
25352535- plant.Birth(GetX(d), GetY(b), b, d, [], a);
25362536- return plant;
25372537- }),
25382538- (CheckAutoSun = function (a) {
25392539- PlayAudio("buttonclick");
25402540- var b = a.checked ? 1 : 0;
25412541- if (b !== oS.AutoSun) {
25422542- oS.AutoSun = b;
25432543- localStorage.setItem("JSPVZAutoSun", b);
25442544- if (b) {
25452545- AutoClickSun();
26572657+ };
26582658+26592659+ oP.FlagNum in oS.LargeWaveFlag ? ShowLargeWave(() => oSym.addTask(560, playAnim, [150])) : playAnim(500);
26602660+};
26612661+26622662+var ShowBOSS = function (callback) {
26632663+ PlayAudio("finalwave");
26642664+ NewImg("ShowBOSS", "images/interface/BOSSWave.gif", "left:71px;top:249px;width:858px;height:102px;z-index:50", EDAll);
26652665+ oSym.addTask(
26662666+ 4,
26672667+ function (w, h, cb) {
26682668+ SetStyle($("LargeWave"), {
26692669+ width: (w -= 57.2) + "px",
26702670+ height: (h -= 6.8) + "px",
26712671+ left: 500 - w * 0.5 + "px",
26722672+ top: 300 - h * 0.5 + "px",
26732673+ });
26742674+ if (w > 286) {
26752675+ oSym.addTask(4, arguments.callee, [w, h, cb]);
26762676+ } else {
26772677+ oSym.addTask(460, () => ClearChild($("ShowBOSS")), []);
26782678+ if (cb) cb();
25462679 }
25472547- }
26802680+ },
26812681+ [858, 102, callback]
26822682+ );
26832683+};
26842684+26852685+var GameOver = function () {
26862686+ PlayAudio("scream");
26872687+ NewImg("iGameOver", "images/interface/ZombiesWon.webp", "width:900px;height:600px;z-index:255", EDAll, {
26882688+ onclick() {
26892689+ SelectModal(oS.Lvl);
26902690+ },
25482691 });
26922692+ oSym.Stop();
26932693+};
2549269425502550-(GetNewCard = function (a, b, c) {
26952695+var GameOverZombies = function (c, a) {
26962696+ StopMusic();
26972697+ PlayAudioLegacy("losemusic");
26982698+ oSym.Stop();
26992699+ SetBlock($("dSurface"), $("dZombieFail"));
27002700+ oSym.Stop();
27012701+};
27022702+27032703+var PrepareGrowPlants = function (callback) {
27042704+ const run = function () {
27052705+ PlayAudio("readysetplant");
27062706+ oSym.addTask(
27072707+ 60,
27082708+ (ele, cb) => {
27092709+ const style = ele.style;
27102710+ style.backgroundPosition = "0 -108px";
27112711+ oSym.addTask(
27122712+ 40,
27132713+ (e, s, c) => {
27142714+ s.backgroundPosition = "0 -216px";
27152715+ oSym.addTask(
27162716+ 100,
27172717+ (el, call) => {
27182718+ ClearChild(el);
27192719+ call();
27202720+ },
27212721+ [e, c]
27222722+ );
27232723+ },
27242724+ [ele, style, cb]
27252725+ );
27262726+ },
27272727+ [
27282728+ NewEle(
27292729+ 0,
27302730+ "div",
27312731+ `position:absolute;overflow:hidden;background:url(images/interface/PrepareGrowPlants.png) no-repeat;width:255px;height:108px;z-index:50;left:${oS.W * 0.5 - 77}px;top:${oS.H * 0.5 - 54}px`,
27322732+ 0,
27332733+ EDAll
27342734+ ),
27352735+ callback,
27362736+ ]
27372737+ );
27382738+ };
27392739+ oS.HaveFog ? oGd.MoveFogLeft(run) : run();
27402740+};
27412741+27422742+var CustomPlants = function (idx, c, r) {
27432743+ new ArCard[idx].PName().Birth(GetX(r), GetY(c), c, r, []);
27442744+};
27452745+27462746+var CustomSpecial = function (Class, r, c, args) {
27472747+ let plant = new Class();
27482748+ plant.Birth(GetX(c), GetY(r), r, c, [], args);
27492749+ return plant;
27502750+};
27512751+27522752+var CheckAutoSun = function (checkbox) {
27532753+ PlayAudio("buttonclick");
27542754+ const val = checkbox.checked ? 1 : 0;
27552755+ if (val !== oS.AutoSun) {
27562756+ oS.AutoSun = val;
27572757+ localStorage.setItem("JSPVZAutoSun", val);
27582758+ if (val) AutoClickSun();
27592759+ }
27602760+};
27612761+27622762+var GetNewCard = function (ele, plantClass, nextLvl) {
25512763 StopMusic();
25522764 PlayAudioLegacy("winmusic");
25532765 oSym.Clear();
25542554- SetStyle(a, {
27662766+ SetStyle(ele, {
25552767 left: "350px",
25562768 top: "131px",
25572769 width: "200px",
···25592771 clip: "rect(0,auto,120px,0)",
25602772 cursor: "url(images/interface/Cursor.cur),default",
25612773 }).onclick = null;
27742774+25622775 oSym.Init(
25632563- function (d, e) {
25642564- ++d < 100
25652565- ? (SetAlpha(e, d, d * 0.01), oSym.addTask(4, arguments.callee, [d, e]))
25662566- : (function () {
25672567- StopAudio("winmusic");
25682568- PlayAudio("plantsgarden", true);
25692569- SetHidden(EDAll, $("dTop"));
25702570- var f = b.prototype;
25712571- $("iNewPlantCard").src = f.PicArr[f.CardGif];
25722572- $("iNewPlantCard").style.width = 100 + "px";
25732573- $("iNewPlantCard").style.height = 120 + "px";
25742574- // $("iNewPlantCard").style.marginTop =
25752575- // 180 - f.height + "px";
25762576- innerText($("dNewPlantName"), f.CName);
25772577- $("dNewPlantTooltip").innerHTML = f.Tooltip;
25782578- $("btnNextLevel").onclick = function () {
25792579- StopAudio("plantsgarden");
25802580- SetHidden($("bMainMenu"));
25812581- SelectModal(c);
25822582- };
25832583- SetStyle($("dNewPlant"), {
25842584- visibility: "visible",
25852585- zIndex: 255,
25862586- });
25872587- SetVisible($("bMainMenu"));
25882588- })();
27762776+ function (opacity, element) {
27772777+ if (++opacity < 100) {
27782778+ SetAlpha(element, opacity, opacity * 0.01);
27792779+ oSym.addTask(4, arguments.callee, [opacity, element]);
27802780+ } else {
27812781+ StopAudio("winmusic");
27822782+ PlayAudio("plantsgarden", true);
27832783+ SetHidden(EDAll, $("dTop"));
27842784+27852785+ const proto = plantClass.prototype;
27862786+ $("iNewPlantCard").src = proto.PicArr[proto.CardGif];
27872787+ $("iNewPlantCard").style.width = "100px";
27882788+ $("iNewPlantCard").style.height = "120px";
27892789+ innerText($("dNewPlantName"), proto.CName);
27902790+ $("dNewPlantTooltip").innerHTML = proto.Tooltip;
27912791+27922792+ $("btnNextLevel").onclick = function () {
27932793+ StopAudio("plantsgarden");
27942794+ SetHidden($("bMainMenu"));
27952795+ SelectModal(nextLvl);
27962796+ };
27972797+27982798+ SetStyle($("dNewPlant"), {
27992799+ visibility: "visible",
28002800+ zIndex: 255,
28012801+ });
28022802+ SetVisible($("bMainMenu"));
28032803+ }
25892804 },
25902805 [0, $("DivA")]
25912806 );
25922592-}),
25932593- (getCookie1 = function (b, g) {
25942594- var d = document.cookie;
25952595- var f = d.split(";");
25962596- var c = f.length;
25972597- var a;
25982598- var e;
25992599- var h;
26002600- while (c--) {
26012601- h = (a = f[c]).split("=");
26022602- if (h[0].replace(" ", "") === b) {
26032603- if ((e = h.length) === 2) {
26042604- return unescape(h[1]);
26052605- }
26062606- h.shift();
26072607- h = h.join("=").split("&");
26082608- if (g === undefined) {
26092609- return unescape(h);
26102610- }
26112611- e = h.length;
26122612- while (e--) {
26132613- if ((a = h[e].split("="))[0].replace(" ", "") === g) {
26142614- return unescape(a[1]);
26152615- }
26162616- }
28072807+};
28082808+28092809+var getCookie1 = function (key, subKey) {
28102810+ const cookie = document.cookie;
28112811+ const list = cookie.split(";");
28122812+ let i = list.length;
28132813+28142814+ while (i--) {
28152815+ let entry = list[i].split("=");
28162816+ if (entry[0].replace(" ", "") === key) {
28172817+ if (entry.length === 2) return unescape(entry[1]);
28182818+28192819+ entry.shift();
28202820+ let subEntries = entry.join("=").split("&");
28212821+ if (subKey === undefined) return unescape(subEntries);
28222822+28232823+ let j = subEntries.length;
28242824+ while (j--) {
28252825+ let sub = subEntries[j].split("=");
28262826+ if (sub[0].replace(" ", "") === subKey) return unescape(sub[1]);
26172827 }
26182828 }
26192619- return 0;
26202620- }),
26212621- (getCookie = function (b) {
26222622- var a = document.cookie.match(new RegExp("(^| )" + b + "=([^;]*)(;|$)"));
26232623- if (a != null) {
26242624- return unescape(a[2]);
26252625- }
26262626- return 0;
26272627- }),
26282628- (addCookie = function (b, d, e) {
26292629- var c = b + "=" + escape(d);
26302630- if (e) {
26312631- var a = new Date();
26322632- a.setTime(a.getTime + e * 3600 * 1e3);
26332633- c += ";expire=" + a.toGMTString();
26342634- }
26352635- document.cookie = c;
26362636- }),
26372637- (deleteCookie = function (a) {
26382638- document.cookie = a + "=0;";
26392639- }),
26402640- (WordUTF8 =
26412641- '<div id="dLogo" style="position:absolute;width:900px;height:600px;z-index:1"><span id="commit" style="position: absolute;color: #ffffff0f;bottom: 0;user-select: none;"></span><div id="LogoWord" style="position:absolute;color:#FF0;top:300px;width:100%;height:100px"><span style="position:absolute;width:305px;height:150px;left:285px;top:5px;cursor:url(images/interface/Pointer.cur),pointer" onclick="PlayAudio(\'gravebutton\');SetBlock($(\'dSurface\'),$(\'iSurfaceBackground\'));ShowNameDiv();sa_event(\'clickstart0js\')"></span><div style="position:absolute;font-size:14px;left:660px;text-align:center;width:140px;top:185px;line-height:1.5;font-weight:bold"><span style="cursor:url(images/interface/Pointer.cur),pointer"><span id="" style=""></span></span></div></div><div style="position:absolute;width:74px;height:41px;left:807px;top:502px;cursor:url(images/interface/Pointer.cur),pointer;z-index:300" onclick="SetVisible($(\'dProcess\'))"></div><img src="" style="position:absolute;left:550px;top:-40px"></div>');
28292829+ }
28302830+ return 0;
28312831+};
28322832+28332833+var getCookie = function (key) {
28342834+ const match = document.cookie.match(new RegExp("(^| )" + key + "=([^;]*)(;|$)"));
28352835+ if (match != null) return unescape(match[2]);
28362836+ return 0;
28372837+};
28382838+28392839+var addCookie = function (key, val, expireHours) {
28402840+ let str = key + "=" + escape(val);
28412841+ if (expireHours) {
28422842+ const date = new Date();
28432843+ date.setTime(date.getTime + expireHours * 3600 * 1e3);
28442844+ str += ";expire=" + date.toGMTString();
28452845+ }
28462846+ document.cookie = str;
28472847+};
28482848+28492849+var deleteCookie = function (key) {
28502850+ document.cookie = key + "=0;";
28512851+};
28522852+28532853+var WordUTF8 = `<div id="dLogo" style="position:absolute;width:900px;height:600px;z-index:1"><span id="commit" style="position: absolute;color: #ffffff0f;bottom: 0;user-select: none;"></span><div id="LogoWord" style="position:absolute;color:#FF0;top:300px;width:100%;height:100px"><span style="position:absolute;width:305px;height:150px;left:285px;top:5px;cursor:url(images/interface/Pointer.cur),pointer" onclick="PlayAudio('gravebutton');SetBlock($('dSurface'),$('iSurfaceBackground'));ShowNameDiv();"></span><div style="position:absolute;font-size:14px;left:660px;text-align:center;width:140px;top:185px;line-height:1.5;font-weight:bold"><span style="cursor:url(images/interface/Pointer.cur),pointer"><span id="" style=""></span></span></div></div><div style="position:absolute;width:74px;height:41px;left:807px;top:502px;cursor:url(images/interface/Pointer.cur),pointer;z-index:300" onclick="SetVisible($('dProcess'))"></div><img src="" style="position:absolute;left:550px;top:-40px"></div>`;
2642285426432643-(ShowNameDiv = function () {
28552855+var ShowNameDiv = function () {
26442856 oSym.Start();
26452645- (function (c) {
26462646- var b = c[0];
26472647- var d = 3;
26482648- c.shift();
26492649- while (d--) {
26502650- SetStyle(($("dNameDiv" + d).style.top = b[d] + "px"));
28572857+ (function (config) {
28582858+ let item = config[0];
28592859+ let i = 3;
28602860+ config.shift();
28612861+ while (i--) {
28622862+ SetStyle(($("dNameDiv" + i).style.top = item[i] + "px"));
26512863 }
26522652- c.length && oSym.addTask(b[3], arguments.callee, [c]);
28642864+ if (config.length) oSym.addTask(item[3], arguments.callee, [config]);
26532865 })([
26542866 [-260, 96, 136, 10],
26552867 [-94, 96, 136, 10],
···26592871 [-8, 136, 189, 17],
26602872 [-8, 134, 187, 10],
26612873 ]);
26622662-}),
26632663- (ShowLoginDiv = function () {
26642664- $User.isAuthorWebsite ? PlayAudio("tap") : GotoAuthorWebsite("");
26652665- }),
26662666- (CheckLogin = function () {
26672667- var c = $("txtName").value;
26682668- var e = $("txtPass").value;
26692669- var a = /^\w{3,10}$/;
26702670- var b = /^[\u4e00-\u9fa5\w]{3,10}$/;
26712671- var d = /^\w{3,20}$/;
26722672- return !!((a.exec(c) || b.exec(c)) && d.exec(e));
26732673- }),
26742674- (SelectModal = function (g) {
26752675- HiddenLevel();
26762676- HiddenMiniGame(1);
26772677- HiddenRiddleGame(1);
26782678- StopMusic();
26792679- PausedAudioArr = [];
26802680- g === undefined && (g = $User.Visitor.Progress);
26812681- oS.LvlClearFunc && oS.LvlClearFunc();
26822682- var b = oS.GlobalVariables;
26832683- var c = oS.LvlVariables;
26842684- var e = oS.SelfVariables;
26852685- var a = window;
26862686- var d;
26872687- for (d in b) {
26882688- a[d] = b[d];
26892689- }
26902690- for (d in c) {
26912691- a[d] = null;
26922692- }
26932693- for (d = e.length; d--; delete oS[e[d]]) {}
26942694- for (d in $Pn) {
26952695- $Pn[d] = null;
26962696- }
26972697- oS.GlobalVariables = {};
26982698- oS.LvlVariables = {};
26992699- oS.SelfVariables.length = 0;
27002700- SetHidden($("dCardList"), $("tGround"), $("dSelectCard"), $("dTop"), $("dMenu"), $("dHandBook"), $("dNewPlant"), $("dProcess"));
27012701- SetNone($("dSurface"), $("iSurfaceBackground"));
27022702- ClearChild($("dFlagMeterTitleB").firstChild);
27032703- EDAll = $("dBody").replaceChild(EDNewAll, EDAll);
27042704- $("dBody").replaceChild(EDNewFlagMeter, $("dFlagMeter"));
27052705- LoadLvl(g);
27062706- }),
27072707- (GotoAuthorWebsite = function () {
27082708- window.open("https://github.com/ROBlNET13/pvz");
27092709- }),
27102710- (InitGame = function () {
27112711- var e = NewEle(
27122712- "dServer",
27132713- "div",
27142714- "position:absolute;line-height:28px;left:706px;top:245px;width:700px;height:100px;font-size:16px;color:#040;font-family:Tahoma;font-weight:bold;z-index:2;display:none",
27152715- 0,
27162716- $("dAll")
28742874+};
28752875+28762876+var ShowLoginDiv = function () {
28772877+ $User.isAuthorWebsite ? PlayAudio("tap") : GotoAuthorWebsite("");
28782878+};
28792879+28802880+var CheckLogin = function () {
28812881+ const user = $("txtName").value;
28822882+ const pass = $("txtPass").value;
28832883+ const regUser1 = /^\w{3,10}$/;
28842884+ const regUser2 = /^[\u4e00-\u9fa5\w]{3,10}$/;
28852885+ const regPass = /^\w{3,20}$/;
28862886+ return !!((regUser1.exec(user) || regUser2.exec(user)) && regPass.exec(pass));
28872887+};
28882888+28892889+var SelectModal = function (level) {
28902890+ HiddenLevel();
28912891+ HiddenMiniGame(1);
28922892+ HiddenRiddleGame(1);
28932893+ StopMusic();
28942894+ PausedAudioArr = [];
28952895+28962896+ if (level === undefined) level = $User.Visitor.Progress;
28972897+ if (oS.LvlClearFunc) oS.LvlClearFunc();
28982898+ // check if loadedMenus exists - if it does, clear it
28992899+ if (window.loadedMenus) {
29002900+ window.loadedMenus.length = 0;
29012901+ }
29022902+29032903+ const globals = oS.GlobalVariables;
29042904+ const lvls = oS.LvlVariables;
29052905+ const selfs = oS.SelfVariables;
29062906+ const win = window;
29072907+29082908+ for (let key in globals) win[key] = globals[key];
29092909+ for (let key in lvls) win[key] = null;
29102910+ let i = selfs.length;
29112911+ while (i--) delete oS[selfs[i]];
29122912+ for (let key in $Pn) $Pn[key] = null;
29132913+29142914+ oS.GlobalVariables = {};
29152915+ oS.LvlVariables = {};
29162916+ oS.SelfVariables.length = 0;
29172917+29182918+ SetHidden($("dCardList"), $("tGround"), $("dSelectCard"), $("dTop"), $("dMenu"), $("dHandBook"), $("dNewPlant"), $("dProcess"));
29192919+ SetNone($("dSurface"), $("iSurfaceBackground"));
29202920+ ClearChild($("dFlagMeterTitleB").firstChild);
29212921+29222922+ EDAll = $("dBody").replaceChild(EDNewAll, EDAll);
29232923+ $("dBody").replaceChild(EDNewFlagMeter, $("dFlagMeter"));
29242924+ LoadLvl(level);
29252925+};
29262926+29272927+var GotoAuthorWebsite = function () {
29282928+ window.open("https://github.com/ROBlNET13/pvz");
29292929+};
29302930+29312931+var InitGame = function () {
29322932+ const serverDiv = NewEle(
29332933+ "dServer",
29342934+ "div",
29352935+ "position:absolute;line-height:28px;left:706px;top:245px;width:700px;height:100px;font-size:16px;color:#040;font-family:Tahoma;font-weight:bold;z-index:2;display:none",
29362936+ 0,
29372937+ $("dAll")
29382938+ );
29392939+ const procDiv = $("dProcess");
29402940+29412941+ if (!$("dText1")) {
29422942+ procDiv.insertBefore(
29432943+ NewEle(
29442944+ "dText1",
29452945+ "div",
29462946+ 0,
29472947+ {
29482948+ innerHTML: atob(
29492949+ "PHNwYW4gc3R5bGU9ImZvbnQtZmFtaWx5OnNhbnMtc2VyaWY7Y29sb3I6I2JiYjt3aWR0aDo4NSU7ZGlzcGxheTpibG9jazttYXJnaW46MTVweCBhdXRvIDAgYXV0byI+PHNwYW4gc3R5bGU9ImNvbG9yOiNmNjA7Ij5XZWxjb21lIHRvIFBsYW50cyB2cy4gWm9tYmllczogTU9EREVEPGJyPjwvc3Bhbj48c3BhbiBzdHlsZT0iY29sb3I6I2VlZTsiPlBsYW50cyB2cy4gWm9tYmllcyBNT0RERUQgJmNvcHk7IDIwMjUgYnkgUk9CbE5FVDEzIGlzIGxpY2Vuc2VkIHVuZGVyIDxhIGhyZWY9Imh0dHBzOi8vY3JlYXRpdmVjb21tb25zLm9yZy9saWNlbnNlcy9ieS1uYy1uZC80LjAvZGVlZC5lbiI+Q0MgQlktTkMtTkQgNC4wPC9hPi4gVGhpcyBsaWNlbnNlIGFwcGxpZXMgb25seSB0byBvcmlnaW5hbCBjb2RlL2NvbnRlbnQgY3JlYXRlZCBieSB0aGUgbW9kZGluZyB0ZWFtLiBBbGwgUGxhbnRzIHZzLiBab21iaWVzIGludGVsbGVjdHVhbCBwcm9wZXJ0eSByZW1haW5zIHRoZSBleGNsdXNpdmUgcHJvcGVydHkgb2YgUG9wQ2FwIEdhbWVzIGFuZCBFbGVjdHJvbmljIEFydHMgKEVBKS48L3NwYW4+PGJyPjxicj5QbGFudHMgdnMuIFpvbWJpZXMgTU9EREVEIGlzIGFuIHVub2ZmaWNpYWwgbW9kaWZpY2F0aW9uIGFuZCBpcyBub3QgYWZmaWxpYXRlZCB3aXRoLCBlbmRvcnNlZCBieSwgb3IgYXNzb2NpYXRlZCB3aXRoIFBvcENhcCBHYW1lcywgRWxlY3Ryb25pYyBBcnRzIChFQSksIG9yIHRoZSBvZmZpY2lhbCBQbGFudHMgdnMuIFpvbWJpZXMgZ2FtZS4gQWxsIGludGVsbGVjdHVhbCBwcm9wZXJ0eSwgdHJhZGVtYXJrcywgYW5kIGNvcHlyaWdodHMgcmVsYXRlZCB0byB0aGUgb3JpZ2luYWwgUGxhbnRzIHZzLiBab21iaWVzIGdhbWUgYXJlIHRoZSBwcm9wZXJ0eSBvZiBQb3BDYXAgR2FtZXMgYW5kIEVBLiBBbGwgY29kZSBpbiB0aGlzIGZhbmdhbWUgaXMgb3JpZ2luYWwsIGJhc2VkIG9uIGEgUHZaIHdlYmdhbWUgb3JpZ2luYWxseSBjcmVhdGVkIGJ5IEppYW5nTmFuIEdhbWUgRGV2ZWxvcG1lbnQgQ29tcGFueSBhbmQgTG9uZWx5U3Rhci4gVGhpcyBtb2QgZG9lcyBub3QgdXNlIGFueSBjb2RlIHdyaXR0ZW4gb3Igb3duZWQgYnkgUG9wQ2FwIEdhbWVzIG9yIEVBLiBUaGlzIG1vZCBpcyBjcmVhdGVkIGJ5IGZhbnMgZm9yIGVudGVydGFpbm1lbnQgcHVycG9zZXMgb25seSwgYW5kIG5vIGNvbW1lcmNpYWwgZ2FpbiBpcyBzb3VnaHQgb3Igb2J0YWluZWQgZnJvbSBpdHMgZGlzdHJpYnV0aW9uLiBVc2Ugb2YgdGhpcyBtb2QgaXMgYXQgeW91ciBvd24gcmlzaywgYW5kIHRoZSBjcmVhdG9ycyBvZiB0aGUgbW9kIGFyZSBub3QgbGlhYmxlIGZvciBhbnkgZGFtYWdlcyBvciBpc3N1ZXMgdGhhdCBtYXkgYXJpc2UgZnJvbSBpdHMgdXNlLjxicj48YnI+VXNlcyBvZiB0aGUgUG9wQ2FwIEdhbWVzIG9yIEVsZWN0cm9uaWMgQXJ0cyAoRUEpIG5hbWVzIGFyZSBmb3IgaWRlbnRpZmljYXRpb24gcHVycG9zZXMgb25seSBhbmQgZG8gbm90IGltcGx5IGFuIGVuZG9yc2VtZW50IGJ5IFBvcENhcCBHYW1lcyBvciBFQS48YnI+PGJyPjx1PkRvIG5vdCByZW1vdmUgdGhpcyB3YXJuaW5nLjwvdT4gRG9pbmcgc28gPHNwYW4gc3R5bGU9ImNvbG9yOnJlZCI+dmlvbGF0ZXM8L3NwYW4+IHRoZSB0ZXJtcyBvZiB0aGUgbGVnYWxseS1iaW5kaW5nIENyZWF0aXZlIENvbW1vbnMgTGljZW5zZSwgaWYgb3JpZ2luYWwgY29kZS9jb250ZW50IGNyZWF0ZWQgYnkgdGhlIG1vZGRpbmcgdGVhbSBpcyBpbmNsdWRlZC48YnI+PGJyPjxiPklmIHJlcXVlc3RlZCBieSBhbiBvZmZpY2lhbCBzb3VyY2UsIHdlIHdpbGwgcHJvbXB0bHkgdGFrZSBkb3duIHRoaXMgZmFuIGdhbWUgYW5kIHRoZSBhc3NvY2lhdGVkIEdpdEh1YiByZXBvLiBZb3UgbWF5IGNvbnRhY3QgdXMgdXNpbmcgdGhlIGVtYWlsIGxpc3RlZCBvbiA8YSBocmVmPSJodHRwczovL2dpdGh1Yi5jb20vUk9CbE5FVDEzL3B2ei9ibG9iL21haW4vUkVBRE1FLm1kI2xlZ2FsLWluZm8iPmh0dHBzOi8vZ2l0aHViLmNvbS9ST0JsTkVUMTMvcHZ6L2Jsb2IvbWFpbi9SRUFETUUubWQjbGVnYWwtaW5mbzwvYT4uPC9iPjwvc3Bhbj4="
29502950+ ),
29512951+ },
29522952+ 0
29532953+ ),
29542954+ procDiv.firstChild
27172955 );
27182718- var c = $User.Server;
27192719- var b = c.List;
27202720- var a = $("dProcess");
27212721- var floor = oS.B;
27222722- !$("dText1") &&
27232723- a.insertBefore(
27242724- NewEle(
27252725- "dText1",
27262726- "div",
27272727- 0,
27282728- {
27292729- innerHTML: floor(
27302730- "PHNwYW4gc3R5bGU9ImZvbnQtZmFtaWx5OnNhbnMtc2VyaWY7Y29sb3I6I2JiYjt3aWR0aDo4NSU7ZGlzcGxheTpibG9jazttYXJnaW46MTVweCBhdXRvIDAgYXV0byI+PHNwYW4gc3R5bGU9ImNvbG9yOiNmNjA7Ij5XZWxjb21lIHRvIFBsYW50cyB2cy4gWm9tYmllczogTU9EREVEPGJyPjwvc3Bhbj48c3BhbiBzdHlsZT0iY29sb3I6I2VlZTsiPlBsYW50cyB2cy4gWm9tYmllcyBNT0RERUQgJmNvcHk7IDIwMjUgYnkgUk9CbE5FVDEzIGlzIGxpY2Vuc2VkIHVuZGVyIDxhIGhyZWY9Imh0dHBzOi8vY3JlYXRpdmVjb21tb25zLm9yZy9saWNlbnNlcy9ieS1uYy1uZC80LjAvZGVlZC5lbiI+Q0MgQlktTkMtTkQgNC4wPC9hPi4gVGhpcyBsaWNlbnNlIGFwcGxpZXMgb25seSB0byBvcmlnaW5hbCBjb2RlL2NvbnRlbnQgY3JlYXRlZCBieSB0aGUgbW9kZGluZyB0ZWFtLiBBbGwgUGxhbnRzIHZzLiBab21iaWVzIGludGVsbGVjdHVhbCBwcm9wZXJ0eSByZW1haW5zIHRoZSBleGNsdXNpdmUgcHJvcGVydHkgb2YgUG9wQ2FwIEdhbWVzIGFuZCBFbGVjdHJvbmljIEFydHMgKEVBKS48L3NwYW4+PGJyPjxicj5QbGFudHMgdnMuIFpvbWJpZXMgTU9EREVEIGlzIGFuIHVub2ZmaWNpYWwgbW9kaWZpY2F0aW9uIGFuZCBpcyBub3QgYWZmaWxpYXRlZCB3aXRoLCBlbmRvcnNlZCBieSwgb3IgYXNzb2NpYXRlZCB3aXRoIFBvcENhcCBHYW1lcywgRWxlY3Ryb25pYyBBcnRzIChFQSksIG9yIHRoZSBvZmZpY2lhbCBQbGFudHMgdnMuIFpvbWJpZXMgZ2FtZS4gQWxsIGludGVsbGVjdHVhbCBwcm9wZXJ0eSwgdHJhZGVtYXJrcywgYW5kIGNvcHlyaWdodHMgcmVsYXRlZCB0byB0aGUgb3JpZ2luYWwgUGxhbnRzIHZzLiBab21iaWVzIGdhbWUgYXJlIHRoZSBwcm9wZXJ0eSBvZiBQb3BDYXAgR2FtZXMgYW5kIEVBLiBBbGwgY29kZSBpbiB0aGlzIGZhbmdhbWUgaXMgb3JpZ2luYWwsIGJhc2VkIG9uIGEgUHZaIHdlYmdhbWUgb3JpZ2luYWxseSBjcmVhdGVkIGJ5IEppYW5nTmFuIEdhbWUgRGV2ZWxvcG1lbnQgQ29tcGFueSBhbmQgTG9uZWx5U3Rhci4gVGhpcyBtb2QgZG9lcyBub3QgdXNlIGFueSBjb2RlIHdyaXR0ZW4gb3Igb3duZWQgYnkgUG9wQ2FwIEdhbWVzIG9yIEVBLiBUaGlzIG1vZCBpcyBjcmVhdGVkIGJ5IGZhbnMgZm9yIGVudGVydGFpbm1lbnQgcHVycG9zZXMgb25seSwgYW5kIG5vIGNvbW1lcmNpYWwgZ2FpbiBpcyBzb3VnaHQgb3Igb2J0YWluZWQgZnJvbSBpdHMgZGlzdHJpYnV0aW9uLiBVc2Ugb2YgdGhpcyBtb2QgaXMgYXQgeW91ciBvd24gcmlzaywgYW5kIHRoZSBjcmVhdG9ycyBvZiB0aGUgbW9kIGFyZSBub3QgbGlhYmxlIGZvciBhbnkgZGFtYWdlcyBvciBpc3N1ZXMgdGhhdCBtYXkgYXJpc2UgZnJvbSBpdHMgdXNlLjxicj48YnI+VXNlcyBvZiB0aGUgUG9wQ2FwIEdhbWVzIG9yIEVsZWN0cm9uaWMgQXJ0cyAoRUEpIG5hbWVzIGFyZSBmb3IgaWRlbnRpZmljYXRpb24gcHVycG9zZXMgb25seSBhbmQgZG8gbm90IGltcGx5IGFuIGVuZG9yc2VtZW50IGJ5IFBvcENhcCBHYW1lcyBvciBFQS48YnI+PGJyPjx1PkRvIG5vdCByZW1vdmUgdGhpcyB3YXJuaW5nLjwvdT4gRG9pbmcgc28gPHNwYW4gc3R5bGU9ImNvbG9yOnJlZCI+dmlvbGF0ZXM8L3NwYW4+IHRoZSB0ZXJtcyBvZiB0aGUgbGVnYWxseS1iaW5kaW5nIENyZWF0aXZlIENvbW1vbnMgTGljZW5zZSwgaWYgb3JpZ2luYWwgY29kZS9jb250ZW50IGNyZWF0ZWQgYnkgdGhlIG1vZGRpbmcgdGVhbSBpcyBpbmNsdWRlZC48YnI+PGJyPjxiPklmIHJlcXVlc3RlZCBieSBhbiBvZmZpY2lhbCBzb3VyY2UsIHdlIHdpbGwgcHJvbXB0bHkgdGFrZSBkb3duIHRoaXMgZmFuIGdhbWUgYW5kIHRoZSBhc3NvY2lhdGVkIEdpdEh1YiByZXBvLiBZb3UgbWF5IGNvbnRhY3QgdXMgdXNpbmcgdGhlIGVtYWlsIGxpc3RlZCBvbiA8YSBocmVmPSJodHRwczovL2dpdGh1Yi5jb20vUk9CbE5FVDEzL3B2ei9ibG9iL21haW4vUkVBRE1FLm1kI2xlZ2FsLWluZm8iPmh0dHBzOi8vZ2l0aHViLmNvbS9ST0JsTkVUMTMvcHZ6L2Jsb2IvbWFpbi9SRUFETUUubWQjbGVnYWwtaW5mbzwvYT4uPC9iPjwvc3Bhbj4="
27312731- ),
27322732- },
27332733- 0
27342734- ),
27352735- a.firstChild
29562956+ }
29572957+ LoadLvl();
29582958+ // check if izl_id query parameter exists
29592959+ const urlParams = new URLSearchParams(window.location.search);
29602960+ const izlId = urlParams.get("izl_id");
29612961+ if (izlId) {
29622962+ setTimeout(() => {
29632963+ fetch(`${$User.Server.URL}/api/levels/${izlId}/download`, {
29642964+ method: "GET",
29652965+ })
29662966+ .then((response) => response.arrayBuffer())
29672967+ .then(async (arrayBuffer) => {
29682968+ // load the level
29692969+ const levelData = await fileToLevelData(arrayBuffer);
29702970+ console.log(levelData);
29712971+ levelDataToLoad = levelData[0] === "=" ? parseCloneTiny_OLD(levelData) : parseCloneTiny(levelData);
29722972+ // load the izombiecustomlevel level
29732973+ if (levelDataToLoad.lfValue[3] === 2) {
29742974+ SelectModal("izombiecustomlevelwater");
29752975+ } else {
29762976+ SelectModal("izombiecustomlevelnormal");
29772977+ }
29782978+ })
29792979+ .catch((e) => {
29802980+ console.error(e);
29812981+ alert("There was an error loading the level. Please try again later.");
29822982+ LoadLvl();
29832983+ });
29842984+ }, 0);
29852985+ }
29862986+};
29872987+29882988+var LoadLvl = function (level, startTime) {
29892989+ if (oSym.Timer) oSym.Stop();
29902990+ const isReplay = oSym.Now === startTime;
29912991+ const user = $User;
29922992+29932993+ if (oS.CenterContent && ((level === 0 && isReplay) || level !== 0)) {
29942994+ oS.DisplayAD = true;
29952995+ }
29962996+29972997+ level = level || 0;
29982998+ if ($("dServer") && level !== 0) SetNone($("dServer"));
29992999+30003000+ oSym.Init(
30013001+ (lvl) => {
30023002+ const script = $("JSPVZ");
30033003+ if (script) ClearChild(script);
30043004+ NewEle(
30053005+ "JSPVZ",
30063006+ "script",
30073007+ 0,
30083008+ {
30093009+ src: "level/" + (oS.Lvl = lvl) + ".js",
30103010+ type: "text/javascript",
30113011+ },
30123012+ document.getElementsByTagName("head").item(0)
27363013 );
27372737- LoadLvl();
27382738- }),
27392739- (LoadLvl = function (e, c) {
27402740- oSym.Timer && oSym.Stop();
27412741- var b = oSym.Now === c;
27422742- var d = $User;
27432743- var a = d.Visitor;
27442744- oS.CenterContent && ((e === 0 && b) || e !== 0) && (oS.DisplayAD = true);
27452745- e = e || 0;
27462746- $("dServer") && e !== 0 && SetNone($("dServer"));
27472747- oSym.Init(
27482748- (g, f) => {
27492749- (f = $("JSPVZ")) && ClearChild(f);
27502750- NewEle(
27512751- "JSPVZ",
27522752- "script",
27532753- 0,
27542754- {
27552755- src: "level/" + (oS.Lvl = g) + ".js",
27562756- type: "text/javascript",
27572757- },
27582758- document.getElementsByTagName("head").item(0)
27592759- );
27602760- },
27612761- [e && b ? 0 : e]
27622762- );
27632763- /* $("aLvlLink").href =
27642764- "html/2-1" + (e && !isNaN(e) ? "-" + e : "") + ".htm"; */
27652765- }),
27662766- (AppearTombstones = function (n, e, m) {
27672767- var r = oGd.$Tombstones;
27682768- var k = [];
27692769- var h = oS.R + 1;
27702770- var b;
27712771- var d = 0;
27722772- var q;
27732773- var a;
27742774- var g;
27752775- var f;
27762776- var s = oGd.$;
27772777- var l;
27782778- var p;
27792779- while (--h) {
27802780- g = e;
27812781- while (g >= n) {
27822782- !r[h + "_" + g] && (k[d++] = [h, g]);
27832783- --g;
27842784- }
30143014+ },
30153015+ [level && isReplay ? 0 : level]
30163016+ );
30173017+};
30183018+30193019+var AppearTombstones = function (minR, maxR, count) {
30203020+ const tombs = oGd.$Tombstones;
30213021+ const candidates = [];
30223022+ let r = oS.R + 1;
30233023+30243024+ // Find valid locations
30253025+ while (--r) {
30263026+ let c = maxR;
30273027+ while (c >= minR) {
30283028+ if (!tombs[r + "_" + c]) candidates.push([r, c]);
30293029+ --c;
27853030 }
27862786- while (m--) {
27872787- q = k[(g = Math.floor(Math.random() * k.length))];
27882788- r[(p = (h = q[0]) + "_" + (b = q[1]))] = 1;
27892789- for (f = 0; f < 4; f++) {
27902790- (l = s[p + "_" + f]) && l.Die();
27912791- }
27922792- k.splice(g, 1);
27932793- a = NewEle(
27942794- "dTombstones" + h + "_" + b,
27952795- "div",
27962796- "position:absolute;width:86px;height:91px;left:" + (GetX(b) - 43) + "px;top:" + (GetY(h) - 91) + "px",
27972797- 0,
27982798- EDAll
27992799- );
28002800- h = Math.floor(Math.random() * 4);
28012801- b = Math.floor(Math.random() * 2);
28022802- var c;
28032803- a.appendChild(
28042804- (c = NewEle("", "div", "background-position:-" + 86 * h + "px -" + 91 * b + "px", { className: "Tom1" }, a).cloneNode(false))
28052805- ).className = "Tom2";
30313031+ }
30323032+30333033+ while (count--) {
30343034+ let randIdx = Math.floor(Math.random() * candidates.length);
30353035+ let coord = candidates[randIdx];
30363036+ let tr = coord[0];
30373037+ let tc = coord[1];
30383038+ let key = tr + "_" + tc;
30393039+30403040+ tombs[key] = 1;
30413041+30423042+ // Kill existing plants at location
30433043+ for (let i = 0; i < 4; i++) {
30443044+ let p = oGd.$[key + "_" + i];
30453045+ if (p) p.Die();
28063046 }
28072807- }),
28082808- (ResetGame = function (b) {
28092809- AllAudioPauseCanceled();
28102810- var a = oSym;
28112811- a.Start();
28122812- innerText(b, "Speed");
28132813- $("dMenu1").onclick = ClickMenu;
28142814- $("dMenu0").onclick = ShowSpeed;
28152815- SetNone($("dSurface"), $("dPause"));
28162816- $("dPauseAD").innerHTML = "";
28172817- }),
28182818- (PauseGame = function (c, a) {
28192819- var b = oSym;
30473047+30483048+ candidates.splice(randIdx, 1);
30493049+30503050+ const div = NewEle("dTombstones" + key, "div", `position:absolute;width:86px;height:91px;left:${GetX(tc) - 43}px;top:${GetY(tr) - 91}px`, 0, EDAll);
30513051+ const bgX = Math.floor(Math.random() * 4);
30523052+ const bgY = Math.floor(Math.random() * 2);
30533053+30543054+ div.appendChild(NewEle("", "div", `background-position:-${86 * bgX}px -${91 * bgY}px`, { className: "Tom1" }, div).cloneNode(false)).className = "Tom2";
30553055+ }
30563056+};
30573057+30583058+var ResetGame = function (menuBtn) {
30593059+ AllAudioPauseCanceled();
30603060+ oSym.Start();
30613061+ innerText(menuBtn, "Speed");
30623062+ $("dMenu1").onclick = ClickMenu;
30633063+ $("dMenu0").onclick = ShowSpeed;
30643064+ SetNone($("dSurface"), $("dPause"));
30653065+ $("dPauseAD").innerHTML = "";
30663066+};
30673067+30683068+var PauseGame = function (menuBtn, showAd) {
30693069+ AllAudioPaused();
30703070+ oSym.Stop();
30713071+ innerText(menuBtn, "Speed");
30723072+ $("dMenu1").onclick = null;
30733073+ $("dMenu0").onclick = null;
30743074+ if (!showAd) SetBlock($("dSurface"), $("dPause"));
30753075+};
30763076+30773077+var ClickMenu = function (e, btn) {
30783078+ if (oSym.Timer) {
28203079 AllAudioPaused();
28212821- b.Stop();
28222822- innerText(c, "Speed");
28232823- $("dMenu1").onclick = null;
28242824- $("dMenu0").onclick = null;
28252825- !a && SetBlock($("dSurface"), $("dPause"));
28262826- }),
28272827- (ClickMenu = function (b, a) {
28282828- oSym.Timer && (AllAudioPaused(), PlayAudio("pause"), oSym.Stop(), SetBlock($("dSurface")), innerText($("dMenu0"), "Speed"), ShowOptions());
28292829- document.getElementById("sOptionsMenu").textContent = "Back To Game";
28302830- if (ArCard[oS.ChoseCard] && ArCard[oS.ChoseCard].DID != null) {
28312831- CancelPlant();
28322832- }
28332833- }),
28342834- (OptionsMenuDown = function (b, a) {
28352835- b.className = "OptionsMenuButtonDown";
28362836- a.style.paddingTop = "2px";
28372837- }),
28382838- (OptionsMenuUP = function (b, a) {
28392839- b.className = "OptionsMenuButton";
28402840- a.style.paddingTop = "0px";
28412841- }),
28422842- (ShowSpeed = function () {
28432843- var b = oSym;
28442844- b.Stop();
28452845- PlayAudio("gravebutton");
28462846- SetNone($("dOptionsMenuback"), $("dOptionsMenu"));
28472847- SetBlock($("dSpeedContainer"));
28482848- }),
28492849- (HiddenSpeed = function () {
28502850- PlayAudio("tap");
28512851- SetNone($("dSpeedContainer"));
28522852- oS.Lvl && ResetGame($("dMenu0"));
28532853- }),
28542854- (CSpeed = function (a, c, b) {
28552855- $User.Visitor.NowStep = oSym.NowStep = a;
28562856- $User.Visitor.TimeStep = oSym.TimeStep = c;
28572857- $("dDisplaySpeed").innerHTML = b;
28582858- }),
28592859- (ShowLevel = function () {
30803080+ PlayAudio("pause");
30813081+ oSym.Stop();
30823082+ SetBlock($("dSurface"));
30833083+ innerText($("dMenu0"), "Speed");
30843084+ ShowOptions();
30853085+ }
30863086+ document.getElementById("sOptionsMenu").textContent = "Back To Game";
30873087+ if (ArCard[oS.ChoseCard] && ArCard[oS.ChoseCard].DID != null) {
30883088+ CancelPlant();
30893089+ }
30903090+};
30913091+30923092+var OptionsMenuDown = function (ele, wrapper) {
30933093+ ele.className = "OptionsMenuButtonDown";
30943094+ wrapper.style.paddingTop = "2px";
30953095+};
30963096+30973097+var OptionsMenuUP = function (ele, wrapper) {
30983098+ ele.className = "OptionsMenuButton";
30993099+ wrapper.style.paddingTop = "0px";
31003100+};
31013101+31023102+var ShowSpeed = function () {
31033103+ oSym.Stop();
31043104+ PlayAudio("gravebutton");
31053105+ SetNone($("dOptionsMenuback"), $("dOptionsMenu"));
31063106+ SetBlock($("dSpeedContainer"));
31073107+};
31083108+31093109+var HiddenSpeed = function () {
31103110+ PlayAudio("tap");
31113111+ SetNone($("dSpeedContainer"));
31123112+ if (oS.Lvl) ResetGame($("dMenu0"));
31133113+};
31143114+31153115+var CSpeed = function (nowStep, timeStep, displayLabel) {
31163116+ $User.Visitor.NowStep = oSym.NowStep = nowStep;
31173117+ $User.Visitor.TimeStep = oSym.TimeStep = timeStep;
31183118+ $("dDisplaySpeed").innerHTML = displayLabel;
31193119+};
31203120+31213121+var ShowLevel = function () {
31223122+ PlayAudio("gravebutton");
31233123+ SetNone($("dOptionsMenu"));
31243124+ SetBlock($("dAdvSmallContainer"));
31253125+};
31263126+31273127+var HiddenLevel = function () {
31283128+ PlayAudio("tap");
31293129+ SetNone($("dOptionsMenuback"), $("dAdvSmallContainer"));
31303130+ if (oS.Lvl) {
31313131+ SetNone($("dSurface"));
31323132+ ResetGame($("dMenu0"));
31333133+ }
31343134+};
31353135+31363136+var ShowMiniGame = function () {
31373137+ PlayAudio("gravebutton");
31383138+ SetBlock($("dMiniSmallContainer"));
31393139+};
31403140+31413141+var HiddenMiniGame = function (isSilent) {
31423142+ if (!isSilent) PlayAudio("tap");
31433143+ SetNone($("dMiniSmallContainer"));
31443144+};
31453145+31463146+var ShowRiddleGame = function () {
31473147+ PlayAudio("gravebutton");
31483148+ SetBlock($("dRiddleSmallContainer"));
31493149+};
31503150+31513151+var HiddenRiddleGame = function (isSilent) {
31523152+ if (!isSilent) PlayAudio("tap");
31533153+ SetNone($("dRiddleSmallContainer"));
31543154+};
31553155+31563156+var ShowOptions = function () {
31573157+ document.getElementById("sOptionsMenu").textContent = "OK";
31583158+ PlayAudio(oS.Lvl ? "gravebutton" : "tap");
31593159+ SetBlock($("dOptionsMenuback"), $("dOptionsMenu"));
31603160+};
31613161+31623162+var HiddenOptions = function () {
31633163+ PlayAudio("gravebutton");
31643164+ PlayAudio("buttonclick");
31653165+ SetNone($("dOptionsMenuback"), $("dOptionsMenu"));
31663166+ if (oS.Lvl) {
31673167+ SetNone($("dSurface"));
31683168+ ResetGame($("dMenu0"));
31693169+ }
31703170+};
31713171+31723172+var ViewHandBook = function () {
31733173+ SetNone($("dOptionsMenuback"), $("dOptionsMenu"));
31743174+ if (oS.Lvl) {
31753175+ AllAudioPaused();
28603176 PlayAudio("gravebutton");
28612861- SetNone($("dOptionsMenu"));
28622862- SetBlock($("dAdvSmallContainer"));
28632863- }),
28642864- (HiddenLevel = function () {
31773177+ SetNone($("dSurface"));
31783178+ oSym.Stop();
31793179+ innerText($("dMenu0"), "back to game");
31803180+ $("dMenu1").onclick = null;
31813181+ } else {
31823182+ AllAudioPaused();
28653183 PlayAudio("tap");
28662866- SetNone($("dOptionsMenuback"), $("dAdvSmallContainer"));
28672867- oS.Lvl && (SetNone($("dSurface")), ResetGame($("dMenu0")));
28682868- }),
28692869- (ShowMiniGame = function () {
28702870- PlayAudio("gravebutton");
28712871- SetBlock($("dMiniSmallContainer"));
28722872- }),
28732873- (HiddenMiniGame = function (a) {
28742874- !a && PlayAudio("tap");
28752875- SetNone($("dMiniSmallContainer"));
28762876- }),
28772877- (ShowRiddleGame = function () {
28782878- PlayAudio("gravebutton");
28792879- SetBlock($("dRiddleSmallContainer"));
28802880- }),
28812881- (HiddenRiddleGame = function (a) {
28822882- !a && PlayAudio("tap");
28832883- SetNone($("dRiddleSmallContainer"));
28842884- }),
28852885- (ShowOptions = function () {
28862886- (document.getElementById("sOptionsMenu").textContent = "OK"), PlayAudio(oS.Lvl ? "gravebutton" : "tap");
28872887- SetBlock($("dOptionsMenuback"), $("dOptionsMenu"));
28882888- }),
28892889- (HiddenOptions = function () {
28902890- PlayAudio("gravebutton");
28912891- PlayAudio("buttonclick");
28922892- SetNone($("dOptionsMenuback"), $("dOptionsMenu"));
28932893- oS.Lvl && (SetNone($("dSurface")), ResetGame($("dMenu0")));
28942894- }),
28952895- (ViewHandBook = function () {
28962896- SetNone($("dOptionsMenuback"), $("dOptionsMenu"));
28972897- oS.Lvl
28982898- ? (AllAudioPaused(),
28992899- PlayAudio("gravebutton"),
29002900- SetNone($("dSurface")),
29012901- oSym.Stop(),
29022902- innerText($("dMenu0"), "back to game"),
29032903- ($("dMenu1").onclick = null))
29042904- : (AllAudioPaused(), PlayAudio("tap"));
29052905- PlayAudio("ChooseYourSeeds");
29062906- SetVisible($("dHandBook"));
29072907- }),
29082908- (ReturnHandBookInx = function () {
29092909- PlayAudio("tap");
29102910- SetNone($("dHandBookP"), $("dHandBookZ"));
29112911- SetHidden($("dHandBookPZ"));
29122912- }),
29132913- (CloseHandBook = function () {
29142914- PlayAudio("tap");
29152915- StopAudio("ChooseYourSeeds");
29162916- oS.Lvl ? ResetGame($("dMenu0")) : oSym.addTask(100, AllAudioPauseCanceled);
29172917- SetNone($("dHandBookP"), $("dHandBookZ"));
29182918- SetHidden($("dHandBookPZ"), $("dHandBook"));
29192919- }),
29202920- (ShowHelp = function () {
29212921- PlayAudio("tap");
29222922- SetBlock($("dHelp"));
29232923- }),
29242924- (HiddenHelp = function () {
29252925- PlayAudio("tap");
29262926- SetNone($("dHelp"));
29272927- }),
29282928- ($ = function (a) {
29292929- return document.getElementById(a);
29302930- }),
29312931- ($n = function (a) {
29322932- return document.createElement(a);
29332933- }),
29342934- (ClearChild = function () {
29352935- var a = arguments.length;
29362936- var c;
29372937- while (a--) {
29382938- try {
29392939- c = arguments[a];
29402940- c.parentNode.removeChild(c);
29412941- c = null;
29422942- } catch (b) {}
31843184+ }
31853185+ PlayAudio("ChooseYourSeeds");
31863186+ SetVisible($("dHandBook"));
31873187+};
31883188+31893189+var ReturnHandBookInx = function () {
31903190+ PlayAudio("tap");
31913191+ SetNone($("dHandBookP"), $("dHandBookZ"));
31923192+ SetHidden($("dHandBookPZ"));
31933193+};
31943194+31953195+var CloseHandBook = function () {
31963196+ PlayAudio("tap");
31973197+ StopAudio("ChooseYourSeeds");
31983198+ if (oS.Lvl) {
31993199+ ResetGame($("dMenu0"));
32003200+ } else {
32013201+ oSym.addTask(100, AllAudioPauseCanceled);
32023202+ }
32033203+ SetNone($("dHandBookP"), $("dHandBookZ"));
32043204+ SetHidden($("dHandBookPZ"), $("dHandBook"));
32053205+};
32063206+32073207+var ShowHelp = function () {
32083208+ PlayAudio("tap");
32093209+ SetBlock($("dHelp"));
32103210+};
32113211+32123212+var HiddenHelp = function () {
32133213+ PlayAudio("tap");
32143214+ SetNone($("dHelp"));
32153215+};
32163216+32173217+var $ = function (id) {
32183218+ return document.getElementById(id);
32193219+};
32203220+32213221+var $n = function (tag) {
32223222+ return document.createElement(tag);
32233223+};
32243224+32253225+var ClearChild = function () {
32263226+ let i = arguments.length;
32273227+ while (i--) {
32283228+ try {
32293229+ let child = arguments[i];
32303230+ child.parentNode.removeChild(child);
32313231+ child = null;
32323232+ } catch (e) {}
32333233+ }
32343234+};
32353235+32363236+var SetBlock = function () {
32373237+ let i = arguments.length;
32383238+ while (i--) {
32393239+ if (arguments[i]) arguments[i].style.display = "block";
32403240+ }
32413241+};
32423242+32433243+var SetNone = function () {
32443244+ let i = arguments.length;
32453245+ while (i--) {
32463246+ if (arguments[i] && arguments[i].style) {
32473247+ arguments[i].style.display = "none";
32483248+ }
32493249+ }
32503250+};
32513251+32523252+var SetHidden = function () {
32533253+ let i = arguments.length;
32543254+ while (i--) {
32553255+ if (arguments[i]) arguments[i].style.visibility = "hidden";
32563256+ }
32573257+};
32583258+32593259+var SetVisible = function () {
32603260+ let i = arguments.length;
32613261+ while (i--) {
32623262+ if (arguments[i]) arguments[i].style.visibility = "visible";
32633263+ }
32643264+};
32653265+32663266+var SetAlpha = $User.Browser.IE6
32673267+ ? function (ele, val, opacity) {
32683268+ ele.style.filter = "alpha(opacity=" + val + ")";
32693269+ }
32703270+ : function (ele, val, opacity) {
32713271+ ele.style.opacity = opacity;
32723272+ };
32733273+32743274+var SetStyle = function (ele, styles) {
32753275+ const s = ele.style;
32763276+ for (let key in styles) {
32773277+ s[key] = styles[key];
32783278+ }
32793279+ return ele;
32803280+};
32813281+32823282+var NewImg = function (id, src, cssText, parent, props) {
32833283+ const img = $n("img");
32843284+ img.src = src;
32853285+ if (cssText) img.style.cssText = cssText;
32863286+ if (props) {
32873287+ for (let key in props) {
32883288+ img[key] = props[key];
32893289+ }
32903290+ }
32913291+ if (id) img.id = id;
32923292+ if (parent) parent.appendChild(img);
32933293+ return img;
32943294+};
32953295+32963296+var EditImg = function (img, id, src, styles, parent) {
32973297+ if (id) img.id = id;
32983298+ if (src) img.src = src;
32993299+ if (styles) SetStyle(img, styles);
33003300+ if (parent) parent.appendChild(img);
33013301+ return img;
33023302+};
33033303+33043304+var NewEle = function (id, tag, cssText, props, parent, attrs) {
33053305+ const ele = $n(tag);
33063306+ if (id) ele.id = id;
33073307+ if (cssText) ele.style.cssText = cssText;
33083308+ if (props) {
33093309+ for (let key in props) {
33103310+ ele[key] = props[key];
33113311+ }
33123312+ }
33133313+ if (attrs) {
33143314+ for (let key in attrs) {
33153315+ ele.setAttribute(key, attrs[key]);
33163316+ }
33173317+ }
33183318+ if (parent) parent.appendChild(ele);
33193319+ return ele;
33203320+};
33213321+33223322+var EditEle = function (ele, attrs, styles, props, parent) {
33233323+ // Backward/forward compatibility:
33243324+ // Many call sites use EditEle(ele, attrs, styles, parent) or
33253325+ // EditEle(ele, attrs, styles, parent, props). Detect and normalize.
33263326+ if (props && props.nodeType && parent && !parent.nodeType) {
33273327+ // (ele, attrs, styles, parentEle, propsObj)
33283328+ const realParent = props;
33293329+ props = parent;
33303330+ parent = realParent;
33313331+ } else if (!parent && props && props.nodeType) {
33323332+ // (ele, attrs, styles, parentEle)
33333333+ parent = props;
33343334+ props = null;
33353335+ }
33363336+ if (attrs) {
33373337+ for (let key in attrs) {
33383338+ ele.setAttribute(key, attrs[key]);
29433339 }
29442944- }),
29452945- (SetBlock = function () {
29462946- var a = arguments.length;
29472947- while (a--) {
29482948- arguments[a].style.display = "block";
33403340+ }
33413341+ if (styles) SetStyle(ele, styles);
33423342+ if (props) {
33433343+ for (let key in props) {
33443344+ if (key === "outerText" && !ele.parentNode) {
33453345+ ele.textContent = props[key];
33463346+ } else {
33473347+ ele[key] = props[key];
33483348+ }
29493349 }
29502950- }),
29512951- (SetNone = function () {
29522952- var a = arguments.length;
29532953- while (a--) {
29542954- if (arguments[a] && arguments[a].style) {
29552955- arguments[a].style.display = "none";
33503350+ }
33513351+ if (parent) parent.appendChild(ele);
33523352+ return ele;
33533353+};
33543354+33553355+var NewO = function (proto, constructor) {
33563356+ constructor = function () {};
33573357+ constructor.prototype = proto;
33583358+ return constructor;
33593359+};
33603360+33613361+var SetPrototype = function (child, parent) {
33623362+ const p = child.prototype;
33633363+ for (let key in parent) {
33643364+ p[key] = parent[key];
33653365+ }
33663366+};
33673367+33683368+var InheritO = function (Parent, properties, arrayProps, child, parentArr, childArr) {
33693369+ const Child = function () {};
33703370+ Child.prototype = new Parent();
33713371+ if (properties) SetPrototype(Child, properties);
33723372+33733373+ if (arrayProps) {
33743374+ const proto = Child.prototype;
33753375+ for (let key in arrayProps) {
33763376+ parentArr = proto[key].slice(0);
33773377+ childArr = arrayProps[key];
33783378+ for (let k in childArr) {
33793379+ parentArr[k] = childArr[k];
29563380 }
33813381+ Child.prototype[key] = parentArr;
29573382 }
29582958- }),
29592959- (SetHidden = function () {
29602960- var a = arguments.length;
29612961- while (a--) {
29622962- arguments[a].style.visibility = "hidden";
33833383+ }
33843384+ return Child;
33853385+};
33863386+33873387+var Compare = function (val, min, max, func, arg) {
33883388+ const result = val < min ? min : val > max ? max : val;
33893389+ return func ? [func(result), result] : [result];
33903390+};
33913391+33923392+var $Switch = function (val, cases, comparer, result, len) {
33933393+ let i = 0;
33943394+ len = cases.length;
33953395+ while (i < len) {
33963396+ if (comparer(val, cases[i])) break;
33973397+ ++i;
33983398+ }
33993399+ return result[i];
34003400+};
34013401+34023402+var $SEql = function (key, map) {
34033403+ return key in map ? map[key] : map.default;
34043404+};
34053405+34063406+var $SSml = function (val, thresholds, results) {
34073407+ let i = 0;
34083408+ const len = thresholds.length;
34093409+ while (i < len) {
34103410+ if (val < thresholds[i]) break;
34113411+ ++i;
34123412+ }
34133413+ return results[i];
34143414+};
34153415+34163416+var $SGrt = function (val, thresholds, results) {
34173417+ let i = 0;
34183418+ const len = thresholds.length;
34193419+ while (i < len) {
34203420+ if (val > thresholds[i]) break;
34213421+ ++i;
34223422+ }
34233423+ return results[i];
34243424+};
34253425+34263426+var ImgSpriter = function (id, cardId, config, frameIdx, callback) {
34273427+ const frame = config[frameIdx];
34283428+ const nextIdx = frame[2];
34293429+ const ele = $(id);
34303430+34313431+ if (ele) {
34323432+ ele.style.backgroundPosition = frame[0];
34333433+ oSym.addTask(
34343434+ frame[1],
34353435+ (idx) => {
34363436+ idx > -1 ? ImgSpriter(id, cardId, config, idx, callback) : callback(id, cardId);
34373437+ },
34383438+ [nextIdx]
34393439+ );
34403440+ }
34413441+};
34423442+34433443+var Ajax = function () {};
34443444+34453445+Date.prototype.format = function (fmt) {
34463446+ const o = {
34473447+ "M+": this.getMonth() + 1,
34483448+ "d+": this.getDate(),
34493449+ "h+": this.getHours(),
34503450+ "m+": this.getMinutes(),
34513451+ "s+": this.getSeconds(),
34523452+ "q+": Math.floor((this.getMonth() + 3) / 3),
34533453+ S: this.getMilliseconds(),
34543454+ };
34553455+ if (/(y+)/.test(fmt)) {
34563456+ fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
34573457+ }
34583458+ for (let k in o) {
34593459+ if (new RegExp("(" + k + ")").test(fmt)) {
34603460+ fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
29633461 }
29642964- }),
29652965- (SetVisible = function () {
29662966- var a = arguments.length;
29672967- while (a--) {
29682968- arguments[a].style.visibility = "visible";
34623462+ }
34633463+ return fmt;
34643464+};
34653465+34663466+var NewMusic = $User.HTML5
34673467+ ? function (src) {
34683468+ NewAudio({ autoplay: true, loop: true, source: src });
29693469 }
29702970- }),
29712971- (SetAlpha = $User.Browser.IE6
29722972- ? function (c, b, a) {
29732973- c.style.filter = "alpha(opacity=" + b + ")";
34703470+ : function (src) {
34713471+ if (!oS.Silence) $("oEmbed").innerHTML = "";
34723472+ };
34733473+34743474+var PauseMusic = $User.HTML5
34753475+ ? function () {
34763476+ const audio = oAudio[oS.LoadMusic];
34773477+ if (audio) {
34783478+ audio.currentTime = 0;
34793479+ audio.pause();
29743480 }
29752975- : function (c, b, a) {
29762976- c.style.opacity = a;
29772977- }),
29782978- (SetStyle = function (d, b) {
29792979- var c = d.style;
29802980- var a;
29812981- for (a in b) {
29822982- c[a] = b[a];
34813481+ }
34823482+ : function () {
34833483+ $("oEmbed").innerHTML = "";
34843484+ };
34853485+34863486+var StartAdventure = function (level) {
34873487+ const handDiv = $("ZombieHand");
34883488+ const advDiv = $("dAdventure");
34893489+ const handImg = NewImg("", "images/interface/ZombieHand.png", "position:absolute;left:0", handDiv);
34903490+34913491+ advDiv.onclick = advDiv.onmouseover = advDiv.onmouseout = null;
34923492+ SetBlock(handDiv);
34933493+ StopMusic();
34943494+ PlayAudio("losemusic");
34953495+34963496+ oSym.addTask(
34973497+ 120,
34983498+ () => {
34993499+ PlayAudio("evillaugh");
35003500+ },
35013501+ []
35023502+ );
35033503+35043504+ oSym.addTask(
35053505+ 7,
35063506+ function (count, ele, left) {
35073507+ ele.style.left = (left -= 330) + "px";
35083508+ if (--count) oSym.addTask(7, arguments.callee, [count, ele, left]);
35093509+ },
35103510+ [6, handImg, 0]
35113511+ );
35123512+35133513+ const animation = function (ele, frame, count) {
35143514+ if (--count) {
35153515+ ele.style.backgroundPosition = ["top", "bottom"][frame];
35163516+ oSym.addTask(10, arguments.callee, [ele, frame ? 0 : 1, count]);
35173517+ } else {
35183518+ ele.style.backgroundPosition = "top";
35193519+ ele.onclick = StartAdventure;
35203520+ ele.onmouseover = function () {
35213521+ this.style.backgroundPosition = "bottom";
35223522+ };
35233523+ ele.onmouseout = function () {
35243524+ this.style.backgroundPosition = "top";
35253525+ };
35263526+35273527+ if ($User.HTML5) StopAudio("evillaugh");
35283528+ SelectModal(level);
35293529+ handDiv.innerHTML = "";
29833530 }
29842984- return d;
29852985- }),
29862986- (NewImg = function (f, e, b, c, d) {
29872987- var a = $n("img");
29882988- a.src = e;
29892989- b && (a.style.cssText = b);
29902990- if (d) {
29912991- for (v in d) {
29922992- a[v] = d[v];
35313531+ };
35323532+35333533+ if ($User.HTML5) {
35343534+ animation(advDiv, 1, 50);
35353535+ } else {
35363536+ NewMusic("evillaugh");
35373537+ animation(advDiv, 1, 50);
35383538+ }
35393539+};
35403540+35413541+var oAudio = {};
35423542+var PausedAudioArr = [];
35433543+35443544+var NewAudio = $User.HTML5
35453545+ ? function (config) {
35463546+ const src = config.source;
35473547+ if (oAudio[src]) return;
35483548+35493549+ const audio = document.createElement("audio");
35503550+ const types = { mp3: "audio/mpeg" };
35513551+ const formats = ["mp3"];
35523552+ let i = formats.length;
35533553+35543554+ audio.autoplay = !!config.autoplay;
35553555+35563556+ if (config.loop) {
35573557+ audio.addEventListener(
35583558+ "ended",
35593559+ () => {
35603560+ audio.play();
35613561+ },
35623562+ false
35633563+ );
29933564 }
35653565+35663566+ while (i--) {
35673567+ let source = document.createElement("source");
35683568+ source.type = types[formats[i]];
35693569+ source.src = "audio/" + src + ".mp3";
35703570+ audio.appendChild(source);
35713571+ }
35723572+35733573+ audio.preload = config.preload === undefined ? "auto" : ["auto", "meta", "none"][config.preload];
35743574+ audio.muted = oS.Silence;
35753575+35763576+ if (config.callback) audio.addEventListener("canplaythrough", config.callback, false);
35773577+35783578+ return (oAudio[src] = audio);
29943579 }
29952995- f && (a.id = f);
29962996- c && c.appendChild(a);
29972997- return a;
29982998- }),
29992999- (EditImg = function (e, f, c, b, a) {
30003000- f && (e.id = f);
30013001- c && (e.src = c);
30023002- b && SetStyle(e, b);
30033003- a && a.appendChild(e);
30043004- return e;
30053005- }),
30063006- (NewEle = function (h, b, d, a, e, f, g, c) {
30073007- g = $n(b);
30083008- h && (g.id = h);
30093009- d && (g.style.cssText = d);
30103010- if (a) {
30113011- for (c in a) {
30123012- g[c] = a[c];
35803580+ : function () {};
35813581+35823582+var PlayMusic = $User.HTML5
35833583+ ? function (src) {
35843584+ let audio = oAudio[src];
35853585+ if (audio) {
35863586+ try {
35873587+ audio.currentTime = 0;
35883588+ } catch (e) {}
35893589+ audio.play();
35903590+ } else {
35913591+ NewMusic(src);
35923592+ oAudio[src].play();
30133593 }
30143594 }
30153015- if (f) {
30163016- for (c in f) {
30173017- g.setAttribute(c, f[c]);
35953595+ : function (src) {
35963596+ NewMusic(src);
35973597+ };
35983598+35993599+var PlayAudioLegacy = $User.HTML5
36003600+ ? function (src, loop) {
36013601+ const audio = oAudio[src];
36023602+ if (audio) {
36033603+ audio.loop = !!loop;
36043604+ audio.play();
36053605+ } else {
36063606+ NewAudio({ source: src, loop: !!loop }).play();
30183607 }
30193608 }
30203020- e && e.appendChild(g);
30213021- return g;
30223022- }),
30233023- (EditEle = function (g, f, a, e, b, c) {
30243024- if (f) {
30253025- for (c in f) {
30263026- g.setAttribute(c, f[c]);
36093609+ : function () {};
36103610+36113611+var PlayAudio = $User.HTML5
36123612+ ? function (src, loop) {
36133613+ let audio = oAudio[src];
36143614+ if (!audio) {
36153615+ audio = NewAudio({ source: src, loop: !!loop });
36163616+ oAudio[src] = audio;
36173617+ } else {
36183618+ audio.loop = !!loop;
30273619 }
36203620+ audio.currentTime = 0;
36213621+ audio.play();
30283622 }
30293029- a && SetStyle(g, a);
30303030- if (b) {
30313031- for (c in b) {
30323032- g[c] = b[c];
30333033- }
36233623+ : function () {};
36243624+36253625+var PauseAudio = $User.HTML5
36263626+ ? function (src) {
36273627+ oAudio[src].pause();
30343628 }
30353035- e && e.appendChild(g);
30363036- return g;
30373037- }),
30383038- (NewO = function (b, a) {
30393039- return ((a = function () {}).prototype = b), a;
30403040- }),
30413041- (SetPrototype = function (d, c, a) {
30423042- a = d.prototype;
30433043- for (var b in c) {
30443044- a[b] = c[b];
36293629+ : function () {};
36303630+36313631+var StopMusic = $User.HTML5
36323632+ ? function () {
36333633+ const audio = oAudio[oS.LoadMusic];
36343634+ try {
36353635+ audio.currentTime = 0;
36363636+ } catch (e) {}
36373637+ if (audio) audio.pause();
30453638 }
30463046- }),
30473047- (InheritO = function (d, i, c, g, b, h, f, e, a) {
30483048- var g = function () {};
30493049- g.prototype = new d();
30503050- i && SetPrototype(g, i);
30513051- if (c) {
30523052- a = g.prototype;
30533053- for (f in c) {
30543054- b = a[f].slice(0);
30553055- h = c[f];
30563056- for (e in h) {
30573057- b[e] = h[e];
36393639+ : function () {};
36403640+36413641+var StopAudio = $User.HTML5
36423642+ ? function (src) {
36433643+ const audio = oAudio[src];
36443644+ try {
36453645+ audio.currentTime = 0;
36463646+ } catch (e) {}
36473647+ try {
36483648+ audio.pause();
36493649+ } catch (e) {}
36503650+ }
36513651+ : function () {};
36523652+36533653+var AllAudioPaused = $User.HTML5
36543654+ ? function () {
36553655+ for (let key in oAudio) {
36563656+ let audio = oAudio[key];
36573657+ if (!(audio.paused || audio.ended)) {
36583658+ PausedAudioArr.push(key);
36593659+ audio.pause();
30583660 }
30593059- g.prototype[f] = b;
30603661 }
30613662 }
30623062- return g;
30633063- }),
30643064- (Compare = function (e, b, a, c, d) {
30653065- return (d = e < b ? b : e > a ? a : e), c ? [c(d), d] : [d];
30663066- }),
30673067- ($Switch = function (h, d, c, a, g, b, e) {
30683068- b = 0;
30693069- g = d.length;
30703070- e = c;
30713071- while (b < g) {
30723072- if (e(h, d[b])) {
30733073- break;
36633663+ : function () {};
36643664+36653665+var AllAudioPauseCanceled = $User.HTML5
36663666+ ? function () {
36673667+ let i = PausedAudioArr.length;
36683668+ while (i--) {
36693669+ oAudio[PausedAudioArr[i]].play();
30743670 }
30753075- ++b;
30763076- }
30773077- return a[b];
30783078- }),
30793079- ($SEql = function (c, b, a) {
30803080- return c in b ? b[c] : b.default;
30813081- });
30823082-($SSml = function (d, c, a) {
30833083- var b = 0;
30843084- LX = c.length;
30853085- while (b < LX) {
30863086- if (d < c[b]) {
30873087- break;
36713671+ PausedAudioArr.length = 0;
30883672 }
30893089- ++b;
36733673+ : function () {};
36743674+36753675+var AllAudioMuted = function () {
36763676+ for (let key in oAudio) {
36773677+ oAudio[key].muted = true;
36783678+ }
36793679+};
36803680+36813681+var AllAudioMuteCanceled = function () {
36823682+ for (let key in oAudio) {
36833683+ oAudio[key].muted = false;
30903684 }
30913091- return a[b];
30923092-}),
30933093- ($SGrt = function (d, c, a) {
30943094- var b = 0;
30953095- LX = c.length;
30963096- while (b < LX) {
30973097- if (d > c[b]) {
30983098- break;
36853685+};
36863686+36873687+var CheckSilence = $User.HTML5
36883688+ ? function (checkbox) {
36893689+ const val = checkbox.checked ? 1 : 0;
36903690+ if (val !== oS.Silence) {
36913691+ addCookie("JSPVZSilence", (oS.Silence = val));
36923692+ val ? AllAudioMuted() : AllAudioMuteCanceled();
30993693 }
31003100- ++b;
31013694 }
31023102- return a[b];
31033103- }),
31043104- (ImgSpriter = function (h, c, e, f, g) {
31053105- var b = e[f];
31063106- var d = b[2];
31073107- var a = $(h);
31083108- a &&
31093109- ((a.style.backgroundPosition = b[0]),
31103110- oSym.addTask(
31113111- b[1],
31123112- (j) => {
31133113- j > -1 ? ImgSpriter(h, c, e, j, g) : g(h, c);
31143114- },
31153115- [d]
31163116- ));
31173117- }),
31183118- (Ajax = function () {}),
31193119- (Date.prototype.format = function (b) {
31203120- var c = {
31213121- "M+": this.getMonth() + 1,
31223122- "d+": this.getDate(),
31233123- "h+": this.getHours(),
31243124- "m+": this.getMinutes(),
31253125- "s+": this.getSeconds(),
31263126- "q+": Math.floor((this.getMonth() + 3) / 3),
31273127- S: this.getMilliseconds(),
36953695+ : function (checkbox) {
36963696+ const val = checkbox.checked ? 1 : 0;
36973697+ if (val !== oS.Silence) {
36983698+ addCookie("JSPVZSilence", (oS.Silence = val));
36993699+ val ? PauseMusic() : NewMusic(oS.StartGameMusic);
37003700+ }
31283701 };
31293129- if (/(y+)/.test(b)) {
31303130- b = b.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
31313131- }
31323132- for (var a in c) {
31333133- if (new RegExp("(" + a + ")").test(b)) {
31343134- b = b.replace(RegExp.$1, RegExp.$1.length === 1 ? c[a] : ("00" + c[a]).substr(("" + c[a]).length));
31353135- }
31363136- }
31373137- return b;
31383138- }),
31393139- (NewMusic = $User.HTML5
31403140- ? function (a) {
31413141- NewAudio({ autoplay: true, loop: true, source: a });
31423142- }
31433143- : function (a) {
31443144- !oS.Silence && ($("oEmbed").innerHTML = "");
31453145- }),
31463146- (PauseMusic = $User.HTML5
31473147- ? function () {
31483148- var a = oAudio[oS.LoadMusic];
31493149- a.currentTime = 0;
31503150- a.pause();
31513151- }
31523152- : function () {
31533153- $("oEmbed").innerHTML = "";
31543154- }),
31553155- (StartAdventure = function (d) {
31563156- var c = $("ZombieHand");
31573157- var b = $("dAdventure");
31583158- var a = NewImg("", "images/interface/ZombieHand.png", "position:absolute;left:0", c);
31593159- b.onclick = b.onmouseover = b.onmouseout = null;
31603160- SetBlock(c);
31613161- StopMusic();
31623162- PlayAudio("losemusic");
37023702+37033703+var AppearCard = function (x, y, PlantClass, moveType, duration) {
37043704+ const id = "dCard" + Math.random();
37053705+ let style = `opacity:1;width:100px;height:120px;cursor:url(images/interface/Pointer.cur),pointer;clip:rect(auto,auto,60px,auto);left:${x}px;top:-1000px`;
37063706+ duration = duration || 1500;
37073707+ let endTop;
37083708+37093709+ if (moveType) {
37103710+ endTop = 0;
37113711+ oSym.addTask(1, MoveDropCard, [id, y, duration]);
37123712+ } else {
37133713+ endTop = y - 15 - 20;
37143714+ style += ";top:" + endTop + "px";
37153715+37163716+ oSym.addTask(1, DisappearCard, [id, duration]);
37173717+37183718+ // Parabolic drop animation
31633719 oSym.addTask(
31643164- 120,
31653165- () => {
31663166- PlayAudio("evillaugh");
31673167- },
31683168- []
31693169- );
31703170- oSym.addTask(
31713171- 7,
31723172- function (f, e, g) {
31733173- e.style.left = (g -= 330) + "px";
31743174- --f && oSym.addTask(7, arguments.callee, [f, e, g]);
31753175- },
31763176- [6, a, 0]
31773177- );
31783178- $User.HTML5
31793179- ? (function (g, h, e) {
31803180- var f = oAudio.evillaugh;
31813181- if (--e) {
31823182- g.style.backgroundPosition = ["top", "bottom"][h];
31833183- oSym.addTask(10, arguments.callee, [g, h ? 0 : 1, e]);
31843184- } else {
31853185- (g.style.backgroundPosition = "top"), (g.onclick = StartAdventure);
31863186- g.onmouseover = function () {
31873187- this.style.backgroundPosition = "bottom";
31883188- };
31893189- g.onmouseout = function () {
31903190- this.style.backgroundPosition = "top";
31913191- };
31923192- StopAudio("evillaugh");
31933193- SelectModal(d);
31943194- c.innerHTML = "";
31953195- }
31963196- })(b, 1, 50)
31973197- : (NewMusic("evillaugh"),
31983198- (function (f, g, e) {
31993199- if (--e) {
32003200- f.style.backgroundPosition = ["top", "bottom"][g];
32013201- oSym.addTask(10, arguments.callee, [f, g ? 0 : 1, e]);
32023202- } else {
32033203- (f.style.backgroundPosition = "top"), (f.onclick = StartAdventure);
32043204- f.onmouseover = function () {
32053205- this.style.backgroundPosition = "bottom";
32063206- };
32073207- f.onmouseout = function () {
32083208- this.style.backgroundPosition = "top";
32093209- };
32103210- SelectModal(d);
32113211- c.innerHTML = "";
37203720+ 1,
37213721+ function (cardId, curX, curY, xStep, ySteps, dir, stepsLeft, tick) {
37223722+ if (ArCard[cardId] && $(cardId)) {
37233723+ SetStyle($(cardId), {
37243724+ left: (curX += xStep * dir) + "px",
37253725+ top: (curY += Number(ySteps[0])) + "px",
37263726+ });
37273727+ ySteps.shift();
37283728+ --stepsLeft;
37293729+ if (stepsLeft > 0) {
37303730+ if (ySteps.length === 0) ySteps = [8, 16, 24, 32];
37313731+ oSym.addTask(tick, arguments.callee, [cardId, curX, curY, xStep, ySteps, dir, stepsLeft, ++tick]);
32123732 }
32133213- })(b, 1, 50));
32143214- }),
32153215- (oAudio = {}),
32163216- (PausedAudioArr = []),
32173217- (NewAudio = $User.HTML5
32183218- ? function (b) {
32193219- var a = b.source;
32203220- if (oAudio[a]) {
32213221- return;
32223733 }
32233223- var f = document.createElement("audio");
32243224- var c = b.autoplay;
32253225- var g = b.loop;
32263226- var m;
32273227- var h = { mp3: "audio/mpeg" };
32283228- var k = b.preload;
32293229- var l = b.callback;
32303230- var j = ["mp3"];
32313231- var e = j.length;
32323232- var d;
32333233- f.autoplay = !!c;
32343234- g &&
32353235- f.addEventListener(
32363236- "ended",
32373237- () => {
32383238- f.play();
32393239- },
32403240- false
32413241- );
32423242- while (e--) {
32433243- (m = document.createElement("source")).type = h[(d = j[e])];
32443244- m.src = "audio/" + a + "." + "mp3";
32453245- f.appendChild(m);
32463246- }
32473247- f.preload = k === undefined ? "auto" : ["auto", "meta", "none"][k];
32483248- f.muted = oS.Silence;
32493249- l && f.addEventListener("canplaythrough", l, false);
32503250- return (oAudio[a] = f);
32513251- }
32523252- : function () {}),
32533253- (PlayMusic = $User.HTML5
32543254- ? function (b) {
32553255- var a = oAudio[b];
32563256- if (a) {
32573257- try {
32583258- a.currentTime = 0;
32593259- } catch (c) {}
32603260- a.play();
32613261- } else {
32623262- NewMusic(b);
32633263- oAudio[b].play();
32643264- }
32653265- }
32663266- : function (a) {
32673267- NewMusic(a);
32683268- }),
32693269- (PlayAudioLegacy = $User.HTML5
32703270- ? function (c, a) {
32713271- var b = oAudio[c];
32723272- if (b) {
32733273- b.loop = !!a;
32743274- b.play();
32753275- } else {
32763276- NewAudio({ source: c, loop: !!a }).play();
32773277- }
32783278- }
32793279- : function () {}),
32803280- (PlayAudio = $User.HTML5
32813281- ? function (c, a) {
32823282- var b = oAudio[c];
37343734+ },
37353735+ [id, x, endTop, Math.floor(Math.random() * 4), [-32, -24, -16, -8], [-1, 1][Math.floor(Math.random() * 2)], 8, 2]
37363736+ );
37373737+ }
3283373832843284- if (!b) {
32853285- b = NewAudio({ source: c, loop: !!a });
32863286- oAudio[c] = b;
32873287- } else {
32883288- b.loop = !!a;
32893289- }
37393739+ ArCard[id] = {
37403740+ DID: id,
37413741+ PName: PlantClass,
37423742+ PixelTop: 600,
37433743+ CDReady: 1,
37443744+ SunReady: 1,
37453745+ top: endTop,
37463746+ HasChosen: false,
37473747+ Kind: 1,
37483748+ };
3290374932913291- b.currentTime = 0; // Restart to beginning
32923292- b.play();
32933293- }
32943294- : function () {}),
32953295- (PauseAudio = $User.HTML5
32963296- ? function (a) {
32973297- oAudio[a].pause();
32983298- }
32993299- : function () {}),
33003300- (StopMusic = $User.HTML5
33013301- ? function () {
33023302- var a = oAudio[oS.LoadMusic];
33033303- try {
33043304- a.currentTime = 0;
33053305- } catch (b) {}
33063306- a.pause();
33073307- }
33083308- : function () {}),
33093309- (StopAudio = $User.HTML5
33103310- ? function (b) {
33113311- var a = oAudio[b];
33123312- try {
33133313- a.currentTime = 0;
33143314- } catch (c) {}
33153315- try {
33163316- a.pause();
33173317- } catch (c) {}
33183318- }
33193319- : function () {}),
33203320- (AllAudioPaused = $User.HTML5
33213321- ? function () {
33223322- var a;
33233323- var b;
33243324- for (a in oAudio) {
33253325- b = oAudio[a];
33263326- !(b.paused || b.ended) && (PausedAudioArr.push(a), b.pause());
33273327- }
33283328- }
33293329- : function () {}),
33303330- (AllAudioPauseCanceled = $User.HTML5
33313331- ? function () {
33323332- var a = PausedAudioArr.length;
33333333- while (a--) {
33343334- oAudio[PausedAudioArr[a]].play();
33353335- }
33363336- PausedAudioArr.length = 0;
33373337- }
33383338- : function () {}),
33393339- (AllAudioMuted = function () {
33403340- var a;
33413341- for (a in oAudio) {
33423342- oAudio[a].muted = true;
37503750+ NewImg(id, PlantClass.prototype.PicArr[PlantClass.prototype.CardGif], style, $("dCardList"), {
37513751+ onclick(e) {
37523752+ const self = this;
37533753+ ClearChild($("MovePlant"), $("MovePlantAlpha"));
37543754+ CancelPlant();
37553755+ if (self.style) self.style.opacity = 0.5;
37563756+ ChosePlant(e, self.id);
37573757+ if (ArCard[self.id]) ArCard[self.id].HasChosen = true;
37583758+ },
37593759+ });
37603760+};
37613761+37623762+var MoveDropCard = function (id, targetY, duration) {
37633763+ const card = ArCard[id];
37643764+ const ele = $(id);
37653765+ if (card && ele) {
37663766+ if (!card.HasChosen && card.top < targetY - 52) {
37673767+ ele.style.top = (card.top += 2) + "px";
37683768+ oSym.addTask(5, MoveDropCard, [id, targetY, duration]);
37693769+ } else {
37703770+ DisappearCard(id, duration);
33433771 }
33443344- }),
33453345- (AllAudioMuteCanceled = function () {
33463346- var a;
33473347- for (a in oAudio) {
33483348- oAudio[a].muted = false;
33493349- }
33503350- }),
33513351- (CheckSilence = $User.HTML5
33523352- ? function (a) {
33533353- var b = a.checked ? 1 : 0;
33543354- b !== oS.Silence && (addCookie("JSPVZSilence", (oS.Silence = b)), b ? AllAudioMuted() : AllAudioMuteCanceled());
33553355- }
33563356- : function (a) {
33573357- var b = a.checked ? 1 : 0;
33583358- b !== oS.Silence && (addCookie("JSPVZSilence", (oS.Silence = b)), b ? PauseMusic() : NewMusic(oS.StartGameMusic));
33593359- }),
33603360- (AppearCard = function (h, f, e, a, t) {
33613361- // x, y, 植物id, 移动卡槽类型, 消失时间(默认 15s)
33623362- var b;
33633363- var d;
33643364- var g = "dCard" + Math.random();
33653365- var c = "opacity:1;width:100px;height:120px;cursor:url(images/interface/Pointer.cur),pointer;clip:rect(auto,auto,60px,auto);left:" + h + "px;top:-1000";
33663366- var t = t || 1500;
37723772+ }
37733773+};
37743774+37753775+var DisappearCard = function (id, duration) {
37763776+ const step = 5;
37773777+ let ele = $(id);
37783778+37793779+ (function tick(timeLeft) {
37803780+ if (!ArCard[id] || !ele) return;
3367378133683368- if (a) {
33693369- (d = 0), oSym.addTask(1, MoveDropCard, [g, f, t]);
37823782+ if (oS.Chose === 1 && oS.ChoseCard === id) {
37833783+ // Selected, do nothing
37843784+ } else if (timeLeft > 500) {
37853785+ ele.style.opacity = 1;
37863786+ } else if (timeLeft > 0) {
37873787+ ele.style.opacity = [1, 0.5][Math.ceil(timeLeft / 50) % 2];
37883788+ } else {
37893789+ delete ArCard[id];
37903790+ ClearChild(ele);
37913791+ return;
33703792 }
33713371- // 从天而降,反之抛物线掉落
33723372- else {
33733373- (d = f - 15 - 20),
33743374- (c += ";top:" + d + "px"),
33753375- oSym.addTask(1, DisappearCard, [g, t]),
33763376- oSym.addTask(
33773377- 1,
33783378- function (q, p, n, j, l, k, m, i) {
33793379- if (ArCard[q] && $(q)) {
33803380- SetStyle($(q), {
33813381- left: (p += j * k) + "px",
33823382- top: (n += Number(l[0])) + "px",
33833383- });
33843384- l.shift();
33853385- --m;
33863386- m > 0 && (l.length === 0 && (l = [8, 16, 24, 32]), oSym.addTask(i, arguments.callee, [q, p, n, j, l, k, m, ++i]));
33873387- }
33883388- },
33893389- [g, h, d, Math.floor(Math.random() * 4), [-32, -24, -16, -8], [-1, 1][Math.floor(Math.random() * 2)], 8, 2]
33903390- );
33913391- } // 开始记时,确定抛物线,与阳光部分相似故压缩
3392379333933393- ArCard[g] = {
33943394- DID: g,
33953395- PName: e,
33963396- PixelTop: 600,
33973397- CDReady: 1,
33983398- SunReady: 1,
33993399- top: d,
34003400- HasChosen: false,
34013401- Kind: 1,
34023402- }; // 生成卡片数据,是否被点击过
34033403- NewImg(g, e.prototype.PicArr[e.prototype.CardGif], c, $("dCardList"), {
34043404- // 生成卡片 ele
34053405- onclick(g) {
34063406- var self = this;
34073407- var { style } = self;
34083408- var { id } = self;
34093409- ClearChild($("MovePlant"), $("MovePlantAlpha")),
34103410- CancelPlant(),
34113411- style && (style.opacity = 0.5),
34123412- ChosePlant(g, id),
34133413- ArCard[id] && (ArCard[id].HasChosen = true);
34143414- },
34153415- });
34163416- }),
34173417- (MoveDropCard = function (c, b, t) {
34183418- // 掉落目标
34193419- var a = ArCard[c];
34203420- var ele = $(c);
34213421- a && ele && (!a.HasChosen && a.top < b - 52 ? ((ele.style.top = (a.top += 2) + "px"), oSym.addTask(5, MoveDropCard, [c, b, t])) : DisappearCard(c, t));
34223422- }),
34233423- (DisappearCard = function (d, r) {
34243424- var q = 5;
34253425- var e = $(d);
34263426- var f = function (t) {
34273427- switch (true) {
34283428- case !ArCard[d] || !e:
34293429- return; // 卡片已经消失,不做处理
34303430- case oS.Chose === 1 && oS.ChoseCard === d:
34313431- break; // 选中
34323432- case t > 500:
34333433- e.style.opacity = 1;
34343434- break; // 未到闪烁时间
34353435- case t > 0:
34363436- e.style.opacity = [1, 0.5][Math.ceil(t / 50) % 2];
34373437- break; // 闪烁
34383438- default:
34393439- delete ArCard[d], ClearChild(e);
34403440- return;
34413441- }
34423442- (e = $(d)), oSym.addTask(q, arguments.callee, [t - q]);
34433443- };
34443444- f(r);
34453445- });
37943794+ ele = $(id);
37953795+ oSym.addTask(step, tick, [timeLeft - step]);
37963796+ })(duration);
37973797+};
3446379834473799NewEle("dTitle", "div", 0, 0, $("dBody"));
38003800+38013801+const allPlantsStringArray = [
38023802+ // for alamanac
38033803+ "oPeashooter",
38043804+ "oSunFlower",
38053805+ "oCherryBomb",
38063806+ "oWallNut",
38073807+ "oPotatoMine",
38083808+ "oSnowPea",
38093809+ "oChomper",
38103810+ "oRepeater",
38113811+ "oPuffShroom",
38123812+ "oSunShroom",
38133813+ "oFumeShroom",
38143814+ "oGraveBuster",
38153815+ "oHypnoShroom",
38163816+ "oScaredyShroom",
38173817+ "oIceShroom",
38183818+ "oDoomShroom",
38193819+ "oLilyPad",
38203820+ "oSquash",
38213821+ "oThreepeater",
38223822+ "oTangleKlep",
38233823+ "oJalapeno",
38243824+ "oSpikeweed",
38253825+ "oTorchwood",
38263826+ "oTallNut",
38273827+ "oCactus",
38283828+ "oPlantern",
38293829+ "oSplitPea",
38303830+ "oStarfruit",
38313831+ "oPumpkinHead",
38323832+ "oFlowerPot",
38333833+ "oCoffeeBean",
38343834+ "oGarlic",
38353835+ "oSeaShroom",
38363836+ "oOxygen",
38373837+ "ostar",
38383838+ "oTTS",
38393839+ "oGun",
38403840+ "oSeaAnemone",
38413841+ "oGatlingPea",
38423842+ "oGloomShroom",
38433843+ "oTwinSunflower",
38443844+ "oSpikerock",
38453845+ "oTenManNut",
38463846+ "oSnowRepeater",
38473847+ "oCattail",
38483848+ "oLotusRoot",
38493849+ "oIceFumeShroom",
38503850+ "oLaserBean",
38513851+ "oBigChomper",
38523852+ "oFlamesMushroom",
38533853+ "oBalloon",
38543854+];
38553855+38563856+const allPlantsArray = () => {
38573857+ // also for almanac
38583858+ const arr = [];
38593859+ for (let i = 0; i < allPlantsStringArray.length; i++) {
38603860+ arr.push(window[allPlantsStringArray[i]]);
38613861+ }
38623862+ return arr;
38633863+};
38643864+38653865+const izombiePlantsMap = [
38663866+ // for izombie (DONT CHANGE THE ORDER!!!!!!)
38673867+ "oPeashooter",
38683868+ "oSunFlower",
38693869+ "oCherryBomb",
38703870+ "oWallNut",
38713871+ "oPotatoMine",
38723872+ "oSnowPea",
38733873+ "oChomper",
38743874+ "oRepeater",
38753875+ "oPuffShroom",
38763876+ "oSunShroom",
38773877+ "oFumeShroom",
38783878+ "oGraveBuster",
38793879+ "oHypnoShroom",
38803880+ "oScaredyShroom",
38813881+ "oIceShroom",
38823882+ "oDoomShroom",
38833883+ "oLilyPad",
38843884+ "oILilyPad",
38853885+ "oSquash",
38863886+ "oThreepeater",
38873887+ "oTangleKlep",
38883888+ "oJalapeno",
38893889+ "oSpikeweed",
38903890+ "oTorchwood",
38913891+ "oTallNut",
38923892+ "oCactus",
38933893+ "oPlantern",
38943894+ "oSplitPea",
38953895+ "oStarfruit",
38963896+ "oPumpkinHead",
38973897+ "oFlowerPot",
38983898+ "oCoffeeBean",
38993899+ "oGarlic",
39003900+ "oSeaShroom",
39013901+ "oOxygen",
39023902+ "ostar",
39033903+ "oTTS",
39043904+ "oGun",
39053905+ "oSeaAnemone",
39063906+ "oGatlingPea",
39073907+ "oGloomShroom",
39083908+ "oTwinSunflower",
39093909+ "oSpikerock",
39103910+ "oTenManNut",
39113911+ "oSnowRepeater",
39123912+ "oCattail",
39133913+ "oLotusRoot",
39143914+ "oIceFumeShroom",
39153915+ "oLaserBean",
39163916+ "oBigChomper",
39173917+ "oFlamesMushroom",
39183918+];
+28-1
game/js/Custom.js
···200200 }, 100);
201201}
202202203203-checkInterval2;
203203+checkInterval2();
204204205205let playingSounds = [];
206206function PlaySound2(path, name, loop = false) {
···231231 }
232232 });
233233}
234234+235235+// new save system
236236+237237+$User.Visitor.SaveLvl = 1;
238238+$User.Visitor.SaveLvlCallBack = function (o) {
239239+ /*
240240+ o is an object with these properties:
241241+ - Lvl: level name (number for adventure mode, text for others)
242242+ - SunNum: remaining sun after completing the level
243243+ - UserName: player's name
244244+ - T: time taken to complete the level (divide by 100 to get seconds)
245245+ */
246246+ // check if o.Lvl is valid and is in the whitelist
247247+ if (!o.Lvl || !saveWhitelist.includes(o.Lvl)) {
248248+ return;
249249+ }
250250+ // save logic
251251+ let levels = {};
252252+ // check if "levels" exists in localStorage
253253+ if (localStorage.getItem("levels")) {
254254+ levels = JSON.parse(localStorage.getItem("levels"));
255255+ }
256256+ // add the level to the levels object if it doesn't exist
257257+ if (!levels[o.Lvl]) {
258258+ levels[o.Lvl] = o;
259259+ }
260260+};
···99 property="og:description"
1010 content="Play Plants vs Zombies Modded here for Free - A tower defense game created by PopCap Games and released on May 5, 2009. Click to Play now! Mod by ROBLNET13 on Github."
1111 />
1212- <meta property="og:url" content="https://pvzm.net/game/iframe.html" />
1212+ <meta property="og:url" content="https://pvzm.net/game" />
1313 <meta property="og:site_name" content="ROBlNET13" />
1414 <meta property="og:image" content="https://pvzm.net/game/images/gamethumbnail5.png" />
1515 <meta property="og:image:alt" content="Plants vs. Zombies - MODDED" />
···2020 <meta name="twitter:description" content="Play Plants vs. Zombie Modded here for Free - Mod by ROBlNET13 on Github." />
2121 <meta name="twitter:image" content="https://pvzm.net/game/images/gamethumbnail5.png" />
2222 <meta name="google-site-verification" content="fJLVF6HtXXMM2ag1_bMLijwLhOVj9XWFtUb8KlkdS0I" />
2323- <meta http-equiv="refresh" content="0; url=game/iframe.html" />
2323+ <meta http-equiv="refresh" content="0; url=/game" />
2424 </head>
2525</html>