Guest User

Magic Shards Modified

a guest
Dec 12th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //-----------------------------------------------------------------------------
  2. //  Galv's Magic Shards - Opacity Window Modified by Rito
  3. //-----------------------------------------------------------------------------
  4. //  For: RPGMAKER MV
  5. //  GALV_MagicShards.js
  6. //-----------------------------------------------------------------------------
  7. // 2015-11-30 - Version 1.7 - fixed crash issue in some browsers
  8. // 2015-11-22 - Version 1.6 - fixed a crash when levelling
  9. // 2015-11-19 - Version 1.5 - added ability to disable/enable menu command
  10. // 2015-11-19 - Version 1.4 - added plugin command to change shards on actors
  11. // 2015-11-18 - Version 1.3 - added ability to lock shard slots through
  12. //                          - plugin commands and cursed shards
  13. // 2015-11-18 - Version 1.2 - fixed a display bug made from last patch
  14. //                          - added compatibility with yanfly passive states
  15. // 2015-11-18 - Version 1.1 - fixed a bug with showing more than 12 shards
  16. // 2015-11-18 - Version 1.0 - release
  17. //-----------------------------------------------------------------------------
  18. // Terms can be found at:
  19. // galvs-scripts.com
  20. //-----------------------------------------------------------------------------
  21.  
  22. var Imported = Imported || {};
  23. Imported.Galv_MagicShards = true;
  24.  
  25. var Galv = Galv || {};          // Galv's main object
  26. Galv.pCmd = Galv.pCmd || {};    // Plugin Command manager
  27. Galv.MS = Galv.MS || {};        // Galv's stuff
  28.  
  29. // Galv Notetag setup (Add notes required for this plugin if not already added)
  30. Galv.setupNotes = Galv.setupNotes || function() {};       // Alias this function for note setup
  31.  
  32.  
  33. //-----------------------------------------------------------------------------
  34. /*:
  35.  * @plugindesc A scene to equip actors with "Shards" to grant skills and parameter bonuses
  36.  *
  37.  * @author Galv - galvs-scripts.com / Rito (Opacity Windows)
  38.  *
  39.  * @param Appear in Menu
  40.  * @desc Can be true or false if you want this plugin to add the Menu Command to the main menu or not
  41.  * @default true
  42.  *
  43.  *
  44.  * @param Show as Icons
  45.  * @desc Can be true or false. true will display shard items in the scene as icons without name. False will display as normal.
  46.  * @default true
  47.  *
  48.  * @param Inventory Category
  49.  * @desc item, weapon, armor, keyItem, none - To display in inventroy category. Make sure to use correct capitalization here.
  50.  * @default item
  51.  *
  52.  * @param Max Shard Slots
  53.  * @desc The maximum amount of shards slots an actor can ever have.
  54.  * @default 11
  55.  *
  56.  * @param Cursed Shards
  57.  * @desc List of SHARD ID's (not weapon or armor ids) separated by commas. Cursed shards lock the slot they are equipped to.
  58.  * @default 666,13,1337
  59.  *
  60.  * @param ----- VOCAB -----
  61.  * @desc
  62.  * @default
  63.  *
  64.  * @param Menu Command
  65.  * @desc Text for the Magic Shard's main menu command
  66.  * @default Orb Shard
  67.  *
  68.  * @param Equip
  69.  * @desc Text for "Equip" menu command
  70.  * @default Equip
  71.  *
  72.  * @param Remove
  73.  * @desc Text for "Remove" menu command
  74.  * @default Remove
  75.  *
  76.  * @param Gained
  77.  * @desc Text before skills that are added when equipping shards
  78.  * @default Gained:
  79.  *
  80.  * @param Lost
  81.  * @desc Text before skills that are lost when equipping shards
  82.  * @default Lost:
  83.  *
  84.  * @param Empty
  85.  * @desc Text displayed in an empty shard slot (displayed in non-graphics mode)
  86.  * @default >>>
  87.  *
  88.  * @param ----- SOUND -----
  89.  * @desc
  90.  * @default
  91.  *
  92.  * @param Gain Skill SE
  93.  * @desc Sound effect that plays when gaining a skill.
  94.  * FileName,volume,pitch.
  95.  * @default Flash1,80,110
  96.  *
  97.  * @param Lose Skill SE
  98.  * @desc Sound effect that plays when losing a skill.
  99.  * FileName,volume,pitch.
  100.  * @default Down2,70,150
  101.  *
  102.  * @param ----- IMAGES -----
  103.  * @desc
  104.  * @default
  105.  *
  106.  * @param Background Image
  107.  * @desc true or false. Display /system/shardBg.png as scene background if true, false shows as normal.
  108.  * @default true
  109.  *
  110.  * @param Graphics
  111.  * @desc Can be true or false. true uses specific graphics from /img/system/ (see HELP for details).
  112.  * @default true
  113.  *
  114.  * @param Orb Dimensions
  115.  * @desc The width and height of the magic orb graphic (pixels), separated by a comma.
  116.  * @default 336,336
  117.  *
  118.  * @param Orb XY
  119.  * @desc The x,y offset for the orb graphics separated by a comma.
  120.  * @default 0,0
  121.  *
  122.  * @param ----- OTHER -----
  123.  * @desc
  124.  * @default
  125.  *
  126.  * @param Use Links
  127.  * @desc Can be true or false if you want to use the Shards.txt file for link skills
  128.  * @default true
  129.  *
  130.  * @param Folder
  131.  * @desc The folder name in your project that contains Shards.txt file for link skills.
  132.  * @default data
  133.  *
  134.  *
  135.  *
  136.  *
  137.  * @param
  138.  * @param Status Opacity
  139.  * @desc Default : 255
  140.  * @default 255
  141.  * @param Command Opacity
  142.  * @desc Default : 255
  143.  * @default 255
  144.  * @param Slot Opacity
  145.  * @desc Default : 255
  146.  * @default 255
  147.  * @param Name Opacity
  148.  * @desc Default : 255
  149.  * @default 255
  150.  * @param Info Opacity
  151.  * @desc Default : 255
  152.  * @default 255
  153.  * @param Item Opacity
  154.  * @desc Default : 255
  155.  * @default 255
  156.  * @help
  157.  *   Galv's Magic Shards
  158.  * ----------------------------------------------------------------------------
  159.  * This plugin creates a new way for players to customize their characters.
  160.  * It adds a "Magic Orb" to characters, which can have a number of "Shards"
  161.  * equipped to the orb. During the game these characters can improve the
  162.  * number of shards they are capable of equipping by adding "Shard Slots".
  163.  *
  164.  * Weapons and armors can be changed into shards (so they are no longer equips)
  165.  * using the note tag found further below. All functions of the weapon/armor
  166.  * will work for the shards including features, stats and equip restrictions.
  167.  * This means you will need to set the actor up to be allowed to equip the
  168.  * weapon/armor shard (using features) to be able to equip them in the scene.
  169.  *
  170.  * ----------------------------------------------------------------------------
  171.  *   Note Tag for WEAPONS or ARMORS:
  172.  * ----------------------------------------------------------------------------
  173.  *
  174.  *    <shard: n>       // This classifies a weapon/armor to be a shard
  175.  *                     // Shards will display in the "Inventory Category" as
  176.  *                     // well as the Magic Shard scene.
  177.  *                     // The n is the shard ID, which is used in the external
  178.  *                     // data/shards.txt file to determine skills gained by
  179.  *                     // adjacent shards.
  180.  *
  181.  * ----------------------------------------------------------------------------
  182.  *   Note Tag for ACTORS:
  183.  * ----------------------------------------------------------------------------
  184.  *
  185.  *    <shardimg: X>     // image number for the actor's Shard Orb graphic.
  186.  *                      // Taken from /img/system/ShardOrbX.png. If this tag is
  187.  *                      // not included, actor will use ShardOrb0.png
  188.  *
  189.  * ----------------------------------------------------------------------------
  190.  *   Note Tag for CLASS SKILLS TO LEARN:
  191.  * ----------------------------------------------------------------------------
  192.  * This note tag is to be used in the "Skills To Learn" section of the "Class"
  193.  * tab. It is used to increase an actor's shard slots when the actor levels.
  194.  *
  195.  *     <shard: x>          // x is the amount of slots added to actor
  196.  *
  197.  * NOTE: This increase happens whenever this class learns the skill at the
  198.  * specified level and it is permanent. If the actor levels down and levels up
  199.  * again, it will increase again. So use only if not doing that stuff.
  200.  * This cannot increase shard slots more than "Max Shards" setting.
  201.  *
  202.  * ----------------------------------------------------------------------------
  203.  *   PLUGIN COMMANDS
  204.  * ----------------------------------------------------------------------------
  205.  *
  206.  *   MSHARDS SLOTS ACTORID MOD    // Changes actor's max shards.
  207.  *                                // MSHARDS - the plugin command word
  208.  *                                // SLOTS - command word to change max slots
  209.  *                                // ACTORID - the id of the actor changing
  210.  *                                //           use negative for a party member
  211.  *                                //           v# to use a variable
  212.  *                                // MOD - positive/negative number to change
  213.  *                                //       the amount of slots an actor has.
  214.  *                                //       v# to use a variable
  215.  *
  216.  *   MSHARDS IMG ACTORID X        // Changes actor's shard orb image.
  217.  *                                // MSHARDS - the plugin command word
  218.  *                                // IMG - command word to change orb img
  219.  *                                // ACTORID - the id of the actor changing
  220.  *                                //           use negative for a party member
  221.  *                                //           v# to use a variable
  222.  *                                // X - the number of the orb image taken
  223.  *                                //     from /img/system/ShardOrbX.png.
  224.  *                                //     v# to use a variable
  225.  *
  226.  *   MSHARDS SCENE ACTORID        // Opens the shard scene for actor.
  227.  *                                // MSHARDS - the plugin command word
  228.  *                                // SCENE - command word to start scene
  229.  *                                // ACTORID - the id of the actor changing
  230.  *                                //           use negative for a party member
  231.  *                                //           v# to use a variable
  232.  *
  233.  *   MSHARDS LOCK ACTORID X       // Prevents actor from changing shards.
  234.  *                                // MSHARDS - the plugin command word
  235.  *                                // LOCK - command word for locking
  236.  *                                // ACTORID - the id of the actor changing
  237.  *                                //           use negative for a party member
  238.  *                                //           v# to use a variable
  239.  *                                // X - the slot position to be locked. Dont
  240.  *                                //     include this if you want to lock all
  241.  *                                //     v# to use a variable
  242.  *
  243.  *   MSHARDS UNLOCK ACTORID X     // Unlocks actors shard slots
  244.  *                                // Same as above but unlock instead of lock
  245.  *
  246.  *   MSHARDS CHANGE ACTORID X S   // Change an actor's shard in a certain slot
  247.  *                                // MSHARDS - the plugin command word
  248.  *                                // CHANGE - command word for changing shards
  249.  *                                // ACTORID - the id of the actor changing
  250.  *                                //           use negative for a party member
  251.  *                                //           v# to use a variable
  252.  *                                // X - the slot position to change.
  253.  *                                //     v# to use a variable
  254.  *                                // S - the shard equip item - letterNumber
  255.  *                                //     eg. w10 for weapon 10
  256.  *                                //         a4 for armor 4
  257.  *                                //         none to remove the shard
  258.  *
  259.  *   MSHARDS MENU STATUS          // Change the status of the menu command.
  260.  *                                // MSHARDS - the plugin command word
  261.  *                                // MENU - command word for changing shards
  262.  *                                // STATUS - can be one of the following:
  263.  *                                //          enabled
  264.  *                                //          disabled
  265.  *                                //          hidden
  266.  *
  267.  * Examples:
  268.  * MSHARDS SLOTS 2 3       // Adds 3 slots to actor 2 limited to "Max Shards"
  269.  * MSHARDS SLOTS -2 1      // Adds 1 slot to party member 2
  270.  * MSHARDS SCENE 4         // Opens the shard scene for actor 4
  271.  * MSHARDS SCENE -1        // Opens the shard scene for party member 1 (leader)
  272.  * MSHARDS IMG 1 4         // Changes actor 1's shard image to MagicOrb4.png
  273.  * MSHARDS LOCK 5 1        // Lock the first shard slot for actor 5
  274.  * MSHARDS UNLOCK 7        // Unlock all slots for actor 7
  275.  * MSHARDS CHANGE 2 1 w2   // Changes slot 1 on actor 2 to weapon 10
  276.  * MSHARDS CHANGE -1 2 none  // Changes slot 2 on party member 1 to empty
  277.  * MSHARDS MENU disabled     // Make menu command unable to be accessed
  278.  * MSHARDS MENU hidden       // Don't show menu command
  279.  * MSHARDS MENU enabled      // Menu command is active and normal
  280.  *
  281.  * ----------------------------------------------------------------------------
  282.  *  LOCKED SHARD SLOTS & CURSED SHARDS
  283.  * ----------------------------------------------------------------------------
  284.  * With the above plugin commands, it is possible to lock and unlock actor's
  285.  * shard slots during the game. The settings also include a "Cursed Shards"
  286.  * section, which you can list all SHARD ID's (NOT weapon id or armor id) that
  287.  * you would like to be cursed.
  288.  *
  289.  * A cursed shard, when equipped, will lock the slot it was equipped to. The
  290.  * only way to "uncurse" is to use the plugin commands above to unlock that
  291.  * slot. Note that when the slot is unlocked, the cursed shard remains
  292.  * equipped, but if you unequip it and then equip it again - the curse will
  293.  * activate once more.
  294.  *
  295.  * ----------------------------------------------------------------------------
  296.  *  Acquiring Skills through Shard Links
  297.  * ----------------------------------------------------------------------------
  298.  * If the setting "Use Links" is true, you can set up "Shard Links" in the
  299.  * "Shards.txt" file (See below for required details for this file).
  300.  *
  301.  * A shard link means if you have 2 shards equipped in slots that are next to
  302.  * each other (adjacent), they are considered linked. The text file contains a
  303.  * list of possible combinations of SHARD ID's (the number specified in the
  304.  * notetag you added to the weapon or armor).
  305.  *
  306.  * The Shards.txt file allows you to add as many combinations as you require
  307.  * and each combination must be on a separate line in the txt file. Eg:
  308.  *
  309.  *    1,2,8    # example
  310.  *    5,3,34   # example
  311.  *    1,3,9    # Learn Fire
  312.  *
  313.  * The data above has 3 numbers per line separated by commas:
  314.  * Shard Id, Shard Id, Skill Id      # Notes to keep track
  315.  * The example: 1,3,9
  316.  * Means if a shard with Shard Id of 1, and a shard with Shard Id of 3 are
  317.  * equipped adjacent to each other - they are "linked" and the actor will
  318.  * learn skill 9.
  319.  *
  320.  * ----------------------------------------------------------------------------
  321.  *  REQUIRED FILE INFORMATION                                     ! IMPORTANT
  322.  * ----------------------------------------------------------------------------
  323.  * If the setting "Use Links" is set to true, the plugin requires you to have
  324.  * a file in your project in the folder you specified in the "Folder" setting.
  325.  * This is the "data" folder by default. The required file must be named:
  326.  *
  327.  *   Shards.txt
  328.  *
  329.  * For example, this file by default is set to be:
  330.  * YourProject/data/Shards.txt
  331.  *
  332.  * When the "Graphics" setting is set to true, the plugin uses the graphical
  333.  * version which requires you to have certain graphics in /img/system/ folder.
  334.  * Below is details about those graphics:
  335.  *
  336.  *   MagicOrb0.png     - The Magic Orb image.
  337.  *                     - 336 x 336 pixels (Must be same width and height)
  338.  *                     - Make sure "Orb Dimensions" setting is this size
  339.  *                     - can add additional MagicOrb images with diff number
  340.  *
  341.  *   MagicOrbSlot.png  - The image for "slots" around the Magic Orb.
  342.  *
  343.  *   MagicOrbSlotLink.png  - The image that appears above the slot on shards
  344.  *                         - that have a link in the "Shards.txt" file.
  345.  *
  346.  *   shardBg.png       - Optional. Used if "Background Image" setting is true.
  347.  *
  348.  */
  349.  
  350.  
  351. //-----------------------------------------------------------------------------
  352. //  CODE STUFFS
  353. //-----------------------------------------------------------------------------
  354.  
  355.  
  356. (function() {
  357.    
  358.     // GALV'S PLUGIN MANAGEMENT. INCLUDED IN ALL GALV PLUGINS THAT HAVE PLUGIN COMMAND CALLS, BUT ONLY RUN ONCE.
  359.     if (!Galv.aliased) {
  360.         var Galv_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  361.         Game_Interpreter.prototype.pluginCommand = function(command, args) {
  362.             if (Galv.pCmd[command]) {
  363.                 Galv.pCmd[command](args);
  364.                 return;
  365.             };
  366.             Galv_Game_Interpreter_pluginCommand.call(this, command, args);
  367.         };
  368.         Galv.aliased = true; // Don't keep aliasing for other Galv scripts.
  369.     };
  370.    
  371.     // Direct to Plugin Object
  372.     Galv.pCmd.MSHARDS = function(arguments) {Galv.MS.plugin(arguments)};
  373.     // END GALV'S PLUGIN MANAGEMENT
  374.    
  375.    
  376.     Galv.MS.plugin = function(arr) {
  377.         if (arr[0] === "MENU") {
  378.             $gameSystem.shardMenu = arr[1].toLowerCase();
  379.             return;
  380.         };
  381.        
  382.        
  383.         var actorId = null;
  384.         // Get correct actor ID
  385.         actorId = Galv.MS.getActorId(arr[1]);
  386.         if (!actorId) return;
  387.  
  388.         // Do plugin stuff     
  389.         switch (arr[0]) {
  390.             case "LOCK":
  391.             case "UNLOCK":
  392.                 // Lock or unlock shards for ("lock"/"unlock",id,shard slot (1 is first))
  393.                 var slot = arr[2] ? Galv.MS.getValue(arr[2]) : null;
  394.                 Galv.MS.setLock(arr[0].toLowerCase(),actorId,slot)
  395.                 break;
  396.             case "SCENE":
  397.                 // Run scene for certain actor
  398.                 Galv.MS.run(actorId)
  399.                 break;
  400.             case "SLOTS":
  401.                 // Change actor's max slots
  402.                 Galv.MS.changeShardSlots(actorId,Galv.MS.getValue(arr[2]));
  403.                 break;
  404.             case "CHANGE":
  405.                 // Change actor's equipped shard in certain slot
  406.                 var slot = Galv.MS.getValue(arr[2]);
  407.                 console.log(slot);
  408.                 if (slot > $gameActors.actor(actorId)._shardSlots) return;  // dont equip if dont have that slot open
  409.                 var itemTag = arr[3] ? arr[3].toLowerCase() : "none";
  410.                 if (itemTag[0] === "w") {
  411.                     var shard = $dataWeapons[Number(itemTag.replace("w",""))];
  412.                 } else if (itemTag[0] === "a") {
  413.                     var shard = $dataArmors[Number(itemTag.replace("a",""))];
  414.                 } else {
  415.                     var shard = null;
  416.                 };
  417.  
  418.                 $gameActors.actor(actorId).changeShard(slot - 1, shard, true)
  419.                 break;
  420.             case "IMG":
  421.                 // Change actor's orb image
  422.                 $gameActors.actor(actorId)._shardImg = Galv.MS.getValue(arr[2]);
  423.                 break;
  424.         };
  425.     };
  426.        
  427.     Galv.MS.getValue = function(string) {
  428.         if (string[0].toLowerCase() === "v") {
  429.             // Use variable
  430.             var varId = Number(string.replace("v",""));
  431.             return $gameVariables.value(varId);
  432.         } else {
  433.             return Number(string);
  434.         };
  435.     };
  436.    
  437.     Galv.MS.getActorId = function(string) {
  438.         if (string[0].toLowerCase() === "v") {
  439.             // Use variable
  440.             var varId = Number(string.replace("v",""));
  441.             return Math.abs($gameVariables.value(varId));
  442.         } else if (Number(string) > 0) {
  443.             // Use actor ID
  444.             return Number(string);
  445.         } else if (Number(string) <= 0) {
  446.             var pId = Math.abs(Number(string));
  447.             pId = pId == 0 ? 0 : pId - 1;  // if 0, leader. If 1 leader, 2 for 2nd, etc.
  448.             if (!$gameParty.members()[pId]) return null;
  449.             return $gameParty.members()[pId].actorId();
  450.         };
  451.     };
  452.    
  453.     Galv.MS.graphics = PluginManager.parameters('Galv_MagicShards')["Graphics"] === "true" ? true : false;
  454.     Galv.MS.mActive = PluginManager.parameters('Galv_MagicShards')["Appear in Menu"] === "true" ? true : false;
  455.     Galv.MS.asIcons = PluginManager.parameters('Galv_MagicShards')["Show as Icons"] === "true" ? true : false;
  456.     Galv.MS.iCat = PluginManager.parameters('Galv_MagicShards')["Inventory Category"];
  457.     Galv.MS.maxAllowed = Number(PluginManager.parameters('Galv_MagicShards')["Max Shard Slots"]);
  458.     Galv.MS.mCommand = PluginManager.parameters('Galv_MagicShards')["Menu Command"];
  459.     Galv.MS.equip = PluginManager.parameters('Galv_MagicShards')["Equip"];
  460.     Galv.MS.remove = PluginManager.parameters('Galv_MagicShards')["Remove"];
  461.     Galv.MS.empty = PluginManager.parameters('Galv_MagicShards')["Empty"];
  462.     Galv.MS.gained = PluginManager.parameters('Galv_MagicShards')["Gained"];
  463.     Galv.MS.lost = PluginManager.parameters('Galv_MagicShards')["Lost"];
  464.     Galv.MS.bg = PluginManager.parameters('Galv_MagicShards')["Background Image"] === "true" ? true : false;
  465.     Galv.MS.xy = function() {
  466.         var a = PluginManager.parameters('Galv_MagicShards')["Orb XY"].split(",");
  467.         return [Number(a[0]),Number(a[1])];
  468.     }();
  469.    
  470.     Galv.MS.wh = function() {
  471.         var a = PluginManager.parameters('Galv_MagicShards')["Orb Dimensions"].split(",");
  472.         return [Number(a[0]),Number(a[1])];
  473.     }();
  474.    
  475.     Galv.MS.cursedShards = function() {
  476.         var a = PluginManager.parameters('Galv_MagicShards')["Cursed Shards"].split(",");
  477.         for (i = 0; i < a.length;i++) {
  478.             a[i] = Number(a[i]);
  479.         };
  480.         return a;
  481.     }();
  482.    
  483.    
  484.     Galv.MS.run = function(actorId) {
  485.         if (actorId) {
  486.             $gameParty.setMenuActor($gameActors.actor(actorId));
  487.         } else {
  488.             $gameParty.setMenuActor($gameParty.leader());
  489.         };
  490.         SceneManager.push(Scene_MShards);
  491.     };
  492.  
  493.  
  494.     Galv.MS.makeSound = function(txt) {
  495.         if (Array.isArray(txt)) {
  496.             var arr = txt;
  497.         } else {
  498.             var arr = txt.split(",");
  499.         };
  500.         var obj = {
  501.             name: arr[0],
  502.             pan: 0,
  503.             pitch: Number(arr[2]),
  504.             volume: Number(arr[1])
  505.         };
  506.         return obj;
  507.     };
  508.    
  509.     Galv.MS.GainSe = Galv.MS.makeSound(PluginManager.parameters('Galv_MagicShards')["Gain Skill SE"]);
  510.     Galv.MS.LoseSe = Galv.MS.makeSound(PluginManager.parameters('Galv_MagicShards')["Lose Skill SE"]);
  511.  
  512.     Galv.MS.createShards = function(string) {
  513.         if (Galv.MS.shardMixes) return;
  514.         Galv.MS.shardMixes = {};
  515.         var lines = string.split("\n");
  516.         for (var i = 0; i < lines.length; i++) {
  517.             var lineArr = lines[i].split(/(?:,| )+/);
  518.    
  519.             if (!isNaN(lineArr[0])) {
  520.                 Galv.MS.shardMixes[[Number(lineArr[0]),Number(lineArr[1])]] = Number(lineArr[2]);
  521.             };
  522.         };
  523.     };
  524.    
  525.     Galv.MS.changeShardSlots = function(id,amount) {
  526.         if (!$gameActors.actor(id)) return;
  527.         var actor = $gameActors.actor(id);
  528.         if (amount > 0 ) {
  529.             // Adding Shard Slot
  530.             var m = Galv.MS.maxAllowed - actor._shardSlots;
  531.             var amount = amount > m ? m : amount;
  532.             actor._shardSlots += amount;
  533.         } else if (amount < 0) {
  534.             // Removing Shard Slot
  535.             var amount = (actor._shardSlots - Math.abs(amount)) < 0 ? 0 : Math.abs(amount);
  536.             // Add shards to inventory from slots that are removed
  537.             for (var i = 0; i < amount; i++) {
  538.                 var slot = actor._shardSlots - i - 1;
  539.                 actor.changeShard(slot, null);
  540.             };
  541.             actor._shardSlots -= amount;
  542.         };
  543.     };
  544.  
  545.  
  546.     Galv.MS.setLock = function(type,id,slot) {
  547.         if (!$gameActors.actor(id)) return;
  548.         var actor = $gameActors.actor(id);
  549.         var slots = [];
  550.        
  551.         if (!slot) {
  552.             // Get all slots
  553.             for (var i = 0; i < Galv.MS.maxAllowed;i++) {
  554.                 slots.push(i);
  555.             };
  556.         } else {
  557.             slots.push(slot - 1);
  558.         };
  559.        
  560.         if (type == "lock") {
  561.             // Lock all slots in chosen slot list
  562.             for (var i = 0;i < slots.length;i++) {
  563.                 if (!actor._shardLocks.contains(slots[i])) actor._shardLocks.push(slots[i]);
  564.             };
  565.         } else {
  566.             // Unlock all slots in chosen slot list
  567.             for (var i = 0;i < slots.length;i++) {
  568.                 var elementIndex = actor._shardLocks.indexOf(slots[i]);
  569.                 if (elementIndex >= 0) {
  570.                     // If the slot number to remove is in the list - nuke it
  571.                     actor._shardLocks.splice(elementIndex, 1);
  572.                 };
  573.             };
  574.         };
  575.     };
  576.  
  577.  
  578.  
  579. //-----------------------------------------------------------------------------
  580. //  NOTE TAGS
  581. //-----------------------------------------------------------------------------
  582.  
  583. if (!Galv.notesLoaded) {   // Add alias only if not added by another Galv plugin
  584.     var Galv_Scene_Boot_start = Scene_Boot.prototype.start;
  585.     Scene_Boot.prototype.start = function() {
  586.         Galv.notesLoaded = true;
  587.         Galv.setupNotes();
  588.         Galv_Scene_Boot_start.call(this);
  589.     };
  590. };
  591.  
  592. var Galv_ShardNotes_SetupNotes = Galv.setupNotes;
  593. Galv.setupNotes = function() {
  594.     // Weapon Notes
  595.     for (var i = 1;i < $dataWeapons.length;i++) {
  596.         var note = $dataWeapons[i].note.toLowerCase().match(/<shard:(.*)>/i)
  597.         $dataWeapons[i].isShard = note ? Number(note[1]) : 0;
  598.     };
  599.     // Armor Notes
  600.     for (var i = 1;i < $dataArmors.length;i++) {
  601.         var note = $dataArmors[i].note.toLowerCase().match(/<shard:(.*)>/i)
  602.         $dataArmors[i].isShard = note ? Number(note[1]) : 0;
  603.     };
  604.  
  605.     Galv_ShardNotes_SetupNotes.call(this);
  606. };
  607.  
  608. DataManager.isShard = function(item) {
  609.     if (!item) return false;
  610.     if ($dataWeapons.contains(item) || $dataArmors.contains(item)) {
  611.         return item.isShard;
  612.     };
  613. };
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620. var Galv_Game_System_initialize = Game_System.prototype.initialize;
  621. Game_System.prototype.initialize = function() {
  622.     Galv_Game_System_initialize.call(this);
  623.     this.shardMenu = "enabled";
  624. };
  625.  
  626.  
  627.  
  628.  
  629. // Display shards in chosen inventory category only
  630. var Galv_Window_ItemList_includes = Window_ItemList.prototype.includes;
  631. Window_ItemList.prototype.includes = function(item) {
  632.     if (DataManager.isShard(item)) {
  633.         return this._category === Galv.MS.iCat;
  634.     } else {
  635.         return Galv_Window_ItemList_includes.call(this, item);
  636.     };
  637. };
  638.  
  639. // Cache window items
  640. var Galv_Scene_Boot_loadSystemImages = Scene_Boot.prototype.loadSystemImages;
  641. Scene_Boot.prototype.loadSystemImages = function() {
  642.      Galv_Scene_Boot_loadSystemImages.call(this);
  643.      ImageManager.loadSystem('MagicOrbSlot');
  644.      ImageManager.loadSystem('MagicOrbSlotLink');
  645. };
  646.  
  647.  
  648. //-----------------------------------------------------------------------------
  649. //  GAME_ACTOR
  650. //-----------------------------------------------------------------------------
  651.  
  652.  
  653. var Galv_Game_Actor_setup = Game_Actor.prototype.setup;
  654. Game_Actor.prototype.setup = function(actorId) {
  655.     Galv_Game_Actor_setup.call(this,actorId);
  656.     this.initShards();
  657. };
  658.  
  659. Game_Actor.prototype.initShards = function() {
  660.     this._shardSlots = 0;    // Current shard slots actor has unlocked
  661.     this._shards = {};       // Crate equipped shard object
  662.     this._shardLocks = [];    // array of shard slot ID's (1 being first, 2 being second etc)
  663.     var img = $dataActors[this._actorId].note.toLowerCase().match(/<shardimg:(.*)>/i)  // Shard Image ID
  664.     this._shardImg = img ? Number(img[1]) : 0;
  665. };
  666.  
  667. Game_Actor.prototype.isShardChangeOk = function(slotId) {
  668.     return !this._shardLocks.contains(slotId); //|| (this._shardSlots[slotId] && this._shardSlots[slotId].object().shardLocked);
  669. };
  670.  
  671. Game_Actor.prototype.changeShard = function(slotId, item, temp) {
  672.     var newItem = item;
  673.     var oldItem = (this._shards[slotId] && this._shards[slotId].object()) ? this._shards[slotId].object() : null;
  674.    
  675.     // Add old item to inventory
  676.     if (oldItem && !temp) $gameParty.gainItem(oldItem,1);
  677.    
  678.     // Add new item to slot
  679.     if (newItem) {
  680.         this._shards[slotId] = new Game_Item();              // Make item space
  681.         this._shards[slotId].setObject(newItem);             // If item, set it to actor
  682.         if (!temp) $gameParty.loseItem(newItem,1);           // Remove from inventory
  683.         // if item is cursed
  684.         if (Galv.MS.cursedShards.contains(newItem.isShard)) Galv.MS.setLock("lock",this.actorId(),slotId + 1)
  685.     } else {
  686.         this._shards[slotId] = null;
  687.         delete(this._shards[slotId]);              // If no new item, remove shard from actor
  688.     };
  689.        
  690.     this.refresh();
  691. };
  692.  
  693.  
  694. var Galv_Game_Actor_levelUp = Game_Actor.prototype.levelUp;
  695. Game_Actor.prototype.levelUp = function() {
  696.     Galv_Game_Actor_levelUp.call(this);
  697.     this.currentClass().learnings.forEach(function(learning) {
  698.         if (learning.level === this._level) {
  699.             console.log(learning);
  700.             var shardSlots = learning.note.toLowerCase().match(/<shard:(.*)>/i);
  701.             if (shardSlots) Galv.MS.changeShardSlots(this.actorId(),Number(shardSlots[1]));
  702.         }
  703.     }, this);
  704. };
  705.  
  706.  
  707. // Make equipping shards the same as default equipping items.
  708. var Galv_Game_BattlerBase_canEquip = Game_BattlerBase.prototype.canEquip;
  709. Game_BattlerBase.prototype.canShardEquip = function(item) {
  710.     return Galv_Game_BattlerBase_canEquip.call(this,item);
  711. };
  712.  
  713.  
  714. // Prevent equipping shards in normal equipping item locations
  715. Game_BattlerBase.prototype.canEquip = function(item) {
  716.     if (item && item.isShard) return false;
  717.     return Galv_Game_BattlerBase_canEquip.call(this,item);
  718. };
  719.  
  720. // Get traits from equipped shards
  721. var Galv_Game_Actor_traitObjects = Game_Actor.prototype.traitObjects;
  722. Game_Actor.prototype.traitObjects = function() {
  723.     var objects = Galv_Game_Actor_traitObjects.call(this);
  724.  
  725.     var shards = this._shards;
  726.     for (var slot in shards) {
  727.         var item = shards[slot].object();
  728.         if (item) {
  729.             objects.push(item);
  730.         };
  731.     };
  732.     return objects;
  733. };
  734.  
  735. // Get stats from equipped shards
  736. var Galv_Game_Actor_paramPlus = Game_Actor.prototype.paramPlus;
  737. Game_Actor.prototype.paramPlus = function(paramId) {
  738.     var value = Galv_Game_Actor_paramPlus.call(this,paramId);
  739.  
  740.     var shards = this._shards;
  741.     for (var slot in shards) {
  742.         var item = shards[slot].object();
  743.         if (item) {
  744.             value += item.params[paramId];
  745.         };
  746.     };
  747.     return value;
  748. };
  749.  
  750.  
  751. // Add skills gained from linked shards
  752. var Galv_Game_Actor_skills = Game_Actor.prototype.skills;
  753. Game_Actor.prototype.skills = function() {
  754.     var list = Galv_Game_Actor_skills.call(this);
  755.     var shards = this._shards;
  756.  
  757.     // Get list of equipped shards as array of shard ID's
  758.     var sArr = [];
  759.     for (var i = 0; i < this._shardSlots; i++) {
  760.         sArr.push(null);
  761.     };
  762.    
  763.     for (shard in shards) {
  764.         //sArr.push(shards[shard].object().isShard);
  765.         if (shards[shard]) sArr[shard] = shards[shard].object().isShard;
  766.     };
  767.  
  768.     // Get shard before and shard after
  769.     var shardCount = sArr.length;
  770.  
  771.     for (var i = 0; i < shardCount;i++) {
  772.         var nextIndex = (i === this._shardSlots - 1) ? 0 : i + 1;  // Next Shard
  773.         var next = sArr[nextIndex];
  774.         var toCheck = [next,sArr[i]].sort();
  775.  
  776.         var sId = Galv.MS.shardMixes[[toCheck[0],toCheck[1]]];
  777.         if (sId && !list.contains($dataSkills[sId])) {
  778.             list.push($dataSkills[sId]);
  779.         };
  780.     };
  781.     return list;
  782. };
  783.  
  784.  
  785. //-----------------------------------------------------------------------------
  786. //  SCENE_MENU
  787. //-----------------------------------------------------------------------------
  788. if (Galv.MS.mActive) {  // If menu command setting is true
  789.     var Galv_Scene_Menu_createCommandWindow = Scene_Menu.prototype.createCommandWindow;
  790.     Scene_Menu.prototype.createCommandWindow = function() {
  791.         Galv_Scene_Menu_createCommandWindow.call(this);
  792.         this._commandWindow.setHandler('mshards',      this.commandPersonal.bind(this));
  793.     };
  794.    
  795.     var Galv_Scene_Menu_onPersonalOk = Scene_Menu.prototype.onPersonalOk;
  796.     Scene_Menu.prototype.onPersonalOk = function() {
  797.         if (this._commandWindow.currentSymbol() === 'mshards') {
  798.             SceneManager.push(Scene_MShards);
  799.             return;
  800.         };
  801.         Galv_Scene_Menu_onPersonalOk.call(this);
  802.     };
  803.    
  804.     var Galv_Window_MenuCommand_addOriginalCommands = Window_MenuCommand.prototype.addOriginalCommands;
  805.     Window_MenuCommand.prototype.addOriginalCommands = function() {
  806.         Galv_Window_MenuCommand_addOriginalCommands.call(this);
  807.         this.addMShardsCommand();
  808.     };
  809.    
  810.     Window_MenuCommand.prototype.addMShardsCommand = function() {
  811.         if (this.needsCommand('mshards')) {
  812.             switch ($gameSystem.shardMenu) {
  813.                 case 'enabled':
  814.                 case 'enable':
  815.                     var enabled = true;
  816.                     break;
  817.                 case 'disabled':
  818.                 case 'disable':
  819.                     var enabled = false;
  820.                     break;
  821.                 case 'hidden':
  822.                 default:
  823.                     // Don't add the command
  824.                     return;
  825.             };
  826.             this.addCommand(Galv.MS.mCommand, 'mshards', enabled);
  827.         }
  828.     };
  829. };
  830.  
  831.  
  832. //-----------------------------------------------------------------------------
  833. //  SCENE_MSHARDS
  834. //-----------------------------------------------------------------------------
  835.  
  836. function Scene_MShards() {
  837.     this.initialize.apply(this, arguments);
  838. }
  839.  
  840. Scene_MShards.prototype = Object.create(Scene_MenuBase.prototype);
  841. Scene_MShards.prototype.constructor = Scene_MShards;
  842.  
  843. Scene_MShards.prototype.initialize = function() {
  844.     Scene_MenuBase.prototype.initialize.call(this);
  845. };
  846.  
  847.  
  848. // CREATE STUFF
  849.  
  850. Status_Opacity = Number(PluginManager.parameters('Galv_MagicShards')["Status Opacity"]);
  851. Command_Opacity = Number(PluginManager.parameters('Galv_MagicShards')["Command Opacity"]);
  852. Slot_Opacity = Number(PluginManager.parameters('Galv_MagicShards')["Slot Opacity"]);
  853. Name_Opacity = Number(PluginManager.parameters('Galv_MagicShards')["Name Opacity"]);
  854. Info_Opacity = Number(PluginManager.parameters('Galv_MagicShards')["Info Opacity"]);
  855. Item_Opacity = Number(PluginManager.parameters('Galv_MagicShards')["Item Opacity"]);
  856.  
  857. Scene_MShards.prototype.create = function() {
  858.    
  859.     Scene_MenuBase.prototype.create.call(this);
  860.    
  861.     this.createHelpWindow();
  862.    
  863.     this.createStatusWindow();
  864.    
  865.     this.createCommandWindow();
  866.     this.createNameWindow();
  867.    
  868.     this.createSlotWindow();
  869.     this.createItemWindow();
  870.     this.createInfoWindow();
  871.     this.refreshActor();
  872.    
  873.     this.updateOpacity();
  874. };
  875.  
  876. Scene_MShards.prototype.updateOpacity = function() {
  877.     this._statusWindow.opacity = Status_Opacity;
  878.     this._commandWindow.opacity = Command_Opacity;
  879.     this._slotWindow.opacity = Slot_Opacity;
  880.     this._nameWindow.opacity = Name_Opacity;
  881.     this._infoWindow.opacity = Info_Opacity;
  882.     this._itemWindow.opacity = Item_Opacity;
  883. };
  884.  
  885. Scene_MShards.prototype.updateShardImage = function() {
  886.     if (!Galv.MS.graphics) return;
  887.    
  888.     // Set centered
  889.     var w = Galv.MS.wh[0];
  890.     var h = Galv.MS.wh[1];
  891.     var ox = Galv.MS.xy[0];
  892.     var oy = Galv.MS.xy[1];
  893.    
  894.     this._shardImage.x = ox + this._statusWindow.width + (Graphics.boxWidth - this._statusWindow.width) / 2 - (w / 2);
  895.     this._shardImage.y = oy + this._helpWindow.height + (Graphics.boxHeight - this._helpWindow.height) / 2 - (h / 2);
  896.    
  897.     this._center = [this._shardImage.x + w / 2,this._shardImage.y + h / 2];
  898.     this._slotWindow.setCenter(this._center[0] - this._statusWindow.width, this._center[1] - this._helpWindow.height - this._nameWindow.height,w / 2);
  899.     this._slotWindow.refresh();
  900.    
  901.    
  902.     var actor = $gameParty.menuActor();
  903.     this._shardImage.bitmap = ImageManager.loadSystem("MagicOrb" + actor._shardImg);
  904. };
  905.  
  906. Scene_MShards.prototype.createBackground = function() {
  907.     if (Galv.MS.bg) {
  908.         this._backgroundSprite = new Sprite();
  909.         this._backgroundSprite.bitmap = ImageManager.loadSystem("shardBg");
  910.         this.addChild(this._backgroundSprite);
  911.     } else {
  912.         Scene_MenuBase.prototype.createBackground.call(this);
  913.     };
  914.     if (!Galv.MS.graphics) return;
  915.     this._shardImage = new Sprite();
  916.  
  917.     this.addChild(this._shardImage);
  918. };
  919.  
  920. Scene_MShards.prototype.createStatusWindow = function() {
  921.     this._statusWindow = new Window_ShardStatus(0, 0);
  922.     this._statusWindow.y = Graphics.height - this._statusWindow.height;
  923.     //this._statusWindow.width += 50;
  924.     this.addWindow(this._statusWindow);
  925. };
  926.  
  927. Scene_MShards.prototype.createCommandWindow = function() {
  928.     var wx = this._statusWindow.x;
  929.     var wy = this._helpWindow.height;
  930.     var ww = this._statusWindow.width;
  931.     this._commandWindow = new Window_MShardCommand(wx, wy, ww);
  932.     this._commandWindow.setHelpWindow(this._helpWindow);
  933.     this._commandWindow.setHandler('equip',    this.commandEquip.bind(this));
  934.     this._commandWindow.setHandler('remove',   this.commandRemove.bind(this));
  935.     this._commandWindow.setHandler('cancel',   this.popScene.bind(this));
  936.     this._commandWindow.setHandler('pagedown', this.nextActor.bind(this));
  937.     this._commandWindow.setHandler('pageup',   this.previousActor.bind(this));
  938.     this.addWindow(this._commandWindow);
  939. };
  940.  
  941. Scene_MShards.prototype.createSlotWindow = function() {
  942.     var wx = this._statusWindow.width;
  943.     var wy = this._helpWindow.height + this._commandWindow.height;
  944.     var ww = Graphics.boxWidth - this._statusWindow.width;
  945.     var wh = Graphics.boxHeight - this._helpWindow.height - this._commandWindow.height;
  946.     this._slotWindow = new Window_ShardSlot(wx, wy, ww, wh);
  947.     this._slotWindow.setHelpWindow(this._helpWindow);
  948.     this._slotWindow.setStatusWindow(this._statusWindow);
  949.     this._slotWindow.setHandler('ok',       this.onSlotOk.bind(this));
  950.     this._slotWindow.setHandler('cancel',   this.onSlotCancel.bind(this));
  951.     this.addWindow(this._slotWindow);
  952. };
  953.  
  954. Scene_MShards.prototype.createNameWindow = function() {
  955.     var wx = this._statusWindow.width;
  956.     var wy = this._helpWindow.height;
  957.     var ww = Graphics.boxWidth - this._statusWindow.width;
  958.     var wh = this._commandWindow.height;
  959.     this._nameWindow = new Window_ShardName(wx, wy, ww, wh);
  960.     this.addWindow(this._nameWindow);
  961. };
  962.  
  963. Scene_MShards.prototype.createInfoWindow = function() {
  964.     var ww = Graphics.boxWidth / 2;
  965.     var wx = ww / 2;
  966.     var wh = this._helpWindow.height;
  967.     var wy = Graphics.boxHeight - wh - 20;
  968.     this._infoWindow = new Window_ShardInfo(wx, wy, ww, wh);
  969.     this.addWindow(this._infoWindow);
  970. };
  971.  
  972. Scene_MShards.prototype.createItemWindow = function() {
  973.     var wx = this._commandWindow.x;
  974.     var wy = this._commandWindow.y + this._commandWindow.height;
  975.     var ww = this._commandWindow.width;
  976.     var wh = Graphics.boxHeight - wy - this._statusWindow.height;
  977.     this._itemWindow = new Window_ShardItem(wx, wy, ww, wh);
  978.     this._itemWindow.setHelpWindow(this._helpWindow);
  979.     this._itemWindow.setStatusWindow(this._statusWindow);
  980.     this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
  981.     this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
  982.     this._slotWindow.setItemWindow(this._itemWindow);
  983.     this.addWindow(this._itemWindow);
  984. };
  985.  
  986.  
  987. // Functionality
  988.  
  989.  
  990. Scene_MShards.prototype.refreshActor = function() {
  991.     var actor = this.actor();
  992.     this._statusWindow.setActor(actor);
  993.     this._slotWindow.setActor(actor);
  994.     this._itemWindow.setActor(actor);
  995.     this._commandWindow.refresh();
  996.     this.updateShardImage();
  997.     this._nameWindow.refresh();
  998. };
  999.  
  1000. Scene_MShards.prototype.commandEquip = function() {
  1001.     this._slotWindow.activate();
  1002.     this._slotWindow.select(0);
  1003. };
  1004.  
  1005. Scene_MShards.prototype.commandRemove = function() {
  1006.     this._slotWindow.activate();
  1007.     this._slotWindow.select(0);
  1008. };
  1009.  
  1010. Scene_MShards.prototype.onItemOk = function() {
  1011.  
  1012.     var skillsBefore = this.actor().skills()
  1013.     this.actor().changeShard(this._slotWindow.index(), this._itemWindow.item());
  1014.     var skillsAfter = this.actor().skills()
  1015.     var skillsAdded = skillsAfter.filter(function(a) { return skillsBefore.indexOf(a) < 0 });
  1016.     var skillsLost = skillsBefore.filter(function(a) { return skillsAfter.indexOf(a) < 0 });
  1017.    
  1018.     this._infoWindow.popup(skillsAdded,skillsLost);   // Show and update info window for action information
  1019.     this.playSe(skillsAdded,skillsLost);
  1020.    
  1021.     this._slotWindow.activate();
  1022.     this._slotWindow.refresh();
  1023.     this._itemWindow.deselect();
  1024.     this._itemWindow.refresh();
  1025.     this._statusWindow.refresh();
  1026.     this._nameWindow.refresh();
  1027. };
  1028.  
  1029. Scene_MShards.prototype.onItemCancel = function() {
  1030.     this._slotWindow.activate();
  1031.     this._itemWindow.deselect();
  1032. };
  1033.  
  1034. Scene_MShards.prototype.onActorChange = function() {
  1035.     this.refreshActor();
  1036.     this._nameWindow.refresh();
  1037.     this._commandWindow.activate();
  1038. };
  1039.  
  1040. Scene_MShards.prototype.onSlotOk = function() {
  1041.     if (this._infoWindow._openness >= 255) {
  1042.         // To close info window on press if it's open
  1043.         this._infoWindow.close();
  1044.     };
  1045.  
  1046.     if (this._commandWindow.index() == 0) {
  1047.         // Equip
  1048.         this._itemWindow.activate();
  1049.         this._itemWindow.select(0);
  1050.     } else {
  1051.         // Remove
  1052.         var skillsBefore = this.actor().skills()
  1053.         this.actor().changeShard(this._slotWindow.index(), null);
  1054.         var skillsAfter = this.actor().skills()
  1055.         var skillsAdded = skillsAfter.filter(function(a) { return skillsBefore.indexOf(a) < 0 });
  1056.         var skillsLost = skillsBefore.filter(function(a) { return skillsAfter.indexOf(a) < 0 });
  1057.        
  1058.         this._infoWindow.popup(skillsAdded,skillsLost);   // Show and update info window for action information
  1059.         this.playSe(skillsAdded,skillsLost);
  1060.        
  1061.         this._statusWindow.refresh();
  1062.         this._slotWindow.refresh();
  1063.         this._itemWindow.refresh();
  1064.         this._nameWindow.refresh();
  1065.         this._slotWindow.activate();
  1066.     };
  1067. };
  1068.  
  1069. Scene_MShards.prototype.onSlotCancel = function() {
  1070.     this._slotWindow.deselect();
  1071.     this._commandWindow.activate();
  1072. };
  1073.  
  1074. Scene_MShards.prototype.playSe = function(skillsAdded,skillsLost) {
  1075.     if (skillsAdded.length + skillsLost.length === 0) {
  1076.         SoundManager.playEquip();
  1077.     } else if (skillsAdded.length >= skillsLost.length) {
  1078.         AudioManager.playSe(Galv.MS.GainSe);
  1079.     } else if (skillsLost.length > skillsAdded.length) {
  1080.         AudioManager.playSe(Galv.MS.LoseSe);
  1081.     } else {
  1082.         SoundManager.playEquip();
  1083.     };
  1084. };
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090. //-----------------------------------------------------------------------------
  1091. // Windows
  1092. //-----------------------------------------------------------------------------
  1093.  
  1094.  
  1095.  
  1096. // Window_ShardStatus
  1097. //-----------------------------------------------------------------------------
  1098.  
  1099. function Window_ShardStatus() {
  1100.     this.initialize.apply(this, arguments);
  1101. }
  1102.  
  1103. Window_ShardStatus.prototype = Object.create(Window_EquipStatus.prototype);
  1104. Window_ShardStatus.prototype.constructor = Window_ShardStatus;
  1105.  
  1106. Window_ShardStatus.prototype.numVisibleRows = function() {return 8};
  1107.  
  1108. if (Galv.MS.asIcons) {
  1109.     Window_ShardStatus.prototype.windowWidth = function() {return 312;};
  1110. } else {
  1111.     Window_ShardStatus.prototype.windowWidth = function() {return 362;};
  1112. };
  1113.  
  1114. Window_ShardStatus.prototype.refresh = function() {
  1115.     this.contents.clear();
  1116.     if (this._actor) {
  1117.         //this.drawActorName(this._actor, this.textPadding(), 0);
  1118.         for (var i = 0; i < 8; i++) {
  1119.             this.drawItem(0, this.lineHeight() * i, i);
  1120.         }
  1121.     }
  1122. };
  1123.  
  1124.  
  1125.  
  1126.  
  1127. // Window_MShardCommand
  1128. //-----------------------------------------------------------------------------
  1129.  
  1130.  
  1131. function Window_MShardCommand() {
  1132.     this.initialize.apply(this, arguments);
  1133. }
  1134.  
  1135. Window_MShardCommand.prototype = Object.create(Window_HorzCommand.prototype);
  1136. Window_MShardCommand.prototype.constructor = Window_MShardCommand;
  1137.  
  1138. Window_MShardCommand.prototype.initialize = function(x, y, width) {
  1139.     this._windowWidth = width;
  1140.     Window_HorzCommand.prototype.initialize.call(this, x, y);
  1141. };
  1142.  
  1143. Window_MShardCommand.prototype.windowWidth = function() {return this._windowWidth};
  1144. Window_MShardCommand.prototype.maxCols = function() {return 2};
  1145.  
  1146. Window_MShardCommand.prototype.makeCommandList = function() {
  1147.     var enabled = $gameParty.menuActor()._shardSlots > 0;
  1148.     this.addCommand(Galv.MS.equip,   'equip', enabled);
  1149.     this.addCommand(Galv.MS.remove, 'remove', enabled);
  1150. };
  1151.  
  1152.  
  1153.  
  1154. // Window_ShardSlot
  1155. //-----------------------------------------------------------------------------
  1156.  
  1157. function Window_ShardSlot() {
  1158.     this.initialize.apply(this, arguments);
  1159. }
  1160.  
  1161. Window_ShardSlot.prototype = Object.create(Window_Selectable.prototype);
  1162. Window_ShardSlot.prototype.constructor = Window_ShardSlot;
  1163.  
  1164. Window_ShardSlot.prototype.initialize = function(x, y, width, height) {
  1165.     if (Galv.MS.graphics) {
  1166.         var height = Math.max(this.fittingHeight(Galv.MS.maxAllowed),height);
  1167.     };
  1168.    
  1169.     Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  1170.     this._actor = null;
  1171.     if (Galv.MS.graphics) this.opacity = 0;
  1172.     this.refresh();
  1173. };
  1174.  
  1175. Window_ShardSlot.prototype.setActor = function(actor) {
  1176.     if (this._actor !== actor) {
  1177.         this._actor = actor;
  1178.         this.refresh();
  1179.     }
  1180. };
  1181.  
  1182. Window_ShardSlot.prototype.update = function() {
  1183.     Window_Selectable.prototype.update.call(this);
  1184.     if (this._itemWindow) {
  1185.         this._itemWindow.setSlotId(this.index());
  1186.     }
  1187. };
  1188.  
  1189. Window_ShardSlot.prototype.maxItems = function() {
  1190.     //return this._actor ? this._actor.equipSlots().length : 0;
  1191.     return this._actor ? this._actor._shardSlots : 0;
  1192. };
  1193.  
  1194. Window_ShardSlot.prototype.item = function() {
  1195.     return (this._actor && this._actor._shards[this.index()]) ? this._actor._shards[this.index()].object() : null;
  1196. };
  1197.  
  1198. Window_ShardSlot.prototype.refresh = function() {
  1199.    
  1200.     // Get Linked Shard ID's
  1201.     var list = []
  1202.     var actor = $gameParty.menuActor();
  1203.  
  1204.     for (var i = 0; i < actor._shardSlots;i++) {
  1205.         var nextIndex = (i === actor._shardSlots - 1) ? 0 : i + 1;  // Next Shard
  1206.        
  1207.         var nextShardId = actor._shards[nextIndex] ? actor._shards[nextIndex].object().isShard : 0;
  1208.         var thisShardId = actor._shards[i] ? actor._shards[i].object().isShard : 0;
  1209.         var toCheck = [nextShardId,thisShardId].sort();
  1210.  
  1211.         var sId = Galv.MS.shardMixes[[toCheck[0],toCheck[1]]];
  1212.         if (sId) {
  1213.             if (!list.contains(i)) list.push(i);
  1214.             if (!list.contains(nextIndex)) list.push(nextIndex);
  1215.         };
  1216.     };
  1217.     this.linked = list;
  1218.  
  1219.     Window_Selectable.prototype.refresh.call(this);
  1220. };
  1221.  
  1222. if (Galv.MS.graphics) {
  1223. // If Graphics is turned on
  1224.  
  1225. Window_ShardSlot.prototype.cursorRight = function(wrap) {this.cursorDown(wrap)};
  1226. Window_ShardSlot.prototype.cursorLeft = function(wrap) {this.cursorUp(wrap)};
  1227. Window_ShardSlot.prototype.standardPadding = function() {return 0};
  1228. Window_ShardSlot.prototype.textPadding = function() {return 0};
  1229.    
  1230. Window_ShardSlot.prototype.drawSlot = function(x,y,i) {
  1231.     var pw = 58;
  1232.     var ph = 58;
  1233.     var sx = 0;
  1234.     var sy = 0;
  1235.     var bitmap = ImageManager.loadSystem('MagicOrbSlot');
  1236.     this.contents.blt(bitmap, sx, sy, pw, ph, x, y);
  1237.  
  1238.     if (this.linked.contains(i)) {
  1239.         bitmap = ImageManager.loadSystem('MagicOrbSlotLink');
  1240.         this.contents.blt(bitmap, sx, sy, pw, ph, x, y);
  1241.     };
  1242. };
  1243.  
  1244. Window_ShardSlot.prototype.setCenter = function(x,y,r) {
  1245.     this._cx = x;
  1246.     this._cy = y;
  1247.     this._radius = r - 15;
  1248. };
  1249.  
  1250.    
  1251. Window_ShardSlot.prototype.itemRect = function(index) {
  1252.     var actor = $gameParty.menuActor();
  1253.     var gap = 360 / actor._shardSlots;
  1254.     var angle = (gap * index - 90) * 0.0174532925;
  1255.     return {
  1256.         x: Math.cos(angle) * this._radius + this._cx - 29,  // the 29 is half the slot size
  1257.         y: Math.sin(angle) * this._radius + this._cy - 29,
  1258.         width: 58,
  1259.         height: 58
  1260.     };
  1261. };
  1262.    
  1263. Window_ShardSlot.prototype.drawItem = function(index) {
  1264.     if (this._actor) {
  1265.         var rect = this.itemRectForText(index);
  1266.  
  1267.         this.changePaintOpacity(this.isEnabled(index));
  1268.         this.drawSlot(rect.x,rect.y,index);
  1269.         if (this._actor._shards[index] && this._actor._shards[index].object()) {
  1270.             var item = this._actor._shards[index].object();
  1271.             var o = (58 - Window_Base._iconWidth) / 2;
  1272.             this.drawIcon(item.iconIndex, rect.x + o, rect.y + o);
  1273.         };
  1274.         this.changePaintOpacity(true);
  1275.     }
  1276. }; 
  1277.    
  1278. } else {
  1279. // If Graphics is turned OFF
  1280.  
  1281. Window_ShardSlot.prototype.drawItem = function(index) {
  1282.     if (this._actor) {
  1283.         var rect = this.itemRectForText(index);
  1284.         this.changeTextColor(this.systemColor());
  1285.         this.changePaintOpacity(this.isEnabled(index));
  1286.         if (this._actor._shards[index] && this._actor._shards[index].object()) {
  1287.             this.drawItemName(this._actor._shards[index].object() || null, rect.x, rect.y);
  1288.         } else {
  1289.             this.changeTextColor(this.normalColor());
  1290.             this.drawText(Galv.MS.empty,rect.x,rect.y,rect.width);
  1291.         };
  1292.         this.changePaintOpacity(true);
  1293.     }
  1294. };
  1295.  
  1296. }; // END GRAPHICS CONDITIONAL
  1297.  
  1298. Window_ShardSlot.prototype.isEnabled = function(index) {
  1299.     return this._actor ? this._actor.isShardChangeOk(index) : false;
  1300. };
  1301.  
  1302. Window_ShardSlot.prototype.isCurrentItemEnabled = function() {
  1303.     return this.isEnabled(this.index());
  1304. };
  1305.  
  1306. Window_ShardSlot.prototype.setStatusWindow = function(statusWindow) {
  1307.     this._statusWindow = statusWindow;
  1308.     this.callUpdateHelp();
  1309. };
  1310.  
  1311. Window_ShardSlot.prototype.setItemWindow = function(itemWindow) {
  1312.     this._itemWindow = itemWindow;
  1313.     this.update();
  1314. };
  1315.  
  1316. Window_ShardSlot.prototype.updateHelp = function() {
  1317.     Window_Selectable.prototype.updateHelp.call(this);
  1318.     this.setHelpWindowItem(this.item());
  1319.     if (this._statusWindow) {
  1320.         this._statusWindow.setTempActor(null);
  1321.     }
  1322. };
  1323.  
  1324.  
  1325.  
  1326.  
  1327. // Window_ShardItem
  1328. //-----------------------------------------------------------------------------
  1329.  
  1330.  
  1331. function Window_ShardItem() {
  1332.     this.initialize.apply(this, arguments);
  1333. }
  1334.  
  1335. Window_ShardItem.prototype = Object.create(Window_ItemList.prototype);
  1336. Window_ShardItem.prototype.constructor = Window_ShardItem;
  1337.  
  1338. Window_ShardItem.prototype.initialize = function(x, y, width, height) {
  1339.     Window_ItemList.prototype.initialize.call(this, x, y, width, height);
  1340.     this._actor = null;
  1341.     this._slotId = 0;
  1342. };
  1343.  
  1344. Window_ShardItem.prototype.maxCols = function() {return Galv.MS.asIcons ? 4 : 1};
  1345. Window_ShardItem.prototype.spacing = function() {return 8};
  1346.  
  1347. Window_ShardItem.prototype.drawItemNumber = function(item, x, y, width) {
  1348.     if (this.needsNumber()) {
  1349.         this.drawText($gameParty.numItems(item), x, y, width, 'right');
  1350.     }
  1351. };
  1352.  
  1353. if (Galv.MS.asIcons) {
  1354.     Window_ShardItem.prototype.drawItemName = function(item, x, y, width) {
  1355.         width = width || 312;
  1356.         if (item) {
  1357.             var iconBoxWidth = this.lineHeight();
  1358.             var padding = (iconBoxWidth - Window_Base._iconWidth) / 2;
  1359.             this.drawIcon(item.iconIndex, x + padding, y + padding);
  1360.         };
  1361.     };
  1362. };
  1363.  
  1364.  
  1365.  
  1366. Window_ShardItem.prototype.setActor = function(actor) {
  1367.     if (this._actor !== actor) {
  1368.         this._actor = actor;
  1369.         this.refresh();
  1370.         this.resetScroll();
  1371.     }
  1372. };
  1373.  
  1374. Window_ShardItem.prototype.setSlotId = function(slotId) {
  1375.     if (this._slotId !== slotId) {
  1376.         this._slotId = slotId;
  1377.         this.refresh();
  1378.         this.resetScroll();
  1379.     }
  1380. };
  1381.  
  1382. Window_ShardItem.prototype.includes = function(item) {
  1383.     return item && item.isShard;
  1384. };
  1385.  
  1386. Window_ShardItem.prototype.isEnabled = function(item) {
  1387.     return this._actor ? this._actor.canShardEquip(item) : false;
  1388. };
  1389.  
  1390. Window_ShardItem.prototype.selectLast = function() {
  1391. };
  1392.  
  1393. Window_ShardItem.prototype.setStatusWindow = function(statusWindow) {
  1394.     this._statusWindow = statusWindow;
  1395.     this.callUpdateHelp();
  1396. };
  1397.  
  1398. Window_ShardItem.prototype.updateHelp = function() {
  1399.     Window_ItemList.prototype.updateHelp.call(this);
  1400.     if (this._actor && this._statusWindow) {
  1401.         var actor = JsonEx.makeDeepCopy(this._actor);
  1402.         if (this._actor.canShardEquip(this.item())) actor.changeShard(this._slotId, this.item(),true);
  1403.         this._statusWindow.setTempActor(actor);
  1404.     }
  1405. };
  1406.  
  1407. Window_ShardItem.prototype.playOkSound = function() {
  1408. };
  1409.  
  1410.  
  1411.  
  1412. // Window_ShardName
  1413. //-----------------------------------------------------------------------------
  1414.  
  1415.  
  1416. function Window_ShardName() {
  1417.     this.initialize.apply(this, arguments);
  1418. }
  1419.  
  1420. Window_ShardName.prototype = Object.create(Window_Base.prototype);
  1421. Window_ShardName.prototype.constructor = Window_ShardName;
  1422.  
  1423. Window_ShardName.prototype.initialize = function(x,y,w,h) {
  1424.     Window_Base.prototype.initialize.call(this, x, y, w, h);
  1425.     if (Galv.MS.graphics) this.opacity = 0;
  1426.     this.refresh();
  1427. };
  1428.  
  1429. Window_ShardName.prototype.refresh = function() {
  1430.     this.contents.clear();
  1431.     var actor = $gameParty.menuActor();
  1432.     var width = this.contents.width - this.textPadding() * 2;
  1433.     this.drawText(actor.name(), 0, 0, width);
  1434.     var equipped = Object.keys(actor._shards).length;
  1435.     this.drawText(equipped + "/" + actor._shardSlots, 0, 0, width,'right');
  1436. };
  1437.  
  1438.  
  1439.  
  1440. // Window_ShardInfo
  1441. //-----------------------------------------------------------------------------
  1442.  
  1443.  
  1444. function Window_ShardInfo() {
  1445.     this.initialize.apply(this, arguments);
  1446. }
  1447.  
  1448. Window_ShardInfo.prototype = Object.create(Window_Base.prototype);
  1449. Window_ShardInfo.prototype.constructor = Window_ShardInfo;
  1450.  
  1451. Window_ShardInfo.prototype.initialize = function(x,y,w,h) {
  1452.     Window_Base.prototype.initialize.call(this, x, y, w, h);
  1453.     this._openness = 0;
  1454.     this._timer = 0;
  1455. };
  1456.  
  1457. Window_ShardInfo.prototype.update  = function() {
  1458.     Window_Base.prototype.update.call(this);
  1459.     this._timer -= 1;
  1460.     if (this._timer === 0) this.close();
  1461. };
  1462.  
  1463. Window_ShardInfo.prototype.popup = function(skillsAdded,skillsLost) {
  1464.     this.contents.clear();
  1465.     var width = this.contents.width - this.textPadding() * 2;
  1466.     var line = 0;
  1467.     var allowOpen = false;
  1468.    
  1469.     // Skills Added
  1470.     var count = skillsAdded.length;
  1471.     if (count > 0) {
  1472.         var names = Galv.MS.gained + " ";
  1473.         for (var i = 0; i < count;i++) {
  1474.             names = names + skillsAdded[i].name;
  1475.             if (i < count - 1) names = names + ", ";
  1476.         };
  1477.         this.changeTextColor("#99ff66");
  1478.         this.drawText(names, 0, 0, width,'center');
  1479.         allowOpen = true;
  1480.         line = 1;
  1481.     };
  1482.    
  1483.     // Skills Lost
  1484.     var count = skillsLost.length;
  1485.     if (count > 0) {
  1486.         var names = Galv.MS.lost + " ";
  1487.         for (var i = 0; i < count;i++) {
  1488.             names = names  + skillsLost[i].name;
  1489.             if (i < count - 1) names = names + ", ";
  1490.         };
  1491.         this.changeTextColor("#ff6666");
  1492.         this.drawText(names, 0, this.lineHeight() * line, width,'center');
  1493.         allowOpen = true;
  1494.     };
  1495.  
  1496.     if (allowOpen) {
  1497.         this.open();
  1498.         this._timer = 100;
  1499.     } else {
  1500.         this._timer = 1;
  1501.     };
  1502.    
  1503. };
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510. // GET TXT FILE SHARD MIXTURES
  1511. //-----------------------------------------------------------------------------
  1512. if (PluginManager.parameters('Galv_MagicShards')["Use Links"] === "true") {
  1513.  
  1514.     Galv.MS.file = {}
  1515.    
  1516.     Galv.MS.file.getString = function(filePath) {
  1517.         var request = new XMLHttpRequest();
  1518.         request.open("GET", filePath);
  1519.         request.overrideMimeType('application/json');
  1520.         request.onload = function() {
  1521.             if (request.status < 400) {
  1522.                 Galv.MS.createShards(request.responseText);
  1523.             }
  1524.         };
  1525.         request.send();
  1526.     };
  1527.  
  1528.     var folder = PluginManager.parameters('Galv_MagicShards')["Folder"];
  1529.     if (folder !== "") folder = folder + "/";
  1530.     Galv.MS.file.getString(folder + "Shards.txt");
  1531.  
  1532. } else {
  1533.     // No link shards
  1534.     Galv.MS.createShards("");
  1535. };
  1536.  
  1537.  
  1538.  
  1539.  
  1540. // Yanfly Patch
  1541. if (Imported.YEP_AutoPassiveStates) {
  1542.     var Galv_Game_Actor_passiveStatesRaw = Game_Actor.prototype.passiveStatesRaw;
  1543.     Game_Actor.prototype.passiveStatesRaw = function() {
  1544.         var pstates = Galv_Game_Actor_passiveStatesRaw.call(this);
  1545.        
  1546.         // Get passive state data for shard equips
  1547.         for (var shard in this._shards) {
  1548.             var s = this._shards[shard].object();
  1549.             pstates = pstates.concat(this.getPassiveStateData(s));
  1550.         };
  1551.         return pstates;
  1552.     };
  1553. };
  1554.  
  1555.  
  1556.  
  1557. })();
Add Comment
Please, Sign In to add comment