dsiver144

Dark's Item Expiration v1.2

Mar 16th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.52 KB | None | 0 0
  1. #===============================================================================
  2. # ╔══════════════════════════════════╗
  3. # ║ ▼ Dark's Item Expiration         ║  
  4. # ║ ▼ Author: Nhat Nguyen (Dark Sky) ║
  5. # ║ ▼ Release Date: March 8th 2016   ║
  6. # ╚══════════════════════════════════╝
  7. #-------------------------------------------------------------------------------
  8. # Version 1.0: Release!
  9. # Version 1.1: Fix a bug when recive a(n) weapon/ammour.
  10. # Version 1.2: Fix a bug that occurs when using Battle Test.
  11. #-------------------------------------------------------------------------------
  12. # ▼ Notetag: <dark_custom_item: {hour},{expired item id}>
  13. #  -> <dark_custom_item: 24,28>  : 24 là thời gian item được gán dòng note này
  14. #                                  sẽ bị hết hạn và nhân vật sẽ nhận được item
  15. #                                  với id là 28.
  16. #===============================================================================
  17. $imported = {} if $imported.nil?
  18. $imported["DRK-Item-Expiration"] = true
  19.  
  20. if $imported["TH_InstanceItems"] != true
  21.   msgbox_p("Instance Item not found! Exiting...")
  22.   exit
  23. end
  24.  
  25. module REGEXP
  26.   TOKEN = /<dark_custom_item:\s*(\w+),\s*(\w+)>/i
  27. end
  28.  
  29. module DataManager
  30.     #--------------------------------------------------------------------------
  31.     # ● Loads the database
  32.     #--------------------------------------------------------------------------
  33.     class << self
  34.         alias_method(:my_load_database, :load_database)
  35.     end
  36.     def self.load_database
  37.         my_load_database
  38.         load_my_notetags
  39.     end  
  40.     #--------------------------------------------------------------------------
  41.     # ● Loads the note tags
  42.     #--------------------------------------------------------------------------
  43.     def self.load_my_notetags
  44.     groups = [$data_items] #, $data_weapons, $data_armors]
  45.         for group in groups
  46.             for obj in group
  47.                 next if obj.nil?
  48.                 obj.load_my_notetags
  49.             end
  50.         end
  51.     end
  52. end
  53.  
  54. #==========================================================================
  55. #  ■  RPG::Item
  56. #==========================================================================
  57. class RPG::Item < RPG::UsableItem
  58.     #--------------------------------------------------------------------------
  59.     # ● Public instance variables
  60.     #--------------------------------------------------------------------------
  61.   attr_accessor   :time_nhan
  62.   attr_accessor   :qtime_het_han
  63.   attr_accessor   :time_het_han
  64.   attr_accessor   :co_the_het_han
  65.   attr_accessor   :het_han_item
  66.     #--------------------------------------------------------------------------
  67.     # ● Loads the note tags
  68.     #--------------------------------------------------------------------------
  69.     def load_my_notetags
  70.     @note.split(/[\r\n]+/).each do |line|
  71.       if line =~ REGEXP::TOKEN
  72.         @co_the_het_han = true
  73.         @qtime_het_han = $1.to_i
  74.         @het_han_item = $2.to_i
  75.       end
  76.     end
  77.     end
  78. end
  79.  
  80. class Game_Party < Game_Unit
  81.   #-----------------------------------------------------------------------------
  82.   # The gain item method performs various checks on the item that you want to
  83.   # add to the inventory. Namely, it checks whether it is a template item or
  84.   # an instance item, updates the item counts, and so on.
  85.   #-----------------------------------------------------------------------------
  86.   def gain_item(item, amount, include_equip = false)
  87.     # special check for normal items
  88.     if !instance_enabled?(item)
  89.       th_instance_items_gain_item(item, amount, include_equip)
  90.     else
  91.       if item
  92.         if amount > 0
  93.           amount.times do |i|
  94.             new_item = get_instance(item)
  95.             if new_item.is_a?(RPG::Item) && !$BTEST
  96.               if new_item.co_the_het_han
  97.                 new_item.time_nhan = GameTime.unlimit_hour
  98.                 new_item.time_het_han = new_item.time_nhan + new_item.qtime_het_han
  99.               end
  100.             end
  101.             add_instance_item(new_item)
  102.           end
  103.         else
  104.           amount.abs.times do |i|
  105.             item_template = get_template(item)
  106.             if item.is_template?
  107.               # remove using template rules. If an item was lost, then decrease
  108.               # template count by 1.
  109.               lose_template_item(item, include_equip)
  110.             else
  111.               # remove the instance item, and decrease template count by 1
  112.               lose_instance_item(item)
  113.             end
  114.           end
  115.         end
  116.       else
  117.         th_instance_items_gain_item(item, amount, include_equip)
  118.       end
  119.     end
  120.   end
  121. end
  122.  
  123. module GameTime
  124.   class << self
  125.      alias :darkGameTimeUpdate :update
  126.   end
  127.   def self.update
  128.     darkGameTimeUpdate
  129.     $game_party.items.each do |item|
  130.       if item
  131.         if item.co_the_het_han && !$BTEST
  132.           if $game_time.unlimited_time >= item.time_het_han
  133.             $game_party.gain_item($data_items[item.het_han_item],1)
  134.             $game_party.gain_item(item,-1)
  135.           end
  136.         end
  137.       end
  138.     end
  139.   end
  140.  
  141.   def self.unlimit_hour
  142.     return $game_time.unlimited_time
  143.   end
  144. end
  145.  
  146.   class GameTime::Current_Time
  147.    
  148.     attr_accessor   :unlimited_time
  149.     alias dark_reset_all_values reset_all_values
  150.     def reset_all_values
  151.       dark_reset_all_values
  152.       @unlimited_time = 0
  153.     end
  154.    
  155.     alias darkaddhour addhour
  156.    
  157.     def addhour(h)
  158.       @unlimited_time += h
  159.       darkaddhour(h)
  160.     end
  161.    
  162. end
Advertisement
Add Comment
Please, Sign In to add comment