Adapt StoryManager for Snowman
This commit is contained in:
@ -1,4 +1,6 @@
|
|||||||
|
var State = window.story.state
|
||||||
|
|
||||||
|
State.variables = Object.create(null)
|
||||||
// Game stats
|
// Game stats
|
||||||
State.variables.reputation = 0;
|
State.variables.reputation = 0;
|
||||||
State.variables.playerKnowledge = {poetry: 0, industry: 0, astronomy: 0};
|
State.variables.playerKnowledge = {poetry: 0, industry: 0, astronomy: 0};
|
||||||
|
@ -6,45 +6,51 @@ At the Duchess's Party
|
|||||||
"ifid": "BE18C022-A213-466C-8DD1-DCCD5CB1DF48"
|
"ifid": "BE18C022-A213-466C-8DD1-DCCD5CB1DF48"
|
||||||
}
|
}
|
||||||
|
|
||||||
:: Story JavaScript [script]
|
:: Story JavaScript
|
||||||
Config.passages.nobr = true; // Deal with linebreaks.
|
Config.passages.nobr = true; // Deal with linebreaks.
|
||||||
|
|
||||||
:: Start
|
:: Start
|
||||||
The footmen at the door to the duchess's city residence bows over your forged invitation, seemingly not examining at all. The uniform you wear is authentic, at least, though Frin had found a tailor who would accept some extra florins to not demand to see a letter of appointment before sewing on captain's bars. And just like that, you're in. Could it be that easy, you wonder? <br> <br>
|
The footmen at the door to the duchess's city residence bows over your forged invitation, seemingly not examining at all. The uniform you wear is authentic, at least, though Frin had found a tailor who would accept some extra florins to not demand to see a letter of appointment before sewing on captain's bars. And just like that, you're in. Could it be that easy, you wonder? <br> <br>
|
||||||
|
|
||||||
Of course it isn't. The hall is filled with aristocrats in evening-wear, making small talk in an ever-shifting constellation. Across the room, the doors to the duchess's private rooms are firmly closed. No way to sneak in without being seen. You're going to have to find a way to [[talk your way in | Circulating]].
|
Of course it isn't. The hall is filled with aristocrats in evening-wear, making small talk in an ever-shifting constellation. Across the room, the doors to the duchess's private rooms are firmly closed. No way to sneak in without being seen. You're going to have to find a way to [[talk your way in |Circulating]].
|
||||||
|
|
||||||
:: Circulating
|
:: Circulating
|
||||||
You mingle through the crowd, keeping a wary eye around you.<br>
|
You mingle through the crowd, keeping a wary eye around you.<br>
|
||||||
<<getStoryletLinks 3 "circulating">>
|
<%= window.SM.getStoryletLinks(3, "circulating") %>
|
||||||
|
|
||||||
:: Conversation
|
:: Conversation
|
||||||
<<set $talkingTo = $currentStorylet.character>>
|
<% s.variables.talkingTo = window.SM.currentStorylet.character %>
|
||||||
You talk with $talkingTo.name. <br>
|
You talk with <%= window.SM.currentStorylet.character.name %>. <br>
|
||||||
<<getStoryletLinks 3 "during conversation">>
|
<%= window.SM.getStoryletLinks(3, "during conversation") %>
|
||||||
[[Keep circulating | Circulating]]
|
[[Keep circulating|Circulating]]
|
||||||
|
|
||||||
:: Being approached
|
:: Being approached
|
||||||
$currentStorylet.character.name is coming toward you to talk. <br>
|
<%= window.SM.currentStorylet.character.name %> is coming toward you to talk. <br>
|
||||||
You can [[talk to them | Conversation]], or risk snubbing them by [[trying to get away | Circulating][$reputation = $reputation - 1]].
|
You can [[talk to them|Conversation]], or risk snubbing them by <div onclick="s.variables.reputation -= 1">[[trying to get away|Circulating]]</div>.
|
||||||
|
|
||||||
:: Conversation topic
|
:: Conversation topic
|
||||||
<<set $topic = $currentStorylet.topic>>
|
<% var topic = window.SM.currentStorylet.character %>
|
||||||
<<if $playerKnowledge[$topic] < $talkingTo[$topic] >>
|
|
||||||
$talkingTo.name tells you about <<print $conversationTopics[$topic][$playerKnowledge[$topic]]>>.
|
|
||||||
<<set $playerKnowledge[$topic] = $playerKnowledge[$topic] + 1>>
|
|
||||||
<<set $reputation = $reputation - 0.5>>
|
|
||||||
<<elseif $playerKnowledge[$topic] == $talkingTo[$topic]>>
|
|
||||||
You and $talkingTo.name discuss <<print $conversationTopics[$topic][$playerKnowledge[$topic]]>>.
|
|
||||||
<<set $reputation = $reputation + 1>>
|
|
||||||
<<elseif $playerKnowledge[$topic] > $talkingTo[$topic]>>
|
|
||||||
You tell $talkingTo.name about <<print $conversationTopics[$topic][$talkingTo[$topic]]>>.
|
|
||||||
<<set $characters[$talkingTo.id][$topic] = $talkingTo[$topic] + 1>>
|
|
||||||
They listen intently, and seem impressed.
|
|
||||||
<<set $reputation = $reputation + 2>>
|
|
||||||
<</if>><br><br>
|
|
||||||
|
|
||||||
[[Keep circulating | Circulating]]
|
<% var topic = window.SM.currentStorylet.topic
|
||||||
|
if (s.variables.playerKnowledge[topic] < s.variables.talkingTo[topic]) { %>
|
||||||
|
<%= s.variables.talkingTo.name %> tells you about <%= s.variables.conversationTopics[topic][s.variables.playerKnowledge[topic]] %>
|
||||||
|
<%
|
||||||
|
s.variables.playerKnowledge[topic] += 1
|
||||||
|
s.variables.reputation -= 0.5
|
||||||
|
} else if (s.variables.playerKnowledge[topic] == s.variables.talkingTo[topic]) { %>
|
||||||
|
You and <%= s.variables.talkingTo.name %> discuss <%= s.variables.conversationTopics[topic][s.variables.playerKnowledge[topic]] %>
|
||||||
|
<%
|
||||||
|
s.variables.reputation += 1
|
||||||
|
} else { %>
|
||||||
|
You tell <%= s.variables.talkingTo.name %> about <%= s.variables.conversationTopics[topic][s.variables.playerKnowledge[topic]] %>
|
||||||
|
They listen intently and seem impressed.
|
||||||
|
<%
|
||||||
|
s.variables.talkingTo[topic] += 1
|
||||||
|
s.variables.reputation += 2
|
||||||
|
}
|
||||||
|
%>
|
||||||
|
|
||||||
|
[[Keep circulating|Circulating]]
|
||||||
|
|
||||||
:: Asked to leave
|
:: Asked to leave
|
||||||
The footman demands to see your invitation.
|
The footman demands to see your invitation.
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
var StoryManager = {};
|
var StoryManager = {};
|
||||||
StoryManager.storylets = {};
|
StoryManager.storylets = {};
|
||||||
|
StoryManager.nextStoryletCache = [];
|
||||||
|
StoryManager.currentStorylet = Object.create(null);
|
||||||
|
|
||||||
StoryManager.getAllStorylets = function(tag=null) {
|
StoryManager.getAllStorylets = function(tag=null) {
|
||||||
let allStorylets = [];
|
let allStorylets = [];
|
||||||
@ -99,32 +101,54 @@ StoryManager.weightedRandom = function(allStorylets, n) {
|
|||||||
return selectedStorylets;
|
return selectedStorylets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StoryManager.setCurrentStorylet = function(id) {
|
||||||
|
if (Object.hasOwn(StoryManager.nextStoryletCache, id)) {
|
||||||
|
StoryManager.currentStorylet = StoryManager.nextStoryletCache[id]
|
||||||
|
StoryManager.nextStoryletCache = Object.create(null);
|
||||||
|
} else {
|
||||||
|
console.log("Error: didn't find storylet cache entry: " + id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StoryManager.getStoryletLinks = function(n, tag, selection) {
|
||||||
|
var links = _.map(StoryManager.getStorylets(n, tag, selection), function(storylet) {
|
||||||
|
// Maybe store the current storylet in a map generating a unique ID, then
|
||||||
|
// add some code below looking it up via that ID?
|
||||||
|
//
|
||||||
|
// How to keep storylets from building up over time?
|
||||||
|
// Clear them when a passage is left
|
||||||
|
|
||||||
|
var id = _.uniqueId("storylet-key_")
|
||||||
|
StoryManager.nextStoryletCache[id] = storylet;
|
||||||
|
return "<div onclick=\"window.SM.setCurrentStorylet('" + id + "');\" >[[" + storylet.description + "|" + storylet.passage + "]]<br></div>"
|
||||||
|
})
|
||||||
|
return _.reduce(links, function(memo, link) { return memo + link }, "")
|
||||||
|
}
|
||||||
|
|
||||||
// Set up macros
|
// Set up macros
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
Macro.add("getStoryletLinks", {
|
// Macro.add("getStoryletLinks", {
|
||||||
handler: function() {
|
// handler: function() {
|
||||||
let n, tag, selection;
|
// let n, tag, selection;
|
||||||
[n=null, tag=null, selection="ordered"] = this.args;
|
// [n=null, tag=null, selection="ordered"] = this.args;
|
||||||
State.temporary.nextStorylets = StoryManager.getStorylets(n, tag, selection);
|
// State.temporary.nextStorylets = StoryManager.getStorylets(n, tag, selection);
|
||||||
$(this.output).wiki(`\
|
// $(this.output).wiki(`\
|
||||||
<<for _storylet range _nextStorylets>> \
|
// <<for _storylet range _nextStorylets>> \
|
||||||
<<capture _storylet>> \
|
// <<capture _storylet>> \
|
||||||
[[_storylet.description|_storylet.passage][$currentStorylet=_storylet]]<br>
|
// [[_storylet.description|_storylet.passage][$currentStorylet=_storylet]]<br>
|
||||||
<</capture>> \
|
// <</capture>> \
|
||||||
<</for>> \
|
// <</for>> \
|
||||||
`)
|
// `)
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
Macro.add("linkToNextStorylet", {
|
// Macro.add("linkToNextStorylet", {
|
||||||
handler: function() {
|
// handler: function() {
|
||||||
let text, tag, selection;
|
// let text, tag, selection;
|
||||||
[text, tag=null, selection="weighted"] = this.args;
|
// [text, tag=null, selection="weighted"] = this.args;
|
||||||
State.temporary.nextStorylet = StoryManager.getStorylets(1, tag, selection)[0];
|
// State.temporary.nextStorylet = StoryManager.getStorylets(1, tag, selection)[0];
|
||||||
$(this.output).wiki(`<<capture _nextStorylet>>[[${text}|_nextStorylet.passage][$currentStorylet=_nextStorylet]]<</capture>>`);
|
// $(this.output).wiki(`<<capture _nextStorylet>>[[${text}|_nextStorylet.passage][$currentStorylet=_nextStorylet]]<</capture>>`);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
window.SM = StoryManager;
|
window.SM = StoryManager;
|
Reference in New Issue
Block a user