Weapons with many Weapon Types (Done)

I am hoping to be able to assign additional Weapon Types to a single weapon so that it will qualify for multiple skill 'Required Weapon' options.


The weapon would be treated as the default database selected type for purposes of equipping. However, it would include the additional weapon types along with its default type, when any skill is checking for required weapons.


I leave the specific note tag details, etc.., up to the author. 🙂


Note: I would hope that anyone might use the solution for their own project as well. Commercial or not.
Seems I may be the only one in need of this. 🙂 No attention.
Since this is so small, and its about time I start poking at Javascript, I've gone ahead and attempted to tackle it...


So far, not so good. >_>


Anyone willing to look at this and point out where I am going wrong here?
 

Spoiler
//RD_WeaponTypes.js
//This is incomplete...

//Credits:
// Hime (Of HimeWorks) I stole the regex function! 🙂

var RD = RD || {};
RD.WeaponTypes = RD.WeaponTypes || {};

(function($) {

// <weapon types: xx, xx>
$.WTRegex = /<weapon[-_ ]types:\s*(.+?)\s*>/im

$.extraWeaponTypes = function(equip) {
if (equip.extraWeaponTypes === undefined) {
equip.extraWeaponTypes = [];
var res = $.WTRegex.exec(equip.note);
if (res) {
var data = res[1].split(",");
for (var i = 0; i < data.length; i++) {
equip.extraWeaponTypes.push(Math.floor(data));
}
}
}
return equip.extraWeaponTypes;
};

//Include additional WeaponTypes.
var RD_isWtypeEquipped = Game_Actor.prototype.isWtypeEquipped;
Game_Actor.prototype.isWtypeEquipped = function(wtypeId) {
//Immediately call alias...
if (RD_isWtypeEquipped.call(this, wtypeId) === true) {
return true;
}

return this.weapons().some(function(weapon) {
console.log("Checking " + weapon.name + " for Added WTypes.");
//Check wtype additions
var n = $.extraWeaponTypes(weapon);
console.log(n);
for(var i = 0; i < n.length; ++i) {
console.log("Checked: " + n);
if(n === wtypeId) {
console.log("Equipped: " + wtypeId);
return true;
}
}

});
};


})(RD.WeaponTypes);






Attempting to use it causes an undefined function error, and I don't see how. Maybe it's something simple and my Javascript-noob eyes are oblivious to it.


Edit:


I figured out why I was getting the undefined function. But the regex is returning an empty array.


When I replace the regex call with a hard value array the plugin works. I just need to figure out why the note tag is not fitting the regex.


Note: An example of the note tag is commented above the regex functions code.


I appreciate any assistance!
Well, it seems the issue was not the code but a conflict with someone else's code. 🙂


The above code will work for anyone NOT using Yanfly's Item Core.


For those that are using it, make sure to select the plugins parameter for Midgame Note Parsing as TRUE.


I am not versed enough in Javascript yet to try and figure out how to work around the fact that Item Core wipes copied equips note tags.

Original thread: https://forums.rpgmakerweb.com/threads/weapons-with-many-weapon-types-done.55304/