IceDragon200

SEX - Scene Equip X - R2

Jul 26th, 2011
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.33 KB | None | 0 0
  1. # // IceDragon Edited on 07/10/2011 : Fixed a few issues.
  2. module Z_Systems
  3.   module SceneEquipX
  4.     #==========================================================================#
  5.     #            Multiple Equip Feature : For Redefining Equipment!            #
  6.     #             To disable this feature, set 'EQUIPS = ORIGINAL'             #
  7.     #==========================================================================#
  8.     USE_MULTI_EQUIP_SYSTEM = true
  9.     ORIGINAL = [ # Default types.  Do not edit unless you know what this does.
  10.       :weapon, :shield, :helm, :armor, :acces]
  11.    
  12.     EQUIPS = [
  13.       :weapon,  # Must be Weapon
  14.       :shield,  # Must be replaced if Weapon is two handed
  15.       :helm,
  16.       :back,
  17.       :armor,
  18.       :acces,
  19.       :acces
  20.     ] # DO NOT REMOVE
  21.     REPLACE = {
  22.       #            Condition,                New Vocab,        New Symbol
  23.       :weapon  => ['actor.two_swords_style', 'Vocab::weapon1', :weapon],
  24.       :shield  => ['actor.two_swords_style', 'Vocab::weapon2', :weapon]
  25.     }
  26.     EQUIP_DATA = {
  27.       #          Condition for Equip,           Vocab
  28.       :weapon => ['check_type(0) and noregexp', 'Vocab::weapon'],
  29.       :shield => ['check_type(1) and noregexp', 'Vocab::armor1'],
  30.       :helm   => ['check_type(2) and noregexp', 'Vocab::armor2'],
  31.       :armor  => ['check_type(3) and noregexp', 'Vocab::armor3'],
  32.       :acces  => ['check_type(4) and noregexp', 'Vocab::armor4'],
  33.       :back   => ['regexp("BACK")',             '"Back"']
  34.     }
  35.     # Scripts for above's 'Condition for Equip' ONLY!!! (All returns bool values)
  36.     # check_type(i)   => checks item's kind to original index
  37.     # regexp(string)  => checks for <equip_type: string>
  38.     # noregexp        => checks to see if <equip_type: > does not exist.
  39.    
  40.     #==========================================================================#
  41.     #           Slot and Gem Feature : Set SLOT_MAX to 0 to Disable!           #
  42.     #==========================================================================#
  43. #~     USE_SLOT_SYSTEM = false # NOT YET INSTALLED
  44. #~     SLOT_VOCAB = "Slot"
  45. #~     SLOT_MAX   = 2 #Number from 0..2 ONLY! Future versions may include more.
  46.  
  47. #========#======================#====#================================#========#
  48. #--------#                      #----# DO NOT EDIT PAST THIS POINT!!! #--------#
  49. #--------# End of Customization #----# Editing will cause death by    #--------#
  50. #--------#                      #----# brain asplosions.              #--------#
  51. #========#======================#====#================================#========#
  52.     unless USE_MULTI_EQUIP_SYSTEM
  53.       EQUIPS = ORIGINAL
  54.       REPLACE = {
  55.       ORIGINAL[0] => ['actor.two_swords_style', 'Vocab::weapon1', ORIGINAL[0]],
  56.       ORIGINAL[1] => ['actor.two_swords_style', 'Vocab::weapon2', ORIGINAL[0]]}
  57.       EQUIP_DATA = {}
  58.       for i in 0..4
  59.         EQUIP_DATA[ORIGINAL[i]] = (['check_type('+i.to_s+')'])
  60.         if i == 0
  61.           EQUIP_DATA[ORIGINAL[i]][1] = 'Vocab::weapon'
  62.         else
  63.           EQUIP_DATA[ORIGINAL[i]][1] = 'Vocab::armor'+i.to_s
  64.         end
  65.       end
  66.     end
  67.   end
  68. end
  69.  
  70. $zsys ||= {}
  71. $zsys['SceneEquipX'] = true
  72.  
  73. module Z
  74.  
  75.   def self.active_actor
  76.     return $scene.active_actor
  77.   end
  78.  
  79. end
  80.  
  81. class Scene_Base
  82.  
  83.   def active_actor
  84.     return @actor
  85.   end
  86.  
  87. end
  88.  
  89. module Z::SceneEquipX
  90.   include Z_Systems::SceneEquipX
  91.  
  92.   def self.symbol_index(i)
  93.     symbol = EQUIPS[i]
  94.     unless REPLACE[symbol].nil?
  95.       actor = Z::active_actor
  96.       actor ||= $actor
  97.       if eval(REPLACE[symbol][0])
  98.         symbol = REPLACE[symbol][2]
  99.       end
  100.     end
  101.     return symbol
  102.   end
  103.  
  104.   def self.vocab_index(i)
  105.     symbol = EQUIPS[i]
  106.     vocab  = eval(EQUIP_DATA[symbol][1])
  107.     unless REPLACE[symbol].nil?
  108.       actor = Z::active_actor
  109.       actor ||= $actor
  110.       if eval(REPLACE[symbol][0])
  111.         vocab = eval(REPLACE[symbol][1])
  112.       end
  113.     end
  114.     return vocab
  115.   end
  116.  
  117.   def self.check_type(i, item)
  118.     if i == 0
  119.       return (item.is_a?(RPG::Weapon))
  120.     else
  121.       return item.kind == i - 1
  122.     end
  123.   end
  124.  
  125.   def self.noregexp(item)
  126.     item.note.scan(/<equip_type:[ ](.*)>/i){
  127.       return (false)
  128.     }
  129.     return true
  130.   end
  131.  
  132.   def self.regexp(string, item)
  133.     item.note.scan(/<equip_type:[ ](.*)>/i){|nstring|
  134.       return (string.upcase == nstring[0].upcase)
  135.     }
  136.     return false
  137.   end
  138.  
  139.   def self.original_equipment(actor)
  140.     return [$data_weapons[actor.weapon_id],
  141.              $data_armors[actor.armor1_id],
  142.              $data_armors[actor.armor2_id],
  143.              $data_armors[actor.armor3_id],
  144.              $data_armors[actor.armor4_id]]
  145.   end
  146.  
  147. end
  148.  
  149. class RPG::BaseItem
  150.   include Z_Systems::SceneEquipX
  151.  
  152.   def symbol
  153.     for sym in EQUIPS.compact
  154.       if eval(EQUIP_DATA[sym][0])
  155.         return sym
  156.       end
  157.     end
  158.     print "Error, symbol not found for #{self.name}"
  159.   end
  160.  
  161.   def check_type(i)
  162.     return Z::SceneEquipX::check_type(i, self)
  163.   end
  164.  
  165.   def regexp(string)
  166.     return Z::SceneEquipX::regexp(string, self)
  167.   end
  168.  
  169.   def noregexp
  170.     return Z::SceneEquipX::noregexp(self)
  171.   end
  172.  
  173. end
  174.  
  175. class Window_Rect < Window_Selectable
  176.  
  177.   alias seqx_init initialize
  178.   def initialize(x, y, width, height)
  179.     seqx_init(x, y, width, height)
  180.     self.opacity = 0
  181.   end
  182.  
  183. end
  184.  
  185. class Scene_Equip < Scene_Base
  186.   include Z_Systems::SceneEquipX
  187.   EQUIP_TYPE_MAX = EQUIPS.size
  188.  
  189.   def update_status_window
  190.     if @equip_window.active
  191.       @status_window.set_new_parameters(nil, nil, nil, nil)
  192.     elsif @item_window.active
  193.       temp_actor = Marshal.load(Marshal.dump(@actor))
  194.       equip = @actor.equip_at_slot(@equip_window.index)
  195.       temp_actor.change_equip(@equip_window.index, @item_window.item, true)
  196.       new_atk = temp_actor.atk
  197.       new_def = temp_actor.def
  198.       new_spi = temp_actor.spi
  199.       new_agi = temp_actor.agi
  200.       @status_window.set_new_parameters(new_atk, new_def, new_spi, new_agi)
  201.     end
  202.     @status_window.update
  203.   end
  204.  
  205.   def update_equip_selection
  206.     if Input.trigger?(Input::B)
  207.       Sound.play_cancel
  208.       return_scene
  209.     elsif Input.trigger?(Input::R)
  210.       Sound.play_cursor
  211.       next_actor
  212.     elsif Input.trigger?(Input::L)
  213.       Sound.play_cursor
  214.       prev_actor
  215.     elsif Input.trigger?(Input::C)
  216.       if @actor.fix_equipment
  217.         Sound.play_buzzer
  218.       else
  219.         Sound.play_decision
  220.         @equip_window.active = false
  221.         @item_window.active = true
  222.         @item_window.index = 0
  223.         update_status_window
  224.       end
  225.     end
  226.   end
  227.  
  228.   def update_item_selection
  229.     if Input.trigger?(Input::B)
  230.       Sound.play_cancel
  231.       @equip_window.active = true
  232.       @item_window.active = false
  233.       @item_window.index = -1
  234.     elsif Input.trigger?(Input::C)
  235.       Sound.play_equip
  236.       @actor.change_equip(@equip_window.index, @item_window.item)
  237.       @equip_window.active = true
  238.       @item_window.active = false
  239.       @item_window.index = -1
  240.       @equip_window.refresh
  241.       for item_window in @item_windows
  242.         item_window.refresh
  243.       end
  244.       update_status_window
  245.     end
  246.   end
  247.  
  248.   def update_item_windows
  249.     for i in 0...EQUIP_TYPE_MAX
  250.       @item_windows[i].visible = (@equip_window.index == i)
  251.       @item_windows[i].update
  252.     end
  253.     @item_window = @item_windows[@equip_window.index]
  254.     update_status_window
  255.   end
  256.  
  257.   def update_equip_window
  258.     @equip_window.update
  259.     update_status_window
  260.   end
  261.  
  262. end
  263.  
  264. class Window_Equip < Window_Selectable
  265.   include Z_Systems::SceneEquipX
  266.  
  267.   def refresh
  268.     @data = []
  269.     for item in @actor.equips do @data.push(item) end
  270.     @item_max = EQUIPS.size
  271.     create_contents
  272.     self.contents.font.color = system_color
  273.     for i in 0...EQUIPS.size
  274.       self.contents.draw_text(4, WLH*i, 92, WLH, Z::SceneEquipX::vocab_index(i))
  275.     end
  276.     for i in 0...EQUIPS.size
  277.       draw_item_name(@data[i], 92, WLH * i)
  278.     end
  279.   end
  280.  
  281. end
  282.  
  283. class Window_EquipItem < Window_Item
  284.  
  285.   def initialize(x, y, width, height, actor, equip_type)
  286.     @actor = actor
  287.     @equip_type = equip_type
  288.     super(x, y, width, height)
  289.   end
  290.  
  291.   def include?(item)
  292.     return true if item == nil
  293.     return false unless @actor.equippable?(item)
  294.     return (item.symbol == Z::SceneEquipX::symbol_index(@equip_type))
  295.   end
  296.  
  297. end
  298.  
  299.  
  300. class Game_Actor < Game_Battler
  301.   include Z_Systems::SceneEquipX
  302.  
  303.   alias seqx_setup setup
  304.   def setup(actor_id)
  305.     seqx_setup(actor_id)
  306.     setup_equip_ids() if @equips_id.nil?()
  307.   end
  308.  
  309.   def setup_equip_ids
  310.     @equips_id = []
  311.     $actor = self
  312.     for i in 0...EQUIPS.size
  313.       @equips_id.push(0)
  314.       for equip in Z::SceneEquipX::original_equipment(self)
  315.         next if equip.nil?
  316.         if equip.symbol == Z::SceneEquipX::symbol_index(i)
  317.           @equips_id[i] = equip.id
  318.           break
  319.         end
  320.       end
  321.     end
  322.   end
  323.  
  324.   def weapons
  325.     setup_equip_ids() if @equips_id.nil?()
  326.     result = []
  327.     for i in 0...EQUIPS.size
  328.       item = $data_weapons[@equips_id[i]]
  329.       next if Z::SceneEquipX::symbol_index(i) != ORIGINAL[0]
  330.       result.push(item)
  331.     end
  332.     return result
  333.   end
  334.  
  335.   def armors
  336.     setup_equip_ids() if @equips_id.nil?()
  337.     result = []
  338.     for i in 0...EQUIPS.size
  339.       item = $data_armors[@equips_id[i]]
  340.       next if Z::SceneEquipX::symbol_index(i) == ORIGINAL[0]
  341.       if item.nil?
  342.         result.push(nil)
  343.         next
  344.       end
  345.       result.push(item) if (Z::SceneEquipX::symbol_index(i) == item.symbol)
  346.     end
  347.     return result
  348.   end
  349.  
  350.   def atk_animation_id
  351.     if weapons.size > 1
  352.       return weapons[0].animation_id if weapons[0] != nil
  353.       return weapons[1] == nil ? 1 : 0
  354.     else
  355.       return weapons[0] == nil ? 1 : weapons[0].animation_id
  356.     end
  357.   end
  358.  
  359.   def atk_animation_id2
  360.     if weapons.size > 1
  361.       return weapons[1] == nil ? 0 : weapons[1].animation_id
  362.     else
  363.       return 0
  364.     end
  365.   end
  366.  
  367.   def change_equip_by_id(equip_type, item_id, test = false)
  368.     if Z::SceneEquipX::symbol_index(equip_type) == ORIGINAL[0]
  369.       change_equip(equip_type, $data_weapons[item_id], test)
  370.     else
  371.       change_equip(equip_type, $data_armors[item_id], test)
  372.     end
  373.   end
  374.  
  375.   def change_equip(equip_type, item, test = false)
  376.     unless test
  377.       last_item = equip_at_slot(equip_type)
  378.       return if $game_party.item_number(item) == 0 if item != nil
  379.       $game_party.gain_item(last_item, 1)
  380.       $game_party.lose_item(item, 1)
  381.     end
  382.     item_id = item == nil ? 0 : item.id
  383.     @equips_id[equip_type] = item_id
  384.   end
  385.  
  386.   def equip_at_slot(i)
  387.     id = @equips_id[i]
  388.     if Z::SceneEquipX::symbol_index(i) == ORIGINAL[0]
  389.       item = $data_weapons[id]
  390.     else
  391.       item = $data_armors[id]
  392.     end
  393.   end
  394.  
  395.   def discard_equip(item)
  396.     for i in 0...EQUIPS.size
  397.       if (@equips_id[i] == item.id and
  398.           item.symbol == Z::SceneEquipX::symbol_index(i))
  399.         @equips_id[i] = 0
  400.         break
  401.       end
  402.     end
  403.   end
  404.  
  405.   def two_hands_legal?
  406.     if weapons[0] != nil and weapons[0].two_handed
  407.       return false if @equips_id[1] != 0
  408.     end
  409.     if weapons[1] != nil and weapons[1].two_handed
  410.       return false if @equips_id[0] != 0
  411.     end
  412.     return true
  413.   end
  414.  
  415.   def class_id=(class_id)
  416.     @class_id = class_id
  417.     for i in 0..EQUIPS.size
  418.       change_equip(i, nil) unless equippable?(equips[i])
  419.     end
  420.   end
  421.  
  422. end
Advertisement
Add Comment
Please, Sign In to add comment