define(["character","exceptions"],function(e,t){var n=e.extend({MAX_LEVEL:10,init:function(e,t,n){this._super(e,n),this.name=t,this.nameOffsetY=-10,this.spriteName="clotharmor",this.weaponName="sword1",this.isLootMoving=!1,this.isSwitchingWeapon=!0},loot:function(e){if(e){var n,r,i,s;this.currentArmorSprite?s=this.currentArmorSprite.name:s=this.spriteName,e.type==="armor"?(n=Types.getArmorRank(e.kind),r=Types.getArmorRank(Types.getKindFromString(s)),i="You are wearing a better armor"):e.type==="weapon"&&(n=Types.getWeaponRank(e.kind),r=Types.getWeaponRank(Types.getKindFromString(this.weaponName)),i="You are wielding a better weapon");if(n&&r){if(n===r)throw new t.LootException("You already have this "+e.type);if(n<=r)throw new t.LootException(i)}log.info("Player "+this.id+" has looted "+e.id),Types.isArmor(e.kind)&&this.invincible&&this.stopInvincibility(),e.onLoot(this)}},isMovingToLoot:function(){return this.isLootMoving},getSpriteName:function(){return this.spriteName},setSpriteName:function(e){this.spriteName=e},getArmorName:function(){var e=this.getArmorSprite();return e.id},getArmorSprite:function(){return this.invincible?this.currentArmorSprite:this.sprite},getWeaponName:function(){return this.weaponName},setWeaponName:function(e){this.weaponName=e},hasWeapon:function(){return this.weaponName!==null},switchWeapon:function(e){var t=14,n=!1,r=this,i=function(){return n=!n,n};if(e!==this.getWeaponName()){this.isSwitchingWeapon&&clearInterval(s),this.switchingWeapon=!0;var s=setInterval(function(){i()?r.setWeaponName(e):r.setWeaponName(null),t-=1,t===1&&(clearInterval(s),r.switchingWeapon=!1,r.switch_callback&&r.switch_callback())},90)}},switchArmor:function(e){var t=14,n=!1,r=this,i=function(){return n=!n,n};if(e&&e.id!==this.getSpriteName()){this.isSwitchingArmor&&clearInterval(s),this.isSwitchingArmor=!0,r.setSprite(e),r.setSpriteName(e.id);var s=setInterval(function(){r.setVisible(i()),t-=1,t===1&&(clearInterval(s),r.isSwitchingArmor=!1,r.switch_callback&&r.switch_callback())},90)}},onArmorLoot:function(e){this.armorloot_callback=e},onSwitchItem:function(e){this.switch_callback=e},onInvincible:function(e){this.invincible_callback=e},startInvincibility:function(){var e=this;this.invincible?this.invincibleTimeout&&clearTimeout(this.invincibleTimeout):(this.currentArmorSprite=this.getSprite(),this.invincible=!0,this.invincible_callback()),this.invincibleTimeout=setTimeout(function(){e.stopInvincibility(),e.idle()},15e3)},stopInvincibility:function(){this.invincible_callback(),this.invincible=!1,this.currentArmorSprite&&(this.setSprite(this.currentArmorSprite),this.setSpriteName(this.currentArmorSprite.id),this.currentArmorSprite=null),this.invincibleTimeout&&clearTimeout(this.invincibleTimeout)}});return n});