// ==EMEVD==
// @docs    nr-common.emedf.json
// @compress    DCX_KRAK
// @game    Sekiro
// @string    "W:\\CL\\data\\Param\\event\\common_func.emevd\u0000W:\\CL\\data\\Param\\event\\common_macro.emevd\u0000\u0000\u0000\u0000\u0000\u0000"
// @linked    [0,82]
// @version    3.6.1
// ==/EMEVD==

//boss arena preconstructor
$Event(99989998, Default, function() {
    $InitializeEvent(0, 99989900); //various (event 50)
    $InitializeEvent(0, 99989901); //death handling (modified)
});

//boss arena constructor
$Event(99989999, Default, function() {
    $InitializeEvent(0, 99980000); //various
    $InitializeEvent(0, 99980001); //infinite revives cheat
    $InitializeEvent(0, 99980002); //set default variant flags
    $InitializeEvent(0, 99980003); //player immortality handling
    $InitializeEvent(0, 99980004); //apply buffs from flags
    $InitializeEvent(0, 99980005); //apply buffs from flags
    $InitializeEvent(0, 99980006); //apply buffs from flags
    $InitializeEvent(0, 99980007); //apply buffs from flags
    $InitializeEvent(0, 99980008); //set default flags (1.0.3)
    $InitializeEvent(0, 99980009); //test event
    //$InitializeEvent(0, 99980010); //set default flags (2.0) //update
    $InitializeEvent(0, 99980011); //return to roundtable from grace
    $InitializeCommonEvent(0, 99993002); //expedition boss rush: display round number
    $InitializeCommonEvent(0, 99993003); //expedition boss rush: grace warp triggers
    $InitializeCommonEvent(0, 99993006); //boss rush: set player level
    $InitializeCommonEvent(0, 99993007); //boss rush: update player level while in grace menu
    $InitializeEvent(0, 10004000); //single boss selection ESD triggers
    $InitializeEvent(0, 10004001); //expedition boss rush esd triggers
    $InitializeEvent(0, 10004010); //rematch
    $InitializeEvent(0, 10004100); //flasks menu
    $InitializeEvent(0, 10004101); //obtain shop itemlots
    $InitializeEvent(0, 10004102); //obtain shop itemlots
    $InitializeEvent(0, 10004103); //obtain shop itemlots
    $InitializeEvent(0, 10004105); //clear buffs
    $InitializeEvent(0, 10004106); //clear all buffs
    $InitializeEvent(0, 10004107); //apply all buffs
    $InitializeEvent(0, 10004108); //show warning about active boss rush
    $InitializeEvent(0, 10004109); //unlock characters and outfits
});

//test event
$Event(99980009, Default, function() {
    //WaitFor(CharacterHasSpEffect(10000, 705010));
    //DisplayBlinkingMessage(1);
    //WaitFor(!CharacterHasSpEffect(10000, 705010));
    //DisplayBlinkingMessage(1);
});

//various (preconstructor)
$Event(99989900, Default, function() {
    if (PlayerInMap(10, 0, 0, 0)) {
        SetEventFlagID(7500, OFF); //day 1 flag
        SetEventFlagID(7505, OFF); //day 2 flag
        SetEventFlagID(7510, OFF); //day 3 flag
        SetEventFlagID(7515, OFF); //night boss flag
        DisableCharacterImmortality(10000);
    }
    else {
        SetEventFlagID(7500, ON); //day 1 flag
        SetEventFlagID(7505, ON); //day 2 flag
        SetEventFlagID(7510, ON); //day 3 flag
        SetEventFlagID(7515, ON); //night boss flag
    }
    BatchSetEventFlags(12005000, 12005999, OFF); //reset temp flags
    BatchSetEventFlags(70000, 70099, OFF); //reset libra summon flags
    $InitializeCommonEvent(0, 99992001); //clear libra deal speffects
    //$InitializeCommonEvent(0, 99992002); //remove storm ruler
    $InitializeCommonEvent(0, 99992003); //clear wormface night boss effects and items
});

//various (constructor)
$Event(99980000, Default, function() {
    BonfirelikeRecovery(); //recovery in every map
    ClearSpEffect(20000, 9621); //enable attack in roundtable
});

//infinite revives cheat
$Event(99980001, Default, function() {
    if (EventFlag(12000202)) {
        WaitFor(!CharacterHasSpEffect(10000, 6999500));
        WaitFixedTimeFrames(1);
        SetSpEffect(10000, 6999500);
        RestartEvent();
    }
    else if (!EventFlag(12000207)) //if solo revive is disabled
            ClearSpEffect(10000, 6999500);
});

//player immortality handling
$Event(99980003, Default, function() {
    EndIf(!PlayerInMap(13, 20, 0, 0)
    && !PlayerInMap(18, 0, 0, 0)
    && !PlayerInMap(19, 0, 0, 0));
    WaitFor(!CharacterHasSpEffect(10000, 6999500) //sp revive
    && !CharacterHasSpEffect(10000, 540155) //wending grace
    && !CharacterHasSpEffect(10000, 6999100)); //favor of noklateo
    EnableCharacterImmortality(10000);
    SetEventFlagID(12000203, ON);
    WaitFor(CharacterHasSpEffect(10000, 6999500)
    || CharacterHasSpEffect(10000, 540155)
    || CharacterHasSpEffect(10000, 6999100));
    DisableCharacterImmortality(10000);
    SetEventFlagID(12000203, OFF);
    RestartEvent();
});

//singleplayer death handling (modified)
$Event(99989901, Restart, function() {
    EndIf(!PlayerInMap(13, 20, 0, 0)
    && !PlayerInMap(18, 0, 0, 0)
    && !PlayerInMap(19, 0, 0, 0));
    WaitFixedTimeSeconds(0.1);
    if (!HasMultiplayerState(MultiplayerState.Singleplayer)) {
        EndEvent();
    }
    WaitFor(EventFlag(7500));
    WaitFor((EventFlag(7515) || EventFlag(7510)) && CharacterHPValue(10000) > 0);
    if (CharacterHasSpEffect(10000, 705010)) { //if revenant ult active
        WaitFor(!CharacterHasSpEffect(10000, 705010));
        if (CharacterHPValue(10000) == 1) {
            SetSpEffect(10000, 136927016); //add 1 hp to prevent defeat trigger
            WaitFixedTimeFrames(1);
        }
    }
    if (EventFlag(12000203)) //if player is immortal (revive speffects not active)
        WaitFor(
            (!EventFlag(7515) && !EventFlag(7510))
            ||  CharacterHPValue(10000) <= 1
                || CharacterHasTeamType(10000, TeamType.Unknown77));
    else { //if player is mortal (revive speffects active)
        WaitFor(
            (!EventFlag(7515) && !EventFlag(7510))
            ||  CharacterHPValue(10000) <= 0
                || CharacterHasTeamType(10000, TeamType.Unknown77));
            }
    RestartIf(!EventFlag(7515) && !EventFlag(7510));
    if (CharacterHasSpEffect(20000, 6999500)) {
        WaitFor(CharacterHasSpEffect(20000, 540157));
        SetSpEffect(20000, 6999505);
        SetSpEffect(20000, 6999501);
        WaitFor(CharacterHPValue(20000) != 0 && !CharacterHasTeamType(10000, TeamType.Unknown77));
        RestartEvent();
    }
    if (CharacterHasSpEffect(20000, 540155)) {
        WaitFor(CharacterHasSpEffect(20000, 540157));
        SetSpEffect(20000, 540150);
        RemoveItemFromPlayer(ItemType.Goods, 700, 1);
        WaitFor(CharacterHPValue(20000) != 0 && !CharacterHasTeamType(10000, TeamType.Unknown77));
        RestartEvent();
    }
    if (CharacterHasSpEffect(20000, 6999100)) {
        WaitFor(CharacterHasSpEffect(20000, 540157));
        SetSpEffect(20000, 6999101);
        SetSpEffect(20000, 6999104);
        SetSpEffect(20000, 6999105);
        SetSpEffect(20000, 6999106);
        SetSpEffect(20000, 6999107);
        WaitFor(CharacterHPValue(20000) != 0 && !CharacterHasTeamType(10000, TeamType.Unknown77));
        RestartEvent();
    }
    //EndIf(EventFlag(7513));
    //SetSpEffect(20000, 102140);
    //SetEventFlagID(9017, ON);
    //WaitFixedTimeSeconds(4);
    //EndIf(EventFlag(7513));
    //SetEventFlagID(7519, ON);
    //DisplayTextEffectId(4010);
    //SetEventFlagID(7516, ON);
    //WaitFixedTimeSeconds(5);
    //SetEventFlagID(7001, ON);
    if (CharacterHasSpEffect(10000, 705010)) //if revenant ult active
        RestartEvent();
    DisableCharacterAI(13205999);
    EnableCharacterInvincibility(10000);
    EnableCharacterInvincibility(13205999);
    EnableCharacterImmortality(13205999);
    WaitFixedTimeSeconds(1);
    DisplayTextEffectId(4010);
    WaitFixedTimeSeconds(3);
    $InitializeCommonEvent(0, 99992001); //clear libra deal speffects
    DisableCharacter(13205999);
    FadeToBlack(1, 0, 1, 0);
    if (EventFlag(12000204)) { //respawn set to arena
        if (PlayerInMap(13, 20, 0, 0))
            WarpPlayer(13, 20, 0, 0, 13202999, -1);
        else if (PlayerInMap(18, 0, 0, 0))
            WarpPlayer(18, 0, 0, 0, 18002300, -1);
        else if (PlayerInMap(19, 0, 0, 0))
            WarpPlayer(19, 0, 0, 0, 19002300, -1);
    }
    else if (EventFlag(12000205)) //respawn set to roundtable
        WarpPlayer(10, 0, 0, 0, 10002200, -1);
    else { //prompt enabled
        WaitFixedTimeSeconds(2);
        DisplayGenericDialogAndSetEventFlags(7232901, PromptType.YESNO, NumberofOptions.TwoButtons, 0, 100, 12005203, 12005204, 12005204);
        WaitFor(EventFlag(12005203) || EventFlag(12005204));     
        if (EventFlag(12005203)) //if yes, return to roundtable
            WarpPlayer(10, 0, 0, 0, 10002200, -1);
        else { //if no, retry battle
            if (EventFlag(12000207) && !EventFlag(12000212)) //if solo revive enabled and not in boss rush mode
                SetSpEffect(20000, 6999500); //enable revive
            if (PlayerInMap(13, 20, 0, 0))
                WarpPlayer(13, 20, 0, 0, 13202999, -1);
            else if (PlayerInMap(18, 0, 0, 0))
                WarpPlayer(18, 0, 0, 0, 18002300, -1);
            else if (PlayerInMap(19, 0, 0, 0))
                WarpPlayer(19, 0, 0, 0, 19002300, -1);
        }
    }
});

//apply buffs from flags 1
$Event(99980004, Default, function() {
    //Improved Physical Attack Power (+6%)
    if (EventFlag(12000300) && !CharacterHasSpEffect(10000, 8100000))
        SetSpEffect(10000, 8100000);
    //Improved Physical Attack Power (+9%)
    if (EventFlag(12000301) && !CharacterHasSpEffect(10000, 8100001))
        SetSpEffect(10000, 8100001);
    //Improved Affinity Attack Power (+5%)
    if (EventFlag(12000302) && !CharacterHasSpEffect(10000, 8100500))
        SetSpEffect(10000, 8100500);
    //Improved Affinity Attack Power (+8%)
    if (EventFlag(12000303) && !CharacterHasSpEffect(10000, 8100501))
        SetSpEffect(10000, 8100501);
    //Improved Stance-Breaking (+10%)
    if (EventFlag(12000304) && !CharacterHasSpEffect(10000, 8120000))
        SetSpEffect(10000, 8120000);
    //Improved Stance-Breaking (+15%)
    if (EventFlag(12000305) && !CharacterHasSpEffect(10000, 8120001))
        SetSpEffect(10000, 8120001);
    //Dragonwound upon Dragon Communion
    if (EventFlag(12000306) && !CharacterHasSpEffect(10000, 8330700))
        SetSpEffect(10000, 8330700);
    //Successful Parries Activate Golden Retaliation
    if (EventFlag(12000307) && !CharacterHasSpEffect(10000, 8350400))
        SetSpEffect(10000, 8350400);
    //Lightning upon Dodging
    if (EventFlag(12000308) && !CharacterHasSpEffect(10000, 8410100))
        SetSpEffect(10000, 8410100);
    //Guard Counters Activate Holy Attacks
    if (EventFlag(12000309) && !CharacterHasSpEffect(10000, 8420100))
        SetSpEffect(10000, 8420100);
    //Guard Counters Activate Summoning Attack
    if (EventFlag(12000310) && !CharacterHasSpEffect(10000, 8420200))
        SetSpEffect(10000, 8420200);
    //Improved Thrusting Counterattack (+20%)
    if (EventFlag(12000311) && !CharacterHasSpEffect(10000, 8430000))
        SetSpEffect(10000, 8430000);
    //Ice Storm Surge Sprint
    if (EventFlag(12000312) && !CharacterHasSpEffect(10000, 8450100))
        SetSpEffect(10000, 8450100);
    //Flame of Frenzy While Walking
    if (EventFlag(12000313) && !CharacterHasSpEffect(10000, 8460200))
        SetSpEffect(10000, 8460200);
    //Violent Deluge of Star Rain While Walking
    if (EventFlag(12000314) && !CharacterHasSpEffect(10000, 8460400))
        SetSpEffect(10000, 8460400);
});
    
//apply buffs from flags 2
$Event(99980005, Default, function() {
    //Periodical Giant Glintblades
    if (EventFlag(12000315) && !CharacterHasSpEffect(10000, 8530200))
        SetSpEffect(10000, 8530200);
    //Increased Damage after Critical Hit (+15%)
    if (EventFlag(12000316) && !CharacterHasSpEffect(10000, 8642000))
        SetSpEffect(10000, 8642000);
    //Critical Hits Inflict Blood Loss
    if (EventFlag(12000317) && !CharacterHasSpEffect(10000, 8660200))
        SetSpEffect(10000, 8660200);
    //Blood Loss in Vicinity Increases Attack Power (+20%)
    if (EventFlag(12000318) && !CharacterHasSpEffect(10000, 8710002))
        SetSpEffect(10000, 8710002);
    //Favor of the Rotted Woods
    if (EventFlag(12000319) && !CharacterHasSpEffect(10000, 6999200))
        SetSpEffect(10000, 6999200);
    //Favor of Noklateo, the Shrouded City
    if (EventFlag(12000320) && !CharacterHasSpEffect(10000, 6999100))
        SetSpEffect(10000, 6999100);
    //Increased Maximum HP (+10%)
    if (EventFlag(12000321) && !CharacterHasSpEffect(10000, 8000000))
        SetSpEffect(10000, 8000000);
    //Increased Maximum HP (+15%)
    if (EventFlag(12000322) && !CharacterHasSpEffect(10000, 8000001))
        SetSpEffect(10000, 8000001);
    //Improved Physical Damage Negation (+12%)
    if (EventFlag(12000323) && !CharacterHasSpEffect(10000, 8200000))
        SetSpEffect(10000, 8200000);
    //Improved Physical Damage Negation (+18%)
    if (EventFlag(12000324) && !CharacterHasSpEffect(10000, 8200001))
        SetSpEffect(10000, 8200001);
    //Improved Affinity Damage Negation (+12%)
    if (EventFlag(12000325) && !CharacterHasSpEffect(10000, 8200500))
        SetSpEffect(10000, 8200500);
    //Improved Affinity Damage Negation (+18%)
    if (EventFlag(12000326) && !CharacterHasSpEffect(10000, 8200501))
        SetSpEffect(10000, 8200501);
    //All Resistances Up (+57)
    if (EventFlag(12000327) && !CharacterHasSpEffect(10000, 8210700))
        SetSpEffect(10000, 8210700);
    //All Resistances Up (+75)
    if (EventFlag(12000328) && !CharacterHasSpEffect(10000, 8210701))
        SetSpEffect(10000, 8210701);
    //Improved Poise (+25%)
    if (EventFlag(12000329) && !CharacterHasSpEffect(10000, 8230000))
        SetSpEffect(10000, 8230000);
});

//apply buffs from flags 3
$Event(99980006, Default, function() {
    //Improved Poise (+38%)
    if (EventFlag(12000330) && !CharacterHasSpEffect(10000, 8230001))
        SetSpEffect(10000, 8230001);
    //Improved Dodging
    if (EventFlag(12000331) && !CharacterHasSpEffect(10000, 8410000))
        SetSpEffect(10000, 8410000);
    //Improved Flask HP Restoration (+20%)
    if (EventFlag(12000332) && !CharacterHasSpEffect(10000, 8440000))
        SetSpEffect(10000, 8440000);
    //Improved Flask HP Restoration (+30%)
    if (EventFlag(12000333) && !CharacterHasSpEffect(10000, 8440001))
        SetSpEffect(10000, 8440001);
    //Gradual Restoration by Flask
    if (EventFlag(12000334) && !CharacterHasSpEffect(10000, 8440200))
        SetSpEffect(10000, 8440200);
    //HP Restoration upon Successive Attacks (+3%)
    if (EventFlag(12000335) && !CharacterHasSpEffect(10000, 8610000))
        SetSpEffect(10000, 8610000);
    //Critical Hit HP Restoration (+10%)
    if (EventFlag(12000336) && !CharacterHasSpEffect(10000, 8640000))
        SetSpEffect(10000, 8640000);
    //HP Recovery From Successful Guarding (+10)
    if (EventFlag(12000337) && !CharacterHasSpEffect(10000, 8650000))
        SetSpEffect(10000, 8650000);
    //Poison & Rot Trigger Continuous HP Recovery (+7)
    if (EventFlag(12000338) && !CharacterHasSpEffect(10000, 8700002))
        SetSpEffect(10000, 8700002);
    //Favor of the Night (Improved Art Gauge charge)
    if (EventFlag(12000339) && !CharacterHasSpEffect(10000, 6999000))
        SetSpEffect(10000, 6999000);
    //Favor of the Mountaintop
    if (EventFlag(12000340) && !CharacterHasSpEffect(10000, 6999300))
        SetSpEffect(10000, 6999300);
    //Increased Maximum FP (+10%)
    if (EventFlag(12000341) && !CharacterHasSpEffect(10000, 8010000))
        SetSpEffect(10000, 8010000);
    //Increased Maximum FP (+15%)
    if (EventFlag(12000342) && !CharacterHasSpEffect(10000, 8010001))
        SetSpEffect(10000, 8010001);
    //Reduced FP Consumption (+10%)
    if (EventFlag(12000343) && !CharacterHasSpEffect(10000, 8010100))
        SetSpEffect(10000, 8010100);
    //Reduced FP Consumption (+15%)
    if (EventFlag(12000344) && !CharacterHasSpEffect(10000, 8010101))
        SetSpEffect(10000, 8010101);
});

//apply buffs from flags 4
$Event(99980007, Default, function() {
    //Increased Max Stamina (+10%)
    if (EventFlag(12000345) && !CharacterHasSpEffect(10000, 8020000))
        SetSpEffect(10000, 8020000);
    //Increased Max Stamina (+15%)
    if (EventFlag(12000346) && !CharacterHasSpEffect(10000, 8020001))
        SetSpEffect(10000, 8020001);
    //Improved Stamina Recovery (+4)
    if (EventFlag(12000347) && !CharacterHasSpEffect(10000, 8020200))
        SetSpEffect(10000, 8020200);
    //Improved Stamina Recovery (+6)
    if (EventFlag(12000348) && !CharacterHasSpEffect(10000, 8020201))
        SetSpEffect(10000, 8020201);
    //Improved Sorceries and Incantations (+7%)
    if (EventFlag(12000349) && !CharacterHasSpEffect(10000, 8330103))
        SetSpEffect(10000, 8330103);
    //Improved Sorceries and Incantations (+11%)
    if (EventFlag(12000350) && !CharacterHasSpEffect(10000, 8330104))
        SetSpEffect(10000, 8330104);
    //Extended Sorcery and Incantation Duration (+100%)
    if (EventFlag(12000351) && !CharacterHasSpEffect(10000, 8330500))
        SetSpEffect(10000, 8330500);
    //Improved Ultimate Art Gauge Charge Speed (+6%)
    if (EventFlag(12000352) && !CharacterHasSpEffect(10000, 8360000))
        SetSpEffect(10000, 8360000);
    //Character Skill Cooldown Reduction (+10%)
    if (EventFlag(12000353) && !CharacterHasSpEffect(10000, 8370000))
        SetSpEffect(10000, 8370000);
    //FP Restoration upon Successive Attacks (+10%)
    if (EventFlag(12000354) && !CharacterHasSpEffect(10000, 8610100))
        SetSpEffect(10000, 8610100);
    //Critical Hit FP Restoration (+10%)
    if (EventFlag(12000355) && !CharacterHasSpEffect(10000, 8640100))
        SetSpEffect(10000, 8640100);
    //FP Recovery From Successful Guarding (+2)
    if (EventFlag(12000356) && !CharacterHasSpEffect(10000, 8650100))
        SetSpEffect(10000, 8650100);
    //Creates Holy Ground at Low HP
    if (EventFlag(12000357) && !CharacterHasSpEffect(10000, 8660300))
        SetSpEffect(10000, 8660300);
    //Unifying Fate (Flask also restores FP)
    if (EventFlag(12000358) && !CharacterHasSpEffect(10000, 8970020))
        SetSpEffect(10000, 8970020);
});

//set default flags (1.0)
$Event(99980002, Default, function() {
    EndIf(EventFlag(12000201));
    SetEventFlagID(12001000, ON); //boss variants
    SetEventFlagID(12001006, ON);
    SetEventFlagID(12001012, ON);
    SetEventFlagID(12001018, ON);
    SetEventFlagID(12001024, ON);
    SetEventFlagID(12001030, ON);
    SetEventFlagID(12001036, ON);
    SetEventFlagID(12001042, ON);
    SetEventFlagID(12001048, ON);
    SetEventFlagID(12001054, ON);
    SetEventFlagID(12001060, ON);
    SetEventFlagID(12001066, ON);
    SetEventFlagID(12001072, ON);
    SetEventFlagID(12001078, ON);
    SetEventFlagID(12001084, ON);
    SetEventFlagID(12001090, ON);
    SetEventFlagID(12001096, ON);
    SetEventFlagID(12001102, ON);
    SetEventFlagID(12001108, ON);
    SetEventFlagID(12001114, ON);
    SetEventFlagID(12001120, ON);
    SetEventFlagID(12001126, ON);
    SetEventFlagID(12001132, ON);
    SetEventFlagID(12001138, ON);
    SetEventFlagID(12001144, ON);
    SetEventFlagID(12001150, ON);
    SetEventFlagID(12001156, ON);
    SetEventFlagID(12001162, ON);
    SetEventFlagID(12001168, ON);
    SetEventFlagID(12001174, ON);
    SetEventFlagID(12001180, ON);
    SetEventFlagID(12001186, ON);
    SetEventFlagID(12001192, ON);
    SetEventFlagID(12001198, ON);
    SetEventFlagID(12001204, ON);
    SetEventFlagID(12001210, ON);
    SetEventFlagID(12001216, ON);
    SetEventFlagID(12001222, ON);
    SetEventFlagID(12001228, ON);
    SetEventFlagID(12001234, ON);
    SetEventFlagID(12001240, ON);
    SetEventFlagID(12001246, ON);
    SetEventFlagID(12001938, ON);
    SetEventFlagID(12001257, ON);
    SetEventFlagID(12001263, ON);
    SetEventFlagID(12001269, ON);
    SetEventFlagID(12001275, ON);
    SetEventFlagID(12001281, ON);
    SetEventFlagID(12001287, ON);
    SetEventFlagID(12001293, ON);
    SetEventFlagID(12001299, ON);
    SetEventFlagID(12001305, ON);
    SetEventFlagID(12001311, ON);
    SetEventFlagID(12001317, ON);
    SetEventFlagID(12001323, ON);
    SetEventFlagID(12001329, ON);
    SetEventFlagID(12001335, ON);
    SetEventFlagID(12001341, ON);
    SetEventFlagID(12001347, ON);
    SetEventFlagID(12001353, ON);
    SetEventFlagID(12001359, ON);
    SetEventFlagID(12001365, ON);
    SetEventFlagID(12001371, ON);
    SetEventFlagID(12001377, ON);
    SetEventFlagID(12001383, ON);
    SetEventFlagID(12001389, ON);
    SetEventFlagID(12001395, ON);
    SetEventFlagID(12001401, ON);
    SetEventFlagID(12001407, ON);
    SetEventFlagID(12001413, ON);
    SetEventFlagID(12001419, ON);
    SetEventFlagID(12001425, ON);
    SetEventFlagID(12001431, ON);
    SetEventFlagID(12001437, ON);
    SetEventFlagID(12001443, ON);
    SetEventFlagID(12001449, ON);
    SetEventFlagID(12001455, ON);
    SetEventFlagID(12001461, ON);
    SetEventFlagID(12001467, ON);
    SetEventFlagID(12001473, ON);
    SetEventFlagID(12001479, ON);
    SetEventFlagID(12001485, ON);
    SetEventFlagID(12001491, ON);
    SetEventFlagID(12001497, ON);
    SetEventFlagID(12001503, ON);
    SetEventFlagID(12001509, ON);
    SetEventFlagID(12001515, ON);
    SetEventFlagID(12001521, ON);
    SetEventFlagID(12001527, ON);
    SetEventFlagID(12001533, ON);
    SetEventFlagID(12001539, ON);
    SetEventFlagID(12001545, ON);
    SetEventFlagID(12001551, ON);
    SetEventFlagID(12001557, ON);
    SetEventFlagID(12001563, ON);
    SetEventFlagID(12001569, ON);
    SetEventFlagID(12001575, ON);
    SetEventFlagID(12001581, ON);
    SetEventFlagID(12001587, ON);
    SetEventFlagID(12001593, ON);
    SetEventFlagID(12001599, ON);
    SetEventFlagID(12001605, ON);
    SetEventFlagID(12001611, ON);
    SetEventFlagID(12001617, ON);
    SetEventFlagID(12001623, ON);
    SetEventFlagID(12001719, ON);
    SetEventFlagID(12001721, ON);
    SetEventFlagID(12001723, ON);
    SetEventFlagID(12001725, ON);
    SetEventFlagID(12001727, ON);
    SetEventFlagID(12001729, ON);
    SetEventFlagID(12001731, ON);
    SetEventFlagID(12001733, ON);
    SetEventFlagID(12001735, ON);
    SetEventFlagID(12001737, ON);
    SetEventFlagID(12001739, ON);
    SetEventFlagID(12001741, ON);
    SetEventFlagID(12001743, ON);
    SetEventFlagID(12001745, ON);
    SetEventFlagID(12001747, ON);
    SetEventFlagID(12001749, ON);
    SetEventFlagID(12001751, ON);
    SetEventFlagID(12001753, ON);
    SetEventFlagID(12001755, ON);
    SetEventFlagID(12001757, ON);
    SetEventFlagID(12001759, ON);
    SetEventFlagID(12001761, ON);
    SetEventFlagID(12001763, ON);
    SetEventFlagID(12001765, ON);
    SetEventFlagID(12001767, ON);
    SetEventFlagID(12001769, ON);
    SetEventFlagID(12001771, ON);
    SetEventFlagID(12001773, ON);
    SetEventFlagID(12001775, ON);
    SetEventFlagID(12001777, ON);
    SetEventFlagID(12001779, ON);
    SetEventFlagID(12001781, ON);
    SetEventFlagID(12001783, ON);
    SetEventFlagID(12001785, ON);
    SetEventFlagID(12001787, ON);
    SetEventFlagID(12001789, ON);
    SetEventFlagID(12001791, ON);
    SetEventFlagID(12001793, ON);
    SetEventFlagID(12001795, ON);
    SetEventFlagID(12001797, ON);
    SetEventFlagID(12001799, ON);
    SetEventFlagID(12001801, ON);
    SetEventFlagID(12001803, ON);
    SetEventFlagID(12001805, ON);
    SetEventFlagID(12001807, ON);
    SetEventFlagID(12001809, ON);
    SetEventFlagID(12001811, ON);
    SetEventFlagID(12001813, ON);
    SetEventFlagID(12001815, ON);
    SetEventFlagID(12001817, ON);
    SetEventFlagID(12001819, ON);
    SetEventFlagID(12001821, ON);
    SetEventFlagID(12001823, ON);
    SetEventFlagID(12001825, ON);
    SetEventFlagID(12001827, ON);
    SetEventFlagID(12001829, ON);
    SetEventFlagID(12001831, ON);
    SetEventFlagID(12001833, ON);
    SetEventFlagID(12001835, ON);
    SetEventFlagID(12001837, ON);
    SetEventFlagID(12001839, ON);
    SetEventFlagID(12001841, ON);
    SetEventFlagID(12001843, ON);
    SetEventFlagID(12001845, ON);
    SetEventFlagID(12001847, ON);
    SetEventFlagID(12001849, ON);
    SetEventFlagID(12001851, ON);
    SetEventFlagID(12001853, ON);
    SetEventFlagID(12001855, ON);
    SetEventFlagID(12001857, ON);
    SetEventFlagID(12001859, ON);
    SetEventFlagID(12001861, ON);
    SetEventFlagID(12001863, ON);
    SetEventFlagID(12001865, ON);
    SetEventFlagID(12001867, ON);
    SetEventFlagID(12001869, ON);
    SetEventFlagID(12001871, ON);
    SetEventFlagID(12001873, ON);
    SetEventFlagID(12001875, ON);
    SetEventFlagID(12001877, ON);
    SetEventFlagID(12001879, ON);
    SetEventFlagID(12001881, ON);
    SetEventFlagID(12001885, ON);
    SetEventFlagID(12001889, ON);
    SetEventFlagID(12001891, ON);
    SetEventFlagID(12001893, ON);
    SetEventFlagID(12001897, ON);
    SetEventFlagID(12001900, ON);
    SetEventFlagID(12001902, ON);
    SetEventFlagID(12001904, ON);
    SetEventFlagID(12001906, ON);
    SetEventFlagID(12001908, ON);
    SetEventFlagID(12001910, ON);
    SetEventFlagID(12001913, ON);
    SetEventFlagID(12001915, ON);
    SetEventFlagID(12001917, ON);
    SetEventFlagID(12001921, ON);
    SetEventFlagID(12001923, ON);
    SetEventFlagID(12001926, ON);
    SetEventFlagID(12001928, ON);
    SetEventFlagID(12001930, ON);
    SetEventFlagID(12001932, ON);
    SetEventFlagID(12001934, ON);
    SetEventFlagID(12001936, ON);
    SetEventFlagID(12000206, ON); //respawn location: always ask
    SetEventFlagID(12000207, ON); //solo revive enabled
    SetEventFlagID(12000201, ON); //event has run
});

//set default flags (1.0.3)
$Event(99980008, Default, function() {
    EndIf(EventFlag(12000211));
    SetEventFlagID(12000215, ON); //spawn grace after boss defeat
    SetEventFlagID(12000217, ON); //enable blinking messages
    SetEventFlagID(12000211, ON); //event has run
});

//set default flags (2.0)
$Event(99980010, Default, function() {
    EndIf(EventFlag(12000218));
    SetEventFlagID(12000430, ON); //random target: regular only
    SetEventFlagID(12000434, ON); //boss rush: depth 0
    SetEventFlagID(12000218, ON); //event has run
});

//return to roundtable from grace
$Event(99980011, Default, function() {
    WaitFor(EventFlag(12005219)); //esd trigger
    WarpPlayer(10, 0, 0, 0, 10002200, 0);
});

//single boss selection ESD trigger
$Event(10004000, Default, function() {
    WaitFor(AnyBatchEventFlags(12005000, 12005199)); //esd triggers
    if (EventFlag(12000212)) { //if boss rush active, restart
        WaitFixedTimeSeconds(1);
        RestartEvent();
    }
    SetEventFlagID(12000200, ON); //enable rematch
    SetEventFlagID(12000212, OFF); //boss rush not active
    if (EventFlag(12000207)) //if solo revive enabled
        SetSpEffect(20000, 6999500); //enable revive
    else
        ClearSpEffect(20000, 6999500); //disable revive
    $InitializeCommonEvent(0, 99991001);
    $InitializeCommonEvent(0, 99991002);
});

//expedition boss rush ESD triggers
$Event(10004001, Default, function() {
    WaitFor(AnyBatchEventFlags(12005400, 12005429));
    SetEventFlagID(12000200, OFF); //disable rematch
    SetEventFlagID(12000212, ON); //boss rush active
    BatchSetEventFlags(12000401, 12000429, OFF); //reset target selection
    if (EventFlag(12000207)) //if solo revive enabled
        SetSpEffect(20000, 6999500); //enable revive
    else
        ClearSpEffect(20000, 6999500); //enable revive
    //Target: Random
    if (EventFlag(12005400)) {
        if (EventFlag(12000430)) //regular only
            RandomlySetEventFlagInRange(12000401, 12000408, ON);
        else if (EventFlag(12000431)) //everdark only
            RandomlySetEventFlagInRange(12000409, 12000415, ON);
        else if (EventFlag(12000432)) //regular + everdark
            RandomlySetEventFlagInRange(12000401, 12000415, ON);
    }
    //Target: Tricephalos
    else if (EventFlag(12005401))
        SetEventFlagID(12000401, ON);
    //Target: Gaping Jaw
    else if (EventFlag(12005402))
        SetEventFlagID(12000402, ON);
    //Target: Sentient Pest
    else if (EventFlag(12005403))
        SetEventFlagID(12000403, ON);
    //Target: Augur
    else if (EventFlag(12005404))
        SetEventFlagID(12000404, ON);
    //Target: Equilibrious Beast
    else if (EventFlag(12005405))
        SetEventFlagID(12000405, ON);
    //Target: Darkdrift Knight
    else if (EventFlag(12005406))
        SetEventFlagID(12000406, ON);
    //Target: Fissure in the Fog
    else if (EventFlag(12005407))
        SetEventFlagID(12000407, ON);
    //Target: Night Aspect
    else if (EventFlag(12005408))
        SetEventFlagID(12000408, ON);
    //Target: Tricephalos (Everdark)
    else if (EventFlag(12005409))
        SetEventFlagID(12000409, ON);
    //Target: Gaping Jaw (Everdark)
    else if (EventFlag(12005410))
        SetEventFlagID(12000410, ON);
    //Target: Sentient Pest (Everdark)
    else if (EventFlag(12005411))
        SetEventFlagID(12000411, ON);
    //Target: Augur (Everdark)
    else if (EventFlag(12005412))
        SetEventFlagID(12000412, ON);
    //Target: Equilibrious Beast (Everdark)
    else if (EventFlag(12005413))
        SetEventFlagID(12000413, ON);
    //Target: Darkdrift Knight (Everdark)
    else if (EventFlag(12005414))
        SetEventFlagID(12000414, ON);
    //Target: Fissure in the Fog (Everdark)
    else if (EventFlag(12005415))
        SetEventFlagID(12000415, ON);
    ClearEventValue(8145, 4); //reset evergaol count
    ClearEventValue(12000450, 8); //reset round counter
    IncrementEventValue(12000450, 8, 1000); //set round 1
    $InitializeCommonEvent(0, 99993004); //reset character
    $InitializeCommonEvent(0, 99993005); //clear all buffs
    ClearEventValue(12000460, 4); //reset level value
    IncrementEventValue(12000460, 4, 15); //set level 1
    SetEventFlagID(12000213, OFF); //reset boss defeated flag
    WaitFixedTimeFrames(1);
    $InitializeCommonEvent(0, 99993000); //boss rush init
});

//flasks menu refill and dialogs
$Event(10004100, Default, function() {
    WaitFor(AnyBatchEventFlags(12005205, 12005207));
    if (EventFlag(12005205)) //charges already at max
        DisplayBlinkingMessageWithPriority(7232902, 0, 1);
    else if (EventFlag(12005206)) //charges already at base value
        DisplayBlinkingMessageWithPriority(7232903, 0, 1);
    else if (EventFlag(12005207)) //flask refill
        RefillEstus();
    BatchSetEventFlags(12005205, 12005207, OFF);
    RestartEvent();
});

//award shop items: remembrance outfits
$Event(10004101, Default, function() {
    WaitFor(EventFlag(12005208));
    SetEventFlagID(12005208, OFF);
    if (!PlayerHasItem(ItemType.Goods, 40030))
        AwardItemLot(101015);
    if (!PlayerHasItem(ItemType.Goods, 40530))
        AwardItemLot(108015);
    if (!PlayerHasItem(ItemType.Goods, 40130))
        AwardItemLot(107015);
    if (!PlayerHasItem(ItemType.Goods, 40230))
        AwardItemLot(106020);
    if (!PlayerHasItem(ItemType.Goods, 40430))
        AwardItemLot(103020);
    if (!PlayerHasItem(ItemType.Goods, 40630))
        AwardItemLot(105030);
    if (!PlayerHasItem(ItemType.Goods, 40330))
        AwardItemLot(102020);
    if (!PlayerHasItem(ItemType.Goods, 40730))
        AwardItemLot(104000);
});

//award shop items: remembrance vessels
$Event(10004102, Default, function() {
    WaitFor(EventFlag(12005209));
    SetEventFlagID(12005209, OFF);
    if (!PlayerHasItem(ItemType.Goods, 9605))
        AwardItemLot(107030);
    if (!PlayerHasItem(ItemType.Goods, 9620))
        AwardItemLot(105000);
    if (!PlayerHasItem(ItemType.Goods, 9623))
        AwardItemLot(104015);
    if (!PlayerHasItem(ItemType.Goods, 9602))
        AwardItemLot(101020);
    if (!PlayerHasItem(ItemType.Goods, 9614))
        AwardItemLot(103010);
    if (!PlayerHasItem(ItemType.Goods, 9608))
        AwardItemLot(106005);
    if (!PlayerHasItem(ItemType.Goods, 9611))
        AwardItemLot(102000);
    if (!PlayerHasItem(ItemType.Goods, 9617))
        AwardItemLot(108020);
});

//award shop items: unique relics 1
$Event(10004103, Default, function() {
    WaitFor(EventFlag(12005210));
    SetEventFlagID(12005210, OFF);
    if (!PlayerHasItem(ItemType.Antique, 10002))
        AwardItemLot(100102);
    if (!PlayerHasItem(ItemType.Antique, 11001))
        AwardItemLot(101000);
    if (!PlayerHasItem(ItemType.Antique, 11002))
        AwardItemLot(101011);
    if (!PlayerHasItem(ItemType.Antique, 11000))
        AwardItemLot(101030);
    if (!PlayerHasItem(ItemType.Antique, 14001))
        AwardItemLot(102010);
    if (!PlayerHasItem(ItemType.Antique, 14002))
        AwardItemLot(102030);
    if (!PlayerHasItem(ItemType.Antique, 14000))
        AwardItemLot(102040);
    if (!PlayerHasItem(ItemType.Antique, 15000))
        AwardItemLot(103000);
    if (!PlayerHasItem(ItemType.Antique, 15002))
        AwardItemLot(103030);
    if (!PlayerHasItem(ItemType.Antique, 18000))
        AwardItemLot(104011);
    if (!PlayerHasItem(ItemType.Antique, 18002))
        AwardItemLot(104030);
    if (!PlayerHasItem(ItemType.Antique, 17001))
        AwardItemLot(105010);
    if (!PlayerHasItem(ItemType.Antique, 17002))
        AwardItemLot(105020);
    if (!PlayerHasItem(ItemType.Antique, 13001))
        AwardItemLot(106001);
    if (!PlayerHasItem(ItemType.Antique, 13002))
        AwardItemLot(106030);
    if (!PlayerHasItem(ItemType.Antique, 12001))
        AwardItemLot(107000);
    $InitializeEvent(0, 10004104);
});

//award shop items: unique relics 2
$Event(10004104, Default, function() {
    if (!PlayerHasItem(ItemType.Antique, 12002) && !PlayerHasItem(ItemType.Antique, 12003))
        AwardItemLot(107011);
    if (!PlayerHasItem(ItemType.Antique, 12000))
        AwardItemLot(107040);
    if (!PlayerHasItem(ItemType.Antique, 16001))
        AwardItemLot(108000);
    if (!PlayerHasItem(ItemType.Antique, 16002))
        AwardItemLot(108011);
    if (!PlayerHasItem(ItemType.Antique, 2000))
        AwardItemLot(120000);
    if (!PlayerHasItem(ItemType.Antique, 2010))
        AwardItemLot(120005);
    if (!PlayerHasItem(ItemType.Antique, 2020))
        AwardItemLot(120010);
    if (!PlayerHasItem(ItemType.Antique, 2030))
        AwardItemLot(120015);
    if (!PlayerHasItem(ItemType.Antique, 2040))
        AwardItemLot(120020);
    if (!PlayerHasItem(ItemType.Antique, 2050))
        AwardItemLot(120025);
    if (!PlayerHasItem(ItemType.Antique, 2060))
        AwardItemLot(120030);
    if (!PlayerHasItem(ItemType.Antique, 2100))
        AwardItemLot(120035);
});

//clear buffs
$Event(10004105, Default, function() {
    WaitFor(AnyBatchEventFlags(12005300, 12005358));
    //Improved Physical Attack Power (+6%)
    if (EventFlag(12005300))
        ClearSpEffect(10000, 8100000);
    //Improved Physical Attack Power (+9%)
    else if (EventFlag(12005301))
        ClearSpEffect(10000, 8100001);
    //Improved Affinity Attack Power (+5%)
    else if (EventFlag(12005302))
        ClearSpEffect(10000, 8100500);
    //Improved Affinity Attack Power (+8%)
    else if (EventFlag(12005303))
        ClearSpEffect(10000, 8100501);
    //Improved Stance-Breaking (+10%)
    else if (EventFlag(12005304))
        ClearSpEffect(10000, 8120000);
    //Improved Stance-Breaking (+15%)
    else if (EventFlag(12005305))
        ClearSpEffect(10000, 8120001);
    //Dragonwound upon Dragon Communion
    else if (EventFlag(12005306))
        ClearSpEffect(10000, 8330700);
    //Successful Parries Activate Golden Retaliation
    else if (EventFlag(12005307))
        ClearSpEffect(10000, 8350400);
    //Lightning upon Dodging
    else if (EventFlag(12005308))
        ClearSpEffect(10000, 8410100);
    //Guard Counters Activate Holy Attacks
    else if (EventFlag(12005309))
        ClearSpEffect(10000, 8420100);
    //Guard Counters Activate Summoning Attack
    else if (EventFlag(12005310))
        ClearSpEffect(10000, 8420200);
    //Improved Thrusting Counterattack (+20%)
    else if (EventFlag(12005311))
        ClearSpEffect(10000, 8430000);
    //Ice Storm Surge Sprint
    else if (EventFlag(12005312))
        ClearSpEffect(10000, 8450100);
    //Flame of Frenzy While Walking
    else if (EventFlag(12005313))
        ClearSpEffect(10000, 8460200);
    //Violent Deluge of Star Rain While Walking
    else if (EventFlag(12005314))
        ClearSpEffect(10000, 8460400);
    //Periodical Giant Glintblades
    else if (EventFlag(12005315))
        ClearSpEffect(10000, 8530200);
    //Increased Damage after Critical Hit (+15%)
    else if (EventFlag(12005316))
        ClearSpEffect(10000, 8642000);
    //Critical Hits Inflict Blood Loss
    else if (EventFlag(12005317))
        ClearSpEffect(10000, 8660200);
    //Blood Loss in Vicinity Increases Attack Power (+20%)
    else if (EventFlag(12005318))
        ClearSpEffect(10000, 8710002);
    //Favor of the Rotted Woods
    else if (EventFlag(12005319))
        ClearSpEffect(10000, 6999200);
    //Favor of Noklateo, the Shrouded City
    else if (EventFlag(12005320))
        ClearSpEffect(10000, 6999100);
    //Increased Maximum HP (+10%)
    else if (EventFlag(12005321))
        ClearSpEffect(10000, 8000000);
    //Increased Maximum HP (+15%)
    else if (EventFlag(12005322))
        ClearSpEffect(10000, 8000001);
    //Improved Physical Damage Negation (+12%)
    else if (EventFlag(12005323))
        ClearSpEffect(10000, 8200000);
    //Improved Physical Damage Negation (+18%)
    else if (EventFlag(12005324))
        ClearSpEffect(10000, 8200001);
    //Improved Affinity Damage Negation (+12%)
    else if (EventFlag(12005325))
        ClearSpEffect(10000, 8200500);
    //Improved Affinity Damage Negation (+18%)
    else if (EventFlag(12005326))
        ClearSpEffect(10000, 8200501);
    //All Resistances Up (+57)
    else if (EventFlag(12005327))
        ClearSpEffect(10000, 8210700);
    //All Resistances Up (+75)
    else if (EventFlag(12005328))
        ClearSpEffect(10000, 8210701);
    //Improved Poise (+25%)
    else if (EventFlag(12005329))
        ClearSpEffect(10000, 8230000);
    //Improved Poise (+38%)
    else if (EventFlag(12005330))
        ClearSpEffect(10000, 8230001);
    //Improved Dodging
    else if (EventFlag(12005331))
        ClearSpEffect(10000, 8410000);
    //Improved Flask HP Restoration (+20%)
    else if (EventFlag(12005332))
        ClearSpEffect(10000, 8440000);
    //Improved Flask HP Restoration (+30%)
    else if (EventFlag(12005333))
        ClearSpEffect(10000, 8440001);
    //Gradual Restoration by Flask
    else if (EventFlag(12005334))
        ClearSpEffect(10000, 8440200);
    //HP Restoration upon Successive Attacks (+3%)
    else if (EventFlag(12005335))
        ClearSpEffect(10000, 8610000);
    //Critical Hit HP Restoration (+10%)
    else if (EventFlag(12005336))
        ClearSpEffect(10000, 8640000);
    //HP Recovery From Successful Guarding (+10)
    else if (EventFlag(12005337))
        ClearSpEffect(10000, 8650000);
    //Poison & Rot Trigger Continuous HP Recovery (+7)
    else if (EventFlag(12005338))
        ClearSpEffect(10000, 8700002);
    //Favor of the Night (Improved Art Gauge charge)
    else if (EventFlag(12005339))
        ClearSpEffect(10000, 6999000);
    //Favor of the Mountaintop
    else if (EventFlag(12005340))
        ClearSpEffect(10000, 6999300);
    //Increased Maximum FP (+10%)
    else if (EventFlag(12005341))
        ClearSpEffect(10000, 8010000);
    //Increased Maximum FP (+15%)
    else if (EventFlag(12005342))
        ClearSpEffect(10000, 8010001);
    //Reduced FP Consumption (+10%)
    else if (EventFlag(12005343))
        ClearSpEffect(10000, 8010100);
    //Reduced FP Consumption (+15%)
    else if (EventFlag(12005344))
        ClearSpEffect(10000, 8010101);
    //Increased Max Stamina (+10%)
    else if (EventFlag(12005345))
        ClearSpEffect(10000, 8020000);
    //Increased Max Stamina (+15%)
    else if (EventFlag(12005346))
        ClearSpEffect(10000, 8020001);
    //Improved Stamina Recovery (+4)
    else if (EventFlag(12005347))
        ClearSpEffect(10000, 8020200);
    //Improved Stamina Recovery (+6)
    else if (EventFlag(12005348))
        ClearSpEffect(10000, 8020201);
    //Improved Sorceries and Incantations (+7%)
    else if (EventFlag(12005349))
        ClearSpEffect(10000, 8330103);
    //Improved Sorceries and Incantations (+11%)
    else if (EventFlag(12005350))
        ClearSpEffect(10000, 8330104);
    //Extended Sorcery and Incantation Duration (+100%)
    else if (EventFlag(12005351))
        ClearSpEffect(10000, 8330500);
    //Improved Ultimate Art Gauge Charge Speed (+6%)
    else if (EventFlag(12005352))
        ClearSpEffect(10000, 8360000);
    //Character Skill Cooldown Reduction (+10%)
    else if (EventFlag(12005353))
        ClearSpEffect(10000, 8370000);
    //FP Restoration upon Successive Attacks (+10%)
    else if (EventFlag(12005354))
        ClearSpEffect(10000, 8610100);
    //Critical Hit FP Restoration (+10%)
    else if (EventFlag(12005355))
        ClearSpEffect(10000, 8640100);
    //FP Recovery From Successful Guarding (+2)
    else if (EventFlag(12005356))
        ClearSpEffect(10000, 8650100);
    //Creates Holy Ground at Low HP
    else if (EventFlag(12005357))
        ClearSpEffect(10000, 8660300);
    //Unifying Fate (Flask also restores FP)
    else if (EventFlag(12005358))
        ClearSpEffect(10000, 8970020);    
    BatchSetEventFlags(12005300, 12005358, OFF);
    RestartEvent();
});

//clear all buffs
$Event(10004106, Default, function() {
    WaitFor(AnyBatchEventFlags(12005211, 12005214));
    if (EventFlag(12005211)) //clear all buffs
        Goto(S0);
    else if (EventFlag(12005212)) //clear offensive buffs
        Goto(S0);
    else if (EventFlag(12005213)) //clear defensive buffs
        Goto(S1);
    else if (EventFlag(12005214)) //clear multipurpose buffs
        Goto(S2);
S0: //offensive
    ClearSpEffect(10000, 8100000);
    ClearSpEffect(10000, 8100001);
    ClearSpEffect(10000, 8100500);
    ClearSpEffect(10000, 8100501);
    ClearSpEffect(10000, 8120000);
    ClearSpEffect(10000, 8120001);
    ClearSpEffect(10000, 8330700);
    ClearSpEffect(10000, 8350400);
    ClearSpEffect(10000, 8410100);
    ClearSpEffect(10000, 8420100);
    ClearSpEffect(10000, 8420200);
    ClearSpEffect(10000, 8430000);
    ClearSpEffect(10000, 8450100);
    ClearSpEffect(10000, 8460200);
    ClearSpEffect(10000, 8460400);
    ClearSpEffect(10000, 8530200);
    ClearSpEffect(10000, 8642000);
    ClearSpEffect(10000, 8660200);
    ClearSpEffect(10000, 8710002);
    if (EventFlag(12005212))
        Goto(S3);
S1: //defensive
    ClearSpEffect(10000, 6999200);
    ClearSpEffect(10000, 6999100);
    ClearSpEffect(10000, 8000000);
    ClearSpEffect(10000, 8000001);
    ClearSpEffect(10000, 8200000);
    ClearSpEffect(10000, 8200001);
    ClearSpEffect(10000, 8200500);
    ClearSpEffect(10000, 8200501);
    ClearSpEffect(10000, 8210700);
    ClearSpEffect(10000, 8210701);
    ClearSpEffect(10000, 8230000);
    ClearSpEffect(10000, 8230001);
    ClearSpEffect(10000, 8410000);
    ClearSpEffect(10000, 8440000);
    ClearSpEffect(10000, 8440001);
    ClearSpEffect(10000, 8440200);
    ClearSpEffect(10000, 8610000);
    ClearSpEffect(10000, 8640000);
    ClearSpEffect(10000, 8650000);
    ClearSpEffect(10000, 8700002);
    if (EventFlag(12005213))
        Goto(S3);
S2: //multipurpose
    ClearSpEffect(10000, 6999000);
    ClearSpEffect(10000, 6999300);
    ClearSpEffect(10000, 8010000);
    ClearSpEffect(10000, 8010001);
    ClearSpEffect(10000, 8010100);
    ClearSpEffect(10000, 8010101);
    ClearSpEffect(10000, 8020000);
    ClearSpEffect(10000, 8020001);
    ClearSpEffect(10000, 8020200);
    ClearSpEffect(10000, 8020201);
    ClearSpEffect(10000, 8330103);
    ClearSpEffect(10000, 8330104);
    ClearSpEffect(10000, 8330500);
    ClearSpEffect(10000, 8360000);
    ClearSpEffect(10000, 8370000);
    ClearSpEffect(10000, 8610100);
    ClearSpEffect(10000, 8640100);
    ClearSpEffect(10000, 8650100);
    ClearSpEffect(10000, 8660300);
    ClearSpEffect(10000, 8970020);
S3:
    if (EventFlag(12005211)) {
        DisplayBlinkingMessageWithPriority(7232904, 0, 1); //all buffs cleared
        BatchSetEventFlags(12000300, 12000358, OFF);
    }
    else if (EventFlag(12005212)) {
        DisplayBlinkingMessageWithPriority(7232905, 0, 1); //all offensive buffs cleared
        BatchSetEventFlags(12000300, 12000318, OFF);
    }
    else if (EventFlag(12005213)) {
        DisplayBlinkingMessageWithPriority(7232906, 0, 1); //all defensive buffs cleared
        BatchSetEventFlags(12000319, 12000338, OFF);
    }
    else if (EventFlag(12005214)) {
        DisplayBlinkingMessageWithPriority(7232907, 0, 1); //all multipurpose buffs cleared
        BatchSetEventFlags(12000339, 12000358, OFF);
    }
    BatchSetEventFlags(12005211, 12005214, OFF);
    RestartEvent();
});

//apply all buffs
$Event(10004107, Default, function() {
    WaitFor(AnyBatchEventFlags(12005215, 12005218));
    if (EventFlag(12005215)) //apply all buffs
        Goto(S0);
    else if (EventFlag(12005216)) //apply offensive buffs
        Goto(S0);
    else if (EventFlag(12005217)) //apply defensive buffs
        Goto(S1);
    else if (EventFlag(12005218)) //apply multipurpose buffs
        Goto(S2);
S0: //offensive
    if (!CharacterHasSpEffect(10000, 8100000))
        SetSpEffect(10000, 8100000);
    if (!CharacterHasSpEffect(10000, 8100001))
        SetSpEffect(10000, 8100001);
    if (!CharacterHasSpEffect(10000, 8100500))
        SetSpEffect(10000, 8100500);
    if (!CharacterHasSpEffect(10000, 8100501))
        SetSpEffect(10000, 8100501);
    if (!CharacterHasSpEffect(10000, 8120000))
        SetSpEffect(10000, 8120000);
    if (!CharacterHasSpEffect(10000, 8120001))
        SetSpEffect(10000, 8120001);
    if (!CharacterHasSpEffect(10000, 8330700))
        SetSpEffect(10000, 8330700);
    if (!CharacterHasSpEffect(10000, 8350400))
        SetSpEffect(10000, 8350400);
    if (!CharacterHasSpEffect(10000, 8410100))
        SetSpEffect(10000, 8410100);
    if (!CharacterHasSpEffect(10000, 8420100))
        SetSpEffect(10000, 8420100);
    if (!CharacterHasSpEffect(10000, 8420200))
        SetSpEffect(10000, 8420200);
    if (!CharacterHasSpEffect(10000, 8430000))
        SetSpEffect(10000, 8430000);
    if (!CharacterHasSpEffect(10000, 8450100))
        SetSpEffect(10000, 8450100);
    if (!CharacterHasSpEffect(10000, 8460200))
        SetSpEffect(10000, 8460200);
    if (!CharacterHasSpEffect(10000, 8460400))
        SetSpEffect(10000, 8460400);
    if (!CharacterHasSpEffect(10000, 8530200))
        SetSpEffect(10000, 8530200);
    if (!CharacterHasSpEffect(10000, 8642000))
        SetSpEffect(10000, 8642000);
    if (!CharacterHasSpEffect(10000, 8660200))
        SetSpEffect(10000, 8660200);
    if (!CharacterHasSpEffect(10000, 8710002))
        SetSpEffect(10000, 8710002);
    if (EventFlag(12005216))
        Goto(S3);
S1: //defensive
    if (!CharacterHasSpEffect(10000, 6999200))
        SetSpEffect(10000, 6999200);
    if (!CharacterHasSpEffect(10000, 6999100))
        SetSpEffect(10000, 6999100);
    if (!CharacterHasSpEffect(10000, 8000000))
        SetSpEffect(10000, 8000000);
    if (!CharacterHasSpEffect(10000, 8000001))
        SetSpEffect(10000, 8000001);
    if (!CharacterHasSpEffect(10000, 8200000))
        SetSpEffect(10000, 8200000);
    if (!CharacterHasSpEffect(10000, 8200001))
        SetSpEffect(10000, 8200001);
    if (!CharacterHasSpEffect(10000, 8200500))
        SetSpEffect(10000, 8200500);
    if (!CharacterHasSpEffect(10000, 8200501))
        SetSpEffect(10000, 8200501);
    if (!CharacterHasSpEffect(10000, 8210700))
        SetSpEffect(10000, 8210700);
    if (!CharacterHasSpEffect(10000, 8210701))
        SetSpEffect(10000, 8210701);
    if (!CharacterHasSpEffect(10000, 8230000))
        SetSpEffect(10000, 8230000);
    if (!CharacterHasSpEffect(10000, 8230001))
        SetSpEffect(10000, 8230001);
    if (!CharacterHasSpEffect(10000, 8410000))
        SetSpEffect(10000, 8410000);
    if (!CharacterHasSpEffect(10000, 8440000))
        SetSpEffect(10000, 8440000);
    if (!CharacterHasSpEffect(10000, 8440001))
        SetSpEffect(10000, 8440001);
    if (!CharacterHasSpEffect(10000, 8440200))
        SetSpEffect(10000, 8440200);
    if (!CharacterHasSpEffect(10000, 8610000))
        SetSpEffect(10000, 8610000);
    if (!CharacterHasSpEffect(10000, 8640000))
        SetSpEffect(10000, 8640000);
    if (!CharacterHasSpEffect(10000, 8650000))
        SetSpEffect(10000, 8650000);
    if (!CharacterHasSpEffect(10000, 8700002))
        SetSpEffect(10000, 8700002);
    if (EventFlag(12005217))
        Goto(S3);
S2: //multipurpose
    if (!CharacterHasSpEffect(10000, 6999000))
        SetSpEffect(10000, 6999000);
    if (!CharacterHasSpEffect(10000, 6999300))
        SetSpEffect(10000, 6999300);
    if (!CharacterHasSpEffect(10000, 8010000))
        SetSpEffect(10000, 8010000);
    if (!CharacterHasSpEffect(10000, 8010001))
        SetSpEffect(10000, 8010001);
    if (!CharacterHasSpEffect(10000, 8010100))
        SetSpEffect(10000, 8010100);
    if (!CharacterHasSpEffect(10000, 8010101))
        SetSpEffect(10000, 8010101);
    if (!CharacterHasSpEffect(10000, 8020000))
        SetSpEffect(10000, 8020000);
    if (!CharacterHasSpEffect(10000, 8020001))
        SetSpEffect(10000, 8020001);
    if (!CharacterHasSpEffect(10000, 8020200))
        SetSpEffect(10000, 8020200);
    if (!CharacterHasSpEffect(10000, 8020201))
        SetSpEffect(10000, 8020201);
    if (!CharacterHasSpEffect(10000, 8330103))
        SetSpEffect(10000, 8330103);
    if (!CharacterHasSpEffect(10000, 8330104))
        SetSpEffect(10000, 8330104);
    if (!CharacterHasSpEffect(10000, 8330500))
        SetSpEffect(10000, 8330500);
    if (!CharacterHasSpEffect(10000, 8360000))
        SetSpEffect(10000, 8360000);
    if (!CharacterHasSpEffect(10000, 8370000))
        SetSpEffect(10000, 8370000);
    if (!CharacterHasSpEffect(10000, 8610100))
        SetSpEffect(10000, 8610100);
    if (!CharacterHasSpEffect(10000, 8640100))
        SetSpEffect(10000, 8640100);
    if (!CharacterHasSpEffect(10000, 8650100))
        SetSpEffect(10000, 8650100);
    if (!CharacterHasSpEffect(10000, 8660300))
        SetSpEffect(10000, 8660300);
    if (!CharacterHasSpEffect(10000, 8970020))
        SetSpEffect(10000, 8970020);
S3:
    if (EventFlag(12005215)) {
        DisplayBlinkingMessageWithPriority(7232908, 0, 1); //all buffs applied
        BatchSetEventFlags(12000300, 12000358, ON);
    }
    else if (EventFlag(12005216)) {
        DisplayBlinkingMessageWithPriority(7232909, 0, 1); //all offensive buffs applied
        BatchSetEventFlags(12000300, 12000318, ON);
    }
    else if (EventFlag(12005217)) {
        DisplayBlinkingMessageWithPriority(7232910, 0, 1); //all defensive buffs applied
        BatchSetEventFlags(12000319, 12000338, ON);
    }
    else if (EventFlag(12005218)) {
        DisplayBlinkingMessageWithPriority(7232911, 0, 1); //all multipurpose buffs applied
        BatchSetEventFlags(12000339, 12000358, ON);
    }
    BatchSetEventFlags(12005215, 12005218, OFF);
    RestartEvent();
});

//show warning about active boss rush
$Event(10004108, Default, function() {
    EndIf(!PlayerInMap(10, 0, 0, 0)); //end if not at roundtable
    WaitFixedTimeSeconds(0.5);
    if (EventFlag(12000212))
        DisplayGenericDialog(7232912, 1, 1, 0, 1000);
});

//unlock characters and outfits
$Event(10004109, Default, function() {
    SetEventFlagID(6031, ON); //unlock duchess
    SetEventFlagID(6037, ON); //unlock revenant
    SetEventFlagID(6050, ON); //unlock garb change
});

//rematch 1 (minor bosses)
$Event(10004010, Default, function() {
    WaitFor(EventFlag(12005200)); //esd trigger
    SetEventFlagID(12005200, OFF);
    //Omen
    if (EventFlag(12000000))
        SetEventFlagID(12005000, ON);
    //Grave Warden Duelist
    else if (EventFlag(12000001))
        SetEventFlagID(12005001, ON);
    //Bloodhound Knight
    else if (EventFlag(12000002))
        SetEventFlagID(12005002, ON);
    //Stoneskin Lords
    else if (EventFlag(12000003))
        SetEventFlagID(12005003, ON);
    //Nox Warriors
    else if (EventFlag(12000004))
        SetEventFlagID(12005004, ON);
    //Beastly Brigade
    else if (EventFlag(12000005))
        SetEventFlagID(12005005, ON);
    //Beastmen of Farum Azula
    else if (EventFlag(12000006))
        SetEventFlagID(12005006, ON);
    //Crystalian Alliance
    else if (EventFlag(12000007))
        SetEventFlagID(12005007, ON);
    //Banished Knights
    else if (EventFlag(12000008))
        SetEventFlagID(12005008, ON);
    //Godskin Noble
    else if (EventFlag(12000009))
        SetEventFlagID(12005009, ON);
    //Godskin Apostle
    else if (EventFlag(12000010))
        SetEventFlagID(12005010, ON);
    //Crucible Knight (Treespear)
    else if (EventFlag(12000011))
        SetEventFlagID(12005011, ON);
    //Crucible Knight (Sword)
    else if (EventFlag(12000012))
        SetEventFlagID(12005012, ON);
    //Grafted Scion
    else if (EventFlag(12000013))
        SetEventFlagID(12005013, ON);
    //Black Knife Assassin
    else if (EventFlag(12000014))
        SetEventFlagID(12005014, ON);
    //Red Wolf of the King Consort
    else if (EventFlag(12000015))
        SetEventFlagID(12005015, ON);
    //Ancient Hero of Zamor
    else if (EventFlag(12000016))
        SetEventFlagID(12005016, ON);
    //Leonine Misbegotten
    else if (EventFlag(12000017))
        SetEventFlagID(12005017, ON);
    //Elder Lion
    else if (EventFlag(12000018))
        SetEventFlagID(12005018, ON);
    //Golden Hippopotamus
    else if (EventFlag(12000019))
        SetEventFlagID(12005019, ON);
    //Demi-Human Queen
    else if (EventFlag(12000020))
        SetEventFlagID(12005020, ON);
    //Miranda Blossom
    else if (EventFlag(12000021))
        SetEventFlagID(12005021, ON);
    //Night's Cavalry
    else if (EventFlag(12000022))
        SetEventFlagID(12005022, ON);
    //Flying Dragon of the Hills
    else if (EventFlag(12000023))
        SetEventFlagID(12005023, ON);
    //Erdtree Avatar
    else if (EventFlag(12000024))
        SetEventFlagID(12005024, ON);
    //Ancestor Spirit
    else if (EventFlag(12000025))
        SetEventFlagID(12005025, ON);
    //Tree Sentinel
    else if (EventFlag(12000026))
        SetEventFlagID(12005026, ON);
    //Magma Wyrm
    else if (EventFlag(12000027))
        SetEventFlagID(12005027, ON);
    //Royal Carian Knight
    else if (EventFlag(12000028))
        SetEventFlagID(12005028, ON);
    //Black Blade Kindred
    else if (EventFlag(12000029))
        SetEventFlagID(12005029, ON);
    //Draconic Tree Sentinel
    else if (EventFlag(12000030))
        SetEventFlagID(12005030, ON);
    //Guardian Golem
    else if (EventFlag(12000031))
        SetEventFlagID(12005031, ON);
    //Mausoleum Knight
    else if (EventFlag(12000032))
        SetEventFlagID(12005032, ON);
    //Fire Monk
    else if (EventFlag(12000033))
        SetEventFlagID(12005033, ON);
    //Oracle Envoys
    else if (EventFlag(12000034))
        SetEventFlagID(12005034, ON);
    //Lordsworn Captain
    else if (EventFlag(12000035))
        SetEventFlagID(12005035, ON);
    //Abductor Virgin
    else if (EventFlag(12000036))
        SetEventFlagID(12005036, ON);
    //Erdtree Burial Watchdogs
    else if (EventFlag(12000037))
        SetEventFlagID(12005037, ON);
    //Battlemages
    else if (EventFlag(12000038))
        SetEventFlagID(12005038, ON);
    //Albinaurics
    else if (EventFlag(12000039))
        SetEventFlagID(12005039, ON);
    //Sanguine Noble
    else if (EventFlag(12000040))
        SetEventFlagID(12005040, ON);
    //Albinauric Archers
    else if (EventFlag(12000041))
        SetEventFlagID(12005041, ON);
    //Beastmen of Farum Azula (Ruins)
    else if (EventFlag(12000042))
        SetEventFlagID(12005042, ON);
    //Crystalian Alliance (Fort)
    else if (EventFlag(12000043))
        SetEventFlagID(12005043, ON);
    //Dragonkin Soldier
    else if (EventFlag(12000044))
        SetEventFlagID(12005044, ON);
    //Wormface (Ruins)
    else if (EventFlag(12000045))
        SetEventFlagID(12005045, ON);
    //Flying Dragon
    else if (EventFlag(12000046))
        SetEventFlagID(12005046, ON);
    //Ancient Heroes of Zamor
    else if (EventFlag(12000047))
        SetEventFlagID(12005047, ON);
    //Guardian Golem (Greatbow)
    else if (EventFlag(12000048))
        SetEventFlagID(12005048, ON);
    //Perfumers
    else if (EventFlag(12000049))
        SetEventFlagID(12005049, ON);
    //Runebear
    else if (EventFlag(12000050))
        SetEventFlagID(12005050, ON);
    //Redmane Knights
    else if (EventFlag(12000051))
        SetEventFlagID(12005051, ON);
    //Flame Chariots
    else if (EventFlag(12000052))
        SetEventFlagID(12005052, ON);
    //Royal Army Knights
    else if (EventFlag(12000053))
        SetEventFlagID(12005053, ON);
    //Frenzied Flame Troll
    else if (EventFlag(12000054))
        SetEventFlagID(12005054, ON);
    //Fire Prelates
    else if (EventFlag(12000055))
        SetEventFlagID(12005055, ON);
    //Fallingstar Beast
    else if (EventFlag(12000056))
        SetEventFlagID(12005056, ON);
    //Snowfield Trolls
    else if (EventFlag(12000057))
        SetEventFlagID(12005057, ON);
    //Demi-Human Swordmaster
    else if (EventFlag(12000058))
        SetEventFlagID(12005058, ON);
    //Giant Crows
    else if (EventFlag(12000059))
        SetEventFlagID(12005059, ON);
    //Mountaintop Ice Dragon
    else if (EventFlag(12000060))
        SetEventFlagID(12005060, ON);
    //Headless Troll
    else if (EventFlag(12000061))
        SetEventFlagID(12005061, ON);
    //Naturalborn of the Void
    else if (EventFlag(12000062))
        SetEventFlagID(12005062, ON);
    else
        $InitializeEvent(0, 10004011);
});

//rematch 2 (night bosses + nightlords)
$Event(10004011, Default, function() {
    //Demi-Human Queen & Demi-Human Swordmaster
    if (EventFlag(12000063))
        SetEventFlagID(12005063, ON);
    //Bell Bearing Hunter
    else if (EventFlag(12000064))
        SetEventFlagID(12005064, ON);
    //Gaping Dragon
    else if (EventFlag(12000065))
        SetEventFlagID(12005065, ON);
    //Wormface (Night)
    else if (EventFlag(12000066))
        SetEventFlagID(12005066, ON);
    //Valiant Gargoyle
    else if (EventFlag(12000067))
        SetEventFlagID(12005067, ON);
    //The Duke's Dear Freja
    else if (EventFlag(12000068))
        SetEventFlagID(12005068, ON);
    //Night's Cavalry Duo
    else if (EventFlag(12000069))
        SetEventFlagID(12005069, ON);
    //Smelter Demon
    else if (EventFlag(12000070))
        SetEventFlagID(12005070, ON);
    //Battlefield Commander
    else if (EventFlag(12000071))
        SetEventFlagID(12005071, ON);
    //Centipede Demon
    else if (EventFlag(12000072))
        SetEventFlagID(12005072, ON);
    //Tibia Mariner
    else if (EventFlag(12000073))
        SetEventFlagID(12005073, ON);
    //Ulcerated Tree Spirit
    else if (EventFlag(12000074))
        SetEventFlagID(12005074, ON);
    //Grafted Monarch
    else if (EventFlag(12000075))
        SetEventFlagID(12005075, ON);
    //Royal Revenant
    else if (EventFlag(12000076))
        SetEventFlagID(12005076, ON);
    //Fell Omen
    else if (EventFlag(12000077))
        SetEventFlagID(12005077, ON);
    //Tree Sentinel & Royal Cavalrymen
    else if (EventFlag(12000078))
        SetEventFlagID(12005078, ON);
    //Ancient Dragon
    else if (EventFlag(12000079))
        SetEventFlagID(12005079, ON);
    //Crucible Knight & Golden Hippopotamus
    else if (EventFlag(12000080))
        SetEventFlagID(12005080, ON);
    //Outland Commander
    else if (EventFlag(12000081))
        SetEventFlagID(12005081, ON);
    //Great Wyrm
    else if (EventFlag(12000082))
        SetEventFlagID(12005082, ON);
    //Nox Dragonkin Soldier
    else if (EventFlag(12000083))
        SetEventFlagID(12005083, ON);
    //Draconic Tree Sentinel & Royal Cavalrymen
    else if (EventFlag(12000084))
        SetEventFlagID(12005084, ON);
    //Full-Grown Fallingstar Beast
    else if (EventFlag(12000085))
        SetEventFlagID(12005085, ON);
    //Godskin Duo
    else if (EventFlag(12000086))
        SetEventFlagID(12005086, ON);
    //Death Rite Bird
    else if (EventFlag(12000087))
        SetEventFlagID(12005087, ON);
    //Nameless King
    else if (EventFlag(12000088))
        SetEventFlagID(12005088, ON);
    //Dancer of the Boreal Valley
    else if (EventFlag(12000089))
        SetEventFlagID(12005089, ON);
    //Gladius, Beast of Night
    else if (EventFlag(12000150))
        SetEventFlagID(12005150, ON);
    //Adel, Baron of Night
    else if (EventFlag(12000151))
        SetEventFlagID(12005151, ON);
    //Gnoster, Wisdom of Night
    else if (EventFlag(12000152))
        SetEventFlagID(12005152, ON);
    //Maris, Fathom of Night
    else if (EventFlag(12000153))
        SetEventFlagID(12005153, ON);
    //Libra, Creature of Night
    else if (EventFlag(12000154))
        SetEventFlagID(12005154, ON);
    //Fulghor, Champion of Nightglow
    else if (EventFlag(12000155))
        SetEventFlagID(12005155, ON);
    //Caligo, Miasma of Night
    else if (EventFlag(12000156))
        SetEventFlagID(12005156, ON);
    //Heolstor, the Nightlord
    else if (EventFlag(12000157))
        SetEventFlagID(12005157, ON);
    //Gladius, Beast of Night (Everdark)
    else if (EventFlag(12000160))
        SetEventFlagID(12005160, ON);
    //Adel, Baron of Night (Everdark)
    else if (EventFlag(12000161))
        SetEventFlagID(12005161, ON);
    //Gnoster, Wisdom of Night (Everdark)
    else if (EventFlag(12000162))
        SetEventFlagID(12005162, ON);
    //Maris, Fathom of Night (Everdark)
    else if (EventFlag(12000163))
        SetEventFlagID(12005163, ON);
    //Libra, Creature of Night (Everdark)
    else if (EventFlag(12000164))
        SetEventFlagID(12005164, ON);
    //Fulghor, Champion of Nightglow (Everdark)
    else if (EventFlag(12000165))
        SetEventFlagID(12005165, ON);
    //Caligo, Miasma of Night (Everdark)
    else if (EventFlag(12000166))
        SetEventFlagID(12005166, ON);
});

$Event(0, Default, function() {
    $InitializeEvent(0, 99989999); //boss arena constructor
    $InitializeEvent(0, 1600);
    $InitializeEvent(0, 1601);
    $InitializeEvent(0, 1610);
    if (MissionActive(101)) {
        $InitializeCommonEvent(0, 90085010, 101, 8325, 12030);
        if (12210 != 0) {
            $InitializeCommonEvent(0, 90085028, 101, 8325, 8327, 12210);
        }
        if (0 == 1) {
            $InitializeCommonEvent(0, 90085024, 101, 8327, 8325);
        }
        GotoIf(S1, 1 == 0);
        $InitializeCommonEvent(0, 90085025, 101, 9206, 8325);
        GotoIf(S0, 1 != 1);
        $InitializeCommonEvent(0, 90085026, 101, 8325, 1);
    }
S0:
    if (1 == 2) {
        $InitializeCommonEvent(0, 90085026, 101, 8325, 0);
    }
S1:
    if (MissionActive(102)) {
        $InitializeCommonEvent(0, 90085010, 102, 8330, 12030);
        if (12211 != 0) {
            $InitializeCommonEvent(0, 90085028, 102, 8330, 8332, 12211);
        }
        if (0 == 1) {
            $InitializeCommonEvent(0, 90085024, 102, 8332, 8330);
        }
        GotoIf(S3, 1 == 0);
        $InitializeCommonEvent(0, 90085025, 102, 9207, 8330);
        GotoIf(S2, 1 != 1);
        $InitializeCommonEvent(0, 90085026, 102, 8330, 1);
    }
S2:
    if (1 == 2) {
        $InitializeCommonEvent(0, 90085026, 102, 8330, 0);
    }
S3:
    if (MissionActive(202)) {
        $InitializeCommonEvent(0, 90085010, 202, 8355, 12035);
        if (0 != 0) {
            $InitializeCommonEvent(0, 90085028, 202, 8355, 8357, 0);
        }
        if (1 == 1) {
            $InitializeCommonEvent(0, 90085024, 202, 8357, 8355);
        }
        GotoIf(S5, 1 == 0);
        $InitializeCommonEvent(0, 90085025, 202, 9208, 8355);
        GotoIf(S4, 1 != 1);
        $InitializeCommonEvent(0, 90085026, 202, 8355, 1);
    }
S4:
    if (1 == 2) {
        $InitializeCommonEvent(0, 90085026, 202, 8355, 0);
    }
S5:
    if (MissionActive(203)) {
        $InitializeCommonEvent(0, 90085010, 203, 8360, 12035);
        if (0 != 0) {
            $InitializeCommonEvent(0, 90085028, 203, 8360, 0, 0);
        }
        if (0 == 1) {
            $InitializeCommonEvent(0, 90085024, 203, 0, 8360);
        }
        GotoIf(S7, 1 == 0);
        $InitializeCommonEvent(0, 90085025, 203, 9200, 8360);
        GotoIf(S6, 1 != 1);
        $InitializeCommonEvent(0, 90085026, 203, 8360, 1);
    }
S6:
    if (1 == 2) {
        $InitializeCommonEvent(0, 90085026, 203, 8360, 0);
    }
S7:
    if (MissionActive(302)) {
        $InitializeCommonEvent(0, 90085010, 302, 8380, 12040);
        if (0 != 0) {
            $InitializeCommonEvent(0, 90085028, 302, 8380, 8382, 0);
        }
        if (1 == 1) {
            $InitializeCommonEvent(0, 90085024, 302, 8382, 8380);
        }
        GotoIf(S9, 2 == 0);
        $InitializeCommonEvent(0, 90085025, 302, 9209, 8380);
        GotoIf(S8, 2 != 1);
        $InitializeCommonEvent(0, 90085026, 302, 8380, 1);
    }
S8:
    if (2 == 2) {
        $InitializeCommonEvent(0, 90085026, 302, 8380, 0);
    }
S9:
    if (MissionActive(303)) {
        $InitializeCommonEvent(0, 90085010, 303, 8385, 12040);
        if (0 != 0) {
            $InitializeCommonEvent(0, 90085028, 303, 8385, 0, 0);
        }
        if (0 == 1) {
            $InitializeCommonEvent(0, 90085024, 303, 0, 8385);
        }
        GotoIf(S11, 0 == 0);
        $InitializeCommonEvent(0, 90085025, 303, 9211, 8385);
        GotoIf(S10, 0 != 1);
        $InitializeCommonEvent(0, 90085026, 303, 8385, 1);
    }
S10:
    if (0 == 2) {
        $InitializeCommonEvent(0, 90085026, 303, 8385, 0);
    }
S11:
    if (MissionActive(401)) {
        $InitializeCommonEvent(0, 90085010, 401, 8400, 12045);
        if (12212 != 0) {
            $InitializeCommonEvent(0, 90085028, 401, 8400, 8402, 12212);
        }
        if (0 == 1) {
            $InitializeCommonEvent(0, 90085024, 401, 8402, 8400);
        }
        GotoIf(S13, 1 == 0);
        $InitializeCommonEvent(0, 90085025, 401, 9212, 8400);
        GotoIf(S12, 1 != 1);
        $InitializeCommonEvent(0, 90085026, 401, 8400, 1);
    }
S12:
    if (1 == 2) {
        $InitializeCommonEvent(0, 90085026, 401, 8400, 0);
    }
S13:
    if (MissionActive(403)) {
        $InitializeCommonEvent(0, 90085010, 403, 8410, 12045);
        if (12213 != 0) {
            $InitializeCommonEvent(0, 90085028, 403, 8410, 8412, 12213);
        }
        if (0 == 1) {
            $InitializeCommonEvent(0, 90085024, 403, 8412, 8410);
        }
        GotoIf(S15, 1 == 0);
        $InitializeCommonEvent(0, 90085025, 403, 9213, 8410);
        GotoIf(S14, 1 != 1);
        $InitializeCommonEvent(0, 90085026, 403, 8410, 1);
    }
S14:
    if (1 == 2) {
        $InitializeCommonEvent(0, 90085026, 403, 8410, 0);
    }
S15:
    if (MissionActive(601)) {
        $InitializeCommonEvent(0, 90085010, 601, 8450, 12055);
        if (0 != 0) {
            $InitializeCommonEvent(0, 90085028, 601, 8450, 0, 0);
        }
        if (0 == 1) {
            $InitializeCommonEvent(0, 90085024, 601, 0, 8450);
        }
        GotoIf(S17, 0 == 0);
        $InitializeCommonEvent(0, 90085025, 601, 9214, 8450);
        GotoIf(S16, 0 != 1);
        $InitializeCommonEvent(0, 90085026, 601, 8450, 1);
    }
S16:
    if (0 == 2) {
        $InitializeCommonEvent(0, 90085026, 601, 8450, 0);
    }
S17:
    if (MissionActive(701)) {
        $InitializeCommonEvent(0, 90085010, 701, 8475, 12060);
        if (0 != 0) {
            $InitializeCommonEvent(0, 90085028, 701, 8475, 8477, 0);
        }
        if (1 == 1) {
            $InitializeCommonEvent(0, 90085024, 701, 8477, 8475);
        }
        GotoIf(S19, 2 == 0);
        $InitializeCommonEvent(0, 90085025, 701, 9216, 8475);
        GotoIf(S18, 2 != 1);
        $InitializeCommonEvent(0, 90085026, 701, 8475, 1);
    }
S18:
    if (2 == 2) {
        $InitializeCommonEvent(0, 90085026, 701, 8475, 0);
    }
S19:
    if (MissionActive(802)) {
        $InitializeCommonEvent(0, 90085010, 802, 8505, 12065);
        if (12215 != 0) {
            $InitializeCommonEvent(0, 90085028, 802, 8505, 8507, 12215);
        }
        if (0 == 1) {
            $InitializeCommonEvent(0, 90085024, 802, 8507, 8505);
        }
        GotoIf(S21, 1 == 0);
        $InitializeCommonEvent(0, 90085025, 802, 9217, 8505);
        GotoIf(S20, 1 != 1);
        $InitializeCommonEvent(0, 90085026, 802, 8505, 1);
    }
S20:
    if (1 == 2) {
        $InitializeCommonEvent(0, 90085026, 802, 8505, 0);
    }
S21:
    if (MissionActive(803)) {
        $InitializeCommonEvent(0, 90085010, 803, 8510, 12065);
        if (12214 != 0) {
            $InitializeCommonEvent(0, 90085028, 803, 8510, 8512, 12214);
        }
        if (0 == 1) {
            $InitializeCommonEvent(0, 90085024, 803, 8512, 8510);
        }
        GotoIf(S23, 1 == 0);
        $InitializeCommonEvent(0, 90085025, 803, 9218, 8510);
        GotoIf(S22, 1 != 1);
        $InitializeCommonEvent(0, 90085026, 803, 8510, 1);
    }
S22:
    if (1 == 2) {
        $InitializeCommonEvent(0, 90085026, 803, 8510, 0);
    }
S23:
    if (MissionActive(302)) {
        SetNetworkconnectedEventFlagID(74017, ON);
    }
    if (MissionActive(203)) {
        $InitializeCommonEvent(0, 90085222, 203, 8360, 9201, 9202, 8361);
    }
    $InitializeEvent(0, 1100);
    //$InitializeEvent(0, 1101); //enable sp revive on day 1 start
    $InitializeEvent(0, 1111);
    $InitializeEvent(0, 1102);
    $InitializeEvent(0, 1103);
    $InitializeEvent(0, 1113);
    //$InitializeEvent(0, 1104); //enable sp revive on day 2 start
    $InitializeEvent(0, 1105);
    $InitializeEvent(0, 1106);
    $InitializeEvent(0, 1116);
    $InitializeEvent(0, 1190);
    $InitializeEvent(0, 1191);
    $InitializeEvent(0, 1160);
    $InitializeEvent(0, 1161);
    $InitializeEvent(0, 1107);
    $InitializeEvent(0, 1120);
    $InitializeEvent(0, 1121);
    $InitializeEvent(0, 1122);
    $InitializeEvent(0, 1124);
    $InitializeEvent(0, 1125);
    $InitializeEvent(0, 1127, 1044360220, 1044360225);
    $InitializeEvent(1, 1127, 1044380230, 1044380235);
    $InitializeEvent(0, 1129);
    $InitializeEvent(0, 1131);
    $InitializeEvent(0, 1132);
    $InitializeEvent(0, 1133);
    $InitializeEvent(0, 1134);
    $InitializeEvent(0, 1135);
    $InitializeEvent(0, 1136);
    $InitializeEvent(0, 1139);
    $InitializeEvent(0, 1140);
    $InitializeEvent(0, 1150);
    $InitializeEvent(0, 1151);
    $InitializeCommonEvent(0, 99075460, 1, 70000, 70001, 70002, 70003, 70004, 70005, 70006, 70007, 70008, 70009);
    $InitializeCommonEvent(0, 99075460, 2, 70030, 70031, 70032, 70033, 70034, 70035, 70036, 70037, 70038, 70039);
    $InitializeCommonEvent(0, 99075460, 3, 70060, 70061, 70062, 70063, 70064, 70065, 70066, 70067, 70068, 70069);
    $InitializeCommonEvent(0, 99075461, 1, 70010, 70011, 70012, 70013, 70014, 70015);
    $InitializeCommonEvent(0, 99075461, 2, 70040, 70041, 70042, 70043, 70044, 70045);
    $InitializeCommonEvent(0, 99075461, 3, 70070, 70071, 70072, 70073, 70074, 70075);
    $InitializeCommonEvent(0, 99075462, 1, 70020, 70022);
    $InitializeCommonEvent(0, 99075462, 2, 70050, 70052);
    $InitializeCommonEvent(0, 99075462, 3, 70080, 70082);
    $InitializeCommonEvent(0, 99075465, 1, 19010450, 19010453, 0, 70000, 70001, 70002, 70003, 70004, 70005, 70006, 70007, 70008, 70009, 70010, 70011, 70012, 70013, 70014, 70015, 70020, 70021, 70022);
    $InitializeCommonEvent(0, 99075465, 2, 19010451, 19010454, 0, 70030, 70031, 70032, 70033, 70034, 70035, 70036, 70037, 70038, 70039, 70040, 70041, 70042, 70043, 70044, 70045, 70050, 70051, 70052);
    $InitializeCommonEvent(0, 99075465, 3, 19010452, 19010455, 0, 70060, 70061, 70062, 70063, 70064, 70065, 70066, 70067, 70068, 70069, 70070, 70071, 70072, 70073, 70074, 70075, 70080, 70081, 70082);
    $InitializeEvent(0, 1909);
    //$InitializeEvent(0, 1300); day banners
    $InitializeEvent(0, 1301);
    $InitializeEvent(0, 1302);
    if (IsPlayerNo(1)) {
        $InitializeEvent(0, 1310, 7010);
    }
    if (IsPlayerNo(2)) {
        $InitializeEvent(0, 1310, 7011);
    }
    if (IsPlayerNo(3)) {
        $InitializeEvent(0, 1310, 7012);
    }
    $InitializeEvent(0, 1108, 9019);
    $InitializeEvent(0, 1305);
    $InitializeEvent(0, 1311);
    $InitializeEvent(0, 1313);
    $InitializeEvent(0, 1312);
    $InitializeEvent(0, 1306);
    $InitializeEvent(0, 1307);
    $InitializeEvent(0, 1308);
    $InitializeEvent(0, 1309);
    $InitializeEvent(0, 1314);
    $InitializeEvent(0, 1320, 99874, 99810);
    $InitializeEvent(1, 1320, 99879, 99811);
    $InitializeEvent(0, 1325);
    $InitializeEvent(0, 1330, 1044382790);
    $InitializeEvent(1, 1330, 1044382791);
    $InitializeEvent(2, 1330, 1044362790);
    $InitializeEvent(3, 1330, 1043382790);
    $InitializeEvent(0, 1304);
    $InitializeCommonEvent(0, 90015208, 9328, 9051, 9040);
    $InitializeEvent(0, 1170);
    $InitializeEvent(1, 1520, 102, 8330, 97120);
    $InitializeEvent(2, 1520, 202, 8355, 97220);
    $InitializeEvent(3, 1520, 302, 8380, 97320);
    $InitializeEvent(4, 1520, 401, 8400, 97410);
    $InitializeEvent(5, 1520, 403, 8410, 97430);
    $InitializeEvent(6, 1520, 701, 8475, 97710);
    $InitializeEvent(7, 1520, 802, 8505, 97820);
    $InitializeEvent(8, 1520, 803, 8510, 97830);
    $InitializeEvent(0, 1592, 97112, 97110, 9204);
    $InitializeCommonEvent(0, 90015014, 7602, 72447);
    $InitializeCommonEvent(0, 90015014, 7602, 72448);
    $InitializeCommonEvent(0, 90015014, 7605, 72451);
    $InitializeCommonEvent(0, 90015014, 7605, 72458);
    $InitializeCommonEvent(0, 90015014, 7605, 72459);
    $InitializeEvent(0, 1500);
    $InitializeEvent(0, 1519, 72250, 7605);
    $InitializeEvent(0, 1510, 72251, 7601);
    $InitializeEvent(1, 1510, 72252, 7602);
    $InitializeEvent(2, 1510, 72253, 7603);
    $InitializeEvent(3, 1510, 72255, 7605);
    $InitializeEvent(0, 1505, 72560, 7605);
    $InitializeEvent(0, 1506, 72561, 7603);
    $InitializeCommonEvent(0, 90015019, 1027500200, 1027500700);
    $InitializeCommonEvent(0, 90015019, 1036500250, 1036500750);
    $InitializeCommonEvent(0, 90035086);
    $InitializeCommonEvent(0, 90015100, 8000, 9100, 7070001, 8120);
    $InitializeCommonEvent(1, 90015100, 8000, 9111, 7070001, 8131);
    $InitializeCommonEvent(2, 90015100, 8000, 9106, 7070001, 8126);
    $InitializeCommonEvent(3, 90015100, 8001, 9101, 7070001, 8121);
    $InitializeCommonEvent(4, 90015100, 8001, 9110, 7070001, 8130);
    $InitializeCommonEvent(5, 90015100, 8001, 9107, 7070001, 8127);
    $InitializeCommonEvent(6, 90015100, 8002, 9102, 7070001, 8122);
    $InitializeCommonEvent(7, 90015100, 8002, 9109, 7070001, 8129);
    $InitializeCommonEvent(8, 90015100, 8002, 9108, 7070001, 8128);
    $InitializeCommonEvent(9, 90015100, 8003, 9103, 7070001, 8123);
    $InitializeCommonEvent(10, 90015100, 8003, 9108, 7070001, 8128);
    $InitializeCommonEvent(11, 90015100, 8003, 9109, 7070001, 8129);
    $InitializeCommonEvent(12, 90015100, 8004, 9104, 7070001, 8124);
    $InitializeCommonEvent(13, 90015100, 8004, 9107, 7070001, 8127);
    $InitializeCommonEvent(14, 90015100, 8004, 9110, 7070001, 8130);
    $InitializeCommonEvent(15, 90015100, 8005, 9105, 7070001, 8125);
    $InitializeCommonEvent(16, 90015100, 8005, 9106, 7070001, 8126);
    $InitializeCommonEvent(17, 90015100, 8005, 9111, 7070001, 8131);
    $InitializeCommonEvent(18, 90015100, 8006, 9106, 7070001, 8126);
    $InitializeCommonEvent(19, 90015100, 8006, 9105, 7070001, 8125);
    $InitializeCommonEvent(20, 90015100, 8006, 9100, 7070001, 8120);
    $InitializeCommonEvent(21, 90015100, 8007, 9107, 7070001, 8127);
    $InitializeCommonEvent(22, 90015100, 8007, 9104, 7070001, 8124);
    $InitializeCommonEvent(23, 90015100, 8007, 9101, 7070001, 8121);
    $InitializeCommonEvent(24, 90015100, 8008, 9108, 7070001, 8128);
    $InitializeCommonEvent(25, 90015100, 8008, 9103, 7070001, 8123);
    $InitializeCommonEvent(26, 90015100, 8008, 9102, 7070001, 8122);
    $InitializeCommonEvent(27, 90015100, 8009, 9109, 7070001, 8129);
    $InitializeCommonEvent(28, 90015100, 8009, 9102, 7070001, 8122);
    $InitializeCommonEvent(29, 90015100, 8009, 9103, 7070001, 8123);
    $InitializeCommonEvent(30, 90015100, 8010, 9110, 7070001, 8130);
    $InitializeCommonEvent(31, 90015100, 8010, 9101, 7070001, 8121);
    $InitializeCommonEvent(32, 90015100, 8010, 9104, 7070001, 8124);
    $InitializeCommonEvent(33, 90015100, 8011, 9111, 7070001, 8131);
    $InitializeCommonEvent(34, 90015100, 8011, 9100, 7070001, 8120);
    $InitializeCommonEvent(35, 90015100, 8011, 9105, 7070001, 8125);
    $InitializeEvent(0, 1400, 7060001, 7060000);
    $InitializeEvent(0, 1402, 7060201, 7060200);
    $InitializeEvent(0, 1403, 7060101, 7060100);
    $InitializeEvent(0, 1406, 7060400, 7060401, 7060402, 8160, 9350);
    $InitializeEvent(1, 1406, 7060600, 7060601, 0, 8165, 9355);
    $InitializeEvent(2, 1406, 7060500, 7060501, 0, 8170, 9360);
    $InitializeEvent(3, 1406, 7060300, 7060301, 0, 8175, 9365);
    $InitializeEvent(0, 1450, 8970001, 8970000);
    $InitializeCommonEvent(0, 90015003, 6999000, 7704, 7724, 8024, 0, 1, 2.5);
    $InitializeCommonEvent(0, 90015003, 8970001, 8075, 0, 8025, 0, 8970000, 2.5);
    $InitializeCommonEvent(0, 90015003, 6999400, 8075, 0, 9056, 0, 5, 2.5);
    $InitializeCommonEvent(0, 90015003, 8970020, 8076, 0, 8025, 0, 8970020, 2.5);
    $InitializeCommonEvent(0, 90015003, 6999400, 8076, 0, 9056, 0, 5, 2.5);
    $InitializeCommonEvent(0, 90015003, 6999000, 8077, 0, 8025, 0, 1, 2.5);
    $InitializeCommonEvent(0, 90015003, 8970010, 8078, 0, 8025, 0, 8970010, 2.5);
    $InitializeCommonEvent(0, 90015003, 8970030, 8079, 0, 8025, 0, 8970030, 2.5);
    $InitializeCommonEvent(0, 90015003, 6999200, 7603, 0, 9192, 0, 3, 2.5);
    $InitializeCommonEvent(0, 90015003, 6999300, 7601, 0, 9193, 0, 4, 2.5);
    $InitializeCommonEvent(0, 90015003, 9700, 0, 0, 9206, 0, 100, 0);
    $InitializeCommonEvent(0, 90015003, 9701, 0, 0, 9207, 0, 101, 0);
    $InitializeCommonEvent(0, 90015003, 9713, 0, 0, 9208, 0, 113, 0);
    $InitializeCommonEvent(0, 90015003, 9714, 0, 0, 9200, 0, 114, 0);
    $InitializeCommonEvent(0, 90015003, 9710, 0, 0, 9209, 0, 110, 0);
    $InitializeCommonEvent(0, 90015003, 9711, 0, 0, 9211, 0, 111, 0);
    $InitializeCommonEvent(0, 90015003, 9702, 0, 0, 9212, 0, 102, 0);
    $InitializeCommonEvent(0, 90015003, 9703, 0, 0, 9213, 0, 103, 0);
    $InitializeCommonEvent(0, 90015003, 9716, 0, 0, 9214, 0, 116, 0);
    $InitializeCommonEvent(0, 90015003, 9707, 0, 0, 9216, 0, 107, 0);
    $InitializeCommonEvent(0, 90015003, 9704, 0, 0, 9218, 0, 104, 0);
    $InitializeCommonEvent(0, 90015003, 9706, 0, 0, 9217, 0, 106, 0);
    $InitializeEvent(0, 1200);
    $InitializeEvent(0, 1201);
    $InitializeEvent(0, 1202);
    $InitializeEvent(0, 1210);
    $InitializeCommonEvent(0, 90005595, 1042360950, 0);
    $InitializeCommonEvent(0, 90005595, 1042370950, 0);
    $InitializeCommonEvent(0, 90005595, 1042370952, 0);
    $InitializeCommonEvent(0, 90005595, 1042380951, 0);
    $InitializeCommonEvent(0, 90005595, 1042380952, 0);
    $InitializeCommonEvent(0, 90005595, 1042390951, 0);
    $InitializeCommonEvent(0, 90005595, 1043360950, 0);
    $InitializeCommonEvent(0, 90005595, 1043360951, 0);
    $InitializeCommonEvent(0, 90005595, 1043370951, 0);
    $InitializeCommonEvent(0, 90005595, 1043380950, 0);
    $InitializeCommonEvent(0, 90005595, 1043380951, 0);
    $InitializeCommonEvent(0, 90005595, 1043390951, 6011);
    $InitializeCommonEvent(0, 90005595, 1043390953, 0);
    $InitializeCommonEvent(0, 90005595, 1044360950, 0);
    $InitializeCommonEvent(0, 90005595, 1044360955, 0);
    $InitializeCommonEvent(0, 90005595, 1044370955, 0);
    $InitializeCommonEvent(0, 90005595, 1044370950, 0);
    $InitializeCommonEvent(0, 90005595, 1044370953, 0);
    $InitializeCommonEvent(0, 90005595, 1044370955, 0);
    $InitializeCommonEvent(0, 90005595, 1044380950, 0);
    $InitializeCommonEvent(0, 90005595, 1044380953, 0);
    $InitializeCommonEvent(0, 90005595, 1044390951, 6011);
    $InitializeCommonEvent(0, 90005595, 1044390952, 0);
    $InitializeCommonEvent(0, 90005595, 1045360951, 0);
    $InitializeCommonEvent(0, 90005595, 1045370950, 0);
    $InitializeCommonEvent(0, 90005595, 1045370951, 0);
    $InitializeCommonEvent(0, 90005595, 1045370953, 0);
    $InitializeCommonEvent(0, 90005595, 1045370954, 0);
    $InitializeCommonEvent(0, 90005595, 1045370955, 0);
    $InitializeCommonEvent(0, 90005595, 1045380950, 0);
    $InitializeCommonEvent(0, 90005595, 1045390951, 0);
    $InitializeCommonEvent(0, 90005595, 1043370950, 0);
    $InitializeCommonEvent(0, 90005595, 1043360951, 0);
    $InitializeCommonEvent(0, 90005595, 1042370951, 0);
    $InitializeCommonEvent(0, 90005595, 12001950, 0);
    $InitializeCommonEvent(0, 90005595, 1043390960, 0);
    $InitializeEvent(7, 1700, 7, 9307, 0);
    $InitializeEvent(8, 1700, 8, 9308, 0);
    $InitializeEvent(9, 1700, 9, 9309, 0);
    $InitializeEvent(10, 1700, 10, 9310, 0);
    $InitializeEvent(11, 1700, 11, 9311, 0);
    $InitializeEvent(12, 1700, 12, 9312, 0);
    $InitializeEvent(13, 1700, 13, 9313, 0);
    $InitializeEvent(14, 1700, 14, 9314, 0);
    $InitializeEvent(15, 1700, 15, 9315, 0);
    $InitializeEvent(20, 1700, 20, 9320, 0);
    $InitializeEvent(21, 1700, 21, 9321, 0);
    $InitializeEvent(22, 1700, 22, 9322, 0);
    $InitializeEvent(23, 1700, 23, 9323, 0);
    $InitializeEvent(24, 1700, 24, 9324, 0);
    $InitializeCommonEvent(0, 90015202, 9320, 6210, 9193);
    $InitializeCommonEvent(1, 90015202, 9321, 6211, 9194);
    $InitializeCommonEvent(2, 90015202, 9322, 6212, 9192);
    $InitializeCommonEvent(3, 90015202, 9323, 6213, 9191);
    $InitializeCommonEvent(0, 90015203, 9324, 9193);
    $InitializeCommonEvent(1, 90015203, 9324, 9194);
    $InitializeCommonEvent(2, 90015203, 9324, 9192);
    $InitializeCommonEvent(3, 90015203, 9324, 9191);
    $InitializeEvent(26, 1700, 26, 9326, 0);
    $InitializeCommonEvent(0, 90015204, 6200, Hero.Wylder);
    $InitializeCommonEvent(1, 90015204, 6201, Hero.Guardian);
    $InitializeCommonEvent(2, 90015204, 6202, Hero.Ironeye);
    $InitializeCommonEvent(3, 90015204, 6203, Hero.Duchess);
    $InitializeCommonEvent(4, 90015204, 6204, Hero.Raider);
    $InitializeCommonEvent(5, 90015204, 6205, Hero.Revenant);
    $InitializeCommonEvent(6, 90015204, 6206, Hero.Recluse);
    $InitializeCommonEvent(7, 90015204, 6207, Hero.Executor);
    $InitializeCommonEvent(0, 90015205, 9326, 6200, Hero.Wylder);
    $InitializeCommonEvent(1, 90015205, 9326, 6201, Hero.Guardian);
    $InitializeCommonEvent(2, 90015205, 9326, 6202, Hero.Ironeye);
    $InitializeCommonEvent(3, 90015205, 9326, 6203, Hero.Duchess);
    $InitializeCommonEvent(4, 90015205, 9326, 6204, Hero.Raider);
    $InitializeCommonEvent(5, 90015205, 9326, 6205, Hero.Revenant);
    $InitializeCommonEvent(6, 90015205, 9326, 6206, Hero.Recluse);
    $InitializeCommonEvent(7, 90015205, 9326, 6207, Hero.Executor);
    $InitializeEvent(27, 1700, 27, 9327, 0);
    $InitializeCommonEvent(0, 90015206, 9327);
    $InitializeEvent(28, 1700, 28, 9328, 0);
    $InitializeCommonEvent(0, 90015207, 9328, 9040, 9041);
    $InitializeEvent(29, 1700, 29, 9329, 0);
    $InitializeCommonEvent(0, 90015209, 9329);
    $InitializeEvent(30, 1700, 30, 9330, 0);
    $InitializeCommonEvent(0, 90015211, 9330, 46800800);
    $InitializeEvent(32, 1700, 32, 9332, 0);
    $InitializeCommonEvent(0, 90015212, 9332, 8075, 8025);
    $InitializeEvent(33, 1700, 33, 9333, 0);
    $InitializeCommonEvent(1, 90015212, 9333, 8078, 8025);
    $InitializeEvent(34, 1700, 34, 9334, 0);
    $InitializeCommonEvent(2, 90015212, 9334, 8076, 8025);
    $InitializeEvent(35, 1700, 35, 9335, 0);
    $InitializeCommonEvent(3, 90015212, 9335, 8079, 8025);
    $InitializeEvent(0, 1680, 0, 100, 0);
    $InitializeEvent(1, 1680, 1, 101, 0);
    $InitializeEvent(2, 1680, 2, 110, 0);
    $InitializeEvent(3, 1680, 3, 115, 0);
    $InitializeEvent(0, 1690, 0, 120, 0);
    $InitializeEvent(1, 1690, 1, 110, 0);
    $InitializeEvent(2, 1690, 2, 115, 0);
    $InitializeEvent(3, 1690, 3, 951, 0);
});

$Event(50, Default, function() {
    $InitializeEvent(0, 99989998); //boss arena preconstructor
    $InitializeEvent(0, 1180);
    $InitializeEvent(0, 1181);
    if (!HasMultiplayerState(MultiplayerState.Singleplayer)) {
        if (IsPlayerNo(1)) {
            $InitializeEvent(0, 1182, 7005);
            $InitializeEvent(0, 1183, 7010, 7005);
        }
        if (IsPlayerNo(2)) {
            $InitializeEvent(0, 1182, 7006);
            $InitializeEvent(0, 1183, 7011, 7006);
        }
        if (IsPlayerNo(3)) {
            $InitializeEvent(0, 1182, 7007);
            $InitializeEvent(0, 1183, 7012, 7007);
        }
        $InitializeEvent(0, 1184, 10002, 7005, 7010);
        $InitializeEvent(1, 1184, 10003, 7006, 7011);
        $InitializeEvent(2, 1184, 10004, 7007, 7012);
    }
    $InitializeEvent(0, 1900);
    $InitializeEvent(0, 1901);
    $InitializeEvent(0, 1902);
    $InitializeEvent(0, 1903);
    SetEventFlagID(6000, OFF);
    SetEventFlagID(6001, ON);
    $InitializeEvent(0, 1904);
    $InitializeEvent(0, 1905);
    $InitializeEvent(0, 1906, 550, Weather.Type01);
    $InitializeEvent(1, 1906, 551, Weather.Type00);
    $InitializeEvent(2, 1906, 552, Weather.Type10);
    $InitializeEvent(3, 1906, 553, Weather.Type11);
    $InitializeEvent(4, 1906, 554, Weather.Type20);
    $InitializeEvent(5, 1906, 555, Weather.Type21);
    $InitializeEvent(6, 1906, 556, Weather.Type30);
    $InitializeEvent(7, 1906, 557, Weather.Type31);
    $InitializeEvent(8, 1906, 558, Weather.Type40);
    $InitializeEvent(9, 1906, 559, Weather.Type41);
    $InitializeEvent(10, 1906, 560, Weather.Type50);
    $InitializeEvent(11, 1906, 561, Weather.Type51);
    $InitializeEvent(12, 1906, 562, Weather.Type52);
    $InitializeEvent(13, 1906, 563, Weather.Type60);
    $InitializeEvent(0, 1907);
    $InitializeEvent(0, 1908);
    EndEvent();
});

$Event(1100, Default, function() {
    WaitFor(IsGameMode(2) || EventFlag(69991));
    if (!EventFlag(7500)) {
        if (PlayerIsInOwnWorld()) {
            SetNetworkconnectedEventFlagID(7500, ON);
        }
    }
    if (!EventFlag(7502)) {
        WaitFor(EventFlag(7502) && PlayerIsInOwnWorld());
        if (!EventFlag(7700)) {
            if (PlayerIsInOwnWorld()) {
                SetNetworkconnectedEventFlagID(7503, ON);
            }
        }
    }
    if (EventFlag(7700)) {
        if (!EventFlag(8020)) {
            WaitFor(EventFlag(8020) && PlayerIsInOwnWorld());
            if (PlayerIsInOwnWorld()) {
                SetNetworkconnectedEventFlagID(7503, ON);
            }
        }
    }
    if (!EventFlag(7505)) {
        WaitFor(PlayAreaCurrentTimeInRange(0, 0, 0, 22, 59, 59) && PlayerIsInOwnWorld());
        if (PlayerIsInOwnWorld()) {
            SetNetworkconnectedEventFlagID(7505, ON);
        }
    }
    if (!EventFlag(7507)) {
        WaitFor(EventFlag(7507) && PlayerIsInOwnWorld());
        if (!EventFlag(7720)) {
            if (PlayerIsInOwnWorld()) {
                SetNetworkconnectedEventFlagID(7508, ON);
            }
        }
    }
    if (EventFlag(7720)) {
        if (!EventFlag(8020)) {
            WaitFor(EventFlag(8020) && PlayerIsInOwnWorld());
            if (PlayerIsInOwnWorld()) {
                SetNetworkconnectedEventFlagID(7508, ON);
            }
        }
    }
    WaitFor(EventFlag(7000));
    EndEvent();
});

//enable sp revive on day 1 start
$Event(1101, Default, function() {
    EndIf(EventFlag(7500));
    WaitFor(EventFlag(7500));
    if (HasMultiplayerState(MultiplayerState.Singleplayer)) {
        SetSpEffect(20000, 6999500);
    }
    SetNetworkconnectedEventFlagID(82100, ON);
    WaitFor(ElapsedSeconds(2));
    EndEvent();
});

$Event(1102, Default, function() {
    EndIf(EventFlag(7501));
    WaitFor(EventFlag(7501));
    EndEvent();
});

$Event(1103, Default, function() {
    EndIf(EventFlag(7505));
    if (!EventFlag(7520)) {
        WaitFor(EventFlag(7503));
        WaitFor(ElapsedSeconds(20));
        SetNetworkconnectedEventFlagID(7520, ON);
    }
L0:
    PlaySE(20000, SoundType.EnvironmentalSound, 600010100);
    WaitFixedTimeSeconds(2);
    SpawnOneshotSFX(TargetEntityType.Character, 10000, -1, 807070);
    WaitFor(ElapsedSeconds(2));
    ResetTimeOfDay(7, 0, 0, 4);
    EndEvent();
});

//enable sp revive on day 2 start
$Event(1104, Default, function() {
    EndIf(EventFlag(7505));
    WaitFor(EventFlag(7505));
    WaitFor(ElapsedSeconds(5));
    if (HasMultiplayerState(MultiplayerState.Singleplayer)) {
        SetSpEffect(20000, 6999500);
    }
    if (!EventFlag(7811)) {
        RecordUserDispLog(11281, 20000, LogObjectType.None, -1);
        SetNetworkconnectedEventFlagID(7517, ON);
    }
    EndEvent();
});

$Event(1105, Default, function() {
    EndIf(EventFlag(7506));
    WaitFor(EventFlag(7506));
    EndEvent();
});

$Event(1106, Default, function() {
    EndIf(EventFlag(7508));
    WaitFor(EventFlag(7508));
    EndEvent();
});

$Event(1107, Default, function() {
    WaitFor(EventFlag(7500));
    if (!EventFlag(7515)) {
        WaitFor(PlayAreaCurrentTimeInRange(23, 59, 0, 23, 59, 59) && PlayerIsInOwnWorld());
        if (PlayerIsInOwnWorld()) {
            SetNetworkconnectedEventFlagID(7515, ON);
        }
    }
    RestartIf(!EventFlag(7515));
    WaitFor(
        PlayerIsInOwnWorld()
            && (PlayAreaCurrentTimeInRange(0, 0, 0, 23, 58, 59)
                || ((!EventFlag(7505)
                    && ((!EventFlag(7700) && EventFlag(7502)) || (EventFlag(7700) && EventFlag(8020))))
                    || (EventFlag(7505)
                        && ((!EventFlag(7720) && EventFlag(7507))
                            || (EventFlag(7720) && EventFlag(8020)))))));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(7515, OFF);
    }
    WaitFor(PlayAreaCurrentTimeInRange(0, 0, 0, 23, 58, 59) && PlayerIsInOwnWorld());
    RestartEvent();
});

$Event(1108, Default, function(eventFlagId) {
    DisableNetworkSync();
    WaitFor(EventFlag(7500));
    GotoIf(L0, !EventFlag(eventFlagId));
    GotoIf(L1, EventFlag(eventFlagId));
L0:
    WaitFor(
        (!EventFlag(9052)
            && PlayAreaCurrentTimeInRange(23, 59, 0, 23, 59, 59)
            && !(!EventFlag(7505) && EventFlag(7502)))
            || EventFlag(eventFlagId));
    SetEventFlagID(eventFlagId, ON);
    RestartEvent();
L1:
    WaitFor(
        EventFlag(9052)
            || PlayAreaCurrentTimeInRange(0, 0, 0, 23, 58, 59)
            || (!EventFlag(7505) && EventFlag(7502))
            || !EventFlag(eventFlagId));
    SetEventFlagID(eventFlagId, OFF);
    RestartEvent();
});

$Event(1111, Default, function() {
    DisableNetworkSync();
    if (EventFlag(9011)) {
        SetEventFlagID(9012, OFF);
        EndEvent();
    }
    if (IsGameMode(2)) {
        SetEventFlagID(9012, ON);
        SetSpEffect(10000, 99202);
    }
    WaitFor(EventFlag(7500));
    if ((CharacterHasSpEffect(10002, 702000)
        || CharacterHasSpEffect(10003, 702000)
        || CharacterHasSpEffect(10004, 702000))
        && !IsHero(Hero.Ironeye)) {
        SetSpEffect(10000, 702001);
    }
    SetEventFlagID(9012, ON);
    WaitFor(ElapsedFrames(1));
    if (EventFlag(7812)) {
        RecordUserDispLog(11350, 0, LogObjectType.None, -1);
    }
    if (EventFlag(7811)) {
        RecordUserDispLog(11360, 0, LogObjectType.None, -1);
        RecordUserDispLog(13000, 0, LogObjectType.None, -1);
    }
    SetEventFlagID(9011, ON);
    WaitFor(CharacterHasSpEffect(20000, 99210) || ElapsedSeconds(1));
    WaitFor(!CharacterHasSpEffect(20000, 99210) && !CharacterHasSpEffect(20000, 102610));
    SetEventFlagID(9012, OFF);
});

$Event(1113, Default, function() {
    DisableNetworkSync();
    EndIf(EventFlag(7505));
    WaitFor(EventFlag(7503));
    if (CharacterHasSpEffect(20000, 46285)) {
        SetSpEffect(20000, 46286);
    }
    if (CharacterHasSpEffect(20000, 99685)) {
        SetSpEffect(20000, 99686);
    }
});

$Event(1116, Default, function() {
    DisableNetworkSync();
    EndIf(EventFlag(7508));
    WaitFor(EventFlag(7508));
    if (CharacterHasSpEffect(20000, 46285)) {
        SetSpEffect(20000, 46286);
    }
    if (CharacterHasSpEffect(20000, 99685)) {
        SetSpEffect(20000, 99686);
    }
});

$Event(1120, Default, function() {
    EndIf(!EventFlag(7700) && !EventFlag(7720));
    EndIf(EventFlag(8035));
    if (EventFlag(7700)) {
        WaitFor(EventFlag(7502));
    }
    if (EventFlag(7720)) {
        WaitFor(EventFlag(7507));
    }
    WaitFor(ElapsedSeconds(15));
    WaitFor(PlayerIsInOwnWorld());
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8035, ON);
    }
});

$Event(1121, Default, function() {
    EndIf(!EventFlag(7701) && !EventFlag(7721));
    EndIf(EventFlag(8042));
    if (EventFlag(7701)) {
        WaitFor(EventFlag(7500));
    }
    if (EventFlag(7721)) {
        WaitFor(EventFlag(7505));
    }
    WaitFor((EventFlag(9013) || EventFlag(8040)) && PlayerIsInOwnWorld());
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8040, ON);
    }
    WaitFor(ElapsedSeconds(5));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8041, ON);
    }
    EndEvent();
});

$Event(1122, Default, function() {
    EndIf(!EventFlag(7702) && !EventFlag(7722));
    EndIf(EventFlag(8047));
    WaitFor(PlayerIsInOwnWorld());
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8045, ON);
    }
    WaitFor(ElapsedFrames(1));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8046, ON);
    }
    EndEvent();
});

$Event(1124, Default, function() {
    EndIf(!EventFlag(7704) && !EventFlag(7724));
    EndIf(EventFlag(8055));
    if (EventFlag(7704)) {
        WaitFor(EventFlag(7500));
    }
    if (EventFlag(7724)) {
        WaitFor(EventFlag(7505));
    }
    WaitFor((EventFlag(9013) || EventFlag(8055)) && PlayerIsInOwnWorld());
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8055, ON);
    }
    EndEvent();
});

$Event(1125, Default, function() {
    EndIf(!EventFlag(7705) && !EventFlag(7725));
    EndIf(EventFlag(8060));
    WaitFor((EventFlag(9013) || EventFlag(8060)) && PlayerIsInOwnWorld());
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8060, ON);
    }
    EndEvent();
});

$Event(1127, Default, function(eventFlagId, eventFlagId2) {
    EndIf(!EventFlag(7707) && !EventFlag(7727));
    EndIf(!EventFlag(eventFlagId));
    if (EventFlag(8027)) {
        SetNetworkconnectedEventFlagID(eventFlagId2, OFF);
        EndEvent();
    }
    WaitFor(EventFlag(8071));
    SetNetworkconnectedEventFlagID(eventFlagId2, ON);
    WaitFor(EventFlag(8072) || EventFlag(8073));
    SetNetworkconnectedEventFlagID(eventFlagId2, OFF);
    EndIf(EventFlag(8072));
    WaitFor(!EventFlag(8073));
    RestartEvent();
});

$Event(1129, Default, function() {
    DisableNetworkSync();
    EndIf(!AnyBatchEventFlags(7700, 7739));
    EndIf(EventFlag(9013));
    if (AnyBatchEventFlags(7700, 7719)) {
        WaitFor(EventFlag(7500));
    }
    if (AnyBatchEventFlags(7720, 7739)) {
        WaitFor(EventFlag(7505));
    }
    if (EventFlag(7725) && !EventFlag(7600)) {
        time |= RandomElapsedSeconds(120, 180) || PlayAreaCurrentTimeInRange(10, 38, 42, 23, 59, 59);
        WaitFor(time);
    } else if (AnyBatchEventFlags(7700, 7719)) {
        time |= RandomElapsedSeconds(360, 480) || PlayAreaCurrentTimeInRange(16, 43, 12, 23, 59, 59);
        WaitFor(time);
    } else if (AnyBatchEventFlags(7720, 7739)) {
        time |= RandomElapsedSeconds(120, 480) || PlayAreaCurrentTimeInRange(16, 43, 12, 23, 59, 59);
        WaitFor(time);
        Goto(L0);
    }
L0:
    SetEventFlagID(9013, ON);
});

$Event(1130, Default, function() {
    EndIf(!EventFlag(8076));
    WaitFor(EventFlag(8090));
    timeFlag |= ElapsedSeconds(180);
    if (EventFlag(9998)) {
        timeFlag |= EventFlag(8912);
    } else {
        timeFlag |= EventFlag(8062);
    }
    WaitFor(timeFlag);
    GotoIf(S0, !EventFlag(9998));
    GotoIf(S2, EventFlag(8912));
    Goto(S1);
S0:
    GotoIf(S2, EventFlag(8062));
S1:
    SetNetworkconnectedEventFlagID(8091, ON);
S2:
    NoOp();
});

$Event(1131, Default, function() {
    EndIf(!EventFlag(8078));
    EndIf(EventFlag(8061));
    WaitFor(EventFlag(8060));
    WaitFor(ElapsedSeconds(5));
    EndIf(EventFlag(8061));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8100, ON);
    }
    WaitFor(ElapsedSeconds(5));
    EndIf(EventFlag(8061));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8101, ON);
    }
    EndEvent();
});

$Event(1132, Default, function() {
    EndIf(!EventFlag(8076));
    EndIf(EventFlag(8061));
    WaitFor(EventFlag(8060));
    WaitFor(ElapsedSeconds(5));
    EndIf(EventFlag(8061));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8092, ON);
    }
    WaitFor(ElapsedSeconds(5));
    EndIf(EventFlag(8061));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8093, ON);
    }
    WaitFor(ElapsedSeconds(5));
    EndIf(EventFlag(8061));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8094, ON);
    }
    EndEvent();
});

$Event(1133, Default, function() {
    EndIf(!EventFlag(8075));
    EndIf(EventFlag(8061));
    WaitFor(EventFlag(8060));
    WaitFor(ElapsedSeconds(5));
    EndIf(EventFlag(8061));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8088, ON);
    }
    WaitFor(ElapsedSeconds(5));
    EndIf(EventFlag(8061));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8089, ON);
    }
    EndEvent();
});

$Event(1134, Default, function() {
    EndIf(!EventFlag(8079));
    EndIf(EventFlag(8061));
    WaitFor(EventFlag(8060));
    WaitFor(ElapsedSeconds(5));
    EndIf(EventFlag(8061));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8108, ON);
    }
    WaitFor(ElapsedSeconds(5));
    EndIf(EventFlag(8061));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(8109, ON);
    }
    EndEvent();
});

$Event(1135, Default, function() {
    EndIf(!EventFlag(7705) && !EventFlag(7725));
    EndIf(EventFlag(8062));
    if (EventFlag(8061)) {
        ActivateGparamOverride(2, 3);
        SetSpEffect(20000, 99160);
    } else {
        WaitFor(EventFlag(8061));
        PlaySE(20000, SoundType.EnvironmentalSound, 600080000);
        ActivateGparamOverride(2, 3);
        SetSpEffect(20000, 99160);
    }
L0:
    WaitFor(EventFlag(8062));
    PlaySE(20000, SoundType.EnvironmentalSound, 600080010);
    DeactivateGparamOverride(2);
    SetSpEffect(20000, 99161);
});

$Event(1136, Default, function() {
    EndIf(!EventFlag(7705) && !EventFlag(7725));
    EndIf(EventFlag(8062));
    EndIf(EventFlag(8061) && PlayAreaCurrentTimeInRange(20, 24, 0, 23, 59, 0));
    WaitFor(EventFlag(8061));
    UnknownSound201013(2);
    WaitFor(PlayAreaCurrentTimeInRange(20, 24, 0, 23, 59, 0) || EventFlag(8062));
    UnknownSound201013(0);
});

$Event(1139, Default, function() {
    DisableNetworkSync();
    EndIf(EventFlag(8061));
    EndIf(EventFlag(8043));
    EndIf(EventFlag(8035));
    EndIf(EventFlag(8057));
    EndIf(EventFlag(8071));
    if (EventFlag(7705) || EventFlag(7725)) {
        WaitFor(EventFlag(8061));
        if (EventFlag(8075)) {
            DisplayTextEffectId(6010);
        }
        if (EventFlag(8076)) {
            DisplayTextEffectId(6020);
        }
        if (EventFlag(8078)) {
            DisplayTextEffectId(6040);
            WaitFixedTimeSeconds(3);
            RecordUserDispLog(11144, 20000, LogObjectType.None, -1);
        }
        if (EventFlag(8079)) {
            DisplayTextEffectId(6030);
        }
        EndEvent();
    }
L0:
    if (EventFlag(7701) || EventFlag(7721)) {
        WaitFor(EventFlag(8043));
        DisplayTextEffectId(6060);
        EndEvent();
    }
L1:
    if (EventFlag(7700) || EventFlag(7720)) {
        WaitFor(EventFlag(8035));
        WaitFixedTimeSeconds(7);
        DisplayTextEffectId(6050);
        RecordUserDispLog(11150, 20000, LogObjectType.None, -1);
        EndEvent();
    }
L2:
    if (EventFlag(7704) || EventFlag(7724)) {
        WaitFor(EventFlag(8057));
        if (!EventFlag(8058)) {
            DisplayTextEffectId(6070);
        }
        if (EventFlag(8058)) {
            DisplayTextEffectId(6071);
        }
        EndEvent();
    }
L3:
    if (EventFlag(7707) || EventFlag(7727)) {
        WaitFor(EventFlag(8071));
        DisplayTextEffectId(6080);
        EndEvent();
    }
L4:
    NoOp();
});

$Event(1140, Restart, function() {
    if (!(EventFlag(7700) || EventFlag(7720))) {
        SetNetworkconnectedEventFlagID(7518, OFF);
        EndEvent();
    }
    if (EventFlag(8020)) {
        SetNetworkconnectedEventFlagID(7518, OFF);
        EndEvent();
    }
    WaitFor(EventFlag(8035));
    SetNetworkconnectedEventFlagID(7518, ON);
    WaitFor(EventFlag(8020));
    SetNetworkconnectedEventFlagID(7518, OFF);
});

$Event(1150, Default, function() {
    EndIf(!EventFlag(7602));
    EndIf(AnyBatchEventFlags(8192, 8194));
    EndIf(!PlayerIsInOwnWorld());
    if (EventFlagAndRandomCondition(7602, 0.15)) {
        SetNetworkconnectedEventFlagID(8192, ON);
        EndEvent();
    }
L0:
    if (EventFlagAndRandomCondition(7602, 0.706)) {
        SetNetworkconnectedEventFlagID(8193, ON);
        EndEvent();
    }
L1:
    SetNetworkconnectedEventFlagID(8194, ON);
});

$Event(1151, Default, function() {
    EndIf(!EventFlag(7602));
    EndIf(EventFlag(8190));
    WaitFor(AnyBatchEventFlags(8192, 8194));
    if (EventFlag(8192)) {
        WaitFor(
            (!EventFlag(7505) && PlayAreaCurrentTimeInRange(16, 0, 0, 0, 0, 0)) || EventFlag(7505));
    } else {
L0:
        if (EventFlag(8193)) {
            WaitFor(EventFlag(7505) && PlayAreaCurrentTimeInRange(11, 0, 0, 0, 0, 0));
        } else {
L1:
            if (EventFlag(8194)) {
                WaitFor(EventFlag(7505) && PlayAreaCurrentTimeInRange(16, 0, 0, 0, 0, 0));
            } else {
L2:
                NoOp();
            }
        }
    }
L3:
    SetNetworkconnectedEventFlagID(8190, ON);
});

$Event(1160, Default, function() {
    DisableNetworkSync();
    WaitFor(CharacterHasSpEffect(20000, 99200) && !CharacterHasSpEffect(20000, 99230));
    ShowFloatingMessage(100, 20000);
    WaitFor(!CharacterHasSpEffect(20000, 99200) || CharacterHasSpEffect(20000, 99230));
    HideFloatingMessage(100, 20000);
    WaitFixedTimeSeconds(1);
    RestartEvent();
});

$Event(1161, Default, function() {
    DisableNetworkSync();
    WaitFor(CharacterHasSpEffect(20000, 102610) && !CharacterHasSpEffect(20000, 99230));
    WaitFixedTimeSeconds(2);
    ShowFloatingMessage(101, 20000);
    WaitFor(!CharacterHasSpEffect(20000, 102610) || CharacterHasSpEffect(20000, 99230));
    HideFloatingMessage(101, 20000);
    WaitFixedTimeSeconds(1);
    RestartEvent();
});

$Event(1170, Default, function() {
    DisableNetworkSync();
    WaitFor(EventFlag(4990));
    RecordUserDispLog(11250, 0, LogObjectType.None, -1);
    SetEventFlagID(4990, OFF);
    WaitFixedTimeFrames(1);
    RestartEvent();
});

//multiplayer death handling
$Event(1180, Restart, function() {
    EndIf(HasMultiplayerState(MultiplayerState.Singleplayer));
    WaitFor(EventFlag(7500));
    cond &= !AnyBatchEventFlags(7005, 7007);
    cond &= EventFlag(7515) || EventFlag(7510);
    WaitFor(cond);
    if (AnyBatchEventFlags(7010, 7012)) {
        if (IsPlayerNo(1)) {
            if (CharacterHasSpEffect(10002, 540155)) {
                cond &= CharacterHasSpEffect(10002, 540157) && InsidePlayArea(10002, 0);
                WaitFor(cond);
                SetSpEffect(10002, 540150);
                RemoveItemFromPlayer(ItemType.Goods, 700, 1);
            } else if (CharacterHasSpEffect(10002, 6999100)) {
                cond &= CharacterHasSpEffect(10002, 540157) && InsidePlayArea(10002, 0);
                WaitFor(cond);
                SetSpEffect(10002, 6999101);
                SetSpEffect(10002, 6999104);
                SetSpEffect(10002, 6999105);
                SetSpEffect(10002, 6999106);
                SetSpEffect(10002, 6999107);
            }
        }
L1:
        if (IsPlayerNo(2)) {
            if (CharacterHasSpEffect(10003, 540155)) {
                cond &= CharacterHasSpEffect(10003, 540157) && InsidePlayArea(10003, 0);
                WaitFor(cond);
                SetSpEffect(10003, 540150);
                RemoveItemFromPlayer(ItemType.Goods, 700, 1);
            } else if (CharacterHasSpEffect(10003, 6999100)) {
                cond &= CharacterHasSpEffect(10003, 540157) && InsidePlayArea(10003, 0);
                WaitFor(cond);
                SetSpEffect(10003, 6999101);
                SetSpEffect(10003, 6999104);
                SetSpEffect(10003, 6999105);
                SetSpEffect(10003, 6999106);
                SetSpEffect(10003, 6999107);
            }
        }
L2:
        if (IsPlayerNo(3)) {
            if (CharacterHasSpEffect(10004, 540155)) {
                cond &= CharacterHasSpEffect(10004, 540157) && InsidePlayArea(10004, 0);
                WaitFor(cond);
                SetSpEffect(10004, 540150);
                RemoveItemFromPlayer(ItemType.Goods, 700, 1);
            } else if (CharacterHasSpEffect(10004, 6999100)) {
                cond &= CharacterHasSpEffect(10004, 540157) && InsidePlayArea(10004, 0);
                WaitFor(cond);
                SetSpEffect(10004, 6999101);
                SetSpEffect(10004, 6999104);
                SetSpEffect(10004, 6999105);
                SetSpEffect(10004, 6999106);
                SetSpEffect(10004, 6999107);
            }
        }
L3:
        SaveRequest();
        WaitFor(AnyBatchEventFlags(7005, 7007) || ElapsedSeconds(20));
        WaitFixedTimeSeconds(1);
        RestartEvent();
    }
L0:
    EndIf(EventFlag(7513));
    EnableCharacterInvincibility(10002);
    EnableCharacterInvincibility(10003);
    EnableCharacterInvincibility(10004);
    SetEventFlagID(9017, ON);
    WaitFor(ElapsedSeconds(2));
    if (AnyBatchEventFlags(7005, 7007)) {
        DisableCharacterInvincibility(10002);
        DisableCharacterInvincibility(10003);
        DisableCharacterInvincibility(10004);
        SetEventFlagID(9017, OFF);
        RestartEvent();
    }
    SetSpEffect(10002, 102140);
    SetSpEffect(10003, 102140);
    SetSpEffect(10004, 102140);
    WaitFor(ElapsedSeconds(2));
    EndIf(EventFlag(7513));
    UnknownTextEffect200721(3000);
    SetEventFlagID(7519, ON);
    DisplayTextEffectId(4010);
    SetEventFlagID(7516, ON);
    WaitFixedTimeSeconds(5);
    SetEventFlagID(7001, ON);
    EndEvent();
});

//singleplayer death handling (vanilla)
$Event(1181, Restart, function() {
    EndIf(PlayerInMap(13, 20, 0, 0)
    || PlayerInMap(18, 0, 0, 0)
    || PlayerInMap(19, 0, 0, 0));
    if (!HasMultiplayerState(MultiplayerState.Singleplayer)) {
        EndEvent();
    }
    WaitFor(EventFlag(7500));
    WaitFor((EventFlag(7515) || EventFlag(7510)) && CharacterHPValue(10000) > 0);
    WaitFor(
        (!EventFlag(7515) && !EventFlag(7510))
            || CharacterHPValue(10000) <= 0
            || CharacterHasTeamType(10000, TeamType.Unknown77));
    RestartIf(!EventFlag(7515) && !EventFlag(7510));
    if (CharacterHasSpEffect(20000, 6999500)) {
        WaitFor(CharacterHasSpEffect(20000, 540157));
        SetSpEffect(20000, 6999505);
        SetSpEffect(20000, 6999501);
        WaitFor(CharacterHPValue(20000) != 0 && !CharacterHasTeamType(10000, TeamType.Unknown77));
        RestartEvent();
    }
    if (CharacterHasSpEffect(20000, 540155)) {
        WaitFor(CharacterHasSpEffect(20000, 540157));
        SetSpEffect(20000, 540150);
        RemoveItemFromPlayer(ItemType.Goods, 700, 1);
        WaitFor(CharacterHPValue(20000) != 0 && !CharacterHasTeamType(10000, TeamType.Unknown77));
        RestartEvent();
    }
    if (CharacterHasSpEffect(20000, 6999100)) {
        WaitFor(CharacterHasSpEffect(20000, 540157));
        SetSpEffect(20000, 6999101);
        SetSpEffect(20000, 6999104);
        SetSpEffect(20000, 6999105);
        SetSpEffect(20000, 6999106);
        SetSpEffect(20000, 6999107);
        WaitFor(CharacterHPValue(20000) != 0 && !CharacterHasTeamType(10000, TeamType.Unknown77));
        RestartEvent();
    }
    EndIf(EventFlag(7513));
    SetSpEffect(20000, 102140);
    SetEventFlagID(9017, ON);
    WaitFixedTimeSeconds(4);
    EndIf(EventFlag(7513));
    SetEventFlagID(7519, ON);
    DisplayTextEffectId(4010);
    SetEventFlagID(7516, ON);
    WaitFixedTimeSeconds(5);
    SetEventFlagID(7001, ON);
    EndEvent();
});

$Event(1182, Restart, function(eventFlagId) {
    DisableNetworkSync();
    SetNetworkconnectedEventFlagID(eventFlagId, ON);
    WaitFor(
        ((EventFlag(7515) || EventFlag(7510))
            && (CharacterHPValue(20000) > 0 || CharacterHasTeamType(20000, TeamType.Unknown77)))
            || !EventFlag(eventFlagId));
    WaitFor(
        !(CharacterHasTeamType(20000, TeamType.Human)
            || CharacterHasTeamType(20000, TeamType.WhitePhantom)
            || CharacterHasTeamType(20000, TeamType.Coop)
            || CharacterHasTeamType(20000, TeamType.Indiscriminate))
            || (!EventFlag(7515) && !EventFlag(7510))
            || !EventFlag(eventFlagId));
    RestartIf(!EventFlag(7515) && !EventFlag(7510));
    SetNetworkconnectedEventFlagID(eventFlagId, OFF);
    WaitFor(
        CharacterHasTeamType(20000, TeamType.Human)
            || CharacterHasTeamType(20000, TeamType.WhitePhantom)
            || CharacterHasTeamType(20000, TeamType.Coop)
            || CharacterHasTeamType(20000, TeamType.Indiscriminate)
            || EventFlag(eventFlagId));
    RestartEvent();
});

$Event(1183, Restart, function(eventFlagId, eventFlagId2) {
    DisableNetworkSync();
    if (!(CharacterHasSpEffect(20000, 540155) || CharacterHasSpEffect(20000, 6999100))) {
        SetNetworkconnectedEventFlagID(eventFlagId, OFF);
    }
    spFlag = CharacterHasSpEffect(20000, 540155)
        || CharacterHasSpEffect(20000, 6999100)
        || EventFlag(eventFlagId);
    WaitFor(spFlag || ElapsedSeconds(10));
    RestartIf(!spFlag.Passed);
    SetNetworkconnectedEventFlagID(eventFlagId, ON);
    spFlag2 = (!CharacterHasSpEffect(20000, 540155) && !CharacterHasSpEffect(20000, 6999100))
        || !EventFlag(eventFlagId);
    WaitFor(spFlag2 || ElapsedSeconds(10));
    RestartIf(!spFlag2.Passed);
    if (!EventFlag(eventFlagId)) {
        WaitFor(EventFlag(eventFlagId2));
    }
    RestartEvent();
});

$Event(1184, Restart, function(chrEntityId, eventFlagId, eventFlagId2) {
    WaitFor(
        !(CharacterHasTeamType(chrEntityId, TeamType.Human)
            || CharacterHasTeamType(chrEntityId, TeamType.WhitePhantom)
            || CharacterHasTeamType(chrEntityId, TeamType.Coop)
            || CharacterHasTeamType(chrEntityId, TeamType.Indiscriminate)
            || CharacterHasTeamType(chrEntityId, TeamType.Unknown77)
            || CharacterHasTeamType(chrEntityId, TeamType.Disabled))
            && (EventFlag(eventFlagId) || EventFlag(eventFlagId2))
            && PlayerIsInOwnWorld());
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(eventFlagId, OFF);
        SetNetworkconnectedEventFlagID(eventFlagId2, OFF);
    }
    RestartEvent();
});

$Event(1187, Default, function() {
    if (!HasMultiplayerState(MultiplayerState.Singleplayer)) {
        EndEvent();
    }
    EndIf(EventFlag(7519));
    WaitFor(EventFlag(7516));
    UnknownTextEffect200721(3000);
    WaitFixedTimeFrames(2);
    RestartEvent();
});

$Event(1190, Default, function() {
    WaitFor(
        EventFlag(47000800)
            || EventFlag(47100800)
            || EventFlag(47200800)
            || EventFlag(47300800)
            || EventFlag(47400800)
            || EventFlag(47700800)
            || EventFlag(47800800)
            || EventFlag(47900800)
            || EventFlag(48000800)
            || EventFlag(48100800)
            || EventFlag(48200800)
            || EventFlag(48300800)
            || EventFlag(48400800)
            || EventFlag(48500800)
            || EventFlag(48600800)
            || EventFlag(48700800)
            || EventFlag(48800800)
            || EventFlag(48900800)
            || EventFlag(49100800)
            || EventFlag(49170800)
            || EventFlag(49180800)
            || EventFlag(49190800)
            || EventFlag(49200800)
            || EventFlag(49210800)
            || EventFlag(49230800)
            || EventFlag(49240800)
            || EventFlag(49250800)
            || EventFlag(49260800)
            || EventFlag(49270800)
            || EventFlag(49280800)
            || EventFlag(49290800)
            || EventFlag(49300800)
            || EventFlag(49900800));
    SetNetworkconnectedEventFlagID(7502, ON);
});

$Event(1191, Default, function() {
    WaitFor(
        EventFlag(47000850)
            || EventFlag(47100850)
            || EventFlag(47200850)
            || EventFlag(47300850)
            || EventFlag(47400850)
            || EventFlag(47700850)
            || EventFlag(47800850)
            || EventFlag(47900850)
            || EventFlag(48000850)
            || EventFlag(48100850)
            || EventFlag(48200850)
            || EventFlag(48300850)
            || EventFlag(48400850)
            || EventFlag(48500850)
            || EventFlag(48600850)
            || EventFlag(48700850)
            || EventFlag(48800850)
            || EventFlag(48900850)
            || EventFlag(49100850)
            || EventFlag(49170850)
            || EventFlag(49180850)
            || EventFlag(49190850)
            || EventFlag(49200850)
            || EventFlag(49210850)
            || EventFlag(49230850)
            || EventFlag(49240850)
            || EventFlag(49250850)
            || EventFlag(49260850)
            || EventFlag(49270850)
            || EventFlag(49280850)
            || EventFlag(49290850)
            || EventFlag(49300850)
            || EventFlag(49900850));
    SetNetworkconnectedEventFlagID(7507, ON);
});

$Event(1200, Default, function() {
    EndIf(HasMultiplayerState(MultiplayerState.Singleplayer));
    EndIf(EventFlag(7510));
    EndIf(EventFlag(7523));
    WaitFor(EventFlag(7523));
    SetNetworkconnectedEventFlagID(9052, ON);
    WarpPlayerWithPlayerNo(12, 0, 0, 0, 12002310);
});

$Event(1201, Default, function() {
    DisableAsset(1060001501);
    EndIf(!EventFlag(7605));
    DisableAsset(1060001500);
    EnableAsset(1060001501);
});

$Event(1202, Default, function() {
    DisableAsset(1060001502);
    EndIf(!EventFlag(7602));
    DisableAsset(1060001500);
    DisableAsset(1060001510);
    EnableAsset(1060001502);
});

$Event(1210, Default, function() {
    DisableNetworkSync();
    WaitFor(EventFlag(1056304580) || EventFlag(9192));
    SetEventFlagID(1056304581, ON);
});

//day banners
$Event(1300, Default, function() {
    DisableNetworkSync();
    EndIf(PlayerInMap(18, 0, 0, 0));
    EndIf(PlayerInMap(11, 0, 0, 0));
    WaitFixedTimeSeconds(2);
    if (EventFlag(7500) && !EventFlag(7505)) {
        DisplayTextEffectId(4099);
    }
    if (EventFlag(7505) && !EventFlag(7510)) {
        DisplayTextEffectId(4100);
    }
    if (EventFlag(7500) && !EventFlag(7505)) {
        WaitFor(EventFlag(7505));
        WaitFixedTimeSeconds(4);
        DisplayTextEffectId(4100);
    }
});

$Event(1301, Default, function() {
    DisableNetworkSync();
    if (!IsRequestGameMode(3)) {
        if (!EventFlag(6013)) {
            WaitFor(
                (EventFlag(7515) && InsidePlayArea(10000, 0))
                    || (EventFlag(7510) && !EventFlag(7513))
                    || EventFlag(9015));
            SetEventFlagID(9015, ON);
            WaitFor((!EventFlag(7515) && !EventFlag(7510)) || EventFlag(7513) || !EventFlag(9015));
            SetEventFlagID(9015, OFF);
            RestartEvent();
        }
    }
L0:
    SetEventFlagID(9015, ON);
});

$Event(1302, Default, function() {
    DisableNetworkSync();
    WaitFor(EventFlag(9015) || CharacterHasSpEffect(10000, 102120));
    SetSpEffect(10000, 102120);
    WaitFor(!EventFlag(9015) || !CharacterHasSpEffect(10000, 102120));
    SetSpEffect(20000, 102121);
    RestartEvent();
});

$Event(1303, Restart, function() {
    DisableNetworkSync();
    EndIf(EventFlag(9050));
    if (EventFlag(7502)) {
        AddEstusCharge();
        RefillEstus();
        EndEvent();
    }
    WaitFor(EventFlag(7502));
    SpawnOneshotSFX(TargetEntityType.Character, 20000, 905, 305033);
    AddEstusCharge();
    RefillEstus();
    RecordUserDispLog(11251, 20000, LogObjectType.None, -1);
});

$Event(1304, Restart, function() {
    DisableNetworkSync();
    EndIf(EventFlag(9051));
    if (EventFlag(7507)) {
        AddEstusCharge();
        RefillEstus();
        SetEventFlagID(9051, ON);
        EndEvent();
    }
    WaitFor(EventFlag(7507));
    WaitFixedTimeSeconds(3);
    SetSpEffect(20000, 99270);
    AddEstusCharge();
    RefillEstus();
    SetEventFlagID(9051, ON);
    WaitFixedTimeSeconds(0.5);
    RecordUserDispLog(11251, 20000, LogObjectType.None, -1);
});

$Event(1305, Default, function() {
    DisableNetworkSync();
    WaitFor(
        IsGameMode(2) && (EventFlag(7516) || EventFlag(7512)) && (IsPlayMode(0) || IsPlayMode(1)));
    SetEventFlagID(6090, OFF);
    SetEventFlagID(6091, OFF);
    SetEventFlagID(6092, OFF);
    SetEventFlagID(6093, OFF);
    SetEventFlagID(6095, OFF);
    GotoIf(L1, EventFlag(7602));
    GotoIf(L2, EventFlag(7601));
    GotoIf(L3, EventFlag(7603));
    GotoIf(L4, EventFlag(7605));
    SetEventFlagID(6095, ON);
    EndEvent();
L1:
    SetEventFlagID(6090, ON);
    EndEvent();
L2:
    SetEventFlagID(6091, ON);
    EndEvent();
L3:
    SetEventFlagID(6092, ON);
    EndEvent();
L4:
    SetEventFlagID(6093, ON);
    EndEvent();
});

$Event(1306, Default, function() {
    DisableNetworkSync();
    EndIf(!IsGameMode(2));
    SetSpEffect(20000, 7998000);
    SetSpEffect(20000, 7998003);
});

//solo rune bonus
$Event(1307, Restart, function() {
    DisableNetworkSync();
    //EndIf(!IsGameMode(2));
    WaitFor(
        HasMultiplayerState(MultiplayerState.Singleplayer) || CharacterHasSpEffect(20000, 99240));
    SetSpEffect(20000, 99240);
    WaitFor(
        HasMultiplayerState(MultiplayerState.Multiplayer) || !CharacterHasSpEffect(20000, 99240));
    ClearSpEffect(20000, 99240);
    RestartEvent();
});

//duo rune bonus
$Event(1308, Restart, function() {
    DisableNetworkSync();
    //EndIf(!IsGameMode(2));
    WaitFor(IsPlayerCount(2) || CharacterHasSpEffect(20000, 99241));
    SetSpEffect(20000, 99241);
    WaitFor(!IsPlayerCount(2) || !CharacterHasSpEffect(20000, 99241));
    ClearSpEffect(20000, 99241);
    RestartEvent();
});

$Event(1309, Restart, function() {
    DisableNetworkSync();
    EndIf(!(IsGameMode(2) || IsGameMode(4)));
    EndIf(EventFlag(9052));
    WaitFor(
        !(WeatherActive(Weather.Type83, 0, 0) || WeatherActive(Weather.Type81, 0, 0))
            && (InArea(20000, 1045372400) || InArea(20000, 1029102400)));
    if (InArea(20000, 1045372400)) {
        ChangeWeather(Weather.Type51, -1, false);
        areaFlag = !InArea(20000, 1045372400) || EventFlag(9052);
        cond = WeatherActive(Weather.Type83, 0, 0) || WeatherActive(Weather.Type81, 0, 0);
        WaitFor(areaFlag || cond);
        RestartIf(cond.Passed);
        ChangeWeather(Weather.Type00, -1, false);
        RestartEvent();
    }
L0:
    if (InArea(20000, 1029102400)) {
        ChangeWeather(Weather.Type40, -1, false);
        cond2 = !InArea(20000, 1029102400) || EventFlag(9052);
        cond3 = WeatherActive(Weather.Type83, 0, 0) || WeatherActive(Weather.Type81, 0, 0);
        WaitFor(cond2 || cond3);
        RestartIf(cond3.Passed);
        ChangeWeather(Weather.Type00, -1, false);
        RestartEvent();
    }
L1:
    NoOp();
});

//death handling?
$Event(1310, Restart, function(eventFlagId) {
    DisableNetworkSync();
    EndIf(!IsGameMode(2));
    WaitFor(
        EventFlag(9015)
            && CharacterHasTeamType(20000, TeamType.Unknown77)
            && CharacterHasSpEffect(20000, 540157)
            && !InsidePlayArea(20000, 0));
    cond = !AnyBatchEventFlags(7005, 7007) && EventFlag(eventFlagId);
    flagChr = !EventFlag(9015) || !CharacterHasTeamType(20000, TeamType.Unknown77) || InsidePlayArea(20000, 0);
    WaitFor(ElapsedSeconds(15) || cond || flagChr);
    EndIf(EventFlag(7516));
    RestartIf(flagChr.Passed);
    SetSpEffect(20000, 102145);
    WaitFor(
        !EventFlag(9015)
            || !CharacterHasTeamType(20000, TeamType.Unknown77)
            || InsidePlayArea(20000, 0));
    RestartEvent();
});

$Event(1311, Default, function() {
    DisableNetworkSync();
    WaitFor(IsGameMode(2) && EventFlag(7516));
    GotoIf(L0, !EventFlag(105));
    GotoIf(L1, !EventFlag(106));
    Goto(L2);
L0:
    SetEventFlagID(105, ON);
    SetEventFlagID(106, OFF);
    EndEvent();
L1:
    SetEventFlagID(105, ON);
    SetEventFlagID(106, ON);
    EndEvent();
L2:
    EndEvent();
});

//relic awards
$Event(1312, Default, function() {
    DisableNetworkSync();
    WaitFor(IsGameMode(2) && (EventFlag(7516) || EventFlag(7512)));
    SetEventFlagID(9089, OFF);
    SetEventFlagID(9090, OFF);
    SetEventFlagID(9091, OFF);
    SetEventFlagID(9092, OFF);
    SetEventFlagID(9093, OFF);
    SetEventFlagID(9094, OFF);
    SetEventFlagID(9095, OFF);
    SetEventFlagID(9096, OFF);
    SetEventFlagID(9097, OFF);
    if (IsCampaignSession()) {
        SetEventFlagID(9089, ON);
    }
L0:
    GotoIf(L1, TargetingBoss(TargetBoss.Gladius));
    GotoIf(L2, TargetingBoss(TargetBoss.Adel));
    GotoIf(L3, TargetingBoss(TargetBoss.Gnoster));
    GotoIf(L4, TargetingBoss(TargetBoss.Maris));
    GotoIf(L5, TargetingBoss(TargetBoss.Libra));
    GotoIf(L6, TargetingBoss(TargetBoss.Fulghor));
    GotoIf(L7, TargetingBoss(TargetBoss.Caligo));
    GotoIf(L8, TargetingBoss(TargetBoss.Heolstor));
    EndEvent();
L1:
    SetEventFlagID(9090, ON);
    EndEvent();
L2:
    SetEventFlagID(9091, ON);
    EndEvent();
L3:
    SetEventFlagID(9092, ON);
    EndEvent();
L4:
    SetEventFlagID(9093, ON);
    EndEvent();
L5:
    SetEventFlagID(9094, ON);
    EndEvent();
L6:
    SetEventFlagID(9095, ON);
    EndEvent();
L7:
    SetEventFlagID(9096, ON);
    EndEvent();
L8:
    SetEventFlagID(9097, ON);
    EndEvent();
});

$Event(1313, Default, function() {
    DisableNetworkSync();
    EndIf(EventFlag(131));
    WaitFor(IsGameMode(2) && IsPlayMode(2) && (EventFlag(7516) || EventFlag(7512)));
    SetEventFlagID(131, ON);
    EndEvent();
});

$Event(1314, Default, function() {
    DisableNetworkSync();
    WaitFor((EventFlag(7506) && EventFlag(9015)) || EventFlag(7507));
    SetEventFlagID(9018, ON);
});

$Event(1320, Restart, function(spEffectId, spEffectId2) {
    WaitFor(CharacterHasSpEffect(20000, spEffectId));
    ClearSpEffect(20000, spEffectId);
    WaitFor(!InsidePlayArea(20000, 0) || ElapsedFrames(1));
    if (!InsidePlayArea(20000, 0)) {
        SetSpEffect(20000, spEffectId2);
    }
    RestartEvent();
});

$Event(1325, Restart, function() {
    DisableNetworkSync();
    if (!EventFlag(7508)) {
        WaitFor(EventFlag(7508));
        WaitFixedTimeSeconds(4);
    }
L0:
    WaitFor(!CharacterHasSpEffect(20000, 99271));
    SetSpEffect(20000, 99271);
    WaitFor(!CharacterHasSpEffect(20000, 99271));
    RestartEvent();
});

$Event(1330, Restart, function(areaEntityId) {
    DisableNetworkSync();
    WaitFor(InArea(20000, areaEntityId));
    SetSpEffect(20000, 16166);
    WaitFor(!InArea(20000, areaEntityId));
    SetSpEffect(20000, 16167);
    RestartEvent();
});

//evergaol relic buffs
$Event(1400, Restart, function(spEffectId, spEffectId2) {
    DisableNetworkSync();
    EndIf(!CharacterHasSpEffect(20000, spEffectId));
    if (EventValue(9125, 4) < 1) {
        WaitFor(EventValue(8145, 4) >= 1);
        IncrementEventValue(9125, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L1:
    if (EventValue(9125, 4) < 2) {
        WaitFor(EventValue(8145, 4) >= 2);
        IncrementEventValue(9125, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L2:
    if (EventValue(9125, 4) < 3) {
        WaitFor(EventValue(8145, 4) >= 3);
        IncrementEventValue(9125, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L3:
    if (EventValue(9125, 4) < 4) {
        WaitFor(EventValue(8145, 4) >= 4);
        IncrementEventValue(9125, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L4:
    if (EventValue(9125, 4) < 5) {
        WaitFor(EventValue(8145, 4) >= 5);
        IncrementEventValue(9125, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L5:
    if (EventValue(9125, 4) < 6) {
        WaitFor(EventValue(8145, 4) >= 6);
        IncrementEventValue(9125, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L6:
    if (EventValue(9125, 4) < 7) {
        WaitFor(EventValue(8145, 4) >= 7);
        IncrementEventValue(9125, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L7:
    NoOp();
});

//evergaol relic buffs
$Event(1401, Default, function() {
    WaitFor(
        EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 46500800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 146500800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 246500800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 346500800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 446500800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 546500800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 646500800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 746500800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 846500800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 946500800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 46600800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 146600800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 246600800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 346600800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 446600800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 546600800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 646600800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 746600800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 846600800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 946600800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 46700800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 146700800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 246700800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 346700800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 446700800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 546700800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 646700800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 746700800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 846700800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 946700800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 46800800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 146800800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 246800800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 346800800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 446800800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 546800800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 646800800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 746800800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 846800800)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 946800800));
    IncrementNetworkconnectedEventValue(8145, 4, 7);
    RestartEvent();
});

$Event(1402, Restart, function(spEffectId, spEffectId2) {
    DisableNetworkSync();
    EndIf(!CharacterHasSpEffect(20000, spEffectId));
    if (EventValue(9135, 3) < 1) {
        WaitFor(EventValue(8155, 3) >= 1);
        IncrementEventValue(9135, 3, 4);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L1:
    if (EventValue(9135, 3) < 2) {
        WaitFor(EventValue(8155, 3) >= 2);
        IncrementEventValue(9135, 3, 4);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L2:
    if (EventValue(9135, 3) < 3) {
        WaitFor(EventValue(8155, 3) >= 3);
        IncrementEventValue(9135, 3, 4);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L3:
    if (EventValue(9135, 3) < 4) {
        WaitFor(EventValue(8155, 3) >= 4);
        IncrementEventValue(9135, 3, 4);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L4:
    NoOp();
});

//sorcerer's rise buffs
$Event(1403, Default, function(spEffectId, spEffectId2) {
    DisableNetworkSync();
    EndIf(!CharacterHasSpEffect(20000, spEffectId));
    if (EventValue(9120, 4) < 1) {
        WaitFor(EventValue(8140, 4) >= 1);
        IncrementEventValue(9120, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L1:
    if (EventValue(9120, 4) < 2) {
        WaitFor(EventValue(8140, 4) >= 2);
        IncrementEventValue(9120, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L2:
    if (EventValue(9120, 4) < 3) {
        WaitFor(EventValue(8140, 4) >= 3);
        IncrementEventValue(9120, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L3:
    if (EventValue(9120, 4) < 4) {
        WaitFor(EventValue(8140, 4) >= 4);
        IncrementEventValue(9120, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L4:
    if (EventValue(9120, 4) < 5) {
        WaitFor(EventValue(8140, 4) >= 5);
        IncrementEventValue(9120, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L5:
    if (EventValue(9120, 4) < 6) {
        WaitFor(EventValue(8140, 4) >= 6);
        IncrementEventValue(9120, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L6:
    if (EventValue(9120, 4) < 7) {
        WaitFor(EventValue(8140, 4) >= 7);
        IncrementEventValue(9120, 4, 7);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L7:
    NoOp();
});

//sorcerer's rise buffs?
$Event(1404, Default, function() {
    WaitFor(
        EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 40000500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 140000500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 240000500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 340000500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 440000500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 540000500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 640000500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 740000500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 840000500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 940000500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 40900500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 140900500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 240900500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 340900500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 440900500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 540900500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 640900500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 740900500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 840900500)
            || EventFlagState(CHANGE, TargetEventFlagType.EventFlag, 940900500));
    IncrementNetworkconnectedEventValue(8140, 4, 7);
    RestartEvent();
});

$Event(1405, Restart, function(spEffectId, eventFlagId) {
    DisableNetworkSync();
    EndIf(!CharacterHasSpEffect(20000, spEffectId));
    SetEventFlagID(eventFlagId, ON);
});

$Event(1406, Default, function(spEffectId, spEffectId2, spEffectId3, eventFlagId, eventFlagId2) {
    DisableNetworkSync();
    WaitFor(CharacterHasSpEffect(20000, spEffectId));
    if (EventValue(eventFlagId2, 4) < 1) {
        WaitFor(EventValue(eventFlagId, 4) >= 1);
        IncrementEventValue(eventFlagId2, 4, 10);
        SetSpEffect(20000, spEffectId2);
        if (Signed(spEffectId3) != 0) {
            SetSpEffect(20000, spEffectId3);
        }
        WaitFixedTimeFrames(1);
    }
L1:
    if (EventValue(eventFlagId2, 4) < 2) {
        WaitFor(EventValue(eventFlagId, 4) >= 2);
        IncrementEventValue(eventFlagId2, 4, 10);
        SetSpEffect(20000, spEffectId2);
        if (Signed(spEffectId3) != 0) {
            SetSpEffect(20000, spEffectId3);
        }
        WaitFixedTimeFrames(1);
    }
L2:
    if (EventValue(eventFlagId2, 4) < 3) {
        WaitFor(EventValue(eventFlagId, 4) >= 3);
        IncrementEventValue(eventFlagId2, 4, 10);
        SetSpEffect(20000, spEffectId2);
        if (Signed(spEffectId3) != 0) {
            SetSpEffect(20000, spEffectId3);
        }
        WaitFixedTimeFrames(1);
    }
L3:
    if (EventValue(eventFlagId2, 4) < 4) {
        WaitFor(EventValue(eventFlagId, 4) >= 4);
        IncrementEventValue(eventFlagId2, 4, 10);
        SetSpEffect(20000, spEffectId2);
        if (Signed(spEffectId3) != 0) {
            SetSpEffect(20000, spEffectId3);
        }
        WaitFixedTimeFrames(1);
    }
L4:
    if (EventValue(eventFlagId2, 4) < 5) {
        WaitFor(EventValue(eventFlagId, 4) >= 5);
        IncrementEventValue(eventFlagId2, 4, 10);
        SetSpEffect(20000, spEffectId2);
        if (Signed(spEffectId3) != 0) {
            SetSpEffect(20000, spEffectId3);
        }
        WaitFixedTimeFrames(1);
    }
L5:
    if (EventValue(eventFlagId2, 4) < 6) {
        WaitFor(EventValue(eventFlagId, 4) >= 6);
        IncrementEventValue(eventFlagId2, 4, 10);
        SetSpEffect(20000, spEffectId2);
        if (Signed(spEffectId3) != 0) {
            SetSpEffect(20000, spEffectId3);
        }
        WaitFixedTimeFrames(1);
    }
L6:
    if (EventValue(eventFlagId2, 4) < 7) {
        WaitFor(EventValue(eventFlagId, 4) >= 7);
        IncrementEventValue(eventFlagId2, 4, 10);
        SetSpEffect(20000, spEffectId2);
        if (Signed(spEffectId3) != 0) {
            SetSpEffect(20000, spEffectId3);
        }
        WaitFixedTimeFrames(1);
    }
L7:
    if (EventValue(eventFlagId2, 4) < 8) {
        WaitFor(EventValue(eventFlagId, 4) >= 8);
        IncrementEventValue(eventFlagId2, 4, 10);
        SetSpEffect(20000, spEffectId2);
        if (Signed(spEffectId3) != 0) {
            SetSpEffect(20000, spEffectId3);
        }
        WaitFixedTimeFrames(1);
    }
L8:
    if (EventValue(eventFlagId2, 4) < 9) {
        WaitFor(EventValue(eventFlagId, 4) >= 9);
        IncrementEventValue(eventFlagId2, 4, 10);
        SetSpEffect(20000, spEffectId2);
        if (Signed(spEffectId3) != 0) {
            SetSpEffect(20000, spEffectId3);
        }
        WaitFixedTimeFrames(1);
    }
L9:
    if (EventValue(eventFlagId2, 4) < 10) {
        WaitFor(EventValue(eventFlagId, 4) >= 10);
        IncrementEventValue(eventFlagId2, 4, 10);
        SetSpEffect(20000, spEffectId2);
        if (Signed(spEffectId3) != 0) {
            SetSpEffect(20000, spEffectId3);
        }
        WaitFixedTimeFrames(1);
    }
L10:
    NoOp();
});

//fell omen graces buff
$Event(1450, Default, function(spEffectId, spEffectId2) {
    DisableNetworkSync();
    WaitFor(CharacterHasSpEffect(20000, spEffectId));
    if (EventValue(9130, 4) < 1) {
        WaitFor(TeamOpenedBonfires() >= 1);
        IncrementEventValue(9130, 4, 10);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L1:
    if (EventValue(9130, 4) < 2) {
        WaitFor(TeamOpenedBonfires() >= 2);
        IncrementEventValue(9130, 4, 10);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L2:
    if (EventValue(9130, 4) < 3) {
        WaitFor(TeamOpenedBonfires() >= 3);
        IncrementEventValue(9130, 4, 10);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L3:
    if (EventValue(9130, 4) < 4) {
        WaitFor(TeamOpenedBonfires() >= 4);
        IncrementEventValue(9130, 4, 10);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L4:
    if (EventValue(9130, 4) < 5) {
        WaitFor(TeamOpenedBonfires() >= 5);
        IncrementEventValue(9130, 4, 10);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L5:
    if (EventValue(9130, 4) < 6) {
        WaitFor(TeamOpenedBonfires() >= 6);
        IncrementEventValue(9130, 4, 10);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L6:
    if (EventValue(9130, 4) < 7) {
        WaitFor(TeamOpenedBonfires() >= 7);
        IncrementEventValue(9130, 4, 10);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L7:
    if (EventValue(9130, 4) < 8) {
        WaitFor(TeamOpenedBonfires() >= 8);
        IncrementEventValue(9130, 4, 10);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L8:
    if (EventValue(9130, 4) < 9) {
        WaitFor(TeamOpenedBonfires() >= 9);
        IncrementEventValue(9130, 4, 10);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L9:
    if (EventValue(9130, 4) < 10) {
        WaitFor(TeamOpenedBonfires() >= 10);
        IncrementEventValue(9130, 4, 10);
        SetSpEffect(20000, spEffectId2);
        WaitFixedTimeFrames(1);
    }
L10:
    NoOp();
});

$Event(1500, Restart, function() {
    if (!EventFlag(6013)) {
        if (!EventFlag(6011)) {
            SetEventFlagID(72200, ON);
            SetEventFlagID(72201, ON);
            EndEvent();
        }
L0:
        SetEventFlagID(72200, OFF);
        SetEventFlagID(72201, OFF);
        EndEvent();
    }
L1:
    SetEventFlagID(72200, OFF);
    SetEventFlagID(72201, ON);
    EndEvent();
});

$Event(1505, Restart, function(eventFlagId, eventFlagId2) {
    if (!EventFlag(eventFlagId2)) {
        SetEventFlagID(eventFlagId, ON);
        EndEvent();
    }
    SetEventFlagID(eventFlagId, OFF);
    EndEvent();
});

$Event(1506, Restart, function(eventFlagId, eventFlagId2) {
    if (!(EventFlag(eventFlagId2) || EventFlag(6011))) {
        SetEventFlagID(eventFlagId, OFF);
        EndEvent();
    }
    SetEventFlagID(eventFlagId, ON);
    EndEvent();
});

$Event(1510, Restart, function(eventFlagId, eventFlagId2) {
    if (!EventFlag(eventFlagId2)) {
        SetEventFlagID(eventFlagId, ON);
        EndEvent();
    }
    SetEventFlagID(eventFlagId, OFF);
    EndEvent();
});

$Event(1519, Restart, function(eventFlagId, eventFlagId2) {
    if (!(EventFlag(eventFlagId2) || EventFlag(6011))) {
        SetEventFlagID(eventFlagId, OFF);
        EndEvent();
    }
    SetEventFlagID(eventFlagId, ON);
    EndEvent();
});

$Event(1520, Restart, function(missionId, eventFlagId, eventFlagId2) {
    DisableNetworkSync();
    EndIf(!MissionActive(missionId));
    if (IsPlayerNo(1)) {
        EndIf(!EventFlag(7015));
    }
    if (IsPlayerNo(2)) {
        EndIf(!EventFlag(7016));
    }
    if (IsPlayerNo(3)) {
        EndIf(!EventFlag(7017));
    }
    EndIf(EventFlag(eventFlagId));
    SetNetworkconnectedEventFlagID(eventFlagId2, ON);
});

$Event(1590, Default, function() {
    EndIf(!MissionActive(602));
    EndIf(!IsHero(Hero.Revenant));
    WaitFor(EventFlag(9205));
    SetNetworkconnectedEventFlagID(8456, ON);
    SetNetworkconnectedEventFlagID(8457, ON);
    SetNetworkconnectedEventFlagID(8458, ON);
    SetNetworkconnectedEventFlagID(8459, ON);
    SetNetworkconnectedEventFlagID(8460, ON);
    SetNetworkconnectedEventFlagID(8461, ON);
    SetNetworkconnectedEventFlagID(8462, ON);
    SetNetworkconnectedEventFlagID(8463, ON);
    SetNetworkconnectedEventFlagID(8464, ON);
});

$Event(1591, Default, function() {
    EndIf(!MissionActive(801));
    EndIf(!IsHero(Hero.Executor));
    WaitFor(EventFlag(9215));
    SetNetworkconnectedEventFlagID(9261, ON);
    SetNetworkconnectedEventFlagID(9262, ON);
    SetNetworkconnectedEventFlagID(9263, ON);
    SetNetworkconnectedEventFlagID(9264, ON);
    SetNetworkconnectedEventFlagID(9265, ON);
    SetNetworkconnectedEventFlagID(9266, ON);
    SetNetworkconnectedEventFlagID(9267, ON);
});

$Event(1592, Default, function(eventFlagId, eventFlagId2, eventFlagId3) {
    DisableNetworkSync();
    EndIf(!MissionActive(101));
    if (IsPlayerNo(1)) {
        EndIf(!EventFlag(7015));
    }
    if (IsPlayerNo(2)) {
        EndIf(!EventFlag(7016));
    }
    if (IsPlayerNo(3)) {
        EndIf(!EventFlag(7017));
    }
    EndIf(EventFlag(8325));
    SetEventFlagID(eventFlagId, ON);
    SetEventFlagID(eventFlagId2, OFF);
    SetEventFlagID(eventFlagId3, OFF);
    WaitFor(EventFlag(eventFlagId3));
    SetEventFlagID(eventFlagId, OFF);
    SetEventFlagID(eventFlagId2, ON);
    WaitFor(!EventFlag(eventFlagId3));
    RestartEvent();
});

$Event(1600, Default, function() {
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(50));
    GotoIf(L0, EventFlag(2000));
    GotoIf(L1, EventFlag(2001));
    GotoIf(L2, EventFlag(2002));
L0:
L9:
L1:
L9_:
L2:
L9__:
L9___:
    SetEventFlagID(50, ON);
    EndEvent();
});

$Event(1601, Default, function() {
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(50));
    GotoIf(L0, EventFlag(2000));
    GotoIf(L1, EventFlag(2001));
    GotoIf(L2, EventFlag(2002));
L0:
    AwardGesture(0);
    AwardGesture(2);
    AwardGesture(7);
    AwardGesture(8);
    AwardGesture(20);
    AwardGesture(21);
    AwardGesture(22);
    AwardGesture(23);
    AwardGesture(24);
    AwardGesture(30);
    AwardGesture(50);
    AwardGesture(52);
    AwardGesture(60);
    AwardGesture(70);
    AwardGesture(71);
L9:
L1:
    AwardGesture(0);
    AwardGesture(2);
    AwardGesture(7);
    AwardGesture(8);
    AwardGesture(20);
    AwardGesture(21);
    AwardGesture(22);
    AwardGesture(23);
    AwardGesture(24);
    AwardGesture(30);
    AwardGesture(50);
    AwardGesture(52);
    AwardGesture(60);
    AwardGesture(70);
    AwardGesture(71);
L9_:
L2:
    AwardGesture(0);
    AwardGesture(2);
    AwardGesture(7);
    AwardGesture(8);
    AwardGesture(20);
    AwardGesture(21);
    AwardGesture(22);
    AwardGesture(23);
    AwardGesture(24);
    AwardGesture(30);
    AwardGesture(50);
    AwardGesture(52);
    AwardGesture(60);
    AwardGesture(70);
    AwardGesture(71);
L9__:
L9___:
    EndEvent();
});

$Event(1610, Restart, function() {
    DisableNetworkSync();
    if (EventFlag(6950)) {
        if (!EventFlag(61000)) {
            WaitFixedTimeFrames(3);
            WaitFor(CutsceneEnded());
            AwardGesture(140);
        }
        RemoveGesture(141);
        SetEventFlagID(61000, ON);
        SetEventFlagID(61001, OFF);
        EndEvent();
    }
    if (EventFlag(6960)) {
        RemoveGesture(140);
        if (!EventFlag(61001)) {
            WaitFixedTimeFrames(3);
            WaitFor(CutsceneEnded());
            AwardGesture(141);
        }
        SetEventFlagID(61000, OFF);
        SetEventFlagID(61001, ON);
        EndEvent();
    }
    RemoveGesture(140);
    SetEventFlagID(61000, OFF);
});

$Event(1680, Restart, function(activityId, eventFlagId, timeSeconds) {
    DisableNetworkSync();
    EndIf(ThisEventSlot());
    WaitFor(EventFlag(eventFlagId));
    WaitFixedTimeSeconds(timeSeconds);
    StartPS5Activity(activityId);
});

$Event(1690, Restart, function(activityId, eventFlagId, timeSeconds) {
    DisableNetworkSync();
    EndIf(ThisEventSlot());
    WaitFor(EventFlag(eventFlagId));
    WaitFixedTimeSeconds(timeSeconds);
    EndPS5Activity(activityId);
});

$Event(1700, Restart, function(achievementId, eventFlagId, timeSeconds) {
    DisableNetworkSync();
    EndIf(EventFlag(eventFlagId));
    WaitFor(EventFlag(eventFlagId));
    WaitFixedTimeSeconds(timeSeconds);
    AwardAchievement(achievementId);
});

$Event(1900, Restart, function() {
    WaitFor(cond);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
        SetEventFlagID(200, ON);
        SetEventFlagID(201, OFF);
        EndEvent();
    }
L0:
    SetEventFlagID(200, OFF);
    SetEventFlagID(201, ON);
    EndEvent();
});

$Event(1901, Restart, function() {
    DisableNetworkSync();
    SetEventFlagID(202, OFF);
    SetEventFlagID(203, ON);
    WaitFor(
        HasMultiplayerState(MultiplayerState.MultiplayerPending)
            || HasMultiplayerState(MultiplayerState.Multiplayer));
    SetEventFlagID(202, ON);
    SetEventFlagID(203, OFF);
    WaitFor(
        !(HasMultiplayerState(MultiplayerState.MultiplayerPending)
            || HasMultiplayerState(MultiplayerState.Multiplayer)));
    SetEventFlagID(202, OFF);
    SetEventFlagID(203, ON);
    RestartEvent();
});

$Event(1902, Default, function() {
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(210, OFF);
    }
    SetEventFlagID(211, OFF);
    WaitFor(
        PlayerInMap(10, 0, 0, 0)
            || PlayerInMap(11, 0, 0, 0)
            || PlayerInMap(12, 0, 0, 0)
            || PlayerInMap(13, 0, 0, 0)
            || PlayerInMap(14, 0, 0, 0)
            || PlayerInMap(15, 0, 0, 0)
            || PlayerInMap(16, 0, 0, 0));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(210, ON);
    }
    SetEventFlagID(211, ON);
    WaitFor(
        !(PlayerInMap(10, 0, 0, 0)
            || PlayerInMap(11, 0, 0, 0)
            || PlayerInMap(12, 0, 0, 0)
            || PlayerInMap(13, 0, 0, 0)
            || PlayerInMap(14, 0, 0, 0)
            || PlayerInMap(15, 0, 0, 0)
            || PlayerInMap(16, 0, 0, 0)));
    RestartEvent();
});

$Event(1903, Default, function() {
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(220, OFF);
    }
    SetEventFlagID(221, OFF);
    WaitFor(
        PlayerInMap(10, 0, 0, 0)
            || PlayerInMap(11, 0, 0, 0)
            || PlayerInMap(12, 0, 0, 0)
            || PlayerInMap(13, 0, 0, 0)
            || PlayerInMap(14, 0, 0, 0)
            || PlayerInMap(15, 0, 0, 0)
            || PlayerInMap(16, 0, 0, 0));
    if (PlayerIsInOwnWorld()) {
        SetNetworkconnectedEventFlagID(220, ON);
    }
    SetEventFlagID(221, ON);
    WaitFor(
        !(PlayerInMap(10, 0, 0, 0)
            || PlayerInMap(11, 0, 0, 0)
            || PlayerInMap(12, 0, 0, 0)
            || PlayerInMap(13, 0, 0, 0)
            || PlayerInMap(14, 0, 0, 0)
            || PlayerInMap(15, 0, 0, 0)
            || PlayerInMap(16, 0, 0, 0)));
    RestartEvent();
});

$Event(1904, Default, function() {
    DisableNetworkSync();
    ChangeCamera(-1);
});

$Event(1905, Restart, function() {
    GotoIf(L1, PlayAreaCurrentTimeInRange(5, 30, 0, 11, 59, 59));
    GotoIf(L2, PlayAreaCurrentTimeInRange(12, 0, 0, 19, 59, 59));
    GotoIf(L3, PlayAreaCurrentTimeInRange(20, 0, 0, 5, 29, 59));
L1:
    SetEventFlagID(530, ON);
    SetEventFlagID(531, OFF);
    SetEventFlagID(532, OFF);
    WaitFor(!PlayAreaCurrentTimeInRange(6, 0, 0, 11, 59, 59));
    RestartEvent();
L2:
    SetEventFlagID(530, OFF);
    SetEventFlagID(531, ON);
    SetEventFlagID(532, OFF);
    WaitFor(!PlayAreaCurrentTimeInRange(12, 0, 0, 19, 59, 59));
    RestartEvent();
L3:
    SetEventFlagID(530, OFF);
    SetEventFlagID(531, OFF);
    SetEventFlagID(532, ON);
    WaitFor(!PlayAreaCurrentTimeInRange(20, 0, 0, 5, 59, 59));
    RestartEvent();
});

$Event(1906, Default, function(eventFlagId, weather) {
    DisableNetworkSync();
    SetEventFlagID(eventFlagId, OFF);
    WaitFor(WeatherActive(weather, 0, 0));
    WaitFixedTimeFrames(1);
    SetEventFlagID(eventFlagId, ON);
    WaitFor(!WeatherActive(weather, 0, 0));
    WaitFixedTimeFrames(1);
    RestartEvent();
});

$Event(1907, Restart, function() {
    DisableNetworkSync();
    GotoIf(L0, WeatherActive(Weather.Type01, 0, 0));
    GotoIf(L1, 
        WeatherActive(Weather.Type00, 0, 0)
            || WeatherActive(Weather.Type10, 0, 0)
            || WeatherActive(Weather.Type11, 0, 0));
    GotoIf(L2, 
        WeatherActive(Weather.Type20, 0, 0)
            || WeatherActive(Weather.Type21, 0, 0)
            || WeatherActive(Weather.Type30, 0, 0)
            || WeatherActive(Weather.Type52, 0, 0));
    GotoIf(L3, WeatherActive(Weather.Type40, 0, 0) || WeatherActive(Weather.Type41, 0, 0));
    GotoIf(L4, WeatherActive(Weather.Type50, 0, 0) || WeatherActive(Weather.Type51, 0, 0));
    GotoIf(L5, WeatherActive(Weather.Type31, 0, 0) || WeatherActive(Weather.Type60, 0, 0));
    SetEventFlagID(570, OFF);
    SetEventFlagID(571, OFF);
    SetEventFlagID(572, OFF);
    SetEventFlagID(573, OFF);
    SetEventFlagID(574, OFF);
    SetEventFlagID(575, OFF);
    WaitFixedTimeSeconds(3);
    RestartEvent();
L0:
    SetEventFlagID(570, ON);
    SetEventFlagID(571, OFF);
    SetEventFlagID(572, OFF);
    SetEventFlagID(573, OFF);
    SetEventFlagID(574, OFF);
    SetEventFlagID(575, OFF);
    WaitFor(!WeatherActive(Weather.Type01, 0, 0));
    RestartEvent();
L1:
    SetEventFlagID(570, OFF);
    SetEventFlagID(571, ON);
    SetEventFlagID(572, OFF);
    SetEventFlagID(573, OFF);
    SetEventFlagID(574, OFF);
    SetEventFlagID(575, OFF);
    WaitFor(
        !(WeatherActive(Weather.Type00, 0, 0)
            || WeatherActive(Weather.Type10, 0, 0)
            || WeatherActive(Weather.Type11, 0, 0)));
    RestartEvent();
L2:
    SetEventFlagID(570, OFF);
    SetEventFlagID(571, OFF);
    SetEventFlagID(572, ON);
    SetEventFlagID(573, OFF);
    SetEventFlagID(574, OFF);
    SetEventFlagID(575, OFF);
    WaitFor(
        !(WeatherActive(Weather.Type20, 0, 0)
            || WeatherActive(Weather.Type21, 0, 0)
            || WeatherActive(Weather.Type30, 0, 0)
            || WeatherActive(Weather.Type52, 0, 0)));
    RestartEvent();
L3:
    SetEventFlagID(570, OFF);
    SetEventFlagID(571, OFF);
    SetEventFlagID(572, OFF);
    SetEventFlagID(573, ON);
    SetEventFlagID(574, OFF);
    SetEventFlagID(575, OFF);
    WaitFor(!(WeatherActive(Weather.Type40, 0, 0) || WeatherActive(Weather.Type41, 0, 0)));
    RestartEvent();
L4:
    SetEventFlagID(570, OFF);
    SetEventFlagID(571, OFF);
    SetEventFlagID(572, OFF);
    SetEventFlagID(573, OFF);
    SetEventFlagID(574, ON);
    SetEventFlagID(575, OFF);
    WaitFor(!(WeatherActive(Weather.Type50, 0, 0) || WeatherActive(Weather.Type51, 0, 0)));
    RestartEvent();
L5:
    SetEventFlagID(570, OFF);
    SetEventFlagID(571, OFF);
    SetEventFlagID(572, OFF);
    SetEventFlagID(573, OFF);
    SetEventFlagID(574, OFF);
    SetEventFlagID(575, ON);
    WaitFor(!(WeatherActive(Weather.Type31, 0, 0) || WeatherActive(Weather.Type60, 0, 0)));
    RestartEvent();
});

$Event(1908, Default, function() {
    WaitFor(CharacterHasSpEffect(10000, 8998));
    DeactivateGparamOverride(3);
    ChangeWeather(Weather.Type00, 1, false);
    ClearSpEffect(10000, 8998);
    WaitFixedTimeSeconds(1.2);
    RestartEvent();
});

$Event(1909, Default, function() {
    DisableNetworkSync();
    GotoIf(L0, EventFlag(9021));
    GotoIf(L1, EventFlag(1099002100));
    SuppressSE(SoundType.BGM, 0, false);
    WaitFor(EventFlag(1099002100) || EventFlag(9021));
    RestartEvent();
L0:
    SuppressSE(SoundType.BGM, 0, true);
    SetEventFlagID(9021, OFF);
    WaitFor(ElapsedSeconds(1) || EventFlag(1099002100));
    GotoIf(L2, EventFlag(1099002100));
    RestartEvent();
L1:
    SuppressSE(SoundType.BGM, 0, true);
L2:
    WaitFor(!EventFlag(1099002100));
    WaitFixedTimeFrames(1);
    RestartEvent();
});
