const _視界調整長さ = 0.2;
Game_Interpreter.prototype.Check前視界 = function (_長さ , _範囲 = 1) {
    return this.Check前視界EvNo(0 , _長さ , _範囲);
}
Game_Interpreter.prototype.Check前視界EvNo = function (_evNo , _長さ , _範囲 = 1) {
    var evChara = this.character(_evNo);
    var plChara = $gamePlayer;
    switch (evChara._direction) {
        case 2: 
            if (plChara._y > evChara._y) {
                if (Math.abs(plChara._x - evChara._x) < _範囲 &&
                    Math.abs(plChara._realY - evChara._realY) - _視界調整長さ < _長さ) {
                    console.log("下");
                    return true;
                }
            }
            break;
        case 4: 
            if (plChara._x < evChara._x) {
                if (Math.abs(plChara._y - evChara._y) < _範囲 &&
                    Math.abs(plChara._realX - evChara._realX) - _視界調整長さ < _長さ) {
                    console.log("左");
                    return true;
                }
            }
            break;
        case 6: 
            if (plChara._x > evChara._x) {
                if (Math.abs(plChara._y - evChara._y) < _範囲 &&
                    Math.abs(plChara._realX - evChara._realX) - _視界調整長さ < _長さ) {
                    console.log("右");
                    return true;
                }
            }
            break;
        case 8: 
            if (plChara._y < evChara._y) {
                if (Math.abs(plChara._x - evChara._x) < _範囲 &&
                    Math.abs(plChara._realY - evChara._realY) - _視界調整長さ < _長さ) {
                    console.log("上");
                    return true;
                }
            }
            break;
    }
    return false;
}
Game_Interpreter.prototype.Check前視界Memo = function (Memo , _長さ , _範囲 = 1) {
    let matchedEvents = [];
    for (const event of $gameMap.events()) {
        if (!event || !event.event()) continue; 
        let memoStr = MetaChecker(event.event() , "視界" , false);
        if (memoStr != false) {
            matchedEvents.push(event);
        }
    }
    for (let i = 0; i < matchedEvents.length; i++) {
        let evNo = matchedEvents[i]._eventId;
        if (this.Check前視界EvNo(evNo , _長さ , _範囲)) {
            return true;
        }
    }
    return false;
}
Game_Interpreter.prototype.Check方向視界 = function (_方向 , _長さ , _範囲 = 1) {
    var evChara = this.character(0);
    var plChara = $gamePlayer;
    switch (_方向) {
        case "下": 
            if (plChara._y >= evChara._y) {
                if (Math.abs(plChara._x - evChara._x) < _範囲 &&
                    Math.abs(plChara._realY - evChara._realY) - _視界調整長さ < _長さ) {
                    console.log("下");
                    return true;
                }
            }
            break;
        case "左": 
            if (plChara._x <= evChara._x) {
                if (Math.abs(plChara._y - evChara._y) < _範囲 &&
                    Math.abs(plChara._realX - evChara._realX) - _視界調整長さ < _長さ) {
                    console.log("左");
                    return true;
                }
            }
            break;
        case "右": 
            if (plChara._x >= evChara._x) {
                if (Math.abs(plChara._y - evChara._y) < _範囲 &&
                    Math.abs(plChara._realX - evChara._realX) - _視界調整長さ < _長さ) {
                    console.log("右");
                    return true;
                }
            }
            break;
        case "上": 
            if (plChara._y <= evChara._y) {
                if (Math.abs(plChara._x - evChara._x) < _範囲 &&
                    Math.abs(plChara._realY - evChara._realY) - _視界調整長さ < _長さ) {
                    console.log("上");
                    return true;
                }
            }
            break;
    }
    return false;
}
