Advertisement
roninator2

Block instance item creation

Dec 15th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.17 KB | None | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Block Instance Items         ║  Version: 1.00     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║                                     ╠════════════════════╣
  7. # ║ Allow some items to not be Instance ║    28 Apr 2023     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Instructions:                                            ║
  11. # ║   Add note tag to the items that are to not become       ║
  12. # ║   instance items.                                        ║
  13. # ║   <instance_blocked>                                     ║
  14. # ║   Non instance items will be treated like normal         ║
  15. # ║   Required Tsukihime's Instance Items script             ║
  16. # ╚══════════════════════════════════════════════════════════╝
  17. # ╔══════════════════════════════════════════════════════════╗
  18. # ║ Terms of use:                                            ║
  19. # ║ Free for all uses in RPG Maker except nudity             ║
  20. # ╚══════════════════════════════════════════════════════════╝
  21.  
  22. module RPG
  23.   class Item < UsableItem
  24.     attr_accessor :in_hand
  25.    
  26.     Instance_Blocked      = /<instance_blocked>/i
  27.     def instance_blocked?
  28.       self.note.split(/[\r\n]+/).each do |line|
  29.         case line
  30.         when Instance_Blocked
  31.           return true
  32.         end
  33.       end
  34.       return false
  35.     end
  36.     def in_hand
  37.       @in_hand = 0 unless @in_hand
  38.       return @in_hand
  39.     end
  40.   end
  41.  
  42.   class EquipItem < BaseItem    
  43.     attr_accessor :in_hand
  44.    
  45.     Instance_Blocked      = /<instance_blocked>/i
  46.     def instance_blocked?
  47.       self.note.split(/[\r\n]+/).each do |line|
  48.         case line
  49.         when Instance_Blocked
  50.           return true
  51.         end
  52.       end
  53.       return false
  54.     end
  55.    
  56.     def in_hand
  57.       @in_hand = 0 unless @in_hand
  58.       return @in_hand
  59.     end
  60.   end
  61. end
  62.  
  63. class Game_Party < Game_Unit
  64.   #-----------------------------------------------------------------------------
  65.   # The gain item method performs various checks on the item that you want to
  66.   # add to the inventory. Namely, it checks whether it is a template item or
  67.   # an instance item, updates the item counts, and so on.
  68.   #-----------------------------------------------------------------------------
  69.   def gain_item(item, amount, include_equip = false)
  70.     # special check for normal items
  71.     if !instance_enabled?(item)
  72.       th_instance_items_gain_item(item, amount, include_equip)
  73.     else
  74.       if item
  75.         if amount > 0
  76.           amount.times do |i|
  77.             new_item = get_instance(item)
  78.             if item.instance_blocked?
  79.               add_instance_blocked_item(item)
  80.             else
  81.               add_instance_item(new_item)
  82.             end
  83.           end
  84.         else
  85.           amount.abs.times do |i|
  86.             item_template = get_template(item)
  87.             if item.is_template?
  88.               # remove using template rules. If an item was lost, then decrease
  89.               # template count by 1.
  90.               lose_template_item(item, include_equip)
  91.             else
  92.               # remove the instance item, and decrease template count by 1
  93.               if item.instance_blocked?
  94.                 lose_instance_blocked_item(item)
  95.               else
  96.                 lose_instance_item(item)
  97.               end
  98.             end
  99.           end
  100.         end
  101.       else
  102.         th_instance_items_gain_item(item, amount, include_equip)
  103.       end
  104.     end
  105.   end
  106.   #-----------------------------------------------------------------------------
  107.   # New. Adds the instance item to the appropriate list
  108.   #-----------------------------------------------------------------------------
  109.   def add_instance_blocked_item(item)
  110.     container = item_container(item.class)
  111.     container[item.template_id] ||= 0
  112.     container[item.template_id] += 1
  113.     container[item.in_hand] ||= 0
  114.     container[item.in_hand] += 1 if container[item.in_hand] == 0
  115.     container_list = item_container_list(item)
  116.     if container_list == []
  117.       container_list.push(item)
  118.     else
  119.       item_found = false
  120.       container_list.each do |itm|
  121.         if item.template_id == itm.template_id
  122.           itm.in_hand += 1 if itm.in_hand == 0
  123.           itm.in_hand += 1
  124.           item_found = true
  125.         end
  126.       end
  127.       container_list.push(item) if !item_found
  128.     end
  129.   end
  130.  
  131.   #-----------------------------------------------------------------------------
  132.   # New. Lose an instance item. Simply delete it from the appropriate container
  133.   # list
  134.   #-----------------------------------------------------------------------------
  135.   def lose_instance_blocked_item(item)
  136.     container = item_container(item.class)
  137.     container[item.template_id] ||= 0
  138.     container[item.template_id] -= 1
  139.     container[item.in_hand] -= 1
  140.     container_list = item_container_list(item)
  141.     container_list.each do |itm|
  142.       if item.template_id == itm.template_id
  143.         itm.in_hand -= 1
  144.         if itm.in_hand == 0
  145.           container_list.delete(item)
  146.         end
  147.       end
  148.     end
  149.   end
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement