let SaveL2DVNNos = [37 , 38];
let SaveL2DSWNos = [17,18,19,20,39,40,200,303,304,311,815,963];
for (let i = 56; i <= 71; i++) SaveL2DSWNos.push(i);
for (let i = 171; i <= 174; i++) SaveL2DSWNos.push(i);
for (let i = 351; i <= 356; i++) SaveL2DSWNos.push(i);
for (let i = 1177; i <= 1183; i++) SaveL2DSWNos.push(i);
class SaveL2DData {
    constructor(){
        this.VNDatas = []; 
        this.SWDatas = []; 
    }
}
class L2DVnSwData {
    constructor(No , Value){
        this.No = No;
        this.Value = Value;
    }
}
let RomashaL2DSave_Initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function () { 
    RomashaL2DSave_Initialize.call(this);
    this.SaveL2DData = [new SaveL2DData() , new SaveL2DData() , new SaveL2DData() , new SaveL2DData() , new SaveL2DData()];
};
Game_Interpreter.prototype.SettingSaveL2DData = function (saveL2DData) {
    for (let i = 0; i < SaveL2DSWNos.length; i++)
        saveL2DData.SWDatas.push(new L2DVnSwData(SaveL2DSWNos[i] , $gameSwitches.value(SaveL2DSWNos[i])));
    for (let i = 0; i < SaveL2DVNNos.length; i++)
        saveL2DData.VNDatas.push(new L2DVnSwData(SaveL2DVNNos[i] , $gameVariables.value(SaveL2DVNNos[i])));
}
Game_Interpreter.prototype.LoadL2DData = function (saveL2DData) {
    for (let i = 0; i < saveL2DData.SWDatas.length; i++) {
        $gameSwitches.setValue(saveL2DData.SWDatas[i].No , saveL2DData.SWDatas[i].Value);
    }
    for (let i = 0; i < saveL2DData.VNDatas.length; i++) {
        $gameVariables.setValue(saveL2DData.VNDatas[i].No , saveL2DData.VNDatas[i].Value);
    }
}
let NowSaveL2DData;
Game_Interpreter.prototype.SaveNowRomashaL2DData = function () {
    if (NowSaveL2DData == null) NowSaveL2DData = new SaveL2DData();
    var saveL2DData = NowSaveL2DData;
    saveL2DData = new SaveL2DData();
    this.SettingSaveL2DData(saveL2DData);
    NowSaveL2DData = saveL2DData;
}
Game_Interpreter.prototype.LoadNowRomashaL2DData = function () {
    this.LoadL2DData(NowSaveL2DData);
}
Game_Interpreter.prototype.SaveRomashaL2DData = function (saveNo) {
    if ($gameSystem.SaveL2DData == undefined)
        $gameSystem.SaveL2DData = [new SaveL2DData() , new SaveL2DData() , new SaveL2DData() , new SaveL2DData() , new SaveL2DData()];
    var saveL2DData = $gameSystem.SaveL2DData[saveNo];
    saveL2DData = new SaveL2DData();
    this.SettingSaveL2DData(saveL2DData);
    $gameSystem.SaveL2DData[saveNo] = saveL2DData;
}
Game_Interpreter.prototype.LoadRomashaL2DData = function (loadNo) {
    if ($gameSystem.SaveL2DData == undefined)
        $gameSystem.SaveL2DData = [new SaveL2DData() , new SaveL2DData() , new SaveL2DData() , new SaveL2DData() , new SaveL2DData()];
    this.LoadL2DData($gameSystem.SaveL2DData[loadNo]);
}
let _CkL2DBef = [
    [VN_TL2DKigae, 0],
    [VN_TL2DKami, 0],
    [SW_BuraOFF, false],
    [SW_PantuOFF, false],
    [SW_MizugiON, false],
    [SW_NemakiON, false],
    [SW_MinzokuON, false],
    [SW_BaniON, false]
];
let Nupu_Live2D_Update = Game_Interpreter.prototype.NUpdate;
Game_Interpreter.prototype.NUpdate = function () {
    Nupu_Live2D_Update.call(this);
    this.Nupu_L2DUpdate(); 
}
let _L2DCngFlame = 10;
let _BtlL2DCngFlg = false; 
Game_Interpreter.prototype.Nupu_L2DUpdate = function () {
    let _CngFlg = false;
    for (let i = 0; i <= _CkL2DBef.length - 1; i++) {
        if (typeof (_CkL2DBef[i][1]) == "number") {
            if (_CkL2DBef[i][1] != $gameVariables.value(_CkL2DBef[i][0])) {
                _CkL2DBef[i][1] = $gameVariables.value(_CkL2DBef[i][0]);
                _CngFlg = true;
            }
        } else {
            if (_CkL2DBef[i][1] != $gameSwitches.value(_CkL2DBef[i][0])) {
                _CkL2DBef[i][1] = $gameSwitches.value(_CkL2DBef[i][0]);
                _CngFlg = true;
            }
        }
    }
    if (_BtlL2DCngFlg) { 
        Live2DParamSetCmnEventStart(MdlRomashaBattle);
    }
    if (_CngFlg) {
        Live2DParamSetCmnEventStart("romasha_talk");
        _BtlL2DCngFlg = true;
    }
}
let Live2DParamSetCmnEventStart = function (MdlName) {
    switch (MdlName) {
        case "romasha_talk": //Live2DParamSetCmnEventStart("romasha_talk");
            if (MdlRomashaBattle == "romasha_battale2"){
                $gameTemp.reserveCommonEvent(CN_romasha_talk2);
                break
            }
            $gameTemp.reserveCommonEvent(CN_romasha_talk);
            break;
        case MdlRomashaBattle: //Live2DParamSetCmnEventStart(MdlRomashaBattle);
            if (MdlRomashaBattle == "romasha_battale2"){
                $gameTemp.reserveCommonEvent(CN_romasha_battale2);
                break
            }
            $gameTemp.reserveCommonEvent(CN_romasha_battale);
            break;
        case "romasha_massaging_ass":
            $gameTemp.reserveCommonEvent(CN_romasha_massaging_ass);
            break;
        case "romasha_battleback":
            $gameTemp.reserveCommonEvent(CN_romasha_battleback);
            break;
        case "romasha_kick":
            if (MdlRomashaBattle == "romasha_battale2"){
                $gameTemp.reserveCommonEvent(CN_romasha_kick2);
                break
            }
            $gameTemp.reserveCommonEvent(CN_romasha_kick);
            break;
        case "romasha_kusuguri":
            $gameTemp.reserveCommonEvent(CN_romasha_kusuguri);
            break;
    }
}
Game_Interpreter.prototype.command313 = function () {
    this.iterateActorEx(this._params[0], this._params[1], function (actor) {
        let alreadyDead = actor.isDead();
        if (this._params[2] === 0) {
            actor.addState(this._params[3]);
        } else {
            actor.removeState(this._params[3]);
        }
        if (actor.isDead() && !alreadyDead) {
            actor.performCollapse();
        }
        actor.clearResult();
    }.bind(this));
    $gameTemp.reserveCommonEvent(CN_romasha_talk); 
    return true;
};
