SHARE
TWEET

Untitled

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