class BtlPLTurn_Class {
    constructor() {
        this.endBtnBlinkFlame = 0;
        this.befCardSelectNo = -1; 
        this.endBtnBlink間隔Flame = 80; 
        this.endBtnBlinkColorUpValue = 5; 
    }
}
let BtlPLTurn = new BtlPLTurn_Class();
Game_Interpreter.prototype.ChangePhase_CardSelect = function () { 
    BtlData.Mode = EnBtlMode.CardSelect;
    this._手札常在効果確認();
    _使用禁止ColCng();
}
let DbgCardUseNo = -1;  
let EnforceCardUseNo = -1;  
let EnforceCostZeroFlg = false;
Game_Interpreter.prototype.BtlCardSelect_Update = function () {
    if (LastEffectUISelectUpdate) {
        $gameSystem.BtlAutoFlg = false;
    }
    if (CardSelecter_Endflame > 0) {
        this.CardSelecter_EndUpdate(); 
        return;
    }
    let overPicArr = [];
    let overMax_i = [];
    this._手札常在効果確認();
    for (let i = 0; i <= CardData.length - 1; i++) {
        if (overPointerCkTm(CardData[i].setPNo)) { 
            if (_bef_BtlUISel_OverPicNo != CardData[i].setPNo) {
                _bef_BtlUISel_OverPicNo = CardData[i].setPNo;
            }
            overPicArr.push(CardData[i]); 
            overMax_i.push(i);
        }
    }
    let maxPicNo = -1;
    let max_i = -1;
    for (let i = 0; i <= overPicArr.length - 1; i++) {
        if (maxPicNo < overPicArr[i].setPNo && PL_MouseY < 789) {
            maxPicNo = overPicArr[i].setPNo; 
            UseCard = overPicArr[i];
            max_i = overMax_i[i];
        }
    }
    if (PN_Card + CardData.length - 1 != maxPicNo && maxPicNo != -1) {
        BefSelectNo = -2; 
    }
    if (autoCoolFrame > 0) {
        autoCoolFrame--;
    }
    if (!LastEffectUISelectUpdate) {
        if ($gameSystem.BtlAutoFlg && BtlData.Mode == EnBtlMode.CardSelect && !$gameTroop._interpreter.isRunning()) {
            let useCardFlg = false;
            for (let i = 0; i <= CardData.length - 1; i++) {
                if (CardData[i].Cost <= NPlayer[0]._mp && !CardData[i]._使用禁止) { 
                    maxPicNo = CardData[i].setPNo;
                    UseCard = CardData[i];
                    max_i = i;
                    this.CardSetumei(); 
                    useCardFlg = true;
                    break;
                }
            }
            if (!useCardFlg) {
                if (Is防御コマンド使用可能()) {
                    this.PlayBtlDefCommand(); 
                }
            }
        }
    }
    if (maxPicNo != -1) {
        if (befSelectCardPicNo != maxPicNo) {
            SetTarGet_Reset();
            befSelectCardPicNo = maxPicNo;
        }
        this.CardSelect(maxPicNo);
    }
    if (maxPicNo == PN_Card + CardData.length - 1) {
        this.CardSetumei(); 
    } else {
        BtlPLTurn.befCardSelectNo = -1;
        this.TarGetReset(); 
        this.SetumeiDel();  
    }
    if (BtlActiveTouchUIUpdateOff) return; 
    if (TouchInput.isTriggered() || $gameSystem.BtlAutoFlg || DbgCardUseNo != -1 || EnforceCardUseNo != -1) {
        let _useCardNo = -1;
        if (DbgCardUseNo != -1 || EnforceCardUseNo != -1) {
            if (DbgCardUseNo != -1) {
                _useCardNo = DbgCardUseNo;
                NPlayer[0]._mp = 9; 
            }
            if (EnforceCardUseNo != -1) {
                _useCardNo = EnforceCardUseNo;
            }
            let _setNCard = new Card($dataWeapons[_useCardNo]);
            if (EnforceCostZeroFlg) { 
                _setNCard.Cost = 0;
                EnforceCostZeroFlg = false;
            }
            CardData.push(_setNCard);
            max_i = CardData.length - 1;
            maxPicNo = PN_Card + CardData.length - 1;
            UseCard = CardData[CardData.length - 1];
            this.CardTargetGet(UseCard.CardData);
            DbgCardUseNo = EnforceCardUseNo = -1;
        }
        if (maxPicNo == PN_Card + CardData.length - 1) { 
            if (Number(UseCard.Cost) > NPlayer[0]._mp) {
                this.SetPicStrPopC(PN_ExText, SCol.Red + "コストが足りません", 20, UseCard.XPos, UseCard.YPos - 100);
                return;
            }
            if (CardData[max_i]._使用禁止) {
                this.SetPicStrPopC(PN_ExText, SCol.Red + "使用できません", 20, UseCard.XPos, UseCard.YPos - 100);
                return;
            }
            if (UseCard.Cost != "All") NPlayer[0]._mp -= UseCard.Cost;
            this.TurnEndBtnDraw();
            CardData.splice(max_i, 1);  
            this.DeckMaisuView();   
            this.TarGetReset();     
            BtlPLTurn.befCardSelectNo = -1;
            this.ChangePhase_CardUse();   
            btl操作不能Flame = 10;
            if (_useCardNo != CNo_DeffCmd) {
                btlターン使用カード枚数++;
            }
            if (_手札UseDamage != 0) {
                DmgESet_SkipFlg = true;
                DmgMotionSkipFlg = true;
                SetEnemyDmgStac(DType.Dmg, -1, 15, _手札UseDamage);     
            }
            if (_手札UseSexUp != 0) {
                if ($gameVariables._data[VN_Seikan] == undefined) $gameVariables._data[VN_Seikan] = 0;
                $gameVariables._data[VN_Seikan] = $gameVariables._data[VN_Seikan] + _手札UseSexUp;
                this.TextPopUp_ENo(-1, SCol.Red + "性感値上昇+" + _手札UseSexUp, 24);
            }
        }
        if (!LastEffectUISelectUpdate) {
            if (overPointerSpCk(PN_EdBtn) && !$gameSystem.BtlAutoFlg && maxPicNo == -1) { 
                this.EndBtn_Push();
            }
        }
    }
    if (this.AutoTurnEndCheck() || AutoTurnEndFlg || this.IsPlayerメタル化()) {
        this.EndBtn_Push(); 
        AutoTurnEndFlg = false;
    }
}
let AutoTurnEndFlg = false;
Game_Interpreter.prototype.AutoTurnEndCheck = function (){
    if (autoCoolFrame > 0) return false;
    let _useOkItem無し = true; 
    // if ($gameSystem.AdSysCT.length < btlItemPicArr.length) _useOkItem無し = false;
    // for (let i = 0; i < $gameSystem.AdSysCT.length; i++) {
    //     if ($gameSystem.AdSysCT[i].ct <= 0) {
    return notUseCardFlg && !Is防御コマンド使用可能() && _useOkItem無し;
}
let Is防御コマンド使用可能 = function () {
    return DefBtnCoolTime == 0 && NPlayer[0]._mp >= 1;
}
Game_Interpreter.prototype.CardSelecter_EndUpdate = function () {
    this.BtlBit_PLTurnEnd_Update(); 
    CardSelecter_Endflame--;
    if (CardSelecter_Endflame == 0) {
        this.ChangePhase_TurnChange(); 
    }
}
let BefSelectNo = -2; 
Game_Interpreter.prototype.CardSelect = function (SelectCPNo) {
    if (BefSelectNo == SelectCPNo) return; 
    BefSelectNo = SelectCPNo;
    let Cardxset = HandZureX();
    let selcount = 0; 
    if (SelectCPNo == -1) {
        this.HandKeepGet(); 
    }
    for (let i = 0; i <= CardData.length - 1; i++) {
        if (SelectCPNo == CardData[i].setPNo) {
            CardData[i].selectFlg = true;
        } else {
            CardData[i].selectFlg = false;
        }
    }
    let _cardKakudo = (CardData.length / 2) * -Cardkakudo;
    let inCnt = 0;
    let _SelXZure = 0;
    EasingStr = "easeOutQuad";
    for (let i = 0; i <= CardData.length - 1; i++) {
        CardData[i].XPos = handCardBasePostion._x + (Cardxset * i) + _SelXZure;
        CardData[i].YPos = handCardBasePostion._y + Math.abs(_cardKakudo + (Cardkakudo * i) * 1.2);
        if (CardData[i].selectFlg) { 
            if (i != 0) {
                _SelXZure += 30;
                if (CardData.length >= 9) _SelXZure = 0; 
            }
            CardData[i].XPos += _SelXZure;
            CardData[i].YPos = handCardBasePostion._y - 20;
            CardData[i].setPNo = PN_Card + CardData.length - 1;
            this.PicInObj(CardData[i].setPNo, CardData[i].KeepPicData);
            this.MovePict(CardData[i].setPNo, CardData[i].XPos, CardData[i].YPos, 5, 255, Btl_手札拡大率, Btl_手札拡大率);
            $gameScreen.tintPicture(CardData[i].setPNo, [0, 0, 0, 0], 0);
            selcount = 1;
            _SelXZure += 30;
        } else {
            let ccOpi = 200;
            if (selcount == 0) { 
                CardData[i].setPNo = PN_Card + inCnt;
                this.PicInObj(CardData[i].setPNo, CardData[i].KeepPicData);
                this.MovePict(CardData[i].setPNo, CardData[i].XPos, CardData[i].YPos, 5, ccOpi, Btl_手札拡大率, Btl_手札拡大率);
                $gameScreen.tintPicture(CardData[i].setPNo, [-20, -20, -20, 0], 0);
                inCnt++;
            } else { 
                CardData[i].setPNo = PN_Card + CardData.length - 1 - (selcount);
                this.PicInObj(CardData[i].setPNo, CardData[i].KeepPicData);
                this.MovePict(CardData[i].setPNo, CardData[i].XPos, CardData[i].YPos, 5, ccOpi, Btl_手札拡大率, Btl_手札拡大率);
                $gameScreen.tintPicture(CardData[i].setPNo, [-20, -20, -20, 0], 0);
                selcount++;
            }
        }
        if (!CardData[i].selectFlg) {
            this.AnglePict(CardData[i].setPNo, _cardKakudo + (Cardkakudo * i));
        } else {
            this.AnglePict(CardData[i].setPNo);
        }
        if (CardData[i].MoveAftPtc != "") {
            this.PlayPtcPic(CardData[i].MoveAftPtc, CardData[i].XPos, CardData[i].YPos);
            CardData[i].MoveAftPtc = "";
        }
    }
    for (let i = 0; i < 11; i++) {
        let skipFlg = false;
        for (let j = 0; j < CardData.length; j++) {
            if (PN_Card + i == CardData[j].setPNo) {
                skipFlg = true;
                break;
            }
        }
        if (!skipFlg) this.DelPict(PN_Card + i);
    }
    EasingStr = "";
    _使用禁止ColCng();
}
let SelectTurnCFlg = false;
let btl説明描画Flg = false;
let Btl説明No = null; 
let _bef_BtlUISel_OverPicNo = 0;
let LastEffectUISelectUpdate = false;
Game_Interpreter.prototype.UISelectUpdate = function () {
    if (LastEffectUISelectUpdate) return;
    if ($gameSystem.BtlAutoFlg) return;
    if (btl操作不能Flame > 0) return; 
    let MTCoverFlg = false;
    let STCNo = -2;
    STCNo = this.TCPicOverUpdate(); 
    if (STCNo != null) MTCoverFlg = true;
    btl説明描画Flg = false;
    if (overPointerSpCk(PN_IjoP)) {
        if (_bef_BtlUISel_OverPicNo != PN_IjoP) {
            _bef_BtlUISel_OverPicNo = PN_IjoP;
        } else {
            btl説明描画Flg = true;
            this.IjoSetuViewON(-1);
        }
    }
    if (overPointerSpCk(PN_IjoP_2)) {
        if (_bef_BtlUISel_OverPicNo != PN_IjoP_2) {
            _bef_BtlUISel_OverPicNo = PN_IjoP_2;
        } else {
            btl説明描画Flg = true;
            this.IjoSetuViewON(-1, 5);
        }
    }
    let drawStateIjo = false;
    for (let i = 0; i <= NEnemy.length - 1; i++) {
        if (overPointerSpCk(PN_IjoE + 4 * i)) {
            if (_bef_BtlUISel_OverPicNo != PN_IjoE + 4 * i) {
                _bef_BtlUISel_OverPicNo = PN_IjoE + 4 * i;
            } else {
                btl説明描画Flg = true;
            }
            this.DelSprite(PN_SetuWaku);
            this.DelSpriteSpan(PN_T_Setu , PN_T_Setu + 2);
            this.DelSprite(PN_Setu_End - 1);
            this.IjoSetuViewON(i);
            drawStateIjo = true;
        }
    }
    if (overPointerSpCk(PN_Trash)) {
        if (_bef_BtlUISel_OverPicNo != PN_Trash) {
            _bef_BtlUISel_OverPicNo = PN_Trash;
        } else {
            btl説明描画Flg = true;
            this.BtlDeckNokoriView(false);
        }
    }
    if (overPointerSpCkTm(PN_Deck)) {
        if (_bef_BtlUISel_OverPicNo != PN_Deck) {
            _bef_BtlUISel_OverPicNo = PN_Deck;
        } else {
            btl説明描画Flg = true;
            this.BtlDeckNokoriView(true);
        }
    }
    if (!drawStateIjo) {
        for (let i = 0; i <= NEnemy.length - 1; i++) { 
            if (overPointerSpCk(PN_Character + NEnemy[i]._PicNo) && NEnemy[i]._hp > 0) {
                _bef_BtlUISel_OverPicNo = PN_Character + NEnemy[i]._PicNo;
                MTCoverFlg = true;
                NEnemy[i]._TgtOpi = 255;
                this.DelSpriteSpan(PN_SetuI + 0 , PN_SetuI + 29);
                this.EmStateViews(i);
                btl説明描画Flg = true;
                for (let j = 0; j <= NEnemy.length - 1; j++) {
                    if (i != j) {
                        NEnemy[j]._TgtOpi = 0;
                    }
                }
            }
        }
    }
    this.Btl_RericUpdate();
    if (MTCoverFlg) {
        if (!SelectTurnCFlg) {
            SetTarGet_Reset(); 
        }
        SelectTurnCFlg = true;
    } else {
        SelectTurnCFlg = false;
        Alpha0Sprite(PN_SelTurnC);
    }
}
Game_Interpreter.prototype.EndBtn_Push = function () {
    if (this.EndBtnEvnt()) {
        IsPlayerSelect = false; 
        this.SpriteCngColor(PN_EdBtn);
        this.CardSelecter_EndStart();
    }
    this.SetumeiDel(); 
}
let CardSelecter_Endflame = 0;
Game_Interpreter.prototype.CardSelecter_EndStart = function () {
    _Skill狙撃Dmg = 0; 
    StateSyoriNo = 0;
    stateData = NPlayer[0]._NState;
    for (let j = 0; j < stateData.length; j++) {
        CheckStateData = $dataStates[stateData[j]._No];
        for (let i = 0; i <= CheckStateData.traits.length - 1; i++) {
            let stateDamage = 0;
            switch (CheckStateData.traits[i].dataId) {
                case StType.CelDmg:  
                    this.StateEffectSet(-1);
                    stateDamage = Math.round(stateData[j]._Turn);
                    if (stateDamage > 0) {
                        SetEnemyDmgStac(DType.Dmg, -1, 15, stateDamage);     
                    } else {
                        SetEnemyDmgStac(DType.HpRecv, -1, 15, -stateDamage);  
                    }
                    stateData[j]._Turn--;
                    if (stateData[j]._Turn <= 0) {
                        stateData.splice(j , 1); j--;
                    }
                    break;
            }
        }
        StateSyoriNo++;
    }
    this.BtlBit_PLTurnEnd();
    CardSelecter_Endflame = 5;
}
let notUseCardFlg = false;
let wait_TurnEndBtnUIUpdate = 0;
Game_Interpreter.prototype.TurnEndBtnUIUpdate = function () {
    if (LastEffectUISelectUpdate) return;
    if (wait_TurnEndBtnUIUpdate > 0) {
        wait_TurnEndBtnUIUpdate--;
        return;
    }
    let endBLFlg = true;
    for (let i = 0; i <= CardData.length - 1; i++) {
        if (CardData[i]._使用禁止) continue;
        if (CardData[i].Cost <= 0) endBLFlg = false; 
        if (CardData[i].Cost <= NPlayer[0]._mp) {
            endBLFlg = false;
        }
    }
    if (BtlData.Mode == EnBtlMode.CardUse) endBLFlg = false; 
    if (endBLFlg) {
        notUseCardFlg = true;
        BtlPLTurn.endBtnBlinkFlame++;
        if (BtlPLTurn.endBtnBlinkFlame > BtlPLTurn.endBtnBlink間隔Flame) {
            BtlPLTurn.endBtnBlinkFlame = 0;
        }
        let cVal = 0;
        if (BtlPLTurn.endBtnBlinkFlame > BtlPLTurn.endBtnBlink間隔Flame / 2) {
            cVal = (BtlPLTurn.endBtnBlinkFlame - BtlPLTurn.endBtnBlink間隔Flame / 2) * (BtlPLTurn.endBtnBlinkColorUpValue * 2);
        }
        this.SpriteCngColor(PN_EdBtn,
            [
                BtlPLTurn.endBtnBlinkFlame * BtlPLTurn.endBtnBlinkColorUpValue - cVal,
                BtlPLTurn.endBtnBlinkFlame * BtlPLTurn.endBtnBlinkColorUpValue - cVal,
                BtlPLTurn.endBtnBlinkFlame * BtlPLTurn.endBtnBlinkColorUpValue - cVal
                , 0]);
    } else {
        notUseCardFlg = false;
        this.SpriteCngColor(PN_EdBtn);
    }
    if (overPointerSpCk(PN_EdBtn)) this.SpriteCngColor(PN_EdBtn, [150, 150, 150, 0]);
}
let bef異常ViewNo = null; 
Game_Interpreter.prototype.IjoSetuViewON = function (_ENo, _StZure) {
    _StZure = typeof _StZure !== 'undefined' ? _StZure : 0;
    if (bef異常ViewNo == _ENo) return;
    bef異常ViewNo = _ENo;
    let _Ps = new Pos2D(0, 0);
    let _CkNState = [];
    if (_ENo <= -1) {
        _Ps._x = NPlayer[(_ENo * -1) - 1]._screenX - 39;
        _Ps._y = NPlayer[(_ENo * -1) - 1]._screenY + 103;
        _CkNState = NPlayer[(_ENo * -1) - 1]._NState;
    } else {
        _Ps._x = NEnemy[_ENo]._screenX + NEnemy[_ENo]._bar_x - 51;
        _Ps._y = NEnemy[_ENo]._screenY + (NEnemy[_ENo]._pHeight / 2) + NEnemy[_ENo]._bar_y - 11;
        _CkNState = NEnemy[_ENo]._NState;
    }
    this.IjoSetuDraw(PN_SetuI, _CkNState, _Ps, _StZure);
}
let IjoSetuDraw_下描画Flg = false;
let IjoPicDraw_Flg = false; 
Game_Interpreter.prototype.IjoSetuDraw = function (_PicNo, _CkNState, _Ps, _StZure, _ZPs) { 
    _StZure = typeof _StZure !== 'undefined' ? _StZure : 0;
    _ZPs = typeof _ZPs !== 'undefined' ? _ZPs : new Pos2D(0, 0);
    let _ViewIjoArr = []
    D_Text_Cng_font = "Makinas";
    let _Draw_i = 0;
    for (let i = 0; i <= _CkNState.length - 1 - _StZure; i++) {
        if (_Draw_i == 5) break;
        if (_ViewIjoArr.indexOf(_CkNState[i + _StZure]._No) != -1) continue;
        let _PosX = _Ps._x - 26 + _ZPs._x;
        let _YCngVar = 1;
        if (IjoSetuDraw_下描画Flg) _YCngVar = -1;
        let _PosY = _Ps._y - 65 - (_Draw_i * 88 * _YCngVar) + _ZPs._y;
        if (IjoPicDraw_Flg) {
            this.SetPict(_PicNo + (_Draw_i * 4) + 0, BtlPicPath + "StSetuWin", _PosX, _PosY);
        } else {
            this.SetSprite(_PicNo + (_Draw_i * 4) + 0, BtlPicPath + "StSetuWin", _PosX, _PosY);
        }
        let StateNo = _CkNState[i + _StZure]._No;
        _ViewIjoArr.push(StateNo);
        _CkNState[i + _StZure]._Turn = Math.floor(_CkNState[i + _StZure]._Turn);
        let StateTurn = _CkNState[i + _StZure]._Turn;
        let StateIcoStr = "\\I[" + $dataStates[StateNo].iconIndex + "]";
        let _TurnStr = "（残り" + StateTurn + "ターン）";
        if (StateTurn > 10 || StateTurn == 0 || StateNo == StOneType.Defense || _ZPs._y != 0) {
            _TurnStr = "";
        }
        let SetuStr = StateIcoStr + " \\}" + $dataStates[StateNo].name + _TurnStr;
        if (IjoPicDraw_Flg) this.SetPicStr(_PicNo + (_Draw_i * 4) + 1, SetuStr, 24, _PosX + 6, _PosY + 9);
            else this.SpriteStr(_PicNo + (_Draw_i * 4) + 1, SetuStr, 24, _PosX + 6, _PosY + 9);
        let _SCnt = 0;
        DText_NRZureY = -10; 
        let _異常説明Str = MetaChecker($dataStates[StateNo], "説明", false);
        if (!_異常説明Str) {
            for (let j = 0; j <= $dataStates[StateNo].traits.length - 1; j++) {
                if ($dataStates[StateNo].traits[j].code == 11) {
                    let _SetVar = ($dataStates[StateNo].traits[j].value * 100) - 100;
                    let _SetSer2 = GetStateSetu($dataStates[StateNo].traits[j].dataId, StateTurn, _SetVar, $dataStates[StateNo]);
                    DText_NRZureY = -10;
                    if (IjoPicDraw_Flg) this.SetPicStr(_PicNo + (_Draw_i * 4) + 2 + j, _SetSer2, 16, _PosX + 48, _PosY + 38 + (j * 18));
                        else this.SpriteStr(_PicNo + (_Draw_i * 4) + 2 + j, _SetSer2, 16, _PosX + 48, _PosY + 38 + (j * 18));
                    DText_NRZureY = 0;
                    _SCnt++;
                }
            }
        } else {
            let strArr = _異常説明Str.split("\\n");
            for (let j = 0; j <= strArr.length - 1; j++) {
                if (IjoPicDraw_Flg) this.SetPicStr(_PicNo + (_Draw_i * 4) + 2 + j, strArr[j], 16, _PosX + 48, _PosY + 38 + (j * 18));
                    else this.SpriteStr(_PicNo + (_Draw_i * 4) + 2 + j, strArr[j], 16, _PosX + 48, _PosY + 38 + (j * 18));
            }
        }
        DText_NRZureY = 0; 
        _Draw_i++;
    }
    D_Text_Cng_font = "";
    IjoSetuDraw_下描画Flg = false;
    IjoPicDraw_Flg = false;
}
class DeckCardData {
    constructor(_No, _Cnt) {
        this._No = _No;   
        this._Cnt = _Cnt; 
    }
}
Game_Interpreter.prototype.BtlDeckNokoriView = function (_DeckFlg) {
    _DeckFlg = typeof _DeckFlg !== 'undefined' ? _DeckFlg : true;
    let DeckNokori = []; 
    let DeckViewArr = DeckCard.concat();
    let _BPosX = 10;
    let _BPosY = 386;
    this.SetSprite(PN_SetuWaku, BtlPicPath + "PN_SetuDeckWaku", _BPosX, _BPosY);
    if (!_DeckFlg) { 
        _BPosX = 900;
        _BPosY = 412;
        this.SetSprite(PN_SetuWaku, BtlPicPath + "PN_TrashSetu", _BPosX, _BPosY);
        DeckViewArr = BtlDeck.concat();
        for (let i = 0; i <= DeckCard.length - 1; i++) {
            for (let j = 0; j <= DeckViewArr.length - 1; j++) {
                if (DeckCard[i] == DeckViewArr[j]) {
                    DeckViewArr.splice(j, 1);
                    break; 
                }
            }
        }
        for (let i = 0; i <= CardData.length - 1; i++) {
            for (let j = 0; j <= DeckViewArr.length - 1; j++) {
                if (CardData[i].CardData.id == DeckViewArr[j]) {
                    DeckViewArr.splice(j, 1);
                    break; 
                }
            }
        }
    }
    for (let i = 0; i <= DeckViewArr.length - 1; i++) {
        let newFlg = true;
        for (let j = 0; j <= DeckNokori.length - 1; j++) {
            if (DeckNokori[j]._No == DeckViewArr[i]) {
                DeckNokori[j]._Cnt++;
                newFlg = false;
            }
        }
        if (newFlg) {
            let _inNo = 0;
            for (let j = 0; j <= DeckNokori.length - 1; j++) {
                if (DeckNokori[j]._No > DeckViewArr[i]) {
                    _inNo = j;
                    break;
                }
                _inNo = DeckNokori.length;
            }
            DeckNokori.splice(_inNo, 0, new DeckCardData(DeckViewArr[i], 1)); 
        }
    }
    let setCdstr = "";
    let setNostr = "";
    let CdStrar = []; 
    let NoStrar = []; 
    for (let i = 0; i <= DeckNokori.length - 1; i++) {
        if (DeckNokori[i]._No == -1) {
            DeckNokori.splice(i , 1); i--;
            continue;
        }
        setCdstr += "\\I[" + $dataWeapons[DeckNokori[i]._No].iconIndex + "] ";
        let _piconNo = DeckNokori[i]._Cnt;
        if (_piconNo >= 11) {
            _piconNo = 11;
        }
        let SerIjoTc = _piconNo + Int1IcoNo - 1;
        setNostr += "\\I[" + SerIjoTc + "] ";
        if (i % 5 == 4) {
            CdStrar.push(setCdstr);
            NoStrar.push(setNostr);
            setCdstr = "";
            setNostr = "";
        }
    }
    CdStrar.push(setCdstr);
    NoStrar.push(setNostr);
    for (let i = 0; i <= CdStrar.length - 1; i++) {
        this.SpriteStr(PN_T_Setu + i, CdStrar[i], 25, _BPosX + 18, _BPosY + 33 + (51 * i));
        this.SpriteStr(PN_T_Setu + 5 + i, NoStrar[i], 25, _BPosX + 8, _BPosY + 39 + (51 * i));
    }
    if (TouchInput.isTriggered()) {
        let _SetDeckArr = [];
        DeckNokori.forEach(_DeckDt => {
            for (let i = 0; i <= _DeckDt._Cnt - 1; i++) {
                _SetDeckArr.push(_DeckDt._No);
            }
        });
        if (_DeckFlg) {
            _SetDeckArr.sort(function (a, b) {
                return a - b;
            });
            this.Deck一覧View(PN_CSelBack, _SetDeckArr);
        } else {
            _SetDeckArr.sort(function (a, b) {
                return a - b;
            });
            this.Deck一覧View(PN_CSelBack, _SetDeckArr, "TrashDeckBack");
        }
        btlDeckViewFlg = true;
    }
}
Game_Interpreter.prototype.EmStateViews = function (_ENo) {
    let stEX = NEnemy[_ENo]._screenX + NEnemy[_ENo]._bar_x + 43;
    let stEY = NEnemy[_ENo]._screenY + (NEnemy[_ENo]._pHeight / 2) + NEnemy[_ENo]._bar_y - 110;
    this.SetSprite(PN_SetuWaku, BtlPicPath + "PN_SetuStateWaku", stEX, stEY);
    D_Text_Cng_font = "Makinas";
    let fseSet = "\\ow[3]"
    this.SpriteStr(PN_T_Setu, fseSet + NEnemy[_ENo]._name, 15, stEX + 83, stEY + 25);
    let _AtkStr = String(NEnemy[_ENo].atk).split('').join(' ');
    this.SpriteStr(PN_T_Setu + 1, fseSet + "攻撃力：" + _AtkStr, 15, stEX + 83, stEY + 25 + (23 * 1));
    this.SpriteStr(PN_T_Setu + 2, fseSet + "情報", 15, stEX + 83, stEY + 25 + (23 * 2));
    let _SetStr = MetaChecker(NEnemy[_ENo].enemy(), "StIco", "");
    if (_SetStr != "") {
        let _ckArr = _SetStr.split(',');
        _SetStr = "";
        for (let i = 0; i <= _ckArr.length - 1; i++) {
            _SetStr += "\\I[" + _ckArr[i] + "]";
        }
    }
    this.SpriteStr(PN_T_Setu + 3, _SetStr, 25, stEX + 81, stEY + 96);
    let _SetTCStr = MetaChecker(GetEnemyData_ENo(_ENo), "TCPic" , GetEnemyData_ENo(_ENo).battlerName);
    let tcecount = 0;
    for (let i = 0; i <= 8 - 1; i++) {
        if (TurnCard[i]._No == _ENo) {
            tcecount++;
            _SetTCStr = TurnCard[i]._PicStr;
            this.SetSprite(PN_T_Setu + 3 + tcecount, BtlPicPath + "PN_SelTurnC", 858 + (71 * i), 10);
        }
    }
    this.SetSprite(PN_Cmp, "enemies/TC/" + _SetTCStr, 0, 0, 0);
    this.SetSprite(PN_Setu_End - 1, "enemies/TC/" + _SetTCStr, stEX + 8, stEY + 33);
}
let SetTarGet_Reset = function () {
    btlTargetSelectFlame = 0;
}
Game_Interpreter.prototype.SetTarget = function () {
    btlTargetSelectFlame += 30; 
    if (btlTargetSelectFlame > 100) btlTargetSelectFlame = 100;
    let RockPStr = "";
    if (SelectTurnCFlg) {
        RockPStr = "PN_elRockOn";
    } else {
        RockPStr = "PN_RockOn";
    }
    for (let i = 0; i <= NEnemy.length - 1; i++) { //ターゲット判定処理(エネミー)
        if (NEnemy[i]._hp < 1) {
            continue;
        }
        if (NEnemy[i]._TgtOpi == 0) {
            Alpha0Sprite(PN_RockOn + i);
            continue;
        }
        let _PsX = NEnemy[i]._screenX - 7;
        let _PsY = NEnemy[i]._screenY - 19;
        let _拡大率 = 200 - btlTargetSelectFlame;
        this.SetSpriteC(PN_RockOn + i, BtlPicPath + RockPStr, _PsX, _PsY, NEnemy[i]._TgtOpi, _拡大率, _拡大率);
        SexEmName = "";
    }
    for (let i = 0; i <= NPlayer.length - 1; i++) {
        if (NPlayer[i]._TgtOpi == 0) {
            Alpha0Sprite(PN_RockOnPL + i);
            continue;
        }
        let _PsX = NPlayer[i]._screenX;
        let _PsY = NPlayer[i]._screenY;
        let _拡大率 = 200 - btlTargetSelectFlame;
        this.SetSpriteC(PN_RockOnPL + i, BtlPicPath + RockPStr, _PsX, _PsY, NPlayer[i]._TgtOpi, _拡大率, _拡大率);
    }
}
Game_Interpreter.prototype.TarGetReset = function () {
    if (!SelectTurnCFlg) { 
        for (let i = 0; i <= NPlayer.length - 1; i++) {
            NPlayer[i]._TgtOpi = 0;
        }
        for (let i = 0; i <= NEnemy.length - 1; i++) {
            if (NEnemy[i]._hp < 1) {
                continue;
            }
            NEnemy[i]._TgtOpi = 0;
        }
        for (let i = PN_RockOn; i <= PN_RockOnPL + 3; i++) {
            Alpha0Sprite(i);
        }
    }
}
let _使用禁止ColCng = function () {
    for (let i = 0; i <= CardData.length - 1; i++) {
        if (CardData[i]._使用禁止) {
            $gameScreen.tintPicture(CardData[i].setPNo, [-100, -100, -100, 0], 0);
        } else {
            $gameScreen.tintPicture(CardData[i].setPNo, [0, 0, 0, 0], 0); 
        }
    }
}
Game_Interpreter.prototype._手札PopUp = function (_CNo, _Str, _Size) {
    if (_Turn常時効果ViewArr.indexOf(_Str) == -1) {
        _Turn常時効果ViewArr.push(_Str);
        this.TextPopUp_ENo(_CNo, _Str, _Size);
    }
}
let _手札AtkCng = 0
Game_Interpreter.prototype._手札常在効果確認 = function () {
    _手札AtkCng = 0;
    _手札AtkChange = 0;
    _手札UseDamage = 0;
    _手札UseSexUp = 0;
    _所持3ターン敗北Flg = false;
    _使用禁止CTypeArr = [];
    for (let i = 0; i <= NPlayer[0]._NState.length - 1; i++) {
        switch (NPlayer[0]._NState[i]._No) {
            case STNo_メタル化 : 
                _使用禁止CTypeArr_追加(1);
                _使用禁止CTypeArr_追加(2);
                _使用禁止CTypeArr_追加(3);
                _使用禁止CTypeArr_追加(4);
                _使用禁止CTypeArr_追加(5);
                _使用禁止CTypeArr_追加(6); 
                break;
        }
    }
    for (let i = 0; i <= CardData.length - 1; i++) {
        for (let j = 0; j <= CardData[i].CardData.traits.length - 1; j++) {
            if (CardData[i].CardData.traits[j].code == 43) { 
                let _ckId = CardData[i].CardData.traits[j].dataId;
                switch (_ckId) {
                    case KSkill.攻撃カード使用禁止:
                        _使用禁止CTypeArr_追加(1);
                        _使用禁止CTypeArr_追加(5);
                        break;
                    case KSkill.防御カード使用禁止:
                        _使用禁止CTypeArr_追加(2);
                        break;
                    case KSkill.補助カード使用禁止:
                        _使用禁止CTypeArr_追加(3);
                        break;
                    case KSkill.他カード使用禁止: 
                        _使用禁止CTypeArr_追加(1);
                        _使用禁止CTypeArr_追加(2);
                        _使用禁止CTypeArr_追加(3);
                        _使用禁止CTypeArr_追加(4);
                        _使用禁止CTypeArr_追加(5);
                        break;
                    case KSkill.使用カード枚数制限: 
                        if (btlターン使用カード枚数 >= 4) {
                            _使用禁止CTypeArr_追加(1);
                            _使用禁止CTypeArr_追加(2);
                            _使用禁止CTypeArr_追加(3);
                            _使用禁止CTypeArr_追加(4);
                            _使用禁止CTypeArr_追加(5);
                            _使用禁止CTypeArr_追加(6);
                            this._手札PopUp(-1, SCol.Red + "巨乳：使用カード上限", 24);
                        }
                        break;
                    case KSkill.カード使用ダメージ:
                        _手札UseDamage = 5;
                        break;
                    case KSkill.常時与ダメージ低下:
                        _手札AtkCng -= 5;
                        break;
                    case KSkill.カード使用快感上昇:
                        _手札UseSexUp += 2;
                        break;
                    case KSkill.カード使用快感5上昇:
                        _手札UseSexUp += 5;
                        break;
                    case KSkill.所持3ターン敗北:
                        _所持3ターン敗北Flg = true;
                        break;
                }
            }
        }
    }
    if (!_所持3ターン敗北Flg) {
        this.RemoveState_ENo(-1 , STNo_石化中); 
        _所持3ターン敗北Turn = 0;
    }
    for (let i = 0; i <= CardData.length - 1; i++) {
        CardData[i]._使用禁止 = false;
        if (_使用禁止CTypeArr.indexOf(CardData[i].CardData.wtypeId) != -1) {
            CardData[i]._使用禁止 = true;
        }
        for (let j = 0; j <= CardData[i].CardData.traits.length - 1; j++) {
            if (CardData[i].CardData.traits[j].code == 43) { 
                let _ckId = CardData[i].CardData.traits[j].dataId;
                switch (_ckId) {
                    case KSkill.一部戦闘使用不可: 
                        if ($gameSwitches.value(SW_BtlLastBoss)) CardData[i]._使用禁止 = true;
                        break
                    case KSkill.ビット消費Tn: 
                        if (NPlayer[0]._BtlBit.length <= 0) CardData[i]._使用禁止 = true;
                        break;
                    case KSkill.裸時のみ使用可能: 
                        if (!$gameSwitches.value(SW_キャストオフ)) CardData[i]._使用禁止 = true;
                        if (Check裸RomashaBattle()) CardData[i]._使用禁止 = false; 
                        break;
                    case KSkill.乳首Open時使用可能: 
                        let useFlg = false;
                        if ($gameSwitches.value(SW_キャストオフ)) useFlg = true; 
                        if (AccessFlg) {
                            if ($gameSwitches.value(SW_BtlPltMuneOFF) && $gameSwitches.value(SW_BtlAmMuneOFF)) {
                                useFlg = true;
                            }
                        } else {
                            if ($gameVariables.value(VN_TL2DKigae) == 0) useFlg = true;
                            if ($gameVariables.value(VN_TL2DKigae) == 1) useFlg = true;
                            if ($gameVariables.value(VN_TL2DKigae) == 2) useFlg = true;
                            if ($gameSwitches.value(SW_BtlPltMuneOFF)) useFlg = true;
                            if ($gameSwitches.value(SW_BtlAmMuneOFF)) useFlg = true;
                        }
                        if (!useFlg) {
                            CardData[i]._使用禁止 = true;
                        }
                        break;
                }
            }
        }
        if (MetaChecker(CardData[i].CardData , "使用不可" , false) != false) {
            CardData[i]._使用禁止 = true;
        }
        if (MetaChecker(CardData[i].CardData , "エロカード" , false) != false) {
            for (let j = 0; j < NEnemy.length; j++) {
                if (MetaChecker(NEnemy[j].enemy() , "男性" , false) == false) {
                    CardData[i]._使用禁止 = true;
                    break;
                }
            }
        }
    }
}
let _使用禁止CTypeArr = [];
let _使用禁止CTypeArr_追加 = function (_禁止Type) {
    if (_使用禁止CTypeArr.indexOf(_禁止Type) == -1) {
        _使用禁止CTypeArr.push(_禁止Type);
    }
}
Game_Interpreter.prototype.SetumeiDel = function () {
    if (!btl説明描画Flg) {
        bef異常ViewNo = null; 
        if (!SetuNoDelFlg) Alpha0SpriteSpan(PN_SetuC, PN_Setu_End);
    }
}
let HandZureX = function () {
    let _chZureX = 7;
    if (CardData.length > 7) _chZureX = 8;
    return 114 - ((CardData.length - 1) * _chZureX);
}
Game_Interpreter.prototype.HandKeepGet = function () {
    let Cardxset = HandZureX();
    for (let i = 0; i <= CardData.length - 1; i++) {
        let _cardKakudo = (CardData.length / 2) * -Cardkakudo;
        CardData[i].setPNo = PN_Card + i;
        CardData[i].XPos = handCardBasePostion._x + (Cardxset * i);
        CardData[i].YPos = handCardBasePostion._y + Math.abs(_cardKakudo + (Cardkakudo * i) * 1.2);
        this.CardReDrawC(i);
        CardData[i].KeepPicData = this.PicObjGet(CardData[i].setPNo);
        this.PicInObj(CardData[i].setPNo, null); 
    }
}
let _BtlSelCardNo = -1;
let _BtlSelSetuCnt = -1;
let _BtlSelIjoCnt = -1;
Game_Interpreter.prototype.CardSetumei = function () {
    for (let i = 0; i <= CardData.length - 1; i++) {
        if (CardData[i].setPNo == PN_Card + CardData.length - 1) { 
            if (BtlPLTurn.befCardSelectNo == i) break; 
            BtlPLTurn.befCardSelectNo = i;
            this.CardTargetGet(CardData[i].CardData);
            this.SetumeiDel(); 
            this.SetSprite(PN_SetuC, BtlPicPath + "PN_SetuC", CardData[i].XPos + 0, CardData[i].YPos - 10 - 160);
            let wakusetX = CardData[i].XPos - 154;
            if (wakusetX < 192) {
                wakusetX = 192;
            } else if (wakusetX > 312) {
                wakusetX = 312;
            }
            let _CPosX = wakusetX;
            let _CPosY = CardData[i].YPos - 107 - 160;
            this.CardSetumei_Draw(CardData[i].CardData.id, _CPosX, _CPosY)
            try {
                if (CardData[i].CardData != undefined) {
                    _BtlSelCardNo = CardData[i].CardData.id;
                }
            } catch (e) {
                console.log("CardData::undefined");
            }
        }
    }
}
Game_Interpreter.prototype.CardSetumei_Draw = function (_CardId, _CPosX, _CPosY) {
    _BtlSelSetuCnt = 0;
    this.SetSprite(PN_SetuWaku, BtlPicPath + "PN_SetuWaku", _CPosX, _CPosY);
    let _SetuArr = this.CardSetuGet(_CardId); 
    for (let i = 0; i <= _SetuArr.length - 1; i++) {
        if (i == 3) break;
        this.SpriteStr(PN_T_Setu + i, _SetuArr[i], 19, _CPosX + 8, _CPosY + 11 + (27 * i));
    }
    _BtlSelSetuCnt = _SetuArr.length;
    for (let i = 0; i <= _CardSetuGet_StList.length - 1; i++) {
        let _Ps = new Pos2D(_CPosX, 300);
        this.IjoSetuDraw(PN_SetuI, _CardSetuGet_StList, _Ps, 0, new Pos2D(20, 95));
    }
}
Game_Interpreter.prototype.BCardSetumei_Draw = function (_CardId , _CPosX , _CPosY) {
    this.SetPict(PN_SetuWaku, BtlPicPath + "BCard_SetuWin", _CPosX, _CPosY);
    let _SetuArr = this.CardSetuGet(_CardId); 
    for (let i = 0; i <= _SetuArr.length - 1; i++) {
        if (i == 3) break;
        this.SetPicStr(PN_T_Setu + i, _SetuArr[i], 19, _CPosX + 15, _CPosY + 14 + (27 * i));
    }
    _BtlSelSetuCnt = _SetuArr.length;
    for (let i = 0; i <= _CardSetuGet_StList.length - 1; i++) {
        IjoPicDraw_Flg = true;
        let _Ps = new Pos2D(_CPosX, 300);
        this.IjoSetuDraw(PN_SetuI, _CardSetuGet_StList, _Ps, 0, new Pos2D(30, 95 + 90));
    }
}
const VN_射精欲 = 704;
Game_Interpreter.prototype.CardTargetGet = function (_CData) {
    Tgt男性Flg = false;
    this.TarGetReset(); 
    CardSkills = []; 
    for (let j = 0; j <= _CData.traits.length - 1; j++) {
        if (_CData.traits[j].code == 43) { 
            let _addSid = _CData.traits[j].dataId;
            let _addSkFlg = true;
            for (let k = 0; k <= $dataSkills[_addSid].effects.length - 1; k++) {
                if ($dataSkills[_addSid].effects[k].code == 43) {
                    let _addSid2 = $dataSkills[_addSid].effects[k].dataId;
                    CardSkills.push($dataSkills[_addSid2]);
                    _addSkFlg = false;
                }
            }
            if (_addSkFlg) CardSkills.push($dataSkills[_addSid]);
            this.TargetSelect(0, _CData.traits[j].dataId); 
            if (KSkill.射精欲_増加 == _CData.traits[j].dataId) {
                _射精欲_Check += UseCard.CardData.params[5]; 
                if (CheckStateInType(NEnemy[0]._NState , StType.Koufun)) {
                    _射精欲_Check += UseCard.CardData.params[5]
                }
                $gameVariables.setValue(VN_射精欲, _射精欲_Check)
            }
        }
    }
}
