let befSelectCardPicNo = -1; 
let btlTargetSelectFlame = 0;
let btlWaitFlame = 0; 
let btl操作不能Flame = 0; 
let btlStopFlg = false; 
let btlDeckViewFlg = false; 
let spainWaitAnimeFlame = 0; 
let btlLive2DMtnStopFlame = 0;
let btlSpineFstLoadFlg = false;
let BtlBef羞恥SwValue = false;
const CardNo_羞恥 = 174; 
const SW羞恥 = 1380; 
Game_Interpreter.prototype.Btl羞恥CardAddUpdate = function () {
    // if ($gameSwitches.value(SW羞恥) && !BtlBef羞恥SwValue) {
    //     this.DeckHandAdd(CardNo_羞恥, 1, true); //手札に羞恥カードを追加
    // BtlBef羞恥SwValue = $gameSwitches.value(SW羞恥);
}
Game_Interpreter.prototype.Btl羞恥AddHand = function () {
    if (!BtlBef羞恥SwValue) {
        BtlBef羞恥SwValue = true;
        this.DeckHandAdd(CardNo_羞恥, 1, true); 
    }
}
Game_Interpreter.prototype.BtlDeckErrorCheck = function () {
}
let autoCoolFrame = 0;
Game_Interpreter.prototype.BtlUpdate = function () {
    this.BtlDeckErrorCheck(); 
    if (btlLive2DMtnStopFlame > 0) {
        btlLive2DMtnStopFlame--;
        return;
    }
    if (this.IsBtlSetupLoading()) return; 
    this.DmgEffectUpdate(); 
    if (this.CardDrawUpdate()) return; 
    this.BtlEnemy行動SW_Update();      
    this.Btlエロ行動制御SW_Update();     
    if (IsSpineLoading()) return;     
    if (NPlayer.length == 0) return;  
    this.CheckWinOrLose();  
    this.BtlTCSetting();    
    this.BtlUiDraw();       
    this.CardEffectUpdate(); 
    this.SkillLogUpdate();  
    this.BtlLive2DUpdate(); 
    this.BtlSpineUpdate();  
    this.SeikanUpdate();    
    this.BtlEnemyActionUpdate();  
    this.BtlBitUpdate();    
    this.BtlEnemyStateCheck_Update(); 
    this.Btl羞恥CardAddUpdate(); 
    this.BtlAutoBtnTouch();     
    if (btlWaitFlame >= 0) { 
        btlWaitFlame--;
        if (waitCmnStartNo != -1) {
            this.SetCmnEventSc(waitCmnStartNo); 
            waitCmnStartNo = -1;
        }
        return;
    }
    if (this.BtlTalkDialogUpdate()) return; 
    if (this.BtlCardSelectionUpdate()) return; 
    if (CardEffectStac.length > 0 || CardEffectViewStac.length > 0) return;   
    if (EnemyDmgStac.length > 0) return;    
    if (BtlData.Mode != EnBtlMode.TurnCheck) {
        if (this.BtlEventUpdate()) return; 
    }
    if (this.BtlItemUseUpdate()) return;  
    if (this.BtlOtherUpdate()) return;  
    if (btlStopFlg) return; 
    if (btlUiOffFlg) return; 
    if (Btl毎ターンCmnPlay中) return;   
    if (_射精欲EvStopFlg) return;
    switch (BtlData.Mode) { 
        case EnBtlMode.PLTurnSetup: 
            this.BtlPLTurnSetup_Update();
            break;
        case EnBtlMode.CardSelect: 
            this.ActiveTouchUIUpdate();     
            if (btlDeckViewFlg) {
                if (this.Deck一覧Update()) btlDeckViewFlg = false;
            } else {
                this.SetTarget();
                if (btl操作不能Flame <= 0) { 
                    this.UISelectUpdate();  
                    this.BtlCardSelect_Update(); 
                    this.TurnEndBtnUIUpdate();  
                    this.BtlItemBtnUpdate();    
                }
            }
            break;
        case EnBtlMode.CardUse: 
            this.BtlCardUse_Update();
            break;
        case EnBtlMode.TurnCheck: 
            this.BtlTurnCheck_Update();
            break;
        case EnBtlMode.EnemyTurn: 
            this.BtlEnemyTurn_Update();
            break;
        case EnBtlMode.Event: 
            break;
        case EnBtlMode.End: 
            this.BtlEnd_Update();
            break;
    }
    if (btl操作不能Flame > 0) btl操作不能Flame--; 
}
class BtlCardDraw_Class {
    constructor() {
        this.CardSetting_Stac = 0;
        this.CardDrawWait = 0;
    }
}
let BtlCardDraw = new BtlCardDraw_Class();
let AddCardDrawStac = function () {
    BtlCardDraw.CardSetting_Stac++;
}
Game_Interpreter.prototype.CardDrawUpdate = function () {
    if (BtlCardDraw.CardSetting_Stac > 0 && BtlCardDraw.CardDrawWait == 0) {
        BtlCardDraw.CardDrawWait = 5;
        if (CardData.length < BtlStatic._手札最大枚数) { 
            this.CardDrawSetting();
            this.CardDrawMove();
            BtlCardDraw.CardSetting_Stac--;
        } else {
            this.CardDrawSetting();
            BtlCardDraw.CardSetting_Stac = 0;
        }
    }
    if (BtlCardDraw.CardDrawWait > 0) {
        BtlCardDraw.CardDrawWait--;
        return true; 
    }
    return false;
}
let B戦闘復活Flg = false;
let B戦闘復活Count = 0;
Game_Interpreter.prototype.CheckWinOrLose = function () {
    if (BtlData.Mode != EnBtlMode.End) {
        WinSetFlg = true;
        for (let i = 0; i <= NEnemy.length - 1; i++) { 
            if (NEnemy[i]._hp > 0) {
                WinSetFlg = false; 
            }
        }
        if (!WinSetFlg) {
            if (NPlayer[0]._hp <= 0) { 
                NPlayer[0]._hp = 0;
                if (!$gameSwitches.value(SW_戦闘HP0復活)) {
                    LoseSetFlg = true;
                } else {
                    if (!B戦闘復活Flg) {
                        B戦闘復活Count++;
                        this.SetSpineAnime(PN_CharacterPL, "Down", false); 
                        this.SetCmnEvent(CN_戦闘時HP0復活演出);
                        B戦闘復活Flg = true;
                    }
                }
            }
        }
        if (WinSetFlg) { 
            this.ChangePhase_EndBtl();
            return;
        }
        if (LoseSetFlg) {
            if (!this.IsPlayerメタル化()) this.SetSpineAnime(PN_CharacterPL, "Down", false);
            this.ChangePhase_EndBtl();
        }
    }
}
Game_Interpreter.prototype.B戦闘復活_処理停止 = function () {
    btlWaitFlame = 999999; 
}
Game_Interpreter.prototype.B戦闘復活_全回復 = function () {
    NPlayer[0]._hp = NPlayer[0].mhp;
    this.SetSpineAnime(PN_CharacterPL, "Idl", true);
}
Game_Interpreter.prototype.B戦闘復活_処理再開 = function () {
    btlWaitFlame = 0; 
    B戦闘復活Flg = false;
}
Game_Interpreter.prototype.BtlTCSetting = function () {
    if (TurnCard.length == 0) TCDataSetting();
    if (TurnCard[0]._No >= 0) {
        if (TurnCard[0]._No < NEnemy.length) {
            TurnEnemyId = GetEnemyData_ENo(TurnCard[0]._No).id;
        }
    } else {
        TurnEnemyId = -1;
    }
}
let CheckDeckInアクセス = function () {
    for (let i = 0; i < DeckCard.length; i++) {
        if (MetaChecker($dataWeapons[DeckCard[i]] , "アクセス" , false) != false) return true;
    }
    return false;
}
let GetCardNo_DeckInアクセス = function () {
    for (let i = 0; i < DeckCard.length; i++) {
        if (MetaChecker($dataWeapons[DeckCard[i]] , "アクセス" , false) != false) return DeckCard[i];
    }
    return -1;
}
Game_Interpreter.prototype.BtlAutoBtnTouch = function () {
    if ($gameTroop._interpreter.isRunning()) return;
    if (BtlActiveTouchUIUpdateOff) return; 
    this.SpriteCngColor(PN_AutoBtn); 
    if (overPointerSpCkTm(PN_AutoBtn)) {
        this.SpriteCngColor(PN_AutoBtn, [80, 80, 80, 0], 0);
        if (TouchInput.isTriggered() && !LastEffectUISelectUpdate) {
            this.BtlAutoChange(!$gameSystem.BtlAutoFlg); 
            this.MoveSprite(PN_AutoBtn, true, true, 10, 255, 100, 100);
        }
    }
}
Game_Interpreter.prototype.BtlAutoChange = function (value) {
    $gameSystem.BtlAutoFlg = value;
    let setPicPath = BtlPicPath + "AutoBtn";
    if ($gameSystem.BtlAutoFlg) setPicPath = BtlPicPath + "Auto_StopBtn";
    this.CngSprite(PN_AutoBtn , setPicPath);
}
let SetuNoDelFlg = false;
const CNo_DeffCmd = 499;    
let BtlActiveTouchUIUpdateOff = false;
Game_Interpreter.prototype.ActiveTouchUIUpdate = function () {
    if (btlUiOffFlg) return; 
    if (BtlActiveTouchUIUpdateOff) return;
    let _CkArr = [PN_EdBtn];
    if (CheckDeckInアクセス()) { 
        _CkArr.push(PN_ACard);
        this.SpriteCngColor(PN_ACard); 
        AlphaCngSprite(PN_ACard, 255);
        AlphaCngSprite(PN_AWBack, 255);
    } else {
        AlphaCngSprite(PN_ACard, 100);
        AlphaCngSprite(PN_AWBack, 100);
    }
    Alpha0Sprite(PN_SetuWin); 
    if (overPointerSpCkTm(PN_AutoBtn)) {
        this.SetSprite(PN_SetuWin, BtlPicPath + "Setu_AutoBtn", 20, 74);
    }
    let cardSelectedFlg = false;
    for (let i = 0; i <= CardData.length - 1; i++) {
        if (overPointerCkTm(CardData[i].setPNo)) {
            cardSelectedFlg = true;
        }
    }
    SetuNoDelFlg = false;
    _CkArr.push(PN_BCard);
    let _OverId = overPointerSpCkArrTm(_CkArr);
    if (cardSelectedFlg) _OverId = -1; 
    switch (_OverId) {
        case PN_EdBtn: 
            if (BtlData.Mode != EnBtlMode.CardSelect) break; 
            this.SetSprite(PN_SetuWin, BtlPicPath + "Setu_EndBtn", 786, 602);
            break;
        case PN_BCard: 
            SetuNoDelFlg = true;
            if (DefBtnCoolTime <= 0　&& !_PLステート確認(StNo_防御禁止)) {
                this.BCardSetumei_Draw(CNo_DeffCmd , 14 , 500);
                if (TouchInput.isTriggered() && !LastEffectUISelectUpdate) {
                    if (Is防御コマンド使用可能()) {
                        this.PlayBtlDefCommand(); 
                    } else {
                        this.SetPicStrPopC(PN_ExText, SCol.Red + "コストが足りません", 20, 146, 650);
                    }
                }
            }
            break;
    }
    if (!SetuNoDelFlg) {
        this.DelPictSpan(PN_SetuWaku , PN_Setu_End);
    }
}
Game_Interpreter.prototype.PlayBtlDefCommand = function () {
    autoCoolFrame = 5;
    DefBtnCoolTime = 2;
    EnforceCardUseNo = CNo_DeffCmd;
    this.DefBtn_Draw();
}
let skPos = new Pos2D(1337, 180);
Game_Interpreter.prototype.SeikanUpdate = function () {
    if (LastEffectUISelectUpdate) return;
    if (FinalFormFlg) { 
        $gameVariables._data[VN_Seikan] = 0;
    }
    if ($gameVariables._data[VN_Seikan] > 100) {
        $gameVariables._data[VN_Seikan] = 100;
    }
    this.SetSprite(PN_SGWaku, BtlPicPath + "PN_SGWaku", skPos._x, skPos._y);
    this.SetSprite(PN_SGbase, BtlPicPath + "PN_SGbase", skPos._x + 18, skPos._y + 13);
    let seikanValue = $gameVariables._data[VN_Seikan];
    if (battleflg) NPlayer[0]._Seikan = seikanValue; 
    this.SetSprite(PN_SGgage, BtlPicPath + "PN_SGgage", skPos._x + 18, skPos._y + 493, 255, 100, -seikanValue);
    this.SetSprite(PN_SGHart, BtlPicPath + "PN_SGHart", skPos._x - 10, skPos._y - 60);
}
Game_Interpreter.prototype.Btl_RericUpdate = function () {
    this.DelPictSpan(PN_BRSetuWaku, PN_BRSetuWaku + 3);
    let _CNo = overPointerSpCkArr(BtlPLTurn.PicArr);
    if (_CNo != -1) {
        _CNo -= PN_BReric;
        let _ItmNo = $gameSystem.Btl_Chara.RericArr[_CNo];
        this.Btl_レリック_説明描画(_ItmNo, BReric.Pos._x - 487, RericPs._y - 82 - (RericY差 * _CNo));
    }
}
Game_Interpreter.prototype.Btl_レリック_説明描画 = function (_RericId, _PosX, _PosY) {
    _STY_SetuPicNo = PN_BRSetuWaku;
    this.SetPict(_STY_SetuPicNo, BtlPicPath + "PN_RericSetuWin", _PosX, _PosY);
    let _CkArr = $dataItems[_RericId].description.split("\n");
    let _icoNo = $dataItems[_RericId].iconIndex;
    let _NameStr = " " + "\\I[" + _icoNo + "] " + $dataItems[_RericId].name;
    this.SetPicStr(_STY_SetuPicNo + 1, _NameStr, 25, _PosX + 13, _PosY + 15);
    for (let j = 0; j <= _CkArr.length - 1; j++) {
        this.SetPicStr(_STY_SetuPicNo + 2 + j, _CkArr[j], 19, _PosX + 25, _PosY + 26 + (27 * (j + 1)));
    }
    _STY_SetuPicNo = PN_BCSetuWaku;
}
let BtlEventUpdateFrame = 0;
Game_Interpreter.prototype.BtlEventUpdate = function () {
    $gameTroop.setupBattleEvent(); 
    if ($gameTroop._interpreter.isRunning()) {
        $gameTroop.updateInterpreter(); 
        if ($gameTroop._interpreter.isRunning()) { 
            //this.BtlAutoChange(false); //オートモードをOFFにする
        }
    }
    return $gameTroop._interpreter.isRunning();
}
let Nupu_Game_Troop_setupBattleEvent = Game_Troop.prototype.setupBattleEvent;
Game_Troop.prototype.setupBattleEvent = function () {
    if ($gameSwitches.value(SW_BtlLastBoss)) {
        if (BtlData.Mode != EnBtlMode.CardSelect) return;
    }
    Nupu_Game_Troop_setupBattleEvent.call(this);
}
let OtherStopFlg = false;
Game_Interpreter.prototype.BtlOtherUpdate = function () {
    return OtherStopFlg;
}
let _射精欲EvStopFlg = false;
let _射精欲_MaxEmNo = -1;
const I射精撃破Cnt = 10;
Game_Interpreter.prototype.BtlEnemyStateCheck_Update = function () {
    if (_射精欲EvStopFlg) return;
    for (let i = 0; i <= NEnemy.length - 1; i++) { 
        if (NEnemy[i]._hp > 0) { 
            for (let j = 0; j <= NEnemy[i]._NState.length - 1; j++) {
                switch (NEnemy[i]._NState[j]._No) {
                    case StOneType.SyaseiYoku:
                        if (NEnemy[i]._NState[j]._Turn >= I射精撃破Cnt) {
                            _射精欲EvStopFlg = true; 
                            _射精欲_MaxEmNo = i;
                            Syasei撃破Flg = true;
                            this.SetCmnEventSc(CN_射精欲コモン); 
                            return;
                        }
                        break;
                }
            }
        }
    }
}
