modern_algebra

[VXA] Equipment Set Bonuses 1.0.0

Jan 12th, 2014
298
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. #    Equipment Set Bonuses
  3. #    Version: 1.0.0
  4. #    Author: modern algebra (rmrk.net)
  5. #    Date: 12 January 2014
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. #  Description:
  8. #
  9. #    This script allows you to group together pieces of equipments and apply
  10. #   bonuses if all of them are equipped on the same actor.
  11. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12. #  Instructions:
  13. #
  14. #    To create an equipment set, simply create an armor (not a weapon) with all
  15. #   of the stat changes and features you want added when the entire set is
  16. #   equipped. Then, in the notebox, use the following codes to determine which
  17. #   items belong to the set:
  18. #
  19. #      \set[x1, x2, ..., xn]
  20. #
  21. #   Where each element is the ID of the piece of equipment, preceded by either
  22. #   A or W to indicate whether it is a weapon or armor.
  23. #
  24. #    For example, a54 would mean the armor with ID 54, while w2 would be the
  25. #   weapon with ID 2.
  26. #
  27. #    As well, you can write more than one of these codes in the notebox, and
  28. #   then the bonuses will be applied if any of the sets are equipped.
  29. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  30. #  Examples:
  31. #
  32. #      \set[w50, a67, a71]
  33. #    If an actor has equipped the weapon with ID 50 and the armors with IDs 67
  34. #    and 71, then the bonuses of this equipment set will be applied.
  35. #
  36. #      \set[a32, a33]\set[a32, a34]\set[a33, a34]
  37. #    If an actor has equipped any two pieces of the armors with IDs 32, 33, and
  38. #    34, then the bonuses of this equipment set will be applied.
  39. #==============================================================================
  40.  
  41. $imported = {} unless $imported
  42. $imported[:MA_EquipmentSetBonuses] = true
  43.  
  44. #==============================================================================
  45. # ** MAESB EquipmentSet
  46. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  47. #  A class to hold data of each set
  48. #==============================================================================
  49.  
  50. class MAESB_EquipmentSet
  51.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  52.   # * Object Initialization
  53.   #    set_string : a string with each armor and weapon as "[AW]\d+"
  54.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55.   def initialize(set_string = "")
  56.     # Initialize arrays to track IDs of equips in set
  57.     @weapons, @armors = [], []
  58.     # Populate Set
  59.     set_string.scan(/([AW]?)\s*?(\d+)/mi) { |type, id|
  60.       (type.upcase == 'W' ? @weapons : @armors).push(id.to_i) }
  61.   end
  62.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63.   # * Items
  64.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65.   def items
  66.     (@weapons.collect {|id| $data_weapons[id] }) + # RPG::Weapons +
  67.       (@armors.collect {|id| $data_armors[id] })   # RPG::Armors
  68.   end
  69.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  70.   # * Set Complete?
  71.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72.   def set_complete?(eqps = [])
  73.     itms = items
  74.     !itms.empty? && ((itms & eqps).size == itms.size)
  75.   end
  76. end
  77.  
  78. module RPG
  79.   #============================================================================
  80.   # ** RPG::EquipItem
  81.   #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  82.   #  Summary of Items:
  83.   #    new methods - maesb_generate_equip_set
  84.   #============================================================================
  85.  
  86.   class EquipItem
  87.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88.     # * Public Instance Variables
  89.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90.     attr_accessor :maesb_belongs_to_sets
  91.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  92.     # * Generate Equip Set
  93.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  94.     def maesb_generate_equip_set
  95.       @maesb_belongs_to_sets = []
  96.     end
  97.   end
  98.  
  99.   #============================================================================
  100.   # ** RPG::Armor
  101.   #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  102.   #  Summary of Items:
  103.   #    new methods - maesb_generate_equip_set
  104.   #============================================================================
  105.  
  106.   class Armor
  107.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  108.     # * Public Instance Variables
  109.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110.     attr_reader   :maesb_sets
  111.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  112.     # * Generate Equip Set
  113.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  114.     def maesb_generate_equip_set
  115.       super
  116.       @maesb_sets = note.scan(/\\SET\s*\[(.+?)\]/i).collect { |set_s|
  117.         MAESB_EquipmentSet.new(set_s[0]) }
  118.     end
  119.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  120.     # * Set Complete?
  121.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  122.     def maesb_set_complete?(maesb_equips)
  123.       maesb_sets.each { |set| return true if set && set.set_complete?(maesb_equips) }
  124.       return false
  125.     end
  126.   end
  127. end
  128.  
  129. #==============================================================================
  130. # *** DataManager
  131. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  132. #  Summary of Changes:
  133. #    aliased methods - load_database
  134. #    new method - maesb_generate_equipment_sets
  135. #==============================================================================
  136.  
  137. class <<  DataManager
  138.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  139.   # * Load Database
  140.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  141.   alias maesb_loadata_9fg4 load_database
  142.   def load_database(*args, &block)
  143.     maesb_loadata_9fg4(*args, &block) # Call Original Method
  144.     maesb_generate_equipment_sets
  145.   end
  146.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  147.   # * Generate Equipment Sets
  148.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  149.   def maesb_generate_equipment_sets
  150.     # Generate Equipment Sets
  151.     ($data_weapons + $data_armors).compact.each { |equip| equip.maesb_generate_equip_set }
  152.     # Update items to refer to the set to which they belong
  153.     set_items = $data_armors.compact.select {|armor| !armor.maesb_sets.empty? }
  154.     set_items.each { |set_item|
  155.       set_item.maesb_sets.collect {|set| set.items }.flatten.uniq.each { |equip|
  156.         equip.maesb_belongs_to_sets.push(set_item.id)
  157.       }
  158.     }
  159.   end
  160. end
  161.  
  162. #==============================================================================
  163. # *** MAESB_GameActr_CreateSets
  164. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  165. #  This module is intended to be mixed in to Game_Actor
  166. #==============================================================================
  167.  
  168. module MAESB_GameActr_CreateSets
  169.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  170.   # * Sets
  171.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  172.   def maesb_sets
  173.     eqps = equips.compact
  174.     if @maesb_set_last_equips != eqps # update if equipment has changed
  175.       @maesb_set_last_equips = eqps
  176.       # Get array of all set items currently equipped
  177.       sets = eqps.inject([]) { |r, eqp| r |= eqp.maesb_belongs_to_sets }
  178.       # Select from them any sets that are complete
  179.       @maesb_sets = (sets.collect {|id| $data_armors[id] }).select {|set|
  180.         set.maesb_set_complete?(eqps) }
  181.     end
  182.     @maesb_sets  # return array of set items
  183.   end
  184.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  185.   # * Get Array of All Objects Retaining Features
  186.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  187.   def feature_objects(*args, &block)
  188.     maesb_sets.compact + (super(*args, &block))
  189.   end
  190.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  191.   # * Get Added Value of Parameter
  192.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  193.   def param_plus(param_id, *args, &block)
  194.     val = super(param_id, *args, &block)
  195.     maesb_sets.compact.inject(val) {|r, item| r += item.params[param_id] }
  196.   end
  197. end
  198.  
  199. #==============================================================================
  200. # ** Game_Actor
  201. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  202. #  Summary of Changes:
  203. #    included modules - MAESB_GameActr_CreateSets
  204. #==============================================================================
  205.  
  206. class Game_Actor
  207.   include MAESB_GameActr_CreateSets
  208. end
RAW Paste Data