code:
//=============================================================================
// AB_SymbolEncounter.js
//=============================================================================
//
// RPGツクールMV用プラグイン　出現位置がランダムなシンボルエンカウントシステム
//
//=============================================================================
// 作者　misty_rain
// ホームページ　Anti-Belphetan
// http://kilisamenosekai.web.fc2.com/
//
// Copyright (c) 2016 misty_rain
// Released under the MIT license
// http://opensource.org/licenses/mit-license.php
//=============================================================================
// ver 1.0 2016/04/14 公開
// ver 1.1 2016/04/18 パラメータが読めなくなっていたので修正
// ver 1.2 2016/08/30 ツクールMV1.3.1に対応
//
//=============================================================================
/*:
 * @plugindesc 出現位置がランダムなシンボルエンカウントシステム
 *
 * @author misty_rain
 *
 * @help イベントの名前を「EnemySymbol」と指定すると、
 * そのイベントはシンボルエンカウント向きの動きをします。
 * メモに「<Region:1>」と指定すると、そのイベントはリージョン1でのみ出現します。
 * 「<Region:2,3>」と指定すれば、そのイベントはリージョン2と3で出現します。
 *
 * ・普段は右か左に90度回転、一歩前進などの動きをします。
 * ・プレイヤーが視界に入ると発見モードになります。
 * ・イベントが向いてる方向に距離6(デフォルト)、幅3(固定)が視界です。横とか後ろから近付いても発見されません。
 * ・発見モードになると、ひたすらプレイヤーに近づく動きになります。
 * ・発見モードでは、プレイヤーとの距離8(デフォルト)より離れると見失います。向いてる方向関係ありません。
 * ・普段の状態の場合、一定時間経過、プレイヤーとの距離10(デフォルト)より離れると消えます。
 * ・消えた後、しばらくするとプレイヤーとの距離10(デフォルト)以内で、指定したリージョン番号の場所に出現します。
 * ・イベントの実行内容で、移動ルートの指定：このイベントで不透明度0にした場合も、どこかへ出現します。
 * ・戦闘の処理など、イベントの実行内容はツクーラーさんが作成してください。最後は移動ルートの指定：このイベントで不透明度0にして消してください。
 * ・イベントが始まると消えます。イベント中は再出現しません。
 * ・発見モード時、プレイヤーの後ろから接触された場合、不意打ち　→　パーティ能力の　不意打ち無効　で防げます
 *　・普段、イベントの後ろからプレイヤーが接触すると先制攻撃　→　パーティ能力の　先制攻撃率アップ　で正面以外先制攻撃(正面だと先に発見モードになる)
 * ・敵の視界は、スイッチで可視化できます。
 *
 * 以下、上級編です。上手く使わないと動かなくなったりします。
 * ・プラグインコマンドはありませんが、移動ルート指定でスクリプトに「this.checkPlayerInSightToSelfSwA();」を指定すると、
 * 　プレイヤーが視界内にいるかどうかチェックし、いればセルフスイッチAがON,いなければOFFになります。
 * ・同様に 「this.checkPlayerInSightToSelfSwB();」でセルフスイッチB、
 * 　 「this.checkPlayerInSightToSelfSwC();」でセルフスイッチC、
 * 　 「this.checkPlayerInSightToSelfSwD();」でセルフスイッチDがONになります。
 * 　また、「this.checkPlayerInSightToSwitch(ONにしたいスイッチNo);」でチェック結果を指定したNoのスイッチに入れます。
 *
 * ・イベントの移動ルートの指定にて、スクリプト「this.stareEffect(距離)」を指定すると、指定した距離内にいるイベントは、
 * 　そのイベントがいる方を一定時間凝視します。例えば、不審な音がしたのでそちらを向くなどの用途に。
 * ・移動ルート指定でスクリプトに「this.checkStareToSelfSwA();」を指定すると、
 * 　凝視中の動作を行い、凝視中ならセルフスイッチAがON,凝視していなければOFFになります。
 * ・同様に 「this.checkStareToSelfSwA();」でセルフスイッチB、
 * 　 「this.checkStareToSelfSwB();」でセルフスイッチC、
 * 　 「this.checkStareToSelfSwC();」でセルフスイッチDがONになります。
 * 　また、「this.checkStareToSwitch(ONにしたいスイッチNo);」でチェック結果を指定したNoのスイッチに入れます。
 * ・イベントの移動ルートの指定にて、スクリプト「this.moveTowardStare();」を指定すると、凝視地点へ一歩近づきます。
 * (例えば一定のルートを巡回しているような場合、凝視地点へ近付けさせた後、何もないと気付いて元のルートに戻るとかはありません)
 * ・イベントの移動ルートの指定にて、スクリプト「this.moveToward(x,y);」を指定すると、x,yで指定した座標へ一歩近づきます。
 *
 * =============================================================================
 * @param FindBalloon
 * @desc 発見モードになった時の吹き出し番号
 * @default 1
 *
 * @param LoseBalloon
 * @desc 発見モードで　見失った時の吹き出し番号
 * @default 2
 *
 * @param FindMoveSpeed
 * @desc 発見モード時の歩く速度
 * @default 4
 *
 * @param NormalMoveSpeed
 * @desc 普段の速度
 * @default 3
 *
 * @param AppearanceTime
 * @desc 普段の状態で、消えるまでの時間
 * @default 100
 *
 * @param SightArea
 * @desc 視界の距離
 * @default 5
 *
 * @param WarpTryTime
 * @desc ワープ試行回数。消えた後、再出現する位置をランダムで決め、リージョンが合うかの判定をする。合うまでは出現しない。一回のループで何回試行するか。
 * @default 10
 *
 * @param ChaseArea
 * @desc　発見モード時、追いかけてくる距離。これを超えると見失う。
 * @default 8
 *
 * @param AppearanceArea
 * @desc 普段、この距離以上にプレイヤーが離れたら強制的に消え、再出現する
 * @default 15
 *
 * @param WarpArea
 * @desc　出現範囲。プレイヤーを中心に、ここで指定した範囲内でランダムに出現
 * @default 10
 *
 * @param LoseCount
 * @desc　発見モード時、プレイヤーを見失ってから、発見モードOFFになるまでのカウント
 * @default 100
 *
 * @param MinWaitTime
 * @desc　普段、動作を待つカウントの最小
 * @default 60
 *
 * @param RndWaitTime
 * @desc　普段、動作を待つカウントの幅(最小＋ランダム分待つ、そのランダムを指す)
 * @default 60
 *
 * @param SightColor
 * @desc　敵視界を可視化した時の色
 * @default red
 *
 * @param SightVisibleSwId
 * @desc　敵視界を可視化するスイッチの番号　１ならスイッチ1ONで敵の視界を可視化する
 * @default 1
 *
 * @param SightOpacity
 * @desc　敵視界を可視化したとき、敵視界の不透明度
 * @default 64
 *
 * @param StareCountMin
 * @desc　不審な音がした時などで、そっちの方を凝視する時間の最小
 * @default 180
 *
 * =============================================================================
 */

(function() {

var parameters = PluginManager.parameters('AB_SymbolEncounter');
var AB_SymbolEncounterMove_FindBalloon = Number(parameters['FindBalloon'] ||　1);
var AB_SymbolEncounterMove_LoseBalloon = Number(parameters['LoseBalloon'] ||　2);
var AB_SymbolEncounterMove_StareBalloon = Number(parameters['StareBalloon'] ||　1);
var AB_SymbolEncounterMove_StareEndBalloon = Number(parameters['StareEndBalloon'] ||　2);
var AB_SymbolEncounterMove_FindMoveSpeed = Number(parameters['FindMoveSpeed'] ||　4);
var AB_SymbolEncounterMove_NormalMoveSpeed = Number(parameters['NormalMoveSpeed'] ||　3);
var AB_SymbolEncounterMove_AppearanceTime = Number(parameters['AppearanceTime'] ||　100);
var AB_SymbolEncounterMove_SightArea = Number(parameters['SightArea'] ||　5);
var AB_SymbolEncounterMove_WarpTryTime = Number(parameters['WarpTryTime'] ||　10);
var AB_SymbolEncounterMove_ChaseArea = Number(parameters['ChaseArea'] ||　8);
var AB_SymbolEncounterMove_AppearanceArea = Number(parameters['AppearanceArea'] || 15);
var AB_SymbolEncounterMove_WarpArea = Number(parameters['WarpArea'] ||　10);
var AB_SymbolEncounterMove_LoseCount = Number(parameters['LoseCount'] ||　100);
var AB_SymbolEncounterMove_MinWaitTime = Number(parameters['MinWaitTime'] || 60);
var AB_SymbolEncounterMove_RndWaitTime = Number(parameters['RndWaitTime'] || 60);
var AB_SymbolEncounterMove_EnemySymbolEventName = "EnemySymbol";

var AB_SEM_SIGHT_FILLRECT_COLOR = parameters['SightColor']||"red" ;
var AB_SEM_SIGHT_FILLRECT_VISIBLE_SW_ID = Number(parameters['SightVisibleSwId'] || 1);

var AB_SEM_SIGHT_FILLRECT_OPACITY = Number(parameters['SightOpacity'] || 32);

var AB_SEM_StareCountMin = Number(parameters['StareCountMin']||180);

Game_Event.prototype.checkTargetInSightStraight  = function(x,y,targetX,targetY,d,step) {
	var sightX = x;
	var sightY = y;
	var findX = targetX;
	var findY = targetY;

	for(var i=0;i<step;i++)
	{
		if(!this.findMode)
		{
			this.fillSights.push([sightX,sightY]);
		}
	    if(findX==sightX && findY==sightY){
	    	return true;
	    }
	    if(!this.canPass(sightX,sightY,d)&& i<step-1)
	    {
	    	i=step-1;
	    }
	    switch (d) {
	    case 2:
	        sightY+=1;
	        break;
	    case 4:
	        sightX-=1;
	        break;
	    case 6:
	        sightX+=1;
	        break;
	    case 8:
	        sightY-=1;
	        break;
	    }
		if(!this.findMode)
		{
			this.fillSights.push([sightX,sightY]);
		}
	    if(findX==sightX && findY==sightY){
	    	return true;
	    }
	}
	return false;
};

Game_Event.prototype.checkTargetInSightDiagonally  = function(x,y,targetX,targetY,d,step) {
	var horz = d;
	var vert = d;
	var horz2 = d;
	var vert2 = d;

	var sightX = x;
	var sightY = y;
	var sightX2 = x;
	var sightY2 = y;
    switch (d) {
    case 2:
		horz = 4;
		horz2 = 6;
		sightY +=1;
		sightY2 +=1;
		sightX -= 1;
		sightX2 += 1;
        break;
    case 4:
		vert = 8;
		vert2 = 2;
		sightX -= 1;
		sightX2 -= 1;
		sightY -= 1;
		sightY2 += 1;
        break;
    case 6:
		vert = 8;
		vert2 = 2;
		sightX += 1;
		sightX2 += 1;
		sightY -= 1;
		sightY2 += 1;
        break;
    case 8:
		horz = 4;
		horz2 = 6;
		sightY -=1;
		sightY2 -=1;
		sightX -= 1;
		sightX2 += 1;
        break;
    }
    var find = false;
    //console.log("horz="+horz+"vert="+vert);
    if(targetX==sightX && targetY==sightY){
    	return true;
    }
    if(this.canPassDiagonally(x, y, horz, vert))
    {
    	find = this.checkTargetInSightStraight(sightX,sightY,targetX,targetY,d,step-1);
    }
    if(!find)
    {
    	//console.log("horz="+horz+"vert="+vert);
	    if(targetX==sightX2 && targetY==sightY2){
	    	return true;
	    }
	    if(this.canPassDiagonally(x, y, horz2, vert2))
	    {
	    	find = this.checkTargetInSightStraight(sightX2,sightY2,targetX,targetY,d,step-1);
	    }
    }
    return find;

};
Game_Event.prototype.findPlayer=function()
{
    var bef = this.findMode;
    if (bef == undefined)
    {
    	bef = false;
    }
    this.findMode = true;
    var aft = this.findMode;
    if(bef != aft)
    {
   		this.requestBalloon(AB_SymbolEncounterMove_FindBalloon);
        this.turnTowardPlayer();
    	this.mresPhase = 0;
    }
}
Game_Event.prototype.losePlayer=function()
{
    var bef = this.findMode;
    if (bef == undefined)
    {
    	bef = false;
    }
    this.findMode = false;
    var aft = this.findMode;
    if(bef != aft)
    {
   		this.requestBalloon(AB_SymbolEncounterMove_LoseBalloon);
    	this.mresPhase = 0;
    }
}

Tilemap.prototype.createSightLayers = function() {
    var width = this._width;
    var height = this._height;
    var margin = this._margin;
    var tileCols = Math.ceil(width / this._tileWidth) + 1;
    var tileRows = Math.ceil(height / this._tileHeight) + 1;
    var layerWidth = tileCols * this._tileWidth;
    var layerHeight = tileRows * this._tileHeight;
    this._sightBitmap = new Bitmap(layerWidth, layerHeight);
    this._sightLayer = new Sprite();
    this._sightLayer.opacity = AB_SEM_SIGHT_FILLRECT_OPACITY;
    //this._sightLayer.move(-margin, -margin, width, height);
    this._sightLayer.z = 2;
    // for (var i = 0; i < 4; i++) {
    // 	this._sightLayer.addChild(new Sprite(this._sightBitmap));
    // }
    this._sightLayer.addChild(new Sprite(this._sightBitmap));
    this.addChild(this._sightLayer);
};

var AB_SEM_Tilemap_updateLayerPositions= ShaderTilemap.prototype._updateLayerPositions;
ShaderTilemap.prototype._updateLayerPositions = function(startX, startY) {
	AB_SEM_Tilemap_updateLayerPositions.call(this,startX, startY);
    var m = this._margin;
    var ox = Math.floor(this.origin.x);
    var oy = Math.floor(this.origin.y);
    var x2 = (ox - m).mod(this._layerWidth);
    var y2 = (oy - m).mod(this._layerHeight);
    var w1 = this._layerWidth - x2;
    var h1 = this._layerHeight - y2;
    var w2 = this._width - w1;
    var h2 = this._height - h1;
    var children = this._sightLayer.children;
    children[0].move(0, 0, w1, h1);
};
var AB_SEM_Spriteset_Map_updateTilemap = Spriteset_Map.prototype.updateTilemap;
Spriteset_Map.prototype.updateTilemap = function() {
    AB_SEM_Spriteset_Map_updateTilemap.call(this);
    var tw = $gameMap.tileWidth();
    var th = $gameMap.tileHeight();
    var tilemap = this._tilemap;
    if(tilemap._sightLayer == undefined || tilemap._sightBitmap == undefined)
    {
    	tilemap.createSightLayers();
    }
	tilemap._sightLayer.opacity = $gameSwitches.value(AB_SEM_SIGHT_FILLRECT_VISIBLE_SW_ID) ? AB_SEM_SIGHT_FILLRECT_OPACITY: 0;

    var events = $gameMap.events()

    tilemap._sightBitmap.clear();
	for(var i = 0;i < events.length; i++)
	{
        if(events[i].fillSights !=  undefined)
        {
			for(var j = 0;j < events[i].fillSights.length; j++)
			{
	        	var xxx = events[i].fillSights[j][0];
	        	var yyy = events[i].fillSights[j][1];
	        	var xxxx = (xxx * tw)-tilemap.origin.x;
	        	var yyyy = (yyy * th)-tilemap.origin.y;

		        tilemap._sightBitmap.fillRect(
	        		 xxxx,
	        		 yyyy,
	        		 tilemap._tileWidth,tilemap._tileHeight,
	        		 AB_SEM_SIGHT_FILLRECT_COLOR
	        	);
	        }
        }
        events[i].fillSights = [];
	}

};

Game_Event.prototype.checkPartyInSight = function(sightX,sightY) {

	var findX = $gamePlayer.x;
	var findY = $gamePlayer.y;

	var find = this.checkTargetInSightStraight(sightX,sightY,findX,findY,this.direction(),AB_SymbolEncounterMove_SightArea);
	if(!find)
	{
		find = this.checkTargetInSightDiagonally(sightX,sightY,findX,findY,this.direction(),AB_SymbolEncounterMove_SightArea);
	}
	if(!find)
	{
		var followers = $gamePlayer.followers();
		if(followers)
		{
			for(var i=0;i<followers._data.length;i++)
			{
				if(followers._data[i].isVisible())
				{
					findX = followers._data[i].x;
					findY = followers._data[i].y;
					find = this.checkTargetInSightStraight(sightX,sightY,findX,findY,this.direction(),AB_SymbolEncounterMove_SightArea);
					if(!find)
					{
						find = this.checkTargetInSightDiagonally(sightX,sightY,findX,findY,this.direction(),AB_SymbolEncounterMove_SightArea);
					}
					if(find)
					{
						return find;
					}

				}
			}
		}
	}

	return find;
}
Game_Event.prototype.checkPlayerInSight = function() {
	var sightX = this._x;
	var sightY = this._y;
	this.fillSights = [];
	var find = this.checkPartyInSight(sightX,sightY);
	if(find)
	{
		this.findPlayer();
		this.loseCount = AB_SymbolEncounterMove_LoseCount;
	}else{
		if(this.loseCount <= 0)
		{
			this.losePlayer();
		}else{
			this.loseCount--;
		}
	}
};

Game_Event.prototype.canWarp = function(x, y,regions,targetX,targetY) {
	if(targetX == x && targetY == y)
	{
		return false;
	}
	var sa = Math.abs(targetX - x)+Math.abs(targetY - y);
	//console.log("sa="+sa);
	if(sa <= 5)
	{
		return false;
	}
	var foundRegion = false;
	for(var i = 0;i<regions.length;i++)
	{
	    if ($gameMap.regionId(x, y)==regions[i]) {
	    	foundRegion = true;
	        break;
	    }
	}
	if(regions.length == 0)
	{
		foundRegion = true;
	}
	if(!foundRegion){
		return false;
	}
    if (!$gameMap.isValid(x, y)) {
        return false;
    }
    if(!$gameMap.checkPassage(x, y, 0x0f)){
    	return false;
    }
    if (this.isThrough() || this.isDebugThrough()) {
        return true;
    }
    if (this.isCollidedWithCharacters(x, y)) {
        return false;
    }
    return true;
};
Game_Event.prototype.warpToPlayer = function(dist,regions) {
	var centerX = $gamePlayer.x;
	var centerY = $gamePlayer.y;
	var minDistX = 3;

	var warpX = centerX + (Math.randomInt(dist*2)-dist);
	var warpY = centerY + (Math.randomInt(dist*2)-dist);
	var times = AB_SymbolEncounterMove_WarpTryTime;
	while(!this.canWarp(warpX,warpY,regions,centerX,centerY))
	{
		warpX = centerX + (Math.randomInt(dist*2)-dist);
		warpY = centerY + (Math.randomInt(dist*2)-dist);
		times--;
		if(times < 1)
		{
			break;
		}
	}
	if(this.canWarp(warpX,warpY,regions,centerX,centerY))
	{
		this.setPosition(warpX,warpY);
		return true;
	}
	return false;
}
Game_Event.prototype.moveRouteEnemySymbolFind = function()
{
    this.setMoveSpeed(AB_SymbolEncounterMove_FindMoveSpeed);
	if(this._opacity == 255)
	{
        var distance = $gameMap.distance(
        	this._x, this._y, $gamePlayer.x, $gamePlayer.y);
        if(distance < AB_SymbolEncounterMove_ChaseArea)
        {
        	if(!this.isBalloonPlaying())
        	{
		        this.moveTowardPlayer();
        	}
        }else{
        	this.losePlayer();
        }
	}else if(this._opacity == 0)
	{
		this.mresPhase = 7;
        this.findMode = false;
	}
}
Game_Event.prototype.moveRouteEnemySymbolNormal = function(regions)
{
    this.setMoveSpeed(AB_SymbolEncounterMove_NormalMoveSpeed);
	if(this.mresPhase == undefined)
	{
		this.mresPhase = 0;
	}
	if(this.mresTime == undefined)
	{
		this.mresTime = AB_SymbolEncounterMove_AppearanceTime;
	}else if(this.mresTime>0){
		this.mresTime -= 1;
	}

    switch (this.mresPhase) {
    case 0:
    	this.setStepAnime(true);
        //
        this.mresPhase = 1;
        break;
    case 1:
		this.turnRightOrLeft90();
        this._waitCount = Math.randomInt(AB_SymbolEncounterMove_RndWaitTime)
        	+AB_SymbolEncounterMove_MinWaitTime - 1;
        if(Math.randomInt(100)<50&&this.mresTime>0)
        {
	        this.mresPhase = 0;
        }else{
       		this.mresPhase = 2;
        }
        break;
    case 2:
    case 3:
    case 4:
    case 5:
        this.moveForward();
        if(Math.randomInt(100)<25&&this.mresTime>0)
        {
	        this.mresPhase = 0;
        }else{
        	this.mresPhase +=1;
        }
        break;
    case 6:
        this._waitCount = Math.randomInt(AB_SymbolEncounterMove_RndWaitTime)
        	+AB_SymbolEncounterMove_MinWaitTime - 1;
        if(Math.randomInt(100)<10||this.mresTime<0)
        {
	        this.mresPhase = 7;
        }else{
       		this.mresPhase = 0;
        }
        break;
    case 7:
	    if(!this.isBalloonPlaying())
	    {
	    	if(this._opacity==255)
	    	{
	        	this.jump(0,0);
	    	}
	        this.setOpacity(this._opacity-8);
	        if(this._opacity<=0)
	        {
	    		// console.log("disappear");
	        	this._opacity = 0;
	        	this.mresPhase = 8;
	        	this.setThrough(true);
	        	this.setPosition(0,0);
        		this._waitCount = Math.randomInt(180)+(180) - 1;
	        }
    	}
        break;
    case 8:
        var warpOK = this.warpToPlayer(AB_SymbolEncounterMove_WarpArea,regions);
        if(warpOK)
        {
    		// console.log("warpOK!"+this._x+","+this._y+"player="+$gamePlayer.x+","+$gamePlayer.y);
        	this.mresPhase = 9;
        }
        break;
    case 9:
        this.setOpacity(this._opacity+8);
        if(this._opacity>=255)
        {
    		// console.log("appear!");
			this.mresTime = AB_SymbolEncounterMove_AppearanceTime;
        	this.setOpacity(255);
        	this.mresPhase = 10;
        	this.setThrough(false);
        }
        break;
    case 10:
    	this.jump(0,0);
      	this.mresPhase = 0;
    	break;
    default:
    	this.mresPhase = 0;
    }
}
Game_Event.prototype.moveRouteEnemySymbol = function(regions)
{

    var distance = $gameMap.distance(
    	this._x, this._y, $gamePlayer.x, $gamePlayer.y);
	// console.log("region="+region+"distance="+distance);
	if(($gameMap.isEventRunning()&& !this._locked) || distance >= AB_SymbolEncounterMove_AppearanceArea )
	{
		if(this.mresPhase != 7 && this.mresPhase != 8)
		{
			this.mresPhase = 7;
		}
        this.findMode = false;
	}
	if(this.findMode)
	{
		this.moveRouteEnemySymbolFind();
	}else{
		this.moveRouteEnemySymbolNormal(regions);
	}

}
Game_Event.prototype.isEnemySymbolEvent= function() {
	return this.event().name.indexOf(AB_SymbolEncounterMove_EnemySymbolEventName) != -1;
}
Game_Event.prototype.getRegions= function() {
	var regions = [];
	var metaRegions = this.event().meta.Region;
	if(metaRegions != undefined)
	{
		var number = "";
		for(var i = 0; i < metaRegions.length;i++){
			if(metaRegions[i] == ',')
			{
				regions.push(parseInt(number,10));
				number = "";
			}else{
				number = number + "" + metaRegions[i];
			}
		}
		if(number!= "")
		{
				regions.push(parseInt(number,10));
		}
	}

	return regions;
}
Game_Event.prototype.updateRoutineMove = function() {
    if (this.isEnemySymbolEvent() && !this._locked) {

	    if (this._waitCount > 0) {
	        this._waitCount--;
	    } else {
	        this.setMovementSuccess(true);
	        this.moveRouteEnemySymbol(this.getRegions());
            this.advanceMoveRouteIndex();
	    }
    }else{
		Game_Character.prototype.updateRoutineMove.call(this);
    }
};
var AB_Game_Event_updateSelfMovement = Game_Event.prototype.updateSelfMovement;
Game_Event.prototype.updateSelfMovement = function() {
    if (this.isEnemySymbolEvent()) {

		if(this._opacity == 255&& (!$gameMap.isEventRunning()))
		{
	        this.checkPlayerInSight();
	        if(!this.findMode)
	        {
				this.updateStare();
	        }
		}
    	if (!this._locked &&　this.checkStop(this.stopCountThreshold())) {
        	this.moveTypeCustom();
    	}
    }else{
    	AB_Game_Event_updateSelfMovement.call(this);
    }
};
// var AB_Game_Event_checkEventTriggerTouch = Game_Event.prototype.checkEventTriggerTouch;
// Game_Event.prototype.checkEventTriggerTouch = function(x,y) {
// 	if(this.isEnemySymbolEvent())
// 	{
// 	    if (!$gameMap.isEventRunning()&&!this.isBalloonPlaying()&&this._opacity==255) {
// 	        if (this._trigger === 2 && $gamePlayer.pos(x, y)) {
// 	            if (!this.isJumping() && this.isNormalPriority()) {
// 	                this.start();
// 	            }
// 	        }
// 	    }
// 	}else{
// 	    AB_Game_Event_checkEventTriggerTouch.call(this,x,y);
// 	}
// };
var AB_SEM_Game_Event_isNormalPriority = Game_Event.prototype.isNormalPriority;
Game_Event.prototype.isNormalPriority = function() {
	if(this.isEnemySymbolEvent())
	{
		if(this._opacity==255&&!this.isJumping()&&this.mresPhase <7)
		{
    		return this._priorityType === 1;
    	}else{
    		return false;
    	}
    }else{
    	return AB_SEM_Game_Event_isNormalPriority.call(this);
    }
};
var AB_SEM_Game_Event_lock = Game_Event.prototype.lock;
Game_Event.prototype.lock = function() {
	if(this.isEnemySymbolEvent())
	{
		//console.log("lock!");
		this.setAbSem();
	    if (!this._locked) {
	        this._prelockDirection = this.direction();
	        this._locked = true;
	    }
	}else{
		AB_SEM_Game_Event_lock.call(this);
	}
};

Game_Event.prototype.setAbSem = function(){
	if(this.findMode == false)
	{
		if(!$gameParty.hasRaisePreemptive())
		{
			//console.log("this.direction()="+this.direction());
			if(this.direction() == 2 && this.y > $gamePlayer.y)
			{
				$gameParty.setAbSemPreemptive(true);
			}else if(this.direction() == 8 && this.y < $gamePlayer.y)
			{
				$gameParty.setAbSemPreemptive(true);
			}else if(this.direction() == 4 && this.x < $gamePlayer.x)
			{
				$gameParty.setAbSemPreemptive(true);
			}else if(this.direction() == 6 && this.x > $gamePlayer.x)
			{
				$gameParty.setAbSemPreemptive(true);
			}
		}else{
			//console.log("this.direction()="+this.direction());
			$gameParty.setAbSemPreemptive(true);
		}
	}else{
		//console.log("findMode!");
		if(!$gameParty.hasCancelSurprise())
		{
			if($gamePlayer.direction() == 2 && $gamePlayer.y > this.y)
			{
				$gameParty.setAbSemSurprise(true);
			}else if($gamePlayer.direction() == 8 && $gamePlayer.y < this.y)
			{
				$gameParty.setAbSemSurprise(true);
			}else if($gamePlayer.direction() == 4 && $gamePlayer.x < this.x)
			{
				$gameParty.setAbSemSurprise(true);
			}else if($gamePlayer.direction() == 6 && $gamePlayer.x > this.x)
			{
				$gameParty.setAbSemSurprise(true);
			}
		}
	}
}
Game_Event.prototype.checkPlayerInSightToSelfSwA = function() {
	var key = [this._mapId, this._eventId, 'A'];
	this.checkPlayerInSight();
	$gameSelfSwitches.setValue(key,this.findMode);
};
Game_Event.prototype.checkPlayerInSightToSelfSwB = function() {
	var key = [this._mapId, this._eventId, 'B'];
	this.checkPlayerInSight();
	$gameSelfSwitches.setValue(key,this.findMode);
};
Game_Event.prototype.checkPlayerInSightToSelfSwC = function() {
	var key = [this._mapId, this._eventId, 'C'];
	this.checkPlayerInSight();
	$gameSelfSwitches.setValue(key,this.findMode);
};
Game_Event.prototype.checkPlayerInSightToSelfSwD = function() {
	var key = [this._mapId, this._eventId, 'D'];
	this.checkPlayerInSight();
	$gameSelfSwitches.setValue(key,this.findMode);
};
Game_Character.prototype.checkPlayerInSightToSwitch = function(switchNo) {
	this.checkPlayerInSight();
	$gameSwitches.setValue(switchNo, this.findMode);
};

Game_Character.prototype.initStare = function() {
	this.stareMode = false;
	this.stareX = 0;
	this.stareY = 0;
	this.stareCount = 0;
	this.stareFirstBalloon = false;
};
Game_Character.prototype.setStare = function(x,y,count) {
	this.stareMode = true;
	this.stareX = x;
	this.stareY = y;
	this.stareCount = count;
	this._waitCount = 0;
};
Game_Character.prototype.checkStare = function(x,y,range) {
	if(this.stareMode == undefined)
	{
		this.initStare();
	}
	var distance = Math.abs(this._x-x) + Math.abs(this._y-y);
	console.log("checkStare!");
	if(distance <= range)
	{
		var rnd = Math.randomInt(AB_SEM_StareCountMin)+AB_SEM_StareCountMin;
		var bef = this.stareMode;
		this.setStare(x,y,rnd);
		var aft = this.stareMode;

		this.stareFirstBalloon = true;
		this.turnToStare();
	}
};
Game_Character.prototype.turnToStare = function() {
    var sx = this.deltaXFrom(this.stareX);
    var sy = this.deltaYFrom(this.stareY);
    if (Math.abs(sx) > Math.abs(sy)) {
        this.setDirection(sx > 0 ? 4 : 6);
    } else if (sy !== 0) {
        this.setDirection(sy > 0 ? 8 : 2);
    }
};
Game_Character.prototype.moveTowardStare = function() {
    var sx = this.deltaXFrom(this.stareX);
    var sy = this.deltaYFrom(this.stareY);
    if (Math.abs(sx) > Math.abs(sy)) {
        this.moveStraight(sx > 0 ? 4 : 6);
        if (!this.isMovementSucceeded() && sy !== 0) {
            this.moveStraight(sy > 0 ? 8 : 2);
        }
    } else if (sy !== 0) {
        this.moveStraight(sy > 0 ? 8 : 2);
        if (!this.isMovementSucceeded() && sx !== 0) {
            this.moveStraight(sx > 0 ? 4 : 6);
        }
    }
};
Game_Character.prototype.moveToward = function(x,y) {
    var sx = this.deltaXFrom(x);
    var sy = this.deltaYFrom(y);
    if (Math.abs(sx) > Math.abs(sy)) {
        this.moveStraight(sx > 0 ? 4 : 6);
        if (!this.isMovementSucceeded() && sy !== 0) {
            this.moveStraight(sy > 0 ? 8 : 2);
        }
    } else if (sy !== 0) {
        this.moveStraight(sy > 0 ? 8 : 2);
        if (!this.isMovementSucceeded() && sx !== 0) {
            this.moveStraight(sx > 0 ? 4 : 6);
        }
    }
};
Game_Character.prototype.updateStare = function() {
    if(this.stareMode)
    {
    	this.turnToStare();
    	if(!this.isBalloonPlaying())
    	{
    		if(this.stareFirstBalloon)
    		{
	   			this.requestBalloon(AB_SymbolEncounterMove_StareBalloon);
				this.stareFirstBalloon = false;
    		}
	    	this.stareCount-=1;
	    	if(this.stareCount <= 0)
	    	{
	   			this.requestBalloon(AB_SymbolEncounterMove_StareEndBalloon);
	   			this.initStare();
	    	}
    	}
    }
};
Game_Character.prototype.stareEffect = function(range) {
	var id = this._eventId;
	var x = this._x;
	var y = this._y;
	$gameMap.events().forEach(function(event) {
		console.log("id="+id+" event._eventId"+event._eventId);
		if(id != event._eventId && event._opacity == 255)
		{
			event.checkStare(x,y,range);
		}
	}, this);
};

Game_Event.prototype.checkStareToSelfSwA = function() {
	var key = [this._mapId, this._eventId, 'A'];
	this.updateStare();
	$gameSelfSwitches.setValue(key,this.stareMode);
};
Game_Event.prototype.checkStareToSelfSwB = function() {
	var key = [this._mapId, this._eventId, 'B'];
	this.updateStare();
	$gameSelfSwitches.setValue(key,this.stareMode);
};
Game_Event.prototype.checkStareToSelfSwC = function() {
	var key = [this._mapId, this._eventId, 'C'];
	this.updateStare();
	$gameSelfSwitches.setValue(key,this.stareMode);
};
Game_Event.prototype.checkStareToSelfSwD = function() {
	var key = [this._mapId, this._eventId, 'D'];
	this.updateStare();
	$gameSelfSwitches.setValue(key,this.stareMode);
};
Game_Character.prototype.checkStareToSwitch = function(switchNo) {
	this.updateStare();
	$gameSwitches.setValue(switchNo, this.stareMode);
};

var AB_SEM_BattleManager_setup = BattleManager.setup;
BattleManager.setup = function(troopId, canEscape, canLose) {
	AB_SEM_BattleManager_setup.call(this,troopId, canEscape, canLose);
	if($gameParty.isAbSemEnable()){
	    this._preemptive = $gameParty.getAbSemPreemptive();
	    this._surprise = ($gameParty.getAbSemSurprise() && !this._preemptive);
	}
	$gameParty.resetAbSem();
};

Game_Party.prototype.getAbSemPreemptive = function()
{
	if(this.abSemPreemptive == undefined)
	{
		this.abSemPreemptive = false;
	}
	return this.abSemPreemptive;
}
Game_Party.prototype.getAbSemSurprise = function()
{
	if(this.abSemSurprise == undefined)
	{
		this.abSemSurprise = false;
	}
	return this.abSemSurprise;
}
Game_Party.prototype.setAbSemPreemptive = function(set)
{
	this.abSemPreemptive = set;
	this.abSemEnable = set;
}
Game_Party.prototype.setAbSemSurprise = function(set)
{
	//console.log("setAbSemSurprise!2");
	this.abSemSurprise = set;
	this.abSemEnable = set;
}
Game_Party.prototype.resetAbSem = function()
{
	this.abSemPreemptive = false;
	this.abSemSurprise = false;
	this.abSemEnable = false;
}
Game_Party.prototype.isAbSemEnable = function()
{
	if(this.abSemEnable == undefined)
	{
		this.abSemEnable = false;
	}
	return this.abSemEnable ;
}

})();


code:
//=============================================================================
// AKUNON_MapScrollDisable.js
// Version: 0.90R
// ----------------------------------------------------------------------------
// Original author: 河原 つつみ
// 連絡先 ：『アクマの脳髄』http://www.akunou.com/
// Original version: AKUNOU_MapScrollDisable.js 0.90
// v.90R author: Remtairy http://www.patreon.com/remtairy
//=============================================================================

/*:
 * @plugindesc プレイヤーキャラの移動に同期した画面スクロールを、一時的に無効にするプラグインコマンドを追加します。
 * @author Remtairy
 * @help
 * プラグインコマンド:
 *   MapScrollDisable 0 # プレイヤー移動によるマップスクロールを許可(初期値)
 *   MapScrollDisable 1 # プレイヤー移動によるマップスクロールを禁止
 *   MapScrollDisable 2 # プレイヤー移動によるXマップスクロールを禁止
 *   MapScrollDisable 3 # プレイヤー移動によるYマップスクロールを禁止
 */

(function() {

    //-------------------------------------------------------------------------
    // Game_System
    //-------------------------------------------------------------------------

    var akunou3_initialize = Game_System.prototype.initialize;
    Game_System.prototype.initialize = function() {
        akunou3_initialize.call(this);
        this._mapscrollEnabled = 0;
    }

    Game_System.prototype.ismapscrollEnabled = function() {
        return this._mapscrollEnabled == 0;
    };

	Game_System.prototype.isXMapScrollDisabled = function() {
        return (this._mapscrollEnabled == 2 || this._mapscrollEnabled == 1);
    };

	Game_System.prototype.isYMapScrollDisabled = function() {
        return (this._mapscrollEnabled == 3 || this._mapscrollEnabled == 1);
    };

    Game_System.prototype.disableAllMapScroll = function() {
        this._mapscrollEnabled = 1;
    };

	Game_System.prototype.disableXMapScroll = function() {
        this._mapscrollEnabled = 2;
    };

	Game_System.prototype.disableYMapScroll = function() {
        this._mapscrollEnabled = 3;
    };

    Game_System.prototype.enableMapScroll = function() {
        this._mapscrollEnabled = 0;
    };

    //-------------------------------------------------------------------------
    // Game_Player
    //-------------------------------------------------------------------------

	Game_Map.prototype.scrollDown = function(distance) {
		if($gameSystem.isYMapScrollDisabled() === true) { return; }
		if (this.isLoopVertical()) {
			this._displayY += distance;
			this._displayY %= $dataMap.height;
			if (this._parallaxLoopY) {
				this._parallaxY += distance;
			}
		} else if (this.height() >= this.screenTileY()) {
			var lastY = this._displayY;
			this._displayY = Math.min(this._displayY + distance,
				this.height() - this.screenTileY());
			this._parallaxY += this._displayY - lastY;
		}
	};

	Game_Map.prototype.scrollLeft = function(distance) {
		if($gameSystem.isXMapScrollDisabled() === true) { return; }
		if (this.isLoopHorizontal()) {
			this._displayX += $dataMap.width - distance;
			this._displayX %= $dataMap.width;
			if (this._parallaxLoopX) {
				this._parallaxX -= distance;
			}
		} else if (this.width() >= this.screenTileX()) {
			var lastX = this._displayX;
			this._displayX = Math.max(this._displayX - distance, 0);
			this._parallaxX += this._displayX - lastX;
		}
	};

	Game_Map.prototype.scrollRight = function(distance) {
	if($gameSystem.isXMapScrollDisabled() === true) { return; }
		if (this.isLoopHorizontal()) {
			this._displayX += distance;
			this._displayX %= $dataMap.width;
			if (this._parallaxLoopX) {
				this._parallaxX += distance;
			}
		} else if (this.width() >= this.screenTileX()) {
			var lastX = this._displayX;
			this._displayX = Math.min(this._displayX + distance,
				this.width() - this.screenTileX());
			this._parallaxX += this._displayX - lastX;
		}
	};

	Game_Map.prototype.scrollUp = function(distance) {
	if($gameSystem.isYMapScrollDisabled() === true) { return; }
		if (this.isLoopVertical()) {
			this._displayY += $dataMap.height - distance;
			this._displayY %= $dataMap.height;
			if (this._parallaxLoopY) {
				this._parallaxY -= distance;
			}
		} else if (this.height() >= this.screenTileY()) {
			var lastY = this._displayY;
			this._displayY = Math.max(this._displayY - distance, 0);
			this._parallaxY += this._displayY - lastY;
		}
	};

    //-------------------------------------------------------------------------
    // Game_Interpreter
    //-------------------------------------------------------------------------

    var _Game_Interpreter_pluginCommand =
            Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        _Game_Interpreter_pluginCommand.call(this, command, args);
        if (command === 'MapScrollDisable') {
            if (Number(args[0]) === 0) {
                $gameSystem.enableMapScroll();
            }
			else if (Number(args[0]) === 1) {
                $gameSystem.disableAllMapScroll();
            }
			else if (Number(args[0]) === 2) {
                $gameSystem.disableXMapScroll();
            }
			else if (Number(args[0]) === 3) {
                $gameSystem.disableYMapScroll();
            }
			else {
				$gameSystem.enableMapScroll();
			}

        }
    };

})();

license: unknown


code:
//=============================================================================
// AKUNOU_OptionBase.js
// Version: 1.02
// ----------------------------------------------------------------------------
// 河原 つつみ
// 連絡先 ：『アクマの脳髄』http://www.akunou.com/
//=============================================================================

/*:
 * @plugindesc オプション追加用のベーススクリプトです。
 * 入れるだけで若干オプションの操作性が向上したりもします。
 * @author Tsutumi Kawahara
 *
 * @param Window Options Width
 * @desc オプションウィンドウ幅を変更します。
 * 表示名とステータスの表示が被ってしまう場合などに。
 * @default 400
 *
 * @param Window Options Number
 * @desc オプションウィンドウの一画面に表示する項目数。
 * @default 13
 *
 * @help
 * プラグインコマンド:
 *   必要なし
 * プラグイン ON にするだけで適用されるスクリプトです。
 */

(function() {

	var parameters = PluginManager.parameters('AKUNOU_OptionBase');
	var windowOptionsWidth = Number(parameters['Window Options Width']);
	var windowOptionsNumber = Number(parameters['Window Options Number']);

	//-------------------------------------------------------------------------
	// ConfigManager
	//-------------------------------------------------------------------------

	var akunou8_makeData = ConfigManager.makeData;

	ConfigManager.makeData = function() {
		var config = akunou8_makeData.call(this);
		this.makeExtraData(config);
		return config;
	};

	ConfigManager.makeExtraData = function(config) {
		return config;
	};

	//-------------------------------------------------------------------------
	// Window_Options
	//-------------------------------------------------------------------------

	Window_Options.prototype.windowWidth = function() {
		return windowOptionsWidth;
	};

	Window_Options.prototype.windowHeight = function() {
		return this.fittingHeight(Math.min(this.numVisibleRows(), windowOptionsNumber));
	};

    var akunou8_makeCommandList = Window_Options.prototype.makeCommandList;

    Window_Options.prototype.makeCommandList = function() {
		this.addExtraOptions();
		akunou8_makeCommandList.call(this);
    }

	Window_Options.prototype.addExtraOptions = function() {
	};

	Window_Options.prototype.statusText = function(index) {
		var symbol = this.commandSymbol(index);
		var value = this.getConfigValue(symbol);
		if (this.isVolumeSymbol(symbol)) {
			return this.volumeStatusText(value);
		} else if (this.isHexSymbol(symbol)) {
			return value;
		} else if (this.isKeySymbol(symbol)) {
			return this.keyStatusText(symbol, value);
		} else {
			return this.booleanStatusText(value);
		}
	};

	Window_Options.prototype.isHexSymbol = function(symbol) {
		return symbol.contains('Hex');
	};

	Window_Options.prototype.isOpacitySymbol = function(symbol) {
		return symbol.contains('Opacity');
	};

	Window_Options.prototype.isColorSymbol = function(symbol) {
		return symbol.contains('Color');
	};

	Window_Options.prototype.isKeySymbol = function(symbol) {
		return symbol.contains('Key');
	};

	Window_Options.prototype.isDefaultSymbol = function(symbol) {
		return symbol.contains('default');
	};

	Window_Options.prototype.keyStatusText = function(symbol, value) {
		return null;
	};

	Window_Options.prototype.keyLength = function(symbol) {
		return null;
	};

	Window_Options.prototype.processOk = function() {
		var index = this.index();
		var symbol = this.commandSymbol(index);
		var value = this.getConfigValue(symbol);
		var lastValue = value;
		if (this.isDefaultSymbol(symbol)) {
			this.defaultAll();
			SoundManager.playOk();
		} else if (this.isVolumeSymbol(symbol)) {
			value += this.volumeOffset();
			if (lastValue < 100 && value > 100) {
				value = 100;
			}
			if (value > 100) {
				value = 0;
			}
			value = value.clamp(0, 100);
			this.changeValue(symbol, value);
		} else if (this.isOpacitySymbol(symbol)) {
			value += this.opacityOffset();
			if (lastValue < 255 && value > 255) {
				value = 255;
			}
			if (value > 255) {
				value = 0;
			}
			value = value.clamp(0, 255);
			this.changeValue(symbol, value);
		} else if (this.isColorSymbol(symbol)) {
			value += this.colorOffset();
			if (lastValue < 255 && value > 255) {
				value = 255;
			}
			if (value > 255) {
				value = -255;
			}
			value = value.clamp(-255, 255);
			this.changeValue(symbol, value);
		} else if (this.isKeySymbol(symbol)) {
			value += 1;
			if (value > this.keyLength(symbol)) {
				value = 0;
			}
			value = value.clamp(0, this.keyLength(symbol));
			this.changeValue(symbol, value);
		} else {
			this.changeValue(symbol, !value);
		}
	};

	Window_Options.prototype.cursorRight = function(wrap) {
		var index = this.index();
		var symbol = this.commandSymbol(index);
		var value = this.getConfigValue(symbol);
		var lastValue = value;
		if (this.isDefaultSymbol(symbol)) {
		} else if (this.isVolumeSymbol(symbol)) {
			value += this.volumeOffset();
			if (lastValue < 100 && value > 100) {
				value = 100;
			}
			if (wrap && value > 100) {
				value = 0;
			}
			value = value.clamp(0, 100);
			this.changeValue(symbol, value);
		} else if (this.isOpacitySymbol(symbol)) {
			value += this.opacityOffset();
			if (lastValue < 255 && value > 255) {
				value = 255;
			}
			if (wrap && value > 255) {
				value = 0;
			}
			value = value.clamp(0, 255);
			this.changeValue(symbol, value);
		} else if (this.isColorSymbol(symbol)) {
			value += this.colorOffset();
			if (lastValue < 255 && value > 255) {
				value = 255;
			}
			if (wrap && value > 255) {
				value = -255;
			}
			value = value.clamp(-255, 255);
			this.changeValue(symbol, value);
		} else if (this.isKeySymbol(symbol)) {
			value += 1;
			if (wrap && value > this.keyLength(symbol)) {
				value = 0;
			}
			value = value.clamp(0, this.keyLength(symbol));
			this.changeValue(symbol, value);
		} else {
			if (wrap) {
				this.changeValue(symbol, !value);
			} else {
				this.changeValue(symbol, true);
			}
		}
	};

	Window_Options.prototype.cursorLeft = function(wrap) {
		var index = this.index();
		var symbol = this.commandSymbol(index);
		var value = this.getConfigValue(symbol);
		var lastValue = value;
		if (this.isDefaultSymbol(symbol)) {
		} else if (this.isVolumeSymbol(symbol)) {
			value -= this.volumeOffset();
			if (lastValue > 0 && value < 0) {
				value = 0;
			}
			if (wrap && value < 0) {
				value = 100;
			}
			value = value.clamp(0, 100);
			this.changeValue(symbol, value);
		} else if (this.isOpacitySymbol(symbol)) {
			value -= this.opacityOffset();
			if (lastValue > 0 && value < 0) {
				value = 0;
			}
			if (wrap && value < 0) {
				value = 255;
			}
			value = value.clamp(0, 255);
			this.changeValue(symbol, value);
		} else if (this.isColorSymbol(symbol)) {
			value -= this.colorOffset();
			if (lastValue > -255 && value < -255) {
				value = -255;
			}
			if (wrap && value < -255) {
				value = 255;
			}
			value = value.clamp(-255, 255);
			this.changeValue(symbol, value);
		} else if (this.isKeySymbol(symbol)) {
			value -= 1;
			if (wrap && value < 0) {
				value = this.keyLength(symbol);
			}
			value = value.clamp(0, this.keyLength(symbol));
			this.changeValue(symbol, value);
		} else {
			if (wrap) {
				this.changeValue(symbol, !value);
			} else {
				this.changeValue(symbol, false);
			}
		}
	};

})();


code:
//=============================================================================
// AKUNOU_OptionGauge.js
// Version: 1.01
// ----------------------------------------------------------------------------
// 河原 つつみ
// 連絡先 ：『アクマの脳髄』http://www.akunou.com/
//=============================================================================

/*:
 * @plugindesc オプションの数値で表されている一部項目にゲージを描画します。
 * @author Tsutumi Kawahara
 *
 * @param Gauge Color 1
 * @desc ゲージのグラデーションに使われるカラー1。
 * 各数値は R(赤), G(緑), B(青), A(アルファ値) 。
 * @default 255, 204, 32, 255
 *
 * @param Gauge Color 2
 * @desc ゲージのグラデーションに使われるカラー2。
 * 各数値は R(赤), G(緑), B(青), A(アルファ値) 。
 * @default 255, 255, 160, 255
 *
 * @param Gauge Color R 1
 * @desc R値ゲージのグラデーションに使われるカラー1。
 * ウィンドウカラーオプションを使用する場合にのみ必要。
 * @default 255, 96, 96, 255
 *
 * @param Gauge Color R 2
 * @desc R値ゲージのグラデーションに使われるカラー2。
 * ウィンドウカラーオプションを使用する場合にのみ必要。
 * @default 255, 192, 192, 255
 *
 * @param Gauge Color G 1
 * @desc G値ゲージのグラデーションに使われるカラー1。
 * ウィンドウカラーオプションを使用する場合にのみ必要。
 * @default 96, 255, 96, 255
 *
 * @param Gauge Color G 2
 * @desc G値ゲージのグラデーションに使われるカラー2。
 * ウィンドウカラーオプションを使用する場合にのみ必要。
 * @default 192, 255, 192, 255
 *
 * @param Gauge Color B 1
 * @desc B値ゲージのグラデーションに使われるカラー1。
 * ウィンドウカラーオプションを使用する場合にのみ必要。
 * @default 96, 96, 255, 255
 *
 * @param Gauge Color B 2
 * @desc B値ゲージのグラデーションに使われるカラー2。
 * ウィンドウカラーオプションを使用する場合にのみ必要。
 * @default 192, 192, 255, 255
 *
 * @help
 * プラグインコマンド:
 *   必要なし
 * プラグイン ON にするだけで適用されるスクリプトです。
 */

(function() {

	var parameters = PluginManager.parameters('AKUNOU_OptionGauge');
	var gaugeColor1 = 'rgba(' + parameters['Gauge Color 1'] + ')';
	var gaugeColor2 = 'rgba(' + parameters['Gauge Color 2'] + ')';
	var gaugeColorR1 = 'rgba(' + parameters['Gauge Color R 1'] + ')';
	var gaugeColorR2 = 'rgba(' + parameters['Gauge Color R 2'] + ')';
	var gaugeColorG1 = 'rgba(' + parameters['Gauge Color G 1'] + ')';
	var gaugeColorG2 = 'rgba(' + parameters['Gauge Color G 2'] + ')';
	var gaugeColorB1 = 'rgba(' + parameters['Gauge Color B 1'] + ')';
	var gaugeColorB2 = 'rgba(' + parameters['Gauge Color B 2'] + ')';

	//-------------------------------------------------------------------------
	// Window_Options
	//-------------------------------------------------------------------------

	var akunou10_drawItem = Window_Options.prototype.drawItem;

	Window_Options.prototype.drawItem = function(index) {
		var symbol = this.commandSymbol(index);
		if (this.isVolumeSymbol(symbol) || this.isHexSymbol(symbol)) {
			if (this.isVolumeSymbol(symbol)) {
				var max = 100;
			} else if (this.isOpacitySymbol(symbol)) {
				var max = 255;
			} else if (this.isColorSymbol(symbol)) {
				var max = 510;
			}
			var value = this.getConfigValue(symbol);
			var rect = this.itemRectForText(index);
			var statusWidth = this.statusWidth();
			if (this.isColorSymbol(symbol)) {
				if (symbol === 'windowColorRHex') {
					this.drawGauge(rect.width - statusWidth, rect.y, statusWidth, (value + 255) / max, gaugeColorR1, gaugeColorR2);
				} else if (symbol === 'windowColorGHex') {
					this.drawGauge(rect.width - statusWidth, rect.y, statusWidth, (value + 255) / max, gaugeColorG1, gaugeColorG2);
				} else if (symbol === 'windowColorBHex') {
					this.drawGauge(rect.width - statusWidth, rect.y, statusWidth, (value + 255) / max, gaugeColorB1, gaugeColorB2);
				}
			} else {
				this.drawGauge(rect.width - statusWidth, rect.y, statusWidth, value / max, gaugeColor1, gaugeColor2);
			}
		}
		akunou10_drawItem.call(this, index);
	};

})();


code:
//=============================================================================
// AKUNOU_OptionMessageSpeed.js
// Version: 1.01
// ----------------------------------------------------------------------------
// 河原 つつみ
// 連絡先 ：『アクマの脳髄』http://www.akunou.com/
//=============================================================================

/*:
 * @plugindesc オプションにメッセージ表示速度の変更を追加します。
 * 動作には同作者のオプションベーススクリプトが必須です。
 * @author Tsutumi Kawahara
 *
 * @param Message Speed Term
 * @desc メッセージ表示速度のオプション画面での表示名を変更します。
 * @default メッセージ速度
 *
 * @param Message Speed List
 * @desc ステータスリスト。表示名: 速度 として表記します。
 * {}",などは外さないで下さい。書式に従えば追加も可能です。
 * @default {"最遅": -2, "遅い": -1, "標準": 0, "微妙に速い": 1, "速い": 2, "もっと速い": 4, "かなり速い": 10, "とても速い": 20, "瞬間": 100}
 *
 * @param Message Speed Default
 * @desc メッセージ表示速度のデフォルトインデックス。
 * ステータスリストの1番目を0として数えて下さい。
 * @default 2
 *
 * @help
 * プラグインコマンド:
 *   必要なし
 * プラグイン ON にするだけで適用されるスクリプトです。
 */

(function() {

	var parameters = PluginManager.parameters('AKUNOU_OptionMessageSpeed');
	var messageSpeedText = parameters['Message Speed Term'];
	var messageSpeedList = JSON.parse(parameters['Message Speed List']);
	var messageSpeedDefault = Number(parameters['Message Speed Default']);

	//-------------------------------------------------------------------------
	// ConfigManager
	//-------------------------------------------------------------------------

	ConfigManager.messageSpeedKey = messageSpeedDefault;

	var akunou4_makeExtraData = ConfigManager.makeExtraData;

	ConfigManager.makeExtraData = function(config) {
		akunou4_makeExtraData.call(this, config);
		config.messageSpeedKey = this.messageSpeedKey;
		return config;
	};

	var akunou4_applyData = ConfigManager.applyData;

	ConfigManager.applyData = function(config) {
		akunou4_applyData.call(this, config);
		this.messageSpeedKey = this.readMessageSpeed(config, 'messageSpeedKey');
	};

	ConfigManager.readMessageSpeed = function(config, name) {
		var value = config[name];
		if (value !== undefined) {
			return Number(value).clamp(0, Object.keys(messageSpeedList).length-1);
		} else {
			return messageSpeedDefault;
		}
	};

	//-------------------------------------------------------------------------
	// Window_Options
	//-------------------------------------------------------------------------

    var akunou4_addExtraOptions = Window_Options.prototype.addExtraOptions;

	Window_Options.prototype.addExtraOptions = function() {
		this.addCommand(messageSpeedText, 'messageSpeedKey');
		akunou4_addExtraOptions.call(this);
	};

	var akunou4_keyStatusText = Window_Options.prototype.keyStatusText;

	Window_Options.prototype.keyStatusText = function(symbol, value) {
		if (symbol === 'messageSpeedKey') {
			return String(Object.keys(messageSpeedList)[Number(value)]);
		} else {
			return akunou4_keyStatusText.call(this, symbol, value);
		}
	};

	var akunou4_keyLength = Window_Options.prototype.keyLength;

	Window_Options.prototype.keyLength = function(symbol) {
		if (symbol === 'messageSpeedKey') {
			return Number(Object.keys(messageSpeedList).length)-1;
		} else {
			return akunou4_keyLength.call(this, symbol);
		}
	};

	var akunou4_defaultAll = Window_Options.prototype.defaultAll;

	Window_Options.prototype.defaultAll = function() {
		akunou4_defaultAll.call(this);
		this.changeValue('messageSpeedKey', messageSpeedDefault);
	};

	//-------------------------------------------------------------------------
	// Window_Message
	//-------------------------------------------------------------------------

	var akunou4_processNormalCharacter = Window_Message.prototype.processNormalCharacter;

	Window_Message.prototype.processNormalCharacter = function(textState) {
		akunou4_processNormalCharacter.call(this, textState);
		this._speedCount--;
		if (this._showFast || this._lineShowFast) {
			return;
		}
		this._waitCount = this._speedWait;
	};

	var akunou4_initMembers = Window_Message.prototype.initMembers;

	Window_Message.prototype.initMembers = function() {
		this._speedWait = 0;
		this._speedCount = 0;
		akunou4_initMembers.call(this);
	};

	Window_Message.prototype.updateMessage = function() {
		if (this._textState) {
			if (messageSpeedList[Object.keys(messageSpeedList)[ConfigManager['messageSpeedKey']]] < 0) {
				this._speedWait = Math.abs(messageSpeedList[Object.keys(messageSpeedList)[ConfigManager['messageSpeedKey']]]);
				this._speedCount = 0;
			} else {
				this._speedWait = 0;
				this._speedCount = messageSpeedList[Object.keys(messageSpeedList)[ConfigManager['messageSpeedKey']]]+1;
			}
			while (!this.isEndOfText(this._textState)) {
				if (this.needsNewPage(this._textState)) {
					this.newPage(this._textState);
				}
				this.updateShowFast();
				this.processCharacter(this._textState);
				if (this._speedCount <= 0 && !this._showFast && !this._lineShowFast) {
					break;
				}
				if (this.pause || this._waitCount > 0) {
					break;
				}
			}
			if (this.isEndOfText(this._textState)) {
				this.onEndOfText();
			}
			return true;
		} else {
			return false;
		}
	};

})();


code:
//=============================================================================
// ARP_TitleCommandExit.js
//=============================================================================

/*:
 * @plugindesc v1.00 Adds an option in the title command window to close
 * game window.
 * @author Atreyo Ray
 *
 * @param Command Exit
 * @desc The text that should appear as the exit command.
 * @default Quit
 *
 * @param Show Exit
 * @desc Highly recommended to only show when deploying to Windows
   or Mac iOS. For HTML or mobiles, make it false.
 * @default true
 *
 * @help This plugin does not provide plugin commands.
 */

(function() {

    var parameters = PluginManager.parameters('ARP_TitleCommandExit');
    var textExit = parameters['Command Exit'];
    var showExit = parameters['Show Exit'];

    var _Window_TitleCommand_makeCommandList =
            Window_TitleCommand.prototype.makeCommandList;
    Window_TitleCommand.prototype.makeCommandList = function() {
        _Window_TitleCommand_makeCommandList.call(this);
       // if (eval(showExit)){
       //     this.addCommand(textExit, 'exitGame');
       // }
    };

    var _Scene_Title_createCommandWindow =
            Scene_Title.prototype.createCommandWindow;
    Scene_Title.prototype.createCommandWindow = function() {
        _Scene_Title_createCommandWindow.call(this);
        this._commandWindow.setHandler('exitGame', this.commandExitGame.bind(this));
    };

    Scene_Title.prototype.commandExitGame = function() {
        this._commandWindow.close();
        this.fadeOutAll();
        SceneManager.exit();
    };

})();


code:
//=============================================================================
// AltMenuScreen.js
//=============================================================================

/*:
 * @plugindesc Alternative menu screen layout.
 * @author Yoji Ojima
 *
 * @help This plugin does not provide plugin commands.
 */

/*:ja
 * @plugindesc メニュー画面のレイアウトを変更します。
 * @author Yoji Ojima
 *
 * @help このプラグインには、プラグインコマンドはありません。
 */

(function() {

    var _Scene_Menu_create = Scene_Menu.prototype.create;
    Scene_Menu.prototype.create = function() {
        _Scene_Menu_create.call(this);
        this._statusWindow.x = 0;
        this._statusWindow.y = this._commandWindow.height;
        this._goldWindow.x = Graphics.boxWidth - this._goldWindow.width;
    };

    Window_MenuCommand.prototype.windowWidth = function() {
        return Graphics.boxWidth;
    };

    Window_MenuCommand.prototype.maxCols = function() {
        return 4;
    };

    Window_MenuCommand.prototype.numVisibleRows = function() {
        return 2;
    };

    Window_MenuStatus.prototype.windowWidth = function() {
        return Graphics.boxWidth;
    };

    Window_MenuStatus.prototype.windowHeight = function() {
        var h1 = this.fittingHeight(1);
        var h2 = this.fittingHeight(2);
        return Graphics.boxHeight - h1 - h2;
    };

    Window_MenuStatus.prototype.maxCols = function() {
        return 4;
    };

    Window_MenuStatus.prototype.numVisibleRows = function() {
        return 1;
    };

    Window_MenuStatus.prototype.drawItemImage = function(index) {
        var actor = $gameParty.members()[index];
        var rect = this.itemRectForText(index);
        var w = Math.min(rect.width, 144);
        var h = Math.min(rect.height, 144);
        var lineHeight = this.lineHeight();
        this.changePaintOpacity(actor.isBattleMember());
        this.drawActorFace(actor, rect.x, rect.y + lineHeight * 2.5, w, h);
        this.changePaintOpacity(true);
    };

    Window_MenuStatus.prototype.drawItemStatus = function(index) {
        var actor = $gameParty.members()[index];
        var rect = this.itemRectForText(index);
        var x = rect.x;
        var y = rect.y;
        var width = rect.width;
        var bottom = y + rect.height;
        var lineHeight = this.lineHeight();
        this.drawActorName(actor, x, y + lineHeight * 0, width);
        this.drawActorLevel(actor, x, y + lineHeight * 1, width);
        this.drawActorClass(actor, x, bottom - lineHeight * 4, width);
        this.drawActorHp(actor, x, bottom - lineHeight * 3, width);
        this.drawActorMp(actor, x, bottom - lineHeight * 2, width);
        this.drawActorIcons(actor, x, bottom - lineHeight * 1, width);
    };

    var _Window_MenuActor_initialize = Window_MenuActor.prototype.initialize;
    Window_MenuActor.prototype.initialize = function() {
        _Window_MenuActor_initialize.call(this);
        this.y = this.fittingHeight(2);
    };

})();


code:
//=============================================================================
// AltMenuScreen2.js
//=============================================================================

/*:
 * @plugindesc Alternative menu screen layout.
 * @author Yoji Ojima, Sasuke KANNAZUKI
 *
 * @param backGroundBitmap
 * @desc background bitmap file at img/pictures.
 * @default
 *
 * @param maxColsMenu
 * @desc max column at menu window
 * @default 4
 *
 * @param commandRows
 * @desc number of visible rows at command window
 * @default 2
 *
 * @param isDisplayStatus
 * @desc whether display status or not. (1 = yes, 0 = no)
 * @default 0
 *
 * @help This plugin does not provide plugin commands.
 *  The differences with AltMenuscreen are follows:
 *   - windows are transparent
 *   - it can set the menu's background bitmap.
 *   - picture is actors' original
 *
 * Actor' note:
 * <stand_picture:filename> set actor's standing picture at menu.
 *   put file at img/pictures.
 *
 * preferred size of actor's picture:
 * width: 174px(maxColsMenu=4), 240px(maxColsMenu=3)
 * height: 408px(commandRows=2), 444px(commandRows=1)
 */

/*:ja
 * @plugindesc レイアウトの異なるメニュー画面
 * @author Yoji Ojima, 神無月サスケ
 *
 * @param backGroundBitmap
 * @desc 背景にするビットマップファイルです。
 * img/pictures に置いてください。
 * @default
 *
 * @param maxColsMenu
 * @desc アクターを表示するウィンドウの1画面の登録最大数です。
 * @default 4
 *
 * @param commandRows
 * @desc コマンドウィンドウの行数です。
 * @default 2
 *
 * @param isDisplayStatus
 * @desc ステータスを表示するかしないかを選びます。(1 = yes, 0 = no)
 * @default 0
 *
 * @help このプラグインには、プラグインコマンドはありません。
 *
 *  AltMenuscreen との違いは以下です:
 *  - ウィンドウが透明です
 *  - 背景ビットマップを付けることが出来ます。
 *  - アクターに立ち絵を利用します。
 *
 * アクターのメモに以下のように書いてください:
 * <stand_picture:ファイル名> ファイル名が、そのアクターの立ち絵になります。
 *   ファイルは img/pictures に置いてください。
 *
 * 望ましいアクター立ち絵のサイズ：
 * 幅：3列:240px, 4列：174px
 * 高さ： コマンドウィンドウ 1行:444px 2行:408px
 *
 */

(function() {

    // set parameters
    var parameters = PluginManager.parameters('AltMenuScreen2');
    var backGroundBitmap = parameters['backGroundBitmap'] || '';
    var maxColsMenuWnd = Number(parameters['maxColsMenu'] || 4);
    var rowsCommandWnd = Number(parameters['commandRows'] || 2);
    var isDisplayStatus = !!Number(parameters['isDisplayStatus']);

    var _Scene_Menu_create = Scene_Menu.prototype.create;
    Scene_Menu.prototype.create = function() {
        _Scene_Menu_create.call(this);
        this._statusWindow.x = 0;
        this._statusWindow.y = this._commandWindow.height;
        this._goldWindow.x = Graphics.boxWidth - this._goldWindow.width;
        // make transparent for all windows at menu scene.
        this._statusWindow.opacity = 0;
        this._goldWindow.opacity = 0;
        this._commandWindow.opacity = 0;
    };

    // load bitmap that set in plugin parameter
    var _Scene_Menu_createBackground = Scene_Menu.prototype.createBackground;
    Scene_Menu.prototype.createBackground = function(){
        if(backGroundBitmap){
            this._backgroundSprite = new Sprite();
            this._backgroundSprite.bitmap =
             ImageManager.loadPicture(backGroundBitmap);
            this.addChild(this._backgroundSprite);
            return;
        }
        // if background file is invalid, it does original process.
        _Scene_Menu_createBackground.call(this);
    };

    Window_MenuCommand.prototype.windowWidth = function() {
        return Graphics.boxWidth;
    };

    Window_MenuCommand.prototype.maxCols = function() {
        return 4;
    };

    Window_MenuCommand.prototype.numVisibleRows = function() {
        return rowsCommandWnd;
    };

    Window_MenuStatus.prototype.windowWidth = function() {
        return Graphics.boxWidth;
    };

    Window_MenuStatus.prototype.windowHeight = function() {
        var h1 = this.fittingHeight(1);
        var h2 = this.fittingHeight(rowsCommandWnd);
        return Graphics.boxHeight - h1 - h2;
    };

    Window_MenuStatus.prototype.maxCols = function() {
        return maxColsMenuWnd;
    };

    Window_MenuStatus.prototype.numVisibleRows = function() {
        return 1;
    };

    Window_MenuStatus.prototype.drawItemImage = function(index) {
        var actor = $gameParty.members()[index];
        var rect = this.itemRectForText(index);
        // load stand_picture
        var bitmapName = $dataActors[actor.actorId()].meta.stand_picture;
        var bitmap = bitmapName ? ImageManager.loadPicture(bitmapName) : null;
        var w = Math.min(rect.width, (bitmapName ? bitmap.width : 144));
        var h = Math.min(rect.height, (bitmapName ? bitmap.height : 144));
        var lineHeight = this.lineHeight();
        this.changePaintOpacity(actor.isBattleMember());
        if(bitmap){
            var sx = (bitmap.width > w) ? (bitmap.width - w) / 2 : 0;
            var sy = (bitmap.height > h) ? (bitmap.height - h) / 2 : 0;
            var dx = (bitmap.width > rect.width) ? rect.x :
                rect.x + (rect.width - bitmap.width) / 2;
            var dy = (bitmap.height > rect.height) ? rect.y :
                rect.y + (rect.height - bitmap.height) / 2;
            this.contents.blt(bitmap, sx, sy, w, h, dx, dy);
        } else { // when bitmap is not set, do the original process.
            this.drawActorFace(actor, rect.x, rect.y + lineHeight * 2.5, w, h);
        }
        this.changePaintOpacity(true);
    };

    Window_MenuStatus.prototype.drawItemStatus = function(index) {
        if(!isDisplayStatus){
            return;
        }
        var actor = $gameParty.members()[index];
        var rect = this.itemRectForText(index);
        var x = rect.x;
        var y = rect.y;
        var width = rect.width;
        var bottom = y + rect.height;
        var lineHeight = this.lineHeight();
        this.drawActorName(actor, x, y + lineHeight * 0, width);
        this.drawActorLevel(actor, x, y + lineHeight * 1, width);
        this.drawActorClass(actor, x, bottom - lineHeight * 4, width);
        this.drawActorHp(actor, x, bottom - lineHeight * 3, width);
        this.drawActorMp(actor, x, bottom - lineHeight * 2, width);
        this.drawActorIcons(actor, x, bottom - lineHeight * 1, width);
    };

    var _Window_MenuActor_initialize = Window_MenuActor.prototype.initialize;
    Window_MenuActor.prototype.initialize = function() {
        _Window_MenuActor_initialize.call(this);
        this.y = this.fittingHeight(2);
    };

})();


code:
//=============================================================================
// AltSaveScreen.js
//=============================================================================

/*:
 * @plugindesc Alternative save/load screen layout.
 * @author Yoji Ojima
 *
 * @help This plugin does not provide plugin commands.
 */

/*:ja
 * @plugindesc セーブ／ロード画面のレイアウトを変更します。
 * @author Yoji Ojima
 *
 * @help このプラグインには、プラグインコマンドはありません。
 */

(function() {

    var _Scene_File_create = Scene_File.prototype.create;
    Scene_File.prototype.create = function() {
        _Scene_File_create.call(this);
        this._listWindow.height = this._listWindow.fittingHeight(8);
        var x = 0;
        var y = this._listWindow.y + this._listWindow.height;
        var width = Graphics.boxWidth;
        var height = Graphics.boxHeight - y;
        this._statusWindow = new Window_SavefileStatus(x, y, width, height);
        this._statusWindow.setMode(this.mode());
        this._listWindow.statusWindow = this._statusWindow;
        this._listWindow.callUpdateHelp();
        this.addWindow(this._statusWindow);
    };

    var _Scene_File_start = Scene_File.prototype.start;
    Scene_File.prototype.start = function() {
        _Scene_File_start.call(this);
        this._listWindow.ensureCursorVisible();
        this._listWindow.callUpdateHelp();
    };

    Window_SavefileList.prototype.windowWidth = function() {
        return Graphics.boxWidth;
    };

    Window_SavefileList.prototype.maxCols = function() {
        return 4;
    };

    Window_SavefileList.prototype.numVisibleRows = function() {
        return 5;
    };

    Window_SavefileList.prototype.spacing = function() {
        return 8;
    };

    Window_SavefileList.prototype.itemHeight = function() {
        return this.lineHeight() * 2;
    };

    var _Window_SavefileList_callUpdateHelp =
            Window_SavefileList.prototype.callUpdateHelp;
    Window_SavefileList.prototype.callUpdateHelp = function() {
        _Window_SavefileList_callUpdateHelp.call(this);
        if (this.active && this.statusWindow) {
            this.statusWindow.setId(this.index() + 1);
        }
    };

    function Window_SavefileStatus() {
        this.initialize.apply(this, arguments);
    }

    Window_SavefileStatus.prototype = Object.create(Window_Base.prototype);
    Window_SavefileStatus.prototype.constructor = Window_SavefileStatus;

    Window_SavefileStatus.prototype.initialize = function(x, y, width, height) {
        Window_Base.prototype.initialize.call(this, x, y, width, height);
        this._id = 1;
    };

    Window_SavefileStatus.prototype.setMode = function(mode) {
        this._mode = mode;
    };

    Window_SavefileStatus.prototype.setId = function(id) {
        this._id = id;
        this.refresh();
    };

    Window_SavefileStatus.prototype.refresh = function() {
        this.contents.clear();
        var id = this._id;
        var valid = DataManager.isThisGameFile(id);
        var info = DataManager.loadSavefileInfo(id);
        var rect = this.contents.rect;
        this.resetTextColor();
        if (this._mode === 'load') {
            this.changePaintOpacity(valid);
        }
        this.drawFileId(id, rect.x, rect.y);
        if (info) {
            this.changePaintOpacity(valid);
            this.drawContents(info, rect, valid);
            this.changePaintOpacity(true);
        }
    };

    Window_SavefileStatus.prototype.drawFileId = function(id, x, y) {
        this.drawText(TextManager.file + ' ' + id, x, y, 180);
    };

    Window_SavefileStatus.prototype.drawContents = function(info, rect, valid) {
        var bottom = rect.y + rect.height;
        var playtimeY = bottom - this.lineHeight();
        this.drawText(info.title, rect.x + 192, rect.y, rect.width - 192);
        if (valid) {
            this.drawPartyfaces(info, rect.x, bottom - 144);
        }
        this.drawText(info.playtime, rect.x, playtimeY, rect.width, 'right');
    };

    Window_SavefileStatus.prototype.drawPartyfaces = function(info, x, y) {
        if (info && info.faces) {
            for (var i = 0; i < info.faces.length; i++) {
                var data = info.faces[i];
                this.drawFace(data[0], data[1], x + i * 150, y);
            }
        }
    };

})();