Skip to content

Instantly share code, notes, and snippets.

@oestrich
Last active December 1, 2018 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oestrich/2f774f97d67aa6a36f6fc3b8a5fc9625 to your computer and use it in GitHub Desktop.
Save oestrich/2f774f97d67aa6a36f6fc3b8a5fc9625 to your computer and use it in GitHub Desktop.
New event structure for exventure

ExVenture Events

Events

  • character/targeted
  • combat/ticked
  • room/entered
  • room/heard
  • state/ticked

Actions

  • commands/emote
  • commands/move
  • commands/say
  • commands/skill
  • commands/target

Schema

defmodule Data.Events do
  @type action :: String.t()

  @type options_mapping :: map()

  @callback type() :: String.t()

  @callback allowed_actions?() :: [action()]
  
  @callback options :: options_mapping()

  def mapping() do
    %{
      "room/entered" => Data.Events.RoomEntered,
      "room/heard" => Data.Events.RoomHeard,
    }
  end
end
defmodule Data.Events.Actions do
  @callback type() :: String.t()

  @callback options :: options_mapping()

  def mapping() do
    %{
      "communications/say" => Data.Events.Actions.Communications.Say,
      "commications/emote" => Data.Events.Actions.Communications.Emote,
    }
  end
end

Event

{
  "type": "room/entered",
  "options": {},
  "actions": []
}
defmodule Data.Events.RoomEntered do
  defstruct [:type, :options, :actions]
  
  @behaviour Data.Events
  
  @impl true
  def type(), do: "room/entered"
  
  @impl true
  def allowed_actions?() do
    [
      "communications/emote",
      "communications/say"
    ]
  end
  
  @impl true
  def options(), do: []
end
defmodule Data.Events.RoomHeard do
  defstruct [:type, :options, :actions]
  
  @behaviour Data.Events
  
  @impl true
  def type(), do: "room/heard"
  
  @impl true
  def allowed_actions?(), do: ["communications/say", "communications/emote"]
  
  @impl true
  def options(), do: [regex: :string]
end
defmodule Data.Events.CombatTick do
  defstruct [:type, :actions]
  
  @behaviour Data.Events
  
  @impl true
  def allowed_actions?(), do: ["target/effects"]
  
  @impl true
  def options(), do: []
end

Action

{
  "type": "communications/say",
  "delay": 0,
  "options": {}
}
defmodule Data.Events.Actions.Communications.Say do
  defstruct [:type, :delay, :options]
  
  @behaviour Data.Events.Actions
  
  @impl true
  def type(), do: "communications/say"

  @impl true
  def options(), do: [message: :string, messages: {:array, :string}]
end
defmodule Data.Events.Actions.Target.Effects do
  defstruct [:type, :delay, :options]
  
  @behaviour Data.Events.Actions
  
  @impl true
  def type(), do: "target/effects"

  @impl true
  def options(), do: [text: :string, weight: :integer, effects: {:array, :effect}]
end

Ideas

What I want them to look like:

{
  "type": "tick",
  "options": {
    "random_delay": 50,
    "minimum_delay": 15
  },
  "actions": [
    {
      "type": "channels/emote",
      "options": {
        "message": "moves about the store"
      }
    },
    {
      "type": "channels/emote",
      "delay": 1,
      "options": {
        "message": "moves about the store",
        "status_key": "moving",
        "status_line": "[name] is moving around the store",
        "status_listen": "[name] is whistling"
      }
    }
  ]
}
{
  "type": "room/entered",
  "actions": [
    {
      "type": "communications/emote",
      "delay": 0.5,
      "options": {
        "message": "[name] glances up from reading his paper",
      }
    },
    {
      "type": "communications/say",
      "delay": 0.75,
      "options": {
        "message": "Welcome!"
      }
    },
    {
      "type": "communications/say",
      "delay": 0.75,
      "options": {
        "message": "How can I help you?"
      }
    }
  ]
}
{
  "type": "room/heard",
  "options": {
    "regex": "hello"
  },
  "actions": [
    {
      "type": "communications/say",
      "delay": 0.5,
      "options": {
        "message": "Welcome!"
      }
    },
  ]
}
{
  "type": "combat/tick",
  "actions": [
    {
      "type": "target/effects",
      "delay": 0.5,
      "options": {
        "text": "{user} slashes at you.",
        "weight": 10,
        "effects": [
          {
            "kind": "damage",
            "type": "slashing",
            "amount": 10
          }
        ]
      }
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment