@korial29/tiny-fps 0.40.0 → 0.41.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/dist/local.js CHANGED
@@ -1 +1 @@
1
- var e={HOME:0,CARRIED:1,DROPPED:2},t={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128,FIRE:256,BLADE:512,SPECIAL:1024},n={THRUST:0,LEFT:1,RIGHT:2,SLASH:3,LUNGE:4,SPIN_L:5,SPIN_R:6,LEAP:7},r={NONE:0,HEAD:1,ARM_L:2,ARM_R:3,LEG_L:4,LEG_R:5},i={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},a={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},o={JUMP:1,DOUBLE:2,DASH:4,LAND:8,GRAB:16,CLIMB:32,WALLRUN_START:64,WALLRUN_END:128,SLIDE_START:256,SLIDE_END:512,RESPAWN:1024},s={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7,CONCRETE:8,GLASS:9,STEEL:10,PAINT:11},c=127,l=16,u=32,d=128/Math.PI,f=254/Math.PI,p=65536/(2*Math.PI),m=e=>Math.round(e*p)&65535,h=e=>Math.max(-32768,Math.min(32767,Math.round(e))),g=e=>h(e*1e4),_=e=>e/1e4,ee=e=>e/p,te=e=>{if(e.byteLength!==12)return null;let t=new DataView(e);return t.getUint8(0)===1?{seq:t.getUint16(1),keys:t.getUint16(3)&2047,yaw:ee(t.getUint16(5)),pitch:_(t.getInt16(7)),view:(t.getUint16(9)*256+t.getUint8(11))/256}:null},v=t=>t===e.CARRIED?2:t===e.DROPPED?8:1,y=n=>{let r=4+52*n.players.length,i=n.balls??[],a=r+8+n.flags.reduce((e,t)=>e+v(t.state),0),o=new DataView(new ArrayBuffer(a+(i.length&&1+11*i.length)));o.setUint8(0,2),o.setUint16(1,n.tick&65535),o.setUint8(3,n.players.length),n.players.forEach((e,n)=>{let r=4+n*52;o.setUint8(r,e.id),o.setFloat32(r+1,e.x),o.setFloat32(r+5,e.y),o.setFloat32(r+9,e.z),o.setFloat32(r+13,e.vx),o.setFloat32(r+17,e.vy),o.setFloat32(r+21,e.vz),o.setFloat32(r+25,e.edge),o.setUint16(r+29,m(e.yaw)),o.setInt16(r+31,g(e.pitch)),o.setUint16(r+33,e.ack&65535),o.setUint8(r+35,e.mode&7|(e.wall&7)<<3|(e.jumps&1)<<6|e.dashes<<7),o.setUint8(r+36,e.t),o.setUint8(r+37,e.dash|(e.by>>2&3)<<6),o.setUint8(r+38,e.coyote&7|(e.buffer&7)<<3|(e.held&t.JUMP?64:0)|(e.held&t.DASH?128:0)),o.setUint8(r+39,e.stun|(e.by&3)<<6);let i=e.hp|e.cool<<3|(e.ammo<0?c:e.ammo)<<6|e.down<<13|!!e.rack<<20|!!e.blade<<21|!!e.wield<<22|!!e.zap<<23;o.setUint8(r+40,i>>16),o.setUint16(r+41,i&65535),o.setUint8(r+43,e.shots),o.setUint8(r+44,e.hits),o.setUint8(r+45,(e.swing??0)&63|((e.cut??0)&3)<<6),o.setUint8(r+46,(e.lost??0)&7|((e.cut??0)&4)<<1),o.setUint8(r+47,e.charge??0),o.setUint8(r+48,e.lock??0),o.setUint8(r+49,(e.foe??0)&15|(e.pressed?128:0)),o.setUint8(r+50,e.pushes??0),o.setUint8(r+51,e.away??0)}),o.setUint8(r,n.score[0]),o.setUint8(r+1,n.score[1]),o.setUint16(r+2,n.clock&32767|(n.over?32768:0)),o.setUint32(r+4,n.packs??0);let s=r+8;for(let t of n.flags)o.setUint8(s,t.state),t.state===e.CARRIED?o.setUint8(s+1,t.by):t.state===e.DROPPED&&(o.setInt16(s+1,h(t.x*l)),o.setInt16(s+3,h(t.y*l)),o.setInt16(s+5,h(t.z*l)),o.setUint8(s+7,Math.min(255,t.left))),s+=v(t.state);i.length&&o.setUint8(s++,i.length);for(let e of i)o.setUint8(s,e.id),o.setUint8(s+1,e.by&127|(e.burst?128:0)),[e.x,e.y,e.z].forEach((e,t)=>o.setInt16(s+2+2*t,h(e*u))),o.setUint8(s+8,Math.round(Math.atan2(-e.dx,-e.dz)*d)&255),o.setInt8(s+9,Math.round(Math.asin(Math.max(-1,Math.min(1,e.dy)))*f)),o.setUint8(s+10,e.power??1),s+=11;return o.buffer},ne=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},b=.4,x=1.8,re=1.6,ie=1.55,ae=.9,oe=.7,se=7.5,ce=1.5,le=.15,ue=.5,de=.9,fe=6.5,pe=.2,me=.03,he=.2,ge=5.5,_e=2.5,ve=[`#ff3d4f`,`#2f80ff`],ye=.12,S=[{ticks:28,strike:10,reach:2.65,arc:.3,hp:2},{ticks:34,strike:13,reach:2.15,arc:1.2,hp:2},{ticks:34,strike:13,reach:2.15,arc:1.2,hp:2},{ticks:40,strike:16,reach:2.15,arc:.45,hp:3},{ticks:36,strike:12,reach:3.2,arc:.3,hp:3},{ticks:48,strike:24,reach:2.3,arc:Math.PI,hp:3},{ticks:48,strike:24,reach:2.3,arc:Math.PI,hp:3},{ticks:58,strike:40,reach:2.4,arc:.6,hp:4}],be=7.5,[xe,Se,Ce]=[.82,.45,.12],we={maxPlayers:16,scoreLimit:3,timeLimit:480},Te=4,C=1024,Ee=(e,t)=>(e+C)*(2*C)+t+C,w=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),De=(e,t=Te)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=w(e[0],t);a<=w(r[0],t);a++)for(let o=w(e[2],t);o<=w(r[2],t);o++){let e=Ee(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},T=(e,t,n,r)=>{let i=[];for(let a=w(t-r,e.cell);a<=w(t+r,e.cell);a++)for(let t=w(n-r,e.cell);t<=w(n+r,e.cell);t++)for(let n of e.grid.get(Ee(a,t))??[])i.includes(n)||i.push(n);return i},E=(e,t,n,r,i=0)=>{let{cell:a,def:o}=e,s=r,c=w(t[0],a),l=w(t[2],a),u=Math.sign(n[0]),d=Math.sign(n[2]),f=u?((c+ +(u>0))*a-t[0])/n[0]:1/0,p=d?((l+ +(d>0))*a-t[2])/n[2]:1/0,m=f,h=p,g=u?a/Math.abs(n[0]):1/0,_=d?a/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(Ee(c,l))??[]){let e=o.brushes[r],[a,c]=[0,s];for(let r=0;r<3&&a<=c;r++){if(!n[r]){(t[r]<e.min[r]-i||t[r]>e.max[r]+i)&&(c=-1);continue}let o=(e.min[r]-i-t[r])/n[r],s=(e.max[r]+i-t[r])/n[r];a=Math.max(a,Math.min(o,s)),c=Math.min(c,Math.max(o,s))}a<=c&&c>0&&a<s&&(s=a)}if(Math.min(m,h)>=s||Math.abs(c)>C||Math.abs(l)>C)return s;m<h?(c+=u,m+=g):(l+=d,h+=_)}},Oe=(e,t,n)=>{let[r,i,a]=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],o=Math.hypot(r,i,a);return o>0&&E(e,t,[r/o,i/o,a/o],o)<o-1e-4},D=1/60,O=Math.PI*2,k=1e-6,A=.01,j=.001,ke=e=>(e%O+O)%O,M=e=>[-Math.sin(e),-Math.cos(e)],N=Math.fround,Ae=Math.sqrt,P=(e,t,n)=>Math.min(Math.max(e,t),n),F=(e,t)=>Ae(e*e+t*t),I=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],je={vx:0,vz:0,mode:i.GROUND,t:0,wall:a.NONE,edge:0,jumps:1,dashes:1,dash:0,stun:0,coyote:6,buffer:0,held:0,hp:5,ammo:-1,cool:0,rack:!1,down:0,shots:0,hits:0,blade:!1,wield:!1,swing:0,cut:0,zap:!1,lost:r.NONE,ev:0,fall:0},Me=(e,t,n,r=0)=>{let{spawns:i}=t.def.teams[r],[a,o,s,c]=i[(n%i.length+i.length)%i.length];return{id:e,x:N(a),y:N(o),z:N(s),vy:0,yaw:ke(c),pitch:0,ground:!0,...je}},Ne=(e,t,n)=>{let{yaw:r,pitch:i,id:a,shots:s,hits:c}=e;Object.assign(e,Me(a,t,a,n),{yaw:r,pitch:i,shots:s,hits:c,ev:e.ev|o.RESPAWN})},L=e=>e===i.GROUND||e===i.SLIDE||e===i.CROUCH,R=e=>e.mode===i.SLIDE||e.mode===i.CROUCH?ae:x,Pe=e=>e.mode===i.SLIDE||e.mode===i.CROUCH?oe:re,Fe=e=>F(e.vx,e.vz),Ie=(e,t,n)=>e.max[1]>t+.5+A&&e.min[1]<t+n-A,z=(e,t,n)=>[t-P(t,e.min[0],e.max[0]),n-P(n,e.min[2],e.max[2])],Le=(e,t,n)=>{let{brushes:r}=t.def,i=T(t,e.x,e.z,2*b),a=(b-k)**2,[o,s]=[0,0];for(let t=0;t<4;t++){let t=0,c=0,l=0;for(let o of i){let i=r[o];if(!Ie(i,e.y,n))continue;let[s,u]=z(i,e.x,e.z),d=s*s+u*u;if(d>=a)continue;if(d){let e=Ae(d);.4-e>t&&(t=b-e,c=s/e*t,l=u/e*t);continue}let[f,p,m]=[[e.x-i.min[0],-1,0],[i.max[0]-e.x,1,0],[e.z-i.min[2],0,-1],[i.max[2]-e.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);f+.4>t&&(t=f+b,[c,l]=[p*t,m*t])}if(!t)break;e.x+=c,e.z+=l,o+=c,s+=l}return[o,s]},Re=(e,t,n)=>{let{brushes:r}=t.def,i=(b-k)**2,a=-1/0,o=1/0;for(let s of T(t,e.x,e.z,b)){let t=r[s],[c,l]=z(t,e.x,e.z);c*c+l*l>=i||(t.max[1]<=e.y+.5+A?a=Math.max(a,t.max[1]):t.min[1]>=e.y+n-A&&(o=Math.min(o,t.min[1])))}return[a,o]},B=(e,t)=>{let n=(b-k)**2;return T(t,e.x,e.z,b).every(r=>{let i=t.def.brushes[r],[a,o]=z(i,e.x,e.z);return a*a+o*o>=n||!Ie(i,e.y,1.8)})},ze=(e,t,n,r,i)=>{let a=(b-k)**2;return T(e,t,n,b).every(o=>{let s=e.def.brushes[o],[c,l]=z(s,t,n);return c*c+l*l>=a||s.max[1]<=r||s.min[1]>=i})},Be=(e,t)=>{let[n,r]=I[t],i=n?0:2;return{a:i,o:2-i,sign:n||r,c:n?e.x:e.z,co:n?e.z:e.x}},Ve=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=Be(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-j&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},He=(e,t,n)=>{let r;for(let i of T(t,e.x,e.z,b+ue)){let a=t.def.brushes[i],o=Ve(a,e,n,ue);o!==void 0&&a.min[1]<e.y+.5&&a.max[1]>e.y+1.8&&(r=Math.min(r??1/0,Math.max(0,o-b)))}return r},Ue=(e,t)=>{let[n,r]=M(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=I[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=Be(e,a);for(let n of T(t,e.x,e.z,b+pe)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(Ve(r,e,a,.2)===void 0||s<1.2||s>2.4||r.min[1]>o-.25||i&&i.top>=o)continue;let u=l>0?r.min[c]:r.max[c],d=u-l*(b+me),f=u+l*he,[p,m]=c===0?[d,e.z]:[e.x,d],[h,g]=c===0?[f,e.z]:[e.x,f];ze(t,p,m,Math.min(e.y,o-2)+A,o+1.8)&&ze(t,h,g,o+A,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},We=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=Be(e,e.wall);return T(t,e.x,e.z,0).some(s=>{let c=t.def.brushes[s],l=i>0?a-c.min[n]:c.max[n]-a;return N(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},Ge=(e,t)=>{if(e.vy>=0)return!1;let[n]=Re(e,t,x),r=6*D;return e.y-n<=-e.vy*r+10*r*r},V=(e,t)=>{e.mode=t,e.t=0},H=(e,t,n,r=48,a=6)=>{e.stun=r,e.vx=N(t*a),e.vz=N(n*a),e.dash=Math.min(e.dash,50),e.coyote=0,e.buffer=0,(e.mode===i.HANG||e.mode===i.CLIMB)&&(e.vy=0),(e.mode===i.HANG||e.mode===i.CLIMB||e.mode===i.WALLRUN)&&(V(e,i.AIR),e.edge=0)},Ke=(e,t)=>{let n=F(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},U=(e,t,n,r)=>{let[i,a]=[n.wx,n.wz];for(let n of T(t,e.x,e.z,b+j)){let o=t.def.brushes[n],[s,c]=z(o,e.x,e.z),l=F(s,c);if(l>0&&l<=.4+j&&Ie(o,e.y,r)){let e=(-i*s-a*c)/l;e>0&&(i+=e*s/l,a+=e*c/l)}}return[i,a]},qe=(e,t,n)=>{let r=F(t[0],t[1]);if(r<k){let t=F(e.vx,e.vz),n=t?Math.max(0,t-45*D)/t:0;e.vx*=n,e.vz*=n;return}let[i,a]=[t[0]/r,t[1]/r],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a],l=F(s,c);if(l){let e=Math.max(0,l-45*D)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*D):Math.max(n,o-12*D),e.vx=s+o*i,e.vz=c+o*a},Je=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*D,e.z+=e.vz*D;let[o,s]=Le(e,t,n),c=F(o,s);if(c){let t=(e.vx*o+e.vz*s)/c;t<0&&(e.vx-=t*o/c,e.vz-=t*s/c)}let[l,u]=Re(e,t,n),d=e.vy-r*20*D;if(e.y+=(e.vy+d)/2*D,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+A:e.y<l){if(e.y=l,e.vy<=0){let t=-e.vy;return e.vy=0,t}}else if(i&&e.vy<=0&&l>=a-.5)return e.y=l,e.vy=0,0;return-1},W=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=o.JUMP},Ye=(e,n,r)=>{let[a,o]=I[e.wall],s=t=>{V(e,t),e.edge=0};if(r.keys&(t.BACK|t.CROUCH))s(i.AIR),e.coyote=0;else if(r.jump&&r.fx*a+r.fz*o<0)s(i.AIR),e.vx=-a*4,e.vz=-o*4,W(e,6);else if(r.jump||r.fwd&&e.t>=6)V(e,i.CLIMB);else if(e.t>=30)s(i.AIR),e.coyote=0;else{let t=Math.max(e.edge-2,Re(e,n,x)[0]);e.y+=P(t-e.y,-8*D,8*D)}},Xe=(e,t)=>{let[n,r]=I[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*D):(e.x+=n*ge*D,e.z+=r*ge*D),e.y>=e.edge&&We(e,t)?(V(e,i.GROUND),e.vx=n*3,e.vz=r*3,e.vy=0,e.edge=0,e.wall=a.NONE,e.coyote=6,e.ev|=o.CLIMB):e.t>=40&&(V(e,e.y>=e.edge?i.GROUND:i.AIR),e.edge=0,e.wall=a.NONE)},Ze=(e,t,n)=>{let[r,a]=I[e.wall],s=e.vx*r+e.vz*a,[c,l]=[e.vx-s*r,e.vz-s*a],u=F(c,l);if(n.jump)V(e,i.AIR),e.vx=c-r*5,e.vz=l-a*5,W(e,fe),e.jumps=1,e.dashes=1,e.ev|=o.WALLRUN_END;else{let s=He(e,t,e.wall);if(s===void 0||!n.fwd||u<3.5||e.t>=60){V(e,i.AIR),e.ev|=o.WALLRUN_END;return}let d=Math.max(0,u-ce*D)/u;e.vx=c*d,e.vz=l*d;let f=Math.min(s,4*D);e.x+=r*f,e.z+=a*f}},Qe=(e,t,n)=>{if(!n.fwd)return;let r=F(e.vx,e.vz);if(!(r<4.5))for(let n=1;n<=4;n++){let[a,s]=I[n],c=e.vx*a+e.vz*s,[l,u]=[e.vx-c*a,e.vz-c*s];if(n!==e.wall&&c<=.75*r&&c>=-.2*r&&He(e,t,n)!==void 0){let t=F(l,u),a=Math.max(t,de*r)/t;V(e,i.WALLRUN),e.wall=n,[e.vx,e.vz]=[l*a,u*a],e.vy=P(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=o.WALLRUN_START;return}}},$e=(e,t)=>{V(e,i.HANG),e.wall=t.side,e.edge=N(t.top),t.side<=a.WEST?e.x=t.hang:e.z=t.hang,e.vx=e.vy=e.vz=0,e.jumps=1,e.dashes=1,e.coyote=0,e.buffer=0,e.ev|=o.GRAB},et=(e,n,r)=>{let s=e.mode===i.GROUND;if(r.dash&&e.dash===0&&(s||(e.mode===i.AIR||e.mode===i.WALLRUN)&&e.dashes>0)){let[t,n]=r.wx||r.wz?[r.wx,r.wz]:[r.fx,r.fz];s||(e.dashes--,e.vy=0,e.mode===i.WALLRUN&&(V(e,i.AIR),e.ev|=o.WALLRUN_END)),e.vx=t*16,e.vz=n*16,e.dash=60,e.ev|=o.DASH}let c=e.dash>50;e.mode===i.WALLRUN&&Ze(e,n,r),L(e.mode)&&tt(e,n,r,c),e.mode===i.AIR&&nt(e,n,r,c);let l=c&&e.vy<=0?0:e.mode===i.WALLRUN?le:1,u=e.mode,d=Je(e,n,R(e),l,L(u));if(d>=0){if(!L(e.mode)){if(e.ev|=o.LAND|(e.mode===i.WALLRUN?o.WALLRUN_END:0),e.fall=d,e.jumps=1,e.dashes=1,e.wall=a.NONE,r.keys&t.CROUCH){let t=F(e.vx,e.vz)>=se;V(e,t?i.SLIDE:i.CROUCH),e.ev|=t?o.SLIDE_START:0}else V(e,i.GROUND)}e.coyote=6}else L(e.mode)&&(e.ev|=e.mode===i.SLIDE?o.SLIDE_END:0,V(e,i.AIR));if(e.mode===i.AIR){let t=Ue(e,n);t?$e(e,t):Qe(e,n,r)}},tt=(e,n,r,a)=>{let s=(r.keys&t.CROUCH)!==0;if(e.buffer>0&&(e.mode===i.GROUND||B(e,n))){e.ev|=e.mode===i.SLIDE?o.SLIDE_END:0,V(e,i.AIR),W(e,7);return}let c=F(e.vx,e.vz);if(e.mode===i.GROUND&&s){let t=c>=se;V(e,t?i.SLIDE:i.CROUCH),e.ev|=t?o.SLIDE_START:0}else e.mode===i.SLIDE&&(e.t>=60||c<4.5||r.stumble)?(e.ev|=o.SLIDE_END,V(e,!s&&B(e,n)?i.GROUND:i.CROUCH)):e.mode===i.SLIDE&&!s&&B(e,n)?(e.ev|=o.SLIDE_END,V(e,i.GROUND)):e.mode===i.CROUCH&&!s&&B(e,n)&&V(e,i.GROUND);if(!a){if(r.stumble){if(c>2.5){let t=Math.max(_e,c-12*D)/c;e.vx*=t,e.vz*=t}else qe(e,U(e,n,r,R(e)),_e)}else if(e.mode===i.SLIDE){let t=Math.max(0,c-4*D)/c;e.vx*=t,e.vz*=t}else if(e.mode===i.CROUCH)qe(e,U(e,n,r,ae),3);else{let i=(r.keys&t.SPRINT)!==0&&r.fwd;qe(e,U(e,n,r,x),i?9:6)}}},nt=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?W(e,7):e.jumps>0&&!Ge(e,t)&&(e.jumps--,W(e,6),e.ev=e.ev&~o.JUMP|o.DOUBLE)),r||!n.wx&&!n.wz)return;let i=F(e.vx,e.vz);e.vx+=n.wx*14*D,e.vz+=n.wz*14*D,Ke(e,Math.max(i,6))},rt=(e,n,r,a=0)=>{e.yaw=ke(n.yaw),e.pitch=Math.max(-ie,Math.min(ie,n.pitch));let o=(n.keys&t.FORWARD?1:0)-(n.keys&t.BACK?1:0),s=(n.keys&t.RIGHT?1:0)-(n.keys&t.LEFT?1:0),c=F(o,s)||1,[l,u]=M(e.yaw),d=t=>(n.keys&t)!==0&&(e.held&t)===0,f=e.stun>0,p={keys:n.keys,stumble:f,jump:!f&&d(t.JUMP),dash:!f&&d(t.DASH),fwd:o>0,wx:(l*o-u*s)/c,wz:(u*o+l*s)/c,fx:l,fz:u},m=e.mode;e.ev=0,e.fall=0,p.jump&&(e.buffer=7),f&&e.stun--,e.dash>0&&(e.dash--,e.dash===50&&Ke(e,10)),e.mode===i.HANG&&Ye(e,r,p),e.mode===i.CLIMB?Xe(e,r):e.mode!==i.HANG&&et(e,r,p),e.y<r.def.floor&&Ne(e,r,a),e.t=e.mode===m?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===i.AIR&&m===i.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=n.keys&(t.JUMP|t.DASH),e.ground=L(e.mode),e.x=N(e.x),e.y=N(e.y),e.z=N(e.z),e.vx=N(e.vx),e.vy=N(e.vy),e.vz=N(e.vz),e.edge=N(e.edge)},it=.7,at=e=>{let[r,i]=[e&t.LEFT,e&t.RIGHT];return r&&!i?n.LEFT:i&&!r?n.RIGHT:e&t.FORWARD?n.THRUST:n.SLASH},ot=(e,t,n)=>{let{reach:r,arc:i}=S[t.cut??0],[a,o]=M(t.yaw),s=[t.x,t.y+it*R(t),t.z];return n.filter(n=>{let[c,l]=[n.x-t.x,n.z-t.z],u=Math.hypot(c,l);if(u-.4>r||t.y>=n.y+R(n)||n.y>=t.y+R(t))return!1;let d=u>.4?Math.abs(Math.atan2(a*l-o*c,a*c+o*l)):0,f=u>.4?Math.asin(b/u):Math.PI;return d<=i+f&&!Oe(e,s,[n.x,n.y+it*R(n),n.z])})},st=(e,t)=>{if(!t.wield||!t.swing||e.lock||t.lock)return!1;let n=S[t.cut??0];if(Math.abs(n.strike-(n.ticks-t.swing))>9)return!1;let[r,i]=[t.x-e.x,t.z-e.z],a=Math.hypot(r,i),o=(e,t,n)=>{let[r,i]=M(e.yaw);return a<1e-6||(r*t+i*n)/a>=Math.cos(.9)};return a-.4<=Math.min(n.reach,S[e.cut??0].reach)&&o(e,r,i)&&o(t,-r,-i)},ct=(e,t)=>{let[r,i]=M(e.yaw),a=e.cut??0;if(a===n.SPIN_L||a===n.SPIN_R){let[n,a]=[t.x-e.x,t.z-e.z],o=Math.hypot(n,a);return o>1e-6?[n/o,a/o]:[r,i]}return a===n.LEFT?[-i,r]:a===n.RIGHT?[i,-r]:[r,i]},lt=(e,t)=>{let[i,a]=M(e.yaw),[o,s]=M(t.yaw),[c,l]=[t.x-e.x,t.z-e.z],u=-a*c+i*l,d=Math.sqrt(Math.max(b*b-u*u,0)),[f,p]=[a*u-i*d,-i*u-a*d],m=-s*f+o*p,h=(e.cut??0)%4;if(h===n.SLASH)return Math.abs(m)<=Ce?r.HEAD:m>0?r.ARM_R:r.ARM_L;let g=(e.y+it*R(e)+Math.tan(e.pitch)*Math.hypot(c,l)-t.y)/R(t);if(g>xe)return r.HEAD;let _=h===n.THRUST?m>0:(h===n.LEFT?1:-1)*(i*o+a*s)<0;return g<Se?_?r.LEG_R:r.LEG_L:h===n.THRUST&&Math.abs(m)<=Ce?r.NONE:_?r.ARM_R:r.ARM_L},G=()=>({state:e.HOME,by:0,x:0,y:0,z:0,left:0}),ut=60,dt=class{score=[0,0];over=!1;flags=[G(),G()];world;rules;mates=/* @__PURE__ */ new Map;clock;back=[0,0];lock=[{id:-1,left:0},{id:-1,left:0}];hold=[0,0];constructor(e,t){this.world=e,this.rules=t,this.clock=t.timeLimit*60}join(e,t,n){this.mates.set(e,{team:t,caps:0,returns:0,ground:[n.x,n.y,n.z]})}leave(e){let t=this.carrying(e),n=this.mates.get(e);t>=0&&n&&this.dropAt(t,n.ground),this.mates.delete(e)}place(e,t){let n=this.mates.get(e);n&&(n.ground=[t.x,t.y,t.z])}moved(e){let t=this.mates.get(e.id);if(!t)return;let n=this.carrying(e.id);e.ev&o.RESPAWN&&n>=0&&this.dropAt(n,t.ground),e.ground&&(t.ground=[e.x,e.y,e.z])}drop(e){let t=this.carrying(e.id),n=this.mates.get(e.id);if(t<0||!n||this.over)return!1;let r=n.ground;if(e.ground)r=[e.x,e.y,e.z];else{let t=E(this.world,[e.x,e.y+.05,e.z],[0,-1,0],ut);t<ut&&(r=[e.x,e.y+.05-t,e.z])}return this.dropAt(t,r),this.lock[t]={id:e.id,left:120},this.hold[t]=120,!0}carrying(t){return this.flags.findIndex(n=>n.state===e.CARRIED&&n.by===t)}winner(){let[e,t]=this.score;return e>t?0:t>e?1:-1}tally(){return[...this.mates].map(([e,t])=>({id:e,caps:t.caps,returns:t.returns}))}reset(){this.over=!1,this.score=[0,0],this.flags=[G(),G()],this.back=[0,0],this.lock.forEach(e=>e.left=0),this.hold=[0,0],this.clock=this.rules.timeLimit*60;for(let e of this.mates.values())e.caps=e.returns=0}wire(){return{score:[...this.score],clock:Math.ceil(this.clock/60),over:this.over,flags:this.flags.map(e=>({...e}))}}tick(t){if(this.over)return--this.clock<=0?(this.reset(),`start`):void 0;for(let t of[0,1]){let n=this.flags[t];this.lock[t].left--,this.hold[t]--,n.state===e.DROPPED&&(n.left=Math.ceil(--this.back[t]/60),this.back[t]<=0&&(this.flags[t]=G()))}for(let n of[0,1]){let r=this.flags[n];if(r.state===e.CARRIED)continue;let i=r.state===e.HOME?this.world.def.teams[n].base:[r.x,r.y,r.z],a=t.filter(e=>ft(e.state,i)),o=r.state===e.DROPPED&&this.hold[n]<=0?a.find(e=>e.team===n):void 0,s=a.find(e=>e.team!==n&&(e.id!==this.lock[n].id||this.lock[n].left<=0));if(o){let e=this.mates.get(o.id);e&&e.returns++,this.flags[n]=G()}else s&&(this.flags[n]={...G(),state:e.CARRIED,by:s.id})}for(let n of t){let t=this.carrying(n.id);if(t>=0&&this.flags[n.team].state===e.HOME&&ft(n.state,this.world.def.teams[n.team].base)){this.score[n.team]++;let e=this.mates.get(n.id);e&&e.caps++,this.flags[t]=G()}}if(this.score.some(e=>e>=this.rules.scoreLimit)||--this.clock<=0)return this.over=!0,this.clock=600,`end`}dropAt(t,[n,r,i]){this.flags[t]={state:e.DROPPED,by:0,x:n,y:r,z:i,left:10},this.back[t]=600}},ft=(e,t)=>Math.hypot(e.x-t[0],e.z-t[2])<1.5&&e.y<t[1]+2.2&&e.y+1.8>t[1],pt=(e,t,n)=>{let[r,i]=[e.x-t[0],e.z-t[2]];return r*r+i*i<n*n&&Math.abs(e.y-t[1])<1},mt=e=>{if(e.mode===i.GROUND){if(e.cut===n.LUNGE){let[t,n]=M(e.yaw);e.vx=t*13,e.vz=n*13,e.dash=60,e.ev|=o.DASH}else e.cut===n.LEAP&&(e.vy=be,e.ev|=o.JUMP)}},K={NONE:0,SHOT:1,CUT:2},ht=(e,n,r,a,o=!0)=>{let s=e.down>0,c=!s&&(e.lock??0)>0;if(rt(e,s||c?{...n,keys:0}:n,r,a),e.zap=!!e.stun&&!!e.zap,s)return e.down>0&&!--e.down&&Ne(e,r,a),K.NONE;if(c)return gt(e,n);let{rack:l,blade:u}=r.def.teams[a],d=!!l&&pt(e,l,1.2);o&&d&&!e.rack&&(e.ammo=60),e.rack=d,e.blade=!!e.blade||o&&!!u&&pt(e,u,1.2),e.cool=Math.max(0,e.cool-1),e.swing=Math.max(0,(e.swing??0)-1),e.wield=e.blade&&(e.swing>0||!!(n.keys&t.BLADE)||e.ammo<0);let f=e.mode===i.HANG||e.mode===i.CLIMB;if(!o)return e.charge=0,K.NONE;let p=S[e.cut??0];if(e.swing&&p.ticks-e.swing===p.strike)return K.CUT;if((e.wield||f||e.ammo<=0)&&(e.charge=0),n.keys&t.FIRE&&!f){let r=S[e.cut??0].ticks-e.swing,i=!!(n.keys&t.SPECIAL)&&(!e.swing||(e.cut??0)<4&&r<=18);e.wield&&(!e.swing||i)?(e.cut=at(n.keys)+(i?4:0),e.swing=S[e.cut].ticks,mt(e)):!e.wield&&!e.cool&&e.ammo>0&&(e.charge=Math.min((e.charge??0)+1,60))}else if(e.charge)return e.power=Math.min(_t(e.charge),e.ammo),e.charge=0,e.ammo-=e.power,e.shots=e.shots+1&255,e.cool=7,K.SHOT;return K.NONE},gt=(e,n)=>{let r=!!(n.keys&t.FIRE);return e.pushes=(e.pushes??0)+ +(r&&!e.pressed)&255,e.pressed=r,e.away=n.keys&(t.LEFT|t.RIGHT|t.BACK)?Math.min((e.away??0)+1,24):0,e.lock=Math.max(1,e.lock-1),[e.wield,e.swing,e.charge]=[!0,0,0],K.NONE},_t=e=>e<10?1:1+Math.floor(4*(e-10)/50),vt=-30,q=(e,t,n,r,i,a=s.CONCRETE)=>({min:[e,vt,t],max:[n,i,r],top:s.CONCRETE,side:a}),J=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c});[q(4,57.7,24,76,10),q(4,36,24,53.5,10,s.GLASS),q(4,20,24,36,12.4),q(4,-5,24,7,12.4,s.GLASS),q(27,20,47,50,8),q(27,60,47,76,8,s.BRICK),J([9,12.2,39],[19,12.6,47],s.STEEL),...((e,t)=>[1,2,3,4,5,6].map(n=>J([12,t,e-n],[14,t+.4*n,e-n+1],s.CONCRETE)))(53,10),J([5,10,42],[5.5,14,42.5],s.STEEL),J([5,10,50],[5.5,14,50.5],s.STEEL),J([8,12.4,24],[20,12.85,24.45],s.STEEL),J([36,8,22],[37,14.5,48],s.PAINT,s.PAINT,[.15,.72,.62]),J([30,8,28],[34,10,32],s.CONCRETE),J([40,8,30],[44,10.2,34],s.PAINT,s.PAINT,[1,.3,.06]),J([28,9.2,44],[35,12,46],s.STEEL,s.PAINT,[.2,.42,1]),J([41.5,7.6,50],[42,8,60],s.STEEL),J([30,8,64],[34,9.6,68],s.PAINT,s.PAINT,[.2,.8,.3])];var Y=240,X=[1,.22,.26],yt=[.2,.46,1],bt=[1,.42,.08],xt=[.12,.7,.62],Z=(e,t,n,r,i,a,o)=>J([e,t,n],[r,i,a],s.PAINT,s.PAINT,o),St=(e,t,n,r,i,a,o,c=vt)=>{let l=Math.ceil((o-a)/.46);return Array.from({length:l},(u,d)=>{let[f,p]=[t+(n-t)*d/l,t+(n-t)*(d+1)/l].sort((e,t)=>e-t),m=a+(o-a)*(d+1)/l;return e===0?J([f,c,r],[p,m,i],s.CONCRETE):J([r,c,f],[i,m,p],s.CONCRETE)})},Q=(e,t,n,r,i,a,o)=>o.map((o,c)=>J([e+c*n,a,t+c*r],[e+c*n+4,o,t+c*r+i],s.STEEL,s.CONCRETE)),Ct=[q(12,212,52,240,26,s.GLASS),Z(12,26,212,52,26.12,212.5,X),Z(12,26,239.5,52,26.12,240,X),Z(12,26,212.5,12.5,26.12,239.5,X),Z(51.5,26,212.5,52,26.12,239.5,X),Z(11.6,12,222,12,25.8,232,X),Z(28,12,211.4,31,25.5,212,X),J([19,26,222],[22,27.4,225],s.STEEL),J([42,26,222],[45,27.4,225],s.STEEL),J([29,26,229],[35,27.1,229.6],s.CONCRETE),J([29,26,215],[35,27.5,219],s.STEEL,s.PAINT,X),q(6,164,26,201,26,s.GLASS),q(6,134,26,147,26,s.GLASS),q(6,201,26,212,19),q(15,147,26,164,19),J([14,26,164],[15,32,196],s.PAINT,s.PAINT,xt),J([14,18,147],[15,32,164],s.PAINT,s.PAINT,xt),J([14,26,134],[15,32,147],s.PAINT,s.PAINT,xt),...Q(6,201,7,0,4,19,[21.2,23.4,25]),...[[18,152,22,156,21.2],[18,158,22,162,23.4],[23,160,26,164,25]].map(([e,t,n,r,i])=>J([e,19,t],[n,i,r],s.STEEL,s.CONCRETE)),J([20,26,178],[23,27.3,181],s.STEEL),J([8,26,176],[11,27.2,179],s.STEEL),J([8,26,190],[11,27.3,193],s.STEEL),J([20,26,140],[23,27.3,143],s.STEEL),q(32,186,76,209,19),Z(32,19,207.5,76,19.1,209,X),...Q(33,209,7,0,3,19,[21.2,23.4,25]),...[[28,196,32,200,21.2],[28,190,32,194,23.4],[26,184,30,188,25]].map(([e,t,n,r,i])=>J([e,vt,t],[n,i,r],s.STEEL,s.CONCRETE)),q(32,166,64,182,21.2,s.GLASS),q(32,140,64,161,19),J([40,21.2,172],[44,22.6,176],s.STEEL),J([52,19,148],[57,20.3,151],s.STEEL),J([38,19,196],[41,20.4,199],s.STEEL),J([60,19,200],[63,20.4,203],s.STEEL),J([52,19,190],[58,20.6,194],s.STEEL),J([66,19,204],[72,20.2,207],s.STEEL),J([56,21.2,170],[60,22.4,174],s.STEEL),J([34,19,152],[37,20.3,156],s.STEEL),...Q(36,135,18,0,3,15,[17.2,17.2]),...Q(6.5,129,6,0,4,15,[17.2,19.4,21.6,23.8]),q(76,213,100,240,14.5,s.STEEL),Z(76,14.5,238.5,100,14.6,240,X),q(76,185,100,209,14.5),q(76,138,100,181,14.5,s.GLASS),J([80,15.7,158],[96,17.7,162],s.STEEL,s.PAINT,bt),J([82,14.5,234],[85,15.9,237],s.STEEL),J([91,14.5,190],[94,15.9,193],s.STEEL),J([80,14.5,204],[83,15.6,207],s.STEEL),J([78,14.5,170],[81,15.9,173],s.STEEL),J([92,14.5,146],[95,15.7,149],s.STEEL),J([92,14.5,222],[96,15.8,226],s.STEEL),...St(0,76,52,226,232,14.5,26),...St(0,85,76,196,202,14.5,19,14.5)],wt=[q(6,106,62,134,15),q(62,106,100,134,14.5),J([34,15,112],[54,17.2,128],s.CONCRETE),Z(38,17.2,116,50,17.3,124,bt),...[[35,113],[35,126.2],[51,113],[51,126.2]].map(([e,t])=>J([e,17.2,t],[e+.8,21.5,t+.8],s.STEEL)),J([34.6,21.5,112.6],[52.2,21.9,127.4],s.GLASS),J([14,15,114],[17,16.5,117],s.STEEL),J([14,15,123],[17,16.5,126],s.STEEL),J([56,15,114],[59,16.5,117],s.STEEL),J([56,15,123],[59,16.5,126],s.STEEL),J([15.35,25.5,106],[15.85,26,134],s.STEEL),J([70,14.5,108],[70.8,38,108.8],s.STEEL),J([70,14.5,131.2],[70.8,38,132],s.STEEL),J([66,14.5,110],[69,15.9,113],s.STEEL),J([66,14.5,127],[69,15.9,130],s.STEEL)],Tt=e=>({...e,min:[e.min[0],e.min[1],Y-e.max[2]],max:[e.max[0],e.max[1],Y-e.min[2]],tint:e.tint===X?yt:e.tint}),Et=(e,t,n)=>[...[16,22,28,34,40].map(n=>[n,26,t,e]),...[19,31,43].map(t=>[t,26,n,e])],Dt=[[20,26,190],[48,21.2,172],[48,19,200],[88,14.5,198]],Ot=[[21,26,168],[46,19,144],[36,21.2,178],[88,14.5,216],[88,14.5,172]],kt={name:`Highline`,brushes:[...Ct,...Ct.map(Tt),...wt],teams:[{base:[32,26,224],spawns:Et(0,236,231),rack:[30.75,27.5,217],blade:[33.25,27.5,217]},{base:[32,26,16],spawns:Et(Math.PI,4,9),rack:[30.75,27.5,23],blade:[33.25,27.5,23]}],packs:[...Dt,...Dt.map(([e,t,n])=>[e,t,Y-n]),[24,15,112],[24,15,128]],ammo:[...Ot,...Ot.map(([e,t,n])=>[e,t,Y-n])],floor:-25,sun:{dir:[.8,.6,0],color:[2.6,2.3,1.8]},sky:[[.04,.2,.72],[.72,.86,.98]],fog:[.72,.86,.98,.0035]},At=40/60,jt=(e,t=0)=>{let[n,r,i,a]=[Math.sin(e.yaw),Math.cos(e.yaw),Math.sin(e.pitch),Math.cos(e.pitch)];return{id:e.shots,by:e.id,team:t,x:e.x,y:e.y+Pe(e),z:e.z,dx:-n*a,dy:i,dz:-r*a,left:80,burst:!1,power:e.power??1}},Mt=(e,t,n,r,i)=>{let[a,o]=[e[0]-n.x,e[2]-n.z],s=t[0]*t[0]+t[2]*t[2],c=a*t[0]+o*t[2],l=c*c-s*(a*a+o*o-r*r),[u,d]=[0,1/0];if(s>1e-12){if(l<0)return 1/0;[u,d]=[(-c-Math.sqrt(l))/s,(-c+Math.sqrt(l))/s]}else if(a*a+o*o>r*r)return 1/0;let[f,p]=[n.y-e[1],n.y+i-e[1]];if(t[1])[u,d]=[Math.max(u,Math.min(f/t[1],p/t[1])),Math.min(d,Math.max(f/t[1],p/t[1]))];else if(f>0||p<0)return 1/0;return u<=d&&d>=0?Math.max(u,0):1/0},Nt=(e,t,n,r)=>{let i=[t.x,t.y,t.z],a=[t.dx,t.dy,t.dz],o=Math.min(n,t.left),s=E(e,i,a,o,ye),c;for(let e of r){let t=Mt(i,a,e,b+ye,R(e));t<s&&([s,c]=[t,e])}return t.burst=s<o,t.left-=s,[t.x,t.y,t.z]=[i[0]+a[0]*s,i[1]+a[1]*s,i[2]+a[2]*s],c},Pt=e=>e.mode===i.SLIDE||e.dash>50,Ft=(e,t)=>Math.hypot(e.x-t.x,e.z-t.z)<1.1&&e.y<t.y+R(t)&&t.y<e.y+R(e),It=20,Lt=2,Rt=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),zt=e=>Rt((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),Bt=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${Rt(e,15-`${r}`.length)} ${r}`;return n},Vt=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},$={lock:0,foe:0,pushes:0,pressed:!1,away:0},Ht=({x:e,y:t,z:n,yaw:r})=>({x:e,y:t,z:n,yaw:r}),Ut=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];world;ctf;halt;rules;rr=[0,0];gone;balls=[];constructor(e={},t=kt){this.rules={...we,...e},this.world=De(t),this.ctf=new dt(this.world,this.rules),this.gone=[...t.packs??[],...t.ammo??[]].map(()=>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=ne(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&te(t);if(r&&n.bank>0){n.bank--;let e=ht(n.state,r,this.world,n.info.team,!this.ctf.over);this.ctf.moved(n.state),this.tackle(n,r.view),e===K.SHOT?this.shoot(n,r.view):e===K.CUT&&this.cut(n,r.view),this.duel(n),n.ack=r.seq}}disconnect(e){let t=this.peers.get(e);this.peers.delete(e),t&&(this.ctf.leave(t.info.id),this.size||(this.ctf.reset(),this.gone.fill(0)),this.roster())}drop(e){let t=this.players().find(t=>t.info.id===e);return!!t&&this.ctf.drop(t.state)}tick(){let e=this.players();if(!e.length){this.balls=[];return}let t=++this.ticks;for(let t of e)t.bank=Math.min(10,t.bank+1);for(let e of this.balls)!e.burst&&e.left>0&&this.fly(e,At);this.heal(e);let n=this.ctf.tick(e.filter(e=>!e.state.down).map(e=>({id:e.info.id,team:e.info.team,state:e.state})));if(n===`end`?this.end(e):n===`start`&&this.restart(e),t%2==0){for(this.history.push({tick:t,players:e.map(e=>({...e.state}))});this.history[0].tick<t-30;)this.history.shift();let n=y({tick:t,players:e.map(e=>({...e.state,ack:e.ack,by:e.state.stun?e.by:0})),...this.ctf.wire(),packs:this.gone.reduce((e,t,n)=>t?e:e|1<<n,0)>>>0,balls:this.balls});e.forEach(e=>e.conn.send(n)),this.balls=this.balls.filter(e=>!e.burst&&e.left>0)}}start(e=Vt){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<It;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.info.id!==e).map(e=>e.state),[r,i]=[this.history[0],this.history.at(-1)];if(!r||!i)return n;let a=((this.ticks-t+32768)%65536+65536)%65536-32768,o=Math.min(Math.max(this.ticks-a,r.tick),i.tick),s=0;for(;s+1<this.history.length&&this.history[s+1].tick<=o;)s++;let[c,l]=[this.history[s],this.history[s+1]??this.history[s]],u=l.tick>c.tick?(o-c.tick)/(l.tick-c.tick):0,d=(e,t)=>e+(t-e)*u;return n.map(e=>{let t=c.players.find(t=>t.id===e.id),n=l.players.find(t=>t.id===e.id);return t&&n?{...n,x:d(t.x,n.x),y:d(t.y,n.y),z:d(t.z,n.z)}:n??t??e})}tackle(e,t){let n=e.state;if(n.down||!Pt(n)||this.ticks-e.tackled<30)return;let r=this.players().filter(t=>t.info.team!==e.info.team),i=this.rewind(e.info.id,t).find(e=>Ft(n,e)&&r.some(t=>t.info.id===e.id&&this.ctf.carrying(t.info.id)>=0)),a=r.find(e=>e.info.id===i?.id);if(!a||!this.drop(a.info.id))return;let o=Fe(n),[s,c]=o>.001?[n.vx/o,n.vz/o]:M(n.yaw);H(a.state,s,c),a.state.zap=!1,a.by=e.info.id,e.tackled=this.ticks}enemies(e,t){let n=this.players();return this.rewind(e.info.id,t).filter(t=>{let r=n.find(e=>e.info.id===t.id);return r&&r.info.team!==e.info.team&&!r.state.down&&!t.down})}harm(e,t){return(e.state.hp-=t)>0?!1:(Object.assign(e.state,{hp:0,down:120,ammo:-1,cool:0,charge:0,blade:!1,wield:!1,swing:0,lost:r.NONE}),this.ctf.drop(e.state),!0)}shoot(e,t=0){let n=jt(e.state,e.info.team),r=(this.ticks-t+65536)%65536;this.balls.push(n),this.fly(n,Math.min(r<32768?r:0,12)*At);let i=this.balls.filter(e=>!e.burst);i.length>64&&(i[0].burst=!0)}fly(e,t){let n=this.players(),r=n.filter(t=>t.info.team!==e.team&&!t.state.down),i=Nt(this.world,e,t,r.map(e=>e.state)),a=r.find(e=>e.state===i);if(!a)return;let o=n.find(t=>t.info.id===e.by);o&&(o.state.hits=o.state.hits+1&255),this.harm(a,e.power??1)}cut(e,t){let n=ot(this.world,e.state,this.enemies(e,t)),r=this.players().filter(e=>n.some(t=>t.id===e.info.id)),i=r.find(t=>st(e.state,{...t.state,...Ht(n.find(e=>e.id===t.info.id))}));if(i){for(let[t,n]of[[e,i],[i,e]])Object.assign(t.state,{...$,lock:240,foe:n.info.id,pressed:!0}),Object.assign(t.state,{swing:0,charge:0,stun:0,zap:!1,vx:0,vz:0});r=r.filter(e=>e!==i)}if(r.length){e.state.hits=e.state.hits+1&255;for(let t of r){let r=n.find(e=>e.id===t.info.id);if(this.harm(t,S[e.state.cut??0].hp))t.state.lost=lt(e.state,r);else{let[n,i]=ct(e.state,r);H(t.state,n,i,24,4),t.state.zap=!0,t.by=e.info.id}}}}duel(e){let t=e.state;if(!t.lock)return;let n=this.players().find(e=>e.info.id===t.foe);if(!n||n.state.foe!==e.info.id||!n.state.lock||n.state.down||t.down){Object.assign(t,$);return}let r=(t.pushes??0)-(n.state.pushes??0),i=(t.away??0)>=24||(n.state.away??0)>=24;if(!(Math.abs(r)<8&&!i&&t.lock>1)){if(Object.assign(t,$),Object.assign(n.state,$),Math.abs(r)>=8){let[t,i]=r>0?[e,n]:[n,e];if(t.state.hits=t.state.hits+1&255,!this.harm(i,3)){let[e,n]=M(t.state.yaw);H(i.state,e,n,24,4),i.state.zap=!0,i.by=t.info.id}}else if(!i){let[e,r]=[n.state.x-t.x,n.state.z-t.z],i=Math.hypot(e,r)||1;H(t,-e/i,-r/i),H(n.state,e/i,r/i)}}}heal(e){let{packs:t=[],ammo:n=[]}=this.world.def;[...t,...n].forEach((n,r)=>{if(this.gone[r]>0){this.gone[r]--;return}let i=r<t.length,a=e.find(({state:e})=>!e.down&&(i?e.hp<5:e.ammo>=0&&e.ammo<60)&&pt(e,n,.9));if(a){let e=a.state;i?e.hp=Math.min(5,e.hp+2):e.ammo=Math.min(60,e.ammo+20),this.gone[r]=1200}})}place(e,t,n){let r=this.world.def.teams[t].spawns.findIndex((r,i)=>{let{x:a,z:o}=Me(e,this.world,i,t);return!n.some(e=>Math.hypot(e.x-a,e.z-o)<Lt)});return Me(e,this.world,r<0?this.rr[t]++:r,t)}end(e){let t=this.ctf.tally().flatMap(t=>{let n=e.find(e=>e.info.id===t.id)?.info;return n?[{...t,name:n.name,team:n.team}]:[]}),n=JSON.stringify({t:`end`,score:this.ctf.score,players:t});e.forEach(e=>e.conn.send(n))}restart(e){let t=[];this.rr=[0,0],this.gone.fill(0);for(let n of e){let{shots:e,hits:r}=n.state;n.state={...this.place(n.info.id,n.info.team,t),shots:e,hits:r},t.push(n.state),this.ctf.place(n.info.id,n.state)}}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=n.filter(e=>e.info.team===0).length,a=+(i>n.length-i),o={conn:e,info:{id:r,name:Bt(zt(t)||`Player ${r}`,n.map(e=>e.info.name)),team:a,color:ve[a]},state:this.place(r,a,n.map(e=>e.state)),bank:10,ack:65535,by:0,tackled:-30};this.peers.set(e,o),this.ctf.join(r,a,o.state),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})))}},Wt=(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()},Gt=(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,c,l,u,d=[],f,p=!1,m=e=>i.postMessage({from:r,...e}),h=e=>!p&&y.onmessage?.({data:e}),g={send:e=>queueMicrotask(()=>h(e))},_=()=>{let e=d.length?d:f?[f]:[];return d=[],e},ee=e=>{if(p)return e();l=e,u=r,c=/* @__PURE__ */ new Map,s=new Ut(t),s.start(Wt),s.connect(g),_().forEach(e=>s.receive(g,e)),m({kind:`h`})};i.onmessage=({data:e})=>{if(!p){if(s&&c){let{from:t,kind:n}=e,r=c.get(t);n===`q`?m({to:t,kind:`h`}):n===`m`&&!e.to?(r||(r={send:e=>!p&&m({to:t,kind:`m`,data:e})},c.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(c.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?h(e.data):e.kind===`h`&&e.from!==u&&(u=e.from,_().forEach(e=>m({kind:`m`,data:e}))))}};let te=e=>{p||(typeof e==`string`&&ne(e)?.t===`join`&&(f=e),s?s.receive(g,e):u?m({kind:`m`,data:e}):d.push(e))},v=()=>{p||(p=!0,globalThis.removeEventListener?.(`pagehide`,v),s?(s.stop(),l()):(m({kind:`b`}),a.abort()),i.close(),setTimeout(()=>y.onclose?.()))},y={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:te,close:v};return o?o.request(n,{signal:a.signal},()=>new Promise(ee)).catch(()=>{}):ee(()=>{}),m({kind:`q`}),globalThis.addEventListener?.(`pagehide`,v),setTimeout(()=>!p&&y.onopen?.()),y};export{Gt as localSocket};
1
+ var e={HOME:0,CARRIED:1,DROPPED:2},t={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128,FIRE:256,BLADE:512,SPECIAL:1024,RAIL:2048},n={THRUST:0,LEFT:1,RIGHT:2,SLASH:3,LUNGE:4,SPIN_L:5,SPIN_R:6,LEAP:7},r={NONE:0,HEAD:1,ARM_L:2,ARM_R:3,LEG_L:4,LEG_R:5},i={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},a={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},o={JUMP:1,DOUBLE:2,DASH:4,LAND:8,GRAB:16,CLIMB:32,WALLRUN_START:64,WALLRUN_END:128,SLIDE_START:256,SLIDE_END:512,RESPAWN:1024},s={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7,CONCRETE:8,GLASS:9,STEEL:10,PAINT:11},c=127,l=16,u=32,d=128/Math.PI,f=254/Math.PI,p=65536/(2*Math.PI),m=e=>Math.round(e*p)&65535,h=e=>Math.max(-32768,Math.min(32767,Math.round(e))),g=e=>h(e*1e4),_=e=>e/1e4,v=e=>e/p,ee=e=>{if(e.byteLength!==12)return null;let t=new DataView(e);return t.getUint8(0)===1?{seq:t.getUint16(1),keys:t.getUint16(3)&4095,yaw:v(t.getUint16(5)),pitch:_(t.getInt16(7)),view:(t.getUint16(9)*256+t.getUint8(11))/256}:null},y=t=>t===e.CARRIED?2:t===e.DROPPED?8:1,b=n=>{let r=4+55*n.players.length,i=n.balls??[],a=r+8+n.flags.reduce((e,t)=>e+y(t.state),0),o=new DataView(new ArrayBuffer(a+(i.length&&1+11*i.length)));o.setUint8(0,2),o.setUint16(1,n.tick&65535),o.setUint8(3,n.players.length),n.players.forEach((e,n)=>{let r=4+n*55;o.setUint8(r,e.id),o.setFloat32(r+1,e.x),o.setFloat32(r+5,e.y),o.setFloat32(r+9,e.z),o.setFloat32(r+13,e.vx),o.setFloat32(r+17,e.vy),o.setFloat32(r+21,e.vz),o.setFloat32(r+25,e.edge),o.setUint16(r+29,m(e.yaw)),o.setInt16(r+31,g(e.pitch)),o.setUint16(r+33,e.ack&65535),o.setUint8(r+35,e.mode&7|(e.wall&7)<<3|(e.jumps&1)<<6|e.dashes<<7),o.setUint8(r+36,e.t),o.setUint8(r+37,e.dash|(e.by>>2&3)<<6),o.setUint8(r+38,e.coyote&7|(e.buffer&7)<<3|(e.held&t.JUMP?64:0)|(e.held&t.DASH?128:0)),o.setUint8(r+39,e.stun|(e.by&3)<<6);let i=e.hp|e.cool<<3|(e.ammo<0?c:e.ammo)<<6|e.down<<13|!!e.rack<<20|!!e.blade<<21|!!e.wield<<22|!!e.zap<<23;o.setUint8(r+40,i>>16),o.setUint16(r+41,i&65535),o.setUint8(r+43,e.shots),o.setUint8(r+44,e.hits),o.setUint8(r+45,(e.swing??0)&63|((e.cut??0)&3)<<6),o.setUint8(r+46,(e.lost??0)&7|((e.cut??0)&4)<<1),o.setUint8(r+47,e.charge??0),o.setUint8(r+48,e.lock??0),o.setUint8(r+49,(e.foe??0)&15|(e.pressed?128:0)),o.setUint8(r+50,e.pushes??0),o.setUint8(r+51,e.away??0),o.setUint8(r+52,(e.rail??-1)+1|(e.railed?32:0)|(e.inRail?64:0)),o.setUint8(r+53,e.reload??0),o.setUint8(r+54,e.slow??0)}),o.setUint8(r,n.score[0]),o.setUint8(r+1,n.score[1]),o.setUint16(r+2,n.clock&32767|(n.over?32768:0)),o.setUint32(r+4,n.packs??0);let s=r+8;for(let t of n.flags)o.setUint8(s,t.state),t.state===e.CARRIED?o.setUint8(s+1,t.by):t.state===e.DROPPED&&(o.setInt16(s+1,h(t.x*l)),o.setInt16(s+3,h(t.y*l)),o.setInt16(s+5,h(t.z*l)),o.setUint8(s+7,Math.min(255,t.left))),s+=y(t.state);i.length&&o.setUint8(s++,i.length);for(let e of i)o.setUint8(s,e.id),o.setUint8(s+1,e.by&127|(e.burst?128:0)),[e.x,e.y,e.z].forEach((e,t)=>o.setInt16(s+2+2*t,h(e*u))),o.setUint8(s+8,Math.round(Math.atan2(-e.dx,-e.dz)*d)&255),o.setInt8(s+9,Math.round(Math.asin(Math.max(-1,Math.min(1,e.dy)))*f)),o.setUint8(s+10,e.power??1),s+=11;return o.buffer},te=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},x=.4,S=1.8,ne=1.6,re=1.55,ie=.9,ae=.7,oe=7.5,se=1.5,ce=.15,le=.5,ue=.9,de=6.5,fe=.2,pe=.03,me=.2,he=5.5,ge=2.5,_e=[`#ff3d4f`,`#2f80ff`],ve=.12,C=[{ticks:28,strike:10,reach:2.65,arc:.3,hp:2},{ticks:34,strike:13,reach:2.15,arc:1.2,hp:2},{ticks:34,strike:13,reach:2.15,arc:1.2,hp:2},{ticks:40,strike:16,reach:2.15,arc:.45,hp:3},{ticks:36,strike:12,reach:3.2,arc:.3,hp:3},{ticks:48,strike:24,reach:2.3,arc:Math.PI,hp:3},{ticks:48,strike:24,reach:2.3,arc:Math.PI,hp:3},{ticks:58,strike:40,reach:2.4,arc:.6,hp:4}],ye=7.5,[be,xe,Se]=[.82,.45,.12],Ce={maxPlayers:16,scoreLimit:3,timeLimit:480},we=4,w=1024,Te=(e,t)=>(e+w)*(2*w)+t+w,T=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),Ee=(e,t=we)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=T(e[0],t);a<=T(r[0],t);a++)for(let o=T(e[2],t);o<=T(r[2],t);o++){let e=Te(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},E=(e,t,n,r)=>{let i=[];for(let a=T(t-r,e.cell);a<=T(t+r,e.cell);a++)for(let t=T(n-r,e.cell);t<=T(n+r,e.cell);t++)for(let n of e.grid.get(Te(a,t))??[])i.includes(n)||i.push(n);return i},D=(e,t,n,r,i=0)=>{let{cell:a,def:o}=e,s=r,c=T(t[0],a),l=T(t[2],a),u=Math.sign(n[0]),d=Math.sign(n[2]),f=u?((c+ +(u>0))*a-t[0])/n[0]:1/0,p=d?((l+ +(d>0))*a-t[2])/n[2]:1/0,m=f,h=p,g=u?a/Math.abs(n[0]):1/0,_=d?a/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(Te(c,l))??[]){let e=o.brushes[r],[a,c]=[0,s];for(let r=0;r<3&&a<=c;r++){if(!n[r]){(t[r]<e.min[r]-i||t[r]>e.max[r]+i)&&(c=-1);continue}let o=(e.min[r]-i-t[r])/n[r],s=(e.max[r]+i-t[r])/n[r];a=Math.max(a,Math.min(o,s)),c=Math.min(c,Math.max(o,s))}a<=c&&c>0&&a<s&&(s=a)}if(Math.min(m,h)>=s||Math.abs(c)>w||Math.abs(l)>w)return s;m<h?(c+=u,m+=g):(l+=d,h+=_)}},De=(e,t,n)=>{let[r,i,a]=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],o=Math.hypot(r,i,a);return o>0&&D(e,t,[r/o,i/o,a/o],o)<o-1e-4},O=1/60,Oe=Math.PI*2,k=1e-6,A=.01,ke=.001,Ae=e=>(e%Oe+Oe)%Oe,j=e=>[-Math.sin(e),-Math.cos(e)],M=Math.fround,je=Math.sqrt,N=(e,t,n)=>Math.min(Math.max(e,t),n),P=(e,t)=>je(e*e+t*t),F=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],Me={vx:0,vz:0,mode:i.GROUND,t:0,wall:a.NONE,edge:0,jumps:1,dashes:1,dash:0,stun:0,coyote:6,buffer:0,held:0,hp:5,ammo:-1,cool:0,rack:!1,down:0,shots:0,hits:0,blade:!1,wield:!1,swing:0,cut:0,zap:!1,lost:r.NONE,ev:0,fall:0},Ne=(e,t,n,r=0)=>{let{spawns:i}=t.def.teams[r],[a,o,s,c]=i[(n%i.length+i.length)%i.length];return{id:e,x:M(a),y:M(o),z:M(s),vy:0,yaw:Ae(c),pitch:0,ground:!0,...Me}},Pe=(e,t,n)=>{let{yaw:r,pitch:i,id:a,shots:s,hits:c}=e;Object.assign(e,Ne(a,t,a,n),{yaw:r,pitch:i,shots:s,hits:c,ev:e.ev|o.RESPAWN})},I=e=>e===i.GROUND||e===i.SLIDE||e===i.CROUCH,L=e=>e.mode===i.SLIDE||e.mode===i.CROUCH?ie:S,Fe=e=>e.mode===i.SLIDE||e.mode===i.CROUCH?ae:ne,Ie=e=>P(e.vx,e.vz),Le=(e,t,n)=>e.max[1]>t+.5+A&&e.min[1]<t+n-A,R=(e,t,n)=>[t-N(t,e.min[0],e.max[0]),n-N(n,e.min[2],e.max[2])],Re=(e,t,n)=>{let{brushes:r}=t.def,i=E(t,e.x,e.z,2*x),a=(x-k)**2,[o,s]=[0,0];for(let t=0;t<4;t++){let t=0,c=0,l=0;for(let o of i){let i=r[o];if(!Le(i,e.y,n))continue;let[s,u]=R(i,e.x,e.z),d=s*s+u*u;if(d>=a)continue;if(d){let e=je(d);.4-e>t&&(t=x-e,c=s/e*t,l=u/e*t);continue}let[f,p,m]=[[e.x-i.min[0],-1,0],[i.max[0]-e.x,1,0],[e.z-i.min[2],0,-1],[i.max[2]-e.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);f+.4>t&&(t=f+x,[c,l]=[p*t,m*t])}if(!t)break;e.x+=c,e.z+=l,o+=c,s+=l}return[o,s]},ze=(e,t,n)=>{let{brushes:r}=t.def,i=(x-k)**2,a=-1/0,o=1/0;for(let s of E(t,e.x,e.z,x)){let t=r[s],[c,l]=R(t,e.x,e.z);c*c+l*l>=i||(t.max[1]<=e.y+.5+A?a=Math.max(a,t.max[1]):t.min[1]>=e.y+n-A&&(o=Math.min(o,t.min[1])))}return[a,o]},z=(e,t)=>{let n=(x-k)**2;return E(t,e.x,e.z,x).every(r=>{let i=t.def.brushes[r],[a,o]=R(i,e.x,e.z);return a*a+o*o>=n||!Le(i,e.y,1.8)})},Be=(e,t,n,r,i)=>{let a=(x-k)**2;return E(e,t,n,x).every(o=>{let s=e.def.brushes[o],[c,l]=R(s,t,n);return c*c+l*l>=a||s.max[1]<=r||s.min[1]>=i})},Ve=(e,t)=>{let[n,r]=F[t],i=n?0:2;return{a:i,o:2-i,sign:n||r,c:n?e.x:e.z,co:n?e.z:e.x}},He=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=Ve(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-ke&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},Ue=(e,t,n)=>{let r;for(let i of E(t,e.x,e.z,x+le)){let a=t.def.brushes[i],o=He(a,e,n,le);o!==void 0&&a.min[1]<e.y+.5&&a.max[1]>e.y+1.8&&(r=Math.min(r??1/0,Math.max(0,o-x)))}return r},We=(e,t)=>{let[n,r]=j(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=F[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=Ve(e,a);for(let n of E(t,e.x,e.z,x+fe)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(He(r,e,a,.2)===void 0||s<1.2||s>2.4||r.min[1]>o-.25||i&&i.top>=o)continue;let u=l>0?r.min[c]:r.max[c],d=u-l*(x+pe),f=u+l*me,[p,m]=c===0?[d,e.z]:[e.x,d],[h,g]=c===0?[f,e.z]:[e.x,f];Be(t,p,m,Math.min(e.y,o-2)+A,o+1.8)&&Be(t,h,g,o+A,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},Ge=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=Ve(e,e.wall);return E(t,e.x,e.z,0).some(s=>{let c=t.def.brushes[s],l=i>0?a-c.min[n]:c.max[n]-a;return M(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},Ke=(e,t)=>{if(e.vy>=0)return!1;let[n]=ze(e,t,S),r=6*O;return e.y-n<=-e.vy*r+10*r*r},B=(e,t)=>{e.mode=t,e.t=0},V=(e,t,n,r=48,a=6)=>{e.stun=r,e.vx=M(t*a),e.vz=M(n*a),e.dash=Math.min(e.dash,50),e.coyote=0,e.buffer=0,(e.mode===i.HANG||e.mode===i.CLIMB)&&(e.vy=0),(e.mode===i.HANG||e.mode===i.CLIMB||e.mode===i.WALLRUN)&&(B(e,i.AIR),e.edge=0)},qe=(e,t)=>{let n=P(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},H=(e,t,n,r)=>{let[i,a]=[n.wx,n.wz];for(let n of E(t,e.x,e.z,x+ke)){let o=t.def.brushes[n],[s,c]=R(o,e.x,e.z),l=P(s,c);if(l>0&&l<=.4+ke&&Le(o,e.y,r)){let e=(-i*s-a*c)/l;e>0&&(i+=e*s/l,a+=e*c/l)}}return[i,a]},Je=(e,t,n)=>{let r=P(t[0],t[1]);if(r<k){let t=P(e.vx,e.vz),n=t?Math.max(0,t-45*O)/t:0;e.vx*=n,e.vz*=n;return}let[i,a]=[t[0]/r,t[1]/r],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a],l=P(s,c);if(l){let e=Math.max(0,l-45*O)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*O):Math.max(n,o-12*O),e.vx=s+o*i,e.vz=c+o*a},Ye=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*O,e.z+=e.vz*O;let[o,s]=Re(e,t,n),c=P(o,s);if(c){let t=(e.vx*o+e.vz*s)/c;t<0&&(e.vx-=t*o/c,e.vz-=t*s/c)}let[l,u]=ze(e,t,n),d=e.vy-r*20*O;if(e.y+=(e.vy+d)/2*O,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+A:e.y<l){if(e.y=l,e.vy<=0){let t=-e.vy;return e.vy=0,t}}else if(i&&e.vy<=0&&l>=a-.5)return e.y=l,e.vy=0,0;return-1},U=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=o.JUMP},Xe=(e,n,r)=>{let[a,o]=F[e.wall],s=t=>{B(e,t),e.edge=0};if(r.keys&(t.BACK|t.CROUCH))s(i.AIR),e.coyote=0;else if(r.jump&&r.fx*a+r.fz*o<0)s(i.AIR),e.vx=-a*4,e.vz=-o*4,U(e,6);else if(r.jump||r.fwd&&e.t>=6)B(e,i.CLIMB);else if(e.t>=30)s(i.AIR),e.coyote=0;else{let t=Math.max(e.edge-2,ze(e,n,S)[0]);e.y+=N(t-e.y,-8*O,8*O)}},Ze=(e,t)=>{let[n,r]=F[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*O):(e.x+=n*he*O,e.z+=r*he*O),e.y>=e.edge&&Ge(e,t)?(B(e,i.GROUND),e.vx=n*3,e.vz=r*3,e.vy=0,e.edge=0,e.wall=a.NONE,e.coyote=6,e.ev|=o.CLIMB):e.t>=40&&(B(e,e.y>=e.edge?i.GROUND:i.AIR),e.edge=0,e.wall=a.NONE)},Qe=(e,t,n)=>{let[r,a]=F[e.wall],s=e.vx*r+e.vz*a,[c,l]=[e.vx-s*r,e.vz-s*a],u=P(c,l);if(n.jump)B(e,i.AIR),e.vx=c-r*5,e.vz=l-a*5,U(e,de),e.jumps=1,e.dashes=1,e.ev|=o.WALLRUN_END;else{let s=Ue(e,t,e.wall);if(s===void 0||!n.fwd||u<3.5||e.t>=60){B(e,i.AIR),e.ev|=o.WALLRUN_END;return}let d=Math.max(0,u-se*O)/u;e.vx=c*d,e.vz=l*d;let f=Math.min(s,4*O);e.x+=r*f,e.z+=a*f}},$e=(e,t,n)=>{if(!n.fwd)return;let r=P(e.vx,e.vz);if(!(r<4.5))for(let n=1;n<=4;n++){let[a,s]=F[n],c=e.vx*a+e.vz*s,[l,u]=[e.vx-c*a,e.vz-c*s];if(n!==e.wall&&c<=.75*r&&c>=-.2*r&&Ue(e,t,n)!==void 0){let t=P(l,u),a=Math.max(t,ue*r)/t;B(e,i.WALLRUN),e.wall=n,[e.vx,e.vz]=[l*a,u*a],e.vy=N(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=o.WALLRUN_START;return}}},et=(e,t)=>{B(e,i.HANG),e.wall=t.side,e.edge=M(t.top),t.side<=a.WEST?e.x=t.hang:e.z=t.hang,e.vx=e.vy=e.vz=0,e.jumps=1,e.dashes=1,e.coyote=0,e.buffer=0,e.ev|=o.GRAB},tt=(e,n,r)=>{let s=e.mode===i.GROUND;if(r.dash&&e.dash===0&&(s||(e.mode===i.AIR||e.mode===i.WALLRUN)&&e.dashes>0)){let[t,n]=r.wx||r.wz?[r.wx,r.wz]:[r.fx,r.fz];s||(e.dashes--,e.vy=0,e.mode===i.WALLRUN&&(B(e,i.AIR),e.ev|=o.WALLRUN_END)),e.vx=t*16,e.vz=n*16,e.dash=60,e.ev|=o.DASH}let c=e.dash>50;e.mode===i.WALLRUN&&Qe(e,n,r),I(e.mode)&&nt(e,n,r,c),e.mode===i.AIR&&rt(e,n,r,c);let l=c&&e.vy<=0?0:e.mode===i.WALLRUN?ce:1,u=e.mode,d=Ye(e,n,L(e),l,I(u));if(d>=0){if(!I(e.mode)){if(e.ev|=o.LAND|(e.mode===i.WALLRUN?o.WALLRUN_END:0),e.fall=d,e.jumps=1,e.dashes=1,e.wall=a.NONE,r.keys&t.CROUCH){let t=P(e.vx,e.vz)>=oe;B(e,t?i.SLIDE:i.CROUCH),e.ev|=t?o.SLIDE_START:0}else B(e,i.GROUND)}e.coyote=6}else I(e.mode)&&(e.ev|=e.mode===i.SLIDE?o.SLIDE_END:0,B(e,i.AIR));if(e.mode===i.AIR){let t=We(e,n);t?et(e,t):$e(e,n,r)}},nt=(e,n,r,a)=>{let s=(r.keys&t.CROUCH)!==0;if(e.buffer>0&&(e.mode===i.GROUND||z(e,n))){e.ev|=e.mode===i.SLIDE?o.SLIDE_END:0,B(e,i.AIR),U(e,7);return}let c=P(e.vx,e.vz);if(e.mode===i.GROUND&&s){let t=c>=oe;B(e,t?i.SLIDE:i.CROUCH),e.ev|=t?o.SLIDE_START:0}else e.mode===i.SLIDE&&(e.t>=60||c<4.5||r.stumble)?(e.ev|=o.SLIDE_END,B(e,!s&&z(e,n)?i.GROUND:i.CROUCH)):e.mode===i.SLIDE&&!s&&z(e,n)?(e.ev|=o.SLIDE_END,B(e,i.GROUND)):e.mode===i.CROUCH&&!s&&z(e,n)&&B(e,i.GROUND);if(!a){if(r.stumble){if(c>2.5){let t=Math.max(ge,c-12*O)/c;e.vx*=t,e.vz*=t}else Je(e,H(e,n,r,L(e)),ge)}else if(e.mode===i.SLIDE){let t=Math.max(0,c-4*O)/c;e.vx*=t,e.vz*=t}else if(e.mode===i.CROUCH)Je(e,H(e,n,r,ie),3);else{let i=(r.keys&t.SPRINT)!==0&&r.fwd;Je(e,H(e,n,r,S),i?9:6)}}},rt=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?U(e,7):e.jumps>0&&!Ke(e,t)&&(e.jumps--,U(e,6),e.ev=e.ev&~o.JUMP|o.DOUBLE)),r||!n.wx&&!n.wz)return;let i=P(e.vx,e.vz);e.vx+=n.wx*14*O,e.vz+=n.wz*14*O,qe(e,Math.max(i,6))},it=(e,n,r,a=0)=>{e.yaw=Ae(n.yaw),e.pitch=Math.max(-re,Math.min(re,n.pitch));let o=(n.keys&t.FORWARD?1:0)-(n.keys&t.BACK?1:0),s=(n.keys&t.RIGHT?1:0)-(n.keys&t.LEFT?1:0),c=P(o,s)||1,[l,u]=j(e.yaw),d=t=>(n.keys&t)!==0&&(e.held&t)===0,f=e.stun>0,p={keys:n.keys,stumble:f,jump:!f&&d(t.JUMP),dash:!f&&d(t.DASH),fwd:o>0,wx:(l*o-u*s)/c,wz:(u*o+l*s)/c,fx:l,fz:u},m=e.mode;e.ev=0,e.fall=0,p.jump&&(e.buffer=7),f&&e.stun--,e.dash>0&&(e.dash--,e.dash===50&&qe(e,10)),e.mode===i.HANG&&Xe(e,r,p),e.mode===i.CLIMB?Ze(e,r):e.mode!==i.HANG&&tt(e,r,p),e.slow&&(e.slow--,qe(e,3)),e.y<r.def.floor&&Pe(e,r,a),e.t=e.mode===m?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===i.AIR&&m===i.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=n.keys&(t.JUMP|t.DASH),e.ground=I(e.mode),e.x=M(e.x),e.y=M(e.y),e.z=M(e.z),e.vx=M(e.vx),e.vy=M(e.vy),e.vz=M(e.vz),e.edge=M(e.edge)},at=.7,ot=e=>{let[r,i]=[e&t.LEFT,e&t.RIGHT];return r&&!i?n.LEFT:i&&!r?n.RIGHT:e&t.FORWARD?n.THRUST:n.SLASH},st=(e,t,n)=>{let{reach:r,arc:i}=C[t.cut??0],[a,o]=j(t.yaw),s=[t.x,t.y+at*L(t),t.z];return n.filter(n=>{let[c,l]=[n.x-t.x,n.z-t.z],u=Math.hypot(c,l);if(u-.4>r||t.y>=n.y+L(n)||n.y>=t.y+L(t))return!1;let d=u>.4?Math.abs(Math.atan2(a*l-o*c,a*c+o*l)):0,f=u>.4?Math.asin(x/u):Math.PI;return d<=i+f&&!De(e,s,[n.x,n.y+at*L(n),n.z])})},ct=(e,t)=>{if(!t.wield||!t.swing||e.lock||t.lock)return!1;let n=C[t.cut??0];if(Math.abs(n.strike-(n.ticks-t.swing))>9)return!1;let[r,i]=[t.x-e.x,t.z-e.z],a=Math.hypot(r,i),o=(e,t,n)=>{let[r,i]=j(e.yaw);return a<1e-6||(r*t+i*n)/a>=Math.cos(.9)};return a-.4<=Math.min(n.reach,C[e.cut??0].reach)&&o(e,r,i)&&o(t,-r,-i)},lt=(e,t)=>{let[r,i]=j(e.yaw),a=e.cut??0;if(a===n.SPIN_L||a===n.SPIN_R){let[n,a]=[t.x-e.x,t.z-e.z],o=Math.hypot(n,a);return o>1e-6?[n/o,a/o]:[r,i]}return a===n.LEFT?[-i,r]:a===n.RIGHT?[i,-r]:[r,i]},ut=(e,t)=>{let[i,a]=j(e.yaw),[o,s]=j(t.yaw),[c,l]=[t.x-e.x,t.z-e.z],u=-a*c+i*l,d=Math.sqrt(Math.max(x*x-u*u,0)),[f,p]=[a*u-i*d,-i*u-a*d],m=-s*f+o*p,h=(e.cut??0)%4;if(h===n.SLASH)return Math.abs(m)<=Se?r.HEAD:m>0?r.ARM_R:r.ARM_L;let g=(e.y+at*L(e)+Math.tan(e.pitch)*Math.hypot(c,l)-t.y)/L(t);if(g>be)return r.HEAD;let _=h===n.THRUST?m>0:(h===n.LEFT?1:-1)*(i*o+a*s)<0;return g<xe?_?r.LEG_R:r.LEG_L:h===n.THRUST&&Math.abs(m)<=Se?r.NONE:_?r.ARM_R:r.ARM_L},W=()=>({state:e.HOME,by:0,x:0,y:0,z:0,left:0}),dt=60,ft=class{score=[0,0];over=!1;flags=[W(),W()];world;rules;mates=/* @__PURE__ */ new Map;clock;back=[0,0];lock=[{id:-1,left:0},{id:-1,left:0}];hold=[0,0];constructor(e,t){this.world=e,this.rules=t,this.clock=t.timeLimit*60}join(e,t,n){this.mates.set(e,{team:t,caps:0,returns:0,ground:[n.x,n.y,n.z]})}leave(e){let t=this.carrying(e),n=this.mates.get(e);t>=0&&n&&this.dropAt(t,n.ground),this.mates.delete(e)}place(e,t){let n=this.mates.get(e);n&&(n.ground=[t.x,t.y,t.z])}moved(e){let t=this.mates.get(e.id);if(!t)return;let n=this.carrying(e.id);e.ev&o.RESPAWN&&n>=0&&this.dropAt(n,t.ground),e.ground&&(t.ground=[e.x,e.y,e.z])}drop(e){let t=this.carrying(e.id),n=this.mates.get(e.id);if(t<0||!n||this.over)return!1;let r=n.ground;if(e.ground)r=[e.x,e.y,e.z];else{let t=D(this.world,[e.x,e.y+.05,e.z],[0,-1,0],dt);t<dt&&(r=[e.x,e.y+.05-t,e.z])}return this.dropAt(t,r),this.lock[t]={id:e.id,left:120},this.hold[t]=120,!0}carrying(t){return this.flags.findIndex(n=>n.state===e.CARRIED&&n.by===t)}winner(){let[e,t]=this.score;return e>t?0:t>e?1:-1}tally(){return[...this.mates].map(([e,t])=>({id:e,caps:t.caps,returns:t.returns}))}reset(){this.over=!1,this.score=[0,0],this.flags=[W(),W()],this.back=[0,0],this.lock.forEach(e=>e.left=0),this.hold=[0,0],this.clock=this.rules.timeLimit*60;for(let e of this.mates.values())e.caps=e.returns=0}wire(){return{score:[...this.score],clock:Math.ceil(this.clock/60),over:this.over,flags:this.flags.map(e=>({...e}))}}tick(t){if(this.over)return--this.clock<=0?(this.reset(),`start`):void 0;for(let t of[0,1]){let n=this.flags[t];this.lock[t].left--,this.hold[t]--,n.state===e.DROPPED&&(n.left=Math.ceil(--this.back[t]/60),this.back[t]<=0&&(this.flags[t]=W()))}for(let n of[0,1]){let r=this.flags[n];if(r.state===e.CARRIED)continue;let i=r.state===e.HOME?this.world.def.teams[n].base:[r.x,r.y,r.z],a=t.filter(e=>pt(e.state,i)),o=r.state===e.DROPPED&&this.hold[n]<=0?a.find(e=>e.team===n):void 0,s=a.find(e=>e.team!==n&&(e.id!==this.lock[n].id||this.lock[n].left<=0));if(o){let e=this.mates.get(o.id);e&&e.returns++,this.flags[n]=W()}else s&&(this.flags[n]={...W(),state:e.CARRIED,by:s.id})}for(let n of t){let t=this.carrying(n.id);if(t>=0&&this.flags[n.team].state===e.HOME&&pt(n.state,this.world.def.teams[n.team].base)){this.score[n.team]++;let e=this.mates.get(n.id);e&&e.caps++,this.flags[t]=W()}}if(this.score.some(e=>e>=this.rules.scoreLimit)||--this.clock<=0)return this.over=!0,this.clock=600,`end`}dropAt(t,[n,r,i]){this.flags[t]={state:e.DROPPED,by:0,x:n,y:r,z:i,left:10},this.back[t]=600}},pt=(e,t)=>Math.hypot(e.x-t[0],e.z-t[2])<1.5&&e.y<t[1]+2.2&&e.y+1.8>t[1],G=(e,t,n)=>{let[r,i]=[e.x-t[0],e.z-t[2]];return r*r+i*i<n*n&&Math.abs(e.y-t[1])<1},mt=e=>{if(e.mode===i.GROUND){if(e.cut===n.LUNGE){let[t,n]=j(e.yaw);e.vx=t*13,e.vz=n*13,e.dash=60,e.ev|=o.DASH}else e.cut===n.LEAP&&(e.vy=ye,e.ev|=o.JUMP)}},K={NONE:0,SHOT:1,CUT:2,RAIL:3},ht=(e,n,r,a,o=!0)=>{let s=e.down>0,c=!s&&(e.lock??0)>0;if(it(e,s||c?{...n,keys:0}:n,r,a),e.zap=!!e.stun&&!!e.zap,s)return e.down>0&&!--e.down&&Pe(e,r,a),K.NONE;if(c)return gt(e,n);let{rack:l,blade:u,rail:d}=r.def.teams[a],f=!!l&&G(e,l,1.2);o&&f&&!e.rack&&(e.ammo=60),e.rack=f,e.blade=!!e.blade||o&&!!u&&G(e,u,1.2);let p=!!d&&G(e,d,1.2);o&&p&&!e.inRail&&(e.rail=10),e.inRail=p,e.cool=Math.max(0,e.cool-1),e.reload=Math.max(0,(e.reload??0)-1),e.swing=Math.max(0,(e.swing??0)-1);let m=[e.ammo>=0,!!e.blade,(e.rail??-1)>=0],h=n.keys&t.BLADE?1:n.keys&t.RAIL?2:0,g=e.swing&&e.blade?1:m[h]?h:m.indexOf(!0);[e.wield,e.railed]=[g==1,g==2];let _=e.mode===i.HANG||e.mode===i.CLIMB;if(!o)return e.charge=0,K.NONE;let v=C[e.cut??0];if(e.swing&&v.ticks-e.swing===v.strike)return K.CUT;if((e.wield||e.railed||_||e.ammo<=0)&&(e.charge=0),n.keys&t.FIRE&&!_){let r=C[e.cut??0].ticks-e.swing,i=!!(n.keys&t.SPECIAL)&&(!e.swing||(e.cut??0)<4&&r<=18);if(e.wield&&(!e.swing||i))e.cut=ot(n.keys)+(i?4:0),e.swing=C[e.cut].ticks,mt(e);else if(e.railed){if(!e.reload&&e.rail>0)return e.rail--,e.shots=e.shots+1&255,e.reload=72,K.RAIL}else!e.wield&&!e.cool&&e.ammo>0&&(e.charge=Math.min((e.charge??0)+1,60))}else if(e.charge)return e.power=Math.min(_t(e.charge),e.ammo),e.charge=0,e.ammo-=e.power,e.shots=e.shots+1&255,e.cool=7,K.SHOT;return K.NONE},gt=(e,n)=>{let r=!!(n.keys&t.FIRE);return e.pushes=(e.pushes??0)+ +(r&&!e.pressed)&255,e.pressed=r,e.away=n.keys&(t.LEFT|t.RIGHT|t.BACK)?Math.min((e.away??0)+1,24):0,e.lock=Math.max(1,e.lock-1),[e.wield,e.swing,e.charge]=[!0,0,0],K.NONE},_t=e=>e<10?1:1+Math.floor(4*(e-10)/50),vt=-30,q=(e,t,n,r,i,a=s.CONCRETE)=>({min:[e,vt,t],max:[n,i,r],top:s.CONCRETE,side:a}),J=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c});[q(4,57.7,24,76,10),q(4,36,24,53.5,10,s.GLASS),q(4,20,24,36,12.4),q(4,-5,24,7,12.4,s.GLASS),q(27,20,47,50,8),q(27,60,47,76,8,s.BRICK),J([9,12.2,39],[19,12.6,47],s.STEEL),...((e,t)=>[1,2,3,4,5,6].map(n=>J([12,t,e-n],[14,t+.4*n,e-n+1],s.CONCRETE)))(53,10),J([5,10,42],[5.5,14,42.5],s.STEEL),J([5,10,50],[5.5,14,50.5],s.STEEL),J([8,12.4,24],[20,12.85,24.45],s.STEEL),J([36,8,22],[37,14.5,48],s.PAINT,s.PAINT,[.15,.72,.62]),J([30,8,28],[34,10,32],s.CONCRETE),J([40,8,30],[44,10.2,34],s.PAINT,s.PAINT,[1,.3,.06]),J([28,9.2,44],[35,12,46],s.STEEL,s.PAINT,[.2,.42,1]),J([41.5,7.6,50],[42,8,60],s.STEEL),J([30,8,64],[34,9.6,68],s.PAINT,s.PAINT,[.2,.8,.3])];var Y=240,X=[1,.22,.26],yt=[.2,.46,1],bt=[1,.42,.08],xt=[.12,.7,.62],Z=(e,t,n,r,i,a,o)=>J([e,t,n],[r,i,a],s.PAINT,s.PAINT,o),St=(e,t,n,r,i,a,o,c=vt)=>{let l=Math.ceil((o-a)/.46);return Array.from({length:l},(u,d)=>{let[f,p]=[t+(n-t)*d/l,t+(n-t)*(d+1)/l].sort((e,t)=>e-t),m=a+(o-a)*(d+1)/l;return e===0?J([f,c,r],[p,m,i],s.CONCRETE):J([r,c,f],[i,m,p],s.CONCRETE)})},Q=(e,t,n,r,i,a,o)=>o.map((o,c)=>J([e+c*n,a,t+c*r],[e+c*n+4,o,t+c*r+i],s.STEEL,s.CONCRETE)),Ct=[q(12,212,52,240,26,s.GLASS),Z(12,26,212,52,26.12,212.5,X),Z(12,26,239.5,52,26.12,240,X),Z(12,26,212.5,12.5,26.12,239.5,X),Z(51.5,26,212.5,52,26.12,239.5,X),Z(11.6,12,222,12,25.8,232,X),Z(28,12,211.4,31,25.5,212,X),J([19,26,222],[22,27.4,225],s.STEEL),J([42,26,222],[45,27.4,225],s.STEEL),J([29,26,229],[35,27.1,229.6],s.CONCRETE),J([27,26,215],[35,27.5,219],s.STEEL,s.PAINT,X),q(6,164,26,201,26,s.GLASS),q(6,134,26,147,26,s.GLASS),q(6,201,26,212,19),q(15,147,26,164,19),J([14,26,164],[15,32,196],s.PAINT,s.PAINT,xt),J([14,18,147],[15,32,164],s.PAINT,s.PAINT,xt),J([14,26,134],[15,32,147],s.PAINT,s.PAINT,xt),...Q(6,201,7,0,4,19,[21.2,23.4,25]),...[[18,152,22,156,21.2],[18,158,22,162,23.4],[23,160,26,164,25]].map(([e,t,n,r,i])=>J([e,19,t],[n,i,r],s.STEEL,s.CONCRETE)),J([20,26,178],[23,27.3,181],s.STEEL),J([8,26,176],[11,27.2,179],s.STEEL),J([8,26,190],[11,27.3,193],s.STEEL),J([20,26,140],[23,27.3,143],s.STEEL),q(32,186,76,209,19),Z(32,19,207.5,76,19.1,209,X),...Q(33,209,7,0,3,19,[21.2,23.4,25]),...[[28,196,32,200,21.2],[28,190,32,194,23.4],[26,184,30,188,25]].map(([e,t,n,r,i])=>J([e,vt,t],[n,i,r],s.STEEL,s.CONCRETE)),q(32,166,64,182,21.2,s.GLASS),q(32,140,64,161,19),J([40,21.2,172],[44,22.6,176],s.STEEL),J([52,19,148],[57,20.3,151],s.STEEL),J([38,19,196],[41,20.4,199],s.STEEL),J([60,19,200],[63,20.4,203],s.STEEL),J([52,19,190],[58,20.6,194],s.STEEL),J([66,19,204],[72,20.2,207],s.STEEL),J([56,21.2,170],[60,22.4,174],s.STEEL),J([34,19,152],[37,20.3,156],s.STEEL),...Q(36,135,18,0,3,15,[17.2,17.2]),...Q(6.5,129,6,0,4,15,[17.2,19.4,21.6,23.8]),q(76,213,100,240,14.5,s.STEEL),Z(76,14.5,238.5,100,14.6,240,X),q(76,185,100,209,14.5),q(76,138,100,181,14.5,s.GLASS),J([80,15.7,158],[96,17.7,162],s.STEEL,s.PAINT,bt),J([82,14.5,234],[85,15.9,237],s.STEEL),J([91,14.5,190],[94,15.9,193],s.STEEL),J([80,14.5,204],[83,15.6,207],s.STEEL),J([78,14.5,170],[81,15.9,173],s.STEEL),J([92,14.5,146],[95,15.7,149],s.STEEL),J([92,14.5,222],[96,15.8,226],s.STEEL),...St(0,76,52,226,232,14.5,26),...St(0,85,76,196,202,14.5,19,14.5)],wt=[q(6,106,62,134,15),q(62,106,100,134,14.5),J([34,15,112],[54,17.2,128],s.CONCRETE),Z(38,17.2,116,50,17.3,124,bt),...[[35,113],[35,126.2],[51,113],[51,126.2]].map(([e,t])=>J([e,17.2,t],[e+.8,21.5,t+.8],s.STEEL)),J([34.6,21.5,112.6],[52.2,21.9,127.4],s.GLASS),J([14,15,114],[17,16.5,117],s.STEEL),J([14,15,123],[17,16.5,126],s.STEEL),J([56,15,114],[59,16.5,117],s.STEEL),J([56,15,123],[59,16.5,126],s.STEEL),J([15.35,25.5,106],[15.85,26,134],s.STEEL),J([70,14.5,108],[70.8,38,108.8],s.STEEL),J([70,14.5,131.2],[70.8,38,132],s.STEEL),J([66,14.5,110],[69,15.9,113],s.STEEL),J([66,14.5,127],[69,15.9,130],s.STEEL)],Tt=e=>({...e,min:[e.min[0],e.min[1],Y-e.max[2]],max:[e.max[0],e.max[1],Y-e.min[2]],tint:e.tint===X?yt:e.tint}),Et=(e,t,n)=>[...[16,22,28,34,40].map(n=>[n,26,t,e]),...[19,31,43].map(t=>[t,26,n,e])],Dt=[[20,26,190],[48,21.2,172],[48,19,200],[88,14.5,198]],Ot=[[21,26,168],[46,19,144],[36,21.2,178],[88,14.5,216],[88,14.5,172]],kt={name:`Highline`,brushes:[...Ct,...Ct.map(Tt),...wt],teams:[{base:[32,26,224],spawns:Et(0,236,231),rack:[30.75,27.5,217],blade:[33.25,27.5,217],rail:[28.25,27.5,217]},{base:[32,26,16],spawns:Et(Math.PI,4,9),rack:[30.75,27.5,23],blade:[33.25,27.5,23],rail:[28.25,27.5,23]}],packs:[...Dt,...Dt.map(([e,t,n])=>[e,t,Y-n]),[24,15,112],[24,15,128]],ammo:[...Ot,...Ot.map(([e,t,n])=>[e,t,Y-n])],floor:-25,sun:{dir:[.8,.6,0],color:[2.6,2.3,1.8]},sky:[[.04,.2,.72],[.72,.86,.98]],fog:[.72,.86,.98,.0035]},At=40/60,jt=(e,t=0)=>{let[n,r,i,a]=[Math.sin(e.yaw),Math.cos(e.yaw),Math.sin(e.pitch),Math.cos(e.pitch)];return{id:e.shots,by:e.id,team:t,x:e.x,y:e.y+Fe(e),z:e.z,dx:-n*a,dy:i,dz:-r*a,left:80,burst:!1,power:e.power??1}},Mt=(e,t,n,r,i)=>{let[a,o]=[e[0]-n.x,e[2]-n.z],s=t[0]*t[0]+t[2]*t[2],c=a*t[0]+o*t[2],l=c*c-s*(a*a+o*o-r*r),[u,d]=[0,1/0];if(s>1e-12){if(l<0)return 1/0;[u,d]=[(-c-Math.sqrt(l))/s,(-c+Math.sqrt(l))/s]}else if(a*a+o*o>r*r)return 1/0;let[f,p]=[n.y-e[1],n.y+i-e[1]];if(t[1])[u,d]=[Math.max(u,Math.min(f/t[1],p/t[1])),Math.min(d,Math.max(f/t[1],p/t[1]))];else if(f>0||p<0)return 1/0;return u<=d&&d>=0?Math.max(u,0):1/0},Nt=(e,t,n,r)=>{let i=[t.x,t.y,t.z],a=[t.dx,t.dy,t.dz],o=Math.min(n,t.left),s=D(e,i,a,o,ve),c;for(let e of r){let t=Mt(i,a,e,x+ve,L(e));t<s&&([s,c]=[t,e])}return t.burst=s<o,t.left-=s,[t.x,t.y,t.z]=[i[0]+a[0]*s,i[1]+a[1]*s,i[2]+a[2]*s],c},Pt=(e,t,n=[])=>{let r=[t.x,t.y+Fe(t),t.z],i=Math.cos(t.pitch),a=[-Math.sin(t.yaw)*i,Math.sin(t.pitch),-Math.cos(t.yaw)*i],o=D(e,r,a,120),s;for(let e of n){let t=Mt(r,a,e,x,L(e));t<o&&([o,s]=[t,e])}return{o:r,d:a,t:o,hit:s}},Ft=e=>e.mode===i.SLIDE||e.dash>50,It=(e,t)=>Math.hypot(e.x-t.x,e.z-t.z)<1.1&&e.y<t.y+L(t)&&t.y<e.y+L(e),Lt=20,Rt=2,zt=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),Bt=e=>zt((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),Vt=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${zt(e,15-`${r}`.length)} ${r}`;return n},Ht=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},$={lock:0,foe:0,pushes:0,pressed:!1,away:0},Ut=({x:e,y:t,z:n,yaw:r})=>({x:e,y:t,z:n,yaw:r}),Wt=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];world;ctf;halt;rules;rr=[0,0];gone;balls=[];constructor(e={},t=kt){this.rules={...Ce,...e},this.world=Ee(t),this.ctf=new ft(this.world,this.rules),this.gone=[...t.packs??[],...t.ammo??[]].map(()=>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=te(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&ee(t);if(r&&n.bank>0){n.bank--;let e=n.state.slow??0,t=ht(n.state,r,this.world,n.info.team,!this.ctf.over);this.ctf.moved(n.state),this.tackle(n,r.view),t===K.SHOT?this.shoot(n,r.view):t===K.CUT?this.cut(n,r.view):t===K.RAIL&&this.rail(n,r.view);let i=n.state.slow??0;e&&i&&!(i%60)&&this.harm(n,1),this.duel(n),n.ack=r.seq}}disconnect(e){let t=this.peers.get(e);this.peers.delete(e),t&&(this.ctf.leave(t.info.id),this.size||(this.ctf.reset(),this.gone.fill(0)),this.roster())}drop(e){let t=this.players().find(t=>t.info.id===e);return!!t&&this.ctf.drop(t.state)}tick(){let e=this.players();if(!e.length){this.balls=[];return}let t=++this.ticks;for(let t of e)t.bank=Math.min(10,t.bank+1);for(let e of this.balls)!e.burst&&e.left>0&&this.fly(e,At);this.heal(e);let n=this.ctf.tick(e.filter(e=>!e.state.down).map(e=>({id:e.info.id,team:e.info.team,state:e.state})));if(n===`end`?this.end(e):n===`start`&&this.restart(e),t%2==0){for(this.history.push({tick:t,players:e.map(e=>({...e.state}))});this.history[0].tick<t-30;)this.history.shift();let n=b({tick:t,players:e.map(e=>({...e.state,ack:e.ack,by:e.state.stun?e.by:0})),...this.ctf.wire(),packs:this.gone.reduce((e,t,n)=>t?e:e|1<<n,0)>>>0,balls:this.balls});e.forEach(e=>e.conn.send(n)),this.balls=this.balls.filter(e=>!e.burst&&e.left>0)}}start(e=Ht){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<Lt;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.info.id!==e).map(e=>e.state),[r,i]=[this.history[0],this.history.at(-1)];if(!r||!i)return n;let a=((this.ticks-t+32768)%65536+65536)%65536-32768,o=Math.min(Math.max(this.ticks-a,r.tick),i.tick),s=0;for(;s+1<this.history.length&&this.history[s+1].tick<=o;)s++;let[c,l]=[this.history[s],this.history[s+1]??this.history[s]],u=l.tick>c.tick?(o-c.tick)/(l.tick-c.tick):0,d=(e,t)=>e+(t-e)*u;return n.map(e=>{let t=c.players.find(t=>t.id===e.id),n=l.players.find(t=>t.id===e.id);return t&&n?{...n,x:d(t.x,n.x),y:d(t.y,n.y),z:d(t.z,n.z)}:n??t??e})}tackle(e,t){let n=e.state;if(n.down||!Ft(n)||this.ticks-e.tackled<30)return;let r=this.players().filter(t=>t.info.team!==e.info.team),i=this.rewind(e.info.id,t).find(e=>It(n,e)&&r.some(t=>t.info.id===e.id&&this.ctf.carrying(t.info.id)>=0)),a=r.find(e=>e.info.id===i?.id);if(!a||!this.drop(a.info.id))return;let o=Ie(n),[s,c]=o>.001?[n.vx/o,n.vz/o]:j(n.yaw);V(a.state,s,c),a.state.zap=!1,a.by=e.info.id,e.tackled=this.ticks}enemies(e,t){let n=this.players();return this.rewind(e.info.id,t).filter(t=>{let r=n.find(e=>e.info.id===t.id);return r&&r.info.team!==e.info.team&&!r.state.down&&!t.down})}harm(e,t){return(e.state.hp-=t)>0?!1:(Object.assign(e.state,{hp:0,down:120,ammo:-1,cool:0,charge:0,blade:!1,wield:!1,swing:0,lost:r.NONE,rail:-1,railed:!1,reload:0,slow:0}),this.ctf.drop(e.state),!0)}shoot(e,t=0){let n=jt(e.state,e.info.team),r=(this.ticks-t+65536)%65536;this.balls.push(n),this.fly(n,Math.min(r<32768?r:0,12)*At);let i=this.balls.filter(e=>!e.burst);i.length>64&&(i[0].burst=!0)}fly(e,t){let n=this.players(),r=n.filter(t=>t.info.team!==e.team&&!t.state.down),i=Nt(this.world,e,t,r.map(e=>e.state)),a=r.find(e=>e.state===i);if(!a)return;let o=n.find(t=>t.info.id===e.by);o&&(o.state.hits=o.state.hits+1&255),this.harm(a,e.power??1)}cut(e,t){let n=st(this.world,e.state,this.enemies(e,t)),r=this.players().filter(e=>n.some(t=>t.id===e.info.id)),i=r.find(t=>ct(e.state,{...t.state,...Ut(n.find(e=>e.id===t.info.id))}));if(i){for(let[t,n]of[[e,i],[i,e]])Object.assign(t.state,{...$,lock:240,foe:n.info.id,pressed:!0}),Object.assign(t.state,{swing:0,charge:0,stun:0,zap:!1,vx:0,vz:0});r=r.filter(e=>e!==i)}if(r.length){e.state.hits=e.state.hits+1&255;for(let t of r){let r=n.find(e=>e.id===t.info.id);if(this.harm(t,C[e.state.cut??0].hp))t.state.lost=ut(e.state,r);else{let[n,i]=lt(e.state,r);V(t.state,n,i,24,4),t.state.zap=!0,t.by=e.info.id}}}}rail(e,t){let{hit:n}=Pt(this.world,e.state,this.enemies(e,t)),r=this.players().find(e=>e.info.id===n?.id);r&&(e.state.hits=e.state.hits+1&255,r.state.slow=180,this.harm(r,1))}duel(e){let t=e.state;if(!t.lock)return;let n=this.players().find(e=>e.info.id===t.foe);if(!n||n.state.foe!==e.info.id||!n.state.lock||n.state.down||t.down){Object.assign(t,$);return}let r=(t.pushes??0)-(n.state.pushes??0),i=(t.away??0)>=24||(n.state.away??0)>=24;if(!(Math.abs(r)<8&&!i&&t.lock>1)){if(Object.assign(t,$),Object.assign(n.state,$),Math.abs(r)>=8){let[t,i]=r>0?[e,n]:[n,e];if(t.state.hits=t.state.hits+1&255,!this.harm(i,3)){let[e,n]=j(t.state.yaw);V(i.state,e,n,24,4),i.state.zap=!0,i.by=t.info.id}}else if(!i){let[e,r]=[n.state.x-t.x,n.state.z-t.z],i=Math.hypot(e,r)||1;V(t,-e/i,-r/i),V(n.state,e/i,r/i)}}}heal(e){let{packs:t=[],ammo:n=[]}=this.world.def;[...t,...n].forEach((n,r)=>{if(this.gone[r]>0){this.gone[r]--;return}let i=r<t.length,a=e.find(({state:e})=>!e.down&&(i?e.hp<5:e.ammo>=0&&e.ammo<60)&&G(e,n,.9));if(a){let e=a.state;i?e.hp=Math.min(5,e.hp+2):e.ammo=Math.min(60,e.ammo+20),this.gone[r]=1200}})}place(e,t,n){let r=this.world.def.teams[t].spawns.findIndex((r,i)=>{let{x:a,z:o}=Ne(e,this.world,i,t);return!n.some(e=>Math.hypot(e.x-a,e.z-o)<Rt)});return Ne(e,this.world,r<0?this.rr[t]++:r,t)}end(e){let t=this.ctf.tally().flatMap(t=>{let n=e.find(e=>e.info.id===t.id)?.info;return n?[{...t,name:n.name,team:n.team}]:[]}),n=JSON.stringify({t:`end`,score:this.ctf.score,players:t});e.forEach(e=>e.conn.send(n))}restart(e){let t=[];this.rr=[0,0],this.gone.fill(0);for(let n of e){let{shots:e,hits:r}=n.state;n.state={...this.place(n.info.id,n.info.team,t),shots:e,hits:r},t.push(n.state),this.ctf.place(n.info.id,n.state)}}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=n.filter(e=>e.info.team===0).length,a=+(i>n.length-i),o={conn:e,info:{id:r,name:Vt(Bt(t)||`Player ${r}`,n.map(e=>e.info.name)),team:a,color:_e[a]},state:this.place(r,a,n.map(e=>e.state)),bank:10,ack:65535,by:0,tackled:-30};this.peers.set(e,o),this.ctf.join(r,a,o.state),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})))}},Gt=(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()},Kt=(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,c,l,u,d=[],f,p=!1,m=e=>i.postMessage({from:r,...e}),h=e=>!p&&b.onmessage?.({data:e}),g={send:e=>queueMicrotask(()=>h(e))},_=()=>{let e=d.length?d:f?[f]:[];return d=[],e},v=e=>{if(p)return e();l=e,u=r,c=/* @__PURE__ */ new Map,s=new Wt(t),s.start(Gt),s.connect(g),_().forEach(e=>s.receive(g,e)),m({kind:`h`})};i.onmessage=({data:e})=>{if(!p){if(s&&c){let{from:t,kind:n}=e,r=c.get(t);n===`q`?m({to:t,kind:`h`}):n===`m`&&!e.to?(r||(r={send:e=>!p&&m({to:t,kind:`m`,data:e})},c.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(c.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?h(e.data):e.kind===`h`&&e.from!==u&&(u=e.from,_().forEach(e=>m({kind:`m`,data:e}))))}};let ee=e=>{p||(typeof e==`string`&&te(e)?.t===`join`&&(f=e),s?s.receive(g,e):u?m({kind:`m`,data:e}):d.push(e))},y=()=>{p||(p=!0,globalThis.removeEventListener?.(`pagehide`,y),s?(s.stop(),l()):(m({kind:`b`}),a.abort()),i.close(),setTimeout(()=>b.onclose?.()))},b={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:ee,close:y};return o?o.request(n,{signal:a.signal},()=>new Promise(v)).catch(()=>{}):v(()=>{}),m({kind:`q`}),globalThis.addEventListener?.(`pagehide`,y),setTimeout(()=>!p&&b.onopen?.()),b};export{Kt as localSocket};
package/dist/server.js CHANGED
@@ -156,7 +156,12 @@ var KEY = {
156
156
  * Set with FIRE by a double click (the client's choice): the katana's special cut, the special
157
157
  * of the cut the keys give (see CUT). Ignored without the katana in hand.
158
158
  */
159
- SPECIAL: 1024
159
+ SPECIAL: 1024,
160
+ /**
161
+ * Set while the player wants the rail gun in hand (the client's choice: 3 or the wheel), with
162
+ * KEY.BLADE clear. Ignored without the rail gun.
163
+ */
164
+ RAIL: 2048
160
165
  };
161
166
  /**
162
167
  * The katana's cuts (PlayerState.cut, constants CUTS), chosen by the keys held when FIRE starts
@@ -1047,6 +1052,10 @@ var move = (p, i, w, team = 0) => {
1047
1052
  if (p.mode === MODE.HANG) hang(p, w, c);
1048
1053
  if (p.mode === MODE.CLIMB) climb(p, w);
1049
1054
  else if (p.mode !== MODE.HANG) free(p, w, c);
1055
+ if (p.slow) {
1056
+ p.slow--;
1057
+ cap(p, 3);
1058
+ }
1050
1059
  if (p.y < w.def.floor) respawn(p, w, team);
1051
1060
  p.t = p.mode === before ? Math.min(255, p.t + 1) : p.t;
1052
1061
  p.buffer = Math.max(0, p.buffer - 1);
@@ -1414,11 +1423,12 @@ var launch$1 = (p) => {
1414
1423
  p.ev |= EV.JUMP;
1415
1424
  }
1416
1425
  };
1417
- /** What a step struck, for the host to resolve: nothing, a shot (a plasma ball), or the katana's cut. */
1426
+ /** What a step struck, for the host to resolve: nothing, a shot (a plasma ball), the katana's cut, or a rail gun's beam. */
1418
1427
  var STRIKE = {
1419
1428
  NONE: 0,
1420
1429
  SHOT: 1,
1421
- CUT: 2
1430
+ CUT: 2,
1431
+ RAIL: 3
1422
1432
  };
1423
1433
  /**
1424
1434
  * One input: the move, then the weapons. Returns what struck on this step (STRIKE), for the host to
@@ -1427,8 +1437,11 @@ var STRIKE = {
1427
1437
  * - The team's rack fills the gun when the player steps into its circle (`rack` tells he is in it),
1428
1438
  * and again each time he comes back; staying gives nothing. The katana rack gives the katana,
1429
1439
  * once and for good: it stays until he goes down.
1430
- * - In hand (`wield`) is the katana when he has it and wants it (KEY.BLADE) or has no gun, and
1431
- * it stays in hand for the length of a swing.
1440
+ * - The rail rack fills the rail gun with RAIL_MAX shots on arrival, as the gun's does.
1441
+ * - In hand is the weapon he wants (KEY.BLADE the katana, KEY.RAIL the rail gun, neither the gun)
1442
+ * when he has it, else the first he has of the gun, the katana and the rail gun; the katana
1443
+ * stays in hand for the length of a swing. `wield` is the katana in hand, `railed` the rail gun.
1444
+ * - The rail gun fires a beam every RAIL_COOLDOWN ticks while FIRE is held, with a shot left.
1432
1445
  * - The trigger: `cool` and `swing` run down, and at 0 a held FIRE charges the gun, with ammo, and
1433
1446
  * letting it go fires a ball as strong as the charge (powerOf()), spending as many shots; or it
1434
1447
  * starts the katana's swing (`cut` from the keys), unless the hands are busy (a hang, a climb).
@@ -1451,14 +1464,25 @@ var step = (p, i, w, team, armed = true) => {
1451
1464
  return STRIKE.NONE;
1452
1465
  }
1453
1466
  if (locked) return duel(p, i);
1454
- const { rack, blade } = w.def.teams[team];
1467
+ const { rack, blade, rail } = w.def.teams[team];
1455
1468
  const inside = !!rack && within(p, rack, 1.2);
1456
1469
  if (armed && inside && !p.rack) p.ammo = 60;
1457
1470
  p.rack = inside;
1458
1471
  p.blade = !!p.blade || armed && !!blade && within(p, blade, 1.2);
1472
+ const inRail = !!rail && within(p, rail, 1.2);
1473
+ if (armed && inRail && !p.inRail) p.rail = 10;
1474
+ p.inRail = inRail;
1459
1475
  p.cool = Math.max(0, p.cool - 1);
1476
+ p.reload = Math.max(0, (p.reload ?? 0) - 1);
1460
1477
  p.swing = Math.max(0, (p.swing ?? 0) - 1);
1461
- p.wield = p.blade && (p.swing > 0 || !!(i.keys & KEY.BLADE) || p.ammo < 0);
1478
+ const has = [
1479
+ p.ammo >= 0,
1480
+ !!p.blade,
1481
+ (p.rail ?? -1) >= 0
1482
+ ];
1483
+ const want = i.keys & KEY.BLADE ? 1 : i.keys & KEY.RAIL ? 2 : 0;
1484
+ const hand = p.swing && p.blade ? 1 : has[want] ? want : has.indexOf(true);
1485
+ [p.wield, p.railed] = [hand == 1, hand == 2];
1462
1486
  const busy = p.mode === MODE.HANG || p.mode === MODE.CLIMB;
1463
1487
  if (!armed) {
1464
1488
  p.charge = 0;
@@ -1466,7 +1490,7 @@ var step = (p, i, w, team, armed = true) => {
1466
1490
  }
1467
1491
  const c = CUTS[p.cut ?? 0];
1468
1492
  if (p.swing && c.ticks - p.swing === c.strike) return STRIKE.CUT;
1469
- if (p.wield || busy || p.ammo <= 0) p.charge = 0;
1493
+ if (p.wield || p.railed || busy || p.ammo <= 0) p.charge = 0;
1470
1494
  if (i.keys & KEY.FIRE && !busy) {
1471
1495
  const late = CUTS[p.cut ?? 0].ticks - p.swing;
1472
1496
  const special = !!(i.keys & KEY.SPECIAL) && (!p.swing || (p.cut ?? 0) < 4 && late <= 18);
@@ -1474,6 +1498,13 @@ var step = (p, i, w, team, armed = true) => {
1474
1498
  p.cut = cutOf(i.keys) + (special ? 4 : 0);
1475
1499
  p.swing = CUTS[p.cut].ticks;
1476
1500
  launch$1(p);
1501
+ } else if (p.railed) {
1502
+ if (!p.reload && p.rail > 0) {
1503
+ p.rail--;
1504
+ p.shots = p.shots + 1 & 255;
1505
+ p.reload = 72;
1506
+ return STRIKE.RAIL;
1507
+ }
1477
1508
  } else if (!p.wield && !p.cool && p.ammo > 0) p.charge = Math.min((p.charge ?? 0) + 1, 60);
1478
1509
  } else if (p.charge) {
1479
1510
  p.power = Math.min(powerOf(p.charge), p.ammo);
@@ -1782,7 +1813,7 @@ var half = [
1782
1813
  229.6
1783
1814
  ], TEX.CONCRETE),
1784
1815
  box([
1785
- 29,
1816
+ 27,
1786
1817
  26,
1787
1818
  215
1788
1819
  ], [
@@ -2316,6 +2347,11 @@ var HIGHLINE = {
2316
2347
  33.25,
2317
2348
  27.5,
2318
2349
  217
2350
+ ],
2351
+ rail: [
2352
+ 28.25,
2353
+ 27.5,
2354
+ 217
2319
2355
  ]
2320
2356
  }, {
2321
2357
  base: [
@@ -2333,6 +2369,11 @@ var HIGHLINE = {
2333
2369
  33.25,
2334
2370
  27.5,
2335
2371
  23
2372
+ ],
2373
+ rail: [
2374
+ 28.25,
2375
+ 27.5,
2376
+ 23
2336
2377
  ]
2337
2378
  }],
2338
2379
  packs: [
@@ -2491,7 +2532,7 @@ var decodeInput = (buf) => {
2491
2532
  if (v.getUint8(0) !== 1) return null;
2492
2533
  return {
2493
2534
  seq: v.getUint16(1),
2494
- keys: v.getUint16(3) & 2047,
2535
+ keys: v.getUint16(3) & 4095,
2495
2536
  yaw: fromTurn(v.getUint16(5)),
2496
2537
  pitch: fromPitch(v.getInt16(7)),
2497
2538
  view: (v.getUint16(9) * 256 + v.getUint8(11)) / 256
@@ -2500,7 +2541,7 @@ var decodeInput = (buf) => {
2500
2541
  /** Bytes of a flag on the wire, by its state. */
2501
2542
  var flagBytes = (state) => state === FLAG.CARRIED ? 2 : state === FLAG.DROPPED ? 8 : 1;
2502
2543
  var encodeSnapshot = (s) => {
2503
- const end = 4 + 52 * s.players.length;
2544
+ const end = 4 + 55 * s.players.length;
2504
2545
  const balls = s.balls ?? [];
2505
2546
  const tail = end + 8 + s.flags.reduce((n, f) => n + flagBytes(f.state), 0);
2506
2547
  const v = new DataView(new ArrayBuffer(tail + (balls.length && 1 + 11 * balls.length)));
@@ -2508,7 +2549,7 @@ var encodeSnapshot = (s) => {
2508
2549
  v.setUint16(1, s.tick & 65535);
2509
2550
  v.setUint8(3, s.players.length);
2510
2551
  s.players.forEach((p, i) => {
2511
- const o = 4 + i * 52;
2552
+ const o = 4 + i * 55;
2512
2553
  v.setUint8(o, p.id);
2513
2554
  v.setFloat32(o + 1, p.x);
2514
2555
  v.setFloat32(o + 5, p.y);
@@ -2537,6 +2578,9 @@ var encodeSnapshot = (s) => {
2537
2578
  v.setUint8(o + 49, (p.foe ?? 0) & 15 | (p.pressed ? 128 : 0));
2538
2579
  v.setUint8(o + 50, p.pushes ?? 0);
2539
2580
  v.setUint8(o + 51, p.away ?? 0);
2581
+ v.setUint8(o + 52, (p.rail ?? -1) + 1 | (p.railed ? 32 : 0) | (p.inRail ? 64 : 0));
2582
+ v.setUint8(o + 53, p.reload ?? 0);
2583
+ v.setUint8(o + 54, p.slow ?? 0);
2540
2584
  });
2541
2585
  v.setUint8(end, s.score[0]);
2542
2586
  v.setUint8(end + 1, s.score[1]);
@@ -2579,6 +2623,36 @@ var parseText = (raw) => {
2579
2623
  return null;
2580
2624
  }
2581
2625
  };
2626
+ // src/shared/rail.ts
2627
+ /**
2628
+ * The beam `p` fires along his look: where it starts (his eye), its unit direction, how far it goes
2629
+ * (to the first brush, or RAIL_RANGE) and the first of `foes` whose body it enters before that.
2630
+ */
2631
+ var beam = (w, p, foes = []) => {
2632
+ const o = [
2633
+ p.x,
2634
+ p.y + eyeHeight(p),
2635
+ p.z
2636
+ ];
2637
+ const cp = Math.cos(p.pitch);
2638
+ const d = [
2639
+ -Math.sin(p.yaw) * cp,
2640
+ Math.sin(p.pitch),
2641
+ -Math.cos(p.yaw) * cp
2642
+ ];
2643
+ let t = ray(w, o, d, 120);
2644
+ let hit;
2645
+ for (const f of foes) {
2646
+ const u = cylinder(o, d, f, PLAYER_R, heightOf(f));
2647
+ if (u < t) [t, hit] = [u, f];
2648
+ }
2649
+ return {
2650
+ o,
2651
+ d,
2652
+ t,
2653
+ hit
2654
+ };
2655
+ };
2582
2656
  // src/shared/tackle.ts
2583
2657
  /** Whether the player's body is a weapon: in a slide, or in the burst of a dash. */
2584
2658
  var tackling = (p) => p.mode === MODE.SLIDE || p.dash > 50;
@@ -2682,11 +2756,15 @@ var Room = class {
2682
2756
  const input = p && decodeInput(data);
2683
2757
  if (input && p.bank > 0) {
2684
2758
  p.bank--;
2759
+ const slow = p.state.slow ?? 0;
2685
2760
  const struck = step(p.state, input, this.world, p.info.team, !this.ctf.over);
2686
2761
  this.ctf.moved(p.state);
2687
2762
  this.tackle(p, input.view);
2688
2763
  if (struck === STRIKE.SHOT) this.shoot(p, input.view);
2689
2764
  else if (struck === STRIKE.CUT) this.cut(p, input.view);
2765
+ else if (struck === STRIKE.RAIL) this.rail(p, input.view);
2766
+ const left = p.state.slow ?? 0;
2767
+ if (slow && left && !(left % 60)) this.harm(p, 1);
2690
2768
  this.duel(p);
2691
2769
  p.ack = input.seq;
2692
2770
  }
@@ -2853,7 +2931,11 @@ var Room = class {
2853
2931
  blade: false,
2854
2932
  wield: false,
2855
2933
  swing: 0,
2856
- lost: LIMB.NONE
2934
+ lost: LIMB.NONE,
2935
+ rail: -1,
2936
+ railed: false,
2937
+ reload: 0,
2938
+ slow: 0
2857
2939
  });
2858
2940
  this.ctf.drop(foe.state);
2859
2941
  return true;
@@ -2929,6 +3011,19 @@ var Room = class {
2929
3011
  }
2930
3012
  }
2931
3013
  /**
3014
+ * A rail beam of `p` went off at the view tick `view`: the first enemy it enters as `p` drew him
3015
+ * takes 1 hp and is drained (`slow`, RAIL_TICKS), and the `hits` count goes up.
3016
+ */
3017
+ rail(p, view) {
3018
+ const { hit } = beam(this.world, p.state, this.enemies(p, view));
3019
+ const foe = this.players().find((q) => q.info.id === hit?.id);
3020
+ if (foe) {
3021
+ p.state.hits = p.state.hits + 1 & 255;
3022
+ foe.state.slow = 180;
3023
+ this.harm(foe, 1);
3024
+ }
3025
+ }
3026
+ /**
2932
3027
  * A saber lock of `p`, after his input: it ends when a side leads by LOCK_WIN presses (the other
2933
3028
  * takes LOCK_HP and the katana's shock, thrown along the winner's look), when one has stepped out
2934
3029
  * (LOCK_BREAK ticks of a side or back key: both are free), or when it has run its LOCK_TICKS (both
@@ -11,6 +11,8 @@ export interface Orb {
11
11
  /** Seconds a muzzle flash, a splash and a spark last. */
12
12
  export declare const FLASH = 0.06;
13
13
  export declare const SPLASH = 0.16;
14
+ /** Seconds a rail beam fades over, rail beams kept at most, and the metres of one turn of its spiral. */
15
+ export declare const RAIL_FADE = 0.7;
14
16
  export interface Tracer {
15
17
  /** A shot's flash at the muzzle `a`; `own` for the player's, which stays on its muzzle; `hot` how charged it was, 0 to 1. */
16
18
  flash(a: Vec3, own?: boolean, hot?: number): void;
@@ -19,6 +21,8 @@ export interface Tracer {
19
21
  p: Vec3;
20
22
  k: number;
21
23
  }[]): void;
24
+ /** A rail beam from `a` to `b`: a green core in a spiral that widens as it fades, sparks where it ends. */
25
+ rail(a: Vec3, b: Vec3): void;
22
26
  /** A ball burst at `at`: a splash of light and a spray of sparks. */
23
27
  burst(at: Vec3): void;
24
28
  /** The balls to draw this frame. */
@@ -44,7 +44,7 @@ type Blade = Pick<PlayerState, 'swing' | 'cut' | 'wield' | 'blade'>;
44
44
  export declare const swung: (a?: Blade, b?: Blade) => number;
45
45
  /** Whether the step from a to b is the strike of its cut: `swing` went down through the strike tick (CUTS). */
46
46
  export declare const struck: (a?: Blade, b?: Blade) => boolean;
47
- export declare const createCombat: (world: World, audio: Pick<Audio, "play">, hud: Pick<Hud, "vitals" | "hit" | "down">, fx: Pick<Effects, "fire" | "cut" | "wound" | "lie">, tracer: Pick<Tracer, "flash" | "burst" | "orbs" | "update" | "mount" | "crackle" | "charging">, ctl: {
47
+ export declare const createCombat: (world: World, audio: Pick<Audio, "play">, hud: Pick<Hud, "vitals" | "hit" | "down">, fx: Pick<Effects, "fire" | "cut" | "wound" | "lie">, tracer: Pick<Tracer, "flash" | "burst" | "orbs" | "update" | "mount" | "crackle" | "charging" | "rail">, ctl: {
48
48
  pitch: number;
49
49
  }, balls: Pick<Balls, "fire" | "frame">) => Combat;
50
50
  export {};
@@ -29,6 +29,8 @@ export interface CtfScene {
29
29
  racks?: readonly (Vec3 | undefined)[];
30
30
  /** Each team's katana rack, where it has one. */
31
31
  blades?: readonly (Vec3 | undefined)[];
32
+ /** Each team's rail gun rack, where it has one. */
33
+ rails?: readonly (Vec3 | undefined)[];
32
34
  packs?: readonly Vec3[];
33
35
  /** The ammo packs that are there to take. */
34
36
  ammo?: readonly Vec3[];
@@ -17,23 +17,32 @@ export declare const TILT: number[];
17
17
  * sides.
18
18
  */
19
19
  export declare const gun: (lod: number) => number[];
20
+ /** The rail gun's muzzle: on the gun's long axis (REAR to MUZZLE), 25 cm further out. */
21
+ export declare const RAIL_MUZZLE: Vec3;
22
+ /**
23
+ * The rail gun at a level of detail (0 far, 1 near), built once like gun(): a long gunmetal
24
+ * receiver over the same grip, two flat rails running out in front of it above and below a glowing
25
+ * green core, four coils round the core between them, and a green strip down each side.
26
+ */
27
+ export declare const railgun: (lod: number) => number[];
20
28
  /** The middle of the grip, for a wrist at `pos`: 8 cm along the fingers and 2 cm toward the palm. */
21
29
  export declare const grip: (pos: Vec3, q: Quat) => Vec3;
22
30
  /**
23
31
  * The ammo as two glowing seven-segment digits on a dark screen set in the back of a small block
24
- * on top of the body, in model space: cyan, red at 10 or fewer, thick segments that bloom only a
32
+ * on top of the body, in model space: cyan, red at `low` or fewer, thick segments that bloom only a
25
33
  * little. The block is part of the readout, so only a gun that shows the ammo carries it. 99 at most.
26
34
  * While the gun charges, a gauge of CHARGE_MAX cells under the digits lights `level` of them, the
27
35
  * strength the shot would have; all orange at the full charge.
28
36
  */
29
- export declare const readout: (ammo: number, level?: number) => number[];
37
+ export declare const readout: (ammo: number, level?: number, low?: number) => number[];
30
38
  /**
31
- * Appends the gun held in the hand at `pos` with the world rotation `q`, `k` times its size about
32
- * the grip, with the ammo on its back when given, and the charge gauge at `level`.
39
+ * Appends the gun (the rail gun when `rail`) held in the hand at `pos` with the world rotation `q`,
40
+ * `k` times its size about the grip, with the ammo on its back when given, and the charge gauge at
41
+ * `level`.
33
42
  */
34
- export declare const held: (out: number[], pos: Vec3, q: Quat, lod: number, k?: number, ammo?: number, level?: number) => void;
35
- /** The muzzle of a gun whose grip is at `at` and whose axes are [right, up, forward]. */
36
- export declare const tip: (at: Vec3, [, u, f]: Vec3[]) => Vec3;
43
+ export declare const held: (out: number[], pos: Vec3, q: Quat, lod: number, k?: number, ammo?: number, level?: number, rail?: boolean) => void;
44
+ /** The muzzle of a gun (the rail gun's when `rail`) whose grip is at `at` and whose axes are [right, up, forward]. */
45
+ export declare const tip: (at: Vec3, [, u, f]: Vec3[], rail?: boolean) => Vec3;
37
46
  /**
38
47
  * The axes [right, up, forward] of a gun held with its grip at `at` so that its long axis, from the
39
48
  * back of the body to the emitter, points at `to`: the beam leaves the emitter along it. `side` is
@@ -23,10 +23,12 @@ export interface Hud {
23
23
  hurt(level: number): void;
24
24
  /**
25
25
  * The health as pips out of HP_MAX, and the weapon in hand: the ammo counter with the gun glyph,
26
- * or the katana glyph when `wield` (or when it is all there is). -1 ammo is no gun, `blade` is a
27
- * katana carried; both carried show the slots (1 gun, 2 katana) over the glyph, none hides it.
26
+ * the katana glyph when `wield` (or when it is all there is), or the rail gun's shots with the
27
+ * gun glyph in green when `railed`. -1 ammo is no gun, `blade` is a katana carried, `rail` the
28
+ * rail gun's shots (-1 none); two or more carried show their slots (1 gun, 2 katana, 3 rail gun)
29
+ * over the glyph, none hides it.
28
30
  */
29
- vitals(hp: number, ammo: number, blade?: boolean, wield?: boolean): void;
31
+ vitals(hp: number, ammo: number, blade?: boolean, wield?: boolean, rail?: number, railed?: boolean): void;
30
32
  /** A hit marker on the crosshair for a moment: a ball or a cut of the own player hit. */
31
33
  hit(): void;
32
34
  /**
@@ -9,15 +9,26 @@ export declare const keyBit: (code: string) => number;
9
9
  export declare const DOUBLE_CLICK_MS = 300;
10
10
  /** The wheel swaps the weapon at most this often (ms): a trackpad's flick is a hundred events, one swap. */
11
11
  export declare const WHEEL_MS = 250;
12
- /** Whether the katana is the choice after a key: 1 the gun, 2 the katana, any other key keeps it. */
13
- export declare const picked: (blade: boolean, code: string) => boolean;
12
+ /** The weapon chosen: 1, 2 and 3 on the keyboard. */
13
+ export declare const WEAPON: {
14
+ readonly GUN: 0;
15
+ readonly BLADE: 1;
16
+ readonly RAIL: 2;
17
+ };
18
+ /** The choice after a key: 1 the gun, 2 the katana, 3 the rail gun, any other key keeps it. */
19
+ export declare const picked: (weapon: number, code: string) => number;
20
+ /** Which of the gun, the katana and the rail gun a player has; all of them when there is no state yet. */
21
+ export declare const owned: (p?: PlayerState) => boolean[];
14
22
  /**
15
- * The choice after a step of the own player. Picking the katana up switches to it, once; losing
16
- * both weapons (going down) goes back to the gun; anything else, the gun picked up included, keeps it.
23
+ * The choice after a step of the own player. Picking the katana or the rail gun up switches to
24
+ * it, once; losing every weapon (going down) goes back to the gun; anything else, the gun picked
25
+ * up included, keeps it.
17
26
  */
18
- export declare const chosen: (blade: boolean, was?: PlayerState, now?: PlayerState) => boolean;
19
- /** The keys of a step with KEY.BLADE set while the katana is the choice. */
20
- export declare const withBlade: (keys: number, blade: boolean) => number;
27
+ export declare const chosen: (weapon: number, was?: PlayerState, now?: PlayerState) => number;
28
+ /** The keys of a step with KEY.BLADE set while the katana is the choice, KEY.RAIL while the rail gun is. */
29
+ export declare const withWeapon: (keys: number, weapon: number) => number;
30
+ /** The choice the wheel turns to, `dir` 1 or -1: the next weapon he has, round the three. */
31
+ export declare const turned: (weapon: number, dir: number, have: boolean[]) => number;
21
32
  /** Live look angles and held keys; the loop reads them once per step and per frame. */
22
33
  export interface Controls {
23
34
  /** Radians, [0, 2π). Mouse right turns right, which lowers yaw. */
@@ -26,16 +37,16 @@ export interface Controls {
26
37
  pitch: number;
27
38
  /** KEY bits held now. */
28
39
  keys: number;
29
- /** The katana is the chosen weapon (1, 2 and the wheel), the gun otherwise. */
30
- blade: boolean;
40
+ /** The chosen weapon (WEAPON: 1, 2, 3 and the wheel). */
41
+ weapon: number;
31
42
  /**
32
43
  * The KEY bits of the next step, read once per step. Same as `keys`, plus BLADE while the katana
33
- * is chosen, except for the step right after a double tap: it carries DASH and only the tapped
44
+ * is chosen and RAIL while the rail gun is, except for the step right after a double tap: it carries DASH and only the tapped
34
45
  * direction, so the dash goes that way whatever else is held, and nothing else is on the wire.
35
46
  * The step after a double click carries FIRE and SPECIAL, however short the click was.
36
47
  */
37
48
  take(): number;
38
- /** One live step of the own player, its state before and after: a katana picked up is chosen, losing both weapons chooses the gun. */
49
+ /** One live step of the own player, its state before and after: a katana or a rail gun picked up is chosen, losing every weapon chooses the gun. */
39
50
  track(was?: PlayerState, now?: PlayerState): void;
40
51
  /** The canvas holds the pointer lock. */
41
52
  locked(): boolean;
@@ -45,7 +56,7 @@ export interface Controls {
45
56
  /**
46
57
  * Click the canvas to lock the pointer; while locked the mouse looks, the keys move (WASD, Shift
47
58
  * sprints, Space jumps, C crouches, a direction key pressed twice within DOUBLE_TAP_MS dashes that
48
- * way, the left button fires or cuts and a double click cuts the special, 1 and 2 or the wheel pick
49
- * the gun or the katana) and M calls `onMute`.
59
+ * way, the left button fires or cuts and a double click cuts the special, 1, 2 and 3 or the wheel pick
60
+ * the gun, the katana or the rail gun) and M calls `onMute`.
50
61
  */
51
62
  export declare const createInput: (canvas: HTMLCanvasElement, onMute?: () => void) => Controls;
@@ -4,10 +4,14 @@ import type { Vec3 } from './mesh';
4
4
  * count from `from`: the ammo packs come after the health packs.
5
5
  */
6
6
  export declare const packsOf: (all?: readonly Vec3[], mask?: number, from?: number) => Vec3[];
7
- /** A rack at `at` (a point on a top): a post and a dish, a ring on the roof of the radius that gives the gun, the gun over it, or with `blade` the katana, crackling. */
8
- export declare const rack: (out: number[], at: Vec3, rgb: number[], t: number, blade?: boolean) => void;
9
- /** Each team's gun rack and katana rack, where it has them. */
10
- export declare const racks: (out: number[], guns?: readonly (Vec3 | undefined)[], blades?: readonly (Vec3 | undefined)[], t?: number) => void;
7
+ /**
8
+ * A rack at `at` (a point on a top): a post and a dish, a ring on the roof of the radius that gives
9
+ * the weapon, and the weapon over it: the gun, or by `kind` the katana (1), crackling, or the rail
10
+ * gun (2).
11
+ */
12
+ export declare const rack: (out: number[], at: Vec3, rgb: number[], t: number, kind?: number) => void;
13
+ /** Each team's gun rack, katana rack and rail gun rack, where it has them. */
14
+ export declare const racks: (out: number[], guns?: readonly (Vec3 | undefined)[], blades?: readonly (Vec3 | undefined)[], t?: number, rails?: readonly (Vec3 | undefined)[]) => void;
11
15
  /** A health pack at `at`: a white box with a glowing green cross on each side. */
12
16
  export declare const kit: (out: number[], at: Vec3, t: number) => void;
13
17
  /** An ammo pack at `at`: a violet box with a glowing cyan cartridge on each side, the gun's colours. */
@@ -56,6 +56,8 @@ export declare const SOUND: {
56
56
  readonly SPLASH: 26;
57
57
  /** A charged shot, under the plain one: a long deep blast. */
58
58
  readonly BLAST: 27;
59
+ /** A rail gun's beam. */
60
+ readonly RAIL: 28;
59
61
  };
60
62
  /**
61
63
  * The sounds of the game: one entry per sound, its voices layered, in SOUND order. A low-passed
@@ -15,6 +15,8 @@ export interface Skin {
15
15
  /** Three vertex indices per triangle, and the palette colour of each of its corners: the colour blends across it. */
16
16
  t: Uint16Array;
17
17
  c: Uint8Array;
18
+ /** Per vertex the light it gets, 1 in the open and less in another part's shadow. */
19
+ o: Float32Array;
18
20
  /** Per triangle the LIMB it comes off with, NONE for the trunk's. */
19
21
  l?: Uint8Array;
20
22
  }