let BtlTalkDialogStac = []; 
class TalkDialogData {
    constructor(ENo, dialogImg, _TxtArr, _ViewTime, _PosX, _PosY) {
        this._ENo = ENo;
        this._SelfImg = dialogImg;
        this._TxtArr = _TxtArr;
        this._ViewTime = _ViewTime;
        this._ViewFlg = false;
        this._PosX = _PosX;
        this._PosY = _PosY;
    }
}
let setBtlTalkDialogData = null;
class BtlTalkDialogSet {
    constructor(_ENo, _SelfImg, _ViewTime, _PosX, _PosY) {
        this._ENo = _ENo;
        this._SelfImg = _SelfImg;
        this._ViewTime = _ViewTime;
        this._PosX = _PosX;
        this._PosY = _PosY;
        this._TxtArr = [];
    }
}
let Nupu_BtlSeff_command101 = Game_Interpreter.prototype.command101;
Game_Interpreter.prototype.command101 = function () {
    if (setBtlTalkDialogData != null) { 
        while (this.isContinueMessageString()) {
            this._index++;
            if (this._list[this._index].code === 401) {
                if (this.currentCommand().parameters[0].indexOf("\\n<") == -1) { 
                    setBtlTalkDialogData._TxtArr.push(this.currentCommand().parameters[0]);
                }
            }
        }
        this.BtlTalkDialogAdd(setBtlTalkDialogData._ENo, setBtlTalkDialogData._SelfImg, setBtlTalkDialogData._TxtArr,
            setBtlTalkDialogData._ViewTime, setBtlTalkDialogData._PosX, setBtlTalkDialogData._PosY);
        return true;
    }
    Nupu_BtlSeff_command101.call(this);
}
Game_Interpreter.prototype.Btl_次のセリフを吹出し変更 = function (_ENo, _SelfImg, _ViewTime, _PosX, _PosY) {
    setBtlTalkDialogData = new BtlTalkDialogSet(_ENo, _SelfImg, _ViewTime, _PosX, _PosY);
}
Game_Interpreter.prototype.BtlTalkDialogAdd = function (_ENo, _SelfImg, _TxtArr, _ViewTime, _PosX, _PosY) {
    _PosX = typeof _PosX !== 'undefined' ? _PosX : 0;
    _PosY = typeof _PosY !== 'undefined' ? _PosY : -142;
    BtlTalkDialogStac.push(new TalkDialogData(_ENo, _SelfImg, _TxtArr, _ViewTime, _PosX, _PosY));
    setBtlTalkDialogData = null;
}
let CheckBtlTalkDialogView = function () {
    return BtlTalkDialogStac.length > 0;
}
Game_Interpreter.prototype.BtlTalkDialogUpdate = function () {
    if (BtlTalkDialogStac.length > 0) {
        if (!BtlTalkDialogStac[0]._ViewFlg) { 
            let _ENo = BtlTalkDialogStac[0]._ENo;
            let _SetPosX = BtlTalkDialogStac[0]._PosX - 374;
            let _SetPosY = BtlTalkDialogStac[0]._PosY - 131;
            if (_ENo <= -1) {
                _SetPosX += NPlayer[(_ENo * -1) - 1]._screenX;
                _SetPosY += NPlayer[(_ENo * -1) - 1]._screenY;
            } else {
                if (SetBtlMVVar_DoEnemyName_味方Flg) {
                    if (_ENo + 1 >= NPlayer.length) _ENo = NPlayer.length - 1; 
                    _SetPosX += NPlayer[_ENo + 1]._screenX;
                    _SetPosY += NPlayer[_ENo + 1]._screenY;
                } else {
                    if (_ENo >= NEnemy.length) _ENo = NEnemy.length - 1; 
                    _SetPosX += NEnemy[_ENo]._screenX;
                    _SetPosY += NEnemy[_ENo]._screenY;
                }
            }
            this.DelPictSpan(PN_BSelfWin , PN_BSelfTxt + 1); 
            let _TxtArr = BtlTalkDialogStac[0]._TxtArr;
            for (let i = 0; i < _TxtArr.length; i++) {
                if (_TxtArr[0].indexOf("\\n<") != -1 || _TxtArr[0].indexOf("\\N<") != -1) {
                    _TxtArr.splice(i, 1); 
                    i--; 
                }
            }
            let _ImgStr = BtlPicPath + BtlTalkDialogStac[0]._SelfImg + "_" + _TxtArr.length;
            this.SetPictC(PN_BSelfWin, _ImgStr, _SetPosX + 270, _SetPosY + 65, 255, 100, 0);
            if (_TxtArr.length == 1) {
                this.SetPicStrC(PN_BSelfTxt + 0, SCol.Blk0 + _TxtArr[0], 21, _SetPosX + 270, _SetPosY + 73
                    , 255, 100, 0);
            }
            if (_TxtArr.length == 2) {
                this.SetPicStrC(PN_BSelfTxt + 0, SCol.Blk0 + _TxtArr[0], 21, _SetPosX + 270, _SetPosY + 73 - 36
                    , 255, 100, 0);
                this.SetPicStrC(PN_BSelfTxt + 1, SCol.Blk0 + _TxtArr[1], 21, _SetPosX + 270, _SetPosY + 73
                    , 255, 100, 0);
            }
            EasingStr = "easeOutBack";
            for (let i = PN_BSelfWin; i <= PN_BSelfTxt + 1; i++) {
                this.MovePict(i, true, true, 15, true, true, 100);
            }
            EasingStr = "";
            BtlTalkDialogStac[0]._ViewFlg = true;
        } else {
            BtlTalkDialogStac[0]._ViewTime--;
            if (BtlTalkDialogStac[0]._ViewTime <= 0) {
                BtlTalkDialogStac.shift(); 
                for (let i = PN_BSelfWin; i <= PN_BSelfTxt + 1; i++) {
                    EasingStr = "easeOutBack";
                    this.MovePict(i, true, true, 15, true, true, 0);
                    EasingStr = "";
                }
            }
        }
        return true;
    }
    return false; 
}
