let BtlMVVar = ""; 
let WaitMdlName = MdlRomashaBattle; 
let WaitSetPs = "right"; 
let WaitZureX = 0; 
let WaitZureY = 0; 
let WaitMotionName = "batalle_bless"; 
let WaitMdl_Reset = function () {
    WaitMdlName = MdlRomashaBattle; 
    WaitSetPs = "right";
    WaitZureX = 0; 
    WaitZureY = 0; 
    WaitMotionName = "batalle_bless"; 
}
let N_BtlDebugMdl = function () {
    WaitMdlName = "romasha_battale";
    WaitMotionName = "batalle_bless";
}
let FカットインOffFrame = 0;
let BBefIsFastカットイン = false;
let FカットインOutModel
let L2dBattleカットインモデルOff = function () {
    L2dAutoFadeOut(WaitMdlName,15);
    BBefIsFastカットイン = isFastOff;
    isFastOff = true;
}
let L2dBattleカットインモデル再開 = function () {
    L2dFadeMdl(WaitMdlName, WaitSetPs + "in", 15, WaitMotionName ,
        1, 1, WaitZureX, WaitZureY);
    if (WaitMdlName == "romasha_battale") {
        L2dIdleStart(WaitMdlName,WaitMotionName);
        L2dSetMotion(WaitMdlName,WaitMotionName); 
        L2D_ParamSet(WaitMdlName, "BattleSize", 30); 
    }
    isFastOff = BBefIsFastカットイン;
}
let Live2D_WaitSetTime = -1; 
let _戦闘Live2Dロード = function () {
    if (BtlRomashaFlg) { 
        L2ModelSetting("romasha_chichimomi");
        L2ModelSetting("romasha_battleback");
        L2ModelSetting("romasha_kick");
        L2ModelSetting("romasha_tawashi");
        L2ModelSetting("romasha_massaging_ass");
        L2ModelSetting("romasha_kusuguri");
    }
}
let _戦闘Live2D_事前読込 = function () {
    L2ModelSetting("romasha_chichimomi");
    L2ModelSetting("romasha_battleback");
    L2ModelSetting("romasha_kick");
    L2ModelSetting("romasha_tawashi");
    L2ModelSetting("romasha_massaging_ass");
    L2ModelSetting("romasha_kusuguri");
}
Game_Interpreter.prototype.L2DTAnimeC = function (PicNo, FileName, CellSu, CellFlm, setx, sety, opi, mx, my) {
    opi = typeof opi !== 'undefined' ? opi : 255;
    mx = typeof mx !== 'undefined' ? mx : 100;
    my = typeof my !== 'undefined' ? my : 100;
    this.PlayPicAnimeC(PicNo, BtlPicPath + "BAnime/" + FileName, CellSu, CellFlm, setx, sety, opi, mx, my);
}
Game_Interpreter.prototype.L2DTAnimeCOne = function (PicNo, FileName, CellSu, CellFlm, setx, sety, opi, mx, my) {
    PPicAnimeLoopFlg = false; 
    this.L2DTAnimeC(PicNo, FileName, CellSu, CellFlm, setx, sety, opi, mx, my);
}
let PlayerBtlChara = null;
Game_Interpreter.prototype.BtlLive2DStart = function () {
    this.Btl_Chara_SetUp();
    let viewLive2DMdl = PlayerBtlChara.BtlLive2D.Name;
    if (FinalFormFlg && viewLive2DMdl == MdlRomashaBattle) {
        viewLive2DMdl = "romasha_battale2"
        PlayerBtlChara.ZureX = 50;
    }
    L2dFadeMdl(viewLive2DMdl, "rightin", 10, "", 1, 1, PlayerBtlChara.ZureX, 0);
    L2dTalkTop(viewLive2DMdl); 
    let _SetWaitMotionName = WaitMotionName;
    WaitMotionName = "";
    this.BtlLive2DWaitCng(_SetWaitMotionName); 
    if (BtlRomashaFlg) {
        L2dAutoFadeOut("romasha_talk", 15); 
        let viewName = MdlRomashaBattle;
        if (FinalFormFlg) viewName = "romasha_battale2";
        L2D_ParamSet(viewName, "BattleSize", 30); 
        _着替え値保管用 = $gameVariables.value(VN_TL2DKigae);
    }
    this.SpineView(PN_CharacterPL, "Romasha", "Idl"
        , true, NPlayer[0]._PosX, NPlayer[0]._PosY, 255, plSpineScaleX, plSpineScaleY);
}
let HajiFlg = false; 
Game_Interpreter.prototype.BtlLive2DWaitCng = function (_MtnName, _Timer) {
    _Timer = typeof _Timer !== 'undefined' ? _Timer : 0;
    if (this.IsPlayerメタル化()) return;
    if (BtlRomashaFlg) {
        if (WaitMdlName == MdlRomashaBattle) {
            switch (_MtnName) {
                case "batalle_blessHAJI":
                    HajiFlg = true;
                    break;
            }
        }
    }
    if (WaitMdlName == MdlRomashaBattle) {
        if (WaitMotionName != _MtnName) {
            Live2D_WaitSetTime = _Timer; 
            WaitMotionName = _MtnName;
            this.BtlLive2DUpdate(); 
        }
    }
}
Game_Interpreter.prototype.BtlLive2DUpdate = function () {
    if (this.IsPlayerメタル化()) return; 
    if (Live2D_WaitSetTime == 0) {
        //L2dSetMotion(WaitMdlName, WaitMotionName);  //即対応させる
        L2dIdleStart(WaitMdlName, WaitMotionName);
    }
    if (Live2D_WaitSetTime >= 0) {
        Live2D_WaitSetTime--;
    }
}
let _BefWaitMotionName = "";
Game_Interpreter.prototype.BtlLive2DParamSet_State = function () {
    if (this.IsPlayerメタル化()) return; 
    if (BtlRomashaFlg) {
        let modelName = MdlRomashaBattle; 
        var setWaitMotionName = "batalle_bless";
        WaitSetPs = "right";
        WaitZureX = 0;
        WaitZureY = 0;
        let _ck優先度 = 0;
        for (let i = 0; i <= En_StCardArr.length - 1; i++) {
            if (_PLステート確認(En_StCardArr[i]._StNo) && _ck優先度 < En_StCardArr[i]._St優先度) {
                _ck優先度 = En_StCardArr[i]._St優先度;
                modelName = En_StCardArr[i]._Model;
                setWaitMotionName = En_StCardArr[i]._Motion;
                WaitSetPs = En_StCardArr[i]._SetPs;
                WaitZureX = En_StCardArr[i]._ZureX;
                WaitZureY = En_StCardArr[i]._ZureY;
            }
        }
        if (NPlayer[0]._hp <= NPlayer[0].mhp * 0.3 && modelName == MdlRomashaBattle) {
            if (_ck優先度 <= 5) setWaitMotionName = "battale_damagebless"; 
        }
        HandStateCng();
        Live2DParamSetCmnEventStart(modelName); 
        BtlLive2DModelIn(modelName); 
        L2D_ParamSet(MdlRomashaBattle, "BattleSize", 30); 
        Live2D_WaitSetTime = 1;
        if (WaitMotionName != setWaitMotionName) {
            let nowPlayAnime = PlayL2DAnimeName(MdlRomashaBattle , 0);
            if (nowPlayAnime != "battale_bottomdamage" && nowPlayAnime != "battale_topdamage") {
                WaitMotionName = setWaitMotionName;
                L2dIdleStartSoku(modelName,WaitMotionName);
            }
        }
        _BefWaitMotionName = WaitMotionName;
    }
}
let BtlLive2DModelIn_MdlNameArr =
    [MdlRomashaBattle , "romasha_battleback" , "romasha_kick" , "romasha_kusuguri"];
let BtlLive2DModelIn = function (modelName) {
    L2dTop(modelName); 
    if (modelName == WaitMdlName) {
        if (_BefWaitMotionName != WaitMotionName) { 
            L2dIdleStart(WaitMdlName, WaitMotionName);
        }
        return;
    }
    WaitMdlName = modelName;
    if (BtlLive2DModelIn_MdlNameArr.indexOf(WaitMdlName) == -1)
        BtlLive2DModelIn_MdlNameArr.push(WaitMdlName);
    for (let i = 0; i < BtlLive2DModelIn_MdlNameArr.length; i++) {
        BtlLive2DInOutEasy(BtlLive2DModelIn_MdlNameArr[i], WaitSetPs);
    }
}
let BtlLive2DInOutEasy = function (_CkMdlName, _PosStr) {
    _PosStr = typeof _PosStr !== 'undefined' ? _PosStr : "right";
    if (_CkMdlName == WaitMdlName) {
        L2dFadeMdl(_CkMdlName, _PosStr + "in", 15, WaitMotionName, 1, 1, WaitZureX, WaitZureY);
        L2dIdleStart(_CkMdlName, WaitMotionName);
    } else {
        L2dAutoFadeOut(_CkMdlName, 15);
    }
}
Game_Interpreter.prototype.BtlLive2DWaitMdlFadeIn = function () {
    L2dFadeMdl(WaitMdlName, WaitSetPs + "in", 15, "", 1, 1, WaitZureX, WaitZureY);
    L2dIdleStart(WaitMdlName, WaitMotionName);
    L2dTop(WaitMdlName);
    L2D_ParamSet(MdlRomashaBattle, "BattleSize", 30);
}
Game_Interpreter.prototype.BtlLive2Dパラメーター更新 = function () {
    Live2DParamSetCmnEventStart(WaitMdlName);
}
let Live2D_PLTurnSetUpEnd = Game_Interpreter.prototype.PlayerTurnSetup_End;
Game_Interpreter.prototype.PlayerTurnSetup_End = function () {
    Live2D_PLTurnSetUpEnd.call(this);
    this.BtlLive2DParamSet_HandCard();
}
Game_Interpreter.prototype.BtlLive2DParamSet_HandCard = function () {
    _手札ステート付与();
    this.BtlLive2DParamSet_State();
}
let CardUsing_EffEnd_Live2DBackFlg = false; 
Game_Interpreter.prototype.BtlLive2DSet_CardEffectEnd = function () {
    L2dTalkTopAll();
    if (!(UseCard == null || UseCard.CardData == null)) {
        if (BtlRomashaFlg) {
            let L2DCardMtnStr = MetaChecker(UseCard.CardData, "L2DMtn", "");
            let cngMdlName = MdlRomashaBattle;
            if (L2DCardMtnStr != "" || CardUsing_EffEnd_Live2DBackFlg) {
                switch (L2DCardMtnStr) {
                    case L2DCardMtn.L2DSlash:
                        cngMdlName = "romasha_battleback";
                        if (MdlRomashaBattle == "romasha_battale2") cngMdlName = "romasha_battleback2";
                        L2dAutoFadeOut(cngMdlName, 15);
                        break;
                    case L2DCardMtn.L2DKick:
                        cngMdlName = "romasha_kick";
                        if (MdlRomashaBattle == "romasha_battale2") cngMdlName = "romasha_kick2";
                        L2dAutoFadeOut(cngMdlName, 15);
                        break;
                }
                if (cngMdlName != WaitMdlName) {
                    L2dFadeMdl(WaitMdlName, WaitSetPs + "in", 15, "", 1, 1, WaitZureX, WaitZureY);
                }
                L2dIdleStart(WaitMdlName, WaitMotionName);
                L2dTop(WaitMdlName);
                L2D_ParamSet(MdlRomashaBattle, "BattleSize", 30);
                CardUsing_EffEnd_Live2DBackFlg = false;
            }
        }
    }
    if (BtlRomashaFlg) { 
        this.BtlLive2DState解除CmnEvent();
    }
}
const CN_EnSt解除 = 431;
let BtlLive2DState解除NoArr = []; 
Game_Interpreter.prototype.BtlLive2DState解除CmnEvent = function () {
    BtlLive2DState解除NoArr = [];
    for (let i = 0; i <= En_StCardArr.length - 1; i++) {
        if (!_PLステート確認(En_StCardArr[i]._StNo)) continue;
        let _CkCardArr = En_StCardArr[i]._CardNoArr;
        let _解除Flg = true;
        switch (En_StCardArr[i]._St条件) {
            case En_St条件._デッキ:
                for (let j = 0; j <= _CkCardArr.length - 1; j++) {
                    if (_デッキカード存在確認(_CkCardArr[j]) > 0) _解除Flg = false;
                }
                if (_解除Flg)
                    BtlLive2DState解除NoArr.push(En_StCardArr[i]._StNo);
                break;
            case En_St条件._手札:
                for (let j = 0; j <= _CkCardArr.length - 1; j++) {
                    if (_手札カード存在確認(_CkCardArr[j]) > 0) _解除Flg = false;
                }
                if (_解除Flg)
                    BtlLive2DState解除NoArr.push(En_StCardArr[i]._StNo);
                break;
        }
    }
    this.SetCmnEvent(CN_EnSt解除);
}
let BtliLive2DState解除Check = function (stateNo) {
    return (BtlLive2DState解除NoArr.indexOf(stateNo) != -1)
}
let EnSt_DeckCk = function (stateNo) { 
    for (let i = 0; i <= En_StCardArr.length - 1; i++) {
        if (En_StCardArr[i]._StNo != stateNo) continue;
        let _CkCardArr = En_StCardArr[i]._CardNoArr;
        for (let j = 0; j <= _CkCardArr.length - 1; j++) {
            if (_デッキカード存在確認(_CkCardArr[j]) > 0) return true;
        }
    }
    return false;
}
let _絶頂処理 = Game_Interpreter.prototype.NUpdateSc;
Game_Interpreter.prototype.NUpdateSc = function () {
    _絶頂処理.call(this);
    if (!OtherStopFlg && $gameVariables._data[VN_Seikan] == 100) {
        OtherStopFlg = true; 
        Btl_絶頂時処理_flame = 0;
        this.SetCmnEventSc(BtlStatic.CN_絶頂); 
    }
}
const CId_オーガズム = 199;
let Btl_絶頂時処理_flame = 0;
let Btl_オーガズムドロー枚数 = 4;
let Btl_絶頂ドロー枚数 = 0;
Game_Interpreter.prototype.Btl_絶頂時処理_Update = function () {
    if (Btl_絶頂時処理_flame == 0) { 
        Btl_絶頂ドロー枚数 = 0;
        this.AllCardTrash(); 
        this.AllCardTrash_Move();
    }
    if (Btl_絶頂時処理_flame == 7) {
        if (Btl_絶頂ドロー枚数 < Btl_オーガズムドロー枚数) {
            this.CardDrawSetting(CId_オーガズム, 500, 300);
            this.CardDrawMove();
            BtlDeck.push(CId_オーガズム);
            Btl_絶頂ドロー枚数++;
            Btl_絶頂時処理_flame = 1;
            return true;
        }
        _手札ステート付与();
        this.BtlLive2DParamSet_State();
        if (WaitMdlName == MdlRomashaBattle) L2dSetMotion(MdlRomashaBattle, "battale_damagebless");
        return false; 
    }
    Btl_絶頂時処理_flame++;
    return true;
}
