/* ■RDスタート処理■■■■■■■■■■■■■■■■■■■■■■■■ */
let RD_Id = -1;
let RD_休憩撤退Flg = false;
let RD_LeftStartFlg = false;
let RD_MikataSetup = false;
let RD_戦闘取得Gold = 0;
let RD_NoReDrawFlg = false; 
Game_Interpreter.prototype.RD_Start = function (_RdId) {
    NPlayer = []; 
    N_Sprite_DLayer = 0;
    EasingStr = ""; 
    RD_NowDungeonEcNo = []; 
    Bef_RD_SetAdSys = [];
    rdEndFlg = false; 
    RD_救助人数 = 0; 
    $gameVariables.setValue(VN_次戦闘敵No ,0); 
    let b階層Flg = false;
    if ($gameVariables.value(VN_RdKaiso) > 0) b階層Flg = true;
    if ($gameSystem.RD_FstKoudo == undefined) $gameSystem.RD_FstKoudo = 5;
    this.DelPictSpan(PN_LoadBase + 0 , PN_dpBar);
    this.DelPictSpan(PN_MobB + 0, PN_MobT + 5);
    this.DelSpriteSpan(PN_MobB + 0, PN_MobT + 5);
    this.RD_相棒設定反映();
    if (!b階層Flg) {
        RD_Keep_NPlayer = null; 
    }
    if (BtlRomashaFlg) { 
        this.PreLoadArr(RDPreLoadImgs);
        $gameSystem.Btl_Chara = null; 
        this.Btl_Romasha_SetUp(b階層Flg); 
    }
    this.DelSpriteSpan(PN_Reric , PN_Reric + 9);
    this.DelSpriteSpan(PN_BReric , PN_BReric + 5);
    if (!b階層Flg) {
        RD_戦闘取得Gold = 0;
        RD_EvStop = false;
        RD_MikataSetup = false;
        RD_休憩撤退Flg = false;
        RD無限マリガンCount = 0; 
        RD_ReloadCnt = 0;
        RD_Id = _RdId;
        $gameActors.actor(1).setHp($gameActors.actor(1).mhp);
        $gameVariables.setValue(VN_ThRitu, 0); 
        RDBtlSettingData = new RDBtlSettingClass(); 
    }
    SelRndRoot = null; 
    RD_BtlWinFlg = false;
    RD_Flg = true;  
    RD_Stop = false;
    this.SetCmnEvent(CN_RdStart); 
    this.RD_WalkImgSetting();
    this.PreLoadArr(BtlPrePic);
    if (!b階層Flg) {
        RD_ClearArr = []; 
        RD_GainGold = 0;
        RD_GainItem = []; 
        BtlKeepRDAdSysCT = [];
        $gameVariables.setValue(VN_BossBrk, 0); 
        $gameVariables.setValue(VN_EmBrk, 0);   
        $gameVariables.setValue(VN_GetFotn, 0); 
        for (let i = 0; i <= 2; i++) {
            $gameVariables.setValue(VN_rdSyori + i, 0); 
        }
    } else {
        this.RD_GainItem描画();
        this.SetSpriteC(PN_rdOpeWin, RdnPicPath + "Ope/OpeWin", 906, 41, 255);
        if ($gameSystem.Btl_Chara.Name != "spina_talk") {
            $gameSystem.Btl_Chara.FDeck = CopyArr(RD階層KeepFDeck); 
        }
    }
    RD_LoseEndFlg = false;
    WinSetFlg = false;
    LoseSetFlg = false; 
    RD_DMapArr = []; 
    $gameSystem.RD_LineX = 0;
    $gameSystem.RD_LineY = 100;
    _RdPlX = 0;
    _RdPlY = 2;
    RD_ClearMode = EnRDClearMode.On;
    RD_BadStCardAdds = [];
    this.RD_PLStart_Cng(); 
    $gameSystem.RD_HandCard = [];
    MenuModeStr = _MMode.RdDungeon;
    this.MapEnd(); 
    $gameSystem.disableMenu(); 
    if ($gameMap.mapId() != RdnMapId) {
        $gameSystem.RD_BackMapData = new RD_MapPosSave(
            $gameMap.mapId(), $gamePlayer.x, $gamePlayer.y, $gamePlayer._direction
        );
        $gamePlayer.reserveTransfer(RdnMapId, 0, 0, 2, 0);
    }
    if (!b階層Flg) {
        this.RD_MoveDeck_Setting();
    }
    $gameSystem.RD_BaseData = RD_MasterData_Get(RD_Id); 
    RD_LeftStartFlg = $gameSystem.RD_BaseData.leftStartFlg; 
    if ($gameSystem.RD_BaseData.moveLimit == 0) $gameSystem.RD_BaseData.moveLimit = 5;
    if ($gameSystem.RD_BaseData.moveLimit == -1) {
        $gameSystem.RD_BaseData.moveLimit = 99; 
    }
    RD_Koudo = $gameSystem.RD_BaseData.moveLimit;
    if ($gameVariables.value(VN_RdKaiso) != 0) {
        RD_KaisoData_Get(RD_Id);
    }
    RD_ClearGold = $gameSystem.RD_BaseData.hosyuGold;
    RD_NoReDrawFlg = $gameSystem.RD_BaseData.noReDrawFlg; 
    var kaisoData = $gameSystem.RD_BaseData.kaisoDatas[$gameVariables.value(VN_RdKaiso)];
    var _LineData = kaisoData.rowDatas.slice(0, kaisoData.rowDatas.length);
    $gameSystem.RD_Map = []; 
    if (kaisoData.loopFlg) {
        for (let i = 0; i <= 50 - 1; i++) {
            for (let j = kaisoData.loopRowNo; j <= kaisoData.rowDatas.length - 1; j++) {
                var rowData = kaisoData.rowDatas[j];
                _LineData.push(rowData);
            }
        }
    }
    for (let i = 0; i <= _LineData.length - 1; i++) {
        for (let j = 0; j <= _LineData[i].massList.length - 1; j++) {
            _LineData[i].massList[j].KankakuCnt = _LineData[i].massList[j].putData.kankakuZure;
        }
        let _LCnt = 0;
        let _SetLine = [];
        while (_LCnt < 200) { 
            let addFlg = false;
            for (let j = 0; j <= _LineData[i].massList.length - 1; j++) {
                var massData = _LineData[i].massList[j];
                switch (massData.putData.type) {
                    case "ライン":
                        _SetLine.push(massData);
                        addFlg = true;
                        break;
                    case "間隔":
                        if (_LineData[i].massList[j] != null) {
                            if (_LineData[i].massList[j].putData.kankaku <= _LineData[i].massList[j].KankakuCnt) {
                                _SetLine.push(massData);
                                addFlg = true;
                                _LineData[i].massList[j].KankakuCnt = 0;
                            }
                            _LineData[i].massList[j].KankakuCnt++;
                        }
                        break;
                    case "確率":
                        if (_LineData[i].massList[j].putData != null) {
                            let _ckPar = Math.random(); 
                            if (_LineData[i].massList[j].putData.kakuritu / 100 >= _ckPar) {
                                _SetLine.push(massData);
                                addFlg = true;
                            }
                        }
                        break;
                }
            }
            if (!addFlg) _SetLine.push(null);
            _LCnt++;
        }
        $gameSystem.RD_Map.push(_SetLine);
    }
    RD_Flame = 0;
    $gameSystem.RD_Line = 0;
    for (let j = 0; j < $gameSystem.AdSysCT.length; j++) {
        $gameSystem.AdSysCT[j].ct = 0;
    }
}
Game_Interpreter.prototype.RD_MoveDeck_Setting = function () {
    if (BtlRomashaFlg) {
        $gameTemp.reserveCommonEvent(CN_romasha_battale);
    }
    $gameSystem.RD_MoveDeck = CopyArr($gameSystem.Btl_Chara.FDeck); 
    $gameSystem.RD_MoveDeckBase = CopyArr($gameSystem.Btl_Chara.FDeck); 
    ShuffleArr($gameSystem.RD_MoveDeck);
}
Game_Interpreter.prototype.RD_PLStart_Cng = function () { 
    RD_Mode = EnRDMode.PL_Start;
    _PLStart_Flame = 0;
}
let Rd_KaisoData = 1;
let 階層上昇 = function () {
    Rd_KaisoData++;
}
let _PLStart_Flame = 0;
let _RdTPos = new Pos2D(720, 405);
Game_Interpreter.prototype.RD_PLStart_Update = function () { 
    if (_PLStart_Flame == 0) {
        Rd_KaisoData = 1;
        D_Text_Cng_font = "Makinas";
        this.SetSpriteC(PN_rdStartWin + 0, RdnPicPath + "Win_MapStart", _RdTPos._x, _RdTPos._y, 0);
        let kaisoName = $gameSystem.RD_BaseData.name + $gameSystem.RD_BaseData.kaisoDatas[$gameVariables.value(VN_RdKaiso)].kaisoName;
        this.SpriteStrC(PN_rdStartWin + 1, "\\ow[7]" + kaisoName, 100, _RdTPos._x, _RdTPos._y, 0);
        D_Text_Cng_font = "";
        $gameScreen.startFadeIn(20);
        this.EnFadeOut(); 
        this.Ensyutu_Out(); 
    }
    if (_PLStart_Flame == 20) {
        this.MoveSprite(PN_rdStartWin + 0, true, true, 30, 255);
        this.MoveSprite(PN_rdStartWin + 1, true, true, 30, 255);
    }
    let _EndTime = 120;
    if (_PLStart_Flame == _EndTime) {
        this.MoveSprite(PN_rdStartWin + 0, true, true, 15, 0);
        this.MoveSprite(PN_rdStartWin + 1, true, true, 15, 0);
        this.RD_UIView();
        this.RD_GainItem描画();
    }
    if (_PLStart_Flame == (_EndTime + 15)) {
        this.RD_PLSelect_Cng();
        this.DelPictSpan(PN_rdStartWin + 0, PN_rdStartWin + 1)
        this.DelSpriteSpan(PN_rdStartWin + 0, PN_rdStartWin + 1)
    }
    _PLStart_Flame++;
}
Game_Interpreter.prototype.RD_FirstView = function () {
    this.Set特殊暗転解除();
    this.DelSpriteSpan(PNo_Map, PNo_HintStr); 
    if (BtlStatic.Battleback1 != "") {
        this.SetSprite(PN_B_back, "battlebacks1/" + BtlStatic.Battleback1, 0, 0);
    }
    if (BtlStatic.Battleback2 != "") {
        this.SetSprite(PN_B_back + 1, "battlebacks2/" + BtlStatic.Battleback2, 0, 0);
    }
    this.RD_Live2D_Draw();
    //this.SetSprite(PN_UFuti, BtlPicPath + "PN_UFuti", 0, 0);
    this.SetSprite(PN_DFuti, BtlPicPath + "PN_DFuti", 0, 507);
    this.SetSprite(PN_rbBBack, RdnPicPath + "BackBlack", 0, 0);
    this.RD_MapLineDraw(true, 0); 
    if (RD_NoReDrawFlg != true) {
        this.SetSprite(PN_Reload, RdnPicPath + "PN_Reload", 0 - 192, 550); 
    }
    this.RD_レリックDraw();
    this.RD_MapHPDraw();
    this.SetSprite(PN_BDeckBtn, RdnPicPath + "PN_BDeckCkBtn", 0, 650, 255);
    this.SetSpriteC(PN_rdOpeWin, RdnPicPath + "Ope/OpeWin", 906, 41, 255);
    $gameSystem.MasterDeck = CopyArr($gameSystem.DeckArr[$gameSystem.SelDeck]);
    $gameSystem.MoveDeck = CopyArr($gameSystem.MasterDeck); 
}
let STY_MovePic_l = "";
let STY_MovePic_t = "";
let STY_MovePic_d = "";
let STY_MovePic_r = "";
let STY_MovePic_down = "";
Game_Interpreter.prototype.RD_WalkImgSetting = function () {
    if (BtlRomashaFlg) {
        this.RD_PC_ImgSet(); 
    } else {
        Spn_FileLoad($gameSystem.Btl_Chara.Name); 
        RD_PlImg = $gameSystem.Btl_Chara.Name;
    }
    STY_MovePic_l = "pictures/UI_Dungeon/Ev/" + $gameSystem.Btl_Chara.Name + "/" + RD_PlImg + "_l";
    STY_MovePic_t = "pictures/UI_Dungeon/Ev/" + $gameSystem.Btl_Chara.Name + "/" + RD_PlImg + "_t";
    STY_MovePic_d = "pictures/UI_Dungeon/Ev/" + $gameSystem.Btl_Chara.Name + "/" + RD_PlImg + "_d";
    STY_MovePic_r = "pictures/UI_Dungeon/Ev/" + $gameSystem.Btl_Chara.Name + "/" + RD_PlImg + "_r";
    STY_MovePic_down = "pictures/UI_Dungeon/Ev/" + $gameSystem.Btl_Chara.Name + "/" + RD_PlImg + "_down";
    this.PreLoadArr([
        STY_MovePic_l, STY_MovePic_t, STY_MovePic_d , STY_MovePic_r, STY_MovePic_down
    ]);
}
Game_Interpreter.prototype.RD_FotoniaGetEffect = function () {
    this.PlayPtcSc2Top("GetFotonia",952,700);
    this.PlayPtcSc2Top("GetFotoniaChara",1100,400);
}
