forked from ThePix/quest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackLib.aslx
More file actions
272 lines (226 loc) · 7.42 KB
/
StackLib.aslx
File metadata and controls
272 lines (226 loc) · 7.42 KB
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
<?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..."
-->
<!--
StackLib v1.1
Quest version: 5.6 (ideally 5.7 for pile of cash)
Written by: The Pixie, 2016-2017
Inspired by Sora's stackable library
Tutorial and notes here:
https://github.com/ThePix/quest/wiki/StackLibrary
-->
<!--
This should be called each time the stack content changes to keep it up to date.
You can send either the stack itself of a member of the stack.
-->
<function name="SetStack" parameters="container"><![CDATA[
if (DoesInherit(container, "childstack_object")) {
container = container.stackparent
}
if (not HasString(container, "originalalias")) {
if (HasString(container, "listalias")) {
container.originalalias = container.listalias
}
else {
container.originalalias = container.alias
}
}
stacked_count = ListCount(GetDirectChildren(container))
if (stacked_count = 0) {
container.parent = Stack Containers
}
else if (stacked_count = 1) {
container.gender = "it"
container.article = "it"
if (container.parent = Stack Containers) {
container.parent = game.pov
}
}
else {
container.gender = "they"
container.article = "them"
}
container.listalias = container.originalalias + ": " + ToString(stacked_count)
]]></function>
<!--
Remove an item from the given stack. If there is more than one
there, the player will be asked to choose.
-->
<function name="Unstack" parameters="container"><![CDATA[
DoStackStuff(container, "_Unstack", null, "Drop which one?")
]]></function>
<!--
Use an item from the given stack. If there is more than one
there, the player will be asked to choose.
-->
<function name="UseInStack" parameters="container"><![CDATA[
DoStackStuff(container, "_UseInStack", null, "Use which one?")
]]></function>
<!--
Use an item from the given stack. If there is more than one
there, the player will be asked to choose.
-->
<function name="LookInStack" parameters="container"><![CDATA[
DoStackStuff(container, null, "look", "Look at which one?")
]]></function>
<!--
Use an item from the given stack. If there is more than one
there, the player will be asked to choose.
-->
<function name="ConsumeInStack" parameters="container"><![CDATA[
DoStackStuff(container, null, "consume", "Consume which one?")
]]></function>
<!--
Use an item from the given stack. If there is more than one
there, the player will be asked to choose.
-->
<function name="DoStackVerb" parameters="container, verb"><![CDATA[
DoStackStuff(container, null, verb, CapFirst(verb) + " which one?")
]]></function>
<!--
Do something with an item from the given stack. If there is more than one
there, the player will be asked to choose.
This will then call a script on the object, if script is not null, or
otherwise the given function.
s is the prompt.
-->
<function name="DoStackStuff" parameters="container, functionname, scriptname, s"><![CDATA[
//msg("container="+container)
//msg("functionname="+functionname)
//msg("scriptname="+scriptname)
//msg("s="+s)
if (container.homogeneous or ListCount(GetDirectChildren(container)) = 1) {
game.functionname_tmp = functionname
game.scriptname_tmp = scriptname
DoingStackStuff(ObjectListItem(GetDirectChildren(container), 0))
}
else {
dic = NewStringDictionary()
foreach (o, GetDirectChildren(container)) {
dictionary add (dic, o.name, o.alias)
}
game.functionname_tmp = functionname
game.scriptname_tmp = scriptname
ShowMenu (s, dic, true) {
if (not result = null) {
DoingStackStuff(GetObject(result))
}
}
}
]]></function>
<function name="DoingStackStuff" parameters="obj"><![CDATA[
stack = obj.parent
if (not game.scriptname_tmp = null) {
PrintOrRun(obj, game.scriptname_tmp)
}
else {
game.tempobj = obj
f = Eval (game.functionname_tmp + "(game.tempobj)")
}
SetStack(stack)
]]></function>
<function name="_Unstack" parameters="object" type="boolean"><![CDATA[
container = object.stackparent
object.parent = game.pov.parent
SetStack(container)
msg("You drop " + GetDisplayName(object) + ".")
if (HasScript(object, "ondrop")) do(object, "ondrop")
return(true)
]]></function>
<function name="_UseInStack" parameters="object" type="boolean"><![CDATA[
dic = NewDictionary()
dictionary add (dic, "object", object)
do(use, "script", dic)
SetStack(object)
return(true)
]]></function>
<!--
-->
<function name="PrintOrRun" parameters="obj, att">
if (HasScript(obj, att)) {
do (obj, att)
}
if (HasString(obj, att)) {
msg (GetString(obj, att))
}
</function>
<type name="stack_container">
<parent type="object">game</parent>
<homogeneous type="boolean">false</homogeneous>
<drop type="script">
Unstack (this)
</drop>
<use type="script">
UseInStack (this)
</use>
<consume type="script">
ConsumeInStack (this)
</consume>
<look type="script">
LookInStack (this)
</look>
</type>
<type name="homo_stack_container">
<inherit name="stack_container" />
<homogeneous/>
</type>
<type name="childstack_object">
<isstackable />
<drop type="boolean">false</drop>
<takemsg>You take it.</takemsg>
<take type="script">
if (this.alias = null) {
this.alias = this.name
}
container = this.stackparent
this.parent = container
SetStack(container)
if (this.takemsg = null) {
msg(DynamicTemplate("TakeSuccessful", object))
}
else {
msg (this.takemsg)
}
</take>
</type>
<type name="cash_object">
<drop type="boolean">false</drop>
<money type="int">1</money>
<takemsg>You take it.</takemsg>
<take type="script">
this.parent = null
game.pov.money = game.pov.money + this.money
if (this.takemsg = null) {
msg(DynamicTemplate("TakeSuccessful", object))
}
else {
msg (this.takemsg)
}
</take>
</type>
<tab>
<parent>_ObjectEditor</parent>
<caption>Stackable</caption>
<mustnotinherit>editor_room; editor_player</mustnotinherit>
<control>
<controltype>dropdowntypes</controltype>
<types>*=Not stackable; stack_container=Heterogeneous stack; homo_stack_container=Homogeneous stack;childstack_object=Member of a stack;cash_object=Pile of cash</types>
<caption>Stack</caption>
</control>
<control>
<controltype>objects</controltype>
<attribute>stackparent</attribute>
<mustinherit>childstack_object</mustinherit>
<caption>Stack container</caption>
</control>
<control>
<controltype>number</controltype>
<attribute>money</attribute>
<mustinherit>cash_object</mustinherit>
<caption>Amount</caption>
</control>
</tab>
</library>