Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // RPG Maker MZ - Skill Buy System - Maliki Extension Version 3.1.3a
- //=============================================================================
- /*:
- * @target MZ
- * @plugindesc Provides extra functionality to Fomar's Skill Buy System.
- * @author Maliki79
- *
- * @param Default Skill Group Cost Buildup
- * @type integer
- * @desc Default percentage Grouped Skills cost rise.
- * @default 0
- *
- * @help MalMZ_FomarSkillSystem_Ex.js ver 3.1.3a
- *
- * Evals added for skills once learned.
- * Use Notetag <skillBuyEvals: code >>>
- * noting that the end of the tag MUST have 3 > signs as shown and the space after the :
- * When the skill is learned from the Skill Learn menu, the code will run.
- * You can use this to increase stats for the player, count skills learned,
- * and much more!
- *
- * Code has been added to allow grouping of skills for the purpose of increasing
- * AP costs within the group. First, you'll need to set groups via the Skill notetag
- * <skillLearnGroup: x> with x being an integer higher than 0.
- * Once done, every skill that is a part of that group will increase AP cost once any skill in that
- * group is bought.
- * This increase can be controlled in 2 ways.
- * first is by the Skill notetag <skillLearnGroupBdup: x> with x being an integer.
- * The other is by using the Default Skill Group Cost Buildup plugin param.
- * each will raise the total percentage rate of skill purchases in that group by the number given.
- * (Technically, you can use negative numbers to lower the percentage, if you like)
- *
- * There have been new script calls created to allow new skills to be added to the
- * buying list. These call are:
- * Game_Actors.actor(p).addBuyableSkills(x, y, z...);
- * and
- * $gameActors.addBuyableSkillsAll(x, y, z...);
- * The first one is usable for a single actor (p is their ID in the database)
- * while the second works on ALL actors in your database, whether in the party or not.
- * (x, y, z refers to the skill Ids of the skills you wish to add and you can add as many as you like.)
- *
- * Also added method to remove skills from list.
- * Use script call Game_Actors.actor(p).removeBuyableSkills(x, y, z...);
- * The skill will be removed from the list preventing the actor from being able to
- * learn it. It will NOT remove already learned skills from the actor. That is what
- * foregtSkill() is for.
- *
- * A quick tip: if you want to make a consumable that teaches the skills easily to one actor
- * or to the current party, you can use an item and the damage formulas.
- * Make the item/skill with a healing effect and put this in the damage formula:
- * b.addBuyableSkills(x, y, z); 0
- * You should also make the item add a state with 0% success so the effect will always trigger.
- *
- * Item requirements have been added.
- * Use the following notetag in skill notes:
- *
- * <skillBuyItemCost: x, y>
- *
- * with x being the item ID and y being the quantity.
- * Insert multiple tags to add different items.
- * Don't include copies of the same item and do not use
- * weapon or armors.
- *
- * Skill buy Evals have been added!
- * Use the following notetag in skill notes:
- *
- *<buyReqEval: x>>>
- *
- * with x being an expression that evaluates to true or false.
- * s[x] and v[x] can be used for switches and variables respectively.
- * Example <buyReqEval: actor.level > v[1]>>>
- * Example 2 <buyReqEval: $gameParty.numItems($dataItems[1] == 1)>>>
- *
- * Created Skill learning Categories.
- * To use, when choosing the skill buy command name in the plugin parameters, separate
- * different categories with a comma.
- * Example: Weapon Skills,Magic,Stat Boosts
- * You can make as many categories as you want.
- *
- * Once made, you must put EACH learnable skill in a category.
- * Do this by adding <skillBuyCat:x> in Skill notes with x being
- * the exact spelling of your premade category.
- * You can only assign one category to each skill.
- *
- * Tip 2: you can use gainItem to regain an item used via item requirements, to
- * make a required tool for learning skills!
- */
- var MalMZ = MalMZ || {};
- MalMZ.SkillBuy = {};
- MalMZ.SkillBuy.parameters = PluginManager.parameters('MalMZ_FomarSkillSystem_Ex');
- MalMZ.SkillBuy.defaultGroupCostRate = parseInt(MalMZ.SkillBuy.parameters["Default Skill Group Cost Buildup"]);
- var MalDataMLSR = DataManager.loadSkillRequirements;
- DataManager.loadSkillRequirements = function() {
- MalDataMLSR.call(this);
- for (var i = 1; i < $dataSkills.length; i++) {
- $dataSkills[i].skillBuyItemCost = [];
- $dataSkills[i].buyReqEval = [];
- $dataSkills[i].skillBuyCat = [];
- $dataSkills[i].skillBuyEvals = [];
- var noteread = $dataSkills[i].note;
- while(noteread.indexOf("skillBuyEvals") > -1)
- {
- var notereg = noteread.split("<skillBuyEvals: ");
- var match = notereg[1].split(">>>");
- $dataSkills[i].skillBuyEvals.push(match[0]);
- noteread = noteread.replace("<skillBuyEvals: ", " ");
- }
- while(noteread.indexOf("skillBuyItemCost") > -1)
- {
- var notereg = noteread.split("<skillBuyItemCost: ");
- var match = notereg[1].split(">");
- var match2 = match[0].split(", ");
- var set = [parseInt(match2[0]), parseInt(match2[1])]
- $dataSkills[i].skillBuyItemCost.push(set),
- noteread = noteread.replace("<skillBuyItemCost: ", " ");
- }
- while(noteread.indexOf("buyReqEval") > -1)
- {
- var notereg = noteread.split("<buyReqEval: ");
- var match = notereg[1].split(">>>");
- $dataSkills[i].buyReqEval.push(match[0]);
- noteread = noteread.replace("<buyReqEval: ", " ");
- }
- $dataSkills[i].skillLearnGroup = parseInt($dataSkills[i].meta.skillLearnGroup) || -1;
- $dataSkills[i].skillLearnGroupBdup = parseInt($dataSkills[i].meta.skillLearnGroupBdup || 0);
- if ($dataSkills[i].meta.skillBuyCat) $dataSkills[i].skillBuyCat = $dataSkills[i].meta.skillBuyCat;
- }
- };
- var MalGActorInitMem = Game_Actor.prototype.initMembers
- Game_Actor.prototype.initMembers = function() {
- MalGActorInitMem.call(this);
- this._buyableSkills = [];
- this._skillLearnGroups = [];
- };
- var MalSkillBuyGASetup = Game_Actor.prototype.setup
- Game_Actor.prototype.setup = function(actorId) {
- MalSkillBuyGASetup.call(this, actorId);
- this.setBuyableSkills();
- };
- Game_Actor.prototype.setBuyableSkills = function() {
- var skills = this.buyableSkills();
- this._buyableSkills = skills;
- };
- Game_Actor.prototype.addBuyableSkills = function (...args) {
- var list = args;
- var skills = this._buyableSkills;
- var skills2 = [];
- for (var i = 0; i < list.length; i++) {
- var newSkill = $dataSkills[list[i]];
- skills.push(newSkill);
- };
- for (var i = 0; i < skills.length; i++) {
- var newSkill = skills[i];
- if (skills2.indexOf(skills[i]) == -1) skills2.push(skills[i]);
- };
- this._buyableSkills = skills2;
- };
- Game_Actor.prototype.removeBuyableSkills = function (...args) {
- var list = args;
- var skills = this._buyableSkills;
- for (var i = 0; i < list.length; i++) {
- var newSkill = $dataSkills[list[i]];
- var index = skills.indexOf(newSkill);
- if (index > -1) {
- skills.splice(index, 1);
- };
- }
- this._buyableSkills = skills;
- }
- Game_Actors.prototype.addBuyableSkillsAll = function(...args) {
- var actors = this._data;
- var list = args;
- var newList = "";
- for (var i = 1; i < actors.length; i++) {
- for (var j = 0; j < list.length; j++) actors[i].addBuyableSkills(list[j]);
- };
- };
- Game_Actor.prototype.buyableSkillCheck = function(skill) {
- if (skill && skill.buyReq.length > 0) {
- for (var i = 0; i < skill.buyReq.length; i++) {
- if (!this.isLearnedSkill(skill.buyReq[i])) return false;
- }
- }
- if (!this.itemRequiredCheck(skill)) return false;
- if (!this.evalRequiredCheck(skill)) return false;
- return true;
- };
- Game_Actor.prototype.itemRequiredCheck = function(skill) {
- if(skill.skillBuyItemCost == []) return true;
- for (var i = 0; i < skill.skillBuyItemCost.length; i++) {
- var req = skill.skillBuyItemCost[i];
- var count = $gameParty.numItems($dataItems[req[0]]);
- if (req[1] > count) return false;
- };
- return true;
- };
- Game_Actor.prototype.evalRequiredCheck = function(skill) {
- if(skill.buyReqEval == []) return true;
- for (var i = 0; i < skill.buyReqEval.length; i++) {
- var buyEvals = skill.buyReqEval[i];
- var actor = this;
- var s = $gameSwitches._data;
- var v = $gameVariables._data;
- if (!eval(buyEvals)) return false;
- };
- return true;
- };
- Window_SkillType.prototype.makeCommandList = function() {
- if (this._actor) {
- Fomar.SkillBuy.Window_SkillType_makeCommandList.call(this);
- var names = Fomar.SkillBuy.SkillBuyCommandName;
- var finalNames = [];
- if(names.indexOf(",") > -1) {
- var finalNamesSub = names.split(",");
- for (var i = 0; i < finalNamesSub.length; i++) {
- finalNames.push(finalNamesSub[i]);
- }
- } else {
- finalNames.push(names);
- }
- for (var i = 0; i < finalNames.length; i++) {
- this.addCommand(finalNames[i], "skill", true, finalNames.length == 1 ? Fomar.SkillBuy.stypeId : finalNames[i]);
- }
- };
- };
- var MalWSkillLstMIL = Window_SkillList.prototype.makeItemList;
- Window_SkillList.prototype.makeItemList = function() {
- if (this._actor && this._stypeId == Fomar.SkillBuy.stypeId) {
- this._data = this._actor._buyableSkills.filter((item => (Fomar.SkillBuy.showLearnt || !this._actor.isLearnedSkill(item.id)) &&
- (Fomar.SkillBuy.showUnReq || this._actor.buyableSkillCheck(item))));
- } else if(this._actor && Number.isNaN(Number.parseInt(this._stypeId))) {
- this._data = this._actor._buyableSkills.filter((item => (Fomar.SkillBuy.showLearnt || !this._actor.isLearnedSkill(item.id)) &&
- (Fomar.SkillBuy.showUnReq || this._actor.buyableSkillCheck(item)) && item.skillBuyCat == this._stypeId));
- } else {
- MalWSkillLstMIL.call(this);
- }
- };
- var MalWSLisEn = Window_SkillList.prototype.isEnabled;
- Window_SkillList.prototype.isEnabled = function(item) {
- if (!item) {
- return false;
- }
- if (this._stypeId == Fomar.SkillBuy.stypeId || Number.isNaN(Number.parseInt(this._stypeId))) {
- var actor = this._actor;
- return (this._actor._ap >= this.skillAPCost(item, actor) && (!this._actor.isLearnedSkill(item.id) && this._actor.buyableSkillCheck(item)));
- } else {
- return MalWSLisEn.call(this, item);
- }
- };
- Window_SkillList.prototype.skillAPCost = function(item, actor) {
- var actor = actor;
- var item = item;
- var cost = parseInt(item.meta["ap"]) || 1;
- if (item.skillLearnGroup > 0 && actor._skillLearnGroups[item.skillLearnGroup]) {
- cost = (cost * (1.0 + (actor._skillLearnGroups[item.skillLearnGroup] / 100)));
- }
- return parseInt(cost);
- };
- var MalWinSklLstDrawSklCst = Window_SkillList.prototype.drawSkillCost;
- Window_SkillList.prototype.drawSkillCost = function(skill, x, y, width) {
- if (skill && (this._stypeId == Fomar.SkillBuy.stypeId || Number.isNaN(Number.parseInt(this._stypeId)))) {
- var actor = this._actor;
- if (this._actor.isLearnedSkill(skill.id)) {
- this.changeTextColor(ColorManager.textColor(Fomar.SkillBuy.apCostColor));
- this.drawText("---", x, y, width, "right");
- } else {
- if(skill.skillBuyItemCost != []){
- var x2 = x*6; //x*2;
- for (var i = 0; i < skill.skillBuyItemCost.length; i++) {
- var req = skill.skillBuyItemCost[i];
- var count = $gameParty.numItems($dataItems[req[0]]);
- if (req[1] > count) {
- this.changeTextColor(ColorManager.textColor(10));
- } else {
- this.changeTextColor(ColorManager.textColor(3));
- }
- this.drawIcon($dataItems[req[0]].iconIndex, width - this.costWidth() - x2, y + 2);
- this.drawText(req[1], x-(x2+8) , y, width - this.costWidth(), "right");
- x2 += this.costWidth();
- };
- };
- this.changeTextColor(ColorManager.textColor(Fomar.SkillBuy.apCostColor));
- if (SceneManager._scene instanceof Scene_Skill) this.drawText(this.skillAPCost(skill, actor) + Fomar.APSystem.vocabAP, x, y, width, "right");
- }
- } else {
- MalWinSklLstDrawSklCst.call(this, skill, x, y, width);
- }
- };
- Window_SkillList.prototype.update = function() {
- Window_Selectable.prototype.update.call(this);
- if (this._stypeId != Fomar.SkillBuy.stypeId || !Number.isNaN(Number.parseInt(this._stypeId))) {
- this._req = [];
- this._oldIndex = -1;
- return;
- }
- if (this._oldIndex != this._index) {
- this._oldIndex = this._index;
- this._req = [];
- if (this.item() && this.item().buyReq.length > 0) {
- for (var i = 0; i < this.item().buyReq.length; i++) {
- this._req.push(this.item().buyReq[i]);
- }
- }
- this.refresh();
- }
- };
- var MalSSUseItem = Scene_Skill.prototype.useItem;
- Scene_Skill.prototype.useItem = function() {
- if (this.item() && (this._itemWindow._stypeId == Fomar.SkillBuy.stypeId || Number.isNaN(Number.parseInt(this._itemWindow._stypeId)))) {
- this.actor().learnSkill(this.item().id);
- this.actor()._ap -= this.skillAPCost(this.item(), this.actor());
- this.processLearnEvals(this.actor(), this.item().id);
- this.processItemCosts(this.item());
- if(this.item().skillLearnGroup > 0) {
- var sgNumb = this.item().skillLearnGroup;
- if(!this.actor()._skillLearnGroups[sgNumb]) this.actor()._skillLearnGroups[sgNumb] = 0;
- this.actor()._skillLearnGroups[sgNumb] += this.item().skillLearnGroupBdup || MalMZ.SkillBuy.defaultGroupCostRate || 1;
- }
- this._statusWindow.refresh();
- this._itemWindow.refresh();
- if (this._itemWindow._index >= this._itemWindow.maxItems()) {
- this._itemWindow.select(this._itemWindow._index - 1);
- }
- this.actor().refresh();
- } else {
- MalSSUseItem.call(this);
- }
- };
- Scene_Skill.prototype.processLearnEvals = function (actor, skillId){
- var skillEvals = $dataSkills[skillId].skillBuyEvals;
- var actor = actor;
- var s = $gameSwitches._data;
- var v = $gameVariables._data;
- for (var i = 0; i < skillEvals.length; i++) {
- var SEval = skillEvals[i];
- eval(SEval);
- };
- };
- Scene_Skill.prototype.processItemCosts = function (item){
- if(item.skillBuyItemCost != []){
- for (var i = 0; i < item.skillBuyItemCost.length; i++) {
- var req = item.skillBuyItemCost[i];
- $gameParty.loseItem($dataItems[req[0]], req[1]);
- };
- };
- };
- Scene_Skill.prototype.skillAPCost = function(item, actor) {
- var actor = actor;
- var item = item;
- var cost = parseInt(item.meta["ap"]) || 1;
- if (item.skillLearnGroup > 0 && actor._skillLearnGroups[item.skillLearnGroup]) {
- cost = (cost * (1.0 + (actor._skillLearnGroups[item.skillLearnGroup] / 100)));
- }
- return parseInt(cost);
- };
- Scene_Skill.prototype.determineItem = function() {
- if (this._itemWindow._stypeId == -2 || Number.isNaN(Number.parseInt(this._itemWindow._stypeId))) {
- this.useItem();
- this.activateItemWindow();
- } else {
- Scene_ItemBase.prototype.determineItem.call(this);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement