Advertisement
Guest User

Untitled

a guest
Dec 16th, 2015
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // SilvItemLog.js
  3. // Version: 1.07a
  4. // License: https://creativecommons.org/licenses/by/4.0/
  5. //=============================================================================
  6. /*:
  7.  * @plugindesc v1.07a 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.  * Enable/Disable automatic item-logging:
  135.  * ItemLog EnableLogging
  136.  * ItemLog DisableLogging
  137.  *
  138.  *--------------------------------------
  139.  * Version History:
  140.  *--------------------------------------
  141.  * v1.07a (16 December 2015) [parameters changed]
  142.  * - Rearranged and categorized parameters
  143.  * - Added this plugin to the global variable Imported.
  144.  * - Added a new plugin-command to clear the itemlog.
  145.  * - Added an option to auto-clear the window upon full-fade.
  146.  * - Added two new plugin commands to enable/disable auto-logging of items.
  147.  *
  148.  * v1.06a (13 December 2015) [parameters changed]
  149.  * - Now supports losing items/gold.
  150.  * - Fixed a minor alignment issue when gaining < 10 items, armors or weapons.
  151.  * - Minor refactoring of the 1.06 code.
  152.  *
  153.  * v1.05 (12 December 2015)
  154.  * - Added a version history.
  155.  * - Fixed a bug that used the wrong amount of gold/item/etc. when using a game-variable instead of a fixed amount.
  156.  * - Added this plugin to Silv.Plugins.
  157.  * - Changed license to https://creativecommons.org/licenses/by/4.0/
  158.  *
  159.  * v1.00 - v1.04 (November 2015)
  160.  */
  161. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  162. // Utilities
  163. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  164. String.prototype.contains = function(it) { return this.indexOf(it) != -1; };
  165.  
  166. // Stack with limited size
  167. // Automatically removes the first element(s) if it exceeds it's maxsize
  168. function Queue_LSize(maxSize)
  169. {
  170.     this._maxSize = maxSize;
  171.     this.length = 0;
  172.     this._storage = [];
  173. }
  174.  
  175. Queue_LSize.prototype.itemByIdx = function(index)
  176. {
  177.     return this._storage[index];
  178. };
  179.  
  180. Queue_LSize.prototype.queue = function(data)
  181. {
  182.     this._storage[this.length] = data;
  183.     this.length++;
  184.     while (this.length > this._maxSize) { this.onAutoRemoval(this.dequeue()); }
  185. };
  186.  
  187. // For aliasing
  188. Queue_LSize.prototype.onAutoRemoval = function(removed_item) {};
  189.  
  190.  // Remove and return first item in array
  191. Queue_LSize.prototype.dequeue = function()
  192. {
  193.     if (this.length)
  194.     {
  195.         var deletedData = this._storage.shift();
  196.         this.length--;
  197.         return deletedData;
  198.     }
  199. };
  200. // Remove and return last item in array
  201. Queue_LSize.prototype.pop = function()
  202. {
  203.     if (this.length)
  204.     {
  205.         var deletedData = this._storage.pop();
  206.         this.length--;
  207.         return deletedData;
  208.     }
  209. };
  210.  
  211. function lpad(word, padStr, length)
  212. {
  213.     word = String(word);
  214.     while (word.length < length) word = padStr + word;
  215.     return word;
  216. }
  217.  
  218. function rpad(word, padStr, length)
  219. {
  220.     word = String(word);
  221.     while (word.length < length) word += padStr;
  222.     return word;
  223. }
  224. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  225. // #Parameters
  226. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  227. var Imported = Imported || {};
  228. Imported.Silv_ItemLog = 1.07;
  229.  
  230. var Silv = Silv || {};
  231. Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilverItemLog>'); })[0].parameters;
  232. Silv.ItemLog = Silv.ItemLog || {};
  233. Silv.ItemLog.Window = null;
  234. Silv.ItemLog.AlreadyPlayedSFX = false;
  235. // General
  236. Silv.ItemLog.AutoLootGain = Silv.Parameters['Auto Gain Loot'].toLowerCase() == 'true';
  237. Silv.ItemLog.AutoLogItems = Silv.Parameters['Auto Log Items'].toLowerCase() == 'true';
  238. Silv.ItemLog.PickupSFXItem = Silv.Parameters['Item SFX'];
  239. Silv.ItemLog.PickupSFXGold = Silv.Parameters['Gold SFX'];
  240. // Positioning & Size
  241. Silv.ItemLog.Window_X = parseInt(Silv.Parameters['Window X']);
  242. Silv.ItemLog.Window_Y = parseInt(Silv.Parameters['Window Y']);
  243. Silv.ItemLog.WindowWidth = parseInt(Silv.Parameters['Window Width']);
  244. Silv.ItemLog.WindowHeight = parseInt(Silv.Parameters['Window Height']);
  245. Silv.ItemLog.WindowHorizontalAlignment = Silv.Parameters['Window Horizontal Alignment'].toLowerCase();
  246. Silv.ItemLog.WindowVerticalAlignment = Silv.Parameters['Window Vertical Alignment'].toLowerCase();
  247. // Window Contents
  248. Silv.ItemLog.FontSize = parseInt(Silv.Parameters['Font Size']);
  249. Silv.ItemLog.EntryTextOffsetX = parseInt(Silv.Parameters['Text Offset X']);
  250. Silv.ItemLog.EntryTextOffsetY = parseInt(Silv.Parameters['Text Offset Y']);
  251. Silv.ItemLog.StandardPadding = parseInt(Silv.Parameters['Standard Padding']);
  252. Silv.ItemLog.TextLines = Silv.ItemLog.TextLines || 'Error: Not yet set';
  253.  
  254. Silv.ItemLog.PositivePrefixText = Silv.Parameters['Positive Prefix Text'];
  255. if (Silv.ItemLog.PositivePrefixText.slice(-1) != ' ') { Silv.ItemLog.PositivePrefixText += ' '; }
  256. Silv.ItemLog.NegativePrefixText = Silv.Parameters['Negative Prefix Text'];
  257. if (Silv.ItemLog.NegativePrefixText.slice(-1) != ' ') { Silv.ItemLog.NegativePrefixText += ' '; }
  258.  
  259. Silv.ItemLog.IconOffsetY = parseInt(Silv.Parameters['Icon Y-offset']);
  260. Silv.ItemLog.WindowSkin = Silv.Parameters['Window Skin'];
  261. Silv.ItemLog.AutoClearUponFullFade = Silv.Parameters['Auto-clear Upon Full-fade'].toLowerCase() == 'true';
  262.  
  263. // Miscellaneous
  264. Silv.ItemLog.FadeoutDelay = parseInt(Silv.Parameters['Fadeout Delay']);
  265. Silv.ItemLog.FadeoutSpeed = parseInt(Silv.Parameters['Fadeout Speed']);
  266. Silv.ItemLog.TextShadingValue = parseFloat(Silv.Parameters['Text Shading']);
  267. Silv.ItemLog.GoldIconIndex = parseInt(Silv.Parameters['Gold IconIndex']);
  268.  
  269. // Non Parameters
  270. Silv.ItemLog.PrefixLength = Math.max(Silv.ItemLog.PositivePrefixText.length, Silv.ItemLog.NegativePrefixText.length);
  271.  
  272. (function()
  273. {
  274. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  275. // Window
  276. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  277. function Window_ItemLog() { this.initialize.apply(this, arguments); }
  278. // Inherit from base window
  279. Window_ItemLog.prototype = Object.create(Window_Base.prototype);
  280. // Set Constructor
  281. Window_ItemLog.prototype.constructor = Window_ItemLog;
  282.  
  283. Window_ItemLog.prototype.loadWindowskin = function() { this.windowskin = ImageManager.loadSystem(Silv.ItemLog.WindowSkin); };
  284. Window_ItemLog.prototype.standardPadding = function() { return Silv.ItemLog.StandardPadding; };
  285. Window_ItemLog.prototype.standardFontSize = function() { return Silv.ItemLog.FontSize; };
  286.  
  287. Window_ItemLog.AutoLogItems = Silv.ItemLog.AutoLogItems;
  288.  
  289. // Initialization
  290. Window_ItemLog.prototype.initialize = function(x, y, width, height)
  291. {
  292.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  293.     this._helpWindow = null;
  294.     this._handlers = {};
  295.     this._touching = false;
  296.     this.deactivate();
  297.     this.maxStackLines = parseInt((height - Silv.ItemLog.EntryTextOffsetY * 2) / parseFloat(Silv.ItemLog.FontSize));
  298.     this.clearItems();
  299.     this.fadeOutCnt = 0;
  300.     this.isFadingOut = false;
  301.     this.isFadedOut = false;
  302.    
  303.     this.update();
  304. };
  305.  
  306. // Update
  307. Window_ItemLog.prototype.update = function()
  308. {
  309.     Window_Base.prototype.update.call(this);
  310.    
  311.     Silv.ItemLog.AlreadyPlayedSFX = false;
  312.     this.updateFadeOut();
  313.     this.drawItemLogContents();
  314. };
  315.  
  316. // Update Fading Out
  317. Window_ItemLog.prototype.updateFadeOut = function()
  318. {
  319.     if (this.isFadedOut) { return; }
  320.    
  321.     if (!this.isFadingOut)
  322.     {
  323.         this.fadeOutCnt++;
  324.         if (this.fadeOutCnt > Silv.ItemLog.FadeoutDelay)
  325.         {
  326.             this.fadeOutCnt = 0;
  327.             this.isFadingOut = true;
  328.         }
  329.     }
  330.     else
  331.     {
  332.         this.fadeOut();
  333.     }
  334. };
  335.  
  336. Window_ItemLog.prototype.clearItems = function()
  337. {
  338.     Silv.ItemLog.TextLines = new Queue_LSize(this.maxStackLines);
  339. };
  340.  
  341. Window_ItemLog.prototype.fadeOut = function()
  342. {
  343.     this.opacity = this.contentsOpacity -= Silv.ItemLog.FadeoutSpeed;
  344.     if (this.opacity <= 0) { this.onFullyFadedOut(); }
  345. };
  346.  
  347. Window_ItemLog.prototype.onFullyFadedOut = function()
  348. {
  349.     this.isFadedOut = true;
  350.     if (Silv.ItemLog.AutoClearUponFullFade) { this.clearItems(); }
  351. };
  352.  
  353. Window_ItemLog.prototype.resetFade = function()
  354. {
  355.     this.isFadingOut = false;
  356.     this.fadeOutCnt = 0;
  357.     this.opacity = this.contentsOpacity  = 255;
  358.     this.isFadedOut = false;
  359. };
  360.  
  361. Window_ItemLog.prototype.fadeOutInstantly = function()
  362. {
  363.     this.opacity = this.contentsOpacity = 0;
  364.     this.onFullyFadedOut();
  365. };
  366.  
  367. // #Drawing
  368. Window_ItemLog.prototype.drawItemLogContents = function()
  369. {
  370.     if (typeof Silv.ItemLog.TextLines === 'string') { return; }
  371.     this.contents.clear();
  372.     this.resetTextColor();
  373.    
  374.     var textLinesCnt = Silv.ItemLog.TextLines.length;
  375.     var text = null;
  376.     for (var i = textLinesCnt - 1; i >= 0; i--)
  377.     {
  378.         var line = Silv.ItemLog.TextLines.itemByIdx(i);
  379.         text = line.t1;
  380.         this.drawText(text, Silv.ItemLog.EntryTextOffsetX, Silv.ItemLog.EntryTextOffsetY + i * Silv.ItemLog.FontSize, 256, 'left');
  381.         var newOffsetX = Silv.ItemLog.EntryTextOffsetX + this.contents.measureTextWidth(line.t1);
  382.         this.drawLootIcon(line.iconIndex, newOffsetX, Silv.ItemLog.EntryTextOffsetY + i * Silv.ItemLog.FontSize + Silv.ItemLog.IconOffsetY);
  383.         newOffsetX += Silv.ItemLog.FontSize + 4;
  384.         text = line.t2;
  385.         this.drawText(text, newOffsetX, Silv.ItemLog.EntryTextOffsetY + i * Silv.ItemLog.FontSize, 256, 'left');
  386.        
  387.         this.contents.textColor = shadeColor(this.contents.textColor, Silv.ItemLog.TextShadingValue);
  388.     }
  389.    
  390.     function shadeColor(color, percent)
  391.     {  
  392.         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;
  393.         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);
  394.     }
  395. };
  396.  
  397. Window_ItemLog.prototype.drawLootIcon = function(iconIndex, x, y)
  398. {
  399.     var bitmap = ImageManager.loadSystem('IconSet');
  400.     var pw = Window_Base._iconWidth;
  401.     var ph = Window_Base._iconHeight;
  402.     var sx = iconIndex % 16 * pw;
  403.     var sy = Math.floor(iconIndex / 16) * ph;
  404.     this.contents.blt(bitmap, sx, sy, pw, ph, x, y, Silv.ItemLog.FontSize, Silv.ItemLog.FontSize);
  405. };
  406. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  407. // Create the ItemLog window
  408. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  409. var alias_silv_itemlog_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
  410. Scene_Map.prototype.createDisplayObjects = function()
  411. {
  412.     alias_silv_itemlog_createDisplayObjects.call(this);
  413.     this.createItemLogWindow();
  414. };
  415.  
  416. Scene_Map.prototype.createItemLogWindow = function()
  417. {
  418.     var x = 0;
  419.     if (Silv.ItemLog.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.ItemLog.WindowWidth; }
  420.     var y = 0;
  421.     if (Silv.ItemLog.WindowVerticalAlignment == 'bottom') { y = Graphics.height - Silv.ItemLog.WindowHeight; }
  422.    
  423.     if (Silv.ItemLog.Window !== null) { this.removeWindow(Silv.ItemLog.Window); }
  424.     Silv.ItemLog.Window = new Window_ItemLog(x + Silv.ItemLog.Window_X, y + Silv.ItemLog.Window_Y, Silv.ItemLog.WindowWidth, Silv.ItemLog.WindowHeight);
  425.     Silv.ItemLog.Window.fadeOutInstantly();
  426.     this.addChildAt(Silv.ItemLog.Window, 1);
  427. };
  428.  
  429. // Omg why does RPG Maker not have this method by default...
  430. Scene_Base.prototype.removeWindow = function(window)
  431. {
  432.     var index = this.children.indexOf(window);
  433.     if (index > -1) { this.children.splice(index, 1); }
  434. };
  435. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  436. // Saving & Loading
  437. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  438. /* Code below does not work for some reason. It does save the data but not load it properly.
  439. var alias_silv_ItemLog_makeSaveContents = DataManager.makeSaveContents;
  440. DataManager.makeSaveContents = function()
  441. {
  442.     contents = alias_silv_ItemLog_makeSaveContents.call(this);
  443.     contents.itemLogData = Silv.ItemLog.TextLines;
  444.     return contents;
  445. }
  446.  
  447. var alias_silv_ItemLog_extractSaveContents = DataManager.extractSaveContents;
  448. DataManager.extractSaveContents = function(contents)
  449. {
  450.     alias_silv_ItemLog_extractSaveContents.call(this, contents);
  451.     Silv = Silv || {};
  452.     Silv.ItemLog = Silv.ItemLog || {};
  453.     Silv.ItemLog.TextLines = contents.itemLogData;
  454. }
  455. */
  456. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  457. // Automatically add items
  458. //------------------------
  459. //
  460. // Explanation of the this._params:
  461. //
  462. // Gold
  463. // [0] = 0: increase, 1: decrease
  464. // [1] = 0: value, 1: $gameVariable was used to determine amount of gold
  465. // [2] = it is a direct amount of gold but if [1] == 1, then this is the gameVariable number that contains the gold-amount instead.
  466. //
  467. //
  468. // Items, Weapons & Armor
  469. // [0] = armor id matching the $dataArmors index
  470. // [1] = 0: increase, 1: decrease
  471. // [2] = 0: value, 1: $gameVariable was used to determine amount of armors
  472. // [3] = it is a direct amount of gold but if [2] == 1, then this is the gameVariable number that contains the gold-amount instead.
  473. // [4] = include equipment? true/false
  474. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  475. Silv.ItemLog.getAmount = function(params) // does not apply to gold! Gold has different parameters.. Yay for RPG Maker...
  476. {
  477.     return ((params[2] == 0) ? params[3] : $gameVariables.value(params[3])) * (params[1] == 1 ? -1 : 1);
  478. };
  479.  
  480. // Change Gold
  481. var alias_silv_command125 = Game_Interpreter.prototype.command125;
  482. Game_Interpreter.prototype.command125 = function()
  483. {
  484.     var amount = (this._params[1] == 0) ? this._params[2] : $gameVariables.value(this._params[2]);
  485.     if (this._params[0] == 1) { amount *= -1; }
  486.    
  487.     var retVal = alias_silv_command125.apply(this, arguments);
  488.     if (Window_ItemLog.AutoLogItems) { PluginCommand('ItemLog', ['gold', String(amount), 'skip']); }
  489.     return retVal;
  490. };
  491.  
  492. // Change Items
  493. var alias_silv_command126 = Game_Interpreter.prototype.command126;
  494. Game_Interpreter.prototype.command126 = function()
  495. {
  496.     var retVal = alias_silv_command126.apply(this, arguments);
  497.     if (Window_ItemLog.AutoLogItems) { PluginCommand('ItemLog', ['item', this._params[0], Silv.ItemLog.getAmount(this._params), 'skip']); }
  498.     return retVal;
  499. };
  500.  
  501. // Change Weapons
  502. var alias_silv_command127 = Game_Interpreter.prototype.command127;
  503. Game_Interpreter.prototype.command127 = function()
  504. {
  505.     var retVal = alias_silv_command127.apply(this, arguments);
  506.     if (Window_ItemLog.AutoLogItems) { PluginCommand('ItemLog', ['weapon', this._params[0], Silv.ItemLog.getAmount(this._params), 'skip']); }
  507.     return retVal;
  508. };
  509.  
  510. // Change Armors
  511. var alias_silv_command128 = Game_Interpreter.prototype.command128;
  512. Game_Interpreter.prototype.command128 = function()
  513. {
  514.     var retVal = alias_silv_command128.apply(this, arguments);
  515.     if (Window_ItemLog.AutoLogItems) { PluginCommand('ItemLog', ['armor', this._params[0], Silv.ItemLog.getAmount(this._params), 'skip']); }
  516.     return retVal;
  517. };
  518. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  519. // Plugin Command
  520. // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
  521. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  522. Silv.ItemLog.getPrefixText = function(amount)
  523. {
  524.     var prefixText = rpad((amount >= 0) ? Silv.ItemLog.PositivePrefixText : Silv.ItemLog.NegativePrefixText, ' ', Silv.ItemLog.PrefixLength);
  525.    
  526.     return prefixText;
  527. };
  528.  
  529. var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  530. Game_Interpreter.prototype.pluginCommand = function(command, args)
  531. {
  532.     _Game_Interpreter_pluginCommand.call(this, command, args);
  533.     if (command.toLowerCase() == 'itemlog') { PluginCommand(command, args); }
  534. };
  535.  
  536. function PluginCommand(cmd, args)
  537. {
  538.     switch(args[0].toLowerCase())
  539.     {
  540.         case 'show':
  541.             Silv.ItemLog.Window.resetFade();
  542.             return;
  543.         case 'clearitems':
  544.             Silv.ItemLog.Window.clearItems();
  545.             return;
  546.         case 'enablelogging':
  547.             Window_ItemLog.AutoLogItems = true;
  548.             return;
  549.         case 'disablelogging':
  550.             Window_ItemLog.AutoLogItems = false;
  551.             return;
  552.     }  
  553.    
  554.     // arg: item 1 10
  555.     // arg: weapon 2 1
  556.     // arg: weapon 2 1 skip
  557.     // arg: gold 123
  558.     var db = getDatabase(args[0]);
  559.     var lootIdx = parseInt(args[1]);
  560.     var skipAddItemToInventory = (String(args[args.length - 1]).toLowerCase() == 'skip');
  561.     if (db != 'gold')
  562.     {
  563.         var amount = parseInt(args[2]);
  564.         var amountStr = String(args[2]);
  565.         var name = db[lootIdx].name;
  566.         var iconIndex = db[lootIdx].iconIndex;
  567.        
  568.         var t1 = Silv.ItemLog.getPrefixText(amount) + lpad(Math.abs(amountStr), ' ', 2) + 'x ';
  569.         var t2 = name;             
  570.        
  571.         Silv.ItemLog.TextLines.queue({t1: t1, iconIndex: iconIndex, t2: t2});
  572.        
  573.         // Add loot
  574.         if (Silv.ItemLog.AutoLootGain && !skipAddItemToInventory)
  575.         {
  576.             $gameParty.gainItem(db[lootIdx], amount);
  577.         }
  578.        
  579.         // sfx
  580.         if (!Silv.ItemLog.AlreadyPlayedSFX)
  581.         {
  582.             Play_SE(Silv.ItemLog.PickupSFXItem);
  583.             Silv.ItemLog.AlreadyPlayedSFX = true;
  584.         }
  585.     }
  586.     else // Gold
  587.     {
  588.         var amount = parseInt(args[1]);
  589.         Silv.ItemLog.TextLines.queue({t1: Silv.ItemLog.getPrefixText(amount) + '    ', iconIndex: Silv.ItemLog.GoldIconIndex, t2: Math.abs(amount) + ' ' + $dataSystem.currencyUnit});
  590.        
  591.         // Add loot
  592.         if (Silv.ItemLog.AutoLootGain && !skipAddItemToInventory)
  593.         {
  594.             $gameParty.gainGold(amount);
  595.         }
  596.        
  597.         // sfx
  598.         if (!Silv.ItemLog.AlreadyPlayedSFX)
  599.         {
  600.             Play_SE(Silv.ItemLog.PickupSFXGold);
  601.             Silv.ItemLog.AlreadyPlayedSFX = true;
  602.         }
  603.     }
  604.     Silv.ItemLog.Window.resetFade(); // Reset the fadeout, if any.
  605.    
  606.     function getDatabase(code)
  607.     {
  608.         code = code.toLowerCase();
  609.         if (code.contains('item') || code.contains('itm'))
  610.             return $dataItems;
  611.         if (code.contains('armor'))
  612.             return $dataArmors;
  613.         if (code.contains('weapon') || code.contains('wpn'))
  614.             return $dataWeapons;
  615.         if (code.contains('gold'))
  616.             return 'gold';
  617.        
  618.         throw('getDatabase('+ code + ') ERROR: invalid code.');
  619.     }
  620.    
  621.     function Play_SE(filename)
  622.     {
  623.         AudioManager.playSe({name: filename, volume: 90, pitch: 100, pan: 0});
  624.     }
  625. }
  626. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  627. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement