//============================================================================= // KISS_Factions.js //============================================================================= /*: * @plugindesc An advanced way to track factions in-game. * @author Konora * *@param Title *@desc The title of the scene. *@default Factions * *@param ----------------- *@param Faction Standings *@param ----------------- * *@param Label *@desc The label for Standings, i.e. for "Current Standings:" *@default Standings * *@param Fantastic Text *@desc The text for the highest level attainable of faction standings. *@default Fantastic * *@param Fantastic Icon *@desc The icon used for the highest level attainable of faction standings. *@default 84 * *@param Great Text *@desc The text for the second highest level attainable of faction standings. *@default Great * *@param Great Icon *@desc The icon used for the second highest level attainable of faction standings. *@default 88 * *@param Good Text *@desc The text for the third highest level attainable of faction standings. *@default Good * *@param Good Icon *@desc The icon used for the third highest level attainable of faction standings. *@default 89 * *@param Neutral Text *@desc The text for the neutral level of faction standings. *@default Neutral * *@param Neutral Icon *@desc The icon used for the neutral level of faction standings. *@default 20 * *@param Not Good Text *@desc The text for the third lowest level attainable of faction standings. *@default Not Good * *@param Not Good Icon *@desc The icon used for the third lowest level attainable of faction standings. *@default 85 * *@param Bad Text *@desc The text for the second lowest level attainable of faction standings. *@default Bad * *@param Bad Icon *@desc The icon used for the second lowest level attainable of faction standings. *@default 21 * *@param Horrible Text *@desc The text for the lowest level attainable of faction standings. *@default Horrible * *@param Horrible Icon *@desc The icon used for the lowest level attainable of faction standings. *@default 26 * *@help *=============== *Plugin Commands *=============== * *faction discover factionId * *Set faction with factionId to discovered. * *Example: faction discover 1 *Set faction 1 to discovered * * *faction sceneStart * *Start the faction scene. * * *=============== *Script Commands *=============== * *$gameSystem.addFactionPoints(faction, points); * *Add the specified number of points to the specified faction. * *Example: $gameSystem.addFactionPoints(1, 10); *Add 10 points to faction 1 * * *$gameSystem.subFactionPoints(faction, points); * *Same deal. Subtract the specified number of points to the specified faction. * *Example: $gameSystem.subFactionPoints(3, 5); *Subtract 5 points from faction 3 * * *In a conditional branch: *$gameSystem.factionDiscovered(faction) * *Returns true or false depending on whether or not the faction is discovered. * * *$gameSystem.getFaction(faction).FactionPoints * *Returns the number of points the player has with the specified faction. */ var $dataFactions = null; DataManager._databaseFiles.push({name: '$dataFactions', src: 'Factions.json'}); //---------------- //Game_Interpreter //---------------- var alias_factions_pluginCmds = Game_Interpreter.prototype.pluginCommand; Game_Interpreter.prototype.pluginCommand = function(command, args){ alias_factions_pluginCmds.call(this, command, args); if (command.toLowerCase() === "faction"){ switch(args[0].toUpperCase()){ case 'DISCOVER': $gameSystem.discoverFaction(args[1]); break; case 'SCENESTART': SceneManager.push(Scene_Factions); break; } } }; //------------ //Game_System //------------ var alias_gs_initialize = Game_System.prototype.initialize; Game_System.prototype.initialize = function(){ alias_gs_initialize.call(this); this.initializeParams(); this.initializeFactions(); }; Game_System.prototype.initializeParams = function(){ var params = PluginManager.parameters('KISS_Factions'); this.factionsTitle = String(params['Title']); this.standingLabel = String(params['Label']); this.fText = String(params['Fantastic Text']); this.fIcon = Number(params['Fantastic Icon']); this.grText = String(params['Great Text']); this.grIcon = Number(params['Great Icon']); this.gText = String(params['Good Text']); this.gIcon = Number(params['Good Icon']); this.nText = String(params['Neutral Text']); this.nIcon = Number(params['Neutral Icon']); this.ngText = String(params['Not Good Text']); this.ngIcon = Number(params['Not Good Icon']); this.bText = String(params['Bad Text']); this.bIcon = Number(params['Bad Icon']); this.hText = String(params['Horrible Text']); this.hIcon = Number(params['Horrible Icon']); }; Game_System.prototype.initializeFactions = function(){ this._factions = {}; for (var i = 0; i < $dataFactions.length; i++) { if (!$dataFactions[i]) continue; var data = $dataFactions[i]; var id = data["ID"]; var name = data["Name"]; var desc = data["Description"]; var iconId = data["IconID"]; var discovered = false; this.addFaction(id, name, desc, iconId, discovered); } }; Game_System.prototype.addFaction = function(id, name, desc, iconId, discovered){ var newFaction = {}; newFaction.Id = id; newFaction.Name = name; newFaction.Description = desc; newFaction.Icon = iconId; newFaction.FactionPoints = 0; newFaction.Discovered = discovered; this._factions[id] = newFaction; }; Game_System.prototype.getFaction = function(id){ return this._factions[id]; }; Game_System.prototype.discoverFaction = function(faction){ this.getFaction(faction).Discovered = true; }; Game_System.prototype.factionDiscovered = function(faction){ return this.getFaction(faction).Discovered; }; Game_System.prototype.addFactionPoints = function(faction, points){ this.getFaction(faction).FactionPoints += points; }; Game_System.prototype.subFactionPoints = function(faction, points){ this.getFaction(faction).FactionPoints -= points; }; Game_System.prototype.factionStanding = function(faction){ var points = this.getFaction(faction).FactionPoints; this.getFactionRanges(); if (this.fantastic.contains(points)){ this.getFaction(faction).FactionStanding = this.fText; this.getFaction(faction).StandingIcon = this.fIcon; } if (this.great.contains(points)){ this.getFaction(faction).FactionStanding = this.grText; this.getFaction(faction).StandingIcon = this.grIcon; } if (this.good.contains(points)){ this.getFaction(faction).FactionStanding = this.gText; this.getFaction(faction).StandingIcon = this.gIcon; } if (points === 0){ this.getFaction(faction).FactionStanding = this.nText; this.getFaction(faction).StandingIcon = this.nIcon; } if (this.not_good.contains(points)){ this.getFaction(faction).FactionStanding = this.ngText; this.getFaction(faction).StandingIcon = this.ngIcon; } if (this.bad.contains(points)){ this.getFaction(faction).FactionStanding = this.bText; this.getFaction(faction).StandingIcon = this.bIcon; } if (this.horrible.contains(points)){ this.getFaction(faction).FactionStanding = this.hText; this.getFaction(faction).StandingIcon = this.hIcon; } } Game_System.prototype.getFactionRanges = function(){ this.fantastic = []; for(var i = 50; i > 30; i--){ this.fantastic.push(i); } this.great = []; for (var i = 30; i > 10; i--){ this.great.push(i); } this.good = []; for (var i = 10; i > 0; i--){ this.good.push(i); } this.neutral = 0; this.not_good = []; for (var i = -10; i < 0; i++){ this.not_good.push(i); } this.bad = []; for (var i = -30; i < -10; i++){ this.bad.push(i); } this.horrible = []; for (var i = -50; i < -30; i++){ this.horrible.push(i); } } //-------------- //Scene_Factions //-------------- function Scene_Factions(){ this.initialize.apply(this, arguments); } Scene_Factions.prototype = Object.create(Scene_MenuBase.prototype); Scene_Factions.prototype.constructor = Scene_Factions; Scene_Factions.prototype.initialize = function(){ Scene_MenuBase.prototype.initialize.call(this); }; Scene_Factions.prototype.start = function(){ Scene_MenuBase.prototype.start.call(this); this.drawWindows(); }; Scene_Factions.prototype.drawWindows = function(){ this.oldIndex = -1; this._factionWindow = new Window_FactionSelect(); this._factionInfo = new Window_FactionInfo(); this._factionTitle = new Window_FactionTitle(); this.addWindow(this._factionWindow); this.addWindow(this._factionInfo); this.addWindow(this._factionTitle); }; Scene_Factions.prototype.update = function(){ Scene_MenuBase.prototype.update.call(this); var index = this._factionWindow.index(); var cmdName = this._factionWindow.commandName(index); if (index != this.oldIndex){ for (var i = 0; i < $dataFactions.length; i++){ if (!$gameSystem._factions[i]) continue; if ($gameSystem.getFaction(i).Name != cmdName){ continue; } else { var faction = i; break; } } this._factionInfo.drawFactionInfo(faction); } this.oldIndex = index; if (Input.isTriggered('cancel')){ SoundManager.playCancel(); SceneManager.goto(Scene_Map); } }; //------------------- //Window_FactionTitle //------------------- function Window_FactionTitle(){ this.initialize.apply(this, arguments); } Window_FactionTitle.prototype = Object.create(Window_Base.prototype); Window_FactionTitle.prototype.constructor = Window_FactionTitle; Window_FactionTitle.prototype.initialize = function(){ Window_Base.prototype.initialize.call(this, 0, 0, Graphics.width, this.fittingHeight(1)); this.drawTitle(); }; Window_FactionTitle.prototype.drawTitle = function(){ this.drawText($gameSystem.factionsTitle, 0, 0, Graphics.width, 'center'); }; //-------------------- //Window_FactionSelect //-------------------- function Window_FactionSelect(){ this.initialize.apply(this, arguments); } Window_FactionSelect.prototype = Object.create(Window_Command.prototype); Window_FactionSelect.prototype.constructor = Window_FactionSelect; Window_FactionSelect.prototype.initialize = function(){ Window_Command.prototype.initialize.call(this, 0, this.fittingHeight(1)); }; Window_FactionSelect.prototype.windowWidth = function(){ return 300; }; Window_FactionSelect.prototype.windowHeight = function(){ return Graphics.height - this.fittingHeight(1); }; Window_FactionSelect.prototype.makeCommandList = function(){ for (var i = 0; i < $dataFactions.length; i++){ if (!$gameSystem._factions[i]) continue; if ($gameSystem.factionDiscovered(i)){ var faction = $gameSystem.getFaction(i); var cmdText = faction.Name; this.addCommand(cmdText); } } }; //------------------ //Window_FactionInfo //------------------ function Window_FactionInfo(){ this.initialize.apply(this, arguments); } Window_FactionInfo.prototype = Object.create(Window_Base.prototype); Window_FactionInfo.prototype.constructor = Window_FactionInfo; Window_FactionInfo.prototype.updateFaction = function(faction_id){ this.faction = faction_id; }; Window_FactionInfo.prototype.initialize = function(){ Window_Base.prototype.initialize.call(this, 300, this.fittingHeight(1), Graphics.width - 300, Graphics.height - this.fittingHeight(1)); }; Window_FactionInfo.prototype.drawFactionInfo = function(faction){ var name = $gameSystem.getFaction(faction).Name; var icon = $gameSystem.getFaction(faction).Icon; var desc = $gameSystem.getFaction(faction).Description; var label = $gameSystem.standingLabel; $gameSystem.factionStanding(faction); var standing = $gameSystem.getFaction(faction).FactionStanding; var text = "\n" + desc; var standlbl = "Current " + label + ": "; var txtWidth = this.contents.measureTextWidth(text); var fp = ($gameSystem.getFaction(faction).FactionPoints + 50)/100 var color = this.determineStandingColors(faction); this.refresh(); this.drawIcon(icon, 0, 0); this.drawTextEx(name, 40, 0); this.drawTextEx(text, 0, this.lineHeight()); this.drawText(standlbl, 0, 350, Graphics.width - 300, "left"); this.changeTextColor(color); this.drawText(standing, 350, 350, Graphics.width - 300, "left"); //this.drawIcon($gameSystem.getFaction(faction).StandingIcon, txtWidth, this.contents.height/2); this.drawGauge(0, 400, Graphics.width - 300, fp, color, color); }; Window_FactionInfo.prototype.determineStandingColors = function(faction){ var f = $gameSystem.getFaction(faction); switch (f.FactionStanding){ case $gameSystem.fText: return this.textColor(29); break; case $gameSystem.grText: return this.textColor(3); break; case $gameSystem.gText: return this.textColor(11); break; case $gameSystem.nText: return this.textColor(1); break; case $gameSystem.ngText: return this.textColor(2); break; case $gameSystem.bText: return this.textColor(10); break; case $gameSystem.hText: return this.textColor(18); break; default: return this.textColor(0); } }; Window_FactionInfo.prototype.refresh = function(){ this.contents.clear(); };