"use strict";var Collision=function(i){this.collisionEngine=i,this.fallAcceleration=Preferences.Collision.FALL_ACCELERATION,this.lastCollisionFrameId=-1,this.keepForbiddenKeyboardForFrameId=0};Collision.prototype.move=function(i,o,e,t){if(o.inAir())return this._checkCollision(o,e.bind(i,t,1));var l=1;this._checkCollision(o,e.bind(i,t,l))},Collision.prototype._checkCollision=function(i,o){if(i.camera.saveCurrentPosition(),null!==o&&o(),Preferences.Collision.__COLLISION_DETECTION){var e=!1,t=player.inTunnel,l=this.collisionEngine.computeCollision(i),n=i.camera.position.clone();if(e=l,!e)if(!t&&player.inTunnel)e=!1;else{var r=i.camera.moveVectorLength?Preferences.Collision.FORWARD_DIRECTION_DISTANCE_LIMIT/i.camera.moveVectorLength:0;if(Collision.noForwardCollisionCheck||(i.camera.position.add(player.camera.moveVector.clone().multiplyScalar(r)),e=this.collisionEngine.computeCollision(i,!0),i.camera.position.copy(n)),!e&&!Collision.noRightLeftCollisionCheck){i.camera.position.add(i.camera.rightVector.clone().multiplyScalar(Preferences.Collision.RIGHT_DIRECTION_DISTANCE_LIMIT).multiplyScalar(1));var s=this.collisionEngine.computeCollision(i,!0);i.camera.position.copy(n),i.camera.position.add(i.camera.rightVector.clone().multiplyScalar(Preferences.Collision.RIGHT_DIRECTION_DISTANCE_LIMIT).multiplyScalar(-1));var a=this.collisionEngine.computeCollision(i,!0);i.camera.position.copy(n),e=!(!a&&!s)&&(!a||!s)}}if(!this.isAvatarInsideTheWorld(i)||e)return i.camera.restoreOldPosition(),this.lastCollisionFrameId=clock.elapsedFrames,i.inFlyMode()&&this.collisionEngine.flyModeHeightDiff<Preferences.Collision.COLLISION_THRESHOLD_FLY_METERS?(i.camera.position.y+=Preferences.Collision.COLLISION_THRESHOLD_FLY_METERS,i.camera._flagViewChanged()):i.jumping&&i.getFreefallDuration()<100||gui.drawVirtualKeyboardAsForbidden(),!1;i.camera._flagViewChanged()}else i.camera._flagViewChanged();return!0},Collision.prototype.isAvatarInsideTheWorld=function(i){return!(i.getPosition().x<=Preferences.Heightmap.WORLD_3D_BOUNDING_BOX.MIN_X||i.getPosition().x>=Preferences.Heightmap.WORLD_3D_BOUNDING_BOX.MAX_X||i.getPosition().z<=Preferences.Heightmap.WORLD_3D_BOUNDING_BOX.MIN_Z||i.getPosition().z>=Preferences.Heightmap.WORLD_3D_BOUNDING_BOX.MAX_Z||i.getY()>=Preferences.Heightmap.MAXIMUM_ALLOWABLE_HEIGHT)},Collision.AirStatus={IN_AIR_FOR_LONG_TIME:0,JUST_GOT_INTO_AIR:1,NOT_IN_AIR:2},Collision.prototype.getAirStatus=function(i){return this.collisionEngine.findAirStatus(i)},Collision.prototype._checkAirStatus=function(i){switch(this.collisionEngine.findAirStatus(i)){case Collision.AirStatus.JUST_GOT_INTO_AIR:i.updateFreefallStartTime();break;case Collision.AirStatus.NOT_IN_AIR:i.resetFreefallStartTime()}},Collision.prototype.freefall=function(i){this._checkAirStatus(i),i.inAir()&&i.inWalkMode()&&this._checkCollision(i,this._checkFreefall.bind(this,i))},Collision.prototype._checkFreefall=function(i){return i.jumping&&i.inAir()&&i.getFreefallDuration()>Preferences.Collision.MAX_JUMP_DURATION?void i.turnJumpMode():(player.lastHeightmapHeight=heightmapWorld.getMain().getWorldHeightAtEntity(player),i.camera.setY(i.camera.positionFallStart-this.computeFallAmount(i.getFreefallDuration())),void this._checkAirStatus(i))},Collision.prototype.computeFallAmount=function(i){return.5*this.fallAcceleration*i*i},Collision.noForwardCollisionCheck=!1,Collision.noRightLeftCollisionCheck=!1,Collision.stagMoatDistEnterSq=125,Collision.stagMoatDistBelowSq=2700,Collision.stagMoatPos=new THREE.Vector3(-149.0069119398264,-1.2286435561563565,-49.121142931314104),Collision.prototype._stagMoatFix=function(){var i=Collision.stagMoatPos.distanceToSquared(player.getPosition());i<=Collision.stagMoatDistEnterSq||i<=1700&&player.getPosition().y<Collision.stagMoatPos.y?Collision.noRightLeftCollisionCheck=!0:Collision.noRightLeftCollisionCheck=!1};