Advertisement
modern_algebra

Geomancy

Oct 31st, 2015
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. //  Geomancy.js
  3. //=============================================================================
  4. //  Version: 1.0.1
  5. //  Date: 31 October 2015
  6. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. /*:
  8.  * @plugindesc Set terrain and region restrictions on skill use
  9.  * @author Modern Algebra (rmrk.net)
  10.  * @help To set up a skill so that it can only be used in certain terrains, you
  11.  * need to put one of the following codes in its notebox:
  12.  *
  13.  *      <onlyTerrains:x>
  14.  *      <prohibitedTerrains:y>
  15.  *
  16.  * If you use the onlyTerrains code, then the skill can be used only on terrains
  17.  * with ID x. If you use the prohibitedTerrains code, then the skill can only be
  18.  * used if the party is not on the terrain with ID y. In both cases, x and y
  19.  * must be set to integers. You can set as many terrain tags as you want; just
  20.  * separate them with a space or a comma.
  21.  *
  22.  * The region codes work essentially the same way.
  23.  *
  24.  *      <onlyRegions:x>
  25.  *      <prohibitedRegions:x>
  26.  *
  27.  * Examples:
  28.  *
  29.  *      <onlyRegions:1 3 4 76>
  30.  *          The skill can only be used when the party is in regions 1, 3, 4, or 76
  31.  *
  32.  *      <prohibitedRegions:5 10>
  33.  *          The skill can be used in every region except regions 5 and 10
  34.  *
  35.  *      <onlyTerrains:7>
  36.  *          The skill can only be used on tiles marked with terrain tag 7.
  37.  */
  38. //=============================================================================
  39.  
  40. (function() {
  41.    
  42.     // Game_BattlerBase - meetsSkillConditions
  43.     //   Test terrain and region too
  44.     var _mag_Game_BattlerBase_meetsSkillConditions =
  45.             Game_BattlerBase.prototype.meetsSkillConditions;
  46.     Game_BattlerBase.prototype.meetsSkillConditions = function(skill) {
  47.         var skillTest = _mag_Game_BattlerBase_meetsSkillConditions.apply(this, arguments);
  48.         if (!skillTest || DataManager.isBattleTest()) { return skillTest; }
  49.         return this.magMeetsSkillTerrainConditions(skill);
  50.     };
  51.    
  52.     // Game_BattlerBase - Test terrain and region conditions for skills
  53.     Game_BattlerBase.prototype.magMeetsSkillTerrainConditions = function(skill) {
  54.         var terrainTag = $gamePlayer.terrainTag();
  55.         var regionId = $gamePlayer.regionId();
  56.         var rpatt = /\d+/g
  57.         // Can't use if on an expressly prohibited terrain
  58.         var prohibitedTerrains = skill.meta.prohibitedTerrains;
  59.         if (prohibitedTerrains) {
  60.             var match = prohibitedTerrains.match(rpatt);
  61.             if (match && match.map(Number).contains(terrainTag)) { return false; }
  62.         }
  63.         // Can't use if in an expressly prohibited region
  64.         var prohibitedRegions = skill.meta.prohibitedRegions;
  65.         if (prohibitedRegions) {
  66.             var match = prohibitedRegions.match(rpatt);
  67.             if (match && match.map(Number).contains(regionId)) { return false; }
  68.         }
  69.         // Can't use if exclusive terrains defined and not on one
  70.         var onlyTerrains = skill.meta.onlyTerrains;
  71.         if (onlyTerrains) {
  72.             var match = onlyTerrains.match(rpatt);
  73.             if (match && !match.map(Number).contains(terrainTag)) { return false; }
  74.         }
  75.         // Can't use if exclusive regions defined and not in one
  76.         var onlyRegions = skill.meta.onlyRegions;
  77.         if (onlyRegions) {
  78.             var match = onlyRegions.match(rpatt);
  79.             if (match && !match.map(Number).contains(regionId)) { return false; }
  80.         }
  81.         return true; // Can use the skill otherwise
  82.     };
  83.    
  84. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement