daily pastebin goal
62%
SHARE
TWEET

Basic Quest System

Vlue Apr 23rd, 2014 (edited) 17,064 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Basic Quest System v1.3f
  2. #----------#
  3. #Features: Quests! What more can you say.
  4. #
  5. #Usage:   Set up your quests and away you go!
  6. #        Script calls:
  7. #         accept_quest(:questid)     - force quest accept
  8. #         ask_accept(:questid)       - open quest acceptance window
  9. #         abandon_quest(:questid)    - force quest abandon
  10. #         turnin_quest(:questid)     - force quest turnin
  11. #         fail_quest(:questid)       - force abandon with ME
  12. #         ask_turnin(:questid)       - open quest complete window
  13. #
  14. #       adv_obj(:questid, :objectiveid, value)   - changes obj by value
  15. #       set_obj(:questid, :objectiveid, value)   - sets obj to value
  16. #       obj(:questid, :objectiveid)              - gets obj value
  17. #       hide_obj(:questid, :objectiveid)         - hides objective
  18. #       show_obj(:questid, :objectiveid)         - shows objective
  19. #
  20. #     $game_quests[:questid].accepted?     - true if quest is accepted
  21. #     $game_quests[:questid].completed?    - true if quest is completed
  22. #     $game_quests[:questid].turned_in?     - true if quest is turned in
  23. #
  24. # Examples:
  25. #  The obj function can be used in conditional branches to check progress
  26. #   of certain objectives. Example.
  27. #    #Checking if :obj3 of :quest89 is greater than 3:
  28. #     obj(:quest89, :obj3) > 3
  29. #
  30. #~ #----------#
  31. #-- Script by: V.M of D.T
  32. #
  33. #- Questions or comments can be:
  34. #    given by email: sumptuaryspade@live.ca
  35. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  36. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  37. #
  38. #--- Free to use in any project, commercial or non-commercial, with credit given
  39. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  40.  
  41. #Visibility of quest log on map
  42. $questlogvisibility = true
  43. #Maximum # of quests displayed on the quest log overlay
  44. $questlogmaxdisplay = 5
  45. #Quest log position, 1 - top-left, 2 - top-right
  46. QUEST_LOG_POSITION = 2
  47. #Quest log offsets
  48. QUEST_LOG_OFFSET_X = 0
  49. QUEST_LOG_OFFSET_Y = 0
  50.  
  51. # Quest Format and set up!
  52.  
  53. # DETAILS[:quest_id] = {
  54. #   :name => "quest name"     #Quest name
  55. #   :level => value           #Arbitrary value (Optional)
  56. #   :difficulty => "string"   #Arbitrary string (Optional)
  57. #   :auto_complete => true    #Recieve rewards on the spot (Optional)
  58. #   :abandonable => false     #Set's whether quest can be abandoned (Optional)
  59. #   :force_accept => true     #ask_accept only allows accepting (Optional)
  60. #   :force_turnin => true     #ask_turnin only allows completing (Optional)
  61. #  }
  62. # DESCRIPTIONS[:quest_id] = {
  63. #   :qgiver_name => "string"  #Quest giver name (shows in log) (Optional)
  64. #   :location => "string"     #Quest giver location (shows in log) (Optional)
  65. #   :desc => "string"         #Description of quest displayed in log (Optional)
  66. #  }
  67. # OBJECTIVES[:quest_id] = {   #Quest objectives, "string" is name, id is max value
  68. #                             #   boolean is hidden objective (true for hidden)
  69. #   :obj_id1 => ["string", id]
  70. #   :obj_id2 => ["string", id, boolean],
  71. #   etc...
  72. #  }
  73. # REWARDS[:quest_id] = {
  74. #   :gold => value            #Gold recieved from quest (Optional)
  75. #   :exp => value             #Exp recieved from quest (Optional)
  76. #         #Items recieved from quest, :type is :item, :weapon, or :armor
  77. #   :scale_exp => value       #Percent value to scale exp based on level vs party
  78. #   :items => [[:type,id,value], ...]],    (Optional)
  79. #  }
  80.  
  81. module QUEST
  82.   DETAILS= {}
  83.   DESCRIPTIONS = {}
  84.   OBJECTIVES = {}
  85.   REWARDS = {}
  86.  
  87.   #Main Quest 1
  88.   DETAILS[:questid001] = {
  89.     :name => "I need water!",
  90.     :level => 1,
  91.     :force_accept => true,
  92.     :force_turnin => true,}
  93.   DESCRIPTIONS[:questid001] = {
  94.     :qgiver_name => "This Lady",
  95.     :location => "This Place",
  96.     :desc => " I'm thirsty, can you get me some water from the merchant?" }
  97.   OBJECTIVES[:questid001] = {
  98.     :obj1 => ["Get a canteen of water",1],
  99.     :obj2 => ["Get another canteen of water",1,true]}
  100.   REWARDS[:questid001] = {
  101. #    :gold => 5,
  102. #    :exp => 10,
  103.     :scale_exp => 5,
  104.     :items => [[:item,1,2]], }  
  105.    
  106.   #Main Quest 2
  107.   DETAILS[:questid002] = {
  108.     :name => "First Steps: Arkineer",
  109.     :level => 2,}
  110.   DESCRIPTIONS[:questid002] = {
  111.     :qgiver_name => "Marshal Avalan",
  112.     :location => "Class Town",
  113.     :desc => " An Arkineer's job is to construct
  114. as much as it is to fight. To do
  115. that, requires materials though.
  116. Head to the Forest Encampment and
  117. see what the situation is." }
  118.   OBJECTIVES[:questid002] = {
  119.     :obj1 => ["Head to the Forest Camp",1] }
  120.   REWARDS[:questid002] = {}
  121.  
  122.     #Main Quest 2
  123.   DETAILS[:questid003] = {
  124.     :name => "First Steps: Arkineer",
  125.     :level => 2,}
  126.   DESCRIPTIONS[:questid003] = {
  127.     :qgiver_name => "Marshal Avalan",
  128.     :location => "Class Town",
  129.     :desc => " An Arkineer's job is to construct
  130. as much as it is to fight. To do
  131. that, requires materials though.
  132. Head to the Forest Encampment and
  133. see what the situation is." }
  134.   OBJECTIVES[:questid003] = {
  135.     :obj1 => ["Head to the Forest Camp",1] }
  136.   REWARDS[:questid003] = {}
  137.  
  138.   #Side Quest
  139.   DETAILS[:sidequest001] = {
  140.     :name => "Fibers for M'Lana",
  141.     :level => 3,}
  142.   DESCRIPTIONS[:sidequest001] = {
  143.     :qgiver_name => "M'Lana Lee",
  144.     :location => "Class Town",
  145.     :desc => " You're not sure what M'Lana
  146. wants with the plant fibres, but at
  147. least she's isn't telling you to
  148. leave anymore. Better do as she
  149. says and collect them from beasts
  150. around the Forest Camp." }
  151.   OBJECTIVES[:sidequest001] = {
  152.     :obj1 => ["Collect 10 plant fibres",10] }
  153.   REWARDS[:sidequest001] = {
  154.     :gold => 20,
  155.     :exp => 25,
  156.     :items => [[:armor,89,1]], }
  157.  
  158. end
  159.  
  160. class Game_Quests
  161.   attr_accessor :reset_hash
  162.   def initialize
  163.     @quests = {}
  164.     QUEST::DETAILS.each do |id, quest|
  165.       @quests[id] = Quest.new(id,quest)
  166.     end
  167.     @reset_hash = {}
  168.     @quests.each_value do |quest|
  169.       @reset_hash[quest.id] = {}
  170.       @reset_hash[quest.id][:accepted] = false
  171.       @reset_hash[quest.id][:turnedin] = false
  172.       quest.objectives.each do |id, obj|
  173.         @reset_hash[quest.id][id] = obj
  174.       end
  175.     end
  176.   end
  177.   def check_quests
  178.     @quests.each do |id, quest|
  179.       if !$game_party.quests[id]
  180.         $game_party.quests[id] = {}
  181.         quest.reset
  182.       end
  183.     end
  184.   end
  185.   def [](quest_id)
  186.     return msgbox("No Quest with id " + quest_id.to_s) if @quests[quest_id].nil?
  187.     @quests[quest_id]
  188.   end
  189.   def []=(quest_id, val)
  190.     @quests[quest_id] = val
  191.   end
  192.   def quests
  193.     @quests
  194.   end
  195.   def no_quests?
  196.     @quests.each do |id, quest|
  197.       return false if quest.accepted? && !quest.turned_in
  198.     end
  199.     return true
  200.   end
  201.   def tracking?
  202.     $game_party.tracking
  203.   end
  204.   def track_quest(id)
  205.     return if $game_party.tracking.include?(id)
  206.     $game_party.tracking.push(id)
  207.     if $game_party.tracking.size > $questlogmaxdisplay = 5
  208.       $game_party.tracking.reverse!.pop
  209.       $game_party.tracking.reverse!
  210.     end
  211.   end
  212.   def untrack_quest(id)
  213.     return unless $game_party.tracking.include?(id)
  214.     $game_party.tracking.delete(id)
  215.     $game_party.tracking.compact!
  216.   end
  217. end
  218.  
  219. class Quest
  220.   attr_accessor :name
  221.   attr_accessor :level
  222.   attr_accessor :id
  223.   attr_accessor :desc
  224.   attr_accessor :objectives
  225.   attr_accessor :turned_in
  226.   attr_accessor :difficulty
  227.   attr_accessor :qgiver_name
  228.   attr_accessor :location
  229.   attr_accessor :auto_complete
  230.   attr_accessor :abandonable
  231.   attr_accessor :force_accept
  232.   attr_accessor :force_turnin
  233.   def initialize(id,quest_hash)
  234.     @id = id
  235.     @level = 0
  236.     @difficulty = 0
  237.     @name = "No Quest Name"
  238.     @desc = ""
  239.     @qgiver_name = 0
  240.     @location = 0
  241.     @auto_complete = false
  242.     @abandonable = true
  243.     @need_popup = false
  244.     @force_turnin = false
  245.     @force_accept = false
  246.     @name = quest_hash[:name] if quest_hash[:name]
  247.     @level = quest_hash[:level] if quest_hash[:level]
  248.     @force_accept = quest_hash[:force_accept] if quest_hash[:force_accept]
  249.     @force_turnin = quest_hash[:force_turnin] if quest_hash[:force_turnin]
  250.     @difficulty = quest_hash[:difficulty] if quest_hash[:difficulty]
  251.     @auto_complete = quest_hash[:auto_complete] if quest_hash[:auto_complete]
  252.     @abandonable = quest_hash[:abandonable] if !quest_hash[:abandonable].nil?
  253.     @desc = QUEST::DESCRIPTIONS[id][:desc] if QUEST::DESCRIPTIONS[id][:desc]
  254.     @qgiver_name = QUEST::DESCRIPTIONS[id][:qgiver_name] if QUEST::DESCRIPTIONS[id][:qgiver_name]
  255.     @location = QUEST::DESCRIPTIONS[id][:location] if QUEST::DESCRIPTIONS[id][:location]
  256.     @objectives = {}
  257.     if QUEST::OBJECTIVES[id]
  258.       QUEST::OBJECTIVES[id].each do |id, obj|
  259.         @objectives[id] = Objective.new(id, obj)
  260.       end
  261.     else
  262.       msgbox("Quest " + id.to_s + " has no objectives.")
  263.     end
  264.     @reward_gold = 0
  265.     @reward_exp = 0
  266.     @scale_exp = 0
  267.     @reward_items = []
  268.     begin
  269.       if QUEST::REWARDS[id][:gold]
  270.         @reward_gold = QUEST::REWARDS[id][:gold]
  271.       end
  272.       if QUEST::REWARDS[id][:exp]
  273.         @reward_exp = QUEST::REWARDS[id][:exp]
  274.         @scale_exp = QUEST::REWARDS[id][:scale_exp] if QUEST::REWARDS[id][:scale_exp]
  275.       end
  276.       if QUEST::REWARDS[id][:items]
  277.         @reward_items = QUEST::REWARDS[id][:items]
  278.       end
  279.     rescue
  280.       msgbox(id.to_s + " has no defined REWARDS. This is not optional.")
  281.     end
  282.   end
  283.   def accept
  284.     reset
  285.     $game_party.quests[id][:accepted] = true
  286.     track_quest
  287.     $game_map.need_refresh = true
  288.     Audio.se_play("Audio/SE/Book2")
  289.   end
  290.   def abandon
  291.     reset
  292.     $game_party.quests[id][:accepted] = false
  293.   end
  294.   def fail
  295.     Audio.me_play("Audio/ME/Gag")
  296.     abandon
  297.   end
  298.   def accepted?
  299.     $game_party.quests[id][:accepted]
  300.   end
  301.   def accepted
  302.     accepted?
  303.   end
  304.   def completed?
  305.     @objectives.each do |id, obj|
  306.       return false if !$game_party.quests[@id][id].completed?
  307.     end
  308.     return true
  309.   end
  310.   def force_done
  311.     $game_party.quests[id][:accepted] = true
  312.     @objectives.each do |id, obj|
  313.       $game_party.quests[@id][id].current = obj.max
  314.     end
  315.     turnin
  316.   end
  317.   def reset
  318.     $game_party.quests[id][:accepted] = false
  319.     @objectives.each do |id, obj|
  320.       $game_party.quests[@id][id] = obj
  321.       $game_party.quests[@id][id].current = 0
  322.     end
  323.     $game_party.quests[id][:turnedin] = false
  324.   end
  325.   def objective(id)
  326.     return Objective.new(id, ["No Objective Found",0]) if @objectives[id].nil?
  327.     $game_party.quests[@id][id]
  328.   end
  329.   def set_obj(id, value)
  330.     objective(id).current = value
  331.     @need_popup = false if !completed?
  332.     popup if completed? && !@need_popup
  333.     turnin if completed? && @auto_complete
  334.     $game_map.need_refresh = true
  335.   end
  336.   def adv_obj(id, value)
  337.     objective(id).current += value
  338.     @need_popup = false if !completed?
  339.     popup if completed? && !@need_popup
  340.     turnin if completed? && @auto_complete
  341.     $game_map.need_refresh = true
  342.   end
  343.   def reward_gold
  344.     @reward_gold
  345.   end
  346.   def reward_exp
  347.     get_mod_exp.to_i
  348.   end
  349.   def reward_items
  350.     @reward_items
  351.   end
  352.   def turnin
  353.     $game_party.quests[id][:turnedin] = true
  354.     untrack_quest
  355.     $game_map.need_refresh = true
  356.     $game_party.gain_gold(@reward_gold)
  357.     $game_party.members.each do |actor|
  358.       actor.gain_exp(@reward_exp)
  359.     end
  360.     @reward_items.each do |array|
  361.       item = $data_items[array[1]] if array[0] == :item
  362.       item = $data_weapons[array[1]] if array[0] == :weapon
  363.       item = $data_armors[array[1]] if array[0] == :armor
  364.       $game_party.gain_item(item, array[2])
  365.     end
  366.   end
  367.   def track_quest
  368.     $game_quests.track_quest(@id)
  369.   end
  370.   def untrack_quest
  371.     $game_quests.untrack_quest(@id)
  372.   end
  373.   def can_abandon?
  374.     @abandonable
  375.   end
  376.   def popup
  377.     @need_popup = true
  378.     Audio.me_play("Audio/ME/Item")
  379.     if Module.const_defined?(:Popup)
  380.       Popup.add([@name + ' complete!'])
  381.     end
  382.   end
  383.   def turned_in?
  384.     $game_party.quests[id][:turnedin]
  385.   end
  386.   def turned_in
  387.     turned_in?
  388.   end
  389.   def active?
  390.     accepted? && !completed?
  391.   end
  392.   def get_mod_exp
  393.     pval = @scale_exp * (@level - $game_party.highest_level).to_f / 100 + 1
  394.     @reward_exp * pval
  395.   end
  396. end
  397.  
  398. class Objective
  399.   attr_accessor :id
  400.   attr_accessor :name
  401.   attr_accessor :current
  402.   attr_accessor :max
  403.   attr_accessor :hidden
  404.   def initialize(id, obj)
  405.     @name = obj[0]
  406.     @current = 0
  407.     @max = obj[1]
  408.     @hidden = obj[2] ? obj[2] : false
  409.   end
  410.   def completed?
  411.     @current >= @max
  412.   end
  413. end
  414.  
  415. module DataManager
  416.   class << self
  417.     alias quest_cgo load_database
  418.     alias quest_sng setup_new_game
  419.   end
  420.   def self.load_database
  421.     quest_cgo
  422.     $game_quests = Game_Quests.new
  423.   end
  424.   def self.setup_new_game
  425.     $game_quests = Game_Quests.new
  426.     quest_sng
  427.   end
  428. end
  429.  
  430. class Scene_Quest < Scene_MenuBase
  431.   def start
  432.     super
  433.     @help_window = Window_Help.new(1)
  434.     @help_window.set_text("Quest Log")
  435.     @list_window = Window_SceneList.new
  436.     @list_window.set_handler(:cancel, method(:list_cancel))
  437.     @list_window.set_handler(:ok, method(:list_ok))
  438.     @list_window.refresh
  439.     @list_window.activate
  440.     @list_window.select(0)
  441.     @detail_window = Window_SceneDetail.new
  442.     @command_window = Window_QuestTrack.new
  443.     @command_window.x = Graphics.width / 2 - @command_window.width / 2
  444.     @command_window.y = Graphics.height / 2 - @command_window.height / 2
  445.     @command_window.set_handler(:track, method(:track))
  446.     @command_window.set_handler(:untrack, method(:untrack))
  447.     @command_window.set_handler(:abandon, method(:abandon))
  448.     @command_window.set_handler(:cancel, method(:command_cancel))
  449.   end
  450.   def update
  451.     super
  452.     @detail_window.quest = @list_window.current_item
  453.   end
  454.   def list_cancel
  455.     SceneManager.return
  456.   end
  457.   def list_ok
  458.     @command_window.quest(@list_window.current_item)
  459.     @command_window.refresh
  460.     @command_window.select(0)
  461.     @command_window.activate
  462.     @command_window.open
  463.   end
  464.   def track
  465.     $game_quests.track_quest(@list_window.current_item.id)
  466.     command_cancel
  467.   end
  468.   def untrack
  469.     $game_quests.untrack_quest(@list_window.current_item.id)
  470.     command_cancel
  471.   end
  472.   def abandon
  473.     @list_window.current_item.abandon
  474.     command_cancel
  475.   end
  476.   def command_cancel
  477.     @command_window.close
  478.     @list_window.refresh
  479.     @list_window.activate
  480.     list_cancel if $game_quests.no_quests?
  481.   end
  482. end
  483.  
  484. class Window_SceneList < Window_Selectable
  485.   def initialize
  486.     super(0,48,Graphics.width/5*2,Graphics.height-48)
  487.     refresh
  488.   end
  489.   def make_item_list
  490.     @data = []
  491.     $game_quests.quests.each do |id, quest|
  492.       @data.push(quest) if quest.accepted? && !quest.turned_in?
  493.     end
  494.     @data.push(nil) if @data.empty?
  495.   end
  496.   def draw_item(index)
  497.     contents.font.size = 18
  498.     item = @data[index]
  499.     if item
  500.       rect = item_rect(index)
  501.       rect.width -= 4
  502.       if $game_quests.tracking?.include?(item.id)
  503.         text = "*" + item.name
  504.       else
  505.         text = item.name
  506.       end
  507.       draw_text(rect, text)
  508.       draw_text(rect, "Lv" + item.level.to_s,2) if item.level > 0
  509.     end
  510.   end
  511.   def col_max; 1; end
  512.   def current_item
  513.     @data[@index]
  514.   end
  515.   def current_item_enabled?
  516.     true
  517.   end
  518.   def refresh
  519.     make_item_list
  520.     create_contents
  521.     draw_all_items
  522.   end
  523.   def item_max
  524.     @data ? @data.size : 0
  525.   end
  526. end
  527.  
  528. class Window_SceneDetail < Window_Base
  529.   def initialize
  530.     super(Graphics.width/5*2,48,Graphics.width-Graphics.width/5*2,Graphics.height-48)
  531.   end
  532.   def quest=(quest)
  533.     return if @quest == quest
  534.     @quest = quest
  535.     refresh
  536.   end
  537.   def refresh
  538.     contents.clear
  539.     return unless @quest
  540.     contents.font.size = 18
  541.     change_color(system_color)
  542.     draw_text(0,0,contents.width,line_height,@quest.qgiver_name) if @quest.qgiver_name != 0
  543.     draw_text(0,0,contents.width,line_height,@quest.location,2) if @quest.location != 0
  544.     change_color(normal_color)
  545.     @quest.qgiver_name != 0 || @quest.location != 0 ? yy = line_height : yy = 0
  546.     draw_text_ex(0,yy,@quest.desc)
  547.     change_color(system_color)
  548.     draw_text(0,line_height*7,contents.width,24,"Objectives:")
  549.     change_color(normal_color)
  550.     yy = line_height * 8
  551.     @quest.objectives.each do |id, obj|
  552.       next if obj.hidden
  553.       draw_objective(yy, obj)
  554.       yy += 24
  555.     end
  556.     change_color(system_color)
  557.     draw_text(0,yy,contents.width,line_height,"Rewards:")
  558.     yy += line_height
  559.     if @quest.reward_exp > 0
  560.       draw_text(6,yy,contents.width/2,line_height,"XP: ")
  561.       change_color(normal_color)
  562.       draw_text(36,yy,contents.width/2,line_height,@quest.reward_exp)
  563.       yy += line_height
  564.     end
  565.     if @quest.reward_gold > 0
  566.       change_color(normal_color)
  567.       draw_text(6,yy,contents.width/2,line_height,@quest.reward_gold.to_s)
  568.       cx = text_size(@quest.reward_gold).width
  569.       change_color(system_color)
  570.       draw_text(6+cx,yy,contents.width/2,line_height,Vocab::currency_unit)
  571.     end
  572.     yy += line_height
  573.     change_color(normal_color)
  574.     @quest.reward_items.each do |array|
  575.       item = $data_items[array[1]] if array[0] == :item
  576.       item = $data_weapons[array[1]] if array[0] == :weapon
  577.       item = $data_armors[array[1]] if array[0] == :armor
  578.       draw_item_name(item, 6, yy, true, contents.width)
  579.       if array[2] > 1
  580.         draw_text(6+text_size(item.name).width+36,yy,48,24,"x"+array[2].to_s)
  581.       end
  582.       yy += line_height
  583.     end
  584.     if @quest.difficulty != 0
  585.       text = "Difficulty: " + @quest.difficulty
  586.       draw_text(0,contents.height-line_height,contents.width,line_height,text,2)
  587.     end
  588.   end
  589.   def draw_objective(yy, obj)
  590.     draw_text(6,yy,contents.width,24,obj.name)
  591.     draw_text(0,yy,contents.width,24,obj.current.to_s+"/"+obj.max.to_s,2)
  592.   end
  593.   def reset_font_settings
  594.     change_color(normal_color)
  595.     contents.font.bold = Font.default_bold
  596.     contents.font.italic = Font.default_italic
  597.   end
  598. end
  599.  
  600. class Window_QuestTrack < Window_Command
  601.   def initialize
  602.     super(0,0)
  603.     self.openness = 0
  604.   end
  605.   def quest(quest)
  606.     @quest = quest
  607.   end
  608.   def make_command_list
  609.     return unless @quest
  610.     if !$game_quests.tracking?.include?(@quest.id)
  611.       add_command("Track Quest", :track)
  612.     else
  613.       add_command("Untrack Quest", :untrack)
  614.     end
  615.     add_command("Abandon Quest", :abandon, @quest.can_abandon?)
  616.   end
  617.   def window_height
  618.     fitting_height(2)
  619.   end
  620. end
  621.  
  622. class Window_MenuCommand
  623.   alias quest_aoc add_original_commands
  624.   def add_original_commands
  625.     quest_aoc
  626.     add_command("Quest Log", :quest, !$game_quests.no_quests?)
  627.   end
  628. end
  629.  
  630. class Scene_Menu
  631.   alias quest_ccw create_command_window
  632.   def create_command_window
  633.     quest_ccw
  634.     @command_window.set_handler(:quest,    method(:scene_quest))
  635.   end
  636.   def scene_quest
  637.     SceneManager.call(Scene_Quest)
  638.   end
  639. end
  640.  
  641. class Scene_Map
  642.   alias quest_start start
  643.   alias quest_update update
  644.   def start
  645.     quest_start
  646.     @quest_log = Window_QuestLog.new
  647.     @quest_confirm = Window_QuestConfirm.new
  648.     @quest_confirm.set_handler(:accept, method(:confirm_accept))
  649.     @quest_confirm.set_handler(:decline, method(:confirm_cancel))
  650.     @quest_confirm.set_handler(:cancel, method(:confirm_cancel))
  651.     @quest_turnin = Window_QuestTurnin.new
  652.     @quest_turnin.set_handler(:accept, method(:turnin_accept))
  653.     @quest_turnin.set_handler(:decline, method(:confirm_cancel))
  654.     @quest_turnin.set_handler(:cancel, method(:confirm_cancel))
  655.     @quest_apply = Window_QuestApply.new(@quest_confirm,@quest_turnin)
  656.   end
  657.   def update(*args)
  658.     @quest_log = Window_QuestLog.new if @quest_log.disposed?
  659.     quest_update(*args)
  660.   end
  661.   def show_quest(id, turnin = false)
  662.     @quest_apply.show($game_quests[id],turnin)
  663.   end
  664.   def accepting?
  665.     @quest_confirm.active || @quest_turnin.active
  666.   end
  667.   def confirm_accept
  668.     @quest_apply.accept
  669.     @quest_apply.hide
  670.   end
  671.   def confirm_cancel
  672.     @quest_apply.hide
  673.   end
  674.   def turnin_accept
  675.     @quest_apply.turnin
  676.     @quest_apply.hide
  677.   end
  678.   def update_call_menu
  679.     if $game_system.menu_disabled || $game_map.interpreter.running? || accepting?
  680.       @menu_calling = false
  681.     else
  682.       @menu_calling ||= Input.trigger?(:B)
  683.       call_menu if @menu_calling && !$game_player.moving?
  684.     end
  685.   end
  686. end
  687.  
  688. class Scene_Base
  689.   def accepting?
  690.     false
  691.   end
  692. end
  693.  
  694. class Window_QuestLog < Window_Base
  695.   def initialize
  696.     super(Graphics.width/5*3,0,Graphics.width/5*2,Graphics.height)
  697.     self.x = 0 if QUEST_LOG_POSITION == 1
  698.     self.x += QUEST_LOG_OFFSET_X
  699.     self.y += QUEST_LOG_OFFSET_Y
  700.     self.opacity = 0
  701.     self.contents.font.size = 18
  702.   end
  703.   def update
  704.     super
  705.     return unless Graphics.frame_count % 20 == 0
  706.     self.visible = $questlogvisibility
  707.     return unless self.visible
  708.     self.visible = !$game_quests.no_quests?
  709.     self.visible = $game_quests.tracking?.size > 0
  710.     return unless self.visible
  711.     contents.clear
  712.     change_color(crisis_color)
  713.     draw_text(0,0,contents.width,18,"Quest Log:",1)
  714.     yy = 18;iter = 0
  715.     $game_quests.tracking?.each do |id|
  716.       quest = $game_quests[id]
  717.       next unless quest.accepted? && !quest.turned_in
  718.       change_color(system_color)
  719.       draw_text(6,yy,contents.width-6,18,quest.name)
  720.       change_color(normal_color)
  721.       yy += 18
  722.       quest.objectives.each do |obj_id, obj|
  723.         next if obj.hidden
  724.         draw_objective(yy, $game_party.quests[id][obj_id])
  725.         yy += 18
  726.       end
  727.       iter += 1
  728.     end
  729.   end
  730.   def draw_objective(yy, obj)
  731.     draw_text(0,yy,contents.width-24,18,obj.name)
  732.     draw_text(0,yy,contents.width,18,obj.current.to_s+"/"+obj.max.to_s,2)
  733.   end
  734. end
  735.    
  736. class Window_QuestApply < Window_Base
  737.   def initialize(confirm_window, turnin_window)
  738.     super(Graphics.width/8,Graphics.width/8,Graphics.width/5*3,Graphics.height-Graphics.width/8*2)
  739.     self.openness = 0
  740.     @confirm_window = confirm_window
  741.     @turnin_window = turnin_window
  742.     self.contents.font.size = 18
  743.   end
  744.   def refresh
  745.     return unless @quest
  746.     contents.clear
  747.     change_color(system_color)
  748.     yy = 0
  749.     if @quest.qgiver_name != 0
  750.       draw_text(0,0,contents.width/2,line_height,@quest.qgiver_name)
  751.       yy = line_height
  752.     end
  753.     if @quest.location != 0
  754.       draw_text(contents.width/2,0,contents.width/2,line_height,@quest.location,2)
  755.       yy = line_height
  756.     end
  757.     change_color(crisis_color)
  758.     draw_text(0,yy,contents.width,line_height,"Lvl: " + @quest.level.to_s) if @quest.level > 0
  759.     draw_text(0,yy,contents.width,line_height,@quest.name,1)
  760.     draw_text(0,yy,contents.width,line_height,@quest.difficulty,2) if @quest.difficulty != 0
  761.     change_color(normal_color)
  762.     draw_text_ex(0,line_height+yy,@quest.desc)
  763.     change_color(system_color)
  764.     draw_text(0,line_height*8,contents.width,line_height,"Objectives:")
  765.     change_color(normal_color)
  766.     yy = line_height * 9
  767.     @quest.objectives.each do |obj_id, obj|
  768.       next if obj.hidden
  769.       draw_objective(yy, $game_party.quests[@quest.id][obj_id])
  770.       yy += line_height
  771.     end
  772.     change_color(system_color)
  773.     draw_text(0,yy,contents.width,line_height,"Rewards:")
  774.     yy += line_height
  775.     if @quest.reward_exp > 0
  776.       draw_text(6,yy,contents.width/2,line_height,"XP: ")
  777.       change_color(normal_color)
  778.       draw_text(36,yy,contents.width/2,line_height,@quest.reward_exp)
  779.       yy += line_height
  780.     end
  781.     if @quest.reward_gold > 0
  782.       change_color(normal_color)
  783.       draw_text(6,yy,contents.width/2,line_height,@quest.reward_gold.to_s)
  784.       cx = text_size(@quest.reward_gold).width
  785.       change_color(system_color)
  786.       draw_text(6+cx,yy,contents.width/2,line_height,Vocab::currency_unit)
  787.     end
  788.     yy += line_height
  789.     change_color(normal_color)
  790.     @quest.reward_items.each do |array|
  791.       item = $data_items[array[1]] if array[0] == :item
  792.       item = $data_weapons[array[1]] if array[0] == :weapon
  793.       item = $data_armors[array[1]] if array[0] == :armor
  794.       draw_item_name(item, 6, yy, true, contents.width)
  795.       if array[2] > 1
  796.         draw_text(6+text_size(item.name).width+36,yy,48,24,"x"+array[2].to_s)
  797.       end
  798.       yy += line_height
  799.     end
  800.   end
  801.   def reset_font_settings
  802.     change_color(normal_color)
  803.     contents.font.bold = Font.default_bold
  804.     contents.font.italic = Font.default_italic
  805.   end
  806.   def line_height
  807.     18
  808.   end
  809.   def draw_objective(yy, obj)
  810.     draw_text(6,yy,contents.width,24,obj.name)
  811.     draw_text(0,yy,contents.width,24,obj.current.to_s+"/"+obj.max.to_s,2)
  812.   end
  813.   def show(quest,turnin)
  814.     @quest = quest
  815.     return if @quest.turned_in
  816.     refresh
  817.     open
  818.     @confirm_window.quest(@quest)
  819.     @confirm_window.open if !turnin
  820.     if turnin
  821.       @turnin_window.quest(@quest)
  822.       @turnin_window.open
  823.     end
  824.   end
  825.   def hide
  826.     close
  827.     @confirm_window.close
  828.     @turnin_window.close
  829.   end
  830.   def accept
  831.     @quest.accept
  832.   end
  833.   def turnin
  834.     @quest.turnin
  835.   end
  836. end
  837.  
  838. class Window_QuestConfirm < Window_HorzCommand
  839.   def initialize
  840.     super(Graphics.width/8,Graphics.width/8+Graphics.height-Graphics.width/8*2)
  841.     self.openness = 0
  842.     self.active = false
  843.     @enabled = true
  844.     refresh
  845.   end
  846.   def window_width
  847.     Graphics.width/5*2
  848.   end
  849.   def window_height
  850.     48
  851.   end
  852.   def make_command_list
  853.     add_command("Accept",:accept)
  854.     add_command("Decline",:decline, @enabled)
  855.   end
  856.   def item_width
  857.     width / 2 - padding * 2
  858.   end
  859.   def open
  860.     super
  861.     activate
  862.     select(0)
  863.   end
  864.   def quest(quest)
  865.     @quest = quest
  866.     @enabled = !@quest.force_accept
  867.     refresh
  868.   end
  869.   def cancel_enabled?
  870.     super && @enabled
  871.   end
  872. end
  873.  
  874. class Window_QuestTurnin < Window_QuestConfirm
  875.   def quest(quest)
  876.     @quest = quest
  877.     @enabled = true
  878.     @enabled = !@quest.completed? if @quest.force_turnin
  879.     refresh
  880.   end
  881.   def make_command_list
  882.     return unless @quest
  883.     add_command("Complete",:accept,@quest.completed? && !@quest.turned_in)
  884.     add_command("Cancel",:decline, @enabled)
  885.   end
  886. end
  887.  
  888. class Game_Party
  889.   attr_accessor :quests
  890.   attr_accessor :tracking
  891.   alias quests_init initialize
  892.   def initialize(*args)
  893.     quests_init(*args)
  894.     @quests = $game_quests.reset_hash unless $game_quests.nil?
  895.     @tracking = []
  896.   end
  897. end
  898.  
  899. class Game_Player
  900.   alias quest_update update
  901.   def update
  902.     return if SceneManager.scene.accepting?
  903.     quest_update
  904.   end
  905. end
  906.  
  907. class Game_Event
  908.   def obj(quest, objective)
  909.     $game_quests[quest].objective(objective).current
  910.   end
  911. end
  912.  
  913. class Game_Interpreter
  914.   def accept_quest(quest)
  915.     $game_quests[quest].accept
  916.   end
  917.   def ask_accept(quest)
  918.     return unless SceneManager.scene.is_a?(Scene_Map)
  919.     SceneManager.scene.show_quest(quest)
  920.     Fiber.yield while SceneManager.scene.accepting?
  921.   end
  922.   def abandon_quest(quest)
  923.     $game_quests[quest].abandon
  924.   end
  925.   def fail_quest(quest)
  926.     $game_quests[quest].fail
  927.   end
  928.   def turnin_quest(quest)
  929.     $game_quests[quest].turnin
  930.   end
  931.   def ask_turnin(quest)
  932.     return unless SceneManager.scene.is_a?(Scene_Map)
  933.     SceneManager.scene.show_quest(quest,true)
  934.     Fiber.yield while SceneManager.scene.accepting?
  935.   end
  936.   def adv_obj(quest, objective, value)
  937.     $game_quests[quest].adv_obj(objective, value)
  938.   end
  939.   def set_obj(quest, objective, value)
  940.     $game_quests[quest].set_obj(objective, value)
  941.   end
  942.   def obj(quest, objective)
  943.     $game_quests[quest].objective(objective).current
  944.   end
  945.   def hide_obj(quest, objective)
  946.     $game_quests[quest].objective(objective).hidden = true
  947.   end
  948.   def show_obj(quest, objective)
  949.     $game_quests[quest].objective(objective).hidden = false
  950.   end
  951. end
  952.  
  953. module DataManager
  954.   class << self
  955.     alias quest_load_game load_game
  956.   end
  957.   def self.load_game(index)
  958.     quest_load_game(index)
  959.     $game_quests.check_quests
  960.   end
  961. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top