forked from mozilla/BrowserQuest
-
Notifications
You must be signed in to change notification settings - Fork 219
Mathieu edited this page Jun 30, 2022
·
5 revisions
client/js/npc.js defines the Npc class, which uses the NpcTalk array that stores for each character the sequence of sentences it is supposed to produce to players.
The Npc class extends class Character
-
NpcTalk
: Each talking npc is associated to a cell in the array, its content is an array with the sentences to produce in the order in which they are to utter them.
-
init
: initialises the npc; -
talk
: displays the next sentence associated to the character in the NpcTalk table.
(see scientist for an example)
Discourse can now be circonstancial. The default mechanism is providing an array of sentences. For more elaborate speech :
[
{"text":[/*sentences*/]},
{"condition": function(game),
"text":[/*sentences*/]},
{"condition": function(game),
"text":[/*sentences*/]}
]
- Each object (except the first, default discussion) has a
"condition"
property (function(game)
→boolean
) which decides when to use this discussion and a"text"
property, which contain the array of lines of the conversation ([/*sentences*/]
). -
name
as the name of the user in npc dialogs
- It could also be modified to provide multilingual support.