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

int spell_source,spell_target,x1,y1,x2,y2;

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(0,"Unicorn key","You found this key in an unicorn pit near the southern shore of Cherayeng Island. So far, you don't know where the key is supposed to be used.");
        init_special_item(1,"Forest key","This is a key with a small symbol of a tree on one side. You found it in a concealed forest on the northwest shore of Cherayeng Island.");
        init_special_item(2,"Basilisk orb","This is a brown orb which you found in the center of Cherayeng Island. You aren't sure where you got it, but you can use it to get past the basilisks easily.");
        init_quest(1,"Explore Cherayeng Island","The Empire asked you, along with Cerund, Danor, and Inala, to survey Cherayeng Island.");
        init_quest(2,"Get off Cherayeng Island","You are trying to find a way to get off Cherayeng Island.");
        init_quest(3,"Deal with spirits","Danor, the food surveyor of the team, wants to explore a grove northeast of the camp for food sources. Every time he goes there, a group of spirits chases him off. He wants you to make sure that the spirits won't be a threat to him.");
	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;
        set_town_visibility(6,0);
break;

// This state is called every tick wherever the party is in the scenario.
// You can use the set_state
beginstate START_STATE;
        if ((get_current_tick() % 5000) == 0) {
                //reset alchemical ingredients
                set_flag(0,5,0); //mandrake in southeast island
                set_flag(0,8,0); //graymold in northeast island
                set_flag(0,12,0); //energetic herbs in east island
                set_flag(2,2,0); //party can now get more food from Danor
        }
break;

// Place your own states below. Give each a number at least 10.
beginstate 10;
        spell_source = who_used_custom_item();
        spell_target = who_is_custom_item_target();
        x1 = char_loc_x(spell_source);
        y1 = char_loc_y(spell_source);
        x2 = char_loc_x(spell_target);
        y2 = char_loc_y(spell_target);
        if (get_energy(spell_source) < 25) { //50
                print_str("Coldwave: You don't have enough spell points.");
                end();
        }
        if (char_dist_to_loc(spell_target,x1,y1) >= 8) {
                print_str("Coldwave: Target out of range.");
                end();
        }
        if (get_stat(spell_source,11) < 12) {
                print_str("Coldwave: You need a Mage Spells skill of 12 or more.");
                end();
        }
        print_str("You cast Coldwave.");
        put_straight_zap(x1,y1,x2,y2,6);
        put_boom_on_char(spell_target,2,0);
        run_animation_sound(52);
        damage_near_loc(x2,y2,(80 + get_ran(1,0,80)),3,5);
        //What I wanted to do is like damage_nearby, but from the target's coordinates, not the caster's.
        change_char_energy(spell_source,-25); //50
        //deduct_ap(5);
break;

beginstate 11;
        spell_source = who_used_custom_item();
        spell_target = who_is_custom_item_target();
        x1 = char_loc_x(spell_source);
        y1 = char_loc_y(spell_source);
        x2 = char_loc_x(spell_target);
        y2 = char_loc_y(spell_target);
        if (get_energy(spell_source) < 15) { //50
                print_str("Withering: You don't have enough spell points.");
                end();
        }
        if (char_dist_to_loc(spell_target,x1,y1) >= 6) {
                print_str("Withering: Target out of range.");
                end();
        }
        if (get_stat(spell_source,11) < 8) {
                print_str("Withering: You need a Mage Spells skill of 8 or more.");
                end();
        }
        print_str("You cast Withering.");
        put_jagged_zap(x1,y1,x2,y2,5);
        put_boom_on_char(spell_target,3,0);
        run_animation_sound(104);
        damage_char(get_target(),(40 + get_ran(1,0,20)),4);
        change_char_energy(spell_source,-15); //50
break;