@korial29/tiny-fps 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.js +21 -13
- package/dist/local.js +1 -1
- package/dist/server.js +285 -210
- package/dist/types/client/effects.d.ts +23 -0
- package/dist/types/client/lights.d.ts +8 -0
- package/dist/types/client/render.d.ts +20 -1
- package/dist/types/shared/types.d.ts +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -200,13 +200,14 @@ Keys are read by their position (`KeyboardEvent.code`), so on an AZERTY keyboard
|
|
|
200
200
|
Parity with the js13k game is tracked in [`docs/PARITY.md`](docs/PARITY.md).
|
|
201
201
|
|
|
202
202
|
- [x] Multiplayer over WebSocket, or between tabs of one browser with no server
|
|
203
|
-
- [x] Doom-style sector maps: steps, pits, low ceilings, balconies, procedural brick, tile, lava and
|
|
203
|
+
- [x] Doom-style sector maps: steps, pits, low ceilings, balconies, eight procedural materials (brick, tile, lava, stone, metal, wood, moss, grating) with bump mapping and per-material highlights, each level themed
|
|
204
204
|
- [x] Client-side prediction, exact to the bit, and the other players interpolated
|
|
205
205
|
- [x] Chaingun with lag-compensated hitscan, spinning barrels, recoil, muzzle flash, head bob, sparks
|
|
206
206
|
- [x] Walkers and flyers: patrol, sight cone, alert, chase, bullets, melee, gibs and explosions
|
|
207
207
|
- [x] Health, hit cooldown, death and respawn, health drops, team keys and barred gates
|
|
208
208
|
- [x] Five levels, the goal and the way back, hard mode on the next run, end screen with the time
|
|
209
209
|
- [x] Flashlights with shadow maps, lit muzzle flashes, explosion, hit, bullet, goal and exit lights
|
|
210
|
+
- [x] Atmosphere: a light colour per room, a fog colour per level, flickering lava light, dust in the flashlight beam, smoke after explosions
|
|
210
211
|
- [x] Sound: a jsfxr-style synthesiser (shot, boom, hit, collect, clock, burst), stereo by position, a looped music; M mutes
|
|
211
212
|
- [x] HUD and screens: health bar, damage vignette and pickup fades, low-health pulse and heartbeat, title and pause screen, death countdown, end screen with each player's kills and deaths
|
|
212
213
|
- [x] Shadow DOM, zero runtime dependencies, size-gated in CI
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,37 @@
|
|
|
1
|
-
var e=.4,t=1.8,n=1.6,r=1.55,i=.5,a=.02,o=1.8,s=.45,c=.9,l=.15,u={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,FIRE:32},d={WALKER:0,FLYER:1},f={DIE:0,HURT:1,BOOM:2,SWING:3},p={HEALTH:0,KEY_RED:1,KEY_BLUE:2,KEY_YELLOW:3},m={HUNT:0,RETURN:1},h={BRICK:0,TILE:1,LAVA:2,STONE:3},g=e=>{let t=(e,t,n,r)=>`${e},${t},${n},${r}`,n=/* @__PURE__ */ new Map;e.sectors.forEach(({pts:e},r)=>e.forEach(([i,a],o)=>n.set(t(i,a,...e[(o+1)%e.length]),r)));let r={map:e,edges:e.sectors.flatMap(({pts:e},r)=>e.map(([i,a],o)=>{let[s,c]=e[(o+1)%e.length];return{ax:i,az:a,bx:s,bz:c,front:r,back:n.get(t(s,c,i,a))??-1}})),barred:/* @__PURE__ */ new Set};return _(r,0,m.HUNT),r},_=({map:e,barred:t},n,r)=>{t.clear(),e.gates?.forEach(e=>n&1<<e.key||t.add(e.sector)),e.exit!==void 0&&r===m.HUNT&&t.add(e.exit)},v=({pts:e},t,n)=>e.every(([r,i],a)=>{let[o,s]=e[(a+1)%e.length];return(o-r)*(n-i)-(s-i)*(t-r)>=0}),y=({map:e},t,n)=>e.sectors.findIndex(e=>v(e,t,n)),b=({map:e,edges:t},[n,r,i],[a,o,s])=>{let[c,l]=[a-n,s-i];return t.some(t=>{let[a,s]=[t.bx-t.ax,t.bz-t.az],u=c*s-l*a;if(!u)return!1;let d=((t.ax-n)*s-(t.az-i)*a)/u,f=((t.ax-n)*l-(t.az-i)*c)/u;if(d<=0||d>=1||f<0||f>1)return!1;if(t.back<0)return!0;let[p,m]=[e.sectors[t.front],e.sectors[t.back]],h=r+d*(o-r);return h<Math.max(p.floor,m.floor)||h>Math.min(p.ceil,m.ceil)})},x=(e,[t,n,r,i],a,o,s,c,l,u)=>Array.from({length:s},(d,f)=>{let[p,m]=e?[n,i]:[t,r],[h,g,_]=[p+f*(m-p)/s,p+(f+1)*(m-p)/s,+(a+f*o).toFixed(1)];return e?[t,h,r,g,_,c,l,u]:[h,n,g,i,_,c,l,u]}),[S,C,w,T]=[p.HEALTH,p.KEY_RED,p.KEY_BLUE,p.KEY_YELLOW],E=Math.PI/4,D=(e,t,[n,r,i],a,o,s,c)=>{let l=t.map(([e,t,n,r])=>[[e,t],[n,t],[n,r],[e,r]]),u=[...new Map(l.flat().map(e=>[`${e}`,e])).values()];return{name:e,sectors:t.map(([,,,,e,t,n=`103`,r],i)=>({pts:l[i].flatMap((e,t,n)=>{let r=n[(t+1)%4],i=t=>(t[0]-e[0])*(r[0]-e[0])+(t[1]-e[1])*(r[1]-e[1]);return[e,...u.filter(t=>(r[0]-e[0])*(t[1]-e[1])===(r[1]-e[1])*(t[0]-e[0])&&i(t)>0&&i(t)<(r[0]-e[0])**2+(r[1]-e[1])**2).sort((e,t)=>i(e)-i(t))]}),floor:e,ceil:t,ft:+n[0],wt:+n[1],ct:+n[2],light:r})),spawns:Array.from({length:16},(e,t)=>[n+t%4*2,r+(t>>2)*2,i*E]),monsters:[...a.map(([e,t,n])=>[e,t,n*E,d.WALKER]),...o.map(([e,t,n])=>[e,t,n*E,d.FLYER])],items:s,gates:t.flatMap(([,,,,,,,,e],t)=>e?[{sector:t,key:e}]:[]),goal:c,exit:0}},O=[D(`Warm-up`,[[0,0,10,10,0,4,`103`],[10,4,22,6,0,2.8,`333`,.6],[22,0,38,14,0,6,`303`],...x(0,[38,4,42,10],.4,.4,4,6,`333`),[42,2,52,12,2,6,`103`,.9],...x(1,[46,12,48,22],1.6,-.4,4,4.8,`000`,.7),[38,22,56,36,0,6,`113`]],[2,2,6],[[28,4,3],[34,10,4],[48,6,4],[44,30,0]],[[30,8,0],[52,28,2]],[[26,12,S],[50,10,S],[40,34,S]],[54,34]),D(`Foundry`,[[0,14,10,26,0,4,`103`],[10,22,20,24,0,2.8,`333`,.6],[24,8,28,16,0,9,`303`],[20,16,28,30,0,9,`303`],...x(1,[20,8,24,16],2,-.4,5,9,`333`),[28,8,42,18,-1.6,9,`203`,.9],...x(1,[28,18,42,21],-1.2,.4,3,9,`333`),[28,21,50,30,0,9,`303`],[42,8,50,21,0,9,`303`],[20,0,50,8,2.4,9,`103`,.8],[50,14,51,17,0,3.5,`000`,1,C],[51,8,59,26,0,7,`113`,.6],[59,8,67,26,.4,7,`013`,.8],[57,26,59,36,0,4.8,`000`,.7],[50,36,68,50,0,7,`013`]],[2,16,6],[[46,14,2],[36,26,0],[38,4,2],[56,12,4],[62,20,2],[60,44,0]],[[35,13,0],[60,14,4],[58,42,6]],[[24,26,S],[24,4,S],[64,10,S],[52,46,S],[46,4,C]],[66,48]),D(`Cistern`,[[0,20,10,32,0,4,`103`],[10,26,20,28,0,2.8,`333`,.6],[20,14,56,26,0,11,`133`,.9],[20,26,34,32,0,11,`133`,.9],[34,26,42,32,-.4,11,`233`],[42,26,56,32,0,11,`133`,.9],[20,32,56,44,0,11,`133`,.9],[36,44,38,54,0,1.9,`333`,.45],[30,54,46,68,0,5,`000`,.7],[56,28,57,31,0,4,`000`,1,C],...x(0,[57,26,65,32],.4,.4,8,10,`333`,.8),[65,22,81,36,3.6,11,`103`],[71,36,74,37,3.6,7,`000`,1,w],[71,37,74,48,3.6,6.4,`333`,.6],[62,48,82,64,3.6,10,`213`]],[2,22,6],[[30,18,4],[50,20,4],[30,40,0],[50,40,0],[36,60,2],[42,64,0],[76,28,2],[70,58,0]],[[26,24,0],[48,22,0],[36,40,2],[72,56,4]],[[24,40,S],[52,42,S],[44,57,S],[68,34,S],[64,62,S],[38,66,C],[79,24,w]],[80,62]),D(`Loop`,[[0,44,10,56,0,4,`103`],[10,49,20,51,0,2.8,`333`,.6],[20,30,52,40,0,9,`303`],[20,48,52,58,0,9,`303`,.9],[20,40,32,48,0,9,`303`],[40,40,52,48,0,9,`303`],[20,22,49,30,3.2,9,`113`,.8],[34,58,36,66,0,2.8,`333`,.5],[26,66,46,84,0,5,`000`,.5],[52,42,53,45,0,4,`000`,1,C],[53,36,64,54,0,6,`133`,.8],[64,36,70,54,.4,6,`233`,.8],[60,35,63,36,0,4,`000`,1,w],[57,12,77,35,0,8,`013`,.9],[56,24,57,27,0,4,`000`,1,T],...x(0,[49,22,56,30],2.8,-.4,7,9,`333`,.8),[12,24,20,28,3.2,6,`333`,.6],[0,10,12,34,3.2,9,`113`]],[2,46,6],[[30,36,4],[44,36,2],[40,52,0],[40,26,4],[30,74,6],[42,78,2],[56,40,6],[64,50,2],[62,18,4],[72,28,2],[6,22,0]],[[28,48,0],[46,44,4],[36,72,0],[60,45,6],[68,22,4]],[[24,54,S],[24,26,S],[44,80,S],[68,38,S],[74,14,S],[36,82,C],[68,52,w],[74,32,T]],[6,13]),D(`Citadel`,[[0,60,10,72,0,4,`103`],[10,65,24,67,0,2.8,`333`,.6],[24,48,56,84,0,12,`313`],[27,40,31,48,0,3.4,`000`,.5],[24,16,34,40,0,12,`303`,.9],...x(0,[34,16,40,26],-.4,-.4,3,12,`233`),[34,26,40,30,0,12,`333`],...x(0,[34,30,40,40],-.4,-.4,3,12,`233`),[40,16,60,40,0,12,`303`,.9],[60,27,61,30,0,4,`000`,1,T],[61,10,101,16,0,14,`103`],[61,40,101,46,0,14,`103`],[61,16,69,40,0,14,`103`],[93,16,101,40,0,14,`103`],[69,16,93,20,.4,14,`233`,.9],[69,36,93,40,.4,14,`233`,.9],[69,20,73,36,.4,14,`233`,.9],[89,20,93,36,.4,14,`233`,.9],[73,20,89,36,.8,14,`333`],[101,26,111,28,0,3.2,`333`,.6],[111,16,131,40,0,8,`113`],[56,66,57,69,0,4,`000`,1,C],[57,56,75,80,0,12,`000`,.7],...x(0,[75,60,85,72],.4,.4,5,12,`333`,.8),[85,52,101,80,2.4,12,`013`],[38,84,42,85,0,4,`000`,1,w],[38,85,42,95,0,1.9,`000`,.4],[28,95,56,115,0,6,`030`,.6]],[2,62,6],[[34,56,4],[50,56,2],[36,76,0],[46,20,4],[54,34,2],[66,60,2],[66,76,0],[92,60,2],[34,100,4],[50,108,2],[70,13,4],[92,13,2],[70,43,0],[92,43,6]],[[30,70,0],[46,68,0],[50,28,0],[76,26,0],[86,30,0],[81,22,0]],[[30,80,S],[56,36,S],[60,78,S],[50,112,S],[64,13,S],[98,43,S],[114,38,S],[52,22,C],[95,66,w],[42,110,T]],[127,36])],k=65536/(2*Math.PI),A=e=>Math.round(e*k)&65535,j=e=>Math.max(-32768,Math.min(32767,Math.round(e))),M=e=>j(e*1e4),N=e=>e/1e4,P=e=>e/k,F=(e=0)=>Math.round(e*256)&16777215,I=e=>({...e,yaw:P(A(e.yaw)),pitch:N(M(e.pitch)),...e.view!==void 0&&{view:F(e.view)/256}}),ee=e=>{let t=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(11));t.setUint8(0,1),t.setUint16(1,e.seq&65535),t.setUint8(3,e.keys&255),t.setUint16(4,A(e.yaw)),t.setInt16(6,M(e.pitch));let n=F(e.view);return t.setUint16(8,n>>8),t.setUint8(10,n&255),t.buffer},te=e=>{if(e.byteLength<7)return null;let t=new DataView(e),n=t.getUint8(3);if(t.getUint8(0)!==2)return null;let r=7+25*n,[i,a,o,s,c]=[14,16,13,14,14].map(n=>{if(e.byteLength<=r)return null;let i=t.getUint8(r),a=r+1;return r=a+n*i,[a,i]});if(!i||!a||!o||!s||!c||e.byteLength!==r)return null;let l=([e,t],n,r)=>Array.from({length:t},(t,i)=>r(e+i*n)),u=[];for(let e=0;e<n;e++){let n=7+e*25;u.push({id:t.getUint8(n),x:t.getFloat32(n+1),y:t.getFloat32(n+5),z:t.getFloat32(n+9),vy:t.getFloat32(n+13),yaw:P(t.getUint16(n+17)),pitch:N(t.getInt16(n+19)),ack:t.getUint16(n+21),cool:t.getUint8(n+23)>>1,ground:(t.getUint8(n+23)&1)==1,hp:t.getUint8(n+24)})}return{tick:t.getUint16(1),players:u,shots:l(i,14,e=>({id:t.getUint8(e),x:t.getFloat32(e+1),y:t.getFloat32(e+5),z:t.getFloat32(e+9),hit:t.getUint8(e+13)===255?-1:t.getUint8(e+13)})),monsters:l(a,16,e=>({id:t.getUint8(e),kind:t.getUint8(e+1)&1,chase:!!(t.getUint8(e+1)&2),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10),yaw:P(t.getUint16(e+14))})),bullets:l(o,13,e=>({id:t.getUint8(e),x:t.getFloat32(e+1),y:t.getFloat32(e+5),z:t.getFloat32(e+9)})),events:l(s,14,e=>({type:t.getUint8(e),id:t.getUint8(e+1),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10)})),level:t.getUint8(4),hard:(t.getUint8(5)&1)==1,phase:t.getUint8(5)>>1&1,keys:t.getUint8(6),items:l(c,14,e=>({id:t.getUint8(e),kind:t.getUint8(e+1),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10)}))}},L=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},R=44100,z={SHOT:0,BOOM:1,HIT:2,COLLECT:3,CLOCK:4,BURST:5,HEART:6},B=([e,t,n,r,i,a,o,s,c,l,u],d)=>{let f=new Float32Array(Math.ceil((r+i+a)*R)),p=0,m=0,h=0,g=()=>{d=d+1831565813|0;let e=Math.imul(d^d>>>15,1|d);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/2**31-1};for(let d=0;d<f.length;d++){let _=d/R;p+=t*2**(n*_)*(_>c?l:1)*(1+o*Math.sin(_*44))/R,p>=1&&(p%=1,h=g());let v=e==3?h:e==2?Math.sin(p*2*Math.PI):e?1-2*p:p<.5?1:-1;m+=(v-m)*s;let y=_<r?_/r:_<r+i?1:((r+i+a-_)/a)**2;f[d]=m*y*u}return f},ne=[[[3,7e3,-.5,.002,0,.06,0,.6,0,1,.8],[0,220,-5,.002,0,.075,0,.3,0,1,.5]],[[3,500,-1.5,.004,.05,.8,0,.1,0,1,2.2],[2,110,-1.5,.004,.05,.6,0,1,0,1,.8]],[[1,160,-1.5,.003,.04,.22,.2,.5,0,1,.6],[0,83,-1,.003,.04,.22,0,.3,0,1,.4],[3,3e3,0,.002,0,.12,0,.4,0,1,.5]],[[2,880,.3,.005,.06,.4,0,1,.09,1.5,.8],[2,1760,.3,.005,.06,.35,0,1,.09,1.5,.3]],[[3,4e3,0,.001,0,.025,0,.5,0,1,.7],[2,1300,-1,.001,0,.04,0,1,0,1,.5]],[[3,1200,-1,.002,0,.14,0,.45,0,1,.7],[0,3200,-1,.002,0,.05,0,1,.025,.7,.2]],[[2,55,-1,.01,.01,.12,0,1,0,1,.9],[2,110,-1,.01,0,.08,0,1,0,1,.3],[2,48,-1,.01,.01,.14,0,1,0,1,.6,.22],[2,96,-1,.01,0,.09,0,1,0,1,.2,.22]]],re=e=>{let t=ne[e].map((t,n)=>[B(t,e*9+n),Math.round((t[11]??0)*R)]);return Float32Array.from({length:Math.max(...t.map(([e,t])=>t+e.length))},(e,n)=>Math.tanh(t.reduce((e,[t,r])=>e+(t[n-r]??0),0)))},V=R*60/108,ie=V/4,ae=4,oe=[2,150,-6,.002,0,.25,0,1,0,1,1],se=[3,9e3,0,.002,0,.15,0,.5,0,1,.5],ce=[3,3e4,0,.001,0,.04,0,.7,0,1,.15],le=()=>{let e=new Float32Array(V*4*ae),t={},n=(n,r)=>(t[String(r)]??=B(r,1)).forEach((t,r)=>e[(n*ie+r)%e.length]+=t),r=e=>55*2**(e/12),i=[0,0,-4,-5],a=[0,0,12,0,0,7,12,7];for(let e=0;e<64;e++){let t=e%16;if(`x.......x.x.....`[t]==`x`&&n(e,oe),`....x.......x...`[t]==`x`&&n(e,se),t%2==0){n(e,ce);let o=i[e>>4]+a[t>>1];n(e,[1,r(o),0,.005,.08,.18,0,.15,0,1,.6])}}[15,12,10,19,17,15].forEach((e,t)=>n([18,24,28,50,54,60][t],[2,r(e+24),0,.02,.1,.6,.01,1,0,1,.5]));let o=e.reduce((e,t)=>Math.max(e,Math.abs(t)),0);return e.map(e=>e/o*.35)},ue=40,de=24,fe=.5,pe=`tiny-fps:muted`,me=()=>{let e=!1;return{unlock:()=>{},listen:()=>{},play:()=>{},mute:t=>{e=t},get muted(){return e},destroy:()=>{}}},he=()=>{let e;try{e=new AudioContext}catch{return me()}let t=(t,n=1)=>{let r=e.createGain();return r.gain.value=n,r.connect(t),r},n=t(e.destination),r=t(n,fe),i=[],a=/* @__PURE__ */ new Set,o=[0,0,0],s=0,c=!1,l=t=>{let n=e.createBuffer(1,t.length,R);return n.getChannelData(0).set(t),n},u=t=>{let n=e.createBufferSource();return n.buffer=t,n};return{unlock(){if(e.resume().catch(()=>{}),!i.length){for(let e of Object.values(z))i[e]=l(re(e));let e=u(l(le()));e.loop=!0,e.connect(r),e.start()}},listen(e,t){[o,s]=[e,t]},play(r,c,l=1){let d=0,f=l;if(c){let[e,t,n]=c.map((e,t)=>e-o[t]),r=Math.hypot(e,t,n);f=Math.max(0,1-r/ue)**2*l,d=(e*Math.cos(s)-n*Math.sin(s))/Math.max(r,1)}let p=i[r];if(!p||!f)return;if(a.size>=de){let e=[...a].reduce((e,t)=>t.vol<e.vol?t:e);if(e.vol>=f)return;e.src.stop(),a.delete(e)}let m=u(p),h=e.createStereoPanner();h.pan.value=d,m.connect(h).connect(t(n,f));let g={vol:f,src:m};a.add(g),m.onended=()=>a.delete(g),m.start()},mute(t){c=t,n.gain.setTargetAtTime(+!t,e.currentTime,.05)},get muted(){return c},destroy:()=>void e.close().catch(()=>{})}},ge=(e,{type:t,id:n,x:r,y:i,z:a},o)=>{let s=[r,i,a];t==f.DIE?e.play(z.BOOM,s):t==f.BOOM?e.play(z.BURST,s):t==f.HURT&&e.play(z.HIT,n==o?void 0:s)},_e=e=>{let t=0;return(n,r)=>{n&&r>=t&&(t=r+1e3,e.play(z.CLOCK))}},ve=e=>{let t=-1/0;return(n,r)=>{if(n<1||n>3)return t=-1/0,0;let i=n>1?800:500;return r-t>=i&&(t=r,e.play(z.HEART,void 0,n>1?.6:1)),1-(r-t)/i}},ye=()=>{try{return localStorage.getItem(pe)==`1`}catch{return!1}},be=e=>{e.mute(!e.muted);try{localStorage.setItem(pe,e.muted?`1`:`0`)}catch{}return e.muted},xe=1/60,H=Math.PI*2,Se=1e-6,Ce=.01,we=e=>(e%H+H)%H,Te=e=>[-Math.sin(e),-Math.cos(e)],Ee=Math.fround,De=(e,t,n)=>Math.min(Math.max(e,t),n),Oe=({map:e,barred:t},n,r,i,a)=>{if(n.back<0||t.has(n.back))return!0;let o=e.sectors[n.front],s=e.sectors[n.back],c=Math.min(o.ceil,s.ceil);return s.floor>r+a+Ce||c-Math.max(o.floor,s.floor)<i-Ce||c<r+i-Ce},ke=(e,t,n,r,i)=>{let a=(n-Se)**2;for(let o=0;o<4;o++){let o=0,s=0,c=0;for(let l of t.edges){let u=l.bx-l.ax,d=l.bz-l.az,f=e.x-l.ax,p=e.z-l.az;if(u*p-d*f<0)continue;let m=De((f*u+p*d)/(u*u+d*d),0,1),h=f-m*u,g=p-m*d,_=h*h+g*g;if(_>=a)continue;let v=Math.sqrt(_);if(n-v<=o||!Oe(t,l,e.y,r,i))continue;o=n-v;let y=v||Math.hypot(u,d);s=(v?h:-d)/y*o,c=(v?g:u)/y*o}if(!o)return;e.x+=s,e.z+=c}},Ae=(e,t,n,r,i,a,o)=>{let{map:s,edges:c}=e,l=Math.max(y(e,t,n),0),{floor:u,ceil:d}=s.sectors[l],f=(i-Se)**2;for(let i of c){if(i.front!==l||i.back<0)continue;let c=i.bx-i.ax,p=i.bz-i.az,m=t-i.ax,h=n-i.az,g=De((m*c+h*p)/(c*c+p*p),0,1);if((m-g*c)**2+(h-g*p)**2<f&&!Oe(e,i,r,a,o)){let e=s.sectors[i.back];u=Math.max(u,e.floor),d=Math.min(d,e.ceil)}}return[u,d]},je=(n,r,a,o,s)=>{n.x+=r,n.z+=a,ke(n,s,e,t,i);let[c,l]=Ae(s,n.x,n.z,n.y,e,t,i);n.ground&&o&&(n.vy=7);let u=n.vy-20*xe;n.y+=(n.vy+u)/2*xe,n.vy=u,n.ground=!1,n.y+1.8>l&&(n.y=l-t,n.vy=Math.min(n.vy,0)),(n.vy<=0?n.y<=c+Ce:n.y<c)&&(n.y=c,n.vy<=0&&(n.vy=0,n.ground=!0)),n.x=Ee(n.x),n.y=Ee(n.y),n.z=Ee(n.z),n.vy=Ee(n.vy)},Me=(e,t,n)=>{let i=(t.keys&u.FIRE)!==0;e.cool=Math.max(0,e.cool-1),e.yaw=we(t.yaw),e.pitch=Math.max(-1.55,Math.min(r,t.pitch));let a=(t.keys&u.FORWARD?1:0)-(t.keys&u.BACK?1:0),o=(t.keys&u.RIGHT?1:0)-(t.keys&u.LEFT?1:0),s=6*xe*(i?.5:1)/(Math.hypot(a,o)||1),[c,l]=Te(e.yaw);return je(e,(c*a-l*o)*s,(l*a+c*o)*s,(t.keys&u.JUMP)!==0,n),i&&!e.cool?(e.cool=5,!0):!1},Ne=.55,Pe=6,Fe=(e,t,n=[0,0,0])=>{let r=[];for(let i=1;i<e.length;i++){let[[a,o],[s,c]]=[e[i-1],e[i]],l=Math.hypot(s-a,c-o);if(!l)continue;let[u,d]=[(c-o)/l,-(s-a)/l],f=(e,i,a)=>{let[o,s]=[Math.cos(e*H/t),Math.sin(e*H/t)];r.push(n[0]+i*o,n[1]+i*s,n[2]-a,u*o,u*s,-d)};for(let e=0;e<t;e++)for(let[t,n,r]of[[e,a,o],[e+1,a,o],[e+1,s,c],[e,a,o],[e+1,s,c],[e,s,c]])f(t,n,r)}return r},Ie=e=>{let t=[];for(let n=0;n<Pe;n++){let r=n*H/Pe;t.push(...Fe([[0,0],[.02,0],[.02,.45],[.014,.45],[.014,.55],[0,.55]],e,[Math.cos(r)*.05,Math.sin(r)*.05,0]))}return{barrels:t,body:Fe([[0,-.3],[.08,-.3],[.09,-.26],[.09,0],[.075,0],[.075,.1],[.03,.1],[.03,.4],[0,.4]],e)}},U=(e,t,n=0)=>{let[r,i,a,o,s,c]=[e,t,n].flatMap(e=>[Math.sin(e),Math.cos(e)]),l=[i,0,-r],u=[r*a,o,i*a];return[l.map((e,t)=>e*c-u[t]*s),u.map((e,t)=>e*c+l[t]*s),[-r*o,a,-i*o]]},W=(e,[t,n,r],[i,a,o],s,c,l=-1)=>{let[u,d]=[Math.sin(s),Math.cos(s)],f=(e,t)=>[e*d+t*u,-e*u+t*d];for(let s=0;s<3;s++)for(let u of[-1,1]){let[d,p]=[(s+1)%3,(s+2)%3],m=[0,0,0];m[s]=u;let[h,g]=f(m[0],m[2]);for(let[_,v]of[[-1,-1],[1,-1],[1,1],[-1,-1],[1,1],[-1,1]]){let y=[0,0,0];[y[s],y[d],y[p]]=[u,_,v];let[b,x]=f(y[0]*i,y[2]*o);e.push(t+b,n+y[1]*a,r+x,h,m[1],g,c[0],c[1],l,c[2])}}},Le=(e,[t,n,r])=>Array.from({length:e.length*(10/6)},(i,a)=>{let[o,s]=[Math.floor(a/10),a%10];return s<6?e[o*6+s]:[t,n,-1,r][s-6]}),G=(e,t,n,[r,i,a],o,s,c=0)=>{let[l,u]=[Math.sin(c),Math.cos(c)],d=(e,t,n)=>[0,1,2].map(o=>r[o]*(e*u-t*l)+i[o]*(e*l+t*u)-a[o]*n),f=[0,1,2].map(e=>n[e]+r[e]*o[0]+i[e]*o[1]+a[e]*o[2]);for(let n=0;n<t.length;n+=10){let r=d(t[n]*s,t[n+1]*s,t[n+2]*s);e.push(f[0]+r[0],f[1]+r[1],f[2]+r[2],...d(t[n+3],t[n+4],t[n+5])),e.push(...t.slice(n+6,n+10))}},Re=.3,ze=3.6,K={body:[.27,.22,.25],arm:[.4,.26,.22],leg:[.18,.17,.22],head:[.45,.33,.3],shell:[.36,.2,.32],fin:[.5,.25,.25],gore:[.6,.08,.07],calm:[.6,.05,.04],chase:[1,.3,.15],blob:[1,.3,.05],core:[1,.8,.4]},Be=[[K.body,K.arm,K.head,K.gore,K.gore,K.chase],[K.shell,K.fin,K.shell,K.gore,K.chase]],Ve=e=>e?K.chase:K.calm,q=({x:e,y:t,z:n,yaw:r},i,a,o)=>{let[s,c]=[Math.sin(r),Math.cos(r)];return[e+i*c-o*s,t+a,n-i*s-o*c]},He=(e,t,n,r,i,a)=>{let o=[];W(o,[0,-i[1],0],i,0,a),G(e,o,t,U(n,r),[0,0,0],1)},Ue=e=>e<.25?-.8*Math.sin(e*4*Math.PI):2*Math.sin((e-.25)*Math.PI/.75),We=(e,t,n,r)=>{let i=Math.sin(n*ze)*.6,a=o*.44,s=o*.8,[c,l]=[-1,1].map(e=>q(t,e*.16,a,0));He(e,c,t.yaw,i,[.09,a/2,.09],K.leg),He(e,l,t.yaw,-i,[.09,a/2,.09],K.leg),He(e,q(t,-.35,s,0),t.yaw,-i*.8,[.07,.34,.07],K.arm),He(e,q(t,.35,s,0),t.yaw,i*.8+(r>0?Ue(r):0),[.07,.34,.07],K.arm),W(e,q(t,0,1.142,0),[.26,.35,.16],t.yaw,K.body),W(e,q(t,0,1.6500000000000001,0),[.15,.15,.15],t.yaw,K.head);let u=t.chase?.06:.045;for(let n of[-1,1])W(e,q(t,n*.075,1.69,.15),[u,u*.7,.02],t.yaw,Ve(t.chase),-2)},Ge=Le(Fe([[0,0],[.18,.06],[s,.32],[s*.93,.5],[.22,.78],[0,c]],8),K.shell),Ke=(e,t,n)=>{let r=Math.sin(n*2+t.id)*.06,i=[t.x,t.y+r,t.z];G(e,Ge,i,U(0,Math.PI/2),[0,0,0],1);for(let r=0;r<4;r++){let a=n*1.5+r*H/4;W(e,[t.x+Math.cos(a)*.4,i[1]+.35,t.z+Math.sin(a)*.4],[.16,.03,.04],-a,K.fin)}let a=q({...t,y:i[1]},0,c*.45,s*.9),o=t.chase?1.3:1;W(e,a,[.1*o,.07*o,.05],t.yaw,Ve(t.chase),-2)},qe=(e,t,n)=>{let r=[t.x,t.y,t.z];if(W(e,r,[l*.8,l*.8,l*.8],0,K.blob,-2),W(e,r,[l*.5,l*.5,l*.5],Math.PI/4,K.core,-2),n)for(let t of[1,2]){let i=l*(1-t*.3);W(e,r.map((e,r)=>e-n[r]*t*.2),[i,i,i],0,K.blob,-2)}},Je=.05,Ye=.3,Xe=96,Ze=64,Qe=12,$e=.3,et=.45,tt=.4,nt=.5,rt=.9,it=.3,at=14,ot=4.4,st=.035,ct=.03,lt=30,ut=({r:e,t})=>{let n=t/$e;return n<1?e*Math.sqrt(n)*(1-n*n*n):0},dt=(e=64)=>{let t=[];return{clear(){t=[]},push(n,r){t.push(...n.map(e=>({t:r,v:e}))),t.splice(0,t.length-e)},due(e){let n=t.findIndex(({t})=>t+100>e);return t.splice(0,n<0?t.length:n).map(({v:e})=>e)}}},ft=(e=Math.random,t)=>{let r=t,i=0,a=0,o=0,s=0,c=0,l,d=()=>e()*2-1,p=/* @__PURE__ */ new Map,m=(e,t,n,r)=>{_.sparks.length<Xe&&_.sparks.push({p:e,v:t,life:n,c:r})},h=(t,n,r,i)=>{for(let a=0;a<n;a++){let[n,a]=[e()*H,d()],o=Math.sqrt(1-a*a)*r*(.5+e()*.5);m(t,[Math.cos(n)*o,a*r,Math.sin(n)*o],Ye*(.6+e()*.4),i)}},g=(e,t)=>{_.blasts.push({p:e,r:t,t:0}),_.blasts.splice(0,_.blasts.length-Qe)},_={bob:0,roll:0,shakeYaw:0,shakePitch:0,kick:0,spin:0,flash:0,flashes:/* @__PURE__ */ new Map,sparks:[],gibs:[],blasts:[],hurt:0,gain:0,gainC:[1,1,1],dead:0,swings:/* @__PURE__ */ new Map,herd:/* @__PURE__ */ new Map,aim:/* @__PURE__ */ new Map,update(e,t,r,f=!1){let p=Math.min(1,r*10),m=e&&l?.ground&&e.ground?Math.hypot(e.x-l.x,e.z-l.z):0;m<1&&(i+=m*ot),a+=(+(m>.5*r&&m<1)-a)*p,l=e,_.dead=Math.max(0,Math.min(1,_.dead+(f?r:-r)/nt));let h=_.dead*_.dead*(3-2*_.dead);_.bob=Math.sin(i)*st*a-h*(n-it);let g=+!!(t&u.RIGHT)-!!(t&u.LEFT);s+=(g*ct-s)*Math.min(1,r*8),_.roll=s+h*rt,o*=Math.exp(-r*12),_.shakeYaw=d()*o,_.shakePitch=d()*o,_.kick*=Math.exp(-r*18),_.flash=Math.max(0,_.flash-r);for(let[e,t]of _.flashes)t>r?_.flashes.set(e,t-r):_.flashes.delete(e);c=Math.max(0,Math.min(lt,c+(t&u.FIRE?60:-25)*r)),_.spin=(_.spin+c*r)%H;for(let e of _.sparks)e.v[1]-=9.8*r,e.p=e.p.map((t,n)=>t+e.v[n]*r),e.life-=r;_.sparks=_.sparks.filter(e=>e.life>0),_.hurt=Math.max(0,_.hurt-r),_.gain=Math.max(0,_.gain-r);for(let[e,t]of _.swings)t>r?_.swings.set(e,t-r):_.swings.delete(e);for(let e of _.blasts)e.t+=r;_.blasts=_.blasts.filter(e=>e.t<$e);for(let e of _.gibs)e.life-=r,e.rest||v(e,r);_.gibs=_.gibs.filter(e=>e.life>0)},hit(){_.hurt=et},pickup(e){[_.gain,_.gainC]=[tt,e]},reset(e){r=e,_.sparks=[],_.gibs=[],_.blasts=[],_.flashes.clear(),_.swings.clear(),_.herd.clear(),_.aim.clear(),p.clear(),_.hurt=_.gain=_.flash=0},shot(t,n,r,i=!0){r?(_.kick=1,_.flash=Je,o=.012):_.flashes.set(t.id,Je);let a=[t.x,t.y,t.z],s=n.map((e,t)=>e-a[t]),c=Math.hypot(...s);if(i&&c>0&&c<99.99)for(let t=0;t<4;t++){let t=s.map(t=>t/c*(2+e()*2)+d());t[1]+=1,m(a,t,Ye*(.6+e()*.4))}},track(e,t){for(let{id:t,kind:n,x:r,z:i}of e){let e=_.herd.get(t),a=e?Math.hypot(r-e.x,i-e.z):0;_.herd.set(t,{x:r,z:i,kind:n,walked:(e?.walked??0)+(a<1?a:0)})}let n=/* @__PURE__ */ new Map;for(let{id:e,x:r,y:i,z:a}of t){let[t,o]=[p.get(e),[r,i,a]],s=t?Math.hypot(o[0]-t[0],o[1]-t[1],o[2]-t[2]):0;t&&s>1e-4&&_.aim.set(e,o.map((e,n)=>(e-t[n])/s)),n.set(e,o)}p=n;for(let e of _.aim.keys())n.has(e)||_.aim.delete(e)},event({type:t,id:n,x:i,y:a,z:o},s){let c=[i,a,o];if(t==f.DIE){let t=Be[_.herd.get(n)?.kind??0]??Be[0],s=10+Math.floor(e()*7);for(let n=0;n<s;n++){let n=e()*H,s=1.5+e()*3.5;_.gibs.push({p:[i,a+d()*.3,o],v:[Math.cos(n)*s,2+e()*4,Math.sin(n)*s],yaw:e()*H,size:.05+e()*.08,c:t[Math.floor(e()*t.length)],life:2+e(),floor:r?.map.sectors[y(r,i,o)]?.floor??a,rest:!1})}_.gibs.splice(0,_.gibs.length-Ze),g(c,.6),h(c,14,5)}else t==f.BOOM?(g(c,.25),h(c,8,3)):t==f.HURT?n!=s&&h(c,8,3,[1,.12,.08]):t==f.SWING&&_.swings.set(n,Re)}},v=(e,t)=>{e.v[1]-=at*t;let n=e.p.map((n,r)=>n+e.v[r]*t);r&&b(r,e.p,n)&&(e.v[0]*=-.3,e.v[2]*=-.3,[n[0],n[2]]=[e.p[0],e.p[2]]);let i=r?.map.sectors[y(r,n[0],n[2])];e.floor=i?.floor??e.floor,i&&n[1]>i.ceil-e.size&&(n[1]=i.ceil-e.size,e.v[1]=Math.min(e.v[1],0)*.3),n[1]<=e.floor+e.size&&(n[1]=e.floor+e.size,e.v[1]<-3?e.v=[e.v[0]*.5,-e.v[1]*.3,e.v[2]*.5]:(e.v=[0,0,0],e.rest=!0)),e.p=n};return _},pt=[[1,1,1],[.95,.15,.1],[.2,.4,1],[1,.85,.15]],mt=(e,t=1)=>`rgba(${e.map(e=>Math.round(e*255))},${t})`,ht=.3,gt=[.25,1,.45],_t=[.85,.1,.1],vt=[.05,.05,.06],J=(e,[t,n,r],[i,a,o],s,c,l,u=-1)=>{let[d,f]=[Math.sin(c),Math.cos(c)];W(e,[t+i*f+o*d,n+a,r-i*d+o*f],s,c,l,u)},yt=(e,{id:t,kind:n,x:r,y:i,z:a},o)=>{let s=o*2+t,c=[r,i+(n?.55:.4)+Math.sin(o*2.5+t)*.07,a],l=pt[n];if(n==p.HEALTH){W(e,c,[.2,.2,.2],s,l);for(let t of[[.21,.06,.21],[.06,.21,.21],[.21,.21,.06]])W(e,c,t,s,_t)}else J(e,c,[0,.17,0],[.1,.1,.025],s,l,-2),J(e,c,[0,.17,0],[.04,.04,.035],s,vt),J(e,c,[0,-.1,0],[.025,.17,.025],s,l),J(e,c,[.06,-.24,0],[.05,.03,.025],s,l),J(e,c,[.045,-.15,0],[.035,.025,.025],s,l)},bt=({map:e},{front:t,back:n})=>{let[r,i]=[e.sectors[t],e.sectors[n]];return[Math.max(r.floor,i.floor),Math.min(r.ceil,i.ceil)]},xt=(e,t,n,r,i,a,o=-1)=>{let[s,c]=[t.bx-t.ax,t.bz-t.az];W(e,[(t.ax+t.bx)/2,n,(t.az+t.bz)/2],[Math.hypot(s,c)/2,r,i],Math.atan2(-c,s),a,o)},St=(e,t,n)=>{let{gates:r=[],exit:i}=t.map;for(let{sector:n,key:i}of r){if(!t.barred.has(n))continue;let r=pt[i];for(let i of t.edges.filter(e=>e.front==n&&e.back>=0)){let[n,a]=bt(t,i),o=Math.ceil(Math.hypot(i.bx-i.ax,i.bz-i.az)/ht);for(let t=0;t<o;t++){let s=(t+.5)/o;W(e,[i.ax+(i.bx-i.ax)*s,(n+a)/2,i.az+(i.bz-i.az)*s],[.03,(a-n)/2,.03],0,r)}xt(e,i,n+.1,.04,.04,r),xt(e,i,a-.1,.04,.04,r)}}if(i!==void 0&&!t.barred.has(i)){let r=gt.map(e=>e*(.75+.25*Math.sin(n*4)));for(let n of t.edges.filter(e=>e.front==i&&e.back>=0)){let[i,a]=bt(t,n);for(let t of[i+.04,a-.04])xt(e,n,t,.04,.04,r,-2);for(let[t,o]of[[n.ax,n.az],[n.bx,n.bz]])W(e,[t,(i+a)/2,o],[.05,(a-i)/2,.05],0,r,-2)}}},Ct=(e,t,n)=>{let r=t.map.goal,i=r&&t.map.sectors[y(t,r[0],r[1])]?.floor;if(!r||i===void 0)return;let a=Math.sin(n*4),[o,s]=[1*(.7+a*.07),[1,.85,.25].map(e=>e*(.75+a*.25))];for(let t of[0,1])W(e,[r[0],i+.03+t*.005,r[1]],[o,.03,o],n/2+t*Math.PI/4,s,-2);W(e,[r[0],i+.8+Math.sin(n*2)*.1,r[1]],[.15,.15,.15],n*2,[1,.95,.5],-2)},wt=(e,t,n,r)=>{for(let t of n)yt(e,t,r);St(e,t,r),Ct(e,t,r)},Tt={TITLE:0,NOTE:1},Et=[2,3,8],Dt=2,Y=.35,Ot=`h1,h2,h4,h5,ul,ol,aside,section,s{position:absolute;margin:0;padding:0;pointer-events:none;user-select:none;white-space:pre-line}h1,h2,h4{left:0;right:0;text-align:center}h1{top:14%;font-size:20px;line-height:1.4}h1::first-line{font-size:44px}h2{top:32%;font-size:22px}h5{top:8px;right:12px;font-size:12px}h4{top:28%;font-size:22px;line-height:1.5;color:#fcc;text-shadow:0 2px 8px #800}h4::first-line{font-size:52px;color:#f33}s{inset:0;opacity:0}s:first-of-type{background:radial-gradient(#d000 45%,#d00 115%)}ul{--f:0;--s:0;--d:0;left:12px;bottom:12px;width:min(40vw,140px);height:22px;border-radius:4px;overflow:hidden;background:#0009;box-shadow:0 0 0 1px #0008,0 0 0 calc(var(--d)*3px) #f22;transform:translateX(calc(var(--s)*1px));filter:brightness(calc(1 + var(--f)*2))}ul li{position:absolute;top:0;bottom:0;left:0;transition:width .15s}ul li+li{right:0;width:auto;text-align:center;line-height:22px;font-size:14px}ol{left:calc(22px + min(40vw,140px));bottom:12px;display:flex;gap:4px;list-style:none}ol li{width:16px;height:22px;border-radius:3px;box-shadow:0 0 0 1px #0008}aside,section{inset:0;z-index:1;display:flex;flex-direction:column;align-items:center;gap:14px;padding:0 12px;text-align:center;background:#000b}aside{justify-content:center}section{padding-top:10%;font-size:20px}:is(aside,section):not([hidden])~:is(h1,h2){visibility:hidden}h6{margin:0;font-size:inherit;text-shadow:none}aside h6{font:900 clamp(36px,13vw,84px)/1 system-ui,sans-serif;letter-spacing:.04em;transform:skewX(-8deg);background:linear-gradient(#fe6,#f92 45%,#d21);-webkit-background-clip:text;background-clip:text;color:transparent;filter:drop-shadow(0 3px 0 #500) drop-shadow(0 0 14px #f604)}section h6{font-size:20px;line-height:1.5}section h6::first-line{font-size:48px}strong{font-size:22px}small{font-size:16px;opacity:.8}table{border-collapse:collapse;font-size:16px}td,th{padding:2px 10px}th{opacity:.6}td+td,th+th{text-align:left}td+td+td,th+th+th{text-align:right}aside td:first-child{text-align:right;opacity:.7}`,kt=e=>{e.insertAdjacentHTML(`beforeend`,`<s></s><s></s><ul><li></li><li></li></ul><ol>${`<li hidden></li>`.repeat(3)}</ol><aside hidden><h6>TINY FPS</h6><span></span><table><tr><td>Mouse<td>look<tr><td>WASD / ZQSD<td>move<tr><td>Space<td>jump<tr><td>Left click<td>fire<tr><td>M<td>mute</table><strong></strong></aside><section hidden><h6></h6><table><thead><tr><th><th>Player<th>Kills<th>Deaths</thead><tbody></tbody></table><small></small></section><h1 hidden></h1><h2 hidden></h2><h4 hidden></h4><h5 hidden>Muted (M)</h5>`);let t=t=>e.querySelector(t),[n,r]=[...e.querySelectorAll(`s`)],[i,a,o]=[t(`ul`),t(`ul li`),t(`ul li+li`)],s=[...e.querySelectorAll(`ol li`)],[c,l,u,d]=[`h4`,`h5`,`section`,`aside`].map(e=>t(e)),[f,p,m]=[`section h6`,`section tbody`,`small`].map(e=>t(e)),[h,g]=[`aside span`,`strong`].map(e=>t(e)),_=[t(`h1`),t(`h2`),u];s.forEach((e,t)=>e.style.background=mt(pt[t+1]));let v=Et.map(()=>0),y=0,[b,x]=[0,0],S=(e,t)=>e.textContent!=t&&(e.textContent=t);return{hp(e){y&&(b=e>y?Y:b,x=e<y?Y:x),y=e,a.style.width=`${e/9*100}%`,a.style.background=`hsl(${(Math.max(e,1)-1)/8*110},75%,42%)`,S(o,String(e))},keys:e=>s.forEach((t,n)=>t.hidden=!(e>>n+1&1)),dead(e){c.hidden=!e,e&&S(c,`You died\nRespawn in ${e}`)},fade(e,t,i,a){n.style.opacity=String(Math.max(e*.9,t&&.2+t*.4)),r.style.opacity=String(i*.32),r.style.background=mt(a)},title(e,t){d.hidden=!e,S(h,t),S(g,e)},end(e,t,n){S(f,e),S(m,n),p.replaceChildren(...t.map(([e,t,n,r])=>{let i=document.createElement(`tr`);return[`●`,e,n,r].forEach((e,n)=>{let r=i.insertCell();r.textContent=String(e),r.style.color=n?``:t}),i})),_[Dt].hidden=!1,v[Dt]=Et[Dt]},mute:e=>l.hidden=!e,say(e,t){_[e].textContent=t,_[e].hidden=!1,v[e]=Et[e]},update(e){v.forEach((t,n)=>{t>0&&(v[n]=t-e)<=0&&(_[n].hidden=!0)}),b=Math.max(0,b-e),x=Math.max(0,x-e);for(let[e,t]of[[`--f`,b/Y],[`--d`,x/Y],[`--s`,Math.sin(x*90)*8*x/Y]])i.style.setProperty(e,String(t))}}},At=.0025,jt=Math.PI*2,Mt={KeyW:u.FORWARD,ArrowUp:u.FORWARD,KeyS:u.BACK,ArrowDown:u.BACK,KeyA:u.LEFT,ArrowLeft:u.LEFT,KeyD:u.RIGHT,ArrowRight:u.RIGHT,Space:u.JUMP},Nt=e=>Mt[e]??0,Pt=(e,t=()=>{})=>{let n=new AbortController,i=(e,t,r)=>e.addEventListener(t,r,{signal:n.signal}),a={yaw:0,pitch:0,keys:0,locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>n.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{a.locked()&&(a.yaw=((a.yaw-e.movementX*At)%jt+jt)%jt,a.pitch=Math.max(-1.55,Math.min(r,a.pitch-e.movementY*At)))}),i(document,`keydown`,e=>{let n=Nt(e.code);e.code==`KeyM`&&!e.repeat&&a.locked()&&t(),n&&a.locked()&&(a.keys|=n,e.preventDefault())}),i(document,`keyup`,e=>{a.keys&=~Nt(e.code)}),i(document,`mousedown`,e=>{e.button==0&&a.locked()&&(a.keys|=u.FIRE)}),i(document,`mouseup`,e=>{e.button==0&&(a.keys&=~u.FIRE)});let o=()=>{a.keys=0};return i(window,`blur`,o),i(document,`pointerlockchange`,()=>a.locked()||o()),a},Ft=e=>{for(let t=0;t<2;t++)e=Math.imul(e^e>>>16,73244475);return(e^e>>>16)>>>0},It=(e,t,n)=>{let[r,i,o,s]=[Math.sin(e),Math.cos(e),Math.sin(t),Math.cos(t)],c=Ft(n+1),l=(c&65535)/65536*H,u=(c>>>16)/65535,[d,f]=[Math.cos(l)*u*a,Math.sin(l)*u*a],p=[-r*s+i*d+r*o*f,o+s*f,-i*s-r*d+i*o*f],m=Math.hypot(...p);return[p[0]/m,p[1]/m,p[2]/m]},Lt=(e,t,n,r)=>{let{map:i,edges:a}=e,o=Math.max(y(e,t[0],t[2]),0),s=0;for(let e=0;e<=i.sectors.length;e++){let{floor:e,ceil:c}=i.sectors[o],l=1/0,u;for(let e of a){if(e.front!==o)continue;let[r,i]=[e.bx-e.ax,e.bz-e.az],a=n[2]*r-n[0]*i;if(a>=0)continue;let c=Math.max(((t[2]-e.az)*r-(t[0]-e.ax)*i)/-a,s),d=((t[0]+c*n[0]-e.ax)*r+(t[2]+c*n[2]-e.az)*i)/(r*r+i*i);d>-1e-9&&d<1+1e-9&&(c<l-1e-9||c<l+1e-9&&e.back<0)&&([l,u]=[c,e])}let d=n[1]<0?(e-t[1])/n[1]:n[1]>0?(c-t[1])/n[1]:1/0;if(d<=l||!u)return Math.min(Math.max(d,s),r);if(l>=r)return r;let f=t[1]+l*n[1],p=u.back<0?void 0:i.sectors[u.back];if(!p||f<Math.max(e,p.floor)||f>Math.min(c,p.ceil))return l;[o,s]=[u.back,l]}return s},Rt=(e,t,n)=>{let[r,i]=[e[0]-n.x,e[2]-n.z],a=t[0]*t[0]+t[2]*t[2],o=r*t[0]+i*t[2],s=r*r+i*i-n.r*n.r,[c,l]=[0,1/0];if(a>1e-12){let e=o*o-a*s;if(e<0)return 1/0;[c,l]=[Math.max(0,(-o-Math.sqrt(e))/a),(-o+Math.sqrt(e))/a]}else if(s>0)return 1/0;let[u,d]=[n.y-e[1],n.y+n.h-e[1]];if(t[1]){let[e,n]=[u/t[1],d/t[1]];c=Math.max(c,Math.min(e,n)),l=Math.min(l,Math.max(e,n))}else if(u>0||d<0)return 1/0;return c<=l?c:1/0},zt=({id:n,x:r,y:i,z:a})=>({id:n,x:r,y:i,z:a,r:e,h:t}),Bt=({id:e,kind:t,x:n,y:r,z:i})=>{let a=t===d.WALKER;return{id:e,x:n,y:r,z:i,r:a?.4:s,h:a?o:c}},Vt=(e,t,r,i)=>{let a=[t.x,t.y+n,t.z],o=It(t.yaw,t.pitch,r),s=Lt(e,a,o,100),c=-1;for(let e of i){let n=e.id===t.id?1/0:Rt(a,o,e);n<s&&([s,c]=[n,e.id])}return{id:t.id,x:a[0]+o[0]*s,y:a[1]+o[1]*s,z:a[2]+o[2]*s,hit:c}},Ht=120,Ut=16,X=({id:e,x:t,y:n,z:r,vy:i,yaw:a,pitch:o,ground:s,cool:c})=>({id:e,x:t,y:n,z:r,vy:i,yaw:a,pitch:o,ground:s,cool:c}),Wt=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,z:e.z+(t.z-e.z)*n}),Gt=(e,t,n)=>we(e+(((t-e+Math.PI)%H+H)%H-Math.PI)*n),Kt=(e,t)=>(t-e&65535)<32768,qt=(e,t,n)=>({...t,...Wt(e,t,n),yaw:Gt(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),Jt=e=>{let t=e,n,r=0,i=[],a,o,s,c=!0,l=/* @__PURE__ */ new Map,u=[],d=e=>{let t=e-100,n=0;for(;n+1<u.length&&u[n+1].t<=t;)n++;let r=u[n],i=u[n+1]??r;return{a:r,b:i,u:i.t>r.t?Math.max(0,Math.min(1,(t-r.t)/(i.t-r.t))):0}},f=e=>{if(!u.length)return;let{a:t,b:n,u:r}=d(e);return(t.s.tick+(n.s.tick-t.s.tick&65535)*r)%65536},p=e=>{let t=u.at(-1);if(!t)return[];let{a:r,b:i,u:a}=d(e);return t.s.players.filter(e=>e.id!==n).map(e=>{let t=r.s.players.find(t=>t.id===e.id),n=i.s.players.find(t=>t.id===e.id);return t&&n?qt(X(t),X(n),a):X(n??t??e)})},m=(e,t,n)=>{if(!u.length)return[];let{a:r,b:i,u:a}=d(e),o=t(r.s);return t(i.s).map(e=>{let t=o.find(t=>t.id===e.id);return t?n(t,e,a):e})},h=e=>m(e,e=>e.monsters,(e,t,n)=>({...t,...Wt(e,t,n),yaw:Gt(e.yaw,t.yaw,n)}));return{you:e=>{n=e},step:(e,n)=>{let d=I({...e,seq:r,view:n===void 0?void 0:f(n)});if(s=void 0,r=r+1&65535,i.push(d),i.length>Ht&&i.shift(),a&&(o=X(a),c&&Me(a,d,t))){let e=n??1/0,r=h(e).filter(e=>!l.has(e.id)),i=u.at(-1)?.s.players??[],o=p(e).filter(e=>i.find(t=>t.id===e.id)?.hp);s=Vt(t,a,d.seq,[...o.map(zt),...r.map(Bt)]),s.hit>=16&&l.set(s.hit,d.seq)}return d},snapshot:(e,r)=>{u.push({t:r,s:e}),u.length>Ut&&u.shift(),_(t,e.keys,e.phase);let s=e.players.find(e=>e.id===n);s&&(c=s.hp>0,i=i.filter(e=>!Kt(e.seq,s.ack)),l.forEach((t,n)=>{let r=e=>e.monsters.some(e=>e.id===n);Kt(t,s.ack)&&(r(e)||!u.some(e=>r(e.s)))&&l.delete(n)}),a=X(s),o=X(a),i.forEach((e,n)=>{n===i.length-1&&(o=X(a)),c&&Me(a,e,t)}))},monsters:h,bullets:e=>m(e,e=>e.bullets,(e,t,n)=>({...t,...Wt(e,t,n)})),level:e=>{t=e,u.length=0,l.clear(),a=o=s=void 0},shot:()=>s,me:e=>a&&o?qt(o,a,Math.max(0,Math.min(1,e))):void 0,others:p}},Yt={SPOT:0,POINT:1},Xt=[1.2,1.1,.9],Zt=[3,1.4,.4],Qt=Math.cos(.436),$t=.5,en=2,tn=4,Z=(e,t,n)=>({kind:Yt.POINT,p:e,d:[0,0,0],cone:0,range:t,color:n,shadow:!1}),nn=(e,t,n,r,i,a=!1)=>({...Z(e,r,i),kind:Yt.SPOT,d:t,cone:n,shadow:a}),rn=(e,...t)=>e.map((e,n)=>e+t.reduce((e,[t,r])=>e+t[n]*r,0)),an=(e,t)=>e.map(e=>e*t),on=({eye:e,yaw:t,pitch:r,dead:i,others:a,fx:o,bullets:s,lvl:c,t:l})=>{let[u,d,f]=U(t,r),p=[];i||(p.push(nn(rn(e,[u,.2],[d,-.2]),f,Qt,25,Xt,!0)),o.flash>0&&p.push(nn(rn(e,[u,.26],[d,-.24],[f,.6+Ne*.8]),f,$t,8,Zt,!0)));let m=t=>Math.hypot(t[0]-e[0],t[1]-e[1],t[2]-e[2]),h=[];a.map(e=>({p:e,e:[e.x,e.y+n,e.z]})).sort((e,t)=>m(e.e)-m(t.e)).forEach(({p:e,e:t},n)=>{let[r,i,a]=U(e.yaw,e.pitch);h.push(nn(rn(t,[a,.35]),a,Qt,25,Xt,n<en)),o.flashes.has(e.id)&&h.push(Z(rn([e.x,e.y+1.25,e.z],[r,.36],[i,-.12],[a,.8]),6,Zt))});for(let e of o.blasts){let t=ut(e);t>0&&h.push(Z(e.p,6,an(Zt,t*6)))}o.hurt>0&&h.push(Z(e,4,an([2,.15,.1],Math.min(1,o.hurt*10)))),s.map(e=>Z([e.x,e.y,e.z],3,[1.2,.4,.15])).sort((e,t)=>m(e.p)-m(t.p)).slice(0,tn).forEach(e=>h.push(e));let{exit:g,goal:_}=c.map;if(g!==void 0){let e=1+.3*Math.sin(l*4);if(c.barred.has(g)){if(_){let t=c.map.sectors[y(c,_[0],_[1])]?.floor??0;h.push(Z([_[0],t+1,_[1]],8,an([.2,1.2,1.5],e)))}}else{let{floor:t}=c.map.sectors[g];for(let{ax:n,az:r,bx:i,bz:a,front:o,back:s}of c.edges)if(o==g&&s>=0){let[o,s]=[i-n,a-r],c=.5/Math.hypot(o,s);h.push(Z([(n+i)/2-s*c,t+1.2,(r+a)/2+o*c],8,an([.2,1.5,.3],e)))}}}return p.concat(h.sort((e,t)=>m(e.p)-m(t.p)).slice(0,16-p.length))},sn=1.5,cn=(e,t)=>{let n=O[e]?.name;return`Level ${e+1}${n?`: ${n}`:``}${t?` (hard mode)`:``}`},ln=e=>{let t=Math.floor(e*10/60);return`${Math.floor(t/600)}:${String(Math.floor(t/10)%60).padStart(2,`0`)}.${t%10}`},un=({spawns:e},t,n)=>e.reduce((e,r)=>Math.hypot(r[0]-t,r[1]-n)<Math.hypot(e[0]-t,e[1]-n)?r:e)[2],dn=({lvl:e,you:t,roster:n,predictor:r,rd:i,delays:a,fx:o,hud:s,audio:c})=>{let l=-1,u=-1,d=0,f=/* @__PURE__ */ new Map,p={lvl:e,items:[],dead:!1,hp:0,name:cn(0,!1),returning:!1,alive:e=>f.get(e)!==0,snapshot(e){let n=t(),h=e.level*2+ +e.hard;if(h!=l){let t=O[e.level];if(!t)return;l=h,p.lvl=g(t),p.items=[],f=/* @__PURE__ */ new Map,u=-1,r.level(p.lvl),i?.level(p.lvl),o.reset(p.lvl),a.forEach(e=>e.clear()),p.name=cn(e.level,e.hard),s.say(Tt.TITLE,`Level ${e.level+1}${e.hard?`
|
|
2
|
-
Hard mode`:``}`)}let _=e.players.find(e=>e.id==n),v=f.get(n);_&&v!==void 0&&_.hp<v&&o.hit(),f=new Map(e.players.map(e=>[e.id,e.hp]));for(let t of p.items)_&&!e.items.some(e=>e.id==t.id)&&Math.hypot(t.x-_.x,t.z-_.z)<
|
|
1
|
+
var e=.4,t=1.8,n=1.6,r=1.55,i=.5,a=.02,o=1.8,s=.45,c=.9,l=.15,u={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,FIRE:32},d={WALKER:0,FLYER:1},f={DIE:0,HURT:1,BOOM:2,SWING:3},p={HEALTH:0,KEY_RED:1,KEY_BLUE:2,KEY_YELLOW:3},m={HUNT:0,RETURN:1},h={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7},g=e=>{let t=(e,t,n,r)=>`${e},${t},${n},${r}`,n=/* @__PURE__ */ new Map;e.sectors.forEach(({pts:e},r)=>e.forEach(([i,a],o)=>n.set(t(i,a,...e[(o+1)%e.length]),r)));let r={map:e,edges:e.sectors.flatMap(({pts:e},r)=>e.map(([i,a],o)=>{let[s,c]=e[(o+1)%e.length];return{ax:i,az:a,bx:s,bz:c,front:r,back:n.get(t(s,c,i,a))??-1}})),barred:/* @__PURE__ */ new Set};return _(r,0,m.HUNT),r},_=({map:e,barred:t},n,r)=>{t.clear(),e.gates?.forEach(e=>n&1<<e.key||t.add(e.sector)),e.exit!==void 0&&r===m.HUNT&&t.add(e.exit)},v=({pts:e},t,n)=>e.every(([r,i],a)=>{let[o,s]=e[(a+1)%e.length];return(o-r)*(n-i)-(s-i)*(t-r)>=0}),y=({map:e},t,n)=>e.sectors.findIndex(e=>v(e,t,n)),b=({map:e,edges:t},[n,r,i],[a,o,s])=>{let[c,l]=[a-n,s-i];return t.some(t=>{let[a,s]=[t.bx-t.ax,t.bz-t.az],u=c*s-l*a;if(!u)return!1;let d=((t.ax-n)*s-(t.az-i)*a)/u,f=((t.ax-n)*l-(t.az-i)*c)/u;if(d<=0||d>=1||f<0||f>1)return!1;if(t.back<0)return!0;let[p,m]=[e.sectors[t.front],e.sectors[t.back]],h=r+d*(o-r);return h<Math.max(p.floor,m.floor)||h>Math.min(p.ceil,m.ceil)})},x=(e,...t)=>t.map(([t,n,r,i,a,o,s,c,l])=>[t,n,r,i,a,o,s,c,l,e]),S=(e,[t,n,r,i],a,o,s,c,l,u)=>Array.from({length:s},(d,f)=>{let[p,m]=e?[n,i]:[t,r],[h,g,_]=[p+f*(m-p)/s,p+(f+1)*(m-p)/s,+(a+f*o).toFixed(1)];return e?[t,h,r,g,_,c,l,u]:[h,n,g,i,_,c,l,u]}),[C,w,T,E]=[p.HEALTH,p.KEY_RED,p.KEY_BLUE,p.KEY_YELLOW],D=Math.PI/4,O=[1,.82,.6],ee=[.6,.75,1],k=(e,t,[n,r,i],a,o,s,c,l)=>{let u=t.map(([e,t,n,r])=>[[e,t],[n,t],[n,r],[e,r]]),f=[...new Map(u.flat().map(e=>[`${e}`,e])).values()];return{name:e,sectors:t.map(([,,,,e,t,n=`103`,r,,i],a)=>({pts:u[a].flatMap((e,t,n)=>{let r=n[(t+1)%4],i=t=>(t[0]-e[0])*(r[0]-e[0])+(t[1]-e[1])*(r[1]-e[1]);return[e,...f.filter(t=>(r[0]-e[0])*(t[1]-e[1])===(r[1]-e[1])*(t[0]-e[0])&&i(t)>0&&i(t)<(r[0]-e[0])**2+(r[1]-e[1])**2).sort((e,t)=>i(e)-i(t))]}),floor:e,ceil:t,ft:+n[0],wt:+n[1],ct:+n[2],light:r,tint:i})),spawns:Array.from({length:16},(e,t)=>[n+t%4*2,r+(t>>2)*2,i*D]),monsters:[...a.map(([e,t,n])=>[e,t,n*D,d.WALKER]),...o.map(([e,t,n])=>[e,t,n*D,d.FLYER])],items:s,gates:t.flatMap(([,,,,,,,,e],t)=>e?[{sector:t,key:e}]:[]),goal:c,exit:0,fog:l}},A=[k(`Warm-up`,[[0,0,10,10,0,4,`103`],[10,4,22,6,0,2.8,`333`,.6],...x([1,.85,.65],[22,0,38,14,0,6,`553`],...S(0,[38,4,42,10],.4,.4,4,6,`553`)),[42,2,52,12,2,6,`103`,.9],...S(1,[46,12,48,22],1.6,-.4,4,4.8,`744`,.7),[38,22,56,36,0,6,`113`]],[2,2,6],[[28,4,3],[34,10,4],[48,6,4],[44,30,0]],[[30,8,0],[52,28,2]],[[26,12,C],[50,10,C],[40,34,C]],[54,34]),k(`Foundry`,[...x([1,.9,.8],[0,14,10,26,0,4,`443`],[10,22,20,24,0,2.8,`744`,.6]),...x([1,.5,.25],[24,8,28,16,0,9,`744`],[20,16,28,30,0,9,`443`],...S(1,[20,8,24,16],2,-.4,5,9,`744`),[28,8,42,18,-1.6,9,`233`,.9],...S(1,[28,18,42,21],-1.2,.4,3,9,`333`),[28,21,50,30,0,9,`744`],[42,8,50,21,0,9,`744`],[20,0,50,8,2.4,9,`744`,.8]),[50,14,51,17,0,3.5,`444`,1,w],...x([.85,.65,.5],[51,8,59,26,0,7,`443`,.6],[59,8,67,26,.4,7,`143`,.8],[57,26,59,36,0,4.8,`744`,.7]),...x([1,.6,.45],[50,36,68,50,0,7,`443`])],[2,16,6],[[46,14,2],[36,26,0],[38,4,2],[56,12,4],[62,20,2],[60,44,0]],[[35,13,0],[60,14,4],[58,42,6]],[[24,26,C],[24,4,C],[64,10,C],[52,46,C],[46,4,w]],[66,48],[.07,.05,.04,.026]),k(`Cistern`,[...x([.45,.9,1],[0,20,10,32,0,4,`363`],[10,26,20,28,0,2.8,`363`,.6],[20,14,56,26,0,11,`363`,.9],[20,26,34,32,0,11,`363`,.9]),...x([.9,.6,.45],[34,26,42,32,-.4,11,`263`]),...x([.45,.9,1],[42,26,56,32,0,11,`363`,.9],[20,32,56,44,0,11,`363`,.9],[36,44,38,54,0,1.9,`000`,.35],[30,54,46,68,0,5,`003`,.7]),[56,28,57,31,0,4,`444`,1,w],...x([.55,.85,1],...S(0,[57,26,65,32],.4,.4,8,10,`333`,.8)),...x([.7,1,.85],[65,22,81,36,3.6,11,`563`]),[71,36,74,37,3.6,7,`444`,1,T],...x([.45,.9,1],[71,37,74,48,3.6,6.4,`363`,.6]),...x([.9,.6,.45],[62,48,82,64,3.6,10,`263`])],[2,22,6],[[30,18,4],[50,20,4],[30,40,0],[50,40,0],[36,60,2],[42,64,0],[76,28,2],[70,58,0]],[[26,24,0],[48,22,0],[36,40,2],[72,56,4]],[[24,40,C],[52,42,C],[44,57,C],[68,34,C],[64,62,C],[38,66,w],[79,24,T]],[80,62],[.04,.11,.1,.034]),k(`Loop`,[...x(O,[0,44,10,56,0,4,`153`],[10,49,20,51,0,2.8,`553`,.6]),[20,30,52,40,0,9,`113`],[20,48,52,58,0,9,`113`,.9],[20,40,32,48,0,9,`113`],[40,40,52,48,0,9,`113`],[20,22,49,30,3.2,9,`743`,.8],...x(O,[34,58,36,66,0,2.8,`553`,.4],[26,66,46,84,0,5,`353`,.5]),[52,42,53,45,0,4,`444`,1,w],...x(O,[53,36,64,54,0,6,`153`,.8],[64,36,70,54,.4,6,`253`,.8]),[60,35,63,36,0,4,`444`,1,T],...x(O,[57,12,77,35,0,8,`053`,.9]),[56,24,57,27,0,4,`444`,1,E],...S(0,[49,22,56,30],2.8,-.4,7,9,`744`,.8),...x(O,[12,24,20,28,3.2,6,`744`,.6],[0,10,12,34,3.2,9,`553`])],[2,46,6],[[30,36,4],[44,36,2],[40,52,0],[40,26,4],[30,74,6],[42,78,2],[56,40,6],[64,50,2],[62,18,4],[72,28,2],[6,22,0]],[[28,48,0],[46,44,4],[36,72,0],[60,45,6],[68,22,4]],[[24,54,C],[24,26,C],[44,80,C],[68,38,C],[74,14,C],[36,82,w],[68,52,T],[74,32,E]],[6,13],[.06,.045,.04,.02]),k(`Citadel`,[...x(ee,[0,60,10,72,0,4,`303`],[10,65,24,67,0,2.8,`363`,.6],[24,48,56,84,0,12,`363`],[27,40,31,48,0,3.4,`363`,.4]),...x([.85,.7,.65],[24,16,34,40,0,12,`443`,.9],...S(0,[34,16,40,26],-.4,-.4,3,12,`243`),[34,26,40,30,0,12,`744`],...S(0,[34,30,40,40],-.4,-.4,3,12,`243`),[40,16,60,40,0,12,`443`,.9]),[60,27,61,30,0,4,`444`,1,E],...x([.55,.3,1],[61,10,101,16,0,14,`443`,1],[61,40,101,46,0,14,`443`,1],[61,16,69,40,0,14,`443`,1],[93,16,101,40,0,14,`443`,1],[69,16,93,20,.4,14,`243`,1],[69,36,93,40,.4,14,`243`,1],[69,20,73,36,.4,14,`243`,1],[89,20,93,36,.4,14,`243`,1],[73,20,89,36,.8,14,`744`,1]),[101,26,111,28,0,3.2,`744`,.6],[111,16,131,40,0,8,`163`],[56,66,57,69,0,4,`444`,1,w],...x([1,.5,.45],[57,56,75,80,0,12,`443`,.7],...S(0,[75,60,85,72],.4,.4,5,12,`744`,.8),[85,52,101,80,2.4,12,`543`]),[38,84,42,85,0,4,`444`,1,T],...x([.6,.85,.85],[38,85,42,95,0,1.9,`363`,.35],[28,95,56,115,0,6,`663`,.6])],[2,62,6],[[34,56,4],[50,56,2],[36,76,0],[46,20,4],[54,34,2],[66,60,2],[66,76,0],[92,60,2],[34,100,4],[50,108,2],[70,13,4],[92,13,2],[70,43,0],[92,43,6]],[[30,70,0],[46,68,0],[50,28,0],[76,26,0],[86,30,0],[81,22,0]],[[30,80,C],[56,36,C],[60,78,C],[50,112,C],[64,13,C],[98,43,C],[114,38,C],[52,22,w],[95,66,T],[42,110,E]],[127,36],[.045,.05,.075,.02])],j=65536/(2*Math.PI),M=e=>Math.round(e*j)&65535,te=e=>Math.max(-32768,Math.min(32767,Math.round(e))),ne=e=>te(e*1e4),N=e=>e/1e4,P=e=>e/j,F=(e=0)=>Math.round(e*256)&16777215,I=e=>({...e,yaw:P(M(e.yaw)),pitch:N(ne(e.pitch)),...e.view!==void 0&&{view:F(e.view)/256}}),L=e=>{let t=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(11));t.setUint8(0,1),t.setUint16(1,e.seq&65535),t.setUint8(3,e.keys&255),t.setUint16(4,M(e.yaw)),t.setInt16(6,ne(e.pitch));let n=F(e.view);return t.setUint16(8,n>>8),t.setUint8(10,n&255),t.buffer},re=e=>{if(e.byteLength<7)return null;let t=new DataView(e),n=t.getUint8(3);if(t.getUint8(0)!==2)return null;let r=7+25*n,[i,a,o,s,c]=[14,16,13,14,14].map(n=>{if(e.byteLength<=r)return null;let i=t.getUint8(r),a=r+1;return r=a+n*i,[a,i]});if(!i||!a||!o||!s||!c||e.byteLength!==r)return null;let l=([e,t],n,r)=>Array.from({length:t},(t,i)=>r(e+i*n)),u=[];for(let e=0;e<n;e++){let n=7+e*25;u.push({id:t.getUint8(n),x:t.getFloat32(n+1),y:t.getFloat32(n+5),z:t.getFloat32(n+9),vy:t.getFloat32(n+13),yaw:P(t.getUint16(n+17)),pitch:N(t.getInt16(n+19)),ack:t.getUint16(n+21),cool:t.getUint8(n+23)>>1,ground:(t.getUint8(n+23)&1)==1,hp:t.getUint8(n+24)})}return{tick:t.getUint16(1),players:u,shots:l(i,14,e=>({id:t.getUint8(e),x:t.getFloat32(e+1),y:t.getFloat32(e+5),z:t.getFloat32(e+9),hit:t.getUint8(e+13)===255?-1:t.getUint8(e+13)})),monsters:l(a,16,e=>({id:t.getUint8(e),kind:t.getUint8(e+1)&1,chase:!!(t.getUint8(e+1)&2),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10),yaw:P(t.getUint16(e+14))})),bullets:l(o,13,e=>({id:t.getUint8(e),x:t.getFloat32(e+1),y:t.getFloat32(e+5),z:t.getFloat32(e+9)})),events:l(s,14,e=>({type:t.getUint8(e),id:t.getUint8(e+1),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10)})),level:t.getUint8(4),hard:(t.getUint8(5)&1)==1,phase:t.getUint8(5)>>1&1,keys:t.getUint8(6),items:l(c,14,e=>({id:t.getUint8(e),kind:t.getUint8(e+1),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10)}))}},ie=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},R=44100,z={SHOT:0,BOOM:1,HIT:2,COLLECT:3,CLOCK:4,BURST:5,HEART:6},B=([e,t,n,r,i,a,o,s,c,l,u],d)=>{let f=new Float32Array(Math.ceil((r+i+a)*R)),p=0,m=0,h=0,g=()=>{d=d+1831565813|0;let e=Math.imul(d^d>>>15,1|d);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/2**31-1};for(let d=0;d<f.length;d++){let _=d/R;p+=t*2**(n*_)*(_>c?l:1)*(1+o*Math.sin(_*44))/R,p>=1&&(p%=1,h=g());let v=e==3?h:e==2?Math.sin(p*2*Math.PI):e?1-2*p:p<.5?1:-1;m+=(v-m)*s;let y=_<r?_/r:_<r+i?1:((r+i+a-_)/a)**2;f[d]=m*y*u}return f},ae=[[[3,7e3,-.5,.002,0,.06,0,.6,0,1,.8],[0,220,-5,.002,0,.075,0,.3,0,1,.5]],[[3,500,-1.5,.004,.05,.8,0,.1,0,1,2.2],[2,110,-1.5,.004,.05,.6,0,1,0,1,.8]],[[1,160,-1.5,.003,.04,.22,.2,.5,0,1,.6],[0,83,-1,.003,.04,.22,0,.3,0,1,.4],[3,3e3,0,.002,0,.12,0,.4,0,1,.5]],[[2,880,.3,.005,.06,.4,0,1,.09,1.5,.8],[2,1760,.3,.005,.06,.35,0,1,.09,1.5,.3]],[[3,4e3,0,.001,0,.025,0,.5,0,1,.7],[2,1300,-1,.001,0,.04,0,1,0,1,.5]],[[3,1200,-1,.002,0,.14,0,.45,0,1,.7],[0,3200,-1,.002,0,.05,0,1,.025,.7,.2]],[[2,55,-1,.01,.01,.12,0,1,0,1,.9],[2,110,-1,.01,0,.08,0,1,0,1,.3],[2,48,-1,.01,.01,.14,0,1,0,1,.6,.22],[2,96,-1,.01,0,.09,0,1,0,1,.2,.22]]],oe=e=>{let t=ae[e].map((t,n)=>[B(t,e*9+n),Math.round((t[11]??0)*R)]);return Float32Array.from({length:Math.max(...t.map(([e,t])=>t+e.length))},(e,n)=>Math.tanh(t.reduce((e,[t,r])=>e+(t[n-r]??0),0)))},se=R*60/108,ce=se/4,le=4,ue=[2,150,-6,.002,0,.25,0,1,0,1,1],de=[3,9e3,0,.002,0,.15,0,.5,0,1,.5],fe=[3,3e4,0,.001,0,.04,0,.7,0,1,.15],pe=()=>{let e=new Float32Array(se*4*le),t={},n=(n,r)=>(t[String(r)]??=B(r,1)).forEach((t,r)=>e[(n*ce+r)%e.length]+=t),r=e=>55*2**(e/12),i=[0,0,-4,-5],a=[0,0,12,0,0,7,12,7];for(let e=0;e<64;e++){let t=e%16;if(`x.......x.x.....`[t]==`x`&&n(e,ue),`....x.......x...`[t]==`x`&&n(e,de),t%2==0){n(e,fe);let o=i[e>>4]+a[t>>1];n(e,[1,r(o),0,.005,.08,.18,0,.15,0,1,.6])}}[15,12,10,19,17,15].forEach((e,t)=>n([18,24,28,50,54,60][t],[2,r(e+24),0,.02,.1,.6,.01,1,0,1,.5]));let o=e.reduce((e,t)=>Math.max(e,Math.abs(t)),0);return e.map(e=>e/o*.35)},me=40,he=24,ge=.5,_e=`tiny-fps:muted`,ve=()=>{let e=!1;return{unlock:()=>{},listen:()=>{},play:()=>{},mute:t=>{e=t},get muted(){return e},destroy:()=>{}}},ye=()=>{let e;try{e=new AudioContext}catch{return ve()}let t=(t,n=1)=>{let r=e.createGain();return r.gain.value=n,r.connect(t),r},n=t(e.destination),r=t(n,ge),i=[],a=/* @__PURE__ */ new Set,o=[0,0,0],s=0,c=!1,l=t=>{let n=e.createBuffer(1,t.length,R);return n.getChannelData(0).set(t),n},u=t=>{let n=e.createBufferSource();return n.buffer=t,n};return{unlock(){if(e.resume().catch(()=>{}),!i.length){for(let e of Object.values(z))i[e]=l(oe(e));let e=u(l(pe()));e.loop=!0,e.connect(r),e.start()}},listen(e,t){[o,s]=[e,t]},play(r,c,l=1){let d=0,f=l;if(c){let[e,t,n]=c.map((e,t)=>e-o[t]),r=Math.hypot(e,t,n);f=Math.max(0,1-r/me)**2*l,d=(e*Math.cos(s)-n*Math.sin(s))/Math.max(r,1)}let p=i[r];if(!p||!f)return;if(a.size>=he){let e=[...a].reduce((e,t)=>t.vol<e.vol?t:e);if(e.vol>=f)return;e.src.stop(),a.delete(e)}let m=u(p),h=e.createStereoPanner();h.pan.value=d,m.connect(h).connect(t(n,f));let g={vol:f,src:m};a.add(g),m.onended=()=>a.delete(g),m.start()},mute(t){c=t,n.gain.setTargetAtTime(+!t,e.currentTime,.05)},get muted(){return c},destroy:()=>void e.close().catch(()=>{})}},be=(e,{type:t,id:n,x:r,y:i,z:a},o)=>{let s=[r,i,a];t==f.DIE?e.play(z.BOOM,s):t==f.BOOM?e.play(z.BURST,s):t==f.HURT&&e.play(z.HIT,n==o?void 0:s)},xe=e=>{let t=0;return(n,r)=>{n&&r>=t&&(t=r+1e3,e.play(z.CLOCK))}},Se=e=>{let t=-1/0;return(n,r)=>{if(n<1||n>3)return t=-1/0,0;let i=n>1?800:500;return r-t>=i&&(t=r,e.play(z.HEART,void 0,n>1?.6:1)),1-(r-t)/i}},Ce=()=>{try{return localStorage.getItem(_e)==`1`}catch{return!1}},we=e=>{e.mute(!e.muted);try{localStorage.setItem(_e,e.muted?`1`:`0`)}catch{}return e.muted},Te=1/60,V=Math.PI*2,Ee=1e-6,De=.01,Oe=e=>(e%V+V)%V,ke=e=>[-Math.sin(e),-Math.cos(e)],Ae=Math.fround,je=(e,t,n)=>Math.min(Math.max(e,t),n),Me=({map:e,barred:t},n,r,i,a)=>{if(n.back<0||t.has(n.back))return!0;let o=e.sectors[n.front],s=e.sectors[n.back],c=Math.min(o.ceil,s.ceil);return s.floor>r+a+De||c-Math.max(o.floor,s.floor)<i-De||c<r+i-De},Ne=(e,t,n,r,i)=>{let a=(n-Ee)**2;for(let o=0;o<4;o++){let o=0,s=0,c=0;for(let l of t.edges){let u=l.bx-l.ax,d=l.bz-l.az,f=e.x-l.ax,p=e.z-l.az;if(u*p-d*f<0)continue;let m=je((f*u+p*d)/(u*u+d*d),0,1),h=f-m*u,g=p-m*d,_=h*h+g*g;if(_>=a)continue;let v=Math.sqrt(_);if(n-v<=o||!Me(t,l,e.y,r,i))continue;o=n-v;let y=v||Math.hypot(u,d);s=(v?h:-d)/y*o,c=(v?g:u)/y*o}if(!o)return;e.x+=s,e.z+=c}},Pe=(e,t,n,r,i,a,o)=>{let{map:s,edges:c}=e,l=Math.max(y(e,t,n),0),{floor:u,ceil:d}=s.sectors[l],f=(i-Ee)**2;for(let i of c){if(i.front!==l||i.back<0)continue;let c=i.bx-i.ax,p=i.bz-i.az,m=t-i.ax,h=n-i.az,g=je((m*c+h*p)/(c*c+p*p),0,1);if((m-g*c)**2+(h-g*p)**2<f&&!Me(e,i,r,a,o)){let e=s.sectors[i.back];u=Math.max(u,e.floor),d=Math.min(d,e.ceil)}}return[u,d]},Fe=(n,r,a,o,s)=>{n.x+=r,n.z+=a,Ne(n,s,e,t,i);let[c,l]=Pe(s,n.x,n.z,n.y,e,t,i);n.ground&&o&&(n.vy=7);let u=n.vy-20*Te;n.y+=(n.vy+u)/2*Te,n.vy=u,n.ground=!1,n.y+1.8>l&&(n.y=l-t,n.vy=Math.min(n.vy,0)),(n.vy<=0?n.y<=c+De:n.y<c)&&(n.y=c,n.vy<=0&&(n.vy=0,n.ground=!0)),n.x=Ae(n.x),n.y=Ae(n.y),n.z=Ae(n.z),n.vy=Ae(n.vy)},Ie=(e,t,n)=>{let i=(t.keys&u.FIRE)!==0;e.cool=Math.max(0,e.cool-1),e.yaw=Oe(t.yaw),e.pitch=Math.max(-1.55,Math.min(r,t.pitch));let a=(t.keys&u.FORWARD?1:0)-(t.keys&u.BACK?1:0),o=(t.keys&u.RIGHT?1:0)-(t.keys&u.LEFT?1:0),s=6*Te*(i?.5:1)/(Math.hypot(a,o)||1),[c,l]=ke(e.yaw);return Fe(e,(c*a-l*o)*s,(l*a+c*o)*s,(t.keys&u.JUMP)!==0,n),i&&!e.cool?(e.cool=5,!0):!1},Le=.55,Re=6,ze=(e,t,n=[0,0,0])=>{let r=[];for(let i=1;i<e.length;i++){let[[a,o],[s,c]]=[e[i-1],e[i]],l=Math.hypot(s-a,c-o);if(!l)continue;let[u,d]=[(c-o)/l,-(s-a)/l],f=(e,i,a)=>{let[o,s]=[Math.cos(e*V/t),Math.sin(e*V/t)];r.push(n[0]+i*o,n[1]+i*s,n[2]-a,u*o,u*s,-d)};for(let e=0;e<t;e++)for(let[t,n,r]of[[e,a,o],[e+1,a,o],[e+1,s,c],[e,a,o],[e+1,s,c],[e,s,c]])f(t,n,r)}return r},Be=e=>{let t=[];for(let n=0;n<Re;n++){let r=n*V/Re;t.push(...ze([[0,0],[.02,0],[.02,.45],[.014,.45],[.014,.55],[0,.55]],e,[Math.cos(r)*.05,Math.sin(r)*.05,0]))}return{barrels:t,body:ze([[0,-.3],[.08,-.3],[.09,-.26],[.09,0],[.075,0],[.075,.1],[.03,.1],[.03,.4],[0,.4]],e)}},H=(e,t,n=0)=>{let[r,i,a,o,s,c]=[e,t,n].flatMap(e=>[Math.sin(e),Math.cos(e)]),l=[i,0,-r],u=[r*a,o,i*a];return[l.map((e,t)=>e*c-u[t]*s),u.map((e,t)=>e*c+l[t]*s),[-r*o,a,-i*o]]},U=(e,[t,n,r],[i,a,o],s,c,l=-1)=>{let[u,d]=[Math.sin(s),Math.cos(s)],f=(e,t)=>[e*d+t*u,-e*u+t*d];for(let s=0;s<3;s++)for(let u of[-1,1]){let[d,p]=[(s+1)%3,(s+2)%3],m=[0,0,0];m[s]=u;let[h,g]=f(m[0],m[2]);for(let[_,v]of[[-1,-1],[1,-1],[1,1],[-1,-1],[1,1],[-1,1]]){let y=[0,0,0];[y[s],y[d],y[p]]=[u,_,v];let[b,x]=f(y[0]*i,y[2]*o);e.push(t+b,n+y[1]*a,r+x,h,m[1],g,c[0],c[1],l,c[2])}}},Ve=(e,[t,n,r])=>Array.from({length:e.length*(10/6)},(i,a)=>{let[o,s]=[Math.floor(a/10),a%10];return s<6?e[o*6+s]:[t,n,-1,r][s-6]}),He=(e,t,n,[r,i,a],o,s,c=0)=>{let[l,u]=[Math.sin(c),Math.cos(c)],d=(e,t,n)=>[0,1,2].map(o=>r[o]*(e*u-t*l)+i[o]*(e*l+t*u)-a[o]*n),f=[0,1,2].map(e=>n[e]+r[e]*o[0]+i[e]*o[1]+a[e]*o[2]);for(let n=0;n<t.length;n+=10){let r=d(t[n]*s,t[n+1]*s,t[n+2]*s);e.push(f[0]+r[0],f[1]+r[1],f[2]+r[2],...d(t[n+3],t[n+4],t[n+5])),e.push(...t.slice(n+6,n+10))}},Ue=.3,We=3.6,W={body:[.27,.22,.25],arm:[.4,.26,.22],leg:[.18,.17,.22],head:[.45,.33,.3],shell:[.36,.2,.32],fin:[.5,.25,.25],gore:[.6,.08,.07],calm:[.6,.05,.04],chase:[1,.3,.15],blob:[1,.3,.05],core:[1,.8,.4]},Ge=[[W.body,W.arm,W.head,W.gore,W.gore,W.chase],[W.shell,W.fin,W.shell,W.gore,W.chase]],Ke=e=>e?W.chase:W.calm,G=({x:e,y:t,z:n,yaw:r},i,a,o)=>{let[s,c]=[Math.sin(r),Math.cos(r)];return[e+i*c-o*s,t+a,n-i*s-o*c]},qe=(e,t,n,r,i,a)=>{let o=[];U(o,[0,-i[1],0],i,0,a),He(e,o,t,H(n,r),[0,0,0],1)},Je=e=>e<.25?-.8*Math.sin(e*4*Math.PI):2*Math.sin((e-.25)*Math.PI/.75),Ye=(e,t,n,r)=>{let i=Math.sin(n*We)*.6,a=o*.44,s=o*.8,[c,l]=[-1,1].map(e=>G(t,e*.16,a,0));qe(e,c,t.yaw,i,[.09,a/2,.09],W.leg),qe(e,l,t.yaw,-i,[.09,a/2,.09],W.leg),qe(e,G(t,-.35,s,0),t.yaw,-i*.8,[.07,.34,.07],W.arm),qe(e,G(t,.35,s,0),t.yaw,i*.8+(r>0?Je(r):0),[.07,.34,.07],W.arm),U(e,G(t,0,1.142,0),[.26,.35,.16],t.yaw,W.body),U(e,G(t,0,1.6500000000000001,0),[.15,.15,.15],t.yaw,W.head);let u=t.chase?.06:.045;for(let n of[-1,1])U(e,G(t,n*.075,1.69,.15),[u,u*.7,.02],t.yaw,Ke(t.chase),-2)},Xe=Ve(ze([[0,0],[.18,.06],[s,.32],[s*.93,.5],[.22,.78],[0,c]],8),W.shell),Ze=(e,t,n)=>{let r=Math.sin(n*2+t.id)*.06,i=[t.x,t.y+r,t.z];He(e,Xe,i,H(0,Math.PI/2),[0,0,0],1);for(let r=0;r<4;r++){let a=n*1.5+r*V/4;U(e,[t.x+Math.cos(a)*.4,i[1]+.35,t.z+Math.sin(a)*.4],[.16,.03,.04],-a,W.fin)}let a=G({...t,y:i[1]},0,c*.45,s*.9),o=t.chase?1.3:1;U(e,a,[.1*o,.07*o,.05],t.yaw,Ke(t.chase),-2)},Qe=(e,t,n)=>{let r=[t.x,t.y,t.z];if(U(e,r,[l*.8,l*.8,l*.8],0,W.blob,-2),U(e,r,[l*.5,l*.5,l*.5],Math.PI/4,W.core,-2),n)for(let t of[1,2]){let i=l*(1-t*.3);U(e,r.map((e,r)=>e-n[r]*t*.2),[i,i,i],0,W.blob,-2)}},$e=.05,et=.3,tt=96,nt=64,rt=12,it=40,at=[5,1.6,5],ot=Math.cos(.436),st=6,ct=.3,lt=.45,ut=.4,dt=.5,ft=.9,pt=.3,mt=14,ht=4.4,gt=.035,_t=.03,vt=30,yt=({r:e,t})=>{let n=t/ct;return n<1?e*Math.sqrt(n)*(1-n*n*n):0},bt=({r:e,t,life:n})=>{let r=t/n;return e*(.3+.7*Math.min(1,r*2))*Math.min(1,(1-r)/.3)},xt=(e,t,n)=>{let r=[];for(let i=0;i<e.motes.length&&!e.dead;i+=3){let a=[0,1,2].map(n=>e.motes[i+n]-t[n]),o=Math.hypot(...a),s=(a[0]*n[0]+a[1]*n[1]+a[2]*n[2])/o;o<st&&s>ot&&r.push(...a.map((e,n)=>t[n]+e),(s-ot)/(1-ot)*(1-o/st))}return r},St=(e=64)=>{let t=[];return{clear(){t=[]},push(n,r){t.push(...n.map(e=>({t:r,v:e}))),t.splice(0,t.length-e)},due(e){let n=t.findIndex(({t})=>t+100>e);return t.splice(0,n<0?t.length:n).map(({v:e})=>e)}}},Ct=(e=Math.random,t)=>{let r=t,i=0,a=0,o=0,s=0,c=0,l=0,d=!0,p=/* @__PURE__ */ new Float32Array(384),m,h=()=>e()*2-1,g=/* @__PURE__ */ new Map,_=(e,t,n,r)=>{C.sparks.length<tt&&C.sparks.push({p:e,v:t,life:n,c:r})},v=(t,n,r,i)=>{for(let a=0;a<n;a++){let[n,a]=[e()*V,h()],o=Math.sqrt(1-a*a)*r*(.5+e()*.5);_(t,[Math.cos(n)*o,a*r,Math.sin(n)*o],et*(.6+e()*.4),i)}},x=(t,n,r)=>{for(let i=0;i<n;i++)C.smoke.push({p:t.map(e=>e+h()*.3),v:[h()*.5,.5+e()*.7,h()*.5],r:r*(.7+e()*.6),yaw:e()*V,t:0,life:1.5+e()});C.smoke.splice(0,C.smoke.length-it)},S=(e,t)=>{C.blasts.push({p:e,r:t,t:0}),C.blasts.splice(0,C.blasts.length-rt)},C={bob:0,roll:0,shakeYaw:0,shakePitch:0,kick:0,spin:0,flash:0,flashes:/* @__PURE__ */ new Map,sparks:[],gibs:[],blasts:[],smoke:[],motes:/* @__PURE__ */ new Float32Array(384),hurt:0,gain:0,gainC:[1,1,1],dead:0,swings:/* @__PURE__ */ new Map,herd:/* @__PURE__ */ new Map,aim:/* @__PURE__ */ new Map,update(e,t,f,g=!1){let _=Math.min(1,f*10),v=e&&m?.ground&&e.ground?Math.hypot(e.x-m.x,e.z-m.z):0;v<1&&(i+=v*ht),a+=(+(v>.5*f&&v<1)-a)*_,m=e,C.dead=Math.max(0,Math.min(1,C.dead+(g?f:-f)/dt));let b=C.dead*C.dead*(3-2*C.dead);C.bob=Math.sin(i)*gt*a-b*(n-pt);let x=+!!(t&u.RIGHT)-!!(t&u.LEFT);s+=(x*_t-s)*Math.min(1,f*8),C.roll=s+b*ft,o*=Math.exp(-f*12),C.shakeYaw=h()*o,C.shakePitch=h()*o,C.kick*=Math.exp(-f*18),C.flash=Math.max(0,C.flash-f);for(let[e,t]of C.flashes)t>f?C.flashes.set(e,t-f):C.flashes.delete(e);c=Math.max(0,Math.min(vt,c+(t&u.FIRE?60:-25)*f)),C.spin=(C.spin+c*f)%V;for(let e of C.sparks)e.v[1]-=9.8*f,e.p=e.p.map((t,n)=>t+e.v[n]*f),e.life-=f;C.sparks=C.sparks.filter(e=>e.life>0),C.hurt=Math.max(0,C.hurt-f),C.gain=Math.max(0,C.gain-f);for(let[e,t]of C.swings)t>f?C.swings.set(e,t-f):C.swings.delete(e);for(let e of C.blasts)e.t+=f;C.blasts=C.blasts.filter(e=>e.t<ct);for(let e of C.gibs)e.life-=f,e.rest||w(e,f);C.gibs=C.gibs.filter(e=>e.life>0);for(let{p:e,v:t}of C.smoke)e.forEach((n,r)=>e[r]=n+t[r]*f),e[1]=Math.min(e[1],r?.map.sectors[y(r,e[0],e[2])]?.ceil??1/0);for(let e of C.smoke)e.t+=f;C.smoke=C.smoke.filter(e=>e.t<e.life),e&&(l+=f,C.motes.forEach((t,r)=>{let[i,a]=[r%3,at[r%3]],o=i==1?e.y+n:i?e.z:e.x;p[r]=d?h()*.1:p[r];let s=d?o+h()*a:t+(p[r]+Math.sin(l*.8+r)*.05)*f;C.motes[r]=o+((s-o+a)%(2*a)+2*a)%(2*a)-a}),d=!1)},hit(){C.hurt=lt},pickup(e){[C.gain,C.gainC]=[ut,e]},reset(e){r=e,C.sparks=[],C.gibs=[],C.blasts=[],C.smoke=[],d=!0,C.flashes.clear(),C.swings.clear(),C.herd.clear(),C.aim.clear(),g.clear(),C.hurt=C.gain=C.flash=0},shot(t,n,r,i=!0){r?(C.kick=1,C.flash=$e,o=.012):C.flashes.set(t.id,$e);let a=[t.x,t.y,t.z],s=n.map((e,t)=>e-a[t]),c=Math.hypot(...s);if(i&&c>0&&c<99.99)for(let t=0;t<4;t++){let t=s.map(t=>t/c*(2+e()*2)+h());t[1]+=1,_(a,t,et*(.6+e()*.4))}},track(e,t){for(let{id:t,kind:n,x:r,z:i}of e){let e=C.herd.get(t),a=e?Math.hypot(r-e.x,i-e.z):0;C.herd.set(t,{x:r,z:i,kind:n,walked:(e?.walked??0)+(a<1?a:0)})}let n=/* @__PURE__ */ new Map;for(let{id:e,x:r,y:i,z:a}of t){let[t,o]=[g.get(e),[r,i,a]],s=t?Math.hypot(o[0]-t[0],o[1]-t[1],o[2]-t[2]):0;t&&s>1e-4&&C.aim.set(e,o.map((e,n)=>(e-t[n])/s)),n.set(e,o)}g=n;for(let e of C.aim.keys())n.has(e)||C.aim.delete(e)},event({type:t,id:n,x:i,y:a,z:o},s){let c=[i,a,o];if(t==f.DIE){let t=Ge[C.herd.get(n)?.kind??0]??Ge[0],s=10+Math.floor(e()*7);for(let n=0;n<s;n++){let n=e()*V,s=1.5+e()*3.5;C.gibs.push({p:[i,a+h()*.3,o],v:[Math.cos(n)*s,2+e()*4,Math.sin(n)*s],yaw:e()*V,size:.05+e()*.08,c:t[Math.floor(e()*t.length)],life:2+e(),floor:r?.map.sectors[y(r,i,o)]?.floor??a,rest:!1})}C.gibs.splice(0,C.gibs.length-nt),S(c,.6),v(c,14,5),x(c,6+Math.floor(e()*3),.3)}else t==f.BOOM?(S(c,.25),v(c,8,3),x(c,3,.15)):t==f.HURT?n!=s&&v(c,8,3,[1,.12,.08]):t==f.SWING&&C.swings.set(n,Ue)}},w=(e,t)=>{e.v[1]-=mt*t;let n=e.p.map((n,r)=>n+e.v[r]*t);r&&b(r,e.p,n)&&(e.v[0]*=-.3,e.v[2]*=-.3,[n[0],n[2]]=[e.p[0],e.p[2]]);let i=r?.map.sectors[y(r,n[0],n[2])];e.floor=i?.floor??e.floor,i&&n[1]>i.ceil-e.size&&(n[1]=i.ceil-e.size,e.v[1]=Math.min(e.v[1],0)*.3),n[1]<=e.floor+e.size&&(n[1]=e.floor+e.size,e.v[1]<-3?e.v=[e.v[0]*.5,-e.v[1]*.3,e.v[2]*.5]:(e.v=[0,0,0],e.rest=!0)),e.p=n};return C},wt=[[1,1,1],[.95,.15,.1],[.2,.4,1],[1,.85,.15]],Tt=(e,t=1)=>`rgba(${e.map(e=>Math.round(e*255))},${t})`,Et=.3,Dt=[.25,1,.45],Ot=[.85,.1,.1],kt=[.05,.05,.06],At=(e,[t,n,r],[i,a,o],s,c,l,u=-1)=>{let[d,f]=[Math.sin(c),Math.cos(c)];U(e,[t+i*f+o*d,n+a,r-i*d+o*f],s,c,l,u)},jt=(e,{id:t,kind:n,x:r,y:i,z:a},o)=>{let s=o*2+t,c=[r,i+(n?.55:.4)+Math.sin(o*2.5+t)*.07,a],l=wt[n];if(n==p.HEALTH){U(e,c,[.2,.2,.2],s,l);for(let t of[[.21,.06,.21],[.06,.21,.21],[.21,.21,.06]])U(e,c,t,s,Ot)}else At(e,c,[0,.17,0],[.1,.1,.025],s,l,-2),At(e,c,[0,.17,0],[.04,.04,.035],s,kt),At(e,c,[0,-.1,0],[.025,.17,.025],s,l),At(e,c,[.06,-.24,0],[.05,.03,.025],s,l),At(e,c,[.045,-.15,0],[.035,.025,.025],s,l)},Mt=({map:e},{front:t,back:n})=>{let[r,i]=[e.sectors[t],e.sectors[n]];return[Math.max(r.floor,i.floor),Math.min(r.ceil,i.ceil)]},Nt=(e,t,n,r,i,a,o=-1)=>{let[s,c]=[t.bx-t.ax,t.bz-t.az];U(e,[(t.ax+t.bx)/2,n,(t.az+t.bz)/2],[Math.hypot(s,c)/2,r,i],Math.atan2(-c,s),a,o)},Pt=(e,t,n)=>{let{gates:r=[],exit:i}=t.map;for(let{sector:n,key:i}of r){if(!t.barred.has(n))continue;let r=wt[i];for(let i of t.edges.filter(e=>e.front==n&&e.back>=0)){let[n,a]=Mt(t,i),o=Math.ceil(Math.hypot(i.bx-i.ax,i.bz-i.az)/Et);for(let t=0;t<o;t++){let s=(t+.5)/o;U(e,[i.ax+(i.bx-i.ax)*s,(n+a)/2,i.az+(i.bz-i.az)*s],[.03,(a-n)/2,.03],0,r)}Nt(e,i,n+.1,.04,.04,r),Nt(e,i,a-.1,.04,.04,r)}}if(i!==void 0&&!t.barred.has(i)){let r=Dt.map(e=>e*(.75+.25*Math.sin(n*4)));for(let n of t.edges.filter(e=>e.front==i&&e.back>=0)){let[i,a]=Mt(t,n);for(let t of[i+.04,a-.04])Nt(e,n,t,.04,.04,r,-2);for(let[t,o]of[[n.ax,n.az],[n.bx,n.bz]])U(e,[t,(i+a)/2,o],[.05,(a-i)/2,.05],0,r,-2)}}},Ft=(e,t,n)=>{let r=t.map.goal,i=r&&t.map.sectors[y(t,r[0],r[1])]?.floor;if(!r||i===void 0)return;let a=Math.sin(n*4),[o,s]=[1*(.7+a*.07),[1,.85,.25].map(e=>e*(.75+a*.25))];for(let t of[0,1])U(e,[r[0],i+.03+t*.005,r[1]],[o,.03,o],n/2+t*Math.PI/4,s,-2);U(e,[r[0],i+.8+Math.sin(n*2)*.1,r[1]],[.15,.15,.15],n*2,[1,.95,.5],-2)},It=(e,t,n,r)=>{for(let t of n)jt(e,t,r);Pt(e,t,r),Ft(e,t,r)},Lt={TITLE:0,NOTE:1},Rt=[2,3,8],zt=2,Bt=.35,Vt=`h1,h2,h4,h5,ul,ol,aside,section,s{position:absolute;margin:0;padding:0;pointer-events:none;user-select:none;white-space:pre-line}h1,h2,h4{left:0;right:0;text-align:center}h1{top:14%;font-size:20px;line-height:1.4}h1::first-line{font-size:44px}h2{top:32%;font-size:22px}h5{top:8px;right:12px;font-size:12px}h4{top:28%;font-size:22px;line-height:1.5;color:#fcc;text-shadow:0 2px 8px #800}h4::first-line{font-size:52px;color:#f33}s{inset:0;opacity:0}s:first-of-type{background:radial-gradient(#d000 45%,#d00 115%)}ul{--f:0;--s:0;--d:0;left:12px;bottom:12px;width:min(40vw,140px);height:22px;border-radius:4px;overflow:hidden;background:#0009;box-shadow:0 0 0 1px #0008,0 0 0 calc(var(--d)*3px) #f22;transform:translateX(calc(var(--s)*1px));filter:brightness(calc(1 + var(--f)*2))}ul li{position:absolute;top:0;bottom:0;left:0;transition:width .15s}ul li+li{right:0;width:auto;text-align:center;line-height:22px;font-size:14px}ol{left:calc(22px + min(40vw,140px));bottom:12px;display:flex;gap:4px;list-style:none}ol li{width:16px;height:22px;border-radius:3px;box-shadow:0 0 0 1px #0008}aside,section{inset:0;z-index:1;display:flex;flex-direction:column;align-items:center;gap:14px;padding:0 12px;text-align:center;background:#000b}aside{justify-content:center}section{padding-top:10%;font-size:20px}:is(aside,section):not([hidden])~:is(h1,h2){visibility:hidden}h6{margin:0;font-size:inherit;text-shadow:none}aside h6{font:900 clamp(36px,13vw,84px)/1 system-ui,sans-serif;letter-spacing:.04em;transform:skewX(-8deg);background:linear-gradient(#fe6,#f92 45%,#d21);-webkit-background-clip:text;background-clip:text;color:transparent;filter:drop-shadow(0 3px 0 #500) drop-shadow(0 0 14px #f604)}section h6{font-size:20px;line-height:1.5}section h6::first-line{font-size:48px}strong{font-size:22px}small{font-size:16px;opacity:.8}table{border-collapse:collapse;font-size:16px}td,th{padding:2px 10px}th{opacity:.6}td+td,th+th{text-align:left}td+td+td,th+th+th{text-align:right}aside td:first-child{text-align:right;opacity:.7}`,Ht=e=>{e.insertAdjacentHTML(`beforeend`,`<s></s><s></s><ul><li></li><li></li></ul><ol>${`<li hidden></li>`.repeat(3)}</ol><aside hidden><h6>TINY FPS</h6><span></span><table><tr><td>Mouse<td>look<tr><td>WASD / ZQSD<td>move<tr><td>Space<td>jump<tr><td>Left click<td>fire<tr><td>M<td>mute</table><strong></strong></aside><section hidden><h6></h6><table><thead><tr><th><th>Player<th>Kills<th>Deaths</thead><tbody></tbody></table><small></small></section><h1 hidden></h1><h2 hidden></h2><h4 hidden></h4><h5 hidden>Muted (M)</h5>`);let t=t=>e.querySelector(t),[n,r]=[...e.querySelectorAll(`s`)],[i,a,o]=[t(`ul`),t(`ul li`),t(`ul li+li`)],s=[...e.querySelectorAll(`ol li`)],[c,l,u,d]=[`h4`,`h5`,`section`,`aside`].map(e=>t(e)),[f,p,m]=[`section h6`,`section tbody`,`small`].map(e=>t(e)),[h,g]=[`aside span`,`strong`].map(e=>t(e)),_=[t(`h1`),t(`h2`),u];s.forEach((e,t)=>e.style.background=Tt(wt[t+1]));let v=Rt.map(()=>0),y=0,[b,x]=[0,0],S=(e,t)=>e.textContent!=t&&(e.textContent=t);return{hp(e){y&&(b=e>y?Bt:b,x=e<y?Bt:x),y=e,a.style.width=`${e/9*100}%`,a.style.background=`hsl(${(Math.max(e,1)-1)/8*110},75%,42%)`,S(o,String(e))},keys:e=>s.forEach((t,n)=>t.hidden=!(e>>n+1&1)),dead(e){c.hidden=!e,e&&S(c,`You died\nRespawn in ${e}`)},fade(e,t,i,a){n.style.opacity=String(Math.max(e*.9,t&&.2+t*.4)),r.style.opacity=String(i*.32),r.style.background=Tt(a)},title(e,t){d.hidden=!e,S(h,t),S(g,e)},end(e,t,n){S(f,e),S(m,n),p.replaceChildren(...t.map(([e,t,n,r])=>{let i=document.createElement(`tr`);return[`●`,e,n,r].forEach((e,n)=>{let r=i.insertCell();r.textContent=String(e),r.style.color=n?``:t}),i})),_[zt].hidden=!1,v[zt]=Rt[zt]},mute:e=>l.hidden=!e,say(e,t){_[e].textContent=t,_[e].hidden=!1,v[e]=Rt[e]},update(e){v.forEach((t,n)=>{t>0&&(v[n]=t-e)<=0&&(_[n].hidden=!0)}),b=Math.max(0,b-e),x=Math.max(0,x-e);for(let[e,t]of[[`--f`,b/Bt],[`--d`,x/Bt],[`--s`,Math.sin(x*90)*8*x/Bt]])i.style.setProperty(e,String(t))}}},Ut=.0025,Wt=Math.PI*2,Gt={KeyW:u.FORWARD,ArrowUp:u.FORWARD,KeyS:u.BACK,ArrowDown:u.BACK,KeyA:u.LEFT,ArrowLeft:u.LEFT,KeyD:u.RIGHT,ArrowRight:u.RIGHT,Space:u.JUMP},Kt=e=>Gt[e]??0,qt=(e,t=()=>{})=>{let n=new AbortController,i=(e,t,r)=>e.addEventListener(t,r,{signal:n.signal}),a={yaw:0,pitch:0,keys:0,locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>n.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{a.locked()&&(a.yaw=((a.yaw-e.movementX*Ut)%Wt+Wt)%Wt,a.pitch=Math.max(-1.55,Math.min(r,a.pitch-e.movementY*Ut)))}),i(document,`keydown`,e=>{let n=Kt(e.code);e.code==`KeyM`&&!e.repeat&&a.locked()&&t(),n&&a.locked()&&(a.keys|=n,e.preventDefault())}),i(document,`keyup`,e=>{a.keys&=~Kt(e.code)}),i(document,`mousedown`,e=>{e.button==0&&a.locked()&&(a.keys|=u.FIRE)}),i(document,`mouseup`,e=>{e.button==0&&(a.keys&=~u.FIRE)});let o=()=>{a.keys=0};return i(window,`blur`,o),i(document,`pointerlockchange`,()=>a.locked()||o()),a},Jt=e=>{for(let t=0;t<2;t++)e=Math.imul(e^e>>>16,73244475);return(e^e>>>16)>>>0},Yt=(e,t,n)=>{let[r,i,o,s]=[Math.sin(e),Math.cos(e),Math.sin(t),Math.cos(t)],c=Jt(n+1),l=(c&65535)/65536*V,u=(c>>>16)/65535,[d,f]=[Math.cos(l)*u*a,Math.sin(l)*u*a],p=[-r*s+i*d+r*o*f,o+s*f,-i*s-r*d+i*o*f],m=Math.hypot(...p);return[p[0]/m,p[1]/m,p[2]/m]},Xt=(e,t,n,r)=>{let{map:i,edges:a}=e,o=Math.max(y(e,t[0],t[2]),0),s=0;for(let e=0;e<=i.sectors.length;e++){let{floor:e,ceil:c}=i.sectors[o],l=1/0,u;for(let e of a){if(e.front!==o)continue;let[r,i]=[e.bx-e.ax,e.bz-e.az],a=n[2]*r-n[0]*i;if(a>=0)continue;let c=Math.max(((t[2]-e.az)*r-(t[0]-e.ax)*i)/-a,s),d=((t[0]+c*n[0]-e.ax)*r+(t[2]+c*n[2]-e.az)*i)/(r*r+i*i);d>-1e-9&&d<1+1e-9&&(c<l-1e-9||c<l+1e-9&&e.back<0)&&([l,u]=[c,e])}let d=n[1]<0?(e-t[1])/n[1]:n[1]>0?(c-t[1])/n[1]:1/0;if(d<=l||!u)return Math.min(Math.max(d,s),r);if(l>=r)return r;let f=t[1]+l*n[1],p=u.back<0?void 0:i.sectors[u.back];if(!p||f<Math.max(e,p.floor)||f>Math.min(c,p.ceil))return l;[o,s]=[u.back,l]}return s},Zt=(e,t,n)=>{let[r,i]=[e[0]-n.x,e[2]-n.z],a=t[0]*t[0]+t[2]*t[2],o=r*t[0]+i*t[2],s=r*r+i*i-n.r*n.r,[c,l]=[0,1/0];if(a>1e-12){let e=o*o-a*s;if(e<0)return 1/0;[c,l]=[Math.max(0,(-o-Math.sqrt(e))/a),(-o+Math.sqrt(e))/a]}else if(s>0)return 1/0;let[u,d]=[n.y-e[1],n.y+n.h-e[1]];if(t[1]){let[e,n]=[u/t[1],d/t[1]];c=Math.max(c,Math.min(e,n)),l=Math.min(l,Math.max(e,n))}else if(u>0||d<0)return 1/0;return c<=l?c:1/0},Qt=({id:n,x:r,y:i,z:a})=>({id:n,x:r,y:i,z:a,r:e,h:t}),$t=({id:e,kind:t,x:n,y:r,z:i})=>{let a=t===d.WALKER;return{id:e,x:n,y:r,z:i,r:a?.4:s,h:a?o:c}},en=(e,t,r,i)=>{let a=[t.x,t.y+n,t.z],o=Yt(t.yaw,t.pitch,r),s=Xt(e,a,o,100),c=-1;for(let e of i){let n=e.id===t.id?1/0:Zt(a,o,e);n<s&&([s,c]=[n,e.id])}return{id:t.id,x:a[0]+o[0]*s,y:a[1]+o[1]*s,z:a[2]+o[2]*s,hit:c}},tn=120,nn=16,K=({id:e,x:t,y:n,z:r,vy:i,yaw:a,pitch:o,ground:s,cool:c})=>({id:e,x:t,y:n,z:r,vy:i,yaw:a,pitch:o,ground:s,cool:c}),rn=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,z:e.z+(t.z-e.z)*n}),an=(e,t,n)=>Oe(e+(((t-e+Math.PI)%V+V)%V-Math.PI)*n),on=(e,t)=>(t-e&65535)<32768,sn=(e,t,n)=>({...t,...rn(e,t,n),yaw:an(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),cn=e=>{let t=e,n,r=0,i=[],a,o,s,c=!0,l=/* @__PURE__ */ new Map,u=[],d=e=>{let t=e-100,n=0;for(;n+1<u.length&&u[n+1].t<=t;)n++;let r=u[n],i=u[n+1]??r;return{a:r,b:i,u:i.t>r.t?Math.max(0,Math.min(1,(t-r.t)/(i.t-r.t))):0}},f=e=>{if(!u.length)return;let{a:t,b:n,u:r}=d(e);return(t.s.tick+(n.s.tick-t.s.tick&65535)*r)%65536},p=e=>{let t=u.at(-1);if(!t)return[];let{a:r,b:i,u:a}=d(e);return t.s.players.filter(e=>e.id!==n).map(e=>{let t=r.s.players.find(t=>t.id===e.id),n=i.s.players.find(t=>t.id===e.id);return t&&n?sn(K(t),K(n),a):K(n??t??e)})},m=(e,t,n)=>{if(!u.length)return[];let{a:r,b:i,u:a}=d(e),o=t(r.s);return t(i.s).map(e=>{let t=o.find(t=>t.id===e.id);return t?n(t,e,a):e})},h=e=>m(e,e=>e.monsters,(e,t,n)=>({...t,...rn(e,t,n),yaw:an(e.yaw,t.yaw,n)}));return{you:e=>{n=e},step:(e,n)=>{let d=I({...e,seq:r,view:n===void 0?void 0:f(n)});if(s=void 0,r=r+1&65535,i.push(d),i.length>tn&&i.shift(),a&&(o=K(a),c&&Ie(a,d,t))){let e=n??1/0,r=h(e).filter(e=>!l.has(e.id)),i=u.at(-1)?.s.players??[],o=p(e).filter(e=>i.find(t=>t.id===e.id)?.hp);s=en(t,a,d.seq,[...o.map(Qt),...r.map($t)]),s.hit>=16&&l.set(s.hit,d.seq)}return d},snapshot:(e,r)=>{u.push({t:r,s:e}),u.length>nn&&u.shift(),_(t,e.keys,e.phase);let s=e.players.find(e=>e.id===n);s&&(c=s.hp>0,i=i.filter(e=>!on(e.seq,s.ack)),l.forEach((t,n)=>{let r=e=>e.monsters.some(e=>e.id===n);on(t,s.ack)&&(r(e)||!u.some(e=>r(e.s)))&&l.delete(n)}),a=K(s),o=K(a),i.forEach((e,n)=>{n===i.length-1&&(o=K(a)),c&&Ie(a,e,t)}))},monsters:h,bullets:e=>m(e,e=>e.bullets,(e,t,n)=>({...t,...rn(e,t,n)})),level:e=>{t=e,u.length=0,l.clear(),a=o=s=void 0},shot:()=>s,me:e=>a&&o?sn(o,a,Math.max(0,Math.min(1,e))):void 0,others:p}},ln={SPOT:0,POINT:1},un=[1.2,1.1,.9],dn=[3,1.4,.4],fn=Math.cos(.436),pn=.5,mn=2,hn=4,q=(e,t,n)=>({kind:ln.POINT,p:e,d:[0,0,0],cone:0,range:t,color:n,shadow:!1}),gn=(e,t,n,r,i,a=!1)=>({...q(e,r,i),kind:ln.SPOT,d:t,cone:n,shadow:a}),_n=(e,...t)=>e.map((e,n)=>e+t.reduce((e,[t,r])=>e+t[n]*r,0)),vn=(e,t)=>e.map(e=>e*t),yn=4,bn=/* @__PURE__ */ new WeakMap,xn=e=>{let t=bn.get(e);return t||(t=e.map.sectors.filter(e=>e.ft==h.LAVA).map(({pts:e,floor:t})=>{let[n,r]=[0,1].map(t=>e.map(e=>e[t])),[i,a]=[Math.max(...n)-Math.min(...n),Math.max(...r)-Math.min(...r)];return{p:[(Math.max(...n)+Math.min(...n))/2,t+2,(Math.max(...r)+Math.min(...r))/2],range:4+Math.sqrt(i*a)*.6}}),bn.set(e,t)),t},Sn=(e,t)=>{let n=e[0]+e[2];return vn([1.4,.45,.12],1+.18*Math.sin(t*1.3+n)+.1*Math.sin(t*11+n*3)+.06*Math.sin(t*23+n))},Cn=({eye:e,yaw:t,pitch:r,dead:i,others:a,fx:o,bullets:s,lvl:c,t:l})=>{let[u,d,f]=H(t,r),p=[];i||(p.push(gn(_n(e,[u,.2],[d,-.2]),f,fn,25,un,!0)),o.flash>0&&p.push(gn(_n(e,[u,.26],[d,-.24],[f,.6+Le*.8]),f,pn,8,dn,!0)));let m=t=>Math.hypot(t[0]-e[0],t[1]-e[1],t[2]-e[2]),h=[];a.map(e=>({p:e,e:[e.x,e.y+n,e.z]})).sort((e,t)=>m(e.e)-m(t.e)).forEach(({p:e,e:t},n)=>{let[r,i,a]=H(e.yaw,e.pitch);h.push(gn(_n(t,[a,.35]),a,fn,25,un,n<mn)),o.flashes.has(e.id)&&h.push(q(_n([e.x,e.y+1.25,e.z],[r,.36],[i,-.12],[a,.8]),6,dn))});for(let e of o.blasts){let t=yt(e);t>0&&h.push(q(e.p,6,vn(dn,t*6)))}o.hurt>0&&h.push(q(e,4,vn([2,.15,.1],Math.min(1,o.hurt*10)))),s.map(e=>q([e.x,e.y,e.z],3,[1.2,.4,.15])).sort((e,t)=>m(e.p)-m(t.p)).slice(0,hn).forEach(e=>h.push(e)),xn(c).filter(e=>m(e.p)<e.range*2).map(({p:e,range:t})=>q(e,t,Sn(e,l))).sort((e,t)=>m(e.p)-m(t.p)).slice(0,yn).forEach(e=>h.push(e));let{exit:g,goal:_}=c.map;if(g!==void 0){let e=1+.3*Math.sin(l*4);if(c.barred.has(g)){if(_){let t=c.map.sectors[y(c,_[0],_[1])]?.floor??0;h.push(q([_[0],t+1,_[1]],8,vn([.2,1.2,1.5],e)))}}else{let{floor:t}=c.map.sectors[g];for(let{ax:n,az:r,bx:i,bz:a,front:o,back:s}of c.edges)if(o==g&&s>=0){let[o,s]=[i-n,a-r],c=.5/Math.hypot(o,s);h.push(q([(n+i)/2-s*c,t+1.2,(r+a)/2+o*c],8,vn([.2,1.5,.3],e)))}}}return p.concat(h.sort((e,t)=>m(e.p)-m(t.p)).slice(0,16-p.length))},wn=1.5,Tn=(e,t)=>{let n=A[e]?.name;return`Level ${e+1}${n?`: ${n}`:``}${t?` (hard mode)`:``}`},En=e=>{let t=Math.floor(e*10/60);return`${Math.floor(t/600)}:${String(Math.floor(t/10)%60).padStart(2,`0`)}.${t%10}`},Dn=({spawns:e},t,n)=>e.reduce((e,r)=>Math.hypot(r[0]-t,r[1]-n)<Math.hypot(e[0]-t,e[1]-n)?r:e)[2],On=({lvl:e,you:t,roster:n,predictor:r,rd:i,delays:a,fx:o,hud:s,audio:c})=>{let l=-1,u=-1,d=0,f=/* @__PURE__ */ new Map,p={lvl:e,items:[],dead:!1,hp:0,name:Tn(0,!1),returning:!1,alive:e=>f.get(e)!==0,snapshot(e){let n=t(),h=e.level*2+ +e.hard;if(h!=l){let t=A[e.level];if(!t)return;l=h,p.lvl=g(t),p.items=[],f=/* @__PURE__ */ new Map,u=-1,r.level(p.lvl),i?.level(p.lvl),o.reset(p.lvl),a.forEach(e=>e.clear()),p.name=Tn(e.level,e.hard),s.say(Lt.TITLE,`Level ${e.level+1}${e.hard?`
|
|
2
|
+
Hard mode`:``}`)}let _=e.players.find(e=>e.id==n),v=f.get(n);_&&v!==void 0&&_.hp<v&&o.hit(),f=new Map(e.players.map(e=>[e.id,e.hp]));for(let t of p.items)_&&!e.items.some(e=>e.id==t.id)&&Math.hypot(t.x-_.x,t.z-_.z)<wn&&(o.pickup(wt[t.kind]),c?.play(z.COLLECT));p.items=e.items,e.phase!=u&&(u=e.phase,p.returning=u==m.RETURN,s.say(Lt.NOTE,u==m.RETURN?`Back to the start!`:`Find the exit`)),_?.hp===0&&!p.dead&&(d=e.tick),p.dead=_?.hp===0,p.hp=_?.hp??0,s.hp(p.hp),s.keys(e.keys);let y=180-(e.tick-d&65535);s.dead(p.dead?Math.max(1,Math.ceil(y/60)):0)},end(e,t,r){let i=new Map(n().map(e=>[e.id,e])),a=r.filter(e=>i.has(e.id)).sort((e,t)=>t.kills-e.kills||e.deaths-t.deaths||e.id-t.id).map(({id:e,kills:t,deaths:n})=>[i.get(e).name,i.get(e).color,t,n]);s.end(`Run complete\n${En(e)}${t?` (hard)`:``}`,a,`Next run: Hard mode`)}};return p},kn=Object.keys(h).length,J=(e,t,n)=>{let r=Math.imul(e,374761393)+Math.imul(t,668265263)+Math.imul(n,144665)|0;return r=Math.imul(r^r>>>13,1274126177),((r^r>>>16)>>>0)/4294967296},Y=(e,t,n,r)=>{let[i,a]=[Math.floor(e),Math.floor(t)],[o,s]=[e-i,t-a].map(e=>e*e*(3-2*e)),c=(e,t)=>J((i+e)%n,(a+t)%n,r);return(c(0,0)*(1-o)+c(1,0)*o)*(1-s)+(c(0,1)*(1-o)+c(1,1)*o)*s},An=(e,t,n,r,i)=>{let[a,o]=[0,.5];for(let s=0;s<r;s++,o/=2)a+=o*Y(e*(1<<s),t*(1<<s),n<<s,i+s);return a/(1-o*2)},X=(e,t,n)=>e.map((e,r)=>e+(t[r]-e)*n),Z=(e,t)=>e.map(e=>e*t),Q=e=>Math.min(Math.max(e,0),1),jn=Math.PI*2,$=[];$[h.BRICK]=(e,t)=>{let n=Math.floor(t*8),r=e*4+(n&1)*.5,[i,a,o]=[Math.floor(r)%4,r%1,t*8%1],s=Y(e*16,t*16,16,5),c=.8+.4*s;return a<.05||o<.1?[Z([165,160,150],.7+.3*c),.1+.1*s]:[Z([170,78,56],(.8+.4*J(i,n,1))*c*(.85+.15*o)),.7+.2*s+.1*Q(Math.min(a-.05,o-.1)*12)]},$[h.TILE]=(e,t)=>{let[n,r]=[Math.floor(e*4),Math.floor(t*4)],[i,a]=[e*4%1,t*4%1],o=Y(e*16,t*16,16,7),s=.9+.2*o;return i<.05||a<.05?[Z([85,85,80],s),.1]:[Z([196,190,172],s*(.88+.08*(n+r&1)+.1*J(n,r,2))),.8+.1*o+.1*Q((Math.min(i,a)-.05)*14)]},$[h.LAVA]=(e,t)=>{let n=An(e*4,t*4,4,4,11),r=Math.max(0,1-Math.abs(n-.5)*7)**2;return[X(X([55,8,4],[230,70,8],n),[255,215,90],r),.5]},$[h.STONE]=(e,t)=>{let n=An(e*8,t*8,8,4,3);return[Z([128,124,120],.45+.7*(n*1.3+.1*J(Math.floor(e*128),Math.floor(t*128),4))),Q(n*1.4-.2)]},$[h.METAL]=(e,t)=>{let[n,r,i,a]=[Math.floor(e*2),Math.floor(t*2),e*2%1,t*2%1],o=Q((Y(e*8,t*8,8,13)-.68)*6),s=e=>Math.min(Math.max(Math.round((e-.1)/.4),0),2)*.4+.1,[c,l]=[s(i),s(a)],u=c==l&&c==.5?1:Math.hypot(i-c,a-l),d=Q(1-u/.07),f=Z([98,108,124],(.9+.2*Y(e*32,t*32,32,9)+.12*J(n,r,6))*(1+.3*d)*(.65+.35*Q((u-.06)/.04)));return Math.min(i,a,1-i,1-a)<.03?[Z([40,44,50],1+o),.05]:[X(f,[105,68,45],o*.7),.5+.1*(1-o)+.4*d]},$[h.WOOD]=(e,t)=>{let n=Math.floor(t*8),r=e*2+J(n,0,8)*2,[i,a,o]=[Math.floor(r)%2,r%1,t*8%1],s=J(n,i,3),c=.5+.5*Math.sin(jn*(t*40+2.5*Y(e*4,t*4,4,21)+s*7));return o<.08||a<.015?[[28,18,10],.05]:[X([92,58,32],[158,106,62],c*.6+s*.35),.7+.15*c+.15*Q((o-.08)*15)]},$[h.MOSS]=(e,t)=>{let n=Math.floor(t*4),r=e*2+(n&1)*.5,[i,a,o]=[Math.floor(r)%2,r%1,t*4%1],s=Math.min(a,1-a,(o<.5?o:1-o)*.5),c=a<.04||o<.06,l=Q((.3*An(e*12,t*12,12,3,17)-.03-s)*12),u=Y(e*64,t*64,64,19),d=Z([128,126,118],(.7+.4*J(i,n,5))*(.7+.5*Y(e*16,t*16,16,15)));return[X(c?Z(d,.45):d,X([52,100,34],[96,148,56],u),l),c?.1+.6*l*u:.6+.2*Q(s*30)+.2*l*u]},$[h.GRATE]=(e,t)=>{let[n,r]=[e*8%1,t*8%1],i=Math.max(Math.abs(n-.5),Math.abs(r-.5)),a=Math.min(Math.abs(n-.5),Math.abs(r-.5))>.43,o=Y(e*16,t*16,16,23);return i<.36?[[9,9,12],0]:[Z(X([104,108,116],[96,80,68],Q((o-.55)*4)),(a?1.25:1)-(.5-i)*2.2+.2*o),a?1:.6+.4*Q((i-.36)*12)]};var Mn=()=>{let e=new Uint8ClampedArray(kn*128*128*4);return $.forEach((t,n)=>{for(let r=0;r<16384;r++){let[i,a]=t(r%128/128,Math.floor(r/128)/128);e.set([...i,a*255],(n*128*128+r)*4)}}),e},Nn=[.05,.045,.05,.02],Pn=1<<18,Fn=2,In=512,Ln=.3,Rn=.55,zn=`#version 300 es
|
|
3
3
|
layout(location=0)in vec3 p;layout(location=1)in vec3 n;layout(location=2)in vec4 c;
|
|
4
4
|
uniform mat4 m;out vec3 P,N;out vec4 C;
|
|
5
|
-
void main(){P=p;N=n;C=c;gl_Position=m*vec4(p,1);}`,
|
|
5
|
+
void main(){P=p;N=n;C=c;gl_Position=m*vec4(p,1);}`,Bn=[[.04,8],[.25,30],[0,1],[.08,10],[.8,48],[.06,12],[.3,20],[.7,40],[.1,24]],Vn=`#version 300 es
|
|
6
6
|
precision highp float;precision highp sampler2DArray;precision highp sampler2DArrayShadow;
|
|
7
7
|
in vec3 P,N;in vec4 C;uniform vec3 E;uniform float T,Z;uniform int Q;
|
|
8
|
-
uniform vec4 A[16],B[16],K[16];uniform mat4 M[4];
|
|
8
|
+
uniform vec4 A[16],B[16],K[16],F;uniform vec3 G[16];uniform mat4 M[4];
|
|
9
9
|
uniform sampler2DArray S;uniform sampler2DArrayShadow D;out vec4 o;
|
|
10
|
+
const vec2 SP[${Bn.length}]=vec2[](${Bn.map(([e,t])=>`vec2(${e},${t})`)});
|
|
11
|
+
vec3 e(vec3 x){return 2.*(1.-exp(-.5*x));}
|
|
10
12
|
void main(){
|
|
11
13
|
if(Z<0.)return;
|
|
12
|
-
float L=C.z,s=step(0.,L),g=step(abs(L-${h.LAVA}.),.5)+step(L,-1.5);
|
|
13
|
-
|
|
14
|
-
vec3
|
|
14
|
+
float L=C.z,s=step(0.,L),I=floor(C.w*.5),g=step(abs(L-${h.LAVA}.),.5)+step(L,-1.5);
|
|
15
|
+
vec4 t=texture(S,vec3(C.xy/${Fn}.+vec2(g*T*.01,0),max(L,0.)));
|
|
16
|
+
vec3 c=mix(vec3(C.xy,C.w),t.rgb,s);
|
|
17
|
+
vec3 n=normalize(N),dx=dFdx(P),dy=dFdy(P),a=cross(dy,n),b=cross(n,dx);
|
|
18
|
+
float h=t.a*s*0.06,det=dot(dx,a);
|
|
19
|
+
float f=1.-smoothstep(.6,2.5,${128/Fn}.*max(length(dFdx(C.xy)),length(dFdy(C.xy))));
|
|
20
|
+
vec3 m=normalize(abs(det)*n-sign(det)*f*(dFdx(h)*a+dFdy(h)*b)+n*1e-9);
|
|
21
|
+
vec2 R=SP[int(s>0.?L+.5:${kn}.)];
|
|
22
|
+
vec3 l=mix(vec3(1),G[int(min(I,15.))]*(C.w-2.*I),s)*Z*(.45+.55*max(dot(normalize(n+m),normalize(vec3(.4,.8,.3))),0.)),sp=vec3(0),V=normalize(E-P);
|
|
15
23
|
for(int i=0;i<16;i++){
|
|
16
24
|
if(i>=Q||g>0.)break;
|
|
17
25
|
vec3 d=A[i].xyz-P;float r=length(d),k=K[i].w,u=B[i].w;
|
|
18
26
|
d/=r;
|
|
19
27
|
float w=max(1.-r*r/(A[i].w*A[i].w),0.);
|
|
20
|
-
w*=w*smoothstep(u,u+(1.-u)*.4,-dot(d,B[i].xyz))*max(dot(
|
|
28
|
+
w*=w*smoothstep(u,u+(1.-u)*.4,-dot(d,B[i].xyz))*max(dot(m,d),0.);
|
|
21
29
|
if(w>0.&&k>=0.){
|
|
22
30
|
vec4 q=M[int(k)]*vec4(P+n*.03,1);q.xyz=q.xyz/q.w*.5+.5;
|
|
23
31
|
float v=0.;
|
|
24
|
-
for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/
|
|
32
|
+
for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/In},k,q.z-.0005));
|
|
25
33
|
w*=v/4.;}
|
|
26
|
-
l+=K[i].rgb*w;
|
|
27
|
-
|
|
28
|
-
c
|
|
29
|
-
o=vec4(mix(c,vec3(${vn}),1.-exp(-.02*length(P-E))),1);}`,En=(e,t,n,r,i=0,a=Math.tan(70*Math.PI/360),[o,s]=[.1,200])=>{let[c,l,u]=U(t,n,i),d=(s+o)/(s-o),f=[c.map(e=>e/(a*r)),l.map(e=>e/a),u.map(e=>e*d),u].map(t=>[...t,-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]);return f[2][3]-=2*s*o/(s-o),Float32Array.from({length:16},(e,t)=>f[t&3][t>>2])},Dn=(e,t,n,r)=>{let i=e[3]*t+e[7]*n+e[11]*r+e[15];if(i<=0)return;let a=e[0]*t+e[4]*n+e[8]*r+e[12],o=e[1]*t+e[5]*n+e[9]*r+e[13];return[.5+a/(2*i),.5-o/(2*i)]},On=({p:e,d:t,cone:n,range:r})=>En(e,Math.atan2(-t[0],-t[2]),Math.atan2(t[1],Math.hypot(t[0],t[2])),1,0,Math.min(Math.tan(Math.acos(n)),5.7),[.3,r]),kn=e=>{let[t,n,r]=[0,0,0].map(()=>/* @__PURE__ */ new Float32Array(64)),i=/* @__PURE__ */ new Float32Array(64),a=0,o=e.slice(0,16);return o.forEach((e,o)=>{let s=e.shadow&&e.kind==Yt.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==Yt.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(On(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},An=({map:e},{front:t,back:n})=>{let r=e.sectors[t];if(n<0)return[[r.floor,r.ceil]];let i=e.sectors[n];return[[r.floor,i.floor],[i.ceil,r.ceil]].filter(([e,t])=>t>e)},jn=e=>{let t=[];for(let{pts:n,floor:r,ceil:i,ft:a,ct:o,light:s=1}of e.map.sectors)for(let[e,c,l]of[[r,1,a],[i,-1,o]])for(let r=1;r<n.length-1;r++)for(let[i,a]of[n[0],n[r],n[r+1]])t.push(i,e,a,0,c,0,i,a,l,s);for(let n of e.edges){let{ax:r,az:i,bx:a,bz:o,front:s}=n,{wt:c,light:l=1}=e.map.sectors[s],u=Math.hypot(a-r,o-i),[d,f]=[(a-r)/u,(o-i)/u];for(let[s,u]of An(e,n))for(let[e,n,p]of[[r,i,s],[a,o,s],[a,o,u],[r,i,s],[a,o,u],[r,i,u]])t.push(e,p,n,-f,0,d,e*d+n*f,p,c,l)}return t},Mn=(n,r)=>{let i=r,a=n.getContext(`webgl2`,{antialias:!0});if(!a)throw Error(`WebGL2 is not available`);let o=document.createElement(`canvas`).getContext(`2d`),s=/* @__PURE__ */ new Map,c=e=>{let t=s.get(e);if(!t){o.fillStyle=`#888`,o.fillStyle=e;let n=parseInt(o.fillStyle.slice(1),16),r=n>=0?n:8947848;s.set(e,t=[r>>16,r>>8&255,r&255].map(e=>e/255))}return t},l=jn(i),u=_n(),f=l.length*4,p=f+yn,[m,h]=[[.55,.55,.6],[.2,.2,.23]],g={barrels:Le(Ie(10).barrels,m),body:Le(Ie(10).body,h)},_={barrels:Le(Ie(5).barrels,m),body:Le(Ie(5).body,h)},v=[],y=[];for(let e of[[.1,.01,.03],[.01,.1,.03],[.03,.03,.05]])W(v,[0,0,-Ne-.04],e,0,[1,.85,.4],-2),W(y,[0,0,-Ne-.12],e.map(e=>e*3),0,[1,.85,.4],-2);let b={},x,S,C=!1,w=/* @__PURE__ */ new Float32Array(16),T=()=>{a.bufferData(a.ARRAY_BUFFER,p,a.DYNAMIC_DRAW),a.bufferSubData(a.ARRAY_BUFFER,0,new Float32Array(l))},E=()=>{let e=a.createProgram();for(let[t,n]of[[a.VERTEX_SHADER,wn],[a.FRAGMENT_SHADER,Tn]]){let r=a.createShader(t);a.shaderSource(r,n),a.compileShader(r),a.attachShader(e,r)}a.linkProgram(e),a.useProgram(e),b=Object.fromEntries([`m`,`E`,`T`,`Z`,`Q`,`A`,`B`,`K`,`M`,`D`].map(t=>[t,a.getUniformLocation(e,t)])),a.uniform1i(b.D,1),a.bindBuffer(a.ARRAY_BUFFER,a.createBuffer()),T(),[3,3,4].reduce((e,t,n)=>(a.enableVertexAttribArray(n),a.vertexAttribPointer(n,t,a.FLOAT,!1,40,e*4),e+t),0),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D_ARRAY,x=a.createTexture()),a.texStorage3D(a.TEXTURE_2D_ARRAY,1,a.DEPTH_COMPONENT24,xn,xn,4);for(let[e,t]of[[a.TEXTURE_MIN_FILTER,a.LINEAR],[a.TEXTURE_MAG_FILTER,a.LINEAR],[a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE],[a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE],[a.TEXTURE_COMPARE_MODE,a.COMPARE_REF_TO_TEXTURE]])a.texParameteri(a.TEXTURE_2D_ARRAY,e,t);a.bindFramebuffer(a.FRAMEBUFFER,S=a.createFramebuffer()),a.drawBuffers([a.NONE]),a.bindFramebuffer(a.FRAMEBUFFER,null),a.polygonOffset(2,4),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D_ARRAY,a.createTexture()),a.texImage3D(a.TEXTURE_2D_ARRAY,0,a.RGBA8,128,128,fn,0,a.RGBA,a.UNSIGNED_BYTE,u),a.generateMipmap(a.TEXTURE_2D_ARRAY),a.texParameteri(a.TEXTURE_2D_ARRAY,a.TEXTURE_MIN_FILTER,a.LINEAR_MIPMAP_LINEAR);let t=a.getExtension(`EXT_texture_filter_anisotropic`);t&&a.texParameterf(a.TEXTURE_2D_ARRAY,t.TEXTURE_MAX_ANISOTROPY_EXT,8),a.enable(a.DEPTH_TEST),a.clearColor(vn[0],vn[1],vn[2],1)};E();let D=e=>{e.preventDefault(),C=!0},O=()=>{E(),C=!1};return n.addEventListener(`webglcontextlost`,D),n.addEventListener(`webglcontextrestored`,O),{level(e){i=e,l=jn(i),f=l.length*4,p=f+yn,C||T()},frame(r,o,s,u,m,h,E,D,O,k){let A=Math.min(devicePixelRatio,2),j=Math.round(n.clientWidth*A),M=Math.round(n.clientHeight*A);if(C||!j||!M)return;(n.width!=j||n.height!=M)&&(n.width=j,n.height=M),w=En(r,o,s,j/M,h.roll);let N=[];for(let n of u){let[r,i]=Te(n.yaw),a=e*.8,o=1.4500000000000002;W(N,[n.x,n.y+o/2,n.z],[a,o/2,a],n.yaw,[...c(m.get(n.id)??`#888`)]);let s=[n.x,n.y+t-.17,n.z];W(N,s,[.17,.17,.17],n.yaw,[.95,.8,.65]),W(N,[s[0]+r*.17,s[1]+.03,s[2]+i*.17],[.13,.05,.03],n.yaw,[.1,.1,.12]);let l=[n.x,n.y+1.25,n.z],u=U(n.yaw,n.pitch);for(let e of[_.barrels,_.body,h.flashes.has(n.id)?y:[]])G(N,e,l,u,[.36,-.12,.3],.8)}let P=performance.now()/1e3;for(let e of E)if(e.kind==d.FLYER)Ke(N,e,P);else{let t=h.swings.get(e.id);We(N,e,h.herd.get(e.id)?.walked??0,t?1-t/Re:0)}wt(N,i,O,P);for(let{p:e,yaw:t,size:n,c:r,life:i}of h.gibs){let a=n*Math.min(1,i*2);W(N,e,[a,a,a],t,r)}let F=N.length;for(let e of D)qe(N,e,h.aim.get(e.id));for(let{p:e,c:t}of h.sparks)W(N,e,[.025,.025,.025],0,t??[1,.8,.3],-2);for(let e of h.blasts){let[t,n]=[ut(e),e.t/$e],r=[1,.9-n*.7,.5-n*.45];for(let n of[0,Math.PI/4])W(N,e.p,[t,t,t],n,r,-2)}let I=N.length,ee=U(o,s,h.roll),te=[.26,-.24+h.kick*.01,.6-h.kick*.06];h.dead||(G(N,g.body,r,ee,te,.8),G(N,g.barrels,r,ee,te,.8,h.spin),h.flash>0&&G(N,v,r,ee,te,.8,h.spin*3)),f+N.length*4>p&&(p=f+N.length*8,T()),a.bufferSubData(a.ARRAY_BUFFER,f,new Float32Array(N));let L=kn(k),R=l.length/10;if(L.maps){a.uniform1f(b.Z,-1),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D_ARRAY,null),a.bindFramebuffer(a.FRAMEBUFFER,S),a.viewport(0,0,xn,xn),a.enable(a.POLYGON_OFFSET_FILL);for(let e=0;e<L.maps;e++)a.framebufferTextureLayer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,x,0,e),a.uniformMatrix4fv(b.m,!1,L.m.subarray(e*16,e*16+16)),a.clear(a.DEPTH_BUFFER_BIT),a.drawArrays(a.TRIANGLES,0,R+F/10);a.disable(a.POLYGON_OFFSET_FILL),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindTexture(a.TEXTURE_2D_ARRAY,x),a.activeTexture(a.TEXTURE0)}a.viewport(0,0,j,M),a.uniformMatrix4fv(b.m,!1,w),a.uniform3fv(b.E,r),a.uniform1f(b.T,performance.now()/1e3),a.uniform1f(b.Z,Sn),a.uniform1i(b.Q,L.n),a.uniform4fv(b.A,L.a),a.uniform4fv(b.B,L.b),a.uniform4fv(b.K,L.k),a.uniformMatrix4fv(b.M,!1,L.m),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT),a.drawArrays(a.TRIANGLES,0,R+I/10),a.clear(a.DEPTH_BUFFER_BIT),a.uniform1f(b.Z,Cn),a.drawArrays(a.TRIANGLES,R+I/10,(N.length-I)/10)},project:(e,t,n)=>Dn(w,e,t,n),destroy(){n.removeEventListener(`webglcontextlost`,D),n.removeEventListener(`webglcontextrestored`,O),a.getExtension(`WEBGL_lose_context`)?.loseContext()}}},Nn=1/60,Pn=5,Fn=(e,i)=>{let a=document.createElement(`div`),o=a.attachShadow({mode:`open`});o.innerHTML=`<style>:host{display:block;width:100%;height:100%}div{position:relative;width:100%;height:100%;overflow:hidden;background:#000;font:600 14px system-ui,sans-serif;color:#fff;text-shadow:0 1px 2px #000}canvas{display:block;width:100%;height:100%;cursor:pointer}i,p,b{position:absolute;pointer-events:none;user-select:none;margin:0}`+Ot+`i{left:50%;top:50%;width:6px;height:6px;margin:-3px;border-radius:50%;background:#fff;box-shadow:0 0 0 1px #0008}p{top:8px;left:12px}b{transform:translate(-50%,-100%);font-size:12px;white-space:nowrap}[hidden]{display:none}</style><div><canvas></canvas><i></i><p></p></div>`,e.append(a);let s=o.querySelector(`canvas`),c=o.querySelector(`p`),l=o.querySelector(`div`),u=kt(l),d={roster:[],open:[],close:[]},f=e=>d[e].forEach(e=>e()),p=g(O[0]),m=Jt(p),h=he();h.mute(ye()),u.mute(h.muted);let _=_e(h),v=ve(h),y=Pt(s,()=>u.mute(be(h)));s.addEventListener(`click`,()=>h.unlock());let x=ft(Math.random,p),S=dt(),C=dt(),w=-1,T;try{T=Mn(s,p)}catch{}let E=dn({lvl:p,you:()=>w,roster:()=>D,predictor:m,rd:T,delays:[S,C],fx:x,hud:u,audio:h}),D=[],k=/* @__PURE__ */ new Map,A=/* @__PURE__ */ new Map,j=/* @__PURE__ */ new Map,M=!1,N=T?``:`WebGL2 is not available`,P=!1,F=-1,I=!1,R=performance.now(),B=0,ne=0,re=!1,V=i.socket??new WebSocket(i.url);V.binaryType=`arraybuffer`,V.onopen=()=>{M=!0,V.send(JSON.stringify({t:`join`,name:i.name})),f(`open`)},V.onclose=()=>{M=!1,N||=`Connection closed`,f(`close`)},V.onmessage=({data:e})=>{if(typeof e!=`string`){let t=te(e);if(t){let e=performance.now();E.snapshot(t),m.snapshot(t,e);let n=t.players.find(e=>e.id==w),r=t.level*2+ +t.hard;n?.hp&&(r!=F||!I)&&([y.yaw,y.pitch]=[un(E.lvl.map,n.x,n.z),0]),[F,I]=[r,!!n?.hp],S.push(t.shots.filter(e=>e.id!=w),e),C.push(t.events,e)}return}let t=L(e);t?.t==`roster`?(D=t.players,k=new Map(D.map(e=>[e.id,e.color])),A=new Map(D.map(e=>[e.id,e.name])),m.you(w=t.you),c.textContent=`Players: ${D.length}`,f(`roster`)):t?.t==`full`?N=`Room is full`:t?.t==`end`&&E.end(t.ticks,t.hard,t.stats)};let ie=e=>{let t=j.get(e);return t||(j.set(e,t=document.createElement(`b`)),l.append(t)),t},ae=()=>{ne=requestAnimationFrame(ae);let e=performance.now(),i=R;if(B=Math.min(B+(e-R)/1e3,Pn*Nn),R=e,!P){let e=m.me(0);e&&([y.yaw,y.pitch,P]=[e.yaw,e.pitch,!0]),B=0}for(;P&&B>=Nn;B-=Nn){let t=E.dead?0:y.keys,r=m.step({keys:t,yaw:y.yaw,pitch:y.pitch},e);M&&V.send(ee(r));let i=m.shot(),a=i&&m.me(1);i&&a&&(x.shot(i,[a.x,a.y+n,a.z],!0),h.play(z.SHOT))}let a=m.me(B/Nn),o=m.others(e).filter(e=>E.alive(e.id)),s=m.monsters(e),c=m.bullets(e),l=a?[a.x,a.y+n,a.z]:[0,0,0];x.track(s,c),h.listen(l,y.yaw);for(let t of S.due(e)){let e=o.find(e=>e.id==t.id);if(e){let r=[e.x,e.y+n,e.z];x.shot(t,r,!1,t.hit!=w),h.play(z.SHOT,r)}}for(let t of C.due(e))x.event(t,w),ge(h,t,w);_(E.returning,e);let d=Math.min((e-i)/1e3,.1);if(x.update(a,y.keys,d,E.dead),u.update(d),a&&T){let t=Math.max(-1.55,Math.min(r,y.pitch+x.shakePitch));T.frame([l[0],l[1]+x.bob,l[2]],y.yaw+x.shakeYaw,t,o,k,x,s,c,E.items,on({eye:[l[0],l[1]+x.bob,l[2]],yaw:y.yaw,pitch:y.pitch,dead:E.dead,others:o,fx:x,bullets:c,lvl:E.lvl,t:e/1e3}))}let f=/* @__PURE__ */ new Set;for(let e of o){let n=[e.x,e.y+t+.3,e.z],r=a&&!b(E.lvl,l,n)?T?.project(...n):void 0,i=ie(e.id);f.add(e.id),i.hidden=!r,r&&(i.style.left=r[0]*100+`%`,i.style.top=r[1]*100+`%`);let o=A.get(e.id)??``;i.textContent!=o&&(i.textContent=o)}for(let[e,t]of j)f.has(e)||(t.remove(),j.delete(e));u.fade(x.hurt/et,v(E.hp,e),x.gain/tt,x.gainC),u.title(N||(M?P?y.locked()?``:`Click to play`:`Joining…`:`Connecting…`),E.name)};return ne=requestAnimationFrame(ae),{on:(e,t)=>void d[e].push(t),players:()=>D,destroy(){re||(re=!0,cancelAnimationFrame(ne),y.destroy(),h.destroy(),T?.destroy(),V.onopen=V.onclose=V.onmessage=null,V.close(),document.exitPointerLock(),a.remove())}}};export{Fn as tinyFps};
|
|
34
|
+
l+=K[i].rgb*w;
|
|
35
|
+
sp+=K[i].rgb*w*pow(max(dot(m,normalize(d+V)),0.),R.y);}
|
|
36
|
+
c=c*mix(e(l),vec3(1.4),g)+e(sp*R.x*(.4+.6*mix(1.,t.a,s)));
|
|
37
|
+
o=vec4(mix(c,F.rgb,1.-exp(-F.a*length(P-E))),1);}`,Hn=(e,t,n,r,i=0,a=Math.tan(70*Math.PI/360),[o,s]=[.1,200])=>{let[c,l,u]=H(t,n,i),d=(s+o)/(s-o),f=[c.map(e=>e/(a*r)),l.map(e=>e/a),u.map(e=>e*d),u].map(t=>[...t,-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]);return f[2][3]-=2*s*o/(s-o),Float32Array.from({length:16},(e,t)=>f[t&3][t>>2])},Un=(e,t,n,r)=>{let i=e[3]*t+e[7]*n+e[11]*r+e[15];if(i<=0)return;let a=e[0]*t+e[4]*n+e[8]*r+e[12],o=e[1]*t+e[5]*n+e[9]*r+e[13];return[.5+a/(2*i),.5-o/(2*i)]},Wn=({p:e,d:t,cone:n,range:r})=>Hn(e,Math.atan2(-t[0],-t[2]),Math.atan2(t[1],Math.hypot(t[0],t[2])),1,0,Math.min(Math.tan(Math.acos(n)),5.7),[.3,r]),Gn=e=>{let[t,n,r]=[0,0,0].map(()=>/* @__PURE__ */ new Float32Array(64)),i=/* @__PURE__ */ new Float32Array(64),a=0,o=e.slice(0,16);return o.forEach((e,o)=>{let s=e.shadow&&e.kind==ln.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==ln.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(Wn(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},Kn=({map:e},{front:t,back:n})=>{let r=e.sectors[t];if(n<0)return[[r.floor,r.ceil]];let i=e.sectors[n];return[[r.floor,i.floor],[i.ceil,r.ceil]].filter(([e,t])=>t>e)},qn=({map:e})=>[...new Map([[`1,1,1`,[1,1,1]],...e.sectors.flatMap(({tint:e})=>e?[[`${e}`,e]]:[])]).values()].slice(0,16),Jn=e=>{let t=[],n=qn(e).map(String),r=({light:e=1,tint:t})=>e+2*Math.max(0,n.indexOf(`${t}`));for(let n of e.map.sectors){let{pts:e,floor:i,ceil:a,ft:o,ct:s}=n,c=r(n);for(let[n,r,l]of[[i,1,o],[a,-1,s]])for(let i=1;i<e.length-1;i++)for(let[a,o]of[e[0],e[i],e[i+1]])t.push(a,n,o,0,r,0,a,o,l,c)}for(let n of e.edges){let{ax:i,az:a,bx:o,bz:s,front:c}=n,{wt:l}=e.map.sectors[c],u=r(e.map.sectors[c]),d=Math.hypot(o-i,s-a),[f,p]=[(o-i)/d,(s-a)/d];for(let[r,c]of Kn(e,n))for(let[e,n,d]of[[i,a,r],[o,s,r],[o,s,c],[i,a,r],[o,s,c],[i,a,c]])t.push(e,d,n,-p,0,f,e*f+n*p,d,l,u)}return t},Yn=2073600,Xn=(e,t,n)=>{let r=Math.min(n,2,Math.sqrt(Yn/(e*t||1)));return[Math.round(e*r),Math.round(t*r)]},Zn=(n,r)=>{let i=r,a=n.getContext(`webgl2`,{antialias:!0});if(!a)throw Error(`WebGL2 is not available`);let o=document.createElement(`canvas`).getContext(`2d`),s=/* @__PURE__ */ new Map,c=e=>{let t=s.get(e);if(!t){o.fillStyle=`#888`,o.fillStyle=e;let n=parseInt(o.fillStyle.slice(1),16),r=n>=0?n:8947848;s.set(e,t=[r>>16,r>>8&255,r&255].map(e=>e/255))}return t},l=Jn(i),u=Mn(),f=l.length*4,p=f+Pn,[m,h]=[[.55,.55,.6],[.2,.2,.23]],g={barrels:Ve(Be(10).barrels,m),body:Ve(Be(10).body,h)},_={barrels:Ve(Be(5).barrels,m),body:Ve(Be(5).body,h)},v=[],y=[];for(let e of[[.1,.01,.03],[.01,.1,.03],[.03,.03,.05]])U(v,[0,0,-Le-.04],e,0,[1,.85,.4],-2),U(y,[0,0,-Le-.12],e.map(e=>e*3),0,[1,.85,.4],-2);let b={},x,S,C=!1,w=/* @__PURE__ */ new Float32Array(16),T=()=>{a.bufferData(a.ARRAY_BUFFER,p,a.DYNAMIC_DRAW),a.bufferSubData(a.ARRAY_BUFFER,0,new Float32Array(l))},E=()=>{let e=a.createProgram();for(let[t,n]of[[a.VERTEX_SHADER,zn],[a.FRAGMENT_SHADER,Vn]]){let r=a.createShader(t);a.shaderSource(r,n),a.compileShader(r),a.attachShader(e,r)}a.linkProgram(e),a.useProgram(e),b=Object.fromEntries([`m`,`E`,`T`,`Z`,`Q`,`A`,`B`,`K`,`M`,`D`,`F`,`G`].map(t=>[t,a.getUniformLocation(e,t)])),a.uniform1i(b.D,1),a.bindBuffer(a.ARRAY_BUFFER,a.createBuffer()),T(),[3,3,4].reduce((e,t,n)=>(a.enableVertexAttribArray(n),a.vertexAttribPointer(n,t,a.FLOAT,!1,40,e*4),e+t),0),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D_ARRAY,x=a.createTexture()),a.texStorage3D(a.TEXTURE_2D_ARRAY,1,a.DEPTH_COMPONENT24,In,In,4);for(let[e,t]of[[a.TEXTURE_MIN_FILTER,a.LINEAR],[a.TEXTURE_MAG_FILTER,a.LINEAR],[a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE],[a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE],[a.TEXTURE_COMPARE_MODE,a.COMPARE_REF_TO_TEXTURE]])a.texParameteri(a.TEXTURE_2D_ARRAY,e,t);a.bindFramebuffer(a.FRAMEBUFFER,S=a.createFramebuffer()),a.drawBuffers([a.NONE]),a.bindFramebuffer(a.FRAMEBUFFER,null),a.polygonOffset(2,4),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D_ARRAY,a.createTexture()),a.texImage3D(a.TEXTURE_2D_ARRAY,0,a.RGBA8,128,128,kn,0,a.RGBA,a.UNSIGNED_BYTE,u),a.generateMipmap(a.TEXTURE_2D_ARRAY),a.texParameteri(a.TEXTURE_2D_ARRAY,a.TEXTURE_MIN_FILTER,a.LINEAR_MIPMAP_LINEAR);let t=a.getExtension(`EXT_texture_filter_anisotropic`);t&&a.texParameterf(a.TEXTURE_2D_ARRAY,t.TEXTURE_MAX_ANISOTROPY_EXT,8),a.enable(a.DEPTH_TEST),D()},D=()=>{let e=i.map.fog??Nn,t=qn(i);a.uniform4fv(b.F,e),a.uniform3fv(b.G,Float32Array.from({length:48},(e,n)=>t[n/3|0]?.[n%3]??1)),a.clearColor(e[0],e[1],e[2],1)};E();let O=e=>{e.preventDefault(),C=!0},ee=()=>{E(),C=!1};return n.addEventListener(`webglcontextlost`,O),n.addEventListener(`webglcontextrestored`,ee),{level(e){i=e,l=Jn(i),f=l.length*4,p=f+Pn,C||(T(),D())},frame(r,o,s,u,m,h,E,D,O,ee){let[k,A]=Xn(n.clientWidth,n.clientHeight,devicePixelRatio);if(C||!k||!A)return;(n.width!=k||n.height!=A)&&(n.width=k,n.height=A),w=Hn(r,o,s,k/A,h.roll);let j=[];for(let n of u){let[r,i]=ke(n.yaw),a=e*.8,o=1.4500000000000002;U(j,[n.x,n.y+o/2,n.z],[a,o/2,a],n.yaw,[...c(m.get(n.id)??`#888`)]);let s=[n.x,n.y+t-.17,n.z];U(j,s,[.17,.17,.17],n.yaw,[.95,.8,.65]),U(j,[s[0]+r*.17,s[1]+.03,s[2]+i*.17],[.13,.05,.03],n.yaw,[.1,.1,.12]);let l=[n.x,n.y+1.25,n.z],u=H(n.yaw,n.pitch);for(let e of[_.barrels,_.body,h.flashes.has(n.id)?y:[]])He(j,e,l,u,[.36,-.12,.3],.8)}let M=performance.now()/1e3;for(let e of E)if(e.kind==d.FLYER)Ze(j,e,M);else{let t=h.swings.get(e.id);Ye(j,e,h.herd.get(e.id)?.walked??0,t?1-t/Ue:0)}It(j,i,O,M);for(let{p:e,yaw:t,size:n,c:r,life:i}of h.gibs){let a=n*Math.min(1,i*2);U(j,e,[a,a,a],t,r)}let te=j.length;for(let e of D)Qe(j,e,h.aim.get(e.id));for(let e of h.smoke){let[t,n]=[bt(e),.42-.32*(e.t/e.life)];for(let r of[e.yaw,e.yaw+Math.PI/4])U(j,e.p,[t,t,t],r,[n,n,n*1.05])}let[,,ne]=H(o,s),N=xt(h,r,ne);for(let e=0;e<N.length;e+=4){let[t,n]=[Math.sqrt(N[e+3]),.01+.025*N[e+3]];U(j,N.slice(e,e+3),[n,n,n],0,[t,t*.9,t*.7],-2)}for(let{p:e,c:t}of h.sparks)U(j,e,[.025,.025,.025],0,t??[1,.8,.3],-2);for(let e of h.blasts){let[t,n]=[yt(e),e.t/ct],r=[1,.9-n*.7,.5-n*.45];for(let n of[0,Math.PI/4])U(j,e.p,[t,t,t],n,r,-2)}let P=j.length,F=H(o,s,h.roll),I=[.26,-.24+h.kick*.01,.6-h.kick*.06];h.dead||(He(j,g.body,r,F,I,.8),He(j,g.barrels,r,F,I,.8,h.spin),h.flash>0&&He(j,v,r,F,I,.8,h.spin*3)),f+j.length*4>p&&(p=f+j.length*8,T()),a.bufferSubData(a.ARRAY_BUFFER,f,new Float32Array(j));let L=Gn(ee),re=l.length/10;if(L.maps){a.uniform1f(b.Z,-1),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D_ARRAY,null),a.bindFramebuffer(a.FRAMEBUFFER,S),a.viewport(0,0,In,In),a.enable(a.POLYGON_OFFSET_FILL);for(let e=0;e<L.maps;e++)a.framebufferTextureLayer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,x,0,e),a.uniformMatrix4fv(b.m,!1,L.m.subarray(e*16,e*16+16)),a.clear(a.DEPTH_BUFFER_BIT),a.drawArrays(a.TRIANGLES,0,re+te/10);a.disable(a.POLYGON_OFFSET_FILL),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindTexture(a.TEXTURE_2D_ARRAY,x),a.activeTexture(a.TEXTURE0)}a.viewport(0,0,k,A),a.uniformMatrix4fv(b.m,!1,w),a.uniform3fv(b.E,r),a.uniform1f(b.T,performance.now()/1e3),a.uniform1f(b.Z,Ln),a.uniform1i(b.Q,L.n),a.uniform4fv(b.A,L.a),a.uniform4fv(b.B,L.b),a.uniform4fv(b.K,L.k),a.uniformMatrix4fv(b.M,!1,L.m),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT),a.drawArrays(a.TRIANGLES,0,re+P/10),a.clear(a.DEPTH_BUFFER_BIT),a.uniform1f(b.Z,Rn),a.drawArrays(a.TRIANGLES,re+P/10,(j.length-P)/10)},project:(e,t,n)=>Un(w,e,t,n),destroy(){n.removeEventListener(`webglcontextlost`,O),n.removeEventListener(`webglcontextrestored`,ee),a.getExtension(`WEBGL_lose_context`)?.loseContext()}}},Qn=1/60,$n=5,er=(e,i)=>{let a=document.createElement(`div`),o=a.attachShadow({mode:`open`});o.innerHTML=`<style>:host{display:block;width:100%;height:100%}div{position:relative;width:100%;height:100%;overflow:hidden;background:#000;font:600 14px system-ui,sans-serif;color:#fff;text-shadow:0 1px 2px #000}canvas{display:block;width:100%;height:100%;cursor:pointer}i,p,b{position:absolute;pointer-events:none;user-select:none;margin:0}`+Vt+`i{left:50%;top:50%;width:6px;height:6px;margin:-3px;border-radius:50%;background:#fff;box-shadow:0 0 0 1px #0008}p{top:8px;left:12px}b{transform:translate(-50%,-100%);font-size:12px;white-space:nowrap}[hidden]{display:none}</style><div><canvas></canvas><i></i><p></p></div>`,e.append(a);let s=o.querySelector(`canvas`),c=o.querySelector(`p`),l=o.querySelector(`div`),u=Ht(l),d={roster:[],open:[],close:[]},f=e=>d[e].forEach(e=>e()),p=g(A[0]),m=cn(p),h=ye();h.mute(Ce()),u.mute(h.muted);let _=xe(h),v=Se(h),y=qt(s,()=>u.mute(we(h)));s.addEventListener(`click`,()=>h.unlock());let x=Ct(Math.random,p),S=St(),C=St(),w=-1,T;try{T=Zn(s,p)}catch{}let E=On({lvl:p,you:()=>w,roster:()=>D,predictor:m,rd:T,delays:[S,C],fx:x,hud:u,audio:h}),D=[],O=/* @__PURE__ */ new Map,ee=/* @__PURE__ */ new Map,k=/* @__PURE__ */ new Map,j=!1,M=T?``:`WebGL2 is not available`,te=!1,ne=-1,N=!1,P=performance.now(),F=0,I=0,R=!1,B=i.socket??new WebSocket(i.url);B.binaryType=`arraybuffer`,B.onopen=()=>{j=!0,B.send(JSON.stringify({t:`join`,name:i.name})),f(`open`)},B.onclose=()=>{j=!1,M||=`Connection closed`,f(`close`)},B.onmessage=({data:e})=>{if(typeof e!=`string`){let t=re(e);if(t){let e=performance.now();E.snapshot(t),m.snapshot(t,e);let n=t.players.find(e=>e.id==w),r=t.level*2+ +t.hard;n?.hp&&(r!=ne||!N)&&([y.yaw,y.pitch]=[Dn(E.lvl.map,n.x,n.z),0]),[ne,N]=[r,!!n?.hp],S.push(t.shots.filter(e=>e.id!=w),e),C.push(t.events,e)}return}let t=ie(e);t?.t==`roster`?(D=t.players,O=new Map(D.map(e=>[e.id,e.color])),ee=new Map(D.map(e=>[e.id,e.name])),m.you(w=t.you),c.textContent=`Players: ${D.length}`,f(`roster`)):t?.t==`full`?M=`Room is full`:t?.t==`end`&&E.end(t.ticks,t.hard,t.stats)};let ae=e=>{let t=k.get(e);return t||(k.set(e,t=document.createElement(`b`)),l.append(t)),t},oe=()=>{I=requestAnimationFrame(oe);let e=performance.now(),i=P;if(F=Math.min(F+(e-P)/1e3,$n*Qn),P=e,!te){let e=m.me(0);e&&([y.yaw,y.pitch,te]=[e.yaw,e.pitch,!0]),F=0}for(;te&&F>=Qn;F-=Qn){let t=E.dead?0:y.keys,r=m.step({keys:t,yaw:y.yaw,pitch:y.pitch},e);j&&B.send(L(r));let i=m.shot(),a=i&&m.me(1);i&&a&&(x.shot(i,[a.x,a.y+n,a.z],!0),h.play(z.SHOT))}let a=m.me(F/Qn),o=m.others(e).filter(e=>E.alive(e.id)),s=m.monsters(e),c=m.bullets(e),l=a?[a.x,a.y+n,a.z]:[0,0,0];x.track(s,c),h.listen(l,y.yaw);for(let t of S.due(e)){let e=o.find(e=>e.id==t.id);if(e){let r=[e.x,e.y+n,e.z];x.shot(t,r,!1,t.hit!=w),h.play(z.SHOT,r)}}for(let t of C.due(e))x.event(t,w),be(h,t,w);_(E.returning,e);let d=Math.min((e-i)/1e3,.1);if(x.update(a,y.keys,d,E.dead),u.update(d),a&&T){let t=Math.max(-1.55,Math.min(r,y.pitch+x.shakePitch));T.frame([l[0],l[1]+x.bob,l[2]],y.yaw+x.shakeYaw,t,o,O,x,s,c,E.items,Cn({eye:[l[0],l[1]+x.bob,l[2]],yaw:y.yaw,pitch:y.pitch,dead:E.dead,others:o,fx:x,bullets:c,lvl:E.lvl,t:e/1e3}))}let f=/* @__PURE__ */ new Set;for(let e of o){let n=[e.x,e.y+t+.3,e.z],r=a&&!b(E.lvl,l,n)?T?.project(...n):void 0,i=ae(e.id);f.add(e.id),i.hidden=!r,r&&(i.style.left=r[0]*100+`%`,i.style.top=r[1]*100+`%`);let o=ee.get(e.id)??``;i.textContent!=o&&(i.textContent=o)}for(let[e,t]of k)f.has(e)||(t.remove(),k.delete(e));u.fade(x.hurt/lt,v(E.hp,e),x.gain/ut,x.gainC),u.title(M||(j?te?y.locked()?``:`Click to play`:`Joining…`:`Connecting…`),E.name)};return I=requestAnimationFrame(oe),{on:(e,t)=>void d[e].push(t),players:()=>D,destroy(){R||(R=!0,cancelAnimationFrame(I),y.destroy(),h.destroy(),T?.destroy(),B.onopen=B.onclose=B.onmessage=null,B.close(),document.exitPointerLock(),a.remove())}}};export{er as tinyFps};
|
package/dist/local.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=65536/(2*Math.PI),t=t=>Math.round(t*e)&65535,n=e=>Math.max(-32768,Math.min(32767,Math.round(e))),r=e=>n(e*1e4),i=e=>e/1e4,a=t=>t/e,o=e=>{if(e.byteLength!==11)return null;let t=new DataView(e);return t.getUint8(0)===1?{seq:t.getUint16(1),keys:t.getUint8(3),yaw:a(t.getUint16(4)),pitch:i(t.getInt16(6)),view:(t.getUint16(8)*256+t.getUint8(10))/256}:null},s=e=>{let n=7+25*e.players.length,i=n+1+14*e.shots.length,a=i+1+16*e.monsters.length,o=a+1+13*e.bullets.length,s=o+1+14*e.events.length,c=new DataView(new ArrayBuffer(s+1+14*e.items.length));return c.setUint8(0,2),c.setUint16(1,e.tick&65535),c.setUint8(3,e.players.length),c.setUint8(4,e.level),c.setUint8(5,+e.hard|(e.phase&1)<<1),c.setUint8(6,e.keys),e.players.forEach((e,n)=>{let i=7+n*25;c.setUint8(i,e.id),c.setFloat32(i+1,e.x),c.setFloat32(i+5,e.y),c.setFloat32(i+9,e.z),c.setFloat32(i+13,e.vy),c.setUint16(i+17,t(e.yaw)),c.setInt16(i+19,r(e.pitch)),c.setUint16(i+21,e.ack&65535),c.setUint8(i+23,+e.ground|e.cool<<1),c.setUint8(i+24,e.hp)}),c.setUint8(n,e.shots.length),e.shots.forEach((e,t)=>{let r=n+1+t*14;c.setUint8(r,e.id),c.setFloat32(r+1,e.x),c.setFloat32(r+5,e.y),c.setFloat32(r+9,e.z),c.setUint8(r+13,e.hit&255)}),c.setUint8(i,e.monsters.length),e.monsters.forEach((e,n)=>{let r=i+1+n*16;c.setUint8(r,e.id),c.setUint8(r+1,e.kind&1|e.chase<<1),c.setFloat32(r+2,e.x),c.setFloat32(r+6,e.y),c.setFloat32(r+10,e.z),c.setUint16(r+14,t(e.yaw))}),c.setUint8(a,e.bullets.length),e.bullets.forEach((e,t)=>{let n=a+1+t*13;c.setUint8(n,e.id),c.setFloat32(n+1,e.x),c.setFloat32(n+5,e.y),c.setFloat32(n+9,e.z)}),c.setUint8(o,e.events.length),e.events.forEach((e,t)=>{let n=o+1+t*14;c.setUint8(n,e.type),c.setUint8(n+1,e.id),c.setFloat32(n+2,e.x),c.setFloat32(n+6,e.y),c.setFloat32(n+10,e.z)}),c.setUint8(s,e.items.length),e.items.forEach((e,t)=>{let n=s+1+t*14;c.setUint8(n,e.id),c.setUint8(n+1,e.kind),c.setFloat32(n+2,e.x),c.setFloat32(n+6,e.y),c.setFloat32(n+10,e.z)}),c.buffer},c=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},l=.4,u=1.8,d=1.6,f=1.55,p=.5,m=.5,h=.02,g=.4,_=1.8,v=2.5,y=.45,b=.9,x=1.2,S=3.5,ee=Math.cos(Math.PI/6),C=.15,te=1.3,ne=.6,w={maxPlayers:16},T={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,FIRE:32},E={WALKER:0,FLYER:1},D={DIE:0,HURT:1,BOOM:2,SWING:3},O={HEALTH:0,KEY_RED:1,KEY_BLUE:2,KEY_YELLOW:3},k={HUNT:0,RETURN:1},A=e=>{let t=(e,t,n,r)=>`${e},${t},${n},${r}`,n=/* @__PURE__ */ new Map;e.sectors.forEach(({pts:e},r)=>e.forEach(([i,a],o)=>n.set(t(i,a,...e[(o+1)%e.length]),r)));let r={map:e,edges:e.sectors.flatMap(({pts:e},r)=>e.map(([i,a],o)=>{let[s,c]=e[(o+1)%e.length];return{ax:i,az:a,bx:s,bz:c,front:r,back:n.get(t(s,c,i,a))??-1}})),barred:/* @__PURE__ */ new Set};return j(r,0,k.HUNT),r},j=({map:e,barred:t},n,r)=>{t.clear(),e.gates?.forEach(e=>n&1<<e.key||t.add(e.sector)),e.exit!==void 0&&r===k.HUNT&&t.add(e.exit)},M=({pts:e},t,n)=>e.every(([r,i],a)=>{let[o,s]=e[(a+1)%e.length];return(o-r)*(n-i)-(s-i)*(t-r)>=0}),N=({map:e},t,n)=>e.sectors.findIndex(e=>M(e,t,n)),P=({map:e,edges:t},[n,r,i],[a,o,s])=>{let[c,l]=[a-n,s-i];return t.some(t=>{let[a,s]=[t.bx-t.ax,t.bz-t.az],u=c*s-l*a;if(!u)return!1;let d=((t.ax-n)*s-(t.az-i)*a)/u,f=((t.ax-n)*l-(t.az-i)*c)/u;if(d<=0||d>=1||f<0||f>1)return!1;if(t.back<0)return!0;let[p,m]=[e.sectors[t.front],e.sectors[t.back]],h=r+d*(o-r);return h<Math.max(p.floor,m.floor)||h>Math.min(p.ceil,m.ceil)})},F=(e,[t,n,r,i],a,o,s,c,l,u)=>Array.from({length:s},(d,f)=>{let[p,m]=e?[n,i]:[t,r],[h,g,_]=[p+f*(m-p)/s,p+(f+1)*(m-p)/s,+(a+f*o).toFixed(1)];return e?[t,h,r,g,_,c,l,u]:[h,n,g,i,_,c,l,u]}),[I,L,R,z]=[O.HEALTH,O.KEY_RED,O.KEY_BLUE,O.KEY_YELLOW],B=Math.PI/4,V=(e,t,[n,r,i],a,o,s,c)=>{let l=t.map(([e,t,n,r])=>[[e,t],[n,t],[n,r],[e,r]]),u=[...new Map(l.flat().map(e=>[`${e}`,e])).values()];return{name:e,sectors:t.map(([,,,,e,t,n=`103`,r],i)=>({pts:l[i].flatMap((e,t,n)=>{let r=n[(t+1)%4],i=t=>(t[0]-e[0])*(r[0]-e[0])+(t[1]-e[1])*(r[1]-e[1]);return[e,...u.filter(t=>(r[0]-e[0])*(t[1]-e[1])===(r[1]-e[1])*(t[0]-e[0])&&i(t)>0&&i(t)<(r[0]-e[0])**2+(r[1]-e[1])**2).sort((e,t)=>i(e)-i(t))]}),floor:e,ceil:t,ft:+n[0],wt:+n[1],ct:+n[2],light:r})),spawns:Array.from({length:16},(e,t)=>[n+t%4*2,r+(t>>2)*2,i*B]),monsters:[...a.map(([e,t,n])=>[e,t,n*B,E.WALKER]),...o.map(([e,t,n])=>[e,t,n*B,E.FLYER])],items:s,gates:t.flatMap(([,,,,,,,,e],t)=>e?[{sector:t,key:e}]:[]),goal:c,exit:0}},re=[V(`Warm-up`,[[0,0,10,10,0,4,`103`],[10,4,22,6,0,2.8,`333`,.6],[22,0,38,14,0,6,`303`],...F(0,[38,4,42,10],.4,.4,4,6,`333`),[42,2,52,12,2,6,`103`,.9],...F(1,[46,12,48,22],1.6,-.4,4,4.8,`000`,.7),[38,22,56,36,0,6,`113`]],[2,2,6],[[28,4,3],[34,10,4],[48,6,4],[44,30,0]],[[30,8,0],[52,28,2]],[[26,12,I],[50,10,I],[40,34,I]],[54,34]),V(`Foundry`,[[0,14,10,26,0,4,`103`],[10,22,20,24,0,2.8,`333`,.6],[24,8,28,16,0,9,`303`],[20,16,28,30,0,9,`303`],...F(1,[20,8,24,16],2,-.4,5,9,`333`),[28,8,42,18,-1.6,9,`203`,.9],...F(1,[28,18,42,21],-1.2,.4,3,9,`333`),[28,21,50,30,0,9,`303`],[42,8,50,21,0,9,`303`],[20,0,50,8,2.4,9,`103`,.8],[50,14,51,17,0,3.5,`000`,1,L],[51,8,59,26,0,7,`113`,.6],[59,8,67,26,.4,7,`013`,.8],[57,26,59,36,0,4.8,`000`,.7],[50,36,68,50,0,7,`013`]],[2,16,6],[[46,14,2],[36,26,0],[38,4,2],[56,12,4],[62,20,2],[60,44,0]],[[35,13,0],[60,14,4],[58,42,6]],[[24,26,I],[24,4,I],[64,10,I],[52,46,I],[46,4,L]],[66,48]),V(`Cistern`,[[0,20,10,32,0,4,`103`],[10,26,20,28,0,2.8,`333`,.6],[20,14,56,26,0,11,`133`,.9],[20,26,34,32,0,11,`133`,.9],[34,26,42,32,-.4,11,`233`],[42,26,56,32,0,11,`133`,.9],[20,32,56,44,0,11,`133`,.9],[36,44,38,54,0,1.9,`333`,.45],[30,54,46,68,0,5,`000`,.7],[56,28,57,31,0,4,`000`,1,L],...F(0,[57,26,65,32],.4,.4,8,10,`333`,.8),[65,22,81,36,3.6,11,`103`],[71,36,74,37,3.6,7,`000`,1,R],[71,37,74,48,3.6,6.4,`333`,.6],[62,48,82,64,3.6,10,`213`]],[2,22,6],[[30,18,4],[50,20,4],[30,40,0],[50,40,0],[36,60,2],[42,64,0],[76,28,2],[70,58,0]],[[26,24,0],[48,22,0],[36,40,2],[72,56,4]],[[24,40,I],[52,42,I],[44,57,I],[68,34,I],[64,62,I],[38,66,L],[79,24,R]],[80,62]),V(`Loop`,[[0,44,10,56,0,4,`103`],[10,49,20,51,0,2.8,`333`,.6],[20,30,52,40,0,9,`303`],[20,48,52,58,0,9,`303`,.9],[20,40,32,48,0,9,`303`],[40,40,52,48,0,9,`303`],[20,22,49,30,3.2,9,`113`,.8],[34,58,36,66,0,2.8,`333`,.5],[26,66,46,84,0,5,`000`,.5],[52,42,53,45,0,4,`000`,1,L],[53,36,64,54,0,6,`133`,.8],[64,36,70,54,.4,6,`233`,.8],[60,35,63,36,0,4,`000`,1,R],[57,12,77,35,0,8,`013`,.9],[56,24,57,27,0,4,`000`,1,z],...F(0,[49,22,56,30],2.8,-.4,7,9,`333`,.8),[12,24,20,28,3.2,6,`333`,.6],[0,10,12,34,3.2,9,`113`]],[2,46,6],[[30,36,4],[44,36,2],[40,52,0],[40,26,4],[30,74,6],[42,78,2],[56,40,6],[64,50,2],[62,18,4],[72,28,2],[6,22,0]],[[28,48,0],[46,44,4],[36,72,0],[60,45,6],[68,22,4]],[[24,54,I],[24,26,I],[44,80,I],[68,38,I],[74,14,I],[36,82,L],[68,52,R],[74,32,z]],[6,13]),V(`Citadel`,[[0,60,10,72,0,4,`103`],[10,65,24,67,0,2.8,`333`,.6],[24,48,56,84,0,12,`313`],[27,40,31,48,0,3.4,`000`,.5],[24,16,34,40,0,12,`303`,.9],...F(0,[34,16,40,26],-.4,-.4,3,12,`233`),[34,26,40,30,0,12,`333`],...F(0,[34,30,40,40],-.4,-.4,3,12,`233`),[40,16,60,40,0,12,`303`,.9],[60,27,61,30,0,4,`000`,1,z],[61,10,101,16,0,14,`103`],[61,40,101,46,0,14,`103`],[61,16,69,40,0,14,`103`],[93,16,101,40,0,14,`103`],[69,16,93,20,.4,14,`233`,.9],[69,36,93,40,.4,14,`233`,.9],[69,20,73,36,.4,14,`233`,.9],[89,20,93,36,.4,14,`233`,.9],[73,20,89,36,.8,14,`333`],[101,26,111,28,0,3.2,`333`,.6],[111,16,131,40,0,8,`113`],[56,66,57,69,0,4,`000`,1,L],[57,56,75,80,0,12,`000`,.7],...F(0,[75,60,85,72],.4,.4,5,12,`333`,.8),[85,52,101,80,2.4,12,`013`],[38,84,42,85,0,4,`000`,1,R],[38,85,42,95,0,1.9,`000`,.4],[28,95,56,115,0,6,`030`,.6]],[2,62,6],[[34,56,4],[50,56,2],[36,76,0],[46,20,4],[54,34,2],[66,60,2],[66,76,0],[92,60,2],[34,100,4],[50,108,2],[70,13,4],[92,13,2],[70,43,0],[92,43,6]],[[30,70,0],[46,68,0],[50,28,0],[76,26,0],[86,30,0],[81,22,0]],[[30,80,I],[56,36,I],[60,78,I],[50,112,I],[64,13,I],[98,43,I],[114,38,I],[52,22,L],[95,66,R],[42,110,z]],[127,36])],H=1/60,U=Math.PI*2,ie=1e-6,W=.01,G=e=>(e%U+U)%U,K=e=>[-Math.sin(e),-Math.cos(e)],q=Math.fround,ae=(e,t,n)=>Math.min(Math.max(e,t),n),oe=({map:e,barred:t},n,r,i,a)=>{if(n.back<0||t.has(n.back))return!0;let o=e.sectors[n.front],s=e.sectors[n.back],c=Math.min(o.ceil,s.ceil);return s.floor>r+a+W||c-Math.max(o.floor,s.floor)<i-W||c<r+i-W},se=(e,t,n,r,i)=>{let a=(n-ie)**2;for(let o=0;o<4;o++){let o=0,s=0,c=0;for(let l of t.edges){let u=l.bx-l.ax,d=l.bz-l.az,f=e.x-l.ax,p=e.z-l.az;if(u*p-d*f<0)continue;let m=ae((f*u+p*d)/(u*u+d*d),0,1),h=f-m*u,g=p-m*d,_=h*h+g*g;if(_>=a)continue;let v=Math.sqrt(_);if(n-v<=o||!oe(t,l,e.y,r,i))continue;o=n-v;let y=v||Math.hypot(u,d);s=(v?h:-d)/y*o,c=(v?g:u)/y*o}if(!o)return;e.x+=s,e.z+=c}},ce=(e,t,n,r,i,a,o)=>{let{map:s,edges:c}=e,l=Math.max(N(e,t,n),0),{floor:u,ceil:d}=s.sectors[l],f=(i-ie)**2;for(let i of c){if(i.front!==l||i.back<0)continue;let c=i.bx-i.ax,p=i.bz-i.az,m=t-i.ax,h=n-i.az,g=ae((m*c+h*p)/(c*c+p*p),0,1);if((m-g*c)**2+(h-g*p)**2<f&&!oe(e,i,r,a,o)){let e=s.sectors[i.back];u=Math.max(u,e.floor),d=Math.min(d,e.ceil)}}return[u,d]},J=(e,t,n,r,i)=>{e.x+=t,e.z+=n,se(e,i,l,u,p);let[a,o]=ce(i,e.x,e.z,e.y,l,u,p);e.ground&&r&&(e.vy=7);let s=e.vy-20*H;e.y+=(e.vy+s)/2*H,e.vy=s,e.ground=!1,e.y+1.8>o&&(e.y=o-u,e.vy=Math.min(e.vy,0)),(e.vy<=0?e.y<=a+W:e.y<a)&&(e.y=a,e.vy<=0&&(e.vy=0,e.ground=!0)),e.x=q(e.x),e.y=q(e.y),e.z=q(e.z),e.vy=q(e.vy)},le=(e,t,n,r,i)=>{e.x+=t,e.z+=r,se(e,i,y,b,0);let[a,o]=ce(i,e.x,e.z,e.y,y,b,0),s=Math.min(a+x,o-b),c=Math.max(a,Math.min(s,e.y+S*H));e.y=Math.min(Math.max(e.y+n,c),o-b),e.x=q(e.x),e.y=q(e.y),e.z=q(e.z)},ue=(e,t,n)=>{let r=(t.keys&T.FIRE)!==0;e.cool=Math.max(0,e.cool-1),e.yaw=G(t.yaw),e.pitch=Math.max(-f,Math.min(f,t.pitch));let i=(t.keys&T.FORWARD?1:0)-(t.keys&T.BACK?1:0),a=(t.keys&T.RIGHT?1:0)-(t.keys&T.LEFT?1:0),o=6*H*(r?m:1)/(Math.hypot(i,a)||1),[s,c]=K(e.yaw);return J(e,(s*i-c*a)*o,(c*i+s*a)*o,(t.keys&T.JUMP)!==0,n),r&&!e.cool?(e.cool=5,!0):!1},de=(e,t,n)=>{let{spawns:r,sectors:i}=t.map,[a,o,s]=r[(n%r.length+r.length)%r.length],c=i[Math.max(N(t,a,o),0)].floor;return{id:e,x:q(a),y:q(c),z:q(o),vy:0,yaw:G(s),pitch:0,ground:!0,cool:0}},fe=e=>{for(let t=0;t<2;t++)e=Math.imul(e^e>>>16,73244475);return(e^e>>>16)>>>0},pe=(e,t,n)=>{let[r,i,a,o]=[Math.sin(e),Math.cos(e),Math.sin(t),Math.cos(t)],s=fe(n+1),c=(s&65535)/65536*U,l=(s>>>16)/65535,[u,d]=[Math.cos(c)*l*h,Math.sin(c)*l*h],f=[-r*o+i*u+r*a*d,a+o*d,-i*o-r*u+i*a*d],p=Math.hypot(...f);return[f[0]/p,f[1]/p,f[2]/p]},me=(e,t,n,r)=>{let{map:i,edges:a}=e,o=Math.max(N(e,t[0],t[2]),0),s=0;for(let e=0;e<=i.sectors.length;e++){let{floor:e,ceil:c}=i.sectors[o],l=1/0,u;for(let e of a){if(e.front!==o)continue;let[r,i]=[e.bx-e.ax,e.bz-e.az],a=n[2]*r-n[0]*i;if(a>=0)continue;let c=Math.max(((t[2]-e.az)*r-(t[0]-e.ax)*i)/-a,s),d=((t[0]+c*n[0]-e.ax)*r+(t[2]+c*n[2]-e.az)*i)/(r*r+i*i);d>-1e-9&&d<1+1e-9&&(c<l-1e-9||c<l+1e-9&&e.back<0)&&([l,u]=[c,e])}let d=n[1]<0?(e-t[1])/n[1]:n[1]>0?(c-t[1])/n[1]:1/0;if(d<=l||!u)return Math.min(Math.max(d,s),r);if(l>=r)return r;let f=t[1]+l*n[1],p=u.back<0?void 0:i.sectors[u.back];if(!p||f<Math.max(e,p.floor)||f>Math.min(c,p.ceil))return l;[o,s]=[u.back,l]}return s},he=(e,t,n)=>{let[r,i]=[e[0]-n.x,e[2]-n.z],a=t[0]*t[0]+t[2]*t[2],o=r*t[0]+i*t[2],s=r*r+i*i-n.r*n.r,[c,l]=[0,1/0];if(a>1e-12){let e=o*o-a*s;if(e<0)return 1/0;[c,l]=[Math.max(0,(-o-Math.sqrt(e))/a),(-o+Math.sqrt(e))/a]}else if(s>0)return 1/0;let[u,d]=[n.y-e[1],n.y+n.h-e[1]];if(t[1]){let[e,n]=[u/t[1],d/t[1]];c=Math.max(c,Math.min(e,n)),l=Math.min(l,Math.max(e,n))}else if(u>0||d<0)return 1/0;return c<=l?c:1/0},ge=({id:e,x:t,y:n,z:r})=>({id:e,x:t,y:n,z:r,r:l,h:u}),Y=({id:e,kind:t,x:n,y:r,z:i})=>{let a=t===E.WALKER;return{id:e,x:n,y:r,z:i,r:a?g:y,h:a?_:b}},_e=(e,t,n,r)=>{let i=[t.x,t.y+d,t.z],a=pe(t.yaw,t.pitch,n),o=me(e,i,a,100),s=-1;for(let e of r){let n=e.id===t.id?1/0:he(i,a,e);n<o&&([o,s]=[n,e.id])}return{id:t.id,x:i[0]+a[0]*o,y:i[1]+a[1]*o,z:i[2]+a[2]*o,hit:s}},X=1/60,ve=.05,ye=.4,Z=1,be=15,Q=1.2,xe=255,Se=e=>{let t=e|0;return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}},Ce=(e,t,n=!1)=>{let r=(e.map.monsters??[]).slice(0,64),[i,a]=n?[te,ne]:[1,1],[o,s]=[v*i,S*i],[c,f]=[90,45].map(e=>Math.round(e*a)),m=[],h=[],g=0,_=0,y=r.map(([n,r,i,a],o)=>{let{floor:s,ceil:l}=e.map.sectors[Math.max(N(e,n,r),0)],u=a===E.FLYER;return{id:16+o,kind:a,x:Math.fround(n),y:Math.fround(u?Math.min(s+x,l-b):s),z:Math.fround(r),yaw:G(i),chase:!1,vy:0,ground:!0,target:-1,turn:Math.floor(t()*240),melee:0,swing:0,shoot:Math.floor(t()*c)}}),w=e=>e.y+Y(e).h/2,T=e=>[e.x,e.kind===E.WALKER?e.y+d:w(e),e.z],O=e=>[e.x,e.y+d,e.z],k=(e,t)=>{e.target=t,e.chase=t>=0},A=(t,n)=>{for(let r of y)r!==t&&!r.chase&&Math.hypot(r.x-t.x,r.z-t.z)<12&&!P(e,T(t),T(r))&&k(r,n)},j=(t,n)=>{let[r,i]=K(t.yaw),a,o=1/0;for(let s of n){let[n,c]=[s.x-t.x,s.z-t.z],l=Math.hypot(n,c);l<=30&&l<o&&n*r+c*i>=ee*l&&!P(e,T(t),O(s))&&([a,o]=[s,l])}if(a){let e=!t.chase;k(t,a.id),e&&A(t,a.id)}},M=(e,t)=>{let n=((t-e.yaw+Math.PI)%U+U)%U-Math.PI;e.yaw=G(e.yaw+Math.max(-.05,Math.min(ve,n)))},F=(t,n)=>e.map.sectors[Math.max(N(e,t.x,t.z),0)].floor<n-p,I=n=>{let r=(n.kind===E.WALKER?o:s)*ye*X,[i,a]=K(n.yaw),c={x:n.x,y:n.y,z:n.z,vy:n.vy,ground:n.ground};n.kind===E.WALKER?J(n,i*r,a*r,!1,e):le(n,i*r,-r,a*r,e);let l=n.kind===E.WALKER&&F(n,c.y);l||Math.hypot(n.x-c.x,n.z-c.z)<r/2?(l&&Object.assign(n,c),n.yaw=G(n.yaw+t()*U)):--n.turn<=0&&(n.turn=120+Math.floor(t()*240),n.yaw=G(n.yaw+(t()-.5)*Math.PI))},L=(n,r)=>{let[i,a,o]=T(n);if(m.length>=xe||P(e,[i,a,o],O(r))){n.shoot=0;return}let s=[r.x-i,r.y+Q-a,r.z-o],l=12*X/Math.hypot(...s);m.push({id:_++&255,x:i,y:a,z:o,vx:s[0]*l,vy:s[1]*l,vz:s[2]*l,life:300}),n.shoot=c+Math.floor((t()-.5)*20)},R=(t,n)=>{let[r,i]=[n.x-t.x,n.z-t.z],a=Math.hypot(r,i);if(a>1e-6&&M(t,Math.atan2(-r,-i)),t.kind===E.WALKER){let[n,r]=K(t.yaw),i=a>Z?o*X:0;J(t,n*i,r*i,!1,e)}else{let o=n.y+Q-b/2-t.y,c=Math.min(1,s*X/(Math.hypot(a,o)||1));le(t,a>Z?r*c:0,o*c,a>Z?i*c:0,e)}let c=Math.hypot(n.x-t.x,n.z-t.z)<=1.4&&t.y<n.y+1.8&&n.y<t.y+Y(t).h;if(t.melee=Math.max(0,t.melee-1),t.swing&&!--t.swing&&c){let[e,r]=K(t.yaw);(n.x-t.x)*e+(n.z-t.z)*r>0&&h.push({type:D.HURT,id:n.id,x:n.x,y:n.y+Q,z:n.z})}c&&!t.melee&&(h.push({type:D.SWING,id:t.id,x:t.x,y:w(t),z:t.z}),[t.melee,t.swing]=[f,be]),t.kind===E.WALKER&&t.shoot--<=0&&a<=30&&L(t,n)},z=(t,n)=>{let r=Math.hypot(t.vx,t.vy,t.vz),i=[t.x,t.y,t.z],a=[t.vx/r,t.vy/r,t.vz/r],o=me(e,i,a,r),s=-1;for(let e of n){let t=he(i,a,{id:e.id,x:e.x,y:e.y-C,z:e.z,r:l+C,h:u+2*C});t<o&&([o,s]=[t,e.id])}return[t.x,t.y,t.z]=[i[0]+a[0]*o,i[1]+a[1]*o,i[2]+a[2]*o],s>=0?h.push({type:D.HURT,id:s,x:t.x,y:t.y,z:t.z}):o<r&&h.push({type:D.BOOM,id:t.id,x:t.x,y:t.y,z:t.z}),s<0&&o>=r&&--t.life>0};return{monsters:()=>y.map(({id:e,kind:t,x:n,y:r,z:i,yaw:a,chase:o})=>({id:e,kind:t,x:n,y:r,z:i,yaw:a,chase:o})),bullets:()=>m.map(({id:e,x:t,y:n,z:r})=>({id:e,x:t,y:n,z:r})),events:h,step:e=>{g++;for(let t of y){(g+t.id)%60==0&&j(t,e);let n=e.find(e=>e.id===t.target);t.chase&&!n&&k(t,-1),n?R(t,n):I(t)}m=m.filter(t=>z(t,e))},kill:(e,t)=>{let n=y.findIndex(t=>t.id===e);if(n<0)return;let[r]=y.splice(n,1);return h.push({type:D.DIE,id:e,x:r.x,y:w(r),z:r.z}),A(r,t),r}}},we=20,Te=.5,Ee=2,$=[`#e6194b`,`#3cb44b`,`#ffe119`,`#4363d8`,`#f58231`,`#911eb4`,`#42d4f4`,`#f032e6`,`#bfef45`,`#fabed4`,`#469990`,`#dcbeff`,`#9a6324`,`#800000`,`#aaffc3`,`#808000`],De=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),Oe=e=>De((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),ke=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${De(e,15-`${r}`.length)} ${r}`;return n},Ae=(e,t,n,r,i)=>Math.hypot(e.x-t,e.z-r)<=i&&e.y<n+Te&&n<e.y+1.8,je=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},Me=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];maps;lvl;horde;rand;level=0;hard=!1;phase=k.HUNT;keys=0;items=[];nextItem=0;kills=0;runStart=0;shots=[];halt;rules;rr=0;constructor(e={},t=Date.now(),n=re){this.rules={...w,...e},this.rand=Se(t),this.maps=n.map(A),this.load(0)}get size(){return this.players().length}connect(e){this.peers.set(e,null)}receive(e,t){let n=this.peers.get(e);if(typeof t==`string`){let r=c(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&o(t);if(r&&n.bank>0){if(n.bank--,n.hp&&ue(n.state,r,this.lvl)){let e=_e(this.lvl,n.state,r.seq,this.rewind(n,r.view));if(this.shots.push(e),e.hit>=16){let t=this.horde.kill(e.hit,n.state.id);t&&n.kills++,t&&++this.kills%4==0&&this.drop(O.HEALTH,t.x,t.z)}}n.ack=r.seq}}disconnect(e){let t=this.peers.get(e);this.peers.delete(e),t&&this.roster()}tick(){let e=this.players();if(!e.length)return;let t=++this.ticks;for(let n of e)n.bank=Math.min(10,n.bank+1),!n.hp&&t-n.hurt>=180&&(n.hp=9,n.state=this.place(n.info.id,e.filter(e=>e.hp&&e!==n).map(e=>e.state)));let{events:n}=this.horde,r=n.length;if(this.horde.step(e.filter(e=>e.hp).map(e=>e.state)),n.push(...n.splice(r).filter(e=>e.type!==D.HURT||this.wound(e.id,t))),this.progress(e.filter(e=>e.hp)),t%2==0){let n=this.horde.monsters();for(this.history.push({tick:t,players:e.map(e=>({...e.state})),monsters:n});this.history[0].tick<t-30;)this.history.shift();let r=s({tick:t,players:e.map(e=>({...e.state,ack:e.ack,hp:e.hp})),shots:this.shots,monsters:n,bullets:this.horde.bullets(),events:this.horde.events.splice(0,255),level:this.level,hard:this.hard,phase:this.phase,keys:this.keys,items:this.items});this.shots=[],e.forEach(e=>e.conn.send(r))}}start(e=je){if(this.halt)return;let t=1e3/60,n=performance.now(),r=0;this.halt=e(()=>{let e=performance.now();r+=e-n,n=e;for(let e=0;r>=t&&e<we;e++)this.tick(),r-=t;r%=t},t)}stop(){this.halt?.(),this.halt=void 0}rewind(e,t=0){let n=this.players().filter(t=>t!==e&&t.hp).map(e=>e.state),r=this.horde.monsters(),[i,a]=[this.history[0],this.history.at(-1)];if(!i||!a)return[...n.map(ge),...r.map(Y)];let o=((this.ticks-t+32768)%65536+65536)%65536-32768,s=Math.min(Math.max(this.ticks-o,i.tick),a.tick),c=0;for(;c+1<this.history.length&&this.history[c+1].tick<=s;)c++;let[l,u]=[this.history[c],this.history[c+1]??this.history[c]],d=u.tick>l.tick?(s-l.tick)/(u.tick-l.tick):0,f=(e,t)=>e+(t-e)*d,p=(e,t)=>e.map(e=>{let n=t(l).find(t=>t.id===e.id),r=t(u).find(t=>t.id===e.id);return n&&r?{...r,x:f(n.x,r.x),y:f(n.y,r.y),z:f(n.z,r.z)}:r??n??e});return[...p(n,e=>e.players).map(ge),...p(r,e=>e.monsters).map(Y)]}load(e){this.level=e,this.lvl=this.maps[e],this.keys=0,this.phase=k.HUNT,j(this.lvl,0,k.HUNT),this.horde=Ce(this.lvl,this.rand,this.hard),this.items=[],this.nextItem=0,this.kills=0,this.lvl.map.items?.forEach(([e,t,n])=>this.drop(n,e,t)),this.shots=[],this.history=[];let t=[];for(let e of this.players())e.hp=9,e.state=this.place(e.info.id,t),t.push(e.state)}place(e,t){let n=this.lvl.map.spawns.findIndex((n,r)=>{let{x:i,z:a}=de(e,this.lvl,r);return!t.some(e=>Math.hypot(e.x-i,e.z-a)<Ee)});return de(e,this.lvl,n<0?this.rr++:n)}floor(e,t){return this.lvl.map.sectors[Math.max(N(this.lvl,e,t),0)].floor}drop(e,t,n){let r=Math.fround;this.items.push({id:this.nextItem++,kind:e,x:r(t),y:r(this.floor(t,n)),z:r(n)})}wound(e,t){let n=this.players().find(t=>t.info.id===e);return!n?.hp||t-n.hurt<60?!1:([n.hp,n.hurt]=[n.hp-1,t],n.deaths+=+!n.hp,!0)}progress(e){let{sectors:t,goal:n,exit:r}=this.lvl.map,i=!1;if(this.items=this.items.filter(t=>{let n=e.find(e=>Ae(e.state,t.x,t.y,t.z,.8)&&(t.kind!==O.HEALTH||e.hp<9));return n&&t.kind===O.HEALTH?n.hp=Math.min(9,n.hp+3):n&&(this.keys|=1<<t.kind,i=!0),!n}),this.phase===k.HUNT)n&&e.some(e=>Ae(e.state,n[0],this.floor(...n),n[1],1))&&(this.phase=k.RETURN,i=!0);else if(r!==void 0&&e.length&&e.every(e=>M(t[r],e.state.x,e.state.z)))return this.win();i&&j(this.lvl,this.keys,this.phase)}win(){if(this.level+1<this.maps.length){this.load(this.level+1);return}let e=JSON.stringify({t:`end`,ticks:this.ticks-this.runStart,hard:this.hard,stats:this.players().map(e=>({id:e.info.id,kills:e.kills,deaths:e.deaths}))});this.players().forEach(t=>t.conn.send(e)),this.players().forEach(e=>e.kills=e.deaths=0),[this.hard,this.runStart]=[!0,this.ticks],this.load(0)}players(){return[...this.peers.values()].filter(e=>e!==null)}join(e,t){let n=this.players();if(n.length>=this.rules.maxPlayers){e.send(JSON.stringify({t:`full`}));return}let r=0;for(;n.some(e=>e.info.id===r);)r++;let i=$.find(e=>!n.some(t=>t.info.color===e))??$[r%$.length],a={conn:e,info:{id:r,name:ke(Oe(t)||`Player ${r}`,n.map(e=>e.info.name)),color:i},state:this.place(r,n.filter(e=>e.hp).map(e=>e.state)),bank:10,ack:65535,hp:9,hurt:-60,kills:0,deaths:0};this.peers.set(e,a),this.roster()}roster(){let e=this.players(),t=e.map(e=>e.info).sort((e,t)=>e.id-t.id);e.forEach(e=>e.conn.send(JSON.stringify({t:`roster`,you:e.info.id,players:t})))}},Ne=(e,t)=>{let n=()=>{},r=()=>{n();let r=setInterval(e,t);n=()=>clearInterval(r)};try{let i=URL.createObjectURL(new Blob([`setInterval(()=>postMessage(0),${t})`])),a=new Worker(i);a.onmessage=e,a.onerror=r,n=()=>{a.terminate(),URL.revokeObjectURL(i)}}catch{r()}return()=>n()},Pe=(e,t)=>{let n=`tiny-fps:`+e,r=Math.random().toString(36).slice(2),i=new BroadcastChannel(n),a=new AbortController,o=globalThis.navigator?.locks,s,l,u,d,f=[],p,m=!1,h=e=>i.postMessage({from:r,...e}),g=e=>!m&&S.onmessage?.({data:e}),_={send:e=>queueMicrotask(()=>g(e))},v=()=>{let e=f.length?f:p?[p]:[];return f=[],e},y=e=>{if(m)return e();u=e,d=r,l=/* @__PURE__ */ new Map,s=new Me(t),s.start(Ne),s.connect(_),v().forEach(e=>s.receive(_,e)),h({kind:`h`})};i.onmessage=({data:e})=>{if(!m){if(s&&l){let{from:t,kind:n}=e,r=l.get(t);n===`q`?h({to:t,kind:`h`}):n===`m`&&!e.to?(r||(r={send:e=>!m&&h({to:t,kind:`m`,data:e})},l.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(l.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?g(e.data):e.kind===`h`&&e.from!==d&&(d=e.from,v().forEach(e=>h({kind:`m`,data:e}))))}};let b=e=>{m||(typeof e==`string`&&c(e)?.t===`join`&&(p=e),s?s.receive(_,e):d?h({kind:`m`,data:e}):f.push(e))},x=()=>{m||(m=!0,globalThis.removeEventListener?.(`pagehide`,x),s?(s.stop(),u()):(h({kind:`b`}),a.abort()),i.close(),setTimeout(()=>S.onclose?.()))},S={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:b,close:x};return o?o.request(n,{signal:a.signal},()=>new Promise(y)).catch(()=>{}):y(()=>{}),h({kind:`q`}),globalThis.addEventListener?.(`pagehide`,x),setTimeout(()=>!m&&S.onopen?.()),S};export{Pe as localSocket};
|
|
1
|
+
var e=65536/(2*Math.PI),t=t=>Math.round(t*e)&65535,n=e=>Math.max(-32768,Math.min(32767,Math.round(e))),r=e=>n(e*1e4),i=e=>e/1e4,a=t=>t/e,o=e=>{if(e.byteLength!==11)return null;let t=new DataView(e);return t.getUint8(0)===1?{seq:t.getUint16(1),keys:t.getUint8(3),yaw:a(t.getUint16(4)),pitch:i(t.getInt16(6)),view:(t.getUint16(8)*256+t.getUint8(10))/256}:null},s=e=>{let n=7+25*e.players.length,i=n+1+14*e.shots.length,a=i+1+16*e.monsters.length,o=a+1+13*e.bullets.length,s=o+1+14*e.events.length,c=new DataView(new ArrayBuffer(s+1+14*e.items.length));return c.setUint8(0,2),c.setUint16(1,e.tick&65535),c.setUint8(3,e.players.length),c.setUint8(4,e.level),c.setUint8(5,+e.hard|(e.phase&1)<<1),c.setUint8(6,e.keys),e.players.forEach((e,n)=>{let i=7+n*25;c.setUint8(i,e.id),c.setFloat32(i+1,e.x),c.setFloat32(i+5,e.y),c.setFloat32(i+9,e.z),c.setFloat32(i+13,e.vy),c.setUint16(i+17,t(e.yaw)),c.setInt16(i+19,r(e.pitch)),c.setUint16(i+21,e.ack&65535),c.setUint8(i+23,+e.ground|e.cool<<1),c.setUint8(i+24,e.hp)}),c.setUint8(n,e.shots.length),e.shots.forEach((e,t)=>{let r=n+1+t*14;c.setUint8(r,e.id),c.setFloat32(r+1,e.x),c.setFloat32(r+5,e.y),c.setFloat32(r+9,e.z),c.setUint8(r+13,e.hit&255)}),c.setUint8(i,e.monsters.length),e.monsters.forEach((e,n)=>{let r=i+1+n*16;c.setUint8(r,e.id),c.setUint8(r+1,e.kind&1|e.chase<<1),c.setFloat32(r+2,e.x),c.setFloat32(r+6,e.y),c.setFloat32(r+10,e.z),c.setUint16(r+14,t(e.yaw))}),c.setUint8(a,e.bullets.length),e.bullets.forEach((e,t)=>{let n=a+1+t*13;c.setUint8(n,e.id),c.setFloat32(n+1,e.x),c.setFloat32(n+5,e.y),c.setFloat32(n+9,e.z)}),c.setUint8(o,e.events.length),e.events.forEach((e,t)=>{let n=o+1+t*14;c.setUint8(n,e.type),c.setUint8(n+1,e.id),c.setFloat32(n+2,e.x),c.setFloat32(n+6,e.y),c.setFloat32(n+10,e.z)}),c.setUint8(s,e.items.length),e.items.forEach((e,t)=>{let n=s+1+t*14;c.setUint8(n,e.id),c.setUint8(n+1,e.kind),c.setFloat32(n+2,e.x),c.setFloat32(n+6,e.y),c.setFloat32(n+10,e.z)}),c.buffer},c=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},l=.4,u=1.8,d=1.6,f=1.55,p=.5,m=.5,h=.02,g=.4,_=1.8,v=2.5,y=.45,b=.9,x=1.2,S=3.5,ee=Math.cos(Math.PI/6),C=.15,te=1.3,ne=.6,w={maxPlayers:16},T={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,FIRE:32},E={WALKER:0,FLYER:1},D={DIE:0,HURT:1,BOOM:2,SWING:3},O={HEALTH:0,KEY_RED:1,KEY_BLUE:2,KEY_YELLOW:3},k={HUNT:0,RETURN:1},A=e=>{let t=(e,t,n,r)=>`${e},${t},${n},${r}`,n=/* @__PURE__ */ new Map;e.sectors.forEach(({pts:e},r)=>e.forEach(([i,a],o)=>n.set(t(i,a,...e[(o+1)%e.length]),r)));let r={map:e,edges:e.sectors.flatMap(({pts:e},r)=>e.map(([i,a],o)=>{let[s,c]=e[(o+1)%e.length];return{ax:i,az:a,bx:s,bz:c,front:r,back:n.get(t(s,c,i,a))??-1}})),barred:/* @__PURE__ */ new Set};return j(r,0,k.HUNT),r},j=({map:e,barred:t},n,r)=>{t.clear(),e.gates?.forEach(e=>n&1<<e.key||t.add(e.sector)),e.exit!==void 0&&r===k.HUNT&&t.add(e.exit)},M=({pts:e},t,n)=>e.every(([r,i],a)=>{let[o,s]=e[(a+1)%e.length];return(o-r)*(n-i)-(s-i)*(t-r)>=0}),N=({map:e},t,n)=>e.sectors.findIndex(e=>M(e,t,n)),P=({map:e,edges:t},[n,r,i],[a,o,s])=>{let[c,l]=[a-n,s-i];return t.some(t=>{let[a,s]=[t.bx-t.ax,t.bz-t.az],u=c*s-l*a;if(!u)return!1;let d=((t.ax-n)*s-(t.az-i)*a)/u,f=((t.ax-n)*l-(t.az-i)*c)/u;if(d<=0||d>=1||f<0||f>1)return!1;if(t.back<0)return!0;let[p,m]=[e.sectors[t.front],e.sectors[t.back]],h=r+d*(o-r);return h<Math.max(p.floor,m.floor)||h>Math.min(p.ceil,m.ceil)})},F=(e,...t)=>t.map(([t,n,r,i,a,o,s,c,l])=>[t,n,r,i,a,o,s,c,l,e]),I=(e,[t,n,r,i],a,o,s,c,l,u)=>Array.from({length:s},(d,f)=>{let[p,m]=e?[n,i]:[t,r],[h,g,_]=[p+f*(m-p)/s,p+(f+1)*(m-p)/s,+(a+f*o).toFixed(1)];return e?[t,h,r,g,_,c,l,u]:[h,n,g,i,_,c,l,u]}),[L,R,z,B]=[O.HEALTH,O.KEY_RED,O.KEY_BLUE,O.KEY_YELLOW],V=Math.PI/4,H=[1,.82,.6],re=[.6,.75,1],U=(e,t,[n,r,i],a,o,s,c,l)=>{let u=t.map(([e,t,n,r])=>[[e,t],[n,t],[n,r],[e,r]]),d=[...new Map(u.flat().map(e=>[`${e}`,e])).values()];return{name:e,sectors:t.map(([,,,,e,t,n=`103`,r,,i],a)=>({pts:u[a].flatMap((e,t,n)=>{let r=n[(t+1)%4],i=t=>(t[0]-e[0])*(r[0]-e[0])+(t[1]-e[1])*(r[1]-e[1]);return[e,...d.filter(t=>(r[0]-e[0])*(t[1]-e[1])===(r[1]-e[1])*(t[0]-e[0])&&i(t)>0&&i(t)<(r[0]-e[0])**2+(r[1]-e[1])**2).sort((e,t)=>i(e)-i(t))]}),floor:e,ceil:t,ft:+n[0],wt:+n[1],ct:+n[2],light:r,tint:i})),spawns:Array.from({length:16},(e,t)=>[n+t%4*2,r+(t>>2)*2,i*V]),monsters:[...a.map(([e,t,n])=>[e,t,n*V,E.WALKER]),...o.map(([e,t,n])=>[e,t,n*V,E.FLYER])],items:s,gates:t.flatMap(([,,,,,,,,e],t)=>e?[{sector:t,key:e}]:[]),goal:c,exit:0,fog:l}},ie=[U(`Warm-up`,[[0,0,10,10,0,4,`103`],[10,4,22,6,0,2.8,`333`,.6],...F([1,.85,.65],[22,0,38,14,0,6,`553`],...I(0,[38,4,42,10],.4,.4,4,6,`553`)),[42,2,52,12,2,6,`103`,.9],...I(1,[46,12,48,22],1.6,-.4,4,4.8,`744`,.7),[38,22,56,36,0,6,`113`]],[2,2,6],[[28,4,3],[34,10,4],[48,6,4],[44,30,0]],[[30,8,0],[52,28,2]],[[26,12,L],[50,10,L],[40,34,L]],[54,34]),U(`Foundry`,[...F([1,.9,.8],[0,14,10,26,0,4,`443`],[10,22,20,24,0,2.8,`744`,.6]),...F([1,.5,.25],[24,8,28,16,0,9,`744`],[20,16,28,30,0,9,`443`],...I(1,[20,8,24,16],2,-.4,5,9,`744`),[28,8,42,18,-1.6,9,`233`,.9],...I(1,[28,18,42,21],-1.2,.4,3,9,`333`),[28,21,50,30,0,9,`744`],[42,8,50,21,0,9,`744`],[20,0,50,8,2.4,9,`744`,.8]),[50,14,51,17,0,3.5,`444`,1,R],...F([.85,.65,.5],[51,8,59,26,0,7,`443`,.6],[59,8,67,26,.4,7,`143`,.8],[57,26,59,36,0,4.8,`744`,.7]),...F([1,.6,.45],[50,36,68,50,0,7,`443`])],[2,16,6],[[46,14,2],[36,26,0],[38,4,2],[56,12,4],[62,20,2],[60,44,0]],[[35,13,0],[60,14,4],[58,42,6]],[[24,26,L],[24,4,L],[64,10,L],[52,46,L],[46,4,R]],[66,48],[.07,.05,.04,.026]),U(`Cistern`,[...F([.45,.9,1],[0,20,10,32,0,4,`363`],[10,26,20,28,0,2.8,`363`,.6],[20,14,56,26,0,11,`363`,.9],[20,26,34,32,0,11,`363`,.9]),...F([.9,.6,.45],[34,26,42,32,-.4,11,`263`]),...F([.45,.9,1],[42,26,56,32,0,11,`363`,.9],[20,32,56,44,0,11,`363`,.9],[36,44,38,54,0,1.9,`000`,.35],[30,54,46,68,0,5,`003`,.7]),[56,28,57,31,0,4,`444`,1,R],...F([.55,.85,1],...I(0,[57,26,65,32],.4,.4,8,10,`333`,.8)),...F([.7,1,.85],[65,22,81,36,3.6,11,`563`]),[71,36,74,37,3.6,7,`444`,1,z],...F([.45,.9,1],[71,37,74,48,3.6,6.4,`363`,.6]),...F([.9,.6,.45],[62,48,82,64,3.6,10,`263`])],[2,22,6],[[30,18,4],[50,20,4],[30,40,0],[50,40,0],[36,60,2],[42,64,0],[76,28,2],[70,58,0]],[[26,24,0],[48,22,0],[36,40,2],[72,56,4]],[[24,40,L],[52,42,L],[44,57,L],[68,34,L],[64,62,L],[38,66,R],[79,24,z]],[80,62],[.04,.11,.1,.034]),U(`Loop`,[...F(H,[0,44,10,56,0,4,`153`],[10,49,20,51,0,2.8,`553`,.6]),[20,30,52,40,0,9,`113`],[20,48,52,58,0,9,`113`,.9],[20,40,32,48,0,9,`113`],[40,40,52,48,0,9,`113`],[20,22,49,30,3.2,9,`743`,.8],...F(H,[34,58,36,66,0,2.8,`553`,.4],[26,66,46,84,0,5,`353`,.5]),[52,42,53,45,0,4,`444`,1,R],...F(H,[53,36,64,54,0,6,`153`,.8],[64,36,70,54,.4,6,`253`,.8]),[60,35,63,36,0,4,`444`,1,z],...F(H,[57,12,77,35,0,8,`053`,.9]),[56,24,57,27,0,4,`444`,1,B],...I(0,[49,22,56,30],2.8,-.4,7,9,`744`,.8),...F(H,[12,24,20,28,3.2,6,`744`,.6],[0,10,12,34,3.2,9,`553`])],[2,46,6],[[30,36,4],[44,36,2],[40,52,0],[40,26,4],[30,74,6],[42,78,2],[56,40,6],[64,50,2],[62,18,4],[72,28,2],[6,22,0]],[[28,48,0],[46,44,4],[36,72,0],[60,45,6],[68,22,4]],[[24,54,L],[24,26,L],[44,80,L],[68,38,L],[74,14,L],[36,82,R],[68,52,z],[74,32,B]],[6,13],[.06,.045,.04,.02]),U(`Citadel`,[...F(re,[0,60,10,72,0,4,`303`],[10,65,24,67,0,2.8,`363`,.6],[24,48,56,84,0,12,`363`],[27,40,31,48,0,3.4,`363`,.4]),...F([.85,.7,.65],[24,16,34,40,0,12,`443`,.9],...I(0,[34,16,40,26],-.4,-.4,3,12,`243`),[34,26,40,30,0,12,`744`],...I(0,[34,30,40,40],-.4,-.4,3,12,`243`),[40,16,60,40,0,12,`443`,.9]),[60,27,61,30,0,4,`444`,1,B],...F([.55,.3,1],[61,10,101,16,0,14,`443`,1],[61,40,101,46,0,14,`443`,1],[61,16,69,40,0,14,`443`,1],[93,16,101,40,0,14,`443`,1],[69,16,93,20,.4,14,`243`,1],[69,36,93,40,.4,14,`243`,1],[69,20,73,36,.4,14,`243`,1],[89,20,93,36,.4,14,`243`,1],[73,20,89,36,.8,14,`744`,1]),[101,26,111,28,0,3.2,`744`,.6],[111,16,131,40,0,8,`163`],[56,66,57,69,0,4,`444`,1,R],...F([1,.5,.45],[57,56,75,80,0,12,`443`,.7],...I(0,[75,60,85,72],.4,.4,5,12,`744`,.8),[85,52,101,80,2.4,12,`543`]),[38,84,42,85,0,4,`444`,1,z],...F([.6,.85,.85],[38,85,42,95,0,1.9,`363`,.35],[28,95,56,115,0,6,`663`,.6])],[2,62,6],[[34,56,4],[50,56,2],[36,76,0],[46,20,4],[54,34,2],[66,60,2],[66,76,0],[92,60,2],[34,100,4],[50,108,2],[70,13,4],[92,13,2],[70,43,0],[92,43,6]],[[30,70,0],[46,68,0],[50,28,0],[76,26,0],[86,30,0],[81,22,0]],[[30,80,L],[56,36,L],[60,78,L],[50,112,L],[64,13,L],[98,43,L],[114,38,L],[52,22,R],[95,66,z],[42,110,B]],[127,36],[.045,.05,.075,.02])],W=1/60,G=Math.PI*2,ae=1e-6,K=.01,q=e=>(e%G+G)%G,J=e=>[-Math.sin(e),-Math.cos(e)],Y=Math.fround,oe=(e,t,n)=>Math.min(Math.max(e,t),n),se=({map:e,barred:t},n,r,i,a)=>{if(n.back<0||t.has(n.back))return!0;let o=e.sectors[n.front],s=e.sectors[n.back],c=Math.min(o.ceil,s.ceil);return s.floor>r+a+K||c-Math.max(o.floor,s.floor)<i-K||c<r+i-K},ce=(e,t,n,r,i)=>{let a=(n-ae)**2;for(let o=0;o<4;o++){let o=0,s=0,c=0;for(let l of t.edges){let u=l.bx-l.ax,d=l.bz-l.az,f=e.x-l.ax,p=e.z-l.az;if(u*p-d*f<0)continue;let m=oe((f*u+p*d)/(u*u+d*d),0,1),h=f-m*u,g=p-m*d,_=h*h+g*g;if(_>=a)continue;let v=Math.sqrt(_);if(n-v<=o||!se(t,l,e.y,r,i))continue;o=n-v;let y=v||Math.hypot(u,d);s=(v?h:-d)/y*o,c=(v?g:u)/y*o}if(!o)return;e.x+=s,e.z+=c}},le=(e,t,n,r,i,a,o)=>{let{map:s,edges:c}=e,l=Math.max(N(e,t,n),0),{floor:u,ceil:d}=s.sectors[l],f=(i-ae)**2;for(let i of c){if(i.front!==l||i.back<0)continue;let c=i.bx-i.ax,p=i.bz-i.az,m=t-i.ax,h=n-i.az,g=oe((m*c+h*p)/(c*c+p*p),0,1);if((m-g*c)**2+(h-g*p)**2<f&&!se(e,i,r,a,o)){let e=s.sectors[i.back];u=Math.max(u,e.floor),d=Math.min(d,e.ceil)}}return[u,d]},X=(e,t,n,r,i)=>{e.x+=t,e.z+=n,ce(e,i,l,u,p);let[a,o]=le(i,e.x,e.z,e.y,l,u,p);e.ground&&r&&(e.vy=7);let s=e.vy-20*W;e.y+=(e.vy+s)/2*W,e.vy=s,e.ground=!1,e.y+1.8>o&&(e.y=o-u,e.vy=Math.min(e.vy,0)),(e.vy<=0?e.y<=a+K:e.y<a)&&(e.y=a,e.vy<=0&&(e.vy=0,e.ground=!0)),e.x=Y(e.x),e.y=Y(e.y),e.z=Y(e.z),e.vy=Y(e.vy)},ue=(e,t,n,r,i)=>{e.x+=t,e.z+=r,ce(e,i,y,b,0);let[a,o]=le(i,e.x,e.z,e.y,y,b,0),s=Math.min(a+x,o-b),c=Math.max(a,Math.min(s,e.y+S*W));e.y=Math.min(Math.max(e.y+n,c),o-b),e.x=Y(e.x),e.y=Y(e.y),e.z=Y(e.z)},de=(e,t,n)=>{let r=(t.keys&T.FIRE)!==0;e.cool=Math.max(0,e.cool-1),e.yaw=q(t.yaw),e.pitch=Math.max(-f,Math.min(f,t.pitch));let i=(t.keys&T.FORWARD?1:0)-(t.keys&T.BACK?1:0),a=(t.keys&T.RIGHT?1:0)-(t.keys&T.LEFT?1:0),o=6*W*(r?m:1)/(Math.hypot(i,a)||1),[s,c]=J(e.yaw);return X(e,(s*i-c*a)*o,(c*i+s*a)*o,(t.keys&T.JUMP)!==0,n),r&&!e.cool?(e.cool=5,!0):!1},fe=(e,t,n)=>{let{spawns:r,sectors:i}=t.map,[a,o,s]=r[(n%r.length+r.length)%r.length],c=i[Math.max(N(t,a,o),0)].floor;return{id:e,x:Y(a),y:Y(c),z:Y(o),vy:0,yaw:q(s),pitch:0,ground:!0,cool:0}},pe=e=>{for(let t=0;t<2;t++)e=Math.imul(e^e>>>16,73244475);return(e^e>>>16)>>>0},me=(e,t,n)=>{let[r,i,a,o]=[Math.sin(e),Math.cos(e),Math.sin(t),Math.cos(t)],s=pe(n+1),c=(s&65535)/65536*G,l=(s>>>16)/65535,[u,d]=[Math.cos(c)*l*h,Math.sin(c)*l*h],f=[-r*o+i*u+r*a*d,a+o*d,-i*o-r*u+i*a*d],p=Math.hypot(...f);return[f[0]/p,f[1]/p,f[2]/p]},he=(e,t,n,r)=>{let{map:i,edges:a}=e,o=Math.max(N(e,t[0],t[2]),0),s=0;for(let e=0;e<=i.sectors.length;e++){let{floor:e,ceil:c}=i.sectors[o],l=1/0,u;for(let e of a){if(e.front!==o)continue;let[r,i]=[e.bx-e.ax,e.bz-e.az],a=n[2]*r-n[0]*i;if(a>=0)continue;let c=Math.max(((t[2]-e.az)*r-(t[0]-e.ax)*i)/-a,s),d=((t[0]+c*n[0]-e.ax)*r+(t[2]+c*n[2]-e.az)*i)/(r*r+i*i);d>-1e-9&&d<1+1e-9&&(c<l-1e-9||c<l+1e-9&&e.back<0)&&([l,u]=[c,e])}let d=n[1]<0?(e-t[1])/n[1]:n[1]>0?(c-t[1])/n[1]:1/0;if(d<=l||!u)return Math.min(Math.max(d,s),r);if(l>=r)return r;let f=t[1]+l*n[1],p=u.back<0?void 0:i.sectors[u.back];if(!p||f<Math.max(e,p.floor)||f>Math.min(c,p.ceil))return l;[o,s]=[u.back,l]}return s},ge=(e,t,n)=>{let[r,i]=[e[0]-n.x,e[2]-n.z],a=t[0]*t[0]+t[2]*t[2],o=r*t[0]+i*t[2],s=r*r+i*i-n.r*n.r,[c,l]=[0,1/0];if(a>1e-12){let e=o*o-a*s;if(e<0)return 1/0;[c,l]=[Math.max(0,(-o-Math.sqrt(e))/a),(-o+Math.sqrt(e))/a]}else if(s>0)return 1/0;let[u,d]=[n.y-e[1],n.y+n.h-e[1]];if(t[1]){let[e,n]=[u/t[1],d/t[1]];c=Math.max(c,Math.min(e,n)),l=Math.min(l,Math.max(e,n))}else if(u>0||d<0)return 1/0;return c<=l?c:1/0},_e=({id:e,x:t,y:n,z:r})=>({id:e,x:t,y:n,z:r,r:l,h:u}),Z=({id:e,kind:t,x:n,y:r,z:i})=>{let a=t===E.WALKER;return{id:e,x:n,y:r,z:i,r:a?g:y,h:a?_:b}},ve=(e,t,n,r)=>{let i=[t.x,t.y+d,t.z],a=me(t.yaw,t.pitch,n),o=he(e,i,a,100),s=-1;for(let e of r){let n=e.id===t.id?1/0:ge(i,a,e);n<o&&([o,s]=[n,e.id])}return{id:t.id,x:i[0]+a[0]*o,y:i[1]+a[1]*o,z:i[2]+a[2]*o,hit:s}},Q=1/60,ye=.05,be=.4,$=1,xe=15,Se=1.2,Ce=255,we=e=>{let t=e|0;return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}},Te=(e,t,n=!1)=>{let r=(e.map.monsters??[]).slice(0,64),[i,a]=n?[te,ne]:[1,1],[o,s]=[v*i,S*i],[c,f]=[90,45].map(e=>Math.round(e*a)),m=[],h=[],g=0,_=0,y=r.map(([n,r,i,a],o)=>{let{floor:s,ceil:l}=e.map.sectors[Math.max(N(e,n,r),0)],u=a===E.FLYER;return{id:16+o,kind:a,x:Math.fround(n),y:Math.fround(u?Math.min(s+x,l-b):s),z:Math.fround(r),yaw:q(i),chase:!1,vy:0,ground:!0,target:-1,turn:Math.floor(t()*240),melee:0,swing:0,shoot:Math.floor(t()*c)}}),w=e=>e.y+Z(e).h/2,T=e=>[e.x,e.kind===E.WALKER?e.y+d:w(e),e.z],O=e=>[e.x,e.y+d,e.z],k=(e,t)=>{e.target=t,e.chase=t>=0},A=(t,n)=>{for(let r of y)r!==t&&!r.chase&&Math.hypot(r.x-t.x,r.z-t.z)<12&&!P(e,T(t),T(r))&&k(r,n)},j=(t,n)=>{let[r,i]=J(t.yaw),a,o=1/0;for(let s of n){let[n,c]=[s.x-t.x,s.z-t.z],l=Math.hypot(n,c);l<=30&&l<o&&n*r+c*i>=ee*l&&!P(e,T(t),O(s))&&([a,o]=[s,l])}if(a){let e=!t.chase;k(t,a.id),e&&A(t,a.id)}},M=(e,t)=>{let n=((t-e.yaw+Math.PI)%G+G)%G-Math.PI;e.yaw=q(e.yaw+Math.max(-.05,Math.min(ye,n)))},F=(t,n)=>e.map.sectors[Math.max(N(e,t.x,t.z),0)].floor<n-p,I=n=>{let r=(n.kind===E.WALKER?o:s)*be*Q,[i,a]=J(n.yaw),c={x:n.x,y:n.y,z:n.z,vy:n.vy,ground:n.ground};n.kind===E.WALKER?X(n,i*r,a*r,!1,e):ue(n,i*r,-r,a*r,e);let l=n.kind===E.WALKER&&F(n,c.y);l||Math.hypot(n.x-c.x,n.z-c.z)<r/2?(l&&Object.assign(n,c),n.yaw=q(n.yaw+t()*G)):--n.turn<=0&&(n.turn=120+Math.floor(t()*240),n.yaw=q(n.yaw+(t()-.5)*Math.PI))},L=(n,r)=>{let[i,a,o]=T(n);if(m.length>=Ce||P(e,[i,a,o],O(r))){n.shoot=0;return}let s=[r.x-i,r.y+Se-a,r.z-o],l=12*Q/Math.hypot(...s);m.push({id:_++&255,x:i,y:a,z:o,vx:s[0]*l,vy:s[1]*l,vz:s[2]*l,life:300}),n.shoot=c+Math.floor((t()-.5)*20)},R=(t,n)=>{let[r,i]=[n.x-t.x,n.z-t.z],a=Math.hypot(r,i);if(a>1e-6&&M(t,Math.atan2(-r,-i)),t.kind===E.WALKER){let[n,r]=J(t.yaw),i=a>$?o*Q:0;X(t,n*i,r*i,!1,e)}else{let o=n.y+Se-b/2-t.y,c=Math.min(1,s*Q/(Math.hypot(a,o)||1));ue(t,a>$?r*c:0,o*c,a>$?i*c:0,e)}let c=Math.hypot(n.x-t.x,n.z-t.z)<=1.4&&t.y<n.y+1.8&&n.y<t.y+Z(t).h;if(t.melee=Math.max(0,t.melee-1),t.swing&&!--t.swing&&c){let[e,r]=J(t.yaw);(n.x-t.x)*e+(n.z-t.z)*r>0&&h.push({type:D.HURT,id:n.id,x:n.x,y:n.y+Se,z:n.z})}c&&!t.melee&&(h.push({type:D.SWING,id:t.id,x:t.x,y:w(t),z:t.z}),[t.melee,t.swing]=[f,xe]),t.kind===E.WALKER&&t.shoot--<=0&&a<=30&&L(t,n)},z=(t,n)=>{let r=Math.hypot(t.vx,t.vy,t.vz),i=[t.x,t.y,t.z],a=[t.vx/r,t.vy/r,t.vz/r],o=he(e,i,a,r),s=-1;for(let e of n){let t=ge(i,a,{id:e.id,x:e.x,y:e.y-C,z:e.z,r:l+C,h:u+2*C});t<o&&([o,s]=[t,e.id])}return[t.x,t.y,t.z]=[i[0]+a[0]*o,i[1]+a[1]*o,i[2]+a[2]*o],s>=0?h.push({type:D.HURT,id:s,x:t.x,y:t.y,z:t.z}):o<r&&h.push({type:D.BOOM,id:t.id,x:t.x,y:t.y,z:t.z}),s<0&&o>=r&&--t.life>0};return{monsters:()=>y.map(({id:e,kind:t,x:n,y:r,z:i,yaw:a,chase:o})=>({id:e,kind:t,x:n,y:r,z:i,yaw:a,chase:o})),bullets:()=>m.map(({id:e,x:t,y:n,z:r})=>({id:e,x:t,y:n,z:r})),events:h,step:e=>{g++;for(let t of y){(g+t.id)%60==0&&j(t,e);let n=e.find(e=>e.id===t.target);t.chase&&!n&&k(t,-1),n?R(t,n):I(t)}m=m.filter(t=>z(t,e))},kill:(e,t)=>{let n=y.findIndex(t=>t.id===e);if(n<0)return;let[r]=y.splice(n,1);return h.push({type:D.DIE,id:e,x:r.x,y:w(r),z:r.z}),A(r,t),r}}},Ee=20,De=.5,Oe=2,ke=[`#e6194b`,`#3cb44b`,`#ffe119`,`#4363d8`,`#f58231`,`#911eb4`,`#42d4f4`,`#f032e6`,`#bfef45`,`#fabed4`,`#469990`,`#dcbeff`,`#9a6324`,`#800000`,`#aaffc3`,`#808000`],Ae=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),je=e=>Ae((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),Me=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${Ae(e,15-`${r}`.length)} ${r}`;return n},Ne=(e,t,n,r,i)=>Math.hypot(e.x-t,e.z-r)<=i&&e.y<n+De&&n<e.y+1.8,Pe=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},Fe=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];maps;lvl;horde;rand;level=0;hard=!1;phase=k.HUNT;keys=0;items=[];nextItem=0;kills=0;runStart=0;shots=[];halt;rules;rr=0;constructor(e={},t=Date.now(),n=ie){this.rules={...w,...e},this.rand=we(t),this.maps=n.map(A),this.load(0)}get size(){return this.players().length}connect(e){this.peers.set(e,null)}receive(e,t){let n=this.peers.get(e);if(typeof t==`string`){let r=c(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&o(t);if(r&&n.bank>0){if(n.bank--,n.hp&&de(n.state,r,this.lvl)){let e=ve(this.lvl,n.state,r.seq,this.rewind(n,r.view));if(this.shots.push(e),e.hit>=16){let t=this.horde.kill(e.hit,n.state.id);t&&n.kills++,t&&++this.kills%4==0&&this.drop(O.HEALTH,t.x,t.z)}}n.ack=r.seq}}disconnect(e){let t=this.peers.get(e);this.peers.delete(e),t&&this.roster()}tick(){let e=this.players();if(!e.length)return;let t=++this.ticks;for(let n of e)n.bank=Math.min(10,n.bank+1),!n.hp&&t-n.hurt>=180&&(n.hp=9,n.state=this.place(n.info.id,e.filter(e=>e.hp&&e!==n).map(e=>e.state)));let{events:n}=this.horde,r=n.length;if(this.horde.step(e.filter(e=>e.hp).map(e=>e.state)),n.push(...n.splice(r).filter(e=>e.type!==D.HURT||this.wound(e.id,t))),this.progress(e.filter(e=>e.hp)),t%2==0){let n=this.horde.monsters();for(this.history.push({tick:t,players:e.map(e=>({...e.state})),monsters:n});this.history[0].tick<t-30;)this.history.shift();let r=s({tick:t,players:e.map(e=>({...e.state,ack:e.ack,hp:e.hp})),shots:this.shots,monsters:n,bullets:this.horde.bullets(),events:this.horde.events.splice(0,255),level:this.level,hard:this.hard,phase:this.phase,keys:this.keys,items:this.items});this.shots=[],e.forEach(e=>e.conn.send(r))}}start(e=Pe){if(this.halt)return;let t=1e3/60,n=performance.now(),r=0;this.halt=e(()=>{let e=performance.now();r+=e-n,n=e;for(let e=0;r>=t&&e<Ee;e++)this.tick(),r-=t;r%=t},t)}stop(){this.halt?.(),this.halt=void 0}rewind(e,t=0){let n=this.players().filter(t=>t!==e&&t.hp).map(e=>e.state),r=this.horde.monsters(),[i,a]=[this.history[0],this.history.at(-1)];if(!i||!a)return[...n.map(_e),...r.map(Z)];let o=((this.ticks-t+32768)%65536+65536)%65536-32768,s=Math.min(Math.max(this.ticks-o,i.tick),a.tick),c=0;for(;c+1<this.history.length&&this.history[c+1].tick<=s;)c++;let[l,u]=[this.history[c],this.history[c+1]??this.history[c]],d=u.tick>l.tick?(s-l.tick)/(u.tick-l.tick):0,f=(e,t)=>e+(t-e)*d,p=(e,t)=>e.map(e=>{let n=t(l).find(t=>t.id===e.id),r=t(u).find(t=>t.id===e.id);return n&&r?{...r,x:f(n.x,r.x),y:f(n.y,r.y),z:f(n.z,r.z)}:r??n??e});return[...p(n,e=>e.players).map(_e),...p(r,e=>e.monsters).map(Z)]}load(e){this.level=e,this.lvl=this.maps[e],this.keys=0,this.phase=k.HUNT,j(this.lvl,0,k.HUNT),this.horde=Te(this.lvl,this.rand,this.hard),this.items=[],this.nextItem=0,this.kills=0,this.lvl.map.items?.forEach(([e,t,n])=>this.drop(n,e,t)),this.shots=[],this.history=[];let t=[];for(let e of this.players())e.hp=9,e.state=this.place(e.info.id,t),t.push(e.state)}place(e,t){let n=this.lvl.map.spawns.findIndex((n,r)=>{let{x:i,z:a}=fe(e,this.lvl,r);return!t.some(e=>Math.hypot(e.x-i,e.z-a)<Oe)});return fe(e,this.lvl,n<0?this.rr++:n)}floor(e,t){return this.lvl.map.sectors[Math.max(N(this.lvl,e,t),0)].floor}drop(e,t,n){let r=Math.fround;this.items.push({id:this.nextItem++,kind:e,x:r(t),y:r(this.floor(t,n)),z:r(n)})}wound(e,t){let n=this.players().find(t=>t.info.id===e);return!n?.hp||t-n.hurt<60?!1:([n.hp,n.hurt]=[n.hp-1,t],n.deaths+=+!n.hp,!0)}progress(e){let{sectors:t,goal:n,exit:r}=this.lvl.map,i=!1;if(this.items=this.items.filter(t=>{let n=e.find(e=>Ne(e.state,t.x,t.y,t.z,.8)&&(t.kind!==O.HEALTH||e.hp<9));return n&&t.kind===O.HEALTH?n.hp=Math.min(9,n.hp+3):n&&(this.keys|=1<<t.kind,i=!0),!n}),this.phase===k.HUNT)n&&e.some(e=>Ne(e.state,n[0],this.floor(...n),n[1],1))&&(this.phase=k.RETURN,i=!0);else if(r!==void 0&&e.length&&e.every(e=>M(t[r],e.state.x,e.state.z)))return this.win();i&&j(this.lvl,this.keys,this.phase)}win(){if(this.level+1<this.maps.length){this.load(this.level+1);return}let e=JSON.stringify({t:`end`,ticks:this.ticks-this.runStart,hard:this.hard,stats:this.players().map(e=>({id:e.info.id,kills:e.kills,deaths:e.deaths}))});this.players().forEach(t=>t.conn.send(e)),this.players().forEach(e=>e.kills=e.deaths=0),[this.hard,this.runStart]=[!0,this.ticks],this.load(0)}players(){return[...this.peers.values()].filter(e=>e!==null)}join(e,t){let n=this.players();if(n.length>=this.rules.maxPlayers){e.send(JSON.stringify({t:`full`}));return}let r=0;for(;n.some(e=>e.info.id===r);)r++;let i=ke.find(e=>!n.some(t=>t.info.color===e))??ke[r%ke.length],a={conn:e,info:{id:r,name:Me(je(t)||`Player ${r}`,n.map(e=>e.info.name)),color:i},state:this.place(r,n.filter(e=>e.hp).map(e=>e.state)),bank:10,ack:65535,hp:9,hurt:-60,kills:0,deaths:0};this.peers.set(e,a),this.roster()}roster(){let e=this.players(),t=e.map(e=>e.info).sort((e,t)=>e.id-t.id);e.forEach(e=>e.conn.send(JSON.stringify({t:`roster`,you:e.info.id,players:t})))}},Ie=(e,t)=>{let n=()=>{},r=()=>{n();let r=setInterval(e,t);n=()=>clearInterval(r)};try{let i=URL.createObjectURL(new Blob([`setInterval(()=>postMessage(0),${t})`])),a=new Worker(i);a.onmessage=e,a.onerror=r,n=()=>{a.terminate(),URL.revokeObjectURL(i)}}catch{r()}return()=>n()},Le=(e,t)=>{let n=`tiny-fps:`+e,r=Math.random().toString(36).slice(2),i=new BroadcastChannel(n),a=new AbortController,o=globalThis.navigator?.locks,s,l,u,d,f=[],p,m=!1,h=e=>i.postMessage({from:r,...e}),g=e=>!m&&S.onmessage?.({data:e}),_={send:e=>queueMicrotask(()=>g(e))},v=()=>{let e=f.length?f:p?[p]:[];return f=[],e},y=e=>{if(m)return e();u=e,d=r,l=/* @__PURE__ */ new Map,s=new Fe(t),s.start(Ie),s.connect(_),v().forEach(e=>s.receive(_,e)),h({kind:`h`})};i.onmessage=({data:e})=>{if(!m){if(s&&l){let{from:t,kind:n}=e,r=l.get(t);n===`q`?h({to:t,kind:`h`}):n===`m`&&!e.to?(r||(r={send:e=>!m&&h({to:t,kind:`m`,data:e})},l.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(l.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?g(e.data):e.kind===`h`&&e.from!==d&&(d=e.from,v().forEach(e=>h({kind:`m`,data:e}))))}};let b=e=>{m||(typeof e==`string`&&c(e)?.t===`join`&&(p=e),s?s.receive(_,e):d?h({kind:`m`,data:e}):f.push(e))},x=()=>{m||(m=!0,globalThis.removeEventListener?.(`pagehide`,x),s?(s.stop(),u()):(h({kind:`b`}),a.abort()),i.close(),setTimeout(()=>S.onclose?.()))},S={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:b,close:x};return o?o.request(n,{signal:a.signal},()=>new Promise(y)).catch(()=>{}):y(()=>{}),h({kind:`q`}),globalThis.addEventListener?.(`pagehide`,x),setTimeout(()=>!m&&S.onopen?.()),S};export{Le as localSocket};
|