Skip to content

Commit

Permalink
Merge pull request #131 from ryleykimmel/issue65
Browse files Browse the repository at this point in the history
Fix #65, add support for emotes/anims in dialogue
  • Loading branch information
garyttierney committed Jan 29, 2016
2 parents 2525ecd + 32ef506 commit 26199f8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
19 changes: 14 additions & 5 deletions data/plugins/dialogue/dialogue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
java_import 'org.apollo.game.message.impl.SetWidgetItemModelMessage'
java_import 'org.apollo.game.message.impl.SetWidgetNpcModelMessage'
java_import 'org.apollo.game.message.impl.SetWidgetPlayerModelMessage'
java_import 'org.apollo.game.message.impl.SetWidgetModelAnimationMessage'
java_import 'org.apollo.game.message.impl.SetWidgetTextMessage'
java_import 'org.apollo.game.action.DistancedAction'

# The map of conversation names to Conversations.
CONVERSATIONS = {}


# Declares a conversation.
def conversation(name, &block)
conversation = Conversation.new(name)
Expand Down Expand Up @@ -419,23 +419,32 @@ def send_text_dialogue(player, dialogue)

# Sends a dialogue displaying the player's head.
def send_player_dialogue(player, dialogue)
send_generic_dialogue(player, dialogue, player.username, PLAYER_DIALOGUE_IDS, ->(id) { SetWidgetPlayerModelMessage.new(id + 1) })
emote = dialogue.emote

send_generic_dialogue player, dialogue, player.username, PLAYER_DIALOGUE_IDS do |id|
player.send(SetWidgetPlayerModelMessage.new(id + 1))
player.send(SetWidgetModelAnimationMessage.new(id + 1, emote)) unless emote.nil?
end
end

# Sends a dialogue displaying the head of an npc.
def send_npc_dialogue(player, dialogue)
npc = dialogue.npc
emote = dialogue.emote
name = NpcDefinition.lookup(npc).name.to_s
name = "" if (name.nil? || name == "null")

send_generic_dialogue(player, dialogue, name, NPC_DIALOGUE_IDS, ->(id) { SetWidgetNpcModelMessage.new(id + 1, npc)})
send_generic_dialogue player, dialogue, name, NPC_DIALOGUE_IDS do |id|
player.send(SetWidgetNpcModelMessage.new(id + 1, npc))
player.send(SetWidgetModelAnimationMessage.new(id + 1, emote)) unless emote.nil?
end
end

# Sends a dialogue displaying an event.
def send_generic_dialogue(player, dialogue, title, ids, event=nil)
def send_generic_dialogue(player, dialogue, title, ids, &event)
text = dialogue.text
dialogue_id = ids[text.size - 1]
player.send(event.call(dialogue_id)) unless event.nil?
event.call(dialogue_id) if block_given?

set_text(player, dialogue_title_id(dialogue_id), title)

Expand Down
7 changes: 7 additions & 0 deletions data/plugins/dialogue/emotes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Declares all of the possible emotes
declare_emote(:calm, 588)
declare_emote(:anxious, 589)
declare_emote(:default, 591)

# TODO: Properly name the rest of the facial emotes.
# Found at http://www.rune-server.org/runescape-development/rs2-server/tutorials/518991-pi-317-player-npc-facial-dialogue-expressions.html
1 change: 1 addition & 0 deletions data/plugins/dialogue/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</authors>
<scripts>
<script>dialogue.rb</script>
<script>emotes.rb</script>
</scripts>
<dependencies>
<dependency>util</dependency>
Expand Down
4 changes: 4 additions & 0 deletions data/plugins/location/tutorial-island/guide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
dialogue :greetings do
type :npc_speech
npc :runescape_guide
emote :calm

precondition { |player| player.tutorial_island_progress == :not_started }

Expand All @@ -53,6 +54,7 @@
dialogue :welcome_back do
type :npc_speech
npc :runescape_guide
emote :calm

precondition { |player| player.tutorial_island_progress != :not_started }

Expand All @@ -65,6 +67,7 @@
dialogue :talk_to_people do
type :npc_speech
npc :runescape_guide
emote :calm

text 'You have already learned the first thing you need to succeed in this world: talking to '\
'people!',
Expand All @@ -81,6 +84,7 @@
dialogue :go_through_door do
type :npc_speech
npc :runescape_guide
emote :calm

text 'To continue the tutorial go through that door over there, and speak to your first '\
'instructor.'
Expand Down

0 comments on commit 26199f8

Please sign in to comment.