Debian Codegraph @

terps/frankendrift/FrankenDrift.Adrift/clsObject.vb

raw
1 Public Class clsObject
2 Inherits clsItemWithProperties
3
4 Private sPrefix As String
5 Private oDescription As Description
6 Private cLocation As clsObjectLocation
7 Private sArticle As String
8
9 Friend m_arlNames As New StringArrayList
10 Friend Property arlNames As StringArrayList
11 Get
12 Return m_arlNames
13 End Get
14 Set(value As StringArrayList)
15 m_arlNames = value
16 End Set
17 End Property
18
19 Private sarlPlurals As StringArrayList
20 Friend ReadOnly Property arlPlurals() As StringArrayList
21 Get
22 If sarlPlurals Is Nothing Then
23 Dim arl As New StringArrayList
24
25 For Each sNoun As String In arlNames
26 'arl.Add(sNoun & "|" & GuessPluralFromNoun(sNoun)) ' This means we're matching non-plurals as plurals, so "get ball" will be the same as "get balls" and therefore take all balls without disambiguation
27 arl.Add(GuessPluralFromNoun(sNoun))
28 Next
29 sarlPlurals = arl
30 End If
31
32 Return sarlPlurals
33 End Get
34 End Property
35
36 Friend Function GuessPluralFromNoun(ByVal sNoun As String) As String
37 If sNoun Is Nothing Then Return ""
38
39 Select Case sNoun
40 Case "deer", "fish", "cod", "mackerel", "trout", "moose", "sheep", "swine", "aircraft", "blues", "cannon" ' Identical Singular & Plural nouns
41 Return sNoun
42 Case "ox" ' Irregular plurals
43 Return "oxen"
44 Case "cow"
45 Return "kine"
46 Case "child"
47 Return "children"
48 Case "foot" ' Umlaut plurals
49 Return "feet"
50 Case "goose"
51 Return "geese"
52 Case "louse"
53 Return "lice"
54 Case "mouse"
55 Return "mice"
56 Case "tooth"
57 Return "teeth"
58 End Select
59
60 Select Case sNoun.Length
61 Case 0
62 Return ""
63 Case 1, 2
64 Return sNoun & "s"
65 Case Else
66 Select Case sNoun.Substring(sNoun.Length - 3, 3)
67 Case "man" ' Umlaut plural
68 Return sNoun.Substring(0, sNoun.Length - 2) & "en"
69 Case "ies"
70 Return sNoun
71 End Select
72 Select Case sNoun.Substring(sNoun.Length - 2, 2)
73 Case "sh", "ss", "ch" ' Sibilant sounds
74 Return sNoun & "es"
75 Case "ge", "se" ' Sibilant sounds, ending with 'e'
76 Return sNoun & "s"
77 Case "ex"
78 Return sNoun.Substring(0, sNoun.Length - 2) & "ices"
79 Case "is"
80 Return sNoun.Substring(0, sNoun.Length - 2) & "es"
81 Case "um"
82 Return sNoun.Substring(0, sNoun.Length - 2) & "a"
83 Case "us"
84 Return sNoun.Substring(0, sNoun.Length - 2) & "i"
85 End Select
86 Select Case sNoun.Substring(sNoun.Length - 1, 1)
87 Case "f"
88 Select Case sNoun
89 Case "dwarf", "hoof", "roof" ' the exceptions
90 Return (sNoun & "s")
91 Case Else
92 Return sNoun.Substring(0, sNoun.Length - 1) & "ves"
93 End Select
94 Case "o" ' nouns ending in 'o' preceded by a consonant
95 Select Case sNoun.Substring(sNoun.Length - 2, 1)
96 Case "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "z"
97 Return sNoun & "es"
98 End Select
99 Case "x" ' normally ends in "es"
100 Return sNoun & "es"
101 Case "y" ' nouns ending in y preceeded by a consonant usually drop y and add ies
102 Select Case sNoun.Substring(sNoun.Length - 2, 1)
103 Case "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "z"
104 Return sNoun.Substring(0, sNoun.Length - 1) & "ies"
105 End Select
106 End Select
107 End Select
108
109 If sNoun.EndsWith("s") Then
110 Return sNoun
111 Else
112 Return sNoun & "s"
113 End If
114
115 End Function
116
117
118 Private iIsStaticCache As Integer = Integer.MinValue
119 Public Property IsStatic() As Boolean
120 Get
121 If iIsStaticCache <> Integer.MinValue Then
122 Return CBool(iIsStaticCache)
123 Else
124 Return GetPropertyValue("StaticOrDynamic") <> "Dynamic"
125 End If
126 End Get
127 Set(value As Boolean)
128 SetPropertyValue("StaticOrDynamic", IIf(value, "Static", "Dynamic").ToString)
129 iIsStaticCache = CInt(value)
130 End Set
131 End Property
132
133 Public Property HasSurface() As Boolean
134 Get
135 Return GetPropertyValue("Surface") IsNot Nothing
136 End Get
137 Set(value As Boolean)
138 TODO("Set HasSurface()")
139 End Set
140 End Property
141
142 ' TODO - Enhance this, or make it user configuratble
143 Public ReadOnly Property IsPlural As Boolean
144 Get
145 Return Article = "some"
146 End Get
147 End Property
148
149
150 Public Property IsContainer() As Boolean
151 Get
152 Return GetPropertyValue("Container") IsNot Nothing
153 End Get
154 Set(value As Boolean)
155 TODO("Set IsContainer()")
156 End Set
157 End Property
158
159 Public Property IsWearable() As Boolean
160 Get
161 Return GetPropertyValue("Wearable") IsNot Nothing
162 End Get
163 Set(value As Boolean)
164 SetPropertyValue("Wearable", value)
165 End Set
166 End Property
167
168
169 Public Property ExplicitlyList() As Boolean
170 Get
171 Return HasProperty("ExplicitlyList")
172 End Get
173 Set(ByVal Value As Boolean)
174 SetPropertyValue("ExplicitlyList", Value)
175 End Set
176 End Property
177
178
179 Public Property ListDescription() As String
180 Get
181 If IsStatic Then
182 Return GetPropertyValue("ListDescription")
183 Else
184 Return GetPropertyValue("ListDescriptionDynamic")
185 End If
186 Return ""
187 End Get
188 Set(ByVal Value As String)
189 If IsStatic Then
190 SetPropertyValue("ListDescription", Value)
191 Else
192 SetPropertyValue("ListDescriptionDynamic", Value)
193 End If
194 End Set
195 End Property
196
197
198 Public Property ExplicitlyExclude() As Boolean
199 Get
200 Return HasProperty("ExplicitlyExclude")
201 End Get
202 Set(ByVal Value As Boolean)
203 SetPropertyValue("ExplicitlyExclude", Value)
204 End Set
205 End Property
206
207
208
209 Public Property IsLieable() As Boolean
210 Get
211 Return HasProperty("Lieable")
212 End Get
213 Set(ByVal Value As Boolean)
214 SetPropertyValue("Lieable", Value)
215 End Set
216 End Property
217
218
219 Public Property IsSittable() As Boolean
220 Get
221 Return HasProperty("Sittable")
222 End Get
223 Set(ByVal Value As Boolean)
224 SetPropertyValue("Sittable", Value)
225 End Set
226 End Property
227
228
229 Public Property IsStandable() As Boolean
230 Get
231 Return HasProperty("Standable")
232 End Get
233 Set(ByVal Value As Boolean)
234 SetPropertyValue("Standable", Value)
235 End Set
236 End Property
237
238 ' Returns True if object is directly on parent, or if on/in something that is on it
239 Public ReadOnly Property IsOn(ByVal sParentKey As String) As Boolean
240 Get
241 If (Me.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.OnObject OrElse Me.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.InObject) AndAlso Parent <> "" Then
242 If Me.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.OnObject AndAlso Parent = sParentKey Then
243 Return True
244 Else
245 Dim obParent As clsObject = Adventure.htblObjects(Parent)
246 Return obParent.IsOn(sParentKey)
247 End If
248 Else
249 Return False
250 End If
251 End Get
252 End Property
253
254 ' Returns True if object is directly inside parent, or if on/in something that is inside it
255 Public ReadOnly Property IsInside(ByVal sParentKey As String) As Boolean
256 Get
257 If (Me.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.OnObject OrElse Me.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.InObject) AndAlso Parent <> "" Then
258 If Me.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.InObject AndAlso Parent = sParentKey Then
259 Return True
260 Else
261 Dim obParent As clsObject = Adventure.htblObjects(Parent)
262 Return obParent.IsInside(sParentKey)
263 End If
264 Else
265 Return False
266 End If
267 End Get
268 End Property
269
270 Public ReadOnly Property ExistsAtLocation(ByVal sLocKey As String, Optional ByVal bDirectly As Boolean = False) As Boolean
271 Get
272 If IsStatic Then
273 Select Case Location.StaticExistWhere
274 Case clsObjectLocation.StaticExistsWhereEnum.AllRooms
275 Return True
276 Case clsObjectLocation.StaticExistsWhereEnum.NoRooms
277 Return sLocKey = HIDDEN
278 Case clsObjectLocation.StaticExistsWhereEnum.PartOfCharacter
279 If bDirectly Then Return False Else Return Adventure.htblCharacters(Location.Key).Location.Key = sLocKey
280 Case clsObjectLocation.StaticExistsWhereEnum.PartOfObject
281 If bDirectly Then Return False Else Return Adventure.htblObjects(Location.Key).ExistsAtLocation(sLocKey)
282 Case clsObjectLocation.StaticExistsWhereEnum.LocationGroup
283 Return Adventure.htblGroups(Location.Key).arlMembers.Contains(sLocKey)
284 Case clsObjectLocation.StaticExistsWhereEnum.SingleLocation
285 Return sLocKey = Location.Key
286 End Select
287 Else
288 Select Case Location.DynamicExistWhere
289 Case clsObjectLocation.DynamicExistsWhereEnum.HeldByCharacter
290 If bDirectly Then Return False Else Return Adventure.htblCharacters(Location.Key).Location.Key = sLocKey
291 Case clsObjectLocation.DynamicExistsWhereEnum.Hidden
292 Return sLocKey = HIDDEN
293 Case clsObjectLocation.DynamicExistsWhereEnum.InLocation
294 Return sLocKey = Location.Key
295 Case clsObjectLocation.DynamicExistsWhereEnum.InObject
296 If bDirectly Then Return False Else Return Adventure.htblObjects(Location.Key).ExistsAtLocation(sLocKey)
297 Case clsObjectLocation.DynamicExistsWhereEnum.OnObject
298 If bDirectly Then Return False Else Return Adventure.htblObjects(Location.Key).ExistsAtLocation(sLocKey)
299 Case clsObjectLocation.DynamicExistsWhereEnum.WornByCharacter
300 If bDirectly Then Return False Else Return Adventure.htblCharacters(Location.Key).Location.Key = sLocKey
301 End Select
302 End If
303 End Get
304 End Property
305
306 Public Property IsTransparent As Boolean
307 Get
308 Return False ' TODO
309 End Get
310 Set(value As Boolean)
311 TODO()
312 End Set
313 End Property
314
315 Public Property IsOpen() As Boolean
316 Get
317 Dim s As String = GetPropertyValue("OpenStatus")
318 Return s Is Nothing OrElse s = "Open"
319 End Get
320 Set(ByVal Value As Boolean)
321 SetPropertyValue("OpenStatus", IIf(Value, "Open", "Closed").ToString)
322 End Set
323 End Property
324 Friend ReadOnly Property FullName(Optional ByVal Article As ArticleTypeEnum = ArticleTypeEnum.Indefinite) As String
325 Get
326 If arlNames.Count > 0 Then
327 Dim sArticle2 As String = Nothing
328 Select Case Article
329 Case ArticleTypeEnum.Definite
330 sArticle2 = "the "
331 Case ArticleTypeEnum.Indefinite
332 sArticle2 = sArticle & " "
333 Case ArticleTypeEnum.None
334 sArticle2 = ""
335 End Select
336 If sPrefix <> "" Then
337 Return sArticle2 & sPrefix & " " & arlNames(0)
338 Else
339 Return sArticle2 & arlNames(0)
340 End If
341 Else
342 Return "Undefined Object"
343 End If
344 End Get
345 End Property
346 Friend Property Article() As String
347 Get
348 Return sArticle
349 End Get
350 Set(ByVal Value As String)
351 sArticle = Value
352 End Set
353 End Property
354
355 Friend Property Prefix() As String
356 Get
357 Return sPrefix
358 End Get
359 Set(ByVal Value As String)
360 sPrefix = Value
361 End Set
362 End Property
363
364 Public Function DisplayCharacterChildren() As String
365
366 Dim sReturn As String = ""
367
368 If ChildrenCharacters(WhereChildrenEnum.OnObject).Count > 0 Then
369 sReturn = pSpace(sReturn)
370 If sReturn = "" Then
371 sReturn &= "%PCase[" & ChildrenCharacters(WhereChildrenEnum.OnObject).List("and") & "]%"
372 Else
373 sReturn &= ChildrenCharacters(WhereChildrenEnum.OnObject).List("and")
374 End If
375 If ChildrenCharacters(WhereChildrenEnum.OnObject).Count = 1 Then
376 sReturn &= " [am/are/is] on "
377 Else
378 sReturn &= " are on "
379 End If
380 sReturn &= FullName(ArticleTypeEnum.Definite)
381 End If
382 If Not Openable OrElse IsOpen Then
383 If ChildrenCharacters(WhereChildrenEnum.InsideObject).Count > 0 Then
384 If ChildrenCharacters(WhereChildrenEnum.OnObject).Count > 0 Then
385 sReturn &= ", and "
386 sReturn &= ChildrenCharacters(WhereChildrenEnum.InsideObject).List("and")
387 Else
388 sReturn = pSpace(sReturn)
389 If sReturn = "" Then
390 sReturn &= "%PCase[" & ChildrenCharacters(WhereChildrenEnum.InsideObject).List("and") & "]%"
391 Else
392 sReturn &= ChildrenCharacters(WhereChildrenEnum.InsideObject).List("and")
393 End If
394 End If
395 If ChildrenCharacters(WhereChildrenEnum.InsideObject).Count = 1 Then
396 sReturn &= " [am/are/is] "
397 Else
398 sReturn &= " are "
399 End If
400 sReturn &= "inside " & FullName(ArticleTypeEnum.Definite)
401 End If
402 End If
403 If ChildrenCharacters(WhereChildrenEnum.OnObject).Count > 0 OrElse (((Openable AndAlso IsOpen) OrElse Not Openable) AndAlso ChildrenCharacters(WhereChildrenEnum.InsideObject).Count > 0) Then sReturn &= "."
404
405 Return sReturn
406 End Function
407
408
409
410 Public Function DisplayObjectChildren() As String
411 Dim sReturn As String = ""
412
413 If Children(WhereChildrenEnum.OnObject).Count > 0 Then
414 sReturn = pSpace(sReturn)
415 sReturn &= ToProper(Children(WhereChildrenEnum.OnObject).List("and", False, ArticleTypeEnum.Indefinite))
416 If Children(WhereChildrenEnum.OnObject).Count = 1 Then
417 sReturn &= " is on "
418 Else
419 sReturn &= " are on "
420 End If
421 sReturn &= FullName(ArticleTypeEnum.Definite)
422 End If
423 If (Openable AndAlso IsOpen) OrElse Not Openable Then
424 If Children(WhereChildrenEnum.InsideObject).Count > 0 Then
425 If Children(WhereChildrenEnum.OnObject).Count > 0 Then
426 sReturn &= ", and inside"
427 Else
428 sReturn = pSpace(sReturn)
429 sReturn &= "Inside " & FullName(ArticleTypeEnum.Definite)
430 End If
431 If Children(WhereChildrenEnum.InsideObject).Count = 1 Then
432 sReturn &= " is "
433 Else
434 sReturn &= " are "
435 End If
436 sReturn &= Children(WhereChildrenEnum.InsideObject).List("and", False, ArticleTypeEnum.Indefinite)
437 End If
438 End If
439 If Children(WhereChildrenEnum.OnObject).Count > 0 OrElse (((Openable AndAlso IsOpen) OrElse Not Openable) AndAlso Children(WhereChildrenEnum.InsideObject).Count > 0) Then sReturn &= "."
440
441 If sReturn = "" Then sReturn = "Nothing is on or inside " & FullName(ArticleTypeEnum.Definite) & "."
442 Return sReturn
443 End Function
444
445
446 Friend Property Description() As Description
447 Get
448 If oDescription.ToString(True) = "" Then
449 oDescription(0).Description = "There is nothing special about " & FullName(ArticleTypeEnum.Definite) & "."
450 End If
451 Return oDescription
452 End Get
453 Set(ByVal Value As Description)
454 oDescription = Value
455 End Set
456 End Property
457
458
459 ' Returns the actual rooms an object is in, regardless of actual location
460 Friend ReadOnly Property LocationRoots() As LocationHashTable
461 Get
462 Dim htblLocRoot As New LocationHashTable
463
464 If Me.IsStatic Then
465 Select Case Location.StaticExistWhere
466 Case clsObjectLocation.StaticExistsWhereEnum.AllRooms
467 Return Adventure.htblLocations
468 Case clsObjectLocation.StaticExistsWhereEnum.NoRooms
469 ' Fall out
470 Case clsObjectLocation.StaticExistsWhereEnum.PartOfCharacter
471 If Adventure.htblCharacters.ContainsKey(Location.Key) Then ' We could be loading...
472 Dim locChar As clsCharacterLocation = Adventure.htblCharacters(Location.Key).Location
473 If locChar.ExistWhere = clsCharacterLocation.ExistsWhereEnum.AtLocation Then htblLocRoot.Add(Adventure.htblLocations(locChar.Key), locChar.Key)
474 End If
475 Return htblLocRoot
476
477 Case clsObjectLocation.StaticExistsWhereEnum.PartOfObject
478 Return Adventure.htblObjects(Location.Key).LocationRoots
479
480 Case clsObjectLocation.StaticExistsWhereEnum.LocationGroup
481 For Each sMemberKey As String In Adventure.htblGroups(Location.Key).arlMembers
482 htblLocRoot.Add(Adventure.htblLocations(sMemberKey), sMemberKey)
483 Next
484
485 Case clsObjectLocation.StaticExistsWhereEnum.SingleLocation
486 htblLocRoot.Add(Adventure.htblLocations(Location.Key), Location.Key)
487
488 End Select
489 Else
490 Select Case Location.DynamicExistWhere
491 Case clsObjectLocation.DynamicExistsWhereEnum.HeldByCharacter
492 Dim locChar As clsCharacterLocation = Adventure.htblCharacters(Location.Key).Location
493 If locChar.ExistWhere = clsCharacterLocation.ExistsWhereEnum.AtLocation Then htblLocRoot.Add(Adventure.htblLocations(locChar.Key), locChar.Key)
494 Return htblLocRoot
495
496 Case clsObjectLocation.DynamicExistsWhereEnum.Hidden
497 ' Fall out
498
499 Case clsObjectLocation.DynamicExistsWhereEnum.InLocation
500 If Location.Key IsNot Nothing AndAlso Location.Key <> "Hidden" Then htblLocRoot.Add(Adventure.htblLocations(Location.Key), Location.Key)
501
502 Case clsObjectLocation.DynamicExistsWhereEnum.InObject
503 Return Adventure.htblObjects(Location.Key).LocationRoots
504
505 Case clsObjectLocation.DynamicExistsWhereEnum.OnObject
506 Return Adventure.htblObjects(Location.Key).LocationRoots
507
508 Case clsObjectLocation.DynamicExistsWhereEnum.WornByCharacter
509 Dim locChar As clsCharacterLocation = Adventure.htblCharacters(Location.Key).Location
510 If locChar.ExistWhere = clsCharacterLocation.ExistsWhereEnum.AtLocation Then htblLocRoot.Add(Adventure.htblLocations(locChar.Key), locChar.Key)
511 Return htblLocRoot
512
513 End Select
514 End If
515
516 Return htblLocRoot
517 End Get
518 End Property
519
520
521 Public Property Location() As clsObjectLocation
522 Get
523 cLocation = New clsObjectLocation
524 If Not Me.IsStatic AndAlso HasProperty("DynamicLocation") Then
525
526 Select Case GetPropertyValue("DynamicLocation")
527 Case "Held By Character"
528 cLocation.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.HeldByCharacter
529 If HasProperty("HeldByWho") Then cLocation.Key = GetPropertyValue("HeldByWho")
530 Case "Hidden"
531 cLocation.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.Hidden
532 Case "In Location"
533 cLocation.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.InLocation
534 If HasProperty("InLocation") Then cLocation.Key = GetPropertyValue("InLocation")
535 Case "Inside Object"
536 cLocation.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.InObject
537 If HasProperty("InsideWhat") Then cLocation.Key = GetPropertyValue("InsideWhat")
538 Case "On Object"
539 cLocation.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.OnObject
540 If HasProperty("OnWhat") Then cLocation.Key = GetPropertyValue("OnWhat")
541 Case "Worn By Character"
542 cLocation.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.WornByCharacter
543 If HasProperty("WornByWho") Then cLocation.Key = GetPropertyValue("WornByWho")
544 End Select
545 ElseIf Me.IsStatic AndAlso HasProperty("StaticLocation") Then
546 Select Case GetPropertyValue("StaticLocation")
547 Case "Nowhere", "Hidden"
548 cLocation.StaticExistWhere = clsObjectLocation.StaticExistsWhereEnum.NoRooms
549 Case "Single Location"
550 cLocation.StaticExistWhere = clsObjectLocation.StaticExistsWhereEnum.SingleLocation
551 If HasProperty("AtLocation") Then cLocation.Key = GetPropertyValue("AtLocation")
552 Case "Location Group"
553 cLocation.StaticExistWhere = clsObjectLocation.StaticExistsWhereEnum.LocationGroup
554 If HasProperty("AtLocationGroup") Then cLocation.Key = GetPropertyValue("AtLocationGroup")
555 Case "Everywhere"
556 cLocation.StaticExistWhere = clsObjectLocation.StaticExistsWhereEnum.AllRooms
557 Case "Part of Character"
558 cLocation.StaticExistWhere = clsObjectLocation.StaticExistsWhereEnum.PartOfCharacter
559 If HasProperty("PartOfWho") Then cLocation.Key = GetPropertyValue("PartOfWho")
560 Case "Part of Object"
561 cLocation.StaticExistWhere = clsObjectLocation.StaticExistsWhereEnum.PartOfObject
562 If HasProperty("PartOfWhat") Then cLocation.Key = GetPropertyValue("PartOfWhat")
563 End Select
564 End If
565 Return cLocation
566 End Get
567
568 Set(ByVal Value As clsObjectLocation)
569 cLocation = Value
570 If Not Me.IsStatic AndAlso HasProperty("DynamicLocation") Then
571 Select Case cLocation.DynamicExistWhere
572 Case clsObjectLocation.DynamicExistsWhereEnum.HeldByCharacter
573 SetPropertyValue("DynamicLocation", "Held By Character")
574 AddProperty("HeldByWho")
575 SetPropertyValue("HeldByWho", cLocation.Key)
576 Case clsObjectLocation.DynamicExistsWhereEnum.Hidden
577 SetPropertyValue("DynamicLocation", "Hidden")
578 Case clsObjectLocation.DynamicExistsWhereEnum.InLocation
579 SetPropertyValue("DynamicLocation", "In Location")
580 AddProperty("InLocation")
581 SetPropertyValue("InLocation", cLocation.Key)
582 Case clsObjectLocation.DynamicExistsWhereEnum.InObject
583 SetPropertyValue("DynamicLocation", "Inside Object")
584 AddProperty("InsideWhat")
585 SetPropertyValue("InsideWhat", cLocation.Key)
586 Case clsObjectLocation.DynamicExistsWhereEnum.OnObject
587 SetPropertyValue("DynamicLocation", "On Object")
588 AddProperty("OnWhat")
589 SetPropertyValue("OnWhat", cLocation.Key)
590 Case clsObjectLocation.DynamicExistsWhereEnum.WornByCharacter
591 SetPropertyValue("DynamicLocation", "Worn By Character")
592 AddProperty("WornByWho")
593 SetPropertyValue("WornByWho", cLocation.Key)
594 End Select
595 ElseIf Me.IsStatic AndAlso HasProperty("StaticLocation") Then
596 Select Case cLocation.StaticExistWhere
597 Case clsObjectLocation.StaticExistsWhereEnum.AllRooms
598 SetPropertyValue("StaticLocation", "Everywhere")
599 Case clsObjectLocation.StaticExistsWhereEnum.LocationGroup
600 SetPropertyValue("StaticLocation", "Location Group")
601 AddProperty("AtLocationGroup")
602 SetPropertyValue("AtLocationGroup", cLocation.Key)
603 Case clsObjectLocation.StaticExistsWhereEnum.NoRooms
604 SetPropertyValue("StaticLocation", "Hidden")
605 Case clsObjectLocation.StaticExistsWhereEnum.PartOfCharacter
606 SetPropertyValue("StaticLocation", "Part of Character")
607 AddProperty("PartOfWho")
608 SetPropertyValue("PartOfWho", cLocation.Key)
609 Case clsObjectLocation.StaticExistsWhereEnum.PartOfObject
610 SetPropertyValue("StaticLocation", "Part of Object")
611 AddProperty("PartOfWhat")
612 SetPropertyValue("PartOfWhat", cLocation.Key)
613 Case clsObjectLocation.StaticExistsWhereEnum.SingleLocation
614 SetPropertyValue("StaticLocation", "Single Location")
615 AddProperty("AtLocation")
616 SetPropertyValue("AtLocation", cLocation.Key)
617 End Select
618 End If
619 End Set
620 End Property
621
622 Public ReadOnly Property Openable() As Boolean
623 Get
624 Return HasProperty("Openable")
625 End Get
626 End Property
627
628 Public ReadOnly Property Lockable() As Boolean
629 Get
630 Return HasProperty("Lockable")
631 End Get
632 End Property
633
634 Public ReadOnly Property Readable() As Boolean
635 Get
636 Return HasProperty("Readable")
637 End Get
638 End Property
639
640 Public Property ReadText() As String
641 Get
642 Return GetPropertyValue("ReadText")
643 End Get
644 Set(ByVal Value As String)
645 SetPropertyValue("ReadText", Value)
646 End Set
647 End Property
648
649
650 ' This gets updated at the end of each turn, and allows any tasks to
651 ' reference the parent before they are updated from task actions
652 '
653 Private sPrevParent As String
654 Public Property PrevParent() As String
655 Get
656 Return sPrevParent
657 End Get
658 Set(ByVal value As String)
659 sPrevParent = value
660 End Set
661 End Property
662
663 Friend Overrides ReadOnly Property Parent() As String
664 Get
665 If IsStatic Then
666 Select Case Location.StaticExistWhere
667 Case clsObjectLocation.StaticExistsWhereEnum.PartOfCharacter, clsObjectLocation.StaticExistsWhereEnum.PartOfObject
668 Return Location.Key
669 Case clsObjectLocation.StaticExistsWhereEnum.SingleLocation
670 Return Location.Key
671 Case clsObjectLocation.StaticExistsWhereEnum.NoRooms
672 Return HIDDEN
673 Case clsObjectLocation.StaticExistsWhereEnum.AllRooms
674 Return ALLROOMS
675 Case clsObjectLocation.StaticExistsWhereEnum.LocationGroup
676 Return Location.Key
677 End Select
678 Else
679 Select Case Location.DynamicExistWhere
680 Case clsObjectLocation.DynamicExistsWhereEnum.HeldByCharacter, clsObjectLocation.DynamicExistsWhereEnum.InObject, clsObjectLocation.DynamicExistsWhereEnum.OnObject, clsObjectLocation.DynamicExistsWhereEnum.WornByCharacter
681 Return Location.Key
682 Case clsObjectLocation.DynamicExistsWhereEnum.InLocation
683 Return Location.Key
684 Case clsObjectLocation.DynamicExistsWhereEnum.Hidden
685 Return HIDDEN
686 End Select
687 End If
688 Return Nothing
689 End Get
690 End Property
691
692
693 Public ReadOnly Property sRegularExpressionString(Optional ByVal bMyRE As Boolean = False, Optional ByVal bPlural As Boolean = False, Optional ByVal bPrefixMandatory As Boolean = False) As String
694 Get
695 Dim arl As StringArrayList = CType(IIf(bPlural, arlPlurals, arlNames), StringArrayList)
696
697 If bMyRE Then
698 ' The ADRIFT 'advanced command construction' expression
699 Dim sRE As String = "{" & sArticle & "/the} "
700 If sPrefix <> "" Then
701 For Each sSinglePrefix As String In Split(sPrefix, " ")
702 sRE &= "{" & sSinglePrefix & "} "
703 Next
704 End If
705 sRE &= "["
706
707 For Each sNoun As String In arl
708 sRE &= sNoun & "/"
709 Next
710 Return Left(sRE, sRE.Length - 1) & "]"
711 Else
712 ' Real Regular Expressions
713 Dim sRE As String = "(" & sArticle & " |the )?"
714 For Each sSinglePrefix As String In Split(sPrefix, " ")
715 If sSinglePrefix <> "" Then sRE &= "(" & MakeTextRESafe(sSinglePrefix) & " )?"
716 Next
717 sRE &= "("
718 For Each sNoun As String In arl
719 sRE &= MakeTextRESafe(sNoun) & "|"
720 Next
721 If arl.Count = 0 Then sRE &= "|" ' Fudge
722 Return Left(sRE, sRE.Length - 1) & ")"
723 End If
724 End Get
725 End Property
726
727 Public Property SeenBy(ByVal sCharKey As String) As Boolean
728 Get
729 If sCharKey = "%Player%" Then sCharKey = Adventure.Player.Key
730 Return Adventure.htblCharacters(sCharKey).HasSeenObject(Key)
731 End Get
732 Set(ByVal Value As Boolean)
733 Adventure.htblCharacters(sCharKey).HasSeenObject(Key) = Value
734 End Set
735 End Property
736
737 Public ReadOnly Property IsHeldByAnyone() As Boolean
738 Get
739 Select Case Location.DynamicExistWhere
740 Case clsObjectLocation.DynamicExistsWhereEnum.HeldByCharacter
741 Return True
742 Case clsObjectLocation.DynamicExistsWhereEnum.Hidden
743 Return False
744 Case clsObjectLocation.DynamicExistsWhereEnum.InLocation
745 Return False
746 Case clsObjectLocation.DynamicExistsWhereEnum.InObject
747 Return Adventure.htblObjects(Location.Key).IsHeldByAnyone
748 Case clsObjectLocation.DynamicExistsWhereEnum.OnObject
749 Return Adventure.htblObjects(Location.Key).IsHeldByAnyone
750 Case clsObjectLocation.DynamicExistsWhereEnum.WornByCharacter
751 Return False
752 End Select
753 End Get
754 End Property
755
756 Public ReadOnly Property IsWornByAnyone() As Boolean
757 Get
758 Select Case Location.DynamicExistWhere
759 Case clsObjectLocation.DynamicExistsWhereEnum.HeldByCharacter
760 Return False
761 Case clsObjectLocation.DynamicExistsWhereEnum.Hidden
762 Return False
763 Case clsObjectLocation.DynamicExistsWhereEnum.InLocation
764 Return False
765 Case clsObjectLocation.DynamicExistsWhereEnum.InObject
766 Return False
767 Case clsObjectLocation.DynamicExistsWhereEnum.OnObject
768 Return False
769 Case clsObjectLocation.DynamicExistsWhereEnum.WornByCharacter
770 Return True
771 End Select
772 End Get
773 End Property
774
775 ' The maximum container for the visibility of the object
776 Public ReadOnly Property BoundVisible As String
777 Get
778 With Me.Location
779 If Me.IsStatic Then
780 Select Case .StaticExistWhere
781 Case clsObjectLocation.StaticExistsWhereEnum.AllRooms
782 Return ALLROOMS
783 Case clsObjectLocation.StaticExistsWhereEnum.LocationGroup
784 Return .Key
785 Case clsObjectLocation.StaticExistsWhereEnum.NoRooms
786 Return HIDDEN
787 Case clsObjectLocation.StaticExistsWhereEnum.PartOfCharacter
788 Return Adventure.htblCharacters(.Key).BoundVisible
789 Case clsObjectLocation.StaticExistsWhereEnum.PartOfObject
790 Return Adventure.htblObjects(.Key).BoundVisible
791 Case clsObjectLocation.StaticExistsWhereEnum.SingleLocation
792 Return .Key
793 End Select
794 Else
795 Select Case .DynamicExistWhere
796 Case clsObjectLocation.DynamicExistsWhereEnum.HeldByCharacter
797 Return Adventure.htblCharacters(.Key).BoundVisible
798 Case clsObjectLocation.DynamicExistsWhereEnum.Hidden
799 Return HIDDEN
800 Case clsObjectLocation.DynamicExistsWhereEnum.InLocation
801 Return .Key
802 Case clsObjectLocation.DynamicExistsWhereEnum.InObject
803 With Adventure.htblObjects(.Key)
804 If Not .Openable OrElse .IsOpen OrElse .IsTransparent Then
805 Return Adventure.htblObjects(.Key).BoundVisible
806 Else
807 Return .Key
808 End If
809 End With
810 Case clsObjectLocation.DynamicExistsWhereEnum.OnObject
811 Return Adventure.htblObjects(.Key).BoundVisible
812 Case clsObjectLocation.DynamicExistsWhereEnum.WornByCharacter
813 Return Adventure.htblCharacters(.Key).BoundVisible
814 End Select
815 End If
816 End With
817 Return HIDDEN
818 End Get
819 End Property
820
821 Public ReadOnly Property IsVisibleTo(ByVal sCharKey As String) As Boolean
822 Get
823 If sCharKey = "%Player%" Then sCharKey = Adventure.Player.Key
824
825 Dim sBoundVisible As String = BoundVisible
826 Dim sBoundVisibleCh As String = Adventure.htblCharacters(sCharKey).BoundVisible
827
828 Select Case sBoundVisible
829 Case HIDDEN
830 Return False
831 Case ALLROOMS
832 Return Adventure.htblLocations.ContainsKey(sBoundVisibleCh)
833 End Select
834
835
836 If Adventure.htblGroups.ContainsKey(sBoundVisible) Then
837 Return Adventure.htblGroups(sBoundVisible).arlMembers.Contains(sBoundVisibleCh)
838 Else
839 Return sBoundVisible = sBoundVisibleCh
840 End If
841 End Get
842 End Property
843
844 Public ReadOnly Property IsVisibleAtLocation(ByVal sLocationKey As String) As Boolean
845 Get
846 Dim sBoundVisible As String = BoundVisible
847
848 Select Case sBoundVisible
849 Case HIDDEN
850 Return False
851 Case ALLROOMS
852 Return Adventure.htblLocations.ContainsKey(sLocationKey)
853 End Select
854
855 If Adventure.htblGroups.ContainsKey(sBoundVisible) Then
856 Return Adventure.htblGroups(sBoundVisible).arlMembers.Contains(sLocationKey)
857 Else
858 Return sBoundVisible = sLocationKey
859 End If
860 End Get
861 End Property
862
863 Public Sub Move(ByVal ToWhere As clsObjectLocation)
864
865 ' If we're moving into or onto an object, make sure we're not going recursive
866 If ToWhere.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.InObject OrElse ToWhere.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.OnObject Then
867 If ToWhere.Key = Me.Key OrElse Adventure.htblObjects(Key).Children(WhereChildrenEnum.Everything).ContainsKey(ToWhere.Key) Then
868 DisplayError("Can't move object " & Me.FullName & " " & If(ToWhere.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.InObject, "inside", "onto").ToString & " " & Adventure.htblObjects(ToWhere.Key).FullName & " as that would create a recursive location.")
869 Exit Sub
870 End If
871 End If
872
873 sPrevParent = Parent
874 Me.Location = ToWhere
875
876 ' Update any 'seen' things
877 If Me.Key IsNot Nothing Then
878 For Each Loc As clsLocation In LocationRoots.Values
879 If Loc IsNot Nothing AndAlso IsVisibleAtLocation(Loc.Key) Then
880 For Each ch As clsCharacter In Adventure.htblLocations(Loc.Key).CharactersVisibleAtLocation.Values
881 ch.HasSeenObject(Me.Key) = True
882 Next
883 End If
884 Next
885 End If
886 End Sub
887
888
889 Friend Enum WhereChildrenEnum
890 InsideOrOnObject
891 InsideObject
892 OnObject
893 Everything ' Includes objects that are part of this object
894 End Enum
895
896 Friend ReadOnly Property Children(ByVal WhereChildren As WhereChildrenEnum, Optional ByVal bRecursive As Boolean = False) As ObjectHashTable
897 Get
898 Dim htblChildren As New ObjectHashTable
899
900 For Each ob As clsObject In Adventure.htblObjects.Values
901 Dim bCheckSubObject As Boolean = False
902 Select Case WhereChildren
903 Case WhereChildrenEnum.Everything
904 bCheckSubObject = (ob.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.InObject OrElse ob.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.OnObject OrElse ob.Location.StaticExistWhere = clsObjectLocation.StaticExistsWhereEnum.PartOfObject)
905 Case WhereChildrenEnum.InsideOrOnObject
906 bCheckSubObject = (ob.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.InObject OrElse ob.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.OnObject)
907 Case WhereChildrenEnum.InsideObject
908 bCheckSubObject = ob.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.InObject
909 Case WhereChildrenEnum.OnObject
910 bCheckSubObject = ob.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.OnObject
911 End Select
912 If bCheckSubObject Then
913 If ob.Location.Key = Me.Key Then
914 htblChildren.Add(ob, ob.Key)
915 If bRecursive Then
916 For Each obChild As clsObject In ob.Children(WhereChildrenEnum.Everything, True).Values
917 htblChildren.Add(obChild, obChild.Key)
918 Next
919 End If
920 End If
921 End If
922 Next
923 If bRecursive Then
924 ' Also got to check all characters inside the object to include anything held/worn by them
925 For Each ch As clsCharacter In Adventure.htblCharacters.Values
926 If (WhereChildren <> WhereChildrenEnum.OnObject AndAlso ch.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.InObject) OrElse (WhereChildren <> WhereChildrenEnum.InsideObject AndAlso ch.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.OnObject) Then
927 If ch.Location.Key = Me.Key Then
928 For Each obHeldWornByChar As clsObject In ch.ChildrenObjects(WhereChildrenEnum.InsideOrOnObject, True).Values
929 htblChildren.Add(obHeldWornByChar, obHeldWornByChar.Key)
930 Next
931 End If
932 End If
933 Next
934 End If
935 Return htblChildren
936 End Get
937 End Property
938
939
940 Friend ReadOnly Property ChildrenCharacters(ByVal WhereChildren As WhereChildrenEnum) As CharacterHashTable
941 Get
942 Dim htblChildren As New CharacterHashTable
943
944 For Each ch As clsCharacter In Adventure.htblCharacters.Values
945 If (WhereChildren <> WhereChildrenEnum.OnObject AndAlso ch.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.InObject) OrElse (WhereChildren <> WhereChildrenEnum.InsideObject AndAlso ch.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.OnObject) Then
946 If ch.Location.Key = Me.Key Then
947 htblChildren.Add(ch, ch.Key)
948 End If
949 End If
950 Next
951
952 Return htblChildren
953 End Get
954 End Property
955
956 Public Sub New()
957 oDescription = New Description
958 End Sub
959
960 Public Overrides ReadOnly Property Clone() As clsItem
961 Get
962 Dim ob As clsObject = CType(Me.MemberwiseClone, clsObject)
963 ob.htblActualProperties = CType(ob.htblActualProperties.Clone, PropertyHashTable)
964 ob.arlNames = ob.arlNames.Clone
965 Return ob
966 End Get
967 End Property
968
969 Public Overrides ReadOnly Property CommonName() As String
970 Get
971 Return FullName
972 End Get
973 End Property
974
975
976 Friend Overrides ReadOnly Property AllDescriptions() As System.Collections.Generic.List(Of SharedModule.Description)
977 Get
978 Dim all As New Generic.List(Of Description)
979 all.Add(Me.Description)
980 For Each p As clsProperty In htblActualProperties.Values
981 all.Add(p.StringData)
982 Next
983 Return all
984 End Get
985 End Property
986
987
988 Friend Overrides Function FindStringLocal(sSearchString As String, Optional sReplace As String = Nothing, Optional bFindAll As Boolean = True, Optional ByRef iReplacements As Integer = 0) As Object
989 Dim iCount As Integer = iReplacements
990 iReplacements += MyBase.FindStringInStringProperty(Me.sArticle, sSearchString, sReplace, bFindAll)
991 iReplacements += MyBase.FindStringInStringProperty(Me.sPrefix, sSearchString, sReplace, bFindAll)
992 For i As Integer = arlNames.Count - 1 To 0 Step -1
993 iReplacements += MyBase.FindStringInStringProperty(Me.arlNames(i), sSearchString, sReplace, bFindAll)
994 Next
995 Return iReplacements - iCount
996 End Function
997
998 Protected Overrides ReadOnly Property PropertyGroupType() As clsGroup.GroupTypeEnum
999 Get
1000 Return clsGroup.GroupTypeEnum.Objects
1001 End Get
1002 End Property
1003
1004 Public Overrides Function ReferencesKey(ByVal sKey As String) As Integer
1005
1006 Dim iCount As Integer = 0
1007 For Each d As Description In AllDescriptions
1008 iCount += d.ReferencesKey(sKey)
1009 Next
1010 'If sKey = Location.Key Then iCount += 1
1011 iCount += htblActualProperties.ReferencesKey(sKey)
1012
1013 Return iCount
1014
1015 End Function
1016
1017 Public Overrides Function DeleteKey(ByVal sKey As String) As Boolean
1018
1019 For Each d As Description In AllDescriptions
1020 d.DeleteKey(sKey)
1021 Next
1022 If Not htblActualProperties.DeleteKey(sKey) Then Return False
1023 ' TODO - Need to do something clever here. E.g. if we have properties Where=InLocation then Location = theroom, we need to set Where=Hidden and remove Location property
1024 Return True
1025 End Function
1026
1027 End Class
1028
1029
1030 Public Class clsObjectLocation
1031
1032 Private _Key As String
1033
1034 Public Enum DynamicExistsWhereEnum
1035 Hidden
1036 InLocation
1037 InObject
1038 OnObject
1039 HeldByCharacter
1040 WornByCharacter
1041 End Enum
1042 Public Property DynamicExistWhere As DynamicExistsWhereEnum
1043
1044 Public Enum StaticExistsWhereEnum
1045 NoRooms
1046 SingleLocation
1047 LocationGroup
1048 AllRooms
1049 PartOfCharacter
1050 PartOfObject
1051 End Enum
1052 Public Property StaticExistWhere As StaticExistsWhereEnum
1053
1054 Public Property Number As Integer
1055
1056 Public Property Key() As String
1057 Get
1058 If _Key = "%Player%" AndAlso Adventure.Player IsNot Nothing Then _Key = Adventure.Player.Key
1059 Return _Key
1060 End Get
1061 Set(ByVal Value As String)
1062 If _Key IsNot Nothing AndAlso Value <> _Key Then
1063 _Key = _Key
1064 End If
1065 _Key = Value
1066 End Set
1067 End Property
1068
1069 Public Function Copy() As clsObjectLocation
1070 Dim loc As New clsObjectLocation
1071 loc.Key = _Key
1072 loc.DynamicExistWhere = DynamicExistWhere
1073 loc.StaticExistWhere = StaticExistWhere
1074 loc.Number = Number
1075 Return loc
1076 End Function
1077
1078 End Class
1079
1080