khanhdu

Victor Engine - Action Reflect

Dec 5th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.67 KB | None | 0 0
  1. #==============================================================================
  2. # ** Victor Engine - Action Reflect
  3. #------------------------------------------------------------------------------
  4. # Author : Victor Sant
  5. #
  6. # Version History:
  7. #  v 1.00 - 2012.07.16 > First release
  8. #------------------------------------------------------------------------------
  9. #  This script allows to setup a trait gives a chance of reflecting
  10. # actions based on the actions or their types. That way you can create traits
  11. # that can repel specific skills or items.
  12. #------------------------------------------------------------------------------
  13. # Compatibility
  14. #   Requires the script 'Victor Engine - Basic Module' v 1.19 or higher
  15. #
  16. # * Alias methods
  17. #   class Game_Battler < Game_BattlerBase
  18. #     def item_mrf(user, item)
  19. #
  20. #   class Window_BattleLog < Window_Selectable
  21. #     def display_reflection(target, item)
  22. #
  23. #------------------------------------------------------------------------------
  24. # Instructions:
  25. #  To instal the script, open you script editor and paste this script on
  26. #  a new section bellow the Materials section. This script must also
  27. #  be bellow the script 'Victor Engine - Basic'
  28. #
  29. #------------------------------------------------------------------------------
  30. # Actors, Classes, Enemies, Weapons, Armors and States note tags:
  31. #   Tags to be used on Actors, Classes, Enemies, Weapons, Armors and States
  32. #   note boxes.
  33. #
  34. #  <skill reflect x: +y%>   <item reflect x: +y%>
  35. #  <skill reflect x: -y%>   <item reflect x: -y%>
  36. #   Setup the skill or item and a rate of reflect for that action
  37. #     x : ID of the skill or item
  38. #     y : reflect chance
  39. #
  40. #  <skill type reflect x: +y%>   <item type reflect x: +y%>
  41. #  <skill type reflect x: -y%>   <item type reflect x: -y%>
  42. #   Setup the skill or item type and a rate of reflect for that actions
  43. #     x : ID of the skill type or item type
  44. #     y : reflect chance
  45. #
  46. #------------------------------------------------------------------------------
  47. # Additional instructions:
  48. #
  49. #  If the action is magical, the action reflect chance is added to the
  50. #  magic reflect chance.
  51. #
  52. #  You can edit the log window message on the module Vocab withing the script
  53. #
  54. #==============================================================================
  55.  
  56. #==============================================================================
  57. # ** Victor Engine
  58. #------------------------------------------------------------------------------
  59. #   Setting module for the Victor Engine
  60. #==============================================================================
  61.  
  62. module Victor_Engine
  63.   #--------------------------------------------------------------------------
  64.   # * required
  65.   #   This method checks for the existance of the basic module and other
  66.   #   VE scripts required for this script to work, don't edit this
  67.   #--------------------------------------------------------------------------
  68.   def self.required(name, req, version, type = nil)
  69.     if !$imported[:ve_basic_module]
  70.       msg = "The script '%s' requires the script\n"
  71.       msg += "'VE - Basic Module' v%s or higher above it to work properly\n"
  72.       msg += "Go to http://victorscripts.wordpress.com/ to download this script."
  73.       msgbox(sprintf(msg, self.script_name(name), version))
  74.       exit
  75.     else
  76.       self.required_script(name, req, version, type)
  77.     end
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * script_name
  81.   #   Get the script name base on the imported value
  82.   #--------------------------------------------------------------------------
  83.   def self.script_name(name, ext = "VE")
  84.     name = name.to_s.gsub("_", " ").upcase.split
  85.     name.collect! {|char| char == ext ? "#{char} -" : char.capitalize }
  86.     name.join(" ")
  87.   end
  88. end
  89.  
  90. $imported ||= {}
  91. $imported[:ve_action_reflect] = 1.00
  92. Victor_Engine.required(:ve_action_reflect, :ve_basic_module, 1.19, :above)
  93.  
  94. #==============================================================================
  95. # ** Vocab
  96. #------------------------------------------------------------------------------
  97. #  This module defines terms and messages. It defines some data as constant
  98. # variables. Terms in the database are obtained from $data_system.
  99. #==============================================================================
  100.  
  101. module Vocab
  102.  
  103.   # Action Counter Message
  104.   VE_ActionReflection = "%s reflected the %s!"
  105.  
  106. end
  107.  
  108. #==============================================================================
  109. # ** Game_Battler
  110. #------------------------------------------------------------------------------
  111. #  This class deals with battlers. It's used as a superclass of the Game_Actor
  112. # and Game_Enemy classes.
  113. #==============================================================================
  114.  
  115. class Game_Battler < Game_BattlerBase
  116.   #--------------------------------------------------------------------------
  117.   # * Public Instance Variables
  118.   #--------------------------------------------------------------------------
  119.   attr_reader   :action_reflected
  120.   #--------------------------------------------------------------------------
  121.   # * Alias method: item_mrf
  122.   #--------------------------------------------------------------------------
  123.   alias :item_mrf_ve_action_reflect :item_cnt
  124.   def item_mrf(user, item)
  125.     result = item_mrf_ve_action_reflect(user, item)
  126.     action = action_reflect(item)
  127.     @action_reflected = action > result
  128.     result + action
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * New method: action_reflect
  132.   #--------------------------------------------------------------------------
  133.   def action_reflect(item)
  134.     item_reflect(item) + item_type_reflect(item)
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # * New method: item_reflect
  138.   #--------------------------------------------------------------------------
  139.   def item_reflect(item)
  140.     get_action_reflect(item.skill? ? "SKILL" : "ITEM", item.id)
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   # * New method: item_type_reflect
  144.   #--------------------------------------------------------------------------
  145.   def item_type_reflect(item)
  146.     type = item.skill? ? "SKILL TYPE" : "ITEM TYPE"
  147.     item.type_set.inject(0.0) {|r, i| r += get_action_reflect(type, i) }
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # * New method: get_action_reflect
  151.   #--------------------------------------------------------------------------
  152.   def get_action_reflect(type, id)
  153.     regexp = /<#{type} REFLECT #{id}: ([+-]?\d+)%?>/i
  154.     get_all_notes.scan(regexp).inject(0.0) {|r| r += ($1.to_i / 100.0) }
  155.   end
  156. end
  157.  
  158. #==============================================================================
  159. # ** Window_BattleLog
  160. #------------------------------------------------------------------------------
  161. #  This window shows the battle progress. Do not show the window frame.
  162. #==============================================================================
  163.  
  164. class Window_BattleLog < Window_Selectable
  165.   #--------------------------------------------------------------------------
  166.   # * Alias method: display_reflection
  167.   #--------------------------------------------------------------------------
  168.   alias :display_reflection_ve_action_reflect :display_reflection
  169.   def display_reflection(target, item)
  170.     if target.action_reflected
  171.       Sound.play_reflection
  172.       add_text(sprintf(Vocab::VE_ActionReflection, target.name, item.name))
  173.       wait
  174.       back_one unless $imported[:ve_animated_battle]
  175.     else
  176.       display_reflection_ve_action_reflect(target, item)
  177.     end
  178.   end
  179. end
Advertisement
Add Comment
Please, Sign In to add comment