let btlBattle_flame = 0;
let KsnTurn = 0; 
let _ksnMflame = 0; 
let _ksnTotalDmgFlame = 0; 
let _drawPlPopCnt = 0;
let _drawEmPopCnt = 0;
Game_Interpreter.prototype.N_Btl_BattleCng = function () {
    L2dFadeMdl("Leona_battle1", "rightout", 15, "", 1, 1, 0, 130);
    L2dFadeMdl("Leona_battleTH", "rightout", 15, "", 1, 1, 0, 130);
    if (NEnemy.Live2D_Name != "") {
        L2dFadeMdl(NEnemy.Live2D_Name, "centerout", 15, "", 1);
    }
    this.MoveSpriteAdd(PN_BtlTHBlt, -20, 0, 5, 0);
    btlMode = _btlMode.Battle;
    btlBattle_flame = 0;
    KsnTurn = 0;
    _ksnMflame = 0;
    _ksnTotalDmgFlame = 0;
    PlTotalDmg = 0;
    EmTotalDmg = 0;
    this.SetSprite(PN_bKBack + 0, BtlKsnPic + "PN_bKBack_1", 0, 0);
    this.SetSprite(PN_bKBack + 1, BtlKsnPic + "PN_bKBack_2", 0, 405);
    this.N_Btl_PlStmove(1150, 647, 10);
    this.N_Btl_EmStmove(30, 7, 10);
    this.N_Btl_SetuDel(); 
    this.N_Btl_DoPResetDraw(); 
    this.Blt_Tutorial決戦開始();
}
let _PlPosX = 0;
let _EmPosX = 360;
let _BltPlPosX = 500;
let _BltEmPosX = 600;
let _BtlUpSyoriNo = 0; 
let _Btl_StopCmnFlg = false;
let _Btl_連続攻撃Cnt = 0; 
let _GoPlBltPs = new Pos2D(0, 0);
let _GoEmBltPs = new Pos2D(0, 0);
let Player_SkillNo = 0;
let Enemy_SkillNo = 0;
let PLAllMissFlg = false; 
let EnAllMissFlg = false;
let Turn_DmgCnt = 0; 
let PL_SkillFlg = false; 
const CN_PlayerSkill = 143; 
const CN_EnemySkill = 144;
const CN_PLAllMiss = 145; 
const CN_EnAllMiss = 146;
const PN_TotalDmg = 369;
let PlTotalDmg = 0;
let EmTotalDmg = 0;
let PL_行動不能Flg; 
Game_Interpreter.prototype.N_Btl_BattleUpdate = function () {
    if (_ksnTotalDmgFlame > 0) {
        _ksnTotalDmgFlame++;
        if (_ksnTotalDmgFlame == 2) {
            D_Text_Cng_font = "Cornerstone"; 
            let zureY = 20;
            this.SetSprite(PN_TotalDmg + 0, BtlPic + "PN_TotalDmg", 0, zureY, 0);
            this.MoveSprite(PN_TotalDmg + 0, 0, 0, 10);
            let redWhiteFont = SCol.Red0 + "\\oc[rgb(255,255,255)]\\ow[5]";
            this.SpriteStrC(PN_TotalDmg + 1, redWhiteFont + " " + EmTotalDmg + " ", 75, 408, 262 + zureY, 0);
            this.SpriteStrC(PN_TotalDmg + 2, redWhiteFont + " " + PlTotalDmg + " ", 75, 1042, 580 + zureY, 0);
            this.MoveSprite(PN_TotalDmg + 1, 408, 262, 10, 255);
            this.MoveSprite(PN_TotalDmg + 2, 1042, 580, 10, 255);
            D_Text_Cng_font = ""; 
        }
        if (_ksnTotalDmgFlame == 75) {
            this.Btl_BattleEnd();
            this.DelSpriteSpan(PN_TotalDmg, PN_TotalDmg + 2);
        }
        return;
    }
    this.DelSprite(PN_bDataBtn); 
    this.Btl_Enter異常描画(); 
    if (_Btl_StopCmnFlg) return;
    if (btlBattle_flame > 30) { 
        if (KsnTurn <= 5) { 
            if (_ksnMflame >= 0 && _BtlUpSyoriNo == 0) {
                Turn_DmgCnt = 0;
                BtlUpSyoriNo = 0;
                PLAllMissFlg = EnAllMissFlg = true;
                _drawPlPopCnt = 0;
                _drawEmPopCnt = 0;
                this._Skill_UseCk(NPlayer);
                this._Skill_UseCk(NEnemy);
                this._Skill事前効果(NPlayer, NEnemy);
                this._Skill事前効果(NEnemy, NPlayer);
                let _plImg = MetaChecker($dataSkills[NPlayer.DO_Arr[KsnTurn]], "Img", "miss");
                this.SetSprite(PN_bPLTatie, BtlTatie_Pl + _plImg, _PlPosX + 200, 277, 0);
                this.SetSpriteC(PN_bEmTatie, BtlTatie_Em + NEnemy.Img, _EmPosX - 100, 202, 0);
                this.Btl_敵画像変更(true); 
                let _mvTime = 9;
                if (isFastForward()) _mvTime /= 3;
                this.MoveSprite(PN_bPLTatie, _PlPosX, 277, _mvTime);
                this.MoveSprite(PN_bEmTatie, _EmPosX, 202, _mvTime);
                PL_行動不能Flg = false;
                if (NPlayer.DO_Arr[KsnTurn] == 0) { 
                    let _ckPNo = PN_bPLBltWin + (Cnt_PN_bPLBltWin * KsnTurn);
                    this.DelSpriteSpan(_ckPNo + 1, _ckPNo + Cnt_PN_bPLBltWin - 1);
                    this.CngSprite(_ckPNo, BtlPic + "PN_bPLBltWin_Miss");
                    this.SetCmnEvent(Number(CN_PlayerSkill));
                    PL_行動不能Flg = true;
                    PLAllMissFlg = false; 
                } else {
                    NPlayer._tp -= btlSelect_TpUse[KsnTurn] * 10;
                }
                if (NEnemy.DO_Arr[KsnTurn] == -1 || NEnemy.DO_Arr[KsnTurn] == 0) { 
                    EnAllMissFlg = false; 
                }
                EasingStr = "easeOutQuad";
                let _PlBltSp = GetSpriteData(PN_bPLBltWin + (KsnTurn * Cnt_PN_bPLBltWin));
                let _EmBltSp = GetSpriteData(PN_bEmBltWin + (KsnTurn * Cnt_PN_bEmBltWin));
                _GoPlBltPs = new Pos2D(_PlBltSp._x + 50, _PlBltSp._y);
                _GoEmBltPs = new Pos2D(_EmBltSp._x - 50, _EmBltSp._y);
                this.N_Btl_Pl弾丸Move(PN_bPLBltWin + (KsnTurn * Cnt_PN_bPLBltWin), _GoPlBltPs._x, _GoPlBltPs._y, 8);
                this.N_Btl_Em弾丸Move(PN_bEmBltWin + (KsnTurn * Cnt_PN_bEmBltWin), _GoEmBltPs._x, _GoEmBltPs._y, 8);
                EasingStr = "";
                _BtlUpSyoriNo = 1;
            }
            if (_ksnMflame == 1 && _BtlUpSyoriNo == 1) {
                this.N_Btl_BattleGo(); 
            }
            if (_ksnMflame == 2 && NPlayer.Skill != undefined) { 
                try {
                    PL_SkillFlg = true;
                    _Btl_StopCmnFlg = true;
                    Player_SkillNo = NPlayer.Skill.id;
                    let _CmnNo = MetaChecker(NPlayer.Skill, "コモンNo", "")
                    if (_CmnNo != "") {
                        this.SetCmnEvent(Number(_CmnNo));
                    } else {
                        this.SetCmnEvent(CN_PlayerSkill);
                    }
                    let _ToVoice = MetaChecker(NPlayer.Skill, "Voice", "")
                    if (_ToVoice != "") {
                        let _ckSplt = _ToVoice.split(',');
                        if (_ckSplt.length > 1) {
                            this.PVoice(_ckSplt[0], _ckSplt[1]);
                        }
                    }
                } catch (e) {
                }
            }
            if (_ksnMflame == 3 && NEnemy.Skill != undefined) { 
                try {
                    PL_SkillFlg = false;
                    Enemy_SkillNo = NEnemy.Skill.id;
                    let _CmnNo = MetaChecker(NEnemy.Skill, "コモンNo", "")
                    if (_CmnNo != "") {
                        this.SetCmnEvent(Number(_CmnNo));
                    } else {
                        this.SetCmnEvent(CN_EnemySkill);
                    }
                    _Btl_StopCmnFlg = true;
                } catch (e) {
                }
            }
            if (_ksnMflame >= 10 && _BtlUpSyoriNo == 1) {
                this.MoveSprite(PN_bPLTatie, _PlPosX - 50, 277, 120);
                this.MoveSprite(PN_bEmTatie, _EmPosX + 50, 202, 120);
                if (NPlayer.DO_Arr[KsnTurn] > 0) {
                    NPlayer.AtkRpt = $dataSkills[NPlayer.DO_Arr[KsnTurn]].repeats;
                    if (NPlayer.UseCostRpts > 1) {
                        NPlayer.AtkRpt = NPlayer.UseCostRpts;
                    }
                }
                if (NEnemy.DO_Arr[KsnTurn] > 0) {
                    NEnemy.AtkRpt = $dataSkills[NEnemy.DO_Arr[KsnTurn]].repeats;
                    if (NEnemy.UseCostRpts > 1) {
                        NEnemy.AtkRpt = NEnemy.UseCostRpts;
                    }
                }
                this.Skill_StateTurnUp();
                this.N_Btl_SkillUse(); //戦闘ダメージ処理（プレイヤー ＆ 敵)
                this.N_Btl_DoPPicCng(); 
                this.N_Btl_ChainDraw();
                EasingStr = "easeInQuad";
                _GoPlBltPs = new Pos2D(_GoPlBltPs._x - 130, _GoPlBltPs._y);
                _GoEmBltPs = new Pos2D(_GoEmBltPs._x + 130, _GoEmBltPs._y);
                let _PlBltSp = GetSpriteData(PN_bPLBltWin + (KsnTurn * Cnt_PN_bPLBltWin));
                this.N_Btl_Pl弾丸Move(PN_bPLBltWin + (KsnTurn * Cnt_PN_bPLBltWin), _GoPlBltPs._x, _GoPlBltPs._y, 5);
                let _EmBltSp = GetSpriteData(PN_bEmBltWin + (KsnTurn * Cnt_PN_bEmBltWin));
                this.N_Btl_Em弾丸Move(PN_bEmBltWin + (KsnTurn * Cnt_PN_bEmBltWin), _GoEmBltPs._x, _GoEmBltPs._y, 5);
                EasingStr = "";
                _BtlUpSyoriNo = 2;
            }
            if (NPlayer.AtkRpt > 0 || (NEnemy.AtkRpt > 0 && NEnemy.Brns > 0)) {
                if (_ksnMflame >= 30 && _BtlUpSyoriNo == 2) {
                    _ksnMflame = 10;
                    this.N_Btl_SkillUse(); 
                }
                _ksnMflame++;
                return; 
            }
            if (_ksnMflame == 18 && _BtlUpSyoriNo == 2 && (PLAllMissFlg || PL_行動不能Flg)) {
                this.SetCmnEvent(CN_PLAllMiss); 
                _Btl_StopCmnFlg = true;
            }
            if (_ksnMflame == 19 && _BtlUpSyoriNo == 2 && EnAllMissFlg) {
                this.SetCmnEvent(CN_EnAllMiss); 
                _Btl_StopCmnFlg = true;
            }
            if (_ksnMflame >= 20 && _BtlUpSyoriNo == 2) { 
                if (WinLoseFlg != _BtlBranch.Btl) {
                    this.N_Btl_EndCng();
                }
                EasingStr = "easeOutQuad";
                let _戻りX = 100;
                _GoPlBltPs = new Pos2D(_GoPlBltPs._x + _戻りX, _GoPlBltPs._y);
                _GoEmBltPs = new Pos2D(_GoEmBltPs._x - _戻りX, _GoEmBltPs._y);
                let _PlBltSp = GetSpriteData(PN_bPLBltWin + (KsnTurn * Cnt_PN_bPLBltWin));
                this.N_Btl_Pl弾丸Move(PN_bPLBltWin + (KsnTurn * Cnt_PN_bPLBltWin), _GoPlBltPs._x, _GoPlBltPs._y, 30);
                let _EmBltSp = GetSpriteData(PN_bEmBltWin + (KsnTurn * Cnt_PN_bEmBltWin));
                this.N_Btl_Em弾丸Move(PN_bEmBltWin + (KsnTurn * Cnt_PN_bEmBltWin), _GoEmBltPs._x, _GoEmBltPs._y, 30);
                EasingStr = "";
                _BtlUpSyoriNo = 3;
            }
            if (_ksnMflame == 20 && _BtlUpSyoriNo == 3) { 
                this.Btl_TurnUp_State効果発動(NPlayer);
                this.Btl_TurnUp_State効果発動(NEnemy);
            }
            if (_ksnMflame >= 130 && _BtlUpSyoriNo == 3) {
                this.MoveSprite(PN_bPLTatie, _PlPosX - 100, 277, 10, 0);
                this.MoveSprite(PN_bEmTatie, _EmPosX + 100, 202, 10, 0);
                _BtlUpSyoriNo = 4;
            }
            if (_ksnMflame >= 140 && _BtlUpSyoriNo == 4) { 
                this.MoveSprite(PN_bPLTatie, 200, 277, 1, 0);
                this.MoveSprite(PN_bEmTatie, _EmPosX - 100, 202, 1, 0);
                _BtlUpSyoriNo = 5;
            }
            if (_ksnMflame >= 142 && _BtlUpSyoriNo == 5) {
                _ksnMflame = -1;
                _BtlUpSyoriNo = 0; 
                KsnTurn++;
            }
        }
        _ksnMflame++;
    }
    if (KsnTurn > 5) {
        if (_ksnMflame == 0) {
            _Btl_StopCmnFlg = true;
            this.SetCmnEvent(CN_全行動終了時コモン); 
        }
        if (_ksnMflame == 1) {
            DoArr_Reset();
            btlSelect_TpUse = [0,0,0,0,0,0]; 
            btlSelect_PlTp = 0;
            _ksnTotalDmgFlame = 1;
        }
    }
    btlBattle_flame++;
}
const DmgPopTimer = 90;
let StateZureCnt = 0;
Game_Interpreter.prototype.Btl_TurnUp_State効果発動 = function (_CkChara) {
    StateZureCnt = 0;
    _CkChara.state.forEach(_CkSt => {
        let _CkState = $dataStates[_CkSt._No];
        for (let i = 0; i <= _CkState.traits.length - 1; i++) {
            let drawZureX = Math.floor( Math.random() * 50);
            let drawZureY = StateZureCnt * -60;
            if (_CkState.traits[i].code == 11) {
                let _CngDmg = 0;
                switch (_CkState.traits[i].dataId) {
                    case _Zoku._回避時TP回復:
                        if (!_CkChara._回避成功) break; 
                        let _AddTp = Math.round(_CkState.traits[i].value * 100 - 100);
                        _CkChara._tp += _AddTp;
                        this.DmgPop_Set(SCol.Yel + "TP+" + _AddTp,
                            _CkChara.APos._x + drawZureX - 30, _CkChara.APos._y + drawZureY - 40, 35, DmgPopTimer, 10);
                        if (_CkChara._tp < 0) _CkChara._tp = 0;
                        if (_CkChara._tp > 100) _CkChara._tp = 100;
                        this.Btl_EnterStateDraw();
                        break;
                    case _Zoku._ﾀｰﾝダメージ: 
                        _CngDmg = Math.round(_CkState.traits[i].value * 100 - 100);
                        _CkChara._hp -= _CngDmg;
                        this.DmgPop_Set(SCol.Red + _CngDmg,
                            _CkChara.APos._x + drawZureX + 30, _CkChara.APos._y + drawZureY - 40, 60, DmgPopTimer, 10);
                        StateZureCnt++;
                        break;
                    case _Zoku._ﾀｰﾝ割合ダメージ: 
                        _CngDmg = Math.floor((_CkState.traits[i].value - 1) * _CkChara.mhp);
                        _CkChara._hp -= _CngDmg;
                        this.DmgPop_Set(SCol.Red + _CngDmg,
                            _CkChara.APos._x + drawZureX + 30, _CkChara.APos._y + drawZureY - 40, 60, DmgPopTimer, 10);
                        StateZureCnt++;
                        break;
                }
            }
        }
    });
}
Game_Interpreter.prototype.Btl_Enter異常描画 = function (_opi) { 
    this.DelSpriteSpan(PN_bPlState, PN_bEmStateTn + 6); 
    for (let i = 0; i <= NPlayer.state.length - 1; i++) {
        let _ckst = $dataStates[NPlayer.state[i]._No];
        let _SetStr = " \\I[" + _ckst.iconIndex + "] ";
        let _PLIPs = new Pos2D(1400, 650);
        this.SpriteStrC(PN_bPlState + i, _SetStr, 25, _PLIPs._x, _PLIPs._y + (-60 * i), 255, 150, 150);
        let _TurnStr = "\\oc[rgba(0,0,0,1)] " + NPlayer.state[i]._Turn + " ";
        this.SpriteStrR(PN_bPlStateTn + i, _TurnStr, 25, _PLIPs._x + 30, _PLIPs._y + (-60 * i), 255);
    }
    for (let i = 0; i <= NEnemy.state.length - 1; i++) {
        let _StPs = new Pos2D(63, 261 + 67 + (56 * i));
        let _ckst = $dataStates[NEnemy.state[i]._No];
        let _SetStr = " \\I[" + _ckst.iconIndex + "] ";
        this.SpriteStrC(PN_bEmState + i, _SetStr, 25, _StPs._x, _StPs._y, 255, 150, 150);
        let _TurnStr = "\\oc[rgba(0,0,0,1)] " + NEnemy.state[i]._Turn + " ";
        this.SpriteStrR(PN_bEmStateTn + i, _TurnStr, 25, _StPs._x, _StPs._y, 255);
    }
}
Game_Interpreter.prototype.Btl_Enter異常削除 = function () { 
    this.DelSpriteSpan(PN_bPlState, PN_bEmStateTn + 6); 
}
Game_Interpreter.prototype.Btlコモン終了 = function () {
    _Btl_StopCmnFlg = false;
}
Game_Interpreter.prototype.Btl_敵画像変更 = function (_ImgFlg) {
    _ImgFlg = typeof _ImgFlg !== 'undefined' ? _ImgFlg : false;
    if (NEnemy.Live2D_Name != "" && !_ImgFlg) {
        L2dFExp = "exp_1";
        L2dFadeMdl(NEnemy.Live2D_Name, "centerin", 15, "wait", 1);
        if (NEnemy.DO_Arr[KsnTurn] == -1) {
            L2dIdleStart(NEnemy.Live2D_Name, "break");
            L2dSetMotion(NEnemy.Live2D_Name, "break");
        } else {
            L2dIdleStart(NEnemy.Live2D_Name, "wait");
            L2dSetMotion(NEnemy.Live2D_Name, "wait");
        }
    } else {
        this.SetSpriteC(PN_bEmTatie, BtlTatie_Em + NEnemy.Img, 300, 202);
        if (NEnemy.DO_Arr[KsnTurn] == -1) { 
            this.CngSprite(PN_bEmTatie, BtlTatie_Em + NEnemy.Img + "_break");
        } else {
            this.CngSprite(PN_bEmTatie, BtlTatie_Em + NEnemy.Img);
            this._ブレイクモード終了確認();
        }
    }
}
Game_Interpreter.prototype.Btl_BattleEnd = function () {
    for (let i = 0; i <= 6 - 1; i++) {
        EasingStr = "";
        let _PlBltSp = GetSpriteData(PN_bPLBltWin + (i * Cnt_PN_bPLBltWin));
        let _EmBltSp = GetSpriteData(PN_bEmBltWin + (i * Cnt_PN_bEmBltWin));
        let _戻りX = -20;
        _GoPlBltPs = new Pos2D(_PlBltSp._x + _戻りX, _PlBltSp._y);
        _GoEmBltPs = new Pos2D(_EmBltSp._x - _戻りX, _EmBltSp._y);
        _PlBltSp = GetSpriteData(PN_bPLBltWin + (i * Cnt_PN_bPLBltWin));
        this.N_Btl_Pl弾丸Move(PN_bPLBltWin + (i * Cnt_PN_bPLBltWin), _GoPlBltPs._x, _GoPlBltPs._y, 10, 0);
        _EmBltSp = GetSpriteData(PN_bEmBltWin + (i * Cnt_PN_bEmBltWin));
        this.N_Btl_Em弾丸Move(PN_bEmBltWin + (i * Cnt_PN_bEmBltWin), _GoEmBltPs._x, _GoEmBltPs._y, 10, 0);
        EasingStr = "";
    }
    BtlTurn++;
    this.MoveSprite(PN_bKBack + 0, true, true, 10, 0);
    this.MoveSprite(PN_bKBack + 1, true, true, 10, 0);
    DoArr_Reset(); 
    this.Btl_Enter異常削除();
    this.N_Btl_SelectCng();
    NPlayer.Skill = undefined;
    NEnemy.Skill = undefined;
    this.Skill_StateTurnUp(); 
    this.N_Btl_TatieView();
    this.N_Btl_PlStView(PLStPos._x, PLStPos._y, true);
    this.N_Btl_EmStView(); 
    this.MoveSpriteAdd(PN_bCmbTxt + 0, 0, 30, 5, 0);
    this.MoveSpriteAdd(PN_bCmbTxt + 1, 0, 30, 5, 0);
}
Game_Interpreter.prototype._Skill事前効果 = function (_AChara, _BChara) {
    if (_AChara.DO_Arr[KsnTurn] > 0) {
        let _SkillNo = _AChara.DO_Arr[KsnTurn];
        if (_Skill_State存在Ck(_SkillNo, _StateDt._相手行動不能)) {
            _BChara.DO_Arr[KsnTurn] = 0;
        }
    }
}
Game_Interpreter.prototype._Skill_UseCk = function (_AChara) {
    if (_AChara.DO_Arr[KsnTurn] > 0) {
        let _ckSkill = $dataSkills[_AChara.DO_Arr[KsnTurn]];
        if (_AChara.Do_Mp < _ckSkill.mpCost) {
            _AChara.DO_Arr[KsnTurn] = 0; 
        }
        let _CmnNo = MetaChecker(_ckSkill, "発生コモンNo", -1);
        if (_CmnNo != -1) {
            _CmnNo = Number(_CmnNo);
            this.SetCmnEventSc(_CmnNo); 
            _Btl_StopCmnFlg = true;
        }
        if (_Skill_State存在Ck(_AChara.DO_Arr[KsnTurn], _StateDt._TP全消費)) {
            _AChara.UseTp = _AChara._tp;
            _AChara._tp = 0;
        }
        if (MetaChecker(_ckSkill, "テンション消費") != "") {
            let _消費TP = Number(MetaChecker(_ckSkill, "テンション消費"));
            if (_AChara._tp - _消費TP >= 0) {
                _AChara._tp -= _消費TP;
            } else {
                let _PNo = PN_bPLBltWin + (KsnTurn * Cnt_PN_bPLBltWin) + 2;
                this.SpriteStr(_PNo, SCol.Red + "攻撃失敗", 22, true, true, 255, true, true);
                _AChara.DO_Arr[KsnTurn] = 0; 
            }
        }
    }
    if (_AChara.DO_Arr[KsnTurn] == 0) _AChara._tp -= 2; 
}
Game_Interpreter.prototype.WinLoseCheck = function () {
}
Game_Interpreter.prototype.N_Btl_BattleGo = function () {
    this.N_Btl_SkillSetting(NPlayer);
    this.N_Btl_SkillSetting(NEnemy);
}
Game_Interpreter.prototype.N_Btl_SkillSetting = function (_AChara) {
    _AChara.Skill = undefined;
    _AChara.UseCost = 0;
    _AChara.UseCostRpts = 1;
    let _SkillNo = _AChara.DO_Arr[KsnTurn];
    if (_SkillNo > 0) {
        _AChara.Skill = $dataSkills[_SkillNo];
        _AChara.UseTp = 0;
        if (_Skill_State存在Ck(_SkillNo, _StateDt._コスト全消費)) {
            _AChara.UseCost = _AChara.Do_Mp;
            if (MetaChecker(_AChara.Skill, "C回数", false) != false) {
                let _WCnt = Number(MetaChecker(_AChara.Skill, "C回数", false));
                _AChara.UseCostRpts = _AChara.Do_Mp / _WCnt;
            }
            _AChara.Do_Mp = 0;
        } else {
            if (_AChara.Skill.mpCost > 0) {
                _AChara.UseCost = _AChara.Skill.mpCost;
                _AChara.Do_Mp -= _AChara.Skill.mpCost;
            } else if (_AChara.Skill.tpCost > 0) {
                _AChara.UseCost = -_AChara.Skill.tpCost;
                _AChara.Do_Mp += _AChara.Skill.tpCost;
            }
        }
        if (_AChara.Do_Mp <= 0) _AChara.Do_Mp = 0;
        if (_AChara.Do_Mp >= _AChara.Do_MaxMp) _AChara.Do_Mp = _AChara.Do_MaxMp;
        if (_AChara.Do_Mp >= DoP_Cnt) _AChara.Do_Mp = DoP_Cnt;
    }
}
let ChainPs = new Pos2D(1176, 214);
let ChainTxtPs = new Pos2D(1232, 184);
let Chain_Cnt = 0; 
let _引分Cnt = 0;
const チェイン増加最大 = 5;
Game_Interpreter.prototype.N_Btl_ChainDraw = function () {
    let _PlSkillNo = NPlayer.DO_Arr[KsnTurn];
    let _EmSkillNo = NEnemy.DO_Arr[KsnTurn];
    let _相性 = Skill相性Ck(_PlSkillNo, _EmSkillNo);
    let _失敗Flg = false;
    switch (_相性) {
        case _相性結果.Win:
            Chain_Cnt++;
            if (Rz_最大チェイン数 < Chain_Cnt) Rz_最大チェイン数 = Chain_Cnt;
            let _TPUp = Chain_Cnt;
            if (_TPUp > チェイン増加最大) _TPUp = チェイン増加最大;
            NPlayer._tp += _TPUp;
            D_Text_Cng_font = "Makinas"; 
            let _OL = "\\ow[5]\\oc[rgb(0,0,0)]"
            this.SpriteStrC(PN_bCmbTxt + 0, _OL + SCol.Yel + " " + Chain_Cnt + " ", 100, ChainPs._x, ChainPs._y - 20, 0);
            this.SpriteStr(PN_bCmbTxt + 1, _OL + SCol.Yel + " chain ", 50, ChainTxtPs._x, ChainTxtPs._y, 255);
            this.DmgPop_Set(SCol.Red + "TP+" + _TPUp, ChainTxtPs._x, ChainTxtPs._y - 40, 35, DmgPopTimer, 10);
            D_Text_Cng_font = ""; 
            this.MoveSpriteAdd(PN_bCmbTxt + 0, 20, 0, 5, 255);
            _引分Cnt = 0;
            break;
        case _相性結果.Draw:
            _引分Cnt++;
            if (Chain_Cnt > 0) {
                this.MoveSprite(PN_bCmbTxt + 0, true, true, 5, 180, 80, 80);
                this.MoveSprite(PN_bCmbTxt + 1, true, true, 5, 180, 80, 80);
            }
            if (_引分Cnt == 2) {
                Chain_Cnt = 0;
                _引分Cnt = 0;
                _失敗Flg = true;
            }
            break;
        case _相性結果.Lose:
            Chain_Cnt = 0;
            _引分Cnt = 0;
            _失敗Flg = true;
            break;
    }
    if (_失敗Flg) {
        this.MoveSpriteAdd(PN_bCmbTxt + 0, 20, 0, 5, 0);
        this.MoveSpriteAdd(PN_bCmbTxt + 1, 20, 0, 5, 0);
    }
}
