khanhdu

Victor Engine - Action Restriction

Dec 5th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.64 KB | None | 0 0
  1. #==============================================================================
  2. # ** Victor Engine - Action Restriction
  3. #------------------------------------------------------------------------------
  4. # Author : Victor Sant
  5. #
  6. # Version History:
  7. #  v 1.00 - 2012.06.16 > First release
  8. #  v 1.01 - 2012.06.16 > Fixed issue when no user is available to use the item.
  9. #------------------------------------------------------------------------------
  10. #  This script allows to set restrictions for action use and effect.
  11. # It's possible to make some items not usable by some actors or to have no
  12. # effect on specific battlers.
  13. #------------------------------------------------------------------------------
  14. # Compatibility
  15. #   Requires the script 'Victor Engine - Basic Module' v 1.09 or higher
  16. #
  17. # * Overwrite methods
  18. #   class Scene_ItemBase < Scene_MenuBase
  19. #     def user
  20. #
  21. # * Alias methods
  22. #   class Game_BattlerBase
  23. #     def usable?(item)
  24. #
  25. #   class Game_Battler < Game_BattlerBase
  26. #     def item_effect_test(user, item, effect)
  27. #     def item_test(user, item)
  28. #
  29. #   class Scene_Battle < Scene_Base
  30. #     def command_item
  31. #
  32. #------------------------------------------------------------------------------
  33. # Instructions:
  34. #  To instal the script, open you script editor and paste this script on
  35. #  a new section bellow the Materials section. This script must also
  36. #  be bellow the script 'Victor Engine - Basic'
  37. #
  38. #------------------------------------------------------------------------------
  39. # Actors, Classes, Enemies, States, Weapons and Armors note tags:
  40. #   Tags to be used on the Actors, Classes, Enemies, States, Weapons and Armors
  41. #   note box in the database
  42. #  
  43. #  <restrict skill use: x>       <restrict item use: x>    
  44. #  <restrict skill use: x, x>    <restrict item use: x, x>
  45. #   The user will not be able to use the action with the ids listed here
  46. #     x = item or skill ID
  47. #  
  48. #  <restrict skill effect: x>       <restrict item effect: x>    
  49. #  <restrict skill effect: x, x>    <restrict item effect: x, x>
  50. #   The actions with id listed won't have any effect on the target
  51. #     x = item or skill ID
  52. #
  53. #==============================================================================
  54.  
  55. #==============================================================================
  56. # ** Victor Engine
  57. #------------------------------------------------------------------------------
  58. #   Setting module for the Victor Engine
  59. #==============================================================================
  60.  
  61. module Victor_Engine
  62.   #--------------------------------------------------------------------------
  63.   # * required
  64.   #   This method checks for the existance of the basic module and other
  65.   #   VE scripts required for this script to work, don't edit this
  66.   #--------------------------------------------------------------------------
  67.   def self.required(name, req, version, type = nil)
  68.     if !$imported[:ve_basic_module]
  69.       msg = "The script '%s' requires the script\n"
  70.       msg += "'VE - Basic Module' v%s or higher above it to work properly\n"
  71.       msg += "Go to http://victorscripts.wordpress.com/ to download this script."
  72.       msgbox(sprintf(msg, self.script_name(name), version))
  73.       exit
  74.     else
  75.       self.required_script(name, req, version, type)
  76.     end
  77.   end
  78.   #--------------------------------------------------------------------------
  79.   # * script_name
  80.   #   Get the script name base on the imported value, don't edit this
  81.   #--------------------------------------------------------------------------
  82.   def self.script_name(name, ext = "VE")
  83.     name = name.to_s.gsub("_", " ").upcase.split
  84.     name.collect! {|char| char == ext ? "#{char} -" : char.capitalize }
  85.     name.join(" ")
  86.   end
  87. end
  88.  
  89. $imported ||= {}
  90. $imported[:ve_action_restriction] = 1.00
  91. Victor_Engine.required(:ve_action_restriction, :ve_basic_module, 1.09, :above)
  92. Victor_Engine.required(:ve_action_restriction, :ve_element_states, 1.00, :bellow)
  93.  
  94. #==============================================================================
  95. # ** Game_BattlerBase
  96. #------------------------------------------------------------------------------
  97. #  This class handles battlers. It's used as a superclass of the Game_Battler
  98. # classes.
  99. #==============================================================================
  100.  
  101. class Game_BattlerBase
  102.   #--------------------------------------------------------------------------
  103.   # * Alias method: usable?
  104.   #--------------------------------------------------------------------------
  105.   alias :usable_ve_action_restriction? :usable?
  106.   def usable?(item)
  107.     return false if !action_restriction?(item)
  108.     usable_ve_action_restriction?(item)
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # * New method: ction_restriction?
  112.   #--------------------------------------------------------------------------
  113.   def action_restriction?(item)
  114.     return true  if !item
  115.     return false if item_restricted?(item, "USE")
  116.     return true
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # * New method: item_restricted?
  120.   #--------------------------------------------------------------------------
  121.   def item_restricted?(item, type)
  122.     id     = item.id
  123.     action = item.skill? ? "SKILL" : "ITEM"
  124.     regexp = /<RESTRICT #{action} #{type}: ((?:\d+ *,? *)+)>/i
  125.     get_all_notes.scan(regexp).any? { $1.scan(/(\d+)/i).include?([id.to_s]) }
  126.   end
  127. end
  128.  
  129. #==============================================================================
  130. # ** Game_Battler
  131. #------------------------------------------------------------------------------
  132. #  This class deals with battlers. It's used as a superclass of the Game_Actor
  133. # and Game_Enemy classes.
  134. #==============================================================================
  135.  
  136. class Game_Battler < Game_BattlerBase
  137.   #--------------------------------------------------------------------------
  138.   # * Alias method: item_effect_test
  139.   #--------------------------------------------------------------------------
  140.   alias :item_effect_test_ve_action_restriction :item_effect_test
  141.   def item_effect_test(user, item, effect)
  142.     return false if item_restricted?(item, "EFFECT")
  143.     item_effect_test_ve_action_restriction(user, item, effect)
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # * Alias method: item_test
  147.   #--------------------------------------------------------------------------
  148.   alias :item_test_ve_action_restriction :item_test
  149.   def item_test(user, item)
  150.     return false if item_restricted?(item, "EFFECT")
  151.     item_test_ve_action_restriction(user, item)
  152.   end
  153. end
  154.  
  155. #==============================================================================
  156. # ** Window_ItemList
  157. #------------------------------------------------------------------------------
  158. #  This window displays a list of items for the item screen.
  159. #==============================================================================
  160.  
  161. class Window_ItemList < Window_Selectable
  162.   #--------------------------------------------------------------------------
  163.   # * New method: actor=
  164.   #--------------------------------------------------------------------------
  165.   def actor=(actor)
  166.     return if @actor == actor
  167.     @actor = actor
  168.     refresh
  169.     self.oy = 0
  170.   end
  171. end
  172.  
  173. #==============================================================================
  174. # ** Window_BattleItem
  175. #------------------------------------------------------------------------------
  176. #  This window displays a list of items for the battle screen.
  177. #==============================================================================
  178.  
  179. class Window_BattleItem < Window_ItemList
  180.   #--------------------------------------------------------------------------
  181.   # * New method: enable?
  182.   #--------------------------------------------------------------------------
  183.   def enable?(item)
  184.     @actor && @actor.usable?(item) && super(item)
  185.   end
  186. end
  187.  
  188. #==============================================================================
  189. # ** Scene_ItemBase
  190. #------------------------------------------------------------------------------
  191. #  This is the superclass for the classes that performs the item and skill
  192. # screens.
  193. #==============================================================================
  194.  
  195. class Scene_ItemBase < Scene_MenuBase
  196.   #--------------------------------------------------------------------------
  197.   # * Overwrite method: user
  198.   #--------------------------------------------------------------------------
  199.   def user
  200.     users = $game_party.movable_members.select {|member| member.usable?(item)}
  201.     users.max_by {|member| member.pha }
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # * Alias method: item_usable?
  205.   #--------------------------------------------------------------------------
  206.   alias :item_usable_ve_action_restriction? :item_usable?
  207.   def item_usable?
  208.     user && item_usable_ve_action_restriction?
  209.   end
  210. end
  211.  
  212. #==============================================================================
  213. # ** Scene_Battle
  214. #------------------------------------------------------------------------------
  215. #  This class performs battle screen processing.
  216. #==============================================================================
  217.  
  218. class Scene_Battle < Scene_Base
  219.   #--------------------------------------------------------------------------
  220.   # * Alias method: command_item
  221.   #--------------------------------------------------------------------------
  222.   alias :command_item_ve_action_restriction :command_item
  223.   def command_item
  224.     @item_window.actor = BattleManager.actor
  225.     command_item_ve_action_restriction
  226.   end
  227. end
Advertisement
Add Comment
Please, Sign In to add comment