Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=============================
- # Z07 :: Quest System v1.01 by Zetu
- # Commands (In call script)
- # => QuestList::acceptquest(symbol)
- # - Adds the quest to questlog.
- # => QuestList::questcomplete?(symbol)
- # - Checks if conditions of quest have been completed.
- # => QuestList::onquest?(symbol)
- # - Checks if quest is in questlog
- # => QuestList::turnin(symbol)
- # - Removes quest from questlog and gives the player rewards.
- #=============================
- module Z07 #questsystem
- QUESTS = {
- # ==============
- :quest1 => [[:defeat, 3, 1, :reward, 3000],
- ["Quest Title01", "Quest Info"]],
- :quest2 => [[:collect, 5, $data_items[3], :reward, 5000],
- ["Quest Title02", "Quest Info"]],
- :quest3 => [[:event, :event01, "Event01disc", :reward, 1, $data_armors[3], :xp, 40],
- ["Quest Title03", "Quest Info"]]
- # ==============
- }
- COLLECTQUEST = " - %s of %s %ss obtained!"
- DEFEATQUEST = " - %s of %s %ss defeated!"
- EVENTQUEST = " - %s"
- end
- module QuestList
- def self.start
- @questlist = []
- end
- def self.acceptquest(symbol)
- @questlist.push(QuestItem.new(symbol))
- end
- def self.questcomplete?(symbol)
- for quest in @questlist
- if quest.symbol == symbol
- return quest.goalscomplete?
- end
- end
- end
- def self.onquest?(symbol)
- for quest in @questlist
- return true if quest.symbol == symbol
- end
- return false
- end
- def self.questlist
- return @questlist
- end
- def self.quest(symbol)
- for quest in @questlist
- return quest if quest.symbol == symbol
- end
- end
- def self.turnin(symbol)
- for quest in @questlist
- if quest.symbol == symbol
- quest.complete
- return
- end
- end
- end
- end
- QuestList.start
- class QuestItem
- attr_reader :symbol, :objectives
- def initialize(symbol)
- @objectives = []
- @rewards = []
- @symbol=symbol
- index = 0
- array = Z07::QUESTS[symbol][0]
- while (index < array.size)
- case array[index]
- when :defeat, :collect, :event
- @objectives.push(QuestObjective.new(array[index..index+2]))
- index += 2
- when :reward
- index += 1
- @rewards.push(array[index])
- next if (index+1 < array.size)
- if (array[index+1].is_a?(RPG::Item)||array[index+1].is_a?(RPG::Armor)||array[index+1].is_a?(RPG::Weapon))
- index +=1; @rewards.push(array[index])
- end
- when :xp
- @rewards.push(:xp)
- @rewards.push(array[index+1])
- index += 1
- end
- index += 1
- end
- end
- def goalscomplete?
- for objective in objectives
- return false unless objective.complete
- end
- return true
- end
- def complete
- index = 0
- while index < @rewards.size
- if @rewards[index] == :xp
- index +=1
- for member in $game_party.all_members
- member.gain_exp(@rewards[index])
- end
- elsif @rewards[index].is_a?(Integer)
- index += 1
- if (index<@rewards.size)and(@rewards[index].is_a?(RPG::Item)||@rewards[index].is_a?(RPG::Armor)||@rewards[index].is_a?(RPG::Weapon))
- $game_party.gain_item(@rewards.size, @rewards[index-1])
- else
- $game_party.gain_gold(@rewards[index-1])
- end
- end
- end
- QuestList::questlist.delete(self)
- end
- end
- class QuestObjective
- attr_reader :type, :enemy_id, :item, :eventtag, :total, :disc, :current, :complete
- def initialize(array)
- @type = array[0]
- case @type
- when :defeat
- @total = array[1]
- @current = 0
- @enemy_id = array[2]
- when :collect
- @total = array[1]
- @current = 0
- @item = array[2]
- when :event
- @eventtag = array[1]
- @disc = array[2]
- end
- end
- def setascomplete
- @complete=true
- end
- def current=(k)
- old = @current
- @current = k
- popup if old < k
- end
- def update
- @current = [@current, @total].min if @current.is_a?(Integer)
- setascomplete if @current==@total
- end
- def popup
- update
- color_index = @complete ? 17 : 0
- case @type
- when :collect
- SceneManager::popup(sprintf(Z07::COLLECTQUEST, @current, @total, @item.name), color_index)
- print "Collet\n"
- when :defeat
- SceneManager::popup(sprintf(Z07::DEFEATQUEST, @current, @total, $data_enemies[@enemy_id].name), color_index)
- print "Defeat\n"
- when :event
- SceneManager::popup(sprintf(Z07::EVENTQUEST, objective.disc), color_index)
- print "Event\n"
- end
- end
- end
- class Game_Enemy < Game_Battler
- alias z07pce perform_collapse_effect
- def perform_collapse_effect
- z07pce
- for quest in QuestList.questlist
- for objective in quest.objectives
- if objective.enemy_id==@enemy_id
- objective.current += 1
- objective.update
- end
- end
- end
- end
- end
- class Game_Party < Game_Unit
- alias z07gi gain_item
- def gain_item(item, amount, include_equip = false)
- z07gi(item, amount, include_equip)
- unless item.nil?
- for quest in QuestList.questlist
- for objective in quest.objectives
- if objective.item==item
- objective.current = $game_party.item_number(item)
- objective.update
- end
- end
- end
- end
- end
- end
- class Scene_QuestLog < Scene_Base
- def start
- super
- @help_window = Window_Help.new(1)
- @help_window.viewport = @viewport
- @help_window.set_text("Quest Log")
- @commandwindow = Window_QuestCommand.new(0,48)
- @commandwindow.set_handler(:cancel, method(:return_scene))
- @info_window = Window_QuestMenuInfo.new(160, 48, 384, 368).set_symbol(@commandwindow.current_ext)
- end
- end
- class Window_QuestCommand < Window_Command
- def make_command_list
- for quest in QuestList.questlist
- add_command(Z07::QUESTS[quest.symbol][1][0], quest.symbol, true, quest.symbol)
- end
- end
- def window_height
- return Graphics.height - 48
- end
- end
- class Window_QuestMenuInfo < Window_Base
- def set_symbol(symbol)
- @symbol = symbol
- refresh
- end
- def refresh
- contents.clear
- return if @symbol.nil?
- draw_text_ex(0, 0, Z07::QUESTS[@symbol][1][0])
- draw_text_ex(0, 24, Z07::QUESTS[@symbol][1][1])
- y = 48
- for objective in QuestList::quest(@symbol).objectives
- change_color(normal_color)
- case objective.type
- when :collect
- change_color(text_color(17)) if objective.current == objective.total
- draw_text_ind(y, sprintf(Z07::COLLECTQUEST, objective.current, objective.total, objective.item.name))
- y += 24
- when :defeat
- change_color(text_color(17)) if objective.current == objective.total
- draw_text_ind(y, sprintf(Z07::DEFEATQUEST, objective.current, objective.total, $data_enemies[objective.enemy_id].name))
- y += 24
- when :event
- change_color(text_color(17)) if objective.current == true
- draw_text_ind(y, sprintf(Z07::EVENTQUEST, objective.disc))
- y += 24
- end
- end
- self.show
- end
- end
- class Window_Base < Window
- def draw_text_ind(y, text)
- draw_text(0, y, self.width-standard_padding * 2, line_height, text)
- end
- end
- module SceneManager
- def self.popup(string, color_id = 0)
- if @scene.popup.nil?
- @scene.popup = Window_Popup.new
- end
- @scene.popup.stack(string, 120, color_id)
- end
- end
- class Window_Popup < Window_Base
- def initialize
- super(0, 0, 544, 416)
- self.opacity=0
- @stack = []
- end
- def stack(text, frames, color_id = 0)
- @stack.push(Window_PopupItem.new(text, frames, text_color(color_id)))
- refresh
- end
- def update
- super
- for window in @stack
- window.update
- @stack.delete(window) if window.time<=0
- end
- for i in 0...@stack.size
- @stack[i].y = 184 + 24*i
- end
- end
- def refresh
- end
- def dispose
- super
- for window in @stack
- window.dispose
- end
- end
- end
- class Window_PopupItem < Window_Base
- attr_reader :time
- def initialize(text, maxtime, color = normal_color)
- super(0, 0, 544, 48)
- self.opacity = 0
- @color = color
- @text=text
- @max=@time=maxtime
- refresh
- end
- def refresh
- contents.clear
- draw_text(0, 0, 496, 24, @text, 1)
- end
- def update
- @time -= 1
- self.contents_opacity = 255*@time / @max
- end
- end
- class Scene_Base
- attr_accessor :popup
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement