Advertisement
Unconnected42

RPG Maker Plug-in - Ammunition System v. 1.1.5

Nov 16th, 2016
125
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Ammunition System, ver1.1.5
  3. //   by Unconnected42
  4. // UNCO_AmmunitionSystem.js
  5. // Last Updated : 2016/11/15
  6. //=============================================================================
  7.  
  8. var Imported = Imported || {};
  9. Imported.UNCO_AmmunitionSystem = true;
  10.  
  11. var Unco = Unco || {};
  12. Unco.AS = Unco.AS || {};
  13.  
  14.  
  15. //=============================================================================
  16.  /*:
  17.  * @plugindesc  Allows skills to need ammunition.
  18.  * <Unco Ammo>
  19.  * @author Unconnected42
  20.  *
  21.  * @param Show Ammo Left When Actor Command
  22.  * @desc If set as 'true', show how much ammunition is left for main attack at the top of the screen, during actor command selection.
  23.  * @default true
  24.  *
  25.  * @param Show Ammo Left In Help Window
  26.  * @desc  If set as 'true', show how much ammunition is left for a skill in its description.
  27.  * @default true
  28.  *
  29.  * @param Help Window Ammo Text
  30.  * @desc  Default text to be displayed in skill description before ammunition amounts.
  31.  * @default Ammunition left
  32.  *
  33.  * @param Show Ammo Left In Skill Window
  34.  * @desc In skill window, show how much ammunition is left together with the cost if set at 'true'.
  35.  * @default false
  36.  *
  37.  * @param No Ammo Icon
  38.  * @desc  Id of the default icon to be displayed when there is no more ammunition and several types of ammunition are possible.
  39.  * @default 16
  40.  *
  41.  * @param Gold Ammo Icon
  42.  * @desc  Id of the icon to be displayed for gold costs.
  43.  * @default 313
  44.  *
  45.  * @param Ammo Font Size
  46.  * @desc Font size of the ammunition amounts in skill window and gauge.
  47.  * @default 20
  48.  *
  49.  * @param Ammo Font Color
  50.  * @desc Font color of the ammunition amounts in skill window and gauge.
  51.  * @default 6
  52.  *
  53.  * @param Show Ammo Left In Actor Command Window
  54.  * @desc If set at true, will display how much ammo is left just next to the attack command.
  55.  * @default false
  56.  *
  57.  * @param Compact Cost Display
  58.  * @desc If set at true, the amount of needed ammo will be displayed on the icon.
  59.  * @default false
  60.  *
  61.  * @help
  62.  * ============================================
  63.  * Introduction
  64.  * ============================================
  65.  *
  66.  * ver1.1.5
  67.  *
  68.  * This plug-in will allow skills or weapons to require the consumption of
  69.  * ammunition, components, etc. in order to work. The cost is  paid each
  70.  * time the skill is used, together with MP/TP costs, or each time the
  71.  * normal attack is used in the case of weapons.
  72.  * The ammunition can be either gold, items or equipments (armours, weapons), or
  73.  * a mix.
  74.  *
  75.  * However, things work differently depending on what type of cost is considered.
  76.  * - items : if several types of items are marked as required as ammunition
  77.  *   for a given skill/weapon, *ALL* of the corresponding prices must be
  78.  *   paid each time the skill/weapon is used.
  79.  * - equipment : the equipment needs to be equipped in order for the skill/weapon
  80.  *   to work. If several types of equipments are marked as required as ammunition
  81.  *   for a given skill/weapon, *ONLY* the cost of the one that is *CURRENTLY
  82.  *   EQUIPPED* will be paid. That means a weapon/skill can be able to use
  83.  *   different interchangeable ammunition types.
  84.  * - Gold cost is straightforward in how it functions.
  85.  *
  86.  * You can also define skills which can change the type of ammunition
  87.  * equipped even during combat, in the case of armour-type ammunition.
  88.  * Then, your hero can use an action to change his/her ammunition type !
  89.  *
  90.  * ============================================
  91.  * Known Compatibility Issues
  92.  * ============================================
  93.  *
  94.  * This plug-in should be placed under all plug-ins that you are using,
  95.  * especially Yanfly's since it actually uses some of their features if
  96.  * they are present.
  97.  * Known exceptions to that rule :
  98.  * - Yanfly's Skill Cooldown
  99.  * - Jay's Dual Techs.
  100.  *   -> Ammunition should be placed above these two plug-ins.
  101.  * This might also be the case for other plug-ins whenever
  102.  * the modification of skill costs is concerned.
  103.  * On the contrary, the following plug-ins MUST be placed above :
  104.  * - Bobstah's BattleCommandList.
  105.  *
  106.  *
  107.  * This plug-in in the present version should be fully compatible
  108.  * with Yanfly's ItemCore Independent Items feature.
  109.  * Therefore, ammunition of any kind can either be independent or
  110.  * not (for the latter case, use a <Not Independent Item> notetag
  111.  * in the ammunition notebox if you are using ItemCore and a max
  112.  * number of items > 0).
  113.  *
  114.  * ============================================
  115.  * Use
  116.  * ============================================
  117.  *
  118.  * + Declaring a weapon/skill to need ammunition
  119.  * ---------------------------------------------
  120.  * Lines to put in either Weapon notebox or Skill notebox for defining costs :
  121.  *   <Gold Cost: c>
  122.  *   <Ammo i Item: c>  (for items ammo)
  123.  *   <Ammo i Equip: c>  (for armors ammo)
  124.  *   <Ammo i Weapon: c>  (for weapons ammo)
  125.  * ... where i is the ID of the ammunition item/armor and c is the cost
  126.  * required for one use.
  127.  * Disclaimer concerning weapon-type ammunition:
  128.  * In its present state it is intended to be used for weapons that would be
  129.  * their own ammo, like throwing knives, shurikens, etc.
  130.  * In theory, however, it *should* be possible to use as ammo for a weapon
  131.  * a different weapon, provided both of them are equipped, but this possibility
  132.  * has yet to be playtested...
  133.  *
  134.  * + Declaring a skill that serves for equipping ammo (during combat)
  135.  * ------------------------------------------------------------------
  136.  * To create a skill that will change the type of ammunition equipped:
  137.  *   <Ammo i Load>
  138.  * ... where i is the ID of the ammunition armor.
  139.  * The following syntax is also authorized:
  140.  *   <Ammo i Load: s>
  141.  * ...where s is the specific slot to be equipped.
  142.  * This syntax is kept only for compatibility reasons, so that people
  143.  * who defined their tags for older versions of the script that did
  144.  * not support the simpler syntax are not forced to change.
  145.  * If your actor(s) have for example the following equipment types:
  146.  *     Weapon, Shield, Head, Body, Accessory, Ammunition
  147.  * ... then the slot number would be 6.
  148.  * Note 1: this is meant to be used during battle, when equip menu is not
  149.  * accessible, if you want your actors to be able to switch ammunition.
  150.  * Note 2: it is necessary to define one skill per type of ammunition.
  151.  * Note 3: it is possible to use this tag for equipping any kind of armor, and
  152.  * not just ammunition.
  153.  * Also, the Load feature currently does not work with weapon-type ammo.
  154.  *
  155.  * + Ammo equipment with charges
  156.  * -----------------------------
  157.  * For an armor- or weapon-type ammunition, you can allow each ammo item to
  158.  * provide a given number of uses instead of being consumed after just one use.
  159.  * Declare the following tag in the ammo equipment notebox:
  160.  *   <Ammo Charges: n>
  161.  * ... where 'n' is the wished number of charges the item possesses.
  162.  * This tag will only actually be used if you are using Yanfly's ItemCore and
  163.  * the item is an independent item.
  164.  * The equipped ammo item has a certain number of charges, and at each use, this
  165.  * is this number that will be reduced, instead of the number of ammo items.
  166.  * When the number of charges hits zero, the item is unequipped, without
  167.  * being returned to inventory. No other item of same type will be equipped even
  168.  * if available in inventory.
  169.  *
  170.  * Instead of having an empty ammunition equipment simply disappear,
  171.  * it is possible to have a specific item be created in the inventory (which
  172.  * then represent the empty equipment).
  173.  * Use the following tag:
  174.  *   <Ammo Charges Empty : i>
  175.  * ...when 'i' is the id of the item to be created.
  176.  * Note that this will be a normal item, not an equipment.
  177.  *
  178.  * + Determining skill's availability depending on a game switch
  179.  * -------------------------------------------------------------
  180.  * You can also now have skill availability depend on a game switch status, with
  181.  * the following tag to put in a skill's notebox:
  182.  *   <Game Switch: n>
  183.  * If the game switch number 'n' is set at false, the skill cannot be used.
  184.  * This might be useful, for example, if you are also using the crafting
  185.  * extension of this plug-in and wish to make crafting available only
  186.  * in certain places/situations.
  187.  *
  188.  * ============================================
  189.  * Displaying Ammunition Amounts & Costs
  190.  * ============================================
  191.  *
  192.  * A given ammunition type is almost always represented by its icon when it
  193.  * is necessary (either to display a cost or a remaining amount).
  194.  * Ammo costs for skills are indicated together with "normal" TP/MP costs.
  195.  *
  196.  * There are several solutions for displaying the remaining ammunition amount
  197.  * so that the player knows where he stands.
  198.  * Most of them are turned on through the plug-in parameters.
  199.  *
  200.  * - For weapons :
  201.  *   + The number of ammunition left can be displayed at the
  202.  *     top of the screen when the actor command menu is active.
  203.  *     This is the default option.
  204.  *   + The number of ammunition left can be displayed in the
  205.  *     command window, just next to the "Attack" option.
  206.  *     No icon in that case.
  207.  *   + If you are using Yanfly's SkillCore plug-in, you can use the following
  208.  *     notetag in the weapon note :
  209.  *         <Swap Gauge n: AMMO>
  210.  *     ...where n is the number of the gauge you want to replace.
  211.  *     Instead of a normal HP/MP/TP gauge, you will then have the amount of
  212.  *     ammunition left for the currently equipped weapon.
  213.  * - For skills :
  214.  *   + The remaining amount for each ammunition type can be showed
  215.  *     together with cost in the skill window.
  216.  *   + It can also be displayed after the skill description, in the help
  217.  *     window. This is the default option.
  218.  *     In that case, you should keep the skill description within one unique
  219.  *     line with no line-break at the end, or else the remaining ammo will
  220.  *     not be visible.
  221.  *
  222.  * The text before ammunition left amounts can be customized with the following
  223.  *   notetag in the skill notebox:
  224.  *   <Ammo Left Text: xxx>
  225.  *   ... with xxx being your custom text.
  226.  * The name of the ammunition type can be displayed along with its icon with
  227.  * the following notetag in the weapon/skill notebox:
  228.  *   <Show Ammo Name>
  229.  *
  230.  * Also, in the case of equipment ammunition, several types of
  231.  * ammunition are possible but only one (the one equipped) will be displayed
  232.  * in any skill/help/etc window (or gauge). When there is no more ammunition,
  233.  * the system normally would not know which icon to use !
  234.  * There is a default icon for that, but you can put the following notetag
  235.  * in skill/weapon notebox to define which icon will be used :
  236.  *   <No Ammo Icon: i>
  237.  *   ... with i being the icon number.
  238.  * It is also possible to add details about the ammunition type currently
  239.  * equipped by adding the following notetag in the ammo notebox :
  240.  *   <Ammo Window Desc: xxx>
  241.  * Where 'xxx' is the description you want to give to your ammo.
  242.  * This description will show up in the skill help window and the ammunition
  243.  * window visible during actor command selection.
  244.  * Please that if you deactivate the ammo window or the display of remaining
  245.  * ammo amount with the corresponding plug-in parameters, you will of course
  246.  * not see any description of ammunition !
  247.  *
  248.  * ============================================
  249.  * Change Log
  250.  * ============================================
  251.  *
  252.  * - 2016-07-10 : ver1.1.5 : fixed compatibility with Yanfly's Weapon Unleash.
  253.  * - 2016-06-11 : ver1.1.4 : fixed compatibility with Yanfly's ItemCore version 1.24
  254.  * - 2016-02-17 : ver1.1.3 : (supposedly?) corrected a bug that causes crashes
  255.  *   when enemy attacks in some situations.
  256.  * - 2015-12-15 : ver1.1.2 : yet another bug correction.
  257.  * - 2015-12-15 : ver1.1.1 : corrected a bug that caused zero cost equip ammunition
  258.  *   to be unequippable.
  259.  * - 2015-12-09 : ver1.1.0 : charged ammunition can now 'create' an 'empty' item when
  260.  *   their charge number is reduced to zero. Also, charged ammunition will show
  261.  *   their remaining charges in equip windows.
  262.  * - 2015-11-29 : ver1.0.0 : added charged ammunition feature. Fixed a (generally
  263.  *   silent) bug that could make skills availables even in case of unsufficient
  264.  *   ammunition in some rare cases.
  265.  * - 2015-11-26 : ver0.4.4 : fixed an issue that caused equip-type ammo to be
  266.  *   equippable when it should not in some situations.
  267.  * - 2015-11-24 : ver0.4.3b : fixed an issue that caused ammo not to be consumed
  268.  *   in some situations when using older versions of Yanfly's ATB.
  269.  * - 2015-11-21 : ver0.4.3 : the previous changes made actually break the ammo cost
  270.  *   implementation when ammo are NOT independent items, causing the ammo to be
  271.  *   simply unequipped... Corrected now.
  272.  * - 2015-11-20 : ver0.4.2 : correction of the 'reload skills' feature so that
  273.  *   indicating the correct equip slot for equip ammunition is no more necessary.
  274.  *   Slight modification of how the cost of equip ammunition is managed internally,
  275.  *   so that it works more logically when independent ammo with variance is used.
  276.  * - 2015-11-15 : ver0.4.1 : corrected a bug causing a crash during battle when
  277.  *   no weapon is equipped and the ammo amount is displayed next to attack command.
  278.  *   Also corrected a bug that could make the displayed cost in attack command incorrect.
  279.  * - 2015-11-15 : ver0.4.0 : added compact cost display, game switch dependency,
  280.  *   and weapon-type ammunition (for now, it is strongly recommended to use it only
  281.  *   for weapons using themselves as ammo, such as throwing knives). Added extension Crafting System.
  282.  *
  283.  */
  284. //=============================================================================
  285.  
  286. //=============================================================================
  287. // Parameter Variables
  288. //=============================================================================
  289.  
  290. Unco.Parameters = $plugins.filter(function(p) {
  291.         return p.description.contains('<Unco Ammo>');
  292.     })[0].parameters; //Copied from Ellye, who thanks Iavra
  293. Unco.Param = Unco.Param || {};
  294.  
  295. Unco.Param.showAmmoLeftActorCommand = String(Unco.Parameters['Show Ammo Left When Actor Command']).toLowerCase();
  296. Unco.Param.showAmmoLeft = String(Unco.Parameters['Show Ammo Left In Skill Window']).toLowerCase();
  297. Unco.Param.ammoFontSize = Number(Unco.Parameters['Ammo Font Size']);
  298. Unco.Param.ammoFontColor = Number(Unco.Parameters['Ammo Font Color']);
  299. Unco.Param.showAmmoLeftInDesc = String(Unco.Parameters['Show Ammo Left In Help Window']).toLowerCase();
  300. Unco.Param.descAmmoLeftText = String(Unco.Parameters['Help Window Ammo Text']);
  301. Unco.Param.defaultNoAmmoIconId = parseInt(String(Unco.Parameters['No Ammo Icon']));
  302. Unco.Param.goldAmmoIconId = parseInt(String(Unco.Parameters['Gold Ammo Icon']));
  303. Unco.Param.showAmmoLeftForAttack = String(Unco.Parameters['Show Ammo Left In Actor Command Window']).toLowerCase();
  304. Unco.Param.compactCostDisplay = String(Unco.Parameters['Compact Cost Display']).toLowerCase();
  305.  
  306. //=============================================================================
  307. // DataManager
  308. //=============================================================================
  309.  
  310. Unco.AS.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  311. DataManager.isDatabaseLoaded = function() {
  312.    if (!Unco.AS.DataManager_isDatabaseLoaded.call(this)) return false;
  313.    if (Imported.YEP_ItemCore && (Yanfly.Param.ItemMaxArmors > 0)) {
  314.       this.processUncoAmmoChargesNotetags($dataArmors);
  315.    }
  316.    if (Imported.YEP_ItemCore && (Yanfly.Param.ItemMaxWeapons > 0)) {
  317.       this.processUncoAmmoChargesNotetags($dataWeapons);
  318.    }
  319.    this.processUncoItemAmmoNotetags($dataSkills);
  320.    this.processUncoSwitchNotetags($dataSkills);
  321.    this.processUncoGoldCostNotetags($dataSkills);
  322.    this.processUncoAmmoTextNotetags($dataSkills);
  323.    this.processUncoEquipAmmoNotetags($dataSkills);
  324.    this.processUncoAmmoLoadNotetags($dataSkills);
  325.    this.processUncoAmmoTextNotetags($dataWeapons);
  326.    this.processUncoItemAmmoNotetags($dataWeapons);
  327.    this.processUncoEquipAmmoNotetags($dataWeapons);
  328.    this.processUncoAmmoDescNotetags($dataArmors);
  329.    return true;
  330. };
  331.  
  332. DataManager.processUncoAmmoChargesNotetags = function(group) {
  333.    for (var n = 1; n < group.length; n++) {
  334.       var obj = group[n];
  335.       if (!DataManager.isIndependent(obj)) continue;
  336.       var notedata = obj.note.split(/[\r\n]+/);
  337.  
  338.       for (var i = 0; i < notedata.length; i++) {
  339.          var line = notedata[i];
  340.          if (line.match(/<(?:AMMO)[ ](?:CHARGES):[ ](\d+)>/i)) {
  341.             var value = parseInt(RegExp.$1);
  342.             if (!isNaN(value) && (value > 0)) {
  343.                obj.ammoCharges = value;
  344.                obj.ammoCurrentCharges = value;
  345.             }
  346.          }
  347.          if (line.match(/<(?:AMMO)[ ](?:CHARGES)[ ](?:EMPTY):[ ](\d+)>/i)) {
  348.             var value = parseInt(RegExp.$1);
  349.             if (!isNaN(value) && (value > 0)) {
  350.                obj.ammoMorphIfEmpty = value;
  351.             }
  352.          }
  353.       }
  354.    }
  355. }
  356.  
  357. DataManager.processUncoSwitchNotetags = function(group) {
  358.    for (var n = 1; n < group.length; n++) {
  359.       var obj = group[n];
  360.       var notedata = obj.note.split(/[\r\n]+/);
  361.      
  362.       obj.ammoGameSwitch = [];
  363.  
  364.       for (var i = 0; i < notedata.length; i++) {
  365.          var line = notedata[i];
  366.          if (line.match(/<(?:GAME)[ ](?:SWITCH):[ ](\d+)>/i)) {
  367.             var value = parseInt(RegExp.$1);
  368.             if (!isNaN(value)) {
  369.                obj.ammoGameSwitch[value] = true;
  370.             }
  371.          }
  372.       }
  373.    }
  374. }
  375.  
  376. DataManager.processUncoGoldCostNotetags = function(group) {
  377.    for (var n = 1; n < group.length; n++) {
  378.       var obj = group[n];
  379.       var notedata = obj.note.split(/[\r\n]+/);
  380.  
  381.       for (var i = 0; i < notedata.length; i++) {
  382.          var line = notedata[i];
  383.          if (line.match(/<(?:GOLD)[ ](?:COST):[ ](\d+)>/i)) {
  384.             var value = parseInt(RegExp.$1);
  385.             if (!isNaN(value)) {
  386.                obj.goldCost = value;
  387.             }
  388.          }
  389.       }
  390.    }
  391. }
  392.  
  393. DataManager.processUncoItemAmmoNotetags = function(group) {
  394.    for (var n = 1; n < group.length; n++) {
  395.       var obj = group[n];
  396.       var notedata = obj.note.split(/[\r\n]+/);
  397.  
  398.       obj.itemAmmoCost = [];
  399.  
  400.       for (var i = 0; i < notedata.length; i++) {
  401.          var line = notedata[i];
  402.          if (line.match(/<(?:AMMO)[ ](\d+)[ ](?:ITEM):[ ](\d+)>/i)) {
  403.             var index = parseInt(RegExp.$1);
  404.             var value = parseInt(RegExp.$2);
  405.             if ( (!isNaN(index)) && (!isNaN(value)) ) {
  406.                obj.itemAmmoCost[index] = value;
  407.                if (DataManager.isWeapon(obj)) {
  408.                   if (typeof $dataItems[index].isItemAmmoForWeapon === 'undefined') $dataItems[index].isItemAmmoForWeapon = [];
  409.                   $dataItems[index].isItemAmmoForWeapon[obj.id] = value;
  410.                } else {
  411.                   if (typeof $dataItems[index].isItemAmmoForSkill === 'undefined') $dataItems[index].isItemAmmoForSkill = [];
  412.                   $dataItems[index].isItemAmmoForSkill[obj.id] = value;
  413.                }
  414.             }
  415.          }
  416.       }
  417.    }
  418. }
  419.  
  420. DataManager.processUncoEquipAmmoNotetags = function(group) {
  421.    for (var n = 1; n < group.length; n++) {
  422.       var obj = group[n];
  423.       var notedata = obj.note.split(/[\r\n]+/);
  424.  
  425.       obj.equipAmmoCost = [];
  426.       obj.equipChargeAmmoCost = [];
  427.       obj.weaponAmmoCost = [];
  428.       obj.weaponChargeAmmoCost = [];
  429.  
  430.       for (var i = 0; i < notedata.length; i++) {
  431.          var line = notedata[i];
  432.          if (line.match(/<(?:AMMO)[ ](\d+)[ ](?:EQUIP):[ ](\d+)>/i)) {
  433.             var index = parseInt(RegExp.$1);
  434.             var value = parseInt(RegExp.$2);
  435.             if ( (!isNaN(index)) && (!isNaN(value)) ) {
  436.                if ($dataArmors[index].ammoCharges) {
  437.                   obj.equipChargeAmmoCost[index] = value;
  438.                } else {
  439.                   obj.equipAmmoCost[index] = value;
  440.                }
  441.                if (DataManager.isWeapon(obj)) {
  442.                   if (typeof $dataArmors[index].isEquipAmmoForWeapon === 'undefined') $dataArmors[index].isEquipAmmoForWeapon = [];
  443.                   $dataArmors[index].isEquipAmmoForWeapon[obj.id] = value;
  444.                } else {
  445.                   if (typeof $dataArmors[index].isEquipAmmoForSkill === 'undefined') $dataArmors[index].isEquipAmmoForSkill = [];
  446.                   $dataArmors[index].isEquipAmmoForSkill[obj.id] = value;
  447.                }
  448.             }
  449.          }
  450.          if (line.match(/<(?:AMMO)[ ](\d+)[ ](?:WEAPON):[ ](\d+)>/i)) {
  451.             var index = parseInt(RegExp.$1);
  452.             var value = parseInt(RegExp.$2);
  453.             if ( (!isNaN(index)) && (!isNaN(value)) ) {
  454.                if ($dataWeapons[index].ammoCharges) {
  455.                   obj.weaponChargeAmmoCost[index] = value;
  456.                } else {
  457.                   obj.weaponAmmoCost[index] = value;
  458.                }
  459.                if (DataManager.isWeapon(obj)) {
  460.                   if (typeof $dataWeapons[index].isWeaponAmmoForWeapon === 'undefined') $dataWeapons[index].isWeaponAmmoForWeapon = [];
  461.                   $dataWeapons[index].isWeaponAmmoForWeapon[obj.id] = value;
  462.                } else {
  463.                   if (typeof $dataWeapons[index].isWeaponAmmoForSkill === 'undefined') $dataWeapons[index].isWeaponAmmoForSkill = [];
  464.                   $dataWeapons[index].isWeaponAmmoForSkill[obj.id] = value;
  465.                }
  466.             }
  467.          }
  468.       }
  469.    }
  470. }
  471.  
  472. DataManager.isItemAmmo = function(item) {
  473.    return this.isItem(item) && (item.isItemAmmoForWeapon || item.isItemAmmoForSkill);
  474. };
  475. DataManager.isEquipAmmo = function(item) {
  476.    return this.isArmor(item) && (item.isEquipAmmoForWeapon || item.isEquipAmmoForSkill);
  477. };
  478. DataManager.isWeaponAmmo = function(item) {
  479.    return this.isWeapon(item) && (item.isWeaponAmmoForWeapon || item.isWeaponAmmoForSkill);
  480. };
  481. DataManager.isAmmo = function(item) {
  482.    return (this.isItemAmmo(item) || this.isEquipAmmo(item) || this.isWeaponAmmo(item));
  483. };
  484.  
  485. DataManager.processUncoAmmoTextNotetags = function(group) {
  486.    for (var n = 1; n < group.length; n++) {
  487.       var obj = group[n];
  488.       var notedata = obj.note.split(/[\r\n]+/);
  489.       for (var i = 0; i < notedata.length; i++) {
  490.          var line = notedata[i];
  491.          if (line.match(/<(?:AMMO)[ ](?:LEFT)[ ](?:TEXT):[ ](.*)>/i)) {
  492.             obj.ammoText = String(RegExp.$1);
  493.          }
  494.          if (line.match(/<(?:NO)[ ](?:AMMO)[ ](?:ICON):[ ](\d+)>/i)) {
  495.             obj.noAmmoIconId = parseInt(RegExp.$1);
  496.          }
  497.          if (line.match(/<(?:SHOW)[ ](?:AMMO)[ ](?:NAME)>/i)) {
  498.             obj.showAmmoName = true;
  499.          }
  500.       }
  501.    }
  502. };
  503.  
  504. DataManager.processUncoAmmoLoadNotetags = function(group) {
  505.    for (var n = 1; n < group.length; n++) {
  506.       var obj = group[n];
  507.       var notedata = obj.note.split(/[\r\n]+/);
  508.       for (var i = 0; i < notedata.length; i++) {
  509.          var line = notedata[i];
  510.          if (line.match(/<(?:AMMO)[ ](\d+)[ ](?:LOAD):[ ](\d+)>/i)) {
  511.             var index = parseInt(RegExp.$1);
  512.             var equid = parseInt(RegExp.$2);
  513.             if ( (!isNaN(index)) && (!isNaN(equid)) ) {
  514.                obj.ammoLoadIndex = index;
  515.                obj.ammoLoadSlot = equid;
  516.             }
  517.          }
  518.          if (line.match(/<(?:AMMO)[ ](\d+)[ ](?:LOAD)>/i)) {
  519.             var index = parseInt(RegExp.$1);
  520.             if (!isNaN(index)) {
  521.                obj.ammoLoadIndex = index;
  522.                obj.ammoLoadSlot = 0;
  523.             }
  524.          }
  525.       }
  526.    }
  527. };
  528.  
  529. DataManager.processUncoAmmoDescNotetags = function(group) {
  530.    for (var n = 1; n < group.length; n++) {
  531.       var obj = group[n];
  532.       var notedata = obj.note.split(/[\r\n]+/);
  533.       for (var i = 0; i < notedata.length; i++) {
  534.          var line = notedata[i];
  535.          if (line.match(/<(?:AMMO)[ ](?:WINDOW)[ ](?:DESC):[ ](.*)>/i)) {
  536.             obj.ammoDesc = String(RegExp.$1);
  537.          }
  538.       }
  539.    }
  540. };
  541.  
  542. Unco.AS.hasAmmoCost = function(obj) {
  543.     if (typeof obj.goldCost == "number") {
  544.         if (obj.goldCost > 0) return true;
  545.     }
  546.     if (typeof obj.equipAmmoCost != "undefined") {
  547.         if (obj.equipAmmoCost.length > 0) return true;
  548.     }
  549.     if (typeof obj.equipChargeAmmoCost != "undefined") {
  550.         if (obj.equipChargeAmmoCost.length > 0) return true;
  551.     }
  552.     if (typeof obj.weaponAmmoCost != "undefined") {
  553.         if (obj.weaponAmmoCost.length > 0) return true;
  554.     }
  555.     if (typeof obj.weaponChargeAmmoCost != "undefined") {
  556.         if (obj.weaponChargeAmmoCost.length > 0) return true;
  557.     }
  558.     if (typeof obj.itemAmmoCost != "undefined") {
  559.         if (obj.itemAmmoCost.length > 0) return true;
  560.     }
  561.     if (typeof obj.ammoGameSwitch != "undefined") {
  562.         if (obj.ammoGameSwitch.length > 0) return true;
  563.     }
  564.     return false;
  565. }
  566.  
  567. //=============================================================================
  568. // Game_Actor
  569. //=============================================================================
  570.  
  571. Game_Actor.prototype.equippableSlotsFor = function(item) {
  572.    var emptySlots = [];
  573.    var equippedSlots = [];
  574.    for (var s in this.equipSlots()) {
  575.       if (this.equipSlots()[s] === item.etypeId) {
  576.          if (this.equips()[s] === null) {
  577.             emptySlots.push(parseInt(s)+1);
  578.          } else {
  579.             equippedSlots.push(parseInt(s)+1);
  580.          }
  581.       }
  582.    }
  583.    return emptySlots.concat(equippedSlots);
  584. }
  585.  
  586. //=============================================================================
  587. // Game_BattlerBase
  588. //=============================================================================
  589.  
  590. Unco.AS.Game_BattlerBase_canEquipArmor = Game_BattlerBase.prototype.canEquipArmor;
  591. Game_BattlerBase.prototype.canEquipArmor = function(item) {
  592.    if (typeof $dataArmors[item.id].isEquipAmmoForWeapon !== 'undefined') {
  593.       var ok = false;
  594.       if (this._equips[0].itemId() > 0) {
  595.          var EquippedWeaponId = ( (typeof $dataWeapons[this._equips[0].itemId()].baseItemId === 'undefined') ? this._equips[0].itemId() : $dataWeapons[this._equips[0].itemId()].baseItemId );
  596.          for (var weaponId in $dataArmors[item.id].isEquipAmmoForWeapon) {
  597.             weaponId = parseInt(weaponId);
  598.             var ammoCost = parseInt( $dataArmors[item.id].isEquipAmmoForWeapon[weaponId] );
  599.             ammoCost = (isNaN(ammoCost)) ? -1 : ammoCost ;
  600.             if ((weaponId === EquippedWeaponId) && (ammoCost > -1)) {
  601.                ok = true;
  602.                break;
  603.             }
  604.          }
  605.       }
  606.       if (ok === false) return false;
  607.    }
  608.    return Unco.AS.Game_BattlerBase_canEquipArmor.call(this,item);
  609. };
  610.  
  611. Unco.AS.Game_BattlerBase_canEquipWeapon = Game_BattlerBase.prototype.canEquipWeapon;
  612. Game_BattlerBase.prototype.canEquipWeapon = function(item) {
  613.    if (typeof $dataWeapons[item.id].isWeaponAmmoForWeapon !== 'undefined') {
  614.       var ok = false;
  615.       var wantedWeaponId = ( (typeof $dataWeapons[item.id].baseItemId === 'undefined') ? item.id : $dataWeapons[item.id].baseItemId );
  616.       var EquippedWeaponId = 0;
  617.       if (this._equips[0].itemId() > 0) {
  618.          EquippedWeaponId = ( (typeof $dataWeapons[this._equips[0].itemId()].baseItemId === 'undefined') ? this._equips[0].itemId() : $dataWeapons[this._equips[0].itemId()].baseItemId );
  619.       }
  620.       for (var weaponId in $dataWeapons[item.id].isWeaponAmmoForWeapon) {
  621.          weaponId = parseInt(weaponId);
  622.          var ammoCost = parseInt( $dataWeapons[item.id].isWeaponAmmoForWeapon[weaponId] );
  623.          ammoCost = (isNaN(ammoCost)) ? -1 : ammoCost ;
  624.          if (this._equips[0].itemId() > 0) {
  625.             if ((weaponId === EquippedWeaponId) && (ammoCost > -1)) {
  626.                ok = true;
  627.                break;
  628.             }
  629.          }
  630.          if (weaponId === wantedWeaponId) {
  631.             ok = true;
  632.             break;
  633.          }
  634.       }
  635.       if (ok === false) return false;
  636.    }
  637.    return Unco.AS.Game_BattlerBase_canEquipWeapon.call(this,item);
  638. };
  639.  
  640. Game_Party.prototype.getItemAmount = function(baseItem) {
  641.    if (!baseItem) return 0;
  642.    var amount = 0;
  643.    if (Imported.YEP_ItemCore) {
  644.       var maxItems = 0;
  645.       if (DataManager.isItem(baseItem)) {
  646.          maxItems = Yanfly.Param.ItemMaxItems;
  647.       }
  648.       if (DataManager.isWeapon(baseItem))  {
  649.          maxItems = Yanfly.Param.ItemMaxWeapons;
  650.       }
  651.       if (DataManager.isArmor(baseItem))  {
  652.          maxItems = Yanfly.Param.ItemMaxArmors;
  653.       }        
  654.       if (maxItems > 0) {
  655.          var nonIndep;
  656.          if (typeof baseItem.nonIndepdent === "boolean") nonIndep = baseItem.nonIndepdent;
  657.          if (typeof baseItem.nonIndependent === "boolean") nonIndep = baseItem.nonIndependent;
  658.          if (nonIndep === false) {
  659.             if (DataManager.isItem(baseItem)) {
  660.                baseItem = ( baseItem.baseItemId ? $dataItems[baseItem.baseItemId] : baseItem );
  661.                var group = this.items();
  662.             }
  663.             if (DataManager.isWeapon(baseItem))  {
  664.                baseItem = ( baseItem.baseItemId ? $dataWeapons[baseItem.baseItemId] : baseItem );
  665.                var group = this.weapons();
  666.             }
  667.             if (DataManager.isArmor(baseItem))  {
  668.                baseItem = ( baseItem.baseItemId ? $dataArmors[baseItem.baseItemId] : baseItem );
  669.                var group = this.armors();
  670.             }        
  671.             var baseItemId = baseItem.id;
  672.             for (var i = 0; i < group.length; ++i) {
  673.                var item = group[i];
  674.                if (!item) continue;
  675.                if (!item.baseItemId) continue;
  676.                if (item.baseItemId !== baseItemId) continue;
  677.                amount += 1;
  678.             }
  679.             return amount;
  680.          }
  681.       }
  682.    }
  683.    if ( DataManager.isItem(baseItem) && $gameParty._items[baseItem.id]) amount = $gameParty._items[baseItem.id];
  684.    if ( DataManager.isArmor(baseItem) && $gameParty._armors[baseItem.id]) amount = $gameParty._armors[baseItem.id];
  685.    if ( DataManager.isWeapon(baseItem) && $gameParty._weapons[baseItem.id]) amount = $gameParty._weapons[baseItem.id];
  686.    return amount;
  687. }
  688.  
  689. Unco.AS.Game_BattlerBase_canPaySkillCost =
  690.    Game_BattlerBase.prototype.canPaySkillCost;
  691. Game_BattlerBase.prototype.canPaySkillCost = function(skill) {
  692.    if (this.isActor()) {
  693.       if (!this.canPaySkillAmmoCost(skill)) return false;
  694.    }
  695.    return Unco.AS.Game_BattlerBase_canPaySkillCost.call(this, skill);
  696. };
  697.  
  698. Game_BattlerBase.prototype.getAmmoCurrentCharges = function(item) {
  699.    if (!item) return 0;
  700.    if (Imported.YEP_ItemCore) {
  701.       if (!DataManager.isIndependent(item)) return 0;
  702.       for (var i in this.equips()) {
  703.          if ((typeof this.equips()[i] !== 'undefined') && (this.equips()[i] !== null)) {
  704.             if (typeof this.equips()[i].baseItemId !== 'undefined') {
  705.                if ((this.equips()[i].baseItemId === item.id) && (this.equips()[i]._dataClass === item._dataClass)) {
  706.                   return this.equips()[i].ammoCurrentCharges;
  707.                }
  708.             }        
  709.          }
  710.       }
  711.    }
  712.    return 0;
  713. };
  714.  
  715. Game_BattlerBase.prototype.addAmmoCurrentCharges = function(item,amount) {
  716.    if (!item) return;
  717.    if (Imported.YEP_ItemCore) {
  718.       if (!DataManager.isIndependent(item)) return 0;
  719.       for (var i in this.equips()) {
  720.          if ((typeof this.equips()[i] !== 'undefined') && (this.equips()[i] !== null)) {
  721.             if (typeof this.equips()[i].baseItemId !== 'undefined') {
  722.                if ((this.equips()[i].baseItemId === item.id) && (this.equips()[i]._dataClass === item._dataClass)) {
  723.                   this.equips()[i].ammoCurrentCharges = parseInt(this.equips()[i].ammoCurrentCharges);
  724.                   this.equips()[i].ammoCharges = parseInt(this.equips()[i].ammoCharges);
  725.                   this.equips()[i].ammoCurrentCharges += amount;
  726.                   if (this.equips()[i].ammoCurrentCharges > this.equips()[i].ammoCharges) {
  727.                      this.equips()[i].ammoCurrentCharges = this.equips()[i].ammoCharges;
  728.                   }
  729.                   if (this.equips()[i].ammoCurrentCharges < 0) {
  730.                      this.equips()[i].ammoCurrentCharges = 0;
  731.                   }
  732.                   break;
  733.                }
  734.             }        
  735.          }
  736.       }
  737.    }
  738. };
  739.  
  740. Game_BattlerBase.prototype.fillAmmoCharges = function(item) {
  741.    if (!item) return;
  742.    if (Imported.YEP_ItemCore) {
  743.       if (!DataManager.isIndependent(item)) return 0;
  744.       for (var i in this.equips()) {
  745.          if ((typeof this.equips()[i] !== 'undefined') && (this.equips()[i] !== null)) {
  746.             if (typeof this.equips()[i].baseItemId !== 'undefined') {
  747.                if (this.equips()[i].baseItemId === item.id) {
  748.                   this.equips()[i].ammoCurrentCharges = this.equips()[i].ammoCharges;
  749.                }
  750.             }        
  751.          }
  752.       }
  753.    }
  754. };
  755.  
  756. Game_BattlerBase.prototype.canPaySkillAmmoCost = function(skill) {
  757.    if (skill.id === this.attackSkillId()) {
  758.       if (typeof this._equips !== 'undefined') {
  759.          if (this._equips[0]._itemId > 0) {
  760.             if ( !Unco.AS.hasAmmoCost(skill) ) {
  761.                skill = $dataWeapons[ ( (typeof $dataWeapons[this._equips[0]._itemId].baseItemId === 'undefined') ? this._equips[0]._itemId : $dataWeapons[this._equips[0]._itemId].baseItemId ) ];
  762.             }
  763.          }
  764.       }
  765.    }
  766.    for (var switchId in skill.ammoGameSwitch) {
  767.       switchId = parseInt(switchId);
  768.       if (!isNaN(switchId) && (switchId > 0)) {
  769.          if ($gameSwitches.value(switchId) === false) {
  770.             return false;
  771.          }
  772.       }
  773.    }
  774.    if (!this.canPaySkillReloadAmmoCost(skill)) return false;
  775.    if (!this.canPaySkillItemAmmoCost(skill)) return false;
  776.    if (!this.canPaySkillEquipAmmoCost(skill)) return false;
  777.    if (!this.canPaySkillEquipChargeAmmoCost(skill)) return false;
  778.    return true;
  779. };
  780.  
  781. Game_BattlerBase.prototype.canPaySkillReloadAmmoCost = function(skill) {
  782.    if ((typeof skill.ammoLoadIndex === 'number') && (typeof skill.ammoLoadSlot === 'number')) {
  783.       if (this.hasArmor($dataArmors[skill.ammoLoadIndex]) || ($gameParty.getItemAmount($dataArmors[skill.ammoLoadIndex]) < 1)) {
  784.          return false;
  785.       }
  786.    }
  787.    return true;
  788. };
  789.  
  790. Game_BattlerBase.prototype.canPaySkillItemAmmoCost = function(skill) {
  791.    if (typeof skill.goldCost === 'number') {
  792.       if (skill.goldCost > $gameParty.gold()) {
  793.          return false;
  794.       }
  795.    }
  796.    for (var ammoId in skill.itemAmmoCost) {
  797.       ammoId = parseInt(ammoId);
  798.       if (!isNaN(ammoId) && (ammoId > 0)) {
  799.          var nbOwned = $gameParty.getItemAmount($dataItems[ammoId]);
  800.          if (skill.itemAmmoCost[ammoId] > nbOwned) {
  801.             return false;
  802.          }
  803.       }
  804.    }
  805.    return true;
  806. };
  807.  
  808. Game_BattlerBase.prototype.canPaySkillEquipAmmoCost = function(skill) {
  809.    if (!this.canPaySkillArmorAmmoCost(skill)) return false;
  810.    if (!this.canPaySkillWeaponAmmoCost(skill)) return false;
  811.    return true;
  812. };
  813.  
  814. Game_BattlerBase.prototype.canPaySkillArmorAmmoCost = function(skill) {
  815.    var retVal = true;
  816.    for (var ammoId in skill.equipAmmoCost) {
  817.       ammoId = parseInt(ammoId);
  818.       if (!isNaN(ammoId) && (ammoId > 0)) {
  819.          if (this.hasArmor($dataArmors[ammoId])) {
  820.             skill.equipAmmoCost[ammoId] = parseInt(skill.equipAmmoCost[ammoId]);
  821.             if (!isNaN(skill.equipAmmoCost[ammoId])) {
  822.                var nbOwned = 1+$gameParty.getItemAmount($dataArmors[ammoId]);
  823.                if (skill.equipAmmoCost[ammoId] <= nbOwned) {
  824.                   return true;
  825.                } else retVal = false;
  826.             } else retVal = false;
  827.          } else retVal = false;
  828.       }
  829.    }
  830.    return retVal;
  831. };
  832.  
  833. Game_BattlerBase.prototype.canPaySkillWeaponAmmoCost = function(skill) {
  834.    var retVal = true;
  835.    for (var ammoId in skill.weaponAmmoCost) {
  836.       ammoId = parseInt(ammoId);
  837.       if (!isNaN(ammoId) && (ammoId > 0)) {
  838.          if (this.hasWeapon($dataWeapons[ammoId])) {
  839.             skill.weaponAmmoCost[ammoId] = parseInt(skill.weaponAmmoCost[ammoId]);
  840.             if (!isNaN(skill.weaponAmmoCost[ammoId])) {
  841.                var nbOwned = 1+$gameParty.getItemAmount($dataWeapons[ammoId]);
  842.                if (skill.weaponAmmoCost[ammoId] <= nbOwned) {
  843.                   return true;
  844.                } else retVal = false;
  845.             } else retVal = false;
  846.          } else retVal = false;
  847.       }
  848.    }
  849.    return retVal;
  850. };
  851.  
  852. Game_BattlerBase.prototype.canPaySkillEquipChargeAmmoCost = function(skill) {
  853.    if (!this.canPaySkillArmorChargeAmmoCost(skill)) return false;
  854.    if (!this.canPaySkillWeaponChargeAmmoCost(skill)) return false;
  855.    return true;
  856. };
  857.  
  858. Game_BattlerBase.prototype.canPaySkillArmorChargeAmmoCost = function(skill) {
  859.    var retVal = true;
  860.    for (var ammoId in skill.equipChargeAmmoCost) {
  861.       ammoId = parseInt(ammoId);
  862.       if (!isNaN(ammoId) && (ammoId > 0)) {
  863.          if (this.hasArmor($dataArmors[ammoId])) {
  864.             var chargeCost = parseInt(skill.equipChargeAmmoCost[ammoId]);
  865.             if (!isNaN(chargeCost)) {
  866.                var nbOwned = this.getAmmoCurrentCharges($dataArmors[ammoId]);
  867.                if (chargeCost <= nbOwned) {
  868.                   return true;
  869.                } else retVal = false;    
  870.             } else retVal = false;
  871.          } else retVal = false;
  872.       }
  873.    }
  874.    return retVal;
  875. };
  876.  
  877. Game_BattlerBase.prototype.canPaySkillWeaponChargeAmmoCost = function(skill) {
  878.    var retVal = true;
  879.    for (var ammoId in skill.weaponChargeAmmoCost) {
  880.       ammoId = parseInt(ammoId);
  881.       if (!isNaN(ammoId) && (ammoId > 0)) {
  882.          if (this.hasWeapon($dataWeapons[ammoId])) {
  883.             var chargeCost = parseInt(skill.weaponChargeAmmoCost[ammoId]);
  884.             if (!isNaN(chargeCost)) {
  885.                var nbOwned = this.getAmmoCurrentCharges($dataWeapons[ammoId]);
  886.                if (chargeCost <= nbOwned) {
  887.                   return true;
  888.                } else retVal = false;    
  889.             } else retVal = false;
  890.          } else retVal = false;
  891.       }
  892.    }
  893.    return retVal;
  894. };
  895.  
  896. Unco.AS.Game_BattlerBase_paySkillCost = Game_BattlerBase.prototype.paySkillCost;
  897. Game_BattlerBase.prototype.paySkillCost = function(skill) {
  898.     Unco.AS.Game_BattlerBase_paySkillCost.call(this, skill);
  899.     if (this.constructor.name === 'Game_Actor') this.paySkillAmmoCost(skill);
  900. };
  901.  
  902. Game_BattlerBase.prototype.paySkillAmmoCost = function(skill) {
  903.    if (skill.id === this.attackSkillId()) {
  904.       if (typeof this._equips !== 'undefined') {
  905.          if (this._equips[0]._itemId > 0) {
  906.             if ( !Unco.AS.hasAmmoCost(skill) ) {
  907.                 skill = $dataWeapons[ ( (typeof $dataWeapons[this._equips[0]._itemId].baseItemId === 'undefined') ? this._equips[0]._itemId : $dataWeapons[this._equips[0]._itemId].baseItemId ) ];
  908.             }            
  909.          }
  910.       }
  911.    }
  912.    this.reloadAmmo(skill);
  913.    this.paySkillItemAmmoCost(skill);
  914.    this.paySkillEquipAmmoCost(skill);
  915.    this.paySkillEquipChargeAmmoCost(skill);
  916. };
  917.  
  918. Game_BattlerBase.prototype.reloadAmmo = function(skill) {
  919.    if ((typeof skill.ammoLoadIndex === 'number') && (typeof skill.ammoLoadSlot === 'number')) {
  920.       var loadSlot = skill.ammoLoadSlot;
  921.       var legitLoadSlots = this.equippableSlotsFor($dataArmors[skill.ammoLoadIndex]);
  922.       if (legitLoadSlots.contains(loadSlot) === false) {
  923.          loadSlot = legitLoadSlots[0];
  924.       }
  925.       this.changeEquipById(loadSlot,skill.ammoLoadIndex);
  926.    }
  927. };
  928.  
  929. Game_BattlerBase.prototype.paySkillItemAmmoCost = function(skill) {
  930.    if (typeof skill.goldCost === 'number') {
  931.       $gameParty.loseGold(skill.goldCost);
  932.    }
  933.    for (var ammoId in skill.itemAmmoCost) {
  934.       ammoId = parseInt(ammoId);
  935.       if (!isNaN(ammoId) && (ammoId > 0)) {
  936.          $gameParty.gainItem($dataItems[ammoId],-skill.itemAmmoCost[ammoId]);
  937.       }
  938.    }
  939. };
  940.  
  941. Game_BattlerBase.prototype.paySkillEquipAmmoCost = function(skill) {
  942.    for (var ammoId in skill.equipAmmoCost) {
  943.       ammoId = parseInt(ammoId);
  944.       if (!isNaN(ammoId) && (ammoId > 0)) {
  945.          skill.equipAmmoCost[ammoId] = parseInt(skill.equipAmmoCost[ammoId]);
  946.          if (this.hasArmor($dataArmors[ammoId]) && !isNaN(skill.equipAmmoCost[ammoId]) && (skill.equipAmmoCost[ammoId] > 0)) {
  947.             this._markForEquipDiscard = ammoId;
  948.             if ($gameParty.getItemAmount($dataArmors[ammoId]) > 0) {
  949.                $gameParty.gainItem($dataArmors[ammoId],-Math.max(skill.equipAmmoCost[ammoId]-1,0));
  950.             }
  951.          }
  952.       }
  953.    }
  954.    for (var ammoId in skill.weaponAmmoCost) {
  955.       ammoId = parseInt(ammoId);
  956.       if (!isNaN(ammoId) && (ammoId > 0)) {
  957.          skill.weaponAmmoCost[ammoId] = parseInt(skill.weaponAmmoCost[ammoId]);
  958.          if (this.hasWeapon($dataWeapons[ammoId]) && !isNaN(skill.weaponAmmoCost[ammoId]) && (skill.weaponAmmoCost[ammoId] > 0)) {
  959.             this._markForWeaponDiscard = ammoId;
  960.             if ($gameParty.getItemAmount($dataWeapons[ammoId]) > 0) {
  961.                $gameParty.gainItem($dataWeapons[ammoId],-Math.max(skill.weaponAmmoCost[ammoId]-1,0));
  962.             }
  963.          }
  964.       }
  965.    }
  966. };
  967.  
  968. Game_BattlerBase.prototype.paySkillEquipChargeAmmoCost = function(skill) {
  969.    for (var ammoId in skill.equipChargeAmmoCost) {
  970.       ammoId = parseInt(ammoId);
  971.       if (!isNaN(ammoId) && (ammoId > 0)) {
  972.          var chargeCost = parseInt(skill.equipChargeAmmoCost[ammoId]);
  973.          if (this.hasArmor($dataArmors[ammoId]) && !isNaN(chargeCost) && (chargeCost > 0)) {
  974.             this.addAmmoCurrentCharges($dataArmors[ammoId], -chargeCost);
  975.             if (this.getAmmoCurrentCharges($dataArmors[ammoId]) <= 0) {
  976.                this._markForEquipDiscard = ammoId;
  977.             }
  978.          }
  979.       }
  980.    }
  981.    for (var ammoId in skill.weaponChargeAmmoCost) {
  982.       ammoId = parseInt(ammoId);
  983.       if (!isNaN(ammoId) && (ammoId > 0)) {
  984.          var chargeCost = parseInt(skill.weaponChargeAmmoCost[ammoId]);
  985.          if (this.hasWeapon($dataWeapons[ammoId]) && !isNaN(chargeCost ) && (chargeCost  > 0)) {
  986.             this.addAmmoCurrentCharges($dataWeapons[ammoId], -chargeCost);
  987.             if (this.getAmmoCurrentCharges($dataWeapons[ammoId]) <= 0) {
  988.                this._markForWeaponDiscard = ammoId;
  989.             }
  990.          }
  991.       }
  992.    }
  993. };
  994.  
  995.  
  996. //=============================================================================
  997. // BattleManager
  998. //=============================================================================
  999. //
  1000. // Management of post-action skill cost application:
  1001. // - un-equip current ammo,
  1002. // - re-equip one if available in inventory.
  1003. //
  1004.  
  1005. Unco.AS.BattleManager_invokeNormalAction = BattleManager.invokeNormalAction;
  1006. BattleManager.invokeNormalAction = function(subject, target) {
  1007.    Unco.AS.BattleManager_invokeNormalAction.call(this,subject,target);
  1008.    if (typeof this._subject._markForEquipDiscard !== 'undefined') {
  1009.       for (var i in this._subject.equips()) {
  1010.          if ((typeof this._subject.equips()[i] !== 'undefined') && (this._subject.equips()[i] !== null)) {
  1011.             if (typeof this._subject.equips()[i].baseItemId !== 'undefined') {
  1012.                if (this._subject.equips()[i].baseItemId === this._subject._markForEquipDiscard) {
  1013.                   this._subject._markForEquipDiscard = this._subject.equips()[i].id;
  1014.                }
  1015.             }        
  1016.          }
  1017.       }
  1018.       if ( (typeof $dataArmors[this._subject._markForEquipDiscard].ammoCurrentCharges === 'number')
  1019.         && ($dataArmors[this._subject._markForEquipDiscard].ammoCurrentCharges === 0)
  1020.         && (typeof $dataArmors[this._subject._markForEquipDiscard].ammoMorphIfEmpty === 'number')  )
  1021.       {
  1022.          $gameParty.gainItem($dataItems[ $dataArmors[this._subject._markForEquipDiscard].ammoMorphIfEmpty ] , 1);
  1023.       }
  1024.       this._subject.discardEquip($dataArmors[this._subject._markForEquipDiscard]);  
  1025.       if (($gameParty.getItemAmount($dataArmors[ this._subject._markForEquipDiscard ]) > 0) && (!$dataArmors[ this._subject._markForEquipDiscard ].ammoCharges)) {
  1026.          var loadSlot = this._subject.equippableSlotsFor($dataArmors[ this._subject._markForEquipDiscard ])[0];
  1027.          var ammoId = ($dataArmors[ this._subject._markForEquipDiscard ].baseItemId) ? ($dataArmors[ this._subject._markForEquipDiscard ].baseItemId) : this._subject._markForEquipDiscard;
  1028.          this._subject.changeEquipById(loadSlot,ammoId);
  1029.       }    
  1030.       delete this._subject._markForEquipDiscard;
  1031.    }
  1032.    if (typeof this._subject._markForWeaponDiscard !== 'undefined') {
  1033.       for (var i in this._subject.equips()) {
  1034.          if ((typeof this._subject.equips()[i] !== 'undefined') && (this._subject.equips()[i] !== null)) {
  1035.             if (typeof this._subject.equips()[i].baseItemId !== 'undefined') {
  1036.                if (this._subject.equips()[i].baseItemId === this._subject._markForWeaponDiscard) {
  1037.                   this._subject._markForWeaponDiscard = this._subject.equips()[i].id;
  1038.                }
  1039.             }        
  1040.          }
  1041.       }
  1042.       if ( (typeof $dataWeapons[this._subject._markForWeaponDiscard].ammoCurrentCharges === 'number')
  1043.         && ($dataWeapons[this._subject._markForWeaponDiscard].ammoCurrentCharges === 0)
  1044.         && (typeof $dataWeapons[this._subject._markForWeaponDiscard].ammoMorphIfEmpty === 'number')  )
  1045.       {
  1046.          $gameParty.gainItem($dataItems[ $dataWeapons[this._subject._markForWeaponDiscard].ammoMorphIfEmpty ] , 1);
  1047.       }
  1048.       this._subject.discardEquip($dataWeapons[this._subject._markForWeaponDiscard]);  
  1049.       if (($gameParty.getItemAmount($dataWeapons[ this._subject._markForWeaponDiscard ]) > 0) && (!$dataWeapons[ this._subject._markForWeaponDiscard ].ammoCharges)) {
  1050.          var loadSlot = this._subject.equippableSlotsFor($dataWeapons[ this._subject._markForWeaponDiscard ])[0];
  1051.          var ammoId = ($dataWeapons[ this._subject._markForWeaponDiscard ].baseItemId) ? ($dataWeapons[ this._subject._markForWeaponDiscard ].baseItemId) : this._subject._markForWeaponDiscard;
  1052.          this._subject.changeEquipById(loadSlot,ammoId);
  1053.       }        
  1054.       delete this._subject._markForWeaponDiscard;
  1055.    }
  1056. };
  1057.  
  1058. //=============================================================================
  1059. // Window_SkillList
  1060. //=============================================================================
  1061.  
  1062. if ((typeof Imported.YEP_SkillCore === 'undefined') || (Imported.YEP_SkillCore !== true)) {  
  1063.    Window_SkillList.prototype.drawSkillCost = function(skill, x, y, width) {
  1064.       var dw = width;
  1065.       if (this._actor.skillTpCost(skill) > 0) {
  1066.          this.changeTextColor(this.tpCostColor());
  1067.          var text = this._actor.skillTpCost(skill);
  1068.          this.drawText(text, x, y, dw, 'right');
  1069.          dw -= this.textWidth(text);
  1070.       }
  1071.       if (dw !== width) {
  1072.          var text = ' ';
  1073.          this.drawText(text, x, y, dw, 'right');
  1074.          dw -= this.textWidth(text);
  1075.       }
  1076.       if (this._actor.skillMpCost(skill) > 0) {
  1077.          this.changeTextColor(this.mpCostColor());
  1078.          var text = this._actor.skillMpCost(skill)
  1079.          this.drawText(text, x, y, dw, 'right');
  1080.          dw -= this.textWidth(text);
  1081.       }
  1082.       return dw;
  1083.    }  
  1084. }
  1085.  
  1086.  
  1087. Unco.AS.Window_SkillList_drawSkillCost = Window_SkillList.prototype.drawSkillCost;  
  1088.    
  1089. Window_SkillList.prototype.drawSkillCost = function(skill, wx, wy, width) {
  1090.    var dw = width;
  1091.    dw = this.drawAllAmmoCosts(skill, wx, wy, dw);
  1092.    return Unco.AS.Window_SkillList_drawSkillCost.call(this,skill, wx, wy, dw);
  1093. };
  1094.    
  1095. Window_SkillList.prototype.drawAmmoCost = function(cost, icon, itemAmountToDisplay, wx, wy, dw) {
  1096.    this.changeTextColor(this.textColor(Unco.Param.ammoFontColor));
  1097.    var text = '';
  1098.    if (Unco.Param.compactCostDisplay === 'false') text = text + 'x';
  1099.    text = text + String(cost);
  1100.    if (Unco.Param.compactCostDisplay === 'false') text = text + ( (itemAmountToDisplay === "") ? "" : (  "/" + itemAmountToDisplay  )  );
  1101.    this.contents.fontSize = Unco.Param.ammoFontSize;
  1102.    if (Unco.Param.compactCostDisplay === 'false') this.drawText(text, wx, wy, dw, 'right');
  1103.    if (Unco.Param.compactCostDisplay === 'false') dw -= this.textWidth(text);
  1104.    if (icon > 0) {
  1105.       var iw = wx + dw - Window_Base._iconWidth;
  1106.       this.drawIcon(icon, iw, wy + 2);
  1107.       if (Unco.Param.compactCostDisplay === 'true') {
  1108.          this.drawText(text, iw, wy, Window_Base._iconWidth, 'center');
  1109.       }
  1110.       dw -= Window_Base._iconWidth + 2;
  1111.    }
  1112.    this.resetFontSettings();
  1113.    return dw;
  1114. }
  1115.  
  1116. Window_SkillList.prototype.drawAllAmmoCosts = function(skill, wx, wy, dw) {
  1117.    //---------------------------------------------------//
  1118.    // - Gold Cost
  1119.    if (typeof skill.goldCost === 'number') {
  1120.       dw = this.drawAmmoCost(skill.goldCost, Unco.Param.goldAmmoIconId, "", wx, wy, dw);
  1121.    }
  1122.    //---------------------------------------------------//
  1123.    // - Item Cost
  1124.    for (var ammoId in skill.itemAmmoCost) {
  1125.       ammoId = parseInt(ammoId);
  1126.       if (!isNaN(ammoId) && (ammoId > 0)) {
  1127.          var ammoCost = skill.itemAmmoCost[ammoId];
  1128.          var icon = $dataItems[ammoId].iconIndex;
  1129.          var amountText = ( (Unco.Param.showAmmoLeft === 'false') ? "" : (  "/" + $gameParty.getItemAmount($dataItems[ammoId])  )  );
  1130.          dw = this.drawAmmoCost(ammoCost, icon, amountText, wx, wy, dw);
  1131.       }
  1132.    }
  1133.    //---------------------------------------------------//
  1134.    // - Armor Cost
  1135.    var zeroArmorAmmo = false;
  1136.    for (var ammoId in skill.equipAmmoCost) {
  1137.       var ammoId = parseInt(ammoId);
  1138.       if (!isNaN(ammoId) && (ammoId > 0)) {
  1139.          if (this._actor.hasArmor($dataArmors[ammoId])) {
  1140.             var ammoCost = skill.equipAmmoCost[ammoId];
  1141.             var icon = $dataArmors[ammoId].iconIndex;
  1142.             var amountText = ( (Unco.Param.showAmmoLeft === 'false') ? "" : (  "/" + ( 1 + $gameParty.getItemAmount($dataArmors[ammoId]) )  )  );
  1143.             dw = this.drawAmmoCost(ammoCost, icon, amountText, wx, wy, dw);
  1144.             zeroArmorAmmo = false;
  1145.             break;
  1146.          } else {
  1147.             zeroArmorAmmo = true;
  1148.             if (typeof smallestCost !== 'Number') {
  1149.                var smallestCost = skill.equipAmmoCost[ammoId];
  1150.             } else {
  1151.                if (skill.equipAmmoCost[ammoId] < smallestCost) smallestCost = skill.equipAmmoCost[ammoId];
  1152.             }
  1153.          }
  1154.       }
  1155.    }
  1156.    if (zeroArmorAmmo === true) {
  1157.       var ammoCost = smallestCost;
  1158.       var icon = ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId );
  1159.       dw = this.drawAmmoCost(ammoCost, icon, "", wx, wy, dw);
  1160.    }
  1161.    //---------------------------------------------------//
  1162.    // - Weapon Cost
  1163.    var zeroWeaponAmmo = false;
  1164.    for (var ammoId in skill.weaponAmmoCost) {
  1165.       var ammoId = parseInt(ammoId);
  1166.       if (!isNaN(ammoId) && (ammoId > 0)) {
  1167.          if (this._actor.hasWeapon($dataWeapons[ammoId])) {
  1168.             var ammoCost = skill.weaponAmmoCost[ammoId];
  1169.             var icon = $dataWeapons[ammoId].iconIndex;
  1170.             var amountText = ( (Unco.Param.showAmmoLeft === 'false') ? "" : (  "/" + ( 1 + $gameParty.getItemAmount($dataWeapons[ammoId]) )  )  );
  1171.             dw = this.drawAmmoCost(ammoCost, icon, amountText, wx, wy, dw);
  1172.             zeroWeaponAmmo = false;
  1173.             break;
  1174.          } else {
  1175.             zeroWeaponAmmo = true;
  1176.             if (typeof smallestCost !== 'Number') {
  1177.                var smallestCost = skill.weaponAmmoCost[ammoId];
  1178.             } else {
  1179.                if (skill.weaponAmmoCost[ammoId] < smallestCost) smallestCost = skill.weaponAmmoCost[ammoId];
  1180.             }
  1181.          }
  1182.       }
  1183.    }
  1184.    if (zeroWeaponAmmo === true) {
  1185.       var ammoCost = smallestCost;
  1186.       var icon = ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId );
  1187.       dw = this.drawAmmoCost(ammoCost, icon, "", wx, wy, dw);
  1188.    }
  1189.    //---------------------------------------------------//
  1190.    // - Charge Armor Cost
  1191.    var zeroChargeArmorAmmo = false;
  1192.    for (var ammoId in skill.equipChargeAmmoCost) {
  1193.       var ammoId = parseInt(ammoId);
  1194.       if (!isNaN(ammoId) && (ammoId > 0)) {
  1195.          if (this._actor.hasArmor($dataArmors[ammoId])) {
  1196.             var ammoCost = skill.equipChargeAmmoCost[ammoId];
  1197.             var icon = $dataArmors[ammoId].iconIndex;
  1198.             var amountText = ( (Unco.Param.showAmmoLeft === 'false') ? "" : (  "/" + this._actor.getAmmoCurrentCharges( $dataArmors[ammoId] )  )  );
  1199.             dw = this.drawAmmoCost(ammoCost, icon, amountText, wx, wy, dw);
  1200.             zeroChargeArmorAmmo = false;
  1201.             break;
  1202.          } else {
  1203.             zeroChargeArmorAmmo = true;
  1204.             if (typeof smallestCost !== 'Number') {
  1205.                var smallestCost = skill.equipChargeAmmoCost[ammoId];
  1206.             } else {
  1207.                if (skill.equipChargeAmmoCost[ammoId] < smallestCost) smallestCost = skill.equipChargeAmmoCost[ammoId];
  1208.             }
  1209.          }
  1210.       }
  1211.    }
  1212.    if (zeroChargeArmorAmmo === true) {
  1213.       var ammoCost = smallestCost;
  1214.       var icon = ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId );
  1215.       dw = this.drawAmmoCost(ammoCost, icon, "", wx, wy, dw);
  1216.    }
  1217.    //---------------------------------------------------//
  1218.    // - Charge Weapon Cost
  1219.    var zeroChargeWeaponAmmo = false;
  1220.    for (var ammoId in skill.weaponChargeAmmoCost) {
  1221.       var ammoId = parseInt(ammoId);
  1222.       if (!isNaN(ammoId) && (ammoId > 0)) {
  1223.          if (this._actor.hasWeapon($dataWeapons[ammoId])) {
  1224.             var ammoCost = skill.weaponChargeAmmoCost[ammoId];
  1225.             var icon = $dataWeapons[ammoId].iconIndex;
  1226.             var amountText = ( (Unco.Param.showAmmoLeft === 'false') ? "" : (  "/" + this._actor.getAmmoCurrentCharges( $dataWeapons[ammoId] )  )  );
  1227.             dw = this.drawAmmoCost(ammoCost, icon, amountText, wx, wy, dw);
  1228.             zeroChargeWeaponAmmo = false;
  1229.             break;
  1230.          } else {
  1231.             zeroChargeWeaponAmmo = true;
  1232.             if (typeof smallestCost !== 'Number') {
  1233.                var smallestCost = skill.weaponChargeAmmoCost[ammoId];
  1234.             } else {
  1235.                if (skill.weaponChargeAmmoCost[ammoId] < smallestCost) smallestCost = skill.weaponChargeAmmoCost[ammoId];
  1236.             }
  1237.          }
  1238.       }
  1239.    }
  1240.    if (zeroChargeWeaponAmmo === true) {
  1241.       var ammoCost = smallestCost;
  1242.       var icon = ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId );
  1243.       dw = this.drawAmmoCost(ammoCost, icon, "", wx, wy, dw);
  1244.    }
  1245.    return dw;
  1246. };
  1247.  
  1248.  
  1249. //=============================================================================
  1250. // Window_Help
  1251. //=============================================================================
  1252.  
  1253. Window_Help.prototype.getAmmoAmountText = function(item) {
  1254.    var text = '';
  1255.    if (typeof item !== 'undefined') {
  1256.       var introText = ( (typeof item.ammoText !== 'undefined') ? item.ammoText : Unco.Param.descAmmoLeftText);
  1257.       if ((DataManager.isSkill(item)) && (Unco.Param.showAmmoLeftInDesc === 'true') && introText !== "") {
  1258.          var skill = item;
  1259.          var withAmmo = false;
  1260.          //---------------------------------------------------//
  1261.          // - Gold Cost
  1262.          if (typeof skill.goldCost === 'number') {
  1263.             text = text + '\\i[' + String(Unco.Param.goldAmmoIconId) + ']';
  1264.             text = text + 'x' + $gameParty.gold();
  1265.             withAmmo = true;
  1266.          }
  1267.          //---------------------------------------------------//
  1268.          // - Item Cost
  1269.          for (var ammoId in skill.itemAmmoCost) {
  1270.             var cost = skill.itemAmmoCost[ammoId];
  1271.             ammoId = parseInt(ammoId);
  1272.             if (!isNaN(ammoId) && (ammoId > 0) && !isNaN(cost)) {
  1273.                var cost = parseInt(cost);
  1274.                var itemOwned = ($gameParty.getItemAmount($dataItems[ammoId]) > 0);
  1275.                text = text + '\\i[' + String($dataItems[ammoId].iconIndex) + ']';
  1276.                text = text + ( (typeof skill.showAmmoName === 'undefined') ? '' : $dataItems[ammoId].name + ' ' );
  1277.                text = text + ( ((cost <= 0) && itemOwned) ? '' : ( 'x' + String( $gameParty.getItemAmount($dataItems[ammoId]) ) )  );
  1278.                withAmmo = true;
  1279.             }
  1280.          }
  1281.          //---------------------------------------------------//
  1282.          // - Armor Cost
  1283.          var zeroEquipAmmo = false;
  1284.          for (var ammoId in skill.equipAmmoCost) {
  1285.             var cost = skill.equipAmmoCost[ammoId];
  1286.             var ammoId = parseInt(ammoId);
  1287.             if (!isNaN(ammoId) && (ammoId > 0) && (typeof this._actor !== 'undefined')) {
  1288.                cost = parseInt(cost);
  1289.                withAmmo = true;
  1290.                if (this._actor.hasArmor($dataArmors[ammoId])) {
  1291.                   text = text + '\\i[' + String($dataArmors[ammoId].iconIndex) + ']';
  1292.                   text = text + ( (typeof skill.showAmmoName === 'undefined') ? '' : $dataArmors[ammoId].name + ' ' );
  1293.                   text = text + ( (cost <= 0) ? '' : 'x' + String( 1 + $gameParty.getItemAmount($dataArmors[ammoId]) ) );
  1294.                   text = text + ( (typeof $dataArmors[ammoId].ammoDesc === 'undefined') ? '' : '(' + $dataArmors[ammoId].ammoDesc + ')' );
  1295.                   zeroEquipAmmo = false;
  1296.                   break;
  1297.                } else {
  1298.                   zeroEquipAmmo = true;
  1299.                }
  1300.             }
  1301.          }
  1302.          if (zeroEquipAmmo === true) text = text + '\\i[' + String( ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId ) ) + ']x0';
  1303.          //---------------------------------------------------//
  1304.          // - Weapon Cost
  1305.          var zeroWeaponAmmo = false;
  1306.          for (var ammoId in skill.weaponAmmoCost) {
  1307.             var cost = skill.weaponAmmoCost[ammoId];
  1308.             var ammoId = parseInt(ammoId);
  1309.             if (!isNaN(ammoId) && (ammoId > 0) && (typeof this._actor !== 'undefined')) {
  1310.                cost = parseInt(cost);
  1311.                withAmmo = true;
  1312.                if (this._actor.hasWeapon($dataWeapons[ammoId])) {
  1313.                   text = text + '\\i[' + String($dataWeapons[ammoId].iconIndex) + ']';
  1314.                   text = text + ( (typeof skill.showAmmoName === 'undefined') ? '' : $dataWeapons[ammoId].name + ' ' );
  1315.                   text = text + ( (cost <= 0) ? '' : 'x' + String( 1 + $gameParty.getItemAmount($dataWeapons[ammoId]) ) );
  1316.                   text = text + ( (typeof $dataWeapons[ammoId].ammoDesc === 'undefined') ? '' : '(' + $dataWeapons[ammoId].ammoDesc + ')' );
  1317.                   zeroWeaponAmmo = false;
  1318.                   break;
  1319.                } else {
  1320.                   zeroWeaponAmmo = true;
  1321.                }
  1322.             }
  1323.          }
  1324.          if (zeroWeaponAmmo === true) text = text + '\\i[' + String( ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId ) ) + ']x0';
  1325.          //---------------------------------------------------//
  1326.          // - Charge Armor Cost
  1327.          var zeroChargeEquipAmmo = false;
  1328.          for (var ammoId in skill.equipChargeAmmoCost) {
  1329.             var cost = skill.equipChargeAmmoCost[ammoId];
  1330.             var ammoId = parseInt(ammoId);
  1331.             if (!isNaN(ammoId) && (ammoId > 0) && (typeof this._actor !== 'undefined')) {
  1332.                cost = parseInt(cost);
  1333.                withAmmo = true;
  1334.                if (this._actor.hasArmor($dataArmors[ammoId])) {
  1335.                   text = text + '\\i[' + String($dataArmors[ammoId].iconIndex) + ']';
  1336.                   text = text + ( (typeof skill.showAmmoName === 'undefined') ? '' : $dataArmors[ammoId].name + ' ' );
  1337.                   text = text + ( (cost <= 0) ? '' : 'x' + String( this._actor.getAmmoCurrentCharges($dataArmors[ammoId]) ) );
  1338.                   text = text + ( (typeof $dataArmors[ammoId].ammoDesc === 'undefined') ? '' : '(' + $dataArmors[ammoId].ammoDesc + ')' );
  1339.                   zeroChargeEquipAmmo = false;
  1340.                   break;
  1341.                } else {
  1342.                   zeroChargeEquipAmmo = true;
  1343.                }
  1344.             }
  1345.          }
  1346.          if (zeroChargeEquipAmmo === true) text = text + '\\i[' + String( ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId ) ) + ']x0';
  1347.          //---------------------------------------------------//
  1348.          // - Charge Weapon Cost
  1349.          var zeroChargeWeaponAmmo = false;
  1350.          for (var ammoId in skill.weaponChargeAmmoCost) {
  1351.             var cost = skill.weaponChargeAmmoCost[ammoId];
  1352.             var ammoId = parseInt(ammoId);
  1353.             if (!isNaN(ammoId) && (ammoId > 0) && (typeof this._actor !== 'undefined')) {
  1354.                cost = parseInt(cost);
  1355.                withAmmo = true;
  1356.                if (this._actor.hasWeapon($dataWeapons[ammoId])) {
  1357.                   text = text + '\\i[' + String($dataWeapons[ammoId].iconIndex) + ']';
  1358.                   text = text + ( (typeof skill.showAmmoName === 'undefined') ? '' : $dataWeapons[ammoId].name + ' ' );
  1359.                   text = text + ( (cost <= 0) ? '' : 'x' + String( this._actor.getAmmoCurrentCharges($dataWeapons[ammoId]) ) );
  1360.                   text = text + ( (typeof $dataWeapons[ammoId].ammoDesc === 'undefined') ? '' : '(' + $dataWeapons[ammoId].ammoDesc + ')' );
  1361.                   zeroWeaponAmmo = false;
  1362.                   break;
  1363.                } else {
  1364.                   zeroWeaponAmmo = true;
  1365.                }
  1366.             }
  1367.          }
  1368.          if (zeroChargeWeaponAmmo === true) text = text + '\\i[' + String( ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId ) ) + ']x0';
  1369.          //---------------------------------------------------//
  1370.          // - End
  1371.          if (withAmmo === true) text = '\n' + introText + ' : ' + text;
  1372.       }
  1373.    }
  1374.    return text;
  1375. }
  1376.  
  1377. Window_Help.prototype.setItem = function(item) {
  1378.    this.setText(item ? item.description + this.getAmmoAmountText(item) : '');
  1379. };
  1380.  
  1381. Unco.AS.Window_SkillList_setHelpWindowItem = Window_SkillList.prototype.setHelpWindowItem;
  1382. Window_SkillList.prototype.setHelpWindowItem = function(item) {
  1383.    if (this._helpWindow) {
  1384.       this._helpWindow._actor = this._actor;
  1385.    }
  1386.    Unco.AS.Window_SkillList_setHelpWindowItem.call(this,item)
  1387. };
  1388.  
  1389. //=============================================================================
  1390. // Window_ActorCommand
  1391. //=============================================================================
  1392.  
  1393. Window_ActorCommand.prototype.getAmmoText = function(skill) {
  1394.     var ammoStr = '';  
  1395.     if (Unco.Param.showAmmoLeftForAttack === 'true') {
  1396.           //---------------------------------------------------//
  1397.           // - Item Cost
  1398.           for (var ammoId in skill.itemAmmoCost) {
  1399.              var ammoId = parseInt(ammoId);
  1400.              var ammoCost = parseInt(skill.itemAmmoCost[ammoId]);
  1401.              if (!isNaN(ammoId) && (ammoId > 0) && !isNaN(ammoCost) && (ammoCost > 0)) {
  1402.                 if (ammoStr !== '') ammoStr += '|';
  1403.                 ammoStr += String(  $gameParty.getItemAmount($dataItems[ammoId]) );              
  1404.              }
  1405.           }
  1406.           //---------------------------------------------------//
  1407.           // - Armor Cost
  1408.           var zeroAmmo = false;
  1409.           for (var ammoId in skill.equipAmmoCost) {
  1410.              var ammoId = parseInt(ammoId);
  1411.              var ammoCost = parseInt(skill.equipAmmoCost[ammoId]);
  1412.              if (!isNaN(ammoId) && (ammoId > 0) && !isNaN(ammoCost) && (ammoCost > 0)) {
  1413.                 if (this._actor.hasArmor($dataArmors[ammoId])) {
  1414.                    if (ammoStr !== '') ammoStr += '|';
  1415.                    ammoStr += String( 1+$gameParty.getItemAmount($dataArmors[ammoId]) );
  1416.                    zeroAmmo = false;
  1417.                    break;
  1418.                 } else {
  1419.                    zeroAmmo = true;
  1420.                 }
  1421.              }
  1422.           }
  1423.           if (zeroAmmo === true) {
  1424.              if (ammoStr !== '') ammoStr += '|';
  1425.              ammoStr += '0';
  1426.           }
  1427.           //---------------------------------------------------//
  1428.           // - Weapon Cost
  1429.           var zeroWeaponAmmo = false;
  1430.           for (var ammoId in skill.weaponAmmoCost) {
  1431.              var ammoId = parseInt(ammoId);
  1432.              var ammoCost = parseInt(skill.weaponAmmoCost[ammoId]);
  1433.              if (!isNaN(ammoId) && (ammoId > 0) && !isNaN(ammoCost) && (ammoCost > 0)) {
  1434.                 if (this._actor.hasWeapon($dataWeapons[ammoId])) {
  1435.                    if (ammoStr !== '') ammoStr += '|';
  1436.                    ammoStr += String( 1+$gameParty.getItemAmount($dataWeapons[ammoId]) );
  1437.                    zeroWeaponAmmo = false;
  1438.                    break;
  1439.                 } else {
  1440.                    zeroWeaponAmmo = true;
  1441.                 }
  1442.              }
  1443.           }
  1444.           if (zeroWeaponAmmo === true) {
  1445.              if (ammoStr !== '') ammoStr += '|';
  1446.              ammoStr += '0';
  1447.           }
  1448.           //---------------------------------------------------//
  1449.           // - Charge Armor Cost
  1450.           var zeroChargeAmmo = false;
  1451.           for (var ammoId in skill.equipChargeAmmoCost) {
  1452.              var ammoId = parseInt(ammoId);
  1453.              var ammoCost = parseInt(skill.equipChargeAmmoCost[ammoId]);
  1454.              if (!isNaN(ammoId) && (ammoId > 0) && !isNaN(ammoCost) && (ammoCost > 0)) {
  1455.                 if (this._actor.hasArmor($dataArmors[ammoId])) {
  1456.                    if (ammoStr !== '') ammoStr += '|';
  1457.                    ammoStr += String( this._actor.getAmmoCurrentCharges($dataArmors[ammoId]) );
  1458.                    zeroChargeAmmo = false;
  1459.                    break;
  1460.                 } else {
  1461.                    zeroChargeAmmo = true;
  1462.                 }
  1463.              }
  1464.           }
  1465.           if (zeroChargeAmmo === true) {
  1466.              if (ammoStr !== '') ammoStr += '|';
  1467.              ammoStr += '0';
  1468.           }
  1469.           //---------------------------------------------------//
  1470.           // - Charge Weapon Cost
  1471.           var zeroChargeWeaponAmmo = false;
  1472.           for (var ammoId in skill.weaponChargeAmmoCost) {
  1473.              var ammoId = parseInt(ammoId);
  1474.              var ammoCost = parseInt(skill.weaponChargeAmmoCost[ammoId]);
  1475.              if (!isNaN(ammoId) && (ammoId > 0) && !isNaN(ammoCost) && (ammoCost > 0)) {
  1476.                 if (this._actor.hasWeapon($dataWeapons[ammoId])) {
  1477.                    if (ammoStr !== '') ammoStr += '|';
  1478.                    ammoStr += String( this._actor.getAmmoCurrentCharges($dataWeapons[ammoId]) );
  1479.                    zeroChargeWeaponAmmo = false;
  1480.                    break;
  1481.                 } else {
  1482.                    zeroChargeWeaponAmmo = true;
  1483.                 }
  1484.              }
  1485.           }
  1486.           if (zeroChargeWeaponAmmo === true) {
  1487.              if (ammoStr !== '') ammoStr += '|';
  1488.              ammoStr += '0';
  1489.           }
  1490.     }
  1491.     //---------------------------------------------------//
  1492.     // - End
  1493.     if (ammoStr !== '') ammoStr = '[' + ammoStr + ']';
  1494.     return ammoStr;
  1495. };
  1496.  
  1497. Unco.AS.Window_ActorCommand_addCommand = Window_ActorCommand.prototype.addCommand;
  1498. if (Imported.BOB_BattleCommandList === true) {
  1499.    Window_ActorCommand.prototype.addCommand = function(name, symbol, enabled, ext, icon) {
  1500.       if ((symbol === 'attack') && (this._actor._equips[0]) && (this._actor._equips[0]._itemId)) {
  1501.          var ammoStr = this.getAmmoText($dataWeapons[this._actor._equips[0]._itemId]);
  1502.          name = name + ammoStr;
  1503.       }
  1504.       if (symbol === 'customSkill') {
  1505.          var ammoStr = this.getAmmoText(ext);
  1506.          name = name + ammoStr;
  1507.       }
  1508.       Unco.AS.Window_ActorCommand_addCommand.call(this,name, symbol, enabled, ext, icon);
  1509.    };
  1510. } else {
  1511.    if (Imported.YEP_WeaponUnleash) {
  1512.        console.log(" ** In Weapon Unleash Compatibility Code");
  1513.        Window_ActorCommand.prototype.addAttackCommand = function() {
  1514.           Yanfly.WUL.Window_ActorCommand_addAttackCommand.call(this);
  1515.           var index = this.findSymbol('attack');
  1516.           if (index < 0) return;
  1517.           var name = $dataSkills[this._actor.attackSkillId()].commandAttackText;
  1518.           if ((this._actor._equips[0]) && (this._actor._equips[0]._itemId)) {
  1519.              var ammoStr = this.getAmmoText($dataWeapons[this._actor._equips[0]._itemId]);
  1520.              name = name + ammoStr;
  1521.           }
  1522.           this._list[index].name = name;
  1523.        };
  1524.        Window_ActorCommand.prototype.addGuardCommand = function() {
  1525.           Yanfly.WUL.Window_ActorCommand_addGuardCommand.call(this);
  1526.           var index = this.findSymbol('guard');
  1527.           if (index < 0) return;
  1528.           var name = $dataSkills[this._actor.guardSkillId()].commandGuardText;
  1529.           var ammoStr = this.getAmmoText( $dataSkills[this._actor.guardSkillId()] );
  1530.           name = name + ammoStr;
  1531.           this._list[index].name = name;
  1532.       };
  1533.    } else {    
  1534.       Window_ActorCommand.prototype.addCommand = function(name, symbol, enabled, ext) {
  1535.          if ((symbol === 'attack') && (this._actor._equips[0]) && (this._actor._equips[0]._itemId)) {
  1536.             var ammoStr = this.getAmmoText($dataWeapons[this._actor._equips[0]._itemId]);
  1537.             name = name + ammoStr;
  1538.          }
  1539.          Unco.AS.Window_ActorCommand_addCommand.call(this,name, symbol, enabled, ext);
  1540.       };
  1541.    }
  1542. }
  1543.  
  1544. Unco.AS.Window_ActorCommand_setHelpWindowItem = Window_ActorCommand.prototype.setHelpWindowItem;
  1545. Window_ActorCommand.prototype.setHelpWindowItem = function(item) {
  1546.    if (this._helpWindow && this._actor) {
  1547.       this._helpWindow._actor = this._actor;
  1548.    }
  1549.    Unco.AS.Window_ActorCommand_setHelpWindowItem.call(this,item)
  1550. };
  1551.  
  1552.  
  1553.  
  1554. if (Imported.YEP_SkillCore === true) {
  1555. //=============================================================================
  1556. // Window_Base
  1557. //=============================================================================
  1558.    Window_Base.prototype.mustDrawActorAmmo = function(actor) {
  1559.       var cond = typeof actor._equips !== 'undefined';
  1560.       if (cond) cond = typeof actor._equips[0] !== 'undefined';
  1561.       if (cond) {
  1562.          if (actor._equips[0]._itemId > 0) {
  1563.             skill = $dataWeapons[actor._equips[0]._itemId];
  1564.             for (var ammoId in skill.itemAmmoCost) {
  1565.                var ammoId = parseInt(ammoId);
  1566.                if (!isNaN(ammoId) && (ammoId > 0)) {                
  1567.                   if (!isNaN(skill.itemAmmoCost[ammoId])) {
  1568.                      return true;
  1569.                   }
  1570.                }
  1571.             }
  1572.             for (var ammoId in skill.equipAmmoCost) {
  1573.                var ammoId = parseInt(ammoId);
  1574.                if (!isNaN(ammoId) && (ammoId > 0)) {                  
  1575.                   if (!isNaN(skill.equipAmmoCost[ammoId])) {
  1576.                      return true;
  1577.                   }
  1578.                }
  1579.             }
  1580.             for (var ammoId in skill.weaponAmmoCost) {
  1581.                var ammoId = parseInt(ammoId);
  1582.                if (!isNaN(ammoId) && (ammoId > 0)) {                  
  1583.                   if (!isNaN(skill.weaponAmmoCost[ammoId])) {
  1584.                      return true;
  1585.                   }
  1586.                }
  1587.             }
  1588.             for (var ammoId in skill.equipChargeAmmoCost) {
  1589.                var ammoId = parseInt(ammoId);
  1590.                if (!isNaN(ammoId) && (ammoId > 0)) {                  
  1591.                   if (!isNaN(skill.equipChargeAmmoCost[ammoId])) {
  1592.                      return true;
  1593.                   }
  1594.                }
  1595.             }
  1596.             for (var ammoId in skill.weaponChargeAmmoCost) {
  1597.                var ammoId = parseInt(ammoId);
  1598.                if (!isNaN(ammoId) && (ammoId > 0)) {                  
  1599.                   if (!isNaN(skill.weaponChargeAmmoCost[ammoId])) {
  1600.                      return true;
  1601.                   }
  1602.                }
  1603.             }
  1604.          }
  1605.       }
  1606.       return false;
  1607.    }
  1608.    Window_Base.prototype.drawActorAmmo = function(actor, x, y, width) {
  1609.       if (typeof actor._equips !== 'undefined') {
  1610.          if (actor._equips[0]._itemId > 0) {
  1611.             skill = $dataWeapons[ ( (typeof $dataWeapons[actor._equips[0]._itemId].baseItemId === 'undefined') ? actor._equips[0]._itemId : $dataWeapons[actor._equips[0]._itemId].baseItemId ) ];
  1612.             var dw = width;
  1613.             //---------------------------------------------------//
  1614.             // - Item Cost
  1615.             for (var ammoId in skill.itemAmmoCost) {
  1616.                var ammoId = parseInt(ammoId);
  1617.                if (!isNaN(ammoId) && (ammoId > 0)) {
  1618.                   var ammoCost = parseInt(skill.itemAmmoCost[ammoId]);              
  1619.                   this.changeTextColor(this.textColor(Unco.Param.ammoFontColor));
  1620.                   var text = (ammoCost <= 0) ? '' : 'x' + String( $gameParty.getItemAmount($dataItems[ammoId]) );
  1621.                   this.contents.fontSize = Unco.Param.ammoFontSize;
  1622.                   this.drawText(text, x, y, dw, 'right');
  1623.                   dw -= this.textWidth(text);
  1624.                   this.resetFontSettings();
  1625.                   if ($dataItems[ammoId].iconIndex > 0) {
  1626.                      var iw = x + dw - Window_Base._iconWidth;
  1627.                      this.drawIcon($dataItems[ammoId].iconIndex, iw, y + 2);
  1628.                      dw -= Window_Base._iconWidth + 2;
  1629.                   }
  1630.                }
  1631.             }
  1632.             //---------------------------------------------------//
  1633.             // - Armor Cost
  1634.             var zeroAmmo = false;
  1635.             for (var ammoId in skill.equipAmmoCost) {
  1636.                var ammoId = parseInt(ammoId);
  1637.                if (!isNaN(ammoId) && (ammoId > 0)) {
  1638.                   var ammoCost = parseInt(skill.equipAmmoCost[ammoId]);  
  1639.                   if (actor.hasArmor($dataArmors[ammoId])) {
  1640.                      this.changeTextColor(this.textColor(Unco.Param.ammoFontColor));
  1641.                      var text = (ammoCost <= 0) ? '' : 'x' + String( 1+$gameParty.getItemAmount($dataArmors[ammoId]) );
  1642.                      this.contents.fontSize = Unco.Param.ammoFontSize;
  1643.                      this.drawText(text, x, y, dw, 'right');
  1644.                      dw -= this.textWidth(text);
  1645.                      this.resetFontSettings();
  1646.                      if ($dataArmors[ammoId].iconIndex > 0) {
  1647.                         var iw = x + dw - Window_Base._iconWidth;
  1648.                         this.drawIcon($dataArmors[ammoId].iconIndex, iw, y + 2);
  1649.                         dw -= Window_Base._iconWidth + 2;
  1650.                      }
  1651.                      zeroAmmo = false;
  1652.                      break;
  1653.                   } else {
  1654.                      zeroAmmo = true;
  1655.                   }
  1656.                }
  1657.             }
  1658.             if (zeroAmmo === true) {
  1659.                this.changeTextColor(this.textColor(Unco.Param.ammoFontColor));
  1660.                var text = 'x0';
  1661.                this.contents.fontSize = Unco.Param.ammoFontSize;
  1662.                this.drawText(text, x, y, dw, 'right');
  1663.                dw -= this.textWidth(text);
  1664.                this.resetFontSettings();
  1665.                var iw = x + dw - Window_Base._iconWidth;
  1666.                this.drawIcon( ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId ) , iw, y + 2);
  1667.                dw -= Window_Base._iconWidth + 2;
  1668.             }
  1669.             //---------------------------------------------------//
  1670.             // - Weapon Cost
  1671.             var zeroWeaponAmmo = false;
  1672.             for (var ammoId in skill.weaponAmmoCost) {
  1673.                var ammoId = parseInt(ammoId);
  1674.                if (!isNaN(ammoId) && (ammoId > 0)) {
  1675.                   var ammoCost = parseInt(skill.weaponAmmoCost[ammoId]);  
  1676.                   if (actor.hasWeapon($dataWeapons[ammoId])) {
  1677.                      this.changeTextColor(this.textColor(Unco.Param.ammoFontColor));
  1678.                      var text = (ammoCost <= 0) ? '' : 'x' + String( 1+$gameParty.getItemAmount($dataWeapons[ammoId]) );
  1679.                      this.contents.fontSize = Unco.Param.ammoFontSize;
  1680.                      this.drawText(text, x, y, dw, 'right');
  1681.                      dw -= this.textWidth(text);
  1682.                      this.resetFontSettings();
  1683.                      if ($dataWeapons[ammoId].iconIndex > 0) {
  1684.                         var iw = x + dw - Window_Base._iconWidth;
  1685.                         this.drawIcon($dataWeapons[ammoId].iconIndex, iw, y + 2);
  1686.                         dw -= Window_Base._iconWidth + 2;
  1687.                      }
  1688.                      zeroWeaponAmmo = false;
  1689.                      break;
  1690.                   } else {
  1691.                      zeroWeaponAmmo = true;
  1692.                   }
  1693.                }
  1694.             }
  1695.             if (zeroWeaponAmmo === true) {
  1696.                this.changeTextColor(this.textColor(Unco.Param.ammoFontColor));
  1697.                var text = 'x0';
  1698.                this.contents.fontSize = Unco.Param.ammoFontSize;
  1699.                this.drawText(text, x, y, dw, 'right');
  1700.                dw -= this.textWidth(text);
  1701.                this.resetFontSettings();
  1702.                var iw = x + dw - Window_Base._iconWidth;
  1703.                this.drawIcon( ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId ) , iw, y + 2);
  1704.                dw -= Window_Base._iconWidth + 2;
  1705.             }
  1706.             //---------------------------------------------------//
  1707.             // - Charge Armor Cost
  1708.             var zeroChargeAmmo = false;
  1709.             for (var ammoId in skill.equipChargeAmmoCost) {
  1710.                var ammoId = parseInt(ammoId);
  1711.                if (!isNaN(ammoId) && (ammoId > 0)) {
  1712.                   var ammoCost = parseInt(skill.equipChargeAmmoCost[ammoId]);  
  1713.                   if (actor.hasArmor($dataArmors[ammoId])) {
  1714.                      this.changeTextColor(this.textColor(Unco.Param.ammoFontColor));
  1715.                      var text = (ammoCost <= 0) ? '' : 'x' + String( actor.getAmmoCurrentCharges($dataArmors[ammoId]) );
  1716.                      this.contents.fontSize = Unco.Param.ammoFontSize;
  1717.                      this.drawText(text, x, y, dw, 'right');
  1718.                      dw -= this.textWidth(text);
  1719.                      this.resetFontSettings();
  1720.                      if ($dataArmors[ammoId].iconIndex > 0) {
  1721.                         var iw = x + dw - Window_Base._iconWidth;
  1722.                         this.drawIcon($dataArmors[ammoId].iconIndex, iw, y + 2);
  1723.                         dw -= Window_Base._iconWidth + 2;
  1724.                      }
  1725.                      zeroChargeAmmo = false;
  1726.                      break;
  1727.                   } else {
  1728.                      zeroChargeAmmo = true;
  1729.                   }
  1730.                }
  1731.             }
  1732.             if (zeroChargeAmmo === true) {
  1733.                this.changeTextColor(this.textColor(Unco.Param.ammoFontColor));
  1734.                var text = 'x0';
  1735.                this.contents.fontSize = Unco.Param.ammoFontSize;
  1736.                this.drawText(text, x, y, dw, 'right');
  1737.                dw -= this.textWidth(text);
  1738.                this.resetFontSettings();
  1739.                var iw = x + dw - Window_Base._iconWidth;
  1740.                this.drawIcon( ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId ) , iw, y + 2);
  1741.                dw -= Window_Base._iconWidth + 2;
  1742.             }
  1743.             //---------------------------------------------------//
  1744.             // - Charge Weapon Cost
  1745.             var zeroChargeWeaponAmmo = false;
  1746.             for (var ammoId in skill.weaponChargeAmmoCost) {
  1747.                var ammoId = parseInt(ammoId);
  1748.                if (!isNaN(ammoId) && (ammoId > 0)) {
  1749.                   var ammoCost = parseInt(skill.weaponChargeAmmoCost[ammoId]);  
  1750.                   if (actor.hasWeapon($dataWeapons[ammoId])) {
  1751.                      this.changeTextColor(this.textColor(Unco.Param.ammoFontColor));
  1752.                      var text = (ammoCost <= 0) ? '' : 'x' + String( actor.getAmmoCurrentCharges($dataWeapons[ammoId]) );
  1753.                      this.contents.fontSize = Unco.Param.ammoFontSize;
  1754.                      this.drawText(text, x, y, dw, 'right');
  1755.                      dw -= this.textWidth(text);
  1756.                      this.resetFontSettings();
  1757.                      if ($dataWeapons[ammoId].iconIndex > 0) {
  1758.                         var iw = x + dw - Window_Base._iconWidth;
  1759.                         this.drawIcon($dataWeapons[ammoId].iconIndex, iw, y + 2);
  1760.                         dw -= Window_Base._iconWidth + 2;
  1761.                      }
  1762.                      zeroChargeWeaponAmmo = false;
  1763.                      break;
  1764.                   } else {
  1765.                      zeroChargeWeaponAmmo = true;
  1766.                   }
  1767.                }
  1768.             }
  1769.             if (zeroChargeWeaponAmmo === true) {
  1770.                this.changeTextColor(this.textColor(Unco.Param.ammoFontColor));
  1771.                var text = 'x0';
  1772.                this.contents.fontSize = Unco.Param.ammoFontSize;
  1773.                this.drawText(text, x, y, dw, 'right');
  1774.                dw -= this.textWidth(text);
  1775.                this.resetFontSettings();
  1776.                var iw = x + dw - Window_Base._iconWidth;
  1777.                this.drawIcon( ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId ) , iw, y + 2);
  1778.                dw -= Window_Base._iconWidth + 2;
  1779.             }
  1780.          }
  1781.       }
  1782.    };
  1783.    
  1784. //=============================================================================
  1785. // DataManager (again)
  1786. //=============================================================================
  1787.    Unco.AS.DataManager_processGSCNotetags1 = DataManager.processGSCNotetags1;
  1788.    DataManager.processGSCNotetags1 = function(group) {
  1789.      Unco.AS.DataManager_processGSCNotetags1.call(this,group);
  1790.      for (var n = 1; n < group.length; n++) {
  1791.        var obj = group[n];
  1792.        var notedata = obj.note.split(/[\r\n]+/);
  1793.  
  1794.        for (var i = 0; i < notedata.length; i++) {
  1795.          var line = notedata[i];
  1796.          if (line.match(/<(?:SWAP GAUGE|gauge)[ ](\d+):[ ](.*)>/i)) {
  1797.            var gauge = parseInt(RegExp.$1);
  1798.            var text = String(RegExp.$2).toUpperCase();
  1799.            if (['AMMO'].contains(text)) {
  1800.              if (gauge === 1) obj.gauge1 = text;
  1801.              if (gauge === 2) obj.gauge2 = text;
  1802.              if (gauge === 3) obj.gauge3 = text;
  1803.            }
  1804.          }
  1805.        }
  1806.      }
  1807.    };
  1808.    Unco.AS.DataManager_processGSCNotetags2 = DataManager.processGSCNotetags2;
  1809.    DataManager.processGSCNotetags2 = function(group) {
  1810.      Unco.AS.DataManager_processGSCNotetags2.call(this,group);
  1811.      for (var n = 1; n < group.length; n++) {
  1812.        var obj = group[n];
  1813.        var notedata = obj.note.split(/[\r\n]+/);
  1814.  
  1815.        for (var i = 0; i < notedata.length; i++) {
  1816.          var line = notedata[i];
  1817.          if (line.match(/<(?:SWAP GAUGE|gauge)[ ](\d+):[ ](.*)>/i)) {
  1818.            var gauge = parseInt(RegExp.$1);
  1819.            var text = String(RegExp.$2).toUpperCase();
  1820.            if (['AMMO'].contains(text)) {
  1821.              if (gauge === 1) obj.gauge1 = text;
  1822.              if (gauge === 2) obj.gauge2 = text;
  1823.              if (gauge === 3) obj.gauge3 = text;
  1824.            }
  1825.          }
  1826.        }
  1827.      }
  1828.    };
  1829.    
  1830.    Unco.AS.Window_Window_Base_drawActorHp = Window_Base.prototype.drawActorHp;
  1831.    Window_Base.prototype.drawActorHp = function(actor, x, y, width) {
  1832.        if ((this.mustDrawActorAmmo(actor)) && (actor.gauge1() === 'AMMO')) {
  1833.        this.drawActorAmmo(actor, x, y, width);
  1834.        } else {
  1835.          Unco.AS.Window_Window_Base_drawActorHp.call(this, actor, x, y, width);
  1836.        }
  1837.    };
  1838.    
  1839.    Unco.AS.Window_Window_Base_drawActorMp = Window_Base.prototype.drawActorMp;
  1840.    Window_Base.prototype.drawActorMp = function(actor, x, y, width) {
  1841.        if ((this.mustDrawActorAmmo(actor)) && (actor.gauge2() === 'AMMO')) {
  1842.          this.drawActorAmmo(actor, x, y, width);
  1843.        } else {
  1844.          Unco.AS.Window_Window_Base_drawActorMp.call(this, actor, x, y, width);
  1845.        }
  1846.    };
  1847.    
  1848.    Unco.AS.Window_Window_Base_drawActorTp = Window_Base.prototype.drawActorTp;
  1849.    Window_Base.prototype.drawActorTp = function(actor, x, y, width) {
  1850.        if ((this.mustDrawActorAmmo(actor)) && (actor.gauge3() === 'AMMO')) {
  1851.        this.drawActorAmmo(actor, x, y, width);
  1852.        } else {
  1853.          Unco.AS.Window_Window_Base_drawActorTp.call(this, actor, x, y, width);
  1854.        }
  1855.    };
  1856. }
  1857.  
  1858. //-----------------------------------------------------------------------------
  1859. // Window_Base
  1860. //
  1861. // Draw item with charges.
  1862.  
  1863. Window_Base.prototype.drawItemName = function(item, x, y, width) {
  1864.    width = width || 312;
  1865.    if (item) {
  1866.       var iconBoxWidth = (Imported.YEP_CoreEngine === true) ? this.lineHeight() : (Window_Base._iconWidth + 4);
  1867.       var padding = (Imported.YEP_CoreEngine === true) ? ( (iconBoxWidth - Window_Base._iconWidth) / 2 ) : 2;
  1868.       this.resetTextColor();
  1869.       this.drawIcon(item.iconIndex, x + padding, y + padding);
  1870.       if (typeof item.ammoCurrentCharges !== 'undefined') {
  1871.          this.changeTextColor(this.textColor(Unco.Param.ammoFontColor));
  1872.          this.contents.fontSize = Unco.Param.ammoFontSize;
  1873.          this.drawText( String( item.ammoCurrentCharges ) , x + padding ,  y + padding , Window_Base._iconWidth , 'center');
  1874.          this.resetTextColor();
  1875.          this.resetFontSettings();
  1876.       }
  1877.       this.drawText(item.name, x + iconBoxWidth, y, width - iconBoxWidth);
  1878.    }
  1879. };
  1880.  
  1881. //-----------------------------------------------------------------------------
  1882. // Window_Ammo
  1883. //
  1884. // The window for displaying the ammunition amount for attack action.
  1885.  
  1886. function Window_Ammo() {
  1887.     this.initialize.apply(this, arguments);
  1888. }
  1889.  
  1890. Window_Ammo.prototype = Object.create(Window_Base.prototype);
  1891. Window_Ammo.prototype.constructor = Window_Ammo;
  1892.  
  1893. Window_Ammo.prototype.initialize = function(numLines) {
  1894.     var width = Graphics.boxWidth;
  1895.     var height = this.fittingHeight(1);
  1896.     var y = Graphics.height-this.fittingHeight(6);
  1897.     Window_Base.prototype.initialize.call(this, 0, 0, width, height);
  1898.     this._text = '';
  1899. };
  1900.  
  1901. Window_Ammo.prototype.setText = function(text) {
  1902.     if (this._text !== text) {
  1903.         this._text = text;
  1904.         this.refresh();
  1905.     }
  1906. };
  1907.  
  1908. Window_Ammo.prototype.clear = function() {
  1909.     this.setText('');
  1910. };
  1911.  
  1912.  
  1913. Window_Ammo.prototype.setItem = function(actor,item) {
  1914.    var text = '';
  1915.    if (typeof item !== 'undefined') {
  1916.       if ((DataManager.isSkill(item)) && (Unco.Param.showAmmoLeftInDesc === 'true')) {
  1917.          var skill = item;
  1918.          if (skill.id === actor.attackSkillId()) {
  1919.             if (typeof actor._equips !== 'undefined') {
  1920.                if (actor._equips[0]._itemId > 0) {
  1921.                   skill = $dataWeapons[ ( (typeof $dataWeapons[actor._equips[0]._itemId].baseItemId === 'undefined') ? actor._equips[0]._itemId : $dataWeapons[actor._equips[0]._itemId].baseItemId ) ];
  1922.                }
  1923.             }
  1924.          }
  1925.          //---------------------------------------------------//
  1926.          // - Item Cost
  1927.          var withAmmo = false;
  1928.          for (var ammoId in skill.itemAmmoCost) {
  1929.             var cost = skill.itemAmmoCost[ammoId];
  1930.             ammoId = parseInt(ammoId);
  1931.             if (!isNaN(ammoId) && (ammoId > 0) && !isNaN(cost)) {
  1932.                var cost = parseInt(cost);
  1933.                var itemOwned = ($gameParty.getItemAmount($dataItems[ammoId]) > 0);
  1934.                text = text + '\\i[' + String($dataItems[ammoId].iconIndex) + ']';
  1935.                text = text + ( (typeof skill.showAmmoName === 'undefined') ? '' : $dataItems[ammoId].name + ' ' );
  1936.                text = text + ( ((cost <= 0) && itemOwned) ? '' : ( 'x' + String( $gameParty.getItemAmount($dataItems[ammoId]) ) )  );
  1937.                withAmmo = true;
  1938.             }
  1939.          }
  1940.          //---------------------------------------------------//
  1941.          // - Armor Cost
  1942.          var zeroEquipAmmo = false;
  1943.          for (var ammoId in skill.equipAmmoCost) {
  1944.             var cost = skill.equipAmmoCost[ammoId];
  1945.             var ammoId = parseInt(ammoId);
  1946.             if (!isNaN(ammoId) && (ammoId > 0)) {
  1947.                cost = parseInt(cost);
  1948.                withAmmo = true;
  1949.                if (actor.hasArmor($dataArmors[ammoId])) {
  1950.                   text = text + '\\i[' + String($dataArmors[ammoId].iconIndex) + ']';
  1951.                   text = text + ( (typeof skill.showAmmoName === 'undefined') ? '' : $dataArmors[ammoId].name + ' ' );
  1952.                   text = text + ( (cost <= 0) ? '' : 'x' + String( 1 + $gameParty.getItemAmount($dataArmors[ammoId]) )  );
  1953.                   text = text + ( (typeof $dataArmors[ammoId].ammoDesc === 'undefined') ? '' : '(' + $dataArmors[ammoId].ammoDesc + ')' );
  1954.                   zeroEquipAmmo = false;
  1955.                   break;
  1956.                } else {
  1957.                   zeroEquipAmmo = true;
  1958.                }
  1959.             }
  1960.          }
  1961.          if (zeroEquipAmmo === true) text = text + '\\i[' + String( ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId ) ) + ']x0';
  1962.          //---------------------------------------------------//
  1963.          // - Weapon Cost
  1964.          var zeroWeaponAmmo = false;
  1965.          for (var ammoId in skill.weaponAmmoCost) {
  1966.             var cost = skill.weaponAmmoCost[ammoId];
  1967.             var ammoId = parseInt(ammoId);
  1968.             if (!isNaN(ammoId) && (ammoId > 0)) {
  1969.                cost = parseInt(cost);
  1970.                withAmmo = true;
  1971.                if (actor.hasWeapon($dataWeapons[ammoId])) {
  1972.                   text = text + '\\i[' + String($dataWeapons[ammoId].iconIndex) + ']';
  1973.                   text = text + ( (typeof skill.showAmmoName === 'undefined') ? '' : $dataWeapons[ammoId].name + ' ' );
  1974.                   text = text + ( (cost <= 0) ? '' : 'x' + String( 1 + $gameParty.getItemAmount($dataWeapons[ammoId]) )  );
  1975.                   text = text + ( (typeof $dataWeapons[ammoId].ammoDesc === 'undefined') ? '' : '(' + $dataWeapons[ammoId].ammoDesc + ')' );
  1976.                   zeroWeaponAmmo = false;
  1977.                   break;
  1978.                } else {
  1979.                   zeroWeaponAmmo = true;
  1980.                }
  1981.             }
  1982.          }
  1983.          if (zeroWeaponAmmo === true) text = text + '\\i[' + String( ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId ) ) + ']x0';
  1984.          //---------------------------------------------------//
  1985.          // - Charge Armor Cost
  1986.          var zeroChargeEquipAmmo = false;
  1987.          for (var ammoId in skill.equipChargeAmmoCost) {
  1988.             var cost = skill.equipChargeAmmoCost[ammoId];
  1989.             var ammoId = parseInt(ammoId);
  1990.             if (!isNaN(ammoId) && (ammoId > 0)) {
  1991.                cost = parseInt(cost);
  1992.                withAmmo = true;
  1993.                if (actor.hasArmor($dataArmors[ammoId])) {
  1994.                   text = text + '\\i[' + String($dataArmors[ammoId].iconIndex) + ']';
  1995.                   text = text + ( (typeof skill.showAmmoName === 'undefined') ? '' : $dataArmors[ammoId].name + ' ' );
  1996.                   text = text + ( (cost <= 0) ? '' : 'x' + String( actor.getAmmoCurrentCharges($dataArmors[ammoId]) )  );
  1997.                   text = text + ( (typeof $dataArmors[ammoId].ammoDesc === 'undefined') ? '' : '(' + $dataArmors[ammoId].ammoDesc + ')' );
  1998.                   zeroChargeEquipAmmo = false;
  1999.                   break;
  2000.                } else {
  2001.                   zeroChargeEquipAmmo = true;
  2002.                }
  2003.             }
  2004.          }
  2005.          if (zeroChargeEquipAmmo === true) text = text + '\\i[' + String( ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId ) ) + ']x0';
  2006.          //---------------------------------------------------//
  2007.          // - Charge Weapon Cost
  2008.          var zeroChargeWeaponAmmo = false;
  2009.          for (var ammoId in skill.weaponChargeAmmoCost) {
  2010.             var cost = skill.weaponChargeAmmoCost[ammoId];
  2011.             var ammoId = parseInt(ammoId);
  2012.             if (!isNaN(ammoId) && (ammoId > 0)) {
  2013.                cost = parseInt(cost);
  2014.                withAmmo = true;
  2015.                if (actor.hasWeapon($dataWeapons[ammoId])) {
  2016.                   text = text + '\\i[' + String($dataWeapons[ammoId].iconIndex) + ']';
  2017.                   text = text + ( (typeof skill.showAmmoName === 'undefined') ? '' : $dataWeapons[ammoId].name + ' ' );
  2018.                   text = text + ( (cost <= 0) ? '' : 'x' + String( actor.getAmmoCurrentCharges($dataWeapons[ammoId]) )  );
  2019.                   text = text + ( (typeof $dataWeapons[ammoId].ammoDesc === 'undefined') ? '' : '(' + $dataWeapons[ammoId].ammoDesc + ')' );
  2020.                   zeroChargeWeaponAmmo = false;
  2021.                   break;
  2022.                } else {
  2023.                   zeroChargeWeaponAmmo = true;
  2024.                }
  2025.             }
  2026.          }
  2027.          if (zeroChargeWeaponAmmo === true) text = text + '\\i[' + String( ( (skill.noAmmoIconId) ? skill.noAmmoIconId : Unco.Param.defaultNoAmmoIconId ) ) + ']x0';
  2028.          
  2029.          if (withAmmo === true) text = ( (typeof skill.ammoText !== 'undefined') ? skill.ammoText : Unco.Param.descAmmoLeftText) + ' : ' + text;
  2030.       }
  2031.    }
  2032.    if (text !== '') {
  2033.       this.setText(item ? text : '');
  2034.       this.show();
  2035.    }
  2036. };
  2037.  
  2038. Window_Ammo.prototype.refresh = function() {
  2039.     this.contents.clear();
  2040.     this.drawTextEx(this._text, this.textPadding(), 0);
  2041. };
  2042.  
  2043. Unco.AS.Scene_Battle_createAllWindows = Scene_Battle.prototype.createAllWindows;
  2044. Scene_Battle.prototype.createAllWindows = function() {
  2045.     Unco.AS.Scene_Battle_createAllWindows.call(this);
  2046.     this.createAmmoWindow();
  2047. };
  2048.  
  2049. Scene_Battle.prototype.createAmmoWindow = function() {
  2050.     this._ammoWindow = new Window_Ammo();
  2051.     this._ammoWindow.visible = false;
  2052.     this.addWindow(this._ammoWindow);
  2053. };
  2054.  
  2055. Scene_Battle.prototype.showAmmoWindow = function() {
  2056.   if (Unco.Param.showAmmoLeftActorCommand === 'true') this._ammoWindow.setItem(BattleManager.actor(),$dataSkills[BattleManager.actor().attackSkillId()]);
  2057. };
  2058.  
  2059. Unco.AS.Scene_Battle_onSelectAction = Scene_Battle.prototype.onSelectAction;
  2060. Scene_Battle.prototype.onSelectAction = function() {
  2061.     this._ammoWindow.hide();
  2062.     Unco.AS.Scene_Battle_onSelectAction.call(this);
  2063. };
  2064.  
  2065. Unco.AS.Scene_Battle_commandAttack = Scene_Battle.prototype.commandAttack;
  2066. Scene_Battle.prototype.commandAttack = function() {
  2067.    this._ammoWindow.hide();
  2068.    Unco.AS.Scene_Battle_commandAttack.call(this);
  2069. };
  2070. Unco.AS.Scene_Battle_commandSkill = Scene_Battle.prototype.commandSkill;
  2071. Scene_Battle.prototype.commandSkill = function() {
  2072.    this._ammoWindow.hide();
  2073.    Unco.AS.Scene_Battle_commandSkill.call(this);
  2074. };
  2075. Unco.AS.Scene_Battle_commandGuard = Scene_Battle.prototype.commandGuard;
  2076. Scene_Battle.prototype.commandGuard = function() {
  2077.    this._ammoWindow.hide();
  2078.    Unco.AS.Scene_Battle_commandGuard.call(this);
  2079. };
  2080. Unco.AS.Scene_Battle_commandItem = Scene_Battle.prototype.commandItem;
  2081. Scene_Battle.prototype.commandItem = function() {
  2082.    this._ammoWindow.hide();
  2083.    Unco.AS.Scene_Battle_commandItem.call(this);
  2084. };
  2085. Unco.AS.Scene_Battle_startActorCommandSelection = Scene_Battle.prototype.startActorCommandSelection;
  2086. Scene_Battle.prototype.startActorCommandSelection = function() {
  2087.    this.showAmmoWindow();
  2088.    Unco.AS.Scene_Battle_startActorCommandSelection.call(this);
  2089. };
  2090. Unco.AS.Scene_Battle_onSkillCancel = Scene_Battle.prototype.onSkillCancel;
  2091. Scene_Battle.prototype.onSkillCancel = function() {
  2092.    this.showAmmoWindow();
  2093.    Unco.AS.Scene_Battle_onSkillCancel.call(this);
  2094. };
  2095. Unco.AS.Scene_Battle_onItemCancel = Scene_Battle.prototype.onItemCancel;
  2096. Scene_Battle.prototype.onItemCancel = function() {
  2097.    this.showAmmoWindow();
  2098.    Unco.AS.Scene_Battle_onItemCancel.call(this);
  2099. };
  2100. Unco.AS.Scene_Battle_onEnemyCancel = Scene_Battle.prototype.onEnemyCancel;
  2101. Scene_Battle.prototype.onEnemyCancel = function() {
  2102.    if (this._actorCommandWindow.currentSymbol() === 'attack') {
  2103.       this.showAmmoWindow();
  2104.    }
  2105.    Unco.AS.Scene_Battle_onEnemyCancel.call(this);
  2106. };
Advertisement
RAW Paste Data Copied
Advertisement