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

// コンストラクタ -- constructor
$Event(0, Default, function() {
    RegisterBonfire(1039420000, 1039421950, 0, 0, 0, 5);
    $InitializeEvent(0, 1039422202, 1039420202);
    $InitializeEvent(1, 1039422202, 1039420203);
    $InitializeEvent(2, 1039422202, 1039420204);
    $InitializeEvent(0, 1039422210, 1039420210, 1039422210, 1039422210);
    $InitializeEvent(1, 1039422210, 1039420211, 1039422210, 1039422211);
    $InitializeEvent(2, 1039422210, 1039420212, 1039422210, 1039422212);
    $InitializeEvent(3, 1039422210, 1039420213, 1039422210, 1039422213);
    $InitializeEvent(4, 1039422210, 1039420214, 1039422210, 1039422214);
    $InitializeEvent(5, 1039422210, 1039420215, 1039422210, 1039422215);
    $InitializeEvent(6, 1039422210, 1039420216, 1039422210, 1039422216);
    $InitializeEvent(7, 1039422210, 1039420217, 1039422210, 1039422217);
    $InitializeEvent(8, 1039422210, 1039420218, 1039422210, 1039422218);
    $InitializeEvent(0, 1039422340, 1039420340, 1039422340, 1039422340);
    $InitializeEvent(0, 1039422200, 1039425200, 1039422200);
    $InitializeEvent(0, 1039422600, 1039421600, 1039421601, 82020);
    $InitializeCommonEvent(0, 90005605, 1039421610, 60, 18, 27, 1, 1035452630, 0, 1035452610, 1039422611, 1039422612, 0, 0, 0, 0);
    $InitializeCommonEvent(0, 90005630, 61394200, 1039421500, 115);
    $InitializeCommonEvent(0, 90005683, 62203, 1039421684, 209, 78294, 78294);
    $InitializeCommonEvent(0, 90005631, 1039421640, 61020);
    $InitializeCommonEvent(0, 90005706, 1039420700, 930025, 0);
});

// プリコンストラクタ -- preconstructor
$Event(50, Default, function() {
    SetCharacterBackreadState(1039420700, true);
});

// 戦場跡_交戦イベント -- Battlefield Ruins_Battle Event
$Event(1039422200, Restart, function(chrEntityId, areaEntityId) {
    ClearSpEffect(chrEntityId, 4800);
    ClearSpEffect(chrEntityId, 5657);
    SetSpEffect(chrEntityId, 4802);
    EndIf(EventFlag(1039422200));
    SetSpEffect(chrEntityId, 4800);
    SetSpEffect(chrEntityId, 5657);
    WaitFor(
        ((CharacterType(10000, TargetType.BlackPhantom) && CharacterHasSpEffect(10000, 3710))
            || CharacterType(10000, TargetType.Alive)
            || CharacterType(10000, TargetType.GrayPhantom)
            || CharacterType(10000, TargetType.WhitePhantom))
            && (HasDamageType(chrEntityId, 10000, DamageType.Unspecified)
                || HasDamageType(chrEntityId, 35000, DamageType.Unspecified)
                || HasDamageType(35000, chrEntityId, DamageType.Unspecified)
                || EntityInRadiusOfEntity(10000, chrEntityId, 10, 1)
                || EntityInRadiusOfEntity(35000, chrEntityId, 10, 1)
                || InArea(10000, areaEntityId)
                || InArea(35000, areaEntityId)));
    SetNetworkconnectedEventFlagID(1039422200, ON);
    ClearSpEffect(chrEntityId, 4800);
    ClearSpEffect(chrEntityId, 5657);
});

// 死亡待機_XX -- Waiting for death_XX
$Event(1039422202, Restart, function(chrEntityId) {
    ForceCharacterDeath(chrEntityId, false);
    EndEvent();
});

// 傀儡召喚イベント_XX -- Puppet summoning event_XX
$Event(1039422210, Restart, function(chrEntityId, areaEntityId, eventFlagId) {
    EndIf(CharacterDead(chrEntityId));
    EndIf(SpecialStandbyEndedFlag(chrEntityId));
    DisableCharacter(chrEntityId);
    DisableCharacterCollision(chrEntityId);
    chrSp = (CharacterType(10000, TargetType.BlackPhantom) && CharacterHasSpEffect(10000, 3710))
        || CharacterType(10000, TargetType.Alive)
        || CharacterType(10000, TargetType.GrayPhantom)
        || CharacterType(10000, TargetType.WhitePhantom);
    areaChr = InArea(10000, areaEntityId)
        || CharacterHasStateInfo(chrEntityId, 436)
        || CharacterHasStateInfo(chrEntityId, 2)
        || CharacterHasStateInfo(chrEntityId, 5)
        || CharacterHasStateInfo(chrEntityId, 6)
        || CharacterHasStateInfo(chrEntityId, 260);
    sp = CharacterHasSpEffect(chrEntityId, 481)
        && !CharacterHasSpEffect(chrEntityId, 90100)
        && !CharacterHasSpEffect(chrEntityId, 90110)
        && !CharacterHasSpEffect(chrEntityId, 90160);
    sp2 = CharacterHasSpEffect(chrEntityId, 482)
        && !CharacterHasSpEffect(chrEntityId, 90100)
        && !CharacterHasSpEffect(chrEntityId, 90120)
        && !CharacterHasSpEffect(chrEntityId, 90160)
        && !CharacterHasSpEffect(chrEntityId, 90162);
    sp3 = CharacterHasSpEffect(chrEntityId, 483)
        && !CharacterHasSpEffect(chrEntityId, 90100)
        && !CharacterHasSpEffect(chrEntityId, 90140)
        && !CharacterHasSpEffect(chrEntityId, 90160)
        && !CharacterHasSpEffect(chrEntityId, 90161);
    sp4 = CharacterHasSpEffect(chrEntityId, 484)
        && !CharacterHasSpEffect(chrEntityId, 90100)
        && !CharacterHasSpEffect(chrEntityId, 90130)
        && !CharacterHasSpEffect(chrEntityId, 90161)
        && !CharacterHasSpEffect(chrEntityId, 90162);
    sp5 = CharacterHasSpEffect(chrEntityId, 487)
        && !CharacterHasSpEffect(chrEntityId, 90100)
        && !CharacterHasSpEffect(chrEntityId, 90150)
        && !CharacterHasSpEffect(chrEntityId, 90160);
    areaChrSp = areaChr && chrSp;
    WaitFor(areaChrSp || sp || sp2 || sp3 || sp4 || sp5);
    SetNetworkconnectedEventFlagID(eventFlagId, ON);
    SetSpecialStandbyEndedFlag(chrEntityId, ON);
    WaitRandomTimeSeconds(0, 1);
    ForceAnimationPlayback(chrEntityId, 30004, false, false, false);
    EnableCharacter(chrEntityId);
    EnableCharacterCollision(chrEntityId);
    ForceAnimationPlayback(chrEntityId, 20004, false, false, false);
    EndEvent();
});

// トロル傀儡召喚イベント -- Troll puppet summoning event
$Event(1039422340, Restart, function(chrEntityId, areaEntityId, eventFlagId) {
    EndIf(CharacterDead(chrEntityId));
    EndIf(SpecialStandbyEndedFlag(chrEntityId));
    DisableCharacter(chrEntityId);
    DisableCharacterCollision(chrEntityId);
    chrSp = (CharacterType(10000, TargetType.BlackPhantom) && CharacterHasSpEffect(10000, 3710))
        || CharacterType(10000, TargetType.Alive)
        || CharacterType(10000, TargetType.GrayPhantom)
        || CharacterType(10000, TargetType.WhitePhantom);
    areaChr = InArea(10000, areaEntityId)
        || CharacterHasStateInfo(chrEntityId, 436)
        || CharacterHasStateInfo(chrEntityId, 2)
        || CharacterHasStateInfo(chrEntityId, 5)
        || CharacterHasStateInfo(chrEntityId, 6)
        || CharacterHasStateInfo(chrEntityId, 260);
    sp = CharacterHasSpEffect(chrEntityId, 481)
        && !CharacterHasSpEffect(chrEntityId, 90100)
        && !CharacterHasSpEffect(chrEntityId, 90110)
        && !CharacterHasSpEffect(chrEntityId, 90160);
    sp2 = CharacterHasSpEffect(chrEntityId, 482)
        && !CharacterHasSpEffect(chrEntityId, 90100)
        && !CharacterHasSpEffect(chrEntityId, 90120)
        && !CharacterHasSpEffect(chrEntityId, 90160)
        && !CharacterHasSpEffect(chrEntityId, 90162);
    sp3 = CharacterHasSpEffect(chrEntityId, 483)
        && !CharacterHasSpEffect(chrEntityId, 90100)
        && !CharacterHasSpEffect(chrEntityId, 90140)
        && !CharacterHasSpEffect(chrEntityId, 90160)
        && !CharacterHasSpEffect(chrEntityId, 90161);
    sp4 = CharacterHasSpEffect(chrEntityId, 484)
        && !CharacterHasSpEffect(chrEntityId, 90100)
        && !CharacterHasSpEffect(chrEntityId, 90130)
        && !CharacterHasSpEffect(chrEntityId, 90161)
        && !CharacterHasSpEffect(chrEntityId, 90162);
    sp5 = CharacterHasSpEffect(chrEntityId, 487)
        && !CharacterHasSpEffect(chrEntityId, 90100)
        && !CharacterHasSpEffect(chrEntityId, 90150)
        && !CharacterHasSpEffect(chrEntityId, 90160);
    areaChrSp = areaChr && chrSp;
    WaitFor(areaChrSp || sp || sp2 || sp3 || sp4 || sp5);
    SetNetworkconnectedEventFlagID(eventFlagId, ON);
    SetSpecialStandbyEndedFlag(chrEntityId, ON);
    ForceAnimationPlayback(chrEntityId, 30004, false, false, false);
    EnableCharacter(chrEntityId);
    EnableCharacterCollision(chrEntityId);
    ForceAnimationPlayback(chrEntityId, 20004, false, false, false);
    EndEvent();
});

// 地図石碑光SFX切り替え -- Map stone monument light SFX switching
$Event(1039422600, Restart, function(assetEntityId, entityId, eventFlagId) {
    if (!EventFlag(eventFlagId)) {
        CreateAssetfollowingSFX(assetEntityId, 200, 803220);
    }
L0:
    WaitFor(EventFlag(eventFlagId));
    ForceAnimationPlayback(entityId, 1, false, false, false);
    DeleteAssetfollowingSFX(assetEntityId, true);
});

// 汎用ワープOBJイベント_開始 -- General purpose warp OBJ event_start
$Event(1039422610, Restart, function(entityId, areaId, blockId, regionId, indexId, initialAreaEntityId, eventFlagId, eventFlagId2) {
    EndIf(HasMultiplayerState(MultiplayerState.Multiplayer));
    SetEventFlagID(eventFlagId, OFF);
    SetEventFlagID(eventFlagId2, OFF);
    WaitFor(
        HasMultiplayerState(MultiplayerState.Singleplayer) && ActionButtonInArea(9140, entityId));
    DisplayGenericDialogAndSetEventFlags(4300, PromptType.YESNO, NumberofOptions.TwoButtons, entityId, 3, eventFlagId, eventFlagId2, eventFlagId2);
    if (!EventFlag(eventFlagId)) {
        WaitFixedTimeSeconds(1);
        RestartEvent();
    }
L1:
    WarpPlayer(areaId, blockId, regionId, indexId, initialAreaEntityId, 0);
});
