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

// コンストラクタ -- constructor
$Event(0, Default, function() {
    RegisterBonfire(71251, 12051951, 0, 0, 0, 5);
    RegisterBonfire(71252, 12051952, 0, 0, 0, 5);
    RegisterBonfire(71253, 12051953, 0, 0, 0, 5);
    $InitializeCommonEvent(0, 9005810, 12050800, 12050000, 12050950, 12051950, 5);
    $InitializeEvent(0, 12052800);
    $InitializeEvent(0, 12052810);
    $InitializeEvent(0, 12052811);
    $InitializeEvent(0, 12052849);
    $InitializeEvent(0, 12052847);
    $InitializeEvent(0, 12052848);
    $InitializeEvent(0, 12052820);
    $InitializeEvent(0, 12052821);
    $InitializeEvent(0, 12052822);
    $InitializeEvent(0, 12052823);
    $InitializeEvent(0, 12052824);
    $InitializeEvent(0, 12052825);
    $InitializeEvent(0, 12052826);
    $InitializeCommonEvent(0, 90005221, 12050200, 30003, 20003, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050202, 30003, 20003, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050203, 30000, 20000, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050204, 30003, 20003, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050205, 30003, 20003, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050206, 30000, 20000, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050207, 30003, 20003, 0, 0);
    $InitializeCommonEvent(0, 90005251, 12050208, 40, 0, -1);
    $InitializeCommonEvent(0, 90005221, 12050209, 30003, 20003, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050211, 30003, 20003, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050212, 30000, 20000, 0, 0);
    $InitializeCommonEvent(0, 90005251, 12050213, 50, 0, -1);
    $InitializeCommonEvent(0, 90005221, 12050214, 30000, 20000, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050215, 30003, 20003, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050216, 30003, 20003, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050217, 30003, 20003, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050218, 30000, 20000, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050219, 30000, 20000, 0, 0);
    $InitializeCommonEvent(0, 90005271, 12050200, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050202, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050203, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050204, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050205, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050206, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050207, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050209, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050211, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050212, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050214, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050215, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050216, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050217, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050218, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12050219, 0, -1);
    $InitializeCommonEvent(0, 90005211, 12050224, 30002, 20002, 12052224, 1, 2, 0, 0, 0, 0);
    $InitializeCommonEvent(0, 90005211, 12050225, 30002, 20002, 12052224, 1, 4.5, 0, 0, 0, 0);
    $InitializeCommonEvent(0, 90005211, 12050226, 30002, 20002, 12052224, 1, 4, 0, 0, 0, 0);
    $InitializeCommonEvent(0, 90005211, 12050227, 30002, 20002, 12052224, 1, 1, 0, 0, 0, 0);
    $InitializeCommonEvent(0, 90005211, 12050229, 30002, 20002, 12052224, 1, 2.5, 0, 0, 0, 0);
    $InitializeCommonEvent(0, 90005250, 12055220, 12052220, 0, -1);
    $InitializeCommonEvent(0, 90005211, 12050232, 30001, 20001, 12052232, 15, 0, 0, 0, 0, 0);
    $InitializeCommonEvent(0, 90005211, 12050233, 30001, 20001, 12052232, 15, 0, 0, 0, 0, 0);
    $InitializeCommonEvent(0, 90005250, 12050240, 12052240, 0, -1);
    $InitializeCommonEvent(0, 90005250, 12050241, 12052240, 0, -1);
    $InitializeCommonEvent(0, 90005271, 12055240, 0, -1);
    $InitializeEvent(0, 12052250, 12050250, 0, 12050360, 30010, 20010);
    $InitializeEvent(1, 12052251, 12050251, 1, 12050361, 30012, 20012);
    $InitializeEvent(2, 12052251, 12050252, 1, 12050362, 30011, 20011);
    $InitializeEvent(3, 12052251, 12050253, 1, 12050363, 30010, 20010);
    $InitializeCommonEvent(0, 90005251, 12055260, 20, 0, -1);
    $InitializeCommonEvent(0, 90005251, 12055268, 20, 0, -1);
    $InitializeCommonEvent(0, 90005251, 12055270, 40, 1.5, -1);
    $InitializeCommonEvent(0, 90005251, 12055261, 15, 0, -1);
    $InitializeCommonEvent(0, 90005251, 12050261, 25, 0, -1);
    $InitializeCommonEvent(0, 90005221, 12050263, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050264, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005201, 12050267, 30006, 20006, 20, 7, 0, 0, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050266, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050265, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050277, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050278, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050279, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050280, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050281, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050282, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050283, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050284, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050285, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050286, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050287, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050288, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050289, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050290, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050291, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050292, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050293, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005200, 12050297, 30006, 20006, 12052297, 0, 0, 0, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050298, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050299, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050300, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050301, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050302, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050303, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050304, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050305, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005221, 12050306, 30006, 20006, 0, 0);
    $InitializeCommonEvent(0, 90005261, 12050310, 12052311, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050311, 12052314, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050312, 12052314, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050313, 12052311, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050314, 12052311, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050315, 12052311, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050316, 12052311, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050317, 12052312, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050318, 12052312, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050319, 12052312, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050320, 12052313, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050321, 12052313, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050322, 12052313, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050323, 12052313, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050324, 12052313, 1, 0, -1);
    $InitializeCommonEvent(0, 90005261, 12050342, 12052342, 20, 0, 20000);
    $InitializeEvent(0, 12052200);
    $InitializeCommonEvent(0, 90005250, 12050346, 12052346, 0, -1);
    $InitializeCommonEvent(0, 90005200, 12050350, 30000, 20000, 12052350, 0, 0, 0, 0, 0);
    $InitializeCommonEvent(0, 90005250, 12050351, 12052351, 0, -1);
    $InitializeCommonEvent(0, 90005200, 12050352, 30000, 20000, 12052352, 0, 0, 0, 0, 0);
    $InitializeCommonEvent(0, 90005200, 12050353, 30000, 20000, 12052353, 0, 0, 0, 0, 0);
    $InitializeEvent(0, 12052360, 12050360, 12050250);
    $InitializeEvent(1, 12052360, 12050361, 12050251);
    $InitializeEvent(2, 12052360, 12050362, 12050252);
    $InitializeEvent(3, 12052360, 12050363, 12050253);
    $InitializeCommonEvent(0, 90005251, 12050370, 60, 0, -1);
    $InitializeCommonEvent(0, 90005300, 12050400, 12050400, 40680, 1.5, 0);
    $InitializeCommonEvent(0, 90005300, 12050401, 12050401, 40682, 1.5, 0);
    $InitializeCommonEvent(0, 90005300, 12050402, 12050402, 40684, 1.5, 0);
    $InitializeCommonEvent(0, 90005300, 12050403, 12050403, 40686, 1.5, 0);
    $InitializeCommonEvent(0, 90005790, 12050800, 12050410, 12052410, 12052411, 12050410, 21, 12052410, 12052411, 0, 0, false, 0);
    $InitializeCommonEvent(0, 90005791, 12050410, 12052410, 12052411, 12050410);
    $InitializeCommonEvent(0, 90005792, 12050410, 12052410, 12052411, 12050410, 0, 0);
    $InitializeCommonEvent(0, 90005790, 12050800, 12050412, 12052412, 12052413, 12050412, 22, 12052412, 12052413, 0, 0, false, 0);
    $InitializeCommonEvent(0, 90005791, 12050412, 12052412, 12052413, 12050412);
    $InitializeCommonEvent(0, 90005792, 12050412, 12052412, 12052413, 12050412, 12050950, 0);
    $InitializeCommonEvent(0, 90005790, 12050800, 12050414, 12052414, 12052415, 12050414, 23, 12052414, 12052415, 0, 0, false, 0);
    $InitializeCommonEvent(0, 90005791, 12050414, 12052414, 12052415, 12050414);
    $InitializeCommonEvent(0, 90005792, 12050414, 12052414, 12052415, 12050414, 0, 0);
    $InitializeCommonEvent(0, 90005501, 12050510, 12050511, 0, 12051510, 12051511, 12051512, 12050512);
    $InitializeEvent(0, 12052510);
    $InitializeEvent(0, 12052680);
    $InitializeCommonEvent(0, 900005610, 12051630, 100, 800, 0);
    $InitializeEvent(0, 12052601, 12051600, 0);
    $InitializeEvent(1, 12052601, 12051601, 1);
    $InitializeEvent(5, 12052601, 12051605, 4);
    $InitializeEvent(6, 12052601, 12051606, 3);
    $InitializeEvent(7, 12052601, 12051607, 2);
    $InitializeEvent(8, 12052601, 12051608, 1.5);
    $InitializeEvent(9, 12052601, 12051609, 0.5);
    $InitializeEvent(11, 12052601, 12051611, 3);
    $InitializeEvent(0, 12052620, 12051620, 12050410, 12052410, 12052411);
    $InitializeEvent(1, 12052620, 12051621, 12050412, 12052412, 12052413);
    $InitializeEvent(2, 12052620, 12051622, 12050414, 12052414, 12052415);
    $InitializeEvent(0, 12052201);
    $InitializeCommonEvent(0, 90005795, 7601, 0, 1042369259, 12052141, 12052142, 80601, 9000, 12051700, 30010);
    if (CeremonyActive(20)) {
        $InitializeCommonEvent(0, 90005796, 7601, 12050705, TextBannerType.HostVanquished, 12052141);
        $InitializeEvent(0, 1039532145);
    }
    $InitializeEvent(0, 12052690);
    $InitializeCommonEvent(0, 90005615, 12052699, 12050800);
    $InitializeEvent(0, 12053700, 12050800, 0, 9112, 12052805, 145);
    $InitializeEvent(0, 12053701, 12050800);
    $InitializeCommonEvent(0, 90005703, 12050710, 4811, 4812, 12059106, 4811, 4810, 4814, 0);
    $InitializeCommonEvent(0, 90005704, 12050710, 4811, 4810, 12059106, 3);
    $InitializeCommonEvent(0, 90005702, 12050710, 4813, 4810, 4814);
    $InitializeCommonEvent(0, 90005725, 4810, 4811, 4813, 12059105, 12050710, 1035450701, 12056700);
    $InitializeEvent(0, 12053710, 12050702);
    $InitializeEvent(0, 12053711, 12050702);
    $InitializeEvent(0, 12053712);
    $InitializeCommonEvent(0, 90005750, 12051700, 4350, 100360, 400036, 400037, 12059166, 0);
    $InitializeCommonEvent(0, 90005702, 12050702, 3183, 3180, 3184);
    $InitializeEvent(0, 12050700, 12050750, 4440, 4443, 4445, 90100, 12059261);
});

// プリコンストラクタ -- preconstructor
$Event(50, Default, function() {
    SetCharacterBackreadState(12050700, true);
    SetCharacterBackreadState(12050701, true);
    SetCharacterBackreadState(12050702, true);
    SetCharacterBackreadState(12050705, true);
    SetCharacterBackreadState(12050710, true);
    SetCharacterBackreadState(12050715, true);
    $InitializeEvent(0, 12052500);
});

// NPC疑似マルチ_戦場医師_開始 -- NPC pseudo-multi_battlefield doctor_start
$Event(1039532145, Restart, function() {
    EndIf(!CeremonyActive(20));
    SetCharacterBackreadState(12050705, false);
    SetCharacterTeamType(12050705, TeamType.Human);
    DeleteAssetfollowingSFX(12056710, true);
    CreateAssetfollowingSFX(12056710, 200, 806700);
});

// 間欠泉_弾丸オーナー作成 -- Geyser_Bullet owner created
$Event(12052600, Restart, function() {
    SetCharacterTeamType(12050600, TeamType.StrongEnemy);
    CreateBulletOwner(12050600);
});

// 血の間欠泉_XX -- Blood geyser_XX
$Event(12052601, Restart, function(entityId, timeSeconds) {
    if (!ThisEventSlot()) {
        WaitFixedTimeSeconds(timeSeconds);
        SetThisEventSlot(ON);
    }
L0:
    if (EventFlag(50)) {
        ShootBullet(12050600, entityId, -1, 802900000, 0, 0, 0);
    } else if (EventFlag(51)) {
        ShootBullet(12050600, entityId, -1, 802900010, 0, 0, 0);
    } else if (EventFlag(52)) {
        ShootBullet(12050600, entityId, -1, 802900020, 0, 0, 0);
    } else if (EventFlag(53)) {
        ShootBullet(12050600, entityId, -1, 802900030, 0, 0, 0);
    } else if (EventFlag(54)) {
        ShootBullet(12050600, entityId, -1, 802900040, 0, 0, 0);
    } else if (EventFlag(55)) {
        ShootBullet(12050600, entityId, -1, 802900050, 0, 0, 0);
    } else if (EventFlag(56)) {
        ShootBullet(12050600, entityId, -1, 802900060, 0, 0, 0);
    } else {
        ShootBullet(12050600, entityId, -1, 802900070, 0, 0, 0);
    }
L10:
    WaitRandomTimeSeconds(6, 10);
    RestartIf(mainGroupAbuse);
});

// 血の泡_XX -- Blood bubbles_XX
$Event(12052620, Restart, function(assetEntityId, eventFlagId, eventFlagId2, areaEntityId) {
    EndIf(EventFlag(eventFlagId));
    CreateAssetfollowingSFX(assetEntityId, 100, 812610);
    WaitFor(
        (CharacterType(10000, TargetType.Alive)
            || CharacterType(10000, TargetType.GrayPhantom)
            || CharacterType(10000, TargetType.WhitePhantom))
            && InArea(10000, areaEntityId)
            && EventFlag(eventFlagId2));
    DeleteAssetfollowingSFX(assetEntityId, true);
    WaitFixedTimeFrames(1);
    CreateAssetfollowingSFX(assetEntityId, 100, 812611);
    WaitFixedTimeSeconds(4);
    DeleteAssetfollowingSFX(assetEntityId, true);
});

// 鴉ティラノ用特殊待機距離判定 -- Special standby distance determination for Raven Tyrano
$Event(12052200, Restart, function() {
    EndIf(SpecialStandbyEndedFlag(12050343));
    ForceAnimationPlayback(12050343, 30013, true, false, false);
    chrSp = (CharacterType(10000, TargetType.BlackPhantom) && CharacterHasSpEffect(10000, 3710))
        || CharacterType(10000, TargetType.Alive)
        || CharacterType(10000, TargetType.BluePhantom)
        || CharacterType(10000, TargetType.WhitePhantom);
    area = InArea(10000, 12052343) || EntityInRadiusOfEntity(10000, 12050343, 20, 1);
    sp = CharacterHasSpEffect(12050343, 5080) || CharacterHasSpEffect(12050343, 5450);
    sp2 = CharacterHasSpEffect(12050343, 481)
        && !CharacterHasSpEffect(12050343, 90100)
        && !CharacterHasSpEffect(12050343, 90110)
        && !CharacterHasSpEffect(12050343, 90160);
    sp3 = CharacterHasSpEffect(12050343, 482)
        && !CharacterHasSpEffect(12050343, 90100)
        && !CharacterHasSpEffect(12050343, 90120)
        && !CharacterHasSpEffect(12050343, 90160)
        && !CharacterHasSpEffect(12050343, 90162);
    sp4 = CharacterHasSpEffect(12050343, 483)
        && !CharacterHasSpEffect(12050343, 90100)
        && !CharacterHasSpEffect(12050343, 90140)
        && !CharacterHasSpEffect(12050343, 90160)
        && !CharacterHasSpEffect(12050343, 90161);
    sp5 = CharacterHasSpEffect(12050343, 484)
        && !CharacterHasSpEffect(12050343, 90100)
        && !CharacterHasSpEffect(12050343, 90130)
        && !CharacterHasSpEffect(12050343, 90161)
        && !CharacterHasSpEffect(12050343, 90162);
    sp6 = CharacterHasSpEffect(12050343, 487)
        && !CharacterHasSpEffect(12050343, 90100)
        && !CharacterHasSpEffect(12050343, 90150)
        && !CharacterHasSpEffect(12050343, 90160);
    areaChrSp = area && CharacterBackreadStatus(12050343) && sp && chrSp;
    WaitFor(
        areaChrSp
            || HasDamageType(12050343, 0, DamageType.Unspecified)
            || CharacterHasStateInfo(12050343, 436)
            || CharacterHasStateInfo(12050343, 2)
            || CharacterHasStateInfo(12050343, 5)
            || CharacterHasStateInfo(12050343, 6)
            || CharacterHasStateInfo(12050343, 260)
            || sp2
            || sp3
            || sp4
            || sp5
            || sp6);
    SetNetworkUpdateRate(12050343, true, CharacterUpdateFrequency.AtLeastEvery2Frames);
    WaitFixedTimeSeconds(0.1);
    SetNetworkconnectedThisEventSlot(ON);
    SetSpecialStandbyEndedFlag(12050343, ON);
    ForceAnimationPlayback(12050343, 20000, true, false, false);
    WaitFixedTimeSeconds(3);
    SetNetworkUpdateRate(12050343, false, CharacterUpdateFrequency.NoUpdate);
});

// 戦場医師NPC世界侵入ワープ領域SFX -- Battlefield Doctor NPC World Invasion Warp Area SFX
$Event(12052201, Restart, function() {
    EndIf(ThisEventSlot());
    SpawnOneshotSFX(TargetEntityType.Area, 12052700, -1, 30010);
});

// 長柄棍棒_踊り始める_XX -- Long-handled club_Start dancing_XX
$Event(12052250, Restart, function(chrEntityId, timeFrames, entityId, animationId, animationId2) {
    EndIf(ThisEventSlot());
    ForceAnimationPlayback(entityId, animationId, true, true, false);
    WaitFor(CharacterAIState(chrEntityId, AIStateType.Combat));
    ForceAnimationPlayback(chrEntityId, 3007, true, true, false);
    ForceAnimationPlayback(entityId, animationId2, true, true, false);
    EndEvent();
    WaitFixedTimeFrames(timeFrames);
});

// 長柄棍棒_踊り始める2_XX -- Long-handled club_Start dancing 2_XX
$Event(12052251, Restart, function(chrEntityId, timeFrames, entityId, animationId, animationId2) {
    EndIf(ThisEventSlot());
    ForceAnimationPlayback(entityId, animationId, true, true, false);
    WaitFor(CharacterAIState(chrEntityId, AIStateType.Combat));
    ForceAnimationPlayback(chrEntityId, 3007, true, true, false);
    ForceAnimationPlayback(entityId, animationId2, true, true, false);
    EndEvent();
    WaitFixedTimeFrames(timeFrames);
});

// 巨大骸骨死亡_XX -- Giant skeleton death_XX
$Event(12052360, Restart, function(chrEntityId, chrEntityId2) {
    if (CharacterDead(chrEntityId2) || HPRatio(chrEntityId2) <= 0.5) {
        ForceCharacterDeath(chrEntityId, false);
        EndEvent();
    }
    WaitFor(CharacterDead(chrEntityId2) || HPRatio(chrEntityId2) <= 0.5);
    ForceCharacterDeath(chrEntityId, false);
    EndEvent();
});

$Event(12052500, Restart, function() {
    EndIf(!PlayerIsInOwnWorld());
    SetEventFlagID(12052501, OFF);
    SetEventFlagID(12052502, OFF);
    WaitFor(
        EventFlag(6951)
            && PlayerIsInOwnWorld()
            && EventFlag(9112)
            && EventFlag(9130)
            && ActionButtonInArea(209500, 12051500));
    DisplayGenericDialogAndSetEventFlags(2020000, PromptType.YESNO, NumberofOptions.TwoButtons, 12051500, 3, 12052501, 12052502, 12052502);
    if (!EventFlag(12052501)) {
        WaitFixedTimeSeconds(3);
        RestartEvent();
    }
L0:
    SendAllPhantomsHome();
    SetEventFlagID(62002, ON);
    SetEventFlagID(82002, ON);
    SetPlayerRespawnPoint(2046402020);
    SaveRequest();
    DisableTextOnLoadingScreen();
    RotateCharacter(10000, 12052500, 60550, false);
    WaitFixedTimeSeconds(2);
    WarpPlayer(61, 46, 40, 0, 2046402020, 120500);
});

// 火の粉SFX処理 -- Spark SFX processing
$Event(12052680, Restart, function() {
    DisableNetworkSync();
    if (!ThisEventSlot()) {
        DeleteMapSFX(12053680, false);
    }
    WaitFor(
        !(PlayerStandingOnHit(12054681)
            || PlayerStandingOnHit(12054682)
            || PlayerStandingOnHit(12054683))
            && InArea(10000, 12052680));
    SpawnMapSFX(12053680);
    WaitFixedTimeSeconds(1);
    WaitFor(
        !InArea(10000, 12052680)
            || PlayerStandingOnHit(12054681)
            || PlayerStandingOnHit(12054682)
            || PlayerStandingOnHit(12054683));
    DeleteMapSFX(12053680, true);
    WaitFixedTimeSeconds(1);
    RestartEvent();
});

// NPC疑似マルチ_バディ石碑使用禁止 -- NPC pseudo-multi_Buddy stone monument use prohibited
$Event(12052690, Restart, function() {
    DisableNetworkSync();
    WaitForEventFlag(ON, TargetEventFlagType.EventFlag, 12052140);
    SetSpEffect(12050102, 9531);
    WaitForEventFlag(OFF, TargetEventFlagType.EventFlag, 12052140);
    SetSpEffect(12050102, 9532);
    WaitFixedTimeSeconds(1);
    RestartEvent();
});

// ボス撃破 -- Defeat the boss
$Event(12052800, Restart, function() {
    EndIf(EventFlag(12050800));
    WaitFor(CharacterHPValue(12050800) <= 0);
    WaitFixedTimeSeconds(4);
    PlaySE(12050800, SoundType.SFX, 888880000);
    WaitFor(
        (PlayerIsInOwnWorld() && CharacterDead(12050800) && !CharacterHasSpEffect(10000, 9646))
            || EventFlag(12050800));
    HandleBossDefeatAndDisplayBanner(12050800, TextBannerType.DemigodFelled);
    if (PlayerIsInOwnWorld()) {
        TriggerMultiplayerEvent(0);
    }
    SetEventFlagID(12050800, ON);
    SetEventFlagID(9112, ON);
    if (PlayerIsInOwnWorld()) {
        SetEventFlagID(61112, ON);
    }
});

// ボス出現 -- Boss appears
$Event(12052810, Restart, function() {
    if (EventFlag(12050800)) {
        DisableCharacter(12050800);
        DisableCharacterCollision(12050800);
        ForceCharacterDeath(12050800, false);
        EndEvent();
    }
L0:
    DisableCharacterAI(12050800);
    if (!EventFlag(12050801)) {
        DisableCharacter(12050800);
        DisableCharacterCollision(12050800);
        DisableCharacterFadeOnEnable(12050800);
        EnableAsset(12051820);
        DisableAsset(12051821);
        DisableAsset(12051822);
        WaitFor(
            (PlayerIsInOwnWorld() && InArea(10000, 12052801))
                || HasDamageType(12050800, 10000, DamageType.Unspecified));
        SetNetworkconnectedEventFlagID(12050801, ON);
        if (PlayerIsInOwnWorld()) {
            SendInvadingPhantomsHome(0);
        }
        if (PlayerIsInOwnWorld()) {
            PlayCutsceneToPlayerAndWarp(12050020, CutscenePlayMode.Skippable, 12052805, 12050000, 10000, 12050000, false);
        } else {
            PlayCutsceneToPlayer(12050020, CutscenePlayMode.Skippable, 10000);
        }
        WaitFixedTimeRealFrames(1);
        SetNetworkconnectedEventFlagID(12050802, ON);
        EnableCharacter(12050800);
        EnableCharacterCollision(12050800);
        ForceAnimationPlayback(12050800, 20020, false, false, false);
    } else {
L1:
        DisableCharacterCollision(12050800);
        WaitFor(EventFlag(12052805) && InArea(10000, 12052800));
        EnableCharacterCollision(12050800);
    }
L2:
    EnableAsset(12051821);
    DisableAsset(12051822);
    EnableCharacterAI(12050800);
    SetNetworkUpdateRate(12050800, true, CharacterUpdateFrequency.AlwaysUpdate);
    DisplayBossHealthBar(Enabled, 12050800, 0, 904800000);
});

// ボス激昂 -- boss rage
$Event(12052811, Restart, function() {
    EndIf(EventFlag(12050800));
    WaitFor(CharacterHasSpEffect(12050800, 10630));
    SetEventFlagID(12052802, ON);
});

// カウント魔法イベント_PCにカウントSFX1をつける -- Count magic event_Attach count SFX1 to PC
$Event(12052820, Restart, function() {
    EndIf(EventFlag(12050800));
    WaitFor(CharacterHasSpEffect(12050800, 10641));
    SetSpEffect(10000, 10650);
});

// カウント魔法イベント_PCにカウントSFX2をつける -- Count magic event_Attach count SFX2 to PC
$Event(12052821, Restart, function() {
    EndIf(EventFlag(12050800));
    WaitFor(CharacterHasSpEffect(12050800, 10642));
    SetSpEffect(10000, 10651);
});

// カウント魔法イベント_PCにカウントSFX3をつける -- Count magic event_Attach count SFX3 to PC
$Event(12052822, Restart, function() {
    EndIf(EventFlag(12050800));
    WaitFor(CharacterHasSpEffect(12050800, 10643));
    SetSpEffect(10000, 10652);
});

// カウント魔法イベント_PCにダメージ1を与える -- Count magic event_Deals 1 damage to PC
$Event(12052823, Restart, function() {
    EndIf(EventFlag(12050800));
    WaitFor(CharacterHasSpEffect(12050800, 10645));
    SetSpEffect(10000, 10660);
    SetSpEffect(10000, 10665);
});

// カウント魔法イベント_PCにダメージ2を与える -- Count magic event_Deals 2 damage to PC
$Event(12052824, Restart, function() {
    EndIf(EventFlag(12050800));
    WaitFor(CharacterHasSpEffect(12050800, 10646));
    SetSpEffect(10000, 10661);
    SetSpEffect(10000, 10666);
});

// カウント魔法イベント_PCにダメージ3を与える -- Count magic event_Deals 3 damage to PC
$Event(12052825, Restart, function() {
    EndIf(EventFlag(12050800));
    WaitFor(CharacterHasSpEffect(12050800, 10647));
    SetSpEffect(10000, 10662);
    SetSpEffect(10000, 10667);
});

// カウント魔法イベント_PCのカウントSFXを削除する -- Count magic event_Delete PC count SFX
$Event(12052826, Restart, function() {
    EndIf(EventFlag(12050800));
    WaitFor(CharacterHasSpEffect(12050800, 10648) || CharacterDead(12050800));
    SetSpEffect(10000, 10653);
});

// ボス_カットシーン用対応1 -- Boss_cutscene support 1
$Event(12052847, Restart, function() {
    EndIf(EventFlag(12050801));
    WaitFor(EventFlag(12050801));
    DisableAsset(12051820);
    DisableAsset(12051821);
    EnableAsset(12051822);
    EndEvent();
});

// ボス_カットシーン用対応2 -- Boss_cutscene support 2
$Event(12052848, Restart, function() {
    if (EventFlag(12050803)) {
        DisableAsset(12051820);
        EnableAsset(12051821);
        DisableAsset(12051822);
        EndEvent();
    }
L0:
    WaitFor(EventFlag(12050802));
    DisableAsset(12051820);
    EnableAsset(12051821);
    DisableAsset(12051822);
    SetNetworkconnectedEventFlagID(12050803, ON);
    EndEvent();
});

// ボス_イベント起動 -- Boss_event activation
$Event(12052849, Restart, function() {
    $InitializeCommonEvent(0, 9005811, 12050800, 12051801, 12, 12050801);
    $InitializeCommonEvent(0, 9005811, 12050800, 12051802, 12, 12050801);
    $InitializeCommonEvent(0, 9005822, 12050800, 90003101, 12052805, 12052806, 0, 12052802, 0, 0);
    $InitializeCommonEvent(0, 9005800, 12050800, 12051800, 12052800, 12052805, 12055800, 10000, 12050801, 12052801);
    $InitializeCommonEvent(0, 9005801, 12050800, 12051800, 12052800, 12052805, 12052806, 10000);
    $InitializeCommonEvent(0, 9005811, 12050800, 12051800, 4, 12050801);
    $InitializeCommonEvent(0, 9005822, 12050800, 480000, 12052805, 12052806, 0, 12052802, 0, 0);
});

// エレベータ起動 -- elevator start
$Event(12052510, Default, function() {
    $InitializeCommonEvent(0, 90005500, 12050510, 12050511, 0, 12051510, 12051511, 12053511, 12051512, 12053512, 12052511, 12052512, 12050512, 12050513, 0);
});

// NPC209グレーターデーモン_会話処理限界の距離変更 -- NPC209 Greater Demon_Distance change for conversation processing limit
$Event(12053700, Restart, function(chrEntityId, chrEntityId2, eventFlagId, eventFlagId2, range) {
    EndIf(!PlayerIsInOwnWorld());
    SetCharacterTalkRange(chrEntityId, 17);
    if (0 != chrEntityId2) {
        SetCharacterTalkRange(chrEntityId2, 17);
    }
    EndIf(EventFlag(eventFlagId));
    GotoIf(L1, !EventFlag(eventFlagId2));
    Goto(L2);
L1:
    WaitFor(EventFlag(eventFlagId2));
    Goto(L2);
L2:
    SetCharacterTalkRange(chrEntityId, range);
    if (0 != chrEntityId2) {
        SetCharacterTalkRange(chrEntityId2, range);
    }
    EndEvent();
});

// NPC209グレーターデーモン_死亡後一定時間バックリード内 -- NPC209 Greater Demon_backread for a certain period of time after death
$Event(12053701, Restart, function(chrEntityId) {
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(12050800));
    WaitFor(CharacterDead(chrEntityId));
    EnableCharacterDefaultBackread(chrEntityId);
    WaitFor(EventFlag(12059205) || ElapsedSeconds(30));
    DisableCharacterDefaultBackread(chrEntityId);
    EndEvent();
});

// NPC301_戦場医師_NPC初期化イベント_地下迷宮で倒した -- NPC301_Battlefield doctor_NPC initialization event_Defeated in the underground labyrinth
$Event(12053710, Restart, function(chrEntityId) {
    WaitFixedTimeFrames(1);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
        if (EventFlag(3180)) {
            SetEventFlagID(1042369205, OFF);
        }
    }
L10:
    if (!EventFlag(3193)) {
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        WaitFor(EventFlag(3193));
        RestartEvent();
    }
L5:
    GotoIf(L1, EventFlag(3180));
    GotoIf(L2, EventFlag(3181));
    GotoIf(L3, EventFlag(3182));
    GotoIf(L4, EventFlag(3183));
L1:
    SetCharacterBackreadState(chrEntityId, false);
    EnableCharacter(chrEntityId);
    SetCharacterTeamType(chrEntityId, TeamType.FriendlyNPC);
    ForceAnimationPlayback(chrEntityId, 90102, false, false, false);
    GotoIf(L20, mainGroupAbuse);
L2:
    SetCharacterBackreadState(chrEntityId, false);
    EnableCharacter(chrEntityId);
    SetCharacterTeamType(chrEntityId, TeamType.HostileNPC);
    Goto(L20);
L3:
    SetCharacterBackreadState(chrEntityId, false);
    EnableCharacter(chrEntityId);
    SetCharacterTeamType(chrEntityId, TeamType.HostileNPC);
    Goto(L20);
L4:
    ForceCharacterTreasure(chrEntityId);
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L20:
    WaitFor(!EventFlag(3193));
    RestartEvent();
});

// NPC301_戦場医師_地下迷宮で倒した_死亡実行 -- NPC301_Battlefield doctor_Defeated in the underground labyrinth_Death execution
$Event(12053711, Restart, function(chrEntityId) {
    WaitFixedTimeFrames(1);
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(3183));
    EndIf(!EventFlag(3193));
    WarpAssetToCharacter(12051700, chrEntityId, -1);
    WaitFor(EventFlag(12059166));
    DisableCharacterCollision(chrEntityId);
    EndEvent();
});

// NPC301_戦場医師_地下迷宮での戦闘_侵入サイン表示 -- NPC301_Battlefield doctor_Battle in the underground labyrinth_Intrusion sign display
$Event(12053712, Restart, function() {
    WaitFixedTimeFrames(1);
    EndIf(!PlayerIsInOwnWorld());
    EndIf(!EventFlag(3192));
    SetEventFlagID(1042369259, ON);
    EndEvent();
});

$Event(12050700, Restart, function(chrEntityId, eventFlagId, eventFlagId2, eventFlagId3, animationId, eventFlagId4) {
    DisableNetworkSync();
    WaitFixedTimeFrames(1);
    if (PlayerIsInOwnWorld()) {
    }
L10:
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    EndIf(!EventFlag(eventFlagId4));
    if (!EventFlag(eventFlagId3)) {
        WaitFor(EventFlag(eventFlagId3));
        RestartEvent();
    }
L0:
    GotoIf(L1, EventFlag(eventFlagId));
    GotoIf(L4, EventFlag(eventFlagId2));
    Goto(L20);
L1:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    SetCharacterTeamType(chrEntityId, TeamType.Disabled);
    WaitFor(CharacterBackreadStatus(chrEntityId));
    ResetCharacterPosition(chrEntityId);
    if (Signed(-1) != animationId) {
        ForceAnimationPlayback(chrEntityId, animationId, true, false, false);
    }
    Goto(L20);
L4:
    Goto(L20);
L20:
    WaitFor(!EventFlag(eventFlagId3));
    RestartEvent();
});


