let RD_MasterData = [];
let OneClear = false;
let RD_KaisoDataArr = []; 
class RD_KaisoData {
    constructor(RDId, kaiso, name, lineDatas, bgm, loopFlg) {
        bgm = typeof bgm !== 'undefined' ? bgm : "";
        loopFlg = typeof loopFlg !== 'undefined' ? loopFlg : false;
        this._RdId = RDId;
        this._Kaiso = kaiso;
        this._Name = name;
        this._LineData = lineDatas;
        this._Bgm = bgm;    
        this._LoopFlg = loopFlg;  
    }
}
class RDDgnData {
    constructor(setData) {
        this.id = setData.id;
        this.name = setData.name;
        this.naiyoTxt = setData.naiyoTxt;
        this.naiyoTxtEx = setData.naiyoTxtEx;
        this.johoTxt = setData.johoTxt;
        this.johoTxtEx = setData.johoTxtEx;
        this.hosyuGold = setData.hosyuGold;
        this.hosyuTxt = setData.hosyuTxt;
        this.firstHosyuTxt = setData.firstHosyuTxt;
        this.clearTxt = setData.clearTxt;
        this.clearValue = setData.clearValue;
        this.areaMemo = setData.areaMemo;
        this.stageBackImg = setData.stageBackImg;
        this.bgmName = setData.bgmName;
        this.moveLimit = setData.moveLimit;
        this.mainFlg = setData.mainFlg;
        this.onePlayFlg = setData.onePlayFlg;
        this.tettaiFlg = setData.tettaiFlg;
        this.leftStartFlg = setData.leftStartFlg;
        this.dengerFlg = setData.dengerFlg;
        this.resultOffFlg = setData.resultOffFlg;
        this.noReDrawFlg = setData.noReDrawFlg;
        this.kaisoDatas = [];
        for (let i = 0; i <= setData.kaisoDatas.length - 1; i++) {
            this.kaisoDatas.push(new RDKaisoData(setData.kaisoDatas[i]));
        }
        this.talkDatas = [];
        if (setData.talkDatas == null) setData.talkDatas = [];
        for (let i = 0; i <= setData.talkDatas.length - 1; i++) {
            this.talkDatas.push(new RDTalkData(setData.talkDatas[i]));
        }
        this.talkDatasEx = [];
        if (setData.talkDatasEx == null) setData.talkDatasEx = [];
        for (let i = 0; i <= setData.talkDatasEx.length - 1; i++) {
            this.talkDatasEx.push(new RDTalkData(setData.talkDatasEx[i]));
        }
    }
}
class RDTalkData {
    constructor(setTalkData){
        this.id = setTalkData.id;
        this.name = setTalkData.name;
        this.speachDatas = [];
        for (let i = 0; i <= setTalkData.speachDatas.length - 1; i++) {
            this.speachDatas.push(new RDSpeachData(setTalkData.speachDatas[i]));
        }
        if (setTalkData.lastClearFlg == null) setTalkData.lastClearFlg = false;
        this.lastClearFlg = setTalkData.lastClearFlg;
    }
}
class RDSpeachData {
    constructor(setSpeachData){
        this.name = setSpeachData.name;
        this.image = setSpeachData.image;
        this.text = setSpeachData.text;
        this.viewFlame = setSpeachData.viewFlame;
    }
}
class RDKaisoData {
    constructor(setKaisoData) {
        this.kaisoName = setKaisoData.kaisoName;
        this.loopFlg = setKaisoData.loopFlg;
        this.loopRowNo = setKaisoData.loopRowNo;
        this.rowDatas = [];
        for (let i = 0; i <= setKaisoData.rowDatas.length - 1; i++) {
            this.rowDatas.push(new RDRowData(setKaisoData.rowDatas[i]));
        }
    }
}
class RDRowData {
    constructor(setRowData) {
        this.massList = [];
        for (let i = 0; i < setRowData.massList.length; i++) {
            this.massList.push(new RDMassData(setRowData.massList[i]));
        }
    }
}
class RDMassData {
    constructor(setMassData) {
        setMassData = typeof setMassData !== 'undefined' ? setMassData : null;
        if(setMassData == null) {
            this.type = "";
            this.id = 0;
            this.image = "";
            this.massImage = "";
            this.bossFlg = false;
            this.putData = null;
        } else {
            this.type = setMassData.type;
            this.id = setMassData.id;
            this.image = setMassData.image;
            this.massImage = setMassData.massImage;
            this.bossFlg = setMassData.bossFlg;
            this.putData = new RDPutData(setMassData.putData);
        }
    }
}
class RDPutData {
    constructor(setPutData) {
        this.type = setPutData.type;
        this.kankaku = setPutData.kankaku;
        this.kankakuZure = setPutData.kankakuZure;
        this.kakuritu = setPutData.kakuritu;
    }
}
/** @type {RDDgnData} */
let SelectRDDgnData = null;
let RD_MasterData_Get = function (_RdId) {
    for (let i = 0; i < $RDData.dgnDatas.length; i++) {
        if ($RDData.dgnDatas[i].id == _RdId) {
            SelectRDDgnData = new RDDgnData($RDData.dgnDatas[i]);
            return SelectRDDgnData;
        }
    }
}
let RD_KaisoData_Get = function (_RdId) {
    for (let i = 0; i <= RD_KaisoDataArr.length - 1; i++) {
        if (RD_KaisoDataArr[i]._RdId == _RdId) {
            if ($gameVariables.value(VN_RdKaiso) == RD_KaisoDataArr[i]._Kaiso) {
                $gameSystem.RD_BaseData._Name = RD_KaisoDataArr[i]._Name;
                $gameSystem.RD_BaseData._LineData = RD_KaisoDataArr[i]._LineData;
                if (this._Bgm != "") $gameSystem.RD_BaseData._Bgm = RD_KaisoDataArr[i]._Bgm;
                if (this._LoopFlg != "") $gameSystem.RD_BaseData._LoopFlg = RD_KaisoDataArr[i]._LoopFlg;
            }
        }
    }
}
class _RootData {
    constructor(_RtCnt, _RtNo, _RData) {
        this._RtCnt = _RtCnt;   
        this._RtNo = _RtNo;     
        this._RData = _RData;   
    }
}
let RndRootData = []; 
RndRootData.push(new _RootData(0, 1, ["l"]));
RndRootData.push(new _RootData(1, 1, ["t", "l"]));
RndRootData.push(new _RootData(1, 2, ["d", "l"]));
RndRootData.push(new _RootData(1, 3, ["l", "d"]));
RndRootData.push(new _RootData(1, 4, ["l", "t"]));
RndRootData.push(new _RootData(1, 5, ["l", "l"]));
RndRootData.push(new _RootData(2, 1, ["t", "l", "l"]));
RndRootData.push(new _RootData(2, 2, ["t", "l", "d"]));
RndRootData.push(new _RootData(2, 3, ["l", "l", "t"]));
RndRootData.push(new _RootData(2, 4, ["l", "t", "l"]));
RndRootData.push(new _RootData(2, 5, ["d", "l", "l"]));
RndRootData.push(new _RootData(2, 6, ["d", "l", "t"]));
RndRootData.push(new _RootData(2, 7, ["l", "l", "d"]));
RndRootData.push(new _RootData(2, 8, ["l", "d", "l"]));
RndRootData.push(new _RootData(3, 1, ["t", "l", "l", "d"]));
RndRootData.push(new _RootData(3, 2, ["t", "l", "d", "l"]));
RndRootData.push(new _RootData(3, 3, ["l", "t", "l", "d"]));
RndRootData.push(new _RootData(3, 4, ["d", "l", "l", "t"]));
RndRootData.push(new _RootData(3, 5, ["d", "l", "t", "l"]));
RndRootData.push(new _RootData(4, 1, ["t", "l", "d", "l", "t"]));
RndRootData.push(new _RootData(4, 2, ["d", "l", "t", "l", "d"]));
