
var Alfodr={};Alfodr.ajaxEventRequestTick=1E3;Alfodr.actor=null;Alfodr.lastAjaxEventRequestTime=null;Alfodr.cancelAjax=false;Alfodr.actionId=null;Alfodr.EventList=null;soundManager.debugMode=false;soundManager.flashVersion=9;soundManager.url="/swf/";soundManager.useFlashBlock=false;soundManager.useHTML5Audio=true;$.ajaxSettings.cache=false;$.ajaxSetup({timeout:2E3});try{history.navigationMode="compatible"}catch(e$$5){}
$(document).ready(function(){Alfodr.actionId=$("body").attr("id").substr(6);Alfodr.EventList=$("#Events");$('[data-onLoadFocus="true"]').focus();$('input[type="submit"], button, .button').button();$("button.link").click(function(){window.location.href=$(this).attr("data-uri")});$(".buttonset").buttonset();$(".accordion").accordion({autoHeight:false,header:"h2"});$(".tabs").tabs();$('[data-enterDoSubmit="true"]').keypress(function(a){a.which==13&&this.form.submit()});$("textarea[maxlength]").limitMaxlength({onEdit:function(a){$(this).siblings(".charsRemaining").text("Characters remaining: "+
a)},onLimit:function(){$(this).stop(true,true);var a=$(this).css("background-color");$(this).css("background-color","#990000");$(this).animate({"background-color":a},333)}});initAjax();$(document).ajaxError(function(a,b,d){d.url.indexOf("/AjaxEvents/")==0&&setupNextAjaxEventsRequestEvent()});initButtonsByActionId()});
var initAjax=function(){if($("#StatusBox").hasClass("isLoggedIn")){Alfodr.cancelAjax=false;$.get("/AjaxEvents/new/"+Alfodr.actionId,function(a){a=eval(a);Alfodr.actor=new Actor(a[1],a[0],a[2]);processAjaxEvents()})}},stopAjax=function(){Alfodr.cancelAjax=true},initButtonsByActionId=function(){switch(Alfodr.actionId){case "Guilds":$(".requestJoin").click(function(a){createModalConfirmDialogAtMouse(a,"Confirm","Do you really want to request to join this guild?",function(){$(this).dialog("close");postSubmit({a:"requestJoin"})})});
$(".kickMember").click(function(a){var b=$(this).parent().parent().attr("data-id");createModalConfirmDialogAtMouse(a,"Confirm","Do you really want to kick this player?",function(){$(this).dialog("close");postSubmit({a:"kickMember",i:b})})});$(".acceptJoin").click(function(a){var b=$(this).parent().parent().attr("data-id");createModalConfirmDialogAtMouse(a,"Confirm","Do you really want to accept that player?",function(){$(this).dialog("close");postSubmit({a:"acceptJoin",i:b})})});$(".makeVice").click(function(a){var b=
$(this).parent().parent().attr("data-id");createModalConfirmDialogAtMouse(a,"Confirm","Do you really want to promote this player to a vice leader?",function(){$(this).dialog("close");postSubmit({a:"makeVice",i:b})})});$(".makeMember").click(function(a){var b=$(this).parent().parent().attr("data-id");createModalConfirmDialogAtMouse(a,"Confirm","Do you really want to demote this player to a member?",function(){$(this).dialog("close");postSubmit({a:"makeMember",i:b})})});$(".leaveGuild").click(function(a){createModalConfirmDialogAtMouse(a,
"Confirm","Do you really want to leave your guild?",function(){$(this).dialog("close");postSubmit({a:"leaveGuild"})})});$(".disbandGuild").click(function(a){createModalConfirmDialogAtMouse(a,"Confirm","Do you really want to disband (delete) your guild?",function(){$(this).dialog("close");postSubmit({a:"disbandGuild"})})});break;case "User":$(".addToVip").click(function(){$.post("/Vip/",{a:"addToVip",i:$("#User").attr("data-id")});$("#User").addClass("isVipped")});$(".removeFromVip").click(function(){$.post("/Vip/",
{a:"removeFromVip",i:$("#User").attr("data-id")});$("#User").removeClass("isVipped")});break;case "Vip":$(".removeFromVip").click(function(){postSubmit({a:"removeFromVip",i:$(this).parent().attr("data-id")});$(this).attr({disabled:true})})}},playMp3=function(a){soundManager.onready(function(){soundManager.supported()&&soundManager.createSound({id:""+a,url:"/mp3/6000",autoLoad:true,autoPlay:true,stream:true,onfinish:function(){soundManager.destroySound(""+a)}})})},postSubmit=function(a){var b=document.createElement("form");
b.setAttribute("method","post");b.setAttribute("action","");for(var d in a){var c=document.createElement("input");c.setAttribute("type","hidden");c.setAttribute("name",d);c.setAttribute("value",a[d]);b.appendChild(c)}document.body.appendChild(b);b.submit()},createAlertDialog=function(a,b){var d=$().add('<div title="'+a+'" style="text-align: center; padding: 30px 0px 20px 0px;">'+b+"</div>");d.dialog({modal:true,draggable:false,resizable:false,show:"highlight",width:500,buttons:{Ok:function(){$(this).dialog("close")}},
close:function(){$(this).remove()}});return d},createAlertDialogAtMouse=function(a,b,d){b=$().add('<div title="'+b+'" style="text-align: center; padding: 30px 0px 20px 0px;">'+d+"</div>");b.dialog({position:[a.pageX-$(window).scrollLeft(),a.pageY-$(window).scrollTop()],modal:true,draggable:false,resizable:false,show:"highlight",width:500,buttons:{Ok:function(){$(this).dialog("close")}},close:function(){$(this).remove()}});return b},createCriticalDialog=function(a,b,d){a=$().add('<div title="'+a+'"><div style="text-align: center; padding: 30px 0px 20px 0px;">'+
b+"</div></div>");a.dialog({modal:true,draggable:false,resizable:false,show:"highlight",width:500,zIndex:65535,buttons:d,close:function(){$(this).remove()}});$(".ui-dialog-titlebar-close").remove();return a},createModalConfirmDialog=function(a,b,d){a=$().add('<div title="'+a+'" style="text-align: center; padding: 30px 0px 20px 0px;">'+b+"</div>");a.dialog({modal:true,draggable:false,resizable:false,width:500,buttons:{Ok:d,Cancel:function(){$(this).dialog("close")}},close:function(){$(this).remove()}});
return a},createModalConfirmDialogAtMouse=function(a,b,d,c){b=$().add('<div title="'+b+'" style="text-align: center; padding: 30px 0px 20px 0px;">'+d+"</div>");b.dialog({position:[a.clientX-$(window).scrollLeft(),a.clientY-$(window).scrollTop()],modal:true,draggable:false,resizable:false,width:500,buttons:{Ok:c,Cancel:function(){$(this).dialog("close")}},close:function(){$(this).remove()}});return b},processAjaxEvents=function(){if(!Alfodr.cancelAjax){var a=(new Date).getTime();Alfodr.lastAjaxEventRequestTime=
a;$.get("/AjaxEvents/"+Alfodr.actor.ajaxUuid_,function(b){if(!Alfodr.cancelAjax){b=eval(b);if(typeof b!="undefined"){for(var d=b.length,c=0;c!=d;c++){var e=b[c],f=e[0];try{switch(f){case 1:battle.mode_==BattleMode.None&&createAlertDialog(e[1],e[2]);break;case 2:stopAjax();battle.remove();createCriticalDialog("Sorry :-(","Please do not open this game more than once.<br><br>This game window is now inactive.",{"Reactivate this Window":function(){$(this).remove();initAjax()}});break;case 3:stopAjax();
battle.remove();createCriticalDialog("Sorry :-(","You were logged off.<br><br>This game window is now inactive.",{"Reactivate this Window":function(){window.location.href=window.location.href}});break;case 4:var g=e[1],i=e[2];$("#PlayerStatAp").html(""+g);$("#PlayerStatHp").html(""+i);break;case 5:battle.remove();battle=new Battle;battle.startBattle(e);break;case 6:if(battle.mode_==BattleMode.Starting||battle.mode_==BattleMode.Fight)battle.handleLivingMovedEvent(e);break;case 7:battle.mode_==BattleMode.Fight&&
battle.projectile(e);break;case 8:battle.mode_==BattleMode.Fight&&battle.livingStatUpdate(e);break;case 9:battle.mode_==BattleMode.Fight&&battle.livingLeft(e);break;case 10:battle.mode_==BattleMode.Fight&&battle.handleBattleEnding(e);break;case 11:battle.remove();stopAjax();createModalConfirmDialog("Server Update!","<p>The game was just updated to a newer version. If the update is a bigger update you may find information about it on the news page.</p><p>Do you want to reload so you can continue playing?</p>",
function(){window.location.href=window.location.href});break;case 12:var h=$("div#MainMenu a.hasIcon.pms");h.addClass("urgent");h.html("Mail ("+e[1]+")");h.effect("pulsate",{times:10},500);appendEvent("Received new Mail");break;case 13:var j=e[1],k=e[2],m=e[3],l=e[4],n=e[5],o=!e[6],p=e[7],r=e[8];if(Alfodr.actionId=="Online")updateOnlineListing(j,k,m,l,n,o,p);else Alfodr.actionId=="BattleTargetListing"&&j!=Alfodr.actor.id_&&updateBattleTargetListing(j,k,m,l,n,o,p,r);break;case 14:appendEvent('<a href="/User/'+
e[1]+'/">'+e[2]+"</a> logged in.")}}catch(q){alert("\nJavascript Exception (Eventtype["+f+"], "+q.name+" - "+q.message+")\n\n\nPlease post this in our Forum so we can fix it.\n")}}Alfodr.cancelAjax||setupNextAjaxEventsRequestEvent()}}})}},appendEvent=function(a){Alfodr.EventList.append('<li><div class="bullet">\u2023</div><div class="text">'+a+"</div></li>");Alfodr.EventList.children("li:last").effect("highlight")},updateBattleTargetListing=function(a,b,d,c,e,f,g,i){c=$('a[href="#BattleTargets"]');
var h=c.attr("data-count"),j='<td class="name"><a class="userLink '+(f?"isFemale":"isMale")+'" href="/User/'+a+'/">'+b+'</a> \u25aa <button class="hasIcon attack" onclick="requestBattle(event,'+a+",'"+b+"',"+i+');">Attack</button></td><td class="level">'+g+"</td>",k=$('div#BattleTargets table tr[data-id="'+a+'"]'),m=f=false,l=i=g=false;if(e&&!d)if(k.length==1){g=true;i=k.attr("data-isOff")}else i=f=true;else if(k.length==1){m=true;l=!k.attr("data-isOff")}if(f){b=$("#BattleTargets tbody tr:last");
b=!b.length||b.hasClass("even");$("#BattleTargets table tbody").append('<tr class="'+(b?"odd":"even")+'" data-id="'+a+'">'+j+"</tr>");k=$("#BattleTargets tbody tr:last")}else if(g)k.html(j);else if(m){a=k.children("td");a.fadeTo(0,0.2);a.find("a.userLink").replaceWith(b);a.find("button").attr("disabled","disabled");a.filter(".level").html("?")}if(g||f)k.find("button").button();if(i){h++;k.removeAttr("data-isOff");k.effect("highlight",{color:"#080"})}else if(l){h--;k.attr("data-isOff",true);k.effect("highlight",
{color:"#800"})}else g&&k.effect("highlight",{color:"#880"});if(i||l){a=h+" player"+(h==1?"":"s")+" ready for battle";c.attr("data-count",h);c.html(a)}},updateOnlineListing=function(a,b,d,c,e,f,g){var i=$('a[href="#OnlineTab"]'),h=i.attr("data-count"),j=h;d='<td class="name"><a class="userLink '+(f?"isFemale":"isMale")+'" href="/User/'+a+'/">'+b+"</a>"+(d?" (in "+c+")":"")+'</td><td class="level">'+g+"</td>";c=$('div#OnlineTab table tr[data-id="'+a+'"]');if(e)if(c.length==1){c.html(d);if(c.attr("data-isOffline")){c.removeAttr("data-isOffline");
c.effect("highlight",{color:"#080"});j++}else c.effect("highlight",{color:"#880"})}else{b=$("#OnlineTab tbody tr:last");b=!b.length||b.hasClass("even");$("#OnlineTab table tbody").append('<tr class="'+(b?"odd":"even")+'" data-id="'+a+'">'+d+"</tr>");c=$("#OnlineTab tbody tr:last");j++;c.effect("highlight",{color:"#080"})}else if(c.length==1){c.attr("data-isOffline",true);a=c.children("td");a.fadeTo(0,0.2);a.find("a.userLink").replaceWith(b);a.filter(".level").html("?");j--;c.effect("highlight",{color:"#800"})}if(h!=
j){h=""+j+" player"+(j==1?"":"s")+" online";i.attr("data-count",j);i.html(h)}},requestBattle=function(a,b,d,c){createModalConfirmDialogAtMouse(a,"Confirm Attack","<p>Do you really want to attack "+d+"?</p><p>This will cost 100 Action Points (AP).</p><p>In case of victory you\u2019ll probably receive "+c+" XP.</p>",function(){$(this).dialog("close");$.get("/Battle/StartBattle/"+b)})},setupNextAjaxEventsRequestEvent=function(){var a=(new Date).getTime();a=Alfodr.ajaxEventRequestTick-(a-Alfodr.lastAjaxEventRequestTime);
a<1?processAjaxEvents():window.setTimeout(processAjaxEvents,a)},posIsIn=function(a,b,d,c,e,f){return a>=d&&a<=e&&b>=c&&b<=f?true:false},MouseMode={Normal:1,Attack:2},Direction={North:0,East:1,South:2,West:3},BattleMode={None:1,Starting:2,Fight:3,Ending:4},KeyCode={W:87,A:65,S:83,D:68,LeftArrow:37,UpArrow:38,RightArrow:39,DownArrow:40};
function Tile(a,b,d){this.x_=a;this.y_=b;this.groundType_=d;this.living_=this.htmlRef_=null;this.entities_=[];this.showOverlay=function(){this.hasOverlay_=true;this.htmlRef_.fadeTo(0,0.5)};this.hideOverlay=function(){this.htmlRef_.fadeTo(0,1);this.hasOverlay_=false};this.hasOverlay=function(){return this.hasOverlay_};this.registerLivingSteppedOn=function(c){this.living_=c};this.registerLivingSteppedOff=function(){this.living_=null};this.left=function(){return this.x_*25+2};this.top=function(){return this.y_*
25+2};this.isBlocking=function(){for(var c=this.living_!=null;!c&&0!=this.entities_.length;)c=this.entities_[0].isBlocking_;return c};this.addEntity=function(c){this.entities_.push(c)};this.draw=function(){this.htmlRef_=$().add('<img src="/img/'+(this.groundType_==1?"34":"35")+'" style="position: absolute; width: 25px; height: 25px; z-index: 100; left: '+this.left()+"px; top: "+this.top()+'px;" />').appendTo(battle.playingFieldRef_);for(var c in this.entities_)this.entities_[c].draw(this.left(),this.top())}}
function Actor(a,b,d){this.id_=a;this.ajaxUuid_=b;this.disabledSound_=d}
function Projectile(a,b,d,c){this.startingTile_=a;this.differenceX_=b;this.differenceY_=d;this.damage_=c;this.damageRef_=this.projectileRef_=null;this.drawAnimation=function(){var e=battle.tiles_[Math.round(this.startingTile_.x_+this.differenceX_)][Math.round(this.startingTile_.y_+this.differenceY_)];this.projectileRef_=$().add('<img src="/img/37" style="position: absolute; width: 25px; height: 25px; z-index: 800; left: '+this.startingTile_.left()+"px; top: "+this.startingTile_.top()+'px;" />').appendTo(battle.playingFieldRef_);
this.projectileRef_.animate({left:Math.round(this.startingTile_.left()+this.differenceX_*25),top:Math.round(this.startingTile_.top()+this.differenceY_*25)},150,"linear",$.proxy(function(){if(this.damage_>0){this.damageRef_=$().add('<div style="position: absolute; z-index: 1100; font-size: 80%; color: red; left: '+e.left()+"px; top: "+e.top()+'px;">'+this.damage_+"</div>").appendTo(battle.playingFieldRef_);this.damageRef_.animate({left:e.left(),top:e.top()-30},950,"swing",$.proxy(function(){this.damageRef_.remove()},
this))}window.setTimeout($.proxy(function(){this.projectileRef_.remove()},this),67)},this))}}
function Weapon(a,b,d,c){this.id_=a;this.imageId_=b;this.attackRange_=d;this.cooldownTime_=c;this.htmlRef_=null;this.isEnabled_=true;this.drawToMenu=function(){this.htmlRef_=$().add('<div style="position: absolute; width: 150px; height: 100px; z-index: 2000; left: 20px; top: '+(20+this.id_*120)+"px; background: url(/img/"+this.imageId_+') no-repeat scroll center center transparent;"> </div>').appendTo(battle.menuRef_)};this.registerGettingInactive=function(){battle.actor().hideAttackRange();this.htmlRef_.css({"background-color":""})};
this.registerGettingActive=function(){battle.actor().showAttackRange(this.attackRange_,null);this.htmlRef_.css({"background-color":"#FF3333"})};this.disableForTime=function(e){this.isEnabled_=false;this.htmlRef_.fadeTo(0,0.01);this.htmlRef_.fadeTo(e+50,0.2,"linear",$.proxy(this.enable,this))};this.enable=function(){this.htmlRef_.fadeTo(0,1);this.isEnabled_=true}}
function Entity(a,b){this.imageId_=a;this.isBlocking_=b;this.ref_=null;this.draw=function(d,c){this.ref_=$().add('<img src="/img/'+this.imageId_+'" style="position: absolute; width: 25px; height: 25px; z-index: 1000; left: '+d+"px; top: "+c+'px;" />').appendTo(battle.playingFieldRef_)}}
function Living(a,b,d){this.id_=a;this.healthPoints_=b;this.name_=d;this.tile_=this.hpRef_=this.nameRef_=this.ghostRef_=this.bodyRef_=null;this.isMoving_=false;this.posIsAcknowledged_=true;this.showAttackRange=function(c,e){this.activeAttackRange_=c;var f=battle.findTilesByDistance(this.tile_,c),g=null;if(e)g=battle.findTilesByDistance(e,c);for(var i in f){var h=f[i];h.hasOverlay()||h.showOverlay()}if(g)for(i in g){e=g[i];h=false;for(var j in f)if(e==f[j]){h=true;break}h||e.hideOverlay()}};this.hideAttackRange=
function(){var c=battle.findTilesByDistance(this.tile_,this.activeAttackRange_),e;for(e in c)c[e].hideOverlay();this.activeAttackRange_=0};this.registerSteppedOnTile=function(c){this.tile_=c};this.registerFinishedMoving=function(){this.isMoving_=false;if(this.ghostRef_){this.ghostRef_.remove();this.ghostRef_=null}battle.registerActorStoppedMoving()};this.drawToPlayingField=function(){var c=this.tile_;this.bodyRef_=$().add('<img src="/img/36" style="position: absolute; width: 25px; height: 25px; z-index: 1000; left: '+
c.left()+"px; top: "+c.top()+'px;" />').appendTo(battle.playingFieldRef_);this.nameRef_=$().add('<div style="position: absolute; z-index: 1001; font-size: 80%; left: '+c.left()+"px; top: "+(c.top()-15)+'px;">'+this.name_+"</div>").appendTo(battle.playingFieldRef_);this.hpRef_=$().add('<div style="position: absolute; z-index: 1001; font-size: 80%; left: '+c.left()+"px; top: "+c.top()+'px;">'+this.healthPoints_+"</div>").appendTo(battle.playingFieldRef_)};this.moveToTile=function(c,e,f){var g=this.tile_;
this.registerSteppedOnTile(c);if(e){if(this.isMoving_){this.bodyRef_.stop(true);this.nameRef_.stop(true);this.hpRef_.stop(true);if(this.ghostRef_){this.ghostRef_.remove();this.ghostRef_=null}}this.isMoving_=true;e={left:c.left(),top:c.top()};this.ghostRef_=$().add('<img src="/img/36" style="position: absolute; width: 25px; height: 25px; z-index: 999; left: '+c.left()+"px; top: "+c.top()+'px;" />').appendTo(battle.playingFieldRef_);this.ghostRef_.fadeTo(0,0.4);this.bodyRef_.animate(e,f,"linear",$.proxy(function(){this.registerFinishedMoving()},
this));this.nameRef_.animate({left:c.left(),top:c.top()-15},f,"linear");this.hpRef_.animate(e,f,"linear");this.activeAttackRange_&&this.showAttackRange(this.activeAttackRange_,g)}};this.statUpdate=function(c,e){this.healthPoints_=c;e&&this.hpRef_.html(""+c)}}
function Battle(){this.menuRef_=this.playingFieldRef_=null;this.mode_=BattleMode.None;this.screenRef_=this.topOverlayRef_=this.overlayRef_=null;this.tiles_=[];this.livings_=[];this.weapons_=[];this.activeTimeout_=this.activeDialog_=this.activeWeapon_=this.player_=this.mouseMode_=this.selectedTileMarker_=this.selectedTile_=null;this.hasActiveDirection_=false;this.activeDirection_=null;this.actor=function(){return this.livings_[Alfodr.actor.id_]};this.isValidPosition=function(a,b){return posIsIn(a,
b,0,0,19,19)};this.calcDistanceTowardsTile=function(a,b){return Math.sqrt(Math.pow(Math.abs(b.x_-a.x_),2)+Math.pow(Math.abs(b.y_-a.y_),2))};this.findTilesByManhattenDistance=function(a,b){for(var d=[],c=a.x_,e=a.y_,f=-b;f<=b;f++)for(var g=-b;g<=b;g++)if(f||g){var i=c+f,h=e+g;this.isValidPosition(i,h)&&d.push(this.tiles_[i][h])}return d};this.findTilesByDistance=function(a,b){var d=[],c=this.findTilesByManhattenDistance(a,Math.floor(b)),e;for(e in c){var f=c[e];this.calcDistanceTowardsTile(a,f)<=b&&
d.push(f)}return d};this.startBattle=function(a){var b=a[1]=="Attacker",d=a[2],c=a[3],e=a[4],f=a[5];a=a[6];!Alfodr.actor.disabledSound_&&a>7E3&&!b&&playMp3(6E3);document.title="!!! BATTLE !!!";this.mode_=BattleMode.Starting;jQuery.fx.interval=33;Alfodr.ajaxEventRequestTick=100;$(document).bind("dblclick",function(i){i.stopImmediatePropagation();return false});this.activeDialog_=b?createCriticalDialog("Battle!","You attack "+c,null):createCriticalDialog("Battle!","You are attacked by "+d,null);for(var g in e){d=
e[g];b=new Tile(d[0][0],d[0][1],d[0][2]);if(d[1].length>0){c=new Living(d[1][0],d[1][1],d[1][2]);b.registerLivingSteppedOn(c);c.registerSteppedOnTile(b);this.livings_[c.id_]=c;if(c.id_==Alfodr.actor.id_)this.player_=c}if(d[2].length>0){d=new Entity(d[2][0],d[2][1]);b.addEntity(d)}this.addTile(b)}for(g in f){e=f[g];e=new Weapon(g,e[0],e[1],e[2]);this.weapons_[g]=e}this.activeTimeout_=window.setTimeout($.proxy(this.displayGameScreen,this),a)};this.displayGameScreen=function(){this.activeDialog_.dialog("close");
this.activeTimeout_=this.activeDialog_=null;this.overlayRef_=$().add('<div class="ui-widget-overlay" style="z-index: 50;"> </div>').appendTo($("body"));this.overlayRef_.fadeTo(0,0.95);this.topOverlayRef_=$().add('<div class="ui-widget-overlay" style="cursor: default; z-index: 64000;"> </div>').appendTo($("body"));this.topOverlayRef_.fadeTo(0,0);this.screenRef_=$().add('<div id="BattleScreen" style="position: absolute; background-color: red; width: 700px; height: 504px; left: 50%; margin-left: -350px; top: 50%; margin-top: -252px;"> </div>').appendTo($("body"));
this.playingFieldRef_=$().add('<div id="PlayingField" style="position: absolute; left: 0px; top: 0px; width: 504px; height: 504px;"> </div>').appendTo(this.screenRef_);this.menuRef_=$().add('<div style="position: absolute; left: 504px; top: 0px; width: 196px; height: 504px; background-color: #CCAAAA"> </div>').appendTo(this.screenRef_);this.playingFieldRef_.append('<div style="position: absolute; top: 0px; left: 0px; width: 2px; height: 504px; background-color: brown;"> </div>');this.playingFieldRef_.append('<div style="position: absolute; top: 0px; left: 0px; width: 2px; height: 504px; background-color: brown;"> </div>');
this.playingFieldRef_.append('<div style="position: absolute; top: 0px; left: 0px; width: 504px; height: 2px; background-color: brown;"> </div>');this.playingFieldRef_.append('<div style="position: absolute; top: 0px; left: 502px; width: 2px; height: 504px; background-color: brown;"> </div>');this.playingFieldRef_.append('<div style="position: absolute; top: 502px; left: 0px; width: 504px; height: 2px; background-color: brown;"> </div>');for(var a in this.tiles_)for(var b in this.tiles_[a]){var d=
this.tiles_[a][b];d.living_!=null&&d.living_.drawToPlayingField();d.draw()}for(var c in this.weapons_)this.weapons_[c].drawToMenu();this.selectedTileMarker_=$().add('<div style="position: absolute; z-index: 200; left: 0px; top: 0px; width: 21px; height: 21px; border: 2px solid black; display: none;" />').appendTo(this.playingFieldRef_);this.switchMouseMode(MouseMode.Normal);this.mode_=BattleMode.Fight;$(document).mousedown($.proxy(this.handleClick,this));this.topOverlayRef_.mousedown($.proxy(this.handleClick,
this));document.onselectstart=function(){return false};$(document).keydown($.proxy(this.handleKeyDown,this));this.topOverlayRef_.keydown($.proxy(this.handleKeyDown,this));$(document).keyup($.proxy(this.handleKeyUp,this));this.topOverlayRef_.keyup($.proxy(this.handleKeyUp,this))};this.addTile=function(a){if(typeof this.tiles_[a.x_]=="undefined")this.tiles_[a.x_]=[];this.tiles_[a.x_][a.y_]=a};this.projectile=function(a){(new Projectile(this.tiles_[a[1]][a[2]],a[3],a[4],a[5])).drawAnimation()};this.livingStatUpdate=
function(a){this.livings_[a[1]].statUpdate(a[2],this.mode_==BattleMode.Fight?true:false)};this.remove=function(){if(this.mode_==BattleMode.Starting){this.activeDialog_.dialog("close");this.activeDialog_=null;window.clearTimeout(this.activeTimeout_);this.activeTimeout_=null}else if(this.mode_==BattleMode.Fight){this.overlayRef_.remove();this.overlayRef_=null;this.topOverlayRef_.remove();this.topOverlayRef_=null;this.screenRef_.remove();this.screenRef_=null;if(this.activeTimeout_){window.clearTimeout(this.activeTimeout_);
this.activeTimeout_=null}}else if(this.mode_==BattleMode.Ending){if(this.activeDialog_){this.activeDialog_.dialog("close");this.activeDialog_=null}window.clearTimeout(this.activeTimeout_);this.activeTimeout_=null}$(document).unbind("keydown");$(document).unbind("keyup");$(document).unbind("dblclick");$(document).unbind("mousedown");document.onselectstart=function(){};Alfodr.ajaxEventRequestTick=1E3};this.livingLeft=function(){};this.handleBattleEnding=function(a){var b=a[1];window.setTimeout($.proxy(function(){this.screenRef_.fadeTo(2500,
0)},this),1500);this.activeTimeout_=window.setTimeout($.proxy(function(){document.title="Battle Finished";this.remove();this.mode_=BattleMode.Ending;this.activeDialog_=createCriticalDialog("Battle Result",b,{"Continue Playing":$.proxy(function(){this.remove();this.mode_=BattleMode.None},this)})},this),4E3)};this.pollMouse=function(){var a=this.playingFieldRef_.offset(),b=Math.floor((globalMousex-a.left-2)/25);a=Math.floor((globalMousey-a.top-2)/25);posIsIn(b,a,0,0,19,19)?this.trySelectTile(b,a):this.tryUnselectTile()};
this.playerMovesIntoActiveDirection=function(){var a=this.activeDirection_,b=this.player_,d=b.tile_.x_,c=b.tile_.y_;switch(a){case Direction.West:d--;break;case Direction.North:c--;break;case Direction.East:d++;break;case Direction.South:c++}if(!posIsIn(d,c,0,0,19,19))return false;d=this.tiles_[d][c];if(d.isBlocking())return false;!b.isMoving_&&b.posIsAcknowledged_&&this.moveLivingToTile(b,d,false,1200);switch(a){case Direction.West:$.get("/Battle/Move/West");break;case Direction.North:$.get("/Battle/Move/North");
break;case Direction.East:$.get("/Battle/Move/East");break;case Direction.South:$.get("/Battle/Move/South")}};this.moveLivingToTile=function(a,b,d,c){var e=this.mode_==BattleMode.Fight?true:false;a.posIsAcknowledged_=d;a.tile_.registerLivingSteppedOff();b.registerLivingSteppedOn(a);a.moveToTile(b,e,c)};this.handleLivingMovedEvent=function(a){var b=a[4],d=this.tiles_[a[2]][a[3]];a=this.livings_[a[1]];if(a.tile_==d){a.posIsAcknowledged_=true;return false}this.moveLivingToTile(a,d,true,b)};this.keyCodeToDirection=
function(a){switch(a){case KeyCode.UpArrow:case KeyCode.W:return Direction.North;case KeyCode.LeftArrow:case KeyCode.A:return Direction.West;case KeyCode.DownArrow:case KeyCode.S:return Direction.South;case KeyCode.RightArrow:case KeyCode.D:return Direction.East;default:return-1}};this.handleKeyDown=function(a){a.stopImmediatePropagation();a=this.keyCodeToDirection(a.which);if(a==-1||this.hasActiveDirection_&&this.activeDirection_==a)return false;this.activeDirection_=a;this.hasActiveDirection_=true;
this.playerMovesIntoActiveDirection();return false};this.handleKeyUp=function(a){a.stopImmediatePropagation();a=this.keyCodeToDirection(a.which);if(a==-1)return false;if(this.activeDirection_==a)this.hasActiveDirection_=false;return false};this.walkToTile=function(a){if(a.isBlocking())return false;$.get("/Battle/WalkTo/"+a.x_+"/"+a.y_+"/")};this.shootAtTile=function(a){var b=this.activeWeapon_.cooldownTime_;$.get("/Battle/Attack/"+a.x_+"/"+a.y_+"/"+this.activeWeapon_.id_);this.switchMouseMode(MouseMode.Normal);
this.tryUnselectWeapon();for(var d in this.weapons_)this.weapons_[d].disableForTime(b)};this.handleClick=function(a){a.stopImmediatePropagation();var b=this.actor(),d=a.pageX;a=a.pageY;var c=this.playingFieldRef_.offset(),e=Math.floor((d-c.left-2)/25);c=Math.floor((a-c.top-2)/25);var f=null;if(posIsIn(e,c,0,0,19,19))f=this.tiles_[e][c];if(f)if(this.mouseMode_==MouseMode.Attack)this.calcDistanceTowardsTile(b.tile_,f)<=b.activeAttackRange_&&this.shootAtTile(f);else this.mouseMode_==MouseMode.Normal&&
this.walkToTile(f);else for(var g in this.weapons_){b=this.weapons_[g];b.isEnabled_&&d>=b.htmlRef_.offset().left&&a>=b.htmlRef_.offset().top&&d<=b.htmlRef_.offset().left+b.htmlRef_.innerWidth()&&a<=b.htmlRef_.offset().top+b.htmlRef_.innerHeight()&&this.registerWeaponClicked(b)}return false};this.registerActorStoppedMoving=function(){this.hasActiveDirection_&&this.playerMovesIntoActiveDirection()};this.registerWeaponClicked=function(a){if(this.activeWeapon_==a){this.switchMouseMode(MouseMode.Normal);
this.activeWeapon_=null;a.registerGettingInactive()}else{this.activeWeapon_==null?this.switchMouseMode(MouseMode.Attack):this.activeWeapon_.registerGettingInactive();this.activeWeapon_=a;a.registerGettingActive()}};this.tryUnselectWeapon=function(){if(this.activeWeapon_==null)return false;this.activeWeapon_.registerGettingInactive();this.activeWeapon_=null;return true};this.switchMouseMode=function(a){this.mouseMode_=a;switch(a){case MouseMode.Normal:this.topOverlayRef_.css({cursor:"default"});this.selectedTileMarker_.css({border:"2px solid black"});
break;case MouseMode.Attack:this.topOverlayRef_.css({cursor:"crosshair"});this.selectedTileMarker_.css({border:"2px solid red"})}}}var battle=new Battle;
jQuery.fn.limitMaxlength=function(a){var b=jQuery.extend({attribute:"maxlength",onLimit:function(){},onEdit:function(){}},a);a=function(){var d=jQuery(this),c=parseInt(d.attr(b.attribute));if(d.val().length>c){d.val(d.val().substr(0,c));jQuery.proxy(b.onLimit,this)()}jQuery.proxy(b.onEdit,this)(c-d.val().length)};this.each(a);return this.keyup(a).keydown(a).focus(a).live("input paste",a)};

