Advertisement
Trihan

Trilobytes - Prestige Class Titles

Mar 15th, 2023 (edited)
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 4.35 KB | Source Code | 0 0
  1. //=============================================================================
  2. // Trilobytes - Prestige Class Titles
  3. // TLB_PrestigeClassTitles.js
  4. //=============================================================================
  5.  
  6. window.Imported ??= {};
  7. Imported.TLB_PrestigeClassTitles = true;
  8.  
  9. window.TLB ??= {};
  10. TLB.PrestigeClassTitles ??= {};
  11. TLB.PrestigeClassTitles.version = 1.00;
  12.  
  13. /*:
  14.  * @target MZ
  15.  * @plugindesc [v1.00] This plugin allows you to define different names for
  16.  * classes based on level.
  17.  * @author John Clifford/Trihan
  18.  *
  19.  * @help
  20.  * ============================================================================
  21.  * Introduction
  22.  * ============================================================================
  23.  *
  24.  * This plugin provides the developer the facility to have actor classes
  25.  * automatically change their names as the actor possessing that class hits
  26.  * defined level milestones.
  27.  *
  28.  * ============================================================================
  29.  * Notetags
  30.  * ============================================================================
  31.  *
  32.  * Use the following notetag in the notebox of your classes (indentation is
  33.  * purely for ease of reading and is not necessary in the note itself):
  34.  *
  35.  * <NameList>
  36.  *   level:name
  37.  *   level2:name2
  38.  *   level3:name3
  39.  * </NameList>
  40.  *
  41.  * Example (in the 'Black Mage' class):
  42.  *
  43.  * <NameList>
  44.  *   5:Black Magus
  45.  *   10:Black Sorcerer
  46.  *   15:Sorcerer Supreme
  47.  * </NameList>
  48.  *
  49.  * You can define as many level-name pairs as you wish. They should be in level
  50.  * order; ordering them otherwise may cause the wrong name to be shown. The
  51.  * original name of the class will be used at first unless you define a level 1
  52.  * pairing.
  53.  *
  54.  * As soon as the actor attains the level defined by a line, that is the name
  55.  * that will be displayed for their class until the next one is reached.
  56.  *
  57.  * ============================================================================
  58.  * Plugin Parameters
  59.  * ============================================================================
  60.  *
  61.  * None
  62.  *
  63.  * ============================================================================
  64.  * Plugin Commands
  65.  * ============================================================================
  66.  *
  67.  * None
  68.  *
  69.  * ============================================================================
  70.  * Changelog
  71.  * ============================================================================
  72.  *
  73.  * Version 1.00:
  74.  * - Finished plugin!
  75.  *
  76.  */
  77.    
  78. TLB.PrestigeClassTitles.DataManager_onLoad = DataManager.onLoad;
  79. DataManager.onLoad = function(object) {
  80.     TLB.PrestigeClassTitles.DataManager_onLoad.call(this, object);
  81.     if (object === $dataClasses) {
  82.         this.loadTLBClassNameNotetags();
  83.     }
  84. };
  85.  
  86. DataManager.loadTLBClassNameNotetags = function() {
  87.     for (const classData of $dataClasses)
  88.     {
  89.         if (!classData) continue;
  90.         const note = classData.note;
  91.         const nameList = note.match(/<NameList>((?:.|\n)*)<\/NameList>/);
  92.         if (nameList)
  93.         {
  94.             const rawNames = nameList[1].split("\n");
  95.             classData.tlbClassNames ??= {};
  96.             const nameData = rawNames.filter(name => name.length > 0);
  97.             for (const line of nameData) {
  98.                 const lineData = line.split(":");
  99.                 const level = lineData[0];
  100.                 const name = lineData[1];
  101.                 classData.tlbClassNames[level] = name;
  102.             }
  103.         }
  104.     }
  105. }
  106.  
  107. TLB.PrestigeClassTitles.Window_StatusBase_drawActorClass = Window_StatusBase.prototype.drawActorClass;
  108. Window_StatusBase.prototype.drawActorClass = function(actor, x, y, width) {
  109.     const classNames = actor.currentClass().tlbClassNames;
  110.     if (classNames) {
  111.         const keys = Object.keys(classNames);
  112.         const validKeys = keys.filter(key => key <= actor.level);
  113.         const currentKey = validKeys[validKeys.length - 1];
  114.         if (currentKey)
  115.         {
  116.             const name = classNames[currentKey];
  117.             width = width || 168;
  118.             this.resetTextColor();
  119.             this.drawText(name, x, y, width);
  120.         } else {
  121.             TLB.PrestigeClassTitles.Window_StatusBase_drawActorClass.call(this, actor, x, y, width);
  122.         }
  123.     } else {
  124.         TLB.PrestigeClassTitles.Window_StatusBase_drawActorClass.call(this, actor, x, y, width);
  125.     }
  126. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement