@korial29/tiny-fps 0.31.0 → 0.33.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/index.js +14 -14
- package/dist/local.js +1 -1
- package/dist/server.js +77 -20
- package/dist/types/client/beams.d.ts +2 -0
- package/dist/types/client/katana.d.ts +9 -6
- package/dist/types/client/limbs.d.ts +50 -0
- package/dist/types/client/sfx.d.ts +8 -3
- package/dist/types/client/skin.d.ts +8 -1
- package/dist/types/client/soldier.d.ts +13 -2
- package/dist/types/shared/blade.d.ts +11 -0
- package/dist/types/shared/constants.d.ts +7 -0
- package/dist/types/shared/physics.d.ts +1 -0
- package/dist/types/shared/protocol.d.ts +1 -1
- package/dist/types/shared/room.d.ts +4 -2
- package/dist/types/shared/types.d.ts +14 -0
- package/package.json +1 -1
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},n={THRUST:0,LEFT:1,RIGHT:2,SLASH:3},r={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},i={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},a={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},o={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7,CONCRETE:8,GLASS:9,STEEL:10,PAINT:11},s=127,c=16,l=65536/(2*Math.PI),u=e=>Math.round(e*l)&65535,d=e=>Math.max(-32768,Math.min(32767,Math.round(e))),f=e=>d(e*1e4),p=e=>e/1e4,m=e=>e/l,h=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)&1023,yaw:m(t.getUint16(5)),pitch:p(t.getInt16(7)),view:(t.getUint16(9)*256+t.getUint8(11))/256}:null},g=t=>t===e.CARRIED?2:t===e.DROPPED?8:1,ee=n=>{let r=4+46*n.players.length,i=new DataView(new ArrayBuffer(r+8+n.flags.reduce((e,t)=>e+g(t.state),0)));i.setUint8(0,2),i.setUint16(1,n.tick&65535),i.setUint8(3,n.players.length),n.players.forEach((e,n)=>{let r=4+n*46;i.setUint8(r,e.id),i.setFloat32(r+1,e.x),i.setFloat32(r+5,e.y),i.setFloat32(r+9,e.z),i.setFloat32(r+13,e.vx),i.setFloat32(r+17,e.vy),i.setFloat32(r+21,e.vz),i.setFloat32(r+25,e.edge),i.setUint16(r+29,u(e.yaw)),i.setInt16(r+31,f(e.pitch)),i.setUint16(r+33,e.ack&65535),i.setUint8(r+35,e.mode&7|(e.wall&7)<<3|(e.jumps&1)<<6|e.dashes<<7),i.setUint8(r+36,e.t),i.setUint8(r+37,e.dash|(e.by>>2&3)<<6),i.setUint8(r+38,e.coyote&7|(e.buffer&7)<<3|(e.held&t.JUMP?64:0)|(e.held&t.DASH?128:0)),i.setUint8(r+39,e.stun|(e.by&3)<<6);let a=e.hp|e.cool<<3|(e.ammo<0?s:e.ammo)<<6|e.down<<13|!!e.rack<<20|!!e.blade<<21|!!e.wield<<22|!!e.zap<<23;i.setUint8(r+40,a>>16),i.setUint16(r+41,a&65535),i.setUint8(r+43,e.shots),i.setUint8(r+44,e.hits),i.setUint8(r+45,(e.swing??0)&63|((e.cut??0)&3)<<6)}),i.setUint8(r,n.score[0]),i.setUint8(r+1,n.score[1]),i.setUint16(r+2,n.clock&32767|(n.over?32768:0)),i.setUint32(r+4,n.packs??0);let a=r+8;for(let t of n.flags)i.setUint8(a,t.state),t.state===e.CARRIED?i.setUint8(a+1,t.by):t.state===e.DROPPED&&(i.setInt16(a+1,d(t.x*c)),i.setInt16(a+3,d(t.y*c)),i.setInt16(a+5,d(t.z*c)),i.setUint8(a+7,Math.min(255,t.left))),a+=g(t.state);return i.buffer},te=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},_=.4,v=1.8,y=1.6,b=1.55,ne=.9,re=.7,ie=7.5,ae=1.5,oe=.15,se=.5,ce=.9,le=6.5,ue=.2,de=.03,fe=.2,pe=5.5,me=2.5,he=[`#ff3d4f`,`#2f80ff`],x=[{ticks:24,strike:8,reach:2.4,arc:.3,hp:2},{ticks:30,strike:11,reach:1.9,arc:1.2,hp:2},{ticks:30,strike:11,reach:1.9,arc:1.2,hp:2},{ticks:36,strike:14,reach:1.9,arc:.45,hp:3}],ge={maxPlayers:16,scoreLimit:3,timeLimit:480},_e=4,S=1024,ve=(e,t)=>(e+S)*(2*S)+t+S,C=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),ye=(e,t=_e)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=C(e[0],t);a<=C(r[0],t);a++)for(let o=C(e[2],t);o<=C(r[2],t);o++){let e=ve(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},w=(e,t,n,r)=>{let i=[];for(let a=C(t-r,e.cell);a<=C(t+r,e.cell);a++)for(let t=C(n-r,e.cell);t<=C(n+r,e.cell);t++)for(let n of e.grid.get(ve(a,t))??[])i.includes(n)||i.push(n);return i},be=(e,t,n,r)=>{let{cell:i,def:a}=e,o=r,s=C(t[0],i),c=C(t[2],i),l=Math.sign(n[0]),u=Math.sign(n[2]),d=l?((s+ +(l>0))*i-t[0])/n[0]:1/0,f=u?((c+ +(u>0))*i-t[2])/n[2]:1/0,p=d,m=f,h=l?i/Math.abs(n[0]):1/0,g=u?i/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(ve(s,c))??[]){let e=a.brushes[r],[i,s]=[0,o];for(let r=0;r<3&&i<=s;r++){if(!n[r]){(t[r]<e.min[r]||t[r]>e.max[r])&&(s=-1);continue}let a=(e.min[r]-t[r])/n[r],o=(e.max[r]-t[r])/n[r];i=Math.max(i,Math.min(a,o)),s=Math.min(s,Math.max(a,o))}i<=s&&s>0&&i<o&&(o=i)}if(Math.min(p,m)>=o||Math.abs(s)>S||Math.abs(c)>S)return o;p<m?(s+=l,p+=h):(c+=u,m+=g)}},xe=(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&&be(e,t,[r/o,i/o,a/o],o)<o-1e-4},T=1/60,E=Math.PI*2,D=1e-6,O=.01,k=.001,Se=e=>(e%E+E)%E,A=e=>[-Math.sin(e),-Math.cos(e)],j=Math.fround,Ce=Math.sqrt,M=(e,t,n)=>Math.min(Math.max(e,t),n),N=(e,t)=>Ce(e*e+t*t),P=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],we={vx:0,vz:0,mode:r.GROUND,t:0,wall:i.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,ev:0,fall:0},F=(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:j(a),y:j(o),z:j(s),vy:0,yaw:Se(c),pitch:0,ground:!0,...we}},Te=(e,t,n)=>{let{yaw:r,pitch:i,id:o,shots:s,hits:c}=e;Object.assign(e,F(o,t,o,n),{yaw:r,pitch:i,shots:s,hits:c,ev:e.ev|a.RESPAWN})},I=e=>e===r.GROUND||e===r.SLIDE||e===r.CROUCH,L=e=>e.mode===r.SLIDE||e.mode===r.CROUCH?ne:v,Ee=e=>e.mode===r.SLIDE||e.mode===r.CROUCH?re:y,De=e=>N(e.vx,e.vz),R=(e,t,n)=>e.max[1]>t+.5+O&&e.min[1]<t+n-O,z=(e,t,n)=>[t-M(t,e.min[0],e.max[0]),n-M(n,e.min[2],e.max[2])],Oe=(e,t,n)=>{let{brushes:r}=t.def,i=w(t,e.x,e.z,2*_),a=(_-D)**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(!R(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=Ce(d);.4-e>t&&(t=_-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+_,[c,l]=[p*t,m*t])}if(!t)break;e.x+=c,e.z+=l,o+=c,s+=l}return[o,s]},B=(e,t,n)=>{let{brushes:r}=t.def,i=(_-D)**2,a=-1/0,o=1/0;for(let s of w(t,e.x,e.z,_)){let t=r[s],[c,l]=z(t,e.x,e.z);c*c+l*l>=i||(t.max[1]<=e.y+.5+O?a=Math.max(a,t.max[1]):t.min[1]>=e.y+n-O&&(o=Math.min(o,t.min[1])))}return[a,o]},V=(e,t)=>{let n=(_-D)**2;return w(t,e.x,e.z,_).every(r=>{let i=t.def.brushes[r],[a,o]=z(i,e.x,e.z);return a*a+o*o>=n||!R(i,e.y,1.8)})},ke=(e,t,n,r,i)=>{let a=(_-D)**2;return w(e,t,n,_).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})},H=(e,t)=>{let[n,r]=P[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}},Ae=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=H(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-k&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},je=(e,t,n)=>{let r;for(let i of w(t,e.x,e.z,_+se)){let a=t.def.brushes[i],o=Ae(a,e,n,se);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-_)))}return r},Me=(e,t)=>{let[n,r]=A(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=P[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=H(e,a);for(let n of w(t,e.x,e.z,_+ue)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(Ae(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*(_+de),f=u+l*fe,[p,m]=c===0?[d,e.z]:[e.x,d],[h,g]=c===0?[f,e.z]:[e.x,f];ke(t,p,m,Math.min(e.y,o-2)+O,o+1.8)&&ke(t,h,g,o+O,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},Ne=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=H(e,e.wall);return w(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 j(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},Pe=(e,t)=>{if(e.vy>=0)return!1;let[n]=B(e,t,v),r=6*T;return e.y-n<=-e.vy*r+10*r*r},U=(e,t)=>{e.mode=t,e.t=0},Fe=(e,t,n,i=48,a=6)=>{e.stun=i,e.vx=j(t*a),e.vz=j(n*a),e.dash=Math.min(e.dash,50),e.coyote=0,e.buffer=0,(e.mode===r.HANG||e.mode===r.CLIMB)&&(e.vy=0),(e.mode===r.HANG||e.mode===r.CLIMB||e.mode===r.WALLRUN)&&(U(e,r.AIR),e.edge=0)},Ie=(e,t)=>{let n=N(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},W=(e,t,n,r)=>{let[i,a]=[n.wx,n.wz];for(let n of w(t,e.x,e.z,_+k)){let o=t.def.brushes[n],[s,c]=z(o,e.x,e.z),l=N(s,c);if(l>0&&l<=.4+k&&R(o,e.y,r)){let e=(-i*s-a*c)/l;e>0&&(i+=e*s/l,a+=e*c/l)}}return[i,a]},Le=(e,t,n)=>{let r=N(t[0],t[1]);if(r<D){let t=N(e.vx,e.vz),n=t?Math.max(0,t-45*T)/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=N(s,c);if(l){let e=Math.max(0,l-45*T)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*T):Math.max(n,o-12*T),e.vx=s+o*i,e.vz=c+o*a},Re=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*T,e.z+=e.vz*T;let[o,s]=Oe(e,t,n),c=N(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]=B(e,t,n),d=e.vy-r*20*T;if(e.y+=(e.vy+d)/2*T,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+O: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},G=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=a.JUMP},ze=(e,n,i)=>{let[a,o]=P[e.wall],s=t=>{U(e,t),e.edge=0};if(i.keys&(t.BACK|t.CROUCH))s(r.AIR),e.coyote=0;else if(i.jump&&i.fx*a+i.fz*o<0)s(r.AIR),e.vx=-a*4,e.vz=-o*4,G(e,6);else if(i.jump||i.fwd&&e.t>=6)U(e,r.CLIMB);else if(e.t>=30)s(r.AIR),e.coyote=0;else{let t=Math.max(e.edge-2,B(e,n,v)[0]);e.y+=M(t-e.y,-8*T,8*T)}},Be=(e,t)=>{let[n,o]=P[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*T):(e.x+=n*pe*T,e.z+=o*pe*T),e.y>=e.edge&&Ne(e,t)?(U(e,r.GROUND),e.vx=n*3,e.vz=o*3,e.vy=0,e.edge=0,e.wall=i.NONE,e.coyote=6,e.ev|=a.CLIMB):e.t>=40&&(U(e,e.y>=e.edge?r.GROUND:r.AIR),e.edge=0,e.wall=i.NONE)},Ve=(e,t,n)=>{let[i,o]=P[e.wall],s=e.vx*i+e.vz*o,[c,l]=[e.vx-s*i,e.vz-s*o],u=N(c,l);if(n.jump)U(e,r.AIR),e.vx=c-i*5,e.vz=l-o*5,G(e,le),e.jumps=1,e.dashes=1,e.ev|=a.WALLRUN_END;else{let s=je(e,t,e.wall);if(s===void 0||!n.fwd||u<3.5||e.t>=60){U(e,r.AIR),e.ev|=a.WALLRUN_END;return}let d=Math.max(0,u-ae*T)/u;e.vx=c*d,e.vz=l*d;let f=Math.min(s,4*T);e.x+=i*f,e.z+=o*f}},He=(e,t,n)=>{if(!n.fwd)return;let i=N(e.vx,e.vz);if(!(i<4.5))for(let n=1;n<=4;n++){let[o,s]=P[n],c=e.vx*o+e.vz*s,[l,u]=[e.vx-c*o,e.vz-c*s];if(n!==e.wall&&c<=.75*i&&c>=-.2*i&&je(e,t,n)!==void 0){let t=N(l,u),o=Math.max(t,ce*i)/t;U(e,r.WALLRUN),e.wall=n,[e.vx,e.vz]=[l*o,u*o],e.vy=M(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=a.WALLRUN_START;return}}},Ue=(e,t)=>{U(e,r.HANG),e.wall=t.side,e.edge=j(t.top),t.side<=i.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|=a.GRAB},We=(e,n,o)=>{let s=e.mode===r.GROUND;if(o.dash&&e.dash===0&&(s||(e.mode===r.AIR||e.mode===r.WALLRUN)&&e.dashes>0)){let[t,n]=o.wx||o.wz?[o.wx,o.wz]:[o.fx,o.fz];s||(e.dashes--,e.vy=0,e.mode===r.WALLRUN&&(U(e,r.AIR),e.ev|=a.WALLRUN_END)),e.vx=t*16,e.vz=n*16,e.dash=60,e.ev|=a.DASH}let c=e.dash>50;e.mode===r.WALLRUN&&Ve(e,n,o),I(e.mode)&&Ge(e,n,o,c),e.mode===r.AIR&&Ke(e,n,o,c);let l=c&&e.vy<=0?0:e.mode===r.WALLRUN?oe:1,u=e.mode,d=Re(e,n,L(e),l,I(u));if(d>=0){if(!I(e.mode)){if(e.ev|=a.LAND|(e.mode===r.WALLRUN?a.WALLRUN_END:0),e.fall=d,e.jumps=1,e.dashes=1,e.wall=i.NONE,o.keys&t.CROUCH){let t=N(e.vx,e.vz)>=ie;U(e,t?r.SLIDE:r.CROUCH),e.ev|=t?a.SLIDE_START:0}else U(e,r.GROUND)}e.coyote=6}else I(e.mode)&&(e.ev|=e.mode===r.SLIDE?a.SLIDE_END:0,U(e,r.AIR));if(e.mode===r.AIR){let t=Me(e,n);t?Ue(e,t):He(e,n,o)}},Ge=(e,n,i,o)=>{let s=(i.keys&t.CROUCH)!==0;if(e.buffer>0&&(e.mode===r.GROUND||V(e,n))){e.ev|=e.mode===r.SLIDE?a.SLIDE_END:0,U(e,r.AIR),G(e,7);return}let c=N(e.vx,e.vz);if(e.mode===r.GROUND&&s){let t=c>=ie;U(e,t?r.SLIDE:r.CROUCH),e.ev|=t?a.SLIDE_START:0}else e.mode===r.SLIDE&&(e.t>=60||c<4.5||i.stumble)?(e.ev|=a.SLIDE_END,U(e,!s&&V(e,n)?r.GROUND:r.CROUCH)):e.mode===r.SLIDE&&!s&&V(e,n)?(e.ev|=a.SLIDE_END,U(e,r.GROUND)):e.mode===r.CROUCH&&!s&&V(e,n)&&U(e,r.GROUND);if(!o){if(i.stumble){if(c>2.5){let t=Math.max(me,c-12*T)/c;e.vx*=t,e.vz*=t}else Le(e,W(e,n,i,L(e)),me)}else if(e.mode===r.SLIDE){let t=Math.max(0,c-4*T)/c;e.vx*=t,e.vz*=t}else if(e.mode===r.CROUCH)Le(e,W(e,n,i,ne),3);else{let r=(i.keys&t.SPRINT)!==0&&i.fwd;Le(e,W(e,n,i,v),r?9:6)}}},Ke=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?G(e,7):e.jumps>0&&!Pe(e,t)&&(e.jumps--,G(e,6),e.ev=e.ev&~a.JUMP|a.DOUBLE)),r||!n.wx&&!n.wz)return;let i=N(e.vx,e.vz);e.vx+=n.wx*14*T,e.vz+=n.wz*14*T,Ie(e,Math.max(i,6))},qe=(e,n,i,a=0)=>{e.yaw=Se(n.yaw),e.pitch=Math.max(-b,Math.min(b,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=N(o,s)||1,[l,u]=A(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&&Ie(e,10)),e.mode===r.HANG&&ze(e,i,p),e.mode===r.CLIMB?Be(e,i):e.mode!==r.HANG&&We(e,i,p),e.y<i.def.floor&&Te(e,i,a),e.t=e.mode===m?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===r.AIR&&m===r.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=n.keys&(t.JUMP|t.DASH),e.ground=I(e.mode),e.x=j(e.x),e.y=j(e.y),e.z=j(e.z),e.vx=j(e.vx),e.vy=j(e.vy),e.vz=j(e.vz),e.edge=j(e.edge)},Je=.7,Ye=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},Xe=(e,t,n)=>{let{reach:r,arc:i}=x[t.cut??0],[a,o]=A(t.yaw),s=[t.x,t.y+Je*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(_/u):Math.PI;return d<=i+f&&!xe(e,s,[n.x,n.y+Je*L(n),n.z])})},Ze=e=>{let[t,r]=A(e.yaw),i=e.cut??0;return i===n.LEFT?[-r,t]:i===n.RIGHT?[r,-t]:[t,r]},K=()=>({state:e.HOME,by:0,x:0,y:0,z:0,left:0}),Qe=60,$e=class{score=[0,0];over=!1;flags=[K(),K()];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&a.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=be(this.world,[e.x,e.y+.05,e.z],[0,-1,0],Qe);t<Qe&&(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=[K(),K()],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]=K()))}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=>et(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]=K()}else s&&(this.flags[n]={...K(),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&&et(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]=K()}}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}},et=(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],tt=(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},q={NONE:0,SHOT:1,CUT:2},nt=(e,n,i,a,o=!0)=>{let s=e.down>0;if(qe(e,s?{...n,keys:0}:n,i,a),e.zap=!!e.stun&&!!e.zap,s)return e.down>0&&!--e.down&&Te(e,i,a),q.NONE;let{rack:c,blade:l}=i.def.teams[a],u=!!c&&tt(e,c,1.2);o&&u&&!e.rack&&(e.ammo=60),e.rack=u,e.blade=!!e.blade||o&&!!l&&tt(e,l,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 d=e.mode===r.HANG||e.mode===r.CLIMB;if(!o)return q.NONE;let f=x[e.cut??0];if(e.swing&&f.ticks-e.swing===f.strike)return q.CUT;if(n.keys&t.FIRE&&!d){if(e.wield&&!e.swing)e.cut=Ye(n.keys),e.swing=x[e.cut].ticks;else if(!e.wield&&!e.cool&&e.ammo>0)return e.ammo--,e.shots=e.shots+1&255,e.cool=7,q.SHOT}return q.NONE},rt=(e,t,n,r)=>{let[i,a]=[e[0]-n.x,e[2]-n.z],o=t[0]*t[0]+t[2]*t[2],s=i*t[0]+a*t[2],c=s*s-o*(i*i+a*a-_*_),[l,u]=[0,1/0];if(o>1e-12){if(c<0)return 1/0;[l,u]=[(-s-Math.sqrt(c))/o,(-s+Math.sqrt(c))/o]}else if(i*i+a*a>.4*.4)return 1/0;let[d,f]=[n.y-e[1],n.y+r-e[1]];if(t[1])[l,u]=[Math.max(l,Math.min(d/t[1],f/t[1])),Math.min(u,Math.max(d/t[1],f/t[1]))];else if(d>0||f<0)return 1/0;return l<=u&&u>=0?Math.max(l,0):1/0},it=(e,t,n)=>{let r=[t.x,t.y+Ee(t),t.z],[i,a,o,s]=[Math.sin(t.yaw),Math.cos(t.yaw),Math.sin(t.pitch),Math.cos(t.pitch)],c=[-i*s,o,-a*s],l=be(e,r,c,80),u;for(let e of n){let t=rt(r,c,e,L(e));t<l&&([l,u]=[t,e])}return u},at=-30,J=(e,t,n,r,i,a=o.CONCRETE)=>({min:[e,at,t],max:[n,i,r],top:o.CONCRETE,side:a}),Y=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c});[J(4,57.7,24,76,10),J(4,36,24,53.5,10,o.GLASS),J(4,20,24,36,12.4),J(4,-5,24,7,12.4,o.GLASS),J(27,20,47,50,8),J(27,60,47,76,8,o.BRICK),Y([9,12.2,39],[19,12.6,47],o.STEEL),...((e,t)=>[1,2,3,4,5,6].map(n=>Y([12,t,e-n],[14,t+.4*n,e-n+1],o.CONCRETE)))(53,10),Y([5,10,42],[5.5,14,42.5],o.STEEL),Y([5,10,50],[5.5,14,50.5],o.STEEL),Y([8,12.4,24],[20,12.85,24.45],o.STEEL),Y([36,8,22],[37,14.5,48],o.PAINT,o.PAINT,[.15,.72,.62]),Y([30,8,28],[34,10,32],o.CONCRETE),Y([40,8,30],[44,10.2,34],o.PAINT,o.PAINT,[1,.3,.06]),Y([28,9.2,44],[35,12,46],o.STEEL,o.PAINT,[.2,.42,1]),Y([41.5,7.6,50],[42,8,60],o.STEEL),Y([30,8,64],[34,9.6,68],o.PAINT,o.PAINT,[.2,.8,.3])];var X=240,Z=[1,.22,.26],ot=[.2,.46,1],st=[1,.42,.08],ct=[.12,.7,.62],Q=(e,t,n,r,i,a,s)=>Y([e,t,n],[r,i,a],o.PAINT,o.PAINT,s),lt=(e,t,n,r,i,a,s,c=at)=>{let l=Math.ceil((s-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+(s-a)*(d+1)/l;return e===0?Y([f,c,r],[p,m,i],o.CONCRETE):Y([r,c,f],[i,m,p],o.CONCRETE)})},$=(e,t,n,r,i,a,s)=>s.map((s,c)=>Y([e+c*n,a,t+c*r],[e+c*n+4,s,t+c*r+i],o.STEEL,o.CONCRETE)),ut=[J(12,212,52,240,26,o.GLASS),Q(12,26,212,52,26.12,212.5,Z),Q(12,26,239.5,52,26.12,240,Z),Q(12,26,212.5,12.5,26.12,239.5,Z),Q(51.5,26,212.5,52,26.12,239.5,Z),Q(11.6,12,222,12,25.8,232,Z),Q(28,12,211.4,31,25.5,212,Z),Y([19,26,222],[22,27.4,225],o.STEEL),Y([42,26,222],[45,27.4,225],o.STEEL),Y([29,26,229],[35,27.1,229.6],o.CONCRETE),J(6,164,26,201,26,o.GLASS),J(6,134,26,147,26,o.GLASS),J(6,201,26,212,19),J(15,147,26,164,19),Y([14,26,164],[15,32,196],o.PAINT,o.PAINT,ct),Y([14,18,147],[15,32,164],o.PAINT,o.PAINT,ct),Y([14,26,134],[15,32,147],o.PAINT,o.PAINT,ct),...$(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])=>Y([e,19,t],[n,i,r],o.STEEL,o.CONCRETE)),Y([20,26,178],[23,27.3,181],o.STEEL),Y([8,26,176],[11,27.2,179],o.STEEL),Y([8,26,190],[11,27.3,193],o.STEEL),Y([20,26,140],[23,27.3,143],o.STEEL),J(32,186,76,209,19),Q(32,19,207.5,76,19.1,209,Z),...$(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])=>Y([e,at,t],[n,i,r],o.STEEL,o.CONCRETE)),J(32,166,64,182,21.2,o.GLASS),J(32,140,64,161,19),Y([40,21.2,172],[44,22.6,176],o.STEEL),Y([52,19,148],[57,20.3,151],o.STEEL),Y([38,19,196],[41,20.4,199],o.STEEL),Y([60,19,200],[63,20.4,203],o.STEEL),Y([52,19,190],[58,20.6,194],o.STEEL),Y([66,19,204],[72,20.2,207],o.STEEL),Y([56,21.2,170],[60,22.4,174],o.STEEL),Y([34,19,152],[37,20.3,156],o.STEEL),...$(36,135,18,0,3,15,[17.2,17.2]),...$(6.5,129,6,0,4,15,[17.2,19.4,21.6,23.8]),J(76,213,100,240,14.5,o.STEEL),Q(76,14.5,238.5,100,14.6,240,Z),J(76,185,100,209,14.5),J(76,138,100,181,14.5,o.GLASS),Y([80,15.7,158],[96,17.7,162],o.STEEL,o.PAINT,st),Y([82,14.5,234],[85,15.9,237],o.STEEL),Y([91,14.5,190],[94,15.9,193],o.STEEL),Y([80,14.5,204],[83,15.6,207],o.STEEL),Y([78,14.5,170],[81,15.9,173],o.STEEL),Y([92,14.5,146],[95,15.7,149],o.STEEL),Y([92,14.5,222],[96,15.8,226],o.STEEL),...lt(0,76,52,226,232,14.5,26),...lt(0,85,76,196,202,14.5,19,14.5)],dt=[J(6,106,62,134,15),J(62,106,100,134,14.5),Y([34,15,112],[54,17.2,128],o.CONCRETE),Q(38,17.2,116,50,17.3,124,st),...[[35,113],[35,126.2],[51,113],[51,126.2]].map(([e,t])=>Y([e,17.2,t],[e+.8,21.5,t+.8],o.STEEL)),Y([34.6,21.5,112.6],[52.2,21.9,127.4],o.GLASS),Y([14,15,114],[17,16.5,117],o.STEEL),Y([14,15,123],[17,16.5,126],o.STEEL),Y([56,15,114],[59,16.5,117],o.STEEL),Y([56,15,123],[59,16.5,126],o.STEEL),Y([15.35,25.5,106],[15.85,26,134],o.STEEL),Y([70,14.5,108],[70.8,38,108.8],o.STEEL),Y([70,14.5,131.2],[70.8,38,132],o.STEEL),Y([66,14.5,110],[69,15.9,113],o.STEEL),Y([66,14.5,127],[69,15.9,130],o.STEEL)],ft=e=>({...e,min:[e.min[0],e.min[1],X-e.max[2]],max:[e.max[0],e.max[1],X-e.min[2]],tint:e.tint===Z?ot:e.tint}),pt=(e,t,n)=>[...[16,22,28,34,40].map(n=>[n,26,t,e]),...[19,31,43].map(t=>[t,26,n,e])],mt=[[20,26,190],[48,21.2,172],[48,19,200],[88,14.5,198]],ht=[[21,26,168],[46,19,144],[36,21.2,178],[88,14.5,216],[88,14.5,172]],gt={name:`Highline`,brushes:[...ut,...ut.map(ft),...dt],teams:[{base:[32,26,224],spawns:pt(0,236,231),rack:[47,26,234],blade:[47,26,231.5]},{base:[32,26,16],spawns:pt(Math.PI,4,9),rack:[47,26,6],blade:[47,26,8.5]}],packs:[...mt,...mt.map(([e,t,n])=>[e,t,X-n]),[24,15,112],[24,15,128]],ammo:[...ht,...ht.map(([e,t,n])=>[e,t,X-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]},_t=e=>e.mode===r.SLIDE||e.dash>50,vt=(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),yt=20,bt=2,xt=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),St=e=>xt((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),Ct=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${xt(e,15-`${r}`.length)} ${r}`;return n},wt=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},Tt=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];world;ctf;halt;rules;rr=[0,0];gone;constructor(e={},t=gt){this.rules={...ge,...e},this.world=ye(t),this.ctf=new $e(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&&h(t);if(r&&n.bank>0){n.bank--;let e=nt(n.state,r,this.world,n.info.team,!this.ctf.over);this.ctf.moved(n.state),this.tackle(n,r.view),e===q.SHOT?this.shoot(n,r.view):e===q.CUT&&this.cut(n,r.view),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)return;let t=++this.ticks;for(let t of e)t.bank=Math.min(10,t.bank+1);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=ee({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});e.forEach(e=>e.conn.send(n))}}start(e=wt){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<yt;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||!_t(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=>vt(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=De(n),[s,c]=o>.001?[n.vx/o,n.vz/o]:A(n.yaw);Fe(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,blade:!1,wield:!1,swing:0}),this.ctf.drop(e.state),!0)}shoot(e,t){let n=this.players().find(n=>n.info.id===it(this.world,e.state,this.enemies(e,t))?.id);n&&(e.state.hits=e.state.hits+1&255,this.harm(n,1))}cut(e,t){let n=Xe(this.world,e.state,this.enemies(e,t)).map(e=>e.id),r=this.players().filter(e=>n.includes(e.info.id));if(!r.length)return;e.state.hits=e.state.hits+1&255;let[i,a]=Ze(e.state);for(let t of r)this.harm(t,x[e.state.cut??0].hp)||(Fe(t.state,i,a,24,4),t.state.zap=!0,t.by=e.info.id)}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)&&tt(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}=F(e,this.world,i,t);return!n.some(e=>Math.hypot(e.x-a,e.z-o)<bt)});return F(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:Ct(St(t)||`Player ${r}`,n.map(e=>e.info.name)),team:a,color:he[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})))}},Et=(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()},Dt=(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))},ee=()=>{let e=d.length?d:f?[f]:[];return d=[],e},_=e=>{if(p)return e();l=e,u=r,c=/* @__PURE__ */ new Map,s=new Tt(t),s.start(Et),s.connect(g),ee().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,ee().forEach(e=>m({kind:`m`,data:e}))))}};let v=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:v,close:y};return o?o.request(n,{signal:a.signal},()=>new Promise(_)).catch(()=>{}):_(()=>{}),m({kind:`q`}),globalThis.addEventListener?.(`pagehide`,y),setTimeout(()=>!p&&b.onopen?.()),b};export{Dt 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},n={THRUST:0,LEFT:1,RIGHT:2,SLASH:3},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=65536/(2*Math.PI),d=e=>Math.round(e*u)&65535,f=e=>Math.max(-32768,Math.min(32767,Math.round(e))),p=e=>f(e*1e4),m=e=>e/1e4,h=e=>e/u,g=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)&1023,yaw:h(t.getUint16(5)),pitch:m(t.getInt16(7)),view:(t.getUint16(9)*256+t.getUint8(11))/256}:null},_=t=>t===e.CARRIED?2:t===e.DROPPED?8:1,ee=n=>{let r=4+47*n.players.length,i=new DataView(new ArrayBuffer(r+8+n.flags.reduce((e,t)=>e+_(t.state),0)));i.setUint8(0,2),i.setUint16(1,n.tick&65535),i.setUint8(3,n.players.length),n.players.forEach((e,n)=>{let r=4+n*47;i.setUint8(r,e.id),i.setFloat32(r+1,e.x),i.setFloat32(r+5,e.y),i.setFloat32(r+9,e.z),i.setFloat32(r+13,e.vx),i.setFloat32(r+17,e.vy),i.setFloat32(r+21,e.vz),i.setFloat32(r+25,e.edge),i.setUint16(r+29,d(e.yaw)),i.setInt16(r+31,p(e.pitch)),i.setUint16(r+33,e.ack&65535),i.setUint8(r+35,e.mode&7|(e.wall&7)<<3|(e.jumps&1)<<6|e.dashes<<7),i.setUint8(r+36,e.t),i.setUint8(r+37,e.dash|(e.by>>2&3)<<6),i.setUint8(r+38,e.coyote&7|(e.buffer&7)<<3|(e.held&t.JUMP?64:0)|(e.held&t.DASH?128:0)),i.setUint8(r+39,e.stun|(e.by&3)<<6);let a=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;i.setUint8(r+40,a>>16),i.setUint16(r+41,a&65535),i.setUint8(r+43,e.shots),i.setUint8(r+44,e.hits),i.setUint8(r+45,(e.swing??0)&63|((e.cut??0)&3)<<6),i.setUint8(r+46,(e.lost??0)&7)}),i.setUint8(r,n.score[0]),i.setUint8(r+1,n.score[1]),i.setUint16(r+2,n.clock&32767|(n.over?32768:0)),i.setUint32(r+4,n.packs??0);let a=r+8;for(let t of n.flags)i.setUint8(a,t.state),t.state===e.CARRIED?i.setUint8(a+1,t.by):t.state===e.DROPPED&&(i.setInt16(a+1,f(t.x*l)),i.setInt16(a+3,f(t.y*l)),i.setInt16(a+5,f(t.z*l)),i.setUint8(a+7,Math.min(255,t.left))),a+=_(t.state);return i.buffer},te=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},v=.4,y=1.8,b=1.6,ne=1.55,re=.9,ie=.7,ae=7.5,oe=1.5,se=.15,ce=.5,le=.9,ue=6.5,de=.2,fe=.03,pe=.2,me=5.5,he=2.5,ge=[`#ff3d4f`,`#2f80ff`],x=[{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}],[_e,ve,ye]=[.82,.45,.12],be={maxPlayers:16,scoreLimit:3,timeLimit:480},xe=4,S=1024,Se=(e,t)=>(e+S)*(2*S)+t+S,C=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),Ce=(e,t=xe)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=C(e[0],t);a<=C(r[0],t);a++)for(let o=C(e[2],t);o<=C(r[2],t);o++){let e=Se(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},w=(e,t,n,r)=>{let i=[];for(let a=C(t-r,e.cell);a<=C(t+r,e.cell);a++)for(let t=C(n-r,e.cell);t<=C(n+r,e.cell);t++)for(let n of e.grid.get(Se(a,t))??[])i.includes(n)||i.push(n);return i},we=(e,t,n,r)=>{let{cell:i,def:a}=e,o=r,s=C(t[0],i),c=C(t[2],i),l=Math.sign(n[0]),u=Math.sign(n[2]),d=l?((s+ +(l>0))*i-t[0])/n[0]:1/0,f=u?((c+ +(u>0))*i-t[2])/n[2]:1/0,p=d,m=f,h=l?i/Math.abs(n[0]):1/0,g=u?i/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(Se(s,c))??[]){let e=a.brushes[r],[i,s]=[0,o];for(let r=0;r<3&&i<=s;r++){if(!n[r]){(t[r]<e.min[r]||t[r]>e.max[r])&&(s=-1);continue}let a=(e.min[r]-t[r])/n[r],o=(e.max[r]-t[r])/n[r];i=Math.max(i,Math.min(a,o)),s=Math.min(s,Math.max(a,o))}i<=s&&s>0&&i<o&&(o=i)}if(Math.min(p,m)>=o||Math.abs(s)>S||Math.abs(c)>S)return o;p<m?(s+=l,p+=h):(c+=u,m+=g)}},Te=(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&&we(e,t,[r/o,i/o,a/o],o)<o-1e-4},T=1/60,E=Math.PI*2,D=1e-6,O=.01,k=.001,Ee=e=>(e%E+E)%E,A=e=>[-Math.sin(e),-Math.cos(e)],j=Math.fround,De=Math.sqrt,M=(e,t,n)=>Math.min(Math.max(e,t),n),N=(e,t)=>De(e*e+t*t),P=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],Oe={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},F=(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:j(a),y:j(o),z:j(s),vy:0,yaw:Ee(c),pitch:0,ground:!0,...Oe}},ke=(e,t,n)=>{let{yaw:r,pitch:i,id:a,shots:s,hits:c}=e;Object.assign(e,F(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?re:y,Ae=e=>e.mode===i.SLIDE||e.mode===i.CROUCH?ie:b,je=e=>N(e.vx,e.vz),R=(e,t,n)=>e.max[1]>t+.5+O&&e.min[1]<t+n-O,z=(e,t,n)=>[t-M(t,e.min[0],e.max[0]),n-M(n,e.min[2],e.max[2])],Me=(e,t,n)=>{let{brushes:r}=t.def,i=w(t,e.x,e.z,2*v),a=(v-D)**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(!R(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=De(d);.4-e>t&&(t=v-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+v,[c,l]=[p*t,m*t])}if(!t)break;e.x+=c,e.z+=l,o+=c,s+=l}return[o,s]},B=(e,t,n)=>{let{brushes:r}=t.def,i=(v-D)**2,a=-1/0,o=1/0;for(let s of w(t,e.x,e.z,v)){let t=r[s],[c,l]=z(t,e.x,e.z);c*c+l*l>=i||(t.max[1]<=e.y+.5+O?a=Math.max(a,t.max[1]):t.min[1]>=e.y+n-O&&(o=Math.min(o,t.min[1])))}return[a,o]},V=(e,t)=>{let n=(v-D)**2;return w(t,e.x,e.z,v).every(r=>{let i=t.def.brushes[r],[a,o]=z(i,e.x,e.z);return a*a+o*o>=n||!R(i,e.y,1.8)})},Ne=(e,t,n,r,i)=>{let a=(v-D)**2;return w(e,t,n,v).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})},H=(e,t)=>{let[n,r]=P[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}},Pe=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=H(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-k&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},Fe=(e,t,n)=>{let r;for(let i of w(t,e.x,e.z,v+ce)){let a=t.def.brushes[i],o=Pe(a,e,n,ce);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-v)))}return r},Ie=(e,t)=>{let[n,r]=A(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=P[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=H(e,a);for(let n of w(t,e.x,e.z,v+de)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(Pe(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*(v+fe),f=u+l*pe,[p,m]=c===0?[d,e.z]:[e.x,d],[h,g]=c===0?[f,e.z]:[e.x,f];Ne(t,p,m,Math.min(e.y,o-2)+O,o+1.8)&&Ne(t,h,g,o+O,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},Le=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=H(e,e.wall);return w(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 j(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},Re=(e,t)=>{if(e.vy>=0)return!1;let[n]=B(e,t,y),r=6*T;return e.y-n<=-e.vy*r+10*r*r},U=(e,t)=>{e.mode=t,e.t=0},ze=(e,t,n,r=48,a=6)=>{e.stun=r,e.vx=j(t*a),e.vz=j(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)&&(U(e,i.AIR),e.edge=0)},Be=(e,t)=>{let n=N(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},W=(e,t,n,r)=>{let[i,a]=[n.wx,n.wz];for(let n of w(t,e.x,e.z,v+k)){let o=t.def.brushes[n],[s,c]=z(o,e.x,e.z),l=N(s,c);if(l>0&&l<=.4+k&&R(o,e.y,r)){let e=(-i*s-a*c)/l;e>0&&(i+=e*s/l,a+=e*c/l)}}return[i,a]},Ve=(e,t,n)=>{let r=N(t[0],t[1]);if(r<D){let t=N(e.vx,e.vz),n=t?Math.max(0,t-45*T)/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=N(s,c);if(l){let e=Math.max(0,l-45*T)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*T):Math.max(n,o-12*T),e.vx=s+o*i,e.vz=c+o*a},He=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*T,e.z+=e.vz*T;let[o,s]=Me(e,t,n),c=N(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]=B(e,t,n),d=e.vy-r*20*T;if(e.y+=(e.vy+d)/2*T,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+O: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},G=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=o.JUMP},Ue=(e,n,r)=>{let[a,o]=P[e.wall],s=t=>{U(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,G(e,6);else if(r.jump||r.fwd&&e.t>=6)U(e,i.CLIMB);else if(e.t>=30)s(i.AIR),e.coyote=0;else{let t=Math.max(e.edge-2,B(e,n,y)[0]);e.y+=M(t-e.y,-8*T,8*T)}},We=(e,t)=>{let[n,r]=P[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*T):(e.x+=n*me*T,e.z+=r*me*T),e.y>=e.edge&&Le(e,t)?(U(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&&(U(e,e.y>=e.edge?i.GROUND:i.AIR),e.edge=0,e.wall=a.NONE)},Ge=(e,t,n)=>{let[r,a]=P[e.wall],s=e.vx*r+e.vz*a,[c,l]=[e.vx-s*r,e.vz-s*a],u=N(c,l);if(n.jump)U(e,i.AIR),e.vx=c-r*5,e.vz=l-a*5,G(e,ue),e.jumps=1,e.dashes=1,e.ev|=o.WALLRUN_END;else{let s=Fe(e,t,e.wall);if(s===void 0||!n.fwd||u<3.5||e.t>=60){U(e,i.AIR),e.ev|=o.WALLRUN_END;return}let d=Math.max(0,u-oe*T)/u;e.vx=c*d,e.vz=l*d;let f=Math.min(s,4*T);e.x+=r*f,e.z+=a*f}},Ke=(e,t,n)=>{if(!n.fwd)return;let r=N(e.vx,e.vz);if(!(r<4.5))for(let n=1;n<=4;n++){let[a,s]=P[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&&Fe(e,t,n)!==void 0){let t=N(l,u),a=Math.max(t,le*r)/t;U(e,i.WALLRUN),e.wall=n,[e.vx,e.vz]=[l*a,u*a],e.vy=M(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=o.WALLRUN_START;return}}},qe=(e,t)=>{U(e,i.HANG),e.wall=t.side,e.edge=j(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},Je=(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&&(U(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&&Ge(e,n,r),I(e.mode)&&Ye(e,n,r,c),e.mode===i.AIR&&Xe(e,n,r,c);let l=c&&e.vy<=0?0:e.mode===i.WALLRUN?se:1,u=e.mode,d=He(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=N(e.vx,e.vz)>=ae;U(e,t?i.SLIDE:i.CROUCH),e.ev|=t?o.SLIDE_START:0}else U(e,i.GROUND)}e.coyote=6}else I(e.mode)&&(e.ev|=e.mode===i.SLIDE?o.SLIDE_END:0,U(e,i.AIR));if(e.mode===i.AIR){let t=Ie(e,n);t?qe(e,t):Ke(e,n,r)}},Ye=(e,n,r,a)=>{let s=(r.keys&t.CROUCH)!==0;if(e.buffer>0&&(e.mode===i.GROUND||V(e,n))){e.ev|=e.mode===i.SLIDE?o.SLIDE_END:0,U(e,i.AIR),G(e,7);return}let c=N(e.vx,e.vz);if(e.mode===i.GROUND&&s){let t=c>=ae;U(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,U(e,!s&&V(e,n)?i.GROUND:i.CROUCH)):e.mode===i.SLIDE&&!s&&V(e,n)?(e.ev|=o.SLIDE_END,U(e,i.GROUND)):e.mode===i.CROUCH&&!s&&V(e,n)&&U(e,i.GROUND);if(!a){if(r.stumble){if(c>2.5){let t=Math.max(he,c-12*T)/c;e.vx*=t,e.vz*=t}else Ve(e,W(e,n,r,L(e)),he)}else if(e.mode===i.SLIDE){let t=Math.max(0,c-4*T)/c;e.vx*=t,e.vz*=t}else if(e.mode===i.CROUCH)Ve(e,W(e,n,r,re),3);else{let i=(r.keys&t.SPRINT)!==0&&r.fwd;Ve(e,W(e,n,r,y),i?9:6)}}},Xe=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?G(e,7):e.jumps>0&&!Re(e,t)&&(e.jumps--,G(e,6),e.ev=e.ev&~o.JUMP|o.DOUBLE)),r||!n.wx&&!n.wz)return;let i=N(e.vx,e.vz);e.vx+=n.wx*14*T,e.vz+=n.wz*14*T,Be(e,Math.max(i,6))},Ze=(e,n,r,a=0)=>{e.yaw=Ee(n.yaw),e.pitch=Math.max(-ne,Math.min(ne,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=N(o,s)||1,[l,u]=A(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&&Be(e,10)),e.mode===i.HANG&&Ue(e,r,p),e.mode===i.CLIMB?We(e,r):e.mode!==i.HANG&&Je(e,r,p),e.y<r.def.floor&&ke(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=j(e.x),e.y=j(e.y),e.z=j(e.z),e.vx=j(e.vx),e.vy=j(e.vy),e.vz=j(e.vz),e.edge=j(e.edge)},Qe=.7,$e=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},et=(e,t,n)=>{let{reach:r,arc:i}=x[t.cut??0],[a,o]=A(t.yaw),s=[t.x,t.y+Qe*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(v/u):Math.PI;return d<=i+f&&!Te(e,s,[n.x,n.y+Qe*L(n),n.z])})},tt=e=>{let[t,r]=A(e.yaw),i=e.cut??0;return i===n.LEFT?[-r,t]:i===n.RIGHT?[r,-t]:[t,r]},nt=(e,t)=>{let[i,a]=A(e.yaw),[o,s]=A(t.yaw),[c,l]=[t.x-e.x,t.z-e.z],u=-a*c+i*l,d=Math.sqrt(Math.max(v*v-u*u,0)),[f,p]=[a*u-i*d,-i*u-a*d],m=-s*f+o*p,h=e.cut??0;if(h===n.SLASH)return Math.abs(m)<=ye?r.HEAD:m>0?r.ARM_R:r.ARM_L;let g=(e.y+Qe*L(e)+Math.tan(e.pitch)*Math.hypot(c,l)-t.y)/L(t);if(g>_e)return r.HEAD;let _=h===n.THRUST?m>0:(h===n.LEFT?1:-1)*(i*o+a*s)<0;return g<ve?_?r.LEG_R:r.LEG_L:h===n.THRUST&&Math.abs(m)<=ye?r.NONE:_?r.ARM_R:r.ARM_L},K=()=>({state:e.HOME,by:0,x:0,y:0,z:0,left:0}),rt=60,it=class{score=[0,0];over=!1;flags=[K(),K()];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=we(this.world,[e.x,e.y+.05,e.z],[0,-1,0],rt);t<rt&&(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=[K(),K()],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]=K()))}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=>at(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]=K()}else s&&(this.flags[n]={...K(),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&&at(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]=K()}}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}},at=(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],ot=(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},q={NONE:0,SHOT:1,CUT:2},st=(e,n,r,a,o=!0)=>{let s=e.down>0;if(Ze(e,s?{...n,keys:0}:n,r,a),e.zap=!!e.stun&&!!e.zap,s)return e.down>0&&!--e.down&&ke(e,r,a),q.NONE;let{rack:c,blade:l}=r.def.teams[a],u=!!c&&ot(e,c,1.2);o&&u&&!e.rack&&(e.ammo=60),e.rack=u,e.blade=!!e.blade||o&&!!l&&ot(e,l,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 d=e.mode===i.HANG||e.mode===i.CLIMB;if(!o)return q.NONE;let f=x[e.cut??0];if(e.swing&&f.ticks-e.swing===f.strike)return q.CUT;if(n.keys&t.FIRE&&!d){if(e.wield&&!e.swing)e.cut=$e(n.keys),e.swing=x[e.cut].ticks;else if(!e.wield&&!e.cool&&e.ammo>0)return e.ammo--,e.shots=e.shots+1&255,e.cool=7,q.SHOT}return q.NONE},ct=(e,t,n,r)=>{let[i,a]=[e[0]-n.x,e[2]-n.z],o=t[0]*t[0]+t[2]*t[2],s=i*t[0]+a*t[2],c=s*s-o*(i*i+a*a-v*v),[l,u]=[0,1/0];if(o>1e-12){if(c<0)return 1/0;[l,u]=[(-s-Math.sqrt(c))/o,(-s+Math.sqrt(c))/o]}else if(i*i+a*a>.4*.4)return 1/0;let[d,f]=[n.y-e[1],n.y+r-e[1]];if(t[1])[l,u]=[Math.max(l,Math.min(d/t[1],f/t[1])),Math.min(u,Math.max(d/t[1],f/t[1]))];else if(d>0||f<0)return 1/0;return l<=u&&u>=0?Math.max(l,0):1/0},lt=(e,t,n)=>{let r=[t.x,t.y+Ae(t),t.z],[i,a,o,s]=[Math.sin(t.yaw),Math.cos(t.yaw),Math.sin(t.pitch),Math.cos(t.pitch)],c=[-i*s,o,-a*s],l=we(e,r,c,80),u;for(let e of n){let t=ct(r,c,e,L(e));t<l&&([l,u]=[t,e])}return u},ut=-30,J=(e,t,n,r,i,a=s.CONCRETE)=>({min:[e,ut,t],max:[n,i,r],top:s.CONCRETE,side:a}),Y=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c});[J(4,57.7,24,76,10),J(4,36,24,53.5,10,s.GLASS),J(4,20,24,36,12.4),J(4,-5,24,7,12.4,s.GLASS),J(27,20,47,50,8),J(27,60,47,76,8,s.BRICK),Y([9,12.2,39],[19,12.6,47],s.STEEL),...((e,t)=>[1,2,3,4,5,6].map(n=>Y([12,t,e-n],[14,t+.4*n,e-n+1],s.CONCRETE)))(53,10),Y([5,10,42],[5.5,14,42.5],s.STEEL),Y([5,10,50],[5.5,14,50.5],s.STEEL),Y([8,12.4,24],[20,12.85,24.45],s.STEEL),Y([36,8,22],[37,14.5,48],s.PAINT,s.PAINT,[.15,.72,.62]),Y([30,8,28],[34,10,32],s.CONCRETE),Y([40,8,30],[44,10.2,34],s.PAINT,s.PAINT,[1,.3,.06]),Y([28,9.2,44],[35,12,46],s.STEEL,s.PAINT,[.2,.42,1]),Y([41.5,7.6,50],[42,8,60],s.STEEL),Y([30,8,64],[34,9.6,68],s.PAINT,s.PAINT,[.2,.8,.3])];var X=240,Z=[1,.22,.26],dt=[.2,.46,1],ft=[1,.42,.08],pt=[.12,.7,.62],Q=(e,t,n,r,i,a,o)=>Y([e,t,n],[r,i,a],s.PAINT,s.PAINT,o),mt=(e,t,n,r,i,a,o,c=ut)=>{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?Y([f,c,r],[p,m,i],s.CONCRETE):Y([r,c,f],[i,m,p],s.CONCRETE)})},$=(e,t,n,r,i,a,o)=>o.map((o,c)=>Y([e+c*n,a,t+c*r],[e+c*n+4,o,t+c*r+i],s.STEEL,s.CONCRETE)),ht=[J(12,212,52,240,26,s.GLASS),Q(12,26,212,52,26.12,212.5,Z),Q(12,26,239.5,52,26.12,240,Z),Q(12,26,212.5,12.5,26.12,239.5,Z),Q(51.5,26,212.5,52,26.12,239.5,Z),Q(11.6,12,222,12,25.8,232,Z),Q(28,12,211.4,31,25.5,212,Z),Y([19,26,222],[22,27.4,225],s.STEEL),Y([42,26,222],[45,27.4,225],s.STEEL),Y([29,26,229],[35,27.1,229.6],s.CONCRETE),J(6,164,26,201,26,s.GLASS),J(6,134,26,147,26,s.GLASS),J(6,201,26,212,19),J(15,147,26,164,19),Y([14,26,164],[15,32,196],s.PAINT,s.PAINT,pt),Y([14,18,147],[15,32,164],s.PAINT,s.PAINT,pt),Y([14,26,134],[15,32,147],s.PAINT,s.PAINT,pt),...$(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])=>Y([e,19,t],[n,i,r],s.STEEL,s.CONCRETE)),Y([20,26,178],[23,27.3,181],s.STEEL),Y([8,26,176],[11,27.2,179],s.STEEL),Y([8,26,190],[11,27.3,193],s.STEEL),Y([20,26,140],[23,27.3,143],s.STEEL),J(32,186,76,209,19),Q(32,19,207.5,76,19.1,209,Z),...$(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])=>Y([e,ut,t],[n,i,r],s.STEEL,s.CONCRETE)),J(32,166,64,182,21.2,s.GLASS),J(32,140,64,161,19),Y([40,21.2,172],[44,22.6,176],s.STEEL),Y([52,19,148],[57,20.3,151],s.STEEL),Y([38,19,196],[41,20.4,199],s.STEEL),Y([60,19,200],[63,20.4,203],s.STEEL),Y([52,19,190],[58,20.6,194],s.STEEL),Y([66,19,204],[72,20.2,207],s.STEEL),Y([56,21.2,170],[60,22.4,174],s.STEEL),Y([34,19,152],[37,20.3,156],s.STEEL),...$(36,135,18,0,3,15,[17.2,17.2]),...$(6.5,129,6,0,4,15,[17.2,19.4,21.6,23.8]),J(76,213,100,240,14.5,s.STEEL),Q(76,14.5,238.5,100,14.6,240,Z),J(76,185,100,209,14.5),J(76,138,100,181,14.5,s.GLASS),Y([80,15.7,158],[96,17.7,162],s.STEEL,s.PAINT,ft),Y([82,14.5,234],[85,15.9,237],s.STEEL),Y([91,14.5,190],[94,15.9,193],s.STEEL),Y([80,14.5,204],[83,15.6,207],s.STEEL),Y([78,14.5,170],[81,15.9,173],s.STEEL),Y([92,14.5,146],[95,15.7,149],s.STEEL),Y([92,14.5,222],[96,15.8,226],s.STEEL),...mt(0,76,52,226,232,14.5,26),...mt(0,85,76,196,202,14.5,19,14.5)],gt=[J(6,106,62,134,15),J(62,106,100,134,14.5),Y([34,15,112],[54,17.2,128],s.CONCRETE),Q(38,17.2,116,50,17.3,124,ft),...[[35,113],[35,126.2],[51,113],[51,126.2]].map(([e,t])=>Y([e,17.2,t],[e+.8,21.5,t+.8],s.STEEL)),Y([34.6,21.5,112.6],[52.2,21.9,127.4],s.GLASS),Y([14,15,114],[17,16.5,117],s.STEEL),Y([14,15,123],[17,16.5,126],s.STEEL),Y([56,15,114],[59,16.5,117],s.STEEL),Y([56,15,123],[59,16.5,126],s.STEEL),Y([15.35,25.5,106],[15.85,26,134],s.STEEL),Y([70,14.5,108],[70.8,38,108.8],s.STEEL),Y([70,14.5,131.2],[70.8,38,132],s.STEEL),Y([66,14.5,110],[69,15.9,113],s.STEEL),Y([66,14.5,127],[69,15.9,130],s.STEEL)],_t=e=>({...e,min:[e.min[0],e.min[1],X-e.max[2]],max:[e.max[0],e.max[1],X-e.min[2]],tint:e.tint===Z?dt:e.tint}),vt=(e,t,n)=>[...[16,22,28,34,40].map(n=>[n,26,t,e]),...[19,31,43].map(t=>[t,26,n,e])],yt=[[20,26,190],[48,21.2,172],[48,19,200],[88,14.5,198]],bt=[[21,26,168],[46,19,144],[36,21.2,178],[88,14.5,216],[88,14.5,172]],xt={name:`Highline`,brushes:[...ht,...ht.map(_t),...gt],teams:[{base:[32,26,224],spawns:vt(0,236,231),rack:[47,26,234],blade:[47,26,231.5]},{base:[32,26,16],spawns:vt(Math.PI,4,9),rack:[47,26,6],blade:[47,26,8.5]}],packs:[...yt,...yt.map(([e,t,n])=>[e,t,X-n]),[24,15,112],[24,15,128]],ammo:[...bt,...bt.map(([e,t,n])=>[e,t,X-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]},St=e=>e.mode===i.SLIDE||e.dash>50,Ct=(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),wt=20,Tt=2,Et=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),Dt=e=>Et((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),Ot=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${Et(e,15-`${r}`.length)} ${r}`;return n},kt=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},At=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];world;ctf;halt;rules;rr=[0,0];gone;constructor(e={},t=xt){this.rules={...be,...e},this.world=Ce(t),this.ctf=new it(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&&g(t);if(r&&n.bank>0){n.bank--;let e=st(n.state,r,this.world,n.info.team,!this.ctf.over);this.ctf.moved(n.state),this.tackle(n,r.view),e===q.SHOT?this.shoot(n,r.view):e===q.CUT&&this.cut(n,r.view),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)return;let t=++this.ticks;for(let t of e)t.bank=Math.min(10,t.bank+1);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=ee({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});e.forEach(e=>e.conn.send(n))}}start(e=kt){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<wt;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||!St(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=>Ct(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=je(n),[s,c]=o>.001?[n.vx/o,n.vz/o]:A(n.yaw);ze(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,blade:!1,wield:!1,swing:0,lost:r.NONE}),this.ctf.drop(e.state),!0)}shoot(e,t){let n=this.players().find(n=>n.info.id===lt(this.world,e.state,this.enemies(e,t))?.id);n&&(e.state.hits=e.state.hits+1&255,this.harm(n,1))}cut(e,t){let n=et(this.world,e.state,this.enemies(e,t)),r=this.players().filter(e=>n.some(t=>t.id===e.info.id));if(!r.length)return;e.state.hits=e.state.hits+1&255;let[i,a]=tt(e.state);for(let t of r)if(this.harm(t,x[e.state.cut??0].hp)){let r=n.find(e=>e.id===t.info.id);t.state.lost=nt(e.state,r)}else ze(t.state,i,a,24,4),t.state.zap=!0,t.by=e.info.id}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)&&ot(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}=F(e,this.world,i,t);return!n.some(e=>Math.hypot(e.x-a,e.z-o)<Tt)});return F(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:Ot(Dt(t)||`Player ${r}`,n.map(e=>e.info.name)),team:a,color:ge[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})))}},jt=(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()},Mt=(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},ee=e=>{if(p)return e();l=e,u=r,c=/* @__PURE__ */ new Map,s=new At(t),s.start(jt),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 v=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:v,close:y};return o?o.request(n,{signal:a.signal},()=>new Promise(ee)).catch(()=>{}):ee(()=>{}),m({kind:`q`}),globalThis.addEventListener?.(`pagehide`,y),setTimeout(()=>!p&&b.onopen?.()),b};export{Mt as localSocket};
|
package/dist/server.js
CHANGED
|
@@ -40,38 +40,49 @@ var CUTS = [
|
|
|
40
40
|
(
|
|
41
41
|
/** THRUST: quick and the longest, a narrow line. */
|
|
42
42
|
{
|
|
43
|
-
ticks:
|
|
44
|
-
strike:
|
|
45
|
-
reach: 2.
|
|
43
|
+
ticks: 28,
|
|
44
|
+
strike: 10,
|
|
45
|
+
reach: 2.65,
|
|
46
46
|
arc: .3,
|
|
47
47
|
hp: 2
|
|
48
48
|
}),
|
|
49
49
|
(
|
|
50
50
|
/** LEFT, then RIGHT: across, a wide arc. */
|
|
51
51
|
{
|
|
52
|
-
ticks:
|
|
53
|
-
strike:
|
|
54
|
-
reach:
|
|
52
|
+
ticks: 34,
|
|
53
|
+
strike: 13,
|
|
54
|
+
reach: 2.15,
|
|
55
55
|
arc: 1.2,
|
|
56
56
|
hp: 2
|
|
57
57
|
}),
|
|
58
58
|
{
|
|
59
|
-
ticks:
|
|
60
|
-
strike:
|
|
61
|
-
reach:
|
|
59
|
+
ticks: 34,
|
|
60
|
+
strike: 13,
|
|
61
|
+
reach: 2.15,
|
|
62
62
|
arc: 1.2,
|
|
63
63
|
hp: 2
|
|
64
64
|
},
|
|
65
65
|
(
|
|
66
66
|
/** SLASH: down from above, the slowest and the hardest. */
|
|
67
67
|
{
|
|
68
|
-
ticks:
|
|
69
|
-
strike:
|
|
70
|
-
reach:
|
|
68
|
+
ticks: 40,
|
|
69
|
+
strike: 16,
|
|
70
|
+
reach: 2.15,
|
|
71
71
|
arc: .45,
|
|
72
72
|
hp: 3
|
|
73
73
|
})
|
|
74
74
|
];
|
|
75
|
+
/**
|
|
76
|
+
* Where a finishing cut crosses the body, as a share of its height from the feet, picks the limb
|
|
77
|
+
* (limbOf(), blade.ts): above NECK the head, below HIPS a leg, between them an arm. A thrust or a
|
|
78
|
+
* slash whose line passes within MIDLINE metres of the body's middle takes no arm: the slash takes
|
|
79
|
+
* the head, the thrust nothing unless it is above NECK.
|
|
80
|
+
*/
|
|
81
|
+
var [NECK, HIPS, MIDLINE] = [
|
|
82
|
+
.82,
|
|
83
|
+
.45,
|
|
84
|
+
.12
|
|
85
|
+
];
|
|
75
86
|
var RULES = {
|
|
76
87
|
maxPlayers: 16,
|
|
77
88
|
scoreLimit: 3,
|
|
@@ -116,6 +127,18 @@ var CUT = {
|
|
|
116
127
|
RIGHT: 2,
|
|
117
128
|
SLASH: 3
|
|
118
129
|
};
|
|
130
|
+
/**
|
|
131
|
+
* The limb a katana's cut takes off when it puts a player down (PlayerState.lost), by where the
|
|
132
|
+
* blade crosses the body (see limbOf(), blade.ts). Sides are the victim's own.
|
|
133
|
+
*/
|
|
134
|
+
var LIMB = {
|
|
135
|
+
NONE: 0,
|
|
136
|
+
HEAD: 1,
|
|
137
|
+
ARM_L: 2,
|
|
138
|
+
ARM_R: 3,
|
|
139
|
+
LEG_L: 4,
|
|
140
|
+
LEG_R: 5
|
|
141
|
+
};
|
|
119
142
|
/** The movement state of a player: what the body is doing, one of these. */
|
|
120
143
|
var MODE = {
|
|
121
144
|
/** Standing or running on a floor. */
|
|
@@ -341,6 +364,7 @@ var STILL = {
|
|
|
341
364
|
swing: 0,
|
|
342
365
|
cut: 0,
|
|
343
366
|
zap: false,
|
|
367
|
+
lost: LIMB.NONE,
|
|
344
368
|
ev: 0,
|
|
345
369
|
fall: 0
|
|
346
370
|
};
|
|
@@ -1035,6 +1059,32 @@ var knock = (p) => {
|
|
|
1035
1059
|
const c = p.cut ?? 0;
|
|
1036
1060
|
return c === CUT.LEFT ? [-fz, fx] : c === CUT.RIGHT ? [fz, -fx] : [fx, fz];
|
|
1037
1061
|
};
|
|
1062
|
+
/**
|
|
1063
|
+
* The LIMB the cut of `p` (the state after the step that struck) takes off `f` (as he saw him) when
|
|
1064
|
+
* it puts him down. The blade's line is his look from his chest (CHEST of his height), so a level
|
|
1065
|
+
* cut meets the foe's arms. It enters the foe's body (a circle of PLAYER_R on the floor plane) on
|
|
1066
|
+
* the near side; the side is the foe's own, measured where it enters, on his right axis. A slash
|
|
1067
|
+
* takes the head within MIDLINE of his middle, else the arm on that side. A thrust and a cut across
|
|
1068
|
+
* go by the line's height at the foe's distance, as a share of his height: above NECK the head,
|
|
1069
|
+
* below HIPS a leg, else an arm. A cut across takes the side facing where it comes from; a thrust
|
|
1070
|
+
* the side it enters, and no arm within MIDLINE of his middle.
|
|
1071
|
+
*/
|
|
1072
|
+
var limbOf = (p, f) => {
|
|
1073
|
+
const [fx, fz] = forward(p.yaw);
|
|
1074
|
+
const [gx, gz] = forward(f.yaw);
|
|
1075
|
+
const [dx, dz] = [f.x - p.x, f.z - p.z];
|
|
1076
|
+
const o = -fz * dx + fx * dz;
|
|
1077
|
+
const back = Math.sqrt(Math.max(PLAYER_R * PLAYER_R - o * o, 0));
|
|
1078
|
+
const [ex, ez] = [fz * o - fx * back, -fx * o - fz * back];
|
|
1079
|
+
const s = -gz * ex + gx * ez;
|
|
1080
|
+
const c = p.cut ?? 0;
|
|
1081
|
+
if (c === CUT.SLASH) return Math.abs(s) <= MIDLINE ? LIMB.HEAD : s > 0 ? LIMB.ARM_R : LIMB.ARM_L;
|
|
1082
|
+
const share = (p.y + CHEST * heightOf(p) + Math.tan(p.pitch) * Math.hypot(dx, dz) - f.y) / heightOf(f);
|
|
1083
|
+
if (share > NECK) return LIMB.HEAD;
|
|
1084
|
+
const right = c === CUT.THRUST ? s > 0 : (c === CUT.LEFT ? 1 : -1) * (fx * gx + fz * gz) < 0;
|
|
1085
|
+
if (share < HIPS) return right ? LIMB.LEG_R : LIMB.LEG_L;
|
|
1086
|
+
return c === CUT.THRUST && Math.abs(s) <= MIDLINE ? LIMB.NONE : right ? LIMB.ARM_R : LIMB.ARM_L;
|
|
1087
|
+
};
|
|
1038
1088
|
// src/shared/ctf.ts
|
|
1039
1089
|
var home = () => ({
|
|
1040
1090
|
state: FLAG.HOME,
|
|
@@ -2277,13 +2327,13 @@ var decodeInput = (buf) => {
|
|
|
2277
2327
|
/** Bytes of a flag on the wire, by its state. */
|
|
2278
2328
|
var flagBytes = (state) => state === FLAG.CARRIED ? 2 : state === FLAG.DROPPED ? 8 : 1;
|
|
2279
2329
|
var encodeSnapshot = (s) => {
|
|
2280
|
-
const end = 4 +
|
|
2330
|
+
const end = 4 + 47 * s.players.length;
|
|
2281
2331
|
const v = new DataView(new ArrayBuffer(end + 8 + s.flags.reduce((n, f) => n + flagBytes(f.state), 0)));
|
|
2282
2332
|
v.setUint8(0, 2);
|
|
2283
2333
|
v.setUint16(1, s.tick & 65535);
|
|
2284
2334
|
v.setUint8(3, s.players.length);
|
|
2285
2335
|
s.players.forEach((p, i) => {
|
|
2286
|
-
const o = 4 + i *
|
|
2336
|
+
const o = 4 + i * 47;
|
|
2287
2337
|
v.setUint8(o, p.id);
|
|
2288
2338
|
v.setFloat32(o + 1, p.x);
|
|
2289
2339
|
v.setFloat32(o + 5, p.y);
|
|
@@ -2306,6 +2356,7 @@ var encodeSnapshot = (s) => {
|
|
|
2306
2356
|
v.setUint8(o + 43, p.shots);
|
|
2307
2357
|
v.setUint8(o + 44, p.hits);
|
|
2308
2358
|
v.setUint8(o + 45, (p.swing ?? 0) & 63 | ((p.cut ?? 0) & 3) << 6);
|
|
2359
|
+
v.setUint8(o + 46, (p.lost ?? 0) & 7);
|
|
2309
2360
|
});
|
|
2310
2361
|
v.setUint8(end, s.score[0]);
|
|
2311
2362
|
v.setUint8(end + 1, s.score[1]);
|
|
@@ -2570,7 +2621,8 @@ var Room = class {
|
|
|
2570
2621
|
}
|
|
2571
2622
|
/**
|
|
2572
2623
|
* `hp` of damage to `foe`; the last one puts him down: he lies where he fell, without the gun or
|
|
2573
|
-
* the katana,
|
|
2624
|
+
* the katana, a flag he carries drops with the lock, and `lost` is NONE (a cut sets it after).
|
|
2625
|
+
* True when he went down.
|
|
2574
2626
|
*/
|
|
2575
2627
|
harm(foe, hp) {
|
|
2576
2628
|
if ((foe.state.hp -= hp) > 0) return false;
|
|
@@ -2581,7 +2633,8 @@ var Room = class {
|
|
|
2581
2633
|
cool: 0,
|
|
2582
2634
|
blade: false,
|
|
2583
2635
|
wield: false,
|
|
2584
|
-
swing: 0
|
|
2636
|
+
swing: 0,
|
|
2637
|
+
lost: LIMB.NONE
|
|
2585
2638
|
});
|
|
2586
2639
|
this.ctf.drop(foe.state);
|
|
2587
2640
|
return true;
|
|
@@ -2600,15 +2653,19 @@ var Room = class {
|
|
|
2600
2653
|
* A cut of `p` struck at the view tick `view`: every enemy it reaches as `p` drew him is hit
|
|
2601
2654
|
* (`strike`), and the `hits` count goes up once. Each takes the cut's hp; one it does not put
|
|
2602
2655
|
* down is shocked: a stumble of SHOCK_TICKS thrown SHOCK_KNOCK m/s the way the blade goes, with
|
|
2603
|
-
* `zap`, and `by` the attacker. A shock drops no flag.
|
|
2656
|
+
* `zap`, and `by` the attacker. A shock drops no flag. One it puts down loses the limb the blade
|
|
2657
|
+
* crosses where `p` drew him (`limbOf`).
|
|
2604
2658
|
*/
|
|
2605
2659
|
cut(p, view) {
|
|
2606
|
-
const seen = strike(this.world, p.state, this.enemies(p, view))
|
|
2607
|
-
const foes = this.players().filter((q) => seen.
|
|
2660
|
+
const seen = strike(this.world, p.state, this.enemies(p, view));
|
|
2661
|
+
const foes = this.players().filter((q) => seen.some((s) => s.id === q.info.id));
|
|
2608
2662
|
if (!foes.length) return;
|
|
2609
2663
|
p.state.hits = p.state.hits + 1 & 255;
|
|
2610
2664
|
const [dx, dz] = knock(p.state);
|
|
2611
|
-
for (const foe of foes) if (
|
|
2665
|
+
for (const foe of foes) if (this.harm(foe, CUTS[p.state.cut ?? 0].hp)) {
|
|
2666
|
+
const drawn = seen.find((s) => s.id === foe.info.id);
|
|
2667
|
+
foe.state.lost = limbOf(p.state, drawn);
|
|
2668
|
+
} else {
|
|
2612
2669
|
stumble(foe.state, dx, dz, 24, 4);
|
|
2613
2670
|
foe.state.zap = true;
|
|
2614
2671
|
foe.by = p.info.id;
|
|
@@ -9,6 +9,8 @@ export interface Tracer {
|
|
|
9
9
|
shock(at: Vec3): void;
|
|
10
10
|
/** One frame of the crackle around a shocked runner whose middle is `at`: a few bolts, flickering. */
|
|
11
11
|
crackle(at: Vec3): void;
|
|
12
|
+
/** One spark out of `at`, up and a little aside: a cut limb's stump spitting. */
|
|
13
|
+
spit(at: Vec3): void;
|
|
12
14
|
/** Where the own muzzle is now: the own beams start there, so that a kick of the view does not swing them. */
|
|
13
15
|
mount(a: Vec3): void;
|
|
14
16
|
/** Ages everything by dt seconds and drops what is over. */
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { PlayerState } from '../shared/types';
|
|
2
2
|
import type { Vec3 } from './mesh';
|
|
3
3
|
import type { Quat } from './rig';
|
|
4
|
-
/** Where the blade starts and ends along the model's forward axis, metres from the right hand. */
|
|
4
|
+
/** Where the blade starts and ends along the model's forward axis, metres from the right hand: a metre from the guard to the point. */
|
|
5
5
|
export declare const BASE: number, TIP: number;
|
|
6
|
+
/** The left hand grips this far behind the right one: a gap between the two fists. */
|
|
7
|
+
export declare const BEHIND = 0.14;
|
|
6
8
|
/**
|
|
7
9
|
* The katana at a level of detail (0 far, 1 near), built once, in the vertex format of mesh.ts: the
|
|
8
10
|
* blade (bevelled edge, a ridge, a spine, a point), a thin cyan glow along its edge, a collar, a
|
|
@@ -34,10 +36,11 @@ export declare const ends: (pos: Vec3, q: Quat) => Vec3[];
|
|
|
34
36
|
export declare const frameOf: (d: Vec3, roll: number) => Vec3[];
|
|
35
37
|
/**
|
|
36
38
|
* The cuts. Each is keys of [share of the swing, grip x, y, z, blade direction x, y, z, roll] in
|
|
37
|
-
* the camera's space (right, up, forward), the guard first
|
|
38
|
-
*
|
|
39
|
-
* the
|
|
40
|
-
*
|
|
39
|
+
* the camera's space (right, up, forward), the guard first and last: a wind-up, the strike at its
|
|
40
|
+
* tick (every cut passes the middle of the view there) and a follow-through, with the hands taking
|
|
41
|
+
* the slope between their neighbours' keys (fastest through the strike). Both hands hold the grip,
|
|
42
|
+
* the left BEHIND the right. The wind-ups and follow-throughs go out of the view. The guard is
|
|
43
|
+
* rolled a little, its flat toward the eye.
|
|
41
44
|
*/
|
|
42
45
|
export declare const GUARD: number[];
|
|
43
46
|
/** The grip and the blade direction (x, y, z each) and the roll of cut `cut` at `p` of the swing: one array, rewritten by each call. */
|
|
@@ -48,5 +51,5 @@ export declare const stroke: (cut: number, p: number) => number[];
|
|
|
48
51
|
* time, never more than two ticks ahead of the count, never behind it. `was` is the last answer.
|
|
49
52
|
*/
|
|
50
53
|
export declare const progress: (was: number, p: Pick<PlayerState, "swing" | "cut">, dt: number) => number;
|
|
51
|
-
/** Whether the blade is cutting at `p` of its swing: the wind-up and the recovery leave no trail. */
|
|
54
|
+
/** Whether the blade is cutting at `p` of its swing: the wind-up, over by 0.22 to 0.27, and the recovery leave no trail. */
|
|
52
55
|
export declare const cutting: (p: number) => boolean;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { PlayerState } from '../shared/types';
|
|
2
|
+
import type { World } from '../shared/world';
|
|
3
|
+
import type { Tracer } from './beams';
|
|
4
|
+
import type { Gait } from './gait';
|
|
5
|
+
import type { Vec3 } from './mesh';
|
|
6
|
+
import { solve } from './rig';
|
|
7
|
+
import type { Quat } from './rig';
|
|
8
|
+
/** The height of the floor under (x, z) for something whose middle is at height y. */
|
|
9
|
+
export type Ground = (x: number, y: number, z: number) => number;
|
|
10
|
+
/** The first top under a point, none (it falls out of sight) off the roofs; without a world, the height `y0`. */
|
|
11
|
+
export declare const ground: (world: World | undefined, y0: number) => Ground;
|
|
12
|
+
export interface Piece {
|
|
13
|
+
limb: number;
|
|
14
|
+
/** The joints in the pose of the cut, which the limb is skinned with, and its middle then. */
|
|
15
|
+
s: ReturnType<typeof solve>;
|
|
16
|
+
c: Vec3;
|
|
17
|
+
/** Its points around that middle, for the floor, and its long axis, middle away from the cut. */
|
|
18
|
+
pts: Vec3[];
|
|
19
|
+
long: Vec3;
|
|
20
|
+
/** Where its middle is now, its velocity, its turn since the cut and its spin (axis times rad/s). */
|
|
21
|
+
p: Vec3;
|
|
22
|
+
v: Vec3;
|
|
23
|
+
q: Quat;
|
|
24
|
+
w: Vec3;
|
|
25
|
+
/** The stump's cut face on the body (soldier() keeps it there), and seconds since the cut. */
|
|
26
|
+
at: Vec3;
|
|
27
|
+
age: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The limb `limb` of `p` coming off the body posed as `s`: thrown with the body's speed, a little
|
|
31
|
+
* outward (and back) from the hips and up, tumbling outward.
|
|
32
|
+
*/
|
|
33
|
+
export declare const sever: (limb: number, s: ReturnType<typeof solve>, p: PlayerState) => Piece;
|
|
34
|
+
/**
|
|
35
|
+
* One step of dt seconds of a piece's fall: gravity and spin, then the floor under it, which it
|
|
36
|
+
* bounces off, rubs along and lies down on (its long axis toppling to the level).
|
|
37
|
+
*/
|
|
38
|
+
export declare const fall: (c: Piece, dt: number, floor: Ground) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Keeps the piece of a runner in step with its player `r.p`: made when `lost` is set while down,
|
|
41
|
+
* with a burst of sparks at the cut, or already lying when the runner was `fresh` (first seen that
|
|
42
|
+
* way); moved by dt, the stump spitting; forgotten once he is up.
|
|
43
|
+
*/
|
|
44
|
+
export declare const track: (r: {
|
|
45
|
+
p: PlayerState;
|
|
46
|
+
gait: Pick<Gait, "pose">;
|
|
47
|
+
cut?: Piece;
|
|
48
|
+
}, dt: number, floor: Ground, fresh: boolean, tracer?: Pick<Tracer, "shock" | "spit">) => void;
|
|
49
|
+
/** Appends the piece at level of detail `lod`, in `colors` (see palette()), sunk by `sink` metres with the body. */
|
|
50
|
+
export declare const piece: (out: number[], c: Piece, colors: number[][], lod: number, sink: number) => void;
|
|
@@ -52,6 +52,8 @@ export declare const SOUND: {
|
|
|
52
52
|
readonly SHING: 23;
|
|
53
53
|
readonly SWISH: 24;
|
|
54
54
|
readonly ZAP: 25;
|
|
55
|
+
/** A plasma ball bursting on a wall or a body. */
|
|
56
|
+
readonly SPLASH: 26;
|
|
55
57
|
};
|
|
56
58
|
/**
|
|
57
59
|
* The sounds of the game: one entry per sound, its voices layered, in SOUND order. A low-passed
|
|
@@ -71,9 +73,12 @@ export declare const render: (id: number, layers?: Voice[][]) => Float32Array;
|
|
|
71
73
|
* volume, nothing but noise), whose own ends are no longer heard.
|
|
72
74
|
*/
|
|
73
75
|
export declare const seam: (s: Float32Array, x?: number) => Float32Array;
|
|
76
|
+
/** The music's sample rate: half, as nothing in it but the hats goes past 4 kHz. */
|
|
77
|
+
export declare const MUSIC_RATE: number;
|
|
74
78
|
/**
|
|
75
|
-
* The music:
|
|
76
|
-
*
|
|
77
|
-
*
|
|
79
|
+
* The music: sixteen bars in D major at 84 bpm (whole beats, whole samples), slow pads, sparse
|
|
80
|
+
* bells with an echo, soft hats and a muted pulse; mono samples in [-1, 1] at MUSIC_RATE,
|
|
81
|
+
* deterministic, whose end joins its start (every tail wraps onto the start). Quiet enough to sit
|
|
82
|
+
* under the sounds.
|
|
78
83
|
*/
|
|
79
84
|
export declare const music: () => Float32Array;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Quat } from './rig';
|
|
2
2
|
import type { Vec3 } from './mesh';
|
|
3
|
-
/** Jacket, its darker trim, trousers, skin, hair, shoe upper, sole, gloves and
|
|
3
|
+
/** Jacket, its darker trim, trousers, skin, hair, shoe upper, sole, gloves, shades and the cut's cauterized face, which glows. */
|
|
4
4
|
export declare const palette: (jacket: number[]) => number[][];
|
|
5
5
|
/** The ring where the eye's sleeve ends in the glove, which body.ts starts the palm on, and its sides. */
|
|
6
6
|
export declare const CUFF: number[];
|
|
@@ -13,9 +13,16 @@ export interface Skin {
|
|
|
13
13
|
/** Three vertex indices per triangle, and the palette colour of each. */
|
|
14
14
|
t: Uint16Array;
|
|
15
15
|
c: Uint8Array;
|
|
16
|
+
/** Per triangle the LIMB it comes off with, NONE for the trunk's. */
|
|
17
|
+
l?: Uint8Array;
|
|
16
18
|
}
|
|
17
19
|
/** The skin at a level of detail (see DETAIL in mesh.ts): 0 far, 1 near, 2 near, headless and handless, for the eye. Built once. */
|
|
18
20
|
export declare const body: (lod: number) => Skin;
|
|
21
|
+
/**
|
|
22
|
+
* The skin at a level of detail without the LIMB `limb`, then the limb alone, each closed by a
|
|
23
|
+
* glowing cut face whose middle is the last vertex of the last triangle. Built once.
|
|
24
|
+
*/
|
|
25
|
+
export declare const cut: (lod: number, limb: number) => Skin[];
|
|
19
26
|
/**
|
|
20
27
|
* Appends the skin in the pose `solved` (see solve()) to `out` as triangles in the renderer's
|
|
21
28
|
* vertex format, each in its palette colour: a vertex goes where the two joints it hangs on would
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { PlayerState } from '../shared/types';
|
|
2
2
|
import type { World } from '../shared/world';
|
|
3
3
|
import type { Gait } from './gait';
|
|
4
|
+
import type { Tracer } from './beams';
|
|
5
|
+
import type { Piece } from './limbs';
|
|
4
6
|
import type { Vec3 } from './mesh';
|
|
7
|
+
import type { Pose } from './rig';
|
|
5
8
|
import type { Trail } from './trail';
|
|
6
9
|
/** What a runner keeps between frames. */
|
|
7
10
|
export interface Runner {
|
|
@@ -19,15 +22,23 @@ export interface Runner {
|
|
|
19
22
|
prog: number;
|
|
20
23
|
trail: Trail;
|
|
21
24
|
t: number;
|
|
25
|
+
/** The limb a katana's cut took off, while he is down (see limbs.ts). */
|
|
26
|
+
cut?: Piece;
|
|
22
27
|
}
|
|
23
28
|
/** A runner as first seen: in the pose its state asks for, no ease. */
|
|
24
29
|
export declare const createRunner: (p: PlayerState) => Runner;
|
|
25
30
|
/**
|
|
26
31
|
* Moves each runner of `book` to its player in `others` after dt seconds: a new player gets a
|
|
27
32
|
* runner already in pose, one that left loses it. With a `world` the feet stand on the brushes
|
|
28
|
-
* under them.
|
|
33
|
+
* under them. The `tracer` gets the sparks of a limb cut off.
|
|
29
34
|
*/
|
|
30
|
-
export declare const animate: (book: Map<number, Runner>, others: PlayerState[], dt: number, world?: World) => void;
|
|
35
|
+
export declare const animate: (book: Map<number, Runner>, others: PlayerState[], dt: number, world?: World, tracer?: Pick<Tracer, "shock" | "spit">) => void;
|
|
36
|
+
/**
|
|
37
|
+
* The pose with the katana in both hands: carried, or in a cut, which is the first person's cut
|
|
38
|
+
* seen from the runner's eye (the share `e` of it, so that it is drawn from the carry and back to
|
|
39
|
+
* it), the trunk turning with the blade and leaning into the lunge and the low finish.
|
|
40
|
+
*/
|
|
41
|
+
export declare const brandish: (pose: Pose, p: PlayerState, prog: number, ph: number) => Pose;
|
|
31
42
|
/**
|
|
32
43
|
* Appends a runner at level of detail `lod` (see body()): the jacket in `color` (r, g, b), dark
|
|
33
44
|
* trousers, skin, hair and light shoes, posed by its gait. A dash trails a few glowing streaks.
|
|
@@ -18,3 +18,14 @@ export declare const strike: (w: World, p: PlayerState, foes: PlayerState[]) =>
|
|
|
18
18
|
* so LEFT throws to his right and RIGHT to his left.
|
|
19
19
|
*/
|
|
20
20
|
export declare const knock: (p: PlayerState) => [x: number, z: number];
|
|
21
|
+
/**
|
|
22
|
+
* The LIMB the cut of `p` (the state after the step that struck) takes off `f` (as he saw him) when
|
|
23
|
+
* it puts him down. The blade's line is his look from his chest (CHEST of his height), so a level
|
|
24
|
+
* cut meets the foe's arms. It enters the foe's body (a circle of PLAYER_R on the floor plane) on
|
|
25
|
+
* the near side; the side is the foe's own, measured where it enters, on his right axis. A slash
|
|
26
|
+
* takes the head within MIDLINE of his middle, else the arm on that side. A thrust and a cut across
|
|
27
|
+
* go by the line's height at the foe's distance, as a share of his height: above NECK the head,
|
|
28
|
+
* below HIPS a leg, else an arm. A cut across takes the side facing where it comes from; a thrust
|
|
29
|
+
* the side it enters, and no arm within MIDLINE of his middle.
|
|
30
|
+
*/
|
|
31
|
+
export declare const limbOf: (p: PlayerState, f: PlayerState) => number;
|
|
@@ -200,6 +200,13 @@ export declare const CUTS: {
|
|
|
200
200
|
arc: number;
|
|
201
201
|
hp: number;
|
|
202
202
|
}[];
|
|
203
|
+
/**
|
|
204
|
+
* Where a finishing cut crosses the body, as a share of its height from the feet, picks the limb
|
|
205
|
+
* (limbOf(), blade.ts): above NECK the head, below HIPS a leg, between them an arm. A thrust or a
|
|
206
|
+
* slash whose line passes within MIDLINE metres of the body's middle takes no arm: the slash takes
|
|
207
|
+
* the head, the thrust nothing unless it is above NECK.
|
|
208
|
+
*/
|
|
209
|
+
export declare const NECK: number, HIPS: number, MIDLINE: number;
|
|
203
210
|
/**
|
|
204
211
|
* A cut that does not put the enemy down shocks him: a stumble (`stumble()`, physics.ts) of
|
|
205
212
|
* SHOCK_TICKS (0.4 s), thrown SHOCK_KNOCK m/s the way the blade goes.
|
|
@@ -28,7 +28,7 @@ export declare const MSG_INPUT = 1;
|
|
|
28
28
|
export declare const MSG_SNAPSHOT = 2;
|
|
29
29
|
export declare const INPUT_BYTES = 12;
|
|
30
30
|
export declare const SNAP_HEAD = 4;
|
|
31
|
-
export declare const SNAP_PLAYER =
|
|
31
|
+
export declare const SNAP_PLAYER = 47;
|
|
32
32
|
/** The match block after the players: the captures, the clock, the packs; the flags follow (2 to 16 bytes). */
|
|
33
33
|
export declare const SNAP_MATCH = 8;
|
|
34
34
|
/**
|
|
@@ -78,7 +78,8 @@ export declare class Room {
|
|
|
78
78
|
private enemies;
|
|
79
79
|
/**
|
|
80
80
|
* `hp` of damage to `foe`; the last one puts him down: he lies where he fell, without the gun or
|
|
81
|
-
* the katana,
|
|
81
|
+
* the katana, a flag he carries drops with the lock, and `lost` is NONE (a cut sets it after).
|
|
82
|
+
* True when he went down.
|
|
82
83
|
*/
|
|
83
84
|
private harm;
|
|
84
85
|
/**
|
|
@@ -90,7 +91,8 @@ export declare class Room {
|
|
|
90
91
|
* A cut of `p` struck at the view tick `view`: every enemy it reaches as `p` drew him is hit
|
|
91
92
|
* (`strike`), and the `hits` count goes up once. Each takes the cut's hp; one it does not put
|
|
92
93
|
* down is shocked: a stumble of SHOCK_TICKS thrown SHOCK_KNOCK m/s the way the blade goes, with
|
|
93
|
-
* `zap`, and `by` the attacker. A shock drops no flag.
|
|
94
|
+
* `zap`, and `by` the attacker. A shock drops no flag. One it puts down loses the limb the blade
|
|
95
|
+
* crosses where `p` drew him (`limbOf`).
|
|
94
96
|
*/
|
|
95
97
|
private cut;
|
|
96
98
|
/**
|
|
@@ -49,6 +49,18 @@ export declare const CUT: {
|
|
|
49
49
|
readonly RIGHT: 2;
|
|
50
50
|
readonly SLASH: 3;
|
|
51
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* The limb a katana's cut takes off when it puts a player down (PlayerState.lost), by where the
|
|
54
|
+
* blade crosses the body (see limbOf(), blade.ts). Sides are the victim's own.
|
|
55
|
+
*/
|
|
56
|
+
export declare const LIMB: {
|
|
57
|
+
readonly NONE: 0;
|
|
58
|
+
readonly HEAD: 1;
|
|
59
|
+
readonly ARM_L: 2;
|
|
60
|
+
readonly ARM_R: 3;
|
|
61
|
+
readonly LEG_L: 4;
|
|
62
|
+
readonly LEG_R: 5;
|
|
63
|
+
};
|
|
52
64
|
/** The movement state of a player: what the body is doing, one of these. */
|
|
53
65
|
export declare const MODE: {
|
|
54
66
|
/** Standing or running on a floor. */
|
|
@@ -173,6 +185,8 @@ export interface PlayerState {
|
|
|
173
185
|
cut?: number;
|
|
174
186
|
/** The running stumble (`stun`) is a katana's shock, not a tackle. Absent reads false. */
|
|
175
187
|
zap?: boolean;
|
|
188
|
+
/** While down after a katana's cut put him down: the LIMB it took off, for the clients to draw. NONE once up. Absent reads NONE. */
|
|
189
|
+
lost?: number;
|
|
176
190
|
/** For the animation, not sent: the EV bits of the last step, and the speed of a landing. */
|
|
177
191
|
ev: number;
|
|
178
192
|
fall: number;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@korial29/tiny-fps",
|
|
3
3
|
"description": "Tiny multiplayer first-person rooftop game for the browser: raw WebGL, zero runtime dependencies, WebSocket or same-browser multi-tab play.",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.33.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|