const SkpPic = "pictures/ScenarioSkip/";
class SkpData {
    constructor(_SyoStr){
        this.SyoStr = _SyoStr;
        this.StoryStr = [];
    }
}
class _SkpStr {
    constructor(_SaveNo , _Name){
        this.SaveNo = _SaveNo;
        this.Name = _Name;
    }
}
let SkpDataArr = [];
let VN_SSkipNo = 1080;
let _skpNo = SkpDataArr.length - 1;
SkpDataArr.push(new SkpData("プロローグ"));
_skpNo = SkpDataArr.length - 1;
SkpDataArr[_skpNo].StoryStr.push(new _SkpStr(1,"ロマーシャ操作可能"));
SkpDataArr.push(new SkpData("第１章"));
_skpNo = SkpDataArr.length - 1;
SkpDataArr[_skpNo].StoryStr.push(new _SkpStr(2,"１章：開始"));
SkpDataArr[_skpNo].StoryStr.push(new _SkpStr(3,"１章：ソリティア脱出手前"));
SkpDataArr.push(new SkpData("第２章"));
_skpNo = SkpDataArr.length - 1;
SkpDataArr[_skpNo].StoryStr.push(new _SkpStr(4,"２章：開始"));
SkpDataArr[_skpNo].StoryStr.push(new _SkpStr(5,"２章：ゴブリンパート開始"));
SkpDataArr.push(new SkpData("第３章"));
_skpNo = SkpDataArr.length - 1;
SkpDataArr[_skpNo].StoryStr.push(new _SkpStr(6,"３章：開始"));
SkpDataArr[_skpNo].StoryStr.push(new _SkpStr(7,"３章：自由行動開始"));
SkpDataArr[_skpNo].StoryStr.push(new _SkpStr(8,"３章：大会前"));
SkpDataArr.push(new SkpData("第４章"));
_skpNo = SkpDataArr.length - 1;
SkpDataArr[_skpNo].StoryStr.push(new _SkpStr(9,"４章：開始"));
SkpDataArr[_skpNo].StoryStr.push(new _SkpStr(10,"４章：マトリクス集め開始"));
SkpDataArr[_skpNo].StoryStr.push(new _SkpStr(11,"４章：会見終了後"));
let Skp_3SyoFlg = false;
let Skp_SyoSelNo = 0;   
let Skp_SelNo = 0;      
Game_Interpreter.prototype.Skp_Start = function () {
    Skp_YesNo_Flg = false;
    Skp_SyoSelNo = 0;   
    Skp_SelNo = 0;      
    this.SetPict(PN_SkpBase , SkpPic + "PN_SkpBase" , 0 , 0);
    let _sSkipNo = $gameVariables.value(VN_SSkipNo);
    _sSkipNo = 1000;
    let _ckNo = 0;
    if(_ckNo < _sSkipNo) this.SetPictC(PN_SkpMBtn + 0 , SkpPic + "PN_SkpMBtn_0" , 119 , 216);
    _ckNo += SkpDataArr[0].StoryStr.length;
    if(_ckNo < _sSkipNo) this.SetPictC(PN_SkpMBtn + 1 , SkpPic + "PN_SkpMBtn_1" , 160 , 314);
    _ckNo += SkpDataArr[1].StoryStr.length;
    if(_ckNo < _sSkipNo) this.SetPictC(PN_SkpMBtn + 2 , SkpPic + "PN_SkpMBtn_2" , 117 , 426);
    _ckNo += SkpDataArr[2].StoryStr.length;
    if(_ckNo < _sSkipNo) this.SetPictC(PN_SkpMBtn + 3 , SkpPic + "PN_SkpMBtn_3" , 160 , 534);
    _ckNo += SkpDataArr[3].StoryStr.length;
    if(_ckNo < _sSkipNo) this.SetPictC(PN_SkpMBtn + 4 , SkpPic + "PN_SkpMBtn_4" , 117 , 646);
    this.Skp_Draw(0);
}
Game_Interpreter.prototype.Skp_Draw = function (_No) {
    Skp_SyoSelNo = _No;
    this.SetPicStr(PN_SkpMain , SkpDataArr[_No].SyoStr , 36 , 310 , 154);
    this.DelPictSpan(PN_SkpSBtn , PN_SkpYNBtn + 1);
    let _sSkipNo = $gameVariables.value(VN_SSkipNo);
    _sSkipNo = 1000;
    let _ckNo = 0;
    for (let i = 0; i <= _No - 1; i++) {
        _ckNo += SkpDataArr[i].StoryStr.length;
    }
    if(_ckNo < _sSkipNo){
        this.SetPictFIn( PN_SkpPic , SkpPic + "PN_SkpImg_" + _No , 0 , 0 , 0 , 0 , 10);
    } else {
        this.SetPictFIn( PN_SkpPic , SkpPic + "PN_SkpImg_Rock" , 0 , 0 , 0 , 0 , 10);
    }
    for (let i = 0; i <= SkpDataArr[_No].StoryStr.length - 1; i++) {
        if(_ckNo + i < _sSkipNo) {
            this.SetPict(PN_SkpSBtn + i , SkpPic + "PN_SkpSBtn" , 329 , 251 + (i * 66));
            this.SetPicStr(PN_SkpSBtnT + i , SkpDataArr[_No].StoryStr[i].Name,
                24 , 329 + 30 , 251 + (i * 66) + 13);
        }
    }
    switch (_No) {
        case 0:
            this.SetPict(PN_SkpSSel , SkpPic + "PN_SkpSSel_l" , 119 - 49 , 216 - 48 , 255,100,100,3);
            break;
        case 1:
            this.SetPict(PN_SkpSSel , SkpPic + "PN_SkpSSel" , 160 - 79 , 314 - 80,255,100,100,3);
            break;
        case 2:
            this.SetPict(PN_SkpSSel , SkpPic + "PN_SkpSSel" , 117 - 79 , 426 - 80,255,100,100,3);
            break;
        case 3:
            this.SetPict(PN_SkpSSel , SkpPic + "PN_SkpSSel" , 160 - 79 , 534 - 80,255,100,100,3);
            break;
        case 4:
            this.SetPict(PN_SkpSSel , SkpPic + "PN_SkpSSel" , 117 - 79 , 646 - 80,255,100,100,3);
            break;
    }
}
Game_Interpreter.prototype.Skp_Update = function () {
    if (Skp_YesNo_Flg) { 
        this.Skp_YesNo_Update();
        return true;
    }
    let _ckPicArr = []; let _ckNo = -1;
    for (let i = 0; i <= 5 - 1; i++) {
        _ckPicArr.push(PN_SkpMBtn + i);
    }
    this.PicCngColorArr(_ckPicArr);
    _ckNo = overPointerCkArrTm_GetNo( _ckPicArr );
    if(_ckNo != -1){
        this.PicCngColor( PN_SkpMBtn + _ckNo , [150,150,150,0]);
        if (TouchInput.isTriggered()) this.Skp_Draw(_ckNo);
    }
    _ckPicArr = [];
    for (let i = 0; i <= 7 - 1; i++) {
        _ckPicArr.push(PN_SkpSBtn + i);
    }
    this.PicCngColorArr(_ckPicArr);
    _ckNo = overPointerCkArrTm_GetNo( _ckPicArr );
    if(_ckNo != -1){
        Skp_SelNo = _ckNo;
        this.PicCngColor( PN_SkpSBtn + _ckNo , [150,150,150,0]);
        if (TouchInput.isTriggered()) this.Skp_YesNo_Draw();
    }
    if (Input.isTriggered('menu') || TouchInput.isCancelled()) {
        this.DelPictSpan(PN_SkpBase , PN_SkpYNBtn + 1);
        return false;
    }
    return true; 
}
let Skp_YesNo_Flg = false;
let Skp_YesNo_SelNo = -1;
Game_Interpreter.prototype.Skp_YesNo_Draw = function () {
    Skp_YesNo_Flg = true; Skp_YesNo_SelNo = -1;
    this.SetPict(PN_SkpYNBase , SkpPic + "PN_SkpYNBase" , 0 , 0);
    this.SetPicStrC(PN_SkpYNTxt , SkpDataArr[Skp_SyoSelNo].StoryStr[Skp_SelNo].Name , 36 , 695 , 300);
    this.SetPictC(PN_SkpYNBtn + 0 , SkpPic + "PN_SkpYNBtn_Y2" , 510 , 490);
    this.SetPictC(PN_SkpYNBtn + 1 , SkpPic + "PN_SkpYNBtn_N2" , 510 + 368 , 490);
}
let SkipDeckKeep = [];
let SkipVNKeep = [];
let SkipSWKeep = [];
let SavedWeapons = null;
let SavedSyogoed = null;
let SaveSkipUseFlg = false;
let SaveSkip開発度維持Flg = false;
Game_Interpreter.prototype.Skp_YesNo_Update = function () {
    let _ckNo = overPointerCkArr_GetNo( [PN_SkpYNBtn + 0 , PN_SkpYNBtn + 1] );
    if (_ckNo != Skp_YesNo_SelNo) {
        Skp_YesNo_SelNo = _ckNo;
        switch (Skp_YesNo_SelNo) {
            case 0:
                this.SetPictC(PN_SkpYNBtn + 0 , SkpPic + "PN_SkpYNBtn_Y1" , 510 , 490);
                this.SetPictC(PN_SkpYNBtn + 1 , SkpPic + "PN_SkpYNBtn_N2" , 510 + 368 , 490);
                break;
            case 1:
                this.SetPictC(PN_SkpYNBtn + 0 , SkpPic + "PN_SkpYNBtn_Y2" , 510 , 490);
                this.SetPictC(PN_SkpYNBtn + 1 , SkpPic + "PN_SkpYNBtn_N1" , 510 + 368 , 490);
                break;
        }
    }
    if (SaveSkip開発度維持Flg) {
        this.SetPict(PN_SkpYNBase_Check , SkpPic + "PN_SkpYNBase_CheckOn" , 0 , 0);
    } else {
        this.SetPict(PN_SkpYNBase_Check , SkpPic + "PN_SkpYNBase_CheckOff" , 0 , 0);
    }
    if (overPointerCkTm(PN_SkpYNBase_Check) && TouchInput.isTriggered()) {
        SaveSkip開発度維持Flg = !SaveSkip開発度維持Flg;
    }
    let _cancelFlg = false;
    switch (_ckNo){
        case 0:
            if(TouchInput.isTriggered()) {
                Skp_3SyoFlg = Skp_SyoSelNo == 3;
                _LoadSelectNo = SkpDataArr[Skp_SyoSelNo].StoryStr[Skp_SelNo].SaveNo;
                SkipDeckKeep = JSON.parse(JSON.stringify($gameSystem.DeckArr));
                savedWeapons = JsonEx.makeDeepCopy($gameParty._weapons);
                // for (let i = 0; i <= $dataArmors.length - 1; i++) {
                //     if ($gameActors.actor(1).hasArmor($dataArmors[i + 1])) { //装備
                //         $gameParty.gainItem($dataArmors[i + 1], 1);
                //SavedSyogoed = JsonEx.makeDeepCopy($gameParty._armors);
                SkipVNKeep = [];
                if (SaveSkip開発度維持Flg) {
                    for (let i = 64; i <= 67; i++) {
                        SkipVNKeep.push([i , $gameVariables.value(i)]);
                    }
                    for (let i = 72; i <= 76; i++) {
                        SkipVNKeep.push([i , $gameVariables.value(i)]);
                    }
                    for (let i = 78; i <= 82; i++) {
                        SkipVNKeep.push([i , $gameVariables.value(i)]);
                    }
                    for (let i = 91; i <= 96; i++) {
                        SkipVNKeep.push([i , $gameVariables.value(i)]);
                    }
                }
                SkipSWKeep = [];
                if (SaveSkip開発度維持Flg) {
                    for (let i = 161; i <= 169; i++) { 
                        SkipSWKeep.push([i , $gameSwitches.value(i)]);
                    }
                }
                this.UTA_Save();
                SaveSkipUseFlg = true;
                SaveFolCngName = "save_skip";
                _LoadStartingFlame = 0; 
                this.LoadStarting();
                ClickCkFlg = false;
                SSkipFlg = true;
                Menu禁止Flg = false;
                Menu禁止Flame = 5;
            }
            break;
        case 1:
            _cancelFlg = TouchInput.isTriggered();
            break;
    }
    if (Input.isTriggered('menu') || TouchInput.isCancelled() || _cancelFlg) {
        Skp_YesNo_Flg = false; Skp_YesNo_SelNo = -1;
        this.DelPictSpan(PN_SkpYNBase , PN_SkpYNBtn + 1);
    }
}
