-
Notifications
You must be signed in to change notification settings - Fork 11
/
ConvLib.aslx
730 lines (610 loc) · 43.9 KB
/
ConvLib.aslx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
<?xml version="1.0"?>
<library>
<!--
If you are viewing this on GitHub and want to download it, right click on the RAW button
just above, and select "Save link as..."
-->
<!--
ConvLib v3.2
Quest version: 5.7
Written by: The Pixie, 2013-2018
Tutorial and notes here:
https://github.com/ThePix/quest/wiki/Conversations:-Library
If you use this with Quest versions of 5.5 and 5.6, it should still work fine, just be careful
not to have ant apostophes or quotes in the topic aliases.
Version 3.1 adds exclusive topics, so you can easily have tpics hidden when another is shown.
Version 3.2 adds more dynamic templates to properly internationalise
Reactions:
Each reaction consists of:
A line with just a @
The name of the reaction
The condition, in standard Quest code, evaulating to true or false
This will accept "this", but will get confused if that string in there in another context
Any number of additional lines with these rules
If a line starts with ~, the rest should be the name of another reaction; this will be deleted along with this one
=/+/- set add to or subtract from attribute
# Ignored as a comment
Anything else will be output as test
Set game.showreactions to true to see the reactions box in the editor.
-->
<dynamictemplate name="NoSpeakTopics">"You wonder what you can talk to " + GetDisplayName(object) + " about..."</dynamictemplate>
<dynamictemplate name="NoConsultTopics">"You wonder what you can look up with " + GetDisplayName(object) + "."</dynamictemplate>
<dynamictemplate name="TalkAbout">"Talk to " + GetDisplayName(object) + " about..."</dynamictemplate>
<dynamictemplate name="ConsultAbout">"Consult " + GetDisplayName(object) + " about..."</dynamictemplate>
<dynamictemplate name="ConsultableSwitchedOff">CapFirst(object.gender) + " is not switched on."</dynamictemplate>
<!-- OVER-RIDABLE FUNCTIONS -->
<!--
Can be overriden if necessary. You can use this as a way to add extra topics, for example if you want all your
characters to have some standard topics, add them this way.
-->
<function name="AddExtraTopics" parameters="c, topics">
//list add(topics, everyone_help)
</function>
<!--
Override this to have something happen after each exchange.
-->
<function name="AfterTopicEvent">
</function>
<!--
Override this to have something prevent the player talking.
If the player cannot speak, this should print a message explaining why
and return true. If the player can speak, just return false.
-->
<function name="PlayerCannotTalkTo" parameters="c" type="boolean">
return (false)
</function>
<verb name="consultverb">
<property>consult</property>
<pattern>consult</pattern>
<defaultexpression>"You can't consult " + object.article + "."</defaultexpression>
</verb>
<!--
Call this from game.start to check your game; it will flag any obvious issues.
* Topics without aliases
* Topics that try to display new topics that do not exist
Delete it from game.start before publishing!
-->
<function name="TopicTest"><![CDATA[
topiccount = 0
charcount = 0
foreach(o, AllObjects()) {
if (DoesInherit(o, "talkingchar")) {
charcount = charcount + 1
if (not HasString(o, "alias")) {
msg("Talker with no alias: " + o.name)
}
if (not HasScript(o, "reactions")) {
msg("Talker with reactions: " + o.name)
}
}
if (DoesInherit(o, "topic")) {
topiccount = topiccount + 1
if (not HasString(o, "alias")) {
msg("Topic with no alias: " + o.name)
}
if (HasAttribute(o, "nowshow")) {
foreach(s, o.nowshow) {
if (GetObject(s) = null) {
msg ("Topic " + o.name + " tries to invoke a non-existent topic, " + s)
}
}
}
if (HasAttribute(o, "nowhide")) {
foreach(s, o.nowhide) {
if (GetObject(s) = null) {
msg ("Topic " + o.name + " tries to hide a non-existent topic, " + s)
}
}
}
}
}
msg("Talkers found: " + charcount)
msg("Topics found: " + topiccount)
]]></function>
<!--
Gets a list of current topics for the given character
-->
<function name="GetTopics" type="objectlist" parameters="char">
// List of topics
lst = NewObjectList ()
// option to get topics from [charname]_topics, rather than the character itself
topics = GetObject(char.name + "_topics")
if (topics = null) {
topics = char
}
foreach (obj, GetDirectChildren(topics)) {
_AddTopic (lst, obj)
}
// now grab topics for the room
foreach (obj, GetDirectChildren(game.pov.parent)) {
if (StartsWith(obj.name, char.name)) {
_AddTopic (lst, obj)
}
}
AddExtraTopics(char, lst)
return (lst)
</function>
<!--
Add the given object to the list if (1) it is a topic, (2) "display" is set and (3) "hidden" not set.
Will throw an error if it has no alias.
-->
<function name="_AddTopic" parameters="lst, obj"><![CDATA[
if (DoesInherit (obj, "topic") and GetBoolean (obj, "display") and not GetBoolean (obj, "hidden")) {
if (obj.alias = null) error ("ERROR: Found topic with no alias: " + obj.name)
list add (lst, obj)
}
]]></function>
<!--
Returns true if the given character has any current topics.
-->
<function name="HasTopics" parameters="char" type="boolean"><![CDATA[
return(not ListCount(GetTopics(char)) = 0)
]]></function>
<!--
Activates the listed topics. These should be given in a single string,
separated by vertical bars.
As usual, topics that have already been used will not appear
-->
<function name="SetTopics" parameters="str">
foreach (s, Split(str, "|")) {
do(GetObject(s), "show")
}
</function>
<!--
If any of your topics expire, this must be called every turn to ensure they update.
This is not automatically put in a turn script to allow you to choose what counts as a turn.
You may like to only have this called if it was a proper turn.
-->
<function name="IncConvTime"><![CDATA[
foreach (o, AllObjects()) {
if (DoesInherit(o, "topic")) {
if (o.expires and o.display and not o.hidden) {
o.countdown = o.countdown - 1
if (o.countdown < 0) {
o.display = false
o.hidden = true
}
}
}
}
]]></function>
<function name="Converse" parameters="char, title"><![CDATA[
game.conversationalist = char
game.currenttopics = GetTopics(char)
// no topics found?
if (ListCount (game.currenttopics) = 0) {
if (DoesInherit(char, "talkingchar")) {
P (DynamicTemplate("NoSpeakTopics", char))
}
else {
P (DynamicTemplate("NoConsultTopics", char))
}
}
else {
// show the menu
ShowMenu (title, ListFromAtts(game.currenttopics, "alias"), not char.forcedconversations) {
if (not result = null) {
// if this is the first meeting, do the greeting if available
if (game.conversationalist.nevermet) {
if (not LengthOf(game.conversationalist.exchange) = 0) {
P(game.conversationalist.exchange)
}
if (HasScript (game.conversationalist, "greet")) {
do (game.conversationalist, "greet")
}
game.conversationalist.nevermet = false
game.conversationalist.firstmetroom = game.conversationalist.parent
}
// find the right topic
foreach (o, game.currenttopics) {
if (o.alias = result) {
// do the topics conversation
do (o, "topictalk")
terminate = o.terminal
}
}
if (not IsDefined ("terminate")) error ("Failed to find the conversation topic. If this is in a walk-though, it might be because the topic's alias has changed and the walk-through has not been updated.")
game.conversationalist.chatcount = game.conversationalist.chatcount + 1
AfterTopicEvent
on ready {
if (not terminate and game.conversationalist.activeconversations and not ListCount(GetTopics(game.conversationalist)) = 0) {
do(game.conversationalist, "speak")
}
}
}
}
}
]]></function>
<!--
-->
<function name="SetValue" parameters="s, char"><![CDATA[
ary = Split(s, " ")
if (ListCount(ary) < 3) error ("Insufficient arguments in reaction for " + char.name + ": " + s)
sign = StringListItem(ary, 0)
if (ListCount(ary) < 4 and not sign = "&") error ("Insufficient arguments in reaction that is not & for " + char.name + ": " + s)
list remove(ary, sign)
objname = StringListItem(ary, 0)
list remove(ary, objname)
if (objname = "this") {
obj = char
}
else {
obj = GetObject(objname)
}
if (obj = null) error ("Object not found in reaction for " + objname + ": " + s)
attname = StringListItem(ary, 0)
list remove(ary, attname)
if (sign = "&") {
do(obj, attname)
}
else {
value = Eval(Replace(Join(ary, " "), "this", char.name))
if (sign = "=") {
set(obj, attname, value)
}
else {
oldvalue = GetAttribute (obj, attname)
if (sign = "-") {
value = -value
}
if (TypeOf(oldvalue) = "null") {
set(obj, attname, value)
}
else {
set(obj, attname, oldvalue + value)
}
}
}
]]></function>
<!--
Compiles a string list from the given object list, each entry being the given attribute
of the entry in the original list.
-->
<function name="ListFromAtts" type="stringlist" parameters="objectlist, attname">
l2 = NewStringList()
foreach(o, objectlist) {
list add (l2, GetString(o, attname))
}
return(l2)
</function>
<!--
Show the given topic. Note that if the topic has already been shown and then hidden, this will have no effect.
-->
<function name="ShowTopic" parameters="o">
do(o, "show")
</function>
<!--
Hide the given topic. Note that if the topic is not currently shown, this will stop it ever appearing.
-->
<function name="HideTopic" parameters="o">
do(o, "hide")
</function>
<function name="Shift" parameters="l" type="string">
s = StringListItem(l, 0)
list remove (l, s)
return (s)
</function>
<function name="GetReactions" parameters="text" type="stringlist"><![CDATA[
l = NewStringList()
foreach (s, Split(text, "@")) {
l2 = NewStringList()
foreach (s2, Split(s, "<br/>")) {
if (not StartsWith(s2, "#") and LengthOf(s2) > 1) {
list add (l2, s2)
}
}
list add (l, Join(l2, "<br/>"))
}
Shift (l)
return (l)
]]></function>
<turnscript name="ReactionsTurnScript">
<enabled />
<script><![CDATA[
if (not GetBoolean(game, "showreactions")) {
this.enabled = false
}
else {
foreach (o, GetDirectChildren(game.pov.parent)) {
if (HasString(o, "reactions")) {
// First create reactionslist, if we have not already done so
if (not HasAttribute(o, "reactionslist")) {
o.reactionslist = GetReactions(o.reactions)
}
continue = true
o.reactionstodelete = NewStringList()
foreach (s, o.reactionslist) {
if (continue) {
ary = Split(s, "<br/>")
//Shift(ary)
name = Shift(ary)
test = Replace(Shift(ary), "this", o.name)
flag = Eval(test)
if (flag) {
d = NewDictionary()
dictionary add(d, "name", name)
dictionary add(d, "list", ary)
do (o, "doreaction", d)
continue = false
}
}
}
do(o, "deleteoldreactions")
}
}
}
]]></script>
</turnscript>
<type name="topicuser">
<state type="int">0</state>
<chatcount type="int">0</chatcount>
<usedefaultprefix type="boolean">false</usedefaultprefix>
<activeconversations type="boolean">false</activeconversations>
<forcedconversations type="boolean">false</forcedconversations>
<exchange type="string"></exchange>
<nevermet />
</type>
<type name="talkingchar">
<inherit name="topicuser" />
<animal type="boolean">false</animal>
<speak type="script">
// First check if we can even talk to this character
if (PlayerCannotTalkTo(this)) {
// do nothing
}
else if (HasString(game.pov, "gagstring")) {
P (game.pov.gagstring)
}
else if (HasString(this, "gagstring")) {
P (this.gagstring)
}
else {
Converse(this, DynamicTemplate("TalkAbout", this))
}
</speak>
<quiet type="script">
topics = GetObject(this.name + "_topics")
foreach (obj, GetDirectChildren(topics)) {
if (DoesInherit (obj, "topic") and GetBoolean (obj, "display")) {
obj.display = false
}
}
</quiet>
<colourmylistalias type="script"><![CDATA[
if (HasString(this, "alias")) {
s = CapFirst(this.alias)
}
else {
s = CapFirst(this.name)
}
if (HasString(this, "listalias")) s = this.listalias
this.listalias = "<span style=\"color:#00C000;font-weight:bold;\">" + s + "</span>"
]]></colourmylistalias>
<doreaction type="script"><![CDATA[
//msg("here")
//msg("name=" + name)
list add (this.reactionstodelete, name)
foreach (s2, list) {
if (IsRegexMatch("^(=|\\+|\\-|&) ", s2)) {
SetValue(s2, this)
}
else if (StartsWith(s2, "~")) {
list add (this.reactionstodelete, Trim(Mid(s2, 2)))
}
else if (not StartsWith(s2, "#") and LengthOf(s2) > 1) {
P(s2)
}
}
]]></doreaction>
<deleteoldreactions type="script"><![CDATA[
//msg("ToDelete1=" + this.reactionstodelete)
l2 = NewStringList()
foreach (s, this.reactionslist) {
//msg("Looking at---" + s)
foreach(s3, this.reactionstodelete) {
//msg("Compared to---" + s3 + "---")
if (StartsWith(s, s3 + "<br")) {
//msg("Deleting=" + s3)
list add (l2, s)
}
}
}
//msg("ToDelete2=" + l2)
foreach (s, l2) {
list remove (this.reactionslist, s)
}
//msg("Done")
]]></deleteoldreactions>
</type>
<type name="consultable">
<inherit name="topicuser" />
<displayverbs type="listextend">Consult</displayverbs>
<inventoryverbs type="listextend">Consult</inventoryverbs>
<consult type="script">
// You want to re-write this so you can, for example, test the thing is turned on
if (HasBoolean(this, "switchedon")) {
if (not this.switchedon) {
P(DynamicTemplate("ConsultableSwitchedOff", this))
}
else {
Converse(this, DynamicTemplate("ConsultAbout", this))
}
}
else {
Converse(this, DynamicTemplate("ConsultAbout", this))
}
</consult>
</type>
<type name="topic">
<count type="int">0</count>
<terminal type="boolean">false</terminal>
<display type="boolean">false</display>
<hidden type="boolean">false</hidden>
<visible type="boolean">false</visible>
<expires type="boolean">false</expires>
<countdown type="int">1</countdown>
<hideafter type="boolean">true</hideafter>
<nowshow type="stringlist"></nowshow>
<nowhide type="stringlist"></nowhide>
<exchange type="string"></exchange>
<show type="script">
if (not this.hidden) this.display = true
</show>
<hide type="script">
this.display = false
this.hidden = true
</hide>
<topictalk type="script">
// hide this topic
if (this.hideafter) {
do (this, "hide")
}
if (this.count = 0) {
// show other topics
foreach (t, this.nowshow) {
if (not t = "") {
to = GetObject (t)
if (to = null) error ("Failed to find conversation topic \"" + t + "\" for " + this.name)
to.display = true
}
}
// hide other topics
foreach (t, this.nowhide) {
if (not t = "") {
to = GetObject (t)
if (to = null) error ("Failed to find conversation topic \"" + t + "\" for " + this.name)
do(to, "hide")
}
}
}
// print the text, if there is any
if (not LengthOf(this.exchange) = 0) P(this.exchange)
// run the script if there is one
if (HasScript(this, "talk")) do (this, "talk")
this.count = this.count + 1
if (ListCount(GetTopics(game.conversationalist)) = 0 and HasScript(game.conversationalist, "nomoretopics")) {
do(game.conversationalist, "nomoretopics")
}
</topictalk>
</type>
<type name="startingtopic">
<inherit name="topic" />
<display type="boolean">true</display>
</type>
<!-- Interface -->
<tab>
<parent>_ObjectEditor</parent>
<caption>Conversation</caption>
<mustnotinherit>editor_room; defaultplayer</mustnotinherit>
<control>
<controltype>dropdowntypes</controltype>
<caption>Type</caption>
<types>*=None; talkingchar=Character; consultable=Consultable; topic=Conversation Topic; startingtopic=Starting Conversation Topic</types>
<width>150</width>
</control>
<control>
<caption>Keep conversations active</caption>
<controltype>checkbox</controltype>
<attribute>activeconversations</attribute>
<width>200</width>
<mustinherit>talkingchar</mustinherit>
</control>
<control>
<caption>Force player to converse</caption>
<controltype>checkbox</controltype>
<attribute>forcedconversations</attribute>
<width>200</width>
<mustinherit>talkingchar</mustinherit>
</control>
<control>
<caption>The greeting</caption>
<controltype>richtext</controltype>
<attribute>exchange</attribute>
<mustinherit>topicuser</mustinherit>
</control>
<control>
<caption>Run this greeting script</caption>
<controltype>script</controltype>
<attribute>greet</attribute>
<mustinherit>topicuser</mustinherit>
</control>
<control>
<caption>Automatically hide after showing</caption>
<controltype>checkbox</controltype>
<attribute>hideafter</attribute>
<width>200</width>
<mustinherit>topic</mustinherit>
</control>
<control>
<caption>Terminates an active conversation</caption>
<controltype>checkbox</controltype>
<attribute>terminal</attribute>
<width>200</width>
<mustinherit>topic</mustinherit>
</control>
<control>
<caption>Topic expires?</caption>
<controltype>checkbox</controltype>
<attribute>expires</attribute>
<width>200</width>
<mustinherit>topic</mustinherit>
</control>
<control>
<controltype>label</controltype>
<caption>You need a turnscript that calls IncConvTime to make this work.</caption>
<onlydisplayif>DoesInherit(this, "topic") and this.expires</onlydisplayif>
</control>
<control>
<caption>Hide after this many turns</caption>
<controltype>number</controltype>
<attribute>countdown</attribute>
<width>200</width>
<onlydisplayif>DoesInherit(this, "topic") and this.expires</onlydisplayif>
</control>
<control>
<caption>Follow-on topics. Show these after showing for the first time (must be the name, not the alias)</caption>
<controltype>list</controltype>
<attribute>nowshow</attribute>
<width>200</width>
<mustinherit>topic</mustinherit>
</control>
<control>
<caption>Exclusive topics. Hide these after showing for the first time (must be the name, not the alias)</caption>
<controltype>list</controltype>
<attribute>nowhide</attribute>
<width>200</width>
<mustinherit>topic</mustinherit>
</control>
<control>
<caption>The conversation</caption>
<controltype>richtext</controltype>
<attribute>exchange</attribute>
<mustinherit>topic</mustinherit>
</control>
<control>
<caption>Run this script</caption>
<controltype>script</controltype>
<attribute>talk</attribute>
<mustinherit>topic</mustinherit>
</control>
<control>
<controltype>label</controltype>
<caption>Instructions for use</caption>
<href>https://github.com/ThePix/quest/wiki/Conversations:-Library</href>
</control>
</tab>
<tab>
<parent>_ObjectEditor</parent>
<caption>Reactions</caption>
<onlydisplayif>game.showreactions</onlydisplayif>
<mustinherit>talkingchar</mustinherit>
<onlydisplayif>game.showreactions</onlydisplayif>
<control>
<caption>Reaction script (run after every turn in same room as player)</caption>
<controltype>richtext</controltype>
<attribute>reactions</attribute>
<mustinherit>talkingchar</mustinherit>
<onlydisplayif>game.showreactions</onlydisplayif>
</control>
</tab>
</library>