Skip to content

Instantly share code, notes, and snippets.

@panozzaj
Created May 9, 2014 00:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panozzaj/1bfb37e8689a32f1b0fb to your computer and use it in GitHub Desktop.
Save panozzaj/1bfb37e8689a32f1b0fb to your computer and use it in GitHub Desktop.
grpg state brainstorm
"town:King":
states:
initial:
condition: (gameState) ->
!gameState.magicKey and numTimesTalked is 0
transitions:
talk: "followUp"
action: ->
dialog [
"""
Hello there, stranger!
Want to know about my quest?
Well I'll tell you anyway.
"""
"""
Here is another whole dialog!
Get me the key and I'll be happy.
"""
]
followUp:
condition: (gameState) ->
!gameState.magicKey and numTimesTalked > 0
transitions:
talk: "followUp"
action: ->
dialog "Nice to see you again!"
hasMagicKey:
condition: (gameState) ->
gameState.magicKey
action: ->
dialog """
Sweet! Thanks for the key!
I have been looking for that forever!
Oh, here is another item.
"""
"town:Greeter":
initialize: ->
talked = false
states:
first:
condition: -> !talked
action: ->
dialog("Welcome to Townsville!")
question("Do you like us so far?")
.yes ->
dialog("Yay!")
response = 'yay'
reputation += 5
.no ->
dialog("Boo!")
response = 'boo'
reputation -= 20
talked = true
liked:
condition: -> talked
action: ->
if reputation > 100
dialog "Oh my god! You're a legend!"
else if reputation < 10
dialog "Who are you? You're nobody!"
else
dialog "I've heard rumors of a stranger from the west doing good deeds..."
if response == 'boo'
dialog "You are so nice!"
else
dialog "You are a jerk!"
unliked:
condition: -> talked and response = 'boo'
action: ->
if reputation > 500
dialog "You must have had a good reason to disparage us!"
else if reputation < -500
dialog "Please don't kill me!"
else
dialog "You're a jerk! I was going to give you a potion, but now you get nothing!"
# Behavior? Interaction(s)? not sure
class DialogueLoader
@load: (npc) ->
new Dialogue loadDialogueFromFile()
class Dialogue
execute: (gameState) ->
class NPC
constructor: ->
@dialogue = DialogueLoader.load @
talk: ->
@dialogue.execute(gameState)
ERROR: Must provide condition when there are multiple states!
class NPC
talk: ->
# TODO: check to see if any of the states are now fulfilled
# and if so, switch to that state
_.find Dialog[@name]["states"], (props, condition) ->
gameState.call condition
.dialog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment