Advertisement
Guest User

Untitled

a guest
Oct 27th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 23.90 KB | None | 0 0
  1. #Basic Quest System v1.2c
  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. #
  18. #     $game_quests[:questid].accepted?     - true if quest is accepted
  19. #     $game_quests[:questid].completed?    - true if quest is completed
  20. #     $game_quests[:questid].turned_in?     - true if quest is turned in
  21. #
  22. # Examples:
  23. #  The obj function can be used in conditional branches to check progress
  24. #   of certain objectives. Example.
  25. #    #Checking if :obj3 of :quest89 is greater than 3:
  26. #     obj(:quest89, :obj3) > 3
  27. #
  28. #~ #----------#
  29. #-- Script by: V.M of D.T
  30. #
  31. #- Questions or comments can be:
  32. #    given by email: sumptuaryspade@live.ca
  33. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  34. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  35. #
  36. #--- Free to use in any project, commercial or non-commercial, with credit given
  37. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  38.  
  39. #Visibility of quest log on map
  40. $questlogvisibility = false
  41. #Maximum # of quests displayed on the quest log overlay
  42. $questlogmaxdisplay = 5
  43. #Quest log position, 1 - top-left, 2 - top-right
  44. QUEST_LOG_POSITION = 2
  45. #Quest log offsets
  46. QUEST_LOG_OFFSET_X = 0
  47. QUEST_LOG_OFFSET_Y = 0
  48.  
  49. # Quest Format and set up!
  50.  
  51. # DETAILS[:quest_id] = {
  52. #   :name => "quest name"     #Quest name
  53. #   :level => value           #Arbitrary value (Optional)
  54. #   :difficulty => "string"   #Arbitrary string (Optional)
  55. #   :auto_complete => true    #Recieve rewards on the spot (Optional)
  56. #   :abandonable => false     #Set's whether quest can be abandoned (Optional)
  57. #  }
  58. # DESCRIPTIONS[:quest_id] = {
  59. #   :qgiver_name => "string"  #Quest giver name (shows in log) (Optional)
  60. #   :location => "string"     #Quest giver location (shows in log) (Optional)
  61. #   :desc => "string"         #Description of quest displayed in log (Optional)
  62. #  }
  63. # OBJECTIVES[:quest_id] = {   #Quest objectives, "string" is name, id is max value
  64. #   :obj_id1 => ["string", id]
  65. #   :obj_id2 => ["string", id],
  66. #   etc...
  67. #  }
  68. # REWARDS[:quest_id] = {
  69. #   :gold => value            #Gold recieved from quest (Optional)
  70. #   :exp => value             #Exp recieved from quest (Optional)
  71. #         #Items recieved from quest, :type is :item, :weapon, or :armor
  72. #   :items => [[:type,id,value], ...]],    (Optional)
  73. #  }
  74.  
  75. module QUEST
  76.   DETAILS= {}
  77.   DESCRIPTIONS = {}
  78.   OBJECTIVES = {}
  79.   REWARDS = {}
  80.  
  81.   #Main Miner Quest 1
  82.   DETAILS[1] = {
  83.     :name => "Rise & Shine",
  84.     :level => 1,
  85.     :difficulty => "Easy",
  86.     :auto_complete => true,
  87.     :abandonable => false}
  88.    
  89.   DESCRIPTIONS[1] = {
  90.     :qgiver_name => "",
  91.     :location => "Dustrock Village",
  92.     :desc => "Another day in Dustrock Village.
  93.    Work, collect your pay, and
  94.    cash in your check." }
  95.   OBJECTIVES[1] = {
  96.     :obj1 => ["Entered M&S Mines",1],
  97.     :obj2 => ["Collect check at the main office in North Dustrock.", 1],
  98.     :obj3 => ["Cash your check at the bank in Central Dusrock.", 1]
  99.     }
  100.   REWARDS[1] = {:gold => 500  }  
  101.    
  102.  
  103.  
  104. end
  105.  
  106. class Game_Quests
  107.   attr_accessor :reset_hash
  108.   def initialize
  109.     @quests = {}
  110.     QUEST::DETAILS.each do |id, quest|
  111.       @quests[id] = Quest.new(id,quest)
  112.     end
  113.     @reset_hash = {}
  114.     @quests.each_value do |quest|
  115.       @reset_hash[quest.id] = {}
  116.       @reset_hash[quest.id][:accepted] = false
  117.       @reset_hash[quest.id][:turnedin] = false
  118.       quest.objectives.each do |id, obj|
  119.         @reset_hash[quest.id][id] = obj
  120.       end
  121.     end
  122.   end
  123.   def [](quest_id)
  124.     return msgbox("No Quest with id " + quest_id.to_s) if @quests[quest_id].nil?
  125.     @quests[quest_id]
  126.   end
  127.   def []=(quest_id, val)
  128.     @quests[quest_id] = val
  129.   end
  130.   def quests
  131.     @quests
  132.   end
  133.   def no_quests?
  134.     @quests.each do |id, quest|
  135.       return false if quest.accepted? && !quest.turned_in
  136.     end
  137.     return true
  138.   end
  139.   def tracking?
  140.     $game_party.tracking
  141.   end
  142.   def track_quest(id)
  143.     return if $game_party.tracking.include?(id)
  144.     $game_party.tracking.push(id)
  145.     if $game_party.tracking.size > $questlogmaxdisplay = 5
  146.       $game_party.tracking.reverse!.pop
  147.       $game_party.tracking.reverse!
  148.     end
  149.   end
  150.   def untrack_quest(id)
  151.     return unless $game_party.tracking.include?(id)
  152.     $game_party.tracking.delete(id)
  153.     $game_party.tracking.compact!
  154.   end
  155. end
  156.  
  157. class Quest
  158.   attr_accessor :name
  159.   attr_accessor :level
  160.   attr_accessor :id
  161.   attr_accessor :desc
  162.   attr_accessor :objectives
  163.   attr_accessor :turned_in
  164.   attr_accessor :difficulty
  165.   attr_accessor :qgiver_name
  166.   attr_accessor :location
  167.   attr_accessor :auto_complete
  168.   attr_accessor :abandonable
  169.   def initialize(id,quest_hash)
  170.     @id = id
  171.     @level = 0
  172.     @difficulty = 0
  173.     @name = "No Quest Name"
  174.     @desc = ""
  175.     @qgiver_name = 0
  176.     @location = 0
  177.     @auto_complete = false
  178.     @abandonable = true
  179.     @need_popup = false
  180.     @name = quest_hash[:name] if quest_hash[:name]
  181.     @level = quest_hash[:level] if quest_hash[:level]
  182.     @difficulty = quest_hash[:difficulty] if quest_hash[:difficulty]
  183.     @auto_complete = quest_hash[:auto_complete] if quest_hash[:auto_complete]
  184.     @abandonable = quest_hash[:abandonable] if !quest_hash[:abandonable].nil?
  185.     @desc = QUEST::DESCRIPTIONS[id][:desc] if QUEST::DESCRIPTIONS[id][:desc]
  186.     @qgiver_name = QUEST::DESCRIPTIONS[id][:qgiver_name] if QUEST::DESCRIPTIONS[id][:qgiver_name]
  187.     @location = QUEST::DESCRIPTIONS[id][:location] if QUEST::DESCRIPTIONS[id][:location]
  188.     @objectives = {}
  189.     if QUEST::OBJECTIVES[id]
  190.       QUEST::OBJECTIVES[id].each do |id, obj|
  191.         @objectives[id] = Objective.new(id, obj)
  192.       end
  193.     else
  194.       msgbox("Quest " + id.to_s + " has no objectives.")
  195.     end
  196.     @reward_gold = 0
  197.     @reward_exp = 0
  198.     @reward_items = []
  199.     begin
  200.       if QUEST::REWARDS[id][:gold]
  201.         @reward_gold = QUEST::REWARDS[id][:gold]
  202.       end
  203.       if QUEST::REWARDS[id][:exp]
  204.         @reward_exp = QUEST::REWARDS[id][:exp]
  205.       end
  206.       if QUEST::REWARDS[id][:items]
  207.         @reward_items = QUEST::REWARDS[id][:items]
  208.       end
  209.     rescue
  210.       msgbox(id.to_s + " has no defined REWARDS. This is not optional.")
  211.     end
  212.   end
  213.   def accept
  214.     reset
  215.     $game_party.quests[id][:accepted] = true
  216.     track_quest
  217.     $game_map.need_refresh = true
  218.     Audio.se_play("Audio/SE/Book2")
  219.   end
  220.   def abandon
  221.     reset
  222.     $game_party.quests[id][:accepted] = false
  223.   end
  224.   def fail
  225.     Audio.me_play("Audio/ME/Gag")
  226.     abandon
  227.   end
  228.   def accepted?
  229.     $game_party.quests[id][:accepted]
  230.   end
  231.   def accepted
  232.     accepted?
  233.   end
  234.   def completed?
  235.     @objectives.each do |id, obj|
  236.       return false if !$game_party.quests[@id][id].completed?
  237.     end
  238.     return true
  239.   end
  240.   def force_done
  241.     $game_party.quests[id][:accepted] = true
  242.     @objectives.each do |id, obj|
  243.       $game_party.quests[@id][id].current = obj.max
  244.     end
  245.     turnin
  246.   end
  247.   def reset
  248.     $game_party.quests[id][:accepted] = false
  249.     @objectives.each do |id, obj|
  250.       $game_party.quests[@id][id].current = 0
  251.     end
  252.     $game_party.quests[id][:turnedin] = false
  253.   end
  254.   def objective(id)
  255.     return Objective.new(["No Objective Found",0]) if @objectives[id].nil?
  256.     $game_party.quests[@id][id]
  257.   end
  258.   def set_obj(id, value)
  259.     objective(id).current = value
  260.     @need_popup = false if !completed?
  261.     popup if completed? && !@need_popup
  262.     turnin if completed? && @auto_complete
  263.     $game_map.need_refresh = true
  264.   end
  265.   def adv_obj(id, value)
  266.     objective(id).current += value
  267.     @need_popup = false if !completed?
  268.     popup if completed? && !@need_popup
  269.     turnin if completed? && @auto_complete
  270.     $game_map.need_refresh = true
  271.   end
  272.   def reward_gold
  273.     @reward_gold
  274.   end
  275.   def reward_exp
  276.     @reward_exp
  277.   end
  278.   def reward_items
  279.     @reward_items
  280.   end
  281.   def turnin
  282.     $game_party.quests[id][:turnedin] = true
  283.     untrack_quest
  284.     $game_map.need_refresh = true
  285.     $game_party.gain_gold(@reward_gold)
  286.     $game_party.members.each do |actor|
  287.       actor.gain_exp(@reward_exp)
  288.     end
  289.     @reward_items.each do |array|
  290.       item = $data_items[array[1]] if array[0] == :item
  291.       item = $data_weapons[array[1]] if array[0] == :weapon
  292.       item = $data_armors[array[1]] if array[0] == :armor
  293.       $game_party.gain_item(item, array[2])
  294.     end
  295.   end
  296.   def track_quest
  297.     $game_quests.track_quest(@id)
  298.   end
  299.   def untrack_quest
  300.     $game_quests.untrack_quest(@id)
  301.   end
  302.   def can_abandon?
  303.     @abandonable
  304.   end
  305.   def popup
  306.     @need_popup = true
  307.     Audio.me_play("Audio/ME/Item")
  308.     if Module.const_defined?(:Popup)
  309.       Popup.add([@name + ' complete!'])
  310.     end
  311.   end
  312.   def turned_in?
  313.     $game_party.quests[id][:turnedin]
  314.   end
  315.   def turned_in
  316.     turned_in?
  317.   end
  318.   def active?
  319.     accepted? && !completed?
  320.   end
  321. end
  322.  
  323. class Objective
  324.   attr_accessor :id
  325.   attr_accessor :name
  326.   attr_accessor :current
  327.   attr_accessor :max
  328.   def initialize(id, obj)
  329.     @name = obj[0]
  330.     @current = 0
  331.     @max = obj[1]
  332.   end
  333.   def completed?
  334.     @current >= @max
  335.   end
  336. end
  337.  
  338. module DataManager
  339.   class << self
  340.     alias quest_cgo load_database
  341.     alias quest_sng setup_new_game
  342.   end
  343.   def self.load_database
  344.     quest_cgo
  345.     $game_quests = Game_Quests.new
  346.   end
  347.   def self.setup_new_game
  348.     $game_quests = Game_Quests.new
  349.     quest_sng
  350.   end
  351. end
  352.  
  353. class Scene_Quest < Scene_MenuBase
  354.   def initialize
  355.     super
  356.     @help_window = Window_Help.new(1)
  357.     @help_window.set_text("Quest Log")
  358.     @list_window = Window_SceneList.new
  359.     @list_window.set_handler(:cancel, method(:list_cancel))
  360.     @list_window.set_handler(:ok, method(:list_ok))
  361.     @list_window.refresh
  362.     @list_window.activate
  363.     @list_window.select(0)
  364.     @detail_window = Window_SceneDetail.new
  365.     @command_window = Window_QuestTrack.new
  366.     @command_window.x = Graphics.width / 2 - @command_window.width / 2
  367.     @command_window.y = Graphics.height / 2 - @command_window.height / 2
  368.     @command_window.set_handler(:track, method(:track))
  369.     @command_window.set_handler(:untrack, method(:untrack))
  370.     @command_window.set_handler(:abandon, method(:abandon))
  371.     @command_window.set_handler(:cancel, method(:command_cancel))
  372.   end
  373.   def update
  374.     super
  375.     @detail_window.quest = @list_window.current_item
  376.   end
  377.   def list_cancel
  378.     SceneManager.return
  379.   end
  380.   def list_ok
  381.     @command_window.quest(@list_window.current_item)
  382.     @command_window.refresh
  383.     @command_window.select(0)
  384.     @command_window.activate
  385.     @command_window.open
  386.   end
  387.   def track
  388.     $game_quests.track_quest(@list_window.current_item.id)
  389.     command_cancel
  390.   end
  391.   def untrack
  392.     $game_quests.untrack_quest(@list_window.current_item.id)
  393.     command_cancel
  394.   end
  395.   def abandon
  396.     @list_window.current_item.abandon
  397.     command_cancel
  398.   end
  399.   def command_cancel
  400.     @command_window.close
  401.     @list_window.refresh
  402.     @list_window.activate
  403.     list_cancel if $game_quests.no_quests?
  404.   end
  405. end
  406.  
  407. class Window_SceneList < Window_ItemList
  408.   def initialize
  409.     super(0,48,Graphics.width/5*2,Graphics.height-48)
  410.   end
  411.   def make_item_list
  412.     @data = []
  413.     $game_quests.quests.each do |id, quest|
  414.       @data.push(quest) if quest.accepted? && !quest.turned_in?
  415.     end
  416.     @data.push(nil) if @data.empty?
  417.   end
  418.   def draw_item(index)
  419.     contents.font.size = 18
  420.     item = @data[index]
  421.     if item
  422.       rect = item_rect(index)
  423.       rect.width -= 4
  424.       if $game_quests.tracking?.include?(item.id)
  425.         text = "*" + item.name
  426.       else
  427.         text = item.name
  428.       end
  429.       draw_text(rect, text)
  430.       draw_text(rect, "Lv" + item.level.to_s,2) if item.level > 0
  431.     end
  432.   end
  433.   def col_max; 1; end
  434.   def current_item
  435.     @data[@index]
  436.   end
  437.   def current_item_enabled?
  438.     true
  439.   end
  440. end
  441.  
  442. class Window_SceneDetail < Window_Base
  443.   def initialize
  444.     super(Graphics.width/5*2,48,Graphics.width-Graphics.width/5*2,Graphics.height-48)
  445.   end
  446.   def quest=(quest)
  447.     return if @quest == quest
  448.     @quest = quest
  449.     refresh
  450.   end
  451.   def refresh
  452.     contents.clear
  453.     return unless @quest
  454.     contents.font.size = 18
  455.     change_color(system_color)
  456.     draw_text(0,0,contents.width,line_height,@quest.qgiver_name) if @quest.qgiver_name != 0
  457.     draw_text(0,0,contents.width,line_height,@quest.location,2) if @quest.location != 0
  458.     change_color(normal_color)
  459.     @quest.qgiver_name != 0 || @quest.location != 0 ? yy = line_height : yy = 0
  460.     draw_text_ex(0,yy,@quest.desc)
  461.     change_color(system_color)
  462.     draw_text(0,line_height*7,contents.width,24,"Objectives:")
  463.     change_color(normal_color)
  464.     yy = line_height * 8
  465.     @quest.objectives.each do |id, obj|
  466.       draw_objective(yy, obj)
  467.       yy += 24
  468.     end
  469.     change_color(system_color)
  470.     draw_text(0,yy,contents.width,line_height,"Rewards:")
  471.     yy += line_height
  472.     if @quest.reward_exp > 0
  473.       draw_text(6,yy,contents.width/2,line_height,"XP: ")
  474.       change_color(normal_color)
  475.       draw_text(36,yy,contents.width/2,line_height,@quest.reward_exp)
  476.       yy += line_height
  477.     end
  478.     if @quest.reward_gold > 0
  479.       change_color(normal_color)
  480.       draw_text(6,yy,contents.width/2,line_height,@quest.reward_gold.to_s)
  481.       cx = text_size(@quest.reward_gold).width
  482.       change_color(system_color)
  483.       draw_text(6+cx,yy,contents.width/2,line_height,Vocab::currency_unit)
  484.     end
  485.     yy += line_height
  486.     change_color(normal_color)
  487.     @quest.reward_items.each do |array|
  488.       item = $data_items[array[1]] if array[0] == :item
  489.       item = $data_weapons[array[1]] if array[0] == :weapon
  490.       item = $data_armors[array[1]] if array[0] == :armor
  491.       draw_item_name(item, 6, yy, true, contents.width)
  492.       yy += line_height
  493.     end
  494.     if @quest.difficulty != 0
  495.       text = "Difficulty: " + @quest.difficulty
  496.       draw_text(0,contents.height-line_height,contents.width,line_height,text,2)
  497.     end
  498.   end
  499.   def draw_objective(yy, obj)
  500.     draw_text(6,yy,contents.width,24,obj.name)
  501.     draw_text(0,yy,contents.width,24,obj.current.to_s+"/"+obj.max.to_s,2)
  502.   end
  503.   def draw_text_ex(x, y, text)
  504.     text = convert_escape_characters(text)
  505.     pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  506.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  507.   end
  508. end
  509.  
  510. class Window_QuestTrack < Window_Command
  511.   def initialize
  512.     super(0,0)
  513.     self.openness = 0
  514.   end
  515.   def quest(quest)
  516.     @quest = quest
  517.   end
  518.   def make_command_list
  519.     return unless @quest
  520.     if !$game_quests.tracking?.include?(@quest.id)
  521.       add_command("Track Quest", :track)
  522.     else
  523.       add_command("Untrack Quest", :untrack)
  524.     end
  525.     add_command("Abandon Quest", :abandon, @quest.can_abandon?)
  526.   end
  527.   def window_height
  528.     fitting_height(2)
  529.   end
  530. end
  531.  
  532. class Window_MenuCommand
  533.   alias quest_aoc add_original_commands
  534.   def add_original_commands
  535.     quest_aoc
  536.     add_command("Quest Log", :quest, !$game_quests.no_quests?)
  537.   end
  538. end
  539.  
  540. class Scene_Menu
  541.   alias quest_ccw create_command_window
  542.   def create_command_window
  543.     quest_ccw
  544.     @command_window.set_handler(:quest,    method(:scene_quest))
  545.   end
  546.   def scene_quest
  547.     SceneManager.call(Scene_Quest)
  548.   end
  549. end
  550.  
  551. class Scene_Map
  552.   alias quest_start start
  553.   alias quest_update update
  554.   def start
  555.     quest_start
  556.     @quest_log = Window_QuestLog.new
  557.     @quest_confirm = Window_QuestConfirm.new
  558.     @quest_confirm.set_handler(:accept, method(:confirm_accept))
  559.     @quest_confirm.set_handler(:decline, method(:confirm_cancel))
  560.     @quest_confirm.set_handler(:cancel, method(:confirm_cancel))
  561.     @quest_turnin = Window_QuestTurnin.new
  562.     @quest_turnin.set_handler(:accept, method(:turnin_accept))
  563.     @quest_turnin.set_handler(:decline, method(:confirm_cancel))
  564.     @quest_turnin.set_handler(:cancel, method(:confirm_cancel))
  565.     @quest_apply = Window_QuestApply.new(@quest_confirm,@quest_turnin)
  566.   end
  567.   def update(*args)
  568.     @quest_log = Window_QuestLog.new if @quest_log.disposed?
  569.     quest_update(*args)
  570.   end
  571.   def show_quest(id, turnin = false)
  572.     @quest_apply.show($game_quests[id],turnin)
  573.   end
  574.   def accepting?
  575.     @quest_confirm.active || @quest_turnin.active
  576.   end
  577.   def confirm_accept
  578.     @quest_apply.accept
  579.     @quest_apply.hide
  580.   end
  581.   def confirm_cancel
  582.     @quest_apply.hide
  583.   end
  584.   def turnin_accept
  585.     @quest_apply.turnin
  586.     @quest_apply.hide
  587.   end
  588.   def update_call_menu
  589.     if $game_system.menu_disabled || $game_map.interpreter.running? || accepting?
  590.       @menu_calling = false
  591.     else
  592.       @menu_calling ||= Input.trigger?(:B)
  593.       call_menu if @menu_calling && !$game_player.moving?
  594.     end
  595.   end
  596. end
  597.  
  598. class Scene_Base
  599.   def accepting?
  600.     false
  601.   end
  602. end
  603.  
  604. class Window_QuestLog < Window_Base
  605.   def initialize
  606.     super(Graphics.width/5*3,0,Graphics.width/5*2,Graphics.height)
  607.     self.x = 0 if QUEST_LOG_POSITION == 1
  608.     self.x += QUEST_LOG_OFFSET_X
  609.     self.y += QUEST_LOG_OFFSET_Y
  610.     self.opacity = 0
  611.     self.contents.font.size = 18
  612.   end
  613.   def update
  614.     super
  615.     return unless Graphics.frame_count % 20 == 0
  616.     self.visible = !$game_quests.no_quests?
  617.     self.visible = $game_quests.tracking?.size > 0
  618.     self.visible = $questlogvisibility
  619.     return unless self.visible
  620.     contents.clear
  621.     change_color(crisis_color)
  622.     draw_text(0,0,contents.width,18,"Quest Log:",1)
  623.     yy = 18;iter = 0
  624.     $game_quests.tracking?.each do |id|
  625.       quest = $game_quests[id]
  626.       next unless quest.accepted? && !quest.turned_in
  627.       change_color(system_color)
  628.       draw_text(6,yy,contents.width-6,18,quest.name)
  629.       change_color(normal_color)
  630.       yy += 18
  631.       quest.objectives.each do |obj_id, obj|
  632.         draw_objective(yy, $game_party.quests[id][obj_id])
  633.         yy += 18
  634.       end
  635.       iter += 1
  636.     end
  637.   end
  638.   def draw_objective(yy, obj)
  639.     draw_text(0,yy,contents.width-24,18,obj.name)
  640.     draw_text(0,yy,contents.width,18,obj.current.to_s+"/"+obj.max.to_s,2)
  641.   end
  642. end
  643.    
  644. class Window_QuestApply < Window_Base
  645.   def initialize(confirm_window, turnin_window)
  646.     super(Graphics.width/8,Graphics.width/8,Graphics.width/5*3,Graphics.height-Graphics.width/8*2)
  647.     self.openness = 0
  648.     @confirm_window = confirm_window
  649.     @turnin_window = turnin_window
  650.     self.contents.font.size = 18
  651.   end
  652.   def refresh
  653.     return unless @quest
  654.     contents.clear
  655.     change_color(system_color)
  656.     yy = 0
  657.     if @quest.qgiver_name != 0
  658.       draw_text(0,0,contents.width/2,line_height,@quest.qgiver_name)
  659.       yy = line_height
  660.     end
  661.     if @quest.location != 0
  662.       draw_text(contents.width/2,0,contents.width/2,line_height,@quest.location,2)
  663.       yy = line_height
  664.     end
  665.     change_color(crisis_color)
  666.     draw_text(0,yy,contents.width,line_height,"Lvl: " + @quest.level.to_s) if @quest.level > 0
  667.     draw_text(0,yy,contents.width,line_height,@quest.name,1)
  668.     draw_text(0,yy,contents.width,line_height,@quest.difficulty,2) if @quest.difficulty != 0
  669.     change_color(normal_color)
  670.     draw_text_ex(0,line_height+yy,@quest.desc)
  671.     change_color(system_color)
  672.     draw_text(0,line_height*8,contents.width,line_height,"Objectives:")
  673.     change_color(normal_color)
  674.     yy = line_height * 9
  675.     @quest.objectives.each do |obj_id, obj|
  676.       draw_objective(yy, $game_party.quests[@quest.id][obj_id])
  677.       yy += line_height
  678.     end
  679.     change_color(system_color)
  680.     draw_text(0,yy,contents.width,line_height,"Rewards:")
  681.     yy += line_height
  682.     if @quest.reward_exp > 0
  683.       draw_text(6,yy,contents.width/2,line_height,"XP: ")
  684.       change_color(normal_color)
  685.       draw_text(36,yy,contents.width/2,line_height,@quest.reward_exp)
  686.       yy += line_height
  687.     end
  688.     if @quest.reward_gold > 0
  689.       change_color(normal_color)
  690.       draw_text(6,yy,contents.width/2,line_height,@quest.reward_gold.to_s)
  691.       cx = text_size(@quest.reward_gold).width
  692.       change_color(system_color)
  693.       draw_text(6+cx,yy,contents.width/2,line_height,Vocab::currency_unit)
  694.     end
  695.     yy += line_height
  696.     change_color(normal_color)
  697.     @quest.reward_items.each do |array|
  698.       item = $data_items[array[1]] if array[0] == :item
  699.       item = $data_weapons[array[1]] if array[0] == :weapon
  700.       item = $data_armors[array[1]] if array[0] == :armor
  701.       draw_item_name(item, 6, yy, true, contents.width)
  702.       yy += line_height
  703.     end
  704.   end
  705.   def draw_text_ex(x, y, text)
  706.     text = convert_escape_characters(text)
  707.     pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  708.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  709.   end
  710.   def line_height
  711.     18
  712.   end
  713.   def draw_objective(yy, obj)
  714.     draw_text(6,yy,contents.width,24,obj.name)
  715.     draw_text(0,yy,contents.width,24,obj.current.to_s+"/"+obj.max.to_s,2)
  716.   end
  717.   def show(quest,turnin)
  718.     @quest = quest
  719.     return if @quest.turned_in
  720.     refresh
  721.     open
  722.     @confirm_window.open if !turnin
  723.     if turnin
  724.       @turnin_window.quest(@quest)
  725.       @turnin_window.open
  726.     end
  727.   end
  728.   def hide
  729.     close
  730.     @confirm_window.close
  731.     @turnin_window.close
  732.   end
  733.   def accept
  734.     @quest.accept
  735.   end
  736.   def turnin
  737.     @quest.turnin
  738.   end
  739. end
  740.  
  741. class Window_QuestConfirm < Window_HorzCommand
  742.   def initialize
  743.     super(Graphics.width/8,Graphics.width/8+Graphics.height-Graphics.width/8*2)
  744.     self.openness = 0
  745.     self.active = false
  746.     refresh
  747.   end
  748.   def window_width
  749.     Graphics.width/5*2
  750.   end
  751.   def window_height
  752.     48
  753.   end
  754.   def make_command_list
  755.     add_command("Accept",:accept)
  756.     add_command("Decline",:decline)
  757.   end
  758.   def item_width
  759.     width / 2 - padding * 2
  760.   end
  761.   def open
  762.     super
  763.     activate
  764.     select(0)
  765.   end
  766. end
  767.  
  768. class Window_QuestTurnin < Window_QuestConfirm
  769.   def quest(quest)
  770.     @quest = quest
  771.     refresh
  772.   end
  773.   def make_command_list
  774.     return unless @quest
  775.     add_command("Complete",:accept,@quest.completed? && !@quest.turned_in)
  776.     add_command("Cancel",:decline)
  777.   end
  778. end
  779.  
  780. class Game_Party
  781.   attr_accessor :quests
  782.   attr_accessor :tracking
  783.   alias quests_init initialize
  784.   def initialize(*args)
  785.     quests_init(*args)
  786.     @quests = $game_quests.reset_hash unless $game_quests.nil?
  787.     @tracking = []
  788.   end
  789. end
  790.  
  791. class Game_Player
  792.   alias quest_update update
  793.   def update
  794.     return if SceneManager.scene.accepting?
  795.     quest_update
  796.   end
  797. end
  798.  
  799. class Game_Event
  800.   def obj(quest, objective)
  801.     $game_quests[quest].objective(objective).current
  802.   end
  803. end
  804.  
  805. class Game_Interpreter
  806.   def accept_quest(quest)
  807.     $game_quests[quest].accept
  808.   end
  809.   def ask_accept(quest)
  810.     return unless SceneManager.scene.is_a?(Scene_Map)
  811.     SceneManager.scene.show_quest(quest)
  812.     Fiber.yield while SceneManager.scene.accepting?
  813.   end
  814.   def abandon_quest(quest)
  815.     $game_quests[quest].abandon
  816.   end
  817.   def fail_quest(quest)
  818.     $game_quests[quest].fail
  819.   end
  820.   def turnin_quest(quest)
  821.     $game_quests[quest].turnin
  822.   end
  823.   def ask_turnin(quest)
  824.     return unless SceneManager.scene.is_a?(Scene_Map)
  825.     SceneManager.scene.show_quest(quest,true)
  826.     Fiber.yield while SceneManager.scene.accepting?
  827.   end
  828.   def adv_obj(quest, objective, value)
  829.     $game_quests[quest].adv_obj(objective, value)
  830.   end
  831.   def set_obj(quest, objective, value)
  832.     $game_quests[quest].set_obj(objective, value)
  833.   end
  834.   def obj(quest, objective)
  835.     $game_quests[quest].objective(objective).current
  836.   end
  837. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement