Skip to content

Commit 407797c

Browse files
committed
Fix patterns, add pronouns and rough conversation
1 parent e071aaf commit 407797c

File tree

7 files changed

+113
-9
lines changed

7 files changed

+113
-9
lines changed

data/commands.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Commands.push({
1313

1414
//Examine/look at command
1515
Commands.push({
16-
pattern: "^(x|look\\s+at|examine)\\s+(\\w+)$",
16+
pattern: "^(x|look\\s+at|examine)\\s+(.+)$",
1717
execute: function (game, captures) {
1818
var examined = captures[2];
1919
var position = Mobs[game.player].position;
@@ -29,12 +29,44 @@ Commands.push({
2929
return;
3030
}
3131
}
32+
out("You don't see that here.");
33+
}
34+
});
35+
36+
//Say command
37+
Commands.push({
38+
pattern: "^(say|tell|ask)\\s+(.+)\\s+to\\s+(.+)$",
39+
execute: function (game, captures) {
40+
var topic = captures[2];
41+
var target = captures[3];
42+
for (var mob in Mobs) {
43+
if (Mobs[mob].position === Mobs[game.player].position && Mobs[mob].keywords.includes(target) && Mobs[mob].conversation) {
44+
for (var i = 0; i < Mobs[mob].conversation.length; i++) {
45+
var subject = Mobs[mob].conversation[i];
46+
if (subject.keywords.includes(topic) && subject.check(game)) {
47+
if (!Mobs[mob].topics.includes(subject.name)) {
48+
subject.first_time(game);
49+
} else {
50+
subject.following(game);
51+
}
52+
return 1;
53+
}
54+
}
55+
out(Pronouns[Mobs[mob].pronoun].subject.capitalizeFirstLetter() + " doesn't seem to know anything about that. You could ask " + Pronouns[Mobs[mob].pronoun].object + " about " + Mobs[mob].conversation.filter(function (item) {
56+
return item.check(game);
57+
}).map(function (item) {
58+
return item.description;
59+
}).betterJoin(", ", ", or ") + ".");
60+
return 1;
61+
}
62+
}
63+
out("You don't see them here.");
3264
}
3365
});
3466

3567
//Get command
3668
Commands.push({
37-
pattern: "^(g|get|take|pick\\s+up)\\s+(\\w+)$",
69+
pattern: "^(g|get|take|pick\\s+up)\\s+(.+)$",
3870
execute: function (game, captures) {
3971
var taken = captures[2];
4072
for (var item in Items) {
@@ -55,7 +87,7 @@ Commands.push({
5587

5688
//Drop command
5789
Commands.push({
58-
pattern: "^(drop|leave|throw\\s+away)\\s+(\\w+)$",
90+
pattern: "^(drop|leave|throw\\s+away)\\s+(.+)$",
5991
execute: function (game, captures) {
6092
var dropped = captures[2];
6193
for (var item in Items) {
@@ -102,7 +134,7 @@ Commands.push({
102134

103135
//Goto command
104136
Commands.push({
105-
pattern: "^(go\\s+)?((north|n|south|s|east|e|west|w|up|u|down|d)(?!\\w+)|to\\s+(\\w+))$",
137+
pattern: "^(go\\s+)?((north|n|south|s|east|e|west|w|up|u|down|d)(?!.+)|to\\s+(.+))$",
106138
execute: function (game, captures) {
107139
//Is it a cardinal direction, or are we looking for an adjacent room?
108140
var cardinal = !captures[4];

data/misc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,25 @@ var DirectionAliases = {
55
w: "west",
66
u: "up",
77
d: "down"
8+
}
9+
10+
var Pronouns = {
11+
you: {
12+
subject: "you",
13+
object: "you",
14+
possessive: "your",
15+
reflexive: "yourself"
16+
},
17+
it: {
18+
subject: "it",
19+
object: "it",
20+
possessive: "its",
21+
reflexive: "itself"
22+
},
23+
they: {
24+
subject: "they",
25+
object: "them",
26+
possessive: "theirs",
27+
reflexive: "themselves"
28+
}
829
}

data/mobs.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,51 @@ Mobs.Player = {
44
position: "TowerMageQuarters",
55
name: "yourself",
66
keywords: ["me", "self", "myself"],
7+
pronoun: "you",
78
short_description: "You are standing here.",
89
description: "You are a bit drab in your brown shirt and pants, but not unpleasant to the eye.",
910
};
1011

1112
Mobs.WizardFamiliar = {
1213
position: null,
1314
name: "wizard's imp",
14-
keywords: ["imp", "familiar", "wizard's imp", "wizard's familiar"],
15+
keywords: ["imp", "familiar", "master's imp", "master's familiar", "wizard's imp", "wizard's familiar"],
16+
pronoun: "it",
1517
short_description: "The wizard's familiar is here, idly flapping its wings, looking expectantly at you.",
1618
description: "It's a short, stocky creature, with dark red skin and stubby wings, dressed only in a loincloth.",
1719
each_turn: function (game) {
1820
if (game.turns === 5) {
1921
Mobs.WizardFamiliar.position = Mobs[game.player].position;
2022
out("The room is filled with the smell of sulphur, and your master's familiar appears in a puff of black smoke.\n\n\"The master wants to speak with you.\", it says in a low, gravelly voice.");
2123
}
22-
}
24+
},
25+
topics: [],
26+
conversation: [
27+
{
28+
name: "where",
29+
description: "where the master is",
30+
keywords: ["where", "where is he", "where is the master"],
31+
check: always_true,
32+
first_time: function (game) {
33+
out("\"He's waiting for you in the laboratory, down in the basement.\", it says.");
34+
},
35+
following: function (game) {
36+
out("\"He's in the laboratory, down in the basement.\"");
37+
}
38+
},
39+
{
40+
name: "what",
41+
description: "what does the master want",
42+
keywords: ["what", "what does he want"],
43+
check: always_true,
44+
first_time: function (game) {
45+
out("\"You'll have to ask him yourself.\", it says.");
46+
},
47+
following: function (game) {
48+
out("\"I don't know.\"");
49+
}
50+
}
51+
]
2352
}
2453

2554
Mobs.DummyMob = {

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
</footer>
2121
<script type="text/javascript" src="dist/zepto.min.js"></script>
2222
<script type="text/javascript" src="dist/marked.min.js"></script>
23+
<script type="text/javascript" src="js/common.js"></script>
2324
<script type="text/javascript" src="data/commands.js"></script>
2425
<script type="text/javascript" src="data/items.js"></script>
2526
<script type="text/javascript" src="data/rooms.js"></script>
2627
<script type="text/javascript" src="data/mobs.js"></script>
2728
<script type="text/javascript" src="data/misc.js"></script>
2829
<script type="text/javascript" src="data/main.js"></script>
29-
<script type="text/javascript" src="js/common.js"></script>
3030
<script type="text/javascript" src="js/main.js"></script>
3131
</body>
3232
</html>

index.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
</footer>
2323
<script type="text/javascript">
2424
@all dist/*
25+
@all js/common.js
2526
@all data/*
26-
@all js/*
27+
@all js/main.js
2728
</script>
2829
</body>
2930
</html>

js/common.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
String.prototype.capitalizeFirstLetter = function() {
2+
return this.charAt(0).toUpperCase() + this.slice(1);
3+
}
4+
5+
Array.prototype.betterJoin = function (middle, last) {
6+
var string = "";
7+
for (var i = 0; i < this.length - 1; i++) {
8+
string += this[i];
9+
if (i < this.length - 2) {
10+
string += middle;
11+
}
12+
}
13+
string += last + this[this.length-1];
14+
return string;
15+
}
16+
117
//Appends `text` to the `#story` element, after parsing it with marked,
218
// wrapping it with a tag `box` (defaulting to `<div>` if nothing is
319
// specified).
@@ -64,6 +80,9 @@ function goto (game, room) {
6480
//No-op function
6581
function no_op () {}
6682

83+
//Always returns true
84+
function always_true () { return true; }
85+
6786
//Makes the world tick
6887
function turn_passes (game) {
6988
game.turns += 1;

todo.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@
2424
- [ ] 2016-11-07T22:10 Ground floor
2525
- [ ] 2016-11-07T22:11 Third floor - Library
2626
- Items
27-
- Mobs
27+
- Mobs
28+
- [ ] 2016-11-07T23:01 Add scenes
29+
- [ ] 2016-11-07T23:01 Add hints

0 commit comments

Comments
 (0)