Guest User

Untitled

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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×