/*:
* @plugindesc Displays a meter when encounters are possible
* @author Geowil
*
*
*
* @help
* Credits:
* MakeAMidget - original RMXP script creator
* gstv87 - provided scripting help (rpgmakerweb.com)
* Shaz - provided scripting help (rpgmakerweb.com)
*/
const params = PluginManager.parameters('EncounterMeter');
function Window_Encounter() {
this.initialize.apply(this, arguments);
}
(function(_) {
"use strict";
/* plugin vars */
/* Scene Map */
var Encounter_Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function(){
Encounter_Scene_Map_start.call(this);
this.createEncounterWindow();
};
Scene_Map.prototype.createEncounterWindow = function(){
//only add if not existing
this._encounterWind = new Window_Encounter(0,60);
this.addWindow(this._encounterWind);
};
/* Window Encounter */
Window_Encounter.prototype = Object.create(Window_Base.prototype);
Window_Encounter.prototype.constructor = Window_Encounter;
Window_Encounter.prototype.initialize = function(x,y){
var width= $gamePlayer.getTotalEncSteps();
if (width < 200){
width = 200;
}
var height=80;
Window_Base.prototype.initialize.call(this,x,y,width,height);
this._gColor1 = "#F0F";
this._gColor2 = "#C0C";
this._gWidth = Math.max(9,width);
this._gHeight = 5;
this.contents.fontSize = 18;
this.drawEncounter(0,0,this._gWidth,this._gHeight,0,this._gColor1,this._gColor2);
this.setOpacity();
this._IsVisible = true;
};
Window_Encounter.prototype.update = function(){
if ($gameMap.encounterList().length > 0 && $gamePlayer._inEncRegion){
if (!this._IsVisible){
this.show(); //If window is not active and we are in an enc region then activate it
this._IsVisible = true;
}
var rate = $gamePlayer.getCurrEncSteps() / $gamePlayer.getTotalEncSteps();
this.drawEncounter(0,0,this._gWidth,this._gHeight,rate,this._gColor1,this._gColor2);
} else{
if (this._IsVisible){
this.hide(); //If window is active and we are not in an enc region then deactivate it
this._IsVisible = false;
}
}
};
Window_Encounter.prototype.setOpacity = function(){
this.opacity = 255;
}
Window_Encounter.prototype.drawEncounter = function(x,y,width,height,rate,color1,color2){
var gColorBk = "#000";
var fillWidth1 = Math.floor(width*rate).clamp(0,width);
var fillWidth2 =width;
var encText = "Encounter Meter";
this.drawText(encText,x,y,100,'left');
this.contents.fillRect(x,y+35,fillWidth2,height,gColorBk);
this.contents.gradientFillRect(x,y+35,fillWidth1,height,color1,color2);
};
/* Encounter Game Player */
var Game_Player_InitMembers = Game_Player.prototype.initMembers;
Game_Player.prototype.initMembers = function(){
Game_Player_InitMembers.call(this);
this._totalEncSteps = 0;
this._inEncRegion = false;
this._regionList = [];
};
Game_Player.prototype.makeEncounterCount = function(){
var n = $gameMap.encounterStep();
this._encounterCount = Math.randomInt(n) + Math.randomInt(n) + 1;
this._totalEncSteps = this._encounterCount;
};
Game_Player.prototype.increaseSteps = function() {
//Find a way to only run this if _regionList is empty and there are regions within encounterList objs
$gameMap.encounterList().forEach(function(encounter) { $gamePlayer._regionList.push(encounter.regionSet); });
Game_Character.prototype.increaseSteps.call(this);
if (this.isNormal()) {
$gameParty.increaseSteps();
$gamePlayer._regionList.forEach(function(rgnSet){
if (rgnSet.length === 0 || rgnSet.contains($gamePlayer.regionId())){
//alert("Entering a dangerous region!");
$gamePlayer._inEncRegion = true;
} else{
$gamePlayer._inEncRegion = false;
}
});
}
};
Game_Player.prototype.getTotalEncSteps = function() { return this._totalEncSteps; };
Game_Player.prototype.getCurrEncSteps = function() { return this._totalEncSteps - this._encounterCount; };
Game_Player.prototype.getXLocal = function() { return this.x; };
Game_Player.prototype.getYLocal = function(){ return this.y; };
})();