class _BtlEnst {
    constructor() {
        this.Dmg = 0; 
        this.CltDmgFlg = false; 
        this.c_atk = 0; 
        this.c_def = 0; 
        this.c_hit = 0; 
        this.c_avo = 0; 
    }
}
let 被弾コモン_命中Flg = false;
let 被弾コモン_ダメージ量 = 0;
let _Btl_PL回避成功 = false; 
Game_Interpreter.prototype.N_Btl_SkillUse = function () {
    被弾コモン_命中Flg = false;
    被弾コモン_ダメージ量 = 0;
    NPlayer.AtkRpt--;
    NEnemy.AtkRpt--;
    NPlayer.Enst = new _BtlEnst();
    NEnemy.Enst = new _BtlEnst();
    let _PlSkillNo = NPlayer.DO_Arr[KsnTurn];
    let _EmSkillNo = NEnemy.DO_Arr[KsnTurn];
    NPlayer.Skill = $dataSkills[_PlSkillNo];
    NEnemy.Skill = $dataSkills[_EmSkillNo];
    if (NPlayer.Skill != undefined) NPlayer.stype = NPlayer.Skill.stypeId;
    if (NEnemy.Skill != undefined) NEnemy.stype = NEnemy.Skill.stypeId;
    this.SkillTpCk(); 
    this.Skill_StateSkillSet();
    if (NPlayer.AtkRpt >= 0) {
        UseTp = NPlayer.UseTp;
        UseCost = NPlayer.UseCost;
        if (_Btl_TutorialNo != -1) { 
            DmgSkillSet_強制命中Flg = _Tuto_強制命中[KsnTurn];
        }
        if (this.DmgSkillSet(NPlayer, NEnemy)) { 
            PLAllMissFlg = false;
            NPlayer._tp += 1; 
            let _相性 = Skill相性Ck(_PlSkillNo, _EmSkillNo);
            if (_相性 == _相性結果.Win) {
                if ($dataSkills[_PlSkillNo].stypeId == _Stype._Atk) {
                }
            }
        }
        if (NPlayer.Skill.damage.elementId != _Zoku._通常攻撃) PLAllMissFlg = false;
    }
    if (NEnemy.Brns <= 0) { 
        EnAllMissFlg = false;
    } else {
        if (NEnemy.AtkRpt >= 0) {
            UseTp = NEnemy.UseTp;
            UseCost = NEnemy.UseCost;
            if (this.DmgSkillSet(NEnemy, NPlayer)) {
                被弾コモン_命中Flg = true;
                EnAllMissFlg = false;
            }
            if (NEnemy.Skill.damage.type == _Dtype._Not) EnAllMissFlg = false;
        }
    }
    let PLDmg = this.Dmg_StateCng(NPlayer);
    let EmDmg = this.Dmg_StateCng(NEnemy);
    let _位置乱数範囲 = 50;
    NPlayer._hp -= PLDmg;
    被弾コモン_ダメージ量 = PLDmg;
    PlTotalDmg += PLDmg;
    Rz_合計被ダメージ += PLDmg;
    if (PLDmg > 0) { 
        NPlayer._回避成功 = false;
        let _RndPsX = (Math.random() * _位置乱数範囲 * 2) - _位置乱数範囲;
        let _RndPsY = (Math.random() * _位置乱数範囲 * 2) - _位置乱数範囲;
        if (NPlayer.Enst.CltDmgFlg) PLDmg = SCol.Yel + PLDmg;
        let _PsX = NPlayer.APos._x + 150 + _RndPsX;
        let _PsY = NPlayer.APos._y + 50 + _RndPsY;
        this.DmgPop_Set(PLDmg, _PsX, _PsY, 60, DmgPopTimer, 10);
    } else {
        let _相性 = Skill相性Ck(_PlSkillNo, _EmSkillNo);
        if (_相性 == _相性結果.Win) NPlayer._回避成功 = true;
    }
    NEnemy._hp -= EmDmg;
    EmTotalDmg += EmDmg;
    if (EmDmg > 0) { 
        NEnemy._回避成功 = false;
        Turn_DmgCnt += EmDmg;
        let _RndPsX = (Math.random() * _位置乱数範囲 * 2) - _位置乱数範囲;
        let _RndPsY = (Math.random() * _位置乱数範囲 * 2) - _位置乱数範囲;
        if (NEnemy.Enst.CltDmgFlg) EmDmg = SCol.Yel + EmDmg;
        let _PsX = NEnemy.APos._x - 160 + _RndPsX;
        let _PsY = NEnemy.APos._y - 30 + _RndPsY;
        this.DmgPop_Set(EmDmg, _PsX, _PsY, 60, DmgPopTimer, 10);
        if (Rz_最大与ダメージ < Turn_DmgCnt) Rz_最大与ダメージ = Turn_DmgCnt;
        NEnemy.Brns--; 
        this.N_バランス描画();
        if (NEnemy.Brns <= 0) {
            if (!_Brns_ブレイクFlg) this.N_バランスブレイク();
        }
    } else {
        let _相性 = Skill相性Ck(_EmSkillNo, _PlSkillNo);
        if (_相性 == _相性結果.Win) NEnemy._回避成功 = true;
    }
    if (NPlayer._hp <= 0) NPlayer._hp = 0;
    if (NEnemy._hp <= 0) NEnemy._hp = 0;
    if (DbgFlg) { 
        /*        this.SpriteStr(PN_TestStr + 0, "　命中率：" + NPlayer.dbgArr[0], 22, 18, 729, 255);
                this.SpriteStr(PN_TestStr + 1, "ダメージ：" + EmDmg, 22, 18, 759, 255);
                this.SpriteStr(PN_TestStr + 2, "　命中率：" + NEnemy.dbgArr[0], 22, 1260, 12, 255);
                this.SpriteStr(PN_TestStr + 3, "ダメージ：" + PLDmg, 22, 1260, 42, 255);*/
    }
    NPlayer.dbgArr = [0, 0, 0, 0, 0, 0, 0];
    if (NPlayer._hp <= 0 && NEnemy._hp <= 0) NPlayer._hp = 1; 
    this.Btl_EnterStateDraw(); 
    for (let i = KsnTurn; i <= 6 - 1; i++) {
        let _SkillNo = NPlayer.DO_Arr[i];
        let _HitStr = this._Txt命中被弾(i, _SkillNo);
        let _HitPicNo = PN_bPLBltWin + Cnt_PN_bPLBltWin * i + 3;
        this.CngSpriteStr(_HitPicNo, _HitStr);
    }
    if (NEnemy._hp == 0) {
        if (KsnTurn < 5 && this.BtlPsv_ZokuCk(NEnemy, _Zoku._HPZeroTurn行動継続)) {
            this.DmgPop_Set(SCol.Red + "HP0 Continue", NEnemy.APos._x + 40, NEnemy.APos._y + 0, 35, DmgPopTimer, 10);
        } else {
            WinLoseFlg = _BtlBranch.Win;    
        }
    }
    if (NPlayer._hp == 0) {
        if (KsnTurn < 5 && this.BtlPsv_ZokuCk(NPlayer, _Zoku._HPZeroTurn行動継続)) {
            this.DmgPop_Set(SCol.Red + "HP0 Continue", NPlayer.APos._x + 320, NPlayer.APos._y + 80, 35, DmgPopTimer, 10);
        } else {
            WinLoseFlg = _BtlBranch.Lose;   
        }
    }
    if (WinLoseFlg != _BtlBranch.Btl) {
        NEnemy.AtkRpt = 0;
        NPlayer.AtkRpt = 0;
    } else {
        let _CmnNo = MetaChecker(NPlayer.Skill, "被弾コモンNo", "");
        if (_CmnNo != "") {
            _Btl_StopCmnFlg = true;
            this.SetCmnEvent(Number(_CmnNo));
        }
    }
}
Game_Interpreter.prototype.PlayerダメージPop = function (_dmgValue, _位置乱数範囲) {
    _位置乱数範囲 = typeof _位置乱数範囲 !== 'undefined' ? _位置乱数範囲 : 50;
    let _RndPsX = (Math.random() * _位置乱数範囲 * 2) - _位置乱数範囲;
    let _RndPsY = (Math.random() * _位置乱数範囲 * 2) - _位置乱数範囲;
    let _PsX = NPlayer.APos._x + 150 + _RndPsX;
    let _PsY = NPlayer.APos._y + 50 + _RndPsY;
    this.DmgPop_Set(_dmgValue, _PsX, _PsY, 60, DmgPopTimer, 10);
}
Game_Interpreter.prototype.EnemyダメージPop = function (_dmgValue, _位置乱数範囲) {
    _位置乱数範囲 = typeof _位置乱数範囲 !== 'undefined' ? _位置乱数範囲 : 50;
    let _RndPsX = (Math.random() * _位置乱数範囲 * 2) - _位置乱数範囲;
    let _RndPsY = (Math.random() * _位置乱数範囲 * 2) - _位置乱数範囲;
    let _PsX = NEnemy.APos._x - 160 + _RndPsX;
    let _PsY = NEnemy.APos._y - 30 + _RndPsY;
    this.DmgPop_Set(_dmgValue, _PsX, _PsY, 60, DmgPopTimer, 10);
}
Game_Interpreter.prototype.Btl_結果再確認 = function () {
    this.Btl_EnterStateDraw(); 
    if (NEnemy._hp == 0) {
        if (KsnTurn < 5 && this.BtlPsv_ZokuCk(NEnemy, _Zoku._HPZeroTurn行動継続)) {
            this.DmgPop_Set(SCol.Red + "HP0 Continue", NEnemy.APos._x + 40, NEnemy.APos._y + 0, 35, DmgPopTimer, 10);
        } else {
            WinLoseFlg = _BtlBranch.Win;    
        }
    }
    if (NPlayer._hp == 0) {
        if (KsnTurn < 5 && this.BtlPsv_ZokuCk(NPlayer, _Zoku._HPZeroTurn行動継続)) {
            this.DmgPop_Set(SCol.Red + "HP0 Continue", NPlayer.APos._x + 320, NPlayer.APos._y + 80, 35, DmgPopTimer, 10);
        } else {
            WinLoseFlg = _BtlBranch.Lose;   
        }
    }
}
Game_Interpreter.prototype.Btl_EnterStateDraw = function () {
    this.N_Btl_PlStView(1150, 647);
    this.N_Btl_EmStView(30, 7);
}
let _Brns_ブレイク数 = 0;
let _Brns_ブレイクFlg = false;
const STN_ブレイク = 150; 
Game_Interpreter.prototype.N_バランスブレイク = function () {
    if (_Brns_ブレイク数 > 0) return;
    _Brns_ブレイクFlg = true;
    _Brns_ブレイク数 = NEnemy.Brns_崩れ数;
    NEnemy.state.push(new _State(STN_ブレイク, _Brns_ブレイク数));
    for (let i = KsnTurn; i <= 6 - 1; i++) {
        let _CngPictNo = PN_bEmBltWin + (i * Cnt_PN_bEmBltWin);
        this.CngSprite(_CngPictNo, BtlPic + "PN_bEmBltWin_Brns");
        this.DelSprite(_CngPictNo + 1);
        this.DelSprite(_CngPictNo + 2);
        NEnemy.DO_Arr[i] = -1; 
        _Brns_ブレイク数--;
        if (_Brns_ブレイク数 <= 0) break;
    }
    this.Btl_敵画像変更(true); 
    this.BLogAdd(120, SCol.Yel + NEnemy.Name + " has entered a break state!!");
};
Game_Interpreter.prototype.Dmg_StateCng = function (_AChara) {
    let _rtDmg = _AChara.Enst.Dmg;
    let _被ダメCmnNos = [];
    for (let i = 0; i <= _AChara.state.length - 1; i++) {
        let _ckst = $dataStates[_AChara.state[i]._No];
        for (let j = 0; j <= _ckst.traits.length - 1; j++) {
            switch (_ckst.traits[j].code) {
                case 11: 
                    switch (_ckst.traits[j].dataId) {
                        case _Zoku._被ダメージ変化:
                            let _val = _ckst.traits[j].value;
                            _rtDmg = Math.floor(_rtDmg * _val);
                            break;
                        case _Zoku._被ダメ時ｺﾓﾝ発生:
                            if (_rtDmg > 0) {
                                _Btl_StopCmnFlg = true;
                                let _cmnNo = Math.floor(_ckst.traits[j].value * 100);
                                _被ダメCmnNos.push(_cmnNo)
                            }
                            break;
                    }
                    break;
            }
        }
    }
    if (_rtDmg == 0) return _rtDmg;
    for (let i = 0; i < _被ダメCmnNos.length; i++) this.SetCmnEventSc(_被ダメCmnNos[i]);
    _AChara.PsvArr.forEach(_AmmId => {
        let _Armor = $dataArmors[_AmmId];
        for (let i = 0; i <= _Armor.traits.length - 1; i++) {
            if (_Armor.traits[i].code != 11) continue;
            let _Var = Math.floor(_Armor.traits[i].value * 100) - 100;
            switch (_Armor.traits[i].dataId) {
                case _Zoku._オートガード: 
                    if (_Var >= Math.random() * 100) {
                        _rtDmg = Math.round(_rtDmg * 0.7);
                        this.DmgPop_Set(SCol.Yel + "Auto Guard", _AChara.APos._x - 30, _AChara.APos._y - 40, 35, DmgPopTimer, 10);
                    }
                    break;
            }
        }
    });
    return _rtDmg;
}
Game_Interpreter.prototype.Skill_StateSkillSet = function () {
    this.Skill_StateSet(NPlayer, 1);    
    this.Skill_StateSet(NEnemy, 1);     
}
Game_Interpreter.prototype.Skill_StateTurnUp = function () {
    for (let i = 0; i <= NPlayer.state.length - 1; i++) {
        if (NPlayer.state[i]._Turn != -1) {
            NPlayer.state[i]._Turn--;
            if (NPlayer.state[i]._Turn == 0) {
                NPlayer.state.splice(i, 1);
                i--;
            }
        }
    }
    for (let i = 0; i <= NEnemy.state.length - 1; i++) {
        if (NEnemy.state[i]._Turn != -1) {
            NEnemy.state[i]._Turn--;
            if (NEnemy.state[i]._Turn == 0) {
                NEnemy.state.splice(i, 1);
                i--;
            }
        }
    }
}
Game_Interpreter.prototype.Skill_StateSet = function (_AChara, _優先度, _PopFlg) {
    _PopFlg = typeof _PopFlg !== 'undefined' ? _PopFlg : true;
    if (_AChara.Skill == undefined) return;
    if (_AChara.Skill.damage.type == 1) return; 
    let _stList = _AChara.Skill.effects;
    for (let i = 0; i <= _stList.length - 1; i++) {
        if (_stList[i].code != 21) continue;
        switch (_stList[i].dataId) {
            case _StateDt._コスト削り:
                break;
            case _StateDt._デバフ解除:
                if (_PopFlg) {
                    this.State_デバフ解除(_AChara, Math.round(_stList[i].value1 * 100 - 100));
                    this.Btl_Enter異常描画();
                }
                break;
            default:
                this.State_Setting(_AChara, _stList[i].dataId, _優先度, _PopFlg);
        }
    }
}
Game_Interpreter.prototype.State_Setting = function (_Chara, _StNo, _優先度, _PopFlg) {
    let _ckst = $dataStates[_StNo];
    if (_ckst.priority == _優先度) {
        let _addFlg = true;
        let _No = -1;
        for (let j = 0; j <= _Chara.state.length - 1; j++) {
            if (_ckst.id == _Chara.state[j]._No) {
                _addFlg = false;
                _No = j;
                break;
            }
        }
        if (_addFlg) {
            _Chara.state.push(new _State(_ckst.id, _ckst.stepsToRemove));
        } else { //ターンリセット(すでに追加されていた場合)
            _Chara.state[_No]._Turn = _ckst.stepsToRemove;
        }
        let _PopXZure = 0;
        let _PopYZure = _drawPlPopCnt * 51;
        if (_Chara.EmFlg) {
            _PopXZure = -160;
            _PopYZure = _drawEmPopCnt * 51;
        }
        if (_PopFlg) {
            this.DmgPop_Set("\\I[" + _ckst.iconIndex + "] " + _ckst.name,
                _Chara.APos._x + _PopXZure, _Chara.APos._y + 100 + _PopYZure, 25, 90, 10, 150);
            if (_Chara.EmFlg) _drawEmPopCnt++;
            else _drawPlPopCnt++;
        }
    }
}
Game_Interpreter.prototype.State_デバフ解除 = function (_Chara, _Cnt) {
    let _ckCnt = _Cnt;
    for (let i = _Chara.state.length - 1; i >= 0; i--) {
        let _ckst = $dataStates[_Chara.state[i]._No];
        if (MetaChecker(_ckst, "デバフ", null) != null) {
            _Chara.state.splice(i, 1);
            _ckCnt--;
            if (_ckCnt == 0) return;
        }
    }
}
Game_Interpreter.prototype.SkillTpCk = function () {
    if (NPlayer.stype == NEnemy.stype) return;
    switch (NPlayer.stype) {
        case _Stype._Atk:
            if (NEnemy.stype == _Stype._Taiki) NPlayer._tp += 2;
            if (NEnemy.stype == _Stype._Def) NPlayer._tp -= 2;
            break;
        case _Stype._Def:
            if (NEnemy.stype == _Stype._Atk) NPlayer._tp += 2;
            if (NEnemy.stype == _Stype._Taiki) NPlayer._tp -= 2;
            break;
        case _Stype._Taiki:
            if (NEnemy.stype == _Stype._Def) NPlayer._tp += 2;
            if (NEnemy.stype == _Stype._Atk) NPlayer._tp -= 2;
            break;
    }
}
let UseCost = 0; 
let DmgSkillSet_強制命中Flg = -1; 
Game_Interpreter.prototype.DmgSkillSet = function (_AChara, _BChara) {
    let _AtkHitFlg = false; 
    let _AtkSkill = _AChara.Skill;
    if (_AtkSkill == undefined) return;
    switch (_AtkSkill.damage.elementId) {
        case _Zoku._通常攻撃:
            if (_AtkSkill.damage.type == _Dtype._HPDmg) {
                if (_Skill_State存在Ck(_AtkSkill.id, _StateDt._カウンター)) {
                    if (_BChara.Skill == undefined) return;
                    if (Skill相性Ck(_AtkSkill.id, _BChara.Skill.id) != _相性結果.Win) {
                        return;
                    }
                }
                let _命中判定 = HitKeisan(_AChara, _BChara);
                let _命中Flg = (_命中判定 > Math.random() * 100);
                if (DmgSkillSet_強制命中Flg != -1) _命中Flg = (DmgSkillSet_強制命中Flg == 1);
                if (_命中Flg) {
                    let _技の威力 = Math.floor(eval(_AtkSkill.damage.formula));
                    let _クリティカル補正 = 1;
                    if (_AtkSkill.damage.critical) { 
                        if (Math.random() * 100 < _AtkSkill.damage.variance) {
                            if (_Btl_TutorialNo == -1) { 
                                _BChara.Enst.CltDmgFlg = true;
                                _クリティカル補正 = 1.5;
                            }
                        }
                    }
                    let _パラメータ補正 = _AChara.b_atk / _BChara.b_def;
                    let _攻撃力レベル = Math.floor(_AChara.b_atk / 50) + 1;
                    let _攻撃力レベル補正 = factorial(1.1, (_攻撃力レベル - 2));
                    if (_攻撃力レベル補正 < 1) _攻撃力レベル補正 = 1;
                    let _テンション補正 = 1;
                    if (TH_ModeFlg) {
                        let _TPar100 = (_AChara._tp / 100);
                        _テンション補正 = 1 + 1 * (_TPar100 * _TPar100);
                    }
                    let _Dmg1 = (((_技の威力 * _クリティカル補正) * _パラメータ補正) * _攻撃力レベル補正) * _テンション補正;
                    let _Dmg = Math.floor(_Dmg1 / 2);
                    _AChara.PsvArr.forEach(_AmmId => {
                        let _Armor = $dataArmors[_AmmId];
                        for (let i = 0; i <= _Armor.traits.length - 1; i++) {
                            if (_Armor.traits[i].code != 11) continue;
                            let _Var = Math.floor(_Armor.traits[i].value * 100) - 100;
                            switch (_Armor.traits[i].dataId) {
                                case _Zoku._連続攻撃威力Up:
                                    if (KsnTurn > 0) {
                                        let _ckSkill = $dataSkills[NPlayer.DO_Arr[KsnTurn - 1]];
                                        if (_ckSkill.stypeId == _Stype._Atk) {
                                            _Dmg = Math.ceil(_Dmg * _Armor.traits[i].value);
                                        }
                                    }
                                    break;
                                case _Zoku._攻vs攻威力Up: 
                                    if (_BChara.Skill != undefined) {
                                        if (Skill相性Ck(_AtkSkill.id, _BChara.Skill.id) == _相性結果.Draw) {
                                            _Dmg = Math.ceil(_Dmg * _Armor.traits[i].value);
                                        }
                                    }
                                    break;
                                case _Zoku._ｸﾘ時MP変化:
                                    if (_BChara.Enst.CltDmgFlg) {
                                        _AChara.Do_Mp += _Var;
                                    }
                                    break;
                                case _Zoku._対ﾊﾃﾅテンションUp:
                                    if (!Em_DoViewArr_OpenBef[KsnTurn]) { 
                                        _AChara._tp += _Var; 
                                        this.DmgPop_Set(SCol.Yel + "Passive: TP+" + _Var, _AChara.APos._x + 300, _AChara.APos._y - 40, 35, DmgPopTimer, 10);
                                    }
                                    break;
                            }
                        }
                    });
                    _BChara.Enst.Dmg = _Dmg;
                    this.PlayAnime(_AtkSkill.animationId, _BChara.APos._x, _BChara.APos._y);
                    _AtkHitFlg = true;
                    this.Skill_Effect(_AChara, _BChara);
                } else {
                    let _PopXZure = 0;
                    if (_BChara.EmFlg) _PopXZure = -160;
                    this.DmgPop_Set(SCol.Red + "Miss", _BChara.APos._x + _PopXZure, _BChara.APos._y, 60, DmgPopTimer, 10);
                }
            }
            break;
    }
    this.Skill_StateSet(_AChara, 0); 
    DmgSkillSet_強制命中Flg = -1;
    return _AtkHitFlg;
}
Game_Interpreter.prototype.Skill_Effect = function (_AChara, _BChara) {
    let _stList = _AChara.Skill.effects;
    for (let i = 0; i <= _stList.length - 1; i++) {
        if (_stList[i].code != 21) continue;
        switch (_stList[i].dataId) {
            case _StateDt._コスト削り:
                let _Cost削りVar = Math.round((_stList[i].value1 - 1) * 100);
                _BChara.Do_Mp -= _Cost削りVar;
                let _PopXZure = 0;
                if (_BChara.EmFlg) _PopXZure = -160;
                this.DmgPop_Set(SCol.Red + "Cost-" + _Cost削りVar, _BChara.APos._x + _PopXZure, _BChara.APos._y, 60, DmgPopTimer, 10);
                if (_BChara.Do_Mp < 0) _BChara.Do_Mp = 0;
                break;
            default:
                this.State_Setting(_BChara, _stList[i].dataId, 1, true);
        }
    }
}
//命中判定(100%分率)
let HitKeisan = function (_AChara, _BChara) {
    //{30+[(命中*2)/8]-[回避/8]}+技の命中補正+(テンション/8)
    let _命中 = _AChara.b_hit; 
    let _回避 = _BChara.b_avo; 
    let _テンション = _AChara._tp; 
    let _技の命中補正 = _AChara.Skill.speed; 
    let _テンション補正 = 0; 
    if (TH_ModeFlg) _テンション補正 = (_テンション / 8);
    let _最終命中 = (50 + (_命中 / 8) - (_回避 / 8)) + _技の命中補正 + _テンション補正;
    for (let i = 0; i <= _AChara.state.length - 1; i++) {
        let _ckst = $dataStates[_AChara.state[i]._No];
        for (let j = 0; j <= _ckst.traits.length - 1; j++) {
            switch (_ckst.traits[j].code) {
                case 11: 
                    switch (_ckst.traits[j].dataId) {
                        case _Zoku._命中率変化: 
                            let _val = _ckst.traits[j].value;
                            _最終命中 *= _val;
                            break;
                    }
                    break;
            }
        }
    }
    for (let i = 0; i <= _BChara.state.length - 1; i++) {
        let _ckst = $dataStates[_BChara.state[i]._No];
        for (let j = 0; j <= _ckst.traits.length - 1; j++) {
            switch (_ckst.traits[j].code) {
                case 11: 
                    switch (_ckst.traits[j].dataId) {
                        case _Zoku._被命中率変化: 
                            let _val = _ckst.traits[j].value;
                            _最終命中 *= _val;
                            break;
                    }
                    break;
            }
        }
    }
    if (_BChara.Skill != null) {
        if (_BChara.Skill.stypeId == _Stype._Taiki) _最終命中 += 20;
    } else {
        _最終命中 += 20;
    }
    _AChara.PsvArr.forEach(_AmmId => {
        let _Armor = $dataArmors[_AmmId];
        for (let i = 0; i <= _Armor.traits.length - 1; i++) { 
            switch (_Armor.traits[i].code) {
                case 22: 
                    if (_Armor.traits[i].dataId == 0) { 
                        _最終命中 += Math.floor(_Armor.traits[i].value * 100);
                    }
                    break;
            }
        }
    });
    _最終命中 -= Math.floor(_PsvVarGet(_BChara, 22, 1) * 100); 
    if (_最終命中 > 100) _最終命中 = 100;
    _AChara.dbgArr[0] = _最終命中; 
    return _最終命中;
}
let _PsvVarGet = function (_AChara, _caseNo, _dataId) {
    let _RtnVar = 0;
    _AChara.PsvArr.forEach(_AmmId => {
        let _Armor = $dataArmors[_AmmId];
        for (let i = 0; i <= _Armor.traits.length - 1; i++) { 
            switch (_Armor.traits[i].code) {
                case _caseNo: 
                    if (_Armor.traits[i].dataId == _dataId) {
                        _RtnVar += _Armor.traits[i].value;
                    }
                    break;
            }
        }
    });
    return _RtnVar;
}
let DmgFormula = function (_sikiStr, _AChara, _BChara) {
    let a = _AChara; 
    let b = _BChara;
    return _Dmgvar = Math.floor(eval(_sikiStr)); 
}
let NB_DmgPopUpdate = Game_Interpreter.prototype.NUpdate;
Game_Interpreter.prototype.NUpdate = function () {
    NB_DmgPopUpdate.call(this);
    this.DmgPop_Update();
}
class _DmgPop {
    constructor(_PicNo, _pX, _pY, _ViewFlame, _PopY) {
        this._PicNo = _PicNo;
        this._pX = _pX;
        this._pY = _pY;
        this._ViewFlame = _ViewFlame;
        this._PopY = _PopY;
    }
}
let DmgPopArr = []; 
Game_Interpreter.prototype.DmgPop_Update = function () {
    for (let i = 0; i <= DmgPopArr.length - 1; i++) {
        DmgPopArr[i]._ViewFlame--;
        if (DmgPopArr[i]._ViewFlame == 10) {
            this.MoveSprite(PN_bDmgPop + DmgPopArr[i]._PicNo,
                DmgPopArr[i]._pX, DmgPopArr[i]._pY, 10, 0, true, true);
        }
        if (DmgPopArr[i]._ViewFlame <= 0) {
            this.DelSprite(PN_bDmgPop + DmgPopArr[i]._PicNo);
            DmgPopArr.splice(i, 1);
            i--;
        }
    }
}
Game_Interpreter.prototype.DmgPop_Set = function (_Str, _pX, _pY, _Size, _Time, _PopY, _mx) {
    _Size = typeof _Size !== 'undefined' ? _Size : 30;
    _Time = typeof _Time !== 'undefined' ? _Time : 100;
    _PopY = typeof _PopY !== 'undefined' ? _PopY : 30;
    _mx = typeof _mx !== 'undefined' ? _mx : 100;
    let _ckArr = [];
    for (let i = 0; i <= DmgPopArr.length - 1; i++) {
        _ckArr.push(DmgPopArr[i]._PicNo);
    }
    let _PNo = 0;
    for (let i = 0; i <= 9; i++) {
        if (_ckArr.indexOf(i) == -1) {
            _PNo = i;
        }
    }
    D_Text_Cng_font = "Cornerstone"; 
    let _SetDmg = new _DmgPop(_PNo, _pX, _pY, _Time, _PopY);
    DmgPopArr.push(_SetDmg);
    _Str = "\\ow[5]\\oc[rgba(0,0,0,1)]" + _Str;
    this.SpriteStr(PN_bDmgPop + _PNo, " " + _Str + " ", _Size, _pX, _pY + 50, 0, _mx, _mx);
    EasingStr = "easeOutBounce";
    this.MoveSprite(PN_bDmgPop + _PNo, _pX, _pY, 50, 255, true, true);
    EasingStr = "";
    D_Text_Cng_font = ""; 
}
