Advertisement
Maliki79

MalMZ_FomarSkillSystem_Ex

Oct 4th, 2020 (edited)
2,522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // RPG Maker MZ - Skill Buy System - Maliki Extension Version 3.1.3a
  3. //=============================================================================
  4.  
  5. /*:
  6.  * @target MZ
  7.  * @plugindesc Provides extra functionality to Fomar's Skill Buy System.
  8.  * @author Maliki79
  9.  *
  10.  * @param Default Skill Group Cost Buildup 
  11.  * @type integer   
  12.  * @desc Default percentage Grouped Skills cost rise.  
  13.  * @default 0      
  14.  * 
  15.  * @help MalMZ_FomarSkillSystem_Ex.js ver 3.1.3a
  16.  *
  17.  * Evals added for skills once learned.
  18.  * Use Notetag <skillBuyEvals: code >>>
  19.  * noting that the end of the tag MUST have 3 > signs as shown and the space after the :
  20.  * When the skill is learned from the Skill Learn menu, the code will run.
  21.  * You can use this to increase stats for the player, count skills learned,
  22.  * and much more!
  23.  * 
  24.  * Code has been added to allow grouping of skills for the purpose of increasing   
  25.  * AP costs within the group.  First, you'll need to set groups via the Skill notetag  
  26.  * <skillLearnGroup: x> with x being an integer higher than 0. 
  27.  * Once done, every skill that is a part of that group will increase AP cost once any skill in that
  28.  * group is bought.
  29.  * This increase can be controlled in 2 ways.  
  30.  * first is by the Skill notetag <skillLearnGroupBdup: x> with x being an integer. 
  31.  * The other is by using the Default Skill Group Cost Buildup plugin param.
  32.  * each will raise the total percentage rate of skill purchases in that group by the number given. 
  33.  * (Technically, you can use negative numbers to lower the percentage, if you like)
  34.  * 
  35.  * There have been new script calls created to allow new skills to be added to the 
  36.  * buying list. These call are:
  37.  * Game_Actors.actor(p).addBuyableSkills(x, y, z...);  
  38.  * and 
  39.  * $gameActors.addBuyableSkillsAll(x, y, z...);
  40.  * The first one is usable for a single actor (p is their ID in the database)
  41.  * while the second works on ALL actors in your database, whether in the party or not. 
  42.  * (x, y, z refers to the skill Ids of the skills you wish to add and you can add as many as you like.)
  43.  * 
  44.  * Also added method to remove skills from list.
  45.  * Use script call Game_Actors.actor(p).removeBuyableSkills(x, y, z...);
  46.  * The skill will be removed from the list preventing the actor from being able to
  47.  * learn it.  It will NOT remove already learned skills from the actor. That is what
  48.  * foregtSkill() is for.
  49.  *
  50.  * A quick tip: if you want to make a consumable that teaches the skills easily to one actor   
  51.  * or to the current party, you can use an item and the damage formulas.   
  52.  * Make the item/skill with a healing effect and put this in the damage formula:
  53.  * b.addBuyableSkills(x, y, z); 0  
  54.  * You should also make the item add a state with 0% success so the effect will always trigger.
  55.  * 
  56.  * Item requirements have been added.  
  57.  * Use the following notetag in skill notes:   
  58.  * 
  59.  * <skillBuyItemCost: x, y>    
  60.  * 
  61.  * with x being the item ID and y being the quantity.  
  62.  * Insert multiple tags to add different items.
  63.  * Don't include copies of the same item and do not use
  64.  * weapon or armors.   
  65.  * 
  66.  * Skill buy Evals have been added!
  67.  * Use the following notetag in skill notes:   
  68.  * 
  69.  *<buyReqEval: x>>>
  70.  * 
  71.  * with x being an expression that evaluates to true or false. 
  72.  * s[x] and v[x] can be used for switches and variables respectively.  
  73.  * Example   <buyReqEval: actor.level > v[1]>>>
  74.  * Example 2 <buyReqEval: $gameParty.numItems($dataItems[1] == 1)>>>   
  75.  * 
  76.  * Created Skill learning Categories.  
  77.  * To use, when choosing the skill buy command name in the plugin parameters, separate 
  78.  * different categories with a comma.  
  79.  * Example: Weapon Skills,Magic,Stat Boosts
  80.  * You can make as many categories as you want.
  81.  * 
  82.  * Once made, you must put EACH learnable skill in a category. 
  83.  * Do this by adding <skillBuyCat:x> in Skill notes with x being
  84.  * the exact spelling of your premade category.
  85.  * You can only assign one category to each skill.
  86.  *
  87.  * Tip 2: you can use gainItem to regain an item used via item requirements, to
  88.  * make a required tool for learning skills!
  89.  */
  90.  
  91. var MalMZ = MalMZ || {};   
  92. MalMZ.SkillBuy = {};   
  93. MalMZ.SkillBuy.parameters = PluginManager.parameters('MalMZ_FomarSkillSystem_Ex');
  94. MalMZ.SkillBuy.defaultGroupCostRate = parseInt(MalMZ.SkillBuy.parameters["Default Skill Group Cost Buildup"]);
  95.    
  96. var MalDataMLSR = DataManager.loadSkillRequirements;
  97. DataManager.loadSkillRequirements = function() {   
  98. MalDataMLSR.call(this);
  99. for (var i = 1; i < $dataSkills.length; i++) {
  100.     $dataSkills[i].skillBuyItemCost = [];  
  101.     $dataSkills[i].buyReqEval = [];
  102.     $dataSkills[i].skillBuyCat = [];
  103.     $dataSkills[i].skillBuyEvals = []; 
  104.     var noteread = $dataSkills[i].note;
  105.     while(noteread.indexOf("skillBuyEvals") > -1)  
  106.     {  
  107.         var notereg = noteread.split("<skillBuyEvals: ");  
  108.         var match = notereg[1].split(">>>");   
  109.         $dataSkills[i].skillBuyEvals.push(match[0]);   
  110.         noteread = noteread.replace("<skillBuyEvals: ", " ");  
  111.     }  
  112.     while(noteread.indexOf("skillBuyItemCost") > -1)   
  113.     {  
  114.         var notereg = noteread.split("<skillBuyItemCost: ");   
  115.         var match = notereg[1].split(">"); 
  116.         var match2 = match[0].split(", "); 
  117.         var set = [parseInt(match2[0]), parseInt(match2[1])]   
  118.         $dataSkills[i].skillBuyItemCost.push(set), 
  119.         noteread = noteread.replace("<skillBuyItemCost: ", " ");   
  120.     }  
  121.     while(noteread.indexOf("buyReqEval") > -1) 
  122.     {  
  123.         var notereg = noteread.split("<buyReqEval: "); 
  124.         var match = notereg[1].split(">>>");   
  125.         $dataSkills[i].buyReqEval.push(match[0]);  
  126.         noteread = noteread.replace("<buyReqEval: ", " "); 
  127.     }  
  128.     $dataSkills[i].skillLearnGroup = parseInt($dataSkills[i].meta.skillLearnGroup) || -1;  
  129.     $dataSkills[i].skillLearnGroupBdup = parseInt($dataSkills[i].meta.skillLearnGroupBdup || 0);   
  130.     if ($dataSkills[i].meta.skillBuyCat) $dataSkills[i].skillBuyCat = $dataSkills[i].meta.skillBuyCat;
  131.     }
  132. };
  133.        
  134. var MalGActorInitMem = Game_Actor.prototype.initMembers
  135. Game_Actor.prototype.initMembers = function() {
  136.     MalGActorInitMem.call(this);
  137.     this._buyableSkills = [];  
  138.     this._skillLearnGroups = [];   
  139. };
  140.            
  141. var MalSkillBuyGASetup = Game_Actor.prototype.setup
  142. Game_Actor.prototype.setup = function(actorId) {   
  143.     MalSkillBuyGASetup.call(this, actorId);
  144.     this.setBuyableSkills();   
  145. };
  146.    
  147. Game_Actor.prototype.setBuyableSkills = function() {   
  148. var skills = this.buyableSkills(); 
  149.     this._buyableSkills = skills;  
  150. }; 
  151.        
  152. Game_Actor.prototype.addBuyableSkills = function (...args) {   
  153.     var list = args;   
  154.     var skills = this._buyableSkills;  
  155.     var skills2 = [];  
  156.     for (var i = 0; i < list.length; i++) {
  157.         var newSkill = $dataSkills[list[i]];   
  158.         skills.push(newSkill); 
  159.     }; 
  160.     for (var i = 0; i < skills.length; i++) {  
  161.         var newSkill = skills[i];  
  162.         if (skills2.indexOf(skills[i]) == -1) skills2.push(skills[i]); 
  163.     }; 
  164.     this._buyableSkills = skills2; 
  165. }; 
  166.  
  167. Game_Actor.prototype.removeBuyableSkills = function (...args) {
  168.     var list = args;
  169.     var skills = this._buyableSkills;
  170.     for (var i = 0; i < list.length; i++) {
  171.         var newSkill = $dataSkills[list[i]];   
  172.         var index = skills.indexOf(newSkill);
  173.         if (index > -1) {
  174.             skills.splice(index, 1);
  175.         }; 
  176.     }
  177.     this._buyableSkills = skills;
  178. }
  179.        
  180. Game_Actors.prototype.addBuyableSkillsAll = function(...args) {
  181.     var actors = this._data;   
  182.     var list = args;   
  183.     var newList = "";  
  184.     for (var i = 1; i < actors.length; i++) {  
  185.         for (var j = 0; j < list.length; j++) actors[i].addBuyableSkills(list[j]); 
  186.     }; 
  187. }; 
  188.    
  189. Game_Actor.prototype.buyableSkillCheck = function(skill) { 
  190.     if (skill && skill.buyReq.length > 0) {
  191.         for (var i = 0; i < skill.buyReq.length; i++) {
  192.             if (!this.isLearnedSkill(skill.buyReq[i])) return false;   
  193.         }  
  194.     }  
  195.     if (!this.itemRequiredCheck(skill))  return false; 
  196.     if (!this.evalRequiredCheck(skill))  return false; 
  197.     return true;   
  198. };
  199.            
  200. Game_Actor.prototype.itemRequiredCheck = function(skill) { 
  201.     if(skill.skillBuyItemCost == []) return true;  
  202.     for (var i = 0; i < skill.skillBuyItemCost.length; i++) {  
  203.         var req = skill.skillBuyItemCost[i];   
  204.         var count = $gameParty.numItems($dataItems[req[0]]);   
  205.         if (req[1] > count) return false;  
  206.     }; 
  207.     return true;   
  208. }; 
  209.        
  210. Game_Actor.prototype.evalRequiredCheck = function(skill) { 
  211.     if(skill.buyReqEval == []) return true;
  212.     for (var i = 0; i < skill.buyReqEval.length; i++) {
  213.         var buyEvals = skill.buyReqEval[i];
  214.         var actor = this;  
  215.         var s = $gameSwitches._data;   
  216.         var v = $gameVariables._data;  
  217.         if (!eval(buyEvals)) return false; 
  218.     }; 
  219.     return true;   
  220. };
  221.    
  222. Window_SkillType.prototype.makeCommandList = function() {  
  223.     if (this._actor) { 
  224.         Fomar.SkillBuy.Window_SkillType_makeCommandList.call(this);
  225.         var names = Fomar.SkillBuy.SkillBuyCommandName;
  226.         var finalNames = [];   
  227.         if(names.indexOf(",") > -1) {  
  228.         var finalNamesSub = names.split(",");  
  229.         for (var i = 0; i < finalNamesSub.length; i++) {   
  230.             finalNames.push(finalNamesSub[i]); 
  231.         }  
  232.         } else {   
  233.             finalNames.push(names);
  234.         }  
  235.     for (var i = 0; i < finalNames.length; i++) {  
  236.         this.addCommand(finalNames[i], "skill", true, finalNames.length == 1 ? Fomar.SkillBuy.stypeId : finalNames[i]);
  237.     }  
  238.     }; 
  239. };
  240.      
  241. var MalWSkillLstMIL = Window_SkillList.prototype.makeItemList; 
  242. Window_SkillList.prototype.makeItemList = function() { 
  243.     if (this._actor && this._stypeId == Fomar.SkillBuy.stypeId) {  
  244.         this._data = this._actor._buyableSkills.filter((item => (Fomar.SkillBuy.showLearnt || !this._actor.isLearnedSkill(item.id)) && 
  245.         (Fomar.SkillBuy.showUnReq || this._actor.buyableSkillCheck(item))));   
  246.     } else if(this._actor && Number.isNaN(Number.parseInt(this._stypeId))) {   
  247.         this._data = this._actor._buyableSkills.filter((item => (Fomar.SkillBuy.showLearnt || !this._actor.isLearnedSkill(item.id)) && 
  248.         (Fomar.SkillBuy.showUnReq || this._actor.buyableSkillCheck(item)) && item.skillBuyCat == this._stypeId));  
  249.         } else {   
  250.             MalWSkillLstMIL.call(this);
  251.         }  
  252. };
  253.      
  254. var MalWSLisEn = Window_SkillList.prototype.isEnabled; 
  255. Window_SkillList.prototype.isEnabled = function(item) {
  256.     if (!item) {   
  257.         return false;  
  258.     }  
  259.     if (this._stypeId == Fomar.SkillBuy.stypeId || Number.isNaN(Number.parseInt(this._stypeId))) { 
  260.         var actor = this._actor;   
  261.         return (this._actor._ap >= this.skillAPCost(item, actor) && (!this._actor.isLearnedSkill(item.id) && this._actor.buyableSkillCheck(item)));
  262.         } else {   
  263.             return MalWSLisEn.call(this, item);
  264.         }  
  265. };
  266.  
  267. Window_SkillList.prototype.skillAPCost = function(item, actor) {   
  268.     var actor = actor; 
  269.     var item = item;   
  270.     var cost = parseInt(item.meta["ap"]) || 1; 
  271.     if (item.skillLearnGroup > 0 && actor._skillLearnGroups[item.skillLearnGroup]) {   
  272.         cost = (cost * (1.0 + (actor._skillLearnGroups[item.skillLearnGroup] / 100))); 
  273.     }  
  274.     return parseInt(cost); 
  275. };
  276.  
  277. var MalWinSklLstDrawSklCst = Window_SkillList.prototype.drawSkillCost; 
  278. Window_SkillList.prototype.drawSkillCost = function(skill, x, y, width) {  
  279.     if (skill && (this._stypeId == Fomar.SkillBuy.stypeId || Number.isNaN(Number.parseInt(this._stypeId)))) {
  280.         var actor = this._actor;   
  281.         if (this._actor.isLearnedSkill(skill.id)) {
  282.             this.changeTextColor(ColorManager.textColor(Fomar.SkillBuy.apCostColor));  
  283.             this.drawText("---", x, y, width, "right");
  284.         } else {   
  285.             if(skill.skillBuyItemCost != []){  
  286.                 var x2 = x*6; //x*2;   
  287.                 for (var i = 0; i < skill.skillBuyItemCost.length; i++) {  
  288.                     var req = skill.skillBuyItemCost[i];   
  289.                     var count = $gameParty.numItems($dataItems[req[0]]);   
  290.                     if (req[1] > count) {  
  291.                         this.changeTextColor(ColorManager.textColor(10));  
  292.                     } else {   
  293.                         this.changeTextColor(ColorManager.textColor(3));   
  294.                     }  
  295.                     this.drawIcon($dataItems[req[0]].iconIndex, width - this.costWidth() - x2, y + 2); 
  296.                     this.drawText(req[1], x-(x2+8) , y, width - this.costWidth(), "right");
  297.                     x2 += this.costWidth();
  298.                 }; 
  299.             }; 
  300.         this.changeTextColor(ColorManager.textColor(Fomar.SkillBuy.apCostColor));
  301.         if (SceneManager._scene instanceof Scene_Skill) this.drawText(this.skillAPCost(skill, actor) + Fomar.APSystem.vocabAP, x, y, width, "right");  
  302.         }  
  303.     } else {   
  304.         MalWinSklLstDrawSklCst.call(this, skill, x, y, width); 
  305.     }  
  306. };
  307.  
  308. Window_SkillList.prototype.update = function() {   
  309.     Window_Selectable.prototype.update.call(this); 
  310.     if (this._stypeId != Fomar.SkillBuy.stypeId || !Number.isNaN(Number.parseInt(this._stypeId))) {
  311.         this._req = [];
  312.         this._oldIndex = -1;   
  313.         return;
  314.     }  
  315.     if (this._oldIndex != this._index) {   
  316.         this._oldIndex = this._index;  
  317.         this._req = [];
  318.         if (this.item() && this.item().buyReq.length > 0) {
  319.             for (var i = 0; i < this.item().buyReq.length; i++) {  
  320.                 this._req.push(this.item().buyReq[i]); 
  321.             }  
  322.         }  
  323.         this.refresh();
  324.     }  
  325. };
  326.  
  327. var MalSSUseItem = Scene_Skill.prototype.useItem;  
  328. Scene_Skill.prototype.useItem = function() {   
  329.     if (this.item() && (this._itemWindow._stypeId == Fomar.SkillBuy.stypeId || Number.isNaN(Number.parseInt(this._itemWindow._stypeId)))) {
  330.         this.actor().learnSkill(this.item().id);   
  331.         this.actor()._ap -= this.skillAPCost(this.item(), this.actor());   
  332.         this.processLearnEvals(this.actor(), this.item().id);  
  333.         this.processItemCosts(this.item());
  334.         if(this.item().skillLearnGroup > 0) {  
  335.             var sgNumb = this.item().skillLearnGroup;  
  336.             if(!this.actor()._skillLearnGroups[sgNumb]) this.actor()._skillLearnGroups[sgNumb] = 0;
  337.             this.actor()._skillLearnGroups[sgNumb] += this.item().skillLearnGroupBdup || MalMZ.SkillBuy.defaultGroupCostRate || 1; 
  338.         }  
  339.         this._statusWindow.refresh();  
  340.         this._itemWindow.refresh();
  341.         if (this._itemWindow._index >= this._itemWindow.maxItems()) {  
  342.             this._itemWindow.select(this._itemWindow._index - 1);  
  343.         }  
  344.         this.actor().refresh();
  345.     } else {   
  346.           MalSSUseItem.call(this); 
  347.     }  
  348. };
  349.  
  350. Scene_Skill.prototype.processLearnEvals = function (actor, skillId){   
  351.     var skillEvals = $dataSkills[skillId].skillBuyEvals;   
  352.     var actor = actor; 
  353.     var s = $gameSwitches._data;   
  354.     var v = $gameVariables._data;  
  355.     for (var i = 0; i < skillEvals.length; i++) {  
  356.         var SEval = skillEvals[i]; 
  357.         eval(SEval);   
  358.     }; 
  359. }; 
  360.        
  361. Scene_Skill.prototype.processItemCosts = function (item){  
  362.     if(item.skillBuyItemCost != []){   
  363.         for (var i = 0; i < item.skillBuyItemCost.length; i++) {   
  364.             var req = item.skillBuyItemCost[i];
  365.             $gameParty.loseItem($dataItems[req[0]], req[1]);   
  366.         }; 
  367.     };      
  368. }; 
  369.        
  370. Scene_Skill.prototype.skillAPCost = function(item, actor) {
  371.     var actor = actor; 
  372.     var item = item;   
  373.     var cost = parseInt(item.meta["ap"]) || 1; 
  374.     if (item.skillLearnGroup > 0 && actor._skillLearnGroups[item.skillLearnGroup]) {   
  375.         cost = (cost * (1.0 + (actor._skillLearnGroups[item.skillLearnGroup] / 100))); 
  376.     }  
  377.     return parseInt(cost); 
  378. }; 
  379.      
  380. Scene_Skill.prototype.determineItem = function() { 
  381.     if (this._itemWindow._stypeId == -2 || Number.isNaN(Number.parseInt(this._itemWindow._stypeId))) {
  382.         this.useItem();
  383.         this.activateItemWindow(); 
  384.     } else {   
  385.         Scene_ItemBase.prototype.determineItem.call(this); 
  386.     }  
  387. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement