Advertisement
Unconnected42

RMMV Plug-in Ext _ Unco_X_CraftingSystem_v0_0_1

Nov 15th, 2015
3,737
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Crafting System, ver0.0.1
  3. // Add-on to Ammunition System
  4. //   by Unconnected42
  5. // UNCO_X_Crafting.js
  6. // Last Updated : 2015/11/15
  7. //=============================================================================
  8.  
  9.  
  10. //=============================================================================
  11. //=============================================================================
  12. // Only try to do anthing is Ammunition System is there !!!
  13. if (Imported && Imported.UNCO_AmmunitionSystem === true) {
  14. Unco.CS = Unco.CS || {};
  15. //=============================================================================
  16. //=============================================================================
  17.  
  18.  
  19. //=============================================================================
  20.  /*:
  21.  * @plugindesc  Allows skills to produce items or equipment.
  22.  * <Unco Craft>
  23.  * @author Unconnected42
  24.  *
  25.  * @param Crafting Skill Types
  26.  * @desc Put the list of Crafting Skill Type Ids, separated by commas.
  27.  * @default 0
  28.  *
  29.  * @param Default Products Text
  30.  * @desc  The text introducing the skill's products in Info window.
  31.  * @default Product(s)
  32.  *
  33.  * @param Default Stock Text
  34.  * @desc  The text introducing the skill's products & components amounts introductory text in Info window.
  35.  * @default in stock
  36.  *
  37.  * @param Default Components Text
  38.  * @desc  The text introducing the skill's components (i.e., costs) in Info window.
  39.  * @default Component(s)
  40.  *
  41.  * @param Display Products And Components Names
  42.  * @desc  If set at true, the names of products/components will be displayed. If not, only icons will be displayed.
  43.  * @default false
  44.  *
  45.  * @param Craft Text Font Size
  46.  * @desc  The text font size when drawing components & products info.
  47.  * @default 24
  48.  *
  49.  * @param Craft Text Font Color Normal
  50.  * @desc  The text font color when drawing components & products info.
  51.  * @default 0
  52.  *
  53.  * @param Craft Text Font Color Crisis
  54.  * @desc  The text font color when drawing components & products info, when ammo is insufficient.
  55.  * @default 18
  56.  *
  57.  *
  58.  * @help
  59.  * ============================================
  60.  * Introduction
  61.  * ============================================
  62.  *
  63.  * This plug-in provides a skill-based crafting system.
  64.  *
  65.  * ============================================
  66.  * Known Compatibility Issues
  67.  * ============================================
  68.  *
  69.  * This plug-in is an extension of Ammunition System.
  70.  * It will not work if Ammunition System is not installed.
  71.  *
  72.  * If you are using Bobstah's BattleCommandList plug-in,
  73.  * you will probably have to manually remove from your actors'battle command
  74.  * lists the crafting skill types (see below).
  75.  *
  76.  * ============================================
  77.  * Use
  78.  * ============================================
  79.  *
  80.  * This plug-in functions by allowing skills to produce items of any kind.
  81.  * The crafting skills (i.e., skills producing items) can consume items
  82.  * according to the rules of Ammunition System, with some specific tweaks.
  83.  * Note that crafting skills are not supposed to be used during battle.
  84.  *
  85.  * For the crafting skills to work properly, they must be given special
  86.  * skill types that are to be listed inside the plug-in parameter
  87.  * 'Crafting Skill Types'.
  88.  * Example : create a skill type named 'Alchemy' with number 6 and
  89.  * put '6' as the value for parameter 'Crafting Skill Types'. Then, give
  90.  * the skill type Alchemy to some skills that you want to produce items.
  91.  * Later, if for example you create another crafting skill type named
  92.  * 'Cooking' (number 7), put '6,7' as the value for parameter
  93.  * 'Crafting Skill Types'.
  94.  *
  95.  * When a skill type is listed in the Crafting Skill Types, there are two
  96.  * consequences:
  97.  * - the skill type will not appear during battle (only if you don't use
  98.  *   any plug-ins altering the actor battle command list)
  99.  * - when in main skill menu, when a crafting skill type is selected, the
  100.  *   normal item window will be replaced. Instead, you will have two windows:
  101.  *   the one at left will display the list of skills corresponding to the
  102.  *   selected skill type (all those skills should be crafting skills),
  103.  *   the one at right will display a list of products and components of
  104.  *   the currently selected skill. Current amounts of products/components
  105.  *   will also be displayed.
  106.  *
  107.  * Here are the tags to put in crafting skills notebox for defining production :
  108.  * <Make i Item: n>
  109.  * <Make i Armor: n>
  110.  * <Make i Weapon: n>
  111.  * ... where 'i' is the index of the desired item/armour/weapon and 'n' is the desired
  112.  * amount.
  113.  *
  114.  * As for the components, use the same tags as seen in Ammunition System.
  115.  * However, there is a little difference regarding item consumption.
  116.  * Weapon and armour-type items will be considered as normal items:
  117.  * that is, they do not need to be equipped, only the items in inventory will
  118.  * be accounted for to estimate the available amount (not the ones being equipped),
  119.  * and all the listed equip-type ammo will be consumed, and not only the one
  120.  * equipped.
  121.  *
  122.  * It is possible to customize the texts introducing the products and components
  123.  * in the craft information window with the following tag to put in the skill's
  124.  * notebox:
  125.  * <Craft Product Text: xxx>
  126.  * <Craft Component Text: xxx>
  127.  *
  128.  */
  129. //=============================================================================
  130.  
  131. //=============================================================================
  132. // Parameter Variables
  133. //=============================================================================
  134.  
  135. Unco.Parameters = $plugins.filter(function(p) {
  136.         return p.description.contains('<Unco Craft>');
  137.     })[0].parameters; //Copied from Ellye, who thanks Iavra
  138. Unco.Param = Unco.Param || {};
  139.  
  140. Unco.Param.craftDefProdText = String(Unco.Parameters['Default Products Text']);
  141. Unco.Param.craftDefCompText = String(Unco.Parameters['Default Components Text']);
  142. Unco.Param.craftDefStocText = String(Unco.Parameters['Default Stock Text']);
  143. Unco.Param.craftDispNames = String(Unco.Parameters['Display Products And Components Names']).toLowerCase();
  144. Unco.Param.craftSkillTypes = String(Unco.Parameters['Crafting Skill Types']).split(',');
  145. Unco.Param.craftFontSize = parseInt(String(Unco.Parameters['Craft Text Font Size']));
  146. Unco.Param.craftFontColorNorm = parseInt(String(Unco.Parameters['Craft Text Font Color Normal']));
  147. Unco.Param.craftFontColorCris = parseInt(String(Unco.Parameters['Craft Text Font Color Crisis']));
  148.  
  149. Unco.CS.isCraftSkillType = function(stid) {
  150.    stid = String(stid);  
  151.    for(var i = 0; i < Unco.Param.craftSkillTypes.length; i++) {
  152.       if (Unco.Param.craftSkillTypes[i] === stid) {
  153.          return true;
  154.       }
  155.    }
  156.    return false;
  157. }
  158.  
  159.  
  160. //=============================================================================
  161. // DataManager
  162. //=============================================================================
  163.  
  164. Unco.CS.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  165. DataManager.isDatabaseLoaded = function() {
  166.     if (!Unco.CS.DataManager_isDatabaseLoaded.call(this)) return false;
  167.     this.processUncoCraftNotetags($dataSkills);
  168.     return true;
  169. };
  170.  
  171. DataManager.processUncoCraftNotetags = function(group) {
  172.    for (var n = 1; n < group.length; n++) {
  173.       var obj = group[n];
  174.       var notedata = obj.note.split(/[\r\n]+/);
  175.  
  176.       obj.makeItem = [];
  177.       obj.makeArmor = [];
  178.       obj.makeWeapon = [];
  179.  
  180.       for (var i = 0; i < notedata.length; i++) {
  181.          var line = notedata[i];
  182.          if (line.match(/<(?:MAKE)[ ](\d+)[ ](?:ITEM):[ ](\d+)>/i)) {
  183.             var index = parseInt(RegExp.$1);
  184.             var value = parseInt(RegExp.$2);
  185.             if ( (!isNaN(index)) && (!isNaN(value)) ) {
  186.                obj.makeItem[index] = value;
  187.                obj.isCraft = true;
  188.             }
  189.          }
  190.          if (line.match(/<(?:MAKE)[ ](\d+)[ ](?:ARMOR):[ ](\d+)>/i)) {
  191.             var index = parseInt(RegExp.$1);
  192.             var value = parseInt(RegExp.$2);
  193.             if ( (!isNaN(index)) && (!isNaN(value)) ) {
  194.                obj.makeArmor[index] = value;
  195.                obj.isCraft = true;
  196.             }
  197.          }
  198.          if (line.match(/<(?:MAKE)[ ](\d+)[ ](?:WEAPON):[ ](\d+)>/i)) {
  199.             var index = parseInt(RegExp.$1);
  200.             var value = parseInt(RegExp.$2);
  201.             if ( (!isNaN(index)) && (!isNaN(value)) ) {
  202.                obj.makeWeapon[index] = value;
  203.                obj.isCraft = true;
  204.             }
  205.          }
  206.          if (line.match(/<(?:CRAFT)[ ](?:PRODUCT)[ ](?:TEXT):[ ](.*)>/i)) {
  207.             obj.craftProdText = String(RegExp.$1);
  208.          }
  209.          if (line.match(/<(?:CRAFT)[ ](?:COMPONENT)[ ](?:TEXT):[ ](.*)>/i)) {
  210.             obj.craftCompText = String(RegExp.$1);
  211.          }
  212.       }
  213.    }
  214. }
  215.  
  216.  
  217.  
  218. //=============================================================================
  219. // Window_ActorCommand
  220. //=============================================================================
  221.  
  222. if (!Imported.BOB_BattleCommandList) {
  223.    Window_ActorCommand.prototype.addSkillCommands = function() {
  224.       var skillTypes = this._actor.addedSkillTypes();
  225.       skillTypes.sort(function(a, b) {
  226.          return a - b;
  227.       });
  228.       skillTypes.forEach(function(stypeId) {
  229.          if (Unco.CS.isCraftSkillType(stypeId) === false) {
  230.             var name = $dataSystem.skillTypes[stypeId];
  231.             this.addCommand(name, 'skill', true, stypeId);
  232.          }
  233.       }, this);
  234.    };
  235. }
  236. //=============================================================================
  237. // Game_BattlerBase
  238. //=============================================================================
  239.  
  240. Game_BattlerBase.prototype.canPaySkillEquipAmmoCost = function(skill) {
  241.    if (skill.stypeId && Unco.CS.isCraftSkillType(skill.stypeId)) {
  242.       for (var ammoId in skill.equipAmmoCost) {
  243.          ammoId = parseInt(ammoId);
  244.          if (!isNaN(ammoId) && (ammoId > 0)) {
  245.             var nbOwned = $gameParty.getItemAmount($dataArmors[ammoId]);
  246.             if (skill.equipAmmoCost[ammoId] > nbOwned) {
  247.                return false;
  248.             }
  249.          }
  250.       }
  251.       for (var ammoId in skill.weaponAmmoCost) {
  252.          ammoId = parseInt(ammoId);
  253.          if (!isNaN(ammoId) && (ammoId > 0)) {
  254.             var nbOwned = $gameParty.getItemAmount($dataWeapons[ammoId]);
  255.             if (skill.weaponAmmoCost[ammoId] > nbOwned) {
  256.                return false;
  257.             }
  258.          }
  259.       }
  260.       return true;
  261.    }
  262.    if (!this.canPaySkillArmorAmmoCost(skill)) return false;
  263.    if (!this.canPaySkillWeaponAmmoCost(skill)) return false;
  264.    return true;
  265. };
  266.  
  267. Unco.CS.Game_BattlerBase_paySkillEquipAmmoCost = Game_BattlerBase.prototype.paySkillEquipAmmoCost;
  268. Game_BattlerBase.prototype.paySkillEquipAmmoCost = function(skill) {
  269.    if (skill.stypeId && Unco.CS.isCraftSkillType(skill.stypeId)) {
  270.       for (var ammoId in skill.equipAmmoCost) {
  271.          ammoId = parseInt(ammoId);
  272.          if (!isNaN(ammoId) && (ammoId > 0)) {
  273.             $gameParty.gainItem($dataArmors[ammoId],-skill.equipAmmoCost[ammoId]);
  274.          }
  275.       }
  276.       for (var ammoId in skill.weaponAmmoCost) {
  277.          ammoId = parseInt(ammoId);
  278.          if (!isNaN(ammoId) && (ammoId > 0)) {
  279.             $gameParty.gainItem($dataWeapons[ammoId],-skill.weaponAmmoCost[ammoId]);
  280.          }
  281.       }
  282.    } else {
  283.       Unco.CS.Game_BattlerBase_paySkillEquipAmmoCost.call(this,skill);
  284.    }
  285. };
  286.  
  287. Unco.CS.Game_BattlerBase_paySkillAmmoCost = Game_BattlerBase.prototype.paySkillAmmoCost;
  288. Game_BattlerBase.prototype.paySkillAmmoCost = function(skill) {
  289.    Unco.CS.Game_BattlerBase_paySkillAmmoCost.call(this,skill);
  290.    if (skill.id === this.attackSkillId()) {
  291.       return;
  292.    }
  293.    for (var makeId in skill.makeItem) {
  294.       makeId = parseInt(makeId);
  295.       if (!isNaN(makeId) && (makeId > 0)) {
  296.          var makeAmount = parseInt(skill.makeItem[makeId]);
  297.          if (!isNaN(makeAmount) &&  (makeAmount > 0)) {
  298.             $gameParty.gainItem($dataItems[makeId],makeAmount);
  299.          }
  300.       }
  301.    }
  302.    for (var makeId in skill.makeArmor) {
  303.       makeId = parseInt(makeId);
  304.       if (!isNaN(makeId) && (makeId > 0)) {
  305.          var makeAmount = parseInt(skill.makeArmor[makeId]);
  306.          if (!isNaN(makeAmount) &&  (makeAmount > 0)) {
  307.             $gameParty.gainItem($dataArmors[makeId],makeAmount);
  308.          }
  309.       }
  310.    }
  311.    for (var makeId in skill.makeWeapon) {
  312.       makeId = parseInt(makeId);
  313.       if (!isNaN(makeId) && (makeId > 0)) {
  314.          var makeAmount = parseInt(skill.makeWeapon[makeId]);
  315.          if (!isNaN(makeAmount) &&  (makeAmount > 0)) {
  316.             $gameParty.gainItem($dataWeapons[makeId],makeAmount);
  317.          }
  318.       }
  319.    }
  320. };
  321.  
  322. //-----------------------------------------------------------------------------
  323. // Window_CraftList
  324. //
  325. // The window for selecting a skill on the skill screen, for craft skills.
  326.  
  327. function Window_CraftList() {
  328.     this.initialize.apply(this, arguments);
  329. }
  330.  
  331. Window_CraftList.prototype = Object.create(Window_SkillList.prototype);
  332. Window_CraftList.prototype.constructor = Window_CraftList;
  333.  
  334. Window_CraftList.prototype.initialize = function(x, y, width, height) {
  335.     Window_SkillList.prototype.initialize.call(this, x, y, width, height);
  336.     this._infoWindow = null;
  337. };
  338.  
  339. Window_CraftList.prototype.maxCols = function() {
  340.     return 1;
  341. };
  342.  
  343. Window_CraftList.prototype.drawAmmoCost = function(skill, wx, wy, dw) {
  344.    if (Unco.CS.isCraftSkillType(skill.stypeId) === false) {
  345.       dw = Window_SkillList.prototype.drawAmmoCost.call(this,skill, wx, wy, dw);
  346.    }
  347.    return dw;
  348. };
  349.  
  350. Window_CraftList.prototype.setInfoWindow = function(infoWindow) {
  351.     this._infoWindow = infoWindow
  352.     if (this.active && this._infoWindow) {
  353.         this._infoWindow.setItem(this.item());
  354.     }
  355. };
  356.  
  357. Window_CraftList.prototype.updateHelp = function() {
  358.     this.setHelpWindowItem(this.item());
  359.     if (this._infoWindow) {
  360.         this._infoWindow.setItem(this.item());
  361.     }
  362. };
  363.  
  364. //=============================================================================
  365. // Window_CraftInfo
  366. //=============================================================================
  367.  
  368. function Window_CraftInfo() {
  369.     this.initialize.apply(this, arguments);
  370. }
  371.  
  372. Window_CraftInfo.prototype = Object.create(Window_Base.prototype);
  373. Window_CraftInfo.prototype.constructor = Window_CraftInfo;
  374.  
  375. Window_CraftInfo.prototype.initialize = function(x, y, width, height) {
  376.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  377.     this._item = null;
  378.     this.deactivate();
  379.     this.refresh();
  380. };
  381.  
  382. Window_CraftInfo.prototype.setItem = function(item) {
  383.     if (this._item === item) return;
  384.     this._item = item;
  385.     this.refresh();
  386. };
  387.  
  388. Window_CraftInfo.prototype.refresh = function() {
  389.     this.contents.clear();
  390.     var dy = 0;
  391.     if (!this._item) return dy;
  392.     dy = this.drawProducts(dy);
  393.     dy = this.drawComponents(dy);
  394.     return dy;
  395. };
  396.  
  397. Window_CraftInfo.prototype.drawProducts = function(dy) {
  398.    var skill = this._item;
  399.    var indent = 24;
  400.    var stockIndent = indent*3;
  401.    var dx = this.textPadding();
  402.    var dw = this.contents.width - this.textPadding() * 2;
  403.    this.resetFontSettings();
  404.    var text = ( (typeof skill.craftProdText !== 'undefined') ? skill.craftProdText : Unco.Param.craftDefProdText);
  405.    this.drawDarkRect(dx-indent, dy, dw+indent, this.lineHeight());
  406.    this.drawText(text, dx, dy, dw, 'left');
  407.    dy += this.lineHeight();
  408.    dx += indent;
  409.    this.contents.fontSize = Unco.Param.craftFontSize;
  410.    this.changeTextColor(this.textColor(Unco.Param.craftFontColorNorm));
  411.    for (var makeId in skill.makeItem) {
  412.       makeId = parseInt(makeId);
  413.       if (!isNaN(makeId) && (makeId > 0)) {
  414.          var makeAmount = parseInt(skill.makeItem[makeId]);
  415.          if (!isNaN(makeAmount) &&  (makeAmount > 0)) {
  416.             this.drawIcon($dataItems[makeId].iconIndex, dx, dy);
  417.             if (Unco.Param.craftDispNames === 'true') {
  418.                this.drawText($dataItems[makeId].name, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  419.                dy += this.lineHeight();
  420.             }
  421.             text = 'x' + String(makeAmount);
  422.             this.drawText(text, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  423.             text = '(' + $gameParty.getItemAmount($dataItems[makeId]) + ' ' + Unco.Param.craftDefStocText + ')';
  424.             this.drawText(text, dx + Window_Base._iconWidth + stockIndent, dy, dw, 'left');
  425.             dy += this.lineHeight();
  426.          }
  427.       }
  428.    }
  429.    for (var makeId in skill.makeArmor) {
  430.       makeId = parseInt(makeId);
  431.       if (!isNaN(makeId) && (makeId > 0)) {
  432.          var makeAmount = parseInt(skill.makeArmor[makeId]);
  433.          if (!isNaN(makeAmount) &&  (makeAmount > 0)) {
  434.             this.drawIcon($dataArmors[makeId].iconIndex, dx, dy);
  435.             if (Unco.Param.craftDispNames === 'true') {
  436.                this.drawText($dataArmors[makeId].name, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  437.                dy += this.lineHeight();
  438.             }
  439.             text = 'x' + String(makeAmount);
  440.             this.drawText(text, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  441.             text = '(' + $gameParty.getItemAmount($dataArmors[makeId]) + ' ' + Unco.Param.craftDefStocText + ')';
  442.             this.drawText(text, dx + Window_Base._iconWidth + stockIndent, dy, dw, 'left');
  443.             dy += this.lineHeight();
  444.          }
  445.       }
  446.    }
  447.    for (var makeId in skill.makeWeapon) {
  448.       makeId = parseInt(makeId);
  449.       if (!isNaN(makeId) && (makeId > 0)) {
  450.          var makeAmount = parseInt(skill.makeWeapon[makeId]);
  451.          if (!isNaN(makeAmount) &&  (makeAmount > 0)) {
  452.             this.drawIcon($dataWeapons[makeId].iconIndex, dx, dy);
  453.             if (Unco.Param.craftDispNames === 'true') {
  454.                this.drawText($dataWeapons[makeId].name, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  455.                dy += this.lineHeight();
  456.             }
  457.             text = 'x' + String(makeAmount);
  458.             this.drawText(text, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  459.             text = '(' + $gameParty.getItemAmount($dataWeapons[makeId]) + ' ' + Unco.Param.craftDefStocText + ')';
  460.             this.drawText(text, dx + Window_Base._iconWidth + stockIndent, dy, dw, 'left');
  461.             dy += this.lineHeight();
  462.          }
  463.       }
  464.    }
  465.    this.resetFontSettings();
  466.    return dy;
  467. };
  468.  
  469. Window_CraftInfo.prototype.drawComponents = function(dy) {  
  470.    var skill = this._item;
  471.    var indent = 24;
  472.    var stockIndent = indent*3;
  473.    var dx = this.textPadding();
  474.    var dw = this.contents.width - this.textPadding() * 2;
  475.    this.resetFontSettings();
  476.    this.drawDarkRect(dx-indent, dy, dw+indent, this.lineHeight());
  477.    var text = ( (typeof skill.craftCompText !== 'undefined') ? skill.craftCompText : Unco.Param.craftDefCompText);
  478.    this.drawText(text, dx, dy, dw, 'left');
  479.    dy += this.lineHeight();
  480.    dx += indent;
  481.    this.contents.fontSize = Unco.Param.craftFontSize;
  482.    var craftLineHeight = Math.max(Unco.Param.craftFontSize,Window_Base._iconHeight)+1;  
  483.     if (typeof skill.goldCost === 'number') {
  484.       this.drawIcon(Unco.Param.goldAmmoIconId, dx, dy);
  485.       if (Unco.Param.craftDispNames === 'true') {
  486.          this.drawText(TextManager.currencyUnit, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  487.          dy += craftLineHeight;
  488.       }
  489.       var text = 'x' + String(skill.goldCost);
  490.       this.drawText(text, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  491.       if (skill.goldCost > $gameParty.gold()) this.changeTextColor(this.textColor(Unco.Param.craftFontColorCris));
  492.       text = '(' + $gameParty.gold() + ' ' + Unco.Param.craftDefStocText + ')';
  493.       this.drawText(text, dx + Window_Base._iconWidth + stockIndent, dy, dw, 'left');
  494.       dy += craftLineHeight;
  495.       this.changeTextColor(this.textColor(Unco.Param.craftFontColorNorm));
  496.       this.resetFontSettings();
  497.     }
  498.    for (var ammoId in skill.itemAmmoCost) {
  499.       ammoId = parseInt(ammoId);
  500.       if (!isNaN(ammoId) && (ammoId > 0)) {
  501.          var ammoAmount = parseInt(skill.itemAmmoCost[ammoId]);
  502.          if (!isNaN(ammoAmount) &&  (ammoAmount > 0)) {
  503.             this.drawIcon($dataItems[ammoId].iconIndex, dx, dy);
  504.             if (Unco.Param.craftDispNames === 'true') {
  505.                this.drawText($dataItems[ammoId].name, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  506.                dy += craftLineHeight;
  507.             }
  508.             this.changeTextColor(this.textColor(Unco.Param.craftFontColorNorm));
  509.             text = 'x' + String(ammoAmount);
  510.             this.drawText(text, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  511.             if (ammoAmount > $gameParty.getItemAmount($dataItems[ammoId])) this.changeTextColor(this.textColor(Unco.Param.craftFontColorCris));
  512.             text = '(' + $gameParty.getItemAmount($dataItems[ammoId]) + ' ' + Unco.Param.craftDefStocText + ')';
  513.             this.drawText(text, dx + Window_Base._iconWidth + stockIndent, dy, dw, 'left');
  514.             dy += craftLineHeight;
  515.             this.changeTextColor(this.textColor(Unco.Param.craftFontColorNorm));
  516.          }
  517.       }
  518.    }
  519.    for (var ammoId in skill.equipAmmoCost) {
  520.       ammoId = parseInt(ammoId);
  521.       if (!isNaN(ammoId) && (ammoId > 0)) {
  522.          ammoAmount = parseInt(skill.equipAmmoCost[ammoId]);
  523.          if (!isNaN(ammoAmount) && (ammoAmount > 0)) {
  524.             this.drawIcon($dataArmors[ammoId].iconIndex, dx, dy);
  525.             if (Unco.Param.craftDispNames === 'true') {
  526.                this.drawText($dataArmors[ammoId].name, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  527.                dy += craftLineHeight;
  528.             }
  529.             this.changeTextColor(this.textColor(Unco.Param.craftFontColorNorm));
  530.             text = 'x' + String(ammoAmount);
  531.             this.drawText(text, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  532.             text = '(' + $gameParty.getItemAmount($dataArmors[ammoId]) + ' ' + Unco.Param.craftDefStocText + ')';
  533.             if (ammoAmount > $gameParty.getItemAmount($dataArmors[ammoId])) this.changeTextColor(this.textColor(Unco.Param.craftFontColorCris));
  534.             this.drawText(text, dx + Window_Base._iconWidth + stockIndent, dy, dw, 'left');
  535.             dy += craftLineHeight;
  536.             this.changeTextColor(this.textColor(Unco.Param.craftFontColorNorm));
  537.          }
  538.       }
  539.    }
  540.    for (var ammoId in skill.weaponAmmoCost) {
  541.       ammoId = parseInt(ammoId);
  542.       if (!isNaN(ammoId) && (ammoId > 0)) {
  543.          ammoAmount = parseInt(skill.weaponAmmoCost[ammoId]);
  544.          if (!isNaN(ammoAmount) && (ammoAmount > 0)) {
  545.             this.drawIcon($dataWeapons[ammoId].iconIndex, dx, dy);
  546.             if (Unco.Param.craftDispNames === 'true') {
  547.                this.drawText($dataWeapons[ammoId].name, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  548.                dy += craftLineHeight;
  549.             }
  550.             this.changeTextColor(this.textColor(Unco.Param.craftFontColorNorm));
  551.             text = 'x' + String(ammoAmount);
  552.             this.drawText(text, dx + Window_Base._iconWidth + 2, dy, dw, 'left');
  553.             text = '(' + $gameParty.getItemAmount($dataWeapons[ammoId]) + ' ' + Unco.Param.craftDefStocText + ')';
  554.             if (ammoAmount > $gameParty.getItemAmount($dataWeapons[ammoId])) this.changeTextColor(this.textColor(Unco.Param.craftFontColorCris));
  555.             this.drawText(text, dx + Window_Base._iconWidth + stockIndent, dy, dw, 'left');
  556.             dy += craftLineHeight;
  557.             this.changeTextColor(this.textColor(Unco.Param.craftFontColorNorm));
  558.          }
  559.       }
  560.    }
  561.    return dy;
  562.    this.resetFontSettings();
  563. };
  564.  
  565. Window_CraftInfo.prototype.drawDarkRect = function(dx, dy, dw, dh) {
  566.     var color = this.gaugeBackColor();
  567.     this.changePaintOpacity(false);
  568.     this.contents.fillRect(dx + 1, dy + 1, dw - 2, dh - 2, color);
  569.     this.changePaintOpacity(true);
  570. };
  571.  
  572. //=============================================================================
  573. // Window_SkillType
  574. //=============================================================================
  575. Unco.CS.Window_SkillType_initialize = Window_SkillType.prototype.initialize;
  576. Window_SkillType.prototype.initialize = function(x, y) {
  577.     Unco.CS.Window_SkillType_initialize.call(this, x, y);
  578.     this._craftWindow = null;
  579.     this._infoWindow = null;
  580. };
  581.  
  582. Window_SkillType.prototype.setCraftWindows = function(craftWindow,infoWindow) {
  583.     this._craftWindow = craftWindow;
  584.     this._infoWindow  = infoWindow;
  585.     this.update();
  586. };
  587.  
  588. Unco.CS.Window_SkillType_update = Window_SkillType.prototype.update
  589. Window_SkillType.prototype.update = function() {
  590.     Unco.CS.Window_SkillType_update.call(this);
  591.     if (this._craftWindow) {
  592.         this._craftWindow.setStypeId(this.currentExt());
  593.     }
  594. };
  595.  
  596. Unco.CS.Window_SkillType_select = Window_SkillType.prototype.select;
  597. Window_SkillType.prototype.select = function(index) {
  598.     Unco.CS.Window_SkillType_select.call(this,index);
  599.     if (this._skillWindow) {
  600.         if (Unco.CS.isCraftSkillType(this.currentExt()) === true) {
  601.            this._skillWindow.hide();
  602.            this._craftWindow.show();
  603.            this._infoWindow.show();
  604.         } else {
  605.            this._skillWindow.show();
  606.            this._craftWindow.hide();
  607.            this._infoWindow.hide();
  608.         }
  609.     }
  610.     console.log('Select:');
  611.     console.log(this._list);
  612. };
  613.  
  614. //=============================================================================
  615. // Scene_Skill
  616. //=============================================================================
  617.  
  618. Unco.CS.Scene_Skill_createItemWindow = Scene_Skill.prototype.createItemWindow;
  619. Scene_Skill.prototype.createItemWindow = function() {
  620.     Unco.CS.Scene_Skill_createItemWindow.call(this);
  621.     var wx = 0;
  622.     var wy = this._statusWindow.y + this._statusWindow.height;
  623.     var ww = Graphics.boxWidth/2;
  624.     var wh = Graphics.boxHeight - wy;
  625.     this._craftWindow = new Window_CraftList(wx, wy, ww, wh);
  626.     this._infoWindow  = new Window_CraftInfo(ww, wy, Graphics.boxWidth-ww, wh);
  627.     this._craftWindow.setHelpWindow(this._helpWindow);
  628.     this._craftWindow.setInfoWindow(this._infoWindow);
  629.     this._craftWindow.setHandler('ok',     this.onItemOk.bind(this));
  630.     this._craftWindow.setHandler('cancel', this.onItemCancel.bind(this));
  631.     this._skillTypeWindow.setCraftWindows(this._craftWindow,this._infoWindow);
  632.     this.addWindow(this._craftWindow);
  633.     this.addWindow(this._infoWindow);
  634.     this._craftWindow.hide();
  635.     this._infoWindow.hide();
  636. };
  637.  
  638. Unco.CS.Scene_Skill_commandSkill = Scene_Skill.prototype.commandSkill;
  639. Scene_Skill.prototype.commandSkill = function() {
  640.     console.log('Command:');
  641.     console.log(this._skillTypeWindow.currentExt());
  642.     if (Unco.CS.isCraftSkillType(this._skillTypeWindow.currentExt())) {
  643.        this._craftWindow.activate();
  644.        this._craftWindow.selectLast();
  645.     } else {
  646.        Unco.CS.Scene_Skill_commandSkill.call(this);      
  647.     }
  648. };
  649.  
  650. Scene_Skill.prototype.item = Scene_Skill.prototype.item;
  651. Scene_Skill.prototype.item = function() {
  652.     if (this._craftWindow) {
  653.        if (Unco.CS.isCraftSkillType(this._skillTypeWindow.currentExt()) === true) {
  654.           return this._craftWindow.item();
  655.        }      
  656.     }
  657.     return this._itemWindow.item();
  658. };
  659.  
  660. Unco.CS.Scene_Skill_refreshActor = Scene_Skill.prototype.refreshActor;
  661. Scene_Skill.prototype.refreshActor = function() {
  662.     Unco.CS.Scene_Skill_refreshActor.call(this);
  663.     var actor = this.actor();
  664.     this._craftWindow.setActor(actor);
  665. };
  666.  
  667. Unco.CS.Scene_Skill_onItemCancel = Scene_Skill.prototype.onItemCancel;
  668. Scene_Skill.prototype.onItemCancel = function() {
  669.     if (Unco.CS.isCraftSkillType(this._skillTypeWindow.currentExt()) === true) {
  670.        this._craftWindow.deselect();
  671.        this._infoWindow.contents.clear();
  672.        this._skillTypeWindow.activate();
  673.     } else {
  674.        Unco.CS.Scene_Skill_onItemCancel.call(this);      
  675.     }
  676. };
  677.  
  678. Unco.CS.Scene_Skill_useItem = Scene_Skill.prototype.useItem;
  679. Scene_Skill.prototype.useItem = function() {
  680.     Unco.CS.Scene_Skill_useItem.call(this);
  681.     this._infoWindow.refresh();
  682.     this._craftWindow.refresh();
  683. };
  684.  
  685. Unco.CS.Scene_Skill_activateItemWindow = Scene_Skill.prototype.activateItemWindow;
  686. Scene_Skill.prototype.activateItemWindow = function() {
  687.    if (Unco.CS.isCraftSkillType(this._skillTypeWindow.currentExt()) === true) {
  688.       this._craftWindow.refresh();
  689.       this._craftWindow.activate();
  690.    } else {
  691.       Unco.CS.Scene_Skill_activateItemWindow.call(this);
  692.    }
  693. };
  694.  
  695. //=============================================================================
  696. // Window_Help
  697. //=============================================================================
  698. Unco.CS.Window_Help_getAmmoAmountText = Window_Help.prototype.getAmmoAmountText;
  699. Window_Help.prototype.getAmmoAmountText = function(item) {
  700.    if (typeof item !== 'undefined') {
  701.       if ((typeof item.ammoText !== "undefined") && (item.ammoText !== "")) {
  702.          return Unco.CS.Window_Help_getAmmoAmountText.call(this,item);
  703.       }
  704.       if (Unco.CS.isCraftSkillType(item.stypeId)) {
  705.          return '';
  706.       }
  707.       return Unco.CS.Window_Help_getAmmoAmountText.call(this,item);
  708.    }
  709.    return '';
  710. };
  711.  
  712. //=============================================================================
  713. //=============================================================================
  714. // Only try to do anything is Ammunition System is there !!!
  715. }
  716. //=============================================================================
  717. //=============================================================================
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement