Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";function BulletActor(e){this.bullet=e,this.mesh=Meshes.bullet.createInstance(""),this.mesh.setEnabled(!1)}function loadResources(e){function t(){++a==o.length&&e()}Meshes={},Sounds={},(Materials={}).bullet=new BABYLON.StandardMaterial("bulletMaterial",scene),Materials.bullet.emissiveColor=new BABYLON.Color3(1,1,1);var n=["#define RECEIVESHADOWS"];engineCaps.textureFloat&&n.push("#define SHADOWFULLFLOAT"),Materials.standardShadow=new BABYLON.ShaderMaterial("",scene,"standard",{attributes:["position","normal","color","uv"],uniforms:["world","view","viewProjection","vFogInfos","vFogColor"],defines:n}),Materials.standardShadow.setTexture("shadowSampler",shadowGen.getShadowMapForRendering()),Materials.standardShadow.setMatrix("shadowLightMat",shadowGen.getTransformMatrix()),Materials.standardShadow.setVector3("shadowParams",shadowGen.getDarkness(),shadowGen.getShadowMap().getSize().width,shadowGen.bias),Materials.standardShadow.onBind=function(e){var t=Materials.standardShadow.getEffect();t.setFloat4("vFogInfos",scene.fogMode,scene.fogStart,scene.fogEnd,scene.fogDensity),t.setColor3("vFogColor",scene.fogColor),t.setMatrix("worldView",e.getWorldMatrix())},n.push("#define DIRT"),Materials.map=new BABYLON.ShaderMaterial("",scene,"standard",{attributes:["position","normal","color","uv","world0","world1","world2","world3"],uniforms:["world","view","viewProjection","vFogInfos","vFogColor"],defines:n}),Materials.map.setTexture("shadowSampler",shadowGen.getShadowMapForRendering()),Materials.map.setMatrix("shadowLightMat",shadowGen.getTransformMatrix()),Materials.map.setVector3("shadowParams",shadowGen.getDarkness(),shadowGen.getShadowMap().getSize().width,shadowGen.bias),Materials.map.onBind=function(e){var t=Materials.map.getEffect();t.setFloat4("vFogInfos",scene.fogMode,scene.fogStart,scene.fogEnd,scene.fogDensity),t.setColor3("vFogColor",scene.fogColor),t.setMatrix("worldView",e.computeWorldMatrix())},Materials.standard=new BABYLON.ShaderMaterial("",scene,"standard",{attributes:["position","normal","color","uv"],uniforms:["world","view","viewProjection","vFogInfos","vFogColor"]}),Materials.standard.onBind=function(e){var t=Materials.standard.getEffect();t.setFloat4("vFogInfos",scene.fogMode,scene.fogStart,scene.fogEnd,scene.fogDensity),t.setColor3("vFogColor",scene.fogColor),t.setMatrix("worldView",e.getWorldMatrix())},Materials.eggShell=new BABYLON.ShaderMaterial("",scene,"standard",{attributes:["position","normal","color","uv"],uniforms:["world","view","viewProjection","vFogInfos","vFogColor","hp"],defines:["#define EGGSHELL"]}),Materials.eggShell.onBind=function(e){var t=Materials.eggShell.getEffect();t.setFloat4("vFogInfos",scene.fogMode,scene.fogStart,scene.fogEnd,scene.fogDensity),t.setColor3("vFogColor",scene.fogColor),t.setMatrix("worldView",e.getWorldMatrix()),t.setFloat("hp",e.player.hp/100)},Materials.wireframe=new BABYLON.StandardMaterial("",scene),Materials.wireframe=!0,Materials.normalBackface=new BABYLON.StandardMaterial("",scene),Materials.normalBackface.diffuseColor=new BABYLON.Color3(.5,.5,.5),Materials.normalBackface.ambientColor=new BABYLON.Color3(.5,.5,.5),Materials.normalBackface.specularColor=new BABYLON.Color3(0,0,0),Materials.normalBackface.backFaceCulling=!1,Materials.normalBackface.twoSidedLighting=!0,Materials.muzzleFlash=new BABYLON.StandardMaterial("",scene),Materials.muzzleFlash.emissiveColor=BABYLON.Color3.White(),Materials.ui=new BABYLON.StandardMaterial("ui",scene),Materials.ui.disableLighting=!0,Materials.ui.emissiveColor=BABYLON.Color3.White(),Materials.ui.fogEnabled=!1,Materials.eggWhite=new BABYLON.StandardMaterial("eggWhite",scene),Materials.eggWhite.disableLighting=!0,Materials.eggWhite.alpha=.8,Materials.eggWhite.emissiveColor=BABYLON.Color3.White(),Materials.eggYolk=new BABYLON.StandardMaterial("eggYolk",scene),Materials.eggYolk.disableLighting=!0,Materials.eggYolk.emissiveColor=BABYLON.Color3.White(),Meshes.map=[[],[],[],[],[]],Meshes.map[1].push(null);var a=0,o=[loadMeshes(["egg","eggExplode","bullet","tile","muzzleFlash","ammo","reticle","mountains","sky"],Meshes,!1,t),loadMeshes(["container","containerOrange","containerBlue","blockWall"],Meshes.map[1],!0,t),loadMeshes(["stairs"],Meshes.map[2],!0,t),loadMeshes(["tree"],Meshes.map[3],!0,t),loadMeshes(["barricade"],Meshes.map[4],!0,t)],i={spatialSound:!0,distanceModel:"inverse"};Sounds.eggk47={fire:new BABYLON.Sound("fire","sound/eggk47/fire.mp3",scene,null,i),dryFire:new BABYLON.Sound("dryFire","sound/eggk47/dry fire.mp3",scene,null,i),cycle:new BABYLON.Sound("cycle","sound/eggk47/full cycle.mp3",scene,null,i),insertMag:new BABYLON.Sound("insertMag","sound/eggk47/insert mag.mp3",scene,null,i),removeMag:new BABYLON.Sound("removeMag","sound/eggk47/remove mag.mp3",scene,null,i)},Sounds.dozenGauge={fire:new BABYLON.Sound("fire","sound/dozenGauge/fire.mp3",scene,null,i),open:new BABYLON.Sound("open","sound/dozenGauge/open.mp3",scene,null,i),load:new BABYLON.Sound("load","sound/dozenGauge/load.mp3",scene,null,i),close:new BABYLON.Sound("close","sound/dozenGauge/close.mp3",scene,null,i)},Sounds.csg1={fire:new BABYLON.Sound("fire","sound/csg1/fire.mp3",scene,null,i),pullAction:new BABYLON.Sound("pullAction","sound/csg1/pull action.mp3",scene,null,i),releaseAction:new BABYLON.Sound("releaseAction","sound/csg1/release action.mp3",scene,null,i)},Sounds.cluck9mm={fire:new BABYLON.Sound("fire","sound/cluck9mm/fire.mp3",scene,null,i),removeMag:new BABYLON.Sound("removeMag","sound/cluck9mm/remove mag.mp3",scene,null,i),insertMag:new BABYLON.Sound("insertMag","sound/cluck9mm/insert mag.mp3",scene,null,i)},Sounds.hammerClick=new BABYLON.Sound("hammerClick","sound/hammerClick.mp3",scene),Sounds.ammo=new BABYLON.Sound("ammo","sound/ammo.mp3",scene),Sounds.shellBurst=new BABYLON.Sound("","sound/shellBurst.mp3",scene,null,i),Sounds.hit=new BABYLON.Sound("hit","sound/hit.mp3",scene,null,i),Sounds.death=[];for(var s=1;s<11;s++)Sounds.death.push(new BABYLON.Sound("","sound/death/scream"+s+".mp3",scene,null,i))}function loadMeshes(e,t,n,a){function o(){BABYLON.SceneLoader.ImportMesh("","models/",e[r]+".babylon",scene,function(e,l,h){for(var c=0;c<e.length;c++){var d=e[c];d.setEnabled(!1),d.setMaterial(Materials.standard),d.isPickable=!1,n?t.push(d):t[d.name]=d}r++,0==--i?a&&a.call(s):o()})}var i=e.length,s=this,r=0;o()}function setupLights(){scene.ambientColor=new BABYLON.Color3(.2,.2,.2),scene.fogMode=BABYLON.Scene.FOGMODE_EXP,scene.fogColor=new BABYLON.Color4(.5,.7,.9,1),scene.fogDensity=.025,scene.clearColor=new BABYLON.Color3(.7,.9,1),scene.clearColor=BABYLON.Color3.White();var e=new BABYLON.DirectionalLight("",new BABYLON.Vector3(0,-1,0),scene);return e.intensity=1.2,e.autoUpdateExtends=!1,shadowGen=new BABYLON.ShadowGenerator(1024,e),shadowGen.forceBackFacesOnly=!0,shadowGen.refreshRate=0,e.shadowMinZ=.1,e.shadowMaxZ=40,e.shadowFrustumSize=15,e}function beginAnimation(e,t,n,a,o){scene.beginAnimation(e,t,n,a,o);for(var i=e.getChildMeshes(),s=0;s<i.length;s++)scene.beginAnimation(i[s],t,n,a,o)}function startGame(e,t,n,a){players={},keyIsDown={},map=GameMap.generateMap(e,t,n,a),inputTally="WASDER ",respawnTime=0,me=null,lastTimeStamp=Date.now(),lastDelta=0,fps=Array(60).fill(0),fpsSum=0,fpsIdx=0,pingTotal=0,pingSamples=0,fpsTotal=0,fpsSamples=0,gameStartTime=Date.now(),nextPingSample=Date.now()+1e3,engine.clear(BABYLON.Color3.Black()),engine.stopRenderLoop(),document.getElementById("game").style.display="block",document.getElementById("gameCanvasContainer").appendChild(canvas),document.getElementById("homeButton").style.visibility="visible",document.getElementById("friendsButton").style.visibility="visible",resize(),scene=new BABYLON.Scene(engine),light=setupLights(),camera=new BABYLON.TargetCamera("camera",BABYLON.Vector3.Zero(),scene),scene.activeCameras.push(camera),camera.maxZ=1e3,camera.fov=1.25,camera.minZ=.08,(uiCamera=new BABYLON.FreeCamera("uiCamera",new BABYLON.Vector3(0,0,-1),scene)).mode=BABYLON.Camera.ORTHOGRAPHIC_CAMERA,uiCamera.layerMask=536870912,scene.activeCameras.push(uiCamera),window.onfocus=function(){lastTimeStamp=Date.now()},window.onblur=function(){document.exitPointerLock()},loadResources(onLoadingComplete)}function onLoadingComplete(){hitIndicator=new HitIndicator,reticle=new Reticle,Meshes.muzzleFlash.material=Materials.muzzleFlash,Meshes.bullet.material=Materials.bullet,Meshes.egg.material=Materials.eggShell,Meshes.eggWhite.material=Materials.eggWhite,Meshes.eggYolk.material=Materials.eggYolk,munitionsManager=new MunitionsManager,itemManager=new ItemManager,buildMapMesh(),(bulletHoleManager=new BABYLON.SpriteManager("bulletHoleManager","img/bulletHoles.png",1e3,32,scene)).fogEnabled=!0,bulletHoleManager.idx=0,bulletHoleManager.addHole=function(e,t,n,a){var o=bulletHoleManager.sprites[this.idx]||new BABYLON.Sprite("",this);o.position.x=t,o.position.y=n,o.position.z=a,o.width=.03,o.height=.03,o.angle=6.282*Math.random(),o.cellIndex=e,this.idx=(this.idx+1)%1e3},document.getElementById("mainMenu").style.display="none",document.getElementById("overlay").style.display="none",document.getElementById("game").style.visibility="visible",canvas.addEventListener("click",function(){if(this.requestPointerLock(),me&&me.isDead()&&respawnTime<0){var e=new Comm.output(1);e.packInt8(Comm.requestRespawn),ws.send(e.buffer),respawnTime=1e5}},!1),canvas.addEventListener("mousedown",function(e){inputDown("MOUSE "+e.button),1==e.button&&e.preventDefault()}),canvas.addEventListener("mouseup",function(e){inputUp("MOUSE "+e.button)}),canvas.addEventListener("mousemove",function(e){if(document.pointerLockElement&&me&&me.hp>0){var t=5e-4*settings.mouseSensitivity+.001;me.viewYaw=Math.radAdd(me.viewYaw,e.movementX*t),me.pitch=Math.max(Math.min(me.pitch+e.movementY*settings.mouseInvert*t,1.5),-1.5)}}),captureKeys(),setUpSocket(),closeAlertDialog(),scene.registerBeforeRender(function(){update(),me&&(light.position.x=me.x,light.position.y=me.y+1,light.position.z=me.z)}),engine.runRenderLoop(function(){scene.render()});var e=new Comm.output(1);e.packInt8(Comm.clientReady),ws.send(e.buffer)}function setUpSocket(){ws.onmessage=function(e){for(var t,n=new Comm.input(e.data);t=n.unPackInt8U();)switch(t){case Comm.addPlayer:var a={id:n.unPackInt8U(),name:n.unPackString(),charClass:n.unPackInt8U(),x:n.unPackFloat(),y:n.unPackFloat(),z:n.unPackFloat(),dx:n.unPackFloat(),dy:n.unPackFloat(),dz:n.unPackFloat(),viewYaw:n.unPackRadU(),moveYaw:n.unPackRadU(),pitch:n.unPackRad(),totalKills:n.unPackInt16U(),killStreak:n.unPackInt16U(),bestKillStreak:n.unPackInt16U(),hp:n.unPackInt8U(),weaponIdx:n.unPackInt8U(),controlKeys:n.unPackInt8U()};players[a.id]||(meId==a.id&&addChat("Welcome, "+a.name+"!"),addPlayer(a));break;case Comm.removePlayer:removePlayer(h=n.unPackInt8U());break;case Comm.spawnItem:var o=n.unPackInt16U(),i=n.unPackInt8U(),s=n.unPackFloat(),r=n.unPackFloat(),l=n.unPackFloat();itemManager.spawnItem(o,i,s,r,l);break;case Comm.collectItem:var h=n.unPackInt8U(),i=n.unPackInt8U(),o=n.unPackInt16U();itemManager.collectItem(i,o),h==meId&&(players[h].collectItem(i),updateAmmoUi());break;case Comm.keyDown:var h=n.unPackInt8U(),c=n.unPackInt8U();(W=players[h])&&(W.controlKeys|=c);break;case Comm.keyUp:var h=n.unPackInt8U(),c=n.unPackInt8U();(W=players[h])&&(W.controlKeys^=c);break;case Comm.jump:h=n.unPackInt8U();(W=players[h])&&players[h].jump();break;case Comm.die:var d=n.unPackInt8U(),u=n.unPackInt8U(),m=n.unPackInt8U(),p=players[d],g=players[u];g.isDead()||(g.totalKills++,g.killStreak++,g.bestKillStreak=Math.max(g.bestKillStreak,g.killStreak));var f=new BABYLON.Vector3(p.x,p.y+.32,p.z);p.actor.deathSound.setPosition(f),p.actor.deathSound.play();var y=Math.randomInt(0,Sounds.death.length);if(Sounds.death[y].setPosition(f),Sounds.death[y].play(),d!=meId){if(u==meId){var w=document.getElementById("KILL_BOX");w.style.display="block",document.getElementById("KILLED_NAME").innerText=p.name;var M=document.getElementById("KILL_STREAK");me.killStreak>1?M.innerText=me.killStreak+"-KILL STREAK":M.innerText="";var v=1.5,S=setInterval(function(){w.style.transform="scale("+v+","+v+")",(v-=.025)<=1&&clearInterval(S)},15);clearTimeout(killDisplayTimeout),killDisplayTimeout=setTimeout(function(){w.style.display="none"},4e3)}}else{camera.parent=null,camera.position=new BABYLON.Vector3(me.actor.mesh.position.x,me.actor.mesh.position.y+.2,me.actor.mesh.position.z),camera.lockedTarget=g.actor.bodyMesh,document.exitPointerLock(),respawnTime=m;var B=document.getElementById("DEATH_BOX");B.style.display="block",document.getElementById("KILLED_BY_NAME").innerText=g.name;var v=2,S=setInterval(function(){B.style.transform="scale("+v+","+v+")",(v-=.025)<=1&&clearInterval(S)},15),k=document.getElementById("RESPAWN");k.innerText="";var I=setInterval(function(){k.innerText="You may respawn in "+respawnTime,--respawnTime<0&&(clearInterval(I),k.innerText="CLICK TO RESPAWN!")},1e3)}p.actor.explodeMesh.setEnabled(!0),p.actor.whiteMesh.setEnabled(!0),p.actor.yolkMesh.setEnabled(!0),beginAnimation(p.actor.explodeMesh,0,50,!1,1),scene.beginAnimation(p.actor.whiteMesh,0,50,!1,1),scene.beginAnimation(p.actor.yolkMesh,0,56,!1,1),shellFragBurst(p.actor.mesh,200,1),p.die(),p.previousStates.fill({delta:0,moveYaw:0,fire:!1,jump:!1,x:p.x,y:p.y,z:p.z,dx:0,dy:0,dz:0,controlKeys:0}),p.actor.mesh.position.x=p.x,p.actor.mesh.position.y=p.y,p.actor.mesh.position.z=p.z,rebuildPlayerList(),updateBestStreakUi();break;case Comm.chat:addChat(n.unPackString());break;case Comm.sync:var o=n.unPackInt8U(),b=n.unPackInt8U(),s=n.unPackFloat(),r=n.unPackFloat(),l=n.unPackFloat(),A=n.unPackRadU(),C=n.unPackRad();if(!(W=players[o]))break;if(o==me.id){if(Date.now()>=nextPingSample){nextPingSample=Date.now()+1e3;var x=Date.now()-pingStartTime;pingTotal+=x,pingSamples++;var E=document.getElementById("PING");E.style.color=x<100?"#0f0":x<150?"#ff0":x<200?"#f90":"#f00",document.getElementById("PING").innerText=x+"ms"}for(var z=b,L=1e6,P=b;P!=W.stateIdx;){var O=W.previousStates[P],F=Math.sqrt(Math.pow(s-O.x,2)+Math.pow(r-O.y,2)+Math.pow(l-O.z,2));F<L&&(z=P,L=F),P=(P+1)%256}var P=z,N=(W.previousStates[P],s-W.previousStates[P].x),T=r-W.previousStates[P].y,Y=l-W.previousStates[P].z;W.x+=N;for(P=0;W.collidesWithMap()&&(W.x-=N,N*=.5,W.x+=N,!(++P>100)););for(W.z+=Y,P=0;W.collidesWithMap()&&(W.z-=Y,Y*=.5,W.z+=Y,!(++P>100)););T>=.9&&(W.y=r)}else W.x=s,W.y=r,W.z=l,W.viewYaw=A,W.moveYaw=A,W.pitch=C;break;case Comm.fireBullet:var o=n.unPackInt8U(),s=n.unPackFloat(),r=n.unPackFloat(),l=n.unPackFloat(),D=n.unPackFloat(),G=n.unPackFloat(),R=n.unPackFloat();if(!(W=players[o]))break;o!=meId&&(W.dx*=.5,W.dz*=.5,W.actor.head.rotation.x=W.pitch,W.actor.mesh.rotation.y=W.viewYaw,W.actor.fire(),W.weapon.actor.fire()),munitionsManager.fireBullet(W,{x:s,y:r,z:l},{x:D,y:G,z:R},W.weapon.damage,W.weapon.ttl,W.weapon.velocity);break;case Comm.fireShot:var o=n.unPackInt8U(),s=n.unPackFloat(),r=n.unPackFloat(),l=n.unPackFloat(),D=n.unPackFloat(),G=n.unPackFloat(),R=n.unPackFloat(),U=n.unPackInt8U(),W=players[o];o!=me.id&&(W.dx*=.5,W.dz*=.5,W.actor.head.rotation.x=W.pitch,W.actor.mesh.rotation.y=W.viewYaw,W.actor.fire(),W.weapon.actor.fire()),Math.seed=U;for(P=0;P<20;P++){var H=Math.normalize3({x:D+Math.seededRandom(-.15,.15),y:G+Math.seededRandom(-.1,.1),z:R+Math.seededRandom(-.15,.15)});munitionsManager.fireBullet(W,{x:s,y:r,z:l},H,W.weapon.damage,W.weapon.ttl,W.weapon.velocity*Math.seededRandom(.9,1.1))}break;case Comm.startReload:o=n.unPackInt8U();players[o].weapon.actor.reload();break;case Comm.reload:me.weapon.reload();break;case Comm.stowWeapon:o=n.unPackInt8U();(W=players[o])&&W.weapon.actor.stow();break;case Comm.equipWeapon:var o=n.unPackInt8U(),K=n.unPackInt8U();if(!(W=players[o]))break;players[o].equipWeapon(K);break;case Comm.hitMe:var q=n.unPackInt8U(),N=n.unPackFloat(),Y=n.unPackFloat();me.hp=q,me.actor.hitSound.play(),hitIndicator.hit(N,Y);break;case Comm.hitThem:var o=n.unPackInt8U(),q=n.unPackInt8U();(W=players[o]).hp=q,W.actor.hitSound.play(),q>0&&shellFragBurst(W.actor.mesh,100,1);break;case Comm.respawn:var o=n.unPackInt8U(),s=n.unPackFloat(),r=n.unPackFloat(),l=n.unPackFloat();(W=players[o]).respawn(s,r,l),o==meId&&(document.getElementById("DEATH_BOX").style.display="none",camera.position=BABYLON.Vector3.Zero(),camera.rotation=BABYLON.Vector3.Zero(),camera.rotationQuaternion=BABYLON.Quaternion.Zero(),camera.parent=me.actor.eye,camera.lockedTarget=null)}}}function shellFragBurst(e,t,n){var a=new BABYLON.ParticleSystem("particles",t,scene);a.targetStopDuration=.2,a.disposeOnStop=!0,a.particleTexture=new BABYLON.Texture("./img/shellfrag.png",scene),a.emitter=e,a.minEmitBox=new BABYLON.Vector3(-.2,.2,-.2),a.maxEmitBox=new BABYLON.Vector3(.2,.4,.2),a.color1=new BABYLON.Color4(1,1,1,4),a.color2=new BABYLON.Color4(1,1,1,4),a.colorDead=new BABYLON.Color4(1,1,1,0),a.minSize=.01,a.maxSize=.04,a.minLifeTime=.1,a.maxLifeTime=.3,a.emitRate=t,a.manualEmitCount=t,a.blendMode=BABYLON.ParticleSystem.BLENDMODE_STANDARD,a.gravity=new BABYLON.Vector3(0,-10,0),a.direction1=new BABYLON.Vector3(-2,-1,-2),a.direction2=new BABYLON.Vector3(2,3,2),a.minAngularSpeed=10*-Math.PI,a.maxAngularSpeed=10*Math.PI,a.minEmitPower=1*n,a.maxEmitPower=2*n,a.updateSpeed=.01,a.start()}function createMapCells(){(SPS=new BABYLON.SolidParticleSystem("SPS",scene,{updatable:!1})).computeParticleColor=!1,SPS.computeParticleTexture=!1,SPS.computeParticleRotation=!1,Object.keys(map.min.data).forEach(function(e){var t=map.min.data[e];Object.keys(t).forEach(function(n){if(e>1||n>0){var a=t[n],o=0;Meshes.map[e][n].material=Materials.map,SPS.addShape(Meshes.map[e][n],a.length,{positionFunction:function(t,i,s){t.position.x=a[o].x+.5,t.position.y=a[o].y,t.position.z=a[o].z+.5,t.rotation.x=.5*-Math.PI,t.rotation.y=a[o].dir*rotInc,t.alive=!1,map.data[a[o].x][a[o].y][a[o].z]={cat:e,dec:n,dir:a[o].dir},o++}})}})});var e=0,t=0;SPS.addShape(Meshes.tile,map.width*map.depth,{positionFunction:function(n,a,o){n.position.x=e+.5,n.position.y=0,n.position.z=t+.5,n.rotation.x=.5*-Math.PI,n.rotation.y=rotInc*Math.randomInt(0,3),n.scaling.x=.5,n.scaling.y=.5,n.scaling.z=.5,n.alive=!1,++e>=map.width&&(e=0,t++)}}),(mapMesh=SPS.buildMesh()).receiveShadows=!0,mapMesh.material=Materials.map,mapMesh.freezeWorldMatrix()}function buildMapMesh(){createMapCells();var e=new BABYLON.StandardMaterial("water material",scene);e.diffuseColor=new BABYLON.Color3(.05,.1,.2),e.specularColor=new BABYLON.Color3(0,0,0);var t=BABYLON.MeshBuilder.CreatePlane("plane",{size:1e3},scene);t.rotation.x=Math.PI/2,t.position.y=-1,t.material=e;var n=new BABYLON.SkyMaterial("skyMaterial",scene);n.backFaceCulling=!1;var a=BABYLON.Mesh.CreateBox("skyBox",1e3,scene);a.material=n,a.position.x=map.width/2,a.position.z=map.depth/2,n.fogEnabled=!1,n.useSunPosition=!0,n.sunPosition=new BABYLON.Vector3(-.25,1,-.5),n.turbidity=1.5,n.luminance=.5,n.rayleigh=2;var o=Meshes.sky.clone("sky");o.scaling.x=490,o.scaling.y=100,o.scaling.z=490,o.position.x=map.width/2,o.position.z=map.depth/2;var i=new BABYLON.CloudProceduralTexture("cloud",512,scene);i.cloudColor=new BABYLON.Color3(0,0,0),i.skyColor=new BABYLON.Color3(1,1,1),i.uScale=1,i.vScale=1;var s=new BABYLON.StandardMaterial("cloudMat",scene);s.fogEnabled=!1,s.alphaMode=BABYLON.Engine.ALPHA_MAXIMIZED,s.alpha=.9999,s.emissiveTexture=i,s.diffuseTexture=i,s.backFaceCulling=!1,o.material=s;var r=Meshes.mountains.clone("");r.scaling.x=80,r.scaling.y=50,r.scaling.z=80,r.position.x=map.width/2,r.position.z=map.depth/2,(r=Meshes.mountains.clone("")).scaling.x=45,r.scaling.y=25,r.scaling.z=45,r.position.x=map.width/2,r.position.z=map.depth/2,r.rotation.y=1.5,(r=Meshes.mountains.clone("")).scaling.x=30,r.scaling.y=10,r.scaling.z=30,r.position.x=map.width/2,r.position.z=map.depth/2,r.rotation.y=3}function update(){var e=document.getElementById("FPS");fps[fpsIdx]=engine.getFps(),fpsSum+=fps[fpsIdx],fpsSum-=fps[(fpsIdx+1)%60],fpsIdx=(fpsIdx+1)%60;var t=Math.ceil(fpsSum/60);fpsSamples++,fpsTotal+=t,e.innerHTML="FPS: "+t;var n=Date.now()-lastTimeStamp;lastTimeStamp+=n,n/=17,Object.keys(players).forEach(function(e){var t=players[e];t&&(t.update(n),t.actor&&t.actor.update())}),me&&(me.stateIdx%10==0&&ws.readyState==ws.OPEN&&me.hp>0&&serverSync(),me.stateIdx=(me.stateIdx+1)%256,me.previousStates[me.stateIdx]={delta:n,moveYaw:me.moveYaw,fire:!1,jump:!1,x:me.x,y:me.y,z:me.z,dx:me.dx,dy:me.dy,dz:me.dz,controlKeys:me.controlKeys},hitIndicator.update(n),reticle.update(n),me.weapon&&0==me.weapon.ammo.rounds&&(me.stateIdx%20==0?document.getElementById("AMMO").style.color="#f00":me.stateIdx%20==10&&(document.getElementById("AMMO").style.color="#fff"))),munitionsManager.update(n),itemManager.update(n)}function hitPlayer(e,t){t.actor.remove()}function serverSync(){if(me){pingStartTime=Date.now(),me.moveYaw=me.viewYaw,me.previousStates[me.stateIdx].moveYaw=me.moveYaw;var e=new Comm.output(6);e.packInt8(Comm.sync),e.packInt8(me.stateIdx),e.packRadU(me.moveYaw),e.packRad(me.pitch),ws.send(e.buffer)}}function addPlayer(e){var t=new Player(e);t.id==meId?((me=t).ws=ws,camera.parent=me.actor.eye):(t.equipWeapon(t.weaponIdx),t.isDead()&&t.actor.die()),players[e.id]=t,rebuildPlayerList()}function removePlayer(e){players[e].actor.remove(),delete players[e],rebuildPlayerList()}function reloadWeapon(){if(me.weapon.startReload()){var e=new Comm.output(1);e.packInt8(Comm.startReload),ws.send(e.buffer)}}function rebuildPlayerList(){var e=Object.keys(players).sort(function(e,t){return players[t].killStreak-players[e].killStreak}),t=document.getElementById("playerList").children,n=0;for(e.forEach(function(e){t[n].style.display="block",t[n].children[0].innerText=players[e].name,t[n].children[1].innerText=players[e].killStreak,t[n].className=e==meId?"thisPlayer":"otherPlayer",n++});n<20;)t[n].style.display="none",n++}function updateBestStreakUi(){var e=players[meId];document.getElementById("BEST_STREAK").innerText="BEST KILL STREAK: "+e.bestKillStreak}function updateAmmoUi(){var e=players[meId],t=document.getElementById("WEAPON_NAME");t.innerHTML=e.weapon.name,(t=document.getElementById("AMMO")).style.color="#fff",t.innerHTML=e.weapon.ammo.rounds+"/"+e.weapon.ammo.store}function addChat(e){var t=document.getElementById("chatOut");t.value+="\n"+e,t.scrollTop=t.scrollHeight}function captureKeys(){document.onkeydown=onKeyDown,document.onkeyup=onKeyUp}function releaseKeys(){document.onkeydown=null,document.onkeyup=null}function inputDown(e){if(!me.isDead()){var t=inputToControlMap[e];switch(t){case"up":case"down":case"left":case"right":var n=controlToBitmask[t];(a=new Comm.output(2)).packInt8(Comm.keyDown),a.packInt8(n),ws.send(a.buffer),me.controlKeys|=n,me.previousStates[me.stateIdx].controlKeys|=n;break;case"jump":var a=new Comm.output(1);a.packInt8(Comm.jump),ws.send(a.buffer),me.jump(),me.previousStates[me.stateIdx].jump=!0,me.previousStates[me.stateIdx].dy=me.dy;break;case"fire":document.pointerLockElement&&me&&(me.previousStates[me.stateIdx].fire=!0,me.weapon&&(me.weapon.triggerPulled=!0),me.queueShot(),0==me.weapon.ammo.rounds&&reloadWeapon());break;case"reload":reloadWeapon();break;case"weapon":me.stowWeapon(0==me.weaponIdx?1:0)}}}function inputUp(e){if(!me.isDead()){var t=inputToControlMap[e];switch(t){case"fire":me.weapon&&(me.weapon.triggerPulled=!1);break;case"up":case"down":case"left":case"right":var n=controlToBitmask[t],a=new Comm.output(2);a.packInt8(Comm.keyUp),a.packInt8(n),ws.send(a.buffer),me.controlKeys^=n,me.previousStates[me.stateIdx].controlKeys|=n}}}function onKeyDown(e){if(!keyIsDown[e.keyCode]){keyIsDown[e.keyCode]=!0;var t=e.key.toLocaleUpperCase();""!=inputTally&&""==(inputTally=inputTally.replace(t,""))&&(document.getElementById("help").style.display="none",localStorage.setItem("hideHelp",1))," "==t&&(t="SPACE",e.preventDefault()),inputDown(t)}}function onKeyUp(e){if(keyIsDown[e.keyCode]){keyIsDown[e.keyCode]=!1;var t=e.key.toLocaleUpperCase();" "==t&&(t="SPACE",e.preventDefault()),inputUp(t)}}function HitIndicator(){this.mesh=new BABYLON.Mesh("hitIndicator",scene),this.mesh.updatable=!0,this.mesh.hasVertexAlpha=!0,this.positions=[0,0,0,0,.5,0,.5,.5,0,.5,0,0,.5,-.5,0,0,-.5,0,-.5,-.5,0,-.5,0,0,-.5,.5,0];var e=[0,1,8,0,2,1,0,2,1,0,3,2,0,3,2,0,4,3,0,4,3,0,5,4,0,5,4,0,6,5,0,6,5,0,7,6,0,7,6,0,8,7,0,8,7,0,1,8];this.colors=new Array(48).fill(0);for(var t=0;t<48;t+=4)this.colors[t]=1,this.colors[t+1]=.9,this.colors[t+2]=0,this.colors[t+3]=-.5;var n=new BABYLON.VertexData;n.positions=this.positions,n.indices=e,n.colors=this.colors,n.applyToMesh(this.mesh,!0),this.mesh.layerMask=536870912,this.mesh.material=Materials.ui,this.resize()}function Reticle(){this.mesh=new BABYLON.AbstractMesh("reticle",scene),this.lines=[];for(var e=0;e<4;e++){var t=Meshes.reticle.clone("reticleLine",this.mesh);t.parent=this.mesh,t.scaling=new BABYLON.Vector3(1,1,1),t.rotation.z=e*Math.PI/2,this.lines.push(t)}this.mesh.setLayerMask(536870912),this.mesh.setMaterial(Materials.ui)}function inviteFriends(){var e=selectedServer.toString(36)+uniqueId.toString(36)+uniqueKey.toString(36);document.getElementById("friendCode").innerText="shellshock.io/#"+e,document.getElementById("inviteFriends").style.display="block"}function copyFriendCode(){document.getElementById("friendCode").select();try{document.execCommand("copy")}catch(e){console.log("Unable to copy to clipboard")}}function Eggk47Actor(e){this.gun=e,this.playerActor=e.player.actor,this.gunMesh=Meshes.eggk47.clone("eggk47",this.playerActor.gunContainer),this.gunMesh.setEnabled(!1),this.clipMesh=Meshes.eggk47Mag.clone("eggk47Mag",this.playerActor.gunContainer),this.clipMesh.setEnabled(!1),this.muzzleFlash=Meshes.muzzleFlash.clone("muzzleFlash",this.playerActor.gunContainer),this.muzzleFlash.setEnabled(!1),this.muzzleFlash.parent=this.playerActor.gunContainer,this.muzzleFlash.position.x=.25,this.muzzleFlash.position.z=.6,this.gun.player.id==meId&&(this.gunMesh.setRenderingGroupId(2),this.clipMesh.renderingGroupId=2,this.muzzleFlash.renderingGroupId=2),this.fireSound=Sounds.eggk47.fire.clone(),this.gunMesh.attachSound(this.fireSound),this.dryFireSound=Sounds.eggk47.dryFire.clone(),this.gunMesh.attachSound(this.dryFireSound),this.addSoundEvent(24,Sounds.eggk47.removeMag.clone()),this.addSoundEvent(72,Sounds.eggk47.insertMag.clone()),this.addSoundEvent(90,Sounds.eggk47.cycle.clone())}function DozenGaugeActor(e){this.gun=e,this.playerActor=e.player.actor,this.gripHandTarget=this.playerActor.gripHand.getChildMeshByName("gripHand.doubleShotgunGrip"),this.gunMesh=Meshes.doubleShotgun.clone("doubleShotgun",this.playerActor.gripHand),this.gunMesh.attachToParent(this.gripHandTarget),this.gunMesh.setEnabled(!1),this.barrel=this.gunMesh.getChildMeshByName("doubleShotgun.doubleShotgun.barrel"),this.muzzleFlash=Meshes.muzzleFlash.clone("muzzleFlash",this.playerActor.gunContainer),this.muzzleFlash.setEnabled(!1),this.muzzleFlash.parent=this.playerActor.gunContainer,this.muzzleFlash.position.x=.25,this.muzzleFlash.position.z=.6,this.gun.player.id==meId&&(this.gunMesh.setRenderingGroupId(2),this.muzzleFlash.renderingGroupId=2),this.fireSound=Sounds.dozenGauge.fire.clone(),this.gunMesh.attachSound(this.fireSound),this.dryFireSound=Sounds.eggk47.dryFire.clone(),this.gunMesh.attachSound(this.dryFireSound),this.addSoundEvent(321,Sounds.dozenGauge.open.clone()),this.addSoundEvent(377,Sounds.dozenGauge.load.clone()),this.addSoundEvent(397,Sounds.dozenGauge.close.clone())}function CSG1Actor(e){this.gun=e,this.playerActor=e.player.actor,this.gunMesh=Meshes.csg1.clone("csg1",this.playerActor.gunContainer),this.gunMesh.setEnabled(!1),this.clipMesh=Meshes.csg1Mag.clone("csg1Mag",this.playerActor.gunContainer),this.clipMesh.setEnabled(!1),this.muzzleFlash=Meshes.muzzleFlash.clone("muzzleFlash",this.playerActor.gunContainer),this.muzzleFlash.setEnabled(!1),this.muzzleFlash.parent=this.playerActor.gunContainer,this.muzzleFlash.position.x=.25,this.muzzleFlash.position.z=.6,this.gun.player.id==meId&&(this.gunMesh.setRenderingGroupId(2),this.clipMesh.renderingGroupId=2,this.muzzleFlash.renderingGroupId=2),this.fireSound=Sounds.csg1.fire.clone(),this.gunMesh.attachSound(this.fireSound),this.dryFireSound=Sounds.eggk47.dryFire.clone(),this.gunMesh.attachSound(this.dryFireSound),this.addSoundEvent(881,Sounds.eggk47.removeMag.clone()),this.addSoundEvent(947,Sounds.eggk47.insertMag.clone()),this.addSoundEvent(1030,Sounds.csg1.pullAction.clone()),this.addSoundEvent(1100,Sounds.csg1.releaseAction.clone())}function Cluck9mmActor(e){this.gun=e,this.playerActor=e.player.actor,this.gunMesh=Meshes.cluck9mm.clone("cluck9mm",this.playerActor.gunContainer),this.gunMesh.setEnabled(!1),this.clipMesh=this.gunMesh.getChildMeshByName("cluck9mm.cluck9mmMag"),this.muzzleFlash=Meshes.muzzleFlash.clone("muzzleFlash",this.playerActor.gunContainer),this.muzzleFlash.setEnabled(!1),this.muzzleFlash.parent=this.playerActor.gunContainer,this.muzzleFlash.position.x=.25,this.muzzleFlash.position.z=.6,this.gun.player.id==meId&&(this.gunMesh.setRenderingGroupId(2),this.clipMesh.renderingGroupId=2,this.muzzleFlash.renderingGroupId=2),this.fireSound=Sounds.cluck9mm.fire.clone(),this.gunMesh.attachSound(this.fireSound),this.dryFireSound=Sounds.eggk47.dryFire.clone(),this.gunMesh.attachSound(this.dryFireSound),this.addSoundEvent(628,Sounds.cluck9mm.removeMag.clone()),this.addSoundEvent(675,Sounds.cluck9mm.insertMag.clone())}function ItemActor(e){this.kind=e}function AmmoActor(){ItemActor.call(this,ItemManager.AMMO),this.mesh=Meshes.ammo.clone("ammo"),this.mesh.setEnabled(!1),shadowGen.getShadowMap().renderList.push(this.mesh)}function ItemManager(){this.pools=[new Pool(function(){return new ItemManager.Constructors[ItemManager.AMMO]},100)]}function getKeyByValue(e,t){for(var n in e)if(e.hasOwnProperty(n)&&e[n]===t)return n}function selectServer(e){selectedServer=e}function resize(){canvas&&(inGame?(canvas.style.width="100%",canvas.style.height="100%",canvas.className=""):(canvas.style.width="100%",canvas.height=.66*canvas.width,canvas.className="roundedBorder")),engine&&engine.resize(),hitIndicator&&hitIndicator.resize()}function onResourcesLoaded(){function e(){document.getElementById("className").innerText=classes[selectedClass].name,document.getElementById("classWeapon").innerText="Weapon: "+i[selectedClass].weapon.name;for(c in l){var e=(i[selectedClass].weapon[c]+l[c].min)/(l[c].max-Math.abs(l[c].min));e=Math.floor(95*e)+5,document.getElementById(l[c].name).style.width=e+"%"}}var t=document.getElementById("username");t.value=getStoredString("lastUsername",""),t.addEventListener("keydown",function(e){"Enter"!=e.code&&13!=e.keyCode||(t.disabled=!0,login())});var n=classes.length;meId=0;var a=new BABYLON.StandardMaterial("groundMat",scene);a.diffuseColor=new BABYLON.Color3(.4,.3,.2);var o=BABYLON.Mesh.CreatePlane("ground",100,scene);o.position.y=-.32,o.rotation.x=Math.PI/2,o.receiveShadows=!0,o.material=a,light.position.y=2;for(var i=[],s=0;s<n;s++){var r=new function(e,t,n,a){this.id=1,this.name="",this.x=e,this.y=t,this.z=n,this.hp=100,this.actor=new PlayerActor(this),this.actor.mesh.setPivotPoint(new BABYLON.Vector3(0,0,-1.6),BABYLON.Space.GLOBAL),this.actor.head.rotation.y=2.5,this.weapon=new classes[a].weapon(this),this.weapon.equip()}(0,-.32,1.6,s);r.actor.mesh.rotation.y=s*Math.PI/(n/2),i.push(r)}for(var l={totalDamage:{name:"damage",max:-1e3,min:1e3,flip:!1},accuracy:{name:"accuracy",max:-1e3,min:1e3,flip:!0},rof:{name:"fireRate",max:-1e3,min:1e3,flip:!0},range:{name:"range",max:-1e3,min:1e3,flip:!1}},s=0;s<n;s++){var h=i[s].weapon;for(var c in l)l[c].flip?(l[c].max=Math.max(l[c].max,-h[c]),l[c].min=Math.min(l[c].min,-h[c])):(l[c].max=Math.max(l[c].max,h[c]),l[c].min=0)}var d=-(selectedClass=getStoredNumber("selectedClass",Math.randomInt(0,classes.length)));window.selectClass=function(t){selectedClass=Math.mod(selectedClass+t,n),d-=t,e()},e(),BABYLON.Engine.audioEngine.setGlobalVolume(settings.volume),engine.runRenderLoop(function(){scene.render();var e=d/5;d-=e;for(var t=0;t<n;t++)i[t].actor.mesh.rotation.y+=e*(Math.PI/(n/2))})}function getRequest(e,t,n){var a=new XMLHttpRequest;return!!a&&("function"!=typeof t&&(t=function(){}),"function"!=typeof n&&(n=function(){}),a.onreadystatechange=function(){if(4==a.readyState)return 200===a.status?t(a.responseText):n(a.status)},a.open("GET",e,!0),a.send(null),a)}function openJoinBox(){document.getElementById("customGame").style.display="none",document.getElementById("joinGame").style.display="block"}function closeJoinBox(){document.getElementById("customGame").style.display="block",document.getElementById("joinGame").style.display="none",document.getElementById("joinCode").value="",console.log("HSDHSFSD"),history.replaceState(null,null,location.pathname)}function login(e){privateGame=e,localStorage.setItem("lastVersionPlayed",version);var t,n=selectedServer,a=document.getElementById("joinCode").value.trim();if(""!=a){a.startsWith("#")&&(a=a.substr(1)),n=Number.parseInt(a.substr(0,1),36);try{t="ws://"+servers[n].address+"/j"+a.substr(1)}catch(e){return openAlertDialog("GAME NOT FOUND","Sorry! This game ID is either<br>invalid, or no longer exists.",{label:"OK"}),uniqueId=0,uniqueKey=0,void(document.getElementById("joinCode").value="")}selectedServer=n}else t="ws://"+servers[n].address;privateGame&&(t+="/p"),(ws=new WebSocket(t)).binaryType="arraybuffer",0!=(username=document.getElementById("username").value.trim()).length&&(document.getElementById("alert").focus(),openAlertDialog("CONNECTING","Please wait!",null,null,!0),ws.onopen=function(e){localStorage.setItem("lastUsername",username),localStorage.setItem("selectedClass",selectedClass),ga("send","event","play game","class",classes[selectedClass].name),fbq("trackCustom","PlayGame",{charClass:classes[selectedClass].name,server:servers[selectedServer].name});var t=3+2*username.length+1;facebookId&&(t+=2*facebookId.length+4);var n=new Comm.output(t);n.packInt8(Comm.login),n.packInt8(selectedClass),n.packString(username),facebookId&&(n.packInt32(gameSession),n.packString(facebookId)),ws.send(n.buffer)},ws.onclose=function(e){4e3==e.code?(openAlertDialog("GAME NOT FOUND","Sorry! This game ID is either<br>invalid, or no longer exists.",{label:"OK"}),uniqueId=0,uniqueKey=0,document.getElementById("joinCode").value=""):4001==e.code?openAlertDialog("GAME FULL","Sorry, this game is currently full!<br>Wait a moment, or try another one!",{label:"OK"}):inGame?openAlertDialog("CONNECTION LOST","Please try a different server,<br> or try again later!",{label:"OK",onclick:showMainMenu}):openAlertDialog("CANNOT CONNECT","Please try a different server,<br> or try again later!",{label:"OK"})},ws.onmessage=function(e){var t=new Comm.input(e.data);switch(t.unPackInt8U()){case Comm.loggedIn:meId=t.unPackInt8U();var n=t.unPackInt8U(),a=t.unPackInt8U(),o=t.unPackInt8U(),i=t.unPackInt16U();uniqueId=t.unPackInt16U(),uniqueKey=t.unPackInt16U(),privateGame&&inviteFriends(),inGame=!0,startGame(n,a,o,i);break;case Comm.invalidName:closeAlertDialog(),openAlertDialog("INVALID NAME","I'm going to guess you know why.",{label:"Yes"}),(e=document.getElementById("username")).value="",e.disabled=!1,e.focus(),document.getElementById("playButton").disabled=!1}})}function setVolume(e){settings.volume=e.value,localStorage.setItem("volume",settings.volume),BABYLON.Engine.audioEngine.setGlobalVolume(settings.volume)}function setMouseSensitivity(e){settings.mouseSensitivity=e.value,localStorage.setItem("mouseSensitivity",settings.mouseSensitivity)}function setMouseInvert(e){settings.mouseInvert=e.checked?-1:1,localStorage.setItem("mouseInvert",settings.mouseInvert)}function getStoredNumber(e,t){var n=Number(localStorage.getItem(e));return n||t}function getStoredString(e,t){var n=localStorage.getItem(e);return n||t}function refactorConfigKeys(e){document.getElementsByName("config").forEach(function(t){t!=e&&t.innerText==e.innerText&&(delete inputToControlMap[t.innerText],t.style.fontWeight="normal",t.style.color="#aaa",t.innerText="undefined")})}function setControl(e){refactorConfigKeys(e),delete inputToControlMap[e.oldText],inputToControlMap[e.innerText]=e.id,controlEl=null,inGame&&captureKeys(),window.onkeydown=null,window.onkeyup=null,localStorage.setItem("controlConfig",JSON.stringify(inputToControlMap))}function configKey(e){var t=e.target;e=e||window.event,t==controlEl?(1==e.button&&event.preventDefault(),t.style.fontWeight="bold",t.style.color="#fff",t.innerText="MOUSE "+e.button,setControl(t)):(controlEl&&(controlEl.style.fontWeight="bold",controlEl.style.color="#fff",controlEl.innerText=controlEl.oldText),t.oldText=t.innerText,t.style.fontWeight="normal",t.style.color="#edc",t.innerText="Press key or button",controlEl=t,t.focus(),inGame&&releaseKeys(),window.onkeydown=function(e){if(27!=(e.which||e.keyCode)){var n=e.key;return" "==n&&(n="space",e.preventDefault()),t.style.fontWeight="bold",t.style.color="#fff",t.innerText=n.toLocaleUpperCase(),setControl(t),e.stopPropagation(),!1}t.style.fontWeight="bold",t.style.color="#fff",t.innerText=t.oldText,controlEl=null},window.onkeyup=function(e){return e.stopPropagation(),!1})}function startAlertBar(){var e=document.getElementById("alertFooter");e.style.display="block",alertBarInterval=setInterval(function(){e.innerText+="-",e.innerText.length>10&&(e.innerText="-")},200)}function openAlertDialog(e,t,n,a,o){document.getElementById("overlay").style.display="block",document.getElementById("alertHeader").innerHTML=e,document.getElementById("alertMessage").innerHTML=t;i=document.getElementById("alertButton1");n?(i.style.display="inline-block",i.innerHTML=n.label||"OK",i.style.width=n.width||"80px",i.onclick=n.onclick||closeAlertDialog):i.style.display="none";var i=document.getElementById("alertButton2");a?(i.style.display="inline-block",i.innerHTML=a.label||"Cancel",i.style.width=a.width||"80px",i.onclick=a.onclick||closeAlertDialog):i.style.display="none",o?startAlertBar():(document.getElementById("alertFooter").style.display="none",clearInterval(alertBarInterval)),document.exitPointerLock(),window.onkeydown=null,window.onkeyup=null}function closeAlertDialog(){document.getElementById("overlay").style.display="none",document.getElementById("alertFooter").style.display="none",document.getElementById("username").disabled=!1,clearInterval(alertBarInterval)}function resetGameUI(){document.getElementById("chatOut").value="",document.getElementById("BEST_STREAK").innerText="BEST KILL STREAK: 0",document.getElementById("KILL_BOX").style.display="none",document.getElementById("DEATH_BOX").style.display="none"}function showMainMenuConfirm(){openAlertDialog("MAIN MENU","Leave game and return<br>to the main menu?",{label:"Yes",width:"4em",onclick:showMainMenu},{label:"No",width:"4em",onclick:closeAlertDialog})}function reloadPage(){window.location.reload()}function showMainMenu(){if(openAlertDialog("LOADING","Hacks enabled >:)",null,null,!0),document.getElementById("homeButton").style.visibility="hidden",document.getElementById("friendsButton").style.visibility="hidden",document.getElementById("game").style.display="none",document.getElementById("inviteFriends").style.display="none",resetGameUI(),inGame){return void reloadPage()}inGame=!1,(scene=new BABYLON.Scene(engine)).fogMode=BABYLON.Scene.FOGMODE_EXP2,scene.fogColor=new BABYLON.Color3(0,0,0),scene.fogDensity=.1,scene.clearColor=new BABYLON.Color3(0,0,0),(light=new BABYLON.SpotLight("light",new BABYLON.Vector3(0,10,.7),new BABYLON.Vector3(0,-1,.33),.75,40,scene)).intensity=1.5,light.autoUpdateExtends=!1;var e=new BABYLON.HemisphericLight("light2",new BABYLON.Vector3(-.25,1,-.5),scene);e.intensity=.8,(e=new BABYLON.HemisphericLight("light3",new BABYLON.Vector3(0,-1,0),scene)).intensity=.5,e.diffuse=new BABYLON.Color3(1,.8,.6),(shadowGen=new BABYLON.ShadowGenerator(1024,light)).useBlurExponentialShadowMap=!0,shadowGen.frustumEdgeFalloff=1,light.shadowMinZ=1,light.shadowMaxZ=40,light.shadowFrustumSize=10,shadowGen.blurScale=2,shadowGen.blurBoxOffset=1,camera=new BABYLON.FreeCamera("camera",new BABYLON.Vector3(0,.2,0),scene),scene.activeCameras.push(camera),camera.maxZ=100,camera.fov=.5,camera.minZ=.1,camera.rotation.x=.12,loadResources(function(){document.getElementById("mainMenu").style.display="flex",document.getElementById("characterCanvasContainer").appendChild(canvas),resize(),closeAlertDialog(),onResourcesLoaded(),document.getElementById("username").disabled=!1})}function hideMainMenu(){document.getElementById("mainMenu").style.display="none"}function toggleFullscreen(){if(document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement)(t=document.exitFullscreen||document.webkitExitFullscreen||document.mozCancelFullScreen||document.msExitFullscreen)&&t.call(document);else{var e=document.getElementById("container"),t=e.requestFullscreen||e.webkitRequestFullscreen||e.mozRequestFullScreen||e.msRequestFullscreen;t&&(t.call(e),ga("send","event","fullscreen"))}}function onFullscreenChange(){engine.resize();var e=document.getElementById("container");e.style.display="none",setTimeout(function(){e.style.display="flex"},1)}function openSettingsMenu(){ga("send","event","open settings"),document.getElementById("settings").style.display="block",document.getElementById("help").style.display="none",localStorage.setItem("hideHelp",1)}function closeSettingsMenu(){document.getElementById("settings").style.display="none"}function showChangelog(){ga("send","event","view changelog"),openAlertDialog("Version "+version,document.getElementById("changelog").innerHTML,{label:"OK"})}function PlayerActor(e){if(this.player=e,this.mesh=new BABYLON.AbstractMesh("player",scene),this.player==me?(this.bodyMesh=new BABYLON.AbstractMesh("egg",this.mesh),this.bodyMesh.position.y=.32,this.bodyMesh.parent=this.mesh,this.bodyMesh.player=this.player):(this.bodyMesh=Meshes.egg.clone("egg",this.mesh),this.bodyMesh.position.y=.32,this.bodyMesh.parent=this.mesh,this.bodyMesh.player=this.player,this.bodyMesh.material=Materials.eggShell),this.explodeMesh=Meshes.eggExplode.clone("explode",this.mesh),this.explodeMesh.position.y=.32,this.explodeMesh.parent=this.mesh,this.explodeMesh.setMaterial(Materials.normalBackface),this.explodeMesh.setEnabled(!1),this.whiteMesh=Meshes.eggWhite.clone("white",this.mesh),this.whiteMesh.parent=this.explodeMesh,this.whiteMesh.setEnabled(!1),this.yolkMesh=Meshes.eggYolk.clone("yolk",this.mesh),this.yolkMesh.parent=this.explodeMesh,this.yolkMesh.setEnabled(!1),this.head=new BABYLON.AbstractMesh("head",scene),this.head.parent=this.mesh,this.head.position.y=.3,this.head.position.z=0,this.gunContainer=new BABYLON.AbstractMesh("gunContainer",scene),this.gunContainer.parent=this.head,this.gunContainer.rotation.y=-.14,this.gunContainer.rotation.x=-.035,this.eye=new BABYLON.AbstractMesh("eye",scene),this.eye.position.y=.1,this.eye.position.x=.1,this.eye.parent=this.head,this.gripHand=Meshes.gripHand.clone("gripHand",this.gunContainer),this.gripHand.parent=this.gunContainer,this.foreHand=Meshes.foreHand.clone("foreHand",this.gunContainer),this.foreHand.parent=this.gunContainer,this.recoil={rot:{x:0,y:0},targetRot:{x:0,y:0},kick:0,targetKick:0},shadowGen.getShadowMap().renderList.push(this.bodyMesh),inGame)if(this.player.id==meId)this.gripHand.renderingGroupId=2,this.foreHand.renderingGroupId=2;else{this.nameSurface=BABYLON.Mesh.CreatePlane("nameSurface",.5,scene,!1),this.nameSurface.material=new BABYLON.StandardMaterial("nameSurfaceMaterial",scene),this.nameSurface.material.specularColor=new BABYLON.Color3(0,0,0),this.nameSurface.material.emissiveColor=new BABYLON.Color3(1,1,1);var t=new BABYLON.DynamicTexture("nameTexture",256,scene,!1,1);this.nameSurface.material.diffuseTexture=t,this.nameSurface.material.diffuseTexture.hasAlpha=!0,this.nameSurface.material.useAlphaFromDiffuseTexture=!0,this.nameSurface.material.backFaceCulling=!1,t.drawText(this.player.name,9*(14-this.player.name.length),30,"bold 30px Nunito","white","transparent"),this.nameSurface.parent=this.mesh,this.nameSurface.billboardMode=BABYLON.AbstractMesh.BILLBOARDMODE_ALL,this.nameSurface.position.y=.475}this.mesh.position.x=this.player.x,this.mesh.position.y=this.player.y,this.mesh.position.z=this.player.z,this.deathSound=Sounds.shellBurst.clone(),this.hitSound=Sounds.hit.clone(),this.bodyMesh.attachSound(this.hitSound)}function Bullet(){this.x=0,this.y=0,this.z=0,this.dx=0,this.dy=0,this.dz=0,this.ttl=0,this.active=!1,this.player=null,this.damage=20,void 0!==BulletActor&&(this.actor=new BulletActor(this))}function Gun(e){this.player=e,this.rofCountdown=0,this.shotsQueued=0,this.reloadCountdown=0,this.triggerPulled=!1,this.equipCountdown=0}function Eggk47(e){Gun.call(this,e),this.name="EggK-47",this.ammo={rounds:30,capacity:30,reload:30,store:240,storeMax:240,pickup:30},this.rof=6,this.automatic=!0,this.accuracy=15,this.shotSpreadIncrement=45,this.accuracySettleFactor=.91,this.damage=200,this.totalDamage=250,this.ttl=30,this.velocity=.5,this.range=this.ttl*this.velocity,this.equipTime=15,this.stowWeaponTime=15,this.longReloadTime=125,this.shortReloadTime=84,void 0!==Eggk47Actor&&(this.actor=new Eggk47Actor(this))}function DozenGauge(e){Gun.call(this,e),this.name="Dozen Gauge",this.ammo={rounds:2,capacity:2,reload:2,store:24,storeMax:24,pickup:8},this.rof=15,this.automatic=!1,this.accuracy=50,this.shotSpreadIncrement=160,this.accuracySettleFactor=.9,this.damage=9.5,this.totalDamage=20*this.damage,this.ttl=15,this.velocity=.45,this.range=this.ttl*this.velocity,this.equipTime=15,this.stowWeaponTime=15,this.longReloadTime=95,this.shortReloadTime=95,void 0!==DozenGaugeActor&&(this.actor=new DozenGaugeActor(this))}
- function CSG1(e){Gun.call(this,e),this.name="CSG-1",this.ammo={rounds:5,capacity:5,reload:5,store:15,storeMax:15,pickup:5},this.rof=60,this.automatic=!1,this.accuracy=0,this.shotSpreadIncrement=10,this.accuracySettleFactor=.4,this.damage=250,this.totalDamage=250,this.ttl=80,this.velocity=.9,this.range=this.ttl*this.velocity,this.equipTime=15,this.stowWeaponTime=15,this.longReloadTime=10,this.shortReloadTime=5,void 0!==CSG1Actor&&(this.actor=new CSG1Actor(this))}
- function Cluck9mm(e){Gun.call(this,e),this.name="Cluck 9mm",this.ammo={rounds:15,capacity:15,reload:15,store:60,storeMax:60,pickup:15},this.rof=6,this.automatic=!1,this.accuracy=30,this.shotSpreadIncrement=100,this.accuracySettleFactor=.82,this.damage=35,this.totalDamage=35,this.ttl=100,this.velocity=.45,this.range=this.ttl*this.velocity,this.equipTime=15,this.stowWeaponTime=15,this.longReloadTime=113,this.shortReloadTime=113,void 0!==Cluck9mmActor&&(this.actor=new Cluck9mmActor(this))}function MunitionsManager(){this.bulletPool=new Pool(function(){return new Bullet},1e3)}function Player(e){this.id=e.id,this.name=e.name,this.charClass=e.charClass,this.x=e.x,this.y=e.y,this.z=e.z,this.dx=e.dx,this.dy=e.dy,this.dz=e.dz,this.viewYaw=e.viewYaw,this.controlKeys=e.controlKeys,this.moveYaw=e.moveYaw,this.pitch=e.pitch,this.totalKills=e.totalKills,this.totalDeaths=e.totalDeaths,this.killStreak=e.killStreak,this.bestKillStreak=e.bestKillStreak,this.hp=e.hp,this.weaponIdx=e.weaponIdx,this.equipWeaponIdx=0,this.stowWeaponCountdown=0,this.shotSpread=0,this.jumping=!1,this.stateIdx=0,this.previousStates=Array(256).fill({delta:0,moveYaw:0,fire:!1,jump:!1,x:e.x,y:e.y,z:e.z,dx:0,dy:0,dz:0,controlKeys:0}),void 0!==PlayerActor&&(this.actor=new PlayerActor(this)),this.weapons=[new Cluck9mm(this),new classes[this.charClass].weapon(this)],this.weapon=this.weapons[0]}function Pool(e,t){this.size=0,this.originalSize=t,this.constructorFn=e,this.objects=[],this.idx=0,this.numActive=0,this.expand(t)}BulletActor.prototype.fire=function(){this.mesh.setEnabled(!0),this.mesh.position.x=this.bullet.x,this.mesh.position.y=this.bullet.y,this.mesh.position.z=this.bullet.z,this.mesh.lookAt(new BABYLON.Vector3(this.bullet.x+this.bullet.dx,this.bullet.y+this.bullet.dy,this.bullet.z+this.bullet.dz)),this.mesh.rotation.x+=.015,this.mesh.rotation.y-=.015,this.mesh.scaling.z=.5},BulletActor.prototype.update=function(){this.mesh.position.x=this.bullet.x,this.mesh.position.y=this.bullet.y,this.mesh.position.z=this.bullet.z,this.mesh.scaling.z=Math.min(this.mesh.scaling.z+.05,3)},BulletActor.prototype.remove=function(){this.mesh.setEnabled(!1)};var Meshes={},Materials={},Sounds={},mapMesh;BABYLON.Mesh.prototype.attachToParent=function(e){this.parent=e,this.position=BABYLON.Vector3.Zero(),this.rotation=BABYLON.Vector3.Zero(),this.rotationQuaternion=BABYLON.Quaternion.Identity()},BABYLON.AbstractMesh.prototype.getChildMeshByName=function(e){for(var t=this.getChildMeshes(),n=0;n<t.length;n++)if(t[n].name==e)return t[n];return null},BABYLON.AbstractMesh.prototype.setLayerMask=function(e){this.layerMask=e;for(var t=this.getChildMeshes(),n=0;n<t.length;n++)t[n].setLayerMask(e)},BABYLON.AbstractMesh.prototype.setRenderingGroupId=function(e){this.renderingGroupId=e;for(var t=this.getChildMeshes(),n=0;n<t.length;n++)t[n].setRenderingGroupId(e)},BABYLON.AbstractMesh.prototype.setMaterial=function(e){this.material=e;for(var t=this.getChildMeshes(),n=0;n<t.length;n++)t[n].setMaterial(e)},BABYLON.AbstractMesh.prototype.attachSound=function(e){this.attachedSounds||(this.attachedSounds=[]),e.attachToMesh(this),this.attachedSounds.push(e)},BABYLON.AbstractMesh.prototype.disposeOfSounds=function(){if(this.attachedSounds)for(var e in this.attachedSounds)this.attachedSounds[e].detachFromMesh(),this.attachedSounds[e].dispose();for(var t=this.getChildMeshes(),n=0;n<t.length;n++)t[n].disposeOfSounds()};var bulletHoleManager,respawnTime,players,keyIsDown,map,inputTally,light,camera,uiCamera,me,lastTimeStamp,lastDelta,fps,fpsSum,fpsIdx,reticle,hitIndicator,munitionsManager,itemManager,killDisplayTimeout,SPS,rotInc=Math.PI/2,pingStartTime,controlToBitmask={up:1,down:2,left:4,right:8};HitIndicator.prototype.resize=function(){this.mesh.scaling.x=window.innerWidth,this.mesh.scaling.y=window.innerHeight},HitIndicator.prototype.update=function(e){for(var t=7;t<48;t+=4)this.colors[t]-=(this.colors[t]+.5)/10*e;var n=Math.pow(.9,e);me&&!me.isDead()&&(camera.position.x*=n,camera.position.z*=n),this.mesh.updateVerticesData(BABYLON.VertexBuffer.ColorKind,this.colors,!0),document.getElementById("healthBar").style.width=me.hp+"%"},HitIndicator.prototype.hit=function(e,t){var n=Math.radRange(-Math.atan2(e,-t)-me.viewYaw+.393);n=Math.floor(n/Math.PI2*8);var a=new BABYLON.Vector2(-this.positions[3*n+3],-this.positions[3*n+4]).normalize();camera.position.x=.03*a.x,camera.position.z=.03*a.y,this.colors[4*n+7]=2},Reticle.prototype.update=function(e){if(me.weapon)for(var t=0;t<4;t++){var n=t*Math.PI/2,a=1+me.weapon.accuracy;this.lines[t].position.x=-Math.sin(n)*a,this.lines[t].position.y=Math.cos(n)*a}},Eggk47Actor.prototype.addSoundEvent=function(e,t){var n=new BABYLON.AnimationEvent(e,function(){t.play()});this.playerActor.gripHand.animations[0].addEvent(n),this.gunMesh.attachSound(t)},Eggk47Actor.prototype.animate=function(e,t,n){scene.beginAnimation(this.playerActor.gripHand,e,t,!1,1,n),scene.beginAnimation(this.playerActor.foreHand,e,t,!1,1),scene.beginAnimation(this.gunMesh,e,t,!1,1),scene.beginAnimation(this.clipMesh,e,t,!1,1)},Eggk47Actor.prototype.dryFire=function(){this.dryFireSound.play()},Eggk47Actor.prototype.fire=function(){this.fireSound.play(),this.muzzleFlash.rotation.z=3.141*Math.random(),this.muzzleFlash.setEnabled(!0);var e=this;setTimeout(function(){e.muzzleFlash.setEnabled(!1)},40),this.animate(0,6)},Eggk47Actor.prototype.reload=function(){var e=this;this.animate(7,74,function(){e.gun.ammo.rounds>0?e.animate(133,154,function(){e.gun.reloadCountdown=0}):e.animate(74,132,function(){e.gun.reloadCountdown=0})})},Eggk47Actor.prototype.stow=function(){var e=this;this.animate(154,168,function(){e.gunMesh.setEnabled(!1),e.clipMesh.setEnabled(!1),e.gun.player.stowWeaponCountdown=0})},Eggk47Actor.prototype.equip=function(){var e=this;this.gunMesh.setEnabled(!0),this.clipMesh.setEnabled(!0),this.animate(168,182,function(){e.gun.equipCountdown=0})},Eggk47Actor.prototype.update=function(){},DozenGaugeActor.prototype.addSoundEvent=function(e,t){var n=new BABYLON.AnimationEvent(e,function(){t.play()});this.playerActor.gripHand.animations[0].addEvent(n),this.gunMesh.attachSound(t)},DozenGaugeActor.prototype.animate=function(e,t,n){scene.beginAnimation(this.playerActor.gripHand,e,t,!1,1,n),scene.beginAnimation(this.playerActor.foreHand,e,t,!1,1),scene.beginAnimation(this.gunMesh,e,t,!1,1),scene.beginAnimation(this.barrel,e,t,!1,1)},DozenGaugeActor.prototype.dryFire=function(){this.dryFireSound.play()},DozenGaugeActor.prototype.fire=function(){this.fireSound.play(),this.muzzleFlash.rotation.z=3.141*Math.random(),this.muzzleFlash.setEnabled(!0);var e=this;setTimeout(function(){e.muzzleFlash.setEnabled(!1)},40),this.animate(300,320)},DozenGaugeActor.prototype.reload=function(){var e=this;this.animate(320,415,function(){e.gun.reloadCountdown=0})},DozenGaugeActor.prototype.stow=function(){var e=this;this.animate(416,433,function(){e.gunMesh.setEnabled(!1),e.gun.player.stowWeaponCountdown=0})},DozenGaugeActor.prototype.equip=function(){var e=this;this.gunMesh.setEnabled(!0),this.animate(433,449,function(){e.gun.equipCountdown=0})},DozenGaugeActor.prototype.update=function(){},CSG1Actor.prototype.addSoundEvent=function(e,t){var n=new BABYLON.AnimationEvent(e,function(){t.play()});this.playerActor.gripHand.animations[0].addEvent(n),this.gunMesh.attachSound(t)},CSG1Actor.prototype.animate=function(e,t,n){scene.beginAnimation(this.playerActor.gripHand,e,t,!1,1,n),scene.beginAnimation(this.playerActor.foreHand,e,t,!1,1),scene.beginAnimation(this.gunMesh,e,t,!1,1),scene.beginAnimation(this.clipMesh,e,t,!1,1)},CSG1Actor.prototype.dryFire=function(){this.dryFireSound.play()},CSG1Actor.prototype.fire=function(){this.fireSound.play(),this.muzzleFlash.rotation.z=3.141*Math.random(),this.muzzleFlash.setEnabled(!0);var e=this;setTimeout(function(){e.muzzleFlash.setEnabled(!1)},40),this.animate(800,860)},CSG1Actor.prototype.reload=function(){var e=this;e.gun.ammo.rounds>0?this.animate(860,1e3,function(){e.gun.reloadCountdown=0}):this.animate(1001,1080,function(){e.animate(880,952,function(){e.animate(1081,1165,function(){e.gun.reloadCountdown=0})})})},CSG1Actor.prototype.stow=function(){var e=this;this.animate(1166,1181,function(){e.gunMesh.setEnabled(!1),e.clipMesh.setEnabled(!1),e.gun.player.stowWeaponCountdown=0})},CSG1Actor.prototype.equip=function(){var e=this;this.gunMesh.setEnabled(!0),this.clipMesh.setEnabled(!0),this.animate(1181,1196,function(){e.gun.equipCountdown=0})},CSG1Actor.prototype.update=function(){},Cluck9mmActor.prototype.addSoundEvent=function(e,t){var n=new BABYLON.AnimationEvent(e,function(){t.play()});this.playerActor.gripHand.animations[0].addEvent(n),this.gunMesh.attachSound(t)},Cluck9mmActor.prototype.animate=function(e,t,n){scene.beginAnimation(this.playerActor.gripHand,e,t,!1,1,n),scene.beginAnimation(this.playerActor.foreHand,e,t,!1,1),scene.beginAnimation(this.gunMesh,e,t,!1,1),scene.beginAnimation(this.clipMesh,e,t,!1,1)},Cluck9mmActor.prototype.dryFire=function(){this.dryFireSound.play()},Cluck9mmActor.prototype.fire=function(){this.fireSound.play(),this.muzzleFlash.rotation.z=3.141*Math.random(),this.muzzleFlash.setEnabled(!0);var e=this;setTimeout(function(){e.muzzleFlash.setEnabled(!1)},40),this.animate(600,606)},Cluck9mmActor.prototype.reload=function(){var e=this;this.animate(607,720,function(){e.gun.reloadCountdown=0})},Cluck9mmActor.prototype.stow=function(){var e=this;this.animate(721,735,function(){e.gunMesh.setEnabled(!1),e.gun.player.stowWeaponCountdown=0})},Cluck9mmActor.prototype.equip=function(){var e=this;this.gunMesh.setEnabled(!0),this.animate(735,750,function(){e.gun.equipCountdown=0})},Cluck9mmActor.prototype.update=function(){},ItemActor.prototype.update=function(e){this.mesh.rotation.y+=.03*e},ItemActor.prototype.remove=function(){this.mesh.setEnabled(!1)},AmmoActor.prototype=Object.create(ItemActor.prototype),AmmoActor.prototype.constructor=ItemActor,ItemManager.AMMO=0,ItemManager.Constructors=[AmmoActor],ItemManager.prototype.update=function(e){for(var t=0;t<this.pools.length;t++)this.pools[t].forEachActive(function(t){t.update(e)})},ItemManager.prototype.spawnItem=function(e,t,n,a,o){var i=this.pools[t].retrieve(e);i.mesh.setEnabled(!0),i.mesh.position.x=n,i.mesh.position.y=a,i.mesh.position.z=o},ItemManager.prototype.collectItem=function(e,t){this.pools[e].recycle(this.pools[e].objects[t]),this.pools[e].objects[t].remove()};var fbAppId="503435033333554",engine,scene,canvas,shadowGen,camera,light,engineCaps,ws,selectedClass,selectedServer,meId,username,gameSession,facebookId,gameStartTime,pingTotal,pingSamples,fpsTotal,fpsSamples,nextPingSample,inGame=!1,uniqueId,uniqueKey,privateGame,settings={},inputToControlMap={W:"up",S:"down",A:"left",D:"right",SPACE:"jump","MOUSE 0":"fire",R:"reload",E:"weapon"},ga;!function(e,t,n,a,o,i,s){e.GoogleAnalyticsObject=o,e[o]=e[o]||function(){(e[o].q=e[o].q||[]).push(arguments)},e[o].l=1*new Date,i=t.createElement(n),s=t.getElementsByTagName(n)[0],i.async=1,i.src="https://www.google-analytics.com/analytics.js",s.parentNode.insertBefore(i,s)}(window,document,"script",0,"ga"),ga("create","UA-105800112-1","auto"),ga("send","pageview"),window.onmessage=function(e){var t=e.data;"function"==typeof window[t.func]&&window[t.func].call(null,t.message)},window.addEventListener("contextmenu",function(e){e.preventDefault()},!1),window.onresize=function(){resize()},window.onload=function(){function e(e){console.log(e),facebookId=null,gameSession=null,d=e;var t=document.getElementById("ritekit-alerts");t&&(t.style.visibility="hidden"),"connected"===e.status?(document.getElementById("fbLoginRequest").style.display="none",document.getElementById("statsRetrieval").style.display="block",facebookId=e.authResponse.userID,getRequest("!host_specific/requestUserData.php?id="+e.authResponse.userID+"&token="+e.authResponse.accessToken,function(e){try{var t=JSON.parse(e);if(t.error)document.getElementById("stats").innerText="DB error: "+t.error;else{var n=Math.floor(t.kills/Math.max(t.kills+t.deaths,1)*100);document.getElementById("stats").innerHTML=t.kills.toLocaleString()+"<br>"+t.deaths.toLocaleString()+"<br>"+n+"%<br>"+t.streak.toLocaleString(),document.getElementById("statsRetrieval").style.display="none",document.getElementById("statsPane").style.display="block",gameSession=t.session}}catch(t){document.getElementById("stats").innerHTML=e}})):(d={status:null},console.log("lsdkfjdslkj"),document.getElementById("fbLoginRequest").style.display="block")}if(resize(),BABYLON.Engine.isSupported()){for(var t=[{image:"TopTank_banner_01.png",link:"https://itunes.apple.com/app/top-tank/id925229581?mt=8"},{image:"TopTank_banner_01.png",link:"https://itunes.apple.com/app/top-tank/id925229581?mt=8"},{image:"TopTank_banner_01.png",link:"https://itunes.apple.com/app/top-tank/id925229581?mt=8"},{image:"TopTank_banner_01.png",link:"https://itunes.apple.com/app/top-tank/id925229581?mt=8"},{image:"ST_banner_00.png",link:"http://store.steampowered.com/app/562230/Space_Tyrant/"},{image:"ST_banner_01.jpg",link:"http://store.steampowered.com/app/562230/Space_Tyrant/"},{image:"ST_banner_02.jpg",link:"http://store.steampowered.com/app/562230/Space_Tyrant/"},{image:"ST_banner_03.jpg",link:"http://store.steampowered.com/app/562230/Space_Tyrant/"},{image:"ST_banner_04.jpg",link:"http://store.steampowered.com/app/562230/Space_Tyrant/"}],n=(Math.randomInt(0,t.length),document.getElementById("serverSelect")),a=0;a<servers.length;a++){var o=servers[a];(r=document.createElement("option")).textContent=o.name,n.appendChild(r),o.pingEl=new Image,o.pingEl.idx=a,o.pingEl.onerror=function(e){selectedServer=e.target.idx,n.selectedIndex=selectedServer;for(var t=0;t<servers.length;t++)servers[t].pingEl.onerror=null}}for(a=0;a<servers.length;a++)servers[a].pingEl.src="http://"+servers[a].address;settings.volume=getStoredNumber("volume",1),settings.mouseInvert=getStoredNumber("mouseInvert",1),settings.mouseSensitivity=getStoredNumber("mouseSensitivity",5),inputToControlMap=JSON.parse(localStorage.getItem("controlConfig"))||inputToControlMap;for(var i in inputToControlMap)inputToControlMap.hasOwnProperty(i)&&i!=i.toLocaleUpperCase()&&(inputToControlMap[i.toLocaleUpperCase()]=inputToControlMap[i],delete inputToControlMap[i]);for(var s in inputToControlMap){var r=document.getElementById(inputToControlMap[s]);r.innerText=s.toLocaleUpperCase(),r.style.fontWeight="bold",r.style.color="#fff"}document.getElementById("volume").value=settings.volume,document.getElementById("mouseSensitivity").value=settings.mouseSensitivity,document.getElementById("mouseInvert").checked=-1==settings.mouseInvert;for(var l=document.getElementById("playerList"),h=document.getElementById("playerSlot"),a=0;a<20;a++){var c=h.cloneNode(!0);l.appendChild(c)}getStoredString("lastVersionPlayed",version);getStoredNumber("hideHelp",null)&&(document.getElementById("help").style.display="none");var d={status:null};window.checkLoginState=function(){FB.getLoginStatus(function(t){e(t)})},window.fbAsyncInit=function(){FB.init({appId:fbAppId,cookie:!0,xfbml:!0,version:"v2.8"}),FB.AppEvents.logPageView(),FB.getLoginStatus(function(t){e(t)}),FB.Event.subscribe("auth.login",function(t){e(t)})},function(e,t,n){var a,o=e.getElementsByTagName(t)[0];e.getElementById(n)||((a=e.createElement(t)).id=n,a.src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.11&appId=503435033333554",o.parentNode.insertBefore(a,o))}(document,"script","facebook-jssdk"),canvas=document.createElement("canvas"),document.getElementById("offCanvasContainer").appendChild(canvas),resize(),engine=new BABYLON.Engine(canvas,!0,null,!1),engineCaps=engine.getCaps(),showMainMenu(),"?openSettings"==window.location.search&&openSettingsMenu(),window.location.hash&&(openJoinBox(),document.getElementById("joinCode").value=window.location.hash.substr(1))}else openAlertDialog("OH, NO!",'Shell Shockers requires WebGL, but your<br>browser is not configured to support it.<br><br><a style="text-decoration: underline" target="_window" href="http://shellshock.io/faq.html#webgl">Click here to learn more</a>')},window.onbeforeunload=function(e){if(gameStartTime>0){var t=Date.now()-gameStartTime;ga("send","timing","game","play time",t),fbq("trackCustom","EndGame",{timePlayed:t})}pingSamples>4&&(ga("send","timing","game","ping",Math.floor(pingTotal/pingSamples),servers[selectedServer].name),ga("send","event","game","stats","fps",Math.ceil(fpsTotal/fpsSamples)),ga("send","event","game","settings","volume",settings.volume),ga("send","event","game","settings","mouse sensitivity",settings.mouseSensitivity),ga("send","event","game","settings","mouse invert",settings.mouseInvert))};var controlEl,alertBarInterval;document.onfullscreenchange=onFullscreenChange,document.onmsfullscreenchange=onFullscreenChange,document.onmozfullscreenchange=onFullscreenChange,document.onwebkitfullscreenchange=onFullscreenChange,PlayerActor.prototype.update=function(){var e=this.player.x-this.mesh.position.x,t=this.player.y-this.mesh.position.y,n=this.player.z-this.mesh.position.z;Math.length3(e,t,n)<.9?(this.mesh.position.x+=e/6,this.mesh.position.y+=t/2,this.mesh.position.z+=n/6):(this.mesh.position.x=this.player.x,this.mesh.position.y=this.player.y,this.mesh.position.z=this.player.z);var a=.9;this.player.id!=meId&&(a=.5);var o=Math.radDifference(this.player.viewYaw,this.mesh.rotation.y),i=Math.radDifference(this.player.pitch,this.head.rotation.x);this.player.addRotationShotSpread(o,i),this.mesh.rotation.y+=o*a,this.head.rotation.x+=i*a,this.bodyMesh.rotation.x=this.head.rotation.x/4,this.recoil.rot.x+=(this.recoil.targetRot.x-this.recoil.rot.x)/4,this.recoil.rot.y+=(this.recoil.targetRot.y-this.recoil.rot.y)/4,this.recoil.kick+=(this.recoil.targetKick-this.recoil.kick)/4,this.recoil.targetRot.x*=.5,this.recoil.targetRot.y*=.5,this.recoil.targetKick*=.5},PlayerActor.prototype.die=function(){this.bodyMesh.setEnabled(!1),this.head.setEnabled(!1),this.eye.setEnabled(!1),this.nameSurface&&this.nameSurface.setEnabled(!1)},PlayerActor.prototype.respawn=function(){this.bodyMesh.setEnabled(!0),this.head.setEnabled(!0),this.eye.setEnabled(!0),this.nameSurface&&this.nameSurface.setEnabled(!0),this.explodeMesh.setEnabled(!1),this.whiteMesh.setEnabled(!1),this.yolkMesh.setEnabled(!1)},PlayerActor.prototype.remove=function(){this.mesh.disposeOfSounds(),this.mesh.dispose()},PlayerActor.prototype.fire=function(){this.recoil.targetRot.x=-.05*Math.random()-.07,this.recoil.targetRot.y=.1*Math.random()-.05,this.recoil.targetKick=.1*Math.random()+.2},BABYLON.Effect.ShadersStore.standardVertexShader="\n#include<instancesDeclaration>\n\nprecision highp float;\n\n// Attributes\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec4 color;\nattribute vec2 uv; // X\n\n// Uniforms\n//uniform mat4 world;\nuniform mat4 view;\nuniform mat4 viewProjection; // X\nuniform mat4 shadowLightMat;\n\n// Varying\nvarying vec4 vPositionFromLight;\nvarying vec3 vNormal;\nvarying vec4 vColor;\nvarying float fFogDistance;\n\nfloat random(vec2 p)\n{\nvec2 K1 = vec2(23.14069263277926, 2.665144142690225);\nreturn fract(cos(dot(p, K1)) * 12345.6789);\n}\n\n// MAIN\nvoid main(void) {\n#include<instancesVertex>\nvec4 worldPosition = finalWorld * vec4(position, 1.);\n\n#ifdef RECEIVESHADOWS\nvPositionFromLight = shadowLightMat * worldPosition;\n#endif\n\nvNormal = normalize(vec3(world * vec4(normal, 0.0)));\nvColor = color;\n\n#ifdef DIRT\nvColor.rgb *= random(worldPosition.xy) * 0.1 + 0.7;\n#endif\n\nfFogDistance = (view * worldPosition).z;\ngl_Position = viewProjection * worldPosition;\n}\n",BABYLON.Effect.ShadersStore.standardPixelShader="\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\n\nprecision highp float;\n\n// Uniforms\nuniform sampler2D shadowSampler;\nuniform vec3 shadowParams;\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nuniform mat4 worldView;\nuniform float hp;\n\n// Varying\nvarying vec4 vPositionFromLight;\nvarying vec4 vColor;\nvarying vec3 vNormal;\nvarying float fFogDistance;\n\nconst float sOff = .001;\n\n// FUNCTIONS\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift = vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0);\nreturn dot(color, bit_shift);\n}\n\nfloat random(vec2 p)\n{\nvec2 K1 = vec2(23.14069263277926, 2.665144142690225);\nreturn fract(cos(dot(p, K1)) * 12345.6789);\n}\n\nfloat calcFogFactor()\n{\nfloat fogCoeff = 1.0;\nfloat fogStart = vFogInfos.y;\nfloat fogEnd = vFogInfos.z;\nfloat fogDensity = vFogInfos.w;\n\n//fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart); // Linear\n//fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity * 2.); // Exp;\nfogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity * 4.); // Exp2\n\nreturn clamp(fogCoeff, 0.0, 1.0);\n}\n\nfloat computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float darkness)\n{\nvec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\ndepth = 0.5 * depth + vec3(0.5);\nvec2 uv = depth.xy;\n\nif (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\n{\nreturn 1.0;\n}\n\n#ifndef SHADOWFULLFLOAT\nfloat shadow = unpack(texture2D(shadowSampler, uv));\n#else\nfloat shadow = texture2D(shadowSampler, uv).x;\n#endif\n\nif (depth.z < shadow) return 1.;\n//return 0.5;\nfloat s = clamp((depth.z - shadow) * 24. + 0.5, 0.5, 1.0);\nreturn min(1.0, max(s, length(vPositionFromLight.xy)));\n}\n\nvec3 desaturate(vec3 color, float amount)\n{\nvec3 gray = vec3(dot(vec3(0.2126,0.7152,0.0722), color));\nreturn vec3(mix(color, gray, amount));\n}\n\n// MAIN\nvoid main(void)\n{\nvec4 color = vColor;\n\n#ifdef EGGSHELL\ncolor.rgb = min((color.rgb - 0.5) * 4. + hp + 2., 1.);\n#endif\n\n#ifdef RECEIVESHADOWS\nfloat s = computeShadow(vPositionFromLight, shadowSampler, shadowParams.x);\n//s = clamp(s, 0.66, 1.);\nif (vNormal.y > -0.5)\n{\ncolor *= vec4(s, s, s, 1.0);\n}\n#endif\n\ncolor.rgb *= max(max(0., -vNormal.y * 0.4), dot(vNormal, normalize(vec3(-.2, 1., -.1)) * 1.) + 0.4);\ncolor.rgb = min(color.rgb, vec3(1., 1., 1.));\ncolor.rgb = color.rgb * (vec3(1., 1., 1.) - color.rgb) * .5 + color.rgb;\ncolor.rgb = desaturate(color.rgb, 1. - length(color.rgb));\n\nfloat fog = calcFogFactor();\ncolor.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\n\ngl_FragColor = color;\n}\n",Bullet.prototype.update=function(e){if(this.ttl<=0||this.collidesWithMap())return munitionsManager.bulletPool.recycle(this),void(this.actor&&this.actor.remove());this.x+=this.dx*e,this.y+=this.dy*e,this.z+=this.dz*e,this.ttl-=e,this.actor&&this.actor.update()},Bullet.prototype.fire=function(e,t,n,a,o,i){this.player=e,this.x=t.x,this.y=t.y,this.z=t.z,this.dx=n.x*i,this.dy=n.y*i,this.dz=n.z*i,this.ttl=o,this.damage=a,this.active=!0,this.actor&&this.actor.fire()},Bullet.prototype.collidesWithCell=function(){var e=Math.floor(this.x),t=Math.floor(this.y),n=Math.floor(this.z);if(e<0||n<0||e>=map.width||n>=map.depth||t<0||t>=map.height)return!1;try{var a=map.data[e][t][n]}catch(a){log.err("Seriously, bullet?? fx: "+e+" fy: "+t+" fz: "+n)}if(a.cat){if(2==a.cat)switch(a.dir){case 0:if(this.y-t>this.z-n)return!1;break;case 2:if(this.y-t>1-(this.z-n))return!1;break;case 1:if(this.y-t>this.x-e)return!1;break;case 3:if(this.y-t>1-(this.x-e))return!1}else if(3==a.cat){var o=this.x-e,i=this.z-n;if(o>.7||o<.3||i>.7||i<.3)return!1}else if(4==a.cat){var o=this.x-e,s=this.y-t,i=this.z-n;if(o>.7||o<.3||i>.7||i<.3||s>.5)return!1}return{x:e,y:t,z:n}}},Bullet.prototype.collidesWithMap=function(){if(this.y<0)return this.actor&&this.x>0&&this.z>0&&this.x<map.width&&this.z<map.depth&&bulletHoleManager.addHole(1,this.x,.01,this.z),!0;if(this.y>=map.height)return!1;if(this.x<0||this.x>=map.width||this.z<0||this.z>=map.depth)return!1;var e=this.collidesWithCell();if(e){if(this.actor){var t=map.data[e.x][e.y][e.z];if(t&&Meshes.map[t.cat][t.dec]){var n=new BABYLON.Ray(new BABYLON.Vector3(this.x-this.dx-e.x-.5,this.y-this.dy-e.y,this.z-this.dz-e.z-.5),new BABYLON.Vector3(this.dx,this.dy,this.dz),new BABYLON.Vector3(this.dx,this.dy,this.dz).length);Meshes.map[t.cat][t.dec].rotation.y=t.dir*rotInc;var a=n.intersectsMesh(Meshes.map[t.cat][t.dec],!1);if(a.hit){var o=new BABYLON.Vector3(-this.dx,-this.dy,-this.dz).normalize().scale(.005);bulletHoleManager.addHole(0,a.pickedPoint.x+e.x+.5+o.x,a.pickedPoint.y+e.y+o.y,a.pickedPoint.z+e.z+.5+o.z)}}}return!0}};var Comm={loggedIn:0,addPlayer:1,removePlayer:2,chat:3,keyDown:4,keyUp:5,sync:6,fire:7,jump:8,die:9,hitThem:10,hitMe:11,collectItem:12,spawnItem:13,respawn:14,startReload:15,reload:16,stowWeapon:17,equipWeapon:18,fireBullet:19,fireShot:20,login:21,invalidName:22,ping:23,pong:24,clientReady:25,requestRespawn:26,status:27,output:function(e){this.buffer=new Uint8Array(e),this.idx=0,this.packInt8=function(e){this.buffer[this.idx]=255&e,this.idx++},this.packInt16=function(e){this.buffer[this.idx]=255&e,this.buffer[this.idx+1]=e>>8&255,this.idx+=2},this.packInt32=function(e){this.buffer[this.idx]=255&e,this.buffer[this.idx+1]=e>>8&255,this.buffer[this.idx+2]=e>>16&255,this.buffer[this.idx+3]=e>>24&255,this.idx+=4},this.packRadU=function(e){this.packInt16(1e4*e)},this.packRad=function(e){this.packInt16(1e4*(e+Math.PI))},this.packFloat=function(e){this.packInt16(100*e)},this.packString=function(e){this.packInt8(e.length);for(var t=0;t<e.length;t++)this.packInt16(e.charCodeAt(t))}},input:function(e){this.buffer=new Uint8Array(e),this.idx=0,this.isMoreDataAvailable=function(){return this.idx<this.buffer.length},this.unPackInt8U=function(){var e=this.idx;return this.idx++,this.buffer[e]},this.unPackInt8=function(){return(this.unPackInt8U()+128)%256-128},this.unPackInt16U=function(){var e=this.idx;return this.idx+=2,this.buffer[e]+(this.buffer[e+1]<<8)},this.unPackInt32U=function(){var e=this.idx;return this.idx+=4,this.buffer[e]+256*this.buffer[e+1]+65536*this.buffer[e+2]+16777216*this.buffer[e+3]},this.unPackInt16=function(){return(this.unPackInt16U()+32768)%65536-32768},this.unPackRadU=function(){return this.unPackInt16U()/1e4},this.unPackRad=function(){return this.unPackRadU()-Math.PI},this.unPackFloat=function(){return this.unPackInt16()/100},this.unPackString=function(e){e=e||1e3;for(var t=Math.min(this.unPackInt8U(),e),n=new String,a=0;a<t;a++){var o=this.unPackInt16U();o>0&&(n+=String.fromCharCode(o))}return n}}},GameMap={makeMinMap:function(e){e.min={},e.min.width=e.width,e.min.depth=e.depth,e.min.height=e.height,e.min.data={};for(var t=0;t<e.width;t++)for(var n=0;n<e.height;n++)for(var a=0;a<e.depth;a++){var o=e.data[t][n][a];o.cat&&(e.min.data[o.cat]||(e.min.data[o.cat]={}),e.min.data[o.cat][o.dec]||(e.min.data[o.cat][o.dec]=[]),e.min.data[o.cat][o.dec].push({x:t,y:n,z:a,dir:o.dir}))}},generateMap:function(e,t,n,a){Math.seed=a;var o={};o.width=e,o.depth=t,o.height=n,o.seed=a,o.data=Array(o.width);for(l=0;l<o.width;l++){o.data[l]=Array(o.height);for(m=0;m<o.height;m++)o.data[l][m]=Array(o.depth).fill({})}for(p=0;p<o.width*o.depth*o.height*.2;)for(var i=Math.seededRandomInt(4,8),s=Math.seededRandomInt(4,8),r=Math.seededRandomInt(2,p%o.height),l=Math.seededRandomInt(1,o.width-1-i),h=Math.seededRandomInt(1,o.depth-1-s),c=(Math.seededRandomInt(1,4),l);c<l+i;c++)for(y=h;y<h+s;y++)for(var d=0;d<r;d++){var u=c==l||y==h||c==l+i-1||y==h+s-1;o.data[c][d][y].cat||p++,o.data[c][d][y]=u?{cat:1,dec:4,dir:Math.seededRandomInt(0,4)}:d%2==0?{cat:1,dec:0,dir:Math.seededRandomInt(0,4)}:{cat:1,dec:4,dir:Math.seededRandomInt(0,4)}}for(l=0;l<o.width;l++)for(m=0;m<o.height;m++)for(h=0;h<o.depth;h++)0==o.data[l][m][h].dec&&(o.data[l][m][h]={});for(g=0;g<o.width*o.depth*o.height/2;g++){var l=Math.seededRandomInt(0,o.width),m=2*Math.seededRandomInt(0,Math.floor(o.height/2)),h=Math.seededRandomInt(0,o.depth);1==o.data[l][m][h].cat&&o.data[l][m][h].dec>0&&4==GameMap.numNeighbors6(o,l,m,h)&&(o.data[l][m][h]={})}for(var p=0;p<o.width*o.depth*o.height/60;){var l=Math.seededRandomInt(1,o.width-1),m=Math.seededRandomInt(0,o.height-1),h=Math.seededRandomInt(1,o.depth-1);o.data[l][m][h].cat||0!=m&&1!=o.data[l][m-1][h].cat||(1!=o.data[l][m][h+1].cat||o.data[l][m+1][h+1].cat||o.data[l][m][h-1].cat||0!=m&&1!=o.data[l][m-1][h-1].cat?1!=o.data[l+1][m][h].cat||o.data[l+1][m+1][h].cat||o.data[l-1][m][h].cat||0!=m&&1!=o.data[l-1][m-1][h].cat?1!=o.data[l][m][h-1].cat||o.data[l][m+1][h-1].cat||o.data[l][m][h+1].cat||0!=m&&1!=o.data[l][m-1][h+1].cat?1!=o.data[l-1][m][h].cat||o.data[l-1][m+1][h].cat||o.data[l+1][m][h].cat||0!=m&&1!=o.data[l+1][m-1][h].cat||(o.data[l][m][h]={cat:2,dec:0,dir:3},o.data[l][m+1][h]={},o.data[l+1][m+1][h]={},p++):(o.data[l][m][h]={cat:2,dec:0,dir:2},o.data[l][m+1][h]={},o.data[l][m+1][h+1]={},p++):(o.data[l][m][h]={cat:2,dec:0,dir:1},o.data[l][m+1][h]={},o.data[l-1][m+1][h]={},p++):(o.data[l][m][h]={cat:2,dec:0,dir:0},o.data[l][m+1][h]={},o.data[l][m+1][h-1]={},p++))}for(g=0;g<o.width*o.depth*o.height/10;g++){var l=Math.seededRandomInt(1,o.width-1),m=Math.seededRandomInt(0,o.height-1),h=Math.seededRandomInt(1,o.depth-1);!o.data[l][m][h].cat&&(0==m||1==o.data[l][m-1][h].cat)&&GameMap.numNeighbors26(o,l,m,h)<11&&(o.data[l][m][h]={cat:4,dec:0,dir:0})}for(var g=0;g<o.width*o.depth*o.height/10;g++){var l=Math.seededRandomInt(1,o.width-1),m=Math.seededRandomInt(0,o.height-1),h=Math.seededRandomInt(1,o.depth-1);if(!o.data[l][m][h].cat&&(0==m||1==o.data[l][m-1][h].cat&&4==o.data[l][m-1][h].dec)&&GameMap.numNeighbors26(o,l,m,h)<11){o.data[l][m][h]={cat:1,dec:Math.seededRandomInt(1,4),dir:Math.seededRandomInt(0,4)};for(var f=0;f<20;f++){var c=l+Math.seededRandomInt(-1,2),y=h+Math.seededRandomInt(-1,2);if(4==o.data[y][m][y].cat)break;if(!o.data[y][m][y].cat&&(0==m||1==o.data[c][m-1][y].cat&&4==o.data[c][m-1][y].dec)){o.data[c][m][y]={cat:4,dec:0,dir:0};break}}}}for(l=0;l<o.width;l++)for(h=0;h<o.depth;h++)for(m=0;m<o.height-1;m++)!o.data[l][m][h].cat&&this.numNeighbors6(o,l,m,h)>=4&&!o.data[l][m+1][h].cat&&(o.data[l][m][h]={cat:1,dec:this.firstNeighborDec(o,l,m,h),dir:Math.seededRandomInt(0,4)});for(l=0;l<o.width;l++)for(m=0;m<o.height;m++)for(h=0;h<o.depth;h++)o.data[l][m][h].cat&&6==GameMap.numNeighbors6(o,l,m,h)&&(o.data[l][m][h].cat=1,o.data[l][m][h].dec=0);return GameMap.makeMinMap(o),o},firstNeighborDec:function(e,t,n,a){for(var o=Math.max(1,t-1);o<=Math.min(e.width-2,t+1);o++)for(var i=Math.max(0,n-1);i<=Math.min(e.height-1,n+1);i++)for(var s=Math.max(1,a-1);s<=Math.min(e.depth-2,a+1);s++)if((t!=o||n!=i||a!=s)&&1==e.data[o][i][s].cat)return e.data[o][i][s].dec;return 0},numNeighbors6:function(e,t,n,a){for(var o=0,i=Math.max(1,t-1);i<=Math.min(e.width-2,t+1);i++)for(var s=Math.max(0,n-1);s<=Math.min(e.height-1,n+1);s++)for(var r=Math.max(1,a-1);r<=Math.min(e.depth-2,a+1);r++)Math.abs(i-t)+Math.abs(s-n)+Math.abs(r-a)==1&&1==e.data[i][s][r].cat&&o++;return 0==n&&o++,o},numNeighbors26:function(e,t,n,a){for(var o=0,i=Math.max(1,t-1);i<=Math.min(e.width-2,t+1);i++)for(var s=Math.max(0,n-1);s<=Math.min(e.height-1,n+1);s++)for(var r=Math.max(1,a-1);r<=Math.min(e.depth-2,a+1);r++)t==i&&n==s&&a==r||1==e.data[i][s][r].cat&&o++;return 0==n&&(o+=9),o}};Gun.prototype.update=function(e){this.actor&&(this.actor.update(e),this.triggerPulled&&this.queueShot()),this.shotsQueued>0&&0==this.equipCountdown&&(this.actor?(this.fire(),this.shotsQueued=0):0==this.rofCountdown&&(this.fire(),this.rofCountdown=.8*this.rof,this.shotsQueued--)),this.rofCountdown>0&&(this.rofCountdown=Math.max(0,this.rofCountdown-e)),this.actor||(this.equipCountdown>0&&(this.equipCountdown=Math.max(0,this.equipCountdown-e)),this.reloadCountdown>0&&(this.reloadCountdown-=e,this.reloadCountdown<=0&&(this.reloadCountdown=0,this.reload())))},Gun.prototype.collectAmmo=function(){return this.ammo.store<this.ammo.storeMax&&(this.ammo.store=Math.min(this.ammo.storeMax,this.ammo.store+this.ammo.pickup),!0)},Gun.prototype.queueShot=function(){if(this.ammo.rounds>0){if(this.isAtReady())if(this.actor){if(0==this.rofCountdown){this.shotsQueued++,this.rofCountdown=this.rof;var e=new Comm.output(6);e.packInt8(Comm.fire),e.packInt8(this.player.id),e.packRad(this.player.pitch),e.packRadU(this.player.viewYaw),ws.send(e.buffer),0==this.automatic&&(this.triggerPulled=!1)}}else this.shotsQueued++}else this.actor&&this.actor.dryFire(),this.triggerPulled=!1},Gun.prototype.fire=function(){if(this.ammo.rounds--,this.actor)this.actor.fire(),this.player.actor.fire(),this.player.id==meId&&updateAmmoUi();else{var e=BABYLON.Matrix.RotationYawPitchRoll(this.player.viewYaw,this.player.pitch,0),t=BABYLON.Matrix.Translation(0,0,1).multiply(e),n=.002*(this.player.shotSpread+this.player.weapon.accuracy),a=BABYLON.Matrix.RotationYawPitchRoll((Math.random()-.5)*n,(Math.random()-.5)*n,(Math.random()-.5)*n),o=(t=t.multiply(a)).getTranslation(),i=BABYLON.Matrix.Translation(.1,.1,.6),s=(i=(i=i.multiply(e)).add(BABYLON.Matrix.Translation(this.player.x,this.player.y+.3,this.player.z))).getTranslation();this.fireMunitions(s,o)}this.player.dx*=.5,this.player.dz*=.5,this.player.shotSpread+=this.shotSpreadIncrement,0==this.ammo.rounds&&(this.actor&&Sounds.hammerClick.play(),this.triggerPulled=!1)},Gun.prototype.startReload=function(){return 0!=this.ammo.store&&0!=this.isAtReady()&&!this.triggerPulled&&(this.ammo.rounds!=this.ammo.capacity&&(0==this.ammo.rounds?this.reloadCountdown=this.longReloadTime:this.reloadCountdown=this.shortReloadTime,this.actor&&this.actor.reload(),!0))},Gun.prototype.reload=function(){var e=Math.min(Math.min(this.ammo.capacity,this.ammo.reload)-this.ammo.rounds,this.ammo.store);if(this.ammo.rounds+=e,this.ammo.store-=e,this.actor)this.reloadCountdown=0,this.player.id==meId&&updateAmmoUi();else{var t=new Comm.output(1);t.packInt8(Comm.reload),this.player.ws.safeSend(t.buffer)}},Gun.prototype.equip=function(){this.equipCountdown=this.equipTime,this.shotsQueued=0,this.triggerPulled=!1,this.player.shotSpread+=this.shotSpreadIncrement,this.actor&&this.actor.equip()},Gun.prototype.stow=function(){return 0!=this.isAtReady()&&!this.triggerPulled&&(this.player.stowWeaponCountdown=this.stowWeaponTime,this.actor&&this.actor.stow(),!0)},Gun.prototype.isAtReady=function(){return 0==this.shotsQueued&&0==this.reloadCountdown&&0==this.equipCountdown&&0==this.player.stowWeaponCountdown&&!this.player.isDead()},Eggk47.prototype=Object.create(Gun.prototype),Eggk47.prototype.constructor=Gun,Eggk47.prototype.fireMunitions=function(e,t){munitionsManager.fireBullet(this.player,e,t,this.damage,this.ttl,this.velocity);var n=new Comm.output(14);n.packInt8(Comm.fireBullet),n.packInt8(this.player.id),n.packFloat(e.x),n.packFloat(e.y),n.packFloat(e.z),n.packFloat(t.x),n.packFloat(t.y),n.packFloat(t.z),send(n.buffer)},DozenGauge.prototype=Object.create(Gun.prototype),DozenGauge.prototype.constructor=Gun,DozenGauge.prototype.fireMunitions=function(e,t){var n=Date.now()%256;Math.seed=n;for(var a=0;a<20;a++){var o=Math.normalize3({x:t.x+Math.seededRandom(-.15,.15),y:t.y+Math.seededRandom(-.1,.1),z:t.z+Math.seededRandom(-.15,.15)});munitionsManager.fireBullet(this.player,e,o,this.damage,this.ttl,this.velocity)}var i=new Comm.output(15);i.packInt8(Comm.fireShot),i.packInt8(this.player.id),i.packFloat(e.x),i.packFloat(e.y),i.packFloat(e.z),i.packFloat(t.x),i.packFloat(t.y),i.packFloat(t.z),i.packInt8(n),send(i.buffer)},CSG1.prototype=Object.create(Gun.prototype),CSG1.prototype.constructor=Gun,CSG1.prototype.fireMunitions=function(e,t){munitionsManager.fireBullet(this.player,e,t,this.damage,this.ttl,this.velocity);var n=new Comm.output(14);n.packInt8(Comm.fireBullet),n.packInt8(this.player.id),n.packFloat(e.x),n.packFloat(e.y),n.packFloat(e.z),n.packFloat(t.x),n.packFloat(t.y),n.packFloat(t.z),send(n.buffer)},Cluck9mm.prototype=Object.create(Gun.prototype),Cluck9mm.prototype.constructor=Gun,Cluck9mm.prototype.fireMunitions=function(e,t){munitionsManager.fireBullet(this.player,e,t,this.damage,this.ttl,this.velocity);var n=new Comm.output(14);n.packInt8(Comm.fireBullet),n.packInt8(this.player.id),n.packFloat(e.x),n.packFloat(e.y),n.packFloat(e.z),n.packFloat(t.x),n.packFloat(t.y),n.packFloat(t.z),send(n.buffer)},Math.PI2=2*Math.PI,Math.mod=function(e,t){var n=e%t;return n>=0?n:n+t},Math.length2=function(e,t){return Math.sqrt(Math.pow(e,2)+Math.pow(t,2))},Math.length3=function(e,t,n){return Math.sqrt(Math.pow(e,2)+Math.pow(t,2)+Math.pow(n,2))},Math.normalize3=function(e){var t=Math.length3(e.x,e.y,e.z);return e.x*=1/t,e.y*=1/t,e.z*=1/t,e},Math.radAdd=function(e,t){return Math.mod(e+t,Math.PI2)},Math.radSub=function(e,t){return Math.mod(e-t,Math.PI2)},Math.radRange=function(e){return Math.mod(e,Math.PI2)},Math.radDifference=function(e,t){var n=(e-t+Math.PI)%Math.PI2-Math.PI;return n=n<-Math.PI?n+Math.PI2:n},Math.randomInt=function(e,t){return Math.floor(Math.random()*(t-e)+e)},Math.seed=100,Math.seededRandom=function(e,t){return e=e||0,t=t||1,Math.seed=(9301*Math.seed+49297)%233280,e+Math.seed/233280*(t-e)},Math.seededRandomInt=function(e,t){return Math.floor(Math.seededRandom(e,t))},MunitionsManager.prototype.update=function(e){for(var t=this,n=0;n<4;n++)this.bulletPool.forEachActive(function(n){n.update(.25*e),Object.keys(players).forEach(function(e){var a=players[e];a&&!a.isDead()&&Math.abs(n.x-a.x)<.3&&Math.abs(n.y-(a.y+.3))<.3&&Math.abs(n.z-a.z)<.3&&(hitPlayer(a,n),t.bulletPool.recycle(n))})})},MunitionsManager.prototype.fireBullet=function(e,t,n,a,o,i){this.bulletPool.retrieve().fire(e,t,n,a,o,i)};var CONTROL={up:1,down:2,left:4,right:8},classes=[{name:"Soldier",weapon:Eggk47},{name:"Scrambler",weapon:DozenGauge},{name:"Free Ranger",weapon:CSG1}];Player.prototype.update=function(e){var t=0,n=0;this.controlKeys&CONTROL.left&&(t-=Math.cos(this.moveYaw),n+=Math.sin(this.moveYaw)),this.controlKeys&CONTROL.right&&(t+=Math.cos(this.moveYaw),n-=Math.sin(this.moveYaw)),this.controlKeys&CONTROL.up&&(t+=Math.sin(this.moveYaw),n+=Math.cos(this.moveYaw)),this.controlKeys&CONTROL.down&&(t-=Math.sin(this.moveYaw),n-=Math.cos(this.moveYaw));var a=new BABYLON.Vector2(t,n).normalize(),o=this.dx,i=this.dy,s=this.dz;this.dx+=.007*a.x*e,this.dz+=.007*a.y*e,this.dy-=.003*e;var r=.5*(this.dx+o)*e,l=.5*(this.dy+i)*e,h=.5*(this.dz+s)*e;if(this.x+=r,this.collidesWithMap()){c=this.y;this.y+=Math.abs(r),this.collidesWithMap()&&(this.x-=r,this.dx*=Math.pow(.5,e),this.y=c)}if(this.z+=h,this.collidesWithMap()){var c=this.y;this.y+=Math.abs(h),this.collidesWithMap()&&(this.z-=h,this.dz*=Math.pow(.5,e),this.y=c)}this.y+=l,this.collidesWithMap()?(l<0&&(this.jumping=!1),this.y-=l,this.dy*=Math.pow(.5,e)):0==this.jumping&&(this.jumping=!0);var d=Math.length3(this.dx,this.dy,this.dz);this.shotSpread*=this.weapon.accuracySettleFactor,this.dx*=Math.pow(.8,e),this.dz*=Math.pow(.8,e),this.weapon&&this.weapon.update(e),this.hp>0&&(this.hp=Math.min(100,this.hp+.05*e)),!this.actor&&this.stowWeaponCountdown>0&&(this.stowWeaponCountdown-=e,this.stowWeaponCountdown<=0&&(this.stowWeaponCountdown=0,this.equipWeapon(this.equipWeaponIdx))),this.isAI&&this.doAI()},Player.prototype.doAI=function(){(Math.random()<.001||playerTotal>botGoal&&Math.random()<.01)&&removePlayer(this.ws),Math.random()<.01&&(this.viewYaw=6.282*Math.random()-3.141)},Player.prototype.jump=function(){var e=!this.jumping;e||(this.y-=.2,this.collidesWithMap()&&(e=!0),this.y+=.2),e&&(this.dy=.06,this.jumping=!0)},Player.prototype.equipWeapon=function(e){if(this.weaponIdx=e,this.weapon=this.weapons[e],this.weapons[e].equip(),this.actor)this.id==meId&&updateAmmoUi();else{var t=new Comm.output(3);t.packInt8(Comm.equipWeapon),t.packInt8(this.id),t.packInt8(this.equipWeaponIdx),send(t.buffer)}},Player.prototype.stowWeapon=function(e){if(this.equipWeaponIdx=e,this.weapon.stow())if(this.actor)(t=new Comm.output(2)).packInt8(Comm.stowWeapon),t.packInt8(e),this.ws.send(t.buffer);else{var t=new Comm.output(2);t.packInt8(Comm.stowWeapon),t.packInt8(this.id),sendToOthers(t.buffer,this.id)}},Player.prototype.addRotationShotSpread=function(e,t){this.shotSpread+=Math.sqrt(Math.pow(60*e,2)+Math.pow(60*t,2))},Player.prototype.collectItem=function(e){switch(e){case ItemManager.AMMO:return!!this.weapon.collectAmmo()&&(this.actor&&(Sounds.ammo.play(),updateAmmoUi()),!0)}},Player.prototype.queueShot=function(){if(this.hp>0&&this.weapon)return this.weapon.queueShot()},Player.prototype.die=function(){this.hp=0,this.killStreak=0,this.controlKeys=0,this.shotSpread=0,this.jumping=!1,this.actor?this.actor.die():this.resetWeaponState()},Player.prototype.respawn=function(e,t,n){this.x=e,this.y=t,this.z=n,this.hp=100,this.actor&&(this.actor.mesh.position.x=e,this.actor.mesh.position.y=t,this.actor.mesh.position.z=n,this.actor.respawn(),this.weapon.equip(),this.resetWeaponState(),this.id==meId&&updateAmmoUi())},Player.prototype.resetWeaponState=function(){this.stowWeaponCountdown=0;for(var e=0;e<this.weapons.length;e++)this.weapons[e]&&(this.weapons[e].ammo.rounds=this.weapons[e].ammo.capacity,this.weapons[e].reloadCountdown=0,this.weapons[e].rofCountdown=0,this.weapons[e].shotsQueued=0,this.weapons[e].triggerPulled=!1,this.weapons[e].equipCountdown=0)},Player.prototype.isDead=function(){return 0==this.hp},Player.prototype.collidesWithMap=function(){var e=this.x-.5,t=this.y,n=this.z-.5;if(t>map.height-1)return!1;if(t<0)return!0;if(e<-.25||n<-.25||e>map.width-.75||n>map.depth-.75)return!0;for(var a=.25;a<=.75;a+=.25)for(var o=0;o<=.6;o+=.3)for(var i=.25;i<=.75;i+=.25){var s=e+a,r=t+o,l=n+i,h=Math.floor(s),c=Math.floor(r),d=Math.floor(l);try{var u=map.data[h][c][d];if(1==u.cat)return u;if(2==u.cat){var m=s-h,p=r-c,g=l-d;switch(u.dir){case 0:if(p<g)return u;break;case 2:if(p<1-g)return u;break;case 1:if(p<m)return u;break;case 3:if(p<1-m)return u}}else if(4==u.cat){var p=r-c,g=l-d;if((m=s-h)<.7&&m>.3&&g<.7&&g>.3&&p<.5)return u}else if(3==u.cat){g=l-d;if((m=s-h)<.7&&m>.3&&g<.7&&g>.3)return u}}catch(e){}}return!1},Pool.prototype.expand=function(e){for(var t=0;t<e;t++){var n=this.constructorFn();n.id=t+this.size,n.active=!1,this.objects.push(n)}this.size+=e},Pool.prototype.retrieve=function(e){if(void 0!=e)return this.numActive++,this.objects[e].active=!0,this.objects[e];var t=this.idx;do{t=(t+1)%this.size;var n=this.objects[t];if(!n.active)return this.idx=t,this.numActive++,n.active=!0,n}while(t!=this.idx);return this.expand(this.originalSize),log.out("Expanding pool for: "+this.objects[0].constructor.name+" to: "+this.size),this.retrieve()},Pool.prototype.recycle=function(e){e.active=!1,this.numActive--},Pool.prototype.forEachActive=function(e){for(var t=0;t<this.size;t++){var n=this.objects[t];!0===n.active&&e(n,t)}};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement