//=============================================================================
// MrLiu_AutoBalloon.js
//=============================================================================

/*:
 * @plugindesc 在RMMV游戏中地图界面的人物头顶自动显示气球
 * @author MrLiu-过眼云烟
 *
 * @help 事件页的说明下加入“autoballoon_11”,即显示第11行的表情,需将Balloon_1.png
 * 文件放在\img\system目录下,该文件默认大小为96*352,默认每格表情大小为32,每行3格
 * 后续版本将提供修改格式,显示速度等功能,敬请期待,如有问题欢迎给我留言。
 */
//-----------------------------------------------------------------------------
var Imported = Imported || {};
Imported.MrLiu_AutoBalloon = true;

var Lmd = Lmd || {};
Lmd.MrLiu_AutoBalloon = Lmd.MrLiu_AutoBalloon || {};



  var parameters = PluginManager.parameters('MrLiu_Shadow');
  var displayAutoBalloon = String(parameters['displayAutoBalloon']);
  var shadowOpacity = Number(parameters['shadowOpacity']);
  displayAutoBalloon = false;
  
Lmd.MrLiu_AutoBalloon.Game_Character_initialize = Game_Character.prototype.initialize;
  Game_Character.prototype.initialize = function() {
    Lmd.MrLiu_AutoBalloon.Game_Character_initialize.call(this);
    this._auto_balloon = 0;
};

Game_Character.prototype._auto_balloon = function() {
	return this._auto_balloon;
};

  
Lmd.MrLiu_AutoBalloon.Game_Event_refresh = Game_Event.prototype.refresh;
Game_Event.prototype.refresh = function() {
	Lmd.MrLiu_AutoBalloon.Game_Event_refresh.call(this);
	if((this._erased == false)&&(this._trigger == 0)){
	var list = this.list();
	for(var i=0 ;i= 0) {
		this._auto_balloon = 0;
        this.setupPageSettings();
    } else {
		this._auto_balloon = 0;
        this.clearPageSettings();
    }
    this.refreshBushDepth();
    this.clearStartingFlag();
    this.checkEventTriggerAuto();
};




  
  
Lmd.MrLiu_AutoBalloon.Sprite_Character_initialize = Sprite_Character.prototype.initialize;
Sprite_Character.prototype.initialize = function(character) {
    Lmd.MrLiu_AutoBalloon.Sprite_Character_initialize.call(this,character);
	this.createAutoBalloon();
	this._dis_flag = 0;
	this._flag = 0;
	this._bx = 0
	this.character = character;
};
Sprite_Character.prototype.createAutoBalloon = function() {
    this._auto_balloon_sprite = new Sprite();
    this._auto_balloon_sprite.bitmap = ImageManager.loadSystem('Balloon_1');
	this._auto_balloon_sprite.opacity = 0;
	this._auto_balloon_sprite.z = 7;
	this._auto_balloon_sprite.x = this.x;
    this._auto_balloon_sprite.y = this.y-40;//-this.patternHeight();// ;//- this.height*2;
	this._auto_balloon_sprite.anchor.x = 0.5;
    this._auto_balloon_sprite.anchor.y = 1;
	//this.addChild(this._auto_balloon_sprite);
    this.addChild(this._auto_balloon_sprite);
	if (displayAutoBalloon){
		this._p_balloon_sprite = new Sprite();
		this._p_balloon_sprite.bitmap = ImageManager.loadSystem('Balloon_1');
		this._p_balloon_sprite.opacity = 0;
		this._p_balloon_sprite.z = 7;
		this.parent.addChild(this._p_balloon_sprite);//this.addChild(this._p_balloon_sprite);
	}
}	

Lmd.MrLiu_AutoBalloon.Sprite_Character_update = Sprite_Character.prototype.update;
Sprite_Character.prototype.update = function() {
	Lmd.MrLiu_AutoBalloon.Sprite_Character_update.call(this);
	if ((this.character._auto_balloon == 0)  || ! (this._balloonDuration == 0 ) || ($gameMap._interpreter.isRunning()) || ($gameSwitches[212] == true)){
      this.clear_auto_balloon();
	}
    else{
      this.update_auto_balloon();
	}
}


Sprite_Character.prototype.face_to_event = function() {
    var data = new Array();
    var w = 1;
    var h = 1 * 2;
	for (var i=0;i<(h+1);i++)
	{
		for (var j=0;j<(h+1);j++)
			{
			    data.push([(this.character.x-w)+i,(this.character.y-w)+j]);
			}
	}
	 for(var i =0;i