owned this note
owned this note
Linked with GitHub
title: "2D Online Chat: Story Line Feature"
# 2D Online Chat: Story Line Feature
Code base (WIP): https://github.com/g0v/greatescape2035/tree/story-line
This is a proposal for the "story line" or "mission" framework in 2d-online-chat. Key features we want to support:
- [x] Talk to an NPC to trigger the next step.
- [x] Go to a specific region on the map to trigger the next step.
- [ ] Branches. For example,
- [x] Go to different branch when a user select a different answer.
- [ ] Go to different branch when a user go to different region on the map.
- [ ] Game states
- [x] Global state (e.g. a counter of some choices)
- [x] Choices made by the current user
- [ ] Randomly generated state
## Detail Design
### File schema
The file contains multiple missions, each "mission" will have a title, multiple steps. "steps" is a mapping from `step-id` to step definition. "steps" forms a directed graph (a state machine).
<mission-id>: # repeated
"value": "<expected value>"
<step-id>: # repeated
nextStep: <step-id> # the default next step
npcId: <npc-id> # Trigger this step by pressing ENTER near this NPC.
# NPC can be an object (e.g. a box).
locationId: <locationId> # Trigger this step by move close to a
# location on the map.
# if none of <npcId> and <locationId> are given, the conversation
# will be triggered immediately.
- name: "NPC name" or $player # who is talking
line: "hello, $player"
id: <line-id> # optional
nextLine: <line-id> # optional: if we don't want to fallthrough. "$EOD" means "end of dialog"
- name: "NPC name" or $player
type: "input.select" # declare a multiple choice question
storeKey: "<key>" # field name to save the answer
question: "Red pill or blue pill?"
- text: "Red"
- text: "Blue"
- name: ...
type: "input.text" # declare a open-ended question.
storeKey: "<key>" # answer will be saved in this field.
question: "what is your name?"
You can also check out this [JSON file](https://github.com/g0v/IDystopia/blob/builder/static/story-lines/regular.json).
# mission definition
- name: 玩家
- name: 父親
- name: 玩家
npcId: "Lady of Lake"
- name: $player
- name: 湖中女神
- text: 銀色的
- text: 金色的
- text: 都不是
- id: label-bad
nextLine: $EOD # "EOD" is a special label, which means end of dialog.
nextStep: step-5 # override the default next step
- id: label-good
### Game Mechanism
All missions of a given map should be collected into one single file.
Each player will have a new property: `story_line_states`, which is a list of strings `"<mission-id>:<step-id>"`. For each step, there is an NPC id, players have to find these NPCs (active NPC) to trigger the next step. In render function, active NPCs will have exclamation marks ("!") on their heads. When a player is standing next to an active NPC, a dialog will be shown to select a dialog (because there might be multiple steps of missions assigned to the same NPC).
* Save user state to local storage
* Global state
1. there are `n` people online that has finished mission `m1`, mission `m2` will be enabled.
* this might be easier, because we only need to maintain the "current state".
3. there are `n` people finished mission `m1` (accumulative), then mission `m2` will be enabled.
* this is more difficult, we need to save this info somewhere.
### Game State
## Required Works
## Open Questions