roninator2

Kread-Ex - Actor Inventory Mod

Dec 6th, 2024
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.76 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. #  ▼ Actor Inventory Mod
  3. #  Author: Roninator2
  4. #  Version 1.1
  5. #  Release date: 11/20/2020
  6. #  Last Updated: 11/21/2020
  7. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  8. #------------------------------------------------------------------------------
  9. #  ▼ UPDATES
  10. #------------------------------------------------------------------------------
  11. # # 11/20/2020. Patch allows multiple equipment slots for items.
  12. # # 11/21/2020. added support to have accessories in extra slots
  13. # # 11/21/2020. fixed bug with all armour allowed to be added in extra slots
  14. # # 11/21/2020. Added option to have equipment act as items or skills
  15. #------------------------------------------------------------------------------
  16. #  ▼ TERMS OF USAGE
  17. #------------------------------------------------------------------------------
  18. # #  Follow original authors terms of use
  19. #------------------------------------------------------------------------------
  20. #  ▼ INSTRUCTIONS
  21. #------------------------------------------------------------------------------
  22. # # Put the following notetag on your equipment that will act as if it
  23. # # is an item
  24. # # <equip_uses: 1>
  25. # # Then the equipment will do what a potion does
  26. # # <equip_skill: 26>
  27. # # Then the equipment will do what the skill does
  28. # # If both tags are used, the item will be used not the skill.
  29. # # If two of the same tag are used the last one will be used.
  30. #------------------------------------------------------------------------------
  31.  
  32. module KRX
  33.   ITEMS_ETYPE_ID2 = 5
  34.   ITEMS_ETYPE_ID3 = 6
  35.   module REGEXP
  36.     ITEM_EQUIP_USE = /<equip_uses:[ ](\d+)>/i
  37.     ITEM_EQUIP_SKILL = /<equip_skill:[ ](\d+)>/i
  38.   end
  39. end
  40.  
  41. module DataManager  
  42.     #--------------------------------------------------------------------------
  43.     # ● Loads the database
  44.     #--------------------------------------------------------------------------
  45.     class << self
  46.         alias_method(:r2_actuse_dm_load_database, :load_database)
  47.     end
  48.     def self.load_database
  49.         r2_actuse_dm_load_database
  50.         load_actusearm_notetags
  51.     load_actusewep_notetags
  52.     end  
  53.     def self.load_actusearm_notetags
  54.         groups = [$data_armors]
  55.         for group in groups
  56.             for obj in group
  57.                 next if obj.nil?
  58.                 obj.load_actusearm_notetags
  59.             end
  60.         end
  61.     end
  62.     def self.load_actusewep_notetags
  63.         groups = [$data_weapons]
  64.         for group in groups
  65.             for obj in group
  66.                 next if obj.nil?
  67.                 obj.load_actusewep_notetags
  68.             end
  69.         end
  70.     end
  71. end
  72. class RPG::Item < RPG::UsableItem
  73.   def etype_id2
  74.     KRX::ITEMS_ETYPE_ID2
  75.   end
  76.   def etype_id3
  77.     KRX::ITEMS_ETYPE_ID3
  78.   end
  79. end
  80.  
  81. class RPG::Weapon < RPG::EquipItem
  82.   def etype_id2
  83.     KRX::ITEMS_ETYPE_ID2
  84.   end
  85.   def etype_id3
  86.     KRX::ITEMS_ETYPE_ID3
  87.   end
  88.   attr_accessor   :equip_use
  89.   attr_accessor   :equip_skill
  90.     def load_actusewep_notetags
  91.         @note.split(/[\r\n]+/).each do |line|
  92.             case line
  93.             when KRX::REGEXP::ITEM_EQUIP_USE
  94.         @equip_use = $1.to_i
  95.             when KRX::REGEXP::ITEM_EQUIP_SKILL
  96.         @equip_skill = $1.to_i
  97.             end
  98.         end
  99.     end
  100. end
  101.  
  102. class RPG::Armor < RPG::EquipItem
  103.   def etype_id2
  104.     KRX::ITEMS_ETYPE_ID2
  105.   end
  106.   def etype_id3
  107.     KRX::ITEMS_ETYPE_ID3
  108.   end
  109.   attr_accessor   :equip_use
  110.   attr_accessor   :equip_skill
  111.     def load_actusearm_notetags
  112.         @note.split(/[\r\n]+/).each do |line|
  113.             case line
  114.             when KRX::REGEXP::ITEM_EQUIP_USE
  115.         @equip_use = $1.to_i
  116.             when KRX::REGEXP::ITEM_EQUIP_SKILL
  117.         @equip_skill = $1.to_i
  118.             end
  119.         end
  120.     end
  121. end
  122.  
  123. class Window_EquipItem < Window_ItemList
  124.   #--------------------------------------------------------------------------
  125.   # ● Determine if an item goes into the list
  126.   #--------------------------------------------------------------------------
  127.   def include?(item)
  128.     if item.nil? && !@actor.nil?
  129.       etype_id = @actor.equip_slots[@slot_id]
  130.       return YEA::EQUIP::TYPES[etype_id][1]
  131.     end
  132.     return true if item.nil?
  133.     return false if @slot_id < 0
  134.     return false if (item.etype_id != @actor.equip_slots[@slot_id] &&
  135.     item.etype_id2 != @actor.equip_slots[@slot_id] &&
  136.     item.etype_id3 != @actor.equip_slots[@slot_id])
  137.     return false if item.etype_id != @actor.equip_slots[@slot_id] && (item.is_a?(RPG::Armor) ||
  138.     item.is_a?(RPG::Weapon)) && item.etype_id < (item.etype_id2 - 1)
  139.     return @actor.equippable?(item)
  140.   end
  141. end
  142.  
  143. class Game_Actor < Game_Battler
  144.   def change_equip(slot_id, item)
  145.     return unless trade_item_with_party(item, equips[slot_id])
  146.     if item.nil? && !@optimize_clear
  147.       etype_id = equip_slots[slot_id]
  148.       return unless YEA::EQUIP::TYPES[etype_id][1]
  149.     elsif item.nil? && @optimize_clear
  150.       etype_id = equip_slots[slot_id]
  151.       return unless YEA::EQUIP::TYPES[etype_id][2]
  152.     end
  153.     if item.is_a?(RPG::Item) && !item.nil?
  154.       @equips[slot_id].object = item
  155.       @equips[slot_id] = Game_BaseItem.new if @equips[slot_id].nil?
  156.     end
  157.     if item.is_a?(RPG::Armor) && !item.nil?
  158.       @equips[slot_id].object = item
  159.       @equips[slot_id] = Game_BaseItem.new if @equips[slot_id].nil?
  160.     end
  161.     return if item && (equip_slots[slot_id] != item.etype_id)
  162.     @equips[slot_id].object = item
  163.     refresh
  164.   end
  165.   def release_unequippable_items(item_gain = true)
  166.     loop do
  167.       last_equips = equips.dup
  168.       @equips.each_with_index do |item, i|
  169.         next if item && item.object.is_a?(RPG::Item) || item.object.is_a?(RPG::Armor)
  170.         if !equippable?(item.object) || item.object.etype_id != equip_slots[i]
  171.           trade_item_with_party(nil, item.object) if item_gain
  172.           item.object = nil
  173.         end
  174.       end
  175.       return if equips == last_equips
  176.     end
  177.   end
  178. end
  179.  
  180. class Window_ActorItem < Window_EquipSlot
  181.   #--------------------------------------------------------------------------
  182.   # ● Determine if a slot can be selected
  183.   #--------------------------------------------------------------------------
  184.   def enable?(index)
  185.     item = @actor.equips[index]
  186.     return true if item.is_a?(RPG::Item) && item.battle_ok?
  187.     return true if !item.nil? && !item.equip_use.nil?
  188.     return true if !item.nil? && !item.equip_skill.nil?
  189.     return false
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # ● Makes the window appear
  193.   #--------------------------------------------------------------------------
  194.   def show
  195.     @help_window.show
  196.     super
  197.   end
  198.   #--------------------------------------------------------------------------
  199.   # ● Makes the window disappear
  200.   #--------------------------------------------------------------------------
  201.   def hide
  202.     @help_window.hide unless @help_window.nil?
  203.     super
  204.   end
  205. end
  206.  
  207. class Scene_Battle < Scene_Base
  208.   def on_item_ok
  209.     @item = @item_window.item
  210.     $game_temp.item_equip_index = @item_window.index
  211.     if $game_temp.item_equip_index < KRX::ITEMS_ETYPE_ID && !@item.nil?
  212.       if !@item.equip_use.nil?
  213.         @item = $data_items[@item.equip_use]
  214.         $game_temp.item_equip_index = -1
  215.       elsif !@item.equip_skill.nil?
  216.         @skill = $data_skills[@item.equip_skill]
  217.         $game_temp.item_equip_index = -1
  218.         BattleManager.actor.input.set_skill(@skill.id)
  219.         BattleManager.actor.last_skill.object = @skill
  220.         if !@skill.need_selection?
  221.           next_command
  222.         elsif @skill.for_opponent?
  223.           @item_window.hide
  224.           select_enemy_selection
  225.         else
  226.           select_actor_selection
  227.         end
  228.         return
  229.       end
  230.     end
  231.     if !@item.battle_ok?
  232.       Sound.play_buzzer
  233.       @item_window.activate
  234.       $game_temp.battle_aid = nil
  235.       return
  236.     end
  237.     $game_temp.battle_aid = @item
  238.     BattleManager.actor.input.set_item(@item.id)
  239.     if @item.for_opponent?
  240.       select_enemy_selection
  241.     elsif @item.for_friend?
  242.       select_actor_selection
  243.     else
  244.       @item_window.hide
  245.       next_command
  246.       $game_temp.battle_aid = nil
  247.     end
  248.     $game_party.last_item.object = @item
  249.   end
  250.   def on_enemy_cancel
  251.     if $imported["YEA-BattleEngine"]
  252.       BattleManager.actor.input.clear
  253.       @status_aid_window.refresh
  254.       $game_temp.battle_aid = nil
  255.     end
  256.     if @skill_window.visible || @item_window.visible
  257.       @help_window.show
  258.     else
  259.       @help_window.hide
  260.       if $game_temp.item_equip_index == -1
  261.         @item_window.show
  262.         @item_window.activate
  263.         @help_window.show
  264.       end
  265.     end
  266.     @enemy_window.hide
  267.     case @actor_command_window.current_symbol
  268.     when :attack
  269.       @actor_command_window.activate
  270.     when :skill
  271.       if $game_temp.item_equip_index == -1
  272.         @item_window.show
  273.         @item_window.activate
  274.         @help_window.show
  275.       else
  276.         @skill_window.activate
  277.       end
  278.     when :item
  279.       @item_window.activate
  280.     end
  281.   end
  282. end
Add Comment
Please, Sign In to add comment