1 line
3.5 KiB
JavaScript
1 line
3.5 KiB
JavaScript
define(["character","timer"],function(e,t){var n=Class.extend({init:function(e){this.game=e,this.playerAggroTimer=new t(1e3)},update:function(){this.updateZoning(),this.updateCharacters(),this.updatePlayerAggro(),this.updateTransitions(),this.updateAnimations(),this.updateAnimatedTiles(),this.updateChatBubbles(),this.updateInfos()},updateCharacters:function(){var t=this;this.game.forEachEntity(function(n){var r=n instanceof e;n.isLoaded&&(r&&(t.updateCharacter(n),t.game.onCharacterUpdate(n)),t.updateEntityFading(n))})},updatePlayerAggro:function(){var e=this.game.currentTime,t=this.game.player;t&&!t.isMoving()&&!t.isAttacking()&&this.playerAggroTimer.isOver(e)&&t.checkAggro()},updateEntityFading:function(e){if(e&&e.isFading){var t=1e3,n=this.game.currentTime,r=n-e.startFadingTime;r>t?(this.isFading=!1,e.fadingAlpha=1):e.fadingAlpha=r/t}},updateTransitions:function(){var e=this,t=null,n=this.game.currentZoning;this.game.forEachEntity(function(n){t=n.movement,t&&t.inProgress&&t.step(e.game.currentTime)}),n&&n.inProgress&&n.step(this.game.currentTime)},updateZoning:function(){var e=this.game,t=e.camera,n=e.currentZoning,r=3,i=16,s=500;if(n&&n.inProgress===!1){var o=this.game.zoningOrientation,u=endValue=offset=0,a=null,f=null;if(o===Types.Orientations.LEFT||o===Types.Orientations.RIGHT)offset=(t.gridW-2)*i,u=o===Types.Orientations.LEFT?t.x-i:t.x+i,endValue=o===Types.Orientations.LEFT?t.x-offset:t.x+offset,a=function(n){t.setPosition(n,t.y),e.initAnimatedTiles(),e.renderer.renderStaticCanvases()},f=function(){t.setPosition(n.endValue,t.y),e.endZoning()};else if(o===Types.Orientations.UP||o===Types.Orientations.DOWN)offset=(t.gridH-2)*i,u=o===Types.Orientations.UP?t.y-i:t.y+i,endValue=o===Types.Orientations.UP?t.y-offset:t.y+offset,a=function(n){t.setPosition(t.x,n),e.initAnimatedTiles(),e.renderer.renderStaticCanvases()},f=function(){t.setPosition(t.x,n.endValue),e.endZoning()};n.start(this.game.currentTime,a,f,u,endValue,s)}},updateCharacter:function(e){var t=this,n=Math.round(16/Math.round(e.moveSpeed/(1e3/this.game.renderer.FPS)));e.isMoving()&&e.movement.inProgress===!1&&(e.orientation===Types.Orientations.LEFT?e.movement.start(this.game.currentTime,function(t){e.x=t,e.hasMoved()},function(){e.x=e.movement.endValue,e.hasMoved(),e.nextStep()},e.x-n,e.x-16,e.moveSpeed):e.orientation===Types.Orientations.RIGHT?e.movement.start(this.game.currentTime,function(t){e.x=t,e.hasMoved()},function(){e.x=e.movement.endValue,e.hasMoved(),e.nextStep()},e.x+n,e.x+16,e.moveSpeed):e.orientation===Types.Orientations.UP?e.movement.start(this.game.currentTime,function(t){e.y=t,e.hasMoved()},function(){e.y=e.movement.endValue,e.hasMoved(),e.nextStep()},e.y-n,e.y-16,e.moveSpeed):e.orientation===Types.Orientations.DOWN&&e.movement.start(this.game.currentTime,function(t){e.y=t,e.hasMoved()},function(){e.y=e.movement.endValue,e.hasMoved(),e.nextStep()},e.y+n,e.y+16,e.moveSpeed))},updateAnimations:function(){var e=this.game.currentTime;this.game.forEachEntity(function(t){var n=t.currentAnimation;n&&n.update(e)&&t.setDirty()});var t=this.game.sparksAnimation;t&&t.update(e);var n=this.game.targetAnimation;n&&n.update(e)},updateAnimatedTiles:function(){var e=this,t=this.game.currentTime;this.game.forEachAnimatedTile(function(n){n.animate(t)&&(n.isDirty=!0,n.dirtyRect=e.game.renderer.getTileBoundingRect(n),(e.game.renderer.mobile||e.game.renderer.tablet)&&e.game.checkOtherDirtyRects(n.dirtyRect,n,n.x,n.y))})},updateChatBubbles:function(){var e=this.game.currentTime;this.game.bubbleManager.update(e)},updateInfos:function(){var e=this.game.currentTime;this.game.infoManager.update(e)}});return n}); |