// ==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(11100000, 11101950, 0, 0, 0, 1);
    $InitializeEvent(0, 11100020);
    $InitializeEvent(0, 11100030);
    $InitializeEvent(0, 11100031);
    $InitializeCommonEvent(0, 90005790, 0, 11100180, 11102180, 11102181, 11100785, 23, 11102385, 11102386, 0, 0, false, 0);
    $InitializeCommonEvent(0, 90005791, 11100180, 11102180, 11102181, 11100785);
    $InitializeCommonEvent(0, 90005792, 11100180, 11102180, 11102181, 11100785, 11100800, 0);
    $InitializeEvent(0, 11102600);
    $InitializeEvent(0, 11102602);
    $InitializeEvent(0, 11102605);
    $InitializeEvent(0, 11102606);
    $InitializeEvent(0, 11102620, 11100180, 11102621, 11102622, 11101620, 11102620, 11, 10, 0, 0);
    $InitializeCommonEvent(0, 90005620, 11100570, 11101570, 11101571, 0, 11102570, 11102571, 11102572);
    $InitializeCommonEvent(0, 90005621, 11100570, 11101573);
    $InitializeCommonEvent(0, 90005620, 11100575, 11101575, 11101576, 11101577, 11102575, 11102576, 11102577);
    $InitializeCommonEvent(0, 90005621, 11100575, 11101578);
    $InitializeEvent(0, 11102680);
    $InitializeEvent(0, 11103700, 11100715);
    $InitializeCommonEvent(0, 11103702);
    $InitializeCommonEvent(0, 11103703);
    $InitializeEvent(0, 11103705, 11100705);
    $InitializeCommonEvent(0, 90005708, 11100705, 3480, 0);
    $InitializeEvent(0, 11103706, 11100720);
    $InitializeEvent(0, 11103707, 11100720);
    $InitializeCommonEvent(0, 90005708, 11100705, 11109355, 0);
    $InitializeEvent(0, 11103710, 11100710);
    $InitializeEvent(0, 11103711, 11100711);
    $InitializeEvent(0, 11103712, 11100712);
    $InitializeEvent(0, 11103713);
    $InitializeEvent(0, 11103714, 11100711);
    $InitializeEvent(0, 11100704);
    $InitializeEvent(0, 11103715, 11100725);
    $InitializeEvent(0, 11103716, 11100726);
    $InitializeEvent(0, 11103720, 11100730);
    $InitializeEvent(0, 11100730, 11100735, 11101730);
    $InitializeEvent(0, 11100731, 11100736, 11101717, 11101562);
    $InitializeEvent(0, 11100732);
    $InitializeCommonEvent(0, 90005708, 11100735, 4110, 0);
    $InitializeCommonEvent(0, 90005750, 11101716, 4110, 103400, 400349, 400349, 4048, 0);
    $InitializeCommonEvent(0, 90005775, 81463900, 1045399206, -1);
    $InitializeEvent(0, 11100735, 11100740);
    $InitializeEvent(0, 11100736, 11100741);
    $InitializeCommonEvent(0, 90005740, 11102845, 11102846, 11102847, 11100740, 702, 11101741, 702, 0.4, 90300, 90302, -1, 1.3);
    $InitializeCommonEvent(0, 90005741, 11102848, 11102849, 11102847, 11100740, 90320, 0, 90322, -1, 0.5);
    $InitializeEvent(0, 11100737, 11100741);
    $InitializeCommonEvent(0, 90005733, 11102844);
    $InitializeEvent(0, 11100750, 11100755, 11101715);
    $InitializeCommonEvent(0, 90005708, 11100755, 3900, 0);
    $InitializeCommonEvent(0, 90005708, 11100755, 3903, 0);
    $InitializeCommonEvent(0, 90005750, 11101755, 4110, 103590, 400359, 400359, 3909, 0);
    $InitializeCommonEvent(0, 90005750, 11101755, 4110, 103580, 400356, 400358, 400359, 0);
    $InitializeEvent(0, 11100740, 11100750);
    $InitializeEvent(0, 11100741, 11100751);
    $InitializeCommonEvent(0, 90005775, 85495300, 11109687, -1);
    $InitializeEvent(0, 11100745, 11100770);
    $InitializeEvent(0, 11100755, 11100745);
    $InitializeEvent(0, 11100756, 11100746);
    $InitializeEvent(0, 11100760, 11100780);
    $InitializeEvent(0, 11100761, 11100781);
    $InitializeEvent(0, 11100765, 11100765);
    $InitializeCommonEvent(0, 90005774, 11109656, 11100900, 11107900);
    $InitializeCommonEvent(0, 90005750, 11101765, 4110, 104900, 400490, 400490, 11109656, 0);
    $InitializeCommonEvent(0, 11103770);
    $InitializeCommonEvent(0, 11103771);
    $InitializeCommonEvent(0, 11103772);
    $InitializeEvent(0, 11103775);
    $InitializeEvent(0, 11100790);
    $InitializeEvent(0, 11100791, 400282, 11109770);
    $InitializeEvent(1, 11100791, 400283, 11109771);
    $InitializeEvent(2, 11100791, 68210, 11109772);
    $InitializeEvent(3, 11100791, 400285, 11109773);
    $InitializeEvent(0, 11100795);
    $InitializeEvent(0, 11100796);
    $InitializeEvent(0, 11100797);
    $InitializeEvent(0, 11102651, 710700, 1700, 9125, 69250);
    $InitializeEvent(0, 11102650, 710720, 1720, 9128, 69280);
    $InitializeEvent(0, 11102652, 710780, 1780, 9132, 69320);
});

// プリコンストラクタ -- preconstructor
$Event(50, Default, function() {
    SetCharacterBackreadState(11100705, true);
    SetCharacterBackreadState(11100710, true);
    SetCharacterBackreadState(11100711, true);
    SetCharacterBackreadState(11100715, true);
    SetCharacterBackreadState(11100725, true);
    SetCharacterBackreadState(11100726, true);
    SetCharacterBackreadState(11100735, true);
    SetCharacterBackreadState(11100736, true);
    SetCharacterBackreadState(11100740, true);
    SetCharacterBackreadState(11100741, true);
    SetCharacterBackreadState(11100745, true);
    SetCharacterBackreadState(11100746, true);
    SetCharacterBackreadState(11100750, true);
    SetCharacterBackreadState(11100751, true);
    SetCharacterBackreadState(11100755, true);
    SetCharacterBackreadState(11100765, true);
    SetCharacterBackreadState(11100766, true);
    SetCharacterBackreadState(11100770, true);
    SetCharacterBackreadState(11100780, true);
    SetCharacterBackreadState(11100781, true);
    SetCharacterBackreadState(11100785, true);
    EnableAssetInvunerability(11101715);
    EnableAssetInvunerability(11101730);
    $InitializeEvent(0, 11100690);
    $InitializeEvent(0, 11002548);
    $InitializeEvent(0, 11100680);
    $InitializeEvent(0, 11102100);
});

// 初回拠点訪問 -- First base visit
$Event(11100020, Default, function() {
    EndIf(ThisEventSlot());
    WaitFor(PlayerIsInOwnWorld() && PlayerInMap(11, 10, 0, 0));
    SetEventFlagID(71190, ON);
    OpenWorldMapPoint(111000, 100);
    SetEventFlagID(105, ON);
});

// 次の周回へ行く -- go to next round
$Event(11100030, Restart, function() {
    EndIf(!PlayerIsInOwnWorld());
    WaitFor(PlayerIsInOwnWorld() && EventFlag(3001));
    SetEventFlagID(30, ON);
});

// クリア後拠点訪問 -- Visit base after clearing
$Event(11100031, Default, function() {
    EndIf(!EventFlag(120));
    EndIf(EventFlag(121));
    WaitFor(PlayerIsInOwnWorld() && EventFlag(120));
    SetEventFlagID(71900, OFF);
    SetEventFlagID(121, ON);
});

// 炎上時の変化 -- Changes during a fire
$Event(11102100, Default, function() {
    GotoIf(L1, EventFlag(302));
    GotoIf(L0, !EventFlag(300));
    ChangeWeather(Weather.WindyPuffyClouds, -1, true);
    DeleteMapSFX(11102100, false);
    EndEvent();
L1:
    ChangeWeather(Weather.Cloudless, -1, true);
L0:
    DeleteMapSFX(11102101, false);
    DeleteMapSFX(11102110, false);
    DeleteMapSFX(11102111, false);
    DeleteMapSFX(11102112, false);
    DeleteMapSFX(11102113, false);
    DeleteMapSFX(11102114, false);
    DeleteMapSFX(11102115, false);
    DeleteMapSFX(11102116, false);
    DeleteMapSFX(11102117, false);
    DeleteMapSFX(11102118, false);
    DeleteMapSFX(11102119, false);
    DeleteMapSFX(11102120, false);
    DeleteMapSFX(11102121, false);
    DeleteMapSFX(11102122, false);
    DeleteMapSFX(11102123, false);
    DeleteMapSFX(11102124, false);
    DeleteMapSFX(11102125, false);
    DeleteMapSFX(11102126, false);
    DeleteMapSFX(11102127, false);
    DeleteMapSFX(11102128, false);
    DeleteMapSFX(11102129, false);
    DeleteMapSFX(11102130, false);
    DeleteMapSFX(11102131, false);
    DeleteMapSFX(11102132, false);
    DeleteMapSFX(11102133, false);
    DeleteMapSFX(11102134, false);
    DeleteMapSFX(11102135, false);
    DeleteMapSFX(11102136, false);
    DeleteMapSFX(11102137, false);
    DeleteMapSFX(11102138, false);
    DeleteMapSFX(11102139, false);
    DeleteMapSFX(11102140, false);
    DeleteMapSFX(11102141, false);
    DeleteMapSFX(11102142, false);
    DeleteMapSFX(11102143, false);
    DeleteMapSFX(11102144, false);
    DeleteMapSFX(11102145, false);
    DeleteMapSFX(11102146, false);
    DeleteMapSFX(11102147, false);
    EndEvent();
});

// 奥の間の扉が開いている -- The door in the back room is open
$Event(11002548, Restart, function() {
    EndIf(EventFlag(11108548));
    WaitFor(PlayerIsInOwnWorld() && EventFlag(181));
    SetEventFlagID(11108548, ON);
});

// 非戦闘エリア設定 -- Non-combat area setting
$Event(11102600, Restart, function() {
    DisableNetworkSync();
    ClearSpEffect(10000, 9621);
    WaitFor(PlayerInMap(11, 10, 0, 0) && !InArea(10000, 11102600) && !CeremonyActive(20));
    SetSpEffect(10000, 9621);
    WaitFixedTimeSeconds(1);
    WaitFor(!(PlayerInMap(11, 10, 0, 0) && !InArea(10000, 11102600) && !CeremonyActive(20)));
    RestartEvent();
});

// 位置非表示設定 -- Location hidden setting
$Event(11102602, Restart, function() {
    EndIf(!PlayerInMap(11, 10, 0, 0));
    SetPlayerPositionDisplay(Disabled, true, 11, 10, 0, 0, -305.7, -20.58, -298.1);
});

// 糞喰いの部屋解放 -- Shit-eater room released
$Event(11102605, Restart, function() {
    WaitForEventFlag(ON, TargetEventFlagType.EventFlag, 3063);
    ReproduceAssetAnimation(11101560, 2);
    EndEvent();
});

// 百智卿の部屋解放 -- Lord Hyakuchi's room released
$Event(11102606, Restart, function() {
    WaitFor(
        EventFlag(11109358)
            || (EventFlag(11109659) && EventFlag(3966))
            || (EventFlag(11109358) && EventFlag(11109660) && EventFlag(3967))
            || (EventFlag(110) && EventFlag(3967)));
    ReproduceAssetAnimation(11101750, 2);
    EndEvent();
});

// 拠点1F脱出スペル -- Base 1F escape spell
$Event(11102620, Default, function(eventFlagId, eventFlagId2, eventFlagId3, assetEntityId, initialAreaEntityId, areaId, blockId, regionId, indexId) {
    EndIf(!PlayerIsInOwnWorld());
    SetEventFlagID(eventFlagId2, OFF);
    SetEventFlagID(eventFlagId3, OFF);
    WaitFor(PlayerIsInOwnWorld() && EventFlag(eventFlagId));
    if (!ThisEventSlot()) {
        CreateAssetfollowingSFX(assetEntityId, 190, 1300);
    }
    WaitFor(
        !(HasMultiplayerState(MultiplayerState.MultiplayerPending)
            || HasMultiplayerState(MultiplayerState.Multiplayer))
            && ActionButtonInArea(9290, assetEntityId));
    DisplayGenericDialogAndSetEventFlags(4100, PromptType.YESNO, NumberofOptions.TwoButtons, assetEntityId, 3, eventFlagId2, eventFlagId3, eventFlagId3);
    if (!EventFlag(eventFlagId2)) {
        SetEventFlagID(eventFlagId3, ON);
        WaitFixedTimeSeconds(2);
        RestartEvent();
    }
L1:
    RotateCharacter(10000, 11101620, -1, true);
    ForceAnimationPlayback(10000, 60460, false, false, false);
    WaitFixedTimeSeconds(2.5);
    WarpPlayer(areaId, blockId, regionId, indexId, initialAreaEntityId, -11100);
});

// チュートリアルメッセージ_ホスト -- Tutorial message_host
$Event(11102650, Restart, function(eventFlagId, tutorialParamId, itemId, eventFlagId2) {
    DisableNetworkSync();
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(eventFlagId));
    WaitFor(
        PlayerIsInOwnWorld()
            && PlayerHasItem(ItemType.Goods, 104)
            && !(HasMultiplayerState(MultiplayerState.Multiplayer)
                || HasMultiplayerState(MultiplayerState.MultiplayerPending))
            && !CharacterHasSpEffect(10000, 9640));
    SetEventFlagID(eventFlagId, ON);
    ShowTutorialPopup(tutorialParamId, true, true);
    EndIf(EventFlag(eventFlagId2));
    DirectlyGivePlayerItem(ItemType.Goods, itemId, eventFlagId, 1);
    SetEventFlagID(eventFlagId2, ON);
});

// チュートリアルメッセージ_ゲスト -- Tutorial message_guest
$Event(11102651, Restart, function(eventFlagId, tutorialParamId, itemId, eventFlagId2) {
    DisableNetworkSync();
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(eventFlagId));
    WaitFor(
        PlayerIsInOwnWorld()
            && PlayerHasItem(ItemType.Goods, 105)
            && !(HasMultiplayerState(MultiplayerState.Multiplayer)
                || HasMultiplayerState(MultiplayerState.MultiplayerPending))
            && !CharacterHasSpEffect(10000, 9640));
    SetEventFlagID(eventFlagId, ON);
    ShowTutorialPopup(tutorialParamId, true, true);
    EndIf(EventFlag(eventFlagId2));
    DirectlyGivePlayerItem(ItemType.Goods, itemId, eventFlagId, 1);
    SetEventFlagID(eventFlagId2, ON);
});

// チュートリアルメッセージ_拠点到達 -- Tutorial message_reach base
$Event(11102652, Restart, function(eventFlagId, tutorialParamId, itemId, eventFlagId2) {
    DisableNetworkSync();
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(eventFlagId));
    WaitFor(
        PlayerIsInOwnWorld()
            && !EventFlag(eventFlagId)
            && PlayerInMap(11, 10, 0, 0)
            && !(HasMultiplayerState(MultiplayerState.Multiplayer)
                || HasMultiplayerState(MultiplayerState.MultiplayerPending))
            && !CharacterHasSpEffect(10000, 9640));
    SetEventFlagID(eventFlagId, ON);
    WaitFixedTimeSeconds(2);
    ShowTutorialPopup(tutorialParamId, true, true);
    EndIf(EventFlag(eventFlagId2));
    DirectlyGivePlayerItem(ItemType.Goods, itemId, eventFlagId, 1);
    SetEventFlagID(eventFlagId2, ON);
});

// 暗黒円卓空間_暗黒時 -- Dark Round Table Space_Dark Hours
$Event(11100680, Default, function() {
    EndIf(!CeremonyActive(20));
    EndIf(EventFlag(11109656));
    DisableCharacterHPBarDisplay(11100140);
    ActivateGparamOverride(1, 0);
    SetCharacterTeamType(11100766, TeamType.Enemy);
    WaitFixedTimeSeconds(0.5);
    ReproduceAssetAnimation(11101548, 0);
    WaitFor(CharacterDead(11100766));
    SetEventFlagID(11109656, ON);
    DisplayBanner(TextBannerType.GreatEnemyFelled);
    SetEventFlagID(1035429211, OFF);
    SetPsuedoMultiplayerReturnPosition(11102766);
    SetSpEffect(20000, 4820);
    IssueEndOfPseudoMultiplayerNotification(true);
});

// 暗黒円卓空間_敵起動 -- Dark round table space_enemy activation
$Event(11102680, Default, function() {
    EndIf(!CeremonyActive(20));
    EndIf(EventFlag(11109656));
    SetCharacterBackreadState(11100766, false);
    DisableCharacterAI(11100766);
    WaitFor(
        !InArea(10000, 11102681)
            || ElapsedSeconds(5)
            || HasDamageType(11100766, 10000, DamageType.Unspecified)
            || CharacterHasStateInfo(11000766, 6)
            || CharacterHasStateInfo(11000766, 2)
            || CharacterHasStateInfo(11000766, 436)
            || CharacterHasStateInfo(11000766, 260));
    EnableCharacterAI(11100766);
});

// 闘技場マリカ像_ハマり解消 -- Arena Marika Statue_Getting addicted
$Event(11100690, Restart, function() {
    EndIf(!PlayerIsInOwnWorld());
    EndIf(ThisEventSlot());
    area = InArea(10000, 11102690);
    GotoIf(L0, area);
    GotoIf(L1, !area);
L0:
    WarpCharacterAndCopyFloor(10000, TargetEntityType.Area, 11102691, -1, 0);
L1:
    EndEvent();
});

// NPC213鍛冶屋_NPC初期化イベント -- NPC213 Blacksmith_NPC initialization event
$Event(11103700, Restart, function(chrEntityId) {
    DisableNetworkSync();
    WaitFixedTimeFrames(1);
    if (PlayerIsInOwnWorld()) {
        if (EventFlag(3220)) {
            SetEventFlagID(11009248, OFF);
        }
    }
L10:
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    DisableAsset(11101740);
    DisableAsset(11101742);
    GotoIf(L5, EventFlag(3225) || EventFlag(3226) || EventFlag(3227) || EventFlag(3228));
    WaitFor(EventFlag(3225) || EventFlag(3226) || EventFlag(3227) || EventFlag(3228));
    RestartEvent();
    SetCharacterTalkRange(chrEntityId, 50);
L5:
    GotoIf(L1, EventFlag(3220));
    GotoIf(L2, EventFlag(3221));
    GotoIf(L4, EventFlag(3223));
L1:
    if (!(CeremonyActive(20) && EventFlag(1035429211))) {
        DeleteAssetfollowingSFX(11101702, true);
        CreateAssetfollowingSFX(11101702, 100, 803450);
        if (EventFlag(110)) {
            EnableAsset(11101742);
        }
        if (!EventFlag(110)) {
            EnableAsset(11101740);
        }
    }
    SetCharacterBackreadState(chrEntityId, false);
    EnableCharacter(chrEntityId);
    ForceAnimationPlayback(chrEntityId, 930010, false, false, false);
    if (EventFlag(3225) && EventFlag(11109205) && !EventFlag(11109209) && EventFlag(11109206)) {
        ForceAnimationPlayback(chrEntityId, 930013, false, false, false);
    }
    if (EventFlag(3225) && EventFlag(11109209) && !EventFlag(11109339) && EventFlag(11109340)) {
        ForceAnimationPlayback(chrEntityId, 930015, false, false, false);
    }
    GotoIf(L20, mainGroupAbuse);
L2:
    SetCharacterBackreadState(chrEntityId, false);
    EnableCharacter(chrEntityId);
    SetCharacterTeamType(chrEntityId, TeamType.HostileNPC);
    ForceAnimationPlayback(chrEntityId, 920015, false, false, false);
    Goto(L20);
L4:
    ForceCharacterTreasure(chrEntityId);
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L20:
    WaitFor(!(EventFlag(3225) || EventFlag(3226) || EventFlag(3227) || EventFlag(3228)));
    RestartEvent();
});

// NPC213鍛冶屋_自動会話イベント_祈り -- NPC213 Blacksmith_Automatic conversation event_Prayer
$Event(11103702, Restart, function() {
    WaitFor(
        EventFlag(3225)
            && EventFlag(11109205)
            && !EventFlag(11102702)
            && !EventFlag(11109209)
            && EventFlag(11109206)
            && (InArea(10000, 11102700) || EntityInRadiusOfEntity(10000, 11100715, 8, 1)));
    SetNetworkconnectedEventFlagID(11102704, ON);
    EndEvent();
});

// NPC213鍛冶屋_自動会話イベント_足りぬ -- NPC213 Blacksmith_Automatic conversation event_Not enough
$Event(11103703, Restart, function() {
    WaitFor(
        EventFlag(3225)
            && EventFlag(11109205)
            && !EventFlag(11102702)
            && EventFlag(11109209)
            && !EventFlag(11109339)
            && EventFlag(11109340)
            && (InArea(10000, 11102700) || EntityInRadiusOfEntity(10000, 11100715, 8, 1)));
    SetNetworkconnectedEventFlagID(11102708, ON);
    EndEvent();
});

// NPC320_ファルネーゼ_頭巾アイテムに差し替え -- NPC320_Farnese_Replaced with hood item
$Event(11100704, Restart, function() {
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(11109213));
    WaitFor(EventFlag(11109213));
    SetEventFlagID(10007450, ON);
    SetEventFlagID(10007452, OFF);
});

// NPC102指読み_NPC初期化イベント -- NPC102 finger reading_NPC initialization event
$Event(11103705, Restart, function(chrEntityId) {
    WaitFixedTimeFrames(1);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
        if (EventFlag(3480)) {
            SetEventFlagID(11109355, OFF);
        }
    }
L10:
    if (!EventFlag(3489)) {
        if (!(EventFlag(3485) || EventFlag(3486) || EventFlag(3487) || EventFlag(3488))) {
            DisableCharacter(chrEntityId);
            SetCharacterBackreadState(chrEntityId, true);
            WaitFor(
                EventFlag(3485)
                    || EventFlag(3486)
                    || EventFlag(3487)
                    || EventFlag(3488)
                    || EventFlag(3489));
            RestartEvent();
        }
L5:
        GotoIf(L1, EventFlag(3480));
        GotoIf(L2, EventFlag(3481));
        GotoIf(L3, EventFlag(3482));
        GotoIf(L4, EventFlag(3483));
L1:
        SetCharacterBackreadState(chrEntityId, false);
        EnableCharacter(chrEntityId);
        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);
    } else {
L4:
        EnableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, false);
        ForceAnimationPlayback(chrEntityId, 930010, false, false, false);
        Goto(L20);
    }
L20:
    WaitFor(
        !(EventFlag(3485)
            || EventFlag(3486)
            || EventFlag(3487)
            || EventFlag(3488)
            || EventFlag(3489)));
    RestartEvent();
});

// NPC104二本指_ジェスチャー入手 -- NPC104 Two fingers_Gesture obtained
$Event(11103706, Restart, function(entityId) {
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(60843));
    WaitFor(ActionButtonInArea(6321, entityId));
    SetEventFlagID(60843, ON);
    AwardGesture(102);
    EndEvent();
});

// NPC104二本指_待機アニメ再生 -- NPC104 Two fingers_standby animation playback
$Event(11103707, Restart, function(entityId) {
    ForceAnimationPlayback(entityId, 930001, false, false, false);
    WaitFixedTimeFrames(1);
    EndIf(EventFlag(3485));
    EndIf(EventFlag(3486));
    ForceAnimationPlayback(entityId, 930000, false, false, false);
    EndEvent();
});

// NPC320_ファルネーゼ_NPC初期化イベント_拠点に来た -- NPC320_Farnese_NPC initialization event_came to base
$Event(11103710, Restart, function(chrEntityId) {
    WaitFixedTimeFrames(1);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
    }
L19:
    if (!EventFlag(3707)) {
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        WaitFor(EventFlag(3707));
        RestartEvent();
    }
L6:
    GotoIf(L1, EventFlag(3700));
    GotoIf(L2, EventFlag(3701));
    GotoIf(L4, EventFlag(3703));
L1:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    ForceAnimationPlayback(chrEntityId, 90103, false, false, false);
    Goto(L20);
L2:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    SetCharacterTeamType(chrEntityId, TeamType.HostileNPC);
    Goto(L20);
L4:
    ForceCharacterTreasure(chrEntityId);
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L20:
    WaitFor(!EventFlag(3707));
    RestartEvent();
});

// NPC320_ファルネーゼ_NPC初期化イベント_調霊師 -- NPC320_Farnese_NPC initialization event_Soulmaster
$Event(11103711, Restart, function(chrEntityId) {
    WaitFixedTimeFrames(1);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
    }
L19:
    if (!(EventFlag(3708) || (EventFlag(3709) && EventFlag(11109279)))) {
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        if (!(EventFlag(3709) && !EventFlag(11109279))) {
            DisableAsset(11101720);
        }
        EndEvent();
    }
L6:
    GotoIf(L1, EventFlag(3700));
    GotoIf(L2, EventFlag(3701));
    GotoIf(L4, EventFlag(3703));
L1:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    EnableAsset(11101720);
    ForceAnimationPlayback(chrEntityId, 90104, false, false, false);
    Goto(L20);
L2:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    SetCharacterTeamType(chrEntityId, TeamType.HostileNPC);
    Goto(L20);
L4:
    ForceCharacterTreasure(chrEntityId);
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L20:
    WaitFor(!EventFlag(3708) && !EventFlag(3709));
    RestartEvent();
});

// NPC320_ファルネーゼ_NPC初期化イベント_世界樹が焼けた -- NPC320_Farnese_NPC initialization event_World Tree burnt
$Event(11103712, Restart, function(chrEntityId) {
    WaitFixedTimeFrames(1);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
    }
L19:
    if (!(EventFlag(3709) && !EventFlag(11109279))) {
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        EndEvent();
    }
L6:
    GotoIf(L1, EventFlag(3700));
    GotoIf(L2, EventFlag(3701));
    GotoIf(L4, EventFlag(3703));
L1:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    ForceAnimationPlayback(chrEntityId, 90103, false, false, false);
    SetNetworkconnectedEventFlagID(11102719, ON);
    Goto(L20);
L2:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    SetCharacterTeamType(chrEntityId, TeamType.HostileNPC);
    Goto(L20);
L4:
    ForceCharacterTreasure(chrEntityId);
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L20:
    WaitFor(!EventFlag(3709));
    RestartEvent();
});

// NPC320_ファルネーゼ_調霊回数チェックイベント -- NPC320_Farnese_Number of spiritual training check event
$Event(11103713, Restart, function() {
    EndIf(EventFlag(11109266));
    WaitForEventFlag(ON, TargetEventFlagType.EventFlag, 1041389415);
    StoreItemAmountHeldInEventValue(ItemType.Goods, 10903, 1041389417, 10);
    StoreItemAmountHeldInEventValue(ItemType.Goods, 10913, 1041389427, 10);
    SetEventFlagID(1041389415, OFF);
    SetEventFlagID(1041389416, ON);
    RestartEvent();
});

// NPC320_ファルネーゼ_調霊師_ランダムアニメ再生 -- NPC320_Farnese_Soulmaster_Random animation playback
$Event(11103714, Restart, function(entityId) {
    EndIf(!EventFlag(11109265));
    EndIf(EventFlag(11109266) && !EventFlag(11109267));
    EndIf(!EventFlag(1041389411));
    EndIf(EventFlag(3063) && !EventFlag(11109268));
    EndIf(EventFlag(11109268) && !EventFlag(35009306));
    EndIf(EventFlag(11109268) && EventFlag(4247) && !EventFlag(11109270));
    EndIf(EventFlag(11109268) && EventFlag(4248) && !EventFlag(11109272));
    EndIf(EventFlag(11109272) && EventFlag(4249) && !EventFlag(11109271));
    WaitFor(
        (EventFlag(3708) && InArea(10000, 11102700))
            || (EventFlag(3709) && EventFlag(11109279) && InArea(10000, 11102700)));
    RandomlySetEventFlagInRange(11102710, 11102716, ON);
    GotoIf(L1, EventFlag(11102710));
    GotoIf(L2, EventFlag(11102711));
    GotoIf(L3, EventFlag(11102712));
    GotoIf(L20, AnyBatchEventFlags(11102713, 11102716));
L1:
    ForceAnimationPlayback(entityId, 90202, false, false, false);
    Goto(L20);
L2:
    ForceAnimationPlayback(entityId, 90203, false, false, false);
    Goto(L20);
L3:
    ForceAnimationPlayback(entityId, 90204, false, false, false);
    Goto(L20);
L20:
    EndEvent();
});

// NPC314ムノウ_NPC初期化イベント_初期状態 -- NPC314 Munou_NPC initialization event_Initial state
$Event(11103715, Restart, function(chrEntityId) {
    DisableNetworkSync();
    WaitFixedTimeFrames(1);
    if (PlayerIsInOwnWorld()) {
        if (EventFlag(3440) && EventFlag(11109405)) {
            SetEventFlagID(11109405, OFF);
        }
    }
L10:
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    if (!EventFlag(3445)) {
        WaitFor(EventFlag(3445));
        RestartEvent();
    }
L5:
    GotoIf(L1, EventFlag(3440));
    GotoIf(L2, EventFlag(3441));
    GotoIf(L3, EventFlag(3442));
    GotoIf(L4, EventFlag(3443));
L1:
    SetCharacterBackreadState(chrEntityId, false);
    EnableCharacter(chrEntityId);
    ForceAnimationPlayback(chrEntityId, 90100, 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(3445));
    RestartEvent();
});

// NPC314ムノウ_NPC初期化イベント_火山館に誘われている -- NPC314 Munou_NPC initialization event_Invited to the Volcano Hall
$Event(11103716, Restart, function(chrEntityId) {
    DisableNetworkSync();
    WaitFixedTimeFrames(1);
    if (PlayerIsInOwnWorld()) {
        if (EventFlag(3440) && EventFlag(11109405)) {
            SetEventFlagID(11109405, OFF);
        }
    }
L10:
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    if (!EventFlag(3447)) {
        WaitFor(EventFlag(3447));
        RestartEvent();
    }
L5:
    GotoIf(L1, EventFlag(3440));
    GotoIf(L2, EventFlag(3441));
    GotoIf(L3, EventFlag(3442));
    GotoIf(L4, EventFlag(3443));
L1:
    SetCharacterBackreadState(chrEntityId, false);
    EnableCharacter(chrEntityId);
    ForceAnimationPlayback(chrEntityId, 90100, 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(3447));
    RestartEvent();
});

// NPC318_混沌の宿主_NPC初期化イベント_拠点に来た -- NPC318_Host of Chaos_NPC initialization event_Comed to base
$Event(11103720, Restart, function(chrEntityId) {
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
});

// NPC319ダヴィド_NPC初期化イベント_拠点 -- NPC319 David_NPC initialization event_base
$Event(11100730, Restart, function(chrEntityId, assetEntityId) {
    WaitFixedTimeFrames(1);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
    }
L19:
    if (!EventFlag(4047)) {
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        DisableAssetInvunerability(assetEntityId);
        DisableAsset(assetEntityId);
        WaitFor(EventFlag(4047));
        RestartEvent();
    }
L7:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    RequestAssetRestoration(assetEntityId);
    EnableAssetInvunerability(assetEntityId);
    EnableAsset(assetEntityId);
    ForceAnimationPlayback(chrEntityId, 90100, false, false, false);
    Goto(L20);
L20:
    WaitFor(!EventFlag(4047));
    RestartEvent();
});

// NPC319ダヴィド_NPC初期化イベント_死体 -- NPC319 David_NPC initialization event_corpse
$Event(11100731, Restart, function(chrEntityId, assetEntityId, entityId) {
    WaitFixedTimeFrames(1);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
    }
L19:
    if (!EventFlag(4048)) {
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        DisableAsset(assetEntityId);
        WaitFor(EventFlag(4048));
        RestartEvent();
    }
L8:
    ForceAnimationPlayback(entityId, 2, false, false, false);
    if (!AllBatchEventFlags(400349, 400349)) {
        EnableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, false);
        DisableCharacterCollision(chrEntityId);
        ForceAnimationPlayback(chrEntityId, 90104, false, false, false);
        EnableAsset(assetEntityId);
    } else {
L3:
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        DisableAsset(assetEntityId);
        Goto(L20);
    }
L20:
    WaitFor(!EventFlag(4048));
    RestartEvent();
});

// NPC319ダヴィド_拠点移動時リアルタイム遷移 -- NPC319 David_Real-time transition when moving base
$Event(11100732, Restart, function() {
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(11109609));
    WaitFor(EventFlag(4046));
    SetEventFlagID(11109609, ON);
    SetEventFlagID(4058, ON);
});

// NPC322ユリア_NPC初期化イベント_初期状態 -- NPC322 Yuria_NPC initialization event_initial state
$Event(11100735, Restart, function(chrEntityId) {
    DisableNetworkSync();
    WaitFixedTimeFrames(1);
    if (PlayerIsInOwnWorld()) {
    }
L19:
    if (!EventFlag(4125)) {
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        WaitFor(EventFlag(4125));
        RestartEvent();
    }
L5:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    ForceAnimationPlayback(chrEntityId, 90100, false, false, false);
    Goto(L20);
L20:
    WaitFor(!EventFlag(4125));
    RestartEvent();
});

// NPC322ユリア_NPC初期化イベント_聖痕を取り戻した -- NPC322 Yuria_NPC initialization event_Recovered stigmata
$Event(11100736, Restart, function(chrEntityId) {
    WaitFixedTimeFrames(1);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
    }
L19:
    if (!EventFlag(4126)) {
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        WaitFor(EventFlag(4126));
        RestartEvent();
    }
L6:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    ForceAnimationPlayback(chrEntityId, 90101, false, false, false);
    Goto(L20);
L20:
    WaitFor(!EventFlag(4126));
    RestartEvent();
});

// NPC322ユリア_リアルタイム状態遷移 -- NPC322 Yuria_Real-time state transition
$Event(11100737, Restart, function(entityId) {
    EndIf(!PlayerIsInOwnWorld());
    WaitFor(EventFlag(4126) && EventFlag(11109015) && PlayerIsInOwnWorld());
    ForceAnimationPlayback(entityId, 90207, false, false, false);
});

// NPC324百智卿_ﾌｪｰｽﾞ1_NPC初期化イベント -- NPC324 Lord Hyakuchi_Phase 1_NPC initialization event
$Event(11100740, Restart, function(chrEntityId) {
    WaitFixedTimeFrames(1);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
    }
L19:
    if (!EventFlag(3965)) {
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        WaitFor(EventFlag(3965));
        RestartEvent();
    }
L6:
    GotoIf(L1, EventFlag(3960));
    GotoIf(L2, EventFlag(3961));
    GotoIf(L4, EventFlag(3963));
L1:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    ForceAnimationPlayback(chrEntityId, 90100, false, false, false);
    Goto(L20);
L2:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    SetCharacterTeamType(chrEntityId, TeamType.HostileNPC);
    Goto(L20);
L4:
    ForceCharacterTreasure(chrEntityId);
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L20:
    WaitFor(!EventFlag(3965));
    RestartEvent();
});

// NPC324百智卿_ﾌｪｰｽﾞ2or3_NPC初期化イベント -- NPC324 Momochi Lord_Phase 2or3_NPC initialization event
$Event(11100741, Restart, function(chrEntityId) {
    WaitFixedTimeFrames(1);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
    }
L19:
    if (!(EventFlag(3966) || EventFlag(3967))) {
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        WaitFor(EventFlag(3966) || EventFlag(3967));
        RestartEvent();
    }
L6:
    GotoIf(L1, EventFlag(3960));
    GotoIf(L2, EventFlag(3961));
    GotoIf(L4, EventFlag(3963));
L1:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    ForceAnimationPlayback(chrEntityId, 90101, false, false, false);
    Goto(L20);
L2:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    SetCharacterTeamType(chrEntityId, TeamType.HostileNPC);
    Goto(L20);
L4:
    ForceCharacterTreasure(chrEntityId);
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L20:
    WaitFor(!EventFlag(3966) && !EventFlag(3967));
    RestartEvent();
});

// NPC351金仮面の従者_NPC初期化イベント -- NPC351 Gold Masked Squire_NPC initialization event
$Event(11100745, Restart, function(chrEntityId) {
    DisableNetworkSync();
    WaitFixedTimeFrames(1);
    if (PlayerIsInOwnWorld()) {
    }
L10:
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    if (!EventFlag(4205)) {
        WaitFor(EventFlag(4205));
        RestartEvent();
    }
L5:
    GotoIf(L1, EventFlag(4200));
    GotoIf(L2, EventFlag(4201));
    GotoIf(L4, EventFlag(4203));
L1:
    SetCharacterBackreadState(chrEntityId, false);
    EnableCharacter(chrEntityId);
    ForceAnimationPlayback(chrEntityId, 90101, false, false, false);
    GotoIf(L20, mainGroupAbuse);
L2:
    SetCharacterBackreadState(chrEntityId, false);
    EnableCharacter(chrEntityId);
    SetCharacterTeamType(chrEntityId, TeamType.HostileNPC);
    Goto(L20);
L4:
    ForceCharacterTreasure(chrEntityId);
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L20:
    WaitFor(!EventFlag(4205));
    RestartEvent();
});

// NPC325ロジェール_NPC初期化イベント_拠点で再会 -- NPC325 Roger_NPC initialization event_Reunion at the base
$Event(11100750, Restart, function(chrEntityId, assetEntityId) {
    DisableNetworkSync();
    WaitFixedTimeFrames(1);
    if (PlayerIsInOwnWorld()) {
        if (EventFlag(11109527)) {
            SetEventFlagID(11109529, ON);
        }
        if (EventFlag(11109535)) {
            IncrementEventValue(11109545, 5, 2);
        }
    }
L19:
    GotoIf(L7, EventFlag(3907));
    GotoIf(L8, EventFlag(3908));
    GotoIf(L9, EventFlag(3909));
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    DisableAssetInvunerability(assetEntityId);
    DisableAsset(assetEntityId);
    WaitFor(AnyBatchEventFlags(3907, 3909));
    RestartEvent();
L7:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    ForceAnimationPlayback(chrEntityId, 90101, false, false, false);
    RequestAssetRestoration(assetEntityId);
    EnableAssetInvunerability(assetEntityId);
    EnableAsset(assetEntityId);
    Goto(L20);
L20:
    WaitFor(!EventFlag(3907));
    RestartEvent();
L8:
L9:
    if (PlayerIsInOwnWorld()) {
        if (!EventFlag(11109522)) {
            SetEventFlagID(400356, ON);
        }
    }
    if (!AllBatchEventFlags(400356, 400359)) {
        EnableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, false);
        ForceAnimationPlayback(chrEntityId, 90106, false, false, false);
        RequestAssetRestoration(assetEntityId);
        EnableAssetInvunerability(assetEntityId);
        EnableAsset(assetEntityId);
    } else {
L3:
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        DisableAssetInvunerability(assetEntityId);
        DisableAsset(assetEntityId);
        Goto(L20);
    }
L20:
    WaitFor(!AnyBatchEventFlags(3908, 3909));
    RestartEvent();
});

// NPC323糞喰い_ﾌｪｰｽﾞ1_NPC初期化イベント -- NPC323 Shit-eating_Phase 1_NPC initialization event
$Event(11100755, Restart, function(chrEntityId) {
    DisableNetworkSync();
    WaitFixedTimeFrames(1);
    if (PlayerIsInOwnWorld()) {
    }
L10:
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    if (!(EventFlag(4245) || (EventFlag(4246) && !EventFlag(35009315)))) {
        WaitFor(EventFlag(4245) || (EventFlag(4246) && !EventFlag(35009315)));
        RestartEvent();
    }
L5:
    GotoIf(L1, EventFlag(4240));
    GotoIf(L2, EventFlag(4241));
    GotoIf(L4, EventFlag(4243));
L1:
    SetCharacterBackreadState(chrEntityId, false);
    EnableCharacter(chrEntityId);
    ForceAnimationPlayback(chrEntityId, 90100, false, false, false);
    GotoIf(L20, mainGroupAbuse);
L2:
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L4:
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L20:
    WaitFor(!(EventFlag(4245) || (EventFlag(4246) && !EventFlag(35009315))));
    RestartEvent();
});

// NPC323糞喰い_ﾌｪｰｽﾞ2_NPC初期化イベント -- NPC323 Shit-eating_Phase 2_NPC initialization event
$Event(11100756, Restart, function(chrEntityId) {
    DisableNetworkSync();
    WaitFixedTimeFrames(1);
    if (PlayerIsInOwnWorld()) {
    }
L10:
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    if (!EventFlag(4248)) {
        WaitFor(EventFlag(4248));
        RestartEvent();
    }
L5:
    GotoIf(L1, EventFlag(4240));
    GotoIf(L2, EventFlag(4241));
    GotoIf(L4, EventFlag(4243));
L1:
    SetCharacterBackreadState(chrEntityId, false);
    EnableCharacter(chrEntityId);
    ForceAnimationPlayback(chrEntityId, 90100, false, false, false);
    GotoIf(L20, mainGroupAbuse);
L2:
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L4:
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L20:
    WaitFor(!EventFlag(4248));
    RestartEvent();
});

// NPC334百智卿の娘_ﾌｪｰｽﾞ2_NPC初期化イベント -- NPC334 Momochi Lord's Daughter_Phase 2_NPC Initialization Event
$Event(11100760, Restart, function(chrEntityId) {
    WaitFixedTimeFrames(1);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
    }
L19:
    GotoIf(L6, EventFlag(4226) && (EventFlag(3966) || EventFlag(3967)));
    GotoIf(L4, EventFlag(4226) && EventFlag(4223));
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    WaitFor((EventFlag(3966) || EventFlag(3967)) && EventFlag(4226));
    RestartEvent();
L6:
    GotoIf(L1, EventFlag(4220));
    GotoIf(L2, EventFlag(4221));
    GotoIf(L4, EventFlag(4223));
L1:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    ForceAnimationPlayback(chrEntityId, 90100, false, false, false);
    Goto(L20);
L2:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    SetCharacterTeamType(chrEntityId, TeamType.HostileNPC);
    Goto(L20);
L4:
    ForceCharacterTreasure(chrEntityId);
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    EndEvent();
L20:
    WaitFor(!((EventFlag(3966) || EventFlag(3967)) && EventFlag(4226)));
    RestartEvent();
});

// NPC334百智卿の娘_ﾌｪｰｽﾞ4_NPC初期化イベント -- NPC334 Momochi Lord's Daughter_Phase 4_NPC Initialization Event
$Event(11100761, Restart, function(chrEntityId) {
    WaitFixedTimeFrames(1);
    DisableNetworkSync();
    if (PlayerIsInOwnWorld()) {
    }
L19:
    if (!EventFlag(4228)) {
        DisableCharacter(chrEntityId);
        SetCharacterBackreadState(chrEntityId, true);
        WaitFor(EventFlag(4228));
        RestartEvent();
    }
L6:
    GotoIf(L1, EventFlag(4220));
    GotoIf(L2, EventFlag(4221));
    GotoIf(L4, EventFlag(4223));
L1:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    ForceAnimationPlayback(chrEntityId, 90101, false, false, false);
    Goto(L20);
L2:
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    SetCharacterTeamType(chrEntityId, TeamType.HostileNPC);
    Goto(L20);
L4:
    ForceCharacterTreasure(chrEntityId);
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    Goto(L20);
L20:
    WaitFor(!EventFlag(4228));
    RestartEvent();
});

// NPC339百智卿の手先_NPC初期化イベント -- NPC339 Lord Hyakuchi's minions_NPC initialization event
$Event(11100765, Restart, function(chrEntityId) {
    DisableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, true);
    WaitFor(!(EventFlag(110) || EventFlag(11109656)));
    EnableCharacter(chrEntityId);
    SetCharacterBackreadState(chrEntityId, false);
    ForceAnimationPlayback(chrEntityId, 90100, false, false, false);
    EndEvent();
});

// 王都到達済みチェック -- Check that you have reached the royal capital
$Event(11103770, Restart, function() {
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(11109340) && EventFlag(11109558));
    WaitFor(AnyBatchEventFlags(71100, 71108) || AnyBatchEventFlags(73500, 73504));
    SetNetworkconnectedEventFlagID(11109340, ON);
    SetNetworkconnectedEventFlagID(11109558, ON);
    EndEvent();
});

// 腐れ大樹到達済みチェック -- Check that the rotten tree has been reached
$Event(11103771, Restart, function() {
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(11109559));
    WaitFor(AnyBatchEventFlags(71500, 71508));
    SetNetworkconnectedEventFlagID(11109559, ON);
    EndEvent();
});

// 平原奥地到達済みチェック -- Check that you have reached the plains hinterland
$Event(11103772, Restart, function() {
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(11109560));
    WaitFor(AnyBatchEventFlags(71250, 71253));
    SetNetworkconnectedEventFlagID(11109560, ON);
    EndEvent();
});

// 拠点入場時ダイアログ表示 -- Dialog display when entering base
$Event(11103775, Default, function() {
    EndIf(!PlayerIsInOwnWorld());
    if (EventFlag(11109786)) {
        SetEventFlagID(11109786, OFF);
        EndEvent();
    }
    EndIf(CeremonyActive(20));
    EndIf(!EntityInRadiusOfEntity(10000, 11102020, 1, 1));
    WaitFixedTimeSeconds(0.1);
    flag = EventFlag(1034509254);
    WaitFor(flag || EventFlag(11109785));
    if (!flag.Passed) {
        SetEventFlagID(11109785, OFF);
        DisplayGenericDialog(30120, PromptType.OKCANCEL, NumberofOptions.OneButton, 0, 5);
        EndEvent();
    }
L0:
    SetEventFlagID(1034509254, OFF);
    DisplayGenericDialog(30130, PromptType.YESNO, NumberofOptions.NoButtons, 0, 5);
    EndEvent();
});

// 篝火_拠点に居る判定 -- Bonfire_Judgment of being at the base
$Event(11100790, Restart, function() {
    EndIf(!PlayerIsInOwnWorld());
    SetNetworkconnectedEventFlagID(11102790, ON);
    EndEvent();
});

// 遺灰ショップ_百智卿取り逃し対策_XX -- Ashes shop_Measures for missing Lord Hyakuchi_XX
$Event(11100791, Restart, function(eventFlagId, eventFlagId2) {
    EndIf(!PlayerIsInOwnWorld());
    EndIf(EventFlag(eventFlagId));
    EndIf(EventFlag(eventFlagId2));
    WaitFor(EventFlag(3968) || EventFlag(eventFlagId));
    if (EventFlag(3968)) {
        if (!EventFlag(eventFlagId)) {
            SetEventFlagID(eventFlagId2, ON);
            SetEventFlagID(11109785, ON);
        }
    }
    EndEvent();
});

// 化粧台アニメ起動 -- Vanity table animation launch
$Event(11100795, Restart, function() {
    EndIf(!PlayerIsInOwnWorld());
    WaitFor(CharacterHasSpEffect(10000, 9614) && !CharacterHasSpEffect(10000, 9615));
    ForceAnimationPlayback(10000, 60540, false, false, false);
    WaitFixedTimeSeconds(0.2);
    RestartEvent();
});

// 救済対応_大ルーン2個チェック系 -- Relief response_2 large runes checked
$Event(11100796, Default, function() {
    EndIf(!PlayerIsInOwnWorld());
    EndIf(!EventFlag(182));
    if (!EventFlag(60020) && !EventFlag(11109774)) {
        SetEventFlagID(11109774, ON);
        SetEventFlagID(11109785, ON);
    }
    if (!EventFlag(60120) && !EventFlag(11109775)) {
        SetEventFlagID(11109775, ON);
        SetEventFlagID(11109785, ON);
    }
    if (!EventFlag(60130) && !EventFlag(11109776)) {
        SetEventFlagID(11109776, ON);
        SetEventFlagID(11109785, ON);
    }
    EndEvent();
});

// 救済対応_指読み -- Relief response_finger reading
$Event(11100797, Default, function() {
    EndIf(!PlayerIsInOwnWorld());
    WaitFixedTimeRealFrames(1);
    EndIf(!(AnyBatchEventFlags(3487, 3489) && !EventFlag(60500) && !EventFlag(11109777)));
    SetEventFlagID(11109777, ON);
    SetEventFlagID(11109785, ON);
    EndEvent();
});
