Enelvon

SES: MultiSlot

Apr 14th, 2012
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.79 KB | None | 0 0
  1. ###############################################################################
  2. # SES: MultiSlot
  3. # v1.0
  4. # 4.14.2012
  5. # Compatibility: VXAce/RGSS3
  6. # Author: Enelvon
  7. #===============================================================================
  8. # Terms of Use:
  9. #
  10. # This script may be used for free in any game, whether it's commercial or not.
  11. # The only requirement is that I be credited in some visible manner. You may not
  12. # claim this script as your own work. You are free to modify this script, but
  13. # may not redistribute it except for in a thread that I have started that relates
  14. # to it in some way.
  15. #===============================================================================
  16. # Changelog:
  17. # 4.14.2012: v1.0 - Script written.
  18. #===============================================================================                          
  19. # This script implements more equipment slots for actors. You can have as many
  20. # as you would like, and pieces of equipment can go into more than one type of
  21. # slot.
  22. #===============================================================================
  23. # Required Scripts: Enelvon Script Core v1.0 or higher
  24. # Known Incompatibilities: None, though it contains some redefinitions so some
  25. #     may occur if this script is below another script that aliases the same
  26. #     method, or if it is above another script that redefines that method. A full
  27. #     list of redefinition is included at the bottom of my comments.
  28. #===============================================================================
  29. # Installation: Place below Materials and the Enelvon Script Core and above all
  30. # other custom scripts (just to be safe).
  31. #===============================================================================
  32. # Instructions:
  33. #
  34. # ***Constants for SES::MultiSlot***
  35. #
  36. # Actorslots - this is a hash consisting of actor IDs and an associated array of
  37. #     equipment slot IDs, in the order that you desire for them to appear.
  38. #
  39. # EquipSlot - this is the RegExp to set the slot ID for a piece of equipment.
  40. #     You can include more than one of these to allow a piece of equipment to
  41. #     fit into more than one slot. Make sure to set the Equip Type of the
  42. #     equipment in the Database to Accessory if you don't want it to also fit
  43. #     into the Database type selection. There is more on this in the next section.
  44. #
  45. # Seal - this is the RegExp that allows you to seal new equipment types, as per
  46. #     the Feature. There is more on this in the next section.
  47. #
  48. # Fix - this is the RegExp that allows you to fix an equipment slot and make it
  49. #     unchangeable, as per the Feature. There is more on this in the next section.
  50. #
  51. # Equips - this is the RegExp that allows you to set an actor's default equipment
  52. #     for new slots. There is more on this in the next section.
  53. #
  54. # ***Methods for SES::MultiSlot***
  55. #
  56. # self.terms(etype_id)
  57. #   This is the method that tells the game what the names of equipment slots are.
  58. #   Add in additional when statements for the new slots that you add.
  59. #
  60. # ***Additional: Equipment Tags***
  61. #
  62. # You can customize this script for each piece of equipment in your game by adding
  63. # tags in their Notes boxes. These are the tags available in this script:
  64. #
  65. # <Equip: !Slot!>
  66. #   Place this in a Notes box to allow an item to be placed in an equip slot.
  67. #   You can include more than one of these per item.
  68. #   Replacements:
  69. #     !Slot! with the slot ID that you want the item to be placed in.
  70. #
  71. # <Seal: !Slot!>
  72. #   Place this in a Notes box to cause the item to seal an equip slot, exactly
  73. #   like the Feature. You can include more than one of these per item.
  74. #   Replacements:
  75. #     !Slot! with the slot ID that you want the item to seal.
  76. #
  77. # <Fix: !Slot!>
  78. #   Place this in a Notes box to cause the item to fix an equip slot, exactly
  79. #   like the Feature. You can include more than one of these per item.
  80. #   Replacements:
  81. #     !Slot! with the slot ID that you want the item to fix.
  82. #
  83. # ***Additional: Actor Tags***
  84. #
  85. # You can customize this script for each actor in your game by adding tags in
  86. # their Notes boxes. These are the tags available in this script:
  87. #
  88. # <Equip: !Slot!, !Equip!>
  89. #   Place this in a Notes box to select the default equipment to be placed in
  90. #   a slot.
  91. #   Replacements:
  92. #     !Slot! with the slot ID that you want the item to be placed in.
  93. #     !Equip! with the ID of the equipment that you want to be placed in the slot.
  94. #
  95. # <Seal: !Slot!>
  96. #   Place this in a Notes box to seal an actor's equip slot, exactly like the
  97. #   Feature. You can include more than one of these per actor.
  98. #   Replacements:
  99. #     !Slot! with the slot ID that you want to be sealed.
  100. #
  101. # <Fix: !Slot!>
  102. #   Place this in a Notes box to fix an actor's equip slot, exactly like the
  103. #   Feature. You can include more than one of these per actor.
  104. #   Replacements:
  105. #     !Slot! with the slot ID that you want to be fixed.
  106. #
  107. # ***Additional: Class Tags***
  108. #
  109. # You can customize this script for each class in your game by adding tags in
  110. # their Notes boxes. These are the tags available in this script:
  111. #
  112. # <Seal: !Slot!>
  113. #   Place this in a Notes box to cause the class to seal an actor's equip slot,
  114. #   exactly like the Feature. You can include more than one of these per class.
  115. #   Replacements:
  116. #     !Slot! with the slot ID that you want to be sealed.
  117. #
  118. # <Fix: !Slot!>
  119. #   Place this in a Notes box to cause the class to fix an actor's equip slot,
  120. #   exactly like the Feature. You can include more than one of these per class.
  121. #   Replacements:
  122. #     !Slot! with the slot ID that you want to be fixed.
  123. #
  124. #===============================================================================
  125. # Aliases:
  126. #
  127. # These are the methods that are aliased by this script. This information is
  128. # included for the purpose of pinpointing compatibility errors between scripts.
  129. #
  130. # ***class Game_BaseItem***
  131. #
  132. #   object
  133. #
  134. # ***class Game_Actor***
  135. #
  136. # setup(actor_id)
  137. #
  138. #===============================================================================
  139. # Redefinitions:
  140. #
  141. # These are the methods that are redefined by this script. This information is
  142. # included for the purpose of pinpointing compatibility errors between scripts.
  143. #
  144. # ***module Vocab***
  145. #
  146. #   self.etype(etype_id)
  147. #
  148. # ***class Game_Actor***
  149. #
  150. #   release_unequippable_items(item_gain = true)
  151. #   optimize_equipments
  152. #   equip_slots
  153. #   change_equip(slot_id, item)
  154. #
  155. # ***class Window_EquipSlot***
  156. #
  157. #   refresh
  158. #
  159. # ***class Window_EquipItem***
  160. #
  161. #   include?
  162. #
  163. ################################################################################
  164. module SES
  165.   module MultiSlot
  166.  
  167.     Actorslots = {
  168.    
  169.     # Actor ID => Array of Equip Slots. Do not include 0 (weapon) unless you
  170.     #             want more than one weapon slot.
  171.     1 => [1,2,3,5,6,4,4],
  172.  
  173.     }
  174.     # Default array of Equip Slots for Actor IDs that aren't listed in Actorslots.
  175.     Actorslots.default = [1,2,3,5,6,4,4]
  176.    
  177.     # RegExp for an item's equipment slot type. You can include more than one.
  178.     EquipSlot = /^<Equip: ([\d]+)>/i
  179.     # RegExp for sealing an equipment slot when a certain item is equipped.
  180.     Seal = /^<Seal: ([\d]+)>/i
  181.     # RegExp for fixing an equipment slot when a certain item is equipped.
  182.     Fix = /^<Fix: ([\d]+)>/i
  183.     # RegExp for an Actor's default equipment for extra slots.
  184.     Equips = /^<Equip: ([\d]+), ([\d]+)>/i
  185.    
  186.     def self.terms(etype_id) # Method that defines slot names. Edit this for
  187.       case etype_id          # any slots that you add.
  188.       when 0..4
  189.         $data_system.terms.etypes[etype_id]
  190.       when 5 # when Slot ID
  191.         return "Legs" # return "Slot Name"
  192.       when 6
  193.         return "Shoes"
  194.       end
  195.     end
  196.    
  197.   end
  198. end
  199.  
  200. $imported = {} if $imported.nil?
  201. $imported["SES - MultiSlot"] = true
  202.  
  203. class RPG::Actor < RPG::BaseItem
  204.  
  205.   alias en_ms_a_sn en_scan_notes
  206.   def en_scan_notes(tags = [])
  207.     oldequips = @equips.clone
  208.     @equips = []
  209.     SES::MultiSlot::Actorslots[@id].size.times do
  210.       @equips.push(0)
  211.     end
  212.     ns = [0] + SES::MultiSlot::Actorslots[@id]
  213.     for i in 0..oldequips.size-1
  214.       e = ns.index(i)
  215.       @equips[e] = oldequips[i] if !e.nil?
  216.     end
  217.     tags.push([SES::MultiSlot::Equips, "@equips[$1.to_i] = $2.to_i"])
  218.     tags.push([SES::MultiSlot::Seal, "seal = RPG::BaseItem::Feature.new(54, $1.to_i); @features.push(seal)"])
  219.     tags.push([SES::MultiSlot::Fix, "fix = RPG::BaseItem::Feature.new(53, $1.to_i); @features.push(fix)"])
  220.     en_ms_a_sn(tags)
  221.   end
  222. end
  223.  
  224. class RPG::Class
  225.  
  226.   alias en_ms_c_sn en_scan_notes
  227.   def en_scan_notes(tags = [])
  228.     tags.push([SES::MultiSlot::Seal, "seal = RPG::BaseItem::Feature.new(54, $1.to_i); @features.push(seal)"])
  229.     tags.push([SES::MultiSlot::Fix, "fix = RPG::BaseItem::Feature.new(53, $1.to_i); @features.push(fix)"])
  230.     en_ms_c_sn(tags)
  231.   end
  232. end
  233.  
  234. class RPG::EquipItem < RPG::BaseItem
  235.  
  236.   alias en_ms_e_sn en_scan_notes
  237.   def en_scan_notes(tags = [])
  238.     @etype_ids = []
  239.     @etype_ids.push(@etype_id) unless @etype_id == 1
  240.     tags.push([SES::MultiSlot::EquipSlot, "@etype_ids.push($1.to_i)"])
  241.     tags.push([SES::MultiSlot::Seal, "seal = RPG::BaseItem::Feature.new(54, $1.to_i); @features.push(seal)"])
  242.     tags.push([SES::MultiSlot::Fix, "fix = RPG::BaseItem::Feature.new(53, $1.to_i); @features.push(fix)"])
  243.     en_ms_e_sn(tags)
  244.   end
  245.  
  246.   def etype_ids
  247.       en_scan_notes if @etype_ids.nil?
  248.       return @etype_ids
  249.     end
  250. end
  251.  
  252. module Vocab
  253.  
  254.   def self.etype(etype_id)
  255.     return SES::MultiSlot.terms(etype_id)
  256.   end
  257. end
  258.  
  259. class Game_BaseItem
  260.  
  261.   alias en_ms_gbi_o object
  262.   def object
  263.     return if @item_id.nil?
  264.     en_ms_gbi_o
  265.   end
  266. end
  267.  
  268. class Game_Actor < Game_Battler
  269.  
  270.   alias en_ms_a_s setup
  271.   def setup(actor_id)
  272.     @actor_id = actor_id
  273.     actor.en_scan_notes
  274.     en_ms_a_s(actor_id)
  275.   end
  276.  
  277.   def release_unequippable_items(item_gain = true)
  278.     loop do
  279.       last_equips = equips.dup
  280.       @equips.each_with_index do |item, i|
  281.         if !equippable?(item.object) || !item.object.etype_ids.include?(equip_slots[i])
  282.           trade_item_with_party(nil, item.object) if item_gain
  283.           item.object = nil
  284.         end
  285.       end
  286.       return if equips == last_equips
  287.     end
  288.   end
  289.  
  290.   def optimize_equipments
  291.     clear_equipments
  292.     equip_slots.size.times do |i|
  293.       next if !equip_change_ok?(i)
  294.       items = $game_party.equip_items.select do |item|
  295.         item.etype_ids.include?(equip_slots[i]) &&
  296.         equippable?(item) && item.performance >= 0
  297.       end
  298.       change_equip(i, items.max_by do |item| item.performance end)
  299.     end
  300.   end
  301.  
  302.   def equip_slots
  303.     equiptypes = SES::MultiSlot::Actorslots[@actor_id]
  304.     if dual_wield?
  305.       equiptypes.delete_at(1) if equiptypes[1] == 1
  306.       equiptypes.delete_at(0) if equiptypes[0] == 0
  307.       return [0,0] + equiptypes
  308.     else
  309.       return [0] + equiptypes
  310.       return equiptypes
  311.     end
  312.   end
  313.  
  314.   def change_equip(slot_id, item)
  315.     return unless trade_item_with_party(item, equips[slot_id])
  316.     return if item && !item.etype_ids.include?(equip_slots[slot_id])
  317.     @equips[slot_id].object = item
  318.     refresh
  319.   end
  320. end
  321.  
  322. class Window_EquipSlot < Window_Selectable
  323.  
  324.   def refresh
  325.     self.contents.clear
  326.     return unless @actor
  327.     create_contents
  328.     rect = Rect.new(92, 0, self.width - 128, 24)
  329.     @actor.equip_slots.each_with_index do |s, i|
  330.       name = Vocab.etype(s); self.contents.draw_text(4, 24 * i, 92, 24, name)
  331.     end
  332.     item_max.times do |i|   rect.y = 24 * i; draw_item_name(@actor.equips[i], rect.x, rect.y) end
  333.   end
  334. end
  335.  
  336. class Window_EquipItem < Window_ItemList
  337.  
  338.   def include?(item)
  339.     return true if item == nil
  340.     return false unless item.is_a?(RPG::EquipItem)
  341.     return false if @slot_id < 0
  342.     return false if !item.etype_ids.include?(@actor.equip_slots[@slot_id])
  343.     return @actor.equippable?(item)
  344.   end
  345. end
Advertisement
Add Comment
Please, Sign In to add comment