Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.17 KB | None | 0 0
  1. #Basic Quest System v1.2a
  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. # posted on the thread for the script
  33. # given by email: sumptuaryspade@live.ca
  34. # provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  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 = true
  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 Quest 1
  82. DETAILS[:questid001] = {
  83. :name => "[*] Against Thieves",
  84. :level => 1,
  85. :abandonable => false
  86. }
  87. DESCRIPTIONS[:questid001] = {
  88. :qgiver_name => "Storyline",
  89. :location => "Rann, City of Nature",
  90. :desc => " Follow the nearby path
  91. northwest to the city of Rann,
  92. speak with the Inn Keeper." }
  93. OBJECTIVES[:questid001] = {
  94. :obj1 => ["Speak with the Inn Keeper",1], }
  95. REWARDS[:questid001] = {
  96. :gold => 50,
  97. :exp => 0,
  98. :items => [[:item,1,2]], }
  99.  
  100. #Main Quest 2
  101. DETAILS[:sidequest001] = {
  102. :name => "Teddy in Trouble",
  103. :level => 1,}
  104. DESCRIPTIONS[:sidequestid001] = {
  105. :qgiver_name => "Jatessa",
  106. :location => "Rann, City of Nature",
  107. :desc => " Jatessa misplaced her stuffed
  108. teddybear somewhere in the Grand
  109. Greens Forest south of Rann." }
  110. OBJECTIVES[:sidequestid001] = {
  111. :obj1 => ["Find Jatessa's Teddybear",1], }
  112. REWARDS[:sidequestid001] = {
  113. :gold => 50,
  114. :exp => 0, }
  115.  
  116. DETAILS[:questid102] = {
  117. :name => "First Steps: Arkineer",
  118. :level => 2,}
  119. DESCRIPTIONS[:questid102] = {
  120. :qgiver_name => "Marshal Avalan",
  121. :location => "Class Town",
  122. :desc => " An Arkineer's job is to construct
  123. as much as it is to fight. To do
  124. that, requires materials though.
  125. Head to the Forest Encampment and
  126. see what the situation is." }
  127. OBJECTIVES[:questid102] = {
  128. :obj1 => ["Head to the Forest Camp",1] }
  129. REWARDS[:questid102] = {}
  130.  
  131. #Side Quest
  132. DETAILS[:sidequest101] = {
  133. :name => "Fibers for M'Lana",
  134. :level => 3,}
  135. DESCRIPTIONS[:sidequest101] = {
  136. :qgiver_name => "M'Lana Lee",
  137. :location => "Class Town",
  138. :desc => " You're not sure what M'Lana
  139. wants with the plant fibres, but at
  140. least she's isn't telling you to
  141. leave anymore. Better do as she
  142. says and collect them from beasts
  143. around the Forest Camp." }
  144. OBJECTIVES[:sidequest101] = {
  145. :obj1 => ["Collect 10 plant fibres",10] }
  146. REWARDS[:sidequest101] = {
  147. :gold => 20,
  148. :exp => 25,
  149. :items => [[:armor,89,1]], }
  150.  
  151. end
  152.  
  153. class Game_Quests
  154. attr_accessor :reset_hash
  155. def initialize
  156. @quests = {}
  157. QUEST::DETAILS.each do |id, quest|
  158. @quests[id] = Quest.new(id,quest)
  159. end
  160. @reset_hash = {}
  161. @quests.each_value do |quest|
  162. @reset_hash[quest.id] = {}
  163. @reset_hash[quest.id][:accepted] = false
  164. @reset_hash[quest.id][:turnedin] = false
  165. quest.objectives.each do |id, obj|
  166. @reset_hash[quest.id][id] = obj
  167. end
  168. end
  169. end
  170. def [](quest_id)
  171. return msgbox("No Quest with id " + quest_id.to_s) if @quests[quest_id].nil?
  172. @quests[quest_id]
  173. end
  174. def []=(quest_id, val)
  175. @quests[quest_id] = val
  176. end
  177. def quests
  178. @quests
  179. end
  180. def no_quests?
  181. @quests.each do |id, quest|
  182. return false if quest.accepted? && !quest.turned_in
  183. end
  184. return true
  185. end
  186. def tracking?
  187. $game_party.tracking
  188. end
  189. def track_quest(id)
  190. return if $game_party.tracking.include?(id)
  191. $game_party.tracking.push(id)
  192. if $game_party.tracking.size > $questlogmaxdisplay = 5
  193. $game_party.tracking.reverse!.pop
  194. $game_party.tracking.reverse!
  195. end
  196. end
  197. def untrack_quest(id)
  198. return unless $game_party.tracking.include?(id)
  199. $game_party.tracking.delete(id)
  200. $game_party.tracking.compact!
  201. end
  202. end
  203.  
  204. class Quest
  205. attr_accessor :name
  206. attr_accessor :level
  207. attr_accessor :id
  208. attr_accessor :desc
  209. attr_accessor :objectives
  210. attr_accessor :turned_in
  211. attr_accessor :difficulty
  212. attr_accessor :qgiver_name
  213. attr_accessor :location
  214. attr_accessor :auto_complete
  215. attr_accessor :abandonable
  216. def initialize(id,quest_hash)
  217. @id = id
  218. @level = 0
  219. @difficulty = 0
  220. @name = "No Quest Name"
  221. @desc = ""
  222. @qgiver_name = 0
  223. @location = 0
  224. @auto_complete = false
  225. @abandonable = true
  226. @need_popup = false
  227. @name = quest_hash[:name] if quest_hash[:name]
  228. @level = quest_hash[:level] if quest_hash[:level]
  229. @difficulty = quest_hash[:difficulty] if quest_hash[:difficulty]
  230. @auto_complete = quest_hash[:auto_complete] if quest_hash[:auto_complete]
  231. @abandonable = quest_hash[:abandonable] if !quest_hash[:abandonable].nil?
  232. @desc = QUEST::DESCRIPTIONS[id][:desc] if QUEST::DESCRIPTIONS[id][:desc]
  233. @qgiver_name = QUEST::DESCRIPTIONS[id][:qgiver_name] if QUEST::DESCRIPTIONS[id][:qgiver_name]
  234. @location = QUEST::DESCRIPTIONS[id][:location] if QUEST::DESCRIPTIONS[id][:location]
  235. @objectives = {}
  236. if QUEST::OBJECTIVES[id]
  237. QUEST::OBJECTIVES[id].each do |id, obj|
  238. @objectives[id] = Objective.new(id, obj)
  239. end
  240. else
  241. msgbox("Quest " + id.to_s + " has no objectives.")
  242. end
  243. @reward_gold = 0
  244. @reward_exp = 0
  245. @reward_items = []
  246. begin
  247. if QUEST::REWARDS[id][:gold]
  248. @reward_gold = QUEST::REWARDS[id][:gold]
  249. end
  250. if QUEST::REWARDS[id][:exp]
  251. @reward_exp = QUEST::REWARDS[id][:exp]
  252. end
  253. if QUEST::REWARDS[id][:items]
  254. @reward_items = QUEST::REWARDS[id][:items]
  255. end
  256. rescue
  257. msgbox(id.to_s + " has no defined REWARDS. This is not optional.")
  258. end
  259. end
  260. def accept
  261. reset
  262. $game_party.quests[id][:accepted] = true
  263. track_quest
  264. $game_map.need_refresh = true
  265. # Audio.se_play("Audio/SE/Book2")
  266. end
  267. def abandon
  268. reset
  269. $game_party.quests[id][:accepted] = false
  270. end
  271. def fail
  272. # Audio.me_play("Audio/ME/Gag")
  273. abandon
  274. end
  275. def accepted?
  276. $game_party.quests[id][:accepted]
  277. end
  278. def accepted
  279. accepted?
  280. end
  281. def completed?
  282. @objectives.each do |id, obj|
  283. return false if !$game_party.quests[@id][id].completed?
  284. end
  285. return true
  286. end
  287. def force_done
  288. $game_party.quests[id][:accepted] = true
  289. @objectives.each do |id, obj|
  290. $game_party.quests[@id][id].current = obj.max
  291. end
  292. turnin
  293. end
  294. def reset
  295. @objectives.each do |id, obj|
  296. $game_party.quests[@id][id] = obj
  297. end
  298. end
  299. def objective(id)
  300. return Objective.new(["No Objective Found",0]) if @objectives[id].nil?
  301. $game_party.quests[@id][id]
  302. end
  303. def set_obj(id, value)
  304. objective(id).current = value
  305. @need_popup = false if !completed?
  306. popup if completed? && !@need_popup
  307. turnin if completed? && @auto_complete
  308. $game_map.need_refresh = true
  309. end
  310. def adv_obj(id, value)
  311. objective(id).current += value
  312. @need_popup = false if !completed?
  313. popup if completed? && !@need_popup
  314. turnin if completed? && @auto_complete
  315. $game_map.need_refresh = true
  316. end
  317. def reward_gold
  318. @reward_gold
  319. end
  320. def reward_exp
  321. @reward_exp
  322. end
  323. def reward_items
  324. @reward_items
  325. end
  326. def turnin
  327. $game_party.quests[id][:turnedin] = true
  328. untrack_quest
  329. $game_map.need_refresh = true
  330. $game_party.gain_gold(@reward_gold)
  331. $game_party.members.each do |actor|
  332. actor.gain_exp(@reward_exp)
  333. end
  334. @reward_items.each do |array|
  335. item = $data_items[array[1]] if array[0] == :item
  336. item = $data_weapons[array[1]] if array[0] == :weapon
  337. item = $data_armors[array[1]] if array[0] == :armor
  338. $game_party.gain_item(item, array[2])
  339. end
  340. end
  341. def track_quest
  342. $game_quests.track_quest(@id)
  343. end
  344. def untrack_quest
  345. $game_quests.untrack_quest(@id)
  346. end
  347. def can_abandon?
  348. @abandonable
  349. end
  350. def popup
  351. @need_popup = true
  352. Audio.me_play("Audio/ME/Item")
  353. if Module.const_defined?(:Popup)
  354. Popup.add([@name + ' complete!'])
  355. end
  356. end
  357. def turned_in?
  358. $game_party.quests[id][:turnedin]
  359. end
  360. def turned_in
  361. turned_in?
  362. end
  363. def active?
  364. accepted? && !completed?
  365. end
  366. end
  367.  
  368. class Objective
  369. attr_accessor :id
  370. attr_accessor :name
  371. attr_accessor :current
  372. attr_accessor :max
  373. def initialize(id, obj)
  374. @name = obj[0]
  375. @current = 0
  376. @max = obj[1]
  377. end
  378. def completed?
  379. @current >= @max
  380. end
  381. end
  382.  
  383. module DataManager
  384. class << self
  385. alias quest_cgo load_database
  386. alias quest_sng setup_new_game
  387. end
  388. def self.load_database
  389. quest_cgo
  390. $game_quests = Game_Quests.new
  391. end
  392. def self.setup_new_game
  393. $game_quests = Game_Quests.new
  394. quest_sng
  395. end
  396. end
  397.  
  398. class Scene_Quest < Scene_MenuBase
  399. def initialize
  400. super
  401. @help_window = Window_Help.new(1)
  402. @help_window.set_text("Quest Log")
  403. @list_window = Window_SceneList.new
  404. @list_window.set_handler(:cancel, method(:list_cancel))
  405. @list_window.set_handler(:ok, method(:list_ok))
  406. @list_window.refresh
  407. @list_window.activate
  408. @list_window.select(0)
  409. @detail_window = Window_SceneDetail.new
  410. @command_window = Window_QuestTrack.new
  411. @command_window.x = Graphics.width / 2 - @command_window.width / 2
  412. @command_window.y = Graphics.height / 2 - @command_window.height / 2
  413. @command_window.set_handler(:track, method(:track))
  414. @command_window.set_handler(:untrack, method(:untrack))
  415. @command_window.set_handler(:abandon, method(:abandon))
  416. @command_window.set_handler(:cancel, method(:command_cancel))
  417. end
  418. def update
  419. super
  420. @detail_window.quest = @list_window.current_item
  421. end
  422. def list_cancel
  423. SceneManager.return
  424. end
  425. def list_ok
  426. @command_window.quest(@list_window.current_item)
  427. @command_window.refresh
  428. @command_window.select(0)
  429. @command_window.activate
  430. @command_window.open
  431. end
  432. def track
  433. $game_quests.track_quest(@list_window.current_item.id)
  434. command_cancel
  435. end
  436. def untrack
  437. $game_quests.untrack_quest(@list_window.current_item.id)
  438. command_cancel
  439. end
  440. def abandon
  441. @list_window.current_item.abandon
  442. command_cancel
  443. end
  444. def command_cancel
  445. @command_window.close
  446. @list_window.refresh
  447. @list_window.activate
  448. list_cancel if $game_quests.no_quests?
  449. end
  450. end
  451.  
  452. class Window_SceneList < Window_ItemList
  453. def initialize
  454. super(0,48,Graphics.width/5*2,Graphics.height-48)
  455. end
  456. def make_item_list
  457. @data = []
  458. $game_quests.quests.each do |id, quest|
  459. @data.push(quest) if quest.accepted? && !quest.turned_in?
  460. end
  461. @data.push(nil) if @data.empty?
  462. end
  463. def draw_item(index)
  464. contents.font.size = 18
  465. item = @data[index]
  466. if item
  467. rect = item_rect(index)
  468. rect.width -= 4
  469. if $game_quests.tracking?.include?(item.id)
  470. text = "*" + item.name
  471. else
  472. text = item.name
  473. end
  474. draw_text(rect, text)
  475. draw_text(rect, "Lv" + item.level.to_s,2) if item.level > 0
  476. end
  477. end
  478. def col_max; 1; end
  479. def current_item
  480. @data[@index]
  481. end
  482. def current_item_enabled?
  483. true
  484. end
  485. end
  486.  
  487. class Window_SceneDetail < Window_Base
  488. def initialize
  489. super(Graphics.width/5*2,48,Graphics.width-Graphics.width/5*2,Graphics.height-48)
  490. end
  491. def quest=(quest)
  492. return if @quest == quest
  493. @quest = quest
  494. refresh
  495. end
  496. def refresh
  497. contents.clear
  498. return unless @quest
  499. contents.font.size = 18
  500. change_color(system_color)
  501. draw_text(0,0,contents.width,line_height,@quest.qgiver_name) if @quest.qgiver_name != 0
  502. draw_text(0,0,contents.width,line_height,@quest.location,2) if @quest.location != 0
  503. change_color(normal_color)
  504. @quest.qgiver_name != 0 || @quest.location != 0 ? yy = line_height : yy = 0
  505. draw_text_ex(0,yy,@quest.desc)
  506. change_color(system_color)
  507. draw_text(0,line_height*7,contents.width,24,"Objectives:")
  508. change_color(normal_color)
  509. yy = line_height * 8
  510. @quest.objectives.each do |id, obj|
  511. draw_objective(yy, obj)
  512. yy += 24
  513. end
  514. change_color(system_color)
  515. draw_text(0,yy,contents.width,line_height,"Rewards:")
  516. yy += line_height
  517. if @quest.reward_exp > 0
  518. draw_text(6,yy,contents.width/2,line_height,"XP: ")
  519. change_color(normal_color)
  520. draw_text(36,yy,contents.width/2,line_height,@quest.reward_exp)
  521. yy += line_height
  522. end
  523. if @quest.reward_gold > 0
  524. change_color(normal_color)
  525. draw_text(6,yy,contents.width/2,line_height,@quest.reward_gold.to_s)
  526. cx = text_size(@quest.reward_gold).width
  527. change_color(system_color)
  528. draw_text(6+cx,yy,contents.width/2,line_height,Vocab::currency_unit)
  529. end
  530. yy += line_height
  531. change_color(normal_color)
  532. @quest.reward_items.each do |array|
  533. item = $data_items[array[1]] if array[0] == :item
  534. item = $data_weapons[array[1]] if array[0] == :weapon
  535. item = $data_armors[array[1]] if array[0] == :armor
  536. draw_item_name(item, 6, yy, true, contents.width)
  537. yy += line_height
  538. end
  539. if @quest.difficulty != 0
  540. text = "Difficulty: " + @quest.difficulty
  541. draw_text(0,contents.height-line_height,contents.width,line_height,text,2)
  542. end
  543. end
  544. def draw_objective(yy, obj)
  545. draw_text(6,yy,contents.width,24,obj.name)
  546. draw_text(0,yy,contents.width,24,obj.current.to_s+"/"+obj.max.to_s,2)
  547. end
  548. def draw_text_ex(x, y, text)
  549. text = convert_escape_characters(text)
  550. pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  551. process_character(text.slice!(0, 1), text, pos) until text.empty?
  552. end
  553. end
  554.  
  555. class Window_QuestTrack < Window_Command
  556. def initialize
  557. super(0,0)
  558. self.openness = 0
  559. end
  560. def quest(quest)
  561. @quest = quest
  562. end
  563. def make_command_list
  564. return unless @quest
  565. if !$game_quests.tracking?.include?(@quest.id)
  566. add_command("Track Quest", :track)
  567. else
  568. add_command("Untrack Quest", :untrack)
  569. end
  570. add_command("Abandon Quest", :abandon, @quest.can_abandon?)
  571. end
  572. def window_height
  573. fitting_height(2)
  574. end
  575. end
  576.  
  577. class Window_MenuCommand
  578. alias quest_aoc add_original_commands
  579. def add_original_commands
  580. quest_aoc
  581. add_command("Quest Log", :quest, !$game_quests.no_quests?)
  582. end
  583. end
  584.  
  585. class Scene_Menu
  586. alias quest_ccw create_command_window
  587. def create_command_window
  588. quest_ccw
  589. @command_window.set_handler(:quest, method(:scene_quest))
  590. end
  591. def scene_quest
  592. SceneManager.call(Scene_Quest)
  593. end
  594. end
  595.  
  596. class Scene_Map
  597. alias quest_start start
  598. alias quest_update update
  599. def start
  600. quest_start
  601. @quest_log = Window_QuestLog.new
  602. @quest_confirm = Window_QuestConfirm.new
  603. @quest_confirm.set_handler(:accept, method(:confirm_accept))
  604. @quest_confirm.set_handler(:decline, method(:confirm_cancel))
  605. @quest_confirm.set_handler(:cancel, method(:confirm_cancel))
  606. @quest_turnin = Window_QuestTurnin.new
  607. @quest_turnin.set_handler(:accept, method(:turnin_accept))
  608. @quest_turnin.set_handler(:decline, method(:confirm_cancel))
  609. @quest_turnin.set_handler(:cancel, method(:confirm_cancel))
  610. @quest_apply = Window_QuestApply.new(@quest_confirm,@quest_turnin)
  611. end
  612. def update(*args)
  613. @quest_log = Window_QuestLog.new if @quest_log.disposed?
  614. quest_update(*args)
  615. end
  616. def show_quest(id, turnin = false)
  617. @quest_apply.show($game_quests[id],turnin)
  618. end
  619. def accepting?
  620. @quest_confirm.active || @quest_turnin.active
  621. end
  622. def confirm_accept
  623. @quest_apply.accept
  624. @quest_apply.hide
  625. end
  626. def confirm_cancel
  627. @quest_apply.hide
  628. end
  629. def turnin_accept
  630. @quest_apply.turnin
  631. @quest_apply.hide
  632. end
  633. def update_call_menu
  634. if $game_system.menu_disabled || $game_map.interpreter.running? || accepting?
  635. @menu_calling = false
  636. else
  637. @menu_calling ||= Input.trigger?(:B)
  638. call_menu if @menu_calling && !$game_player.moving?
  639. end
  640. end
  641. end
  642.  
  643. class Scene_Base
  644. def accepting?
  645. false
  646. end
  647. end
  648.  
  649. class Window_QuestLog < Window_Base
  650. def initialize
  651. super(Graphics.width/5*3,0,Graphics.width/5*2,Graphics.height)
  652. self.x = 0 if QUEST_LOG_POSITION == 1
  653. self.x += QUEST_LOG_OFFSET_X
  654. self.y += QUEST_LOG_OFFSET_Y
  655. self.opacity = 0
  656. self.contents.font.size = 18
  657. end
  658. def update
  659. super
  660. return unless Graphics.frame_count % 20 == 0
  661. self.visible = $questlogvisibility
  662. self.visible = !$game_quests.no_quests?
  663. self.visible = $game_quests.tracking?.size > 0
  664. return unless self.visible
  665. contents.clear
  666. change_color(crisis_color)
  667. draw_text(0,0,contents.width,18,"Quest Log:",1)
  668. yy = 18;iter = 0
  669. $game_quests.tracking?.each do |id|
  670. quest = $game_quests[id]
  671. next unless quest.accepted? && !quest.turned_in
  672. change_color(system_color)
  673. draw_text(6,yy,contents.width-6,18,quest.name)
  674. change_color(normal_color)
  675. yy += 18
  676. quest.objectives.each do |obj_id, obj|
  677. draw_objective(yy, $game_party.quests[id][obj_id])
  678. yy += 18
  679. end
  680. iter += 1
  681. end
  682. end
  683. def draw_objective(yy, obj)
  684. draw_text(0,yy,contents.width-24,18,obj.name)
  685. draw_text(0,yy,contents.width,18,obj.current.to_s+"/"+obj.max.to_s,2)
  686. end
  687. end
  688.  
  689. class Window_QuestApply < Window_Base
  690. def initialize(confirm_window, turnin_window)
  691. super(Graphics.width/8,Graphics.width/8,Graphics.width/5*3,Graphics.height-Graphics.width/8*2)
  692. self.openness = 0
  693. @confirm_window = confirm_window
  694. @turnin_window = turnin_window
  695. self.contents.font.size = 18
  696. end
  697. def refresh
  698. return unless @quest
  699. contents.clear
  700. change_color(system_color)
  701. yy = 0
  702. if @quest.qgiver_name != 0
  703. draw_text(0,0,contents.width/2,line_height,@quest.qgiver_name)
  704. yy = line_height
  705. end
  706. if @quest.location != 0
  707. draw_text(contents.width/2,0,contents.width/2,line_height,@quest.location,2)
  708. yy = line_height
  709. end
  710. change_color(crisis_color)
  711. draw_text(0,yy,contents.width,line_height,"Lvl: " + @quest.level.to_s) if @quest.level > 0
  712. draw_text(0,yy,contents.width,line_height,@quest.name,1)
  713. draw_text(0,yy,contents.width,line_height,@quest.difficulty,2) if @quest.difficulty != 0
  714. change_color(normal_color)
  715. draw_text_ex(0,line_height+yy,@quest.desc)
  716. change_color(system_color)
  717. draw_text(0,line_height*8,contents.width,line_height,"Objectives:")
  718. change_color(normal_color)
  719. yy = line_height * 9
  720. @quest.objectives.each do |obj_id, obj|
  721. draw_objective(yy, $game_party.quests[@quest.id][obj_id])
  722. yy += line_height
  723. end
  724. change_color(system_color)
  725. draw_text(0,yy,contents.width,line_height,"Rewards:")
  726. yy += line_height
  727. if @quest.reward_exp > 0
  728. draw_text(6,yy,contents.width/2,line_height,"XP: ")
  729. change_color(normal_color)
  730. draw_text(36,yy,contents.width/2,line_height,@quest.reward_exp)
  731. yy += line_height
  732. end
  733. if @quest.reward_gold > 0
  734. change_color(normal_color)
  735. draw_text(6,yy,contents.width/2,line_height,@quest.reward_gold.to_s)
  736. cx = text_size(@quest.reward_gold).width
  737. change_color(system_color)
  738. draw_text(6+cx,yy,contents.width/2,line_height,Vocab::currency_unit)
  739. end
  740. yy += line_height
  741. change_color(normal_color)
  742. @quest.reward_items.each do |array|
  743. item = $data_items[array[1]] if array[0] == :item
  744. item = $data_weapons[array[1]] if array[0] == :weapon
  745. item = $data_armors[array[1]] if array[0] == :armor
  746. draw_item_name(item, 6, yy, true, contents.width)
  747. yy += line_height
  748. end
  749. end
  750. def draw_text_ex(x, y, text)
  751. text = convert_escape_characters(text)
  752. pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  753. process_character(text.slice!(0, 1), text, pos) until text.empty?
  754. end
  755. def line_height
  756. 18
  757. end
  758. def draw_objective(yy, obj)
  759. draw_text(6,yy,contents.width,24,obj.name)
  760. draw_text(0,yy,contents.width,24,obj.current.to_s+"/"+obj.max.to_s,2)
  761. end
  762. def show(quest,turnin)
  763. @quest = quest
  764. return if @quest.turned_in
  765. refresh
  766. open
  767. @confirm_window.open if !turnin
  768. if turnin
  769. @turnin_window.quest(@quest)
  770. @turnin_window.open
  771. end
  772. end
  773. def hide
  774. close
  775. @confirm_window.close
  776. @turnin_window.close
  777. end
  778. def accept
  779. @quest.accept
  780. end
  781. def turnin
  782. @quest.turnin
  783. end
  784. end
  785.  
  786. class Window_QuestConfirm < Window_HorzCommand
  787. def initialize
  788. super(Graphics.width/8,Graphics.width/8+Graphics.height-Graphics.width/8*2)
  789. self.openness = 0
  790. self.active = false
  791. refresh
  792. end
  793. def window_width
  794. Graphics.width/5*2
  795. end
  796. def window_height
  797. 48
  798. end
  799. def make_command_list
  800. add_command("Accept",:accept)
  801. add_command("Decline",:decline)
  802. end
  803. def item_width
  804. width / 2 - padding * 2
  805. end
  806. def open
  807. super
  808. activate
  809. select(0)
  810. end
  811. end
  812.  
  813. class Window_QuestTurnin < Window_QuestConfirm
  814. def quest(quest)
  815. @quest = quest
  816. refresh
  817. end
  818. def make_command_list
  819. return unless @quest
  820. add_command("Complete",:accept,@quest.completed? && !@quest.turned_in)
  821. add_command("Cancel",:decline)
  822. end
  823. end
  824.  
  825. class Game_Party
  826. attr_accessor :quests
  827. attr_accessor :tracking
  828. alias quests_init initialize
  829. def initialize(*args)
  830. quests_init(*args)
  831. @quests = $game_quests.reset_hash unless $game_quests.nil?
  832. @tracking = []
  833. end
  834. end
  835.  
  836. class Game_Player
  837. alias quest_update update
  838. def update
  839. return if SceneManager.scene.accepting?
  840. quest_update
  841. end
  842. end
  843.  
  844. class Game_Event
  845. def obj(quest, objective)
  846. $game_quests[quest].objective(objective).current
  847. end
  848. end
  849.  
  850. class Game_Interpreter
  851. def accept_quest(quest)
  852. $game_quests[quest].accept
  853. end
  854. def ask_accept(quest)
  855. return unless SceneManager.scene.is_a?(Scene_Map)
  856. SceneManager.scene.show_quest(quest)
  857. Fiber.yield while SceneManager.scene.accepting?
  858. end
  859. def abandon_quest(quest)
  860. $game_quests[quest].abandon
  861. end
  862. def fail_quest(quest)
  863. $game_quests[quest].fail
  864. end
  865. def turnin_quest(quest)
  866. $game_quests[quest].turnin
  867. end
  868. def ask_turnin(quest)
  869. return unless SceneManager.scene.is_a?(Scene_Map)
  870. SceneManager.scene.show_quest(quest,true)
  871. Fiber.yield while SceneManager.scene.accepting?
  872. end
  873. def adv_obj(quest, objective, value)
  874. $game_quests[quest].adv_obj(objective, value)
  875. end
  876. def set_obj(quest, objective, value)
  877. $game_quests[quest].set_obj(objective, value)
  878. end
  879. def obj(quest, objective)
  880. $game_quests[quest].objective(objective).current
  881. end
  882. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement