// 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.

// SUMMONS
// 
// Baldev
// Class is 18
// Number is 6
// 
// Goblin
// Class is 17
// Number is 7
// 
// Shinigami
// Class is 16
// Number is 8
// 
// Achilles
// Class is 15
// Number is 9
// 
// Archangel
// Class is 14
// Number is 10
// MUST BE FRIENDLY

beginscenarioscript;

variables;
short natureskill;
short accuracy;
short charhp;
short demi,ok;
short target,user,height,heightraise,clocx,clocy;
short clocyN,clocxE,clocxW,clocyS;
short angel,summoner,what_num,bmessage;

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_quest(0,"See Leader","You have been summoned by Leader, lord of North Canopy.  He is waiting for you in the Meeting Hall.");
	init_quest(1,"Steal Symbols","You are to go west to the Bugbear village, and steal nine religious symbols to demoralize them.");
	init_quest(2,"Catacombs","Your mission is to follow General Alderauge into the Catacombs.  What the mission entails beyond that is a mystery to you.");
	init_quest(2,"Catacombs","Your mission is to follow General Alderauge into the Catacombs.  What the mission entails beyond that is a mystery to you.");
	init_quest(3,"Visit Lealte","Your mission is to visit Liason Lealte in Fortress Grenze, and return to Leader if the authorities in the Fortress prevent you.");
	init_quest(4,"Kill Trahison","Your quest has taken a not-entirely-unexpected turn, in that Trahison actually has betrayed Leader.  You are to kill him.");

	init_special_item(1,"Bugbear Emblem","This golden sun emblem hung in the chambers of the Bugbears is a sign of their sun-worshipping religion.  Too bad the sun is nothing but a myth.");
	init_special_item(2,"Obispopiedra","This stone, made in the shape of the emblems of the Bugbears, glows slightly as you carry it.  It was given to you by Emery for a unknown purpose.");
	init_special_item(20,"Storehouse Key 1","This key will open one of the valuable storehouses of goods in the lower level of Schwertschrein.");
	init_special_item(21,"Storehouse Key 2","This key will open one of the valuable storehouses of goods in the lower level of Schwertschrein.");
	init_special_item(22,"Storehouse Key 3","This key will open one of the valuable storehouses of goods in the lower level of Schwertschrein.");
	init_special_item(23,"Golden Key","This key was held by a Bugbear Mage.  It is ornate, with gems protruding from the gripping surface.");
	init_special_item(24,"Iron Key","This key was given to you by General Alderauge.  It opens the western gate to the amphitheater in Machtschrein.");
	init_special_item(25,"Fusei's Key","This key was on the corpse of Lieutenant Fusei.");
	init_special_item(26,"Steel Key","This key was found on the fifth floor after a failed battle with General Trahison.");
	init_special_item(27,"Silver Key","This key was taken from the body of General Trahison, traitor to the Empire.");
	init_special_item(40,"Explosives","Dangerous explosives, often used in the excavation of tunnels, but capable of boring holes in doors, walls, et cetera.");
	init_special_item(41,"Mithril Ore","A powerful, magically imbued metal, often used to make the most powerful yet easily maneuverable armor and weaponry.  Quite valuable.");
		// There are 
		// Machtschrein - 1
		// Bugbear Village - 3
		// Bugbear Caves - 2
		// Schwertschrein lvl1 - 1
		// Schwertschrein lvl2 - 1
		// Goblin Glade - 1
		// Tiger Caves - 1
		// Kedalvasser - 1
		// TOTAL - 11

	init_special_item(42,"Mithril","A purified form of Mithril, having gone through the forging process.");

	set_creature_type_level(4,99);

	init_special_abil(0,"Cutscene Speed",52);

	demi = 0;
	while(demi <= 3){
		if(char_ok(demi) == TRUE){
			if(get_custom_abil_uses(demi,0) == 0){
				change_custom_abil_uses(demi,0,1);
			}
		}
		demi = (demi + 1);
	}

	if(get_flag(75,0) == 0)
		set_flag(75,0,14);

	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 Random Artifacts

	if(get_flag(5,9) == 0){
		summoner = 5;
		while(summoner <= 24){
			set_flag(summoner,9,get_ran(1,24,255));

			summoner = (summoner + 1);
		}
	}

	// Initialize a few shops.
	
	// Shop 0 - armor
	add_item_to_shop(0,27,4);
	add_item_to_shop(0,28,3);
	add_item_to_shop(0,32,2);
	add_item_to_shop(0,33,1);
	add_item_to_shop(0,37,2);
	add_item_to_shop(0,38,1);
	add_item_to_shop(0,123,3);
	add_item_to_shop(0,124,2);
	add_item_to_shop(0,128,3);
	add_item_to_shop(0,129,2);
	add_item_to_shop(0,133,2);
	add_item_to_shop(0,134,1);
	add_item_to_shop(0,111,15);
	add_item_to_shop(0,112,4);
	add_item_to_shop(0,16,10);
	add_item_to_shop(0,138,4);
	add_item_to_shop(0,139,3);
	add_item_to_shop(0,144,3);
	add_item_to_shop(0,143,2);
	add_item_to_shop(0,465,16);
	add_item_to_shop(0,466,8);
	add_item_to_shop(0,467,4);
	add_item_to_shop(0,468,2);
	add_item_to_shop(0,469,1);
	
	// Shop 1 - weapons
	add_item_to_shop(1,47,5);
	add_item_to_shop(1,48,2);
	add_item_to_shop(1,52,2);
	add_item_to_shop(1,53,1);
	add_item_to_shop(1,57,2);
	add_item_to_shop(1,58,1);
	add_item_to_shop(1,67,2);
	add_item_to_shop(1,68,1);
	add_item_to_shop(1,72,2);
	add_item_to_shop(1,73,1);
	
	// 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 3 - missiles
	add_item_to_shop(3,92,5);
	add_item_to_shop(3,93,1);
	add_item_to_shop(3,97,5);
	add_item_to_shop(3,98,1);
	add_item_to_shop(3,102,20);
	add_item_to_shop(3,103,10);
	add_item_to_shop(3,107,15);
	add_item_to_shop(3,108,8);

	// Shop 4 - potions
	add_item_to_shop(4,220,40);
	add_item_to_shop(4,221,30);
	add_item_to_shop(4,222,30);
	add_item_to_shop(4,227,25);
	add_item_to_shop(4,223,20);
	add_item_to_shop(4,225,15);
	add_item_to_shop(4,226,10);
	add_item_to_shop(4,228,20);
	add_item_to_shop(4,229,15);
	add_item_to_shop(4,230,15);
	add_item_to_shop(4,235,13);
	add_item_to_shop(4,231,10);
	add_item_to_shop(4,232,8);
	add_item_to_shop(4,234,5);

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

	// Shop 7 - magic
	add_item_to_shop(7,2000,6);
	add_item_to_shop(7,2001,6);
	add_item_to_shop(7,2002,6);
	add_item_to_shop(7,2003,6);
	add_item_to_shop(7,2004,5);
	add_item_to_shop(7,2005,5);
	add_item_to_shop(7,2006,5);
	add_item_to_shop(7,2007,5);
	add_item_to_shop(7,2008,5);
	add_item_to_shop(7,2009,5);
	add_item_to_shop(7,2010,4);
	add_item_to_shop(7,2011,4);
	add_item_to_shop(7,2012,4);
	add_item_to_shop(7,2013,4);
	add_item_to_shop(7,2014,4);
	add_item_to_shop(7,2015,4);
	add_item_to_shop(7,2016,3);
	add_item_to_shop(7,2017,3);
	add_item_to_shop(7,2018,3);
	add_item_to_shop(7,2019,3);

	// Shop 8 - artifacts
	add_item_to_shop(8,get_flag(5,9),1);
	add_item_to_shop(8,get_flag(6,9),1);
	add_item_to_shop(8,get_flag(7,9),1);
	add_item_to_shop(8,get_flag(8,9),1);
	add_item_to_shop(8,get_flag(9,9),1);
	add_item_to_shop(8,get_flag(10,9),1);
	add_item_to_shop(8,get_flag(11,9),1);
	add_item_to_shop(8,get_flag(12,9),1);
	add_item_to_shop(8,get_flag(13,9),1);
	add_item_to_shop(8,get_flag(14,9),1);
	add_item_to_shop(8,get_flag(15,9),1);
	add_item_to_shop(8,get_flag(16,9),1);
	add_item_to_shop(8,get_flag(17,9),1);
	add_item_to_shop(8,get_flag(18,9),1);
	add_item_to_shop(8,get_flag(19,9),1);
	add_item_to_shop(8,get_flag(20,9),1);
	add_item_to_shop(8,get_flag(21,9),1);
	add_item_to_shop(8,get_flag(22,9),1);
	add_item_to_shop(8,get_flag(23,9),1);
	add_item_to_shop(8,get_flag(24,9),1);

	// Shop 9 - liquor
	add_item_to_shop(9,414,500);
	add_item_to_shop(9,415,500);
	add_item_to_shop(9,418,500);

	// Shop 10 - priest spells
	add_item_to_shop(10,3000,7);
	add_item_to_shop(10,3001,7);
	add_item_to_shop(10,3002,6);
	add_item_to_shop(10,3003,6);
	add_item_to_shop(10,3004,6);
	add_item_to_shop(10,3005,6);
	add_item_to_shop(10,3006,6);
	add_item_to_shop(10,3007,5);
	add_item_to_shop(10,3008,5);
	add_item_to_shop(10,3009,5);
	add_item_to_shop(10,3010,5);
	add_item_to_shop(10,3011,5);
	add_item_to_shop(10,3012,4);
	add_item_to_shop(10,3013,4);
	add_item_to_shop(10,3014,4);
	add_item_to_shop(10,3016,3);
	add_item_to_shop(10,3017,3);
	add_item_to_shop(10,3018,3);
	add_item_to_shop(10,3019,3);

break;

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

// ANGEL Check

if(get_flag(77,7) == 1){
	summoner = get_flag(76,7);
	force_view_center(char_loc_x(10),char_loc_y(10));
	put_boom_on_space(char_loc_x(10),char_loc_y(10),3,0);
	put_effect_on_space(char_loc_x(10),char_loc_y(10),2,4,0);
	relocate_character(10,1,1);
	erase_char(10);
	force_instant_terrain_redraw();
	run_animation_sound(10);
	print_str_color("Angel disappears.",2);
	set_flag(77,7,0);
}
if(get_flag(77,7) >= 2){
summoner = get_flag(76,7);
set_char_status(summoner,11,1,1,0);
set_char_status(summoner,4,1,1,0);
	angel = get_flag(77,7);
	angel = angel - 1;
	set_flag(77,7,angel);
}

// BALDEV Check

if(get_flag(62,2) == 2 && character_in_party(275) == -1){
	message_dialog("Baldev has perished.","");
	set_flag(62,2,1);
}

// Cloud of Blades Check

	demi = 0;
	while(demi <= 3){
		if(char_ok(demi) == TRUE){
			while(get_spell_level(demi,1,15) >= 1){
				change_spell_level(demi,1,15,-1);
				inc_flag(30,(demi + 5),1);
			}
		}
		demi = (demi + 1);
	}

// Bizarre, invuln-prevention cessation...

	summoner = 0;
	while(summoner <= 3){
		demi = (get_char_status(summoner,4));
		if(demi < 0){
			demi = (demi * -1);
			set_char_status(summoner,4,demi,1,0);
		}
		summoner = (summoner + 1);
	}

break;

// Place your own states below. Give each a number at least 10.

// Naturshand

beginstate 10;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

	if(is_town() > 0){
		print_str_color("Must be used in combat.",1);
		end();
	}

target = who_is_custom_item_target();
user = who_used_custom_item();

	if(creature_type(target) == 226){
		print_str_color("General Shroud is immune!",1);
		end();
	}

		if(get_energy(user) >= 25){
	print_str_color("Naturshand",4);
	change_char_energy(user,-25);
	natureskill = (get_stat(user,24) + get_stat(user,16) + get_stat(user,2));
	while(natureskill >= 1 && char_ok(target) == TRUE){
natureskill = natureskill - 1;
put_straight_zap(char_loc_x(user),char_loc_y(user),char_loc_x(target),char_loc_y(target),3);
put_boom_on_char(target,7,0);
damage_char(target,10,4);
set_char_status(target,0,5,0,0);
set_char_status(target,12,5,0,0);
set_character_pose(user,1);
force_instant_terrain_redraw();
run_animation_sound(169);
set_character_pose(user,2);
force_instant_terrain_redraw();
if(get_attitude(target) < 10){
	set_attitude(target,10);
	change_crime_level(100);
}
	}
	deduct_ap(5);
		}
		else{
	print_str_color("Not enough spell energy.",4);
		}

break;

// Rasereiangriff

beginstate 11;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

	if(is_town() > 0){
		print_str_color("Must be used in combat.",1);
		end();
	}

target = who_is_custom_item_target();
user = who_used_custom_item();

	if(creature_type(target) == 226){
		print_str_color("General Shroud is immune!",1);
		end();
	}

	if(get_energy(user) >= 10){
if(char_dist_to_loc(user,char_loc_x(target),char_loc_y(target)) <= 3){
change_char_energy(user,-10);
print_str_color("Rasereiangriff",1);
charhp = (get_max_health(user) - get_health(user));
demi = (charhp / 2);
play_sound(48);
play_sound(19);
put_straight_zap(char_loc_x(user),char_loc_y(user),char_loc_x(target),char_loc_y(target),0);
put_boom_on_char(target,6,0);
set_character_pose(user,1);
force_instant_terrain_redraw();
damage_char(target,demi,4);
run_animation_sound(69);
set_character_pose(user,2);
force_instant_terrain_redraw();
deduct_ap(5);
if(get_attitude(target) < 10){
	set_attitude(target,10);
	change_crime_level(100);
}
}
else{
print_str_color("Too far away!",1);
}
	}
	else{
		print_str_color("Not enough spell energy.",1);
	}
break;

// Lichtschild

beginstate 12;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

user = who_used_custom_item();

	if(get_energy(user) >= 30){

		target = 0;

		play_sound(28);

		while(target <= 120){
if(char_ok(target) == TRUE){
	if(party_can_see_loc(char_loc_x(target),char_loc_y(target)) == 1 && get_attitude(target) <= 3){
		set_char_status(target,2,20,0,0);
		set_char_status(target,5,5,1,0);
		set_char_status(target,14,25,1,0);
		set_char_status(target,15,25,1,0);
		set_char_status(target,17,5,1,0);
		set_char_status(target,22,40,1,0);
		set_char_status(target,4,1,1,0);
		put_effect_on_char(target,8,2,2);
		put_effect_on_char(target,10,2,2);
	}
}

target = target + 1;

}

		run_animation_sound(4);
		change_char_energy(user,-30);
		deduct_ap(5);
	}
	else{
		print_str_color("Not enough spell energy.",1);
	}

break;

// Blattstrahl

beginstate 13;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

	if(is_town() > 0){
		print_str_color("Must be used in combat.",1);
		end();
	}

target = who_is_custom_item_target();
user = who_used_custom_item();

	if(creature_type(target) == 226){
		print_str_color("General Shroud is immune!",1);
		end();
	}

	if(get_energy(user) >= 5){

natureskill = (get_stat(user,1) + get_stat(user,4) + get_stat(user,5) + get_stat(user,10) + get_stat(user,18) + get_stat(user,19) + get_stat(user,22) + get_stat(user,23) + get_stat(user,28));
accuracy = (natureskill * 5);
charhp = (get_stat(user,0) + get_stat(user,4) + get_stat(user,5) + get_stat(user,10) + get_stat(user,19) + get_stat(user,21) + get_stat(user,21) + get_stat(user,28) + get_stat(user,28) + get_stat(user,28));
demi = (charhp * 8);
put_straight_zap(char_loc_x(user),char_loc_y(user),char_loc_x(target),char_loc_y(target),3);
run_animation_sound(69);
		if(get_ran(1,1,100) <= accuracy){ 
			damage_char(target,demi,0);
		}
		else{
			print_str_color("Attack misses!",1);
			play_sound(2);
		}
change_char_energy(user,-5);
deduct_ap(5);
if(get_attitude(target) < 10){
	set_attitude(target,10);
	change_crime_level(100);
}
	}
	else{
		print_str_color("Not enough spell energy.",1);
	}

break;

// Flammenentwurf

beginstate 14;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

target = who_is_custom_item_target();
user = who_used_custom_item();

if(char_dist_to_loc(user,char_loc_x(target),char_loc_y(target)) <= 1){

charhp = (get_stat(user,0) + get_stat(user,4) + get_stat(user,5) + get_stat(user,10) + get_stat(user,19) + get_stat(user,21) + get_stat(user,21) + get_stat(user,28) + get_stat(user,28) + get_stat(user,28));
demi = (charhp * 10);
natureskill = (charhp * 4);

print_str_color("Flammenentwurf",1);
play_sound(103);
put_boom_on_char(user,0,0);
run_animation_sound(5);
damage_char(user,natureskill,4);
	if(char_ok(user) == TRUE){
play_sound(48);
pause(5);
put_boom_on_char(target,1,0);
set_character_pose(user,1);
force_instant_terrain_redraw();
damage_char(target,demi,1);
run_animation_sound(152);
set_character_pose(user,2);
force_instant_terrain_redraw();
deduct_ap(4);
if(get_attitude(target) < 10){
	set_attitude(target,10);
	change_crime_level(100);
	}
}
}
else{
print_str_color("Too far away!",1);
}

break;

// Jutsuhi

beginstate 15;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

target = who_is_custom_item_target();
user = who_used_custom_item();

	if(get_energy(user) >= 20){
charhp = get_energy(target);
change_char_energy(target,-100);
natureskill = get_energy(target);
demi = (charhp - natureskill);
set_character_pose(user,1);
put_straight_zap(char_loc_x(user),char_loc_y(user),char_loc_x(target),char_loc_y(target),6);
put_boom_on_char(target,4,0);
put_boom_on_char(target,6,0);
force_instant_terrain_redraw();
run_animation_sound(112);
pause(5);
damage_char(target,demi,4);
set_character_pose(user,2);
force_instant_terrain_redraw();
change_char_energy(user,-20);
deduct_ap(5);
if(get_attitude(target) < 10){
	set_attitude(target,10);
	change_crime_level(100);
}
	}
	else{
		print_str_color("Not enough spell energy.",1);
	}

break;

// Tetra-Disaster

beginstate 16;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

user = who_used_custom_item();

	if(is_town() > 0){
		print_str_color("Must be used in combat.",1);
		end();
	}

demi = 0;
ok = 0;

while(demi < 120 && ok == 0){
	if(char_ok(demi) == TRUE){
		if(party_can_see_loc(char_loc_x(demi),char_loc_y(demi)) == TRUE && get_attitude(demi) >= 10){
			ok = 1;
		}
	}
	demi = demi + 1;
}
if(ok == 0){
	print_str_color("No enemies in range!",1);
	end();
}

	if(get_energy(user) >= 40){

	// Fire Attack

set_character_pose(user,2);
text_bubble_on_char(user,"Feuersturm!");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(user,"");
force_instant_terrain_redraw();

demi = 0;
while(demi < 120){
	if(char_ok(demi) == TRUE){
		if(party_can_see_loc(char_loc_x(demi),char_loc_y(demi)) == TRUE && get_attitude(demi) >= 10){

natureskill = (char_dist_to_loc(demi,char_loc_x(user),char_loc_y(user)));
accuracy = (natureskill * 15);
charhp = (90 - accuracy);
if(charhp > 0){
	put_boom_on_char(demi,1,0);

}
	}
		}
demi = (demi + 1);
}

set_character_pose(user,1);
force_instant_terrain_redraw();
run_animation_sound(51);
pause(5);

demi = 0;
while(demi < 120){
	if(char_ok(demi) == TRUE){
		if(party_can_see_loc(char_loc_x(demi),char_loc_y(demi)) == TRUE && get_attitude(demi) >= 10){
natureskill = (char_dist_to_loc(demi,char_loc_x(user),char_loc_y(user)));
accuracy = (natureskill * 15);
charhp = (90 - accuracy);
if(charhp > 0){
	damage_char(demi,charhp,1);

}
	}
		}
demi = (demi + 1);
}

	// Ice Attack

set_character_pose(user,2);
text_bubble_on_char(user,"Hagelsturm!");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(user,"");
force_instant_terrain_redraw();

demi = 0;
while(demi < 120){
	if(char_ok(demi) == TRUE){
		if(party_can_see_loc(char_loc_x(demi),char_loc_y(demi)) == TRUE && get_attitude(demi) >= 10){

natureskill = (char_dist_to_loc(demi,char_loc_x(user),char_loc_y(user)));
accuracy = (natureskill * 15);
charhp = (90 - accuracy);
if(charhp > 0){
	put_boom_on_char(demi,5,0);

}
	}
		}
demi = (demi + 1);
}

set_character_pose(user,1);
force_instant_terrain_redraw();
run_animation_sound(52);
pause(5);

demi = 0;
while(demi < 120){
	if(char_ok(demi) == TRUE){
		if(party_can_see_loc(char_loc_x(demi),char_loc_y(demi)) == TRUE && get_attitude(demi) >= 10){
natureskill = (char_dist_to_loc(demi,char_loc_x(user),char_loc_y(user)));
accuracy = (natureskill * 15);
charhp = (90 - accuracy);
if(charhp > 0){
	damage_char(demi,charhp,5);

}
	}
		}
demi = (demi + 1);
}

	// Magic Attack

set_character_pose(user,2);
text_bubble_on_char(user,"Blitzsturm!");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(user,"");
force_instant_terrain_redraw();

demi = 0;
while(demi < 120){
	if(char_ok(demi) == TRUE){
		if(party_can_see_loc(char_loc_x(demi),char_loc_y(demi)) == TRUE && get_attitude(demi) >= 10){

natureskill = (char_dist_to_loc(demi,char_loc_x(user),char_loc_y(user)));
accuracy = (natureskill * 15);
charhp = (90 - accuracy);
if(charhp > 0){
	put_boom_on_char(demi,4,0);

}
	}
		}
demi = (demi + 1);
}

set_character_pose(user,1);
force_instant_terrain_redraw();
run_animation_sound(54);
pause(5);

demi = 0;
while(demi < 120){
	if(char_ok(demi) == TRUE){
		if(party_can_see_loc(char_loc_x(demi),char_loc_y(demi)) == TRUE && get_attitude(demi) >= 10){
natureskill = (char_dist_to_loc(demi,char_loc_x(user),char_loc_y(user)));
accuracy = (natureskill * 15);
charhp = (90 - accuracy);
if(charhp > 0){
	damage_char(demi,charhp,3);

}
	}
		}
demi = (demi + 1);
}

	// Abyss Attack

set_character_pose(user,2);
text_bubble_on_char(user,"Abgrundangriff!");
force_instant_terrain_redraw();
pause(10);

text_bubble_on_char(user,"");
force_instant_terrain_redraw();

demi = 0;
while(demi < 120){
	if(char_ok(demi) == TRUE){
		if(party_can_see_loc(char_loc_x(demi),char_loc_y(demi)) == TRUE && get_attitude(demi) >= 10){

natureskill = (char_dist_to_loc(demi,char_loc_x(user),char_loc_y(user)));
accuracy = (natureskill * 15);
charhp = (90 - accuracy);
if(charhp > 0){
	put_boom_on_char(demi,6,0);

}
	}
		}
demi = (demi + 1);
}

set_character_pose(user,1);
force_instant_terrain_redraw();
run_animation_sound(53);
pause(5);

demi = 0;
while(demi < 120){
	if(char_ok(demi) == TRUE){
		if(party_can_see_loc(char_loc_x(demi),char_loc_y(demi)) == TRUE && get_attitude(demi) >= 10){
natureskill = (char_dist_to_loc(demi,char_loc_x(user),char_loc_y(user)));
accuracy = (natureskill * 15);
charhp = (90 - accuracy);
if(charhp > 0){
	damage_char(demi,charhp,4);

}
	}
		}
demi = (demi + 1);
}
set_character_pose(user,2);
force_instant_terrain_redraw();
change_char_energy(user,-40);
demi = 0;
deduct_ap(5);
	}
	else{
		print_str_color("Not enough spell energy.",1);
	}

break;

// Shinibiimu

beginstate 17;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

target = who_is_custom_item_target();
user = who_used_custom_item();

	if(get_energy(user) >= 30){
		text_bubble_on_char(user,"Anata ga Shinde iru!");
		force_instant_terrain_redraw();
		pause(15);

		text_bubble_on_char(user,"");
		force_instant_terrain_redraw();
		pause(5);

set_character_pose(user,1);
put_straight_zap(char_loc_x(user),char_loc_y(user),char_loc_x(target),char_loc_y(target),2);
force_instant_terrain_redraw();
run_animation_sound(95);
pause(5);
		if(get_level(target) < 30 && creature_type(target) != 243){
			while(char_ok(target) == TRUE){
				damage_char(target,666,4);
			}
		}
		else{
			damage_char(target,66,4);
			damage_char(target,66,4);
		}
set_character_pose(user,2);
force_instant_terrain_redraw();
deduct_ap(5);
if(get_attitude(target) < 10){
	set_attitude(target,10);
	change_crime_level(100);
}

		change_char_energy(user,-30);
	}
break;

// BEGIN SUMMON SPECIAL SPELLS

// Baldev
// Class is 18
// Number is 6

beginstate 25;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

target = who_is_custom_item_target();
user = who_used_custom_item();
clocx = char_loc_x(user);
clocy = char_loc_y(user);
clocyN = clocy + 1;
clocxE = clocx + 1;
clocxW = clocx - 1;
clocyS = clocy - 1;
height = get_height(clocx,clocy);
heightraise = height + 1;

	if(get_flag(62,2) == 4){
		print_str_color("Baldev is dead!",1);
		end();
	}
	if(current_town() == 7 || get_flag(1,9) > 0){
		print_str_color("Doesn't work!",1);
		end();
	}

	if(get_flag(99,3) >= 1){
		print_str_color("Summons are disabled during",1);
		print_str_color("outdoor combats.",1);
		end();
	}

	if(get_energy(user) >= 30){
change_char_energy(user,-30);
force_view_center(clocx,clocy);
text_bubble_on_char(user,"Baldev!");
force_instant_terrain_redraw();
pause(5);

set_total_visibility(1);
text_bubble_on_char(user,"");
force_view_center(clocx,clocy);
set_height(clocx,clocy,heightraise);
relocate_character(user,1,1);
activate_hidden_group(18);
relocate_character(6,clocx,clocy);
put_boom_on_space(clocx,clocyN,0,0);
put_boom_on_space(clocxE,clocy,0,0);
put_boom_on_space(clocxW,clocy,0,0);
put_boom_on_space(clocx,clocyS,0,0);
force_instant_terrain_redraw();
run_animation_sound(10);
pause(5);

text_bubble_on_char(6,"Flammenwerfer!");
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(6,"");
put_straight_zap(clocx,clocy,char_loc_x(target),char_loc_y(target),0);
put_boom_on_char(target,1,0);
set_character_pose(6,1);
force_instant_terrain_redraw();
run_animation_sound(152);
damage_char(target,700,1);
pause(5);

set_character_pose(6,2);
relocate_character(6,1,1);
erase_char(6);
relocate_character(user,clocx,clocy);
put_boom_on_space(clocx,clocy,2,0);
set_height(clocx,clocy,height);
set_total_visibility(0);
force_instant_terrain_redraw();
run_animation_sound(10);
pause(5);
deduct_ap(5);
if(get_attitude(target) < 10){
	set_attitude(target,10);
	change_crime_level(100);
}

	}
	else{
		print_str_color("Not enough spell energy.",1);
	}
break;

// Goblin
// Class is 17
// Number is 7

beginstate 26;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

target = who_is_custom_item_target();
user = who_used_custom_item();
clocx = char_loc_x(user);
clocy = char_loc_y(user);
clocyN = clocy + 1;
clocxE = clocx + 1;
clocxW = clocx - 1;
clocyS = clocy - 1;
height = get_height(clocx,clocy);
heightraise = height + get_ran(1,0,3);

	if(get_flag(99,3) >= 1){
		print_str_color("Summons are disabled during",1);
		print_str_color("outdoor combats.",1);
		end();
	}

	if(get_energy(user) >= 17){
change_char_energy(user,-17);
force_view_center(clocx,clocy);
text_bubble_on_char(user,"Goblin!");
force_instant_terrain_redraw();
pause(5);

set_total_visibility(1);
text_bubble_on_char(user,"");
force_view_center(clocx,clocy);
set_height(clocx,clocy,heightraise);
relocate_character(user,1,1);
activate_hidden_group(17);
relocate_character(7,clocx,clocy);
put_boom_on_space(clocx,clocyN,get_ran(1,0,7),0);
put_boom_on_space(clocxE,clocy,get_ran(1,0,7),0);
put_boom_on_space(clocxW,clocy,get_ran(1,0,7),0);
put_boom_on_space(clocx,clocyS,get_ran(1,0,7),0);
force_instant_terrain_redraw();
run_animation_sound(10);
pause(5);

text_bubble_on_char(7,"Goblin Punch!");
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(7,"");
put_straight_zap(clocx,clocy,char_loc_x(target),char_loc_y(target),get_ran(1,0,6));
put_boom_on_char(target,get_ran(1,0,7),0);
set_character_pose(7,1);
force_instant_terrain_redraw();
run_animation_sound(152);
damage_char(target,get_ran(1,1,200),get_ran(1,0,6));
pause(5);

set_character_pose(7,2);
relocate_character(7,1,1);
erase_char(7);
relocate_character(user,clocx,clocy);
put_boom_on_space(clocx,clocy,2,0);
set_height(clocx,clocy,height);
set_total_visibility(0);
force_instant_terrain_redraw();
run_animation_sound(10);
pause(5);
deduct_ap(5);
if(get_attitude(target) < 10){
	set_attitude(target,10);
	change_crime_level(100);
}

	}
	else{
		print_str_color("Not enough spell energy.",1);
	}
break;

// Shinigami
// Class is 16
// Number is 8

beginstate 27;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

target = who_is_custom_item_target();
user = who_used_custom_item();
clocx = char_loc_x(user);
clocy = char_loc_y(user);
clocyN = clocy + 1;
clocxE = clocx + 1;
clocxW = clocx - 1;
clocyS = clocy - 1;
height = get_height(clocx,clocy);
heightraise = height + 2;
charhp = get_health(target);
natureskill = (charhp * 3);
demi = (natureskill / 2);

	if(get_flag(99,3) >= 1){
		print_str_color("Summons are disabled during",1);
		print_str_color("outdoor combats.",1);
		end();
	}

	if(get_energy(user) >= 25){
change_char_energy(user,-25);
force_view_center(clocx,clocy);
text_bubble_on_char(user,"Shinigami!");
force_instant_terrain_redraw();
pause(5);

set_total_visibility(1);
text_bubble_on_char(user,"");
force_view_center(clocx,clocy);
set_height(clocx,clocy,heightraise);
relocate_character(user,1,1);
activate_hidden_group(16);
relocate_character(8,clocx,clocy);
put_boom_on_space(clocx,clocyN,6,0);
put_boom_on_space(clocxE,clocy,6,0);
put_boom_on_space(clocxW,clocy,6,0);
put_boom_on_space(clocx,clocyS,6,0);
force_instant_terrain_redraw();
run_animation_sound(10);
pause(5);

text_bubble_on_char(8,"Todstrahl");
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(8,"");
put_jagged_zap(clocx,clocy,char_loc_x(target),char_loc_y(target),2);
put_boom_on_char(target,7,0);
set_character_pose(8,1);
force_instant_terrain_redraw();
run_animation_sound(152);
damage_char(target,demi,1);
pause(5);

set_character_pose(8,2);
relocate_character(8,1,1);
erase_char(8);
relocate_character(user,clocx,clocy);
put_boom_on_space(clocx,clocy,2,0);
set_height(clocx,clocy,height);
set_total_visibility(0);
force_instant_terrain_redraw();
run_animation_sound(10);
pause(5);
deduct_ap(5);
if(get_attitude(target) < 10){
	set_attitude(target,10);
	change_crime_level(100);
}

	}
	else{
		print_str_color("Not enough spell energy.",1);
	}
break;

// Achilles
// Class is 15
// Number is 9

beginstate 28;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

	if(is_town() > 0){
		print_str_color("Cannot be used outdoors.",1);
		end();
	}

	if(get_flag(99,3) >= 1){
		print_str_color("Summons are disabled during",1);
		print_str_color("outdoor combats.",1);
		end();
	}

target = who_is_custom_item_target();
user = who_used_custom_item();
clocx = char_loc_x(user);
clocy = char_loc_y(user);
clocyN = clocy + 1;
clocxE = clocx + 1;
clocxW = clocx - 1;
clocyS = clocy - 1;
height = get_height(clocx,clocy);
natureskill = get_height(char_loc_x(target),char_loc_y(target));
heightraise = height + 3;

	if(get_energy(user) >= 50){
if(char_dist_to_loc(user,char_loc_x(target),char_loc_y(target)) <= 1){
change_char_energy(user,-50);
force_view_center(clocx,clocy);
text_bubble_on_char(user,"Achilles!");
force_instant_terrain_redraw();
pause(5);

set_total_visibility(1);
text_bubble_on_char(user,"");
force_view_center(clocx,clocy);
set_height(clocx,clocy,heightraise);
set_height(char_loc_x(target),char_loc_y(target),heightraise);
relocate_character(user,1,1);
activate_hidden_group(15);
relocate_character(9,clocx,clocy);
set_character_pose(9,2);
put_boom_on_space(clocx,clocy,2,0);
force_instant_terrain_redraw();
run_animation_sound(10);
pause(5);

text_bubble_on_char(9,"Stahlschweif!");
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(9,"");
force_instant_terrain_redraw();
play_sound(48);
pause(3);

demi = 0;

while(demi <= 2 && char_ok(target) == TRUE){
play_sound(19);
set_character_pose(9,2);
force_instant_terrain_redraw();
pause(3);

set_character_pose(9,1);
force_instant_terrain_redraw();
play_sound(70);
damage_char(target,get_ran(25,3,6),0);
pause(3);

demi = demi + 1;

}

set_character_pose(9,2);
force_instant_terrain_redraw();
pause(3);

relocate_character(9,1,1);
erase_char(9);
relocate_character(user,clocx,clocy);
put_boom_on_space(clocx,clocy,2,0);
set_height(clocx,clocy,height);
set_height(char_loc_x(target),char_loc_y(target),natureskill);
set_total_visibility(0);
force_instant_terrain_redraw();
run_animation_sound(10);
pause(3);

set_char_status(1000,1,250,1,0);
set_char_status(1000,2,250,1,0);
set_char_status(1000,3,250,1,0);
set_char_status(1000,5,250,1,0);
set_char_status(1000,15,250,1,0);
change_char_health(1000,70);
deduct_ap(5);
if(get_attitude(target) < 10){
	set_attitude(target,10);
	change_crime_level(100);
}

}
else{
print_str_color("Out of range.",1);
}
	}
	else{
		print_str_color("Not enough spell energy.",1);
	}
break;

// Archangel
// Class is 14
// Number is 10
// MUST BE FRIENDLY

beginstate 29;

	if(get_flag(99,9) >= 1){
		print_str("Combat in Canopy is over.");
		end();
	}

	if(get_flag(99,3) >= 1){
		print_str_color("Summons are disabled during",1);
		print_str_color("outdoor combats.",1);
		end();
	}

	if(is_outdoor() == 1){
		print_str_color("Cannot be used outdoors.",1);
		end();
	}

summoner = who_used_custom_item();
clocx = char_loc_x(summoner);
clocy = char_loc_y(summoner);
clocyN = clocy + 1;
clocxE = clocx + 1;
clocxW = clocx - 1;
clocyS = clocy - 1;

	if(get_flag(77,7) >= 1)
		end();
	if(get_energy(summoner) >= 77){
change_char_energy(summoner,-77);
force_view_center(clocx,clocy);
text_bubble_on_char(summoner,"Archangel!");
force_instant_terrain_redraw();
pause(5);

text_bubble_on_char(summoner,"");
force_view_center(clocx,clocy);
activate_hidden_group(14);
relocate_character(10,clocx,clocy);
put_boom_on_space(clocx,clocyN,3,0);
put_boom_on_space(clocxE,clocy,3,0);
put_boom_on_space(clocxW,clocy,3,0);
put_boom_on_space(clocx,clocyS,3,0);
put_effect_on_space(clocx,clocyN,2,4,0);
put_effect_on_space(clocxE,clocy,2,4,0);
put_effect_on_space(clocxW,clocy,2,4,0);
put_effect_on_space(clocx,clocyS,2,4,0);
force_instant_terrain_redraw();
run_animation_sound(10);
pause(5);

set_flag(77,7,3);
set_flag(76,7,summoner);
print_str_color("You have summoned an Angel!",2);
print_str_color("Your character will be",2);
print_str_color("immobile for the next",2);
print_str_color("ten turns.",2);
set_char_status(summoner,4,0,1,0);
set_char_status(summoner,11,1,1,0);
set_char_status(summoner,4,1,1,0);
deduct_ap(99);

	}
	else{
		print_str_color("Not enough spell energy.",1);
	}
break;

// SCRY MONSTER
// Specials:
// 250 - Bugbear Mage
// 251 - Dark Idol
// 236 - Zauberer
// 235 - Alderauge
// 222 - Fusei
// 242 - Klugmann
// 241 - Todmacher
// 243 - Unumstoesslich
// 240 - Trahison
// 179 - Fallen General
// 107 - Shielded Wizard
// 226 - Defensive Shroud
// 227 - Mixed Shroud
// 228 - Offensive Shroud

beginstate 50;

	if(is_town() > 0){
		print_str_color("Cannot be used outdoors.",1);
		end();
	}

target = who_is_custom_item_target();
user = who_used_custom_item();

	if(get_energy(user) >= 1){
print_named_str(target,"'s details:");
print_big_str("Maximum HP: ",get_max_health(target),".");
print_big_str("Current HP: ",get_health(target),".");
print_big_str("Level: ",get_level(target),".");

		if(creature_type(target) == 250){
print_str_color("Watch out for its Martyr Beam.",1);
print_str_color("Spell resistance is HIGH.",1);
		}
		if(creature_type(target) == 251){
print_str_color("Stay out of its firing range.",1);
print_str_color("Fire and magic resistances are HIGH.",1);
		}
		if(creature_type(target) == 236){
print_str_color("Use the mirror!",1);
print_str_color("Normal attacks are innefective.",1);
		}
		if(creature_type(target) == 235){
print_str_color("Uses deadly archery.",1);
print_big_str("Has ",(4 - get_flag(65,2))," healing potions.");
		}
		if(creature_type(target) == 222){
print_str_color("Uses status effects.",1);
print_str_color("Magic and Mental are innefective.",1);
		}
		if(creature_type(target) == 242){
print_str_color("Uses status effects en masse.",1);
print_str_color("Spell resistance is HIGH.",1);
		}
		if(creature_type(target) == 241){
print_str_color("Dispels summons, uses Bladebeam",1);
print_str_color("Spell resistance is HIGH.",1);
		}
		if(creature_type(target) == 243){
print_str_color("Immune to normal attacks.",1);
print_str_color("Use Shinibiimu or Naturshand.",1);
		}
		if(creature_type(target) == 240){
print_str_color("Powerful warrior with unblockable beam.",1);
print_str_color("Immune to melee damage, use fire.",1);
		}
		if(creature_type(target) == 179){
print_str_color("Undead warrior with fiery touch.",1);
print_str_color("Immune to spells.  Use Repel Spirit.",1);
		}
		if(creature_type(target) == 107){
print_str_color("Completely invulnerable.",1);
print_str_color("Shielded from a source nearby.",1);
		}
		if(creature_type(target) == 226){
print_str_color("Nulls invuln. and defense spells.",1);
print_str_color("Weak against fire.",1);
		}
		if(creature_type(target) == 227){
print_str_color("Nulls invuln. and status spells.",1);
print_str_color("Moderately resistant to all.",1);
		}
		if(creature_type(target) == 228){
print_str_color("Nulls invuln. and attack spells.",1);
print_str_color("Weak against everything.",1);
		}

change_char_energy(user,-1);
deduct_ap(0);
	}
	else{
		print_str_color("Not enough spell energy.",1);
	}
break;

beginstate 51;

	reset_dialog();
	add_dialog_str(0,"Are you ABSOLUTELY SURE that you want to leave Canopy?",0);
	add_dialog_choice(0,"No, I want to CONTINUE PLAYING.");
	add_dialog_choice(1,"Yes, I want to STOP PLAYING.");
	user = run_dialog(0);

	if(user == 2){
		demi = 0;
		while(demi <= 3){
			if(char_ok(demi) == TRUE){
change_spell_level(demi,1,15,get_flag(30,(demi + 5)));
			}
		demi = (demi + 1);
		}

		end_scenario(0);
	}

break;

beginstate 52;

        // Numeric Input v1.0.0
        // numericinput.txt
        // by Kelandon (tomwatts@berkeley.edu)

	message_dialog("How fast would you like the text in cutscenes to be?  Keep in mind that inputting 10 is equal to 1 second.","You MUST input a number from 1 to 40.  No decimals or fractions.  Default speed is 14.");

        what_num = 0;
        
        get_text_response("Cutscene Speed:");
        check_text_response_match("1");
        if (got_text_match())
                what_num = 1;
        check_text_response_match("2");
        if (got_text_match())
                what_num = 2;
        check_text_response_match("3");
        if (got_text_match())
                what_num = 3;
        check_text_response_match("4");
        if (got_text_match())
                what_num = 4;
        check_text_response_match("5");
        if (got_text_match())
                what_num = 5;
        check_text_response_match("6");
        if (got_text_match())
                what_num = 6;
        check_text_response_match("7");
        if (got_text_match())
                what_num = 7;
        check_text_response_match("8");
        if (got_text_match())
                what_num = 8;
        check_text_response_match("9");
        if (got_text_match())
                what_num = 9;
        check_text_response_match("10");
        if (got_text_match())
                what_num = 10;
        check_text_response_match("11");
        if (got_text_match())
                what_num = 11;
        check_text_response_match("12");
        if (got_text_match())
                what_num = 12;
        check_text_response_match("13");
        if (got_text_match())
                what_num = 13;
        check_text_response_match("14");
        if (got_text_match())
                what_num = 14;
        check_text_response_match("15");
        if (got_text_match())
                what_num = 15;
        check_text_response_match("16");
        if (got_text_match())
                what_num = 16;
        check_text_response_match("17");
        if (got_text_match())
                what_num = 17;
        check_text_response_match("18");
        if (got_text_match())
                what_num = 18;
        check_text_response_match("19");
        if (got_text_match())
                what_num = 19;
        check_text_response_match("20");
        if (got_text_match())
                what_num = 20;
        check_text_response_match("21");
        if (got_text_match())
                what_num = 21;
        check_text_response_match("22");
        if (got_text_match())
                what_num = 22;
        check_text_response_match("23");
        if (got_text_match())
                what_num = 23;
        check_text_response_match("24");
        if (got_text_match())
                what_num = 24;
        check_text_response_match("25");
        if (got_text_match())
                what_num = 25;
        check_text_response_match("26");
        if (got_text_match())
                what_num = 26;
        check_text_response_match("27");
        if (got_text_match())
                what_num = 27;
        check_text_response_match("28");
        if (got_text_match())
                what_num = 28;
        check_text_response_match("29");
        if (got_text_match())
                what_num = 29;
        check_text_response_match("30");
        if (got_text_match())
                what_num = 30;
        check_text_response_match("31");
        if (got_text_match())
                what_num = 31;
        check_text_response_match("32");
        if (got_text_match())
                what_num = 32;
        check_text_response_match("33");
        if (got_text_match())
                what_num = 33;
        check_text_response_match("34");
        if (got_text_match())
                what_num = 34;
        check_text_response_match("35");
        if (got_text_match())
                what_num = 35;
        check_text_response_match("36");
        if (got_text_match())
                what_num = 36;
        check_text_response_match("37");
        if (got_text_match())
                what_num = 37;
        check_text_response_match("38");
        if (got_text_match())
                what_num = 38;
        check_text_response_match("39");
        if (got_text_match())
                what_num = 39;
        check_text_response_match("40");
        if (got_text_match())
                what_num = 40;

	if(what_num == 0){
		message_dialog("ERROR: The number you inputted was not equal to an integer between 1 and 40.","If you wish to customize cutscene speed, use this ability again.");
		change_custom_abil_uses(who_used_custom_abil(),0,1);
		end();
	}
	else{
		set_flag(75,0,what_num);
		change_custom_abil_uses(who_used_custom_abil(),0,1);

		reset_dialog();
		add_dialog_str(0,"Would you like to see how long your chosen time for cutscenes is?",0);
		add_dialog_str(1,"(Five brief messages will be displayed over your main character's head.  Keep in mind that messages you will get in-scenario will be more lengthy than this.)",0);
		add_dialog_choice(0,"Test.");
		add_dialog_choice(1,"No thanks.");
		bmessage = run_dialog(0);
		if(bmessage == 2)
			end();
		demi = 0;
		while(char_ok(demi) == FALSE){
			demi = (demi + 1);
		}
		text_bubble_on_char(demi,"Testing...");
		force_instant_terrain_redraw();
		pause(get_flag(75,0));

		text_bubble_on_char(demi,"");
		text_bubble_on_char(demi,"One.");
		force_instant_terrain_redraw();
		pause(get_flag(75,0));

		text_bubble_on_char(demi,"");
		text_bubble_on_char(demi,"Two.");
		force_instant_terrain_redraw();
		pause(get_flag(75,0));

		text_bubble_on_char(demi,"");
		text_bubble_on_char(demi,"Three.");
		force_instant_terrain_redraw();
		pause(get_flag(75,0));

		text_bubble_on_char(demi,"");
		text_bubble_on_char(demi,"Is this thing on?");
		force_instant_terrain_redraw();
		pause(get_flag(75,0));

		text_bubble_on_char(demi,"");
		force_instant_terrain_redraw();
	}

break;