SHARE
TWEET

Untitled

a guest Dec 15th, 2015 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // SilvItemLog.js
  3. // Version: 1.07
  4. // License: https://creativecommons.org/licenses/by/4.0/
  5. //=============================================================================
  6. /*:
  7.  * @plugindesc v1.07 Item Log. Displays the last looted items.
  8.    <SilverItemLog>
  9.  * @author Silver
  10.  *
  11.  * @param -- General --
  12.  *
  13.  * @param Auto Gain Loot
  14.  * @desc Automatically add the loot to the party's inventory? true/false
  15.  * @default true
  16.  *
  17.  * @param Auto Log Items
  18.  * @desc Automatically add items to the log window when added through the GainItem command? true/false
  19.  * @default true
  20.  *
  21.  * @param -- Sound --
  22.  *
  23.  * @param Item SFX
  24.  * @desc Automatically play this sound when picking up items, armors or weapons. Leave blank to disable.
  25.  * @default Item1
  26.  *
  27.  * @param Gold SFX
  28.  * @desc Automatically play this sound when picking up gold (currency). Leave blank to disable.
  29.  * @default Coin
  30.  *
  31.  * @param -- Positioning & Size --
  32.  *
  33.  * @param Window X
  34.  * @desc x-location of itemlog window. If window-alignment is set to Right, this will act as an offset value instead
  35.  * @default -2
  36.  *
  37.  * @param Window Y
  38.  * @desc y-location of itemlog window. If window-alignment is set to Top, this will act as an offset value instead
  39.  * @default 2
  40.  *
  41.  * @param Window Horizontal Alignment
  42.  * @desc Left/Right
  43.  * @default Right
  44.  *
  45.  * @param Window Vertical Alignment
  46.  * @desc Top/Bottom
  47.  * @default Top
  48.  *
  49.  * @param Window Width
  50.  * @desc width of the itemlog window
  51.  * @default 400
  52.  *
  53.  * @param Window Height
  54.  * @desc height of the itemlog window
  55.  * @default 160
  56.  *
  57.  * @param -- Window Contents --
  58.  *
  59.  * @param Font Size
  60.  * @desc Size of the font
  61.  * @default 24
  62.  *
  63.  * @param Text Offset X
  64.  * @desc Text offset X for the log entries
  65.  * @default 10
  66.  *
  67.  * @param Text Offset Y
  68.  * @desc Text offset Y for the log entries
  69.  * @default 6
  70.  *
  71.  * @param Standard Padding
  72.  * @desc Leave at default (it's basically an X and Y offset)
  73.  * @default 0
  74.  *
  75.  * @param Positive Prefix Text
  76.  * @desc Prefix text
  77.  * @default Received
  78.  *
  79.  * @param Negative Prefix Text
  80.  * @desc Prefix text
  81.  * @default Lost
  82.  *
  83.  * @param Icon Y-offset
  84.  * @desc Extra Y-offset for the drawing of the icons to better align them with the sentences
  85.  * @default 4
  86.  *
  87.  * @param Window Skin
  88.  * @desc Name of the window skin to use for this window
  89.  * @default Window_ItemLog
  90.  *
  91.  * @param Auto-clear Upon Full-fade
  92.  * @desc Clear the items in the item-window if the window fully faded? true/false
  93.  * @default false
  94.  *
  95.  * @param -- Miscellaneous --
  96.  *
  97.  * @param Fadeout Delay
  98.  * @desc How long before the window starts fading out (in frames)
  99.  * @default 240
  100.  *
  101.  * @param Fadeout Speed
  102.  * @desc How fast the window fades out
  103.  * @default 2
  104.  *
  105.  * @param Text Shading
  106.  * @desc Displays previously looted items in darker text. Set to 0 to disable.
  107.  * @default -0.15
  108.  *
  109.  * @param Gold IconIndex
  110.  * @desc iconindex for the gold/currency icon
  111.  * @default 163
  112.  *
  113.  * @help
  114.  * Plugin Commands:
  115.  * Note that all commands & parameters are NOT case sensitive.
  116.  *
  117.  * ItemLog <loot type> <loot database-index> <amount> <optional: skip (override: does not actually add the item to the inventory)>
  118.  * example to loot 3 potions: ItemLog item 1 3
  119.  * example to loot 5 swords:  ItemLog weapon 1 5
  120.  * example to loot 6 axes:    ItemLog weapon 2 6
  121.  * example to log (but does not add to inventory regardless of the "Auto Gain Loot" parameter) 6 axes:    ItemLog weapon 2 6 skip
  122.  *
  123.  * The exception is gold, examples:
  124.  *                            ItemLog gold 123
  125.  *                            ItemLog gold 999
  126.  *
  127.  *
  128.  * Show the itemlog window w/o adding anything:
  129.  * ItemLog show
  130.  *
  131.  * Clear the items in the itemlog window:
  132.  * Itemlog ClearItems
  133.  *
  134.  *--------------------------------------
  135.  * Version History:
  136.  *--------------------------------------
  137.  * v1.07 (15 December 1025) [parameters changed]
  138.  * - Rearranged and categorized parameters
  139.  * - Added this plugin to the global variable Imported.
  140.  * - Added a new plugin-command to clear the itemlog.
  141.  * - Added an option to auto-clear the window upon full-fade.
  142.  *
  143.  * v1.06a (13 December 2015) [parameters changed]
  144.  * - Now supports losing items/gold.
  145.  * - Fixed a minor alignment issue when gaining < 10 items, armors or weapons.
  146.  * - Minor refactoring of the 1.06 code.
  147.  *
  148.  * v1.05 (12 December 2015)
  149.  * - Added a version history.
  150.  * - Fixed a bug that used the wrong amount of gold/item/etc. when using a game-variable instead of a fixed amount.
  151.  * - Added this plugin to Silv.Plugins.
  152.  * - Changed license to https://creativecommons.org/licenses/by/4.0/
  153.  *
  154.  * v1.00 - v1.04 (November 2015)
  155.  */
  156. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  157. // Utilities
  158. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  159. String.prototype.contains = function(it) { return this.indexOf(it) != -1; };
  160.  
  161. // Stack with limited size
  162. // Automatically removes the first element(s) if it exceeds it's maxsize
  163. function Queue_LSize(maxSize)
  164. {
  165.         this._maxSize = maxSize;
  166.     this.length = 0;
  167.     this._storage = [];
  168. }
  169.  
  170. Queue_LSize.prototype.itemByIdx = function(index)
  171. {
  172.         return this._storage[index];
  173. };
  174.  
  175. Queue_LSize.prototype.queue = function(data)
  176. {
  177.     this._storage[this.length] = data;
  178.         this.length++;
  179.         while (this.length > this._maxSize) { this.onAutoRemoval(this.dequeue()); }
  180. };
  181.  
  182. // For aliasing
  183. Queue_LSize.prototype.onAutoRemoval = function(removed_item) {};
  184.  
  185.  // Remove and return first item in array
  186. Queue_LSize.prototype.dequeue = function()
  187. {
  188.     if (this.length)
  189.         {
  190.         var deletedData = this._storage.shift();
  191.         this.length--;
  192.         return deletedData;
  193.     }
  194. };
  195. // Remove and return last item in array
  196. Queue_LSize.prototype.pop = function()
  197. {
  198.     if (this.length)
  199.         {
  200.         var deletedData = this._storage.pop();
  201.         this.length--;
  202.         return deletedData;
  203.     }
  204. };
  205.  
  206. function lpad(word, padStr, length)
  207. {
  208.     word = String(word);
  209.     while (word.length < length) word = padStr + word;
  210.     return word;
  211. }
  212.  
  213. function rpad(word, padStr, length)
  214. {
  215.     word = String(word);
  216.     while (word.length < length) word += padStr;
  217.     return word;
  218. }
  219. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  220. // #Parameters
  221. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  222. var Imported = Imported || {};
  223. Imported.Silv_ItemLog = 1.07;
  224.  
  225. var Silv = Silv || {};
  226. Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilverItemLog>'); })[0].parameters;
  227. Silv.ItemLog = Silv.ItemLog || {};
  228. Silv.ItemLog.Window = null;
  229. Silv.ItemLog.AlreadyPlayedSFX = false;
  230. // General
  231. Silv.ItemLog.AutoLootGain = Silv.Parameters['Auto Gain Loot'].toLowerCase() == 'true';
  232. Silv.ItemLog.AutoLogItems = Silv.Parameters['Auto Log Items'].toLowerCase() == 'true';
  233. Silv.ItemLog.PickupSFXItem = Silv.Parameters['Item SFX'];
  234. Silv.ItemLog.PickupSFXGold = Silv.Parameters['Gold SFX'];
  235. // Positioning & Size
  236. Silv.ItemLog.Window_X = parseInt(Silv.Parameters['Window X']);
  237. Silv.ItemLog.Window_Y = parseInt(Silv.Parameters['Window Y']);
  238. Silv.ItemLog.WindowWidth = parseInt(Silv.Parameters['Window Width']);
  239. Silv.ItemLog.WindowHeight = parseInt(Silv.Parameters['Window Height']);
  240. Silv.ItemLog.WindowHorizontalAlignment = Silv.Parameters['Window Horizontal Alignment'].toLowerCase();
  241. Silv.ItemLog.WindowVerticalAlignment = Silv.Parameters['Window Vertical Alignment'].toLowerCase();
  242. // Window Contents
  243. Silv.ItemLog.FontSize = parseInt(Silv.Parameters['Font Size']);
  244. Silv.ItemLog.EntryTextOffsetX = parseInt(Silv.Parameters['Text Offset X']);
  245. Silv.ItemLog.EntryTextOffsetY = parseInt(Silv.Parameters['Text Offset Y']);
  246. Silv.ItemLog.StandardPadding = parseInt(Silv.Parameters['Standard Padding']);
  247. Silv.ItemLog.TextLines = Silv.ItemLog.TextLines || 'Error: Not yet set';
  248.  
  249. Silv.ItemLog.PositivePrefixText = Silv.Parameters['Positive Prefix Text'];
  250. if (Silv.ItemLog.PositivePrefixText.slice(-1) != ' ') { Silv.ItemLog.PositivePrefixText += ' '; }
  251. Silv.ItemLog.NegativePrefixText = Silv.Parameters['Negative Prefix Text'];
  252. if (Silv.ItemLog.NegativePrefixText.slice(-1) != ' ') { Silv.ItemLog.NegativePrefixText += ' '; }
  253.  
  254. Silv.ItemLog.IconOffsetY = parseInt(Silv.Parameters['Icon Y-offset']);
  255. Silv.ItemLog.WindowSkin = Silv.Parameters['Window Skin'];
  256. Silv.ItemLog.AutoClearUponFullFade = Silv.Parameters['Auto-clear Upon Full-fade'].toLowerCase() == 'true';
  257.  
  258. // Miscellaneous
  259. Silv.ItemLog.FadeoutDelay = parseInt(Silv.Parameters['Fadeout Delay']);
  260. Silv.ItemLog.FadeoutSpeed = parseInt(Silv.Parameters['Fadeout Speed']);
  261. Silv.ItemLog.TextShadingValue = parseFloat(Silv.Parameters['Text Shading']);
  262. Silv.ItemLog.GoldIconIndex = parseInt(Silv.Parameters['Gold IconIndex']);
  263.  
  264. // Non Parameters
  265. Silv.ItemLog.PrefixLength = Math.max(Silv.ItemLog.PositivePrefixText.length, Silv.ItemLog.NegativePrefixText.length);
  266.  
  267. (function()
  268. {
  269. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  270. // Window
  271. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  272. function Window_ItemLog() { this.initialize.apply(this, arguments); }
  273. // Inherit from base window
  274. Window_ItemLog.prototype = Object.create(Window_Base.prototype);
  275. // Set Constructor
  276. Window_ItemLog.prototype.constructor = Window_ItemLog;
  277.  
  278. Window_ItemLog.prototype.loadWindowskin = function() { this.windowskin = ImageManager.loadSystem(Silv.ItemLog.WindowSkin); };
  279. Window_ItemLog.prototype.standardPadding = function() { return Silv.ItemLog.StandardPadding; };
  280. Window_ItemLog.prototype.standardFontSize = function() { return Silv.ItemLog.FontSize; };
  281.  
  282. // Initialization
  283. Window_ItemLog.prototype.initialize = function(x, y, width, height)
  284. {
  285.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  286.     this._helpWindow = null;
  287.     this._handlers = {};
  288.     this._touching = false;
  289.     this.deactivate();
  290.         this.maxStackLines = parseInt((height - Silv.ItemLog.EntryTextOffsetY * 2) / parseFloat(Silv.ItemLog.FontSize));
  291.         this.clearItems();
  292.         this.fadeOutCnt = 0;
  293.         this.isFadingOut = false;
  294.         this.isFadedOut = false;
  295.        
  296.         this.update();
  297. };
  298.  
  299. // Update
  300. Window_ItemLog.prototype.update = function()
  301. {
  302.     Window_Base.prototype.update.call(this);
  303.        
  304.         Silv.ItemLog.AlreadyPlayedSFX = false;
  305.         this.updateFadeOut();
  306.     this.drawItemLogContents();
  307. };
  308.  
  309. // Update Fading Out
  310. Window_ItemLog.prototype.updateFadeOut = function()
  311. {
  312.         if (this.isFadedOut) { return; }
  313.        
  314.         if (!this.isFadingOut)
  315.         {
  316.                 this.fadeOutCnt++;
  317.                 if (this.fadeOutCnt > Silv.ItemLog.FadeoutDelay)
  318.                 {
  319.                         this.fadeOutCnt = 0;
  320.                         this.isFadingOut = true;
  321.                 }
  322.         }
  323.         else
  324.         {
  325.                 this.fadeOut();
  326.         }
  327. };
  328.  
  329. Window_ItemLog.prototype.clearItems = function()
  330. {
  331.         Silv.ItemLog.TextLines = new Queue_LSize(this.maxStackLines);
  332. };
  333.  
  334. Window_ItemLog.prototype.fadeOut = function()
  335. {
  336.         this.opacity = this.contentsOpacity -= Silv.ItemLog.FadeoutSpeed;
  337.         if (this.opacity <= 0) { this.onFullyFadedOut(); }
  338. };
  339.  
  340. Window_ItemLog.prototype.onFullyFadedOut = function()
  341. {
  342.         this.isFadedOut = true;
  343.         if (Silv.ItemLog.AutoClearUponFullFade) { this.clearItems(); }
  344. };
  345.  
  346. Window_ItemLog.prototype.resetFade = function()
  347. {
  348.         this.isFadingOut = false;
  349.         this.fadeOutCnt = 0;
  350.         this.opacity = this.contentsOpacity  = 255;
  351.         this.isFadedOut = false;
  352. };
  353.  
  354. Window_ItemLog.prototype.fadeOutInstantly = function()
  355. {
  356.         this.opacity = this.contentsOpacity = 0;
  357.         this.onFullyFadedOut();
  358. };
  359.  
  360. // #Drawing
  361. Window_ItemLog.prototype.drawItemLogContents = function()
  362. {
  363.         if (typeof Silv.ItemLog.TextLines === 'string') { return; }
  364.         this.contents.clear();
  365.         this.resetTextColor();
  366.        
  367.         var textLinesCnt = Silv.ItemLog.TextLines.length;
  368.         var text = null;
  369.         for (var i = textLinesCnt - 1; i >= 0; i--)
  370.         {
  371.                 var line = Silv.ItemLog.TextLines.itemByIdx(i);
  372.                 text = line.t1;
  373.                 this.drawText(text, Silv.ItemLog.EntryTextOffsetX, Silv.ItemLog.EntryTextOffsetY + i * Silv.ItemLog.FontSize, 256, 'left');
  374.                 var newOffsetX = Silv.ItemLog.EntryTextOffsetX + this.contents.measureTextWidth(line.t1);
  375.                 this.drawLootIcon(line.iconIndex, newOffsetX, Silv.ItemLog.EntryTextOffsetY + i * Silv.ItemLog.FontSize + Silv.ItemLog.IconOffsetY);
  376.                 newOffsetX += Silv.ItemLog.FontSize + 4;
  377.                 text = line.t2;
  378.                 this.drawText(text, newOffsetX, Silv.ItemLog.EntryTextOffsetY + i * Silv.ItemLog.FontSize, 256, 'left');
  379.                
  380.                 this.contents.textColor = shadeColor(this.contents.textColor, Silv.ItemLog.TextShadingValue);
  381.         }
  382.        
  383.         function shadeColor(color, percent)
  384.         {  
  385.                 var f=parseInt(color.slice(1),16),t=percent<0?0:255,p=percent<0?percent*-1:percent,R=f>>16,G=f>>8&0x00FF,B=f&0x0000FF;
  386.                 return "#"+(0x1000000+(Math.round((t-R)*p)+R)*0x10000+(Math.round((t-G)*p)+G)*0x100+(Math.round((t-B)*p)+B)).toString(16).slice(1);
  387.         }
  388. };
  389.  
  390. Window_ItemLog.prototype.drawLootIcon = function(iconIndex, x, y)
  391. {
  392.     var bitmap = ImageManager.loadSystem('IconSet');
  393.     var pw = Window_Base._iconWidth;
  394.     var ph = Window_Base._iconHeight;
  395.     var sx = iconIndex % 16 * pw;
  396.     var sy = Math.floor(iconIndex / 16) * ph;
  397.     this.contents.blt(bitmap, sx, sy, pw, ph, x, y, Silv.ItemLog.FontSize, Silv.ItemLog.FontSize);
  398. };
  399. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  400. // Create the ItemLog window
  401. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  402. var alias_silv_itemlog_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
  403. Scene_Map.prototype.createDisplayObjects = function()
  404. {
  405.         alias_silv_itemlog_createDisplayObjects.call(this);
  406.         this.createItemLogWindow();
  407. };
  408.  
  409. Scene_Map.prototype.createItemLogWindow = function()
  410. {
  411.         var x = 0;
  412.         if (Silv.ItemLog.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.ItemLog.WindowWidth; }
  413.         var y = 0;
  414.         if (Silv.ItemLog.WindowVerticalAlignment == 'bottom') { y = Graphics.height - Silv.ItemLog.WindowHeight; }
  415.        
  416.         if (Silv.ItemLog.Window !== null) { this.removeWindow(Silv.ItemLog.Window); }
  417.         Silv.ItemLog.Window = new Window_ItemLog(x + Silv.ItemLog.Window_X, y + Silv.ItemLog.Window_Y, Silv.ItemLog.WindowWidth, Silv.ItemLog.WindowHeight);
  418.         Silv.ItemLog.Window.fadeOutInstantly();
  419.         this.addChildAt(Silv.ItemLog.Window, 1);
  420. };
  421.  
  422. // Omg why does RPG Maker not have this method by default...
  423. Scene_Base.prototype.removeWindow = function(window)
  424. {
  425.         var index = this.children.indexOf(window);
  426.         if (index > -1) { this.children.splice(index, 1); }
  427. };
  428. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  429. // Saving & Loading
  430. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  431. /* Code below does not work for some reason. It does save the data but not load it properly.
  432. var alias_silv_ItemLog_makeSaveContents = DataManager.makeSaveContents;
  433. DataManager.makeSaveContents = function()
  434. {
  435.         contents = alias_silv_ItemLog_makeSaveContents.call(this);
  436.         contents.itemLogData = Silv.ItemLog.TextLines;
  437.         return contents;
  438. }
  439.  
  440. var alias_silv_ItemLog_extractSaveContents = DataManager.extractSaveContents;
  441. DataManager.extractSaveContents = function(contents)
  442. {
  443.         alias_silv_ItemLog_extractSaveContents.call(this, contents);
  444.         Silv = Silv || {};
  445.         Silv.ItemLog = Silv.ItemLog || {};
  446.         Silv.ItemLog.TextLines = contents.itemLogData;
  447. }
  448. */
  449. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  450. // Automatically add items
  451. //------------------------
  452. //
  453. // Explanation of the this._params:
  454. //
  455. // Gold
  456. // [0] = 0: increase, 1: decrease
  457. // [1] = 0: value, 1: $gameVariable was used to determine amount of gold
  458. // [2] = it is a direct amount of gold but if [1] == 1, then this is the gameVariable number that contains the gold-amount instead.
  459. //
  460. //
  461. // Items, Weapons & Armor
  462. // [0] = armor id matching the $dataArmors index
  463. // [1] = 0: increase, 1: decrease
  464. // [2] = 0: value, 1: $gameVariable was used to determine amount of armors
  465. // [3] = it is a direct amount of gold but if [2] == 1, then this is the gameVariable number that contains the gold-amount instead.
  466. // [4] = include equipment? true/false
  467. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  468. Silv.ItemLog.getAmount = function(params) // does not apply to gold! Gold has different parameters.. Yay for RPG Maker...
  469. {
  470.         return ((params[2] == 0) ? params[3] : $gameVariables.value(params[3])) * (params[1] == 1 ? -1 : 1);
  471. };
  472.  
  473. // Change Gold
  474. var alias_silv_command125 = Game_Interpreter.prototype.command125;
  475. Game_Interpreter.prototype.command125 = function()
  476. {
  477.         var amount = (this._params[1] == 0) ? this._params[2] : $gameVariables.value(this._params[2]);
  478.         if (this._params[0] == 1) { amount *= -1; }
  479.        
  480.     var retVal = alias_silv_command125.apply(this, arguments);
  481.         if (Silv.ItemLog.AutoLogItems) { PluginCommand('ItemLog', ['gold', String(amount), 'skip']); }
  482.     return retVal;
  483. };
  484.  
  485. // Change Items
  486. var alias_silv_command126 = Game_Interpreter.prototype.command126;
  487. Game_Interpreter.prototype.command126 = function()
  488. {
  489.     var retVal = alias_silv_command126.apply(this, arguments);
  490.         if (Silv.ItemLog.AutoLogItems) { PluginCommand('ItemLog', ['item', this._params[0], Silv.ItemLog.getAmount(this._params), 'skip']); }
  491.     return retVal;
  492. };
  493.  
  494. // Change Weapons
  495. var alias_silv_command127 = Game_Interpreter.prototype.command127;
  496. Game_Interpreter.prototype.command127 = function()
  497. {
  498.     var retVal = alias_silv_command127.apply(this, arguments);
  499.         if (Silv.ItemLog.AutoLogItems) { PluginCommand('ItemLog', ['weapon', this._params[0], Silv.ItemLog.getAmount(this._params), 'skip']); }
  500.     return retVal;
  501. };
  502.  
  503. // Change Armors
  504. var alias_silv_command128 = Game_Interpreter.prototype.command128;
  505. Game_Interpreter.prototype.command128 = function()
  506. {
  507.     var retVal = alias_silv_command128.apply(this, arguments);
  508.         if (Silv.ItemLog.AutoLogItems) { PluginCommand('ItemLog', ['armor', this._params[0], Silv.ItemLog.getAmount(this._params), 'skip']); }
  509.     return retVal;
  510. };
  511. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  512. // Plugin Command
  513. // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
  514. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  515. Silv.ItemLog.getPrefixText = function(amount)
  516. {
  517.         var prefixText = rpad((amount >= 0) ? Silv.ItemLog.PositivePrefixText : Silv.ItemLog.NegativePrefixText, ' ', Silv.ItemLog.PrefixLength);
  518.        
  519.         return prefixText;
  520. };
  521.  
  522. var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  523. Game_Interpreter.prototype.pluginCommand = function(command, args)
  524. {
  525.         _Game_Interpreter_pluginCommand.call(this, command, args);
  526.         if (command.toLowerCase() == 'itemlog') { PluginCommand(command, args); }
  527. };
  528.  
  529. function PluginCommand(cmd, args)
  530. {
  531.         switch(args[0].toLowerCase())
  532.         {
  533.                 case 'show':
  534.                         Silv.ItemLog.Window.resetFade();
  535.                         return;
  536.                 case 'clearitems':
  537.                         Silv.ItemLog.Window.clearItems();
  538.                         return;
  539.         }      
  540.        
  541.         // arg: item 1 10
  542.         // arg: weapon 2 1
  543.         // arg: weapon 2 1 skip
  544.         // arg: gold 123
  545.         var db = getDatabase(args[0]);
  546.         var lootIdx = parseInt(args[1]);
  547.         var skipAddItemToInventory = (String(args[args.length - 1]).toLowerCase() == 'skip');
  548.         if (db != 'gold')
  549.         {
  550.                 var amount = parseInt(args[2]);
  551.                 var amountStr = String(args[2]);
  552.                 var name = db[lootIdx].name;
  553.                 var iconIndex = db[lootIdx].iconIndex;
  554.                
  555.                 var t1 = Silv.ItemLog.getPrefixText(amount) + lpad(Math.abs(amountStr), ' ', 2) + 'x ';
  556.                 var t2 = name;                         
  557.                
  558.                 Silv.ItemLog.TextLines.queue({t1: t1, iconIndex: iconIndex, t2: t2});
  559.                
  560.         // Add loot
  561.                 if (Silv.ItemLog.AutoLootGain && !skipAddItemToInventory)
  562.                 {
  563.                         $gameParty.gainItem(db[lootIdx], amount);
  564.                 }
  565.                
  566.                 // sfx
  567.                 if (!Silv.ItemLog.AlreadyPlayedSFX)
  568.                 {
  569.                         Play_SE(Silv.ItemLog.PickupSFXItem);
  570.                         Silv.ItemLog.AlreadyPlayedSFX = true;
  571.                 }
  572.         }
  573.         else // Gold
  574.         {
  575.                 var amount = parseInt(args[1]);
  576.                 Silv.ItemLog.TextLines.queue({t1: Silv.ItemLog.getPrefixText(amount) + '    ', iconIndex: Silv.ItemLog.GoldIconIndex, t2: Math.abs(amount) + ' ' + $dataSystem.currencyUnit});
  577.                
  578.                 // Add loot
  579.                 if (Silv.ItemLog.AutoLootGain && !skipAddItemToInventory)
  580.                 {
  581.                         $gameParty.gainGold(amount);
  582.                 }
  583.                
  584.                 // sfx
  585.                 if (!Silv.ItemLog.AlreadyPlayedSFX)
  586.                 {
  587.                         Play_SE(Silv.ItemLog.PickupSFXGold);
  588.                         Silv.ItemLog.AlreadyPlayedSFX = true;
  589.                 }
  590.         }
  591.         Silv.ItemLog.Window.resetFade(); // Reset the fadeout, if any.
  592.        
  593.         function getDatabase(code)
  594.         {
  595.                 code = code.toLowerCase();
  596.                 if (code.contains('item') || code.contains('itm'))
  597.                         return $dataItems;
  598.                 if (code.contains('armor'))
  599.                         return $dataArmors;
  600.                 if (code.contains('weapon') || code.contains('wpn'))
  601.                         return $dataWeapons;
  602.                 if (code.contains('gold'))
  603.                         return 'gold';
  604.                
  605.                 throw('getDatabase('+ code + ') ERROR: invalid code.');
  606.         }
  607.        
  608.         function Play_SE(filename)
  609.         {
  610.                 AudioManager.playSe({name: filename, volume: 90, pitch: 100, pan: 0});
  611.         }
  612. }
  613. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  614. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top