Debian Codegraph @

terps/frankendrift/FrankenDrift.Adrift/clsLocation.vb

raw
1 #If Adravalon Then
2 Imports FrankenDrift.Glue
3 Imports FrankenDrift.Glue.Util
4 #End If
5
6 Public Class clsDirection
7 Public LocationKey As String
8 Friend Restrictions As New RestrictionArrayList
9 Friend bEverBeenBlocked As Boolean = False
10 End Class
11
12 Public Class clsLocation
13 Inherits clsItemWithProperties
14
15 Private oShortDesc As Description
16 Private oLongDesc As Description
17 Public arlDirections As New DirectionArrayList
18 Public MapNode As MapNode
19
20 ' For displaying in Listboxes
21 Public Overrides Function ToString() As String
22 Return Me.ShortDescription.ToString
23 End Function
24
25 Protected Overrides ReadOnly Property PropertyGroupType() As clsGroup.GroupTypeEnum
26 Get
27 Return clsGroup.GroupTypeEnum.Locations
28 End Get
29 End Property
30
31 Private _HideOnMap As Boolean
32 Public Property HideOnMap As Boolean
33 Get
34 Return _HideOnMap
35 End Get
36 Set(value As Boolean)
37 _HideOnMap = value
38 End Set
39 End Property
40
41 Public Property SeenBy(ByVal sCharKey As String) As Boolean
42 Get
43 Return Adventure.htblCharacters(sCharKey).HasSeenLocation(Key)
44 End Get
45 Set(ByVal Value As Boolean)
46 Adventure.htblCharacters(sCharKey).HasSeenLocation(Key) = Value
47 End Set
48 End Property
49
50
51 Friend ReadOnly Property ShortDescriptionSafe As String
52 Get
53 If Adventure.dVersion < 5 Then
54 ' v4 didn't replace ALRs on statusbar and map
55 Return StripCarats(ReplaceFunctions(ShortDescription.ToString))
56 Else
57 Return StripCarats(ReplaceALRs(ShortDescription.ToString))
58 End If
59 End Get
60 End Property
61
62 Friend Property ShortDescription() As Description
63 Get
64 If HasProperty(SHORTLOCATIONDESCRIPTION) Then
65 Dim descShortDesc As Description = oShortDesc.Copy
66 For Each sd As SingleDescription In GetProperty(SHORTLOCATIONDESCRIPTION).StringData
67 descShortDesc.Add(sd)
68 Next
69 Return descShortDesc
70 Else
71 Return oShortDesc
72 End If
73 End Get
74 Set(ByVal Value As Description)
75 oShortDesc = Value
76 End Set
77 End Property
78
79 Friend Property LongDescription() As Description
80 Get
81 If HasProperty(LONGLOCATIONDESCRIPTION) Then
82 Dim descLongDesc As Description = oLongDesc.Copy
83 For Each sd As SingleDescription In GetProperty(LONGLOCATIONDESCRIPTION).StringData
84 descLongDesc.Add(sd)
85 Next
86 Return descLongDesc
87 Else
88 Return oLongDesc
89 End If
90 End Get
91 Set(ByVal Value As Description)
92 oLongDesc = Value
93 End Set
94 End Property
95
96
97 Public ReadOnly Property sRegularExpressionString(Optional ByVal bMyRE As Boolean = False) As String
98 Get
99 If bMyRE Then
100 ' The ADRIFT 'advanced command construction' expression
101 Dim sRE As String = ""
102 For Each sWord As String In Split(ShortDescription.ToString(True), " ")
103 If sWord <> "" Then sRE &= "{" & sWord.ToLower & "} "
104 Next
105 Return sRE
106 Else
107 ' Real Regular Expressions
108 Dim sRE As String = ""
109 For Each sWord As String In Split(ShortDescription.ToString(True), " ")
110 If sRE <> "" Then sRE &= "( )?"
111 If sWord <> "" Then sRE &= "(" & sWord.ToLower & ")?"
112 Next
113 Return sRE
114 End If
115
116 End Get
117 End Property
118
119
120 Public ReadOnly Property ViewLocation() As String
121 Get
122 Dim sView As String = LongDescription.ToString
123
124 ' Do any specific listed objects
125 Dim htblObjects As ObjectHashTable = ObjectsInLocation(WhichObjectsToListEnum.AllSpecialListedObjects, True)
126 For Each ob As clsObject In htblObjects.Values
127 pSpace(sView)
128 sView &= ob.ListDescription
129 Next
130
131 htblObjects = ObjectsInLocation(WhichObjectsToListEnum.AllGeneralListedObjects, True)
132 If htblObjects.Count > 0 Then
133 If sView <> "" OrElse Adventure.dVersion < 5 Then
134 pSpace(sView)
135 If Adventure.dVersion < 5 AndAlso sView = "" Then sView = " "
136 sView &= "Also here is " & htblObjects.List(, , ArticleTypeEnum.Indefinite) & "."
137 Else
138 sView &= "There is " & htblObjects.List(, , ArticleTypeEnum.Indefinite) & " here."
139 End If
140 End If
141
142 For Each e As clsEvent In Adventure.htblEvents.Values
143 Dim sLookText As String = e.LookText()
144 If sLookText <> "" Then sView = pSpace(sView) & sLookText
145 Next
146
147 Dim dCharDesc As New Dictionary(Of String, StringArrayList) ' Description without name, list of names
148 For Each sKey As String In CharactersVisibleAtLocation.Keys
149 Dim ch As clsCharacter = Adventure.htblCharacters(sKey)
150 Dim sName As String = ch.Name(, False)
151 Dim sIsHereDesc As String
152 ' Default to Char is here unless we have property (which can set value to blank)
153 If ch.HasProperty("CharHereDesc") Then
154 sIsHereDesc = ReplaceFunctions(ch.IsHereDesc)
155 Else
156 sIsHereDesc = sName & " is here."
157 End If
158 If sIsHereDesc <> "" Then
159 Dim sDescWithoutName As String = ReplaceIgnoreCase(sIsHereDesc, sName, "##CHARNAME##")
160 If Not dCharDesc.ContainsKey(sDescWithoutName) Then dCharDesc.Add(sDescWithoutName, New StringArrayList)
161 If Not dCharDesc(sDescWithoutName).Contains(sName) Then dCharDesc(sDescWithoutName).Add(sName)
162 End If
163 Next
164 For Each sDesc As String In dCharDesc.Keys
165 With dCharDesc(sDesc)
166 pSpace(sView)
167 If .Count > 1 Then
168 sDesc = sDesc.Replace(" is ", " are ")
169 End If
170 sView &= sDesc.Replace("##CHARNAME##", .List)
171 End With
172 Next
173
174 If Adventure.ShowExits Then
175 Dim iExitCount As Integer = 0
176 Dim sListExists As String = Adventure.Player.ListExits(Me.Key, iExitCount)
177 pSpace(sView)
178 If iExitCount > 1 Then
179 sView &= "Exits are " & sListExists & "."
180 ElseIf iExitCount = 1 Then
181 sView &= "An exit leads " & sListExists & "."
182 End If
183 End If
184
185 If sView = "" Then sView = "Nothing special."
186
187 If UserSession.bShowShortLocations Then
188 sView = "<b>" & ShortDescription.ToString & "</b>" & vbCrLf & sView
189 If Adventure.dVersion >= 5 Then sView = vbCrLf & sView
190 End If
191 Return sView
192 End Get
193 End Property
194
195 Public Sub New()
196
197 For dir As DirectionsEnum = DirectionsEnum.North To DirectionsEnum.NorthWest
198 Dim dirstruct As New clsDirection
199 arlDirections.Add(dirstruct)
200 Next
201 oLongDesc = New Description
202 oShortDesc = New Description
203
204 End Sub
205
206 Friend Enum WhichObjectsToListEnum
207 AllObjects
208 AllListedObjects
209 AllGeneralListedObjects
210 AllSpecialListedObjects
211 End Enum
212 ' Directly means they have to be directly in the room, i.e. not held by a character etc
213 Friend ReadOnly Property ObjectsInLocation(Optional ByVal ListWhat As WhichObjectsToListEnum = WhichObjectsToListEnum.AllListedObjects, Optional ByVal bDirectly As Boolean = True) As ObjectHashTable
214 Get
215 Dim htblObjectsInLocation As New ObjectHashTable
216
217 For Each ob As clsObject In Adventure.htblObjects.Values
218 If ob.ExistsAtLocation(Key, bDirectly) Then
219 Select Case ListWhat
220 Case WhichObjectsToListEnum.AllGeneralListedObjects ' Dynamic objects not excluded plus static objects explicitly included, unless specially listed
221 If ((Not ob.IsStatic AndAlso Not ob.ExplicitlyExclude) OrElse (ob.IsStatic AndAlso ob.ExplicitlyList)) Then
222 If ob.ListDescription = "" Then htblObjectsInLocation.Add(ob, ob.Key)
223 End If
224 Case WhichObjectsToListEnum.AllListedObjects ' All listed objects, including special listed
225 If ((Not ob.IsStatic AndAlso Not ob.ExplicitlyExclude) OrElse (ob.IsStatic AndAlso ob.ExplicitlyList)) Then
226 htblObjectsInLocation.Add(ob, ob.Key)
227 End If
228 Case WhichObjectsToListEnum.AllObjects ' Any object in the location, whether indirectly or not
229 htblObjectsInLocation.Add(ob, ob.Key)
230 Case WhichObjectsToListEnum.AllSpecialListedObjects ' Specially listed objects only (i.e. they have a special listing description)
231 If ((Not ob.IsStatic AndAlso Not ob.ExplicitlyExclude) OrElse (ob.IsStatic AndAlso ob.ExplicitlyList)) Then
232 If ob.ListDescription <> "" Then htblObjectsInLocation.Add(ob, ob.Key)
233 End If
234 End Select
235 End If
236 Next
237
238 Return htblObjectsInLocation
239 End Get
240 End Property
241
242 ' Characters directly in the location
243 Friend ReadOnly Property CharactersDirectlyInLocation(Optional ByVal bIncludePlayer As Boolean = False) As CharacterHashTable
244 Get
245 Dim htblCharactersInLocation As New CharacterHashTable
246
247 For Each ch As clsCharacter In Adventure.htblCharacters.Values
248 If ch.Location.Key = Me.Key AndAlso ch.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.AtLocation AndAlso (bIncludePlayer OrElse ch.Key <> Adventure.Player.Key) Then htblCharactersInLocation.Add(ch, ch.Key) ' AndAlso ch.Key <> Adventure.Player.Key
249 Next
250
251 Return htblCharactersInLocation
252
253 End Get
254 End Property
255
256 ' Characters visible in location (can be in open objects, on objects etc)
257 Friend ReadOnly Property CharactersVisibleAtLocation(Optional ByVal bIncludePlayer As Boolean = False) As CharacterHashTable
258 Get
259 Dim htblCharactersInLocation As New CharacterHashTable
260
261 'Dim sLoc As String = Adventure.Player.Location.LocationKey
262 For Each ch As clsCharacter In Adventure.htblCharacters.Values
263 If ch IsNot Adventure.Player AndAlso ch.IsVisibleAtLocation(Me.Key) Then htblCharactersInLocation.Add(ch, ch.Key)
264 Next
265
266 Return htblCharactersInLocation
267 End Get
268 End Property
269
270 Public Overrides ReadOnly Property Clone() As clsItem
271 Get
272 Return CType(Me.MemberwiseClone, clsLocation)
273 End Get
274 End Property
275
276 Public Function IsAdjacent(ByVal sKey As String) As Boolean
277
278 For Each dir As clsDirection In Me.arlDirections
279 If dir.LocationKey = sKey Then Return True
280 Next
281 Return False
282
283 End Function
284
285 Public Function DirectionTo(ByVal sKey As String) As String
286
287 If sKey = Me.Key Then Return "not moved"
288
289 For drn As SharedModule.DirectionsEnum = DirectionsEnum.North To DirectionsEnum.NorthWest
290 If arlDirections(drn).LocationKey = sKey Then
291 Select Case drn
292 Case DirectionsEnum.North, DirectionsEnum.East, DirectionsEnum.South, DirectionsEnum.West
293 Return "the " & drn.ToString.ToLower
294 Case DirectionsEnum.Up
295 Return "above"
296 Case DirectionsEnum.Down
297 Return "below"
298 Case DirectionsEnum.In
299 Return "inside"
300 Case DirectionsEnum.Out
301 Return "outside"
302 Case DirectionsEnum.NorthEast
303 Return "the north-east"
304 Case DirectionsEnum.NorthWest
305 Return "the north-west"
306 Case DirectionsEnum.SouthEast
307 Return "the south-east"
308 Case DirectionsEnum.SouthWest
309 Return "the south-west"
310 End Select
311 End If
312 Next
313
314 Return "nowhere"
315
316 End Function
317 Public Overrides ReadOnly Property CommonName() As String
318 Get
319 Return ShortDescription.ToString
320 End Get
321 End Property
322 Friend Overrides ReadOnly Property AllDescriptions() As System.Collections.Generic.List(Of SharedModule.Description)
323 Get
324 Dim all As New Generic.List(Of Description)
325 all.Add(Me.ShortDescription)
326 all.Add(Me.LongDescription)
327 For Each p As clsProperty In htblActualProperties.Values
328 all.Add(p.StringData)
329 Next
330 Return all
331 End Get
332 End Property
333 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
334 Dim iCount As Integer = iReplacements
335 '
336 Return iReplacements - iCount
337 End Function
338
339 Public Overrides Function ReferencesKey(ByVal sKey As String) As Integer
340 Dim iCount As Integer = 0
341 For Each d As Description In AllDescriptions
342 iCount += d.ReferencesKey(sKey)
343 Next
344 For Each d As clsDirection In arlDirections
345 If d.LocationKey = sKey Then iCount += 1
346 iCount += d.Restrictions.ReferencesKey(sKey)
347 Next
348 iCount += htblActualProperties.ReferencesKey(sKey)
349
350 Return iCount
351 End Function
352
353
354 Public Overrides Function DeleteKey(ByVal sKey As String) As Boolean
355 For Each d As Description In AllDescriptions
356 If Not d.DeleteKey(sKey) Then Return False
357 Next
358 For Each d As clsDirection In arlDirections
359 If d.LocationKey = sKey Then
360 d.Restrictions.Clear()
361 d.LocationKey = ""
362 Else
363 If Not d.Restrictions.DeleteKey(sKey) Then Return False
364 End If
365 Next
366 If Not htblActualProperties.DeleteKey(sKey) Then Return False
367
368 Return True
369 End Function
370
371 Friend Overrides ReadOnly Property Parent As String
372 Get
373 Return "" ' Suppose we could return a Location Group, but what if we were member of more than one?
374 End Get
375 End Property
376
377 End Class