let WinSetFlg = false;  
let LoseSetFlg = false; 
let BtlEscapeFlg = false; 
let set_branch = -1; 
let EnBtlBranch = { 
    Win: 0,
    Esc: 1,
    Lose: 2
};
let Nupu_BtlEndUpdate = Game_Interpreter.prototype.NUpdate;
Game_Interpreter.prototype.NUpdate = function () {
    Nupu_BtlEndUpdate.call(this);
    if (GainWaitFlg) {
        this.BtlEndGainItem(); 
        GainWaitFlg = false;
        _BefGold = -1;
        this.MapGoldUpdate(); 
    }
}
let Syasei撃破Flg = false;
Game_Interpreter.prototype.command301_BattleEnd = function () {
    $gameSwitches.setValue(SW_射精撃破, Syasei撃破Flg);
    if (Syasei撃破Flg) Syasei撃破Flg = false;
    $gameSwitches.setValue(551, false); 
    this.BtlKeepLoad(); 
    this.ReturnSprite(BtlSaveSprite); 
    this._branch[this._indent] = set_branch;
    _Reset_AnalogMove(); 
    $gameSwitches.setValue(SW_BtlEndAccessFlg, BtlEndAccessFlg);
    $gameSwitches.setValue(SW_RobuON , BtnEndローブKeep);
    //     $gameParty.loseItem($dataItems[ckNo], 1);
    // });
    if ($gameSystem.SetAdSys == undefined) $gameSystem.SetAdSys = [];
    for (let i = 0; i <= $gameSystem.SetAdSys.length - 1; i++) {
        if ($gameSystem.SetAdSys[i] == -1) continue;
        let ckCount = $gameParty.numItems($dataItems[$gameSystem.SetAdSys[i]]);
        if (ckCount <= 0) {
            $gameSystem.SetAdSys[i] = -1; 
        }
    }
    if ($gameSwitches.value(SW_リザルト無し)) {
        this.MovePict(PN_NPicFlash , true , true , 10 , 0);
    }
}
let GainWaitFlg = false;
Game_Interpreter.prototype.command601 = function () {
    this.BattleEnd(); 
    if (this._branch[this._indent] !== 0) { 
        this.skipBranch();
    }
    GainWaitFlg = true; 
    return true;
};
Game_Interpreter.prototype.command603 = function () {
    //this.BattleEnd(); //戦闘終了 ↑の勝った時で一度処理を流しているのでスキップ
    if (this._branch[this._indent] !== 2) { 
        this.skipBranch();
    }
    if ($gameSwitches.value(BtlStatic.SW_終了後HP回復)) {
        $gameActors._data[1]._hp = $gameActors._data[1].mhp; 
    } else {
        $gameActors._data[1]._hp = NPlayer[0]._hp; 
    }
    return true;
};
let 戦闘勝利Flg = false;
Game_Interpreter.prototype.BattleEnd = function () { 
    battleflg = false;
    this.SetCmnEvent(BtlStatic.CN_戦闘終了演出);
    switch (set_branch) {
        case 0:
            戦闘勝利Flg = true;
            break;
        case 1:
            戦闘勝利Flg = false;
            break;
    }
    set_branch = -1; 
}
Game_Interpreter.prototype.Battle強制End = function () { 
    battleflg = false;
    this.DelPictSpan(PN_Character, PN_Character + 4); 
    this.DelPictSpan(PN_CharacterPL, PN_CharacterPL + 4); 
    btlWaitFlame = 0;
}
let EndBtlリザルト無しWhiteOutFlame = 0;
Game_Interpreter.prototype.ChangePhase_EndBtl = function () {
    BtlData.Mode = EnBtlMode.End;
    EndBtlFlame = 0;
    EndBtlリザルト無しWhiteOutFlame = 0;
    DropitemCount = 0;
    this.DelPictSpan(PN_ECard , PN_ECard + 4); 
    this.DelSpriteSpan(PN_T_Setu , PN_Setu_End - 1); 
    this.DelSprite(PN_Setu_End - 1); 
    if ($gameSwitches.value(SW_リザルト無し)) {
        EndBtlリザルト無しWhiteOutFlame = 50;
        return;
    } else {
        this.BtlLive2DSet_CardEffectEnd(); 
        this.DelPictSpan(PN_Card, PN_CHikari); 
        if (bラスボス撃破) {
            BgmLoadSkipFlg = true;
            $gameSwitches.setValue(BtlStatic.SW_BGMCng , true); 
            this.SetPict(PN_NPicFlash, "White", 0, 0 , 0);
            return;
        }
    }
    if (WinSetFlg) {
        if (!WinBgmSkipFlg && !$gameSwitches.value(BtlStatic.SW_BGMCng)) { 
            this.PlayBgm(WinBgm);
        }
    }
    if (BtlEscapeFlg) {
        if (!RD_BtlFlg) AudioManager.fadeOutBgm(1); 
    }
    if (LoseSetFlg) {
        if (!LoseSkipFlg) {
            AudioManager.stopBgm();
        }
    }
    戦闘勝利Flg = WinSetFlg;
}
let EndBtlFlame = 0; 
const EndBtlFirstSetFlame = 30; 
let DropitemCount = 0;
let DropItem_i = 0; 
let BtlEndGetItemArr;  
let BtlEndGetGold;   
let CanBtlEndFlg = false;
let DropItem = [];
let iラスボスEndFlame = 180 + 120;
const StNo_酩酊 = 114;
Game_Interpreter.prototype.BtlEnd_Update = function () {
    if (EndBtlリザルト無しWhiteOutFlame > 0) {
        EndBtlリザルト無しWhiteOutFlame--;
        if (EndBtlリザルト無しWhiteOutFlame == 0) {
            this.SetPict(PN_NPicFlash, "White", 0, 0 , 0);
            this.BtlLive2DSet_CardEffectEnd(); 
            this.DelPictSpan(PN_Card, PN_CHikari); 
        }
        return;
    }
    if (bラスボス撃破) {
        EndBtlFlame++;
        var flash = 5;
        var tmn1G = 1;
        if (EndBtlFlame == tmn1G) {
            AudioManager.fadeOutBgm(1);
            this.PlaySe("zb_sShield1");
            this.MovePict(PN_NPicFlash , true , true , 5);
        }
        if (EndBtlFlame == tmn1G + flash) this.MovePict(PN_NPicFlash , true , true , 5 , 0);
        tmn1G = 60;
        if (EndBtlFlame == tmn1G) {
            this.PlaySe("zb_sShield1");
            this.MovePict(PN_NPicFlash , true , true , 5);
        }
        if (EndBtlFlame == tmn1G + flash) this.MovePict(PN_NPicFlash , true , true , 5 , 0);
        tmn1G = 120;
        if (EndBtlFlame == tmn1G) {
            this.PlaySe("zb_sShield1");
            this.MovePict(PN_NPicFlash , true , true , 5);
        }
        if (EndBtlFlame == tmn1G + flash) this.MovePict(PN_NPicFlash , true , true , 5 , 0);
        tmn1G = 180;
        if (EndBtlFlame == tmn1G) {
            this.PlaySe("Monster8");
            this.MovePict(PN_NPicFlash , true , true , 120);
        }
        if (EndBtlFlame == iラスボスEndFlame) {
            this.InstantLoad(); 
            BtlWinLoseBgmReset(); 
            _BtlL2DCngFlg = false;
        }
        return;
    }
    if ($gameSwitches.value(SW_リザルト無し)) {
        if (EndBtlFlame == 0) this.MovePict(PN_NPicFlash , true , true , 30);
        EndBtlFlame = EndBtlFirstSetFlame;
    }
    Alpha0SpriteSpan(PN_TurnC_Back, PN_TurnC);
    if (EndBtlFlame == EndBtlFirstSetFlame && !BtlEscapeFlg) {
        BLog = []; 
        for (let i = 0; i <= 5; i++) {
            this.DelPict(PN_LogBK + i * 2);
            this.DelPict(PN_LogBK + i * 2 + 1);
        }
        this.SetSprite(PN_BackPLW, BtlPicPath + "PN_BackPLW", 0, 0, 0);
        this.MoveSprite(PN_BackPLW, 0, 0, 15, 255);
        if (WinSetFlg) {
            if (BtlRomashaFlg) { 
                L2dFadeMdl(MdlRomashaBattle, "rightin", 15, "");
                if (Syasei撃破Flg) {
                    if ($gameActors.actor(1).isStateAffected(StNo_酩酊)) {
                        L2dIdleStart(MdlRomashaBattle, "batalle_wait");
                        L2dSetMotion(MdlRomashaBattle, "battale_victory");
                    }
                    else {
                        L2dSetMotion(MdlRomashaBattle, "batalle_wait2");
                        L2dSetMotion(MdlRomashaBattle, "battale_victory2");
                    }
                } else {
                    L2dIdleStart(MdlRomashaBattle, "batalle_wait");
                    L2dSetMotion(MdlRomashaBattle, "battale_victory");
                }
                L2dAutoFadeOut("romasha_battleback", 15);
                L2dAutoFadeOut("romasha_kusuguri", 15);
                L2dAutoFadeOut("romasha_kick", 15);
                let voiceChara = "romasha";
                let winVoices = ["btl_406_otuka","btl_407_kati","btl_408_sennt"];
                let playerVoiceFlg = true;
                for (let i = 1; i < NPlayer.length; i++) {
                    if (NPlayer[i]._hp <= 0) continue;
                    var enemyData = $dataEnemies[NPlayer[i]._enemyId];
                    let winAnime = MetaChecker(enemyData , "SpineWin" , false);
                    if (winAnime != false) {
                        this.SetSpineAnime(PN_CharacterPL + NPlayer[i]._PicNo, "Win", false);
                    }
                    if (btl味方VoiceData.isVoice) playerVoiceFlg = Math.random() < 0.3;
                    if (playerVoiceFlg) {
                        let spinaFlg = MetaChecker(enemyData , "スピナ" , false);
                        let diadFlg = MetaChecker(enemyData , "ディアド" , false);
                        if (spinaFlg) { 
                            voiceChara = "romasha";
                            winVoices = ["btl_412_supin","btl_413_ariga","btl_414_supin"];
                        } else {
                            if (!diadFlg) {
                                voiceChara = "romasha";
                                winVoices = ["btl_410_watas","btl_411_watas"];
                            }
                        }
                    } else {
                        voiceChara = btl味方VoiceData.charaName;
                        winVoices = btl味方VoiceData.WinVoice;
                    }
                }
                if (NPlayer[0]._hp <= 0) NPlayer[0]._hp = 1;
                if (NPlayer[0]._hp < NPlayer[0].mhp * 0.3 && playerVoiceFlg) {
                    voiceChara = "romasha";
                    winVoices = ["btl_409_nannt"]; 
                }
                if ($gameSwitches.value(SW_ゴブリンパート)) {
                    voiceChara = "romasha";
                    winVoices = ["h1_447_haha"];
                }
                if (!$gameSwitches.value(SW_リザルト無し)) {
                    this.PRandVoice(voiceChara , winVoices);
                }
            }
            this.BasePLMove(); 
            if (!this.IsPlayerメタル化()) this.SetSpineAnime(PN_CharacterPL, "Win", false);
            this.SetSpriteC(PN_WinBack, BtlPicPath + "PN_WinBack", 347, 386, 0);
            this.SetSpriteC(PN_Win, BtlPicPath + "PN_Win", 347, 240, 0);
        }
        if (LoseSetFlg) {
            this.SetSpriteC(PN_Win, BtlPicPath + "PN_Lose", 379, 301, 0);
        }
        CanBtlEndFlg = false;
    }
    if ($gameSwitches.value(SW_リザルト無し)) {
        EndBtlFlame = 101;
    }
    if (WinSetFlg) {
        this.Btl_WinUpdate();
    }
    if (LoseSetFlg) {
        this.Btl_LoseUpdate();
    }
    if (BtlEscapeFlg) {
        this.Btl_EscapeUpdate();
    }
    if (EndBtlFlame > 100) {
        RDBtlSettingData.BtlEndReset(); 
        if (BtlEscapeFlg) {
            WinSetFlg = true;
            this.BattleClose(true);
        }
        if (WinSetFlg) { 
            let itemDrawFlg = false;
            for (let i = 0; i < Btl_WinDrawItemIDs.length; i++) {
                let PicNo = Btl_WinDrawItemIDs[i].PicNo;
                let PosX = Btl_WinDrawItemIDs[i].PosX;
                let PosY = Btl_WinDrawItemIDs[i].PosY;
                if (overPointerSpCk(PicNo)) {
                    itemDrawFlg = true;
                    let ItemData = $dataItems[Btl_WinDrawItemIDs[i].ItemID];
                    let ItemSetuStr = ItemData.description;
                    this.SetPict(PN_ItemSetuWin, BtlPicPath + "BCard_SetuWin", PosX, PosY - 112);
                    this.SetPicStr(PN_ItemSetuTxt, ItemSetuStr, 19, PosX + 15, PosY + 14 - 112);
                }
            }
            if (!itemDrawFlg) this.DelPictSpan(PN_ItemSetuWin , PN_ItemSetuTxt);
        }
        let nextFlg = (TouchInput.isTriggered() || BtlReTryEndFlg) && CanBtlEndFlg;
        if ($gameSwitches.value(SW_リザルト無し)) nextFlg = true;
        if (nextFlg) {
            BtlReTryEndFlg = false;
            BtlEndLive2D_FadeOut();
            if (WinSetFlg) this.BattleClose(true);
            if (LoseSetFlg) this.BattleClose(false);
        }
    }
    EndBtlFlame++;
}
class DropItemData {
    constructor(_No) {
        this._No = _No; 
        this._Cnt = 1;  
    }
}
Game_Interpreter.prototype.Btl_EscapeUpdate = function () {
}
let BtlEndLive2D_FadeOut = function () {
    L2dAutoFadeOut("romasha_kick", 15);
    L2dAutoFadeOut("romasha_chichimomi", 15);
    L2dAutoFadeOut("romasha_battleback", 15);
    L2dAutoFadeOut("romasha_massaging_ass", 15);
}
let Btl_WinDrawItemIDs = [];
class BtlDrawItemData {
    constructor(PicNo , ItemID , PosX , PosY){
        this.PicNo = PicNo;
        this.ItemID = ItemID;
        this.PosX = PosX;
        this.PosY = PosY;
    }
}
Game_Interpreter.prototype.Btl_WinUpdate = function () {
    if (EndBtlFlame == 0) {
        Btl_WinDrawItemIDs = [];
        BtlEndGetItemArr = $gameTroop.makeDropItems();
        BtlEndGetGold = $gameTroop.goldTotal();
        BtlEndGetGold = Math.floor(BtlEndGetGold * BtlData.EndGetGold倍率);
        RD_戦闘取得Gold += BtlEndGetGold;
        DropitemCount = 0;
        DropItem_i = 0;
        DropItem = [];
        for (let i = 0; i <= BtlEndGetItemArr.length - 1; i++) {
            let newFlg = true;
            for (let j = 0; j <= DropItem.length - 1; j++) {
                if (DropItem[j]._No == BtlEndGetItemArr[i].id) {
                    DropItem[j]._Cnt++;
                    newFlg = false;
                    break;
                }
            }
            if (newFlg) {
                DropItem.push(new DropItemData(BtlEndGetItemArr[i].id));
            }
        }
        if (_Mikata_Hp_維持Flg) {
            for (let i = 1; i <= NPlayer.length - 1; i++) {
                _Mikata_Hp[i - 1] = NPlayer[i]._hp;
            }
        }
    }
    if (EndBtlFlame == EndBtlFirstSetFlame + 12) {
        this.MoveSprite(PN_WinBack, 347, 386, 3, 255, 115, 115)
    }
    if (EndBtlFlame == EndBtlFirstSetFlame + 15) {
        this.MoveSprite(PN_WinBack, 347, 386, 15, 255)
    }
    if (EndBtlFlame == EndBtlFirstSetFlame + 27) {
        this.MoveSprite(PN_Win, 347, 240, 3, 255, 115, 115)
    }
    if (EndBtlFlame == EndBtlFirstSetFlame + 30) {
        this.MoveSprite(PN_Win, 347, 240, 15, 255)
    }
    let basePosY = 322;
    CanBtlEndFlg = true;
    if (BtlEndGetGold > 0 && DropitemCount == 0 && EndBtlFlame == EndBtlFirstSetFlame + 45) {
        let goldStr = BtlEndGetGold + "\\G";
        if (BtlData.EndGetGold倍率 != 1) goldStr += " （" + BtlData.EndGetGold倍率 + "倍）";
        this.SpriteStr(PN_ItemTxt + DropitemCount, SCol.Yel + goldStr,
            24, 158, basePosY + (DropitemCount * 51), 0);
        this.MoveSprite(PN_ItemTxt + DropitemCount, true, true, 15);
        DropitemCount++;
    }
    if (EndBtlFlame == EndBtlFirstSetFlame + 45 && DropItem_i <= DropItem.length - 1) {
        this.PlayAnime(BtlStatic.ANo_ItemDrop, 158, basePosY + (DropItem_i * 51) - 15);
        if (DropItem[DropItem_i]._Cnt > 1) {
            this.SpriteStr(PN_ItemTxt + DropitemCount,
                "\\item[" + DropItem[DropItem_i]._No + "] × " + DropItem[DropItem_i]._Cnt,
                24, 158, basePosY + (DropitemCount * 51));
        } else {
            this.SpriteStr(PN_ItemTxt + DropitemCount,
                "\\item[" + DropItem[DropItem_i]._No + "]",
                24, 158, basePosY + (DropitemCount * 51));
        }
        Btl_WinDrawItemIDs.push(
            new BtlDrawItemData(PN_ItemTxt + DropitemCount , DropItem[DropItem_i]._No ,
                158, basePosY + (DropitemCount * 51))
        );
        EndBtlFlame -= 14;
        DropitemCount++;
        DropItem_i++;
    }
}
Game_Interpreter.prototype.Btl_LoseUpdate = function () {
    DropItem = [];
    if ($gameSystem.BtlReTryFlg == undefined) $gameSystem.BtlReTryFlg = false;
    if (EndBtlFlame == EndBtlFirstSetFlame + 12) {
        CanBtlEndFlg = true;
        this.MoveSprite(PN_Win, 379, 405, 60, 255, 100, 100);
        BtlReTryFlame = 0;
        BtlReTryEndFlg = false;
    }
    if (EndBtlFlame > 95 && $gameSystem.BtlReTryFlg) {
        if (BtlReTryFlame <= 0) {
            if (TouchInput.isPressed()) this.Btl_LoseReTryStart();
            EndBtlFlame--;
        } else {
            this.Btl_LoseReTryUpdate();
        }
    }
}
const BtlRetryPath = BtlPicPath + "ReTry/";
var BtlReTryFlame = 0;
var BtlReTryYesFlg = true;
var BtlReTryEndFlg = false;
var BtlReTryClickFlg = false;
let BtlLoseReTry_Initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function () { 
    BtlLoseReTry_Initialize.call(this);
    this.BtlReTryFlg = false; 
}
var BtlReTryCheck = function () {
    return $gameSystem.BtlReTryFlg && BtlReTryYesFlg;
}
let BtlReTryClbMap = [
    [431, 428, 260, 78],
    [431 + 290, 428, 260, 78]
];
Game_Interpreter.prototype.Btl_LoseReTryStart = function () {
    BtlReTryYesFlg = true;
    this.SetSpriteFIn(PN_ReTryBack, BtlRetryPath + "PN_ReTryBack", 0, 0, 0, 0, 30);
    this.SetSpriteFIn(PN_ReTryYesNo, BtlRetryPath + "PN_ReTryYes", 0, 0, 0, 0, 30);
    BtlReTryFlame = 1; 
}
Game_Interpreter.prototype.Btl_LoseReTryUpdate = function () {
    BtlReTryFlame++;
    if (BtlReTryFlame > 30 && !BtlReTryEndFlg) {
        let _cmbNo = overSpriteClickable( PN_ReTryBack , BtlReTryClbMap);
        var okFlg = false;
        okFlg = _cmbNo != -1 && TouchInput.isPressed();
        if (Input.isPressed('ok') || okFlg) {
            this.MoveSprite(PN_ReTryBack, true, true, 60, 0);
            this.MoveSprite(PN_ReTryYesNo, true, true, 60, 0);
            BtlReTryEndFlg = true; 
        }
        if (Input.isPressed('left') || _cmbNo == 0) {
            BtlReTryYesFlg = true;
            this.SetSprite(PN_ReTryYesNo, BtlRetryPath + "PN_ReTryYes", 0, 0);
        }
        if (Input.isPressed('right') || _cmbNo == 1) {
            BtlReTryYesFlg = false;
            this.SetSprite(PN_ReTryYesNo, BtlRetryPath + "PN_ReTryNo", 0, 0);
        }
    }
    if (!BtlReTryEndFlg) EndBtlFlame--; 
}
//※敵は全て倒した物とする makeDropItems()
Game_BattlerBase.prototype.isDead = function () {
    return true;
};
Game_Interpreter.prototype.BtlEndGainItem = function () {
    $gameVariables.setValue(VN_RDClearGold, 0);
    if (BtlEndGetGold != undefined) {
        $gameParty._gold += BtlEndGetGold;
        $gameVariables.setValue(VN_RDClearGold, BtlEndGetGold);
    }
    for (let i = 0; i <= DropItem.length - 1; i++) {
        $gameParty.gainItem($dataItems[DropItem[i]._No],
            DropItem[i]._Cnt);
    }
    if (!RD_Flg) {
        this.SozaiCardCng();
    }
}
Game_Interpreter.prototype.BattleEndLoad = function () {
    this.BtlKeepSave(); 
    this.InstantLoad(); 
    BtlWinLoseBgmReset(); 
}
let BtlKeepSwDatas = [];
let BtlKeepVNDatas = [];
let BtlKeepRDAdSysCT = [];
let BtlKeep一時Switchs = [];
class BtlKeep一時SwitchData {
    constructor(No){
        this.No = No;
        this.Value = $gameSwitches.value(No);
    }
}
Game_Interpreter.prototype.BtlKeepSave = function () {
    BtlKeepSwDatas = [];
    BtlKeepVNDatas = [];
    for (let i = 0; i < BtlKeepSWs.length; i++) {
        BtlKeepSwDatas.push($gameSwitches.value(BtlKeepSWs[i]));
    }
    for (let i = 0; i < BtlKeepVNs.length; i++) {
        BtlKeepVNDatas.push($gameVariables.value(BtlKeepVNs[i]));
    }
    if (RD_Flg) {
        BtlKeepRDAdSysCT = [];
        for (let i = 0; i < $gameSystem.AdSysCT.length; i++) {
            BtlKeepRDAdSysCT.push($gameSystem.AdSysCT[i]);
            $gameSystem.AdSysCT[i].ct--; 
            if ($gameSystem.AdSysCT <= 0) {
                $gameSystem.AdSysCT.splice(i , 1); i--;
            }
        }
        BtlKeep一時Switchs.push(new BtlKeep一時SwitchData(SW_BtlGrbOFF));
        BtlKeep一時Switchs.push(new BtlKeep一時SwitchData(SW_BtlUdeSutuOFF));
        BtlKeep一時Switchs.push(new BtlKeep一時SwitchData(SW_BtlInnerOFF));
        BtlKeep一時Switchs.push(new BtlKeep一時SwitchData(SW_BtlBodySutuOFF));
        BtlKeep一時Switchs.push(new BtlKeep一時SwitchData(SW_BtlLegSutuOFF));
        BtlKeep一時Switchs.push(new BtlKeep一時SwitchData(SW_BtlAmKosiOFF));
        BtlKeep一時Switchs.push(new BtlKeep一時SwitchData(SW_BtlAmLegOFF));
        BtlKeep一時Switchs.push(new BtlKeep一時SwitchData(SW_BtlAmKataOFF));
        BtlKeep一時Switchs.push(new BtlKeep一時SwitchData(SW_BtlPltMuneOFF));
        BtlKeep一時Switchs.push(new BtlKeep一時SwitchData(SW_BtlAmMuneOFF));
    }
    _Fz変数保存 = [];
    for (let i = VN_Fz保存変数; i <= VN_Fz保存変数Max; i++) {
        _Fz変数保存.push(new FzVNData(i));
    }
    for (let i = 0; i < Fz_戻しVNNos.length; i++) {
        _Fz変数保存.push(new FzVNData(Fz_戻しVNNos[i]));
    }
    _Fzスイッチ保存 = [];
    for (let i = 0; i < Fz_戻しSWNos.length; i++) {
        _Fzスイッチ保存.push(new FzSNData(Fz_戻しSWNos[i]));
    }
}
Game_Interpreter.prototype.BtlKeepLoad = function () {
    if (BtlKeepSwDatas.length == 0) return;
    if (BtlKeepVNDatas.length == 0) return;
    for (let i = 0; i < BtlKeepSWs.length; i++) {
        $gameSwitches.setValue(BtlKeepSWs[i] , BtlKeepSwDatas[i]);
    }
    for (let i = 0; i < BtlKeepVNs.length; i++) {
        $gameVariables.setValue(BtlKeepVNs[i] ,BtlKeepVNDatas[i]);
    }
    for (let i = 0; i < _Fzスイッチ保存.length; i++) {
        $gameSwitches.setValue(_Fzスイッチ保存[i].SWNo , _Fzスイッチ保存[i].Value);
    }
    for (let i = 0; i < _Fz変数保存.length; i++) {
        $gameVariables.setValue(_Fz変数保存[i].VNNo ,_Fz変数保存[i].Value);
    }
    BtlKeepSwDatas = [];
    BtlKeepVNDatas = [];
    for (let i = 0; i < BtlKeep一時Switchs.length; i++) {
        $gameSwitches.setValue(BtlKeep一時Switchs[i].No , BtlKeep一時Switchs[i].Value);
    }
    BtlKeep一時Switchs = [];
}
let BtlEndAccessFlg = false;
let BtnEndローブKeep = false;
Game_Interpreter.prototype.BattleClose = function (winflg) {
    winflg = typeof winflg !== 'undefined' ? winflg : true;
    if (winflg) {
        set_branch = EnBtlBranch.Win;
    } else {
        set_branch = EnBtlBranch.Lose;
    }
    HajiFlg = false; 
    NPlayer[0]._BtlBit = [];
    BtlEndAccessFlg = AccessFlg;
    BtnEndローブKeep = $gameSwitches.value(SW_RobuON);
    AccessFlg = false; 
    this.setupChild($dataCommonEvents[BtlStatic.CN_戦闘終了後].list, 0); 
    N_Sprite_MNo = 0;
    N_Sprite_TNo = 130; 
    BtlDeck_HandiDel();
}
let BtlDeck_HandiDel = function () {
    for (let i = 0; i <= $gameSystem.HandiSaveArr.length - 1; i++) {
        let ckNo = BtlDeck.indexOf($gameSystem.HandiSaveArr[i]);
        if (ckNo != -1) {
            BtlDeck.splice(ckNo, 1);
        }
    }
}
