Advertisement
Fomar0153

Fomar0153 - Individual Equipment 1.1

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