Advertisement
DrDhoom

[RGSS3] Regional Spells

Sep 30th, 2014
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.95 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # • Dhoom Regional Spells v1.0
  4. # -- Last Updated: 2014.09.30
  5. # -- Level: Easy
  6. # -- Requires: None
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["DHRegional_Spells"] = true
  12.  
  13. #==============================================================================
  14. # ¥ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2014.09.30 - Started and Finished Script.
  17. #==============================================================================
  18. # ¥ Introduction
  19. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  20. # This script change how spells works based on regional id.
  21. #==============================================================================
  22. # ▼ Instructions
  23. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  24. # To install this script, open up your script editor and copy/paste this script
  25. # to an open slot below ▼ Materials and Required Scripts but above ▼ Main.
  26. #
  27. # -----------------------------------------------------------------------------
  28. # Skill Notetags - These notetags go in the skill notebox in the database.
  29. # -----------------------------------------------------------------------------
  30. # <reg_type: x>
  31. # Set skill's regional type with x. Example: <reg_type: fire>
  32. #
  33. # -----------------------------------------------------------------------------
  34. # Region[Region Type] = {
  35. #   :region_id => Region ID for this region type (Array)    
  36. #   :weak => Region type that weaken this region type (Array)
  37. #   :strong => Region type that strengthen this region type (Array)
  38. #   :weak_powerrate => Multiply this spell damage with value specified
  39. #                      when weaken (Float)
  40. #   :strong_powerrate => Multiply this spell damage with value specified
  41. #                        when strengthen (Float)
  42. #   :weak_hitrate =>  The same with :weak_powerrate but affect hit rate (Float)
  43. #   :strong_hitrate =>  The same with :strong_powerrate but affect hit rate (Float)
  44. #   :weak_staterate => The same with :weak_powerrate but affect state rate (Float)
  45. #   :strong_staterate =>  The same with :strong_powerrate but affect state rate (Float)
  46. # } <---- Don't forget to put this
  47. #
  48. # -----------------------------------------------------------------------------
  49. # Script call method. For advanced users.
  50. # -----------------------------------------------------------------------------
  51. # BattleManager.set_region(x)
  52. #   Set region type with x, set x to nil to set based on region id in player
  53. #   coordinate. Will be changed in battle transition if didnt locked.
  54. #
  55. # BattleManager.lock_region(true/false)
  56. #   Lock or unlock region. If locked, region only can be changed manually.
  57. #
  58. # BattleManager.region_locked?
  59. #   Return true or false.
  60. #
  61. # BattleManager.region
  62. #   Return current region.
  63. #
  64. #==============================================================================
  65. # ▼ Configuration
  66. #==============================================================================
  67.  
  68.  
  69. module Dhoom
  70.   module RegionalSpells
  71.     Region = {}   #-------- Don't delete this!
  72.    
  73.     Region[:fire] = {
  74.       :region_id => [1,9],
  75.       :weak => [:ice, :water],
  76.       :strong => [:wood, :dessert],
  77.       :weak_powerrate => 0.2,
  78.       :strong_powerrate => 1.5,
  79.       :weak_hitrate => 0.5,
  80.       :strong_hitrate => 1.5,
  81.       :weak_staterate => 0.5,
  82.       :strong_staterate => 1.2,
  83.     }
  84.    
  85.     Region[:ice] = {
  86.       :region_id => [2],
  87.       :weak => [:dessert, :wood],
  88.       :strong => [:fire],
  89.       :weak_powerrate => 0.2,
  90.       :strong_powerrate => 1.5,
  91.       :weak_hitrate => 0.5,
  92.       :strong_hitrate => 1.5,
  93.       :weak_staterate => 0.5,
  94.       :strong_staterate => 1.2,
  95.     }
  96.   end
  97.  
  98. #==============================================================================
  99. # End of Configuration
  100. #==============================================================================
  101.  
  102.   module REGEXP
  103.     module Skill
  104.       Region_Type = /<(?:reg_type|REG_TYPE|reg type):[ ]*(\w+)>/i
  105.     end  
  106.   end
  107. end
  108.  
  109. class RPG::Skill < RPG::UsableItem
  110.  
  111.   attr_reader :region_type
  112.  
  113.   def load_notetags_region_type
  114.     self.note.split(/[\r\n]+/).each { |line|    
  115.       case line
  116.       when Dhoom::REGEXP::Skill::Region_Type
  117.         @region_type = $1.to_sym        
  118.       end
  119.     }
  120.   end  
  121. end
  122.  
  123. module DataManager
  124.  
  125.   class <<self; alias load_database_dregional_spells load_database; end
  126.   def self.load_database
  127.     load_database_dregional_spells
  128.     load_notetags_region_type
  129.   end
  130.  
  131.  
  132.   def self.load_notetags_region_type
  133.     for obj in $data_skills
  134.       next if obj.nil?
  135.       obj.load_notetags_region_type
  136.     end
  137.   end
  138. end
  139.  
  140. module BattleManager
  141.  
  142.   def self.region
  143.     return @region
  144.   end
  145.  
  146.   def self.set_region(region = nil)
  147.     region = map_region if region.nil?
  148.     @region = region
  149.   end
  150.  
  151.   def self.map_region
  152.     region_id = $game_map.region_id($game_player.x, $game_player.y)
  153.     Dhoom::RegionalSpells::Region.each do |key, value|
  154.       return key if value[:region_id].include?(region_id)
  155.     end
  156.   end
  157.  
  158.   def self.region_locked?
  159.     return @lock_region
  160.   end
  161.  
  162.   def self.lock_region(lock=true)
  163.     @lock_region = lock
  164.   end
  165. end
  166.  
  167. class Game_Battler < Game_BattlerBase
  168.   alias dhoom_regional_spells_gmbattler_make_damage_value make_damage_value
  169.   def make_damage_value(user, item)
  170.     if item.is_a?(RPG::Skill) && item.region_type && BattleManager.region
  171.       value = item.damage.eval(user, self, $game_variables)
  172.       value *= item_element_rate(user, item)
  173.       value *= pdr if item.physical?
  174.       value *= mdr if item.magical?
  175.       value *= rec if item.damage.recover?
  176.       region = Dhoom::RegionalSpells::Region[item.region_type]
  177.       value *= region[:strong_powerrate] if region[:strong].include?(BattleManager.region)
  178.       value *= region[:weak_powerrate] if region[:weak].include?(BattleManager.region)
  179.       value = apply_critical(value) if @result.critical
  180.       value = apply_variance(value, item.damage.variance)
  181.       value = apply_guard(value)
  182.       @result.make_damage(value.to_i, item)
  183.     else
  184.       dhoom_regional_spells_gmbattler_make_damage_value(user, item)
  185.     end    
  186.   end
  187.  
  188.   alias dhoom_regional_spells_gmbattler_item_effect_add_state_normal item_effect_add_state_normal
  189.   def item_effect_add_state_normal(user, item, effect)
  190.     if item.is_a?(RPG::Skill) && item.region_type && BattleManager.region
  191.       chance = effect.value1
  192.       region = Dhoom::RegionalSpells::Region[item.region_type]
  193.       chance *= region[:strong_staterate] if region[:strong].include?(BattleManager.region)
  194.       chance *= region[:weak_staterate] if region[:weak].include?(BattleManager.region)
  195.       chance *= state_rate(effect.data_id) if opposite?(user)
  196.       chance *= luk_effect_rate(user)      if opposite?(user)
  197.       if rand < chance
  198.         add_state(effect.data_id)
  199.         @result.success = true
  200.       end
  201.     else
  202.       dhoom_regional_spells_gmbattler_item_effect_add_state_normal(user, item, effect)
  203.     end
  204.   end
  205.  
  206.   alias dhoom_regional_spells_gmbattler_item_hit item_hit
  207.   def item_hit(user, item)
  208.     if item.is_a?(RPG::Skill) && item.region_type && BattleManager.region
  209.       rate = item.success_rate * 0.01
  210.       rate *= user.hit if item.physical?
  211.       region = Dhoom::RegionalSpells::Region[item.region_type]
  212.       rate *= region[:strong_hitrate] if region[:strong].include?(BattleManager.region)
  213.       rate *= region[:weak_hitrate] if region[:weak].include?(BattleManager.region)
  214.       return rate
  215.     else
  216.       dhoom_regional_spells_gmbattler_item_hit(user, item)
  217.     end
  218.   end
  219. end
  220.  
  221. class Scene_Map < Scene_Base
  222.   alias dhoom_regionspells_scmap_pre_battle_scene pre_battle_scene
  223.   def pre_battle_scene
  224.     dhoom_regionspells_scmap_pre_battle_scene
  225.     BattleManager.set_region if !BattleManager.region_locked?
  226.   end
  227. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement