/*	Legend of the Green Hydra	Main Game Javascript Code, version 1.0	This game has been released for free under the Creative Commons Attribution-Share Alike 3.0 United States License. 	For more information, please visit http://deathraygames.com/play-online/drg/greenhyrda/license.html		Helper files required:		StackedMenu-01.js		ln-std-100x.js*///******** Variables for StackedMenu, requires SM_MaxHeight = [[50, 460], [50, 460], [50, 460], [50, 460], [50, 460], [50, 460]]SM_Open = [[1, 1], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0]];SM_IdPrefix = "m";SM_ContentsIdPrefix = "cm";SM_TimeVar = 1;// General Functionsfunction DeleteElement(array, n){  //delete the nth element of array  var length = array.length;  if (n >= length || n<0) { alert("error in DeleteElement");    return; }  for (var i=n; i<length-1; i++)    array[i] = array[i+1];  array.length--;}function roll (die_sides) {	return (Math.round(( Math.random() * (die_sides-1) ) + 1))}//$$$$$$$$$$$$$$$$$  New Gamefunction create_new_character() {//	if (confirm("Are you sure you want to start a new character?"))	{	var name = prompt("Enter your character's name below.","Rex");	if (name == null) name = "Rex";		//	player.job = prompt("Choose an occupation:  fighter, mage, or merchant","fighter"); 	//name = "Rex";	job = "fighter";	var P, S, M;		switch (job) {			case "fighter":				P=50+roll(10); 				S=35+roll(10);				M=20+roll(10);				break;			case "mage":				M=50+roll(10); 				S=35+roll(10);				P=20+roll(10);				break;			case "merchant":				S=50+roll(10); 				M=35+roll(10);				P=20+roll(10);				break;			case "commoner":				S=40+roll(10); 				P=30+roll(10);				M=20+roll(10);				break;			case "ranger":				P=40+roll(10); 				S=40+roll(10);				M=40+roll(10);				break;			default:				alert("No such job!");				GoGame = 0;		}		player = new creature_obj(1, name, job, "player", P, M, S, 0, [0, 3], 20);		player.armbest();		player.hasMagic = true;		//player.view();		GoGame=1;		Level=0;		Encounter="travel";		Comment = "You begin your quest, seeking adventure and riches!";		Area = "on a forest trail.";		Update_Screen(Comment, Area);				XL('gameboard').display = "block";			Xelt('namebutton').innerHTML = player.name;				//Music_Start(3);	};}/** ##################### # # # # #  DISPLAY  # # # # # ############################# **/var gCreatureImageDir = "images/creatures/";function Update_Screen (Comment, Area){	var t = "";	t += player.name;	t += Bar_HTML(player.hp, player.maxhp, "red", 20, 140);	if (player.hasMagic) t += Bar_HTML(player.mp, player.maxmp, "blue", 20, 140);		Xelt('lifedisplay').innerHTML = t;		var playerimghtml = player.imgHTML();	if (Xelt('lifeimage').innerHTML != playerimghtml) {		Xelt('lifeimage').innerHTML = playerimghtml;	}		t = "XP: " + Math.round(player.xp) + ", HP: " + player.hp+ ", MP: " + player.mp;		Xelt('characterdisplay').innerHTML = t;			if (Area) {		t = "You are " + Area;		Xelt('areadisplay').innerHTML = t;	}		if (Comment) {		Xelt('commentdisplay').innerHTML = Comment;	}		t = "food: " + player.food + ", gold: " + player.gold;		Xelt('bagdisplay').innerHTML = t;		t = "Weapon: " + player.weaponName() + "<BR>Armor: " + player.armorName();		Xelt('onyoudisplay').innerHTML = t;			switch (Encounter) {		case "MERCHANT":			Xelt('button4').value = "Buy";			XLshow('button4'); 			XLshow('button5');			XL('feedbackbox').background = "#A4DCEF";			XL('feedbackbox').color = "black";						XLshow('encounterbox');			XLshow('encounterimage');						Xelt('encounterimage').innerHTML = "";			Xelt('encounterdisplay').innerHTML = "Merchant";			break;		case "CREATURE":			XL('feedbackbox').background = "Green";			XL('feedbackbox').color = "black";						XLshow('encounterbox');			XLshow('encounterimage');						Xelt('encounterimage').innerHTML = current_monster.imgHTML();			Xelt('encounterdisplay').innerHTML = current_monster.name;			break;		case "COMBAT":			Xelt('movebutton').innerHTML = "Flee";			XL('feedbackbox').background = "Red";			XL('feedbackbox').color = "black";						XLshow('encounterbox');			XLshow('encounterimage');						{				var x = current_monster.name + "<BR>";				x += Bar_HTML(current_monster.hp, current_monster.maxhp, "#bb0000", 20, 140);				Xelt('encounterimage').innerHTML = current_monster.imgHTML();				Xelt('encounterdisplay').innerHTML = x;			}			break;					default:			XLhide('innbutton');			Xelt('movebutton').innerHTML = "Travel";						if (!player.hasMagic) XLhide('castbutton');			else XLshow('castbutton');						XLhide('button4'); XLhide('button5');			XL('feedbackbox').background = "#648A48";			XL('feedbackbox').color = "#ffff80";						XL('encounterbox').border = "solid 2px black";			XL('lifebox').border = "solid 2px black";						XLhide('encounterbox');			XLhide('encounterimage');			break;	}		if (Encounter == "INN") XLshow('innbutton');	else XLhide('innbutton');}function Update_Combat_Display (who, hit) {	var thebox = "";	var theborder;	if (who == "Player") {		thebox = "encounterbox";	} else {		if (who == "Enemy") thebox = "lifebox"; 	}	if (!hit) theborder = "solid 2px black";	else theborder = "solid 3px red";	if (thebox) XL(thebox).border = theborder;}function Bar_HTML (current, max, color, height, width) {	var t;	var bordercolor = "black";	var fontcolor = "white";		height = Math.round(height);	width = Math.round(width);		var maxwidth = width - 2;	var maxheight = height - 2;	var barwidth = ((maxwidth / max) * current);	var fontsize = height - 4;	var background = "images/shade-333-666-top.gif";		t = "<DIV style='width:" + maxwidth + "px; height:" + maxheight + "px; border: solid 1px " + bordercolor + ";";	t += "background: #666666 url(\"" + background + "\") top repeat-x;'>";	t += "<DIV style='width:" + barwidth + "px; height:" + maxheight + "px; background:" + color + ";";	t += " color:" + fontcolor + "; font-size:" + fontsize + "px; text-align: center'>";	t += current + "</DIV>";	t += "</DIV>";	//alert(t);	return t;}function Update_Inv_Display (){	Xelt("fullinventorydisplay").innerHTML = player.itemsListHTML();}function Update_Player_Display (){	Xelt("fullcharacterdisplay").innerHTML = player.viewHTML();}/** M M M MMMMMMMMMMMMMMMMMMMMMM*************** MENU SELECTION ************************MMMMMMMMMMMMMMMMM M M M **/function Select_Bag (stackmenuNumber) {	SelectStack(stackmenuNumber);	Update_Inv_Display();	}function Select_Player (stackmenuNumber) {	SelectStack(stackmenuNumber);	Update_Player_Display();}/************* EXPERIENCE  *****************************************************************************/function player_gain_xp () {	alert("Ding! Because of your experiences, your skills have improved.");	var c = "<span style='color:cyan'>Ding! Because of your experiences, your skills have improved.</span>";	//player.view();	player.physical += 1 + roll(3);	player.mental += 1 + roll(3);	player.social += 1 + roll(3);	player.maxhp += 4 + roll(4);	player.maxmp += 4 + roll(4);	player.heal(Math.round(player.physical/3), Math.round(player.mental/3));	Level++;	//player.view();	Update_Screen(c);}function player_wins () {	var win = false;		if (player.xp >= 400) {		win = true;		for (i=0; i<monster.length; i++) {			if (monsterXP[i] <= 0) win = false;		}		} else {		win = false;	}	return win;}function win_sequence () {	alert("Congratulations, you have 400 XP and have killed one of everything.\nYou win!");	if (confirm("Keep playing?")) GoGame = 1;	else EndGame()}function player_death () {	EndGame();	alert("You have died!\nThe Game is Over. :(\nReload the page to start a new game.");}function EndGame () {	GoGame = 0;	Xelt('gameover').style.display = "block";	XL('gameboard').display = "none";}function travel() {  if (GoGame==1) {     if (Encounter!="COMBAT") {	Encounter = "travel";	player.xp += 1;	if (Math.floor(player.xp/50) > Level) player_gain_xp();	if (player_wins()) { win_sequence(); return; }	if (player.food <= 0) { 		player.hp -= 2;		if (player.isDead()) player_death();	} else {		player.food -= 1;			player.heal(1,0);	};	player.heal(0,1);	// +1 mana	var Comment = " ", Area = "in the forest.";	switch (roll(13)) {		case 1: 	Area="in the forest."; break;		case 2: 	Area="in a lovely clearing."; break;		case 3:	Area="crossing a bubbling creek."; break;		case 4:	Area="somewhere in the forest."; Comment="You seem lost..."; break;		case 5:	Area="on a forest trail."; break;		case 6:	Area="at the edge of a marsh."; break;		case 7:	Area="in a muddy area."; Comment="Your boots are dirty."; break;		case 8:	Area="near some pine trees."; break;		case 9:	Area="by a tall oak tree."; break;		case 10:	Area="near some rocks."; break;		case 11:	Area="at some berry bushes."; Comment="You take some berries. (food+6)";			player.food +=6; break;		case 12:	Area="at an oak tree."; Comment="You take some acorns. (food+5)";			player.food +=5; break;		case 13:	Area="at a stream."; Comment="You go fishing. (food+8)";			player.food +=8; break;	}	var Find=roll(20);		switch (Find) {		case 1: case 2: case 3: case 4:			Area="stopped " + Area;			Comment = Creature_Encounter();			break;		case 5: case 6:			Area="ambushed!";			Creature_Encounter();			Comment = current_monster.name + " attacks! " + Enemy_Attack();			Encounter = "COMBAT";			break;		case 7:			Comment=find_something(); break;		case 8: case 9:			if (roll(2) == 1) merchant_type = "food";			else merchant_type = "arms";			Area = "greeted by a merchant.";			Comment = "\"Do you wish to buy or sell " + merchant_type + "?\"";			Encounter = "MERCHANT";			break;		case 10: case 11: 			Comment = "There is a path here with a sign pointing to the nearest inn.";			Encounter = "INN";			break;				 case 12: case 13: case 14:			if (player.karma >= 0) {				Comment = "There is a path here with a sign pointing to the nearest inn.";				Encounter = "INN";			} else {				Comment = "You smell an inn nearby but cannot find it.";			}			break;	}		if (player.food<=10) { 			if (player.food==0) { Comment+=" You're very hungry!" }			else Comment+=" You're running low on food."	}	   } else {	Comment = Give_Up()   }     } else Comment="Start a new game.";    Update_Screen(Comment, Area);}function find_something (n) {	if (!n) {  n = roll(items.length) - 1;	while (items[n].type == "NW" || items[n].type == "NA") n = roll(items.length) - 1;	} else { alert("gotcha"); }	var z = "You found a " + items[n].name;	if (confirm(z + "!\nDo you want to take it?")) {		player.item[player.item.length] = items[n];		z += ", and took it.";	} else z+= ", but did not take it.";	return z;}function Creature_Encounter () {	var txt;	var monster_num;		monster_num = roll(monster.length) - 1;	current_monster = monster[monster_num];		// if the monster's HP are > your XP, then let's get another monster	var i = 0;	while (current_monster.hp > player.xp && i < 4)	{		i++;		monster_num = roll(monster.length) - 1;		current_monster = monster[monster_num];		//alert(i);	}			current_monster.armbest();				// give monster best weapons available		current_monster_number = monster_num;			// keep track of monster ID # for xp purposes		Encounter = (roll(100) > current_monster.social) ? "COMBAT" : "CREATURE";		txt = "You encounter a " + current_monster.name + ", and it's ";	txt += (Encounter=="COMBAT") ? "hostile!" : "friendly.";	return txt;}function arms_merchant (sale) {	var Comment;	if (sale=="buy") {							//BUY ARMS		var profit = 1.2;		if (player.gold > 0) {						var z="***** Arms List *****";			var armslist = new Array;			var c=0;			for (i=0; i<items.length; i++) {				var available = (items[i].getValue() <= (player.xp / 2)) && (items[i].type == "A" || items[i].type == "W") 				if (available) {					armslist[c] = i;					z += "\n["+ c +"] "+ items[armslist[c]].name;					z += " -- "+ Math.round(profit * items[armslist[c]].getValue()) + " gold";					c++;				}							}			if (c==0) Comment = "\"I don't have any weapons to sell you right now.\"";			else {				z += "\n*** Enter a number below ***";				var buynum = prompt(z);				var price = Math.round(profit * items[buynum].getValue())				var canbuy = (buynum > 0 && buynum < armslist.length && player.gold >= price);				if (canbuy) {					player.gold -= price;					Comment = "You buy a " + items[armslist[buynum]].name + ".";					player.item[player.item.length] = items[armslist[buynum]];				} else { Comment="\"You cannot buy that.\"" }			}		} else { Comment="You have no money. \"No beggars!\"" }	} else {								//SELL ARMS		if (player.item.length > 0) {			if (confirm("Sell all extra weapons from your backpack?")) {				var sellgold=0, countsold=0, i=0;				while (i<player.item.length) {					if (i != player.wpn_num && i != player.arm_num) {						//alert("Selling item "+i+ " -- "+player.item[i].name);						countsold++;						sellgold += player.item[i].getValue();						player.itemRemove(i);					} else i++;				}				if (sellgold>0) {					player.gold += sellgold;					Comment = "You sell " + countsold + " items for " + sellgold + " gold coins.";				} else { Comment="You have nothing to sell."; }			}		} else { Comment="You have nothing to sell."; }	}	return Comment;}function food_merchant (sale) {	var Comment;	if (sale=="buy") {		if (player.gold >= 5) {			Comment = "You purchase 4 units of food for 5 gold.";			player.food += 4;			player.gold -= 5;		} else { Comment="You cannot afford to buy anything more." }	} else {		if (player.food >= 5) {			Comment = "You exchange 5 units of food for 4 gold.";			player.food -= 5;			player.gold += 4;		} else { Comment="You do not have enough food to trade." }	}	return Comment;}/*AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA *AAAAAAAAAAAAAAA***************** ACTIONS ************************AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA *AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA */ function StayAtInn() {	var c;	var a;	if (Encounter == "INN") {		a = "at an inn."		var inncost = Math.round(player.xp / 2);		if(confirm("Stay at the inn for " + inncost +" gold?")) {			player.heal(100, 100);			player.gold -= inncost;					c = "You rest at the inn and feel replenished.";			}	} else c = "There is no inn here.";		Update_Screen(c, a);}function buy() {	if (GoGame==1) {	switch (Encounter) {		case "COMBAT": 	//Comment="You cannot trade in combat."; break;				current_monster.view();				break;		case "MERCHANT": 				switch (merchant_type) {					case "arms":	Comment=arms_merchant("buy"); break;					case "food":	Comment=food_merchant("buy"); break;					default:		Comment=food_merchant("buy"); break				}				break;		case "CREATURE":				current_monster.view();				//Comment = "The " + current_monster.name + " does not trade goods.";				break;		default:		Comment = "There is no one to trade with."; break;	}	} else Comment="Start a new game.";	Update_Screen(Comment);}function sell() {	if (GoGame==1) {	switch (Encounter) {		case "COMBAT": 	Comment="You cannot trade in combat."; break;		case "MERCHANT": 				switch (merchant_type) {					case "arms":	Comment=arms_merchant("sell"); break;					case "food":	Comment=food_merchant("sell"); break;					default:		Comment=food_merchant("sell"); break				}				break;		case "CREATURE":				Comment = "The " + current_monster.name + " does not trade goods.";				break;		default:		Comment = "There is no one to trade with."; break;	}	} else Comment="Start a new game.";	Update_Screen(Comment);}function attack() {	if (GoGame==1) {	switch (Encounter) {		case "COMBAT": 	Comment=Do_Combat();				break;		case "MERCHANT": 				if (confirm("If you attack this merchant you will be deemed\nan outlaw. Proceed?")) {					alert("--shame on you!--");					player.xp -= 30;					player.gold += 30;										Comment = "You have slain the merchant and stolen his gold!";					Encounter = "travel";				} else {					Comment = "The merchant gets uneasy when he sees you reaching for your weapon, and decides to leave.";					Encounter = "travel";				}				break;		case "CREATURE":				Comment = "You approach the " + current_monster.name + " with your " + player.item[player.wpn_num].name + " drawn!";				Encounter = "COMBAT";				player.karma -= 1;				break;		default:		Comment = "There is no one to attack."; break;	}	} else Comment="Start a new game.";	Update_Screen(Comment);}function cast() {	if (GoGame==1) {	switch (Encounter) {		case "COMBAT": 	Comment="No time for lengthy spells!";				break;		default:						if (player.mp >= 5) {					Comment = "You cast a healing spell and regain ";					magichealth = roll((Math.round(player.mental/20)+2));					Comment += magichealth + " health points.";					player.heal(magichealth, -5);				} else { Comment = "You need more mana." }				break;	}	} else Comment="Start a new game.";	Update_Screen(Comment);}function talk() {	if (GoGame==1) {	switch (Encounter) {		case "COMBAT": 	Comment = "--Now's not the time for a conversation!--";				break;		case "MERCHANT": 				Comment = "\"Nice day, isn't it?\"";				break;		case "CREATURE":				if (current_monster.mental > 40) Comment = "\"Good day stranger...\"";				else Comment = "\"Urgh...\"";				if (current_monster.mental > 80) Comment = "\"Consider yourself lucky to be meeting "+ current_monster.name +", The Wise.\"";				if (current_monster.social < 30) Comment = "\"Leave me alone.\"";				break;		default:		Comment = "There is no one to talk to."; break;	}	} else Comment="Start a new game.";	Update_Screen(Comment);}function Do_Combat () {	var txt="";	txt += Player_Attack()	if  (Encounter=="COMBAT") txt += Enemy_Attack();	return txt;}function Player_Attack () {	var txt="";	var hitchance = player.physical;	hitchance += (player.item[player.wpn_num]) ? player.item[player.wpn_num].magicbonus : 0;	if (roll(100) > hitchance) {		txt += "You miss! ";				Update_Combat_Display("Player",0);	} else {		dmg = player.getDamage() - current_monster.getProtection();		if (dmg < 1) dmg = 1;		current_monster.hp -= dmg;		if (current_monster.isDead()) {			txt += " " + current_monster.name + " is dead! ";			monsterXP[current_monster_number] += 1;			// keep track of kills of each monster			current_monster.heal(255,255);				//heal monster so he can come back to fight another day			Encounter = "travel";			txt += "You get "+current_monster.gold +"gp, "+current_monster.food+" food, and "+current_monster.xp+" XP.";			player.food += current_monster.food;			player.gold += current_monster.gold;			player.xp += current_monster.xp;			player.heal((current_monster.xp/5), (current_monster.xp/5));			current_monster = null;		} else {			txt += "You hit the " + current_monster.name + " (" + dmg + " dmg)! ";		}				Update_Combat_Display("Player",1);	}	return txt;}function Enemy_Attack () {	var txt="";	hitchance = current_monster.physical;	hitchance += (current_monster.item[current_monster.wpn_num]) ? current_monster.item[current_monster.wpn_num].magicbonus : 0;	if (roll(100) > hitchance) {		txt += "Enemy misses! ";				Update_Combat_Display("Enemy",0);	} else {		dmg = current_monster.getDamage() - player.getProtection();		if (dmg < 1) dmg = 1;		player.hp -= dmg;		if (player.isDead()) player_death();		else txt += "You are hit (" + dmg + " dmg)!";				Update_Combat_Display("Enemy",1);	}	return txt;}function Give_Up () {	var txt;	var question = "\"I will let you go if you give me ";	var terms = roll(4);	switch (terms) {		case 1:	question += " all your gold.\""; break;		case 2:	question += " all your food.\""; break;		case 3:	question += " all your food and gold.\""; break;		default:	question += " everything you own!\""; break;	}	question += "\n\nSurrender to the "+ current_monster.name +"?";	if (confirm(question)) {		switch (terms) {			case 1:	player.gold=0; break;			case 2:	player.food=0; break;			case 3:	player.gold=0; player.food=0; break;			default:	player.gold=0; player.food=0;				while (player.item.length>0) {					player.itemRemove(0);				}				break;		}		txt = "The " + current_monster.name + " leaves you...";		Encounter = "travel";		} else {		txt = "\"Don't like my offer?\" " + Enemy_Attack();	}	return txt;}/////////////////////************************/////////////////<!--Alien Technologyfunction swapImage() { //v1.0  var i,theObj,j=0,swapArray=new Array,oldArray=document.swapImgData;  for (i=0; i < (swapImage.arguments.length-2); i+=3) {    theObj = eval(swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1])    if (theObj != null) {      swapArray[j++] = theObj;      swapArray[j++] = (oldArray==null || oldArray[j-1]!=theObj)?theObj.src:oldArray[j];      theObj.src = swapImage.arguments[i+2];  } }  document.swapImgData = swapArray; //used for restore};function swapImgRestore() {  if (document.swapImgData != null)    for (var i=0; i<(document.swapImgData.length-1); i+=2)      document.swapImgData[i].src = document.swapImgData[i+1];	};		/***************************OBJECTS***************************************************************//********************************************************ITEM OBJECT***/function item_getValue () {	return (6 * this.damage) + (8 * this.protection) + (this.magicbonus * 12);}function item_obj (t, n, d, p, m) {	this.type = t;		/* (A)rmor, (W)eapon, (N)atural weapon	*/	this.name = n;	this.damage = d;	this.protection = p;	this.magicbonus = (m) ? m : 0;	this.isArmor = (t=="A" || t=="NA")  ? 1 : 0;	this.isWeapon = (t=="W" || t=="NW")  ? 1 : 0;	this.getValue = item_getValue;}var items = new Array();items[0] = new item_obj("A", "Cloth", 		0, 1);items[1] = new item_obj("A", "Leather", 	0, 2);items[2] = new item_obj("A", "Studded", 	0, 3);items[3] = new item_obj("W", "Pocket Knife", 	2, 0);items[4] = new item_obj("W", "Large Knife", 	4, 0);items[5] = new item_obj("W", "Club", 		6, 0);items[6] = new item_obj("NW", "Claws", 		3, 0);items[7] = new item_obj("NW", "Fists", 		1, 0);items[8] = new item_obj("NA", "Skin", 		0, 0);items[9] = new item_obj("NA", "Fur", 		0, 1);items[10] = new item_obj("W", "Star Staff", 	6, 2, 1);items[11] = new item_obj("A", "Chainmail", 	0, 5);items[12] = new item_obj("A", "Scalemail", 	0, 6);items[13] = new item_obj("A", "Platemail", 	0, 8);items[14] = new item_obj("A", "Golden Platemail", 0, 10, 2);items[15] = new item_obj("W", "Short Sword", 	8, 0);items[16] = new item_obj("W", "Long Sword", 	10, 0);items[17] = new item_obj("W", "Long Staff", 	9, 2);items[18] = new item_obj("W", "Spear", 		8, 1);items[19] = new item_obj("W", "Spiked Mace", 	12, 0);items[20] = new item_obj("NW", "Large claws", 	5, 0);items[21] = new item_obj("NW", "Fangs", 	3, 0);items[22] = new item_obj("A", "Dragon Scales", 	1, 7, 1);items[23] = new item_obj("W", "War Axe", 	14, 0);items[24] = new item_obj("W", "Battle Blade", 	16, 0);items[25] = new item_obj("W", "Death Axe", 	18, 0, 1);items[26] = new item_obj("W", "Avenger Sword", 	20, 0, 2);var fists = new item_obj("NW", "Fists", 	1, 0);var skin = new item_obj("NA", "Skin", 		0, 0);/***********************************************************CREATURE OBJECT***/function creature_view () {	var txt = "NAME: "+this.name+", the "+this.job+"\nXP: "+this.xp+"";	txt += "\nSKILLS: (out of 100)\n";	txt += "Physical = "+ this.physical + ", Mental = "+ this.mental +", Social = "+ this.social +"\n";	txt += "Hit Points = "+  this.hp + " (" + this.maxhp +"), Mana Points = "+ this.mp + " ("+this.maxmp +")";	txt += "\n\nIN BACKPACK:\n"+ this.gold+" pieces of gold and "+this.food+" food units.\n";	txt += "\n\nArmed with : " + this.weaponName();	txt += " (dmg: "+ (this.damageBase() + 2) + "-" + ((this.damageBase() * 2)+6) + " +" + Math.round(this.physical / 20) + ")";	txt += "\nWearing : " + this.armorName() + " (prot: "+ this.getProtection() + ")";	//txt += "\nwpn_num = " + this.wpn_num + " / arm_num = " + this.arm_num;	alert(txt);}function creature_viewHTML (){	var txt = "NAME: "+this.name+", the "+this.job;	txt += "<br>Hit Points = "+  this.hp + " (" + this.maxhp +")" + Bar_HTML(this.hp, this.maxhp, "red", 20, 240) + "";	txt += "<br>Mana Points = "+ this.mp + " ("+this.maxmp +")" + Bar_HTML(this.mp, this.maxmp, "blue", 20, 240) + "";	txt += "<br>XP: "+this.xp + Bar_HTML(this.xp, 400, "green", 15, 300)	txt += "<p>SKILLS: (out of 100)<ul>";	txt += "<li>Physical = "+ this.physical + Bar_HTML(this.physical, 100, "orange", 10, 240) + "</li>";	txt += "<li>Mental = "+ this.mental + Bar_HTML(this.mental, 100, "cyan", 10, 240) + "</li>";	txt += "<li>Social = "+ this.social + Bar_HTML(this.social, 100, "purple", 10, 240) + "</li>";	txt += "</ul></p>";	txt += "<p>Armed with : " + this.weaponName() + "";	txt += " (dmg: "+ (this.damageBase() + 2) + "-" + ((this.damageBase() * 2)+6) + " +" + Math.round(this.physical / 20) + ")</p>";	txt += "<p>Wearing : " + this.armorName() + " (prot: "+ this.getProtection() + ")</p>";	return txt;}function creature_damageBase () {		var dmg=0;		if (this.item[this.wpn_num]) {			dmg = this.item[this.wpn_num].damage;			dmg += this.item[this.wpn_num].magicbonus;			if (this.arm_num!=-1) dmg += this.item[this.arm_num].damage;		}		return dmg;}function creature_getDamage () {		var dmg= this.damageBase();		dmg = dmg + roll(dmg) + roll(4) + Math.round(this.physical / 15);		return dmg;}function creature_getProtection () {		var p=0;		if (this.item[this.arm_num]) {			p = this.item[this.arm_num].protection;			p += this.item[this.arm_num].magicbonus;			if (this.wpn_num!=-1) p += this.item[this.wpn_num].protection;		}		return p;}function creature_isDead () {	return (this.hp <= 0) ? true : false;}function creature_heal (healhp, healmp) {	this.hp += healhp;	if (this.hp > this.maxhp) this.hp = this.maxhp;	this.mp += healmp;	if (this.mp > this.maxmp) this.mp = this.maxmp;}function creature_weapon_name () {	return (this.item[this.wpn_num]) ? this.item[this.wpn_num].name : "Nothing";}function creature_armor_name () {	return (this.item[this.arm_num]) ? this.item[this.arm_num].name : "Nothing";}function creature_itemsView () { alert(this.itemsList()); }function creature_itemsList () {	var z = "<p>IN BACKPACK: "+ this.gold+" pieces of gold and "+this.food+" food units.</p>";	z += "Number of Items: " + this.item.length;	for (i=0; i<this.item.length; i++) {		z += "<BR>\n[" + i + "] " + this.item[i].name;		if (this.item[i].magicbonus)			z += "+" + this.item[i].magicbonus;		z += " - " + this.item[i].getValue() + "gp";		z += ", Dmg: " + this.item[i].damage + ", Prt: "+ this.item[i].protection;		 		if (i==this.wpn_num) z += " **held**";		if (i==this.arm_num) z += " **worn**";	}	return z;}function creature_itemsListHTML () {	var z= "<p>Number of Items: " + this.item.length + "</p>";	z += "<table>";	z += "<tr><th>Item Name</th><th>Value</th><th>Damage</th><th>Protection</th><th>Equipped?</th></tr>";	for (i=0; i<this.item.length; i++) {		z += "<tr>";		//z += "<td>[" + i + "]</td>";		z += "<td><b>" + this.item[i].name;		if (this.item[i].magicbonus)			z += "+" + this.item[i].magicbonus;		z += "</b></td>";		z += "<td>" + this.item[i].getValue() + "gp</td>";		z += "<td>Dmg: <b>" + this.item[i].damage + "</b></td>";		z += "<td>Prt: <b>"+ this.item[i].protection + "</b></td>";		 		if (i==this.wpn_num) z += "<td>**held** <a href='javascript:player.disarm(1);'>Remove</a></td>";		if (i==this.arm_num) z += "<td>**worn** <a href='javascript:player.disarm(2);'>Remove</a></td>";		z += "</tr>";	}	z += "</table>";	return z;}function creature_itemRemove (n) {	//this.itemsView();	//var z="Removing item "+n+"\nw: "+this.wpn_num+ "  a: "+this.arm_num+"\n\nw: ";	DeleteElement(this.item, n);	if (this.wpn_num==n) this.wpn_num = -1;	else 	if (this.wpn_num>n) this.wpn_num--;	if (this.arm_num==n) this.arm_num = -1;	else	if (this.arm_num>n) this.arm_num--;	//alert(z + this.wpn_num+ "  a: "+this.arm_num);	//this.itemsView();}function creature_disarm (x) {	if (x==1 || x==3) this.wpn_num = -1;	// x=1 means remove wpn, 2 means remove armor	if (x==2 || x==3) this.arm_num = -1;	// 3 means remove both	Update_Screen();	Update_Inv_Display();}function creature_armbest () {	var z;	var best_dmg=-1, best_dmg_item = -1, best_prot=-1, best_prot_item = -1;	//z = this.itemsList() + "\n----------\n";	for (i=0; i<this.item.length; i++) {		item_dmg = (this.item[i].damage + this.item[i].magicbonus);		item_prot = (this.item[i].protection + this.item[i].magicbonus);		if (item_dmg >= best_dmg && this.item[i].isWeapon) {			best_dmg_item = i; 			best_dmg = item_dmg;		}		if (item_prot >= best_prot && this.item[i].isArmor) {			best_prot_item = i;			best_prot = item_prot;		}	}	this.wpn_num = best_dmg_item;	this.arm_num = best_prot_item;	//z += "Now... Armed with ["+ this.wpn_num + "] " + this.weaponName() + ", Dmg: " + this.getDamage();	//z += "\nand Wearing ["+ this.arm_num + "] " + this.armorName() + ", Prt: " + this.getProtection();	//alert(z);	Update_Screen();	Update_Inv_Display();}function creature_imgHTML (){	var c = "monster";	if (this.isPlayer) c = "player";	return "<img src=\"" + gCreatureImageDir + this.imageFile + "\" class=\"" + c + "\">";}function creature_obj (IsPlayer, n, j, file, P, M, S, xp, stuff, f, Gp, Hp, Mp) {	//var z = "Creating " + n + "...\nItems:";	this.name = n;	this.job = j;	this.imageFile = file + ".png";	this.physical = P;	this.mental = M;	this.social = S;	this.xp = xp;	this.item = new Array();	for (i=0; i<stuff.length; i++) {		//z += "\nstuff" + i + " = " + stuff[i] + " (" + items[stuff[i]].name + ")";		this.item[i] = items[stuff[i]];	}	//alert (z);	this.food = (f) ? f : 0;	this.hp = (Hp) ? Hp : P;	this.maxhp = this.hp;	this.mp = (Mp) ? Mp : M;	this.maxmp = this.mp;	this.gold = (Gp) ? Gp : S;	this.karma = 0;	this.wpn_num = -1;	this.arm_num = -1;	this.armbest = creature_armbest;	/* function to arm creature with its best wpn/armor */	this.disarm = creature_disarm;		this.itemRemove = creature_itemRemove;	this.itemsView = creature_itemsView;	this.itemsList = creature_itemsList;	this.itemsListHTML = creature_itemsListHTML;	this.view = creature_view;	this.viewHTML = creature_viewHTML;	this.heal = creature_heal;	this.isDead = creature_isDead;	this.damageBase = creature_damageBase;	this.getDamage = creature_getDamage;	this.getProtection = creature_getProtection;	this.weaponName = creature_weapon_name;	this.armorName = creature_armor_name;	this.isPlayer = (IsPlayer == 1) ? IsPlayer : 0;	this.imgHTML = creature_imgHTML;	this.hasMagic = false;	}var monster = new Array();   //Name		Title					P   M   S  xp  items		f gold	hp	mpmonster[0] = new creature_obj (0, "Beastman", "Savage Murderer", "beast",		50, 10, 1, 20, [6]);monster[1] = new creature_obj (0, "Imp", "fairy", "imp",				10, 65, 80, 10, [0]);monster[2] = new creature_obj (0, "Old Highwayman", "farmer", "highway",		30, 30, 70, 10, [0, 5], 	20);monster[3] = new creature_obj (0, "Kobold", "scavenger", "kobold",			30, 8, 15, 10, [4,0], 		4);monster[4] = new creature_obj (0, "Goblin", "raider", "goblin",				35, 18, 15, 10, [4,1], 		6);monster[5] = new creature_obj (0, "Ratman", "scavenger", "ratman",			40, 10, 15, 15, [18,0], 	8);monster[6] = new creature_obj (0, "Giant Worm", "dirty one", "worm",			90, 90, 5, 50, [22,20], 	0, 100, 180, 200);monster[7] = new creature_obj (0, "Dark Knight", "legionnaire of darkness", "dark",	75, 60, 5, 40, [16,12,4], 	0, 100, 200, 200);monster[8] = new creature_obj (0, "Cobra", "snake", "cobra",				25, 4, 30, 10, [8,21], 		2);monster[9] = new creature_obj (0, "Mercenary", "soldier of fortune", "merc",		45, 50, 50, 10, [19,11], 	15, 20);monster[10] = new creature_obj (0, "Worg", "savage wolf", "worg", 			60, 10, 1, 30, [20,9],		10, 0, 100);monster[11] = new creature_obj (0, "Ork", "warrior", "ork",				70, 60, 10, 20, [11,23,4],	10, 35, 120);monster[12] = new creature_obj (0, "Green Hydra", "warrior", "greenhydra",		70, 60, 10, 20, [22,20],	30, 160, 300, 300);monster[13] = new creature_obj (0, "Goblin Raider", "raider", "goblin2",		50, 18, 15, 10, [16,2], 	12, 0, 60);var monsterXP = new Array();for (i=0; i<monster.length; i++) {	monsterXP[i] = 0;}/***************************INITIALIZATION*********************************************************/var GoGame=0;var player;var Level=0;var Encounter="travel";var current_monster;var current_monster_number;var merchant_type;
