From 248b6a6c0681e47fed42eff8f72799c5aaff5100 Mon Sep 17 00:00:00 2001 From: Major- Date: Mon, 2 Mar 2015 10:53:00 +0000 Subject: [PATCH] Fix QuestStage bug where it would not propery get the attribute. --- .../location/tutorial-island/instructions.rb | 4 +++- .../location/tutorial-island/stages.rb | 6 ++++-- data/plugins/quest/plugin.xml | 4 +++- data/plugins/quest/repository.rb | 20 +++++++++++-------- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/data/plugins/location/tutorial-island/instructions.rb b/data/plugins/location/tutorial-island/instructions.rb index 7320ca55..26c223c5 100644 --- a/data/plugins/location/tutorial-island/instructions.rb +++ b/data/plugins/location/tutorial-island/instructions.rb @@ -7,7 +7,8 @@ module TutorialInstructions # Sends the appropriate instruction to the player. def self.show_instruction(player) instructions = CONVERSATIONS[:tutorial_island_instructions] - name = case player.tutorial_island_progress + progress = player.tutorial_island_progress.name + name = case progress # The Runescape Guide instructions. when :not_started then :getting_started when :runescape_guide_finished then :scenery @@ -17,6 +18,7 @@ module TutorialInstructions when :given_axe then :viewing_items when :cut_tree then :cut_tree when :cutting_tree then :please_wait + else raise "No dialogue for current stage #{progress} exists." end dialogue = instructions.part(name) diff --git a/data/plugins/location/tutorial-island/stages.rb b/data/plugins/location/tutorial-island/stages.rb index 73e732f6..453efb4b 100644 --- a/data/plugins/location/tutorial-island/stages.rb +++ b/data/plugins/location/tutorial-island/stages.rb @@ -5,9 +5,11 @@ private STAGES = [] # The stages that are used when interacting with the Runescape Guide. -STAGES << RUNESCAPE_GUIDE = [ :not_started, :talk_to_people, :go_through_door, :runescape_guide_finished, :moving_around ] +RUNESCAPE_GUIDE = [ :not_started, :talk_to_people, :go_through_door, :runescape_guide_finished, :moving_around ] +STAGES.concat(RUNESCAPE_GUIDE) # The stages that are used when interacting with the Survival Expert. -STAGES << SURVIVAL_EXPERT = [ :given_axe, :cut_tree, :cutting_tree, ] +SURVIVAL_EXPERT = [ :given_axe, :cut_tree, :cutting_tree, ] +STAGES.concat(SURVIVAL_EXPERT) quest :tutorial_island, STAGES \ No newline at end of file diff --git a/data/plugins/quest/plugin.xml b/data/plugins/quest/plugin.xml index f203abf0..b92ef5b3 100644 --- a/data/plugins/quest/plugin.xml +++ b/data/plugins/quest/plugin.xml @@ -10,5 +10,7 @@ - + + attributes + \ No newline at end of file diff --git a/data/plugins/quest/repository.rb b/data/plugins/quest/repository.rb index c6fe7481..ce6189ac 100644 --- a/data/plugins/quest/repository.rb +++ b/data/plugins/quest/repository.rb @@ -1,8 +1,8 @@ # Defines a quest with the specified name. -def quest(name, *stage_names) - stages = Array.new(stage_names.size) - stage_names.each_with_index { |stage, index| stages << stage.kind_of?(QuestStage) ? stage : QuestStage.new(stage, index, name) } +def quest(name, stage_names) + stages = { } + stage_names.each_with_index { |stage, index| stages[stage] = QuestStage.new(stage, index, name) } QUESTS[name] = Quest.new(name, stages) end @@ -18,6 +18,7 @@ class Quest # Creates the Quest. def initialize(name, stages) + raise "Quest name must be a symbol, received '#{name}'." unless name.kind_of?(Symbol) @name = name @stages = stages end @@ -34,7 +35,9 @@ class Quest # Gets the QuestStage with the specified name. def stage(name) - @stages[name] + stage = @stages[name] + raise "No stage named #{name} exists in #{@name}." if stage.nil? + stage end end @@ -113,14 +116,15 @@ class Player args[0] = arg.name if arg.kind_of?(QuestStage) end - result = super.method_missing(symbol, args) + result = super(symbol, args) string = symbol.to_s - if (string.ends_with('_progress')) + if (string.end_with?('_progress')) name = string[0..-10] # Cut the '_progress' from the end quest = QUESTS[name.to_sym] - result = quest.stage(result) unless quest.nil? - raise "No QuestStage with the name #{result} exists - define it as part of the Quest declaration." if result.nil? + raise "No Quest with the name '#{name}' exists." if quest.nil? + + result = quest.stage(result) end result