Code:
//========================================================================================
// Map Safety Level MV.js
//========================================================================================
/*:
* @plugindesc This script allows you to display the current map's name and safety level.
* @version 2023-01-06
* @author Kyonides Arkanthes
*
* @param None
*
* @help
* Aliased Functions:
* Game_Map#setup
* Overwritten Functions:
* Scene_Menu#create
*
* Map Note: <safety N>
* where N is a number. Valid Options: 0 through Maximum.
*
* Plugin Calls:
*
* $gameMap.getSafetyLevel();
* $gameMap.setSafetyLevel(Number);
* $gameMap.getSafetyLevelByMapId(Number);
* $gameMap.safetyLevels();
*/
function MapSafetyWindow() {
this.initialize.apply(this, arguments);
}
MapSafetyWindow.prototype = Object.create(Window_Base.prototype);
MapSafetyWindow.prototype.constructor = MapSafetyWindow;
MapSafetyWindow.prototype.initialize = function(x, y, width, height) {
Window_Base.prototype.initialize.call(this, x, y, width, height);
let w = this.contentsWidth();
this.drawText($gameMap.displayName(), 0, 0, w, "center");
this.changeTextColor(this.currentColor());
this.drawText(this.currentLevel(), 0, 36, w, "center");
};
MapSafetyWindow.prototype.currentColor = function() {
let level = $gameMap.getSafetyLevel();
if (level == 0) {
return "rgb(255, 0, 0)";
} else if (level == 1) {
return "rgb(255, 165, 0)";
} else if (level == 2) {
return "rgb(255, 255, 0)";
} else if (level == 3) {
return "rgb(255, 255, 255)";
} else if (level == 4) {
return "rgb(90, 205, 90)";
} else if (level == 5) {
return "rgb(0, 255, 0)";
}
return "rgb(255, 255, 255)";
}
MapSafetyWindow.prototype.currentLevel = function() {
let level = $gameMap.getSafetyLevel();
if (level == 0) {
return "A Nightmare";
} else if (level == 1) {
return "Dangerous";
} else if (level == 2) {
return "Unsafe";
} else if (level == 3) {
return "Normal Place";
} else if (level == 4) {
return "Great Place";
} else if (level == 5) {
return "The Utopia";
}
return "Error!";
}
const Game_Map_safety_init = Game_Map.prototype.initialize;
const Game_Map_safety_setup = Game_Map.prototype.setup;
Game_Map.prototype.initialize = function() {
Game_Map_safety_init.call(this);
this._safetyLevels = [];
}
Game_Map.prototype.setup = function(mapId) {
Game_Map_safety_setup.call(this, mapId);
if (this._safetyLevels[mapId] == null) {
let slvl = $dataMap.meta.safety || 0;
this.setSafetyLevel(slvl);
}
}
Game_Map.prototype.getSafetyLevel = function() {
return this._safetyLevels[this._mapId];
}
Game_Map.prototype.setSafetyLevel = function(level) {
return this._safetyLevels[this._mapId] = level;
}
Game_Map.prototype.getSafetyLevelByMapId = function(mapId) {
return this._safetyLevels[mapId];
}
Game_Map.prototype.safetyLevels = function() {
return this._safetyLevels;
}
Scene_Menu.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this.createCommandWindow();
this.createMapSafetyWindow();
this.createGoldWindow();
this.createStatusWindow();
};
Scene_Menu.prototype.createMapSafetyWindow = function() {
let w = this._commandWindow.width;
let h = this._commandWindow.height;
this._mapSafetyWindow = new MapSafetyWindow(0, h, w, 108);
this.addWindow(this._mapSafetyWindow);
}