//=============================================================================
// WeaponClassChange.js
//=============================================================================
/*:
* @plugindesc Changes the class of an actor when they equip a different weapon type.
* @author Jeremy Cannady
*
* @param Weapon Types
* @desc
* @default 1,2,3,4,5,6,7,8,9,10
*
* @param Classes
* @desc
* @default 1,2,3,4,5,6,7,8,9,10
*
* @help The paramter order determines the class change.
*For example when you equip weapon type 1 then your class changes to class 1.
*If you changed the Classes parameter to 2,2,3,4,5,6,7,8,9,10
*In this example when you equip weapon type 1 then your class changes to class 2.
*Note that class number 11 is a reserved class for when you have nothing equipped
*so make sure that class 11 in your database has something in it.
*
*
*
*/
//Opens the debug window, delete the next three '//' to access this.
//var _debugWindow = require('nw.gui').Window.get().showDevTools();
//_debugWindow.moveTo(0, 0);
//window.focus();
(function() {
//Retrieve the parameters
var parameters = PluginManager.parameters('WeaponClassChange');
var weaponType = parameters['Weapon Types'];
var classes = parameters['Classes'];
//Store the parameters into an string array and get rid of the commas
var weaponTypeArray = weaponType.split(',');
var classesArray = classes.split(',');
//Convert the parameters into number array
for(var i=0; i<weaponTypeArray.length; i++) { weaponTypeArray = parseInt(weaponTypeArray, 10); }
for(var i=0; i<classesArray.length; i++) { classesArray = parseInt(classesArray, 10); }
//This function compares which weapon type you ahve equipped and gives you the class that corresponds to it.
Game_Actor.prototype.changeClassWeapon = function(){
//Stores what weapon type you have equipped into variable wtypeId
var weapons = this.weapons();
var wtypeId = weapons[0] ? weapons[0].wtypeId : 0;
//Stores the current actor into a variable so we can use it later.
var currentActor = this.actor().id;
//Finds the position of the equipped weapon in the parameters array and stores it into the variable
var position = weaponTypeArray.indexOf(wtypeId);
//Takes the position of the weapon parameter and makes newClassId equal to the the parameter that is in the same position as the weapon type.
var newClassId = classesArray[position];
//If the actor has unequipped a weapon then make the newClassId into call 11 which is 'Unarmed'
if($gameActors.actor(currentActor).hasNoWeapons()){newClassId = 11;};
//Returns the new class when this function is called
return newClassId;
};
//Whenever there is an equipment change then this function runs
Game_Actor.prototype.changeEquip = function(slotId, item) {
if (this.tradeItemWithParty(item, this.equips()[slotId]) &&
(!item || this.equipSlots()[slotId] === item.etypeId)) {
this._equips[slotId].setObject(item);
this.refresh();
//Don't edit the above, was taken directly from the rpg.objects.js file
//Stores the actor id into a variable for later use
var currentActor = this.actor().id;
//Stores our current exp so we know what it is
var currentEXP = $gameActors.actor(currentActor).currentExp();
//Changes our class based on what our function changeClassWeapon gave us in the return
$gameActors.actor(currentActor).changeClass($gameActors.actor(currentActor).changeClassWeapon());
//Changes our exp back to what it was before the class change
$gameActors.actor(currentActor).changeExp(currentEXP,false);
};
};
})();