/*
 */
const CN_拠点コモン = 15;
const CN_仕事訓練後_成功 = 310;
const CN_仕事訓練後_失敗 = 311;
const CN_仕事リザルト後 = 313;
const SN_拠点夜発動 = 1;
const L0BasePic = "pictures/Adv/L0_Base/"; 
Game_Interpreter.prototype.Adv_L0Base_View = function () {
    let _opi = 0;
    this.SetPict(PN_tBackT, AdvPic + "PN_tBackT", 0, 0);
    ViewPicReset();
    this.EventBackCng("Base_Back", 15);
}
const _AdvSellSa = 90;
const VN_TownBtnNo = 75;
let KnrnTktPsX = 0;
let KnrnTktPsY = 0;
Game_Interpreter.prototype.Adv_L0Base_UIDraw = function () {
    if (L0_NotDrawFlg) {
        L0_NotDrawFlg = false;
        return;
    }
    L0_TcPic = []; 
    L0_Selecter = $gameSystem.L0BaseBtnArr.length - 1; 
    let _opi = 0;
    for (let i = 0; i <= $gameSystem.L0BaseBtnArr.length - 1; i++) {
        let _AddZureX = 0;
        let _DrawImg = $gameSystem.L0BaseBtnArr[i];
        if (_DrawImg == "Btn_Town") {
            if ($gameVariables.value(VN_TownBtnNo) > 0) {
                _DrawImg += "_" + $gameVariables.value(VN_TownBtnNo);
            }
        }
        this.SetPict(PN_tSelBtn + i, L0BasePic + _DrawImg, L0BtnPos._x - 100, L0BtnPos._y - (_AdvSellSa * i), _opi);
        if (i != L0_Selecter) {
            this.MovePict(PN_tSelBtn + i, L0BtnPos._x - 15, true, 3);
        } else {
            _AddZureX = 15;
            this.MovePict(PN_tSelBtn + i, L0BtnPos._x, true, 3);
        }
        if (_DrawImg == "Btn_Kunren") {
            KnrnTktPsX = L0BtnPos._x + 155;
            KnrnTktPsY = L0BtnPos._y - (_AdvSellSa * i) + 2;
            this.KunrenTktDraw(_opi, _AddZureX);
        }
        L0_TcPic.push(PN_tSelBtn + i);
    }
    this.SetPictC(PN_AdvSell, AdvPic + "PN_AdvSell", L0BtnPos._x - 15 - 100, L0BtnPos._y - (_AdvSellSa * L0_Selecter) + 35, _opi);
    this.MovePict(PN_AdvSell, L0BtnPos._x - 15, true, 15); 
}
Game_Interpreter.prototype.KunrenTktDraw = function (_opi, _zureX, _mvflg) {
    _opi = typeof _opi !== 'undefined' ? _opi : 0;
    _zureX = typeof _zureX !== 'undefined' ? _zureX : 0;
    _mvflg = typeof _mvflg !== 'undefined' ? _mvflg : false;
    let _TktCnt = $gameParty.numItems($dataItems[_INo_訓練無料券]);
    SoundManager.playCursor();
    if (_TktCnt > 0) {
        if (!_mvflg) {
            this.SetPict(PN_KunrenFree, L0BasePic + "PN_KunrenFree", KnrnTktPsX, KnrnTktPsY, _opi);
            this.SetPicStrC(PN_KunrenFreeTxt, " " + _TktCnt + " ", 28, KnrnTktPsX + 106, KnrnTktPsY + 41, _opi);
        }
        this.MovePict(PN_KunrenFree, KnrnTktPsX + _zureX, true, 3);
        this.MovePict(PN_KunrenFreeTxt, KnrnTktPsX + 106 + _zureX, true, 3);
    } else {
        this.DelPict(PN_KunrenFree);
        this.DelPict(PN_KunrenFreeTxt);
    }
    this.SetPictC(PN_AdvSell, AdvPic + "PN_AdvSell", L0BtnPos._x - 15 - 100, L0BtnPos._y - (_AdvSellSa * L0_Selecter) + 35, _opi);
    this.MovePict(PN_AdvSell, L0BtnPos._x - 15, true, 15); 
}
Game_Interpreter.prototype.Move_Api0_KTkt = function () {
    this.MovePict(PN_KunrenFree, true, true, 3, 0);
    this.MovePict(PN_KunrenFreeTxt, true, true, 3, 0);
}
Game_Interpreter.prototype.Move_Api255_KTkt = function () {
    this.MovePict(PN_KunrenFree, true, true, 3);
    this.MovePict(PN_KunrenFreeTxt, true, true, 3);
}
let _Event_Erase = Game_Interpreter.prototype.command214;
Game_Interpreter.prototype.command214 = function () {
    for (let i = 0; i <= $gameMap._events.length - 1; i++) {
        if ($gameMap._events[i] != undefined) {
            if ($gameMap._events[i]._templateEvent != undefined) {
                if ($gameMap._events[i]._eventId == this._eventId) {
                    if ($gameMap._events[i]._templateEvent.name == _Ck移動EvName) {
                        _Ck移動EvName = "";
                    }
                }
            }
        }
    }
    return _Event_Erase.call(this);
};
let _街Move_flame = 0;
let _Ck移動EvName = "";
Game_Interpreter.prototype.Adv_L0Base_Update = function () {
    if (_街Move_flame >= 1) {
        _街Move_flame++;
        if (_街Move_flame == 5) {
            this.Adv_SpineEffect_Close(); 
        }
        if (_街Move_flame == 10) {
            _街Move_flame = 0;
            this.Adv_L0_Cng(_L0Mode.Town); 
            this.Adv_SpineEffect_Open();
        }
        return;
    }
    if (L0_flame == 13) { 
        this.SetCmnEventSc(CN_拠点コモン); 
    }
    if (L0_flame == 15) { 
        _Ck移動EvName = this.JN_EventLoad("拠点"); 
    }
    if (L0_flame == 18 && _Ck移動EvName != "") {
        L0_flame--;
        return;
    }
    if (L0_flame == 19) {
        this.Adv_L0Base_UIDraw();
    }
    if (L0_flame < 20) return;
    if (L0_flame == 60) { 
        this.AutoSave();
    }
    KyotenYesBtnStartFlg = false;
    let _mvFlg = false;
    if (Input.isTriggered('up')) { 
        L0_Selecter++;
        _mvFlg = true;
        if (L0_Selecter >= $gameSystem.L0BaseBtnArr.length) L0_Selecter = 0;
    }
    if (Input.isTriggered('down')) { 
        L0_Selecter--;
        _mvFlg = true;
        if (L0_Selecter < 0) L0_Selecter = $gameSystem.L0BaseBtnArr.length - 1;
    }
    let _CNo = overPointerCkArr(L0_TcPic);
    if (_CNo != -1) {
        if (L0_Selecter != _CNo - PN_tSelBtn) {
            L0_Selecter = _CNo - PN_tSelBtn;
            _mvFlg = true;
        }
    }
    if (_mvFlg) {
        SoundManager.playCursor();
        for (let i = 0; i <= $gameSystem.L0BaseBtnArr.length - 1; i++) {
            let _AddZureX = 0;
            if (i != L0_Selecter) {
                this.MovePict(PN_tSelBtn + i, L0BtnPos._x - 15, true, 3);
            } else {
                _AddZureX = 15;
                this.MovePict(PN_tSelBtn + i, L0BtnPos._x, true, 3);
            }
            if ($gameSystem.L0BaseBtnArr[i] == "Btn_Kunren") {
                this.KunrenTktDraw(255, _AddZureX, true);
            }
        }
        this.MovePict(PN_AdvSell, L0BtnPos._x - 15, L0BtnPos._y - (_AdvSellSa * L0_Selecter) + 35, 3);
    }
    if (Input.isTriggered('ok') || (_CNo != -1) && TouchInput.isTriggered()) { 
        SoundManager.playOk();
        this.Adv_L0_BtnColCng(L0_Selecter);
        switch ($gameSystem.L0BaseBtnArr[L0_Selecter]) {
            case "Btn_Asobi":   
                Adv_Layer = 1;  
                this.Adv_L1_Cng(_L1Mode.遊び);
                this.Move_Api0_KTkt();
                break;
            case "Btn_Battle":  
                Adv_Layer = 1;  
                this.Adv_L1_Cng(_L1Mode.野試合);
                this.Move_Api0_KTkt();
                NoBtlCnt = 0;
                console.log("野試合を選択！");
                break;
            case "Btn_Work":    
                Adv_Layer = 1;  
                this.Adv_L1_Cng(_L1Mode.仕事);
                this.Move_Api0_KTkt();
                break;
            case "Btn_Kunren":  
                Adv_Layer = 1;  
                this.Adv_L1_Cng(_L1Mode.訓練);
                break;
            case "Btn_Rest":    
                Adv_Layer = 1;  
                this.Adv_L1_Cng(_L1Mode.休憩);
                this.Move_Api0_KTkt();
                break;
            case "Btn_Town":    
                _街Move_flame = 1;
                this.JN_EventLoad("街選択");
                this.Move_Api0_KTkt();
                break;
        }
    }
}
const _BtnCnt = 6; 
Game_Interpreter.prototype.Adv_L0_BtnColCng = function (_Col) {
    _Col = typeof _Col !== 'undefined' ? _Col : -1;
    for (let i = 0; i <= _BtnCnt - 1; i++) {
        if (_Col != i) this.PicCngColor(PN_tSelBtn + i, [-150, -150, -150, 0]);
        if (_Col == -1) this.PicCngColor(PN_tSelBtn + i); 
    }
    this.DelPictArr([PN_tGage + 1, PN_tGage_s + 1]);
    this.Adv_情報_MojiDraw();
}
Game_Interpreter.prototype._街Move_Cancel = function () {
    _街Move_flame = 0;
    this.Adv_L0_Back();
}
const CN_WorkJug = 289;
const CN_KunrenJug = 299;
const VN_Work成功 = 301;
const L1WorkPic = "pictures/Adv/L1_Work/"; 
let L1_Workコモン内ReDrawFlg = false;
Game_Interpreter.prototype.Adv_L1WorkボタンReDraw = function () {
    if (L1_Workコモン内ReDrawFlg) {
        this.Adv_L1Work_FirstDraw();
        L1_Workコモン内ReDrawFlg = false;
    }
}
let L1_WorkDrawFlg = false;
Game_Interpreter.prototype.Adv_L1Work_View = function () {
    this.SetCmnEventSc(CN_WorkJug);
    L1_WorkDrawFlg = true;
    this.JN_EventLoad("仕事"); 
}
const SW_セクハラボタン出現 = 481;
const SW_セクハラ許可 = 482;
Game_Interpreter.prototype.Adv_L1Work_FirstDraw = function () {
    L1_Selecter = 0
    this.Adv_L1Work_Draw();
}
Game_Interpreter.prototype.Adv_L1Work_Draw = function () {
    this.DelPictSpan(PN_tSelIcn , PN_tSexharaBtn);
    this.DelSpriteSpan(PN_tSelIcn , PN_tSelIcn + 25);
    let _SucArr = []; 
    let _StArr = []; 
    if ($gameSystem.L1WorkArr.indexOf("Work7") != -1) {
        $gameSystem.L1WorkArr.push("Work8"); 
        $gameSystem.L1WorkArr.push("Work9"); 
    } else {
        let ckIndex = $gameSystem.L1WorkArr.indexOf("Work8");
        if (ckIndex != -1) $gameSystem.L1WorkArr.splice(ckIndex, 1);
        ckIndex = $gameSystem.L1WorkArr.indexOf("Work9");
        if (ckIndex != -1) $gameSystem.L1WorkArr.splice(ckIndex, 1);
    }
    $gameSystem.L1WorkArr = [...new Set($gameSystem.L1WorkArr)]; 
    for (let i = 0; i <= $gameSystem.L1WorkArr.length - 1; i++) {
        _SucArr.push($gameVariables.value(VN_WorkCk));
        _StArr.push(this.WorkDataGet($gameSystem.L1WorkArr[i])._CSkills);
    }
    this.SetPictFIn(PN_SelBack, L1WorkPic + "PN_WorkBack", 0, 0, 0, 0, 10);
    this.Adv_L1Sel6_View(L1WorkPic , $gameSystem.L1WorkArr , _SucArr , _StArr);
    this.Adv_L1Work_SexharaDraw();
    this.Adv_L1Work_SelDraw($gameSystem.L1WorkArr[0]); 
}
Game_Interpreter.prototype.Adv_L1Work_SexharaDraw = function () {
    if ($gameSwitches.value(SW_セクハラボタン出現)) {
        var setSexharaBtn = "PN_tSexharaBtnb";
        if ($gameSwitches.value(SW_セクハラ許可)) setSexharaBtn = "PN_tSexharaBtna";
        this.SetPictFIn(PN_tSexharaBtn, L1WorkPic + setSexharaBtn, 1096, 510, 0, 0, 10);
    }
}
let _Sel_WorkData; 
let _Sel_WorkNo = 0;
let _Sel_WorkImg = ""; 
let _訓練チュートリアルFlg = false;
Game_Interpreter.prototype.Adv_L1Work_SelDraw = function (_ItemStr, _訓練Flg) {
    _訓練Flg = typeof _訓練Flg !== 'undefined' ? _訓練Flg : false;
    this.DelPictSpan(PN_tJhWin, PN_tJhTxt + 9);
    this.SetPict(PN_tJhWin, AdvPic + "PN_tJhWin", 350, 508);
    let _SelPic = _ItemStr;
    _Sel_WorkData = undefined;
    D_Text_Cng_font = "Makinas"; 
    let _ckADV_Data = null;
    if (!_訓練Flg) _ckADV_Data = ADV_WorkData;
    if (_訓練Flg) _ckADV_Data = ADV_KunrenData;
    for (let i = 0; i <= _ckADV_Data.length - 1; i++) {
        if (_ckADV_Data[i]._BtnImg == _SelPic) { 
            if (!_訓練Flg) {
                this.Adv_SelDataView(_ckADV_Data[i]); 
            } else {
                this.Adv_SelDataView(_ckADV_Data[i], true);
            }
            _Sel_WorkNo = i;
        }
    }
    D_Text_Cng_font = ""; 
}
let ADVData_GetData = function (_BtnImg, _訓練Flg) {
    _訓練Flg = typeof _訓練Flg !== 'undefined' ? _訓練Flg : false;
    if (!_訓練Flg) _ckADV_Data = ADV_WorkData;
    if (_訓練Flg) _ckADV_Data = ADV_KunrenData;
    for (let i = 0; i <= _ckADV_Data.length - 1; i++) {
        if (_ckADV_Data[i]._BtnImg == _BtnImg) { 
            return _ckADV_Data[i];
        }
    }
}
let CheckWork8 = function () {
    return $gameVariables.value(VN_客引き回数) >= 1 && $gameVariables.value(VN_淫乱度) >= 25;
}
let CheckWork9 = function () {
    return $gameVariables.value(VN_接客回数) >= 1 && $gameVariables.value(VN_淫乱度) >= 50;
}
let Workセクハラ選択 = false;
Game_Interpreter.prototype.Adv_SelDataView = function (_WorkData, _訓練Flg) {
    _訓練Flg = typeof _訓練Flg !== 'undefined' ? _訓練Flg : false;
    _Sel_WorkImg = _WorkData._BtnImg; 
    _Sel_WorkData = _WorkData;
    let _仕事名 = _WorkData._Name;
    if (!_訓練Flg) {
        switch (_Sel_WorkImg) {
            case "Work8": 
                if (!CheckWork8()) {
                    this.SetPicStr(PN_tJhTxt + 0, SCol.Blk0 + _仕事名, 25, 380, 524);
                    this.SetPicStr(PN_tJhTxt + 2, SCol.Blk0 +
                        "Unlock: Worked as Tout & Lewdness 25+", 25, 380, 564);
                    return;
                }
                break;
            case "Work9": 
                if (!CheckWork9()) {
                    this.SetPicStr(PN_tJhTxt + 0, SCol.Blk0 + _仕事名, 25, 380, 524);
                    this.SetPicStr(PN_tJhTxt + 2, SCol.Blk0 +
                        "Unlock: Worked as Hostess & Lewdness 50+", 25, 380, 564);
                    return;
                }
                break;
        }
    }
    _WorkData._成功確立 = $gameVariables.value(VN_WorkCk);
    Workセクハラ選択 = false;
    let _成功確率 = _WorkData._成功確立;
    if (_成功確率 >= 100) _成功確率 = 100;
    let _説明 = _WorkData._Setu;
    this.SetPicStr(PN_tJhTxt + 0, SCol.Blk0 + _仕事名, 25, 380, 524);
    let _成功Txt = "Success Rate " + _成功確率 + "% ";
    let _お金 = _WorkData._Gold;
    if (_訓練Flg) {
        _お金 = Math.floor(_お金 * ((100 - $gameVariables.value(VN_訓練割引)) / 100))
        _お金 = "Cost: " + -_お金 + " Borda ";
    } else {
        _お金 = "Pay: " + _お金 + " Borda ";
    }
    let _お金Txt = "　　" + _お金 + " ";
    _成功Txt += _お金Txt;
    this.SetPicStr(PN_tJhTxt + 1, SCol.Blk0 + _成功Txt, 25, 600, 524);
    this.SetPicStr(PN_tJhTxt + 2, SCol.Blk0 + _説明, 25, 380, 564);
    this.Adv_情報_GageDraw(_WorkData._Kenk, _WorkData._Yrki);
    let _SetStTxt = "";
    for (let j = 0; j <= _WorkData._CSkills.length - 1; j++) {
        _SetStTxt += _GetStTxt(_WorkData._CSkills[j]._St, _WorkData._CSkills[j]._Var);
        _SetStTxt += "　　　";
        if (j % 2 == 1) {
            let _PiNo = Math.floor(j / 2);
            this.SetPicStr(PN_tJhTxt + 3 + _PiNo, SCol.Blk0 + _SetStTxt,
                25, 380, 604 + (_PiNo * 40));
            _SetStTxt = "";
        }
    }
    if (_SetStTxt != "") {
        let _PiNo = 0;
        this.SetPicStr(PN_tJhTxt + 3 + _PiNo, SCol.Blk0 + _SetStTxt,
            25, 380, 604 + (_PiNo * 40));
    }
}
const IN_Up = 90; 
const IN_Down = 91; 
let _GetStTxt = function (_CkSt, _変化値) {
    let _CngIco = "";
    if (_変化値 > 0) {
        _CngIco = "\\I[" + IN_Up + "]";
    } else {
        _CngIco = "\\I[" + IN_Down + "]";
    }
    switch (_CkSt) {
        case _St.健康:
            return "HP" + _CngIco;
        case _St.淫乱度:
            return "Lewdness" + _CngIco;
        case _St.体力:
            return "Stamina" + _CngIco;
        case _St.攻撃:
            return "Attack" + _CngIco;
        case _St.防御:
            return "Defense" + _CngIco;
        case _St.命中:
            return "Hit" + _CngIco;
        case _St.回避:
            return "Evasion" + _CngIco;
        case _St.直感:
            return "Intuition" + _CngIco;
    }
}
const CN_仕事変化値設定 = 290;
let CN_WorkJugPlayFlg = false;
Game_Interpreter.prototype.Adv_L1Work_Update = function (_ReFlg) {
    _ReFlg = typeof _ReFlg !== 'undefined' ? _ReFlg : false;
    if (CN_WorkJugPlayFlg) this.SetCmnEventSc(CN_WorkJug); 
    CN_WorkJugPlayFlg = false;
    let _btnStr = "";
    var _sセクハラSelect = false;
    if (overPointerCk(PN_tSexharaBtn)) _sセクハラSelect = true;
    if (Sel6_Selecter + 3 > Sel6_BtnArr.length - 1 && $gameSwitches.value(SW_セクハラボタン出現)) {
        if (!Workセクハラ選択) {
            if (Input.isTriggered('down')) _sセクハラSelect = true;
        }
    }
    if (_sセクハラSelect) {
        this.MovePict(PN_AdvSell, 1090, 560, 5);
        Workセクハラ選択 = true;
    }
    var bセクハラ状態Skip = false;
    if (Workセクハラ選択 && $gameSwitches.value(SW_セクハラボタン出現)) {
        bセクハラ状態Skip = true;
        if (Input.isTriggered('up')) {
            Workセクハラ選択 = false;
            this.Adv_L1Sel6_ReSell();
        }
        if (Input.isTriggered('ok') || (overPointerCk(PN_tSexharaBtn) && TouchInput.isTriggered())) {
            $gameSwitches.setValue(SW_セクハラ許可 , !$gameSwitches.value(SW_セクハラ許可))
            this.Adv_L1Work_SexharaDraw();
            this.PlaySe("Switch2");
            L1_Workコモン内ReDrawFlg = true;
            CN_WorkJugPlayFlg = true;
        }
        let _CNo = overPointerCkArr(_Sel6_TcPic);
        if (_CNo != -1){
            Sel6_Selecter--;
            bセクハラ状態Skip = Workセクハラ選択 = false;
        }
    }
    if (!bセクハラ状態Skip) {
        _btnStr = this.Adv_L1Sel6_Update(_ReFlg); 
        if (_btnStr != "") {
            this.Adv_L1Work_SelDraw(_btnStr); 
        }
        if (L1_WorkDrawFlg) {
            this.Adv_L1Work_FirstDraw();
            L1_WorkDrawFlg = false;
        }
        if (_ReFlg) {
            L1_flame = 0;
            return; 
        }
        if (Input.isTriggered('ok') || (this.Adv_L1Sel6_TcCk() && TouchInput.isTriggered())) { 
            switch (_Sel_WorkData._BtnImg) {
                case "Work8": 
                    if (!CheckWork8()) return;
                    break;
                case "Work9": 
                    if (!CheckWork9()) return;
                    break;
            }
            SoundManager.playOk();
            Adv_Layer = 2; 
            _Sel_WorkData = ADVData_GetData($gameSystem.L1WorkArr[Sel6_Selecter]);
            //this.SetCmnEventSc(CN_仕事変化値設定 + Sel6_Selecter);
            this.Adv_L2_Cng(_L2Mode.Work);
            for (let i = 0; i <= 25 - 1; i++) {
                this.MoveSprite(PN_tSelIcn + i, true, true, 5, 0);
            }
        }
    }
    if (Input.isTriggered('escape') || TouchInput.isCancelled()) { 
        SoundManager.playCancel();
        Adv_Layer = 0;
        Workセクハラ選択 = false;
        this.Move_Api255_KTkt();
        this.Adv_L1_PicDel();    
        this.Adv_L0_BtnColCng(); 
        this.Adv_L0_SelReset();  
        this.DelSpriteSpan(PN_tSelIcn, PN_tSelIcn + 25);
    }
}
const VN_Kunren成功 = 321;
const L1KunrenPic = "pictures/Adv/L1_Kunren/"; 
var KunrenFirstDraw = false;
Game_Interpreter.prototype.Adv_L1Kunren_View = function () {
    this.SetCmnEventSc(CN_KunrenJug);
    KunrenFirstDraw = false;
    this.JN_EventLoad("訓練"); 
}
Game_Interpreter.prototype.Adv_L1Kunren_FirstDraw = function () {
    L1_Selecter = 0
    this.Adv_L1Kunren_Draw();
}
Game_Interpreter.prototype.Adv_L1Kunren_Draw = function () {
    let _SucArr = []; 
    let _StArr = []; 
    for (let i = 0; i <= $gameSystem.L1KunrenArr.length - 1; i++) {
        _SucArr.push($gameVariables.value(VN_WorkCk));
        _StArr.push(this.KunrenDataGet($gameSystem.L1KunrenArr[i])._CSkills);
    }
    this.SetPictFIn(PN_SelBack, L1KunrenPic + "PN_KunrenBack", 0, 0, 0, 0, 10);
    this.Adv_L1Sel6_View(L1KunrenPic, $gameSystem.L1KunrenArr, _SucArr, _StArr);
    $gameVariables.setValue(VN_訓練割引, 0);
    let _TktCnt = $gameParty.numItems($dataItems[_INo_訓練無料券]);
    if (_TktCnt > 0) {
        $gameVariables.setValue(VN_訓練割引, 100);
    }
    this.Adv_L1Work_SelDraw($gameSystem.L1KunrenArr[0], true); 
}
Game_Interpreter.prototype.Adv_訓練再描画 = function () {
    this.Adv_L1Work_SelDraw($gameSystem.L1KunrenArr[0], true); 
    this.KunrenTktDraw(0, 15);
}
Game_Interpreter.prototype.Adv_L1Kunren_Update = function (_ReFlg) {
    _ReFlg = typeof _ReFlg !== 'undefined' ? _ReFlg : false;
    if (!KunrenFirstDraw) {
        this.Adv_L1Kunren_FirstDraw();
        KunrenFirstDraw = true;
        return;
    }
    let _btnStr = this.Adv_L1Sel6_Update(_ReFlg); 
    if (_btnStr != "") {
        this.Adv_L1Work_SelDraw(_btnStr, true); 
    }
    if (_ReFlg) {
        L1_flame = 0;
        return; 
    }
    if (Input.isTriggered('ok') || (this.Adv_L1Sel6_TcCk() && TouchInput.isTriggered())) { 
        SoundManager.playOk();
        if (-1 * (_Sel_WorkData._Gold * ((100 - $gameVariables.value(VN_訓練割引)) / 100)) > $gameParty._gold) {
            D_Text_Cng_font = "Makinas"; 
            let _AdvSel = this.PicObjGet(PN_AdvSell);
            let PssX = _AdvSel._x + 152;
            let PssY = _AdvSel._y - 26;
            this.SetPicStrPopC(PN_tPopTxt, SCol.Red + "Not enough money", 40, PssX, PssY, 30, 30);
            D_Text_Cng_font = "";
            return; 
        }
        _Adv_WaitFlame = 10;
        Adv_Layer = 2; 
        this.Adv_L2_Cng(_L2Mode.Kunren);
        for (let i = 0; i <= 25 - 1; i++) {
            this.MoveSprite(PN_tSelIcn + i, true, true, 5, 0);
        }
    }
    if (_訓練チュートリアルFlg) return; 
    if (Input.isTriggered('escape') || TouchInput.isCancelled()) { 
        SoundManager.playCancel();
        Adv_Layer = 0;
        this.Adv_L1_PicDel(); 
        this.Adv_L0_BtnColCng(); 
        this.Adv_L0_SelReset(); 
        this.DelSpriteSpan(PN_tSelIcn, PN_tSelIcn + 25);
    }
}
let _野試合_Func = Game_System.prototype.initialize;
let _野試合_Sel = 0;
let _野試合DrawArr = [];
let _野試合PicArr = []; 
let _野試合選択ENo = -1;
const CN_野試合選択 = 21;
const AdvBtlPic = AdvPic + "L1_Battle/";
Game_System.prototype.initialize = function () { 
    _野試合_Func.call(this);
    this._野試合Arr = []; 
};
class _野試合Enemy {
    constructor(_No, _WinFlg) {
        this.No = _No;
        this.WinFlg = false;
    }
}
Game_Interpreter.prototype._野試合_セットアップ = function (_敵番号) {
    _野試合DrawArr = [];
    for (let i = 0; i <= $gameSystem._野試合Arr.length - 1; i++) {
        if (!$gameSystem._野試合Arr[i].WinFlg) {
            _野試合DrawArr.push($gameSystem._野試合Arr[i]);
        }
        if (_野試合DrawArr.length >= 3) return;
    }
    for (let i = $gameSystem._野試合Arr.length - 1; i >= 0; i--) {
        if ($gameSystem._野試合Arr[i].WinFlg) {
            _野試合DrawArr.push($gameSystem._野試合Arr[i]);
        }
    }
};
Game_Interpreter.prototype._野試合_敵追加 = function (_敵番号) {
    $gameSystem._野試合Arr.push(new _野試合Enemy(_敵番号));
};
Game_Interpreter.prototype.Adv_L1Battle_View = function () {
};
Game_Interpreter.prototype.Adv_L1Battle_SelectView = function () {
    let _SPs = new Pos2D(146 + 179, 144 + 236);
    _SPs._x += (_野試合_Sel * 421);
    if (_野試合_Sel == 1) _SPs._y += 60;
    this.SetPictC(PN_WSelectH, AdvBtlPic + "PN_WSelectH", _SPs._x, _SPs._y);
};
Game_Interpreter.prototype.Adv_L1Battle_Update = function () {
    let mvFlg = false;
    let _okFlg = false;
    if (Input.isTriggered('left')) {
        _野試合_Sel--;
        mvFlg = true;
    }
    if (Input.isTriggered('right')) {
        _野試合_Sel++;
        mvFlg = true;
    }
    let _CNo = overPointerCkArr(_野試合PicArr);
    if (_CNo != -1) {
        if (_野試合_Sel != _CNo - PN_Wanted) {
            _野試合_Sel = _CNo - PN_Wanted;
            mvFlg = true;
        }
        if (TouchInput.isTriggered()) {
            _okFlg = true;
        }
    }
    if ((Input.isTriggered('menu') || TouchInput.isCancelled())) {
        Adv_Layer = 0;
        SoundManager.playCancel();
        this.Move_Api255_KTkt();
        this.Adv_L1_PicDel();    
        this.Adv_L0_BtnColCng(); 
        this.Adv_L0_SelReset();  
    }
    if (mvFlg) {
        if (_野試合_Sel < 0) _野試合_Sel = _野試合DrawArr.length - 1;
        if (_野試合_Sel >= _野試合DrawArr.length) _野試合_Sel = 0;
        this.Adv_L1Battle_SelectView(); 
    }
    if (Input.isTriggered('ok')) _okFlg = true;
    if (_okFlg) {
        SoundManager.playOk();
        _野試合選択ENo = _野試合DrawArr[_野試合_Sel].No;
        this.SetCmnEventSc(CN_野試合選択);
    }
};
let _Kyukei_flame = 0;
let kakuCBMArr = [ 
    [449 + (296 * 0), 349, 184, 66],
    [449 + (296 * 1), 349, 184, 66]
];
Game_Interpreter.prototype.Adv_L1Kyukei_View = function () {
    D_Text_Cng_font = "Makinas"; 
    _Kyukei_flame = 0;
    this.SetPict(PN_tCkBack, "Black", 0, 0, 0);
    this.MovePict(PN_tCkBack, true, true, 15, 80);
    this.SetPictFIn(PN_tCkWin, AdvPic + "KakuninWin", 0, 0, 0, 0, 15);
    L2Select = 0;
    this.MovePict(PN_AdvSell, YNPos[0]._x, YNPos[0]._y, 5);
    let _restTxt = "Would you like to rest? (Recovers Health)";
    this.SetPicStrC(PN_tCkTxt + 0, _restTxt, 30, 710, 245, 0);
    this.MovePict(PN_tCkTxt + 0, true, true, 5);
    D_Text_Cng_font = ""; 
    this.JN_EventLoad("休憩"); 
    this.Adv_情報_GageDraw(50);
}
let KyotenYesBtnStartFlg = false;
Game_Interpreter.prototype.Adv_L1Kyukei_Update = function () {
    if (_Kyukei_flame > 0) { 
        _Kyukei_flame++;
        return;
    }
    let _MvFlg = false;
    if (Input.isTriggered('left')) {
        L2Select_Cng();
        _MvFlg = true;
    }
    if (Input.isTriggered('right')) {
        L2Select_Cng();
        _MvFlg = true;
    }
    let _CNo = overPicClickable(PN_tCkWin, kakuCBMArr);
    if (_CNo != -1 && L2Select != _CNo) {
        L2Select = _CNo;
        _MvFlg = true;
    }
    if (Input.isTriggered('escape') || TouchInput.isCancelled()) { 
        SoundManager.playCancel();
        this.Move_Api255_KTkt();
        this.Adv_L0_Back();
    }
    if ((Input.isTriggered('ok') || ((_CNo != -1) && TouchInput.isTriggered())) && !KyotenYesBtnStartFlg) { 
        if (L2Select == 0) { 
            KyotenYesBtnStartFlg = true;
            SoundManager.playOk();
            let _健康 = $gameVariables.value(VN_PLKenko) + 50;
            if (_健康 > 100) _健康 = 100;
            $gameVariables.setValue(VN_PLKenko, _健康)
            this.JN_EventLoad("休憩選択");
        }
        if (L2Select == 1) { 
            SoundManager.playCancel();
            this.Adv_L0_Back();
        }
    }
    if (_MvFlg) {
        SoundManager.playCursor();
        this.MovePict(PN_AdvSell, YNPos[L2Select]._x, YNPos[L2Select]._y, 5);
    }
}
let _Work成功率 = 0; 
let _yn_flame = 0;
const CN_仕事訓練挑戦時 = 309;
Game_Interpreter.prototype.Adv_L2Work_View = function (_訓練Flg) {
    _yn_flame = 0;
    L2Select = 0;
    EvCngWait = 5;
    if (!_訓練Flg) this.JN_EventLoad("仕事選択");
    if (_訓練Flg) this.JN_EventLoad("訓練選択");
}
Game_Interpreter.prototype.Adv_L2Work_Update = function (_訓練Flg) {
    _訓練Flg = typeof _訓練Flg !== 'undefined' ? _訓練Flg : false;
    if (EvCngWait > 0) {
        EvCngWait--;
        if (EvCngWait <= 0) {
            D_Text_Cng_font = "Makinas"; 
            this.SetPict(PN_tCkBack, "Black", 0, 0, 0);
            this.MovePict(PN_tCkBack, true, true, 15, 80);
            this.SetPictFIn(PN_tCkWin, AdvPic + "KakuninWin", 0, 0, 0, 0, 15);
            this.MovePict(PN_AdvSell, YNPos[0]._x, YNPos[0]._y, 5);
            if (_Sel_WorkData != undefined) {
                let _仕事Txt = "Do " + _Sel_WorkData._Name + "?";
                this.SetPicStrC(PN_tCkTxt + 0, _仕事Txt, 30, 710, 245, 0);
                this.MovePict(PN_tCkTxt + 0, true, true, 5);
                let _成功確率 = _Sel_WorkData._成功確立;
                _Work成功率 = _成功確率
                if (_成功確率 >= 100) _成功確率 = 100;
                let _成功率 = "Success Rate " + _成功確率 + "% ";
                this.SetPicStrC(PN_tCkTxt + 1, _成功率, 30, 710, 285, 0);
                this.MovePict(PN_tCkTxt + 1, true, true, 5);
            }
            D_Text_Cng_font = ""; 
            return;
        } else {
            return;
        }
    }
    if (L2_flame < 15) return;
    if (WorkingFlg) {
        this.Adv_L2_WorkingUpdate(_訓練Flg); 
        return;
    }
    let _MvFlg = false;
    if (Input.isTriggered('left')) {
        L2Select_Cng();
        _MvFlg = true;
    }
    if (Input.isTriggered('right')) {
        L2Select_Cng();
        _MvFlg = true;
    }
    let _CNo = overPicClickable(PN_tCkWin, kakuCBMArr);
    if (_CNo != -1 && L2Select != _CNo) {
        L2Select = _CNo;
        _MvFlg = true;
    }
    if (_MvFlg) {
        SoundManager.playCursor();
        this.MovePict(PN_AdvSell, YNPos[L2Select]._x, YNPos[L2Select]._y, 5);
    }
    let _closeFlg = false;
    if (_yn_flame > 5) {
        if (Input.isTriggered('ok') || ((_CNo != -1) && TouchInput.isTriggered())) { 
            if (L2Select == 0) { 
                SoundManager.playOk();
                console.log("仕事選択：はい");
                this.MovePict(PN_KunrenFree, true, true, 5, 0);
                this.MovePict(PN_KunrenFreeTxt, true, true, 5, 0);
                this.Adv_L2_WorkingView(_訓練Flg); 
                this.SetCmnEventSc(CN_仕事訓練挑戦時);
            }
            if (L2Select == 1) { 
                SoundManager.playCancel();
                _closeFlg = true;
            }
        }
        if (Input.isTriggered('escape') || TouchInput.isCancelled()) { 
            SoundManager.playCancel();
            _closeFlg = true;
        }
        if (_closeFlg) {
            if (!_訓練Flg) {
                this.Adv_L2_WorkClose();
                this.Adv_L1Work_Draw();
            }
            if (_訓練Flg) {
                this.Adv_L2_KunrenClose();
                this.Adv_L1Kunren_Draw();
            }
        }
    }
    _yn_flame++;
}
const PN_AsBase = PN_Layer1 + 5; 
const PN_AsTxt = PN_AsBase + 1; 
const PN_AsGage_wb = PN_AsTxt + 4; 
const PN_AsGage = PN_AsGage_wb + 5; 
const PN_AsCBack = PN_AsGage + 5; 
const PN_AsHart = PN_AsCBack + 5; 
const PN_AsBackBtn = PN_AsHart + 5; 
const PN_AsOneBtn = PN_AsBackBtn + 1; 
const PN_AsHint = PN_AsOneBtn + 2; 
const SW_CView_Flg = 61; 
const VN_C好感Flg = 61;  
const CN_As遊び = 25; 
let _Const遊びArr = [
    ["Rury", "Hang out with Rury"],
    ["Eve", "Hang out with Eve"],
    ["Rebekka", "Hang out with Rebekka"],
    ["Kotaro", "Hang out with Kotaro"],
    ["Marcus", "Hang out with Marcus"]
];
let _AsTcPic = []; 
let _Asobi_Game_System_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function () { 
    _Asobi_Game_System_initialize.call(this);
    this._遊び説明Arr = _Const遊びArr;  
};
let _AsSelArr = [false, false, false, false, false]; 
const L1AsobiPic = "pictures/Adv/L1_Asobi/"; 
const AsobiBtnZureX = 155;
const SW_ルーリー遊び4 = 304;
const SW_売春経験済 = 333;
Game_Interpreter.prototype.Adv_L1AsobiView = function () {
    L1_Selecter = 0;
    _BefAsobi_TxtNo = -1;
    this.SetPictFIn(PN_AsBase, L1AsobiPic + "PN_AsBase", 0, 0, 0, 0, 15);
    let _posX = 350;
    let _posY = 97;
    _AsTcPic = [];
    for (let i = 0; i <= 5 - 1; i++) {
        if ($gameSwitches.value(SW_CView_Flg + i)) {
            this.SetPictFIn(PN_AsCBack + i, L1AsobiPic + "PN_AsCBack_" + (i + 1), _posX + (AsobiBtnZureX * i), _posY, 0, 0, 15);
            this.SetPictB(PN_AsGage_wb + i, L1AsobiPic + "PN_AsGage_wb", _posX + 3 + (AsobiBtnZureX * i), _posY + 394, 0);
            this.MovePict(PN_AsGage_wb + i, true, true, 15, 255, true, true);
            this.SetPictB(PN_AsGage + i, L1AsobiPic + "PN_AsGage", _posX + 3 + (AsobiBtnZureX * i), _posY + 394, 0, 100, $gameVariables.value(VN_C好感Flg + i));
            this.MovePict(PN_AsGage + i, true, true, 15, 255, true, true);
            let _好感度 = $gameVariables.value(VN_C好感Flg + i);
            this.SetPicStrC(PN_AsHart + i, _好感度 + " ", 25, _posX + (AsobiBtnZureX * i) + 71, _posY + 369, 0);
            this.MovePict(PN_AsHart + i, true, true, 15, 255, true, true);
            _AsSelArr[i] = true;
            _AsTcPic.push(PN_AsCBack + i);
            if (i == 0 && $gameSwitches.value(SW_ルーリー遊び4)) { 
                if (!$gameSwitches.value(SW_売春経験済)) {
                    this.SetPictFIn(PN_AsHint, L1AsobiPic + "PN_AsHint1", 0, 0, 0, 0, 15);
                }
            }
        } else {
            _AsSelArr[i] = false;
        }
    }
    this.Adv_L1Asobi_TxtDraw(); 
/*    this.SetPictFIn(PN_AsOneBtn, L1AsobiPic + "PN_AsOneBtn", 1019, 496, 0, 0, 15);
    _AsTcPic.push(PN_AsOneBtn);*/
    this.MovePict(PN_AdvSell, _posX + (AsobiBtnZureX * L1_Selecter), _posY + 427, 5);
    this.JN_EventLoad("遊び選択", true); 
}
let _BefAsobi_TxtNo = -1;
Game_Interpreter.prototype.Adv_L1Asobi_TxtDraw = function () {
    if ($gameSystem._遊び説明Arr == undefined) {
        $gameSystem._遊び説明Arr = _Const遊びArr;
    }
    if (_BefAsobi_TxtNo != L1_Selecter) {
        D_Text_Cng_font = "Makinas"; 
        this.SetPicStr(PN_AsTxt + 0, SCol.Blk0 + $gameSystem._遊び説明Arr[L1_Selecter][0], 25, 341, 648, 0);
        this.MovePict(PN_AsTxt + 0, true, true, 15, 255, true, true);
        this.SetPicStr(PN_AsTxt + 1, SCol.Blk0 + $gameSystem._遊び説明Arr[L1_Selecter][1], 25, 341, 648 + 40, 0);
        this.MovePict(PN_AsTxt + 1, true, true, 15, 255, true, true);
        D_Text_Cng_font = ""; 
        _BefAsobi_TxtNo = L1_Selecter;
    }
}
Game_Interpreter.prototype.Adv_L1Asobi_Update = function () {
    let _MvFlg = false;
    if (Input.isTriggered('left')) {
        _MvFlg = true;
        while (true) {
            L1_Selecter--;
            if (L1_Selecter < 0) L1_Selecter = _AsSelArr.length - 1;
            if (_AsSelArr[L1_Selecter]) break;
        }
    }
    if (Input.isTriggered('right')) {
        _MvFlg = true;
        while (true) {
            L1_Selecter++;
            if (L1_Selecter >= _AsSelArr.length) L1_Selecter = 0;
            if (_AsSelArr[L1_Selecter]) break;
        }
    }
    if (L1_Selecter < 0) L1_Selecter = _AsSelArr.length - 1;
    if (L1_Selecter >= _AsSelArr.length) L1_Selecter = 0;
    let _CNo = overPointerCkArr(_AsTcPic);
    if (_CNo != -1) {
        L1_Selecter = _CNo - PN_AsCBack;
        if (_CNo == PN_AsOneBtn) L1_Selecter = 5;
        _MvFlg = true;
    }
    if (_MvFlg) {
        this.Adv_L1Asobi_TxtDraw();
        let _posX = 350;
        let _posY = 97;
        if (L1_Selecter < 5) {
            this.MovePict(PN_AdvSell, _posX + (AsobiBtnZureX * L1_Selecter), _posY + 427, 5);
        }
        if (L1_Selecter == 5) {
            this.MovePict(PN_AdvSell, 1004, _posY + 427, 5);
        }
    }
    if (Input.isTriggered('ok') || ((_CNo != -1) && TouchInput.isTriggered())) {
        SoundManager.playOk();
        Adv_Layer = 2; 
        this.Adv_L2_Cng(_L2Mode.Asobi);
    }
    if (Input.isTriggered('escape') || TouchInput.isCancelled()) { 
        SoundManager.playCancel();
        this.Adv_L0_Back();
        this.Move_Api255_KTkt();
    }
}
let _l2Asobi_flame = 0;
Game_Interpreter.prototype.Adv_L2Asobi_View = function () {
    D_Text_Cng_font = "Makinas"; 
    _l2Asobi_flame = 0;
    this.SetPict(PN_tCkBack, "Black", 0, 0, 0);
    this.MovePict(PN_tCkBack, true, true, 15, 80);
    this.SetPictFIn(PN_tCkWin, AdvPic + "KakuninWin", 0, 0, 0, 0, 15);
    L2Select = 0;
    this.MovePict(PN_AdvSell, YNPos[0]._x, YNPos[0]._y, 5);
    let _遊びTxt = "";
    if (L1_Selecter < 5) {
        _遊びTxt = "Hang out with " + $gameSystem._遊び説明Arr[L1_Selecter][0] + "?"
    }
    if (L1_Selecter == 5) {
        _遊びTxt = "Play alone?"
    }
    this.SetPicStrC(PN_tCkTxt + 0, _遊びTxt, 30, 710, 245, 0);
    this.MovePict(PN_tCkTxt + 0, true, true, 5);
    D_Text_Cng_font = ""; 
}
Game_Interpreter.prototype.Adv_L2Asobi_Update = function () {
    let _MvFlg = false;
    if (Input.isTriggered('left')) {
        L2Select_Cng();
        _MvFlg = true;
    }
    if (Input.isTriggered('right')) {
        L2Select_Cng();
        _MvFlg = true;
    }
    let _CNo = overPicClickable(PN_tCkWin, kakuCBMArr);
    if (_CNo != -1 && L2Select != _CNo) {
        L2Select = _CNo;
        _MvFlg = true;
    }
    let _posX = 350;
    let _posY = 97;
    if (Input.isTriggered('escape') || TouchInput.isCancelled()) { 
        SoundManager.playCancel();
        this.Adv_L1_Back();
        this.MovePict(PN_AdvSell, _posX + (AsobiBtnZureX * L1_Selecter), _posY + 427, 5);
    }
    if (Input.isTriggered('ok') || ((_CNo != -1) && TouchInput.isTriggered())) { 
        if (L2Select == 0) { 
            SoundManager.playOk();
            this.JN_EventLoad("遊びC" + (L1_Selecter + 1), true); 
            Adv_Stop = true;
            Adv_Layer = L0_flame = 0;
            this.Adv_PicDel();
        }
        if (L2Select == 1) { 
            SoundManager.playCancel();
            this.Adv_L1_Back();
            this.MovePict(PN_AdvSell, _posX + (AsobiBtnZureX * L1_Selecter), _posY + 427, 5);
        }
    }
    if (_MvFlg) {
        this.MovePict(PN_AdvSell, YNPos[L2Select]._x, YNPos[L2Select]._y, 5);
    }
}
let WorkingFlg = false; 
let WorkingOk_PushCnt = 0; 
let Working_flame = 0;
let WWinPos = new Pos2D(341, 64);
const _INo_訓練無料券 = 10;
Game_Interpreter.prototype.Adv_L2_WorkingView = function (_訓練Flg) {
    _訓練Flg = typeof _訓練Flg !== 'undefined' ? _訓練Flg : false;
    let _PicPath = L1WorkPic;
    if (_訓練Flg) {
        _PicPath = L1KunrenPic;
    }
    WorkingFlg = true;
    WorkingOk_PushCnt = 0;
    Working_flame = 0;
    this.SetPictFIn(PN_tWorkBase, _PicPath + "PN_tBase", 0, 0, 0, 0, 15);
    let _ckImg = _Sel_WorkData._BtnImg + "_Ck";
    this.SetPictFIn(PN_tWorkWin, _PicPath + _ckImg, WWinPos._x, WWinPos._y, 0, 0, 15);
    this.MovePict(PN_AdvSell, true, true, 10, 0); 
    _ViewStCnt = 0; 
    _ViewStFlg = false; 
    _ViewCSkills = [];
    _NowGold = 0; 
    _GainGold = 0; 
    if ($gameParty.hasItem($dataItems[_INo_訓練無料券])) {
    }
}
let _ViewStCnt = 0; 
let _ViewStFlg = false; 
let _ViewCSkills = [];
let _NowGold = 0; 
let _GainGold = 0; 
let _コモンデータセッティングFlg = false;
let _Work_成功Flg = false;
let _WorkSexFlg = false;
let _Working_Stop = false;
let _WorkNo = -1;
const VN_仕事セクハラ変数 = 481;
Game_Interpreter.prototype.Adv_L2_WorkingUpdate = function (_訓練Flg) {
    Other_Voice_OffFlg = true;
    _訓練Flg = typeof _訓練Flg !== 'undefined' ? _訓練Flg : false;
    let _PicPath = L1WorkPic;
    if (_訓練Flg) _PicPath = L1KunrenPic;
    if (_Working_Stop) return;
    Working_flame++;
    if (!_コモンデータセッティングFlg) {
        _コモンデータセッティングFlg = true;
    }
    switch (WorkingOk_PushCnt) {
        case 0: 
            if (Working_flame > 30 && (Input.isTriggered('ok') || TouchInput.isTriggered())) {
                SoundManager.playOk();
                this.SetPict(PN_Ensyutu, "White", 0, 0, 255);
                this.MovePict(PN_Ensyutu, 0, 0, 30, 0);
                _Work_成功Flg = true;
                _WorkSexFlg = false;
                _WorkNo = -1;
                if (_Sel_WorkData._BtnImg.indexOf("Work") != -1) {
                    _WorkNo = Number(_Sel_WorkData._BtnImg.replace("Work" , ""));
                }
                if (Math.random() * 100 < _Work成功率) {
                    _Work_成功Flg = true;
                    let sexyFlg = false;
                    let setX = WWinPos._x;
                    let setY = WWinPos._y;
                    let _ckImg = _Sel_WorkData._BtnImg + "_Ok";
                    if ($gameSwitches.value(SW_セクハラ許可)) {
                        _WorkSexFlg = true;
                        var getVn = $gameVariables.value(VN_仕事セクハラ変数 + _WorkNo);
                        if (getVn > 0) {
                            sexyFlg = true;
                            setX = 0; setY = 0;
                            this.DelPict(PN_tWorkBase);
                            if (getVn > 3) getVn = 3;
                            _ckImg = _Sel_WorkData._BtnImg + "_Sex" + getVn;
                        }
                    }
                    this.SetPictFIn(PN_tWorkWin, _PicPath + _ckImg, setX, setY, 0, 0, 5);
                    this.SetPictFIn(PN_tWorkKek, _PicPath + "Success", 0, 0, 0, 0, 15);
                    this.SetCmnEventSc(CN_仕事訓練後_成功);
                } else {
                    _Work_成功Flg = false;
                    let _ckImg = _Sel_WorkData._BtnImg + "_Miss";
                    this.SetPictFIn(PN_tWorkWin, _PicPath + _ckImg, WWinPos._x, WWinPos._y, 0, 0, 5);
                    this.SetPictFIn(PN_tWorkKek, _PicPath + "Failure", 0, 0, 0, 0, 15);
                    this.SetCmnEventSc(CN_仕事訓練後_失敗);
                }
                Working_flame = 0;
                WorkingOk_PushCnt++;
            }
            break;
        case 1: 
            if (Working_flame == 2) {
                _ViewCSkills = []; 
                for (let i = 0; i <= _Sel_WorkData._CSkills.length - 1; i++) {
                    if (_Sel_WorkData._CSkills[i]._St != _St.健康) {
                        _Sel_WorkData._CSkills[i]._UpVar = _Sel_WorkData._CSkills[i]._Var;
                        if (!_Work_成功Flg) { 
                            _Sel_WorkData._CSkills[i]._UpVar = Math.floor(_Sel_WorkData._CSkills[i]._Var / 2);
                        }
                        _ViewCSkills.push(_Sel_WorkData._CSkills[i]);
                    }
                }
                _GainGold = 0; 
                if (_訓練Flg) {
                    _GainGold = _Sel_WorkData._Gold;
                    if ($gameParty.numItems($dataItems[_INo_訓練無料券]) > 0) {
                        _GainGold = 0;
                        $gameParty.loseItem($dataItems[_INo_訓練無料券], 1);  
                    }
                    _UpVar = Math.floor(_GainGold * ((100 - $gameVariables.value(VN_訓練割引)) / 100));
                    _GainGold = _UpVar;
                } else {
                    if (_Work_成功Flg) _GainGold = _Sel_WorkData._Gold; 
                }
            }
            if (Working_flame > 30 && (Input.isTriggered('ok') || TouchInput.isTriggered())) {
                SoundManager.playOk();
                WorkingOk_PushCnt++;
                this.MovePict(PN_tWorkKek, 0, 0, 30, 0); 
                this.SetPict(PN_twResultBack, _PicPath + "PN_twResultBack", 0, 0, 0);
                this.MovePict(PN_twResultBack, 0, 0, 15);
                Working_flame = _ViewStCnt = 0;
                _ViewStFlg = false;
                _ViewCSkills.push(new _CSkill(_St.お金, _GainGold));
                let _健康 = $gameVariables.value(VN_PLKenko) + _Sel_WorkData._Kenk;
                if (_健康 < 0) _健康 = 0;
                $gameVariables.setValue(VN_PLKenko, _健康);
                this.MovePict(PN_tGage + 1, true, true, 15, 0, true, true);
                let _やる気 = $gameVariables.value(VN_PLYruki) + _Sel_WorkData._Yrki;
                this.MovePict(PN_tGage_s + 1, true, true, 15, 0, true, true);
                if (_やる気 < 0) _やる気 = 0;
                if (_やる気 > 100) _やる気 = 100;
                $gameVariables.setValue(VN_PLYruki, _やる気);
            }
            break;
        case 2: 
            D_Text_Cng_font = "Makinas"; 
            if (Working_flame == 1 && !_ViewStFlg) {
                let _SetTxt = "";
                let _SelSt = _ViewCSkills[_ViewStCnt]._St;
                let _UpVar = _ViewCSkills[_ViewStCnt]._UpVar;
                if (_UpVar >= 0) _UpVar = "+" + _UpVar;
                let _VN_No = -1;
                switch (_SelSt) {
                    case _St.淫乱度:
                        _SetTxt = "Lewdness  ";
                        _VN_No = VN_PLInran;
                        break;
                    case _St.体力:
                        _SetTxt = "Stamina  ";
                        _VN_No = VN_PLHp;
                        break;
                    case _St.攻撃:
                        _SetTxt = "Attack  ";
                        _VN_No = VN_PLAtk;
                        break;
                    case _St.防御:
                        _SetTxt = "Defense  ";
                        _VN_No = VN_PLDef;
                        break;
                    case _St.命中:
                        _SetTxt = "Accuracy  ";
                        _VN_No = VN_PLHit;
                        break;
                    case _St.回避:
                        _SetTxt = "Evasion  ";
                        _VN_No = VN_PLkaihi;
                        break;
                    case _St.直感:
                        _SetTxt = "Intuition  ";
                        _VN_No = VN_PLYomi;
                        break;
                }
                if (_VN_No != -1) {
                    _SetTxt += _UpVar + "(";
                    var ckStr = PL_StateGet(); 
                    var baseValue = 0;
                    switch (_SelSt) {
                        case _St.淫乱度:
                            baseValue = $gameVariables.value(_VN_No);
                            break;
                        case _St.体力: baseValue = ckStr[0]; break;
                        case _St.攻撃: baseValue = ckStr[1]; break;
                        case _St.防御: baseValue = ckStr[2]; break;
                        case _St.命中: baseValue = ckStr[3]; break;
                        case _St.回避: baseValue = ckStr[4]; break;
                        case _St.直感: baseValue = ckStr[5]; break;
                    }
                    _SetTxt += baseValue + "→" + (baseValue + _ViewCSkills[_ViewStCnt]._UpVar) + ")";
                    $gameVariables.setValue(_VN_No, $gameVariables.value(_VN_No) + _ViewCSkills[_ViewStCnt]._UpVar);
                } else {
                    _UpVar = _GainGold;
                    if (_訓練Flg) {
                        _訓練チュートリアルFlg = false; 
                    }
                    if (_UpVar >= 0) _UpVar = "+" + _UpVar;
                    _SetTxt = "Money  " + _UpVar + "(";
                    _SetTxt += $gameParty._gold + "→";
                    $gameParty._gold += _GainGold;
                    _SetTxt += $gameParty._gold + ")";
                }
                this.Adv_情報_MojiDraw();
                let _XPos = 338 + (_ViewStCnt % 2) * 410;
                let _YPos = 620 + Math.floor(_ViewStCnt / 2) * 64;
                this.SetPicStr(PN_twResTxt + _ViewStCnt, _SetTxt, 30, _XPos, _YPos - 30, 0);
                this.MovePict(PN_twResTxt + _ViewStCnt, _XPos, _YPos, 15);
                _ViewStCnt++;
            }
            if (Working_flame == 30 && _ViewStCnt < _ViewCSkills.length) {
                Working_flame = 0;
                break;
            }
            if (Working_flame > 60 + 20 && (Input.isTriggered('ok') || TouchInput.isTriggered())) {
                SoundManager.playOk();
                Adv_Layer = 0;
                WorkingFlg = false; 
                Other_Voice_OffFlg = false;
                this.SetCmnEventSc(CN_日付変更); 
            }
            D_Text_Cng_font = ""; 
            break;
    }
}
Game_Interpreter.prototype.SetVN_Span = function (_StartNo, _EndNo, _Var) {
    for (let i = _StartNo; i <= _EndNo; i++) {
        $gameVariables.setValue(i, _Var)
    }
}
const VN_WorkCk = 309; 
Game_Interpreter.prototype.Work_CkSkillSet = function (_WorkStr) {
    _ViewCSkills = []; 
    if (_WorkStr.indexOf("Work") != -1) { 
        for (let i = 0; i <= ADV_WorkData.length - 1; i++) {
            if (ADV_WorkData[i]._BtnImg == _WorkStr) {
                _Sel_WorkData = ADV_WorkData[i].Copy();
            }
        }
    } else {
        for (let i = 0; i <= ADV_KunrenData.length - 1; i++) {
            if (ADV_KunrenData[i]._BtnImg == _WorkStr) {
                _Sel_WorkData = ADV_KunrenData[i].Copy();
            }
        }
    }
    _Sel_WorkData._Gold = _Sel_WorkData._Kenk = _Sel_WorkData._Yrki = 0;
    let _Set確立 = $gameVariables.value(VN_WorkCk);
    if (_Set確立 > 100) _Set確立 = 99;
    _Sel_WorkData._成功確立 = _Set確立;
    _Sel_WorkData._CSkills = [];
    for (let i = VN_WorkCk + 1; i <= VN_WorkCk + 10; i++) {
        let _ckVar = i - VN_WorkCk - 1;
        if ($gameVariables.value(i) == 0) continue;
        switch (_ckVar) {
            case 0: 
                _Sel_WorkData._CSkills.push(new _CSkill(_St.体力, $gameVariables.value(i)));
                break;
            case 1: 
                _Sel_WorkData._CSkills.push(new _CSkill(_St.攻撃, $gameVariables.value(i)));
                break;
            case 2: 
                _Sel_WorkData._CSkills.push(new _CSkill(_St.防御, $gameVariables.value(i)));
                break;
            case 3: 
                _Sel_WorkData._CSkills.push(new _CSkill(_St.命中, $gameVariables.value(i)));
                break;
            case 4: 
                _Sel_WorkData._CSkills.push(new _CSkill(_St.回避, $gameVariables.value(i)));
                break;
            case 5: 
                _Sel_WorkData._CSkills.push(new _CSkill(_St.直感, $gameVariables.value(i)));
                break;
            case 6: 
                _Sel_WorkData._Gold = $gameVariables.value(i);
                break;
            case 7: 
                _Sel_WorkData._CSkills.push(new _CSkill(_St.淫乱度, $gameVariables.value(i)));
                break;
            case 8: 
                _Sel_WorkData._Kenk = $gameVariables.value(i);
                break;
            case 9: 
                _Sel_WorkData._Yrki = $gameVariables.value(i);
                break;
        }
    }
    if (_WorkStr.indexOf("Work") != -1) { 
        for (let i = 0; i <= ADV_WorkData.length - 1; i++) {
            if (ADV_WorkData[i]._BtnImg == _WorkStr) {
                ADV_WorkData[i] = _Sel_WorkData;
            }
        }
    } else {
        for (let i = 0; i <= ADV_KunrenData.length - 1; i++) {
            if (ADV_KunrenData[i]._BtnImg == _WorkStr) {
                ADV_KunrenData[i] = _Sel_WorkData;
            }
        }
    }
}
Game_Interpreter.prototype.Adv_L2_WorkClose = function () {
    this.Adv_L1_Back(); 
    this.Adv_L1Work_Update(true); 
}
Game_Interpreter.prototype.Adv_L2_KunrenClose = function () {
    this.Adv_L1_Back(); 
    this.Adv_L1Kunren_Update(true); 
}
