// SCENARIO SCRIPT

// This is the special script for your entire scenario. It contains
// special encounters and code accessable from anywhere in the scenario. it also
// contains the code that initializes important special things in the
// scenario (like shops and names and descriptions of special items).

// You can create your own states, but you should give all of them numbers greater than
// or equal to 10.

beginscenarioscript;

variables;
short i,species;
short target,user, healthgap, level,locx,locy,w,n,locx2,locy2;

body;

// This is the state that is called every time the scenario is loaded,
// even when a save file in the scenario is loaded. Some things that should go here:
//    Names and descriptions of special items.
//    Names and effects of custom special abilities.
beginstate LOAD_SCEN_STATE;
	init_special_item(1, "Prison key", "This key is large and black, and has 'Cells' written on it in small writing");
	init_special_item(2, "Intricate key", "A key which, despite being unusually complex, is good and solid.");
break;

// This is the state that is called only once at the very beginning of 
// the scenario. Some things that should go here:
//    The stuff in shops.
//    Creating horses and boats.
beginstate START_SCEN_STATE;


		



	// Initialize a few shops.
	// Shop 0 - Combat gear
	add_item_to_shop(0,26,20);
	add_item_to_shop(0,31,10);
	add_item_to_shop(0,131,2);
	
	add_item_to_shop(0,111,15);
	add_item_to_shop(0,16,10);
	add_item_to_shop(0,136,10);
	add_item_to_shop(0,137,10);
	add_item_to_shop(0,141,5);
	
	add_item_to_shop(0,46,20);
	add_item_to_shop(0,51,10);
	add_item_to_shop(0,55,5);
	add_item_to_shop(0,65,20);
	add_item_to_shop(0,66,10);
	
	add_item_to_shop(0,70,5);
	add_item_to_shop(0,85,500);
	add_item_to_shop(0,86,10);
	
	add_item_to_shop(0,90,3);
	add_item_to_shop(0,95,3);
	add_item_to_shop(0,100,20);
	add_item_to_shop(0,101,10);
	add_item_to_shop(0,105,10);
	add_item_to_shop(0,220,4);
	add_item_to_shop(0,221,3);
	
	add_item_to_shop(0,222,3);
	add_item_to_shop(0,223,2);
	
	
	// Shop 1 - Assorted stuff
	add_item_to_shop(1,157,3);
	add_item_to_shop(1,186,4);
	add_item_to_shop(1,195,5);
	add_item_to_shop(1,247,1);
	add_item_to_shop(1,180,2);
	add_item_to_shop(1,154,1);
	add_item_to_shop(1,81,2);
	add_item_to_shop(1,385,1);
	add_item_to_shop(1,372,2);
	
	// Shop 2 - tools
	add_item_to_shop(2,170,500);
	add_item_to_shop(2,171,500);
	add_item_to_shop(2,172,30);
	add_item_to_shop(2,174,500);
	add_item_to_shop(2,177,500);
	


	// Shop 5 - food
	add_item_to_shop(5,4,500);
	add_item_to_shop(5,6,500);
	add_item_to_shop(5,7,500);
break;

// This state is called every tick wherever the party is in the scenario.
// You can use the set_state
beginstate START_STATE;

break;

// Place your own states below. Give each a number at least 10.
beginstate 10; // Polymorph
target = who_is_custom_item_target();
if (get_species(target) == 12) { // Don't affect important monsters (species special)
	print_named_str(target, " resists.");
} else {
	level = get_level(target);
	level = get_ran(1,1,level + 1);
	locx = char_loc_x(target);
	locy = char_loc_y(target);
	if (level > get_ran(1,1,150)) { // Huge mutation
		print_named_str(target, "mutates horribly.");
		w = get_ran(1,1,6);
		if (w == 1) { n = 33; }
		if (w == 2) { n = 95; }
		if (w == 3) { n = 174; }
		if (w == 4) { n = 227; }
		if (w == 5) { n = 178; }
		if (w == 6) { n = 101; }
	} else {
		print_named_str(target, "mutates.");
		if (level == 1) {
			w = get_ran(1,1,5);
			if (w == 1) { n = 21; }
			if (w == 2) { n = 67; }
			if (w == 3) { n = 80; }
			if (w == 4) { n = 186; }
			if (w == 5) { n = 189; }
		}
		if (level == 2) {
			w = get_ran(1,1,9);
			if (w == 1) { n = 7; }
			if (w == 2) { n = 9; }
			if (w == 3) { n = 53; }
			if (w == 4) { n = 56; }
			if (w == 5) { n = 73; }
			if (w == 6) { n = 129; }
			if (w == 7) { n = 190; }
			if (w == 8) { n = 195; }
			if (w == 9) { n = 196; }
		}
		if (level == 3) {
			w = get_ran(1,1,6);
			if (w == 1) { n = 42; }
			if (w == 2) { n = 62; }
			if (w == 3) { n = 188; }
			if (w == 4) { n = 191; }
			if (w == 5) { n = 198; }
			if (w == 6) { n = 231; }
		}
 
		if (level == 4) {
			w = get_ran(1,1,6);
			if (w == 1) { n = 10; }
			if (w == 2) { n = 14; }
			if (w == 3) { n = 43; }
			if (w == 4) { n = 51; }
			if (w == 5) { n = 134; }
			if (w == 6) { n = 160; }
		}
		if (level == 5) {
			w = get_ran(1,1,7);
			if (w == 1) { n = 22; }
			if (w == 2) { n = 27; }
			if (w == 3) { n = 44; }
			if (w == 4) { n = 50; }
			if (w == 5) { n = 69; }
			if (w == 6) { n = 88; }
			if (w == 7) { n = 120; }
		}
		if (level > 5) {
			w = get_ran(1,1,8);
			if (w == 1) { n = 23; }
			if (w == 2) { n = 25; }
			if (w == 3) { n = 46; }
			if (w == 4) { n = 54; }
			if (w == 5) { n = 145; }
			if (w == 6) { n = 200; }
			if (w == 7) { n = 201; }
			if (w == 8) { n = 232; }
		}
	}
	put_boom_on_space(locx,locy, 6,0);
	erase_char(target);
	place_monster(locx,locy,n,0);
	run_animation_sound(60);
	
}
		
break;

beginstate 11; //Draining
target = who_is_custom_item_target();
user = who_used_custom_item();
healthgap = get_max_health(user) - get_health(user);
if (healthgap < 1) {
	print_str("You aren't hurt.");
} else {
	if (healthgap > get_health(target)) {
		healthgap = get_health(target) + 1; // Be happy.  You get a bonus hitpoint.
	}
	put_jagged_zap(char_loc_x(user),char_loc_y(user),char_loc_x(target),char_loc_y(target), 2);
	run_animation_sound(65);
	heal_char(user, healthgap);
	print_big_str("You steal ", healthgap, " hitpoints");
	damage_char(target, healthgap, 4);
}

break;

beginstate 12; // Translocation
target = who_is_custom_item_target();
user = who_used_custom_item();
put_jagged_zap(char_loc_x(user),char_loc_y(user),char_loc_x(target),char_loc_y(target), 3);
locx = char_loc_x(user);
locy = char_loc_y(user);
locx2 = char_loc_x(target);
locy2 = char_loc_y(target);
relocate_character(user, locx2, locy2);
relocate_character(target, locx, locy);
put_boom_on_char(user,2,0);
put_boom_on_char(target,2,0);
run_animation_sound(60);
break;

