// Town 49: The Second Level
begintownscript;

variables;

short choice,i,j,k;
string dlgstr;

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	add_range_to_group(8,16,1);
	char_give_item(36,478); // Sword of Slicing
	add_range_to_group(37,44,2);
	add_range_to_group(62,74,3);
	add_range_to_group(53,61,4);
	
	i = 6;
	while (i <= 84) {
		set_level(i,95);
		i = i + 1;
		}
	
	set_name(6,"Leksandross");
	
	change_blocked(41,41,1);
	change_blocked(41,42,1);
	change_blocked(41,43,1);
	change_blocked(42,41,1);
	change_blocked(42,42,1);
	change_blocked(42,43,1);
	change_blocked(43,41,1);
	change_blocked(43,42,1);
	change_blocked(43,43,1);
	
	change_blocked(1,2,1);
	change_blocked(1,3,1);
	change_blocked(1,4,1);
	change_blocked(2,2,1);
	change_blocked(2,3,1);
	change_blocked(2,4,1);
	change_blocked(3,2,1);
	change_blocked(3,3,1);
	change_blocked(3,4,1);
	
	if (get_flag(49,0) == 0) {
		force_instant_terrain_redraw();
		reset_dialog();
		add_dialog_str(0,"A battlefield!",0);
		add_dialog_str(1,"Those who fought in life continue to fight in death. The spirits of warriors engage in battle here, locked in struggle for all eternity.",0);
		add_dialog_str(2,"There appears to be a force that is hostile to you, based to the west, and one that is friendly, based to the north. It might not be a bad idea to speak to the leaders in the north.",0);
		set_flag(49,0,run_dialog(1));
		}
	
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
if (is_combat() == 0)
	end();
if (character_in_party(105) < 0)
	end();
	
	if (get_ran(1,1,3) == 1) {
		i = get_ran(1,1,7);
		if (i == 1) {
			heal_char(1000,get_ran(10,10,30));
			put_effect_on_char(0,4,1,2);
			put_effect_on_char(1,4,1,2);
			put_effect_on_char(2,4,1,2);
			put_effect_on_char(3,4,1,2);
			put_effect_on_char(4,4,1,2);
			print_str_color("Phaedra heals the party!",2);
			run_animation_sound(24);
			}
		j = get_ran(1,0,3);
		if (i == 2) {
			heal_char(j,get_ran(10,30,50));
			put_effect_on_char(j,4,1,2);
			clear_buffer();
			append_string("Phaedra heals ");
			append_char_name(j);
			append_string("!");
			get_buffer_text(dlgstr);
			print_str_color(dlgstr,2);
			run_animation_sound(24);
			}
		if (i >= 3) {
			clear_buffer();
			append_string("Phaedra blesses ");
			append_char_name(j);
			append_string("!");
			get_buffer_text(dlgstr);
			print_str_color(dlgstr,2);
			}
		if (i == 3) {
			set_char_status(j,5,20,0,1); // Magic Resistant
			put_effect_on_char(j,4,1,2);
			run_animation_sound(4);
			}
		if (i == 4) {
			set_char_status(j,4,5,0,1); // Invulnerable
			put_effect_on_char(j,8,1,2);
			run_animation_sound(25);
			}
		if (i == 5) {
			set_char_status(j,16,10,0,1); // Divinely Touched
			put_effect_on_char(j,7,1,2);
			run_animation_sound(60);
			}
		if (i == 6) {
			set_char_status(j,17,20,0,1); // Resistant
			put_effect_on_char(j,10,1,2);
			run_animation_sound(166);
			}
		if (i == 7) {
			set_char_status(j,22,20,0,1); // Regenerating
			put_effect_on_char(j,5,1,2);
			run_animation_sound(24);
			}
		}
break;

beginstate 10;
if (get_flag(49,1) == 0) {
	reset_dialog();
	add_dialog_str(0,"This book on the pedestal here is open to a page with a very elaborate system of runic writing. It is clearly magical.",0);
	add_dialog_str(1,"Reading strange spellbooks can be dangerous: they can carry curses or other terrible effects. However, they can also have great spells recorded within.",0);
	add_dialog_str(2,"What do you do?",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Attempt to read it.");
	if (run_dialog(1) == 2) {
		reset_dialog();
		// Requires Arcane Lore of 30.
		if (get_skill_total(42) >= 30) {
			add_dialog_str(0,"The book is written in a strange rune script, but fortunately, due to your knowledge of Arcane Lore, you can read it.",0);
			// Requires some skill in the spell already.
			if (get_flag(292,16) > 0) {
				set_flag(49,1,1);
				add_dialog_str(1,"It's a very advanced spellbook describing how to cast Cloudkill in the most efficient fashion possible. You read over it carefully.",0);
				set_flag(292,16,3); // flag for spell
				}
			else
				add_dialog_str(1,"It's a very advanced spellbook describing how to cast a complex spell, Cloudkill, in a very efficient manner. Unfortunately, you are completely unfamiliar with the spell, so it is too hard for you to understand.",0);
			run_dialog(1);
			}
		else
			message_dialog("The book is written in a strange rune script, and unfortunately, you can't read it. Perhaps if you knew more about Arcane Lore, you would be able to.","");
		}
	}
else
	message_dialog("You find the book on Cloudkill again, but you don't learn anything new from it.","");
break;

beginstate 11;
	reset_dialog_preset_options(3);
	if (run_dialog(1) == 2)
		move_to_new_town(48,10,53);
	else
		block_entry(1);
break;

beginstate 12;
	reset_dialog_preset_options(3);
	if (run_dialog(1) == 2)
		move_to_new_town(54,4,60);
	else
		block_entry(1);
break;

beginstate 13;
if (get_flag(49,2) == 0) {
	reset_dialog();
	add_dialog_str(0,"In this box, you find several papers written in a demonic-looking runic script, with a great deal of details, to judge by the amount of text. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Take them.");
	if (run_dialog(1) == 2) {
		change_spec_item(7,1);
		set_flag(49,2,1);
		}
	}
break;