// =====================================
// GACHA-STYLE RECRUITMENT SYSTEM
// BY MIDNIGHT89 - 2023
// =====================================
/*:
* @plugindesc Gacha-Style Recruitment System
* @author MIDNIGHT89
* @version 1.0
*
* @param --- CONFIG ---
* @default
*
* @param Actors Variable ID
* @parent --- CONFIG ---
* @type variable
* @desc Variable ID for the potential actors you chose on the setup phase. See the help text on the left.
* @default 1
*
* @param Classes Variable ID
* @parent --- CONFIG ---
* @type variable
* @desc Variable ID for the potential classes you chose on the setup phase. See the help text on the left.
* @default 2
*
* @param --- TIER SYSTEM ---
* @default
*
* @param Activate Tier System
* @parent --- TIER SYSTEM ---
* @type number
* @desc Enable or disable the tier system.
* 1 = ON / 0 = OFF
* @min 0
* @max 1
* @default 1
*
* @param Newbie Tier Name
* @parent --- TIER SYSTEM ---
* @type string
* @desc Custom name for the newbie tier.
* @default Newbie
*
* @param Apprentice Tier Name
* @parent --- TIER SYSTEM ---
* @type string
* @desc Custom name for the apprentice tier.
* @default Apprentice
*
* @param Expert Tier Name
* @parent --- TIER SYSTEM ---
* @type string
* @desc Custom name for the expert tier.
* @default Expert
*
* @param Master Tier Name
* @parent --- TIER SYSTEM ---
* @type string
* @desc Custom name for the master tier.
* @default Master
*
* @param Newbie Passive State
* @parent --- TIER SYSTEM ---
* @type state
* @desc State applied if recruit is a newbie.
*
* @param Apprentice Passive State
* @parent --- TIER SYSTEM ---
* @type state
* @desc State applied if recruit is an apprentice.
*
* @param Expert Passive State
* @parent --- TIER SYSTEM ---
* @type state
* @desc State applied if recruit is an expert.
*
* @param Master Passive State
* @parent --- TIER SYSTEM ---
* @type state
* @desc State applied if recruit is a master.
*
* @param Apprentice RNG Trigger Value
* @parent --- TIER SYSTEM ---
* @type number
* @desc If the Tier Choice RNG value is above this one, the recruit will be an apprentice.
* @default 76
*
* @param Expert RNG Trigger Value
* @parent --- TIER SYSTEM ---
* @type number
* @desc If the Tier Choice RNG value is above this one, the recruit will be an expert.
* @default 90
*
* @param Master RNG Trigger Value
* @parent --- TIER SYSTEM ---
* @type number
* @desc If the Tier Choice RNG value is above this one, the recruit will be an master.
* @default 97
*
* @param --- MISC ---
* @default
*
* @param Unique Classes Mode
* @parent --- MISC ---
* @type number
* @desc If activated, a class can't be pulled more than once.
* 1 = ON / 0 = OFF
* @min 0
* @max 1
* @default 0
*
* @param No More Recruits Message
* @parent --- MISC ---
* @type text
* @desc Custom message if recruiting is impossible.
* See help on the left.
* @default There is nobody left to recruit !
*
* @help
*
* ==========================================================================
* WHAT THIS PLUGIN DOES ?
* ==========================================================================
*
* This plugin allows you to implement a simple gacha-style recruitment system.
* When you execute the plugin command, it randomly chooses an actor from a
* list you configure in the setup phase, a class, an optional tier and it
* generates a recruit with these parameters that immediately joins the player's
* party.
* There is several options that you can change. Find more details about these
* in the HOW TO USE section below.
*
* Before using the plugin, you have to do some setup by following the steps
* in the SETUP section below.
*
* ==========================================================================
* SETUP
* ==========================================================================
*
* Before using this plugin, you have to follow some simple steps :
*
* 1.Set up the initial list of recrutables actors by executing this code once
* at the beginning of your game (via a script call) :
*
* $gameVariables.setValue(XX, [1, 2, 3]);
*
* Replace XX by the ID of the game's variable you want to use.
* This variable will store the list of the actors that can be potentially
* recruited.
* Be sure to choose an unused variable ID, once it's set, it cannot be changed.
* Replace 1, 2, 3...by the IDs of the actors you want to be recruitable.
* Respect the syntax and formatting.
*
* Then, set up the list of recruitable classes by executing this code once
* at the beginning of your game (via a script call) :
*
* $gameVariables.setValue(YY, [1, 2, 3]);
*
* Replace YY by the ID of the game variable you want to use.
* This is the variable that will contains the list of the classes that can be
* potentially attributed to recruited actors.
* Be sure to choose an unused variable ID, different from the one you chose
* for the actors. Once it's set, it cannot be changed.
* Replace 1, 2, 3...by the IDs of the classes you want to be assigned to new
* recruits.
* Respect the syntax and formatting.
*
* In the plugin parameters window (on the right), select the variables you've
* chosen for the actors list and the classes list in the "Actors Variable ID"
* and "Classes Variable ID" parameters.
*
* The plugin is now ready to be used !
*
* ==========================================================================
* HOW TO USE
* ==========================================================================
*
* During the game, initiate a "pull" by using the plugin command :
*
* GSRSRecruit (!!!!!!!!!! NOT WORKING YET !!!!!!!!!!)
*
* Or by using the script call :
*
* $gameMap._interpreter.GSRSRecruit();
*
* When you do so, a recruit is generated : a random actor (from the list you've
* configured) is chosen, a random class (from the configured list) and a random
* tier is assigned to him/her.
*
* By default, you can have class duplicates, meaning that multiple recruits can
* have the same class. You can make classes unique in the plugin parameters by
* enabling the "Unique Classes Mode". If this mode is enabled, a class can be
* pulled only if you don't already have a party member with this class.
*
* By default, there is 4 tiers possible for the new recruit :
* Newbie, Apprentice, Expert, Master.
* You can change the name of the tiers and change the proc probabilities of each
* teir in the plugin parameters.
* You can automatically apply states to recruits depending on their tier. It's
* useful if you want to apply bonuses to recruits depending on their tier, and/or
* display an icon on their profile showing their tier.
* (You might need an external plugin if you want these states to be permanent).
*
* To decide which tier the recruit will inherit, the plugin uses RNG :
* A random number between 1 and 100 is chosen and, depending of the result the
* tier is assigned. By default, the values are :
* 1-75 : Newbie / 76-90 : Apprentice / 91 - 96 : Expert / 97 - 100 : Master.
* You can change these values, and even disable some tiers simply by entering
* a trigger value superior to 100.
* If you use custom trigger values, be sure to always put a value for a tier
* superior to the previous tier trigger value, or it will up everything :X
* 30 / 87 / 95 : GOOD
* 45 / 87 / 68 : NOT GOOD
* You can also totally disable the tier system in the plugin parameters.
*
* After the pull, a message appears, informing the player of the results of
* the pull. The list of recruitable actors (and classes if "Unique Classes
* Mode" is enabled) is then automatically updated.
* If you execute a new pull but there is no actors left to recruit (or any
* classes available left if you activated the "Unique Classes Mode"), a message
* saying so appears.
* You can customize the message in the plugin parameters.
*
* ==========================================================================
* USEFUL SCRIPTS
* ==========================================================================
*
* If you want to manually add or re-add an actor to the list of potential
* recruits, use the script call :
*
* var new_actor = XX;
* if (!$gameVariables.value(var_id_actors).includes(new_actor)) {
* }
* else { $gameVariables.value(var_id_actors).push(new_actor);
* }
*
* Replace XX by the ID of the actor you want to add to the potential recruit list.
* If the actor is already in the list, nothing happens (to avoid duplicates).
*
* You can also remove an actor from the list :
*
* var remove_actor = XX;
* if (!$gameVariables.value(var_id_actors).includes(remove_actor)) {
* $gameVariables.value(var_id_actors).splice($gameVariables.value(var_id_actors)
* .indexOf(remove_actor), 1);
* }
* else {
* }
*
* Replace XX by the ID of the actor you want to remove from the potential recruit list.
* If the actor is not in the list, nothing happens.
*
* You can do the same with classes, to add a new class :
*
* var new_class = XX;
* if (!$gameVariables.value(var_id_classes).includes(new_class)) {
* }
* else { $gameVariables.value(var_id_classes).push(new_class);
* }
*
* And to remove a class :
*
* var remove_class = XX;
* if (!$gameVariables.value(var_id_classes).includes(remove_class)) {
* $gameVariables.value(var_id_classes).splice($gameVariables.value(var_id_classes)
* .indexOf(remove_class), 1);
* }
* else {
* }
*
* Please note that if you manually add a class that has already been pulled, it
* will be pullable again, making the "Unique Class Mode" obsolete if it's enabled.
*
* Developpers can check the list of the pullable actors and classes at any time
* via the game's console (F12) :
*
* console.log(var_id_actors);
* console.log(var_id_classes);
*
* A log is also systematically printed in the console at each pull.
*
*
* ==========================================================================
* HAPPY GAME MAKING :)
* ==========================================================================
*/
// (PLUGIN PARAMETERS)
var params = PluginManager.parameters('GSRSRecruit');
var no_more_recruits_message = String(params['No More Recruits Message']);
var var_id_actors = Number(params['Actors Variable ID']);
var var_id_classes = Number(params['Classes Variable ID']);
var tier_system = Number(params['Activate Tier System']);
var newbie_tier_name = String(params['Newbie Tier Name']);
var apprentice_tier_name = String(params['Apprentice Tier Name']);
var expert_tier_name = String(params['Expert Tier Name']);
var master_tier_name = String(params['Master Tier Name']);
var newbie_passive_state = Number(params['Newbie Passive State']);
var apprentice_passive_state = Number(params['Apprentice Passive State']);
var expert_passive_state = Number(params['Expert Passive State']);
var master_passive_state = Number(params['Master Passive State']);
var apprentice_trigger_value = Number(params['Apprentice RNG Trigger Value']);
var expert_trigger_value = Number(params['Expert RNG Trigger Value']);
var master_trigger_value = Number(params['Master RNG Trigger Value']);
var unique_classes_mode = Number(params['Unique Classes Mode']);
// -----------------------------------------------------------
(function() {
// (PLUGIN COMMAND)
Game_Interpreter.prototype.GSRSRecruit = function() {
// (NO RECRUIT LEFT MESSAGE)
if ($gameVariables.value(var_id_actors).length === 0) {
$gameMessage.add(no_more_recruits_message);
}
else if ($gameVariables.value(var_id_classes).length === 0) {
$gameMessage.add(no_more_recruits_message);
}
else {
// (RANDOM ACTOR PICK)
var random_actor_pick;
do {
random_actor_pick = $gameVariables.value(var_id_actors)[Math.floor(Math.random() * $gameVariables.value(var_id_actors).length)];
} while ($gameParty.members().some(function(actor) {
return actor.actorId() === random_actor_pick;
}));
// (RANDOM CLASS PICK)
var random_class_pick;
if (unique_classes_mode == 0) {
random_class_pick = $gameVariables.value(var_id_classes)[Math.floor(Math.random() * $gameVariables.value(var_id_classes).length)];
}
else {
var available_classes = $gameVariables.value(var_id_classes);
do {
random_class_pick = available_classes[Math.floor(Math.random() * available_classes.length)];
}
while ($gameParty.members().some(function(actor) {
return actor.currentClass().id === random_class_pick;
}));
}
// (APPLY BONUS STATE DEPENDING ON TIER)
if (tier_system == 1) {
var tier_name = newbie_tier_name;
$gameActors.actor(random_actor_pick).addState(newbie_passive_state);
var random_tier_pick = Math.floor(Math.random() * 100) + 1;
if (random_tier_pick >= apprentice_trigger_value && random_tier_pick < expert_trigger_value) {
tier_name = apprentice_tier_name;
$gameActors.actor(random_actor_pick).removeState(newbie_passive_state);
$gameActors.actor(random_actor_pick).addState(apprentice_passive_state);
} else if (random_tier_pick >= expert_trigger_value && random_tier_pick < master_trigger_value) {
tier_name = expert_tier_name;
$gameActors.actor(random_actor_pick).removeState(newbie_passive_state);
$gameActors.actor(random_actor_pick).addState(expert_passive_state);
} else if (random_tier_pick >= master_trigger_value) {
tier_name = master_tier_name;
$gameActors.actor(random_actor_pick).removeState(newbie_passive_state);
$gameActors.actor(random_actor_pick).addState(master_passive_state);
}
}
// (ADD THE GENERATED RECRUIT TO THE GROUP)
var acteur = $gameActors.actor(random_actor_pick);
$gameParty.addActor(random_actor_pick);
acteur.changeClass(random_class_pick, false);
// (SHOW A MESSAGE WITH A SUMMARY OF PULLED RECRUIT INFOS)
var actor = $gameActors.actor(random_actor_pick);
var actor_name = actor.name();
var class_name = actor.currentClass().name;
var portraitFilename = actor.faceName();
var portraitIndex = actor.faceIndex();
if (tier_system == 1) {
var message = actor_name + " joins the party ! Class : " + class_name + " Tier : " + tier_name + ".";
$gameMessage.setFaceImage(portraitFilename, portraitIndex);
$gameMessage.add(message);
}
else {
var message = actor_name + " joins the party ! Class : " + class_name + ".";
$gameMessage.setFaceImage(portraitFilename, portraitIndex);
$gameMessage.add(message);
}
// (UPDATE THE POTENTIAL ACTORS RECRUIT LIST)
$gameVariables.value(var_id_actors).splice($gameVariables.value(var_id_actors).indexOf(random_actor_pick), 1);
// (UPDATE THE POTENTIAL CLASS LIST IF UNIQUE CLASS MODE IS ACTIVATED)
if (unique_classes_mode == 1) {
$gameVariables.value(var_id_classes).splice($gameVariables.value(var_id_classes).indexOf(random_class_pick), 1);
}
// (LOGS)
console.log('---------------------');
console.log('Chosen Actor ID : ' + random_actor_pick);
console.log('Chosen Class ID : ' + random_class_pick);
console.log('Tier RNG : ' + random_tier_pick);
console.log('Chosen Tier : ' + tier_name);
console.log('Updated Potential Actors List : ' + $gameVariables.value(var_id_actors));
console.log('Updated Potential Classes List : ' + $gameVariables.value(var_id_classes));
console.log('Unique Class Mode Enabled ? ' + unique_classes_mode);
console.log('Tier System Enabled ? ' + tier_system);
console.log('Custom Tier Names : ' + newbie_tier_name + ' ' + apprentice_tier_name + ' ' + expert_tier_name + ' ' + master_tier_name);
console.log('Custom Tier States : ' + newbie_passive_state + ' ' + apprentice_passive_state + ' ' + expert_passive_state + ' ' + master_passive_state);
console.log('---------------------');
}
};
})();