Debian Codegraph @

terps/frankendrift/FrankenDrift.Adrift/Global.vb

raw
1 Imports System.Drawing
2 Imports FrankenDrift.Glue
3 Imports FrankenDrift.Glue.Util
4
5 Public Module SharedModule
6 Public Property Adventure As clsAdventure
7 Public Glue As UIGlue
8 Public fRunner As frmRunner
9 Public UserSession As RunnerSession
10
11 Public Blorb As clsBlorb
12 Public iLoading As Integer
13 Public dVersion As Double = 5.0
14 Public Const ANYOBJECT As String = "AnyObject"
15 Public Const ANYCHARACTER As String = "AnyCharacter"
16 Public Const ANYDIRECTION As String = "AnyDirection"
17 Public Const NOOBJECT As String = "NoObject"
18 Public Const NOCHARACTER As String = "NoCharacter"
19 Public Const ALLROOMS As String = "AllLocations"
20 Public Const NOROOMS As String = "NoLocations"
21 Public Const THEFLOOR As String = "TheFloor"
22 Public Const THEPLAYER As String = "%Player%"
23 Public Const CHARACTERPROPERNAME As String = "CharacterProperName"
24 Public Const PLAYERLOCATION As String = "PlayerLocation"
25 Public Const HIDDEN As String = "Hidden"
26
27 Public Const DEFAULT_BACKGROUNDCOLOUR As Integer = -16777216
28 Public Const DEFAULT_INPUTCOLOUR As Integer = -3005145
29 Public Const DEFAULT_OUTPUTCOLOUR As Integer = -15096438
30 Public Const DEFAULT_LINKCOLOUR As Integer = -11806788
31
32 ' Mandatory properties
33 Public Const SHORTLOCATIONDESCRIPTION As String = "ShortLocationDescription"
34 Public Const LONGLOCATIONDESCRIPTION As String = "LongLocationDescription"
35 Public Const OBJECTARTICLE As String = "_ObjectArticle"
36 Public Const OBJECTPREFIX As String = "_ObjectPrefix"
37 Public Const OBJECTNOUN As String = "_ObjectNoun"
38
39
40 Public Const sLOCATION As String = "Location"
41 Public Const sOBJECT As String = "Object"
42 Public Const sTASK As String = "Task"
43 Public Const sEVENT As String = "Event"
44 Public Const sCHARACTER As String = "Character"
45 Public Const sGROUP As String = "Group"
46 Public Const sVARIABLE As String = "Variable"
47 Public Const sPROPERTY As String = "Property"
48 Public Const sHINT As String = "Hint"
49 Public Const sALR As String = "Text Override"
50 Public Const sGENERAL As String = "General"
51 Public Const sSELECTED As String = "<Selected>"
52 Public Const sUNSELECTED As String = "<Unselected>"
53
54 Public iImageSizeMode As Integer
55
56 Public Enum PerspectiveEnum
57 None = 0
58 FirstPerson = 1 ' I/Me/Myself
59 SecondPerson = 2 ' You/Yourself
60 ThirdPerson = 3 ' He/She/Him/Her
61 ' It
62 ' We
63 ' They
64 End Enum
65
66 Public Enum ReferencesType
67 [Object]
68 Character
69 Number
70 Text
71 Direction
72 Location
73 Item
74 End Enum
75
76 Public Enum ArticleTypeEnum
77 Definite ' The
78 Indefinite ' A
79 None
80 End Enum
81
82 #Region "Microsoft.VisualBasic compatability"
83
84 Public Function Asc(ByVal c As Char) As Integer
85 Return Convert.ToInt32(c)
86 End Function
87 Public Function Asc(ByVal s As String) As Integer
88 Return System.Text.Encoding.Default.GetBytes(s(0))(0)
89 End Function
90
91 #End Region
92
93 Public ReadOnly Property BinPath(Optional ByVal bSeparatorCharacter As Boolean = False) As String
94 Get
95 Return Application.StartupPath & If(bSeparatorCharacter, IO.Path.DirectorySeparatorChar, "").ToString
96 End Get
97 End Property
98 Public ReadOnly Property DataPath(Optional ByVal bSeparatorCharacter As Boolean = False) As String
99 Get
100 Dim sPath As String
101 sPath = Application.LocalUserAppDataPath
102 If Not IO.Directory.Exists(sPath) Then IO.Directory.CreateDirectory(sPath)
103 Return sPath & If(bSeparatorCharacter, IO.Path.DirectorySeparatorChar, "").ToString
104 End Get
105 End Property
106
107 Private sWarnings As New List(Of String)
108 Public Sub WarnOnce(ByVal sMessage As String)
109
110 If Not sWarnings.Contains(sMessage) Then
111 ErrMsg(sMessage)
112 sWarnings.Add(sMessage)
113 End If
114
115 End Sub
116
117 Private r As Random
118 Public Function Random(ByVal iMax As Integer) As Integer
119 If r Is Nothing Then r = New Random(GetNextSeed)
120 Return r.Next(iMax + 1)
121 End Function
122 Public Function Random(ByVal iMin As Integer, ByVal iMax As Integer) As Integer
123 If r Is Nothing Then r = New Random(GetNextSeed)
124 If iMax < iMin Then
125 Dim i As Integer = iMax
126 iMax = iMin
127 iMin = i
128 End If
129 Return r.Next(iMin, iMax + 1)
130 End Function
131
132 Private Function GetNextSeed() As Integer
133 Static iLastSeed As Integer = 0
134
135 Dim iNextSeed As Integer = CInt(Now.Ticks Mod Integer.MaxValue)
136 While iNextSeed = iLastSeed
137 iNextSeed -= Now.Millisecond
138 End While
139 iLastSeed = iNextSeed
140
141 Return iNextSeed
142
143 End Function
144
145
146 Public Enum DirectionsEnum
147 North = 0
148 East = 1
149 South = 2
150 West = 3
151 Up = 4
152 Down = 5
153 [In] = 6
154 Out = 7
155 NorthEast = 8
156 SouthEast = 9
157 SouthWest = 10
158 NorthWest = 11
159 End Enum
160
161 Public Enum ItemEnum
162 Location
163 [Object]
164 Task
165 [Event]
166 Character
167 Group
168 Variable
169 [Property]
170 Hint
171 ALR
172 General
173 End Enum
174
175 Public Sub GlobalStartup()
176 Dim version As Version = New Version(Application.ProductVersion)
177 dVersion = CDbl(version.Major & System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator & Format(version.Minor, "000") & Format(version.Build, "000") & Format(version.Revision))
178 End Sub
179
180 Friend Function IsHex(ByVal sHex As String) As Boolean
181 For i As Integer = 0 To sHex.Length - 1
182 If "0123456789ABCDEF".IndexOf(sHex(i)) = -1 Then Return False
183 Next
184 Return True
185 End Function
186
187 Public Function ItemToString(ByVal item As ItemEnum, Optional ByVal bPlural As Boolean = False) As String
188 ItemToString = ""
189
190 Select Case item
191 Case ItemEnum.Location
192 ItemToString = sLOCATION
193 Case ItemEnum.Object
194 ItemToString = sOBJECT
195 Case ItemEnum.Task
196 ItemToString = sTASK
197 Case ItemEnum.Event
198 ItemToString = sEVENT
199 Case ItemEnum.Character
200 ItemToString = sCHARACTER
201 Case ItemEnum.Group
202 ItemToString = sGROUP
203 Case ItemEnum.Variable
204 ItemToString = sVARIABLE
205 Case ItemEnum.Property
206 ItemToString = sPROPERTY
207 Case ItemEnum.Hint
208 ItemToString = sHINT
209 Case ItemEnum.ALR
210 ItemToString = sALR
211 Case ItemEnum.General
212 ItemToString = sGENERAL
213 End Select
214
215 If bPlural Then
216 Select Case item
217 Case ItemEnum.Location, ItemEnum.Object, ItemEnum.Task, ItemEnum.Event, ItemEnum.Character, ItemEnum.Group, ItemEnum.Variable, ItemEnum.Hint, ItemEnum.ALR, ItemEnum.General
218 Return ItemToString & "s"
219 Case ItemEnum.Property
220 Return "Properties"
221 End Select
222 End If
223 End Function
224
225 Public Sub ErrMsg(ByVal sMessage As String, Optional ByVal ex As System.Exception = Nothing)
226 Glue.ErrMsg(sMessage, ex)
227 End Sub
228
229 Public Function CharacterCount(ByVal sText As String, ByVal cCharacter As Char) As Integer
230 CharacterCount = 0
231 For i As Integer = 0 To sText.Length - 1
232 If sText.Substring(i, 1) = cCharacter Then CharacterCount += 1
233 Next
234 End Function
235
236
237 Public Function GetLibraries() As String()
238
239 Dim sLibraries As String = GetSetting("ADRIFT", "Generator", "Libraries")
240
241 If sLibraries = "" Then
242 ' Attempt to find the libarary in current directory
243 Dim SL As String = "StandardLibrary.amf"
244
245 For Each sDir As String In New String() {IO.Path.GetDirectoryName(SafeString(Application.ExecutablePath)), DataPath}
246 If IO.File.Exists(sDir & IO.Path.DirectorySeparatorChar & SL) Then
247 sLibraries = sDir & IO.Path.DirectorySeparatorChar & SL
248 Exit For
249 End If
250 Next
251 End If
252
253 Return sLibraries.Split("|"c)
254
255 End Function
256
257 ' A replacement for VB.Left - Substring returns an error if you try to access part of the string that doesn't exist.
258 Public Function sLeft(ByVal sString As String, ByVal iLength As Integer) As String
259 If sString Is Nothing OrElse iLength < 0 Then Return ""
260 If sString.Length < iLength Then
261 If sString <> Left(sString, iLength) Then
262 sString = sString
263 End If
264 Return sString
265 Else
266 If sString.Substring(0, Math.Max(iLength, 0)) <> Left(sString, iLength) Then
267 sString = sString
268 End If
269 Return sString.Substring(0, Math.Max(iLength, 0))
270 End If
271 End Function
272
273 ' A replacement for VB.Right
274 Public Function sRight(ByVal sString As String, ByVal iLength As Integer) As String
275 If sString Is Nothing OrElse iLength < 0 Then Return ""
276 If iLength > sString.Length Then
277 If sString <> Right(sString, iLength) Then
278 sString = sString
279 End If
280 Return sString
281 Else
282 If sString.Substring(sString.Length - iLength) <> Right(sString, iLength) Then
283 sString = sString
284 End If
285 Return sString.Substring(sString.Length - iLength)
286 End If
287 End Function
288
289 ' A replacement for VB.Mid
290 Public Function sMid(ByVal sString As String, ByVal iStart As Integer) As String
291 If sString Is Nothing Then Return ""
292 If iStart < 1 Then iStart = 1
293 If iStart > sString.Length Then
294 Return ""
295 Else
296 Return sString.Substring(iStart - 1)
297 End If
298 End Function
299
300 Public Function sMid(ByVal sString As String, ByVal iStart As Integer, ByVal iLength As Integer) As String
301 If sString Is Nothing Then Return ""
302 If iLength < 0 Then Return ""
303 If iStart < 1 Then iStart = 1
304 If iStart > sString.Length Then
305 Return ""
306 ElseIf iLength > sString.Length OrElse iLength + iStart > sString.Length Then
307 Return sString.Substring(iStart - 1)
308 Else
309 Return sString.Substring(iStart - 1, iLength)
310 End If
311 End Function
312
313
314 Public Function sInstr(ByVal sText As String, ByVal sSearchFor As String) As Integer
315 If InStr(sText, sSearchFor) <> sInstr(1, sText, sSearchFor) Then
316 sText = sText
317 End If
318 Return sInstr(1, sText, sSearchFor)
319 End Function
320 Public Function sInstr(ByVal startIndex As Integer, ByVal sText As String, ByVal sSearchFor As String) As Integer
321 If sText Is Nothing OrElse sText = "" Then Return 0 ' -1
322 If sText.IndexOf(sSearchFor, startIndex - 1) + 1 <> InStr(startIndex, sText, sSearchFor) Then
323 sText = sText
324 End If
325 Return sText.IndexOf(sSearchFor, startIndex - 1) + 1
326 End Function
327
328 Public Sub Source2HTML(ByVal sSource As String, ByRef RichText As RichTextBox, ByVal bClearRTB As Boolean, Optional ByVal bDebug As Boolean = False, Optional ByRef sUnprocessedText As String = Nothing)
329 Glue.OutputHTML(sSource)
330 End Sub
331
332 ' Escape any characters that are special in RE's
333 Friend Function MakeTextRESafe(ByVal sText As String) As String
334 sText = sText.Replace("+", "\+").Replace("*", "\*")
335
336 Return sText
337 End Function
338
339
340 Friend Function invhex(ByVal hexcode As String) As Byte
341 Dim n As Byte
342
343 If Left(hexcode, 1) = "0" Then
344 For n = 0 To 15
345 If Hex(n) = UCase(Right(hexcode, 1)) Then Return n
346 Next n
347 End If
348 For n = 16 To 254
349 If Hex(n) = UCase(hexcode) Then Return n
350 Next n
351 If Hex(255) = UCase(hexcode) Then Return 255
352 Return 0
353 End Function
354
355 Friend Function ColourLookup(ByVal sCode As String) As String
356 sCode = sCode.Replace("""", "")
357
358 ColourLookup = Nothing
359
360 Select Case LCase(sCode)
361 Case "black" : ColourLookup = "000000"
362 Case "blue" : ColourLookup = "0000ff"
363 Case "cyan", "turquoise", "aqua" : ColourLookup = "00ffff"
364 Case "default"
365 Case "gray" : ColourLookup = "808080"
366 Case "green" : ColourLookup = "008000"
367 Case "lime" : ColourLookup = "00ff00"
368 Case "magenta", "fuchsia" : ColourLookup = "ff00ff"
369 Case "maroon" : ColourLookup = "800000"
370 Case "navy" : ColourLookup = "000080"
371 Case "olive" : ColourLookup = "808000"
372 Case "orange" : ColourLookup = "ff8000"
373 Case "pink" : ColourLookup = "ff8888"
374 Case "purple" : ColourLookup = "800080"
375 Case "red" : ColourLookup = "ff0000"
376 Case "silver" : ColourLookup = "c0c0c0"
377 Case "teal" : ColourLookup = "008080"
378 Case "white" : ColourLookup = "ffffff"
379 Case "yellow" : ColourLookup = "ffff00"
380
381 Case Else
382 If Left(sCode, 1) = "#" Then sCode = Right(sCode, Len(sCode) - 1)
383 If Len(sCode) > 6 Then sCode = "ffffff"
384 While Len(sCode) < 6
385 sCode = sCode & "0"
386 End While
387 ColourLookup = sCode
388 End Select
389 End Function
390
391 Public Function DirectionName(ByVal dir As DirectionsEnum) As String
392 Dim sName As String = Adventure.sDirectionsRE(dir)
393 If sName.Contains("/") Then sName = sName.Substring(0, sName.IndexOf("/"))
394 Return sName
395 End Function
396
397
398
399 Public Function DirectionRE(ByVal dir As DirectionsEnum, Optional ByVal bBrackets As Boolean = True, Optional ByVal bRealRE As Boolean = False) As String
400 Dim sRE As String = Adventure.sDirectionsRE(dir).ToLower
401 If bRealRE Then sRE = sRE.Replace("/", "|")
402
403 If bBrackets Then
404 If bRealRE Then
405 Return "(" & sRE & ")"
406 Else
407 Return "[" & sRE & "]"
408 End If
409 Else
410 Return sRE
411 End If
412 End Function
413
414 Public Function KeyExists(ByVal sKey As String) As Boolean
415 With Adventure
416 If .htblLocations.ContainsKey(sKey) Then Return True
417 If .htblObjects.ContainsKey(sKey) Then Return True
418 If .htblTasks.ContainsKey(sKey) Then Return True
419 If .htblEvents.ContainsKey(sKey) Then Return True
420 If .htblCharacters.ContainsKey(sKey) Then Return True
421 If .htblGroups.ContainsKey(sKey) Then Return True
422 If .htblVariables.ContainsKey(sKey) Then Return True
423 If .htblALRs.ContainsKey(sKey) Then Return True
424 If .htblHints.ContainsKey(sKey) Then Return True
425 If .htblAllProperties.ContainsKey(sKey) Then Return True
426 End With
427 Return False
428 End Function
429
430 Public Function FindProperty(ByVal arlStates As StringArrayList) As String
431 Dim bMatch As Boolean
432
433 For Each prop As clsProperty In Adventure.htblAllProperties.Values
434 bMatch = True
435 If prop.arlStates.Count = arlStates.Count Then
436 For Each sState As String In arlStates
437 If Not prop.arlStates.Contains(sState) Then
438 bMatch = False
439 Exit For
440 End If
441 Next
442 If bMatch Then
443 Return prop.Key
444 End If
445 End If
446 Next
447
448 Return Nothing
449 End Function
450
451 Public Function ToProper(ByVal sText As String, Optional ByVal bForceRestLower As Boolean = True) As String
452 If bForceRestLower Then
453 Return sLeft(sText, 1).ToUpper & sRight(sText, sText.Length - 1).ToLower
454 Else
455 Return sLeft(sText, 1).ToUpper & sRight(sText, sText.Length - 1)
456 End If
457 End Function
458
459 Public Function FunctionNames() As StringArrayList
460 Dim Names As New StringArrayList
461 For Each sName As String In New String() {"AloneWithChar", "CharacterDescriptor", "CharacterName", "CharacterProper", "ConvCharacter", "DisplayCharacter", "DisplayLocation", "DisplayObject", "Held", "LCase", "ListCharactersOn", "ListCharactersIn", "ListCharactersOnAndIn", "ListHeld", "ListExits", "ListObjectsAtLocation", "ListWorn", "ListObjectsOn", "ListObjectsIn", "ListObjectsOnAndIn", "LocationName", "LocationOf", "NumberAsText", "ObjectName", "ObjectsIn", "ParentOf", "PCase", "Player", "PopUpChoice", "PopUpInput", "PrevListObjectsOn", "PrevParentOf", "ProperName", "PropertyValue", "Release", "Replace", "Sum", "TaskCompleted", "TheObject", "TheObjects", "Turns", "UCase", "Version", "Worn"}
462 Names.Add(sName)
463 Next
464 If Adventure IsNot Nothing Then
465 For Each UDF As clsUserFunction In Adventure.htblUDFs.Values
466 Names.Add(UDF.Name)
467 Next
468 End If
469 Return Names
470 End Function
471
472 Public Function ReferenceNames() As String()
473 Return New String() {"%object%", "%objects%", "%object1%", "%object2%", "%object3%", "%object4%", "%object5%", "%direction%", "%direction1%", "%direction2%", "%direction3%", "%direction4%", "%direction5%", "%character%", "%character1%", "%character2%", "%character3%", "%character4%", "%character5%", "%text%", "%text1%", "%text2%", "%text3%", "%text4%", "%text5%", "%number%", "%number1%", "%number2%", "%number3%", "%number4%", "%number5%", "%location%", "%location1%", "%location2%", "%location3%", "%location4%", "%location5%", "%item%", "%item1%", "%item2%", "%item3%", "%item4%", "%item5%"}
474 End Function
475
476 Public Function InstrCount(ByVal sText As String, ByVal sSubText As String) As Integer
477 Dim iOffset As Integer = 1
478 Dim iCount As Integer = 0
479
480 While iOffset < sText.Length
481 If sInstr(iOffset, sText, sSubText) > 0 Then
482 iCount += 1
483 iOffset = sInstr(iOffset, sText, sSubText) + 1
484 Else
485 Return iCount
486 End If
487 End While
488
489 Return iCount
490 End Function
491
492 Public Function EvaluateExpression(ByVal sExpression As String) As String
493 If sExpression = "" Then Return ""
494
495 Dim var As New clsVariable
496 var.Type = clsVariable.VariableTypeEnum.Text
497 var.SetToExpression(sExpression)
498 Return var.StringValue
499 End Function
500 Public Function EvaluateExpression(ByVal sExpression As String, ByVal bInt As Boolean) As Integer
501
502 Dim var As New clsVariable
503 var.Type = clsVariable.VariableTypeEnum.Numeric
504 var.SetToExpression(sExpression)
505 Return var.IntValue
506
507 End Function
508
509
510 Public Function ReplaceExpressions(ByVal sText As String) As String
511 Dim reExp As New System.Text.RegularExpressions.Regex("<#(?<expression>.*?)#>", System.Text.RegularExpressions.RegexOptions.Singleline)
512 For Each m As System.Text.RegularExpressions.Match In reExp.Matches(sText)
513 sText = sText.Replace(m.Value, EvaluateExpression(m.Groups("expression").Value))
514 Next
515 Return sText
516 End Function
517
518
519 Public Function ReplaceALRs(ByVal sText As String, Optional ByVal bAutoCapitalise As Boolean = True) As String
520 Try
521 If sText = "" Then Return ""
522
523 sText = ReplaceFunctions(sText)
524 sText = ReplaceExpressions(sText)
525
526 Dim bChanged As Boolean = False
527
528 ' Replace ALRs
529 For Each alr As clsALR In Adventure.htblALRs.Values
530 If sText.Contains(alr.OldText) Then
531 Dim sALR As String = alr.NewText.ToString ' Get it in a variable in case we have DisplayOnce
532 If sText = sALR Then Exit For
533 sText = sText.Replace(alr.OldText, ReplaceALRs(sALR, False))
534 End If
535 Next
536
537 ' Auto-capitalise - needs to happen after ALR replacements, as some replacements may be both intra and start of sentences
538 If bAutoCapitalise Then 'AndAlso bChanged Then
539 Dim reCap As New System.Text.RegularExpressions.Regex("^(?<cap>[a-z])|\n(?<cap>[a-z])|[a-z][\.\!\?] ( )?(?<cap>[a-z])")
540 While reCap.IsMatch(sText)
541 Dim match As System.Text.RegularExpressions.Match = reCap.Match(sText)
542 Dim sCap As String = match.Groups("cap").Value
543 Dim iIndex As Integer = match.Groups("cap").Index
544 sText = sText.Substring(0, iIndex) & sCap.ToUpper & sText.Substring(iIndex + sCap.Length)
545 bChanged = True
546 End While
547 End If
548
549 ' Do a second round of ALR replacements if we auto-capped anything, as user may want to replace the auto-capped version
550 If bChanged Then
551 For Each alr As clsALR In Adventure.htblALRs.Values
552 If sText.Contains(alr.OldText) Then
553 Dim sALR As String = alr.NewText.ToString ' Get it in a variable in case we have DisplayOnce
554 If sText = sALR Then Exit For
555 sText = sText.Replace(alr.OldText, ReplaceALRs(sALR, False))
556 End If
557 Next
558 End If
559
560 Return sText
561
562 Catch ex As Exception
563 ErrMsg("ReplaceALRs error", ex)
564 Return sText
565 End Try
566 End Function
567
568 Public Function pSpace(ByRef sText As String) As String
569 If sText Is Nothing OrElse sText.Length = 0 Then
570 sText = ""
571 Return sText
572 Else
573 If sText.EndsWith(vbLf) Then Return sText
574 End If
575
576 sText &= " "
577 Return sText
578 End Function
579
580
581 Public Sub DisplayError(ByVal sText As String)
582 ErrMsg(sText)
583 End Sub
584
585 ' A case ignoring search
586 Public Function Contains(ByVal sTextToSearchIn As String, ByVal sTextToFind As String, Optional ByVal bExactWord As Boolean = False, Optional ByVal iStart As Integer = 0) As Boolean
587 sTextToFind = sTextToFind.Replace(".", "\.")
588 Dim sPattern As String = If(bExactWord, "\b" & sTextToFind & "\b", sTextToFind).ToString
589 Dim regex As New System.Text.RegularExpressions.Regex(sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
590 Return regex.IsMatch(sTextToSearchIn.Substring(iStart))
591 End Function
592 Public Function ContainsWord(ByVal sTextToSearchIn As String, ByVal sTextToFind As String) As Boolean
593 Return Contains(sTextToSearchIn, sTextToFind, True)
594 End Function
595
596 Public Function PreviousFunction(ByVal sFunction As String, ByVal sArgs As String) As String
597 With UserSession
598 Dim sNewFunction As String = sFunction.Replace("prev", "")
599 Dim PreviousState As clsGameState = CType(.States.Peek, clsGameState) ' Note the previous state
600 .States.RecordState() ' Save where we are now
601 .States.RestoreState(PreviousState) ' Load up the previous state
602
603 PreviousFunction = ReplaceFunctions("%" & sNewFunction & "[" & sArgs & "]%")
604
605 .States.Pop() ' Get rid of the 'current' state and load it back as present
606 End With
607 End Function
608
609 ' Chops the last character off a string
610 Public Function ChopLast(ByVal sText As String) As String
611 If sText.Length > 0 Then
612 Return sText.Substring(0, sText.Length - 1)
613 Else
614 Return ""
615 End If
616 End Function
617
618 ' If this is in an expression, we need to replace anything with a quoted value
619 Public Function ReplaceOO(ByVal sText As String, ByVal bExpression As Boolean) As String
620
621 Dim reIgnore As New System.Text.RegularExpressions.Regex(".*?(?<embeddedexpression><#.*?#>).*?")
622 If reIgnore.IsMatch(sText) Then
623 Dim sMatch As String = reIgnore.Match(sText).Groups("embeddedexpression").Value
624 Dim sGUID As String
625 sGUID = ":" & System.Guid.NewGuid.ToString & ":"
626 Dim sReturn As String = ReplaceOO(sText.Replace(sMatch, sGUID), bExpression)
627 Return sReturn.Replace(sGUID, sMatch)
628 Else
629 ' Match anything unless it's between <# ... #> symbols
630 Dim re As New System.Text.RegularExpressions.Regex("(?!<#.*?)(?<firstkey>%?[A-Za-z][\w\|_]*%?)(?<nextkey>\.%?[A-Za-z][\w\|_]*%?(\(.+?\))?)+(?!.*?#>)")
631 Dim sPrevious As String = ""
632 Dim iStartAt As Integer = 0
633
634 While iStartAt < sText.Length AndAlso re.IsMatch(sText, iStartAt) ' AndAlso sText <> sPrevious
635 sPrevious = sText
636
637 Dim sMatch As String = re.Match(sText, iStartAt).Value
638 Dim bIntValue As Boolean = False
639 Dim sReplace As String = ReplaceOOProperty(sMatch, bInt:=bIntValue)
640 Dim iPrevStart As Integer = iStartAt
641 iStartAt = re.Match(sText, iStartAt).Index + sMatch.Length
642
643 If sReplace <> "#*!~#" Then
644 If sReplace.Contains(sMatch) Then sReplace = sReplace.Replace(sMatch, "*** RECURSIVE REPLACE ***")
645 If bExpression AndAlso Not bIntValue AndAlso Not Contains(sText, """" & sMatch & """", , iPrevStart + 1) Then sReplace = """" & sReplace & """"
646 sText = sText.Substring(0, iPrevStart) & Replace(sText, sMatch, sReplace, iPrevStart + 1, 1) 'sText = sText.Replace(sMatch, sReplace)
647 iStartAt += sReplace.Length - sMatch.Length
648 End If
649
650 End While
651
652 Return ReplaceFunctions(sText, , False)
653 End If
654 End Function
655
656 Private Function ReplaceOOProperty(ByVal sProperty As String, Optional ByVal ob As clsObject = Nothing, Optional ByVal ch As clsCharacter = Nothing, Optional ByVal loc As clsLocation = Nothing, Optional ByVal lst As List(Of clsItemWithProperties) = Nothing, Optional ByVal lstDirs As List(Of DirectionsEnum) = Nothing, Optional ByVal evt As clsEvent = Nothing, Optional sPropertyKey As String = Nothing, Optional ByRef bInt As Boolean = False) As String
657 Dim sFunction As String = sProperty
658 Dim sArgs As String = ""
659 Dim sRemainder As String = ""
660
661 Dim iIndexOfDot As Integer = sFunction.IndexOf(".")
662 Dim iIndexOfOB As Integer = sFunction.IndexOf("(")
663
664 If iIndexOfOB > -1 AndAlso sFunction.Contains(")") Then
665 Dim iIndexOfCB As Integer = sFunction.IndexOf(")", iIndexOfOB)
666 If iIndexOfDot > -1 Then
667 If iIndexOfDot < iIndexOfOB Then
668 sRemainder = sFunction.Substring(iIndexOfDot + 1)
669 sFunction = sFunction.Substring(0, iIndexOfDot)
670 Else
671 sArgs = sFunction.Substring(iIndexOfOB + 1, iIndexOfCB - iIndexOfOB - 1) '.ToLower
672 sRemainder = sFunction.Substring(iIndexOfCB + 2)
673 sFunction = sFunction.Substring(0, iIndexOfOB)
674 End If
675 Else
676 sArgs = sFunction.Substring(iIndexOfOB + 1, sFunction.LastIndexOf(")") - iIndexOfOB - 1) '.ToLower
677 sRemainder = sFunction.Substring(iIndexOfCB + 1)
678 sFunction = sFunction.Substring(0, iIndexOfOB)
679 End If
680 ElseIf iIndexOfDot > 0 Then
681 sRemainder = sFunction.Substring(iIndexOfDot + 1)
682 sFunction = sFunction.Substring(0, iIndexOfDot)
683 End If
684
685 If lst IsNot Nothing OrElse (lstDirs IsNot Nothing AndAlso (sFunction = "List" OrElse sFunction = "Count" OrElse sFunction = "Name" OrElse sFunction = "")) Then
686 Select Case sFunction
687 Case ""
688 Dim sResult As String = ""
689 If lst IsNot Nothing Then
690 For i As Integer = 0 To lst.Count - 1
691 sResult &= lst(i).Key
692 If i < lst.Count - 1 Then sResult &= "|"
693 Next
694 Else
695 For i As Integer = 0 To lstDirs.Count - 1
696 sResult &= lstDirs(i).ToString
697 If i < lstDirs.Count - 1 Then sResult &= "|"
698 Next
699 End If
700
701 Return sResult
702
703 Case "Count"
704 If lst IsNot Nothing Then
705 Return lst.Count.ToString
706 ElseIf lstDirs IsNot Nothing Then
707 Return lstDirs.Count.ToString
708 End If
709 bInt = True
710 Return "0"
711
712 Case "Sum"
713 Dim iSum As Integer = 0
714 If lst IsNot Nothing AndAlso sPropertyKey IsNot Nothing Then
715 For Each oItem As clsItemWithProperties In lst
716 If oItem.HasProperty(sPropertyKey) Then
717 iSum += oItem.htblProperties(sPropertyKey).IntData
718 End If
719 Next
720 End If
721 bInt = True
722 Return iSum.ToString
723
724 Case "Description"
725 Dim sResult As String = ""
726 For Each oItem As clsItem In lst
727 pSpace(sResult)
728 Select Case True
729 Case TypeOf oItem Is clsObject
730 sResult &= CType(oItem, clsObject).Description.ToString
731 Case TypeOf oItem Is clsCharacter
732 sResult &= CType(oItem, clsCharacter).Description.ToString
733 Case TypeOf oItem Is clsLocation
734 If CType(oItem, clsLocation).ViewLocation = "" Then
735 sResult &= "There is nothing of interest here."
736 Else
737 sResult &= CType(oItem, clsLocation).ViewLocation
738 End If
739 End Select
740 Next
741 Return sResult
742
743 Case "List", "Name"
744 ' List(and) - And separated list - Default
745 ' List(or) - Or separated list
746 Dim sSeparator As String = " and "
747 Dim sArgsTest As String = sArgs.ToLower
748
749 If sArgsTest.Contains("or") Then sSeparator = " or "
750 If sArgsTest.Contains("rows") Then sSeparator = vbCrLf
751
752 ' List(definite/the) - List the objects names - Default
753 ' List(indefinite) - List a/an object
754 Dim Article As ArticleTypeEnum = ArticleTypeEnum.Definite
755 If sArgsTest.Contains("indefinite") Then Article = ArticleTypeEnum.Indefinite
756 If sArgsTest.Contains("none") Then Article = ArticleTypeEnum.None
757
758 ' List(true) - List anything in/on everything in the list (single level) - Default
759 ' List(false) - Do not list anything in/on
760 Dim bListInOn As Boolean = True ' List any objects in or on anything in this list
761 If sFunction = "Name" OrElse sArgsTest.Contains("false") OrElse sArgsTest.Contains("0") Then
762 bListInOn = False
763 End If
764
765 Dim bForcePronoun As Boolean = False
766 Dim ePronoun As PronounEnum = PronounEnum.Subjective
767 If sArgsTest.Contains("none") Then ePronoun = PronounEnum.None
768 If sArgsTest.Contains("force") Then bForcePronoun = True
769 If sArgsTest.Contains("objective") OrElse sArgsTest.Contains("object") OrElse sArgsTest.Contains("target") Then ePronoun = PronounEnum.Objective
770 If sArgsTest.Contains("possessive") OrElse sArgsTest.Contains("possess") Then ePronoun = PronounEnum.Possessive
771 If sArgsTest.Contains("reflective") OrElse sArgsTest.Contains("reflect") Then ePronoun = PronounEnum.Reflective
772
773 Dim sList As String = ""
774 Dim i As Integer = 0
775 If lst IsNot Nothing Then
776 For Each oItem As clsItem In lst
777 i += 1
778 If sSeparator = vbCrLf Then
779 If i > 1 Then sList &= sSeparator
780 Else
781 If i > 1 AndAlso i < lst.Count Then sList &= ", "
782 If lst.Count > 1 AndAlso i = lst.Count Then sList &= sSeparator
783 End If
784
785 If TypeOf oItem Is clsObject Then
786 sList &= CType(oItem, clsObject).FullName(Article)
787 If bListInOn AndAlso CType(oItem, clsObject).Children(clsObject.WhereChildrenEnum.InsideOrOnObject).Count > 0 Then sList &= ". " & ChopLast(CType(oItem, clsObject).DisplayObjectChildren)
788 ElseIf TypeOf oItem Is clsCharacter Then
789 Article = ArticleTypeEnum.Indefinite ' opposite default from objects
790 If sArgsTest.Contains("definite") Then Article = ArticleTypeEnum.Definite
791 sList &= CType(oItem, clsCharacter).Name(ePronoun, , , Article, bForcePronoun)
792 ElseIf TypeOf oItem Is clsLocation Then
793 sList &= CType(oItem, clsLocation).ShortDescription.ToString
794 End If
795 Next
796 ElseIf lstDirs IsNot Nothing Then
797 For Each oDir As DirectionsEnum In lstDirs
798 i += 1
799 If i > 1 AndAlso i < lstDirs.Count Then sList &= ", "
800 If lstDirs.Count > 1 AndAlso i = lstDirs.Count Then sList &= sSeparator
801 sList &= LCase(DirectionName(oDir))
802 Next
803 End If
804 If sList = "" Then sList = "nothing"
805 Return sList
806
807 Case "Parent"
808 Dim lstNew As New List(Of clsItemWithProperties)
809 Dim lstKeys As New List(Of String)
810
811 For Each oItem As clsItemWithProperties In lst
812 Dim sParent As String = oItem.Parent
813 If sParent <> "" Then
814 If Not lstKeys.Contains(sParent) Then
815 Dim oItemNew As clsItemWithProperties = CType(Adventure.dictAllItems(sParent), clsItemWithProperties)
816 lstKeys.Add(sParent)
817 lstNew.Add(oItemNew)
818 End If
819 End If
820 Next
821
822 If sRemainder <> "" Then
823 Return ReplaceOOProperty(sRemainder, , , , lstNew, bInt:=bInt)
824 End If
825
826 Case "Children"
827 Dim lstNew As New List(Of clsItemWithProperties)
828
829 For Each oItem As clsItemWithProperties In lst
830 Select Case True
831 Case TypeOf oItem Is clsObject
832 ob = CType(oItem, clsObject)
833 Select Case sArgs.ToLower.Replace(" ", "")
834 Case "", "all", "onandin", "all,onandin"
835 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideOrOnObject, True).Values
836 lstNew.Add(oOb)
837 Next
838 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideOrOnObject).Values
839 lstNew.Add(oCh)
840 Next
841 Case "characters,in"
842 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideObject).Values
843 lstNew.Add(oCh)
844 Next
845 Case "characters,on"
846 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.OnObject).Values
847 lstNew.Add(oCh)
848 Next
849 Case "characters,onandin", "characters"
850 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideOrOnObject).Values
851 lstNew.Add(oCh)
852 Next
853 Case "in"
854 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideObject, True).Values
855 lstNew.Add(oOb)
856 Next
857 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideObject).Values
858 lstNew.Add(oCh)
859 Next
860 Case "objects,in"
861 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideObject, True).Values
862 lstNew.Add(oOb)
863 Next
864 Case "objects,on"
865 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.OnObject, True).Values
866 lstNew.Add(oOb)
867 Next
868 Case "objects,onandin", "objects"
869 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideOrOnObject, True).Values
870 lstNew.Add(oOb)
871 Next
872 End Select
873
874 Case TypeOf oItem Is clsCharacter
875 ' No real reason we couldn't give Children from a Character
876
877 End Select
878 Next
879
880 If sRemainder <> "" OrElse lstNew.Count > 0 Then
881 Return ReplaceOOProperty(sRemainder, , , , lstNew, bInt:=bInt)
882 End If
883
884 Case "Contents"
885 Dim lstNew As New List(Of clsItemWithProperties)
886
887 For Each oItem As clsItemWithProperties In lst
888 Select Case True
889 Case TypeOf oItem Is clsObject
890 ob = CType(oItem, clsObject)
891 Select Case sArgs.ToLower
892 Case "", "all"
893 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideObject, True).Values
894 lstNew.Add(oOb)
895 Next
896 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideObject).Values
897 lstNew.Add(oCh)
898 Next
899 Case "characters"
900 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideObject).Values
901 lstNew.Add(oCh)
902 Next
903 Case "objects"
904 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideObject, True).Values
905 lstNew.Add(oOb)
906 Next
907 End Select
908 End Select
909 Next
910
911 Return ReplaceOOProperty(sRemainder, , , , lstNew, bInt:=bInt)
912
913 Case "Objects"
914 Dim lstNew As New List(Of clsItemWithProperties)
915
916 For Each oItem As clsItemWithProperties In lst
917 Select Case True
918 Case TypeOf oItem Is clsLocation
919 loc = CType(oItem, clsLocation)
920 For Each obLoc As clsObject In loc.ObjectsInLocation.Values
921 lstNew.Add(obLoc)
922 Next
923 Case Else
924 TODO()
925 End Select
926 Next
927
928 Return ReplaceOOProperty(sRemainder, , , , lstNew, bInt:=bInt)
929
930 Case Else
931 If Adventure.htblAllProperties.ContainsKey(sFunction) Then
932 Dim lstNew As New List(Of clsItemWithProperties)
933 Dim lstKeys As New List(Of String)
934 Dim iTotal As Integer = 0
935 Dim sResult As String = ""
936 Dim bIntResult As Boolean = False
937 Dim bPropertyFound As Boolean = False
938 Dim sNewPropertyKey As String = Nothing
939
940 For Each oItem As clsItemWithProperties In lst
941 If oItem.HasProperty(sFunction) Then
942 bPropertyFound = True
943 Dim p As clsProperty = oItem.GetProperty(sFunction)
944
945 Dim bValueOK As Boolean = True
946 If sArgs <> "" Then
947 bValueOK = False
948 If sArgs.Contains(".") Then sArgs = ReplaceFunctions(sArgs)
949 If sArgs.Contains("+") OrElse sArgs.Contains("-") Then
950 Dim sArgsNew As String = EvaluateExpression(sArgs)
951 If sArgsNew IsNot Nothing Then sArgs = sArgsNew
952 End If
953 Select Case p.Type
954 Case clsProperty.PropertyTypeEnum.ValueList
955 Dim iCheckValue As Integer = 0
956 If IsNumeric(sArgs) Then
957 iCheckValue = SafeInt(sArgs)
958 Else
959 If p.ValueList.ContainsKey(sArgs) Then iCheckValue = p.ValueList(sArgs)
960 End If
961 bValueOK = p.IntData = iCheckValue
962 bInt = True
963 Case clsProperty.PropertyTypeEnum.Integer
964 Dim iCheckValue As Integer = 0
965 If IsNumeric(sArgs) Then iCheckValue = SafeInt(sArgs)
966 bValueOK = p.IntData = iCheckValue
967 bInt = True
968 Case clsProperty.PropertyTypeEnum.StateList
969 bValueOK = p.Value.ToLower = sArgs.ToLower
970 Case clsProperty.PropertyTypeEnum.SelectionOnly
971 Select Case sArgs.ToLower
972 Case "false", "0"
973 bValueOK = False
974 Case Else
975 bValueOK = True
976 End Select
977 bInt = True
978 Case Else
979 TODO("Property filter check not yet implemented for " & p.Type.ToString)
980 End Select
981 End If
982
983 If bValueOK Then
984 Select Case p.Type
985 Case clsProperty.PropertyTypeEnum.CharacterKey
986 Dim chP As clsCharacter = Adventure.htblCharacters(p.Value)
987 If Not lstKeys.Contains(chP.Key) Then
988 lstKeys.Add(chP.Key)
989 lstNew.Add(chP)
990 End If
991 Case clsProperty.PropertyTypeEnum.LocationGroupKey
992 For Each sItem As String In Adventure.htblGroups(p.Value).arlMembers
993 If Not lstKeys.Contains(sItem) Then
994 Dim oItemNew As clsItemWithProperties = CType(Adventure.dictAllItems(sItem), clsItemWithProperties)
995 lstKeys.Add(oItemNew.Key)
996 lstNew.Add(oItemNew)
997 End If
998 Next
999 Case clsProperty.PropertyTypeEnum.LocationKey
1000 Dim oItemNew As clsItemWithProperties = Adventure.htblLocations(p.Value)
1001 If Not lstKeys.Contains(oItemNew.Key) Then
1002 lstKeys.Add(oItemNew.Key)
1003 lstNew.Add(oItemNew)
1004 End If
1005 Case clsProperty.PropertyTypeEnum.ObjectKey
1006 Dim oItemNew As clsItemWithProperties = Adventure.htblObjects(p.Value)
1007 If Not lstKeys.Contains(oItemNew.Key) Then
1008 lstKeys.Add(oItemNew.Key)
1009 lstNew.Add(oItemNew)
1010 End If
1011 Case clsProperty.PropertyTypeEnum.Integer, clsProperty.PropertyTypeEnum.ValueList, clsProperty.PropertyTypeEnum.StateList
1012 lstNew.Add(oItem)
1013 sNewPropertyKey = sFunction
1014 bInt = p.Type = clsProperty.PropertyTypeEnum.Integer OrElse p.Type = clsProperty.PropertyTypeEnum.ValueList
1015 Case clsProperty.PropertyTypeEnum.SelectionOnly
1016 ' Selection Only property to further reduce list
1017 lstNew.Add(oItem)
1018 bInt = True
1019 Case clsProperty.PropertyTypeEnum.Text
1020 If sResult <> "" Then
1021 If oItem Is lst(lst.Count - 1) Then sResult &= " and " Else sResult &= ", "
1022 End If
1023 sResult &= p.Value
1024 End Select
1025 End If
1026 Else
1027 If Adventure.htblAllProperties.ContainsKey(sFunction) Then
1028 Dim p As clsProperty = Adventure.htblAllProperties(sFunction)
1029 Dim bValueOK As Boolean = False ' Because this is equiv of arg = (True)
1030 If sArgs <> "" Then
1031 bValueOK = False
1032 If sArgs.Contains(".") Then sArgs = ReplaceFunctions(sArgs)
1033 If sArgs.Contains("+") OrElse sArgs.Contains("-") Then
1034 Dim sArgsNew As String = EvaluateExpression(sArgs)
1035 If sArgsNew IsNot Nothing Then sArgs = sArgsNew
1036 End If
1037 Select Case p.Type
1038 ' Opposite of above, since this item _doesn't_ contain this property
1039 Case clsProperty.PropertyTypeEnum.SelectionOnly
1040 Select Case sArgs.ToLower
1041 Case "false", "0"
1042 bValueOK = True
1043 Case Else
1044 bValueOK = False
1045 End Select
1046 bInt = True
1047 Case clsProperty.PropertyTypeEnum.StateList
1048 bValueOK = False ' Since we don't have the property
1049 Case Else
1050 TODO("Property filter check not yet implemented for " & p.Type.ToString)
1051 End Select
1052 End If
1053 If bValueOK Then
1054 Select Case p.Type
1055 Case clsProperty.PropertyTypeEnum.SelectionOnly
1056 ' Selection Only property to further reduce list
1057 lstNew.Add(oItem)
1058 End Select
1059 End If
1060 End If
1061 End If
1062 Next
1063
1064 If Not bPropertyFound Then
1065 Select Case Adventure.htblAllProperties(sFunction).Type
1066 Case clsProperty.PropertyTypeEnum.Integer, clsProperty.PropertyTypeEnum.ValueList
1067 bIntResult = True
1068 bInt = True
1069 End Select
1070 End If
1071
1072 If sRemainder <> "" OrElse (lstNew.Count > 0 AndAlso Not bIntResult) Then
1073 Return ReplaceOOProperty(sRemainder, lst:=lstNew, sPropertyKey:=sNewPropertyKey, bInt:=bInt)
1074 ElseIf bIntResult Then
1075 Return iTotal.ToString
1076 Else
1077 Return sResult
1078 End If
1079 End If
1080 End Select
1081
1082 ElseIf ob IsNot Nothing Then
1083 Select Case sFunction
1084 Case "Adjective", "Prefix"
1085 Return ob.Prefix
1086
1087 Case "Article"
1088 Return ob.Article
1089
1090 Case "Children"
1091 Dim lstNew As New List(Of clsItemWithProperties)
1092 Select Case sArgs.ToLower.Replace(" ", "")
1093 Case "", "all", "onandin", "all,onandin"
1094 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideOrOnObject, True).Values
1095 lstNew.Add(oOb)
1096 Next
1097 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideOrOnObject).Values
1098 lstNew.Add(oCh)
1099 Next
1100 Case "characters,in"
1101 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideObject).Values
1102 lstNew.Add(oCh)
1103 Next
1104 Case "characters,on"
1105 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.OnObject).Values
1106 lstNew.Add(oCh)
1107 Next
1108 Case "characters,onandin", "characters"
1109 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideOrOnObject).Values
1110 lstNew.Add(oCh)
1111 Next
1112 Case "in"
1113 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideObject, True).Values
1114 lstNew.Add(oOb)
1115 Next
1116 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideObject).Values
1117 lstNew.Add(oCh)
1118 Next
1119 Case "objects,in"
1120 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideObject, True).Values
1121 lstNew.Add(oOb)
1122 Next
1123 Case "objects,on"
1124 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.OnObject, True).Values
1125 lstNew.Add(oOb)
1126 Next
1127 Case "objects,onandin", "objects"
1128 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideOrOnObject, True).Values
1129 lstNew.Add(oOb)
1130 Next
1131 End Select
1132 Return ReplaceOOProperty(sRemainder, , , , lstNew, bInt:=bInt)
1133
1134 Case "Contents"
1135 Dim lstNew As New List(Of clsItemWithProperties)
1136 Select Case sArgs.ToLower
1137 Case "", "all"
1138 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideObject, True).Values
1139 lstNew.Add(oOb)
1140 Next
1141 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideObject).Values
1142 lstNew.Add(oCh)
1143 Next
1144 Case "characters"
1145 For Each oCh As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideObject).Values
1146 lstNew.Add(oCh)
1147 Next
1148 Case "objects"
1149 For Each oOb As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideObject, True).Values
1150 lstNew.Add(oOb)
1151 Next
1152 End Select
1153 Return ReplaceOOProperty(sRemainder, , , , lstNew, bInt:=bInt)
1154
1155 Case "Count"
1156 bInt = True
1157 Return "1"
1158
1159 Case "Description"
1160 Return ob.Description.ToString
1161
1162 Case "Location"
1163 Dim lstNew As New List(Of clsItemWithProperties)
1164 For Each sLocKey As String In ob.LocationRoots.Keys
1165 Dim oLoc As clsLocation = Adventure.htblLocations(sLocKey)
1166 lstNew.Add(oLoc)
1167 Next
1168 Return ReplaceOOProperty(sRemainder, , , , lstNew, bInt:=bInt)
1169
1170 Case "Name", "List"
1171 Dim Article As ArticleTypeEnum = ArticleTypeEnum.Definite
1172 If sArgs.ToLower.Contains("indefinite") Then Article = ArticleTypeEnum.Indefinite
1173 If sArgs.ToLower.Contains("none") Then Article = ArticleTypeEnum.None
1174
1175 Return ob.FullName(Article)
1176
1177 Case "Noun"
1178 Return ob.arlNames(0)
1179
1180 Case "Parent"
1181 Dim sParent As String = ob.Parent
1182 Dim oParentOb As clsObject = Nothing
1183 Dim oParentCh As clsCharacter = Nothing
1184 Dim oParentLoc As clsLocation = Nothing
1185 Adventure.htblObjects.TryGetValue(sParent, oParentOb)
1186 Adventure.htblCharacters.TryGetValue(sParent, oParentCh)
1187 Adventure.htblLocations.TryGetValue(sParent, oParentLoc)
1188 Return ReplaceOOProperty(sRemainder, oParentOb, oParentCh, oParentLoc, bInt:=bInt)
1189
1190 Case ""
1191 Return ob.Key
1192
1193 Case Else
1194 Dim p As clsProperty = Nothing
1195 Dim oOb As clsObject = Nothing
1196 Dim oCh As clsCharacter = Nothing
1197 Dim oLoc As clsLocation = Nothing
1198 Dim lstNew As List(Of clsItemWithProperties) = Nothing
1199
1200 If ob.htblProperties.TryGetValue(sFunction, p) Then
1201 Select Case p.Type
1202 Case clsProperty.PropertyTypeEnum.CharacterKey
1203 oCh = Adventure.htblCharacters(p.Value)
1204 Case clsProperty.PropertyTypeEnum.LocationGroupKey
1205 If lstNew Is Nothing Then lstNew = New List(Of clsItemWithProperties)
1206 For Each sItem As String In Adventure.htblGroups(p.Value).arlMembers
1207 Dim oItem As clsItemWithProperties = CType(Adventure.dictAllItems(sItem), clsItemWithProperties)
1208 lstNew.Add(oItem)
1209 Next
1210 Case clsProperty.PropertyTypeEnum.LocationKey
1211 oLoc = Adventure.htblLocations(p.Value)
1212 Case clsProperty.PropertyTypeEnum.ObjectKey
1213 oOb = Adventure.htblObjects(p.Value)
1214 Case clsProperty.PropertyTypeEnum.Integer, clsProperty.PropertyTypeEnum.ValueList
1215 Return p.IntData.ToString
1216 Case clsProperty.PropertyTypeEnum.SelectionOnly
1217 Return "1"
1218 Case clsProperty.PropertyTypeEnum.Text, clsProperty.PropertyTypeEnum.StateList
1219 Return p.Value
1220 End Select
1221 Else
1222 If Adventure.htblObjectProperties.ContainsKey(sFunction) Then
1223 ' Ok, item doesn't have property. Give it a default
1224 Select Case Adventure.htblObjectProperties(sFunction).Type
1225 Case clsProperty.PropertyTypeEnum.Integer, clsProperty.PropertyTypeEnum.ValueList, clsProperty.PropertyTypeEnum.SelectionOnly
1226 bInt = True
1227 Return "0"
1228 End Select
1229 End If
1230 End If
1231 If sRemainder <> "" Then
1232 Return ReplaceOOProperty(sRemainder, oOb, oCh, oLoc, lstNew, bInt:=bInt)
1233 ElseIf oLoc IsNot Nothing Then
1234 Return oLoc.Key
1235 ElseIf oOb IsNot Nothing Then
1236 Return oOb.Key
1237 ElseIf oCh IsNot Nothing Then
1238 Return oCh.Key
1239 ElseIf lstNew IsNot Nothing AndAlso lstNew.Count > 0 Then
1240 Return ReplaceOOProperty(sRemainder, oOb, oCh, oLoc, lstNew, bInt:=bInt)
1241 End If
1242
1243 End Select
1244
1245 ElseIf ch IsNot Nothing Then
1246 Select Case sFunction
1247 Case "Count"
1248 bInt = True
1249 Return "1"
1250
1251 Case "Descriptor"
1252 Return ch.Descriptor.ToString
1253
1254 Case "Description"
1255 Return ch.Description.ToString
1256
1257 Case "Exits"
1258 Dim lstNew As New List(Of DirectionsEnum)
1259
1260 For d As DirectionsEnum = DirectionsEnum.North To DirectionsEnum.NorthWest
1261 If Adventure.Player.HasRouteInDirection(d, False, Adventure.Player.Location.LocationKey) Then
1262 lstNew.Add(d)
1263 End If
1264 Next
1265 Return ReplaceOOProperty(sRemainder, , ch, , , lstNew, bInt:=bInt)
1266
1267 Case "Held"
1268 Dim lstNew As New List(Of clsItemWithProperties)
1269 Select Case sArgs.ToLower
1270 Case "", "true", "1", "-1"
1271 For Each obHeld As clsObject In ch.HeldObjects(True).Values
1272 lstNew.Add(obHeld)
1273 Next
1274 Case "false", "0"
1275 For Each obHeld As clsObject In ch.HeldObjects(False).Values
1276 lstNew.Add(obHeld)
1277 Next
1278 End Select
1279 Return ReplaceOOProperty(sRemainder, , ch, , lstNew, bInt:=bInt)
1280
1281 Case "Location"
1282 Dim sLoc As String = ch.Location.LocationKey
1283 Dim oLoc As clsLocation = Nothing
1284 Adventure.htblLocations.TryGetValue(sLoc, oLoc)
1285 Return ReplaceOOProperty(sRemainder, , , oLoc, bInt:=bInt)
1286
1287 Case "Name"
1288 Dim bForcePronoun As Boolean = False
1289
1290 Dim bTheNames As Boolean = False ' opposite default from objects
1291 Dim Article As ArticleTypeEnum = ArticleTypeEnum.Definite
1292 Dim bExplicitArticle As Boolean = False
1293 Dim ePronoun As PronounEnum = PronounEnum.Subjective
1294 Dim sArgsTest As String = sArgs.ToLower
1295
1296 If sArgsTest.Contains("none") Then
1297 ' Could mean either article or pronoun
1298 If sArgsTest.Contains("definite") OrElse sArgsTest.Contains("indefinite") Then
1299 ePronoun = PronounEnum.None
1300 ElseIf sArgsTest.Contains("force") OrElse sArgsTest.Contains("objective") OrElse sArgsTest.Contains("possessive") OrElse sArgsTest.Contains("reflective") Then
1301 Article = ArticleTypeEnum.None
1302 Else
1303 ' If only None is specified, assume they mean pronouns, as less likely they'll disable articles on character names
1304 ePronoun = PronounEnum.None
1305 End If
1306 End If
1307 If sArgsTest.Contains("force") Then bForcePronoun = True
1308 If sArgsTest.Contains("objective") OrElse sArgsTest.Contains("object") OrElse sArgsTest.Contains("target") Then ePronoun = PronounEnum.Objective
1309 If sArgsTest.Contains("possessive") OrElse sArgsTest.Contains("possess") Then ePronoun = PronounEnum.Possessive
1310 If sArgsTest.Contains("reflective") OrElse sArgsTest.Contains("reflect") Then ePronoun = PronounEnum.Reflective
1311 'If sArgsTest.Contains("definite") Then Article = ArticleTypeEnum.Definite
1312 If ContainsWord(sArgsTest, "definite") Then
1313 Article = ArticleTypeEnum.Definite
1314 bExplicitArticle = True
1315 End If
1316 If ContainsWord(sArgsTest, "indefinite") Then
1317 Article = ArticleTypeEnum.Indefinite
1318 bExplicitArticle = True
1319 End If
1320
1321 Return ch.Name(ePronoun, , , Article, bForcePronoun, bExplicitArticle)
1322
1323 Case "Parent"
1324 Dim sParent As String = ch.Parent
1325 Dim oParentOb As clsObject = Nothing
1326 Dim oParentCh As clsCharacter = Nothing
1327 Dim oParentLoc As clsLocation = Nothing
1328 Adventure.htblObjects.TryGetValue(sParent, oParentOb)
1329 Adventure.htblCharacters.TryGetValue(sParent, oParentCh)
1330 Adventure.htblLocations.TryGetValue(sParent, oParentLoc)
1331 Return ReplaceOOProperty(sRemainder, oParentOb, oParentCh, oParentLoc, bInt:=bInt)
1332
1333 Case "ProperName"
1334 Return ch.ProperName
1335
1336 Case "Worn"
1337 Dim lstNew As New List(Of clsItemWithProperties)
1338 Select Case sArgs.ToLower
1339 Case "", "true", "1", "-1"
1340 For Each obWorn As clsObject In ch.WornObjects(True).Values
1341 lstNew.Add(obWorn)
1342 Next
1343 Case "false", "0"
1344 For Each obWorn As clsObject In ch.WornObjects(False).Values
1345 lstNew.Add(obWorn)
1346 Next
1347 End Select
1348 Return ReplaceOOProperty(sRemainder, , ch, , lstNew, bInt:=bInt)
1349
1350 Case "WornAndHeld"
1351 Dim lstNew As New List(Of clsItemWithProperties)
1352 Select Case sArgs.ToLower
1353 Case "", "true", "1", "-1"
1354 For Each obWorn As clsObject In ch.WornObjects(True).Values
1355 lstNew.Add(obWorn)
1356 Next
1357 For Each obHeld As clsObject In ch.HeldObjects(True).Values
1358 lstNew.Add(obHeld)
1359 Next
1360 Case "false", "0"
1361 For Each obWorn As clsObject In ch.WornObjects(False).Values
1362 lstNew.Add(obWorn)
1363 Next
1364 For Each obHeld As clsObject In ch.HeldObjects(False).Values
1365 lstNew.Add(obHeld)
1366 Next
1367 End Select
1368 Return ReplaceOOProperty(sRemainder, , ch, , lstNew, bInt:=bInt)
1369
1370 Case ""
1371 Return ch.Key
1372
1373 Case Else
1374 Dim p As clsProperty = Nothing
1375 Dim oOb As clsObject = Nothing
1376 Dim oCh As clsCharacter = Nothing
1377 Dim oLoc As clsLocation = Nothing
1378 Dim lstNew As List(Of clsItemWithProperties) = Nothing
1379
1380 If ch.htblProperties.TryGetValue(sFunction, p) Then
1381 Select Case p.Type
1382 Case clsProperty.PropertyTypeEnum.CharacterKey
1383 oCh = Adventure.htblCharacters(p.Value)
1384 Case clsProperty.PropertyTypeEnum.LocationGroupKey
1385 lstNew = New List(Of clsItemWithProperties)
1386 For Each sItem As String In Adventure.htblGroups(p.Value).arlMembers
1387 Dim oItem As clsItemWithProperties = CType(Adventure.dictAllItems(sItem), clsItemWithProperties)
1388 lstNew.Add(oItem)
1389 Next
1390 Case clsProperty.PropertyTypeEnum.LocationKey
1391 oLoc = Adventure.htblLocations(p.Value)
1392 Case clsProperty.PropertyTypeEnum.ObjectKey
1393 oOb = Adventure.htblObjects(p.Value)
1394 Case clsProperty.PropertyTypeEnum.Integer, clsProperty.PropertyTypeEnum.ValueList
1395 bInt = True
1396 Return p.IntData.ToString
1397 Case clsProperty.PropertyTypeEnum.SelectionOnly
1398 bInt = True
1399 Return "1"
1400 Case clsProperty.PropertyTypeEnum.Text, clsProperty.PropertyTypeEnum.StateList
1401 Return p.Value
1402 End Select
1403 Else
1404 If Adventure.htblCharacterProperties.ContainsKey(sFunction) Then
1405 ' Ok, item doesn't have property. Give it a default
1406 Select Case Adventure.htblCharacterProperties(sFunction).Type
1407 Case clsProperty.PropertyTypeEnum.Integer, clsProperty.PropertyTypeEnum.ValueList, clsProperty.PropertyTypeEnum.SelectionOnly
1408 Return "0"
1409 End Select
1410 End If
1411 End If
1412 If sRemainder <> "" Then
1413 Return ReplaceOOProperty(sRemainder, oOb, oCh, oLoc, lstNew, bInt:=bInt)
1414 ElseIf oLoc IsNot Nothing Then
1415 Return oLoc.Key
1416 ElseIf oOb IsNot Nothing Then
1417 Return oOb.Key
1418 ElseIf oCh IsNot Nothing Then
1419 Return oCh.Key
1420 ElseIf lstNew IsNot Nothing AndAlso lstNew.Count > 0 Then
1421 Return ReplaceOOProperty(sRemainder, oOb, oCh, oLoc, lstNew, bInt:=bInt)
1422 End If
1423
1424 End Select
1425
1426 ElseIf loc IsNot Nothing Then
1427 Select Case sFunction
1428 Case "Characters"
1429 Dim lstNew As New List(Of clsItemWithProperties)
1430 For Each chLoc As clsCharacter In loc.CharactersVisibleAtLocation.Values
1431 lstNew.Add(chLoc)
1432 Next
1433 Return ReplaceOOProperty(sRemainder, , , , lstNew, bInt:=bInt)
1434
1435 Case "Contents"
1436 Dim lstNew As New List(Of clsItemWithProperties)
1437 Select Case sArgs.ToLower
1438 Case "", "all"
1439 For Each oOb As clsObject In loc.ObjectsInLocation.Values
1440 lstNew.Add(oOb)
1441 Next
1442 For Each oCh As clsCharacter In loc.CharactersDirectlyInLocation.Values
1443 lstNew.Add(oCh)
1444 Next
1445 Case "characters"
1446 For Each oCh As clsCharacter In loc.CharactersDirectlyInLocation.Values
1447 lstNew.Add(oCh)
1448 Next
1449 Case "objects"
1450 For Each oOb As clsObject In loc.ObjectsInLocation.Values
1451 lstNew.Add(oOb)
1452 Next
1453 End Select
1454 Return ReplaceOOProperty(sRemainder, , , , lstNew, bInt:=bInt)
1455
1456 Case "Count"
1457 bInt = True
1458 Return "1"
1459
1460 Case "Description", LONGLOCATIONDESCRIPTION
1461 Dim sResult As String = loc.ViewLocation
1462 If sResult = "" Then sResult = "There is nothing of interest here."
1463 Return sResult
1464
1465 Case "Exits"
1466 Dim lstNew As New List(Of DirectionsEnum)
1467
1468 For d As DirectionsEnum = DirectionsEnum.North To DirectionsEnum.NorthWest ' Adventure.iCompassPoints
1469 If loc.arlDirections(d).LocationKey <> "" Then
1470 lstNew.Add(d)
1471 End If
1472 Next
1473 Return ReplaceOOProperty(sRemainder, , ch, , , lstNew, bInt:=bInt)
1474
1475 Case "LocationTo"
1476 Dim lstNew As New List(Of clsItemWithProperties)
1477 Dim locTo As clsLocation = Nothing
1478
1479 For Each sDir As String In sArgs.ToLower.Split("|"c)
1480 For Each d As DirectionsEnum In [Enum].GetValues(GetType(DirectionsEnum))
1481 If sDir = d.ToString.ToLower Then
1482 Dim sLocTo As String = loc.arlDirections(d).LocationKey
1483 If sLocTo IsNot Nothing Then
1484 locTo = Nothing
1485 Adventure.htblLocations.TryGetValue(sLocTo, locTo)
1486 If locTo IsNot Nothing Then
1487 lstNew.Add(locTo)
1488 End If
1489 End If
1490 Exit For
1491 End If
1492 Next
1493 Next
1494
1495 If lstNew.Count = 1 Then
1496 locTo = CType(lstNew(0), clsLocation)
1497 lstNew = Nothing
1498 End If
1499 Return ReplaceOOProperty(sRemainder, , , locTo, lstNew, bInt:=bInt)
1500
1501 Case "Name", SHORTLOCATIONDESCRIPTION
1502 Return loc.ShortDescription.ToString
1503
1504 Case "Objects"
1505 Dim lstNew As New List(Of clsItemWithProperties)
1506 For Each obLoc As clsObject In loc.ObjectsInLocation.Values
1507 lstNew.Add(obLoc)
1508 Next
1509 Return ReplaceOOProperty(sRemainder, , , , lstNew, bInt:=bInt)
1510
1511 Case ""
1512 Return loc.Key
1513
1514 Case Else
1515 Dim p As clsProperty = Nothing
1516 Dim oOb As clsObject = Nothing
1517 Dim oCh As clsCharacter = Nothing
1518 Dim oLoc As clsLocation = Nothing
1519 Dim lstNew As List(Of clsItemWithProperties)
1520
1521 If loc.htblProperties.TryGetValue(sFunction, p) Then
1522 Select Case p.Type
1523 Case clsProperty.PropertyTypeEnum.CharacterKey
1524 oCh = Adventure.htblCharacters(p.Value)
1525 Case clsProperty.PropertyTypeEnum.LocationGroupKey
1526 lstNew = New List(Of clsItemWithProperties)
1527 For Each sItem As String In Adventure.htblGroups(p.Value).arlMembers
1528 Dim oItem As clsItemWithProperties = CType(Adventure.dictAllItems(sItem), clsItemWithProperties)
1529 lstNew.Add(oItem)
1530 Next
1531 Case clsProperty.PropertyTypeEnum.LocationKey
1532 oLoc = Adventure.htblLocations(p.Value)
1533 Case clsProperty.PropertyTypeEnum.ObjectKey
1534 oOb = Adventure.htblObjects(p.Value)
1535 Case clsProperty.PropertyTypeEnum.Integer, clsProperty.PropertyTypeEnum.ValueList
1536 bInt = True
1537 Return p.IntData.ToString
1538 Case clsProperty.PropertyTypeEnum.SelectionOnly
1539 bInt = True
1540 Return "1"
1541 Case clsProperty.PropertyTypeEnum.Text, clsProperty.PropertyTypeEnum.StateList
1542 Return p.Value
1543 End Select
1544 Else
1545 If Adventure.htblLocationProperties.ContainsKey(sFunction) Then
1546 ' Ok, item doesn't have property. Give it a default
1547 Select Case Adventure.htblLocationProperties(sFunction).Type
1548 Case clsProperty.PropertyTypeEnum.Integer, clsProperty.PropertyTypeEnum.ValueList, clsProperty.PropertyTypeEnum.SelectionOnly
1549 Return "0"
1550 End Select
1551 End If
1552 End If
1553 If sRemainder <> "" Then
1554 Return ReplaceOOProperty(sRemainder, oOb, oCh, oLoc, lstNew, bInt:=bInt)
1555 ElseIf oLoc IsNot Nothing Then
1556 Return oLoc.Key
1557 ElseIf oOb IsNot Nothing Then
1558 Return oOb.Key
1559 ElseIf oCh IsNot Nothing Then
1560 Return oCh.Key
1561 ElseIf lstNew.Count > 0 Then
1562 Return ReplaceOOProperty(sRemainder, oOb, oCh, oLoc, lstNew, bInt:=bInt)
1563 End If
1564
1565 End Select
1566
1567 ElseIf evt IsNot Nothing Then
1568 Select Case sFunction
1569 Case "Length"
1570 Return evt.Length.Value.ToString
1571 Case "Position"
1572 Return evt.TimerFromStartOfEvent.ToString
1573 Case ""
1574 Return evt.Key
1575
1576 End Select
1577
1578 Else
1579 If sFunction.Contains("|") Then
1580 Dim lstNew As New List(Of clsItemWithProperties)
1581 For Each sItem As String In sFunction.Split("|"c)
1582 Dim oItem As clsItemWithProperties = CType(Adventure.dictAllItems(sItem), clsItemWithProperties)
1583 lstNew.Add(oItem)
1584 Next
1585 Return ReplaceOOProperty(sRemainder, , , , lstNew, bInt:=bInt)
1586 Else
1587 If Adventure.AllKeys.Contains(sFunction) Then
1588 Dim lstNew As List(Of clsItemWithProperties) = Nothing
1589 If Adventure.htblObjects.ContainsKey(sFunction) Then
1590 ob = Adventure.htblObjects(sFunction)
1591 ElseIf Adventure.htblCharacters.ContainsKey(sFunction) Then
1592 ch = Adventure.htblCharacters(sFunction)
1593 ElseIf Adventure.htblLocations.ContainsKey(sFunction) Then
1594 loc = Adventure.htblLocations(sFunction)
1595 ElseIf Adventure.htblEvents.ContainsKey(sFunction) Then
1596 evt = Adventure.htblEvents(sFunction)
1597 ElseIf Adventure.htblGroups.ContainsKey(sFunction) Then
1598 Dim grp As clsGroup = Adventure.htblGroups(sFunction)
1599 lstNew = New List(Of clsItemWithProperties)
1600 For Each sMember As String In grp.arlMembers
1601 Dim itm As clsItemWithProperties = CType(Adventure.dictAllItems(sMember), clsItemWithProperties)
1602 lstNew.Add(itm)
1603 Next
1604 End If
1605
1606 Return ReplaceOOProperty(sRemainder, ob, ch, loc, lstNew, , evt, bInt:=bInt)
1607 Else
1608 For Each d As DirectionsEnum In [Enum].GetValues(GetType(DirectionsEnum))
1609 If d.ToString = sFunction Then
1610 Dim NewDir As New List(Of DirectionsEnum)
1611 NewDir.Add(d)
1612 Return ReplaceOOProperty(sRemainder, lstDirs:=NewDir, bInt:=bInt)
1613 End If
1614 Next
1615 End If
1616 End If
1617 End If
1618
1619 Return "#*!~#"
1620
1621 End Function
1622
1623 Private Function SplitArgs(ByVal sArgs As String) As List(Of String)
1624 Dim lArgs As New List(Of String)
1625 Dim iLevel As Integer = 0
1626 Dim sArg As String = ""
1627
1628 For i As Integer = 0 To sArgs.Length - 1
1629 Select Case sArgs(i)
1630 Case ","c
1631 If iLevel = 0 Then
1632 If sArg <> "" Then lArgs.Add(sArg)
1633 sArg = ""
1634 Else
1635 sArg &= sArgs(i)
1636 End If
1637 Case "("c, "["c
1638 iLevel += 1
1639 sArg &= sArgs(i)
1640 Case ")"c, "]"c
1641 iLevel -= 1
1642 sArg &= sArgs(i)
1643 Case Else
1644 sArg &= sArgs(i)
1645 End Select
1646 Next
1647 If sArg <> "" Then lArgs.Add(sArg)
1648
1649 Return lArgs
1650 End Function
1651
1652
1653 Private Sub EvaluateUDF(ByVal udf As clsUserFunction, ByRef sText As String)
1654 ' This will need to be a bit more sophisticated once we have arguments...
1655 Dim re As New System.Text.RegularExpressions.Regex("%" & udf.Name & "(\[.*?\])?%")
1656
1657 If re.IsMatch(sText) Then
1658 ' We can't test udf.Output.ToString until we've replaced the parameters below
1659
1660 ' Test for recursion
1661 For Each d As SingleDescription In udf.Output
1662 If d.Description.Contains("%" & udf.Name & If(udf.Arguments.Count = 0, "%", "[")) Then
1663 ErrMsg("Recursive User Defined Function - " & udf.Name)
1664 Exit Sub
1665 End If
1666 Next
1667
1668 ' Replace each parameter with it's resolved value
1669 Dim sMatch As String = re.Match(sText).Value
1670 Dim dOut As Description = udf.Output.Copy
1671
1672 ' Backup existing Refs
1673 Dim refsCopy As clsNewReference() = UserSession.NewReferences
1674 Dim refsUDF As clsNewReference() = {}
1675 Dim iRefNo As Integer = 0
1676
1677 If sMatch.Contains("[") AndAlso sMatch.Contains("]") Then
1678 Dim sArgs As String = sMatch.Substring(sMatch.IndexOf("["c) + 1, sMatch.LastIndexOf("]"c) - sMatch.IndexOf("["c) - 1)
1679
1680 Dim sArg As List(Of String) = SplitArgs(sArgs)
1681 Dim i As Integer = 0
1682 For Each arg As clsUserFunction.Argument In udf.Arguments
1683 Dim sEvaluatedArg As String = ReplaceFunctions(sArg(i))
1684
1685 If sEvaluatedArg.Contains("|") Then ' Means it evaluated to multiple items
1686 ' Depending on arg type, create an objects parameter, and set the refs
1687 Select Case arg.Type
1688 Case clsUserFunction.ArgumentType.Object
1689 Dim refOb As New clsNewReference(ReferencesType.Object)
1690 With refOb
1691 For Each sOb As String In sEvaluatedArg.Split("|"c)
1692 Dim itmOb As New clsSingleItem
1693 itmOb.MatchingPossibilities.Add(sOb)
1694 itmOb.bExplicitlyMentioned = True
1695 .Items.Add(itmOb)
1696 Next
1697 End With
1698 'sEvaluatedArg = "%objects%"
1699 ReDim Preserve refsUDF(iRefNo)
1700 refsUDF(iRefNo) = refOb
1701 iRefNo += 1
1702 End Select
1703 End If
1704
1705 ' Our function argument could be an expression
1706 If New System.Text.RegularExpressions.Regex("\d( )*[+-/*^]( )*\d").IsMatch(sEvaluatedArg) Then
1707 Dim sExpr As String = EvaluateExpression(sEvaluatedArg)
1708 If sExpr IsNot Nothing Then sEvaluatedArg = sExpr
1709 End If
1710
1711 For Each d As SingleDescription In dOut
1712 d.Description = d.Description.Replace("%" & arg.Name & "%", sEvaluatedArg)
1713 For Each r As clsRestriction In d.Restrictions
1714 If r.sKey1 = "Parameter-" & arg.Name Then r.sKey1 = If(sEvaluatedArg.Contains("|"), "ReferencedObjects", sEvaluatedArg).ToString
1715 If r.sKey2 = "Parameter-" & arg.Name Then r.sKey2 = If(sEvaluatedArg.Contains("|"), "ReferencedObjects", sEvaluatedArg).ToString
1716 Next
1717 Next
1718 i += 1
1719 Next
1720 End If
1721
1722 UserSession.NewReferences = refsUDF
1723 Dim sFunctionResult As String = dOut.ToString
1724 ' Restore Refs
1725 UserSession.NewReferences = refsCopy
1726 sText = ReplaceFunctions(re.Replace(sText, sFunctionResult, 1))
1727 End If
1728
1729 End Sub
1730
1731 Public Function ReplaceFunctions(ByVal sText As String, Optional ByVal bExpression As Boolean = False, Optional ByVal bAllowOO As Boolean = True) As String
1732 Try
1733 Dim dictGUIDs As New Dictionary(Of String, String)
1734 While sText.Contains("<#")
1735 Dim iStart As Integer = sText.IndexOf("<#")
1736 Dim iEnd As Integer = sText.IndexOf("#>", iStart)
1737 Dim sGUID As String = ":" & System.Guid.NewGuid.ToString & ":"
1738 Dim sExpression As String = sText.Substring(iStart, iEnd - iStart + 2)
1739 dictGUIDs.Add(sGUID, sExpression)
1740 sText = sText.Replace(sExpression, sGUID)
1741 End While
1742
1743 For Each udf As clsUserFunction In Adventure.htblUDFs.Values
1744 EvaluateUDF(udf, sText)
1745 Next
1746
1747 If sInstr(sText, "%") > 0 Then
1748 Dim sCheck As String
1749 Do
1750 sCheck = sText
1751
1752 sText = ReplaceIgnoreCase(sText, "%Player%", Adventure.Player.Key)
1753
1754 sText = ReplaceIgnoreCase(sText, "%object%", "%object1%")
1755 sText = ReplaceIgnoreCase(sText, "%character%", "%character1%")
1756 sText = ReplaceIgnoreCase(sText, "%location%", "%location1%")
1757 sText = ReplaceIgnoreCase(sText, "%direction%", "%direction1%")
1758 sText = ReplaceIgnoreCase(sText, "%item%", "%item1%")
1759 sText = ReplaceIgnoreCase(sText, "%text%", "%text1%")
1760 sText = ReplaceIgnoreCase(sText, "%number%", "%number1%")
1761
1762 sText = ReplaceIgnoreCase(sText, "%ConvCharacter%", Adventure.sConversationCharKey)
1763 sText = ReplaceIgnoreCase(sText, "%turns%", Adventure.Turns.ToString)
1764 Dim sVersion As String = System.Reflection.Assembly.GetExecutingAssembly.GetName.Version.ToString
1765 sText = ReplaceIgnoreCase(sText, "%version%", sVersion.Substring(0, 1) & sVersion.Substring(2, 1) & sVersion.Substring(4))
1766 sText = ReplaceIgnoreCase(sText, "%release%", Adventure.BabelTreatyInfo.Stories(0).Releases.Attached.Release.Version.ToString)
1767
1768 If Contains(sText, "%AloneWithChar%") Then
1769 Dim sAloneWithChar As String = Adventure.Player.AloneWithChar
1770 If sAloneWithChar Is Nothing Then sAloneWithChar = NOCHARACTER
1771 sText = ReplaceIgnoreCase(sText, "%AloneWithChar%", sAloneWithChar)
1772 End If
1773 If sText.Contains("%CharacterName[") Then
1774 For Each sPronoun As String In New String() {"subject", "subjective", "personal", "target", "object", "objective", "possessive"}
1775 sText = ReplaceIgnoreCase(sText, "%CharacterName[" & sPronoun & "]%", "%CharacterName[%Player%, " & sPronoun & "]%")
1776 Next
1777 End If
1778 sText = ReplaceIgnoreCase(sText, "%CharacterName%", "%CharacterName[%Player%]%") ' Function without args points to Player
1779
1780 With UserSession
1781 If .NewReferences IsNot Nothing Then
1782 For iObRef As Integer = 1 To 5
1783 If Contains(sText, "%object" & iObRef & "%") Then
1784 ' Get the first object reference
1785 Dim bQuote As Boolean = bExpression AndAlso Not Contains(sText, "%object" & iObRef & "%.") AndAlso Not Contains(sText, """%object" & iObRef & "%""")
1786 For Each nr As clsNewReference In .NewReferences
1787 If nr.ReferenceType = ReferencesType.Object Then
1788 If nr.ReferenceMatch = "object" & iObRef Then
1789 Dim sObjects As String = ""
1790 For Each itm As clsSingleItem In nr.Items
1791 If sObjects <> "" Then sObjects &= "|"
1792 sObjects &= itm.MatchingPossibilities(0)
1793 Next
1794 If bQuote Then sObjects = """" & sObjects & """"
1795 If sObjects <> "" Then sText = ReplaceIgnoreCase(sText, "%object" & iObRef & "%", sObjects)
1796 Exit For
1797 End If
1798 End If
1799 Next
1800 End If
1801 Next iObRef
1802
1803 If Contains(sText, "%objects%") Then
1804 ' Get the first object reference
1805 Dim bQuote As Boolean = bExpression AndAlso Not Contains(sText, "%objects%.") AndAlso Not Contains(sText, """%objects%""")
1806 For Each nr As clsNewReference In .NewReferences
1807 If nr.ReferenceType = ReferencesType.Object AndAlso nr.ReferenceMatch = "objects" Then
1808 Dim sObjects As String = ""
1809 For Each itm As clsSingleItem In nr.Items
1810 If sObjects <> "" Then sObjects &= "|"
1811 sObjects &= itm.MatchingPossibilities(0)
1812 Next
1813 If bQuote Then sObjects = """" & sObjects & """"
1814 If sObjects <> "" Then sText = ReplaceIgnoreCase(sText, "%objects%", sObjects)
1815 Exit For
1816 End If
1817 Next
1818 End If
1819
1820 For iCharRef As Integer = 1 To 5
1821 If Contains(sText, "%character" & iCharRef & "%") Then
1822 ' Get the first character reference
1823 Dim bQuote As Boolean = bExpression AndAlso Not Contains(sText, "%character" & iCharRef & "%.") AndAlso Not Contains(sText, """%character" & iCharRef & "%""")
1824 For Each nr As clsNewReference In .NewReferences
1825 If nr.ReferenceType = ReferencesType.Character Then
1826 If nr.ReferenceMatch = "character" & iCharRef Then
1827 Dim sCharacters As String = ""
1828 For Each itm As clsSingleItem In nr.Items
1829 If sCharacters <> "" Then sCharacters &= "|"
1830 sCharacters &= itm.MatchingPossibilities(0)
1831 Next
1832 If bQuote Then sCharacters = """" & sCharacters & """"
1833 If sCharacters <> "" Then sText = ReplaceIgnoreCase(sText, "%character" & iCharRef & "%", sCharacters)
1834 Exit For
1835 End If
1836 End If
1837 Next
1838 End If
1839 Next iCharRef
1840
1841 If Contains(sText, "%characters%") Then
1842 ' Get the first character reference
1843 Dim bQuote As Boolean = bExpression AndAlso Not Contains(sText, "%characters%.") AndAlso Not Contains(sText, """%characters%""")
1844 For Each nr As clsNewReference In .NewReferences
1845 If nr.ReferenceType = ReferencesType.Character Then
1846 Dim sCharacters As String = ""
1847 For Each itm As clsSingleItem In nr.Items
1848 If sCharacters <> "" Then sCharacters &= "|"
1849 sCharacters &= itm.MatchingPossibilities(0)
1850 Next
1851 If bQuote Then sCharacters = """" & sCharacters & """"
1852 If sCharacters <> "" Then sText = ReplaceIgnoreCase(sText, "%characters%", sCharacters)
1853 Exit For
1854 End If
1855 Next
1856 End If
1857
1858 For iLocRef As Integer = 1 To 5
1859 If Contains(sText, "%location" & iLocRef & "%") Then
1860 ' Get the first location reference
1861 Dim bQuote As Boolean = bExpression AndAlso Not Contains(sText, "%location" & iLocRef & "%.") AndAlso Not Contains(sText, """%location" & iLocRef & "%""")
1862 For Each nr As clsNewReference In .NewReferences
1863 If nr.ReferenceType = ReferencesType.Location Then
1864 If nr.ReferenceMatch = "location" & iLocRef Then
1865 Dim sLocations As String = ""
1866 For Each itm As clsSingleItem In nr.Items
1867 If sLocations <> "" Then sLocations &= "|"
1868 sLocations &= itm.MatchingPossibilities(0)
1869 Next
1870 If bQuote Then sLocations = """" & sLocations & """"
1871 If sLocations <> "" Then sText = ReplaceIgnoreCase(sText, "%location" & iLocRef & "%", sLocations)
1872 Exit For
1873 End If
1874 End If
1875 Next
1876 End If
1877 Next iLocRef
1878
1879 For iItemRef As Integer = 1 To 5
1880 If Contains(sText, "%item" & iItemRef & "%") Then
1881 ' Get the first item reference
1882 Dim bQuote As Boolean = bExpression AndAlso Not Contains(sText, "%item" & iItemRef & "%.") AndAlso Not Contains(sText, """%item" & iItemRef & "%""")
1883 For Each nr As clsNewReference In .NewReferences
1884 If nr.ReferenceType = ReferencesType.Item Then
1885 If nr.ReferenceMatch = "item" & iItemRef Then
1886 Dim sItems As String = ""
1887 For Each itm As clsSingleItem In nr.Items
1888 If sItems <> "" Then sItems &= "|"
1889 sItems &= itm.MatchingPossibilities(0)
1890 Next
1891 If bQuote Then sItems = """" & sItems & """"
1892 If sItems <> "" Then sText = ReplaceIgnoreCase(sText, "%item" & iItemRef & "%", sItems)
1893 Exit For
1894 End If
1895 End If
1896 Next
1897 End If
1898 Next iItemRef
1899
1900 For iDirRef As Integer = 1 To 5
1901 If Contains(sText, "%direction" & iDirRef & "%") Then
1902 ' Get the first direction reference
1903 Dim bQuote As Boolean = bExpression AndAlso Not Contains(sText, "%direction" & iDirRef & "%.") AndAlso Not Contains(sText, """%direction" & iDirRef & "%""")
1904 For Each nr As clsNewReference In .NewReferences
1905 If nr.ReferenceType = ReferencesType.Direction Then
1906 If nr.ReferenceMatch = "direction" & iDirRef Then
1907 Dim sDirections As String = ""
1908 For Each itm As clsSingleItem In nr.Items
1909 If sDirections <> "" Then sDirections &= "|"
1910 sDirections &= itm.MatchingPossibilities(0)
1911 Next
1912 If bQuote Then sDirections = """" & sDirections & """"
1913 If sDirections <> "" Then sText = ReplaceIgnoreCase(sText, "%direction" & iDirRef & "%", sDirections)
1914 Exit For
1915 End If
1916 End If
1917 Next
1918 End If
1919 Next iDirRef
1920
1921 For i As Integer = 1 To 5
1922 Dim iRef As Integer = i
1923
1924 Dim sNumber As String = "%number" & If(i > 0, i.ToString, "").ToString & "%"
1925 If Contains(sText, sNumber) Then
1926 Dim bQuote As Boolean = bExpression AndAlso Not Contains(sText, "%number" & If(i > 0, i.ToString, "").ToString & "%.") AndAlso Not Contains(sText, """%number" & If(i > 0, i.ToString, "").ToString & "%""")
1927 For Each ref As clsNewReference In .NewReferences
1928 If ref.ReferenceType = ReferencesType.Number Then
1929 If ref.ReferenceMatch = "number" & iRef Then
1930 Dim sNumbers As String = ""
1931 For Each itm As clsSingleItem In ref.Items
1932 If sNumbers <> "" Then sNumbers &= "|"
1933 sNumbers &= itm.MatchingPossibilities(0)
1934 Next
1935 If bQuote Then sNumbers = """" & sNumbers & """"
1936 If sNumbers <> "" Then sText = ReplaceIgnoreCase(sText, sNumber, sNumbers)
1937 Exit For
1938 End If
1939 End If
1940 Next
1941 End If
1942
1943 Dim sRefText As String = "%text" & If(i > 0, i.ToString, "").ToString & "%"
1944 If Contains(sText, sRefText) Then
1945 Dim bQuote As Boolean = bExpression AndAlso Not Contains(sText, "%text" & If(i > 0, i.ToString, "").ToString & "%.") AndAlso Not Contains(sText, """%text" & If(i > 0, i.ToString, "").ToString & "%""")
1946 For Each ref As clsNewReference In .NewReferences
1947 If ref.ReferenceType = ReferencesType.Text Then
1948 If ref.ReferenceMatch = "text" & iRef Then
1949 If ref.Items.Count = 1 AndAlso ref.Items(0).MatchingPossibilities.Count = 1 Then
1950 If bExpression Then
1951 sText = ReplaceIgnoreCase(sText, sRefText, """" & ref.Items(0).MatchingPossibilities(0) & """")
1952 Else
1953 sText = ReplaceIgnoreCase(sText, sRefText, ref.Items(0).MatchingPossibilities(0))
1954 End If
1955 End If
1956 End If
1957 End If
1958 Next
1959 If bQuote Then
1960 sText = ReplaceIgnoreCase(sText, sRefText, """" & Adventure.sReferencedText(iRef) & """")
1961 Else
1962 sText = ReplaceIgnoreCase(sText, sRefText, Adventure.sReferencedText(iRef))
1963 End If
1964 End If
1965 Next
1966
1967 End If
1968 End With
1969
1970 For Each var As clsVariable In Adventure.htblVariables.Values
1971 If var.Length = 1 Then
1972 While InStr(sText, "%" & var.Name & "%", CompareMethod.Text) > 0
1973 If var.Type = clsVariable.VariableTypeEnum.Numeric Then
1974 sText = ReplaceIgnoreCase(sText, "%" & var.Name & "%", var.IntValue.ToString)
1975 Else
1976 If bExpression Then
1977 sText = ReplaceIgnoreCase(sText, "%" & var.Name & "%", """" & var.StringValue & """")
1978 Else
1979 sText = ReplaceIgnoreCase(sText, "%" & var.Name & "%", var.StringValue)
1980 End If
1981 End If
1982 End While
1983 ElseIf var.Length > 1 Then
1984 While sInstr(sText, "%" & var.Name & "[") > 0
1985 Dim iOffset As Integer = sInstr(sText, "%" & var.Name & "[") + var.Name.Length + 1
1986 Dim sIndex As String = sText.Substring(iOffset, sText.IndexOf("]"c, iOffset) - iOffset)
1987 If IsNumeric(sIndex) Then
1988 If var.Type = clsVariable.VariableTypeEnum.Numeric Then
1989 sText = sText.Replace("%" & var.Name & "[" & sIndex & "]%", var.IntValue(CInt(sIndex)).ToString)
1990 Else
1991 If bExpression Then
1992 sText = sText.Replace("%" & var.Name & "[" & sIndex & "]%", """" & var.StringValue(CInt(sIndex)).ToString & """")
1993 Else
1994 sText = sText.Replace("%" & var.Name & "[" & sIndex & "]%", var.StringValue(CInt(sIndex)).ToString)
1995 End If
1996 End If
1997 Else
1998 Dim iIndex As Integer = 0
1999 If IsNumeric(sIndex) Then
2000 iIndex = SafeInt(sIndex)
2001 Else
2002 Dim varIndex As New clsVariable
2003 varIndex.Type = clsVariable.VariableTypeEnum.Numeric
2004 varIndex.SetToExpression(sIndex)
2005 iIndex = varIndex.IntValue
2006 End If
2007 If var.Type = clsVariable.VariableTypeEnum.Numeric Then
2008 sText = sText.Replace("%" & var.Name & "[" & sIndex & "]%", var.IntValue(iIndex).ToString)
2009 Else
2010 If bExpression Then
2011 sText = sText.Replace("%" & var.Name & "[" & sIndex & "]%", """" & var.StringValue(iIndex).ToString & """")
2012 Else
2013 sText = sText.Replace("%" & var.Name & "[" & sIndex & "]%", var.StringValue(iIndex).ToString)
2014 End If
2015 End If
2016 End If
2017 End While
2018 End If
2019 Next
2020
2021 ' Need this to evaluate text in order, not replace by function order
2022 ' This is in case eg. "%DisplayCharacter% %CharacterName%" where DisplayCharacter contains name, then we must evaluate first
2023 ' name first in case we abbreviate, else we'll abbreviate the first name with 'he' instead of the second.
2024 '
2025 Dim sFirstFunction As String = ""
2026 Dim iFirstLocation As Integer = Integer.MaxValue
2027 For Each sFunctionCheck As String In FunctionNames()
2028 sFunctionCheck = sFunctionCheck.ToLower
2029 Dim iMatchCheck As Integer = sInstr(sText.ToLower, "%" & sFunctionCheck & "[")
2030 If iMatchCheck > 0 AndAlso iMatchCheck < iFirstLocation Then
2031 sFirstFunction = sFunctionCheck
2032 iFirstLocation = iMatchCheck
2033 End If
2034 Next
2035
2036 If sFirstFunction <> "" Then
2037 Dim sFunction As String = sFirstFunction
2038 Dim iMatchLoc As Integer = sInstr(sText.ToLower, "%" & sFunction & "[")
2039 While iMatchLoc > 0
2040 Dim sArgs As String = GetFunctionArgs(sText.Substring(InStr(sText.ToLower, "%" & sFunction & "[") + sFunction.Length))
2041 Dim iArgsLength As Integer = sArgs.Length
2042 Dim bFunctionIsArgument As Boolean = (iMatchLoc > 1 AndAlso sText.Substring(iMatchLoc - 2, 1) = "[" AndAlso sText.Substring(iMatchLoc + sFunction.Length + iArgsLength, 2) = "]%")
2043
2044 If iArgsLength > 0 OrElse sFunction.ToLower = "sum" Then
2045 Dim sOldArgs As String = sArgs
2046 sArgs = ReplaceFunctions(sArgs)
2047 sText = sText.Substring(0, iMatchLoc - 1) & Replace(sText, sOldArgs, sArgs, iMatchLoc, 1)
2048
2049 If sInstr(sText.ToLower, "%" & sFunction & "[" & sArgs.ToLower & "]%") > 0 Then
2050 Dim bAllowBlank As Boolean = False
2051 Dim sResult As String = ""
2052 Dim htblObjects As New ObjectHashTable
2053 Dim htblCharacters As New CharacterHashTable
2054 Dim htblLocations As New LocationHashTable
2055
2056 If sArgs.Contains("|") Then
2057 ' We've got a pipe-separated list of parent keys
2058 Dim sKeys() As String = sArgs.Split("|"c)
2059 For Each sKey As String In sKeys
2060 If sKey.Contains(",") Then sKey = sLeft(sKey, sInstr(sKey, ",") - 1) ' trim off any other args
2061 If Not htblObjects.ContainsKey(sKey) AndAlso Adventure.htblObjects.ContainsKey(sKey) Then htblObjects.Add(Adventure.htblObjects(sKey), sKey)
2062 If Not htblCharacters.ContainsKey(sKey) AndAlso Adventure.htblCharacters.ContainsKey(sKey) Then htblCharacters.Add(Adventure.htblCharacters(sKey), sKey)
2063 If Not htblLocations.ContainsKey(sKey) AndAlso Adventure.htblLocations.ContainsKey(sKey) Then htblLocations.Add(Adventure.htblLocations(sKey), sKey)
2064 Next
2065 Else
2066 Dim sKey As String = sArgs
2067 If sKey.Contains(",") Then sKey = sLeft(sKey, sInstr(sKey, ",") - 1)
2068 If Not htblObjects.ContainsKey(sKey) AndAlso Adventure.htblObjects.ContainsKey(sKey) Then htblObjects.Add(Adventure.htblObjects(sKey), sKey)
2069 If Not htblCharacters.ContainsKey(sKey) AndAlso Adventure.htblCharacters.ContainsKey(sKey) Then htblCharacters.Add(Adventure.htblCharacters(sKey), sKey)
2070 If Not htblLocations.ContainsKey(sKey) AndAlso Adventure.htblLocations.ContainsKey(sKey) Then htblLocations.Add(Adventure.htblLocations(sKey), sKey)
2071 End If
2072
2073 Select Case sFunction
2074 Case "CharacterDescriptor".ToLower
2075 If Adventure.htblCharacters.ContainsKey(sArgs) Then
2076 ' This needs to be The, depending whether we have referred to them already... :-/
2077 sResult = htblCharacters(sArgs).Descriptor
2078 Else
2079 DisplayError("Bad Argument to &perc;CharacterDescriptor[]&perc; - Character Key """ & sArgs & """ not found")
2080 End If
2081
2082 Case "CharacterName".ToLower
2083 Dim sKeys() As String = Split(sArgs.Replace(" ", ""), ",")
2084 Dim sKey As String = ""
2085 If sKeys.Length > 0 Then sKey = sKeys(0)
2086 Dim ePronoun As PronounEnum = PronounEnum.Subjective
2087 If sKeys.Length = 2 Then
2088 Select Case sKeys(1).ToLower
2089 Case "subject", "subjective", "personal"
2090 ePronoun = PronounEnum.Subjective
2091 Case "target", "object", "objective"
2092 ePronoun = PronounEnum.Objective
2093 Case "possess", "possessive"
2094 ePronoun = PronounEnum.Possessive
2095 Case "none"
2096 ePronoun = PronounEnum.None
2097 End Select
2098 End If
2099
2100 If htblCharacters.ContainsKey(sKey) Then
2101 sResult = htblCharacters(sKey).Name(ePronoun)
2102 ' Slight fudge - if the name is the start of a sentence, auto-cap it... (consistent with v4)
2103 If iMatchLoc > 3 Then
2104 If sText.Substring(iMatchLoc - 3, 2) = vbCrLf OrElse sText.Substring(iMatchLoc - 3, 2) = " " Then
2105 sResult = PCase(sResult)
2106 End If
2107 End If
2108 If UserSession.bDisplaying Then UserSession.PronounKeys.Add(sKey, ePronoun, htblCharacters(sKey).Gender, UserSession.sOutputText.Length + iMatchLoc)
2109 ElseIf sKey = NOCHARACTER Then
2110 sResult = "Nobody"
2111 Else
2112 DisplayError("Bad Argument to &perc;CharacterName[]&perc; - Character Key """ & sArgs & """ not found")
2113 End If
2114
2115 Case "CharacterProper".ToLower, "ProperName".ToLower
2116 If Adventure.htblCharacters.ContainsKey(sArgs) Then
2117 sResult = htblCharacters(sArgs).ProperName
2118 Else
2119 DisplayError("Bad Argument to &perc;CharacterProper[]&perc; - Character Key """ & sArgs & """ not found")
2120 End If
2121
2122 Case "DisplayCharacter".ToLower
2123 If Adventure.htblCharacters.ContainsKey(sArgs) Then
2124 sResult = htblCharacters(sArgs).Description.ToString
2125 If sResult = "" Then sResult = "%CharacterName% see[//s] nothing interesting about %CharacterName[" & sArgs & ", target]%."
2126 Else
2127 DisplayError("Bad Argument to &perc;DisplayCharacter[]&perc; - Character Key """ & sArgs & """ not found")
2128 End If
2129
2130 Case "DisplayLocation".ToLower
2131 If Adventure.htblLocations.ContainsKey(sArgs) Then
2132 sResult = Adventure.htblLocations(sArgs).ViewLocation
2133 If sResult = "" Then sResult = "There is nothing of interest here."
2134 Else
2135 DisplayError("Bad Argument to &perc;DisplayLocation[]&perc; - Location Key """ & sArgs & """ not found")
2136 End If
2137
2138 Case "DisplayObject".ToLower
2139 If Adventure.htblObjects.ContainsKey(sArgs) Then
2140 sResult = htblObjects(sArgs).Description.ToString
2141 If sResult = "" Then sResult = "%CharacterName% see[//s] nothing interesting about " & htblObjects(sArgs).FullName(ArticleTypeEnum.Definite) & "."
2142 Else
2143 DisplayError("Bad Argument to &perc;DisplayObject[]&perc; - Object Key """ & sArgs & """ not found")
2144 End If
2145
2146 Case "Held".ToLower
2147 If Adventure.htblCharacters.ContainsKey(sArgs) Then
2148 For Each ob As clsObject In Adventure.htblCharacters(sArgs).HeldObjects.Values
2149 If sResult <> "" Then sResult &= "|"
2150 sResult &= ob.Key
2151 Next
2152 Else
2153 DisplayError("Bad Argument to &perc;Held[]&perc; - Character Key """ & sArgs & """ not found")
2154 End If
2155 bAllowBlank = True
2156 Case "LCase".ToLower
2157 sResult = sArgs.ToLower
2158
2159 Case "ListCharactersOn".ToLower
2160 If Adventure.htblObjects.ContainsKey(sArgs) Then
2161 sResult = Adventure.htblObjects(sArgs).ChildrenCharacters(clsObject.WhereChildrenEnum.OnObject).List()
2162 Else
2163 DisplayError("Bad Argument to &perc;ListCharactersOn[]&perc; - Object Key """ & sArgs & """ not found")
2164 End If
2165
2166 Case "ListCharactersIn".ToLower
2167 If Adventure.htblObjects.ContainsKey(sArgs) Then
2168 sResult = Adventure.htblObjects(sArgs).ChildrenCharacters(clsObject.WhereChildrenEnum.InsideObject).List()
2169 Else
2170 DisplayError("Bad Argument to &perc;ListCharactersIn[]&perc; - Object Key """ & sArgs & """ not found")
2171 End If
2172
2173 Case "ListCharactersOnAndIn".ToLower
2174 If Adventure.htblObjects.ContainsKey(sArgs) Then
2175 sResult = Adventure.htblObjects(sArgs).DisplayCharacterChildren
2176 Else
2177 DisplayError("Bad Argument to &perc;ListCharactersOnAndIn[]&perc; - Object Key """ & sArgs & """ not found")
2178 End If
2179
2180 Case "ListHeld".ToLower
2181 If Adventure.htblCharacters.ContainsKey(sArgs) Then
2182 sResult = Adventure.htblCharacters(sArgs).HeldObjects.List(, True, ArticleTypeEnum.Indefinite)
2183 Else
2184 DisplayError("Bad Argument to &perc;ListHeld[]&perc; - Character Key """ & sArgs & """ not found")
2185 End If
2186 Case "ListExits".ToLower
2187 If Adventure.htblCharacters.ContainsKey(sArgs) Then
2188 sResult = Adventure.htblCharacters(sArgs).ListExits
2189 Else
2190 DisplayError("Bad Argument to &perc;ListExits[]&perc; - Character Key """ & sArgs & """ not found")
2191 End If
2192 Case "ListObjectsAtLocation".ToLower
2193 If Adventure.htblLocations.ContainsKey(sArgs) Then
2194 sResult = Adventure.htblLocations(sArgs).ObjectsInLocation(clsLocation.WhichObjectsToListEnum.AllObjects, True).List(, , ArticleTypeEnum.Indefinite)
2195 Else
2196 DisplayError("Bad Argument to &perc;ListObjectsAtLocation[]&perc; - Location Key """ & sArgs & """ not found")
2197 End If
2198
2199 Case "ListObjectsOn".ToLower
2200 If Adventure.htblObjects.ContainsKey(sArgs) Then
2201 sResult = Adventure.htblObjects(sArgs).Children(clsObject.WhereChildrenEnum.OnObject).List(, , ArticleTypeEnum.Indefinite)
2202 Else
2203 DisplayError("Bad Argument to &perc;ListObjectsOn[]&perc; - Object Key """ & sArgs & """ not found")
2204 End If
2205
2206 Case "ListObjectsIn".ToLower
2207 If Adventure.htblObjects.ContainsKey(sArgs) Then
2208 sResult = Adventure.htblObjects(sArgs).Children(clsObject.WhereChildrenEnum.InsideObject).List(, , ArticleTypeEnum.Indefinite)
2209 Else
2210 DisplayError("Bad Argument to &perc;ListObjectsIn[]&perc; - Object Key """ & sArgs & """ not found")
2211 End If
2212
2213 Case "ListObjectsOnAndIn".ToLower
2214 If htblObjects.Count > 0 Then
2215 For Each ob As clsObject In htblObjects.Values
2216 If htblObjects.Count = 1 OrElse ob.Children(clsObject.WhereChildrenEnum.InsideOrOnObject).Count > 0 Then
2217 If sResult <> "" Then pSpace(sResult)
2218 sResult &= ob.DisplayObjectChildren
2219 End If
2220 Next
2221 Else
2222 DisplayError("Bad Argument to &perc;ListObjectsOnAndIn[]&perc; - Object Key """ & sArgs & """ not found")
2223 End If
2224 Case "ListWorn".ToLower
2225 If Adventure.htblCharacters.ContainsKey(sArgs) Then
2226 sResult = Adventure.htblCharacters(sArgs).WornObjects.List("and", True, ArticleTypeEnum.Indefinite)
2227 Else
2228 DisplayError("Bad Argument to &perc;ListWorn[]&perc; - Character Key """ & sArgs & """ not found")
2229 End If
2230 Case "LocationName".ToLower
2231 If Adventure.htblLocations.ContainsKey(sArgs) Then
2232 sResult = Adventure.htblLocations(sArgs).ShortDescription.ToString
2233 Else
2234 DisplayError("Bad Argument to &perc;LocationName[]&perc; - Location Key """ & sArgs & """ not found")
2235 End If
2236
2237 Case "LocationOf".ToLower
2238 If Adventure.htblCharacters.ContainsKey(sArgs) Then
2239 sResult = Adventure.htblCharacters(sArgs).Location.LocationKey
2240 ElseIf Adventure.htblObjects.ContainsKey(sArgs) Then
2241 For Each sLocKey As String In Adventure.htblObjects(sArgs).LocationRoots.Keys
2242 If sResult <> "" Then sResult &= "|"
2243 sResult &= sLocKey
2244 Next
2245 Else
2246 DisplayError("Bad Argument to &perc;LocationOf[]&perc; - Character Key """ & sArgs & """ not found")
2247 End If
2248
2249 Case "NumberAsText".ToLower
2250 sResult = NumberToString(sArgs)
2251
2252 Case "ObjectName".ToLower
2253 sResult = htblObjects.List(, , ArticleTypeEnum.Indefinite)
2254
2255 Case "ObjectsIn".ToLower
2256 If Adventure.htblObjects.ContainsKey(sArgs) Then
2257 For Each ob As clsObject In Adventure.htblObjects(sArgs).Children(clsObject.WhereChildrenEnum.InsideObject).Values
2258 If sResult <> "" Then sResult &= "|"
2259 sResult &= ob.Key
2260 Next
2261 Else
2262 DisplayError("Bad Argument to &perc;ObjectsIn[]&perc; - Object Key """ & sArgs & """ not found")
2263 End If
2264 bAllowBlank = True
2265
2266 Case "ParentOf".ToLower
2267 For Each ob As clsObject In htblObjects.Values
2268 If sResult <> "" Then sResult &= "|"
2269 sResult &= ob.Parent
2270 Next
2271 For Each ch As clsCharacter In htblCharacters.Values
2272 If sResult <> "" Then sResult &= "|"
2273 sResult &= ch.Parent
2274 Next
2275 Case "PCase".ToLower
2276 sResult = PCase(sArgs, , bExpression)
2277
2278 Case "PopUpChoice".ToLower
2279 Dim sKeys() As String = sArgs.Split(","c) ' TODO - Improve this to read quotes and commas properly
2280 If sKeys.Length = 3 Then
2281 ' For now - needs improving
2282 Dim var As New clsVariable
2283 var.Type = clsVariable.VariableTypeEnum.Text
2284 Select Case MsgBox(sKeys(0) & vbCrLf & vbCrLf & "Yes for " & sKeys(1) & ", No for " & sKeys(2) & " (dialog box to be improved!)", MsgBoxStyle.YesNo)
2285 Case MsgBoxResult.Yes
2286 var.SetToExpression(sKeys(1))
2287 Case MsgBoxResult.No
2288 var.SetToExpression(sKeys(2))
2289 End Select
2290 sResult = var.StringValue
2291 If bExpression Then sResult = """" & sResult & """"
2292 Else
2293 DisplayError("Bad arguments to PopUpChoice function: PopUpChoice[prompt, choice1, choice2]")
2294 End If
2295
2296 Case "PopUpInput".ToLower
2297 Dim sKeys() As String = sArgs.Split(","c) ' TODO - Improve this to read quotes and commas properly
2298 If sKeys.Length = 1 OrElse sKeys.Length = 2 Then
2299 Dim sDefault As String = ""
2300 If sKeys.Length = 2 Then sDefault = EvaluateExpression(sKeys(1))
2301 sResult = """" & InputBox(EvaluateExpression(sKeys(0)), "ADRIFT", sDefault) & """"
2302 Else
2303 DisplayError("Expecting 1 or two arguments to PopUpInput[prompt, default]")
2304 End If
2305
2306 Case "PrevListObjectsOn".ToLower
2307 ' Maintain a 'last turn' state
2308 ' Call ListObjectsOn on this state
2309 sResult = PreviousFunction(sFunction, sArgs)
2310
2311 Case "PrevParentOf".ToLower
2312 ' Get rid of PrevParent, and do the same as above
2313 For Each ob As clsObject In htblObjects.Values
2314 If sResult <> "" Then sResult &= "|"
2315 sResult &= ob.PrevParent
2316 Next
2317 For Each ch As clsCharacter In htblCharacters.Values
2318 If sResult <> "" Then sResult &= "|"
2319 sResult &= ch.PrevParent
2320 Next
2321
2322 Case "PropertyValue".ToLower
2323 bAllowBlank = True
2324 Dim sKeys() As String = Split(sArgs.Replace(" ", ""), ",")
2325 If sKeys.Length = 2 Then
2326 If htblObjects.Count + htblCharacters.Count + htblLocations.Count > 0 Then
2327 Dim arlOutput As New StringArrayList
2328 For Each ob As clsObject In htblObjects.Values
2329 If ob.HasProperty(sKeys(1)) Then
2330 arlOutput.Add(ob.GetPropertyValue(sKeys(1)))
2331 Else
2332 DisplayError("Bad 2nd Argument to &perc;PropertyValue[]&perc; - Property Key """ & sKeys(1) & """ not found")
2333 End If
2334 Next
2335 For Each ch As clsCharacter In htblCharacters.Values
2336 If ch.HasProperty(sKeys(1)) Then
2337 arlOutput.Add(ch.GetPropertyValue(sKeys(1)))
2338 Else
2339 DisplayError("Bad 2nd Argument to &perc;PropertyValue[]&perc; - Property Key """ & sKeys(1) & """ not found")
2340 End If
2341 Next
2342 For Each l As clsLocation In htblLocations.Values
2343 If l.HasProperty(sKeys(1)) Then
2344 arlOutput.Add(l.GetPropertyValue(sKeys(1)))
2345 Else
2346 DisplayError("Bad 2nd Argument to &perc;PropertyValue[]&perc; - Property Key """ & sKeys(1) & """ not found")
2347 End If
2348 Next
2349 sResult = arlOutput.List
2350 Else
2351 ' Only warn about the first arg if it isn't from a function
2352 Dim sOrig As String = Split(sOldArgs.Replace(" ", ""), ",")(0)
2353 If sOrig = sKeys(0) Then DisplayError("Bad 1st Argument to &perc;PropertyValue[]&perc; - Object/Character Key """ & sKeys(0) & """ not found")
2354 End If
2355 Else
2356 DisplayError("Bad call to &perc;PropertyValue[]&perc; - Two arguments expected; Object Key, Property Key")
2357 End If
2358
2359 Case "Sum".ToLower
2360 ' Sum the numbers from a string
2361 Dim sInput As New System.Text.StringBuilder
2362 For Each c As Char In sArgs.ToCharArray
2363 Select Case c
2364 Case "0"c To "9"c, "-"c
2365 sInput.Append(c)
2366 Case Else
2367 sInput.Append(" ")
2368 End Select
2369 Next
2370 While sInput.ToString.Contains(" ")
2371 sInput.Replace(" ", " ")
2372 End While
2373 Dim iTotal As Integer = 0
2374 For Each s As String In sInput.ToString.Split(" "c)
2375 iTotal += SafeInt(s)
2376 Next
2377 sResult = iTotal.ToString
2378
2379 Case "TaskCompleted".ToLower
2380 If Adventure.htblTasks.ContainsKey(sArgs) Then
2381 sResult = Adventure.htblTasks(sArgs).Completed.ToString
2382 Else
2383 DisplayError("Bad Argument to &perc;TaskCompleted[]&perc; - Task Key """ & sArgs & """ not found")
2384 End If
2385
2386 Case "TheObject".ToLower, "TheObjects".ToLower
2387 sResult = htblObjects.List
2388
2389 Case "UCase".ToLower
2390 sResult = sArgs.ToUpper
2391
2392 Case "Worn".ToLower
2393 If Adventure.htblCharacters.ContainsKey(sArgs) Then
2394 For Each ob As clsObject In Adventure.htblCharacters(sArgs).WornObjects.Values
2395 If sResult <> "" Then sResult &= "|"
2396 sResult &= ob.Key
2397 Next
2398 Else
2399 DisplayError("Bad Argument to &perc;Worn[]&perc; - Character Key """ & sArgs & """ not found")
2400 End If
2401 End Select
2402
2403 If sResult = "" AndAlso Not bAllowBlank Then
2404 DisplayError("Bad Function - Nothing output")
2405 End If
2406
2407 sText = ReplaceIgnoreCase(sText, "%" & sFunction & "[" & sArgs & "]%", sResult)
2408
2409 Else
2410 Dim sBadFunction As String = ""
2411 If sText.ToLower.Contains("%" & sFunction) Then sBadFunction = "%" & sFunction
2412 If sText.ToLower.Contains("%" & sFunction & "[") Then sBadFunction = "%" & sFunction & "["
2413 If sText.ToLower.Contains("%" & sFunction & "[" & sArgs.ToLower) Then sBadFunction = "%" & sFunction & "[" & sArgs
2414 If sText.ToLower.Contains("%" & sFunction & "[" & sArgs.ToLower & "]") Then sBadFunction = "%" & sFunction & "[" & sArgs & "]"
2415 sText = ReplaceIgnoreCase(sText, sBadFunction, " <c><u>" & sBadFunction.Replace("%", "&perc;") & "</u></c>")
2416
2417 DisplayError("Bad function " & sFunction)
2418
2419 End If
2420 Else
2421 sText = ReplaceIgnoreCase(sText, "%" & sFunction & "[]%", "")
2422 sText = ReplaceIgnoreCase(sText, "%" & sFunction & "[", "")
2423
2424 DisplayError("No arguments given to function " & sFunction)
2425
2426 End If
2427
2428 iMatchLoc = sInstr(sText.ToLower, "%" & sFunction & "[")
2429 End While
2430 End If
2431
2432 Loop While sText <> sCheck
2433 End If
2434
2435
2436 If bAllowOO Then
2437 Dim sPrev As String
2438 Do
2439 sPrev = sText
2440 sText = ReplaceOO(sText, bExpression)
2441 Loop While sText <> sPrev
2442 End If
2443
2444
2445 Dim rePerspective As New System.Text.RegularExpressions.Regex("\[(?<first>.*?)/(?<second>.*?)/(?<third>.*?)\]")
2446 While rePerspective.IsMatch(sText)
2447 Dim match As System.Text.RegularExpressions.Match = rePerspective.Match(sText)
2448 Dim sFirst As String = match.Groups("first").Value
2449 If sFirst.Contains("[") Then sFirst = sFirst.Substring(sFirst.LastIndexOf("[") + 1)
2450 Dim sSecond As String = match.Groups("second").Value
2451 Dim sThird As String = match.Groups("third").Value
2452 Dim sValue As String = ""
2453
2454 If sFirst.Contains("[") OrElse sFirst.Contains("]") OrElse sSecond.Contains("[") OrElse sSecond.Contains("]") OrElse sThird.Contains("[") OrElse sThird.Contains("]") Then Exit While
2455
2456 Select Case GetPerspective(match.Index)
2457 Case PerspectiveEnum.FirstPerson
2458 sValue = sFirst
2459 Case PerspectiveEnum.SecondPerson
2460 sValue = sSecond
2461 Case PerspectiveEnum.ThirdPerson
2462 sValue = sThird
2463 End Select
2464
2465 sText = sText.Replace("[" & sFirst & "/" & sSecond & "/" & sThird & "]", sValue)
2466 End While
2467
2468 For Each sGUID As String In dictGUIDs.Keys
2469 sText = sText.Replace(sGUID, dictGUIDs(sGUID))
2470 Next
2471
2472 Return sText
2473
2474 Catch ex As Exception
2475 ErrMsg("ReplaceFunctions error", ex)
2476 Return sText
2477 End Try
2478
2479 End Function
2480 Private Function GetPerspective(ByVal iOffset As Integer) As PerspectiveEnum
2481
2482 Dim iHighest As Integer = 0
2483 Dim ePerspective As PerspectiveEnum = PerspectiveEnum.None
2484
2485 #If Runner Then
2486 For Each p As PronounInfo In UserSession.PronounKeys
2487 If iOffset >= p.Offset AndAlso p.Offset > iHighest Then
2488 ePerspective = Adventure.htblCharacters(p.Key).Perspective
2489 iHighest = p.Offset
2490 End If
2491 Next
2492 #End If
2493
2494 If ePerspective <> PerspectiveEnum.None Then
2495 Return ePerspective
2496 Else
2497 Return Adventure.Player.Perspective
2498 End If
2499
2500 End Function
2501
2502
2503 ' Convert a number between 0 and 999 into words.
2504 Private Function GroupToWords(ByVal num As Integer) As _
2505 String
2506 Static one_to_nineteen() As String = {"zero", "one",
2507 "two", "three", "four", "five", "six", "seven",
2508 "eight", "nine", "ten", "eleven", "twelve",
2509 "thirteen", "fourteen", "fifteen", "sixteen",
2510 "seventeen", "eighteen", "nineteen"}
2511 Static multiples_of_ten() As String = {"twenty",
2512 "thirty", "forty", "fifty", "sixty", "seventy",
2513 "eighty", "ninety"}
2514
2515 ' If the number is 0, return an empty string.
2516 If num = 0 Then Return ""
2517
2518 ' Handle the hundreds digit.
2519 Dim digit As Integer
2520 Dim result As String = ""
2521 Dim bAnd As Boolean = False
2522 If num > 99 Then
2523 digit = num \ 100
2524 num = num Mod 100
2525 bAnd = True
2526 result = one_to_nineteen(digit) & " hundred"
2527 End If
2528
2529 ' If num = 0, we have hundreds only.
2530 If num = 0 Then Return result.Trim()
2531
2532 If bAnd Then result &= " and"
2533
2534 ' See if the rest is less than 20.
2535 If num < 20 Then
2536 ' Look up the correct name.
2537 result &= " " & one_to_nineteen(num)
2538 Else
2539 ' Handle the tens digit.
2540 digit = num \ 10
2541 num = num Mod 10
2542 result &= " " & multiples_of_ten(digit - 2)
2543
2544 ' Handle the final digit.
2545 If num > 0 Then
2546 result &= " " & one_to_nineteen(num)
2547 End If
2548 End If
2549
2550 Return result.Trim()
2551 End Function
2552
2553 ' Return a word representation of the whole number value.
2554 Private Function NumberToString(ByVal num_str As String, Optional ByVal use_us_group_names As Boolean = True) As String
2555
2556 Dim result As String = ""
2557 Dim sIn As String = num_str
2558
2559 If Not IsNumeric(num_str) Then
2560 Dim v As New clsVariable
2561 v.SetToExpression(num_str)
2562 num_str = v.IntValue.ToString
2563 End If
2564
2565 Try
2566
2567 ' Get the appropiate group names.
2568 Dim groups() As String
2569 If use_us_group_names Then
2570 groups = New String() {"", "thousand", "million",
2571 "billion", "trillion", "quadrillion",
2572 "quintillion", "sextillion", "septillion",
2573 "octillion", "nonillion", "decillion",
2574 "undecillion", "duodecillion", "tredecillion",
2575 "quattuordecillion", "quindecillion",
2576 "sexdecillion", "septendecillion",
2577 "octodecillion", "novemdecillion",
2578 "vigintillion"}
2579 Else
2580 groups = New String() {"", "thousand", "million",
2581 "milliard", "billion", "1000 billion",
2582 "trillion", "1000 trillion", "quadrillion",
2583 "1000 quadrillion", "quintillion", "1000 " &
2584 "quintillion", "sextillion", "1000 sextillion",
2585 "septillion", "1000 septillion", "octillion",
2586 "1000 octillion", "nonillion", "1000 " &
2587 "nonillion", "decillion", "1000 decillion"}
2588 End If
2589
2590 ' Clean the string a bit.
2591 ' Remove "$", ",", leading zeros, and
2592 ' anything after a decimal point.
2593 Const CURRENCY As String = "$"
2594 Const SEPARATOR As String = ","
2595 Const DECIMAL_POINT As String = "."
2596 num_str = num_str.Replace(CURRENCY,
2597 "").Replace(SEPARATOR, "")
2598 num_str = num_str.TrimStart(New Char() {"0"c})
2599 Dim pos As Integer = num_str.IndexOf(DECIMAL_POINT)
2600 If pos = 0 Then
2601 Return "zero"
2602 ElseIf pos > 0 Then
2603 num_str = num_str.Substring(0, pos - 1)
2604 End If
2605
2606 ' See how many groups there will be.
2607 Dim num_groups As Integer = (num_str.Length + 2) \ 3
2608
2609 ' Pad so length is a multiple of 3.
2610 num_str = num_str.PadLeft(num_groups * 3, " "c)
2611
2612 ' Process the groups, largest first.
2613 Dim group_num As Integer
2614 For group_num = num_groups - 1 To 0 Step -1
2615 ' Get the next three digits.
2616 Dim group_str As String = num_str.Substring(0, 3)
2617 num_str = num_str.Substring(3)
2618 Dim group_value As Integer = CInt(group_str)
2619
2620 ' Convert the group into words.
2621 If group_value > 0 Then
2622 If group_num >= groups.Length Then
2623 result &= GroupToWords(group_value) &
2624 " ?, "
2625 Else
2626 result &= GroupToWords(group_value) &
2627 " " & groups(group_num) & ", "
2628 End If
2629 End If
2630 Next group_num
2631
2632 ' Remove the trailing ", ".
2633 If result.EndsWith(", ") Then
2634 result = result.Substring(0, result.Length - 2)
2635 End If
2636
2637 result = result.Trim()
2638
2639 Catch ex As Exception
2640 ErrMsg("NumberToString error parsing """ & sIn & """", ex)
2641 End Try
2642
2643 If result = "" Then result = "zero"
2644 Return result
2645
2646 End Function
2647
2648 Public Function OppositeDirection(ByVal dir As DirectionsEnum) As DirectionsEnum
2649 Select Case dir
2650 Case DirectionsEnum.North
2651 Return DirectionsEnum.South
2652 Case DirectionsEnum.NorthEast
2653 Return DirectionsEnum.SouthWest
2654 Case DirectionsEnum.East
2655 Return DirectionsEnum.West
2656 Case DirectionsEnum.SouthEast
2657 Return DirectionsEnum.NorthWest
2658 Case DirectionsEnum.South
2659 Return DirectionsEnum.North
2660 Case DirectionsEnum.SouthWest
2661 Return DirectionsEnum.NorthEast
2662 Case DirectionsEnum.West
2663 Return DirectionsEnum.East
2664 Case DirectionsEnum.NorthWest
2665 Return DirectionsEnum.SouthEast
2666 Case DirectionsEnum.Up
2667 Return DirectionsEnum.Down
2668 Case DirectionsEnum.Down
2669 Return DirectionsEnum.Up
2670 Case DirectionsEnum.In
2671 Return DirectionsEnum.Out
2672 Case DirectionsEnum.Out
2673 Return DirectionsEnum.In
2674 Case Else
2675 Return dir
2676 End Select
2677 End Function
2678
2679 Public Function ReplaceIgnoreCase(ByVal Expression As String, ByVal Find As String, ByVal Replacement As String) As String
2680 If Replacement Is Nothing Then Replacement = ""
2681 Dim regex As New System.Text.RegularExpressions.Regex(Find.Replace("[", "\[").Replace("]", "\]").Replace("(", "\(").Replace(")", "\)").Replace("|", "\|").Replace("*", "\*").Replace("?", "\?").Replace("$", "\$").Replace("^", "\^").Replace("+", "\+"), System.Text.RegularExpressions.RegexOptions.IgnoreCase)
2682 Return regex.Replace(Expression, Replacement.Replace("$", "$$"), 1) ' Prevent Substitutions (http://msdn.microsoft.com/en-us/library/ewy2t5e0.aspx)
2683 End Function
2684
2685 Public Function PCase(ByVal sText As String, Optional ByVal bStrictLower As Boolean = False, Optional ByVal bExpression As Boolean = False) As String
2686 Dim bQuotes As Boolean = False
2687 If bExpression AndAlso sText.StartsWith("""") AndAlso sText.EndsWith("""") Then
2688 bQuotes = True
2689 sText = sText.Substring(1, sText.Length - 2)
2690 End If
2691 PCase = ""
2692
2693 Try
2694 If sText.Length > 0 Then
2695 PCase = Left(sText, 1).ToUpper
2696 If sText.Length > 1 Then
2697 If bStrictLower Then
2698 PCase &= Right(sText, sText.Length - 1).ToLower
2699 Else
2700 PCase &= Right(sText, sText.Length - 1)
2701 End If
2702 End If
2703 Else
2704 Return ""
2705 End If
2706 Finally
2707 If bQuotes Then PCase = """" & PCase & """"
2708 End Try
2709 End Function
2710
2711
2712 Public Function GetFunctionArgs(ByVal sText As String) As String
2713 Try
2714 If sInstr(sText, "[") = 0 OrElse sInstr(sText, "]") = 0 Then Return ""
2715
2716 ' Work out this bracket chunk, then run ReplaceFunctions on it
2717 Dim iOffset As Integer = 1
2718 Dim iLevel As Integer = 1
2719
2720 While iLevel > 0
2721 Select Case sText.Substring(iOffset, 1)
2722 Case "["
2723 iLevel += 1
2724 Case "]"
2725 iLevel -= 1
2726 Case Else
2727 ' Ignore
2728 End Select
2729 iOffset += 1
2730 End While
2731
2732 Return sText.Substring(1, iOffset - 2)
2733 Catch ex As Exception
2734 DisplayError("Error obtaining function arguments from """ & sText & """")
2735 Return ""
2736 End Try
2737 End Function
2738
2739 Public Function EnumParsePropertyPropertyOf(ByVal sValue As String) As clsProperty.PropertyOfEnum
2740 Select Case sValue
2741 Case "Objects"
2742 Return clsProperty.PropertyOfEnum.Objects
2743 Case "Characters"
2744 Return clsProperty.PropertyOfEnum.Characters
2745 Case "Locations"
2746 Return clsProperty.PropertyOfEnum.Locations
2747 Case "AnyItem"
2748 Return clsProperty.PropertyOfEnum.AnyItem
2749 Case Else
2750 Throw New Exception("Value " & sValue & " not parsed!")
2751 Return Nothing
2752 End Select
2753 End Function
2754
2755 Public Function EnumParsePropertyType(ByVal sValue As String) As clsProperty.PropertyTypeEnum
2756 Select Case sValue
2757 Case "CharacterKey"
2758 Return clsProperty.PropertyTypeEnum.CharacterKey
2759 Case "Integer"
2760 Return clsProperty.PropertyTypeEnum.Integer
2761 Case "LocationGroupKey"
2762 Return clsProperty.PropertyTypeEnum.LocationGroupKey
2763 Case "LocationKey"
2764 Return clsProperty.PropertyTypeEnum.LocationKey
2765 Case "ObjectKey"
2766 Return clsProperty.PropertyTypeEnum.ObjectKey
2767 Case "SelectionOnly"
2768 Return clsProperty.PropertyTypeEnum.SelectionOnly
2769 Case "StateList"
2770 Return clsProperty.PropertyTypeEnum.StateList
2771 Case "ValueList"
2772 Return clsProperty.PropertyTypeEnum.ValueList
2773 Case "Text"
2774 Return clsProperty.PropertyTypeEnum.Text
2775 Case Else
2776 Throw New Exception("Value " & sValue & " not parsed!")
2777 Return Nothing
2778 End Select
2779 End Function
2780
2781 Public Function EnumParseMoveCharacter(ByVal sValue As String) As clsAction.MoveCharacterToEnum
2782 Select Case sValue
2783 Case "InDirection"
2784 Return clsAction.MoveCharacterToEnum.InDirection
2785 Case "ToLocation"
2786 Return clsAction.MoveCharacterToEnum.ToLocation
2787 Case "ToLocationGroup"
2788 Return clsAction.MoveCharacterToEnum.ToLocationGroup
2789 Case "ToLyingOn"
2790 Return clsAction.MoveCharacterToEnum.ToLyingOn
2791 Case "ToSameLocationAs"
2792 Return clsAction.MoveCharacterToEnum.ToSameLocationAs
2793 Case "ToSittingOn"
2794 Return clsAction.MoveCharacterToEnum.ToSittingOn
2795 Case "ToStandingOn"
2796 Return clsAction.MoveCharacterToEnum.ToStandingOn
2797 Case "ToSwitchWith"
2798 Return clsAction.MoveCharacterToEnum.ToSwitchWith
2799 Case "InsideObject"
2800 Return clsAction.MoveCharacterToEnum.InsideObject
2801 Case "OntoCharacter"
2802 Return clsAction.MoveCharacterToEnum.OntoCharacter
2803 Case "ToParentLocation"
2804 Return clsAction.MoveCharacterToEnum.ToParentLocation
2805 Case "ToGroup"
2806 Return clsAction.MoveCharacterToEnum.ToGroup
2807 Case "FromGroup"
2808 Return clsAction.MoveCharacterToEnum.FromGroup
2809 Case Else
2810 Throw New Exception("Value " & sValue & " not parsed!")
2811 Return Nothing
2812 End Select
2813 End Function
2814
2815 Public Function EnumParseMoveLocation(ByVal sValue As String) As clsAction.MoveLocationToEnum
2816 Select Case sValue
2817 Case "ToGroup"
2818 Return clsAction.MoveLocationToEnum.ToGroup
2819 Case "FromGroup"
2820 Return clsAction.MoveLocationToEnum.FromGroup
2821 Case Else
2822 Throw New Exception("Value " & sValue & " not parsed!")
2823 Return Nothing
2824 End Select
2825 End Function
2826
2827 Public Function EnumParseSetTask(ByVal sValue As String) As clsAction.SetTasksEnum
2828 Select Case sValue
2829 Case "Execute"
2830 Return clsAction.SetTasksEnum.Execute
2831 Case "Unset"
2832 Return clsAction.SetTasksEnum.Unset
2833 Case Else
2834 Throw New Exception("Value " & sValue & " not parsed!")
2835 Return Nothing
2836 End Select
2837 End Function
2838
2839 Public Function EnumParseEndGame(ByVal sValue As String) As clsAction.EndGameEnum
2840 Select Case sValue
2841 Case "Win"
2842 Return clsAction.EndGameEnum.Win
2843 Case "Lose"
2844 Return clsAction.EndGameEnum.Lose
2845 Case "Neutral"
2846 Return clsAction.EndGameEnum.Neutral
2847 Case Else
2848 Throw New Exception("Value " & sValue & " not parsed!")
2849 Return Nothing
2850 End Select
2851 End Function
2852
2853 Public Function EnumParseMoveObject(ByVal sValue As String) As clsAction.MoveObjectToEnum
2854 Select Case sValue
2855 Case "InsideObject"
2856 Return clsAction.MoveObjectToEnum.InsideObject
2857 Case "OntoObject"
2858 Return clsAction.MoveObjectToEnum.OntoObject
2859 Case "ToCarriedBy"
2860 Return clsAction.MoveObjectToEnum.ToCarriedBy
2861 Case "ToLocation"
2862 Return clsAction.MoveObjectToEnum.ToLocation
2863 Case "ToLocationGroup"
2864 Return clsAction.MoveObjectToEnum.ToLocationGroup
2865 Case "ToPartOfCharacter"
2866 Return clsAction.MoveObjectToEnum.ToPartOfCharacter
2867 Case "ToPartOfObject"
2868 Return clsAction.MoveObjectToEnum.ToPartOfObject
2869 Case "ToSameLocationAs"
2870 Return clsAction.MoveObjectToEnum.ToSameLocationAs
2871 Case "ToWornBy"
2872 Return clsAction.MoveObjectToEnum.ToWornBy
2873 Case "ToGroup"
2874 Return clsAction.MoveObjectToEnum.ToGroup
2875 Case "FromGroup"
2876 Return clsAction.MoveObjectToEnum.FromGroup
2877 Case Else
2878 Throw New Exception("Value " & sValue & " not parsed!")
2879 Return Nothing
2880 End Select
2881 End Function
2882
2883 Public Function EnumParseMust(ByVal sValue As String) As clsRestriction.MustEnum
2884 Select Case sValue
2885 Case "Must"
2886 Return clsRestriction.MustEnum.Must
2887 Case "MustNot"
2888 Return clsRestriction.MustEnum.MustNot
2889 Case Else
2890 Throw New Exception("Value " & sValue & " not parsed!")
2891 Return Nothing
2892 End Select
2893 End Function
2894
2895 Public Function EnumParseLocation(ByVal sValue As String) As clsRestriction.LocationEnum
2896 If Adventure.dVersion < 5.000015 Then
2897 If sValue = "SeenByCharacter" Then sValue = "HaveBeenSeenByCharacter"
2898 End If
2899 Select Case sValue
2900 Case "BeInGroup"
2901 Return clsRestriction.LocationEnum.BeInGroup
2902 Case "HaveBeenSeenByCharacter"
2903 Return clsRestriction.LocationEnum.HaveBeenSeenByCharacter
2904 Case "HaveProperty"
2905 Return clsRestriction.LocationEnum.HaveProperty
2906 Case "BeLocation"
2907 Return clsRestriction.LocationEnum.BeLocation
2908 Case "Exist"
2909 Return clsRestriction.LocationEnum.Exist
2910 Case Else
2911 Throw New Exception("Value " & sValue & " not parsed!")
2912 Return Nothing
2913 End Select
2914 End Function
2915
2916 Public Function EnumParseDirections(ByVal sValue As String) As DirectionsEnum
2917 Select Case sValue
2918 Case "Down"
2919 Return DirectionsEnum.Down
2920 Case "East"
2921 Return DirectionsEnum.East
2922 Case "In"
2923 Return DirectionsEnum.In
2924 Case "North"
2925 Return DirectionsEnum.North
2926 Case "NorthEast"
2927 Return DirectionsEnum.NorthEast
2928 Case "NorthWest"
2929 Return DirectionsEnum.NorthWest
2930 Case "Out"
2931 Return DirectionsEnum.Out
2932 Case "South"
2933 Return DirectionsEnum.South
2934 Case "SouthEast"
2935 Return DirectionsEnum.SouthEast
2936 Case "SouthWest"
2937 Return DirectionsEnum.SouthWest
2938 Case "Up"
2939 Return DirectionsEnum.Up
2940 Case "West"
2941 Return DirectionsEnum.West
2942 Case Else
2943 Throw New Exception("Value " & sValue & " not parsed!")
2944 Return Nothing
2945 End Select
2946 End Function
2947
2948 Public Function EnumParseBeforeAfter(ByVal sValue As String) As clsTask.BeforeAfterEnum
2949 Select Case sValue
2950 Case "After"
2951 Return clsTask.BeforeAfterEnum.After
2952 Case "Before"
2953 Return clsTask.BeforeAfterEnum.Before
2954 Case Else
2955 Throw New Exception("Value " & sValue & " not parsed!")
2956 Return Nothing
2957 End Select
2958 End Function
2959
2960 Public Function EnumParseVariable(ByVal sValue As String) As clsRestriction.VariableEnum
2961 Select Case sValue
2962 Case "EqualTo"
2963 Return clsRestriction.VariableEnum.EqualTo
2964 Case "GreaterThan"
2965 Return clsRestriction.VariableEnum.GreaterThan
2966 Case "GreaterThanOrEqualTo"
2967 Return clsRestriction.VariableEnum.GreaterThanOrEqualTo
2968 Case "LessThan"
2969 Return clsRestriction.VariableEnum.LessThan
2970 Case "LessThanOrEqualTo"
2971 Return clsRestriction.VariableEnum.LessThanOrEqualTo
2972 Case "Contain"
2973 Return clsRestriction.VariableEnum.Contain
2974 Case Else
2975 Return Nothing
2976 End Select
2977 End Function
2978
2979 Public Function EnumParseItem(ByVal sValue As String) As clsRestriction.ItemEnum
2980 Select Case sValue
2981 Case "BeAtLocation"
2982 Return clsRestriction.ItemEnum.BeAtLocation
2983 Case "BeCharacter"
2984 Return clsRestriction.ItemEnum.BeCharacter
2985 Case "BeInGroup"
2986 Return clsRestriction.ItemEnum.BeInGroup
2987 Case "BeInSameLocationAsCharacter"
2988 Return clsRestriction.ItemEnum.BeInSameLocationAsCharacter
2989 Case "BeInSameLocationAsObject"
2990 Return clsRestriction.ItemEnum.BeInSameLocationAsObject
2991 Case "BeInsideObject"
2992 Return clsRestriction.ItemEnum.BeInsideObject
2993 Case "BeLocation"
2994 Return clsRestriction.ItemEnum.BeLocation
2995 Case "BeObject"
2996 Return clsRestriction.ItemEnum.BeObject
2997 Case "BeOnCharacter"
2998 Return clsRestriction.ItemEnum.BeOnCharacter
2999 Case "BeOnObject"
3000 Return clsRestriction.ItemEnum.BeOnObject
3001 Case "BeType"
3002 Return clsRestriction.ItemEnum.BeType
3003 Case "Exist"
3004 Return clsRestriction.ItemEnum.Exist
3005 Case "HaveProperty"
3006 Return clsRestriction.ItemEnum.HaveProperty
3007 Case Else
3008 TODO()
3009 End Select
3010 End Function
3011
3012 Public Function EnumParseCharacter(ByVal sValue As String) As clsRestriction.CharacterEnum
3013 Select Case sValue
3014 Case "BeAlone"
3015 Return clsRestriction.CharacterEnum.BeAlone
3016 Case "BeAloneWith"
3017 Return clsRestriction.CharacterEnum.BeAloneWith
3018 Case "BeAtLocation"
3019 Return clsRestriction.CharacterEnum.BeAtLocation
3020 Case "BeCharacter"
3021 Return clsRestriction.CharacterEnum.BeCharacter
3022 Case "BeInConversationWith"
3023 Return clsRestriction.CharacterEnum.BeInConversationWith
3024 Case "Exist"
3025 Return clsRestriction.CharacterEnum.Exist
3026 Case "HaveRouteInDirection"
3027 Return clsRestriction.CharacterEnum.HaveRouteInDirection
3028 Case "HaveSeenCharacter"
3029 Return clsRestriction.CharacterEnum.HaveSeenCharacter
3030 Case "HaveSeenLocation"
3031 Return clsRestriction.CharacterEnum.HaveSeenLocation
3032 Case "HaveSeenObject"
3033 Return clsRestriction.CharacterEnum.HaveSeenObject
3034 Case "BeHoldingObject"
3035 Return clsRestriction.CharacterEnum.BeHoldingObject
3036 Case "BeInSameLocationAsCharacter"
3037 Return clsRestriction.CharacterEnum.BeInSameLocationAsCharacter
3038 Case "BeInSameLocationAsObject"
3039 Return clsRestriction.CharacterEnum.BeInSameLocationAsObject
3040 Case "BeLyingOnObject"
3041 Return clsRestriction.CharacterEnum.BeLyingOnObject
3042 Case "BeMemberOfGroup", "BeInGroup"
3043 Return clsRestriction.CharacterEnum.BeInGroup
3044 Case "BeOfGender"
3045 Return clsRestriction.CharacterEnum.BeOfGender
3046 Case "BeSittingOnObject"
3047 Return clsRestriction.CharacterEnum.BeSittingOnObject
3048 Case "BeStandingOnObject"
3049 Return clsRestriction.CharacterEnum.BeStandingOnObject
3050 Case "BeWearingObject"
3051 Return clsRestriction.CharacterEnum.BeWearingObject
3052 Case "BeWithinLocationGroup"
3053 Return clsRestriction.CharacterEnum.BeWithinLocationGroup
3054 Case "HaveProperty"
3055 Return clsRestriction.CharacterEnum.HaveProperty
3056 Case "BeInPosition"
3057 Return clsRestriction.CharacterEnum.BeInPosition
3058 Case "BeInsideObject"
3059 Return clsRestriction.CharacterEnum.BeInsideObject
3060 Case "BeOnObject"
3061 Return clsRestriction.CharacterEnum.BeOnObject
3062 Case "BeOnCharacter"
3063 Return clsRestriction.CharacterEnum.BeOnCharacter
3064 Case "BeVisibleToCharacter"
3065 Return clsRestriction.CharacterEnum.BeVisibleToCharacter
3066 Case Else
3067 Return Nothing
3068 End Select
3069
3070 End Function
3071
3072 Public Function EnumParseObject(ByVal sValue As String) As clsRestriction.ObjectEnum
3073 Select Case sValue
3074 Case "BeExactText"
3075 Return clsRestriction.ObjectEnum.BeExactText
3076 Case "BeAtLocation"
3077 Return clsRestriction.ObjectEnum.BeAtLocation
3078 Case "BeHeldByCharacter"
3079 Return clsRestriction.ObjectEnum.BeHeldByCharacter
3080 Case "BeHidden"
3081 Return clsRestriction.ObjectEnum.BeHidden
3082 Case "BeInGroup"
3083 Return clsRestriction.ObjectEnum.BeInGroup
3084 Case "BeInsideObject"
3085 Return clsRestriction.ObjectEnum.BeInsideObject
3086 Case "BeInState"
3087 Return clsRestriction.ObjectEnum.BeInState
3088 Case "BeOnObject"
3089 Return clsRestriction.ObjectEnum.BeOnObject
3090 Case "BePartOfCharacter"
3091 Return clsRestriction.ObjectEnum.BePartOfCharacter
3092 Case "BePartOfObject"
3093 Return clsRestriction.ObjectEnum.BePartOfObject
3094 Case "BeVisibleToCharacter"
3095 Return clsRestriction.ObjectEnum.BeVisibleToCharacter
3096 Case "BeWornByCharacter"
3097 Return clsRestriction.ObjectEnum.BeWornByCharacter
3098 Case "Exist"
3099 Return clsRestriction.ObjectEnum.Exist
3100 Case "HaveBeenSeenByCharacter"
3101 Return clsRestriction.ObjectEnum.HaveBeenSeenByCharacter
3102 Case "HaveProperty"
3103 Return clsRestriction.ObjectEnum.HaveProperty
3104 Case "BeObject"
3105 Return clsRestriction.ObjectEnum.BeObject
3106 Case Else
3107 Throw New Exception("Value " & sValue & " not parsed!")
3108 Return Nothing
3109 End Select
3110 End Function
3111
3112 Public Function EnumParseSubEventMeasure(ByVal sValue As String) As clsEvent.SubEvent.MeasureEnum
3113 Select Case sValue
3114 Case "Turns"
3115 Return clsEvent.SubEvent.MeasureEnum.Turns
3116 Case "Seconds"
3117 Return clsEvent.SubEvent.MeasureEnum.Seconds
3118 Case Else
3119 Throw New Exception("Value " & sValue & " not parsed!")
3120 Return Nothing
3121 End Select
3122 End Function
3123
3124 Public Function EnumParseSubEventWhat(ByVal sValue As String) As clsEvent.SubEvent.WhatEnum
3125 Select Case sValue
3126 Case "DisplayMessage"
3127 Return clsEvent.SubEvent.WhatEnum.DisplayMessage
3128 Case "ExecuteTask"
3129 Return clsEvent.SubEvent.WhatEnum.ExecuteTask
3130 Case "SetLook"
3131 Return clsEvent.SubEvent.WhatEnum.SetLook
3132 Case "UnsetTask"
3133 Return clsEvent.SubEvent.WhatEnum.UnsetTask
3134 Case Else
3135 Throw New Exception("Value " & sValue & " not parsed!")
3136 Return Nothing
3137 End Select
3138 End Function
3139
3140 Public Function EnumParseTaskType(ByVal sValue As String) As clsTask.TaskTypeEnum
3141 Select Case sValue
3142 Case "General"
3143 Return clsTask.TaskTypeEnum.General
3144 Case "Specific"
3145 Return clsTask.TaskTypeEnum.Specific
3146 Case "System"
3147 Return clsTask.TaskTypeEnum.System
3148 Case Else
3149 Throw New Exception("Value " & sValue & " not parsed!")
3150 Return Nothing
3151 End Select
3152 End Function
3153
3154 Public Function EnumParseSpecificType(ByVal sValue As String) As ReferencesType
3155 Select Case sValue
3156 Case "Character"
3157 Return ReferencesType.Character
3158 Case "Direction"
3159 Return ReferencesType.Direction
3160 Case "Number"
3161 Return ReferencesType.Number
3162 Case "Object"
3163 Return ReferencesType.Object
3164 Case "Text"
3165 Return ReferencesType.Text
3166 Case "Location"
3167 Return ReferencesType.Location
3168 Case "Item"
3169 Return ReferencesType.Item
3170 Case Else
3171 Throw New Exception("Value " & sValue & " not parsed!")
3172 Return Nothing
3173 End Select
3174 End Function
3175
3176 Public Function EnumParseCharacterType(ByVal sValue As String) As clsCharacter.CharacterTypeEnum
3177 Select Case sValue
3178 Case "NonPlayer"
3179 Return clsCharacter.CharacterTypeEnum.NonPlayer
3180 Case "Player"
3181 Return clsCharacter.CharacterTypeEnum.Player
3182 Case Else
3183 Throw New Exception("Value " & sValue & " not parsed!")
3184 Return Nothing
3185 End Select
3186 End Function
3187
3188 Public Function EnumParseVariableType(ByVal sValue As String) As clsVariable.VariableTypeEnum
3189 Select Case sValue
3190 Case "Numeric"
3191 Return clsVariable.VariableTypeEnum.Numeric
3192 Case "Text"
3193 Return clsVariable.VariableTypeEnum.Text
3194 Case Else
3195 Throw New Exception("Value " & sValue & " not parsed!")
3196 Return Nothing
3197 End Select
3198 End Function
3199
3200 Public Function EnumParseGroupType(ByVal sValue As String) As clsGroup.GroupTypeEnum
3201 Select Case sValue
3202 Case "Characters"
3203 Return clsGroup.GroupTypeEnum.Characters
3204 Case "Locations"
3205 Return clsGroup.GroupTypeEnum.Locations
3206 Case "Objects"
3207 Return clsGroup.GroupTypeEnum.Objects
3208 Case Else
3209 Throw New Exception("Value " & sValue & " not parsed!")
3210 Return Nothing
3211 End Select
3212 End Function
3213
3214 Public Function WriteEnum(ByVal e As clsAction.EndGameEnum) As String
3215 Select Case e
3216 Case clsAction.EndGameEnum.Win
3217 Return "Win"
3218 Case clsAction.EndGameEnum.Lose
3219 Return "Lose"
3220 Case clsAction.EndGameEnum.Neutral
3221 Return "Neutral"
3222 Case Else
3223 Return Nothing
3224 End Select
3225 End Function
3226
3227 Public Function WriteEnum(ByVal w As clsEvent.SubEvent.WhatEnum) As String
3228 Select Case w
3229 Case clsEvent.SubEvent.WhatEnum.DisplayMessage
3230 Return "DisplayMessage"
3231 Case clsEvent.SubEvent.WhatEnum.ExecuteTask
3232 Return "ExecuteTask"
3233 Case clsEvent.SubEvent.WhatEnum.SetLook
3234 Return "SetLook"
3235 Case clsEvent.SubEvent.WhatEnum.UnsetTask
3236 Return "UnsetTask"
3237 Case Else
3238 Return Nothing
3239 End Select
3240 End Function
3241
3242 Public Function WriteEnum(ByVal m As clsEvent.SubEvent.MeasureEnum) As String
3243 Select Case m
3244 Case clsEvent.SubEvent.MeasureEnum.Turns
3245 Return "Turns"
3246 Case clsEvent.SubEvent.MeasureEnum.Seconds
3247 Return "Seconds"
3248 Case Else
3249 Return Nothing
3250 End Select
3251 End Function
3252
3253 Public Function WriteEnum(ByVal d As DirectionsEnum) As String
3254 Select Case d
3255 Case DirectionsEnum.Down
3256 Return "Down"
3257 Case DirectionsEnum.East
3258 Return "East"
3259 Case DirectionsEnum.In
3260 Return "In"
3261 Case DirectionsEnum.North
3262 Return "North"
3263 Case DirectionsEnum.NorthEast
3264 Return "NorthEast"
3265 Case DirectionsEnum.NorthWest
3266 Return "NorthWest"
3267 Case DirectionsEnum.Out
3268 Return "Out"
3269 Case DirectionsEnum.South
3270 Return "South"
3271 Case DirectionsEnum.SouthEast
3272 Return "SouthEast"
3273 Case DirectionsEnum.SouthWest
3274 Return "SouthWest"
3275 Case DirectionsEnum.Up
3276 Return "Up"
3277 Case DirectionsEnum.West
3278 Return "West"
3279 End Select
3280 Return Nothing
3281 End Function
3282
3283 Public Function WriteEnum(ByVal p As clsProperty.PropertyOfEnum) As String
3284 Select Case p
3285 Case clsProperty.PropertyOfEnum.Objects
3286 Return "Objects"
3287 Case clsProperty.PropertyOfEnum.Characters
3288 Return "Characters"
3289 Case clsProperty.PropertyOfEnum.Locations
3290 Return "Locations"
3291 Case clsProperty.PropertyOfEnum.AnyItem
3292 Return "AnyItem"
3293 End Select
3294 Return Nothing
3295 End Function
3296
3297 Public Function WriteEnum(ByVal t As clsProperty.PropertyTypeEnum) As String
3298 Select Case t
3299 Case clsProperty.PropertyTypeEnum.CharacterKey
3300 Return "CharacterKey"
3301 Case clsProperty.PropertyTypeEnum.Integer
3302 Return "Integer"
3303 Case clsProperty.PropertyTypeEnum.LocationGroupKey
3304 Return "LocationGroupKey"
3305 Case clsProperty.PropertyTypeEnum.LocationKey
3306 Return "LocationKey"
3307 Case clsProperty.PropertyTypeEnum.ObjectKey
3308 Return "ObjectKey"
3309 Case clsProperty.PropertyTypeEnum.SelectionOnly
3310 Return "SelectionOnly"
3311 Case clsProperty.PropertyTypeEnum.StateList
3312 Return "StateList"
3313 Case clsProperty.PropertyTypeEnum.ValueList
3314 Return "ValueList"
3315 Case clsProperty.PropertyTypeEnum.Text
3316 Return "Text"
3317 End Select
3318 Return Nothing
3319 End Function
3320
3321 Public Function WriteEnum(ByVal m As clsRestriction.MustEnum) As String
3322 Select Case m
3323 Case clsRestriction.MustEnum.Must
3324 Return "Must"
3325 Case clsRestriction.MustEnum.MustNot
3326 Return "MustNot"
3327 End Select
3328 Return Nothing
3329 End Function
3330
3331 Public Function WriteEnum(ByVal l As clsRestriction.LocationEnum) As String
3332 Select Case l
3333 Case clsRestriction.LocationEnum.BeInGroup
3334 Return "BeInGroup"
3335 Case clsRestriction.LocationEnum.HaveBeenSeenByCharacter
3336 Return "HaveBeenSeenByCharacter"
3337 Case clsRestriction.LocationEnum.HaveProperty
3338 Return "HaveProperty"
3339 Case clsRestriction.LocationEnum.BeLocation
3340 Return "BeLocation"
3341 Case clsRestriction.LocationEnum.Exist
3342 Return "Exist"
3343 End Select
3344 Return Nothing
3345 End Function
3346
3347 Public Function WriteEnum(ByVal o As clsRestriction.ObjectEnum) As String
3348 Select Case o
3349 Case clsRestriction.ObjectEnum.BeAtLocation
3350 Return "BeAtLocation"
3351 Case clsRestriction.ObjectEnum.BeHeldByCharacter
3352 Return "BeHeldByCharacter"
3353 Case clsRestriction.ObjectEnum.BeInGroup
3354 Return "BeInGroup"
3355 Case clsRestriction.ObjectEnum.BeInsideObject
3356 Return "BeInsideObject"
3357 Case clsRestriction.ObjectEnum.BeInState
3358 Return "BeInState"
3359 Case clsRestriction.ObjectEnum.BeOnObject
3360 Return "BeOnObject"
3361 Case clsRestriction.ObjectEnum.BePartOfCharacter
3362 Return "BePartOfCharacter"
3363 Case clsRestriction.ObjectEnum.BePartOfObject
3364 Return "BePartOfObject"
3365 Case clsRestriction.ObjectEnum.BeVisibleToCharacter
3366 Return "BeVisibleToCharacter"
3367 Case clsRestriction.ObjectEnum.BeWornByCharacter
3368 Return "BeWornByCharacter"
3369 Case clsRestriction.ObjectEnum.Exist
3370 Return "Exist"
3371 Case clsRestriction.ObjectEnum.HaveBeenSeenByCharacter
3372 Return "HaveBeenSeenByCharacter"
3373 Case clsRestriction.ObjectEnum.HaveProperty
3374 Return "HaveProperty"
3375 Case clsRestriction.ObjectEnum.BeExactText
3376 Return "BeExactText"
3377 Case clsRestriction.ObjectEnum.BeHidden
3378 Return "BeHidden"
3379 Case clsRestriction.ObjectEnum.BeObject
3380 Return "BeObject"
3381 End Select
3382 Return Nothing
3383 End Function
3384
3385 Public Function WriteEnum(ByVal c As clsRestriction.ItemEnum) As String
3386 Select Case c
3387 Case clsRestriction.ItemEnum.BeAtLocation
3388 Return "BeAtLocation"
3389 Case clsRestriction.ItemEnum.BeCharacter
3390 Return "BeCharacter"
3391 Case clsRestriction.ItemEnum.BeInSameLocationAsCharacter
3392 Return "BeInSameLocationAsCharacter"
3393 Case clsRestriction.ItemEnum.BeInSameLocationAsObject
3394 Return "BeInSameLocationAsObject"
3395 Case clsRestriction.ItemEnum.BeInsideObject
3396 Return "BeInsideObject"
3397 Case clsRestriction.ItemEnum.BeLocation
3398 Return "BeLocation"
3399 Case clsRestriction.ItemEnum.BeInGroup
3400 Return "BeInGroup"
3401 Case clsRestriction.ItemEnum.BeObject
3402 Return "BeObject"
3403 Case clsRestriction.ItemEnum.BeOnCharacter
3404 Return "BeOnCharacter"
3405 Case clsRestriction.ItemEnum.Exist
3406 Return "Exist"
3407 Case clsRestriction.ItemEnum.HaveProperty
3408 Return "HaveProperty"
3409 Case clsRestriction.ItemEnum.BeType
3410 Return "BeType"
3411 Case Else
3412 TODO()
3413 End Select
3414 Return Nothing
3415 End Function
3416
3417 Public Function WriteEnum(ByVal c As clsRestriction.CharacterEnum) As String
3418 Select Case c
3419 Case clsRestriction.CharacterEnum.BeAlone
3420 Return "BeAlone"
3421 Case clsRestriction.CharacterEnum.BeAloneWith
3422 Return "BeAloneWith"
3423 Case clsRestriction.CharacterEnum.BeAtLocation
3424 Return "BeAtLocation"
3425 Case clsRestriction.CharacterEnum.BeCharacter
3426 Return "BeCharacter"
3427 Case clsRestriction.CharacterEnum.BeInConversationWith
3428 Return "BeInConversationWith"
3429 Case clsRestriction.CharacterEnum.Exist
3430 Return "Exist"
3431 Case clsRestriction.CharacterEnum.HaveRouteInDirection
3432 Return "HaveRouteInDirection"
3433 Case clsRestriction.CharacterEnum.HaveSeenCharacter
3434 Return "HaveSeenCharacter"
3435 Case clsRestriction.CharacterEnum.HaveSeenLocation
3436 Return "HaveSeenLocation"
3437 Case clsRestriction.CharacterEnum.HaveSeenObject
3438 Return "HaveSeenObject"
3439 Case clsRestriction.CharacterEnum.BeHoldingObject
3440 Return "BeHoldingObject"
3441 Case clsRestriction.CharacterEnum.BeInSameLocationAsCharacter
3442 Return "BeInSameLocationAsCharacter"
3443 Case clsRestriction.CharacterEnum.BeInSameLocationAsObject
3444 Return "BeInSameLocationAsObject"
3445 Case clsRestriction.CharacterEnum.BeLyingOnObject
3446 Return "BeLyingOnObject"
3447 Case clsRestriction.CharacterEnum.BeInGroup
3448 Return "BeInGroup"
3449 Case clsRestriction.CharacterEnum.BeOfGender
3450 Return "BeOfGender"
3451 Case clsRestriction.CharacterEnum.BeSittingOnObject
3452 Return "BeSittingOnObject"
3453 Case clsRestriction.CharacterEnum.BeStandingOnObject
3454 Return "BeStandingOnObject"
3455 Case clsRestriction.CharacterEnum.BeWearingObject
3456 Return "BeWearingObject"
3457 Case clsRestriction.CharacterEnum.BeWithinLocationGroup
3458 Return "BeWithinLocationGroup"
3459 Case clsRestriction.CharacterEnum.HaveProperty
3460 Return "HaveProperty"
3461 Case clsRestriction.CharacterEnum.BeInPosition
3462 Return "BeInPosition"
3463 Case clsRestriction.CharacterEnum.BeInsideObject
3464 Return "BeInsideObject"
3465 Case clsRestriction.CharacterEnum.BeOnObject
3466 Return "BeOnObject"
3467 Case clsRestriction.CharacterEnum.BeOnCharacter
3468 Return "BeOnCharacter"
3469 Case clsRestriction.CharacterEnum.BeVisibleToCharacter
3470 Return "BeVisibleToCharacter"
3471 End Select
3472 Return Nothing
3473 End Function
3474
3475 Public Function WriteEnum(ByVal v As clsRestriction.VariableEnum) As String
3476 Select Case v
3477 Case clsRestriction.VariableEnum.EqualTo
3478 Return "EqualTo"
3479 Case clsRestriction.VariableEnum.GreaterThan
3480 Return "GreaterThan"
3481 Case clsRestriction.VariableEnum.GreaterThanOrEqualTo
3482 Return "GreaterThanOrEqualTo"
3483 Case clsRestriction.VariableEnum.LessThan
3484 Return "LessThan"
3485 Case clsRestriction.VariableEnum.LessThanOrEqualTo
3486 Return "LessThanOrEqualTo"
3487 Case clsRestriction.VariableEnum.Contain
3488 Return "Contain"
3489 End Select
3490 Return Nothing
3491 End Function
3492
3493 Public Function WriteEnum(ByVal ba As clsTask.BeforeAfterEnum) As String
3494 Select Case ba
3495 Case clsTask.BeforeAfterEnum.After
3496 Return "After"
3497 Case clsTask.BeforeAfterEnum.Before
3498 Return "Before"
3499 End Select
3500 Return Nothing
3501 End Function
3502
3503 Public Function WriteEnum(ByVal mc As clsAction.MoveCharacterToEnum) As String
3504 Select Case mc
3505 Case clsAction.MoveCharacterToEnum.InDirection
3506 Return "InDirection"
3507 Case clsAction.MoveCharacterToEnum.ToLocation
3508 Return "ToLocation"
3509 Case clsAction.MoveCharacterToEnum.ToLocationGroup
3510 Return "ToLocationGroup"
3511 Case clsAction.MoveCharacterToEnum.ToLyingOn
3512 Return "ToLyingOn"
3513 Case clsAction.MoveCharacterToEnum.ToSameLocationAs
3514 Return "ToSameLocationAs"
3515 Case clsAction.MoveCharacterToEnum.ToSittingOn
3516 Return "ToSittingOn"
3517 Case clsAction.MoveCharacterToEnum.ToStandingOn
3518 Return "ToStandingOn"
3519 Case clsAction.MoveCharacterToEnum.ToSwitchWith
3520 Return "ToSwitchWith"
3521 Case clsAction.MoveCharacterToEnum.InsideObject
3522 Return "InsideObject"
3523 Case clsAction.MoveCharacterToEnum.OntoCharacter
3524 Return "OntoCharacter"
3525 Case clsAction.MoveCharacterToEnum.ToParentLocation
3526 Return "ToParentLocation"
3527 Case clsAction.MoveCharacterToEnum.ToGroup
3528 Return "ToGroup"
3529 Case clsAction.MoveCharacterToEnum.FromGroup
3530 Return "FromGroup"
3531 End Select
3532 Return Nothing
3533 End Function
3534
3535 Public Function WriteEnum(ByVal st As clsAction.SetTasksEnum) As String
3536 Select Case st
3537 Case clsAction.SetTasksEnum.Execute
3538 Return "Execute"
3539 Case clsAction.SetTasksEnum.Unset
3540 Return "Unset"
3541 End Select
3542 Return Nothing
3543 End Function
3544
3545 Public Function WriteEnum(ByVal ml As clsAction.MoveLocationToEnum) As String
3546 Select Case ml
3547 Case clsAction.MoveLocationToEnum.FromGroup
3548 Return "FromGroup"
3549 Case clsAction.MoveLocationToEnum.ToGroup
3550 Return "ToGroup"
3551 End Select
3552 Return Nothing
3553 End Function
3554
3555 Public Function WriteEnum(ByVal mo As clsAction.MoveObjectToEnum) As String
3556 Select Case mo
3557 Case clsAction.MoveObjectToEnum.InsideObject
3558 Return "InsideObject"
3559 Case clsAction.MoveObjectToEnum.OntoObject
3560 Return "OntoObject"
3561 Case clsAction.MoveObjectToEnum.ToCarriedBy
3562 Return "ToCarriedBy"
3563 Case clsAction.MoveObjectToEnum.ToLocation
3564 Return "ToLocation"
3565 Case clsAction.MoveObjectToEnum.ToLocationGroup
3566 Return "ToLocationGroup"
3567 Case clsAction.MoveObjectToEnum.ToPartOfCharacter
3568 Return "ToPartOfCharacter"
3569 Case clsAction.MoveObjectToEnum.ToPartOfObject
3570 Return "ToPartOfObject"
3571 Case clsAction.MoveObjectToEnum.ToSameLocationAs
3572 Return "ToSameLocationAs"
3573 Case clsAction.MoveObjectToEnum.ToWornBy
3574 Return "ToWornBy"
3575 Case clsAction.MoveObjectToEnum.ToGroup
3576 Return "ToGroup"
3577 Case clsAction.MoveObjectToEnum.FromGroup
3578 Return "FromGroup"
3579 End Select
3580 Return Nothing
3581 End Function
3582
3583 Public Function WriteEnum(ByVal tt As clsTask.TaskTypeEnum) As String
3584 Select Case tt
3585 Case clsTask.TaskTypeEnum.General
3586 Return "General"
3587 Case clsTask.TaskTypeEnum.Specific
3588 Return "Specific"
3589 Case clsTask.TaskTypeEnum.System
3590 Return "System"
3591 End Select
3592 Return Nothing
3593 End Function
3594
3595 Public Function WriteEnum(ByVal s As ReferencesType) As String
3596 Select Case s
3597 Case ReferencesType.Character
3598 Return "Character"
3599 Case ReferencesType.Direction
3600 Return "Direction"
3601 Case ReferencesType.Number
3602 Return "Number"
3603 Case ReferencesType.Object
3604 Return "Object"
3605 Case ReferencesType.Text
3606 Return "Text"
3607 Case ReferencesType.Location
3608 Return "Location"
3609 Case ReferencesType.Item
3610 Return "Item"
3611 End Select
3612 Return Nothing
3613 End Function
3614
3615 Public Function WriteEnum(ByVal ct As clsCharacter.CharacterTypeEnum) As String
3616 Select Case ct
3617 Case clsCharacter.CharacterTypeEnum.NonPlayer
3618 Return "NonPlayer"
3619 Case clsCharacter.CharacterTypeEnum.Player
3620 Return "Player"
3621 End Select
3622 Return Nothing
3623 End Function
3624
3625 Public Function WriteEnum(ByVal vt As clsVariable.VariableTypeEnum) As String
3626 Select Case vt
3627 Case clsVariable.VariableTypeEnum.Numeric
3628 Return "Numeric"
3629 Case clsVariable.VariableTypeEnum.Text
3630 Return "Text"
3631 End Select
3632 Return Nothing
3633 End Function
3634
3635 Public Function WriteEnum(ByVal gt As clsGroup.GroupTypeEnum) As String
3636 Select Case gt
3637 Case clsGroup.GroupTypeEnum.Characters
3638 Return "Characters"
3639 Case clsGroup.GroupTypeEnum.Locations
3640 Return "Locations"
3641 Case clsGroup.GroupTypeEnum.Objects
3642 Return "Objects"
3643 End Select
3644 Return Nothing
3645 End Function
3646
3647 ' cos Val() is not international-friendly...
3648 Public Function SafeDec(ByVal Expression As Object) As Decimal
3649 Try
3650 If Expression Is Nothing OrElse IsDBNull(Expression) Then Return 0
3651 If IsNumeric(Expression) Then Return CDec(Expression) Else Return 0
3652 Catch ex As Exception
3653 ErrMsg("SafeDec error with expression <" & Expression.ToString & ">", ex)
3654 Return 0
3655 End Try
3656 End Function
3657
3658 Public Function SafeDbl(ByVal Expression As Object) As Double
3659 Try
3660 Dim sExpression As String = SafeString(Expression)
3661 If sExpression.Contains(",") Then sExpression = sExpression.Replace(",", System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator)
3662 If sExpression.Contains(".") Then sExpression = sExpression.Replace(".", System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)
3663
3664 If sExpression = "" OrElse Not IsNumeric(sExpression) Then Return 0
3665 Dim df As Double = CDbl(sExpression)
3666 If Double.IsInfinity(df) OrElse Double.IsNaN(df) Then Return 0 Else Return df
3667 Catch ex As Exception
3668 ErrMsg("SafeDbl error with expression <" & Expression.ToString & ">", ex)
3669 Return 0
3670 End Try
3671 End Function
3672
3673 Public Function SafeInt(ByVal Expression As Object) As Integer
3674 Try
3675 If Expression Is Nothing OrElse IsDBNull(Expression) Then Return 0
3676 If IsNumeric(Expression) Then Return CInt(Int(Expression)) Else Return 0
3677 Catch exOF As OverflowException
3678 Return Integer.MaxValue
3679 Catch ex As Exception
3680 ErrMsg("SafeInt error with expression <" & Expression.ToString & ">", ex)
3681 Return 0
3682 End Try
3683 End Function
3684
3685 Public Function SafeBool(ByVal Expression As Object) As Boolean
3686 Try
3687 If Expression Is Nothing OrElse IsDBNull(Expression) Then Return False
3688 Select Case Expression.ToString.ToUpper
3689 Case True.ToString.ToUpper
3690 Return True
3691 Case False.ToString.ToUpper
3692 Return False
3693 Case Else
3694 Try
3695 Return CBool(Expression)
3696 Catch ex As Exception
3697 Return False
3698 End Try
3699 End Select
3700 Catch ex As Exception
3701 ErrMsg("SafeBool error with expression <" & Expression.ToString & ">", ex)
3702 Return False
3703 End Try
3704 End Function
3705
3706 Public Function SafeString(ByVal Expression As Object) As String
3707 Try
3708 If Expression Is Nothing OrElse IsDBNull(Expression) Then Return ""
3709 Return Expression.ToString
3710 Catch ex As Exception
3711 ErrMsg("SafeString error with expression <" & Expression.ToString & ">", ex)
3712 Return ""
3713 End Try
3714 End Function
3715
3716 Public Function SafeDate(ByVal Expression As Object) As Date
3717 Try
3718 If Expression Is Nothing OrElse IsDBNull(Expression) OrElse Not IsDate(Expression) Then Return New Date
3719 Return CDate(Expression)
3720 Catch ex As Exception
3721 ErrMsg("SafeDate error with expression <" & Expression.ToString & ">", ex)
3722 Return New Date
3723 End Try
3724 End Function
3725
3726 Public Class EventOrWalkControl
3727 Implements ICloneable
3728
3729 Public Enum ControlEnum
3730 Start
3731 [Stop]
3732 Suspend
3733 [Resume]
3734 End Enum
3735 Public eControl As ControlEnum
3736
3737 Public Enum CompleteOrNotEnum
3738 Completion
3739 UnCompletion
3740 End Enum
3741 Public eCompleteOrNot As CompleteOrNotEnum
3742
3743 Public sTaskKey As String
3744
3745 Private Function Clone() As Object Implements System.ICloneable.Clone
3746 Return Me.MemberwiseClone
3747 End Function
3748 Public Function CloneMe() As EventOrWalkControl
3749 Return CType(Me.Clone, EventOrWalkControl)
3750 End Function
3751
3752 End Class
3753
3754 Public Class FromTo
3755 Implements ICloneable
3756
3757 Public iFrom As Integer
3758 Public iTo As Integer
3759 Private iValue As Integer = Integer.MinValue
3760
3761 Public ReadOnly Property Value() As Integer
3762 Get
3763 If iValue = Integer.MinValue Then
3764 iValue = Random(iFrom, iTo) ' CInt(Rnd() * (iTo - iFrom)) + iFrom
3765 End If
3766 Return iValue
3767 End Get
3768 End Property
3769
3770 Public Sub Reset()
3771 iValue = Integer.MinValue
3772 End Sub
3773
3774 Private Function Clone() As Object Implements System.ICloneable.Clone
3775 Return Me.MemberwiseClone
3776 End Function
3777 Public Function CloneMe() As FromTo
3778 Return CType(Clone(), FromTo)
3779 End Function
3780
3781 Public Shadows ReadOnly Property ToString() As String
3782 Get
3783 If iFrom = iTo Then
3784 Return iFrom.ToString
3785 Else
3786 Return iFrom.ToString & " to " & iTo.ToString
3787 End If
3788 End Get
3789 End Property
3790
3791 End Class
3792
3793 <DebuggerDisplay("{Description}")>
3794 Public Class SingleDescription
3795 Implements ICloneable
3796
3797 Public Enum DisplayWhenEnum
3798 StartDescriptionWithThis
3799 StartAfterDefaultDescription
3800 AppendToPreviousDescription
3801 End Enum
3802
3803 Friend Restrictions As New RestrictionArrayList
3804 Friend eDisplayWhen As DisplayWhenEnum = DisplayWhenEnum.AppendToPreviousDescription
3805 Friend sTabLabel As String = ""
3806 Public Description As String = ""
3807 Friend DisplayOnce As Boolean = False
3808 Friend Property ReturnToDefault As Boolean = False
3809 Friend Displayed As Boolean
3810
3811 Private Function Clone() As Object Implements System.ICloneable.Clone
3812 Return Me.MemberwiseClone
3813 End Function
3814 Public Function CloneMe() As SingleDescription
3815 Return CType(Clone(), SingleDescription)
3816 End Function
3817
3818 End Class
3819
3820 Public Class Description
3821 Inherits List(Of SingleDescription)
3822
3823 Public Sub New()
3824 Me.New("")
3825 End Sub
3826 Public Sub New(ByVal sDescription As String)
3827
3828 Dim sd As New SingleDescription
3829 With sd
3830 sd.Description = sDescription
3831 sd.eDisplayWhen = SingleDescription.DisplayWhenEnum.StartDescriptionWithThis
3832 End With
3833 MyBase.Add(sd)
3834
3835 End Sub
3836
3837 Public Function ReferencesKey(ByVal sKey As String) As Integer
3838
3839 Dim iCount As Integer = 0
3840 For Each m As SingleDescription In Me
3841 For Each r As clsRestriction In m.Restrictions
3842 If r.ReferencesKey(sKey) Then iCount += 1
3843 Next
3844 Next
3845 Return iCount
3846
3847 End Function
3848
3849 Public Function DeleteKey(ByVal sKey As String) As Boolean
3850
3851 For Each m As SingleDescription In Me
3852 If Not m.Restrictions.DeleteKey(sKey) Then Return False
3853 Next
3854
3855 Return True
3856
3857 End Function
3858
3859
3860 'Should we add spaces between one desctiption tab and another
3861 Private Function AddSpace(ByVal sText As String) As Boolean
3862 If sText = "" Then Return False
3863 If sText.EndsWith(" ") OrElse sText.EndsWith(vbLf) Then Return False
3864
3865 ' Add spaces after end of sentences
3866 If sText.EndsWith(".") OrElse sText.EndsWith("!") OrElse sText.EndsWith("?") Then Return True
3867
3868 ' If it's a function then add a space -small chance the function could evaluate to "", but we'll take that chance
3869 If sText.EndsWith("%") Then Return True
3870
3871 ' If text ends in an OO function, return True
3872 If New System.Text.RegularExpressions.Regex(".*?(%?[A-Za-z][\w\|_-]*%?)(\.%?[A-Za-z][\w\|_-]*%?(\([A-Za-z ,_]+?\))?)+").IsMatch(sText) Then Return True
3873
3874 ' Otherwise return False
3875 Return False
3876 End Function
3877
3878 ' If bTesting is set, we're just testing the value, so don't mark text as having been output
3879 Public Shadows ReadOnly Property ToString(Optional ByVal bTesting As Boolean = False) As String
3880 Get
3881 Dim sb As New System.Text.StringBuilder
3882
3883 Dim sRestrictionTextIn As String = UserSession.sRestrictionText
3884 Dim iRestNumIn As Integer = UserSession.iRestNum
3885 Dim sRouteErrorIn As String = UserSession.sRouteError
3886
3887 Try
3888 For Each sd As SingleDescription In Me
3889 With sd
3890 If Not sd.DisplayOnce OrElse Not sd.Displayed Then
3891 Dim bDisplayed As Boolean = False
3892 If sd.Restrictions.Count = 0 OrElse UserSession.PassRestrictions(sd.Restrictions) Then
3893 Select Case sd.eDisplayWhen
3894 Case SingleDescription.DisplayWhenEnum.AppendToPreviousDescription
3895 If AddSpace(sb.ToString) Then sb.Append(" ")
3896 sb.Append("<>" & sd.Description)
3897 Case SingleDescription.DisplayWhenEnum.StartAfterDefaultDescription
3898 If sd Is Me(0) Then
3899 sb = New System.Text.StringBuilder(sd.Description)
3900 Else
3901 Dim sDefault As String = Me(0).Description
3902 If AddSpace(sDefault) Then sDefault &= " "
3903 sb = New System.Text.StringBuilder(sDefault & sd.Description)
3904 End If
3905 Case SingleDescription.DisplayWhenEnum.StartDescriptionWithThis
3906 sb = New System.Text.StringBuilder(sd.Description)
3907 End Select
3908 bDisplayed = True
3909 Else
3910 If UserSession.sRestrictionText <> "" Then
3911 Select Case sd.eDisplayWhen
3912 Case SingleDescription.DisplayWhenEnum.AppendToPreviousDescription
3913 If AddSpace(sb.ToString) Then sb.Append(" ")
3914 sb.Append("<>" & UserSession.sRestrictionText)
3915 Case SingleDescription.DisplayWhenEnum.StartAfterDefaultDescription
3916 If sd Is Me(0) Then
3917 sb = New System.Text.StringBuilder(UserSession.sRestrictionText)
3918 Else
3919 Dim sDefault As String = Me(0).Description
3920 If AddSpace(sDefault) Then sDefault &= " "
3921 sb = New System.Text.StringBuilder(sDefault & UserSession.sRestrictionText)
3922 End If
3923 Case SingleDescription.DisplayWhenEnum.StartDescriptionWithThis
3924 sb = New System.Text.StringBuilder(UserSession.sRestrictionText)
3925 End Select
3926 End If
3927 End If
3928 If .DisplayOnce Then
3929 ' Is this right, or should it mark Displayed = True if any text is output?
3930 If Not (bTesting OrElse UserSession.bTestingOutput) AndAlso bDisplayed Then
3931 sd.Displayed = True
3932 If sd.ReturnToDefault Then
3933 For Each sd2 As SingleDescription In Me
3934 sd2.Displayed = False
3935 If sd2 Is sd Then Exit For
3936 Next
3937 End If
3938 End If
3939 Return sb.ToString
3940 End If
3941 End If
3942 End With
3943 Next
3944
3945 Catch
3946 Finally
3947 UserSession.sRestrictionText = sRestrictionTextIn
3948 UserSession.iRestNum = iRestNumIn
3949 UserSession.sRouteError = sRouteErrorIn
3950 End Try
3951
3952 Return sb.ToString
3953 End Get
3954 End Property
3955
3956 Public Function Copy() As Description
3957 Dim d As New Description
3958 d.Clear()
3959 For Each sd As SingleDescription In Me
3960 Dim sdNew As New SingleDescription
3961 sdNew.Description = sd.Description
3962 sdNew.eDisplayWhen = sd.eDisplayWhen
3963 sdNew.Restrictions = sd.Restrictions.Copy
3964 sdNew.DisplayOnce = sd.DisplayOnce
3965 sdNew.ReturnToDefault = sd.ReturnToDefault
3966 sdNew.sTabLabel = sd.sTabLabel
3967 d.Add(sdNew)
3968 Next
3969 Return d
3970 End Function
3971
3972 End Class
3973
3974
3975 Public Sub TODO(Optional ByVal sFunction As String = "")
3976 If sFunction = "" Then sFunction = "This section" Else sFunction = "Function """ & sFunction & """"
3977 Glue.ShowInfo("TODO: " & sFunction & " still has to be completed. Please inform Campbell of what you were doing.")
3978 End Sub
3979
3980 Public Class clsSearchOptions
3981
3982 Public Enum SearchInWhatEnum As Integer
3983 Uninitialised = -1
3984 AllItems = 0
3985 NonLibraryItems = 1
3986 End Enum
3987
3988 Public sLastKey As String = ""
3989 Public sLastSearch As String = ""
3990 Private eSearchInWhat As SearchInWhatEnum = SearchInWhatEnum.Uninitialised
3991 Public Property SearchInWhat() As SearchInWhatEnum
3992 Get
3993 If eSearchInWhat = SearchInWhatEnum.Uninitialised Then
3994 eSearchInWhat = CType(GetSetting("ADRIFT", "Generator", "SearchInWhat", CInt(SearchInWhatEnum.NonLibraryItems).ToString), SearchInWhatEnum)
3995 End If
3996 Return eSearchInWhat
3997 End Get
3998 Set(ByVal value As SearchInWhatEnum)
3999 eSearchInWhat = value
4000 SaveSetting("ADRIFT", "Generator", "SearchInWhat", CInt(value).ToString)
4001 End Set
4002 End Property
4003
4004 Public bSearchMatchCase As Boolean = False
4005 Public bFindExactWord As Boolean = False
4006
4007 End Class
4008
4009 Public SearchOptions As New clsSearchOptions
4010
4011 Public Sub SearchAndReplace(ByVal sFind As String, ByVal sReplace As String, Optional ByVal bSilent As Boolean = False)
4012 Dim iReplacements As Integer = 0
4013
4014 With SearchOptions
4015 For Each item As clsItem In Adventure.dictAllItems.Values
4016 Dim bLookIn As Boolean = False
4017 Select Case .SearchInWhat
4018 Case clsSearchOptions.SearchInWhatEnum.AllItems
4019 bLookIn = True
4020 Case clsSearchOptions.SearchInWhatEnum.NonLibraryItems
4021 bLookIn = Not item.IsLibrary
4022 End Select
4023 If bLookIn Then iReplacements += item.SearchAndReplace(sFind, sReplace)
4024 Next
4025 End With
4026 End Sub
4027
4028 End Module