Guest User

ItemBook v1.3 - SkottyTV Update 03

a guest
Nov 6th, 2015
240
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // ItemBook.js
  3. //=============================================================================
  4.  
  5. /*:
  6.  * @plugindesc v1.03 + SkottyTV Update 03 // Displays detailed statuses of items.
  7.  * @author Yoji Ojima (Compatibility with YEP) / + SkottyTV (thx to DragonPC)
  8.  *
  9.  * @param ----- Functions -----
  10.  *
  11.  * @param Unknown Data
  12.  * @desc The index name for an unknown item.
  13.  * @default ??????
  14.  *
  15.  * @param AutoFill
  16.  * @desc Decide if items will automaticly show up in the book
  17.  * when collected. (true or false)
  18.  * @default true
  19.  *
  20.  * @param Gold Icon
  21.  * @desc Decide if you want to use the Gold Icon from
  22.  * Yanfly Core Engine. (true or false)
  23.  * @default true
  24.  *
  25.  * @param Items in Row
  26.  * @desc Decide how many items you want to show in one row.
  27.  * (default 1)
  28.  * @default 1
  29.  *
  30.  * @param Show Key Items
  31.  * @desc Decide if you want to show the Key Items.
  32.  * (default true)
  33.  * @default true
  34.  *
  35.  * @param ----- Visuals -----
  36.  *
  37.  * @param Price Text
  38.  * @desc The text for "Price".
  39.  * @default Price
  40.  *
  41.  * @param Equip Text
  42.  * @desc The text for "Equip".
  43.  * @default Equip
  44.  *
  45.  * @param Type Text
  46.  * @desc The text for "Type".
  47.  * @default Type
  48.  *
  49.  * @param Half Index Height
  50.  * @desc Decide if you want to half the Index height.                   (default true)
  51.  * @default true
  52.  *
  53.  * @param Show Price Switch
  54.  * @desc Choose the switch ID that shows the price.  (default 0)
  55.  * @default 0
  56.  *
  57.  * @param Show Equip/Type Switch
  58.  * @desc Choose the switch ID that shows the equip/type. (default 0)
  59.  * @default 0
  60.  *
  61.  * @param Show Status Switch
  62.  * @desc Choose the switch ID that shows the stats. (default 0)
  63.  * @default 0
  64.  *
  65.  * @help
  66.  *
  67.  * ============================================================================
  68.  * SkottyTV Update 01 ->
  69.  * 
  70.  * - Decide if items will get an entry automaticly when they collected!
  71.  * - Decide how many items appear in one row!
  72.  * - Decide if you want to use the Gold Icon from Yanflys Core Engine!
  73.  * - Advanced Visual upgrades!
  74.  *
  75.  * SkottyTV Update 02 ->
  76.  *
  77.  * - Visual upgrades!
  78.  *
  79.  * SkottyTV Update 03 ->
  80.  *
  81.  * - Decide if you want to half the Index height.
  82.  * - Decide if you want to show Key Items.
  83.  * - Advanced Visual upgrades!
  84.  * - Use switches to enable different information!
  85.  *   (Price, Equip/Type, Stats)
  86.  * ============================================================================
  87.  *
  88.  * Plugin Command:
  89.  *   ItemBook open             # Open the item book screen
  90.  *   ItemBook add item 1       # Add item #1 to the item book
  91.  *   ItemBook add weapon 2     # Add weapon #2 to the item book
  92.  *   ItemBook add armor 3      # Add armor #3 to the item book
  93.  *   ItemBook remove item 4    # Remove item #4 from the item book
  94.  *   ItemBook remove weapon 5  # Remove weapon #5 from the item book
  95.  *   ItemBook remove armor 6   # Remove armor #6 from the item book
  96.  *   ItemBook complete         # Complete the item book
  97.  *   ItemBook clear            # Clear the item book
  98.  *
  99.  * Item (Weapon, Armor) Note:
  100.  *   <book:no>                # This item does not appear in the item book
  101.  */
  102.  
  103. /*:ja
  104.  * @plugindesc アイテム図鑑です。アイテムの詳細なステータスを表示します。
  105.  * @author Yoji Ojima (Compatibility with YEP) / + SkottyTV (thx to DragonPC)
  106.  *
  107.  * @param Unknown Data
  108.  * @desc 未確認のアイテムの索引名です。
  109.  * @default ??????
  110.  *
  111.  * @param Price Text
  112.  * @desc ã€Œä¾¡æ ¼ã€ã®æ–‡å­—åˆ—ã§ã™ã€‚
  113.  * @default ä¾¡æ ¼
  114.  *
  115.  * @param Equip Text
  116.  * @desc 「装備」の文字列です。
  117.  * @default 装備
  118.  *
  119.  * @param Type Text
  120.  * @desc 「タイプ」の文字列です。
  121.  * @default タイプ
  122.  *
  123.  * @param Gold Icon
  124.  * @desc Decide if you want to use the Gold Icon from Yanfly Core Engine.
  125.  * (true or false)
  126.  * @default true
  127.  *
  128.  * @param AutoFill
  129.  * @desc Decide if items will automaticly show up in the book
  130.  * when collected. (true or false)
  131.  * @default true
  132.  *
  133.  * @param Items in Row
  134.  * @desc Decide how many items you want to show in one row.
  135.  * (default 1)
  136.  * @default 1
  137.  *
  138.  * @param Half Index Height
  139.  * @desc Decide if you want to half the Index height.
  140.  * (default true)
  141.  * @default true
  142.  *
  143.  * @param Show Price Switch
  144.  * @desc Choose the switch ID that shows the price.
  145.  * (default 0)
  146.  * @default 0
  147.  *
  148.  * @param Show Equip/Type Switch
  149.  * @desc Choose the switch ID that shows the equip/type.
  150.  * (default 0)
  151.  * @default 0
  152.  *
  153.  * @param Show Status Switch
  154.  * @desc Choose the switch ID that shows the stats.
  155.  * (default 0)
  156.  * @default 0
  157.  *
  158.  * @param Show Key Items
  159.  * @desc Decide if you want to show the Key Items.
  160.  * (default true)
  161.  * @default true
  162.  *
  163.  * @help
  164.  *
  165.  * ============================================================================
  166.  * SkottyTV Update 01 ->
  167.  * 
  168.  * - Decide if items will get an entry automaticly when they collected!
  169.  * - Decide how many items appear in one row!
  170.  * - Decide if you want to use the Gold Icon from Yanflys Core Engine!
  171.  * - Advanced Visual upgrades!
  172.  *
  173.  * SkottyTV Update 02 ->
  174.  *
  175.  * - Visual upgrades!
  176.  *
  177.  * SkottyTV Update 03 ->
  178.  *
  179.  * - Decide if you want to half the Index height.
  180.  * - Decide if you want to show Key Items.
  181.  * - Advanced Visual upgrades!
  182.  * - Use switches to enable different information!
  183.  *   (Price, Equip/Type, Stats)
  184.  * ============================================================================
  185.  *
  186.  * プラグインコマンド:
  187.  *   ItemBook open            # 図鑑画面を開く
  188.  *   ItemBook add item 1       # Add item #1 to the item book
  189.  *   ItemBook add weapon 3    # 武器3番を図鑑に追åŠ
  190.  *   ItemBook add armor 4     # 防具4番を図鑑に追åŠ
  191.  *   ItemBook remove weapon 2  # Remove weapon #2 from the item book
  192.  *   ItemBook remove armor 5  # 防具5番を図鑑から削除
  193.  *   ItemBook remove item 6   # アイテム6番を図鑑から削除
  194.  *   ItemBook complete        # 図鑑を完成させる
  195.  *   ItemBook clear           # 図鑑をクリアする
  196.  *
  197.  * アイテム(武器、防具)のメモ:
  198.  *   <book:no>                # å›³é‘‘ã«è¼‰ã›ãªã„å ´åˆ
  199.  */
  200.  
  201. (function() {
  202.  
  203.     var parameters = PluginManager.parameters('ItemBook');
  204.     var unknownData = String(parameters['Unknown Data'] || '??????');
  205.     var priceText = String(parameters['Price Text'] || 'Price');
  206.     var equipText = String(parameters['Equip Text'] || 'Equip');
  207.     var typeText = String(parameters['Type Text'] || 'Type');
  208.     var goldIcon = String(parameters['Gold Icon'] || 'true');
  209.     var listRow = Number(parameters['Items in Row']);
  210.     var autoFill = String(parameters['AutoFill'] || 'true');
  211.     var IndexHeight = String(parameters['Half Index Height'] || 'true');
  212.     var ShowStatus = Number(parameters['Show Status Switch']);
  213.     var ShowPrice = Number(parameters['Show Price Switch']);
  214.     var ShowType = Number(parameters['Show Equip/Type Switch']);
  215.     var ShowKeyItems = String(parameters['Show Key Items'] || 'true');
  216.  
  217.     var _Game_Interpreter_pluginCommand =
  218.             Game_Interpreter.prototype.pluginCommand;
  219.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  220.         _Game_Interpreter_pluginCommand.call(this, command, args);
  221.         if (command === 'ItemBook') {
  222.             switch (args[0]) {
  223.             case 'open':
  224.                 SceneManager.push(Scene_ItemBook);
  225.                 break;
  226.             case 'add':
  227.                 $gameSystem.addToItemBook(args[1], Number(args[2]));
  228.                 break;
  229.             case 'remove':
  230.                 $gameSystem.removeFromItemBook(args[1], Number(args[2]));
  231.                 break;
  232.             case 'complete':
  233.                 $gameSystem.completeItemBook();
  234.                 break;
  235.             case 'clear':
  236.                 $gameSystem.clearItemBook();
  237.                 break;
  238.             }
  239.         }
  240.     };
  241.  
  242.     Game_System.prototype.addToItemBook = function(type, dataId) {
  243.         if (!this._ItemBookFlags) {
  244.             this.clearItemBook();
  245.         }
  246.         var typeIndex = this.itemBookTypeToIndex(type);
  247.         if (typeIndex >= 0) {
  248.             this._ItemBookFlags[typeIndex][dataId] = true;
  249.         }
  250.     };
  251.  
  252.     Game_System.prototype.removeFromItemBook = function(type, dataId) {
  253.         if (this._ItemBookFlags) {
  254.             var typeIndex = this.itemBookTypeToIndex(type);
  255.             if (typeIndex >= 0) {
  256.                 this._ItemBookFlags[typeIndex][dataId] = false;
  257.             }
  258.         }
  259.     };
  260.  
  261.     Game_System.prototype.itemBookTypeToIndex = function(type) {
  262.         switch (type) {
  263.         case 'item':
  264.             return 0;
  265.         case 'weapon':
  266.             return 1;
  267.         case 'armor':
  268.             return 2;
  269.         default:
  270.             return -1;
  271.         }
  272.     };
  273.  
  274.     Game_System.prototype.completeItemBook = function() {
  275.         var i;
  276.         this.clearItemBook();
  277.         for (i = 1; i < $dataItems.length; i++) {
  278.             this._ItemBookFlags[0][i] = true;
  279.         }
  280.         for (i = 1; i < $dataWeapons.length; i++) {
  281.             this._ItemBookFlags[1][i] = true;
  282.         }
  283.         for (i = 1; i < $dataArmors.length; i++) {
  284.             this._ItemBookFlags[2][i] = true;
  285.         }
  286.     };
  287.  
  288.     Game_System.prototype.clearItemBook = function() {
  289.         this._ItemBookFlags = [[], [], []];
  290.     };
  291.  
  292.     Game_System.prototype.isInItemBook = function(item) {
  293.         if (this._ItemBookFlags && item) {
  294.             var typeIndex = -1;
  295.             if (DataManager.isItem(item)) {
  296.                 typeIndex = 0;
  297.             } else if (DataManager.isWeapon(item)) {
  298.                 typeIndex = 1;
  299.             } else if (DataManager.isArmor(item)) {
  300.                 typeIndex = 2;
  301.             }
  302.             if (typeIndex >= 0) {
  303.                 return !!this._ItemBookFlags[typeIndex][item.id];
  304.             } else {
  305.                 return false;
  306.             }
  307.         } else {
  308.             return false;
  309.         }
  310.     };
  311.  
  312.     var _Game_Party_gainItem = Game_Party.prototype.gainItem;
  313.     Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
  314.         _Game_Party_gainItem.call(this, item, amount, includeEquip);
  315.         if (item && amount > 0) {
  316.             var type;
  317.             if (DataManager.isItem(item)) {
  318.                 type = 'item';
  319.             } else if (DataManager.isWeapon(item)) {
  320.                 type = 'weapon';
  321.             } else if (DataManager.isArmor(item)) {
  322.                 type = 'armor';
  323.             }
  324.            
  325.             if (autoFill === 'true') {
  326.                 $gameSystem.addToItemBook(type, item.id);
  327.             }
  328.         }
  329.     };
  330.  
  331.     function Scene_ItemBook() {
  332.         this.initialize.apply(this, arguments);
  333.     }
  334.  
  335.     Scene_ItemBook.prototype = Object.create(Scene_MenuBase.prototype);
  336.     Scene_ItemBook.prototype.constructor = Scene_ItemBook;
  337.  
  338.     Scene_ItemBook.prototype.initialize = function() {
  339.         Scene_MenuBase.prototype.initialize.call(this);
  340.     };
  341.  
  342.     Scene_ItemBook.prototype.create = function() {
  343.        
  344.         var w3 = Graphics.boxWidth / 3;
  345.         var ww = (Graphics.boxWidth / 3)*2 + 2;
  346.         var wh = Graphics.boxHeight / 10;
  347.        
  348.         Scene_MenuBase.prototype.create.call(this);
  349.         this._indexWindow = new Window_ItemBookIndex(0, 0);
  350.         this._indexWindow.setHandler('cancel', this.popScene.bind(this));
  351.  
  352.         this._statusWindow = new Window_ItemBookStatus(w3, 0, ww, wh*3);
  353.         this._statusWindow2 = new Window_ItemBookStatus2(w3, wh*3, ww, wh*3);
  354.         this._statusWindow3 = new Window_ItemBookStatus3(w3, (wh*6)-1, ww, (wh*4)+1);
  355.         this.addWindow(this._indexWindow);
  356.         this.addWindow(this._statusWindow);
  357.         this.addWindow(this._statusWindow2);
  358.         this.addWindow(this._statusWindow3);
  359.         this._indexWindow.setStatusWindow(this._statusWindow);
  360.         this._indexWindow.setStatusWindow2(this._statusWindow2);
  361.         this._indexWindow.setStatusWindow3(this._statusWindow3);
  362.     };
  363.  
  364.     function Window_ItemBookIndex() {
  365.         this.initialize.apply(this, arguments);
  366.     }
  367.  
  368.     Window_ItemBookIndex.prototype = Object.create(Window_Selectable.prototype);
  369.     Window_ItemBookIndex.prototype.constructor = Window_ItemBookIndex;
  370.  
  371.     Window_ItemBookIndex.lastTopRow = 0;
  372.     Window_ItemBookIndex.lastIndex  = 0;
  373.  
  374.     Window_ItemBookIndex.prototype.initialize = function(x, y) {
  375.         var width = Graphics.boxWidth / 3;
  376.         if (IndexHeight === 'true') {
  377.             var height = Graphics.boxHeight/2;
  378.         }
  379.         else{
  380.             var height = Graphics.boxHeight;
  381.         }
  382.         Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  383.         this.refresh();
  384.         this.setTopRow(Window_ItemBookIndex.lastTopRow);
  385.         this.select(Window_ItemBookIndex.lastIndex);
  386.         this.activate();
  387.     };
  388.  
  389.     Window_ItemBookIndex.prototype.maxCols = function() {
  390.         return listRow;
  391.     };
  392.  
  393.     Window_ItemBookIndex.prototype.maxItems = function() {
  394.         return this._list ? this._list.length : 0;
  395.     };
  396.  
  397.     Window_ItemBookIndex.prototype.setStatusWindow = function(statusWindow) {
  398.         this._statusWindow = statusWindow;
  399.         this.updateStatus();
  400.     };
  401.     Window_ItemBookIndex.prototype.setStatusWindow2 = function(statusWindow2) {
  402.         this._statusWindow2 = statusWindow2;
  403.         this.updateStatus();
  404.     };
  405.     Window_ItemBookIndex.prototype.setStatusWindow3 = function(statusWindow3) {
  406.         this._statusWindow3 = statusWindow3;
  407.         this.updateStatus();
  408.     };
  409.  
  410.     Window_ItemBookIndex.prototype.update = function() {
  411.         Window_Selectable.prototype.update.call(this);
  412.         this.updateStatus();
  413.     };
  414.  
  415.     Window_ItemBookIndex.prototype.updateStatus = function() {
  416.         if (this._statusWindow) {
  417.             var item = this._list[this.index()];
  418.             this._statusWindow.setItem(item);
  419.         }
  420.         if (this._statusWindow2) {
  421.             var item = this._list[this.index()];
  422.             this._statusWindow2.setItem(item);
  423.         }
  424.         if (this._statusWindow3) {
  425.             var item = this._list[this.index()];
  426.             this._statusWindow3.setItem(item);
  427.         }
  428.     };
  429.  
  430.     Window_ItemBookIndex.prototype.refresh = function() {
  431.         var i, item;
  432.         this._list = [];
  433.         for (i = 1; i < Math.min(5000, $dataItems.length); i++) {
  434.             item = $dataItems[i];
  435.             if (item && item.name && item.itypeId === 1 && item.meta.book !== 'no') {
  436.                 this._list.push(item);
  437.             }
  438.         }
  439.         if (ShowKeyItems === 'true') {                
  440.         for (i = 1; i < Math.min(5000, $dataItems.length); i++) {
  441.             item = $dataItems[i];
  442.             if (item && item.name && item.itypeId === 2 && item.meta.book !== 'no') {
  443.                 this._list.push(item);
  444.             }
  445.         }
  446.         }
  447.         for (i = 1; i < Math.min(5000, $dataWeapons.length); i++) {
  448.             item = $dataWeapons[i];
  449.             if (item && item.name && item.meta.book !== 'no') {
  450.                 this._list.push(item);
  451.             }
  452.         }
  453.         for (i = 1; i < Math.min(5000, $dataArmors.length); i++) {
  454.             item = $dataArmors[i];
  455.             if (item && item.name && item.meta.book !== 'no') {
  456.                 this._list.push(item);
  457.             }
  458.         }
  459.         this.createContents();
  460.         this.drawAllItems();
  461.     };
  462.  
  463.     Window_ItemBookIndex.prototype.drawItem = function(index) {
  464.         var item = this._list[index];
  465.         var rect = this.itemRect(index);
  466.         var width = rect.width - this.textPadding();
  467.         if ($gameSystem.isInItemBook(item)) {
  468.             this.drawItemName(item, rect.x, rect.y, width);
  469.         } else {
  470.             var iw = Window_Base._iconWidth + 4;
  471.             this.drawText(unknownData, rect.x + iw, rect.y, width - iw);
  472.         }
  473.     };
  474.  
  475.     Window_ItemBookIndex.prototype.processCancel = function() {
  476.         Window_Selectable.prototype.processCancel.call(this);
  477.         Window_ItemBookIndex.lastTopRow = this.topRow();
  478.         Window_ItemBookIndex.lastIndex = this.index();
  479.     };
  480.  
  481.     function Window_ItemBookStatus() {
  482.         this.initialize.apply(this, arguments);
  483.     }
  484.     function Window_ItemBookStatus2() {
  485.         this.initialize.apply(this, arguments);
  486.     }
  487.     function Window_ItemBookStatus3() {
  488.         this.initialize.apply(this, arguments);
  489.     }
  490.  
  491.     Window_ItemBookStatus.prototype = Object.create(Window_Base.prototype);
  492.     Window_ItemBookStatus.prototype.constructor = Window_ItemBookStatus;
  493.    
  494.     Window_ItemBookStatus2.prototype = Object.create(Window_Base.prototype);
  495.     Window_ItemBookStatus2.prototype.constructor = Window_ItemBookStatus2;
  496.    
  497.     Window_ItemBookStatus3.prototype = Object.create(Window_Base.prototype);
  498.     Window_ItemBookStatus3.prototype.constructor = Window_ItemBookStatus3;
  499.  
  500.     Window_ItemBookStatus.prototype.initialize = function(x, y, width, height) {
  501.         Window_Base.prototype.initialize.call(this, x, y, width, height);
  502.     };
  503.  
  504.     Window_ItemBookStatus.prototype.setItem = function(item) {
  505.         if (this._item !== item) {
  506.             this._item = item;
  507.             this.refresh();
  508.         }
  509.     };
  510.     Window_ItemBookStatus2.prototype.setItem = function(item) {
  511.         if (this._item !== item) {
  512.             this._item = item;
  513.             this.refresh();
  514.         }
  515.     };
  516.     Window_ItemBookStatus3.prototype.setItem = function(item) {
  517.         if (this._item !== item) {
  518.             this._item = item;
  519.             this.refresh();
  520.         }
  521.     };
  522.  
  523.     Window_ItemBookStatus.prototype.refresh = function() {
  524.         var item = this._item;
  525.         var x = 10;
  526.         var y = 0;
  527.         var lineHeight = this.lineHeight();
  528.  
  529.         this.contents.clear();
  530.  
  531.         if (!item || !$gameSystem.isInItemBook(item)) {
  532.             return;
  533.         }
  534.        
  535.         this.drawItemName(item, x-1, y);
  536.        
  537.         this.drawTextEx(item.description, 10, y + lineHeight*2);
  538.  
  539.     };
  540.    
  541.     Window_ItemBookStatus2.prototype.refresh = function() {
  542.         var item = this._item;
  543.         var x = 10;
  544.         var y = 0;
  545.         var lineHeight = this.lineHeight();
  546.  
  547.         this.contents.clear();
  548.  
  549.         if (!item || !$gameSystem.isInItemBook(item)) {
  550.             return;
  551.         }
  552.        
  553.         if ($gameSwitches.value(ShowPrice) === true || ShowPrice === 0) {
  554.         var price = item.price > 0 ? item.price : '-';
  555.         this.changeTextColor(this.systemColor());
  556.         this.drawText(priceText + ':', x, y, 120);
  557.         this.resetTextColor();
  558.        
  559.         if (goldIcon === 'true') { 
  560.             this.drawText(price, x+60, y, 145, 'right');
  561.             this.drawIcon(Yanfly.Icon.Gold, x+210, y)
  562.         } else {
  563.             this.drawText(price, x+96, y, 145, 'right');
  564.                 }
  565.         }
  566.        
  567.         if ($gameSwitches.value(ShowType) === true || ShowType === 0) {
  568.         if (DataManager.isWeapon(item) || DataManager.isArmor(item)) {
  569.             var etype = $dataSystem.equipTypes[item.etypeId];
  570.             this.changeTextColor(this.systemColor());
  571.             this.drawText(equipText + ':', x, y+lineHeight*3, 120);
  572.             this.resetTextColor();
  573.             this.drawText(etype, x + 120, y+lineHeight*3, 120, 'right');
  574.             y += lineHeight*2;
  575.  
  576.             var type;
  577.             if (DataManager.isWeapon(item)) {
  578.                 type = $dataSystem.weaponTypes[item.wtypeId];
  579.             } else {
  580.                 type = $dataSystem.armorTypes[item.atypeId];
  581.             }
  582.             this.changeTextColor(this.systemColor());
  583.             this.drawText(typeText + ':', x, y, 120);
  584.             this.resetTextColor();
  585.             this.drawText(type, x + 120, y, 120, 'right');
  586.  
  587.             x = this.textPadding() + 350;
  588.         }
  589.         }
  590.     };
  591.    
  592.     Window_ItemBookStatus3.prototype.refresh = function() {
  593.         var item = this._item;
  594.         var x = 10;
  595.         var y = 0;
  596.         var lineHeight = this.lineHeight();
  597.  
  598.         this.contents.clear();
  599.  
  600.         if (!item || !$gameSystem.isInItemBook(item)) {
  601.             return;
  602.         }
  603.         if ($gameSwitches.value(ShowStatus) === true || ShowStatus === 0) {
  604.         if (DataManager.isWeapon(item) || DataManager.isArmor(item)) {
  605.             for (var i = 0; i < 8; i++) {
  606.                 this.changeTextColor(this.systemColor());
  607.                 this.drawText(TextManager.param(i), x, y, 160);
  608.                 this.resetTextColor();
  609.                 this.drawText(item.params[i], x + 180, y, 60, 'right');
  610.                 y += lineHeight;
  611.             }
  612.         }
  613.         }
  614.        
  615.     };
  616. })();
RAW Paste Data