Advertisement
napoleonite

Quest Journal - Debug Addon

Jan 22nd, 2013
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 22.94 KB | None | 0 0
  1. #==============================================================================
  2. # Version 1.02
  3. #
  4. # About:
  5. # A quick debug manager for completing/failing/revealing/concealing quests and
  6. # objectives.
  7. #
  8. # Instructions:
  9. # Place below "Modern Algebra's Quest Journal" but above "▼ Main Process".
  10. # Call like this: SceneManager.call(Scene_QJ_Debug).
  11. # Or Press Q (default) in the quest window to open the debug window.
  12. #
  13. # Requires:
  14. # - Modern Algebra's Quest Journal 1.0.3
  15. # - RPG Maker VX Ace
  16. #
  17. # Written by Napoleon (My very first addon!).
  18. # Special thanks to Modern Algebra for answering my questions.
  19. #
  20. # Terms of Use:
  21. # Credits are appreciated but not required. You may repost this as well as long
  22. # as you do not claim this as your own work.
  23. #
  24. # Version History:
  25. # 1.00 (17-1-2013)
  26. #   - First Release
  27. # 1.01 (18-1-2013)
  28. #   - Added the $TEST variable
  29. # 1.02 (18-1-2013)
  30. #   - Added more functions
  31. #==============================================================================
  32.  
  33.  
  34. #==============================================================================
  35. # ■ Quest Journal - Debug Addon - Singleton instance
  36. #------------------------------------------------------------------------------
  37. #  Singleton instance for the QJ debug scene
  38. #==============================================================================
  39. module Quest_Journal
  40.   module Utility
  41. ################################################################################
  42. # CONFIG START
  43. ################################################################################
  44.     # When set to true (default) then you can Press [Q] (default) in the quest menu to open the debug menu.
  45.     # When set to false this addon can only be manually called.
  46.     # Note: This addon also requires the global $TEST set to true.
  47.     DEBUG_MENU_ENABLED = true
  48.    
  49.     # Key for opening the debug menu from the quest journal. Use a nil value to disable this.
  50.     DEBUG_MENU_KEY = QuestData::MAP_BUTTON # Should be [Q] by default
  51.    
  52.     # Key for completing/resetting an entire quest (left window)
  53.     COMPLETE_RESET_QUEST_KEY = QuestData::MAP_BUTTON # Should be [Q] by default
  54.    
  55.     # Key for opening the debug menu directly from the map. Use a nil value to disable this.
  56.     MAP_KEY = nil
  57.    
  58.     # When set to true then the debug menu will be shown if the Quest Journal has no quests and would have otherwise just played a 'buzzer sound'.
  59.     SHOW_WHEN_NO_QUESTS = true
  60.    
  61.     # The first quest id, usually 0
  62.     FIRST_QUEST = 0
  63.    
  64.     # When set to false then the map is shown after closing the debug menu even if it was opened through the Quest Journal's menu.
  65.     RETURN_TO_QUEST_MENU = true
  66.    
  67.     # The maximum quest id to check. This must be equal or higher than your highest quest id
  68.     MAX_QUEST = 1000
  69.  
  70.     # Quest text color when completed (in debug menu only)
  71.     QUEST_COMPLETE_COLOR = 3 # 3 = lightgreen
  72.    
  73.     # The text status colors
  74.     COLORS = {
  75.       'revealed' => 1, # blue
  76.       'completed' => 3, # green
  77.       'failed' => 18, # red
  78.       'concealed' => 0 # white
  79.     }    
  80. ################################################################################    
  81. # CONFIG END
  82. ################################################################################
  83.     # Samples:
  84.       # Utility.quest_data(1,:objectives)
  85.       # Utility.quest_data(1,:name)
  86.     # Possible symbols: :line, :level, :name, :description, :objectives, :rewards
  87.     def self.quest_data(q_id, symbol)    
  88.       return QuestData.setup_quest(q_id)[symbol]
  89.     end
  90.    
  91.     # Returns true if this addon is enabled AND if the global debug mode is turned on
  92.     def self.enabled?
  93.       return DEBUG_MENU_ENABLED && $TEST
  94.     end
  95.    
  96.     # Returns an array with all used (=non-empty) quest id's.
  97.     def self.set_quest_data
  98.       result = []
  99.       array_idx = 0
  100.       for i in FIRST_QUEST..MAX_QUEST
  101.         if quest_data(i,:name) != nil
  102.           result[array_idx] = i
  103.           array_idx +=1
  104.         end
  105.       end
  106.       return result
  107.     end    
  108.    
  109.     #Utility.quests
  110.     @@quests = set_quest_data
  111.     # static getter
  112.     def self.quests
  113.       @@quests
  114.     end  
  115.    
  116.     #Utility.quest_complete?()
  117.     def self.quest_complete?(q_id)
  118.       return $game_party.quests.revealed?(q_id) && $game_party.quests[q_id].status?(:complete)
  119.     end    
  120.     #Utility.quest_revealed?()
  121.     def self.quest_revealed?(q_id)
  122.       return $game_party.quests.revealed?(q_id)
  123.     end    
  124.     #Utility.quest_failed?()
  125.     def self.quest_failed?(q_id)
  126.       return $game_party.quests.revealed?(q_id) && $game_party.quests[q_id].status?(:failed)
  127.     end    
  128.     #Utility.quest_concealed?()
  129.     def self.quest_concealed?(q_id)
  130.       return !$game_party.quests.revealed?(q_id)
  131.     end        
  132.    
  133.     def self.reveal_objective(q_id, *obj_id)
  134.       obj_id.each do|o_id|
  135.         $game_party.quests[q_id].reveal_objective(o_id)
  136.       end
  137.     end
  138.     def self.conceal_objective(q_id, *obj_id)
  139.       obj_id.each do|o_id|
  140.         $game_party.quests[q_id].conceal_objective(o_id)
  141.       end
  142.     end
  143.     def self.complete_objective(q_id, *obj_id)
  144.       obj_id.each do|o_id|
  145.         $game_party.quests[q_id].complete_objective(o_id)
  146.       end
  147.     end
  148.     def self.fail_objective(q_id, *obj_id)
  149.       obj_id.each do|o_id|
  150.         $game_party.quests[q_id].fail_objective(o_id)
  151.       end
  152.     end    
  153.    
  154.     #Utility.objective_complete?(,)
  155.     def self.objective_complete?(q_id, *obj_id)
  156.       $game_party.quests.revealed?(q_id) && $game_party.quests[q_id].objective_status?(:complete, *obj_id)
  157.     end
  158.     #Utility.objective_revealed?(,)
  159.     def self.objective_revealed?(q_id, *obj_id)
  160.       $game_party.quests.revealed?(q_id) && $game_party.quests[q_id].objective_status?(:revealed, *obj_id)
  161.     end
  162.     #Utility.objective_concealed?(,)
  163.     def self.objective_concealed?(q_id, *obj_id)
  164.       $game_party.quests.revealed?(q_id) && $game_party.quests[q_id].objective_status?(:concealed, *obj_id)
  165.     end          
  166.     #Utility.objective_failed?(,)
  167.     def self.objective_failed?(q_id, *obj_id)
  168.       $game_party.quests.revealed?(q_id) && $game_party.quests[q_id].objective_status?(:failed, *obj_id)
  169.     end    
  170.  
  171.     #Utility.complete_quest(,)
  172.     # Completes all objectives for the specified quest
  173.     # Note that objective ID's may not have gaps. They must be numbered starting from 0 without any gaps in between.
  174.     def self.complete_quest(q_id)
  175.       obj_count = QuestData.setup_quest(q_id)[:objectives].compact.length
  176.       for i in 0..obj_count-1
  177.           complete_objective(q_id,i)
  178.       end
  179.     end    
  180.    
  181.     #Utility.reset_quest()
  182.     def self.reset_quest(q_id)
  183.       $game_party.quests.delete_quest(q_id)
  184.     end
  185.   end # Utility
  186.  
  187.   #==============================================================================
  188.   # ■ Quest Journal - Debug Addon - Quest window (left window)
  189.   #------------------------------------------------------------------------------
  190.   #  This window contains the list of all quests
  191.   #==============================================================================
  192.   class Window_Quests < Window_Selectable
  193.     include Quest_Journal
  194.     #--------------------------------------------------------------------------
  195.     # * Class Variable
  196.     #--------------------------------------------------------------------------
  197.     @@last_top_row = 0                      # For saving first line
  198.     @@last_index   = 0                      # For saving cursor position
  199.     @@sel_quest_id = 1                      # The current selected quest id
  200.     @@is_first_update                       # Determines if this window had it's first update called.
  201.     #--------------------------------------------------------------------------
  202.     # * Public Instance Variables
  203.     #--------------------------------------------------------------------------
  204.     attr_reader   :right_window             # Right window
  205.     attr_reader   :sel_quest_id             #  
  206.     #--------------------------------------------------------------------------
  207.     # * Object Initialization
  208.     #--------------------------------------------------------------------------
  209.     def initialize(x, y)
  210.       @@is_first_update = true
  211.       super(x, y, window_width, window_height)
  212.       @sel_quest_id = Utility.quests[0]
  213.       refresh
  214.       self.top_row = @@last_top_row
  215.       select(@@last_index)
  216.       activate
  217.     end
  218.     #--------------------------------------------------------------------------
  219.     # * Get Window Width
  220.     #--------------------------------------------------------------------------
  221.     def window_width
  222.       return 164
  223.     end
  224.     #--------------------------------------------------------------------------
  225.     # * Get Window Height
  226.     #--------------------------------------------------------------------------
  227.     def window_height
  228.       Graphics.height
  229.     end
  230.     #--------------------------------------------------------------------------
  231.     # * Get Number of Items
  232.     #--------------------------------------------------------------------------
  233.     def item_max
  234.       Utility.quests.length || 0
  235.     end
  236.     #--------------------------------------------------------------------------
  237.     # * Frame Update
  238.     #--------------------------------------------------------------------------
  239.     def update      
  240.       super
  241.       if active && Input.trigger?(Utility::COMPLETE_RESET_QUEST_KEY) && !@@is_first_update
  242.         q_id = Utility.quests[index]
  243.         if Utility.quest_complete?(q_id)
  244.           Utility.reset_quest(q_id)
  245.         else
  246.           Utility.complete_quest(q_id)
  247.         end
  248.         Sound.play_ok
  249.         redraw_current_item
  250.         @right_window.refresh
  251.       end
  252.      
  253.       if !Input.press?(:L) then @@is_first_update = false end
  254.  
  255.       return unless @right_window
  256.       @sel_quest_id = Utility.quests[index]
  257.       @right_window.refresh_me
  258.     end
  259.     #--------------------------------------------------------------------------
  260.     # * Refresh
  261.     #--------------------------------------------------------------------------
  262.     def refresh
  263.       create_contents
  264.       draw_all_items
  265.     end
  266.     #--------------------------------------------------------------------------
  267.     # * Draw Item
  268.     #--------------------------------------------------------------------------
  269.     def draw_item(index)
  270.       quest_id = Utility.quests[index]
  271.      
  272.       # quest item color
  273.       if Utility.quest_failed?(quest_id)
  274.         change_color(text_color(Utility::COLORS['failed']))
  275.       elsif Utility.quest_concealed?(quest_id)
  276.         change_color(text_color(Utility::COLORS['concealed']))
  277.       elsif Utility.quest_complete?(quest_id)              
  278.         change_color(text_color(Utility::COLORS['completed']))    
  279.       elsif Utility.quest_revealed?(quest_id)
  280.         change_color(text_color(Utility::COLORS['revealed']))                
  281.       end
  282.  
  283.       text = sprintf("%02d: #{QuestData.setup_quest(quest_id)[:name]} ", quest_id )
  284.       text_rect = item_rect_for_text(index)
  285.       text_rect.x+=24
  286.      
  287.       draw_text(text_rect, text)
  288.       change_color(normal_color)
  289.       draw_icon(QuestData.setup_quest(quest_id)[:icon_index], text_rect.x-24, text_rect.y, true)
  290.     end
  291.     #--------------------------------------------------------------------------
  292.     # * Processing When Cancel Button Is Pressed
  293.     #--------------------------------------------------------------------------
  294.     def process_cancel
  295.       super
  296.       @@last_top_row = top_row
  297.       @@last_index = index
  298.     end
  299.     #--------------------------------------------------------------------------
  300.     # * Set Right Window
  301.     #--------------------------------------------------------------------------
  302.     def right_window=(right_window)
  303.       @right_window = right_window
  304.       update
  305.     end
  306.   end
  307.  
  308.   #==============================================================================
  309.   # ■ Quest Journal - Debug Addon - Objective window (right window)
  310.   #------------------------------------------------------------------------------
  311.   #  This window contains the list of all objectives for the selected quest
  312.   #==============================================================================
  313.   #==============================================================================
  314.   # ** Objective Window
  315.   #------------------------------------------------------------------------------
  316.   #  Displays the objectives for the currently selected quest (if any)
  317.   #==============================================================================
  318.   class Window_Objectives < Window_Selectable
  319.     include Quest_Journal
  320.     #--------------------------------------------------------------------------
  321.     # * Public Instance Variables
  322.     #--------------------------------------------------------------------------
  323.     # None
  324.     #--------------------------------------------------------------------------
  325.     # * Private Instance Variables
  326.     #--------------------------------------------------------------------------    
  327.     # The previously selected quest id (in the left window)
  328.     @previous_quest_id
  329.    
  330.  
  331.     #--------------------------------------------------------------------------
  332.     # * Object Initialization
  333.     #-------------------------------------------------------------------------
  334.     def initialize(x, y, width, left_window)
  335.       @left_window = left_window
  336.       super(x, y, width, fitting_height(10))      
  337.       refresh
  338.     end
  339.     #--------------------------------------------------------------------------
  340.     # * Get Number of Items
  341.     #--------------------------------------------------------------------------
  342.     def item_max
  343.       return QuestData.setup_quest(sel_q_id)[:objectives].length
  344.     end
  345.     #--------------------------------------------------------------------------
  346.     # * Refresh
  347.     #--------------------------------------------------------------------------
  348.     def refresh
  349.       contents.clear
  350.       draw_all_items
  351.     end
  352.     #--------------------------------------------------------------------------
  353.     # * Selected Quest ID
  354.     #--------------------------------------------------------------------------
  355.     def sel_q_id
  356.       return @left_window.sel_quest_id
  357.     end  
  358.     #--------------------------------------------------------------------------
  359.     # * Draw Item
  360.     #--------------------------------------------------------------------------  
  361.     def draw_item(index)    
  362.       if sel_q_id == nil then return end
  363.      
  364.       obj_id = index # store currently selected objective_id in a more meaningful variable name
  365.       item_text = sprintf("Obj. %0d: #{QuestData.setup_quest(sel_q_id)[:objectives][index]}",obj_id)
  366.       id_width = text_size(item_text).width
  367.       status = Utility.objective_complete?(sel_q_id,obj_id) ? "[X]" : "[ ]"    
  368.      
  369.       # objective item color
  370.       if Utility.objective_failed?(sel_q_id,index)
  371.         change_color(text_color(Utility::COLORS['failed']))
  372.       elsif Utility.objective_concealed?(sel_q_id,index)
  373.         change_color(text_color(Utility::COLORS['concealed']))
  374.       elsif Utility.objective_complete?(sel_q_id,index)              
  375.         change_color(text_color(Utility::COLORS['completed']))    
  376.       elsif Utility.objective_revealed?(sel_q_id,index)
  377.         change_color(text_color(Utility::COLORS['revealed']))                
  378.       end
  379.      
  380.       # draw text
  381.       text_rect = item_rect_for_text(index)
  382.       status_rect = item_rect_for_text(index)
  383.       text_rect.width -= 30
  384.       draw_text(text_rect, item_text)      
  385.       # draw status
  386.       status_rect.x+= 5
  387.       draw_text(status_rect, status, 2)    
  388.       change_color(normal_color) # reset text color
  389.     end
  390.     #--------------------------------------------------------------------------
  391.     # * Refresh
  392.     #--------------------------------------------------------------------------
  393.     def refresh_me
  394.       if sel_q_id != @previous_quest_id then refresh end
  395.       @previous_quest_id = sel_q_id
  396.     end
  397.     #--------------------------------------------------------------------------
  398.     # * redraw_current_items (redraws both windows current items)
  399.     #--------------------------------------------------------------------------
  400.     def redraw_current_items
  401.       redraw_current_item
  402.       @left_window.redraw_current_item
  403.     end
  404.     #--------------------------------------------------------------------------
  405.     # * Frame Update
  406.     #--------------------------------------------------------------------------
  407.     def update
  408.       super
  409.      
  410.       if Input.trigger?(:C)
  411.         if Utility.objective_complete?(sel_q_id,index)
  412.           $game_party.quests[sel_q_id].uncomplete_objective(index)
  413.         else
  414.           Utility.complete_objective(sel_q_id,index)
  415.         end
  416.         redraw_current_items
  417.         Sound.play_ok
  418.       end
  419.      
  420.       if active && Input.trigger?(:L)
  421.         if Utility.objective_complete?(sel_q_id,index)
  422.           $game_party.quests[sel_q_id].fail_objective(index)
  423.           #p 'now failed'
  424.         elsif Utility.objective_failed?(sel_q_id,index)
  425.           $game_party.quests[sel_q_id].unfail_objective(index)
  426.           $game_party.quests[sel_q_id].reveal_objective(index)
  427.           #p 'now revealed'
  428.         elsif Utility.objective_revealed?(sel_q_id,index)
  429.           $game_party.quests[sel_q_id].conceal_objective(index)
  430.           #p 'now concealed'
  431.         else # it's ONLY revealed
  432.           $game_party.quests[sel_q_id].complete_objective(index)
  433.           #p 'now completed'
  434.         end
  435.         redraw_current_items
  436.         Sound.play_cursor
  437.       end      
  438.     end
  439.    
  440.   end # end of right window class
  441.  
  442. end # end of module
  443. #==============================================================================
  444. # ■ Quest Journal - Debug Addon - Scene
  445. #------------------------------------------------------------------------------
  446. #  The scene that contains the debug menu
  447. #==============================================================================
  448. class Scene_QJ_Debug < Scene_MenuBase
  449.   #--------------------------------------------------------------------------
  450.   # * Start Processing
  451.   #--------------------------------------------------------------------------
  452.   def start
  453.     super
  454.     create_left_window
  455.     create_right_window
  456.     create_help_window
  457.   end
  458.   #--------------------------------------------------------------------------
  459.   # * Termination Processing
  460.   #--------------------------------------------------------------------------
  461.   def terminate
  462.     super
  463.   end
  464.   #--------------------------------------------------------------------------
  465.   # * Create Left Window
  466.   #--------------------------------------------------------------------------
  467.   def create_left_window
  468.     @left_window = Quest_Journal::Window_Quests.new(0, 0)
  469.     @left_window.set_handler(:ok,     method(:on_left_ok))
  470.     @left_window.set_handler(:cancel, method(:return_scene))
  471.   end
  472.   #--------------------------------------------------------------------------
  473.   # * Create Right Window
  474.   #--------------------------------------------------------------------------
  475.   def create_right_window
  476.     wx = @left_window.width
  477.     ww = Graphics.width - wx
  478.     @right_window = Quest_Journal::Window_Objectives.new(wx, 0, ww, @left_window)
  479.     @right_window.set_handler(:cancel, method(:on_right_cancel))
  480.     @left_window.right_window = @right_window
  481.   end
  482.   #--------------------------------------------------------------------------
  483.   # * Create Help Window
  484.   #--------------------------------------------------------------------------
  485.   def create_help_window
  486.     wx = @right_window.x
  487.     wy = @right_window.height
  488.     ww = @right_window.width
  489.     wh = Graphics.height - wy
  490.     @help_window = Window_Base.new(wx, wy, ww, wh)
  491.     refresh_help_window(:left)
  492.   end
  493.   #--------------------------------------------------------------------------
  494.   # * Left [OK]
  495.   #--------------------------------------------------------------------------
  496.   def on_left_ok
  497.     refresh_help_window(:right)
  498.     @right_window.activate
  499.     @right_window.select(0)
  500.   end
  501.   #--------------------------------------------------------------------------
  502.   # * Right [Cancel]
  503.   #--------------------------------------------------------------------------
  504.   def on_right_cancel
  505.     @left_window.activate
  506.     @right_window.unselect
  507.     refresh_help_window(:left)
  508.   end
  509.   #--------------------------------------------------------------------------
  510.   # * Refresh Help Window
  511.   #--------------------------------------------------------------------------
  512.   def refresh_help_window(window)
  513.     if window == :left
  514.       help_text = "C (Enter) : Select Quest.\n" +
  515.                   "#{Quest_Journal::Utility::COMPLETE_RESET_QUEST_KEY} (Q) : Complete / Reset+Conceal."
  516.     else
  517.       help_text = "C (Enter) : Complete / Reset\n" +
  518.                   "L (Q) : Completed [green]\nFailed [red]\nRevealed [blue]\nConcealed [white]"
  519.     end
  520.     @help_window.contents.clear
  521.     @help_window.draw_text_ex(4, 0, help_text)
  522.   end
  523. end # Scene
  524.  
  525. #==============================================================================
  526. # Overwrite Algebra's Window_QuestList update method so it can call this addon's scene
  527. #==============================================================================
  528. class Window_QuestList < Window_Selectable
  529.   def update
  530.     super
  531.     if Quest_Journal::Utility.enabled? && Quest_Journal::Utility::DEBUG_MENU_KEY != nil && Input.trigger?(Quest_Journal::Utility::DEBUG_MENU_KEY)
  532.       SceneManager.return if !Quest_Journal::Utility::RETURN_TO_QUEST_MENU
  533.       SceneManager.call(Scene_QJ_Debug)
  534.     end
  535.   end
  536. end
  537. #==============================================================================
  538. # Call this addon directly from the worldmap
  539. #==============================================================================
  540. class Scene_Map  
  541. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  542.   # * Update Call Quest Journal
  543.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  544.   def update_call_quest_journal
  545.     if $game_map.interpreter.running?
  546.       @quest_journal_calling = false
  547.     else      
  548.       if Input.trigger?(QuestData::MAP_BUTTON)
  549.         if $game_system.quest_access_disabled || $game_party.quests.list.empty?
  550.           Quest_Journal::Utility.enabled? && Quest_Journal::Utility::SHOW_WHEN_NO_QUESTS ?
  551.             SceneManager.call(Scene_QJ_Debug) : Sound.play_buzzer
  552.         else
  553.           @quest_journal_calling = true
  554.         end
  555.       end  
  556.       if !@quest_journal_calling && Quest_Journal::Utility.enabled? && Quest_Journal::Utility::MAP_KEY != nil && Input.trigger?(Quest_Journal::Utility::MAP_KEY) && $game_system.quest_map_access && !scene_changing?
  557.         SceneManager.call(Scene_QJ_Debug)
  558.       else
  559.         call_quest_journal if @quest_journal_calling && !$game_player.moving?
  560.       end
  561.     end
  562.   end
  563. end
  564. #==============================================================================
  565. #
  566. # ▼ End of File
  567. #
  568. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement