Add support for executing blocks when directly using close() in a dialogue.

This commit is contained in:
Major-
2015-03-08 10:57:25 +00:00
parent 4f880c7bed
commit a6ac0610e5
3 changed files with 80 additions and 57 deletions
+4 -4
View File
@@ -163,17 +163,17 @@ class Dialogue
end
# Closes the dialogue interface when the player clicks the 'Click here to continue...' text.
def close
continue(:close => true)
def close(&block)
continue(:close => true, &block)
end
# Defines the event that occurs when a player clicks the 'Click here to continue...' text.
def continue(type=nil, &block)
raise 'Cannot add a continue event on a dialogue with options.' unless @options.size.zero?
raise 'Cannot add a continue event on a dialogue with options.' if (@type == :options)
raise 'Must declare either a type or a block for a continue event.' if (type.nil? && block.nil?)
action = get_next_dialogue(type) unless type.nil?
@options << ->(player) { action.call(player) unless type.nil?; block.call(player) unless block.nil? }
@options[0] = ->(player) { action.call(player) unless type.nil?; block.call(player) unless block.nil? }
end
# Sets the emote performed by the dialogue head.
+4 -19
View File
@@ -19,7 +19,7 @@ CHARACTER_DESIGN = 3559
on :login do |event, player|
if player.in_tutorial_island
TutorialInstructions::show_instruction(player)
# INITIAL_TABS.each_with_index { |tab, index| player.send(SwitchTabInterfaceMessage.new(index, tab)) } # This is commented so the lame hack works
INITIAL_TABS.each_with_index { |tab, index| player.send(SwitchTabInterfaceMessage.new(index, tab)) }
if (player.tutorial_island_progress == :not_started)
show_hint_icon(player)
@@ -28,21 +28,6 @@ on :login do |event, player|
end
end
## TODO lame hack to get round the lack of door support - must remove
on :message, :fifth_item_option do |ctx, player, message|
player.teleport(Position.new(3100, 3107)) if message.id == 1
player.tutorial_island_progress = :moving_around
player.interface_set.open_dialogue_overlay(-1)
end
on :login do |event, player|
player.inventory.add(1)
end
## END lame hack
# The conversation with the Runescape Guide, when on tutorial island.
conversation :tutorial_runescape_guide do
@@ -56,7 +41,7 @@ conversation :tutorial_runescape_guide do
text "Greetings! I see you are a new arrival to this land. My job is to welcome all new visitors. So welcome!"
continue :dialogue => :go_through_door do |player|
continue :dialogue => :talk_to_people do |player|
player.tutorial_island_progress = :talk_to_people
end
end
@@ -67,7 +52,7 @@ conversation :tutorial_runescape_guide do
type :npc_speech
npc :runescape_guide
precondition { |player| player.tutorial_island_progress != :not_started }
precondition { |player| player.tutorial_island_progress != :talk_to_people }
text "Welcome back."
@@ -94,7 +79,7 @@ conversation :tutorial_runescape_guide do
text "To continue the tutorial go through that door over there, and speak to your first instructor."
continue :close => true do |player|
close do |player|
if (player.tutorial_island_progress < :runescape_guide_finished)
reset_hint_icon(player)
# TODO door hint icon
@@ -6,19 +6,29 @@ java_import 'org.apollo.game.message.impl.SwitchTabInterfaceMessage'
private
# The Survival Expert Npc.
@survival_expert = spawn_npc :name => :survival_expert, :x => 3104, :y => 3095, :face => :north
# Contains Survival Expert-related constants.
module SurvivalConstants
# The inventory tab index.
INVENTORY_TAB_INDEX = 3
# The Survival Expert Npc.
@survival_expert = spawn_npc :name => :survival_expert, :x => 3104, :y => 3095, :face => :north
# The inventory tab id.
INVENTORY_TAB_ID = 3213
# The inventory tab index.
INVENTORY_TAB_INDEX = 3
# The id of the tree the Player will cut down.
TREE_ID = 3033
# The inventory tab id.
INVENTORY_TAB_ID = 3213
# The id of the tree the Player will cut down.
TREE_ID = 3033
# The id of the bronze axe.
BRONZE_AXE = lookup_item(:bronze_axe)
# The id of the tinderbox.
TINDERBOX = lookup_item(:tinderbox)
end
# TODO prevent axe equipping
# The conversation with the Survival Expert, when on tutorial island.
conversation :tutorial_surivival_expert do
@@ -32,7 +42,7 @@ conversation :tutorial_surivival_expert do
text "Hello there, newcomer. My name is Brynna. My job is to teach you a few survival tips and tricks. First off we're "\
"going to start with the most basic survival skill of all: making a fire."
continue :dialogue => :items
close &:add_survival_items
end
@@ -45,24 +55,44 @@ conversation :tutorial_surivival_expert do
text "Hello again. I'm here to teach you a few survival tips and tricks. First off we're going to start with the most "\
"basic survival skill of all: making a fire."
continue :close => true, &:add_survival_items
close &:add_survival_items
end
# The dialogue displayed when the Survival Guide hands both a bronze axe and a tinderbox to the player.
dialogue :items do
# The dialogue displayed when the Survival Expert gives the player a bronze axe.
dialogue :give_bronze_axe do
type :message_with_item
item :bronze_axe, 200 # TODO the tinderbox is also displayed - find this dialogue id. Scale looks like the default http://i.imgur.com/i1abN5X.png
item :bronze_axe
text "The Survival Guide gives you a tinderbox and a bronze axe!"
text "The Survival Expert gives you a bronze axe!"
close { |player| TutorialInstructions.show_instruction(player) }
end
# The dialogue displayed when the Survival Expert gives the player a tinderbox.
dialogue :give_tinderbox do
type :message_with_item
item :tinderbox
text "The Survival Expert gives you a tinderbox!"
close { |player| TutorialInstructions.show_instruction(player) }
end
# The dialogue displayed when the Survival Expert gives the player both a bronze axe and a tinderbox.
dialogue :give_axe_and_tinderbox do
type :message_with_item
item :bronze_axe # TODO the tinderbox is also displayed - find this dialogue id. Scale looks like the default http://i.imgur.com/i1abN5X.png
text "The Survival Expert gives you a tinderbox and a bronze axe!"
continue :close => true do |player|
if (player.tutorial_island_progress != :given_axe)
close do |player|
if (player.tutorial_island_progress < :given_axe)
player.tutorial_island_progress = :given_axe
player.send(SwitchTabInterfaceMessage.new(INVENTORY_TAB_INDEX, INVENTORY_TAB_ID))
player.send(FlashTabInterfaceMessage.new(INVENTORY_TAB_INDEX))
player.send(SwitchTabInterfaceMessage.new(SurvivalConstants::INVENTORY_TAB_INDEX, SurvivalConstants::INVENTORY_TAB_ID))
player.send(FlashTabInterfaceMessage.new(SurvivalConstants::INVENTORY_TAB_INDEX))
end
add_survival_items(player)
TutorialInstructions.show_instruction(player)
end
end
@@ -72,36 +102,44 @@ conversation :tutorial_surivival_expert do
item :logs
text "You get some logs."
continue :close => true do |player|
TutorialInstructions.show_instruction(player)
end
close { |player| TutorialInstructions.show_instruction(player) }
end
end
# The id of the bronze axe.
BRONZE_AXE = lookup_item(:bronze_axe)
# The id of the tinderbox.
TINDERBOX = lookup_item(:tinderbox)
# Add the survival items (bronze axe and tinderbox) to the inventory of the player, if they do not already have them.
def add_survival_items(player)
inventory = player.inventory
[ BRONZE_AXE, TINDERBOX ].each { |item| inventory.add(item) unless inventory.contains(item) }
TutorialInstructions.show_instruction(player)
unless inventory.contains(BRONZE_AXE)
inventory.add(BRONZE_AXE)
dialogue = :give_bronze_axe
end
unless inventory.contains(TINDERBOX)
inventory.add(TINDERBOX)
dialogue = (dialogue == :give_bronze_axe) ? :give_axe_and_tinderbox : give_tinderbox
end
send_dialogue(player, get_dialogue(:tutorial_surivival_expert, dialogue)
end
# Intercept the FirstObjectActionMessage to send tutorial-only events if the player is chopping down a tree.
on :message, :first_object_action do |ctx, player, message|
# TODO display "You cannot cut down this tree; you must first follow the guide's instructions." if the player has yet to get the axe
if (player.in_tutorial_island && player.tutorial_island_progress == :cut_tree && message.id == TREE_ID)
player.tutorial_island_progress = :cutting_tree # Don't break the chain, so that the Woodcutting event actually happens.
if (player.in_tutorial_island && message.id == TREE_ID)
progress = player.tutorial_island_progress
if (progress < :cut_tree)
# TODO display "You cannot cut down this tree; you must first follow the guide's instructions."
elsif (player.tutorial_island_progress == :cut_tree)
player.tutorial_island_progress = :cutting_tree # Don't break the chain, so that the Woodcutting event actually happens.
end
end
end
# Intercept the FlashingTabClickedMessage to update the player's progress, if applicable.
on :message, :flashing_tab_clicked do |ctx, player, message|
if (player.in_tutorial_island && message.tab == INVENTORY_TAB_INDEX)
if (player.in_tutorial_island && message.tab == INVENTORY_TAB_INDEX && player.tutorial_island_progress == :given_axe)
player.tutorial_island_progress = :cut_tree
ctx.break_handler_chain()
end