Raspsnir/public_html/browserquest/js/character.js

1 line
6.1 KiB
JavaScript
Raw Normal View History

define(["entity","transition","timer"],function(e,t,n){var r=e.extend({init:function(e,n){var r=this;this._super(e,n),this.nextGridX=-1,this.nextGridY=-1,this.orientation=Types.Orientations.DOWN,this.atkSpeed=50,this.moveSpeed=120,this.walkSpeed=100,this.idleSpeed=450,this.setAttackRate(800),this.movement=new t,this.path=null,this.newDestination=null,this.adjacentTiles={},this.target=null,this.unconfirmedTarget=null,this.attackers={},this.hitPoints=0,this.maxHitPoints=0,this.isDead=!1,this.attackingMode=!1,this.followingMode=!1},clean:function(){this.forEachAttacker(function(e){e.disengage(),e.idle()})},setMaxHitPoints:function(e){this.maxHitPoints=e,this.hitPoints=e},setDefaultAnimation:function(){this.idle()},hasWeapon:function(){return!1},hasShadow:function(){return!0},animate:function(e,t,n,r){var i=["atk","walk","idle"];o=this.orientation;if(!this.currentAnimation||this.currentAnimation.name!=="death")this.flipSpriteX=!1,this.flipSpriteY=!1,_.indexOf(i,e)>=0&&(e+="_"+(o===Types.Orientations.LEFT?"right":Types.getOrientationAsString(o)),this.flipSpriteX=this.orientation===Types.Orientations.LEFT?!0:!1),this.setAnimation(e,t,n,r)},turnTo:function(e){this.orientation=e,this.idle()},setOrientation:function(e){e&&(this.orientation=e)},idle:function(e){this.setOrientation(e),this.animate("idle",this.idleSpeed)},hit:function(e){this.setOrientation(e),this.animate("atk",this.atkSpeed,1)},walk:function(e){this.setOrientation(e),this.animate("walk",this.walkSpeed)},moveTo_:function(e,t,n){this.destination={gridX:e,gridY:t},this.adjacentTiles={};if(this.isMoving())this.continueTo(e,t);else{var r=this.requestPathfindingTo(e,t);this.followPath(r)}},requestPathfindingTo:function(e,t){return this.request_path_callback?this.request_path_callback(e,t):(log.error(this.id+" couldn't request pathfinding to "+e+", "+t),[])},onRequestPath:function(e){this.request_path_callback=e},onStartPathing:function(e){this.start_pathing_callback=e},onStopPathing:function(e){this.stop_pathing_callback=e},followPath:function(e){e.length>1&&(this.path=e,this.step=0,this.followingMode&&e.pop(),this.start_pathing_callback&&this.start_pathing_callback(e),this.nextStep())},continueTo:function(e,t){this.newDestination={x:e,y:t}},updateMovement:function(){var e=this.path,t=this.step;e[t][0]<e[t-1][0]&&this.walk(Types.Orientations.LEFT),e[t][0]>e[t-1][0]&&this.walk(Types.Orientations.RIGHT),e[t][1]<e[t-1][1]&&this.walk(Types.Orientations.UP),e[t][1]>e[t-1][1]&&this.walk(Types.Orientations.DOWN)},updatePositionOnGrid:function(){this.setGridPosition(this.path[this.step][0],this.path[this.step][1])},nextStep:function(){var e=!1,t,n,r;this.isMoving()&&(this.before_step_callback&&this.before_step_callback(),this.updatePositionOnGrid(),this.checkAggro(),this.interrupted?(e=!0,this.interrupted=!1):(this.hasNextStep()&&(this.nextGridX=this.path[this.step+1][0],this.nextGridY=this.path[this.step+1][1]),this.step_callback&&this.step_callback(),this.hasChangedItsPath()?(t=this.newDestination.x,n=this.newDestination.y,r=this.requestPathfindingTo(t,n),this.newDestination=null,r.length<2?e=!0:this.followPath(r)):this.hasNextStep()?(this.step+=1,this.updateMovement()):e=!0),e&&(this.path=null,this.idle(),this.stop_pathing_callback&&this.stop_pathing_callback(this.gridX,this.gridY)))},onBeforeStep:function(e){this.before_step_callback=e},onStep:function(e){this.step_callback=e},isMoving:function(){return this.path!==null},hasNextStep:function(){return this.path.length-1>this.step},hasChangedItsPath:function(){return this.newDestination!==null},isNear:function(e,t){var n,r,i=!1;return n=Math.abs(this.gridX-e.gridX),r=Math.abs(this.gridY-e.gridY),n<=t&&r<=t&&(i=!0),i},onAggro:function(e){this.aggro_callback=e},onCheckAggro:function(e){this.checkaggro_callback=e},checkAggro:function(){this.checkaggro_callback&&this.checkaggro_callback()},aggro:function(e){this.aggro_callback&&this.aggro_callback(e)},onDeath:function(e){this.death_callback=e},lookAtTarget:function(){this.target&&this.turnTo(this.getOrientationTo(this.target))},go:function(e,t){this.isAttacking()?this.disengage(