dsiver144

Dark's Item Expiration v1.1

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