Advertisement
Iavra

[Ace] Item/Skill Discovery

May 30th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.88 KB | None | 0 0
  1. #==========================================================================
  2. # Iavra Item/Skill Discovery 1.0
  3. # -------------------------------------------------------------------------
  4. # Description:
  5. # Allows to hide the icon, name and description of items and skills until
  6. # they get used for the first time.
  7. # -------------------------------------------------------------------------
  8. # Prerequisites:
  9. # None
  10. # -------------------------------------------------------------------------
  11. # How to Use:
  12. # Place the following tags in the notebox of items/skills you want to hide:
  13. # <hide icon> Hides the icon. Optionally, an icon id can be supplied.
  14. # <hide name> Hides the name. Optionally, a string can be supplied.
  15. # <hide desc> Hides the description. Optionally, a string can be supplied.
  16. # Also, a small message can be shown every time a new item/skill is discovered.
  17. # -------------------------------------------------------------------------
  18. # Terms of Use:
  19. # Free to use for both commercial and non-commercial games. Please give credit.
  20. # -------------------------------------------------------------------------
  21. # Credits:
  22. # Iavra
  23. #==========================================================================
  24.  
  25. module IAVRA
  26.     module DISCOVER
  27.        
  28.         #==========================================================================
  29.         # ■ ■ ■ ■ ■ CONFIGURATION ■ ■ ■ ■ ■
  30.         #==========================================================================
  31.        
  32.         #==========================================================================
  33.         # The default icon id to be used for hidden items/skills if no specific id
  34.         # is supplied in the notetag. This can be done with <hide icon 1>.
  35.         #==========================================================================
  36.        
  37.         DEFAULT_ICON = 1
  38.        
  39.         #==========================================================================
  40.         # The default name to be used for hidden items/skills if no specific string
  41.         # is supplied in the notetag. This can be done with <hide name "Text">
  42.         #==========================================================================
  43.        
  44.         DEFAULT_NAME = "???"
  45.        
  46.         #==========================================================================
  47.         # The default description to be used for hidden items/skills if no specific
  48.         # string is supplied in the notetag. This can be done with <hide desc "Text">
  49.         #==========================================================================
  50.        
  51.         DEFAULT_DESC = "???"
  52.        
  53.         #==========================================================================
  54.         # If set to true, a popup window is shown in the bottom left corner whenever
  55.         # a new iterm/skill is discovered.
  56.         #==========================================================================
  57.        
  58.         SHOW_WINDOW = true
  59.        
  60.         #==========================================================================
  61.         # The width of the popup window
  62.         #==========================================================================
  63.        
  64.         WINDOW_WIDTH = 400
  65.        
  66.         #==========================================================================
  67.         # The vertical space below each window. If a new item is discovered while
  68.         # there is still a window on the screen, the old one(s) will be pushed
  69.         # upwards depending on the new window's height and this value.
  70.         #==========================================================================
  71.        
  72.         WINDOW_SPACING = 10
  73.        
  74.         #==========================================================================
  75.         # If set  to true, the icon of the discovered item/skill is shown in front
  76.         # of the message.
  77.         #==========================================================================
  78.        
  79.         WINDOW_ICON = false
  80.        
  81.         #==========================================================================
  82.         # The text to be displayed. All message codes can be used.
  83.         #==========================================================================
  84.        
  85.         WINDOW_TEXT = " \\C[2]%s\\C[0] discovered!"
  86.        
  87.         #==========================================================================
  88.         # The delay (in frames) before the window starts to fade away and the rate
  89.         # at which the window fades.
  90.         #==========================================================================
  91.        
  92.         WINDOW_FADE_DELAY = 120
  93.         WINDOW_FADE_RATE = 10
  94.        
  95.         #==========================================================================
  96.         # The padding inside the window. X is horizontal, Y is vertical.
  97.         #==========================================================================
  98.        
  99.         WINDOW_PADDING_X = 5
  100.         WINDOW_PADDING_Y = 5
  101.        
  102.         #==========================================================================
  103.         # The background of the window is drawn as a gradient between these colors.
  104.         #==========================================================================
  105.        
  106.         WINDOW_COLOR_1 = Color.new(0, 0, 0, 255)
  107.         WINDOW_COLOR_2 = Color.new(0, 0, 0, 0)
  108.        
  109.         #==========================================================================
  110.         # ■ ■ ■ ■ ■ CONFIGURATION ■ ■ ■ ■ ■
  111.         #==========================================================================
  112.        
  113.         REGEX_ICON = /^\s*<hide icon(\s+(\d+))?>/i
  114.         REGEX_NAME = /^\s*<hide name(\s+"(.*)")?>/i
  115.         REGEX_DESC = /^\s*<hide desc(\s+"(.*)")?>/i
  116.        
  117.         #==========================================================================
  118.         # ▼ IAVRA::DISCOVER::Window_Discover
  119.         #==========================================================================
  120.        
  121.         class Window_Discover < Window_Base
  122.            
  123.             #==========================================================================
  124.             # Initializes the window, draws text etc.
  125.             #==========================================================================
  126.            
  127.             def initialize(item)
  128.                 width = WINDOW_WIDTH + WINDOW_PADDING_X * 2
  129.                 height = fitting_height(1) + WINDOW_PADDING_Y * 2
  130.                 super(0, Graphics.height - height - WINDOW_SPACING, width, height)
  131.                 contents.gradient_fill_rect(contents.rect, WINDOW_COLOR_1, WINDOW_COLOR_2)
  132.                 draw_icon(item.icon_index, WINDOW_PADDING_X, WINDOW_PADDING_Y) if WINDOW_ICON
  133.                 offset = WINDOW_PADDING_X + (WINDOW_ICON ? 24 : 0)
  134.                 draw_text_ex(offset, WINDOW_PADDING_Y, sprintf(WINDOW_TEXT, item.name))
  135.                 self.windowskin = nil
  136.                 @delay = WINDOW_FADE_DELAY
  137.                 self.z = 1000
  138.             end
  139.            
  140.             #==========================================================================
  141.             # Count down delay and fade out. Dispose if opacity is 0.
  142.             #==========================================================================
  143.            
  144.             def update
  145.                 super
  146.                 self.contents_opacity -= WINDOW_FADE_RATE if (@delay -= 1) <= 0
  147.                 dispose if self.contents_opacity == 0
  148.             end
  149.            
  150.             #==========================================================================
  151.             # Umm...yeah.
  152.             #==========================================================================
  153.            
  154.             def standard_padding
  155.                 return 0
  156.             end
  157.            
  158.         end
  159.        
  160.     end
  161. end
  162.  
  163. #==========================================================================
  164. # ▼ DataManager
  165. #==========================================================================
  166.  
  167. module DataManager
  168.    
  169.     class << self
  170.         alias :iavra_discover_load_database :load_database
  171.     end
  172.    
  173.     #==========================================================================
  174.     # Loads our notetags from all skills and items.
  175.     #==========================================================================
  176.    
  177.     def self.load_database
  178.         iavra_discover_load_database
  179.         ($data_items + $data_skills).compact.each{|item| item.iavra_discover_init}
  180.     end
  181.    
  182. end
  183.  
  184. #==========================================================================
  185. # ▼ Game_System
  186. #==========================================================================
  187.  
  188. class Game_System
  189.    
  190.     attr_reader :iavra_discover_discovered
  191.    
  192.     alias :iavra_discover_initialize :initialize
  193.    
  194.     #==========================================================================
  195.     # Initializes our discovery hash.
  196.     #==========================================================================
  197.    
  198.     def initialize(*args)
  199.         iavra_discover_initialize(*args)
  200.         @iavra_discover_discovered = {}
  201.     end
  202.    
  203. end
  204.  
  205. #==========================================================================
  206. # ▼ RPG::UsableItem
  207. #==========================================================================
  208.  
  209. class RPG::UsableItem < RPG::BaseItem
  210.    
  211.     #==========================================================================
  212.     # Parses all notetags and stores the hidden values.
  213.     #==========================================================================
  214.    
  215.     def iavra_discover_init
  216.         self.note.split(/[\r\n]+/).each do |line|
  217.             @iavra_discover_icon = $2.to_i || IAVRA::DISCOVER::DEFAULT_ICON if line[IAVRA::DISCOVER::REGEX_ICON]
  218.             @iavra_discover_name = $2 || IAVRA::DISCOVER::DEFAULT_NAME if line[IAVRA::DISCOVER::REGEX_NAME]
  219.             @iavra_discover_desc = $2 || IAVRA::DISCOVER::DEFAULT_DESC if line[IAVRA::DISCOVER::REGEX_DESC]
  220.         end
  221.     end
  222.    
  223.     #==========================================================================
  224.     # Returns true if any part of the item/skill is still hidden.
  225.     #==========================================================================
  226.    
  227.     def iavra_discover_discoverable?
  228.         (@iavra_discover_icon || @iavra_discover_name || @iavra_discover_desc) &&
  229.         $game_system.iavra_discover_discovered[[self.class, @id]].nil?
  230.     end
  231.    
  232.     #==========================================================================
  233.     # Returns our hidden icon index if the item/skill has not yet been used.
  234.     #==========================================================================
  235.    
  236.     def icon_index
  237.         return @icon_index if $game_system.iavra_discover_discovered[[self.class, @id]]
  238.         return @iavra_discover_icon || @icon_index
  239.     end
  240.    
  241.     #==========================================================================
  242.     # Returns our hidden name if the skill/item has not yet been used.
  243.     #==========================================================================
  244.    
  245.     def name
  246.         return @name if $game_system.iavra_discover_discovered[[self.class, @id]]
  247.         return @iavra_discover_name || @name
  248.     end
  249.    
  250.     #==========================================================================
  251.     # Returns our hidden description if the skill/item has not yet been used.
  252.     #==========================================================================
  253.    
  254.     def description
  255.         return @description if $game_system.iavra_discover_discovered[[self.class, @id]]
  256.         return @iavra_discover_desc || @description
  257.     end
  258.    
  259. end
  260.  
  261. #==========================================================================
  262. # ▼ Game_Actor
  263. #==========================================================================
  264.  
  265. class Game_Actor < Game_Battler
  266.    
  267.     alias :iavra_discover_use_item :use_item
  268.    
  269.     #==========================================================================
  270.     # Marks the skill/item as used.
  271.     #==========================================================================
  272.    
  273.     def use_item(item)
  274.         iavra_discover_use_item(item)
  275.         if(item.iavra_discover_discoverable?)          
  276.             $game_system.iavra_discover_discovered[[item.class, item.id]] = true
  277.             if(IAVRA::DISCOVER::SHOW_WINDOW)
  278.                 window = IAVRA::DISCOVER::Window_Discover.new(item)
  279.                 SceneManager.scene.iavra_discover_add_window(window)
  280.             end
  281.         end
  282.     end
  283. end
  284.  
  285. #==========================================================================
  286. # ▼ Scene_Base
  287. #==========================================================================
  288.  
  289. class Scene_Base
  290.    
  291.     alias :iavra_discover_start :start
  292.     alias :iavra_discover_update_all_windows :update_all_windows
  293.     alias :iavra_discover_dispose_all_windows :dispose_all_windows
  294.    
  295.     #==========================================================================
  296.     # Initialize our window array.
  297.     #==========================================================================
  298.    
  299.     def start(*args)
  300.         iavra_discover_start(*args)
  301.         @iavra_discover_windows = []
  302.     end
  303.    
  304.     #==========================================================================
  305.     # Update all windows and remove disposed ones.
  306.     #==========================================================================
  307.    
  308.     def update_all_windows
  309.         iavra_discover_update_all_windows
  310.         @iavra_discover_windows.reject!{|window| window.disposed?}
  311.         @iavra_discover_windows.each{|window| window.update}
  312.     end
  313.    
  314.     #==========================================================================
  315.     # Cleanup on scene end.
  316.     #==========================================================================
  317.    
  318.     def dispose_all_windows
  319.         iavra_discover_dispose_all_windows
  320.         @iavra_discover_windows.each{|window| window.dispose}
  321.     end
  322.    
  323.     #==========================================================================
  324.     # Add a new window, push older ones up to make space.
  325.     #==========================================================================
  326.    
  327.     def iavra_discover_add_window(window)
  328.         @iavra_discover_windows.each{|w| w.y -= (window.height + IAVRA::DISCOVER::WINDOW_SPACING)}
  329.         @iavra_discover_windows << window
  330.     end
  331.    
  332. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement