Guest User

AIR

a guest
Oct 16th, 2014
587
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Armor and Item Required Skills
  3. # by: Jeneeus Guruman
  4. #------------------------------------------------------------------------------
  5. #  This script allows to:
  6. #     - Make some skills requires armor types to use it. It is the same as the
  7. #     weapon-required skill but in armors.
  8. #     - Make some skills require items in the party's inventory to use it.
  9. #
  10. #   How to use:
  11. #
  12. #     * Plug-n-play
  13. #     * Place this below default and non-aliased scripts.
  14. #      
  15. #       <req_atype: n>
  16. #       n: the index number of the armor type
  17. #       required for the skill (which is beside the name in the "Terms" tab)
  18. #
  19. #     * Note: If you put more than 1, the skill can be used if EITHER 1 of
  20. #       the armor types is equiipped.
  21. #      
  22. #       <req_item: n, amount, comnsumed?>
  23. #       n: the index number of the item in the database
  24. #       required for the skill (which is beside the name in the "Terms" tab)
  25. #       amount: the amount of the specified item needed to use a skill.
  26. #       consumed?: the item needed needed to be consumed or not (true or false).
  27. #       Notetag examples:
  28. #         <req_item: 1, 2, true>    => A skill needs to have at least 2 "Potions"
  29. #       in the inventory to use the skill and those will be consumed after use.
  30. #
  31. #     * Note: If you put more than 1, the skill can be used if ALL of
  32. #       the items is in the party's inventory.
  33. #
  34. #==============================================================================
  35.  
  36. #----------------------------------------------------------------------------
  37. # * Do not edit anything below here. Or else, evil errors will be released
  38. # from the other dimension of evil.
  39. #----------------------------------------------------------------------------
  40.  
  41. module Jene
  42.   REQ_ATYPE = /<req_atype[:]?\s*(\d+)>/i
  43.   REQ_IREQ = /<req_item[:]?\s*(\d+)\s*[,]?\s*(\d+)\s*[,]?\s*(true|false)>/i
  44. end
  45.  
  46. class RPG::Skill
  47.  
  48.   def required_atype_ids
  49.     bonus_arr = []
  50.     self.note.each_line { |line|
  51.       if line =~ Jene::REQ_ATYPE
  52.         bonus_arr.push($1.to_i)
  53.       end
  54.     }
  55.     return bonus_arr
  56.   end
  57.  
  58.   def required_items
  59.     bonus_arr = []
  60.     self.note.each_line { |line|
  61.       if line =~ Jene::REQ_IREQ
  62.         bonus_arr.push([$1.to_i, $2.to_i, $3 == "true"])
  63.       end
  64.     }
  65.     return bonus_arr
  66.   end
  67. end
  68.  
  69. #==============================================================================
  70. # ** Game_BattlerBase
  71. #------------------------------------------------------------------------------
  72. #  This base class handles battlers. It mainly contains methods for calculating
  73. # parameters. It is used as a super class of the Game_Battler class.
  74. #==============================================================================
  75.  
  76. class Game_BattlerBase
  77.   #--------------------------------------------------------------------------
  78.   # * Check Usability Conditions for Skill
  79.   #--------------------------------------------------------------------------
  80.   alias jene_req_skill_conditions_met? skill_conditions_met?
  81.   def skill_conditions_met?(skill)
  82.     return false unless skill_atype_ok?(skill) && skill_ireq_ok?(skill)
  83.     jene_req_skill_conditions_met?(skill)
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # * Determine if Skill-Required Armor Is Equipped
  87.   #--------------------------------------------------------------------------
  88.   def skill_atype_ok?(skill)
  89.     return true
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # * Determine if Skill-Required Item Is In Inventory
  93.   #--------------------------------------------------------------------------
  94.   def skill_ireq_ok?(skill)
  95.     return true
  96.   end
  97. end
  98.  
  99. #==============================================================================
  100. # ** Game_Actor
  101. #------------------------------------------------------------------------------
  102. #  This class handles actors. It is used within the Game_Actors class
  103. # ($game_actors) and is also referenced from the Game_Party class ($game_party).
  104. #==============================================================================
  105.  
  106. class Game_Actor < Game_Battler
  107.   #--------------------------------------------------------------------------
  108.   # * Determine if Skill-Required Armor Is Equipped
  109.   #--------------------------------------------------------------------------
  110.   def skill_atype_ok?(skill)
  111.     return true if skill.required_atype_ids.size == 0
  112.     for i in skill.required_atype_ids
  113.       return true if atype_equipped?(i)
  114.     end
  115.     return false
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # * Determine if Specific Type of Armor Is Equipped
  119.   #--------------------------------------------------------------------------
  120.   def atype_equipped?(atype_id)
  121.     armors.any? {|armor| armor.atype_id == atype_id }
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # * Determine if Skill-Required Item Is In Inventory
  125.   #--------------------------------------------------------------------------
  126.   def skill_ireq_ok?(skill)
  127.     for i in skill.required_items
  128.       item = $data_items[i[0]]
  129.       return false unless $game_party.item_number(item) >= i[1]
  130.     end
  131.     return true
  132.   end
  133. end
  134.  
  135. #==============================================================================
  136. # ** Game_Battler
  137. #------------------------------------------------------------------------------
  138. #  A battler class with methods for sprites and actions added. This class
  139. # is used as a super class of the Game_Actor class and Game_Enemy class.
  140. #==============================================================================
  141.  
  142. class Game_Battler < Game_BattlerBase
  143.   #--------------------------------------------------------------------------
  144.   # * Use Skill/Item
  145.   #    Called for the acting side and applies the effect to other than the user.
  146.   #--------------------------------------------------------------------------
  147.   alias jene_ireq_use_item use_item
  148.   def use_item(item)
  149.     consume_item(item) if item.is_a?(RPG::Skill) && !item.required_items.empty?
  150.     jene_ireq_use_item(item)
  151.   end
  152. end
  153.  
  154. #==============================================================================
  155. # ** Game_Party
  156. #------------------------------------------------------------------------------
  157. #  This class handles parties. Information such as gold and items is included.
  158. # Instances of this class are referenced by $game_party.
  159. #==============================================================================
  160.  
  161. class Game_Party < Game_Unit
  162.   #--------------------------------------------------------------------------
  163.   # * Consume Items
  164.   #    If the specified object is a consumable item, the number in investory
  165.   #    will be reduced by 1.
  166.   #--------------------------------------------------------------------------
  167.   alias jene_ireq_consume_item consume_item
  168.   def consume_item(item)
  169.     if item.is_a?(RPG::Skill)
  170.       for i in item.required_items
  171.         item2 = $data_items[i[0]]
  172.         lose_item(item2, i[1]) if i[2]
  173.       end
  174.     end
  175.     jene_ireq_consume_item(item)
  176.   end
  177. end
RAW Paste Data