/*
 * gItem.js
 *
 * Copyright (c) 2008 Tyler de Witt (tyler-dewitt.com)
 * Unauthorized reproduction or use of this code is not permitted.
 */

function gItem() {
  this.image='book.jpg';
  this.zIndex=15;
  this.walkable=true;
  this.object_type="gItem";
  this.state=new Object();
  this.state.mod=0;
  
  this.save=function() { var o=this.save_default("gItem"); return o; }
  this.load=function(o) {  this.load_default(o,"gItem"); }

  this.walk=function(o,xoffset,yoffset) {
    msg(conjugate_me(o,"see",this));
    return true;
  }

 this.apply=function(who,o) {
    msg("Nothing happens");
  }
  this.throws=function(who) {
    msg(conjugate(who,"throw",this));
  }

  this.pickup=function(who) { return true; }
}

gItem.prototype=new gTile;
gItem.prototype.savedVars = ["state"];

gItem_protos = {
  healing_potion: { image: 'potion.jpg', title: 'healing potion', drink: function(who) {
      who.hp+=roll("1d3+9"); if (who.hp > who.max_hp) who.hp=who.max_hp;
    msg("You feel better.");
  }},

  mana_potion: { image: 'potion.jpg', title: 'mana potion', drink: function(who) {
      who.mp+=roll("1d3+7"); if (who.mp > who.max_mp) who.mp=who.max_mp;
    msg("You feel magical.");
  }},

  extra_healing_potion: { image: 'potion.jpg', title: 'healing potion', drink: function(who) {
      who.hp+=roll("1d7+18"); if (who.hp > who.max_hp) who.hp=who.max_hp;
      msg("You feel much better.");
  }},

  poison_resistance_potion: { image: 'potion.jpg', title: 'potion of poison resistance', drink: function(who) {
      who.state.poison_resistant=1;
      msg("Yummy! You feel a boost in your immune system.");
  }},

  cure_poison_potion: { image: 'potion.jpg', title: 'cure poison potion', drink: function(who) {
      if (who.state.poisoned) {
	delete who.state.poisoned
	for (var i in who.events) {
	  if (who.events[i].sub_type=="poison") {
	    who.events[i].destroy();
	  }
	}
	msg("You a little better now.");
      } else {
	msg("Nothing happens.");
      }
  }},

  //For temporal effects, we create an event and attach it to the character
  poison_potion: { image: 'potion.jpg', title: 'poison potion', drink: function(who) {
      gEvent.prototype.apply_effect(who,"poison");
  }},

  invisibility_potion: { image: 'potion.jpg', title: 'invisibility potion', drink: function(who) {
      gEvent.prototype.apply_effect(who,"invisible", { wearoff: 10 });
  }},

  speed_potion: { image: 'potion.jpg', title: 'speed potion', drink: function(who) {
      gEvent.prototype.apply_effect(who,"speed", { wearoff: 30, amount: 2 });
  }},

  levitation_potion: { image: 'potion.jpg', title: 'levitation potion', drink: function(who) {
      gEvent.prototype.apply_effect(who,"levitate", { wearoff: 50 });
  }},


  curse_weapon_scroll: { image: 'book.jpg', title: 'curse weapon scroll', read: function(who) {
      if (who.worn.right_hand) {
	who.worn.right_hand.state.cursed=true;
	msg("Your " + who.worn.right_hand.title + " glows black.");
      } else {
	msg("Nothing happens.");
      }
  }},

  enchant_weapon_scroll: { image: 'book.jpg', title: 'enchant weapon scroll', read: function(who) {
      if (who.worn.right_hand) {
	who.worn.right_hand.state.mod++;
	msg("Your " + who.worn.right_hand.title + " glows green for a moment.");
      } else {
	msg("Nothing happens.");
      }
  }},

  enchant_armour_scroll: { image: 'book.jpg', title: 'enchant armour scroll', read: function(who) {
      if (who.worn.body) {
	who.worn.body.state.mod++;
	msg("Your " + who.worn.body.title + " glows green for a moment.");
      } else {
	msg("Nothing happens.");
      }
  }},

  blank_spellbook: { image: 'book.jpg', title: 'blank spellbook', read: function(who) {
    msg("The scroll is blank.");
  }},

  stone: {  image: 'stonegrass.jpg', title: 'stone', descrip: 'a large smooth stone.' }
};


