Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Szyu's Quests
- # Version 1.2
- # By Szyu
- #
- # About:
- # Create Quests, the player can do on his journey through the world,
- # intensifying the experience of a real RPG.
- #
- # Instructions:
- # - Place below "▼ Materials" but above "▼ Main Process".
- #
- # How to Use:
- # - $game_party.gain_quest(qid)
- # - $game_party.complete_quest(qid)
- # - $game_party.cancel_quest(qid, failed)
- # - $game_party.quest_completed?(qid)
- # - $game_party.has_quest?(qid)
- #
- # Requires:
- # - RPG Maker VX Ace
- #
- # Terms of Use:
- # - Free for commercal and non-commercial use. Please list me
- # in the credits to support my work.
- #
- # Pastebin:
- # http://adf.ly/UoFvf
- #
- #==============================================================
- # * Configuration
- #==============================================================
- # Access menu in GameMenu
- SCENE_MENU_SZQL_ACCESS = true
- # Terms
- SZ_QUESTLOG_TERM = "Questlog" # Term for Menu Entry
- SZQL_OBJECTIVES_TERM = "Objectives" # Term for Questlog Objectives Head
- SZQL_DESCRIPTION_TERM = "Description" # Term for Questlog Description Head
- SZQL_SW_TRUE_TERM = "True" # Term for Switch Objective "true"
- SZQL_SW_FALSE_TERM = "False" # Term for Switch Objective "false"
- SZQL_LOG_HEADER = ["Current Quests", "Completed Quests"]
- # Text Coloration
- SZQL_COMPLETE_COLOR = 29 # Color or Color-Index (number for text_color(x))
- SZQL_INCOMPLETE_COLOR = 21
- # Icons
- SZQL_SWITCH_ICON = 16 # Index for standard switch icon
- SZQL_VAR_ICON = 16 # Index for standard variable icon
- SZQL_CURRENCY_ICON = 361 # Index for standard currency icon
- QUEST_LIST = {
- # "Quest Name" => [Description, is_active/autostart, objectives]
- # objectives:
- #"s: id, value, match, optional: icon_index, text" -> switch[id] == value?
- #"v: id, value, match, optional: icon_index, text" -> variable[id] matches value?
- #"g: value, match, optional: icon_index, text" -> gold matches value?
- #"i: id, value, match, optional: icon_index, text/item name will be taken if no optional text" -> item[id] matches value?
- #"w: id, value, match, optional: icon_index, text/item name will be taken if no optional text" -> weapon[id] matches value?
- #"a: id, value, match, optional: icon_index, text/item name will be taken if no optional text" -> armor[id] matches value?
- "Stones, Stones, Stones" => ["Collect 3 stones and return to the quest giver.",
- false,
- ["i: 1, 3, >="]],
- "A lonely sister" => ["Talk to sister Ann and return.", false,["s: 1, True, ==, 361,Talked to sister Ann"]],
- "Autostart Quest" => ["Complete 2 quests and talk to \nthe big Monster.",true,["v: 1, 2, >=, -1,Quests completed"]],
- "Get Gold" => ["Get Gold...", true,["g: 2000, >=, 361, Gold"]]
- }
- #=====================================================================
- # Don't edit below this line
- #=====================================================================
- #==============================================================
- # * Scene_QuestLog
- #==============================================================
- class Scene_QuestLog < Scene_MenuBase
- def start
- super
- create_header_window
- create_log_window
- end
- def create_header_window
- @header_window = Window_QuestHeader.new
- end
- def create_log_window
- @log_window = Window_QuestLog.new
- @log_window.set_handler(:cancel, method(:return_scene))
- @log_window.set_handler(:pageup, method(:switch_header))
- @log_window.set_handler(:pagedown, method(:switch_header))
- @info_window = Window_QuestInfo.new(@log_window.width)
- @log_window.header = 0
- @log_window.info_window = @info_window
- end
- def switch_header
- @header_window.header = (@header_window.head_index == 0) ? 1 : 0
- @log_window.header = @header_window.head_index
- @log_window.activate
- end
- end
- #==============================================================
- # * Window_QuestHeader
- #==============================================================
- class Window_QuestHeader < Window_Selectable
- attr_reader :head_index
- def initialize
- super(0,0,Graphics.width/3,line_height*2)
- @head_index = 0
- refresh
- end
- def header=(head)
- @head_index = head
- refresh
- end
- def refresh
- contents.clear
- draw_text(0,0,width-8,line_height, SZQL_LOG_HEADER[@head_index])
- end
- end
- #==============================================================
- # * Window_QuestLog
- #==============================================================
- class Window_QuestLog < Window_Selectable
- attr_reader :info_window
- attr_reader :header
- alias sz_ql_help call_update_help
- def initialize
- super(0,line_height*2,Graphics.width/3,Graphics.height-line_height*2)
- @data = []
- activate
- end
- def header=(head)
- @header = head
- refresh
- end
- def refresh
- make_item_list
- create_contents
- draw_all_items
- end
- def make_item_list
- data = []
- case @header
- when 0
- $game_party.active_quests.each do |q|
- data.push($game_quests.data[q]) if $game_quests.data[q].active
- end
- when 1
- $game_party.completed_quests.each do |q|
- data.push($game_quests.data[q]) if $game_quests.data[q].completed
- end
- end
- select(0) if data.size > 0
- @data = data
- end
- def draw_item(index)
- item = @data[index]
- if item
- rect = item_rect(index)
- rect.width -= 4
- change_color(SZQL_COMPLETE_COLOR.is_a?(Color) ? SZQL_COMPLETE_COLOR : text_color(SZQL_COMPLETE_COLOR)) if item.completed?
- change_color(crisis_color) if item.failed
- draw_text(rect, item.name); change_color(normal_color)
- end
- end
- def item
- @data && index >= 0 ? @data[index] : nil
- end
- def item_max
- @data ? @data.size : 1
- end
- def call_update_help
- sz_ql_help
- @info_window.set_item = item if @info_window
- @info_window.contents.clear if @info_window && @header != 0
- end
- def info_window=(qi)
- @info_window = qi
- refresh
- end
- end
- #==============================================================
- # * Window_QuestInfo
- #==============================================================
- class Window_QuestInfo < Window_Selectable
- def initialize(x)
- super(x,0,Graphics.width-x,Graphics.height)
- @item = nil
- refresh
- end
- def refresh
- contents.clear
- return unless @item
- change_color(system_color)
- draw_text(0,0,width,line_height, SZQL_DESCRIPTION_TERM)
- change_color(normal_color)
- desc = @item.description.split("\n")
- line = 1
- desc.each do |ln|
- draw_text(0,line_height*line,width,line_height, ln)
- line += 1
- end
- line += 1
- change_color(system_color)
- draw_text(0, line_height*line, width,line_height, SZQL_OBJECTIVES_TERM)
- line += 1
- change_color(normal_color)
- for i in 0..@item.objectives.size-1
- obj = @item.objectives[i]
- txt = (obj.type == "s" || obj.type == "v" || obj.type == "g" ||obj.text != nil) ? sprintf("%s?", obj.text) : sprintf("%s?", obj.data.name)
- valtxt = (obj.type == "s" || obj.type == "v" || obj.type == "g") ? obj.data.to_s : $game_party.item_number(obj.data)
- ico_index = nil
- if obj.icon_index == -1
- case obj.type
- when "s"
- ico_index = SZQL_SWITCH_ICON || nil
- when "v"
- ico_index = SZQL_VAR_ICON || nil
- when "g"
- ico_index = SZQL_CURRENCY_ICON || nil
- else
- ico_index = obj.data.icon_index || nil
- end
- else
- ico_index = obj.icon_index
- end
- if obj.achieved?
- change_color(SZQL_COMPLETE_COLOR.is_a?(Color) ? SZQL_COMPLETE_COLOR : text_color(SZQL_COMPLETE_COLOR))
- else
- change_color(SZQL_INCOMPLETE_COLOR.is_a?(Color) ? SZQL_INCOMPLETE_COLOR : text_color(SZQL_INCOMPLETE_COLOR))
- end
- draw_text(0, line_height*(2*i+line), width, line_height, txt)
- change_color(normal_color)
- draw_icon(ico_index,0,line_height*(2*i+line+1)) if ico_index
- draw_text(32, line_height*(2*i+line+1), width, line_height, sprintf("%s %s %s", valtxt,obj.match, obj.value))
- end
- end
- def set_item=(q)
- @item = q
- refresh
- end
- end
- #==============================================================
- # * Game_Quest
- #==============================================================
- class Game_Quest
- attr_reader :name
- attr_reader :description
- attr_reader :id
- attr_accessor :completed
- attr_reader :objectives
- attr_reader :active
- attr_accessor :failed
- def initialize(id,name, args)
- @id = id
- @name = name
- @description = args[0]
- @active = args[1]
- @objectives = []
- @completed = false
- @failed = false
- args[2].each do |obj|
- @objectives.push(Quest_Objective.new(obj))
- end
- end
- def activate
- @active = true if !@active
- end
- def deactivate
- @active = false if @active
- end
- def complete
- @completed = true
- end
- def completed?
- @objectives.each do |obj|
- return false if !obj.achieved?
- end
- return true
- end
- end
- #==============================================================
- # * Quest_Objective
- #==============================================================
- class Quest_Objective
- attr_reader :type
- attr_reader :id
- attr_reader :value
- attr_reader :match
- attr_accessor :text
- attr_accessor :icon_index
- def initialize(objectives)
- if objectives =~ /(\w+):\s*?(\d+),\s*?(\w+),?\s*([><=!]+),?\s*([-]?\d+)?,?\s*([\w\W]+)?/i
- @type = $1
- @id = $2.to_i
- @value = @type == "s" ? $3 : $3.to_i
- @match = $4
- @icon_index = $5 ? $5.to_i : -1
- @text = $6
- elsif objectives =~ /(\w+):\s*?(\d+),?\s*([><=!]+),?\s*([-]?\d+)?,?\s*([\w\W]+)?/i
- @type = $1
- @id = nil
- @value = $2.to_i
- @match = $3
- @icon_index = $4 ? $4.to_i : -1
- @text = $5
- end
- end
- def data
- case @type
- when "s"
- $game_switches[@id]? SZQL_SW_TRUE_TERM : SZQL_SW_FALSE_TERM
- when "v"
- $game_variables[@id]
- when "g"
- $game_party.gold
- when "i"
- $data_items[@id]
- when "w"
- $data_weapons[@id]
- when "a"
- $data_armors[@id]
- end
- end
- def achieved?
- case @match
- when ">"
- return (data.is_a?(RPG::BaseItem)? $game_party.item_number(data) : data) > @value
- when "<"
- return (data.is_a?(RPG::BaseItem)? $game_party.item_number(data) : data) < @value
- when ">="
- return (data.is_a?(RPG::BaseItem)? $game_party.item_number(data) : data) >= @value
- when "<="
- return (data.is_a?(RPG::BaseItem)? $game_party.item_number(data) : data) <= @value
- when "=="
- return (data.is_a?(RPG::BaseItem)? $game_party.item_number(data) : data) == @value
- when "!="
- return (data.is_a?(RPG::BaseItem)? $game_party.item_number(data) : data) != @value
- end
- return true
- end
- end
- #==============================================================
- # * Game_Quests
- #==============================================================
- class Game_Quests
- attr_reader :data
- def initialize
- @data = [nil]
- i=1
- QUEST_LIST.each_pair do |name, q|
- @data.push(Game_Quest.new(i,name, q))
- i += 1
- end
- end
- def [](quest_id)
- return nil unless @data[quest_id]
- @data[quest_id] ||= Game_Quest.new(quest_id)
- end
- end
- #==============================================================
- # * Alias Object Creation
- #==============================================================
- module DataManager
- class << self
- alias sz_qlog_init_quests create_game_objects
- end
- def self.create_game_objects
- sz_qlog_init_quests
- $game_quests = Game_Quests.new
- $game_party.initialize_autoquests
- end
- end
- #==============================================================
- # * Alias Game_Party Quests
- #==============================================================
- class Game_Party < Game_Unit
- attr_reader :active_quests
- attr_reader :completed_quests
- alias szql_init initialize
- def initialize
- szql_init
- @active_quests = []
- @completed_quests = []
- end
- def initialize_autoquests
- $game_quests.data.select {|q| q != nil && q.active }.each do |q|
- $game_party.gain_quest(q.id)
- end
- end
- def has_quest?(qid)
- return true if @completed_quests.include?(qid)
- return @active_quests.include?(qid)
- end
- def gain_quest(qid)
- return false if has_quest?(qid)
- return false if $game_quests[qid].completed
- @active_quests.push(qid)
- $game_quests[qid].activate
- $game_quests[qid].failed = false
- return true
- end
- def quest_completed?(qid)
- return false if !has_quest?(qid)
- return $game_quests[qid].completed?
- end
- def complete_quest(qid)
- return true if $game_quests[qid].completed
- return false if !has_quest?(qid)
- return false if !quest_completed?(qid)
- @completed_quests.push(qid)
- @active_quests.delete(qid)
- $game_quests[qid].complete
- return true
- end
- def cancel_quest(qid, failed=false)
- return unless has_quest?(qid)
- @active_quests.delete(qid)
- $game_quests[qid].deactivate
- $game_quests[qid].failed = true if failed
- end
- end
- #==============================================================
- # * Add Entry to Menu
- #==============================================================
- class Scene_Menu < Scene_MenuBase
- alias :command_szql_wincom :create_command_window
- def create_command_window
- command_szql_wincom
- @command_window.set_handler(:swclass, method(:call_sz_questlog)) if SCENE_MENU_SZQL_ACCESS
- end
- def call_sz_questlog
- SceneManager.call(Scene_QuestLog)
- end
- end
- #==============================================================
- # * Add Entry to Menu
- #==============================================================
- class Window_MenuCommand < Window_Command
- alias :command_szql_wincom :add_main_commands
- def add_main_commands
- command_szql_wincom
- add_command(SZ_QUESTLOG_TERM, :swclass, main_commands_enabled) if SCENE_MENU_SZQL_ACCESS
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement