Maliki79

MalMZDualWield

Aug 28th, 2020 (edited)
3,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Maliki's Dual Weilding/Two-Handed Weapons MZ Version
  3. // MalMZDualWield.js
  4. // version 1.3cMZ
  5. //=============================================================================
  6. /*:
  7.  * @target MZ
  8.  *  
  9.  * @plugindesc ver1.3cMZ - Allows you to set weapons as twohanded, disallowing you from equipping weapons to the Off-hand.  
  10.  * @author Maliki79
  11.  * @param ShieldsArmor
  12.  * @desc Type 1 to place Shield weapons in Menu Screens' Armor category.
  13.  * Default: 0
  14.  * @default 0
  15.  *
  16.  * @param MustUseMain
  17.  * @desc Type 1 to force equips to be placed in Main hand before they can be placed in Off hand.
  18.  * Default: 0
  19.  * @default 0
  20.  *
  21.  * @param OffhandAdjust
  22.  * @desc Percentage of stats offhand weapons add to actors. (Make the number lower than 100 to lower stats and higher to raise)
  23.  * Default: 100
  24.  * @default 100
  25.  *
  26.  * @param OffhandSlotName
  27.  * @desc Name used for offhand weapon slot.
  28.  * Default: Off-Hand
  29.  * @default Off-Hand
  30.  *
  31.  * @param ShowTraitsInConsole
  32.  * @desc Type 1 to show trait code,dataId and value data on console upon item equip.
  33.  * Default: 0
  34.  * @default 0
  35.  *
  36.  * @param PowerAdjustement0
  37.  * @desc Amount of "weight" given to HP when determining strength of weapons as a percent.
  38.  * Default: 100
  39.  * @default 100
  40.  *
  41.  * @param PowerAdjustement1
  42.  * @desc Amount of "weight" given to MP when determining strength of weapons as a percent.
  43.  * Default: 100
  44.  * @default 100
  45.  *
  46.  * @param PowerAdjustement2
  47.  * @desc Amount of "weight" given to ATK when determining strength of weapons as a percent.
  48.  * Default: 100
  49.  * @default 100
  50.  *
  51.  * @param PowerAdjustement3
  52.  * @desc Amount of "weight" given to DEF when determining strength of weapons as a percent.
  53.  * Default: 100
  54.  * @default 100
  55.  *
  56.  * @param PowerAdjustement4
  57.  * @desc Amount of "weight" given to M.ATK when determining strength of weapons as a percent.
  58.  * Default: 100
  59.  * @default 100
  60.  *
  61.  * @param PowerAdjustement5
  62.  * @desc Amount of "weight" given to M.DEF when determining strength of weapons as a percent.
  63.  * Default: 100
  64.  * @default 100
  65.  *
  66.  * @param PowerAdjustement6
  67.  * @desc Amount of "weight" given to AGI when determining strength of weapons as a percent.
  68.  * Default: 100
  69.  * @default 100
  70.  *
  71.  * @param PowerAdjustement7
  72.  * @desc Amount of "weight" given to LUK when determining strength of weapons as a percent.
  73.  * Default: 100
  74.  * @default 100
  75.  *
  76.  * @param PotentialPointsInShop
  77.  * @desc Shows Equipment "Potential" as a point total in shops.  Make this value 1 to enable, otherwise, the default calculations will be used.
  78.  * Default: 1
  79.  * @default 1
  80.  *
  81.  * @param 2H_DisableOtherSlot
  82.  * @desc If 1, equipping a 2Handed Weapon will completely disable the other equip slot.
  83.  * default: 0
  84.  * @default 0
  85.  *
  86.  * @param Matched_Equip_Omit_Traits
  87.  * @desc If 1, double equip traits will be the only plugin provided traits exhibited.  Main and Sub traits will be omitted.
  88.  * default: 0
  89.  * @default 0
  90.  *
  91.  * @help You need two steps to use this plugin:
  92.  * 1: Set your actor(s) up to have Dual-Wield in the Database. TRAITS => EQUIP => SLOT TYPE => DUAL WIELD
  93.  * 2: Add the Notetag <twohand> to any two handed weapons in your Database.
  94.  * 3: (Optional) For Shields, make them weapons in your database and add the tag <shld> to their notes. "Shields" can only be equipped to the off-hand.
  95.  * 3a: Conversly, if you tag a weapon with <mainWeaponOnly> , it will only be equippable on the main hand.
  96.  * 4: (Optional) For one handed Actors you wish to equip shields that are considered weapons in the DB, tag <handnshld>
  97.  *    to the Actor's Class notes. (Those Actors still need to have the Dual Wield trait.)
  98.  * 5: (Optional) An Actor's Class notes can be tagged with <monkeygrip> to allow two handed weapons to be dual wielded or allow a 2H weapon and shield.
  99.  * 6: (Optional) You can tag any weapons with <OffhandAdjust: x> with x being a number. This will allow the specific weapon to use the given value instead of the default.
  100.  * 7: (Optional) You can tag a weapon with <subweapon> so that it's basic attack animation will not be shown in battles when in the off hand.
  101.  * 8: (Optional) You can tag a weapon with <mainweaponTrait: x, y, z> or <subweaponTrait: x, y, z> with x being the trait code, y being the dataId, and z being the value.
  102.  *    Weapons with the Mainweapon tag will exhibit those traits ONLY while in the main weapon slot while supweapon tagged weapons will exhibit
  103.  *    thier traits while in the off hand only.
  104.  * 9: (Optional) You can tag a weapon with <doubleGripTrait: x, y, z> with x being the trait code, y being the dataId, and z being the value.
  105.  *    When one tagged weapon is equipped and while the actor has the <doubleGrip> tag on either class notes or an applied state's notes,
  106.  *    the double grip traits will be applied to the actor.
  107.  * 10:(Optional) You can tag Weapons or Armor with <PotentialP:Number> with Number being a whole number to assign a starting value to the Potential Point
  108.  *    calculations.  Usful if things other than raw stats are used and will factor into the potential score of equipment in your project.
  109.  *
  110.  * Notes on main/sub/double-grip weapon traits:
  111.  * Codes are the number representation of traits as they appear in the database.
  112.  *  Trait codes are listed below:
  113.  *  11-TRAIT_ELEMENT_RATE      41-TRAIT_STYPE_ADD       61-TRAIT_ACTION_PLUS
  114.  *  12-TRAIT_DEBUFF_RATE       42-TRAIT_STYPE_SEAL      62-TRAIT_SPECIAL_FLAG
  115.  *  13-TRAIT_STATE_RATE        43-TRAIT_SKILL_ADD       63-TRAIT_COLLAPSE_TYPE
  116.  *  14-TRAIT_STATE_RESIST      44-TRAIT_SKILL_SEAL      64-TRAIT_PARTY_ABILITY
  117.  *  21-TRAIT_PARAM             51-TRAIT_EQUIP_WTYPE
  118.  *  22-TRAIT_XPARAM            52-TRAIT_EQUIP_ATYPE
  119.  *  23-TRAIT_SPARAM            53-TRAIT_EQUIP_LOCK
  120.  *  31-TRAIT_ATTACK_ELEMENT    54-TRAIT_EQUIP_SEAL
  121.  *  32-TRAIT_ATTACK_STATE      55-TRAIT_SLOT_TYPE
  122.  *  33-TRAIT_ATTACK_SPEED
  123.  *  34-TRAIT_ATTACK_TIMES
  124.  *
  125.  * DataId is the code's parameter.  For example, if you wanted to add a boost to Atk power, you would use code: 21 and the dataId would be 2.
  126.  * The numbers here can vary based on the quantity of things in your database and what code is being used.
  127.  *
  128.  * The value is the amount of the effect the code will express as a float.  So, revisiting the above example, if you wanted attack to be raised by 20%,
  129.  * you would use the value 1.2, which is 120%.
  130.  * The final tag for this example would be:  <subweaponTrait: 21, 2, 1.2>
  131.  *
  132.  * A method to assist with finding the code, dataId and value figures lies in the ShowTraitsInConsole param.  Setting it to 1
  133.  * will allow the console to print out an array of normal traits on an equipped item on the moment it is equipped.
  134.  * (Press F12 to open the console by default.)
  135.  * The array will list the traits in the order that they were added in the database.  So if you need to know the values, just make a dummy/temp
  136.  * equip with the traits you want and note what their values are via the console.
  137.  * (Note that notetag related bonuses/traits/etc not provided by this plugin cannot be used here; Those traits will be active as stipulated in thier respective plugins.)
  138.  *
  139.  * A "potential" value has been introduced.
  140.  * This value is a combination of the default stats of a weapon with differing user defined "weights" for each one.
  141.  * This value is used mainly for the choosing of weapons when optimizing.  
  142.  *
  143.  * A script call has been added to aid those wishing to know which equip slot is housing what equip type.
  144.  * Using the script call $gameActors.isWeaponEquipped(type) will return a number based on the defined type
  145.  * (type is the weapon type ID in the database.)
  146.  * 0 if in the first equip slot,
  147.  * 1 if it's in the second,
  148.  * 2 if it's in both,
  149.  * and -1 if in neither.
  150.  * You can omit the type arguement and the function will return those numbers if there is ANY weapon is equipped in those slots.
  151.  *
  152.  * Equip Groups have been added!
  153.  * Tag weapon equips and shield type armor equips with this tag in thier notes:
  154.  *
  155.  * <mdwEquipGroup: x> with x being an integer higher than 0.
  156.  * If an equip has this tag, it will only be able to be dual wielded with other equips with the same group number.
  157.  * <doubleEquipTrait: x, y, z> Use this tag paired with setting an equip group.  If two equips with matching equip group sets
  158.  * number are equipped together, the traits created will be exhibited.
  159.  * Remember that a matching mdwEquipGroup tag MUST exist on the items for the trait to be seen.
  160.  * <syncTrait: x, y, z> If two equips are the same in the database, the traits created will be exhibited.    
  161.  * Using the plugin Param Matched_Equip_Omit_Traits, the only traits shown will be the double equip or sync traits.
  162.  * Main or Sub weapon traits will not be used when those traits are active.  (Other traits provided by different plugins and the database WILL
  163.  * still be active.)
  164.  *
  165.  * Added Dual Groups.  You can specify any number of groups to give specific sets of weapon equips traits.
  166.  * First, add the equip to groups by adding this notetag:
  167.  *
  168.  * <duGroup: x>
  169.  *
  170.  * With x being any interger above 0.
  171.  * You can add as many copies of this tag as you need to give a single equip multiple group numbers.
  172.  * Then use the following notetag to assign traits to each group:
  173.  *
  174.  * <dualGroupTrait: a, x, y, z>
  175.  *
  176.  * Noting the extra a interger which will match one of your group numbers.
  177.  * You can make a = 0 to make that trait activate whenever a group is formed.
  178.  *
  179.  * Now, if you equip two weapons with the same group number, those group triats will be added to the PC
  180.  * (Again, the 0 group traits will also be added)
  181.  * If you equip two of the same item, those traits will only be counted once.
  182.  *
  183.  * Note about param ShieldsArmor
  184.  * The ShieldsArmor param allows devs to make it so offhand only weapons show up as armor in default item Menu.
  185.  * For those that wish for some offhand weapons to remain in the Weapon category while still using the param,
  186.  * use the notetag <offHWeapon> to create an exception and have that weapon show up in the weapon category.
  187.  */
  188.  
  189. var Mal = Mal || {};
  190.  
  191. Mal.Parameters = PluginManager.parameters('MalMZDualWield');
  192. Mal.Param = Mal.Param || {};
  193.  
  194. Mal.power = [];
  195.  Mal.power.push(Number(Mal.Parameters['PowerAdjustement0']));
  196.  Mal.power.push(Number(Mal.Parameters['PowerAdjustement1']));
  197.  Mal.power.push(Number(Mal.Parameters['PowerAdjustement2']));
  198.  Mal.power.push(Number(Mal.Parameters['PowerAdjustement3']));
  199.  Mal.power.push(Number(Mal.Parameters['PowerAdjustement4']));
  200.  Mal.power.push(Number(Mal.Parameters['PowerAdjustement5']));
  201.  Mal.power.push(Number(Mal.Parameters['PowerAdjustement6']));
  202.  Mal.power.push(Number(Mal.Parameters['PowerAdjustement7']));
  203.  
  204.  Mal.Par2HLock = Number((Mal.Parameters['2H_DisableOtherSlot']))
  205.  
  206.  var MalDualDatabaseLoad = DataManager.isDatabaseLoaded;
  207. DataManager.isDatabaseLoaded = function() {
  208.   if (!MalDualDatabaseLoad.call(this)) return false;
  209.   if (!DataManager._malDual_DatabaseLoaded) {
  210.     this.processDualNotetags($dataWeapons);
  211.     this.processDualNotetags($dataArmors);
  212.     DataManager._malDual_DatabaseLoaded = true;
  213.   }
  214.   return true;
  215. };
  216.  
  217. DataManager.processDualNotetags = function(group) {
  218.     for (var n = 1; n < group.length; n++) {
  219.         var obj = group[n];
  220.         obj.mdwEquipGroup = -1;
  221.         obj.syncNum = obj.id;
  222.         obj.dualGroup = [];
  223.         obj.dualGroupTraits = [];
  224.         this.createDualTraits(obj);
  225.     }
  226. };
  227.  
  228. DataManager.createDualTraits = function(obj) {
  229.  
  230. var traits = [];
  231. var noteread = obj.note;
  232. while(noteread.indexOf("mainweaponTrait") > -1)
  233. {
  234.     var notereg = noteread.split("<mainweaponTrait: ");
  235.     var match = notereg[1].split(", ");
  236.     var match2 = match[2].split(">");
  237.     match2 = match2[0];
  238.     traits.push({"code": parseInt(match[0]), "dataId": parseInt(match[1]), "value": Number(match2)});
  239.     noteread = noteread.replace("<mainweaponTrait: ", " ");
  240. }
  241. obj.mainWTraits = traits;
  242.  
  243. traits = [];
  244. while(noteread.indexOf("subweaponTrait") > -1)
  245. {
  246.     var notereg = noteread.split("<subweaponTrait: ");
  247.     var match = notereg[1].split(", ");
  248.     var match2 = match[2].split(">");
  249.     match2 = match2[0];
  250.     traits.push({"code": parseInt(match[0]), "dataId": parseInt(match[1]), "value": Number(match2)});
  251.     noteread = noteread.replace("<subweaponTrait: ", " ");
  252. }
  253. obj.subWTraits = traits;
  254.  
  255. traits = [];
  256. while(noteread.indexOf("doubleGripTrait") > -1)
  257. {
  258.     var notereg = noteread.split("<doubleGripTrait: ");
  259.     var match = notereg[1].split(", ");
  260.     var match2 = match[2].split(">");
  261.     match2 = match2[0];
  262.     traits.push({"code": parseInt(match[0]), "dataId": parseInt(match[1]), "value": Number(match2)});
  263.     noteread = noteread.replace("<doubleGripTrait: ", " ");
  264. }
  265. obj.doubleGripTraits = traits;
  266.  
  267. traits = [];
  268. while(noteread.indexOf("doubleEquipTrait") > -1)
  269. {
  270.     var notereg = noteread.split("<doubleEquipTrait: ");
  271.     var match = notereg[1].split(", ");
  272.     var match2 = match[2].split(">");
  273.     match2 = match2[0];
  274.     traits.push({"code": parseInt(match[0]), "dataId": parseInt(match[1]), "value": Number(match2)});
  275.     noteread = noteread.replace("<doubleEquipTrait: ", " ");
  276. }
  277. obj.doubEquTraits = traits;
  278.  
  279. traits = [];
  280. while(noteread.indexOf("syncTrait") > -1)
  281. {
  282.     var notereg = noteread.split("<syncTrait: ");
  283.     var match = notereg[1].split(", ");
  284.     var match2 = match[2].split(">");
  285.     match2 = match2[0];
  286.     traits.push({"code": parseInt(match[0]), "dataId": parseInt(match[1]), "value": Number(match2)});
  287.     noteread = noteread.replace("<syncTrait: ", " ");
  288. }
  289. obj.syncTraits = traits;
  290.  
  291. traits = [];
  292. while(noteread.indexOf("dualGroupTrait") > -1)
  293. {
  294.     var notereg = noteread.split("<dualGroupTrait: ");
  295.     var match = notereg[1].split(", ");
  296.     var match2 = match[3].split(">");
  297.     match2 = match2[0];
  298.     var DSGroup = parseInt(match[0]);
  299.     obj.dualGroupTraits[DSGroup] = obj.dualGroupTraits[DSGroup] || [];
  300.     obj.dualGroupTraits[DSGroup].push({"code": parseInt(match[1]), "dataId": parseInt(match[2]), "value": Number(match2)});
  301.     noteread = noteread.replace("<dualGroupTrait: ", " ");
  302. }
  303.  
  304. traits = [];
  305.  
  306. while(noteread.indexOf("duGroup") > -1)
  307. {
  308.     var match = noteread.split("<duGroup: ");
  309.     var match2 = match[1].split(">");
  310.     obj.dualGroup = obj.dualGroup || []
  311.     obj.dualGroup.push(parseInt(match2[0]));
  312.     noteread = noteread.replace("<duGroup: ", " ");
  313. }
  314.        
  315. obj.PotentialP = 0;
  316. while(noteread.indexOf("<PotentialP:") > -1)
  317. {
  318.     var notereg = noteread.split("<PotentialP: ");
  319.     var match = notereg[1].split("> ");
  320.     obj.PotentialP = parseInt(match[0]);
  321.     noteread = noteread.replace("<PotentialP:", " ");
  322. };
  323. if(noteread.indexOf("mdwEquipGroup") > -1) {
  324.     var notereg = noteread.split("<mdwEquipGroup: ");
  325.     var match = parseInt(notereg[1]);
  326.     obj.mdwEquipGroup = match;
  327. }
  328. };
  329.  
  330. var MalEquipChangeOK = Game_Actor.prototype.isEquipChangeOk
  331. Game_Actor.prototype.isEquipChangeOk = function(slotId) {
  332.  
  333.     if (this.twohanding > -1 && Mal.Par2HLock == 1) {
  334.         if (this.twohanding == 0 && slotId == 1) return false;
  335.         if (this.twohanding == 1 && slotId == 0) return false;
  336.     }
  337.     return MalEquipChangeOK.call(this, slotId);
  338. };
  339.  
  340.  
  341. var MalOnSlotOK = Scene_Equip.prototype.onItemOk
  342. Scene_Equip.prototype.onItemOk = function() {
  343.     if (this._slotWindow.index() === 0 && !(this._itemWindow.item()) && (this._actor.equips()[1] && Mal.Parameters['MustUseMain'] == 1)) {
  344.     SoundManager.playBuzzer();
  345.     }else {
  346.     SoundManager.playEquip();
  347.     this.actor().changeEquip(this._slotWindow.index(), this._itemWindow.item());
  348.     if (this._itemWindow.item() && Mal.Parameters['ShowTraitsInConsole'] == 1) console.log(this._itemWindow.item().traits);
  349.     }
  350.     this._slotWindow.activate();
  351.     this._slotWindow.refresh();
  352.     this._itemWindow.deselect();
  353.     this._itemWindow.refresh();
  354.     this._statusWindow.refresh();
  355.     this._slotWindow.show();
  356.     this._itemWindow.hide();
  357.     this._slotWindow.select(this._slotWindow.index());
  358. };
  359.  
  360. Game_Actor.prototype.changeEquip = function(slotId, item) {
  361.     if (this.tradeItemWithParty(item, this.equips()[slotId]) &&
  362.             (!item || this.equipSlots()[slotId] === item.etypeId)) {
  363.         this._equips[slotId].setObject(item);
  364.         if (slotId == 0) {
  365.         var slot = 1;
  366.         } else {
  367.         var slot = 0;
  368.         }
  369.         if (slotId < 2) {
  370.         if (item && item.meta.twohand && !this.currentClass().meta.monkeygrip) {
  371.         this.tradeItemWithParty(null, this.equips()[slot])
  372.         this._equips[slot].setObject(null);
  373.         }
  374.         if (item && this.equips()[slot] && this.equips()[slot].meta.twohand && !this.currentClass().meta.monkeygrip){
  375.         this.tradeItemWithParty(null, this.equips()[slot])
  376.         this._equips[slot].setObject(null);
  377.         }
  378.         if (Mal.Parameters['MustUseMain'] == 1 && !this.equips()[0] && this.equips()[1]){
  379.         if(!this.equips()[1].meta.shld) this._equips[0].setObject(this.equips()[1]);
  380.         this._equips[1].setObject(null);
  381.         }
  382.         }
  383.     this.check2Hand();
  384.         this.refresh();
  385.     }
  386. };
  387.  
  388. Game_Actor.prototype.check2Hand = function() {
  389.     this.twohanding = -1;
  390.     var equip = this.equips()[0];
  391.     if (equip && equip.meta.twohand && !this.currentClass().meta.monkeygrip) this.twohanding = 0;
  392.     var equip = this.equips()[1];
  393.     if (equip && equip.meta.twohand && !this.currentClass().meta.monkeygrip) this.twohanding = 1;
  394. };
  395.  
  396. Game_Actor.prototype.forceChangeEquip = function(slotId, item) {
  397.     if (item) {
  398.         this._equips[slotId].setObject(item);
  399.         if (slotId == 0) {
  400.             var slot = 1;
  401.         } else {
  402.             var slot = 0;
  403.         }
  404.         if (slotId < 2) {
  405.             if (item && item.meta.twohand && !this.currentClass().meta.monkeygrip) {
  406.                 this._equips[slot].setObject(null);
  407.             }
  408.             if (item && this.equips()[slot] && this.equips()[slot].meta.twohand && !this.currentClass().meta.monkeygrip){
  409.                 this._equips[slot].setObject(null);
  410.             }
  411.             if (Mal.Parameters['MustUseMain'] == 1 && !this.equips()[0] && this.equips()[1]){
  412.                 this._equips[0].setObject(this.equips()[1]);
  413.                 this._equips[1].setObject(null);
  414.             }
  415.         }
  416.     } else {
  417.         this._equips[slotId].setObject(null);
  418.     }
  419.     this.releaseUnequippableItems(true);
  420.     this.check2Hand();
  421.     this.refresh();
  422. };
  423.  
  424. var MalreleaseUnEI = Game_Actor.prototype.releaseUnequippableItems;
  425. Game_Actor.prototype.releaseUnequippableItems = function(forcing) {
  426. MalreleaseUnEI.call(this, forcing);
  427. this.check2Hand();
  428. };
  429.  
  430. var MalEquip = Window_EquipItem.prototype.includes
  431. Window_EquipItem.prototype.includes = function(item) {
  432.     if (item === null) {
  433.         if (this._slotId === 0 && (this._actor.equips()[1] && Mal.Parameters['MustUseMain'] == 1)){
  434.         return;
  435.         } else {
  436.         return true;
  437.     }}
  438.     if (this._slotId === 0 && item.meta.shld && this._actor.currentClass().meta.monkeygrip) {
  439.     return this._actor.canEquip(item);
  440.     }
  441.     if (this._slotId === 0 && item.meta.shld) {
  442.     return false;
  443.     }
  444.     if (this._slotId === 1 && !(item.meta.shld) && this._actor.currentClass().meta.handnshld) {
  445.     return false;
  446.     }
  447.     if (this._slotId === 1 && !(this._actor.equips()[0]) && Mal.Parameters['MustUseMain'] == 1 ) {
  448.     return false;
  449.     }
  450.     if (this._slotId === 1 && item.meta.mainWeaponOnly) {
  451.     return false;
  452.     }
  453.     if (this._slotId < 0 || item.etypeId !== this._actor.equipSlots()[this._slotId]) {
  454.         return false;
  455.     }
  456.     if (this._slotId === 0 && this._actor.equips()[1] && item.mdwEquipGroup != this._actor.equips()[1].mdwEquipGroup) return false;
  457.     if (this._slotId === 1 && this._actor.equips()[0] && item.mdwEquipGroup != this._actor.equips()[0].mdwEquipGroup) return false;
  458.     return this._actor.canEquip(item);
  459. };
  460.  
  461. Game_Actor.prototype.optimizeEquipments = function() {
  462.     var maxSlots = this.equipSlots().length;
  463.     this.clearEquipments();
  464.     this.setWeapons();
  465.     for (var i = 2; i < maxSlots; i++) {
  466.         if (this.isEquipChangeOk(i)) {
  467.             this.changeEquip(i, this.bestEquipItem(i));
  468.         }
  469.     }
  470. };
  471.  
  472. Game_Actor.prototype.setWeapons = function() {
  473.     var mode = 1;
  474.     if (this.currentClass().meta.handnshld) mode = 2;
  475.     if (this.currentClass().meta.monkeygrip) mode = 3;
  476.     //First weapon selection
  477.     if (mode == 1 || mode == 2) {
  478.         var items = $gameParty.equipItems().filter(function(item) {
  479.         return item.etypeId === 1 && this.canEquip(item) && !item.meta.shld;
  480.     }, this);
  481.     }
  482.     if (mode == 3) {
  483.         var items = $gameParty.equipItems().filter(function(item) {
  484.         return item.etypeId === 1 && this.canEquip(item);
  485.     }, this);
  486.     }
  487.     var mainW1 = this.bestEquipW(items);
  488.     //End first weapon
  489.     //Second Weapon Selection (First sub)
  490.     if (mode == 1) {
  491.         var newItems = $gameParty.equipItems().filter(function(item) {
  492.         return item.etypeId === 1 && this.canEquip(item) && !(item == mainW1 && $gameParty.oneOfAKind(mainW1)) && !item.meta.twohand && !item.meta.mainWeaponOnly;
  493.     }, this);
  494.     }
  495.     if (mode == 2) {
  496.         var newItems = $gameParty.equipItems().filter(function(item) {
  497.         return item.etypeId === 1 && this.canEquip(item) && !(item == mainW1 && $gameParty.oneOfAKind(mainW1))  && !item.meta.twohand && item.meta.shld && !item.meta.mainWeaponOnly;
  498.     }, this);
  499.     }
  500.     if (mode == 3) {
  501.         var newItems = $gameParty.equipItems().filter(function(item) {
  502.         return item.etypeId === 1 && this.canEquip(item) && !(item == mainW1 && $gameParty.oneOfAKind(mainW1));
  503.     }, this);
  504.     }
  505.     var subW1 = this.bestEquipW(newItems);
  506.     //End Second
  507.     //Third weapon selection (Second Main)
  508.     var subW2 = null;
  509.     if (mode == 1 || mode == 2) {
  510.     items = $gameParty.equipItems().filter(function(item) {
  511.         return item.etypeId === 1 && this.canEquip(item) && !item.meta.shld && !item.meta.twohand && !(item == mainW1 && $gameParty.oneOfAKind(mainW1)) && !(item == subW1 && $gameParty.oneOfAKind(subW1));
  512.     }, this);
  513.     var subW2 = this.bestEquipW(items);
  514.     }
  515.     //End Third
  516.     if (subW2 !== null) {
  517.     if(this.potential(mainW1) > this.potential(subW1) + this.potential(subW2)) {
  518.     if (this.isEquipChangeOk(0)) this.changeEquip(0, mainW1);
  519.     if (!mainW1.meta.twohand) this.changeEquip(1, subW2);
  520.     } else {
  521.     if (this.isEquipChangeOk(0)) this.changeEquip(0, subW2);
  522.     if (this.isEquipChangeOk(1) && subW1 && (subW2.mdwEquipGroup == subW1.mdwEquipGroup)) this.changeEquip(1, subW1);
  523.     }
  524.     } else {
  525.     if (this.isEquipChangeOk(0)) this.changeEquip(0, mainW1);
  526.     if (this.isEquipChangeOk(1) && subW1 && (mainW1.mdwEquipGroup == subW1.mdwEquipGroup)) this.changeEquip(1, subW1);
  527.     }
  528. }
  529.  
  530. Game_Party.prototype.oneOfAKind = function (item) {
  531.     if(this.numItems(item) == 1) return true;
  532.     return false;
  533. };
  534.  
  535. Game_Actor.prototype.bestEquipW = function(itemSet) {
  536.     var items = itemSet;
  537.     var bestItem = null;
  538.     var bestPerformance = -1000;
  539.     for (var i = 0; i < items.length; i++) {
  540.         var performance = this.potential(items[i]);
  541.         if (performance > bestPerformance) {
  542.             bestPerformance = performance;
  543.             bestItem = items[i];
  544.         }
  545.     }
  546.     return bestItem;
  547. };
  548.  
  549. var MalBestEquip = Game_Actor.prototype.bestEquipItem
  550. Game_Actor.prototype.bestEquipItem = function(slotId) {
  551.     const etypeId = this.equipSlots()[slotId];
  552.     const items = $gameParty
  553.         .equipItems()
  554.         .filter(item => item.etypeId === etypeId && this.canEquip(item));
  555.     let bestItem = null;
  556.     let bestPerformance = -1000;
  557.     for (let i = 0; i < items.length; i++) {
  558.         //const performance = this.calcEquipItemPerformance(items[i]);
  559.         const performance = this.potential(items[i]);
  560.         if (performance > bestPerformance) {
  561.             bestPerformance = performance;
  562.             bestItem = items[i];
  563.         }
  564.     }
  565.     return bestItem;
  566. };
  567.  
  568. Game_Actor.prototype.potential = function(item) {
  569.     if (!item) return -1001;
  570.     var potent = item.PotentialP;
  571.     var potent2 = Number(item.params.reduce((a, b) => a + b));
  572.     return potent + potent2;
  573. };
  574.  
  575. var MalItemList = Window_ItemList.prototype.includes
  576. Window_ItemList.prototype.includes = function(item) {
  577.     switch (this._category) {
  578.     case 'item':
  579.         return DataManager.isItem(item) && item.itypeId === 1;
  580.     case 'weapon':
  581.         if (Mal.Parameters['ShieldsArmor'] == 1){
  582.         return DataManager.isWeapon(item) && (!item.meta.shld || item.meta.offHWeapon);
  583.         } else{
  584.         return DataManager.isWeapon(item);
  585.         }
  586.     case 'armor':
  587.     if (Mal.Parameters['ShieldsArmor'] == 1){
  588.         return DataManager.isArmor(item) || (item && item.meta.shld && !item.meta.offHWeapon);
  589.         } else {
  590.         return DataManager.isArmor(item);
  591.         }
  592.     case 'keyItem':
  593.         return DataManager.isItem(item) && item.itypeId === 2;
  594.     default:
  595.         return false;
  596.     }
  597. };
  598.  
  599. var MalSlotName = Window_StatusBase.prototype.actorSlotName
  600. Window_StatusBase.prototype.actorSlotName = function(actor, index) {
  601.     var slots = this._actor.equipSlots();
  602.     if (index === 1 && this._actor.isDualWield()) return this._actor ? Mal.Parameters['OffhandSlotName'] : '';
  603.     return $dataSystem.equipTypes[slots[index]];
  604. };
  605.  
  606. var MalparamPlus = Game_Actor.prototype.paramPlus
  607. Game_Actor.prototype.paramPlus = function(paramId) {
  608.     var value = Game_Battler.prototype.paramPlus.call(this, paramId);
  609.     var equips = this.equips();
  610.     for (var i = 0; i < equips.length; i++) {
  611.         var item = equips[i];
  612.         if (item) {
  613.             if (i == 1) {
  614.             if (item.meta.OffhandAdjust) {
  615.             value += (item.params[paramId] * item.meta.OffhandAdjust / 100) ;
  616.             } else {
  617.                 value += (item.params[paramId] * Mal.Parameters['OffhandAdjust'] / 100) ;
  618.                 }} else {
  619.                 value += item.params[paramId];
  620.                 }
  621.         }
  622.     }
  623.     return value;
  624. };
  625.  
  626. Game_Actor.prototype.attackAnimationId2 = function() {
  627.     var weapons = this.weapons();
  628.     if (weapons[1] && weapons[1].meta.subweapon) return 0;
  629.     return weapons[1] ? weapons[1].animationId : 0;
  630. };
  631.  
  632.  
  633. var MalGame_Actor_allTraits = Game_Actor.prototype.allTraits;
  634. Game_Actor.prototype.allTraits = function() {
  635.     var traits = MalGame_Actor_allTraits.call(this);
  636.     var equips = this.equips();
  637.     var syncFlag = false;
  638.     var matchFlag = false;
  639.     var dualFlag = false;
  640.     if (this.hasMatchedEquip()) {
  641.         traits = traits.concat(equips[0].doubEquTraits);
  642.         traits = traits.concat(equips[1].doubEquTraits);
  643.         matchFlag = true;
  644.     }
  645.     if (this.useSyncTrait()) {
  646.         traits = traits.concat(equips[0].syncTraits);
  647.         syncFlag = true;
  648.     }
  649.     if (this.useDuoTrait()) {
  650.         var dGrp1 = equips[0].dualGroup;
  651.         var dGrp2 = equips[1].dualGroup;
  652.         for (var i = 0; i < dGrp1.length; i++) {
  653.             var point = dGrp1[i];
  654.             if (dGrp2.contains(point)) {
  655.                 if(equips[0].dualGroupTraits[point]) {
  656.                     traits = traits.concat(equips[0].dualGroupTraits[point]);
  657.                     dualFlag = true;
  658.                 }
  659.                 if(equips[1].dualGroupTraits[point]) {
  660.                     if (equips[0].syncNum == equips[1].syncNum) continue;
  661.                     traits = traits.concat(equips[1].dualGroupTraits[point]);
  662.                     dualFlag = true;
  663.                 }
  664.             }
  665.                 if(equips[0].dualGroupTraits[0]) {
  666.                     traits = traits.concat(equips[0].dualGroupTraits[0]);
  667.                     dualFlag = true;
  668.                 }
  669.                 if(equips[1].dualGroupTraits[0]) {
  670.                     if (equips[0].syncNum == equips[1].syncNum) continue;
  671.                     traits = traits.concat(equips[1].dualGroupTraits[0]);
  672.                     dualFlag = true;
  673.                 }
  674.         }      
  675.     }
  676.     if (Mal.Parameters['Matched_Equip_Omit_Traits'] == 1 && (matchFlag || syncFlag || dualFlag)) {
  677.         //Do Nothing
  678.     } else {
  679.     for (var i = 0; i < equips.length; i++) {
  680.         var item = equips[i];
  681.         if(item) {
  682.             if (i == 0 && item.mainWTraits) traits = traits.concat(item.mainWTraits);
  683.             if (i == 1 && item.subWTraits)  traits = traits.concat(item.subWTraits);
  684.             if(item.doubleGripTraits && this.isDoubleGripping()) traits = traits.concat(item.doubleGripTraits);
  685.         }
  686.     }
  687.     }
  688.     return traits;
  689. };
  690.  
  691. Game_Actor.prototype.hasMatchedEquip = function() {
  692.     var equips = this.equips();
  693.     if (!equips[0] || !equips[1]) return false;
  694.     if (equips[0] && equips[0].mdwEquipGroup != -1) return false;
  695.     if (equips[1] && equips[1].mdwEquipGroup != -1) return false;
  696.     return (((equips[0] && equips[0].doubEquTraits) && (equips[1] && equips[1].doubEquTraits)) && equips[0].mdwEquipGroup != -1 && (equips[0].mdwEquipGroup == equips[1].mdwEquipGroup));
  697.     return false;
  698. };
  699.  
  700. Game_Actor.prototype.useSyncTrait = function() {
  701.     var equips = this.equips();
  702.     return (((equips[0] && equips[0].syncTraits) && (equips[1] && equips[1].syncTraits)) && (equips[0].syncNum == equips[1].syncNum));
  703.     return false;
  704. };
  705.  
  706. Game_Actor.prototype.useDuoTrait = function() {
  707.     var equips = this.equips();
  708.     return ((equips[0] && equips[0].dualGroup != []) && (equips[1] && equips[1].dualGroup != []));
  709.     return false;
  710. };
  711.  
  712. Game_Actor.prototype.isSameWeapon = function() {
  713.     var equips = this.equips();
  714.     if (equips[0] && equips[1]) return (equips[0].syncNum == equips[1].syncNum);
  715.     return false;
  716. };
  717.    
  718. Game_Actor.prototype.isDoubleGripping = function() {
  719.     var equips = this.equips();
  720.     return (this.hasDoubleGrip() && ((equips[0] && !equips[1]) || (equips[1] && !equips[0])));
  721. };
  722.  
  723. Game_Actor.prototype.hasDoubleGrip = function() {
  724.     if (this.currentClass().note.indexOf("<doubleGrip>") > -1) return true;
  725.     var equips = this.equips();
  726.     for (var i = 0; i < equips.length; i++) {
  727.         if (equips[i] && equips[i].note.indexOf("<doubleGrip>") > -1) return true;
  728.     }
  729.     var states = this.states();
  730.     for (var i = 0; i < states.length; i++) {
  731.         if (states[i].note.indexOf("<doubleGrip>") > -1) return true;
  732.     }
  733.     return false;
  734. }
  735.  
  736. Game_Actor.prototype.isWeaponEquipped = function(type) {
  737. if (type) {
  738. var type = Number(type);
  739. } else {
  740. var type = 0;
  741. }
  742. if (type == 0){
  743.     if (this.equips()[0]) {
  744.         if (this.equips()[1]) return 2;
  745.         return 0;
  746.     }
  747.     if (this.equips()[1]) return 1;
  748.     return -1;
  749. } else {
  750.     if (this.equips()[0] && this.equips()[0].wtypeId == type) {
  751.         if (this.equips()[1] && this.equips()[1].wtypeId == type) return 2;
  752.         return 0;
  753.     }
  754.     if (this.equips()[1] && this.equips()[1].wtypeId == type) return 1;
  755.     return -1;
  756. }
  757. };
  758.  
  759. Game_Enemy.prototype.isWeaponEquipped = function(type) {
  760. return -1;
  761. };
Add Comment
Please, Sign In to add comment