Advertisement
Fomar0153

Fomar0153 - Individual Equipment 1.0

Mar 1st, 2012
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.37 KB | None | 0 0
  1. =begin
  2. Individual Equipment
  3. by Fomar0153
  4. Version 1.0
  5. ----------------------
  6. Notes
  7. ----------------------
  8. This script changes the way weapons and armours are handled
  9. in game. This script make every weapon and armour unique.
  10. ----------------------
  11. Instructions
  12. ----------------------
  13. Plug and play.
  14. If you want to be able to carry more than 150 weapons and 150 armors
  15. edit MAX_INVENTORY_SIZE which you can find at the top of the script.
  16. This script is designed to be a base for other scripts.
  17. For example:
  18. Proper Weapon and Armour Customisation.
  19. ----------------------
  20. Known bugs
  21. ----------------------
  22. None
  23. =end
  24.  
  25. module CustomEquip
  26.  
  27.   MAX_INVENTORY_SIZE = 150
  28.  
  29. end
  30.  
  31. class Game_CustomEquip < Game_BaseItem
  32.   #--------------------------------------------------------------------------
  33.   # ● New attr_accessor & attr_reader
  34.   #--------------------------------------------------------------------------
  35.   attr_accessor :pos
  36.   attr_reader   :item_id
  37.   #--------------------------------------------------------------------------
  38.   # ● Pos is used to identify weapons and armors
  39.   #--------------------------------------------------------------------------
  40.   def initialize
  41.     super
  42.     @pos = 0
  43.   end
  44.   #--------------------------------------------------------------------------
  45.   # ● The rest of the methods allow this item to pretend to be RPG::Weapon
  46.   #   and RPG::Armor in some cases, increasing compatability, thought not
  47.   #   as much as I would like.
  48.   #--------------------------------------------------------------------------
  49.   def description
  50.     return nil if is_nil?
  51.     return object.description
  52.   end
  53.  
  54.   def name
  55.     return nil if is_nil?
  56.     return object.name
  57.   end
  58.  
  59.   def icon_index
  60.     return nil if is_nil?
  61.     return object.icon_index
  62.   end
  63.  
  64.   def price
  65.     return nil if is_nil?
  66.     return object.price
  67.   end
  68.  
  69.   def animation_id
  70.     return nil if is_nil?
  71.     return nil if is_armor? # variable only exists for RPG::Weapon
  72.     return object.animation_id
  73.   end
  74.  
  75.   def note
  76.     return nil if is_nil?
  77.     return object.note
  78.   end
  79.  
  80.   def id
  81.     return nil if is_nil?
  82.     return object.id
  83.   end
  84.  
  85.   def features
  86.     return nil if is_nil?
  87.     return object.features
  88.   end
  89.  
  90.   def params
  91.     return nil if is_nil?
  92.     return object.params
  93.   end
  94.  
  95.   def etype_id
  96.     return nil if is_nil?
  97.     return object.etype_id
  98.   end
  99.  
  100.   def wtype_id
  101.     return nil if is_nil?
  102.     return nil if is_armor? # variable only exists for RPG::Weapon
  103.     return object.wtype_id
  104.   end
  105.  
  106.   def atype_id
  107.     return nil if is_nil?
  108.     return nil if is_weapon? # variable only exists for RPG::Armor
  109.     return object.atype_id
  110.   end
  111.  
  112.  
  113.   # performance returns an integer calculated from the equip item's params.
  114.   # each point in a param increasing performance by one, except
  115.   # for attack and magic on weapon which counts double
  116.   # for defence and magic defence on armours which counts double
  117.   def performance
  118.     return nil if is_nil?
  119.     return object.performance
  120.   end
  121.  
  122. end
  123.  
  124. class Game_Party < Game_Unit
  125.   #--------------------------------------------------------------------------
  126.   # ● Aliases init_all_items
  127.   #--------------------------------------------------------------------------
  128.   alias ie_init_all_items init_all_items
  129.   def init_all_items
  130.     ie_init_all_items
  131.     @weapons = []
  132.     @armors = []
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # ● Rewrites weapons
  136.   #--------------------------------------------------------------------------
  137.   def weapons
  138.     return @weapons
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # ● Rewrites armors
  142.   #--------------------------------------------------------------------------
  143.   def armors
  144.     return @armors
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # ● Aliases item_number + Probably rewrite
  148.   #--------------------------------------------------------------------------
  149.   alias ie_item_number item_number
  150.   def item_number(item)
  151.     if item.class == RPG::Weapon or item.class == RPG::Armor
  152.       return 1 # I haven't found this to cause unexpected behaviour
  153.                # but I don't like it
  154.     else
  155.       return ie_item_number(item)
  156.     end
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # ● Aliases gain_item
  160.   #--------------------------------------------------------------------------
  161.   alias ie_gain_item gain_item
  162.   def gain_item(item, amount, include_equip = false)
  163.     if item.class == RPG::Weapon
  164.       if amount > 0
  165.         for i in 1..amount
  166.           t = Game_CustomEquip.new
  167.           t.object = item
  168.           @weapons.push(t)
  169.         end
  170.         weapon_sort
  171.       end
  172.     elsif item.is_a?(Game_CustomEquip) && item.is_weapon?
  173.       if amount == 1
  174.         @weapons.push(item)
  175.         weapon_sort
  176.       elsif amount == -1
  177.         # Can't sell more than 1 at a time
  178.         # (is there any other way to remove more than 1 at a time?
  179.         # except through events?)
  180.         @weapons.delete_at(item.pos)
  181.         weapon_sort
  182.       end
  183.     elsif item.class == RPG::Armor
  184.       if amount > 0
  185.         for i in 1..amount
  186.           t = Game_CustomEquip.new
  187.           t.object = item
  188.           @armors.push(t)
  189.         end
  190.         armor_sort
  191.       end
  192.     elsif item.is_a?(Game_CustomEquip) && item.is_armor?
  193.       if amount == 1
  194.         @armors.push(item)
  195.         armor_sort
  196.       elsif amount == -1
  197.         # Can't sell more than 1 at a time
  198.         # (is there any other way to remove more than 1 at a time?
  199.         # except through events?)
  200.         @armors.delete_at(item.pos)
  201.         armor_sort
  202.       end
  203.     else
  204.       ie_gain_item(item, amount, include_equip)
  205.       return
  206.     end
  207.     $game_map.need_refresh = true
  208.   end
  209.  
  210.   def weapon_sort
  211.     @weapons.sort! { |a, b|  a.item_id <=> b.item_id }
  212.     for i in 0..@weapons.size - 1
  213.       @weapons[i].pos = i
  214.     end
  215.   end
  216.  
  217.   def armor_sort
  218.     @armors.sort! { |a, b|  a.item_id <=> b.item_id }
  219.     for i in 0..@armors.size - 1
  220.       @armors[i].pos = i
  221.     end
  222.   end
  223.  
  224.   alias ie_max_item_number max_item_number
  225.   def max_item_number(item)
  226.     if item.class == RPG::Weapon
  227.       return CustomEquip::MAX_INVENTORY_SIZE - @weapons.size
  228.     elsif item.class == RPG::Armor
  229.       return CustomEquip::MAX_INVENTORY_SIZE - @armors.size
  230.     else
  231.       return ie_max_item_number(item)
  232.     end
  233.   end
  234. end
  235.  
  236. class Window_ItemList < Window_Selectable
  237.  
  238.   alias ie_include? include?
  239.   def include?(item)
  240.     case @category
  241.     when :weapon
  242.       item.is_a?(Game_CustomEquip) && item.object.is_a?(RPG::Weapon)
  243.     when :armor
  244.       item.is_a?(Game_CustomEquip) && item.object.is_a?(RPG::Armor)
  245.     else
  246.       ie_include?(item)
  247.     end
  248.   end
  249.  
  250.   alias ie_draw_item draw_item
  251.   def draw_item(index)
  252.     item = @data[index]
  253.     if item && !item.is_a?(Game_CustomEquip)
  254.       ie_draw_item(index)
  255.     elsif item && item.is_a?(Game_CustomEquip)
  256.       rect = item_rect(index)
  257.       rect.width -= 4
  258.       draw_item_name(item, rect.x, rect.y, enable?(item))
  259.       #draw_item_number(rect, item) just this line removed from the default
  260.     end
  261.   end
  262.  
  263. end
  264.  
  265.  
  266. class Window_EquipItem < Window_ItemList
  267.   #--------------------------------------------------------------------------
  268.   # ● Aliases include?
  269.   #--------------------------------------------------------------------------
  270.   alias ie2_include? include?
  271.   def include?(item)
  272.     return true if item == nil
  273.     return false unless item.is_a?(Game_CustomEquip)
  274.     return ie2_include?(item.object)
  275.   end
  276.   #--------------------------------------------------------------------------
  277.   # ● Rewrites update_help
  278.   #--------------------------------------------------------------------------
  279.   def update_help
  280.     super
  281.     if @actor && @status_window
  282.       temp_actor = Marshal.load(Marshal.dump(@actor))
  283.       temp_actor.force_change_equip(@slot_id, item) unless item.nil?
  284.       @status_window.set_temp_actor(temp_actor)
  285.     end
  286.   end
  287. end
  288.  
  289.  
  290. class Game_Actor < Game_Battler
  291.   #--------------------------------------------------------------------------
  292.   # ● Rewrites init_equips
  293.   #--------------------------------------------------------------------------
  294.   def init_equips(equips)
  295.     @equips = Array.new(equip_slots.size) { Game_CustomEquip.new } # only change
  296.     equips.each_with_index do |item_id, i|
  297.       etype_id = index_to_etype_id(i)
  298.       slot_id = empty_slot(etype_id)
  299.       @equips[slot_id].set_equip(etype_id == 0, item_id) if slot_id
  300.     end
  301.     refresh
  302.   end
  303.   #--------------------------------------------------------------------------
  304.   # ● Rewrites change_equip
  305.   #--------------------------------------------------------------------------
  306.   def change_equip(slot_id, item)
  307.     return unless trade_item_with_party(item, equips[slot_id])
  308.     return if item && equip_slots[slot_id] != item.etype_id
  309.     if item.nil?
  310.       @equips[slot_id] = Game_CustomEquip.new
  311.     else
  312.       @equips[slot_id] = item
  313.     end
  314.     refresh
  315.   end
  316.   #--------------------------------------------------------------------------
  317.   # ● Rewrites force_change_equip
  318.   #--------------------------------------------------------------------------
  319.   def force_change_equip(slot_id, item)
  320.     if item.nil?
  321.       @equips[slot_id] = Game_CustomEquip.new
  322.     else
  323.       @equips[slot_id] = item
  324.     end
  325.     release_unequippable_items(false)
  326.     refresh
  327.   end
  328.   #--------------------------------------------------------------------------
  329.   # ● Rewrites trade_item_with_party
  330.   #--------------------------------------------------------------------------
  331.   def trade_item_with_party(new_item, old_item)
  332.     #return false if new_item && !$game_party.has_item?(new_item) removed
  333.     $game_party.gain_item(old_item, 1)
  334.     $game_party.lose_item(new_item, 1)
  335.     return true
  336.   end
  337.   #--------------------------------------------------------------------------
  338.   # ● Rewrites change_equip_by_id
  339.   #--------------------------------------------------------------------------
  340.   def change_equip_by_id(slot_id, item_id)
  341.     if equip_slots[slot_id] == 0
  342.       t = Game_CustomEquip.new
  343.       t.object = $data_weapons[item_id]
  344.       $game_party.gain_item(t, 1)
  345.       change_equip(slot_id, t)
  346.     else
  347.       t = Game_CustomEquip.new
  348.       t.object = $data_armors[item_id]
  349.       $game_party.gain_item(t, 1)
  350.       change_equip(slot_id, t)
  351.     end
  352.   end
  353.   #--------------------------------------------------------------------------
  354.   # ● Rewrites optimize_equipments or does it
  355.   #--------------------------------------------------------------------------
  356.   def optimize_equipments
  357.     clear_equipments
  358.     equip_slots.size.times do |i|
  359.       next if !equip_change_ok?(i)
  360.       items = $game_party.equip_items.select do |item|
  361.         item.etype_id == equip_slots[i] &&
  362.         equippable?(item.object) && item.performance >= 0
  363.       end
  364.       change_equip(i, items.max_by {|item| item.performance })
  365.     end
  366.   end
  367. end
  368.  
  369.  
  370. class Window_ShopStatus < Window_Base
  371.  
  372.   alias ie_draw_possession draw_possession
  373.   def draw_possession(x, y)
  374.     return if @item.is_a?(RPG::EquipItem)
  375.     ie_draw_possession(x, y)
  376.   end
  377.  
  378.   alias ie_draw_equip_info draw_equip_info
  379.   def draw_equip_info(x, y)
  380.     ie_draw_equip_info(x, y - line_height * 2)
  381.   end
  382. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement