<!--This Document is generated by GameMaker, if you edit it by hand then you do so at your own risk!-->
<object>
  <spriteName>&lt;undefined&gt;</spriteName>
  <solid>0</solid>
  <visible>-1</visible>
  <depth>-100000001</depth>
  <persistent>0</persistent>
  <parentName>&lt;undefined&gt;</parentName>
  <maskName>&lt;undefined&gt;</maskName>
  <events>
    <event eventtype="0" enumb="0">
      <action>
        <libid>1</libid>
        <id>603</id>
        <kind>7</kind>
        <userelative>0</userelative>
        <isquestion>0</isquestion>
        <useapplyto>-1</useapplyto>
        <exetype>2</exetype>
        <functionname></functionname>
        <codestring></codestring>
        <whoName>self</whoName>
        <relative>0</relative>
        <isnot>0</isnot>
        <arguments>
          <argument>
            <kind>1</kind>
            <string>if instance_number(objBattleSwirl) &gt; 1 { instance_destroy(); exit }

//Instawin stuff
instawin = 1 
instawin_r = 0
pl_count = global.pl_count 
en_count = global.en_count 
for (var i=1; i&lt;6; i++) {
    e_speed[i] = 0
    e_off[i] = 0
    e_def[i] = 0
    e_hp[i] = 0
    e_droprate[i] = 0
    e_drop[i] = 0
    e_name[i] = ""
    e_art[i] = ""
    e_exp[i] = 0
    if i&lt;5 {
        s_speed[i] = global.s_speed[i]
        s_off[i] = global.s_off[i]
    }
}

dropenemy = 0
droprate = 0
drop = 0
_drop = 0
dropenemyname = ""
instawinstep = 0

//The other stuff
with objButterfly { instance_destroy() } 

image_speed        = 0.45
sprite_index       = choose(sprBattleEntry1,sprBattleEntry2,sprBattleEntry3)
image_alpha        = 0.5
done               = 0
if instance_exists(objPlayer){
    objPlayer.canmove = 0
    objPlayer.speed   = 0
}
x=view_xview[0]
y=view_yview[0]

audio_pause_sound(global.bgMusic_)

blue = make_color_rgb(0,0,208)
green = make_color_rgb(8,192,135)
red = make_color_rgb(207,0,0)

if !global.boss {
    switch global.battle_type {
        case 0: color = blue; sound = audio_play_sound(sndenterbattle,0,0); break;
        case 1: color = green; sound = audio_play_sound(sndenterbattle,0,0); break;
        case 2: color = red; sound = audio_play_sound(sndbackattack,0,0); break;
    }
} else {
    color = blue;
    audio_play_sound(sndboss,0,0)
}


event_user(0)

</string>
          </argument>
        </arguments>
      </action>
    </event>
    <event eventtype="2" enumb="4">
      <action>
        <libid>1</libid>
        <id>603</id>
        <kind>7</kind>
        <userelative>0</userelative>
        <isquestion>0</isquestion>
        <useapplyto>-1</useapplyto>
        <exetype>2</exetype>
        <functionname></functionname>
        <codestring></codestring>
        <whoName>self</whoName>
        <relative>0</relative>
        <isnot>0</isnot>
        <arguments>
          <argument>
            <kind>1</kind>
            <string>if instance_exists(objBattleMsg) {
    alarm[4] = 1
} else {
    objPlayer.canmove = 1
    audio_stop_sound(sndlevelup)
    audio_stop_sound(sndEasyWin)
    audio_resume_sound(global.bgMusic_)
    instance_destroy()
    with objOwEnemyBlink { event_perform(ev_other, ev_room_start) }
}
</string>
          </argument>
        </arguments>
      </action>
    </event>
    <event eventtype="2" enumb="3">
      <action>
        <libid>1</libid>
        <id>603</id>
        <kind>7</kind>
        <userelative>0</userelative>
        <isquestion>0</isquestion>
        <useapplyto>-1</useapplyto>
        <exetype>2</exetype>
        <functionname></functionname>
        <codestring></codestring>
        <whoName>self</whoName>
        <relative>0</relative>
        <isnot>0</isnot>
        <arguments>
          <argument>
            <kind>1</kind>
            <string>///Level up

if instance_exists(objBattleMsg) {
    alarm[3] = 1
} else {

    if !audio_is_playing(sndlevelup) {
        audio_stop_sound(sndEasyWin)
        audio_play_sound(sndlevelup,0,1)
    }

    level_up_battle(3);
    
    alarm[4] = 1;
}
</string>
          </argument>
        </arguments>
      </action>
    </event>
    <event eventtype="2" enumb="2">
      <action>
        <libid>1</libid>
        <id>603</id>
        <kind>7</kind>
        <userelative>0</userelative>
        <isquestion>0</isquestion>
        <useapplyto>-1</useapplyto>
        <exetype>2</exetype>
        <functionname></functionname>
        <codestring></codestring>
        <whoName>self</whoName>
        <relative>0</relative>
        <isnot>0</isnot>
        <arguments>
          <argument>
            <kind>1</kind>
            <string>///Enemy drops
if instance_exists(objBattleMsg) {
    alarm[2] = 1
    exit
} else {
    if _drop = 0 {
        audio_play_sound(sndpresent,0,0)
        with instance_create(0,0,objBattleMsg) {
            strno = 1;
            str[0] = objBattleSwirl.dropenemyname + " dropped a present!";
            str[1] = "Inside the present,#   there was "+global.item[objBattleSwirl.drop,17]+global.item[objBattleSwirl.drop,1]+"!";
        }
        _drop = 1
        alarm[2] = 1
    } else {
        var a;
        a = instance_create(0,0,objBattleMsg);
        a.strno = 0
        b = add_item_ext(drop);
        if b = -1 {
            if global.pl_count = 1 {
                a.str[0] = "But "+global.s_name[1]+" was carrying too much stuff already,#   so it was sent to the storage instead."
            } else {
                a.str[0] = "But everyone was carrying too much stuff already,#   so it was sent to the storage instead."
            }
            add_item_storage(drop);
        } else {
            a.str[0] = global.s_name[b+1]+" took it."
            audio_play_sound(snditemget1,0,0)
        }
        alarm[3] = 1
    }
}   
</string>
          </argument>
        </arguments>
      </action>
    </event>
    <event eventtype="2" enumb="1">
      <action>
        <libid>1</libid>
        <id>603</id>
        <kind>7</kind>
        <userelative>0</userelative>
        <isquestion>0</isquestion>
        <useapplyto>-1</useapplyto>
        <exetype>2</exetype>
        <functionname></functionname>
        <codestring></codestring>
        <whoName>self</whoName>
        <relative>0</relative>
        <isnot>0</isnot>
        <arguments>
          <argument>
            <kind>1</kind>
            <string>///You win message
stat_reset()
global.s_exp[1] += global.totalexp*!global.dead[1];
        
if global.pl_count &gt; 1 {
    global.s_exp[2] += global.totalexp*!global.dead[2];
}
if global.pl_count &gt; 2 {
    global.s_exp[3] += global.totalexp*!global.dead[3];
}
if global.pl_count &gt; 3 {
    global.s_exp[4] += global.totalexp*!global.dead[4];
}

global.money += ceil(global.totalexp/4);

with instance_create(0,0,objBattleMsg) {
    strno = 1;
    str[0] = "YOU WONZ"
    if global.totalexp = 0 {
        str[1] = "It was a nice experience."
    } else {
        switch global.pl_count {
            case 1: 
                str[1] = global.s_name[1]+" got "+string(global.totalexp)+" EXP."; break;
            case 2: 
                if global.dead[1] {
                    str[1] = global.s_name[2]+" got "+string(global.totalexp)+" EXP."; break;
                } else if global.dead[2] {
                    str[1] = global.s_name[1]+" got "+string(global.totalexp)+" EXP."; break;
                } else {
                    str[1] = global.s_name[1]+" and "+global.s_name[2]+" got "+string(global.totalexp)+" EXP."; break;
                }
            case 3:
                if global.dead[1] {
                    if global.dead[2] {
                        str[1] = global.s_name[3]+" got "+string(global.totalexp)+" EXP."; break;
                    } else {
                        str[1] = global.s_name[2]+" and "+global.s_name[3]+" got "+string(global.totalexp)+" EXP."; break;
                    }
                } else if global.dead[2] {
                    if global.dead[1] {
                        str[1] = global.s_name[3]+" got "+string(global.totalexp)+" EXP."; break;
                    } else {
                        str[1] = global.s_name[1]+" and "+global.s_name[3]+" got "+string(global.totalexp)+" EXP."; break;
                    }
                } else if global.dead[3] {
                    if global.dead[1] {
                        str[1] = global.s_name[2]+" got "+string(global.totalexp)+" EXP."; break;
                    } else {
                        str[1] = global.s_name[1]+" and "+global.s_name[2]+" got "+string(global.totalexp)+" EXP."; break;
                    }
                } else {
                    str[1] = global.s_name[1]+" and co. got "+string(global.totalexp)+" EXP."; break;
                }
            case 4: 
                str[1] = "The party got "+string(global.totalexp)+" EXP."; break;
        }
    }
}
if random(100)&lt;=droprate and drop != 0 {
    alarm[2] = 1
} else {
    alarm[3] = 1
}
</string>
          </argument>
        </arguments>
      </action>
    </event>
    <event eventtype="2" enumb="0">
      <action>
        <libid>1</libid>
        <id>603</id>
        <kind>7</kind>
        <userelative>0</userelative>
        <isquestion>0</isquestion>
        <useapplyto>-1</useapplyto>
        <exetype>2</exetype>
        <functionname></functionname>
        <codestring></codestring>
        <whoName>self</whoName>
        <relative>0</relative>
        <isnot>0</isnot>
        <arguments>
          <argument>
            <kind>1</kind>
            <string>///Insta-win detection


for (var i=1; i&lt;4; i++) {
    if global.s_crying[i] or global.s_poison[i] or global.s_infected[i] or global.s_radiation[i]
    or global.s_asleep[i] or global.s_numb[i] or global.s_solid[i] or global.s_strange[i]
    or global.s_shocked[i] or global.s_cantconcentrate[i] or global.dead[i] and global.pl_count = i {
        pl_count -= 1;
    }
}
//If the number of enemies is greater than the number of characters who don't suffer from any statuses, you can't instantly win. 
if global.en_count &gt; pl_count {
    instawin = 0;
} else {
    var enemy, highest_enemy_speed, lowest_player_speed, lowest_player_offense;
    for (var ii=1; ii&lt;=global.en_count; ii++) {
        enemy = instance_create(0,0,global.enemy[ii])
        enemy.visible = 0
        e_off[ii] = enemy.e_off
        e_def[ii] = enemy.e_def
        e_hp[ii] = enemy.e_hp
        e_speed[ii] = enemy.e_speed
        e_droprate[ii] = enemy.e_droprate
        e_drop[ii] = enemy.e_drop
        e_name[ii] = enemy.e_name
        e_art[ii] = enemy.e_art
        e_exp[ii] = enemy.e_exp
        instance_deactivate_object(enemy)
    }
    if global.battle_type != 2 and !global.boss {
        if global.battle_type == 0 {
            //In a blue swirl, the highest speed among enemies is compared to the lowest speed among your current party members (even if unconscious). 
            //Each enemy's HP+defense is then compared to the lowest offense among your current party members (even if unconscious). 
            //If your party's stats are greater (not equal) in both cases, you instantly win the fight. 
            highest_enemy_speed = max(e_speed[1],e_speed[2],e_speed[3],e_speed[4],e_speed[5])
            lowest_player_speed = min(s_speed[1],iff(global.pl_count &gt; 1,s_speed[2],1000),iff(global.pl_count &gt; 2,s_speed[3],1000),iff(global.pl_count &gt; 3,s_speed[4],1000))
            if lowest_player_speed &gt; highest_enemy_speed {
                lowest_player_offense = min(s_off[1],iff(global.pl_count &gt; 1,s_off[2],1000),iff(global.pl_count &gt; 2,s_off[3],1000),iff(global.pl_count &gt; 3,s_off[4],1000))
                if !(lowest_player_offense &gt; (e_hp[1]+e_def[1])
                and lowest_player_offense &gt; (e_hp[2]+e_def[2])
                and lowest_player_offense &gt; (e_hp[3]+e_def[3])
                and lowest_player_offense &gt; (e_hp[4]+e_def[4])
                and lowest_player_offense &gt; (e_hp[5]+e_def[5])) {
                    write_line("Instawin: Failed lowest offense test.")
                    instawin = 0;
                }
            } else {
                write_line("Instawin: Failed lowest speed test.")
                instawin = 0;
            }
        } else {
            //In a green swirl, your characters who do not suffer from the aforementioned statuses are sorted by offense in descending order, and the enemies are sorted by HP in descending order. 
            //In turn, each character "attacks" the first enemy which is still "alive", dealing exactly 2*offense-defense "damage". 
            //If every enemy is "killed" this way, you instantly win the fight. 
            var player_list, enemy_list;
            player_list = ds_list_create();
            enemy_list  = ds_list_create();
            for (var i=1; i&lt;global.pl_count+1; i++) {
                if !(global.s_crying[i] or global.s_poison[i] or global.s_infected[i] or global.s_radiation[i]
                or global.s_asleep[i] or global.s_numb[i] or global.s_solid[i] or global.s_strange[i]
                or global.s_shocked[i] or global.s_cantconcentrate[i] or global.dead[i]) {
                    ds_list_add(player_list,s_off[i]);
                }
            }
            for (var i=1; i&lt;=global.en_count; i++) {
                ds_list_add(enemy_list,e_hp[i]+e_def[i]);
            }
            ds_list_sort(player_list,0)
            ds_list_sort(enemy_list,0)
            
            for (var i=1; i&lt;global.pl_count+1; i++) {
                if !(global.s_crying[i] or global.s_poison[i] or global.s_infected[i] or global.s_radiation[i]
                or global.s_asleep[i] or global.s_numb[i] or global.s_solid[i] or global.s_strange[i]
                or global.s_shocked[i] or global.s_cantconcentrate[i] or global.dead[i]) {
                    for (var j=1; j&lt;global.en_count+1; j++) {
                        //write_line(string(ds_list_find_value(player_list, i-1))+"/"+string(ds_list_find_value(enemy_list, j-1)))
                        if !is_undefined(ds_list_find_value(player_list, i-1)) and !is_undefined(ds_list_find_value(enemy_list, j-1)) {
                            if ds_list_find_value(enemy_list, j-1) != -1 {
                                if 2*ds_list_find_value(player_list, i-1) &gt;= ds_list_find_value(enemy_list, j-1) {
                                    ds_list_delete(enemy_list, j-1);
                                }
                            }
                        }
                    }
                }
            }
            
            if !ds_list_empty(enemy_list) {
                write_line("Instawin: Failed because enemy list not empty.")
                instawin = 0;
            }
            ds_list_destroy(player_list);
            ds_list_destroy(enemy_list);
        }
    } else {
        instawin = 0;
    }
}

audio_stop_sound(sndenterbattle)
audio_stop_sound(sndbackattack)
audio_stop_sound(sndboss)

if instawin {
    instawin_r = 1
    audio_play_sound(sndenemyhit,0,0)
    audio_play_sound(sndEasyWin,0,0)
    droprate = e_droprate[dropenemy]
    drop = e_drop[dropenemy]
    dropenemyname = upper(e_art[dropenemy])+e_name[dropenemy]
    switch global.en_count {
        case 1: global.totalexp = e_exp[1]; break;
        case 2: global.totalexp = e_exp[1]+e_exp[2]; break;
        case 3: global.totalexp = e_exp[1]+e_exp[2]+e_exp[3]; break;
        case 4: global.totalexp = e_exp[1]+e_exp[2]+e_exp[3]+e_exp[4]; break;
        case 5: global.totalexp = e_exp[1]+e_exp[2]+e_exp[3]+e_exp[4]+e_exp[5]; break;
    }
    write_line("Instawin: Success.")
    alarm[1] = 1
} else {
    global.cutscene = 0
    instance_create(0,0,objFadeOutBattle);
}
</string>
          </argument>
        </arguments>
      </action>
    </event>
    <event eventtype="3" enumb="0">
      <action>
        <libid>1</libid>
        <id>603</id>
        <kind>7</kind>
        <userelative>0</userelative>
        <isquestion>0</isquestion>
        <useapplyto>-1</useapplyto>
        <exetype>2</exetype>
        <functionname></functionname>
        <codestring></codestring>
        <whoName>self</whoName>
        <relative>0</relative>
        <isnot>0</isnot>
        <arguments>
          <argument>
            <kind>1</kind>
            <string>x=view_xview[0]
y=view_yview[0]

/*if instance_exists(objPlayer) {
    global.thex = objPlayer.x
    global.they = objPlayer.y
}*/

if image_index &gt; image_number-1 and done = 0
{
    image_index = image_number-1
    image_speed = 0
    done = 1
    if instance_exists(objOwEnemyBlink) {
        global.thex = objOwEnemyBlink.x
        global.they = objOwEnemyBlink.y
    } else if instance_exists(objPlayer) {
        global.thex = objPlayer.x
        global.they = objPlayer.y
    }
    if !global.boss { alarm[0] = 120 } else { alarm[0] = 90 }
}
</string>
          </argument>
        </arguments>
      </action>
    </event>
    <event eventtype="7" enumb="10">
      <action>
        <libid>1</libid>
        <id>603</id>
        <kind>7</kind>
        <userelative>0</userelative>
        <isquestion>0</isquestion>
        <useapplyto>-1</useapplyto>
        <exetype>2</exetype>
        <functionname></functionname>
        <codestring></codestring>
        <whoName>self</whoName>
        <relative>0</relative>
        <isnot>0</isnot>
        <arguments>
          <argument>
            <kind>1</kind>
            <string>dropenemy = irandom(global.en_count-1)+1
</string>
          </argument>
        </arguments>
      </action>
    </event>
    <event eventtype="8" enumb="0">
      <action>
        <libid>1</libid>
        <id>603</id>
        <kind>7</kind>
        <userelative>0</userelative>
        <isquestion>0</isquestion>
        <useapplyto>-1</useapplyto>
        <exetype>2</exetype>
        <functionname></functionname>
        <codestring></codestring>
        <whoName>self</whoName>
        <relative>0</relative>
        <isnot>0</isnot>
        <arguments>
          <argument>
            <kind>1</kind>
            <string>if instawin_r = 0 {
    draw_sprite_ext(sprite_index,image_index,x,y,1,1,0,color,image_alpha)
} else {
    if instawinstep &lt; 10 {
        draw_set_alpha(0.9)
        draw_set_color(make_color_hsv( (instawinstep++)*50, 255, 255 ) )
        draw_rectangle(view_xview,view_yview,view_xview+426,view_yview+240,0)
    }
}
</string>
          </argument>
        </arguments>
      </action>
    </event>
  </events>
  <PhysicsObject>0</PhysicsObject>
  <PhysicsObjectSensor>0</PhysicsObjectSensor>
  <PhysicsObjectShape>0</PhysicsObjectShape>
  <PhysicsObjectDensity>0.5</PhysicsObjectDensity>
  <PhysicsObjectRestitution>0.100000001490116</PhysicsObjectRestitution>
  <PhysicsObjectGroup>0</PhysicsObjectGroup>
  <PhysicsObjectLinearDamping>0.100000001490116</PhysicsObjectLinearDamping>
  <PhysicsObjectAngularDamping>0.100000001490116</PhysicsObjectAngularDamping>
  <PhysicsObjectFriction>0.200000002980232</PhysicsObjectFriction>
  <PhysicsObjectAwake>-1</PhysicsObjectAwake>
  <PhysicsObjectKinematic>0</PhysicsObjectKinematic>
  <PhysicsShapePoints/>
</object>
