const SW_AutoLog = 7;   
let BLog = []; 
let BLogStop = false; 
let NextPicNo = PN_LogBK;
let _BLogEndFlame = 0;
const bPicSa = 37; 
const blogMojiYZ = 2;
Game_Interpreter.prototype.BLogUpdate = function (_BLogZureY) {
    _BLogZureY = typeof _BLogZureY !== 'undefined' ? _BLogZureY : 0;
    let maxLogCnt = 4; 
    if (battleflg) maxLogCnt = 4; 
    if (BLog.length > 0) {
        _BLogEndFlame = 0;
        for (let i = 0; i <= BLog.length - 1; i++) {
            BLog[i][0]--; 
            if (i == maxLogCnt) {
                break; 
            }
        }
        if (BLog[0][0] <= 0) {
            this.MovePict(BLog[0][2], -521, BLog[0][3] + _BLogZureY, 15, 0);
            this.MovePict(BLog[0][2] + 1, -521, BLog[0][3] + 1 + _BLogZureY, 15, 0);
            for (let i = 1; i <= BLog.length - 1; i++) {
                BLog[i][3] -= bPicSa; 
                if (i <= maxLogCnt) { 
                    this.MovePict(BLog[i][2], 0, BLog[i][3] + _BLogZureY, 15, 255);
                    this.MovePict(BLog[i][2] + 1, 10, BLog[i][3] + blogMojiYZ + _BLogZureY, 15, 255);
                }
            }
            BLog.shift(); 
        }
    } else {
        if (_BLogEndFlame == 60) {
            this.DelPictSpan(PN_LogBK, PN_LogBK + 11);
        } else {
            _BLogEndFlame++;
        }
    }
    for (let i = 0; i <= BLog.length - 1; i++) {
        if (BLog[i][4] == false) { 
            this.SetPict(BLog[i][2], BtlPicPath + "PN_LogBK", -521, BLog[i][3] + _BLogZureY);
            this.SetPicStr(BLog[i][2] + 1, BLog[i][1], 22, -521, BLog[i][3] + blogMojiYZ + _BLogZureY);
            this.MovePict(BLog[i][2], 0, BLog[i][3] + _BLogZureY, 17);
            this.MovePict(BLog[i][2] + 1, 10, BLog[i][3] + blogMojiYZ + _BLogZureY, 15);
            BLog[i][4] = true;
        }
        if (i == maxLogCnt) {
            break; 
        }
    }
};
Game_Interpreter.prototype.BLogStop = function () {
    BLog = [];
    BLogStop = true;
    this.BLogDell();
}
Game_Interpreter.prototype.BLogStart = function () {
    BLogStop = false;
}
Game_Interpreter.prototype.BLogAdd = function (SSFlame, SetStr, _ColNo) {
    _ColNo = typeof _ColNo !== 'undefined' ? _ColNo : -1;
    if (SetStr == "") return;
    let _ColStr = "";
    if (_ColNo != -1) {
        _ColStr = "\\C[" + _ColNo + "]";
    }
    BLog.push([SSFlame, _ColStr + SetStr, NextPicNo, 84 + bPicSa * BLog.length, false]);
    if (BLog.length > 5) {
        for (let i = 0; i < BLog.length - 5; i++) {
            let setFrame = 10 + i * 5;
            if (BLog[i][0] > setFrame) BLog[i][0] = setFrame;
        }
    }
    NextPicNo += 2;
    if (NextPicNo >= PN_LogBK + 11) {
        NextPicNo = PN_LogBK;
    }
};
Game_Interpreter.prototype.BLogDell = function () {
    for (let i = PN_LogBK; i <= PN_LogBK + 11; i++) {
        this.DelPict(i);
    }
}
Game_Interpreter.prototype.command126 = function () {
    let value = this.operateValue(this._params[1], this._params[2], this._params[3]);
    $gameParty.gainItem($dataItems[this._params[0]], value);
    if (!$gameSwitches.value(SW_AutoLog) &&
        (MenuModeStr == _MMode.Map || MenuModeStr == _MMode.TalkMode)) {
        if (value == 1) this.BLogAdd(180, $dataItems[this._params[0]].name + "を手に入れた！");
        if (value > 1) this.BLogAdd(180, $dataItems[this._params[0]].name + "を " + value + "個 手に入れた！");
    }
    return true;
};
Game_Interpreter.prototype.command127 = function () {
    let value = this.operateValue(this._params[1], this._params[2], this._params[3]);
    $gameParty.gainItem($dataWeapons[this._params[0]], value, this._params[4]);
    if (!$gameSwitches.value(SW_AutoLog) &&
        (MenuModeStr == _MMode.Map || MenuModeStr == _MMode.TalkMode)) {
        if (value == 1) this.BLogAdd(180, "カード「" + $dataWeapons[this._params[0]].name + "」を手に入れた！");
        if (value > 1) this.BLogAdd(180, "カード「" + $dataWeapons[this._params[0]].name + "」を " + value + "枚 手に入れた！");
    }
    return true;
};
