| 1 |
#If Adravalon Then |
| 2 |
Imports FrankenDrift.Glue |
| 3 |
#End If |
| 4 |
|
| 5 |
<DebuggerDisplay("{Name}")> |
| 6 |
Public Class clsCharacter |
| 7 |
Inherits clsItemWithProperties |
| 8 |
Private cLocation As clsCharacterLocation |
| 9 |
Private iMaxSize As Integer |
| 10 |
Private iMaxWeight As Integer |
| 11 |
Private eCharacterType As CharacterTypeEnum = CharacterTypeEnum.NonPlayer |
| 12 |
Private oDescription As Description |
| 13 |
Private sIsHereDesc As String |
| 14 |
|
| 15 |
Private sName As String |
| 16 |
Private sArticle As String |
| 17 |
Private sPrefix As String |
| 18 |
Friend arlDescriptors As New StringArrayList |
| 19 |
Friend arlWalks As New WalkArrayList |
| 20 |
|
| 21 |
Private htblSeenLocation As New BooleanHashTable |
| 22 |
Private htblSeenObject As New BooleanHashTable |
| 23 |
Private htblSeenChar As New BooleanHashTable |
| 24 |
|
| 25 |
Friend htblTopics As New TopicHashTable |
| 26 |
|
| 27 |
|
| 28 |
Public Sub New() |
| 29 |
Location = New clsCharacterLocation(Me) |
| 30 |
End Sub |
| 31 |
|
| 32 |
|
| 33 |
Public Overrides ReadOnly Property CommonName() As String |
| 34 |
Get |
| 35 |
Return Name |
| 36 |
End Get |
| 37 |
End Property |
| 38 |
|
| 39 |
|
| 40 |
' Has the player been told the character exists (e.g. "a man"). Once introduced, they will be referred to as "the man" |
| 41 |
' until they are no longer in the same location. |
| 42 |
' |
| 43 |
Private bIntroduced As Boolean = False |
| 44 |
Friend Property Introduced As Boolean |
| 45 |
Get |
| 46 |
Return bIntroduced |
| 47 |
End Get |
| 48 |
Set(value As Boolean) |
| 49 |
bIntroduced = value |
| 50 |
End Set |
| 51 |
End Property |
| 52 |
|
| 53 |
Private sWalkTo As String |
| 54 |
Public Property WalkTo As String |
| 55 |
Get |
| 56 |
Return sWalkTo |
| 57 |
End Get |
| 58 |
Set(value As String) |
| 59 |
If value <> sWalkTo Then |
| 60 |
sWalkTo = value |
| 61 |
End If |
| 62 |
End Set |
| 63 |
End Property |
| 64 |
|
| 65 |
|
| 66 |
Public Sub DoWalk() |
| 67 |
Static sLastPosition As String = "" |
| 68 |
|
| 69 |
If WalkTo <> "" Then |
| 70 |
If Location.LocationKey = sLastPosition Then |
| 71 |
WalkTo = "" ' Something has stopped us moving, so bomb out the walk |
| 72 |
Exit Sub |
| 73 |
End If |
| 74 |
Dim node As WalkNode = Dijkstra(Location.LocationKey, WalkTo) |
| 75 |
If node IsNot Nothing Then |
| 76 |
While node.iDistance > 1 |
| 77 |
node = node.Previous |
| 78 |
End While |
| 79 |
If Me Is Adventure.Player Then |
| 80 |
For Each d As DirectionsEnum In [Enum].GetValues(GetType(DirectionsEnum)) |
| 81 |
If Adventure.htblLocations(Location.LocationKey).arlDirections(d).LocationKey = node.Key Then |
| 82 |
If node.Key = WalkTo Then WalkTo = "" |
| 83 |
fRunner.SetInput(d.ToString) |
| 84 |
sLastPosition = Location.LocationKey |
| 85 |
fRunner.SubmitCommand() |
| 86 |
sLastPosition = "" |
| 87 |
Exit Sub |
| 88 |
End If |
| 89 |
Next |
| 90 |
End If |
| 91 |
Else |
| 92 |
WalkTo = "" |
| 93 |
End If |
| 94 |
End If |
| 95 |
|
| 96 |
End Sub |
| 97 |
|
| 98 |
|
| 99 |
Private Class WalkNode |
| 100 |
Implements IComparable(Of WalkNode) |
| 101 |
|
| 102 |
Public Key As String |
| 103 |
Public iDistance As Integer = Integer.MaxValue |
| 104 |
Public Previous As WalkNode = Nothing |
| 105 |
|
| 106 |
Public Function CompareTo(other As WalkNode) As Integer Implements System.IComparable(Of WalkNode).CompareTo |
| 107 |
Return iDistance.CompareTo(other.iDistance) |
| 108 |
End Function |
| 109 |
End Class |
| 110 |
|
| 111 |
|
| 112 |
' Adapted from http://en.wikipedia.org/wiki/Dijkstra's_algorithm |
| 113 |
' |
| 114 |
Private Function Dijkstra(ByVal sFrom As String, ByVal sTo As String) As WalkNode |
| 115 |
|
| 116 |
Dim WalkNodes As New Dictionary(Of String, WalkNode) |
| 117 |
Dim Q As New List(Of WalkNode) |
| 118 |
|
| 119 |
For Each sKey As String In Adventure.htblLocations.Keys |
| 120 |
Dim node As New WalkNode |
| 121 |
node.Key = sKey |
| 122 |
node.iDistance = Integer.MaxValue ' Unknown distance function from source to v |
| 123 |
node.Previous = Nothing ' Previous node in optimal path from source |
| 124 |
WalkNodes.Add(sKey, node) |
| 125 |
Q.Add(node) |
| 126 |
Next |
| 127 |
|
| 128 |
WalkNodes(sFrom).iDistance = 0 ' Distance from source to source |
| 129 |
Q.Sort() |
| 130 |
|
| 131 |
While Q.Count > 0 |
| 132 |
|
| 133 |
Dim u As WalkNode = Q(0) ' vertex in Q with smallest distance |
| 134 |
If u.iDistance = Integer.MaxValue Then Exit While ' all remaining vertices are inaccessible from source |
| 135 |
|
| 136 |
If u.Key = sTo Then Return u |
| 137 |
Q.Remove(u) |
| 138 |
|
| 139 |
For Each d As DirectionsEnum In [Enum].GetValues(GetType(DirectionsEnum)) |
| 140 |
If HasRouteInDirection(d, False, u.Key) Then |
| 141 |
Dim sDest As String = Adventure.htblLocations(u.Key).arlDirections(d).LocationKey |
| 142 |
If Adventure.htblLocations(sDest).SeenBy(Me.Key) Then |
| 143 |
Dim alt As Integer = u.iDistance + 1 |
| 144 |
If alt < WalkNodes(sDest).iDistance Then |
| 145 |
WalkNodes(sDest).iDistance = alt |
| 146 |
WalkNodes(sDest).Previous = u |
| 147 |
Q.Sort() |
| 148 |
End If |
| 149 |
End If |
| 150 |
End If |
| 151 |
Next |
| 152 |
|
| 153 |
End While |
| 154 |
|
| 155 |
Return Nothing |
| 156 |
|
| 157 |
End Function |
| 158 |
|
| 159 |
|
| 160 |
Private ePerspective As PerspectiveEnum = PerspectiveEnum.SecondPerson ' Default for Player |
| 161 |
Friend Property Perspective As PerspectiveEnum |
| 162 |
Get |
| 163 |
If eCharacterType = CharacterTypeEnum.Player Then |
| 164 |
Return ePerspective |
| 165 |
Else |
| 166 |
Return PerspectiveEnum.ThirdPerson |
| 167 |
End If |
| 168 |
End Get |
| 169 |
Set(value As PerspectiveEnum) |
| 170 |
ePerspective = value |
| 171 |
End Set |
| 172 |
End Property |
| 173 |
|
| 174 |
|
| 175 |
' This gets updated at the end of each turn, and allows any tasks to |
| 176 |
' reference the parent before they are updated from task actions |
| 177 |
' |
| 178 |
Private sPrevParent As String |
| 179 |
Public Property PrevParent() As String |
| 180 |
Get |
| 181 |
Return sPrevParent |
| 182 |
End Get |
| 183 |
Set(ByVal value As String) |
| 184 |
sPrevParent = value |
| 185 |
End Set |
| 186 |
End Property |
| 187 |
|
| 188 |
|
| 189 |
Friend Overrides ReadOnly Property Parent() As String |
| 190 |
Get |
| 191 |
Return Location.Key |
| 192 |
End Get |
| 193 |
End Property |
| 194 |
|
| 195 |
|
| 196 |
Public Enum CharacterTypeEnum |
| 197 |
Player |
| 198 |
NonPlayer |
| 199 |
End Enum |
| 200 |
|
| 201 |
Public Enum GenderEnum |
| 202 |
Male = 0 |
| 203 |
Female = 1 |
| 204 |
Unknown = 2 |
| 205 |
End Enum |
| 206 |
|
| 207 |
Public Property Gender() As GenderEnum |
| 208 |
Get |
| 209 |
Select Case GetPropertyValue("Gender") |
| 210 |
Case "Male" |
| 211 |
Return GenderEnum.Male |
| 212 |
Case "Female" |
| 213 |
Return GenderEnum.Female |
| 214 |
Case Else |
| 215 |
Return GenderEnum.Unknown |
| 216 |
End Select |
| 217 |
End Get |
| 218 |
Set(ByVal Value As GenderEnum) |
| 219 |
SetPropertyValue("Gender", Value.ToString) |
| 220 |
End Set |
| 221 |
End Property |
| 222 |
|
| 223 |
|
| 224 |
Public Property CharacterType() As CharacterTypeEnum |
| 225 |
Get |
| 226 |
Return eCharacterType |
| 227 |
End Get |
| 228 |
Set(ByVal Value As CharacterTypeEnum) |
| 229 |
eCharacterType = Value |
| 230 |
End Set |
| 231 |
End Property |
| 232 |
|
| 233 |
|
| 234 |
Public Property HasSeenLocation(ByVal sLocKey As String) As Boolean |
| 235 |
Get |
| 236 |
If htblSeenLocation.ContainsKey(sLocKey) Then |
| 237 |
Return CBool(htblSeenLocation(sLocKey)) |
| 238 |
Else |
| 239 |
Return False |
| 240 |
End If |
| 241 |
End Get |
| 242 |
Set(ByVal Value As Boolean) |
| 243 |
If Not htblSeenLocation.ContainsKey(sLocKey) Then |
| 244 |
htblSeenLocation.Add(Value, sLocKey) |
| 245 |
Else |
| 246 |
htblSeenLocation(sLocKey) = Value |
| 247 |
End If |
| 248 |
If Me Is Adventure.Player Then |
| 249 |
For Each p As MapPage In Adventure.Map.Pages.Values |
| 250 |
For Each n As MapNode In p.Nodes |
| 251 |
If n.Key = sLocKey Then |
| 252 |
n.Seen = Value |
| 253 |
Exit Property |
| 254 |
End If |
| 255 |
Next |
| 256 |
Next |
| 257 |
End If |
| 258 |
End Set |
| 259 |
End Property |
| 260 |
|
| 261 |
Public Property HasSeenObject(ByVal sObKey As String) As Boolean |
| 262 |
Get |
| 263 |
If htblSeenObject.ContainsKey(sObKey) Then |
| 264 |
Return CBool(htblSeenObject(sObKey)) |
| 265 |
Else |
| 266 |
Return False |
| 267 |
End If |
| 268 |
End Get |
| 269 |
Set(ByVal Value As Boolean) |
| 270 |
If Not htblSeenObject.ContainsKey(sObKey) Then |
| 271 |
htblSeenObject.Add(Value, sObKey) |
| 272 |
Else |
| 273 |
htblSeenObject(sObKey) = Value |
| 274 |
End If |
| 275 |
End Set |
| 276 |
End Property |
| 277 |
|
| 278 |
Public Property HasSeenCharacter(ByVal sCharKey As String) As Boolean |
| 279 |
Get |
| 280 |
If htblSeenChar.ContainsKey(sCharKey) Then |
| 281 |
Return CBool(htblSeenChar(sCharKey)) |
| 282 |
Else |
| 283 |
Return False |
| 284 |
End If |
| 285 |
End Get |
| 286 |
Set(ByVal Value As Boolean) |
| 287 |
If Not htblSeenChar.ContainsKey(sCharKey) Then |
| 288 |
htblSeenChar.Add(Value, sCharKey) |
| 289 |
Else |
| 290 |
htblSeenChar(sCharKey) = Value |
| 291 |
End If |
| 292 |
End Set |
| 293 |
End Property |
| 294 |
|
| 295 |
Public Property SeenBy(ByVal sCharKey As String) As Boolean |
| 296 |
Get |
| 297 |
Return Adventure.htblCharacters(sCharKey).HasSeenCharacter(Key) |
| 298 |
End Get |
| 299 |
Set(ByVal Value As Boolean) |
| 300 |
Adventure.htblCharacters(sCharKey).HasSeenCharacter(Key) = Value |
| 301 |
End Set |
| 302 |
End Property |
| 303 |
|
| 304 |
|
| 305 |
Public ReadOnly Property AloneWithChar As String |
| 306 |
Get |
| 307 |
Dim iCount As Integer = 0 |
| 308 |
Dim sChar As String = Nothing |
| 309 |
For Each ch As clsCharacter In Adventure.htblCharacters.Values |
| 310 |
If ch IsNot Me Then |
| 311 |
If Location.LocationKey = ch.Location.LocationKey Then |
| 312 |
iCount += 1 |
| 313 |
sChar = ch.Key |
| 314 |
End If |
| 315 |
End If |
| 316 |
If iCount > 1 Then Return Nothing |
| 317 |
Next |
| 318 |
If iCount = 1 Then Return sChar Else Return Nothing |
| 319 |
End Get |
| 320 |
End Property |
| 321 |
|
| 322 |
' ExplicitPronoun - The user has said they want it to be this pronoun, so don't auto-switch it |
| 323 |
Friend ReadOnly Property Name(Optional ByVal Pronoun As PronounEnum = PronounEnum.Subjective, Optional bMarkAsSeen As Boolean = True, Optional ByVal bAllowPronouns As Boolean = True, Optional ByVal Article As ArticleTypeEnum = ArticleTypeEnum.Indefinite, Optional ByVal bForcePronoun As Boolean = False, Optional ByVal bExplicitArticle As Boolean = False) As String |
| 324 |
Get |
| 325 |
With UserSession |
| 326 |
|
| 327 |
|
| 328 |
Dim bReplaceWithPronoun As Boolean = bForcePronoun |
| 329 |
|
| 330 |
If .bDisplaying Then |
| 331 |
If Not bExplicitArticle AndAlso Introduced AndAlso Article = ArticleTypeEnum.Indefinite Then Article = ArticleTypeEnum.Definite |
| 332 |
If bMarkAsSeen Then |
| 333 |
Introduced = True |
| 334 |
If Not Adventure.lCharMentionedThisTurn(Gender).Contains(Key) Then Adventure.lCharMentionedThisTurn(Gender).Add(Key) |
| 335 |
End If |
| 336 |
|
| 337 |
' If we already have mentioned this key, and it's the most recent key, we can replace with pronoun |
| 338 |
If Perspective = PerspectiveEnum.FirstPerson OrElse Perspective = PerspectiveEnum.SecondPerson Then bReplaceWithPronoun = True |
| 339 |
|
| 340 |
If .PronounKeys.Count > 0 Then |
| 341 |
Dim oPreviousPronoun As PronounInfo = Nothing |
| 342 |
For i As Integer = .PronounKeys.Count - 1 To 0 Step -1 |
| 343 |
With .PronounKeys(i) |
| 344 |
If .Gender = Gender AndAlso .Key = Key Then |
| 345 |
oPreviousPronoun = UserSession.PronounKeys(i) |
| 346 |
Exit For |
| 347 |
End If |
| 348 |
End With |
| 349 |
Next |
| 350 |
If oPreviousPronoun IsNot Nothing Then |
| 351 |
bReplaceWithPronoun = True |
| 352 |
If oPreviousPronoun.Pronoun = PronounEnum.Subjective AndAlso Pronoun = PronounEnum.Objective Then |
| 353 |
Pronoun = PronounEnum.Reflective |
| 354 |
End If |
| 355 |
End If |
| 356 |
End If |
| 357 |
End If |
| 358 |
If Pronoun = PronounEnum.None Then bReplaceWithPronoun = False |
| 359 |
|
| 360 |
If Not bAllowPronouns OrElse Not bReplaceWithPronoun Then |
| 361 |
' Display the actual name/descriptor |
| 362 |
Dim sName As String |
| 363 |
If HasProperty("Known") Then |
| 364 |
If GetProperty("Known").Selected Then |
| 365 |
sName = ProperName |
| 366 |
Else |
| 367 |
sName = Descriptor(Article) |
| 368 |
End If |
| 369 |
Else |
| 370 |
If Descriptor <> "" Then |
| 371 |
sName = Descriptor(Article) |
| 372 |
Else |
| 373 |
sName = ProperName |
| 374 |
End If |
| 375 |
End If |
| 376 |
If Pronoun = PronounEnum.Possessive Then |
| 377 |
Return sName & "'s" |
| 378 |
Else |
| 379 |
Return sName |
| 380 |
End If |
| 381 |
Else |
| 382 |
' Display the pronoun |
| 383 |
Select Case Perspective |
| 384 |
Case PerspectiveEnum.FirstPerson |
| 385 |
Select Case Pronoun |
| 386 |
Case PronounEnum.Objective |
| 387 |
Return "me" |
| 388 |
Case PronounEnum.Possessive |
| 389 |
Return "my" ' "mine" |
| 390 |
Case PronounEnum.Reflective |
| 391 |
Return "myself" |
| 392 |
Case PronounEnum.Subjective |
| 393 |
Return "I" |
| 394 |
End Select |
| 395 |
Case PerspectiveEnum.SecondPerson |
| 396 |
Select Case Pronoun |
| 397 |
Case PronounEnum.Objective |
| 398 |
Return "you" |
| 399 |
Case PronounEnum.Possessive |
| 400 |
Return "your" ' "yours" |
| 401 |
Case PronounEnum.Reflective |
| 402 |
Return "yourself" |
| 403 |
Case PronounEnum.Subjective |
| 404 |
Return "you" |
| 405 |
End Select |
| 406 |
Case PerspectiveEnum.ThirdPerson |
| 407 |
Select Case Pronoun |
| 408 |
Case PronounEnum.Objective |
| 409 |
Select Case Gender |
| 410 |
Case GenderEnum.Male |
| 411 |
Return "him" |
| 412 |
Case GenderEnum.Female |
| 413 |
Return "her" |
| 414 |
Case GenderEnum.Unknown |
| 415 |
Return "it" |
| 416 |
End Select |
| 417 |
Case PronounEnum.Possessive |
| 418 |
Select Case Gender |
| 419 |
Case GenderEnum.Male |
| 420 |
Return "his" |
| 421 |
Case GenderEnum.Female |
| 422 |
Return "her" ' "hers" |
| 423 |
Case GenderEnum.Unknown |
| 424 |
Return "its" |
| 425 |
End Select |
| 426 |
Case PronounEnum.Reflective |
| 427 |
Select Case Gender |
| 428 |
Case GenderEnum.Male |
| 429 |
Return "himself" |
| 430 |
Case GenderEnum.Female |
| 431 |
Return "herself" |
| 432 |
Case GenderEnum.Unknown |
| 433 |
Return "itself" |
| 434 |
End Select |
| 435 |
Case PronounEnum.Subjective |
| 436 |
Select Case Gender |
| 437 |
Case GenderEnum.Male |
| 438 |
Return "he" |
| 439 |
Case GenderEnum.Female |
| 440 |
Return "she" |
| 441 |
Case GenderEnum.Unknown |
| 442 |
Return "it" |
| 443 |
End Select |
| 444 |
End Select |
| 445 |
End Select |
| 446 |
End If |
| 447 |
|
| 448 |
Return "" |
| 449 |
|
| 450 |
End With |
| 451 |
End Get |
| 452 |
End Property |
| 453 |
|
| 454 |
|
| 455 |
Friend Property ProperName(Optional ByVal Pronoun As PronounEnum = PronounEnum.Subjective) As String |
| 456 |
Get |
| 457 |
If sName <> "" Then Return sName Else Return "Anonymous" |
| 458 |
End Get |
| 459 |
Set(ByVal Value As String) |
| 460 |
sName = Value |
| 461 |
End Set |
| 462 |
End Property |
| 463 |
|
| 464 |
|
| 465 |
Friend ReadOnly Property Descriptor(Optional ByVal Article As ArticleTypeEnum = ArticleTypeEnum.Indefinite) As String |
| 466 |
Get |
| 467 |
If arlDescriptors.Count > 0 Then |
| 468 |
Dim sArticle2 As String = Nothing ' sArticle |
| 469 |
Select Case Article |
| 470 |
Case ArticleTypeEnum.Definite |
| 471 |
If sArticle <> "" Then sArticle2 = "the" |
| 472 |
Case ArticleTypeEnum.Indefinite |
| 473 |
sArticle2 = sArticle |
| 474 |
Case ArticleTypeEnum.None |
| 475 |
sArticle2 = "" |
| 476 |
End Select |
| 477 |
'If TheName AndAlso sArticle <> "" Then sArticle2 = "the" |
| 478 |
If sArticle <> "" Then sArticle2 &= " " |
| 479 |
If sPrefix <> "" Then |
| 480 |
Return sArticle2 & sPrefix & " " & arlDescriptors(0) |
| 481 |
Else |
| 482 |
Return sArticle2 & arlDescriptors(0) |
| 483 |
End If |
| 484 |
Else |
| 485 |
Return "" |
| 486 |
End If |
| 487 |
End Get |
| 488 |
End Property |
| 489 |
|
| 490 |
|
| 491 |
Public Sub Move(ByVal ToWhere As String) |
| 492 |
|
| 493 |
If Adventure.htblLocations.ContainsKey(ToWhere) Then |
| 494 |
Dim loc As New clsCharacterLocation(Me) |
| 495 |
loc.ExistWhere = clsCharacterLocation.ExistsWhereEnum.AtLocation |
| 496 |
loc.Key = ToWhere |
| 497 |
Move(loc) |
| 498 |
ElseIf ToWhere = HIDDEN Then |
| 499 |
Dim loc As New clsCharacterLocation(Me) |
| 500 |
loc.ExistWhere = clsCharacterLocation.ExistsWhereEnum.Hidden |
| 501 |
loc.Key = "" |
| 502 |
Move(loc) |
| 503 |
End If |
| 504 |
|
| 505 |
End Sub |
| 506 |
Public Sub Move(ByVal ToWhere As clsCharacterLocation) |
| 507 |
If Me Is Adventure.Player Then |
| 508 |
For Each t As clsTask In Adventure.Tasks(clsAdventure.TasksListEnum.SystemTasks).Values |
| 509 |
If t.Repeatable OrElse Not t.Completed Then |
| 510 |
If Adventure.Player.Location.LocationKey <> ToWhere.LocationKey AndAlso t.LocationTrigger = ToWhere.LocationKey Then |
| 511 |
' Ok, we need to trigger this task |
| 512 |
Adventure.qTasksToRun.Enqueue(t.Key) |
| 513 |
End If |
| 514 |
End If |
| 515 |
Next |
| 516 |
End If |
| 517 |
|
| 518 |
' Ensure that character Key is not this character, or on this character |
| 519 |
Me.Location = ToWhere |
| 520 |
|
| 521 |
' Update any 'seen' things |
| 522 |
If ToWhere.ExistWhere = clsCharacterLocation.ExistsWhereEnum.AtLocation Then |
| 523 |
Location.sLastLocationKey = ToWhere.Key |
| 524 |
If htblSeenLocation.ContainsKey(ToWhere.Key) Then htblSeenLocation(ToWhere.Key) = True Else htblSeenLocation.Add(True, ToWhere.Key) |
| 525 |
If Adventure.htblLocations.ContainsKey(ToWhere.Key) Then |
| 526 |
For Each ob As clsObject In Adventure.htblLocations(ToWhere.Key).ObjectsInLocation(clsLocation.WhichObjectsToListEnum.AllObjects, True).Values |
| 527 |
If htblSeenObject.ContainsKey(ob.Key) Then htblSeenObject(ob.Key) = True Else htblSeenObject.Add(True, ob.Key) |
| 528 |
Next |
| 529 |
For Each ch As clsCharacter In Adventure.htblLocations(ToWhere.Key).CharactersVisibleAtLocation.Values |
| 530 |
If htblSeenChar.ContainsKey(ch.Key) Then htblSeenChar(ch.Key) = True Else htblSeenChar.Add(True, ch.Key) |
| 531 |
Next |
| 532 |
End If |
| 533 |
End If |
| 534 |
|
| 535 |
If Adventure.sConversationCharKey <> "" Then |
| 536 |
If Adventure.htblCharacters(Adventure.sConversationCharKey).Location.Key <> Adventure.Player.Location.Key Then |
| 537 |
If Me.Key = Adventure.Player.Key Then |
| 538 |
Dim farewell As clsTopic = UserSession.FindConversationNode(Adventure.htblCharacters(Adventure.sConversationCharKey), clsAction.ConversationEnum.Farewell, "") |
| 539 |
If farewell IsNot Nothing Then |
| 540 |
UserSession.Display(farewell.oConversation.ToString) |
| 541 |
End If |
| 542 |
End If |
| 543 |
Adventure.sConversationCharKey = "" |
| 544 |
Adventure.sConversationNode = "" |
| 545 |
End If |
| 546 |
End If |
| 547 |
|
| 548 |
If Me Is Adventure.Player Then |
| 549 |
Adventure.Map.RefreshNode(Adventure.Player.Location.LocationKey) |
| 550 |
UserSession.Map.SelectNode(Adventure.Player.Location.LocationKey) |
| 551 |
End If |
| 552 |
End Sub |
| 553 |
|
| 554 |
|
| 555 |
Public Property Location() As clsCharacterLocation |
| 556 |
Get |
| 557 |
Return cLocation |
| 558 |
End Get |
| 559 |
Set(ByVal Value As clsCharacterLocation) |
| 560 |
Try |
| 561 |
cLocation = Value |
| 562 |
Catch ex As Exception |
| 563 |
ErrMsg("Error moving character " & Name & " to location", ex) |
| 564 |
End Try |
| 565 |
End Set |
| 566 |
|
| 567 |
End Property |
| 568 |
|
| 569 |
|
| 570 |
Public Property MaxSize() As Integer |
| 571 |
Get |
| 572 |
Return iMaxSize |
| 573 |
End Get |
| 574 |
Set(ByVal Value As Integer) |
| 575 |
iMaxSize = Value |
| 576 |
End Set |
| 577 |
End Property |
| 578 |
|
| 579 |
|
| 580 |
Public Property MaxWeight() As Integer |
| 581 |
Get |
| 582 |
Return iMaxWeight |
| 583 |
End Get |
| 584 |
Set(ByVal Value As Integer) |
| 585 |
iMaxWeight = Value |
| 586 |
End Set |
| 587 |
End Property |
| 588 |
|
| 589 |
Public Property Article() As String |
| 590 |
Get |
| 591 |
Return sArticle |
| 592 |
End Get |
| 593 |
Set(ByVal Value As String) |
| 594 |
sArticle = Value |
| 595 |
End Set |
| 596 |
End Property |
| 597 |
|
| 598 |
Public Property Prefix() As String |
| 599 |
Get |
| 600 |
Return sPrefix |
| 601 |
End Get |
| 602 |
Set(ByVal Value As String) |
| 603 |
sPrefix = Value |
| 604 |
End Set |
| 605 |
End Property |
| 606 |
|
| 607 |
Friend Property Description() As Description |
| 608 |
Get |
| 609 |
If oDescription Is Nothing Then oDescription = New Description |
| 610 |
Return oDescription |
| 611 |
End Get |
| 612 |
Set(ByVal Value As Description) |
| 613 |
oDescription = Value |
| 614 |
End Set |
| 615 |
End Property |
| 616 |
|
| 617 |
Public Property IsHereDesc() As String |
| 618 |
Get |
| 619 |
Return GetPropertyValue("CharHereDesc") |
| 620 |
End Get |
| 621 |
Set(ByVal Value As String) |
| 622 |
If Value <> "" Then |
| 623 |
SetPropertyValue("CharHereDesc", Value) |
| 624 |
Else |
| 625 |
RemoveProperty("CharHereDesc") |
| 626 |
End If |
| 627 |
End Set |
| 628 |
End Property |
| 629 |
|
| 630 |
Public Overrides ReadOnly Property Clone() As clsItem |
| 631 |
Get |
| 632 |
Dim ch As clsCharacter = CType(Me.MemberwiseClone, clsCharacter) |
| 633 |
ch.htblActualProperties = CType(ch.htblActualProperties.Clone, PropertyHashTable) |
| 634 |
ch.arlDescriptors = ch.arlDescriptors.Clone |
| 635 |
Return ch |
| 636 |
End Get |
| 637 |
End Property |
| 638 |
|
| 639 |
|
| 640 |
Friend ReadOnly Property ChildrenObjects(ByVal WhereChildren As clsObject.WhereChildrenEnum, Optional ByVal bRecursive As Boolean = False) As ObjectHashTable |
| 641 |
Get |
| 642 |
Dim htblChildren As New ObjectHashTable |
| 643 |
|
| 644 |
For Each ob As clsObject In Adventure.htblObjects.Values |
| 645 |
If Not ob.IsStatic Then |
| 646 |
If ob.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.HeldByCharacter Or ob.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.WornByCharacter Then |
| 647 |
If ob.Location.Key = Me.Key Then |
| 648 |
htblChildren.Add(ob, ob.Key) |
| 649 |
If bRecursive Then |
| 650 |
For Each obChild As clsObject In ob.Children(clsObject.WhereChildrenEnum.Everything, True).Values |
| 651 |
htblChildren.Add(obChild, obChild.Key) |
| 652 |
Next |
| 653 |
End If |
| 654 |
End If |
| 655 |
End If |
| 656 |
End If |
| 657 |
Next |
| 658 |
|
| 659 |
Return htblChildren |
| 660 |
End Get |
| 661 |
End Property |
| 662 |
|
| 663 |
Friend dictHasRouteCache As New Generic.Dictionary(Of String, Boolean) |
| 664 |
Friend dictRouteErrors As New Generic.Dictionary(Of String, String) |
| 665 |
Public Function HasRouteInDirection(ByVal drn As DirectionsEnum, ByVal bIgnoreRestrictions As Boolean, Optional ByVal sFromLocation As String = "", Optional ByRef sErrorMessage As String = "") As Boolean |
| 666 |
|
| 667 |
If sFromLocation = "" Then sFromLocation = Location.LocationKey |
| 668 |
If Not Adventure.htblLocations.ContainsKey(sFromLocation) Then Return False |
| 669 |
|
| 670 |
Dim d As clsDirection = Adventure.htblLocations(sFromLocation).arlDirections(drn) |
| 671 |
If d.LocationKey <> "" Then |
| 672 |
If bIgnoreRestrictions Then |
| 673 |
Return True |
| 674 |
Else |
| 675 |
Dim bResult As Boolean |
| 676 |
If dictHasRouteCache.ContainsKey(sFromLocation & drn.ToString) Then |
| 677 |
bResult = dictHasRouteCache(sFromLocation & drn.ToString) |
| 678 |
If Not bResult Then sErrorMessage = dictRouteErrors(sFromLocation & drn.ToString) |
| 679 |
Return bResult |
| 680 |
End If |
| 681 |
' evaluate direction restrictions |
| 682 |
bResult = UserSession.PassRestrictions(d.Restrictions) |
| 683 |
If Not bResult Then sErrorMessage = UserSession.sRestrictionText |
| 684 |
dictHasRouteCache.Add(sFromLocation & drn.ToString, bResult) |
| 685 |
dictRouteErrors.Add(sFromLocation & drn.ToString, sErrorMessage) |
| 686 |
If Not bResult Then d.bEverBeenBlocked = True |
| 687 |
Return bResult |
| 688 |
End If |
| 689 |
Else |
| 690 |
Return False |
| 691 |
End If |
| 692 |
|
| 693 |
End Function |
| 694 |
|
| 695 |
Public ReadOnly Property IsInGroupOrLocation(ByVal sGroupOrLocationKey As String) As Boolean |
| 696 |
Get |
| 697 |
If Adventure.htblLocations.ContainsKey(sGroupOrLocationKey) Then |
| 698 |
If Me.Location.LocationKey = sGroupOrLocationKey Then |
| 699 |
Return True |
| 700 |
End If |
| 701 |
ElseIf Adventure.htblGroups.ContainsKey(sGroupOrLocationKey) Then |
| 702 |
If Adventure.htblGroups(sGroupOrLocationKey).arlMembers.Contains(Me.Location.LocationKey) Then |
| 703 |
Return True |
| 704 |
End If |
| 705 |
End If |
| 706 |
|
| 707 |
Return False |
| 708 |
End Get |
| 709 |
End Property |
| 710 |
|
| 711 |
Public ReadOnly Property BoundVisible As String |
| 712 |
Get |
| 713 |
With Me.Location |
| 714 |
Select Case .ExistWhere |
| 715 |
Case clsCharacterLocation.ExistsWhereEnum.AtLocation |
| 716 |
Return .Key |
| 717 |
Case clsCharacterLocation.ExistsWhereEnum.Hidden |
| 718 |
Return HIDDEN |
| 719 |
Case clsCharacterLocation.ExistsWhereEnum.InObject |
| 720 |
With Adventure.htblObjects(.Key) |
| 721 |
If Not .Openable OrElse .IsOpen OrElse .IsTransparent Then |
| 722 |
Return Adventure.htblObjects(.Key).BoundVisible |
| 723 |
Else |
| 724 |
Return .Key |
| 725 |
End If |
| 726 |
End With |
| 727 |
Case clsCharacterLocation.ExistsWhereEnum.OnCharacter |
| 728 |
Return Adventure.htblCharacters(.Key).BoundVisible |
| 729 |
Case clsCharacterLocation.ExistsWhereEnum.OnObject |
| 730 |
Return Adventure.htblObjects(.Key).BoundVisible |
| 731 |
Case clsCharacterLocation.ExistsWhereEnum.Uninitialised |
| 732 |
Return HIDDEN |
| 733 |
End Select |
| 734 |
Return HIDDEN |
| 735 |
End With |
| 736 |
End Get |
| 737 |
End Property |
| 738 |
|
| 739 |
|
| 740 |
Friend Function CanSeeCharacter(ByVal sCharKey As String) As Boolean |
| 741 |
Return IsVisibleTo(sCharKey) |
| 742 |
End Function |
| 743 |
Public ReadOnly Property IsVisibleTo(ByVal sCharKey As String) As Boolean |
| 744 |
Get |
| 745 |
If sCharKey = "%Player%" Then sCharKey = Adventure.Player.Key |
| 746 |
|
| 747 |
Dim sBoundVisible As String = BoundVisible |
| 748 |
Dim sBoundVisibleCh As String = Adventure.htblCharacters(sCharKey).BoundVisible |
| 749 |
|
| 750 |
If sBoundVisible = HIDDEN Then Return False |
| 751 |
|
| 752 |
Return sBoundVisible = sBoundVisibleCh |
| 753 |
|
| 754 |
End Get |
| 755 |
End Property |
| 756 |
|
| 757 |
|
| 758 |
Public ReadOnly Property IsVisibleAtLocation(ByVal sLocationKey As String) As Boolean |
| 759 |
Get |
| 760 |
Dim sBoundVisible As String = BoundVisible |
| 761 |
|
| 762 |
If sBoundVisible = HIDDEN Then Return False |
| 763 |
|
| 764 |
If Adventure.htblGroups.ContainsKey(sBoundVisible) Then |
| 765 |
Return Adventure.htblGroups(sBoundVisible).arlMembers.Contains(sLocationKey) |
| 766 |
Else |
| 767 |
Return sBoundVisible = sLocationKey |
| 768 |
End If |
| 769 |
End Get |
| 770 |
End Property |
| 771 |
|
| 772 |
Public ReadOnly Property CanSeeObject(ByVal sObKey As String) As Boolean |
| 773 |
Get |
| 774 |
Dim sBoundVisible As String = BoundVisible |
| 775 |
|
| 776 |
If sBoundVisible = HIDDEN Then Return False |
| 777 |
|
| 778 |
If Adventure.htblGroups.ContainsKey(sObKey) Then |
| 779 |
For Each sOb As String In Adventure.htblGroups(sObKey).arlMembers |
| 780 |
If CanSeeObject(sOb) Then Return True |
| 781 |
Next |
| 782 |
Return False |
| 783 |
End If |
| 784 |
|
| 785 |
Dim sBoundVisibleOb As String = Adventure.htblObjects(sObKey).BoundVisible |
| 786 |
|
| 787 |
If Adventure.htblGroups.ContainsKey(sBoundVisibleOb) Then |
| 788 |
Return Adventure.htblGroups(sBoundVisibleOb).arlMembers.Contains(sBoundVisible) |
| 789 |
Else |
| 790 |
Return sBoundVisible = sBoundVisibleOb OrElse sBoundVisible = sObKey ' Allow us to see the object we're in, otherwise we can't do anything with it (open it again!) |
| 791 |
End If |
| 792 |
End Get |
| 793 |
End Property |
| 794 |
|
| 795 |
|
| 796 |
Public ReadOnly Property IsWearingObject(ByVal sObKey As String, Optional ByVal bDirectly As Boolean = True) As Boolean |
| 797 |
Get |
| 798 |
If sObKey = NOOBJECT Then Return WornObjects.Count = 0 |
| 799 |
If sObKey = ANYOBJECT Then Return WornObjects.Count > 0 |
| 800 |
|
| 801 |
With Adventure.htblObjects(sObKey).Location |
| 802 |
Select Case .DynamicExistWhere |
| 803 |
Case clsObjectLocation.DynamicExistsWhereEnum.WornByCharacter |
| 804 |
If .Key = Me.Key OrElse (.Key = "%Player%" AndAlso Me.eCharacterType = CharacterTypeEnum.Player) Then Return True |
| 805 |
Case clsObjectLocation.DynamicExistsWhereEnum.InObject, clsObjectLocation.DynamicExistsWhereEnum.OnObject |
| 806 |
If Not bDirectly Then |
| 807 |
Return IsWearingObject(Adventure.htblObjects(sObKey).Parent) |
| 808 |
Else |
| 809 |
Return False |
| 810 |
End If |
| 811 |
End Select |
| 812 |
Return False |
| 813 |
End With |
| 814 |
End Get |
| 815 |
End Property |
| 816 |
|
| 817 |
|
| 818 |
Public ReadOnly Property sRegularExpressionString(Optional ByVal bMyRE As Boolean = False, Optional ByVal bPlural As Boolean = False, Optional ByVal bPrefixMandatory As Boolean = False) As String |
| 819 |
Get |
| 820 |
Dim arl As StringArrayList = arlDescriptors |
| 821 |
|
| 822 |
If bMyRE Then |
| 823 |
' The ADRIFT 'advanced command construction' expression |
| 824 |
Dim sRE As String = "{" & sArticle & "/the} " |
| 825 |
If sPrefix <> "" Then |
| 826 |
For Each sSinglePrefix As String In Split(sPrefix, " ") |
| 827 |
If sSinglePrefix <> "" Then sRE &= "{" & sSinglePrefix.ToLower & "} " |
| 828 |
Next |
| 829 |
End If |
| 830 |
sRE &= "[" |
| 831 |
For Each sNoun As String In arl |
| 832 |
sRE &= sNoun.ToLower & "/" |
| 833 |
Next |
| 834 |
If Not Adventure.htblCharacterProperties.ContainsKey("Known") OrElse HasProperty("Known") OrElse arl.Count = 0 Then sRE &= ProperName.ToLower & "/" |
| 835 |
Return Left(sRE, sRE.Length - 1) & "]" |
| 836 |
Else |
| 837 |
' Real Regular Expressions |
| 838 |
Dim sRE As String = "(" |
| 839 |
If sArticle <> "" Then sRE &= sArticle & " |" |
| 840 |
sRE &= "the )?" |
| 841 |
For Each sSinglePrefix As String In Split(sPrefix, " ") |
| 842 |
If sSinglePrefix <> "" Then sRE &= "(" & sSinglePrefix.ToLower & " )?" |
| 843 |
Next |
| 844 |
sRE &= "(" |
| 845 |
For Each sNoun As String In arl |
| 846 |
sRE &= sNoun.ToLower & "|" |
| 847 |
Next |
| 848 |
If Not Adventure.htblCharacterProperties.ContainsKey("Known") OrElse HasProperty("Known") OrElse arl.Count = 0 Then sRE &= ProperName.ToLower & "|" |
| 849 |
Return Left(sRE, sRE.Length - 1) & ")" |
| 850 |
End If |
| 851 |
|
| 852 |
End Get |
| 853 |
End Property |
| 854 |
|
| 855 |
|
| 856 |
' Returns True if character is directly inside parent, or if on/in something that is inside it |
| 857 |
Public ReadOnly Property IsInside(ByVal sParentKey As String) As Boolean |
| 858 |
Get |
| 859 |
If (Me.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.OnObject OrElse Me.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.InObject) AndAlso Parent <> "" Then |
| 860 |
If Me.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.InObject AndAlso Parent = sParentKey Then |
| 861 |
Return True |
| 862 |
Else |
| 863 |
Dim obParent As clsObject = Adventure.htblObjects(Parent) |
| 864 |
Return obParent.IsInside(sParentKey) |
| 865 |
End If |
| 866 |
Else |
| 867 |
Return False |
| 868 |
End If |
| 869 |
End Get |
| 870 |
End Property |
| 871 |
|
| 872 |
|
| 873 |
' Returns True if character is directly on parent, or if on/in something that is inside it |
| 874 |
Public ReadOnly Property IsOn(ByVal sParentKey As String) As Boolean |
| 875 |
Get |
| 876 |
If (Me.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.OnObject OrElse Me.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.InObject OrElse Me.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.OnCharacter) AndAlso Parent <> "" Then |
| 877 |
If (Me.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.OnObject OrElse Me.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.OnCharacter) AndAlso Parent = sParentKey Then |
| 878 |
Return True |
| 879 |
Else |
| 880 |
If Adventure.htblObjects.ContainsKey(Parent) Then |
| 881 |
Dim obParent As clsObject = Adventure.htblObjects(Parent) |
| 882 |
Return obParent.IsOn(sParentKey) |
| 883 |
ElseIf Adventure.htblCharacters.ContainsKey(Parent) Then |
| 884 |
Dim chParent As clsCharacter = Adventure.htblCharacters(Parent) |
| 885 |
Return chParent.IsOn(sParentKey) |
| 886 |
End If |
| 887 |
End If |
| 888 |
Else |
| 889 |
Return False |
| 890 |
End If |
| 891 |
End Get |
| 892 |
End Property |
| 893 |
|
| 894 |
|
| 895 |
Public ReadOnly Property IsHoldingObject(ByVal sObKey As String, Optional ByVal bDirectly As Boolean = False) As Boolean |
| 896 |
Get |
| 897 |
If sObKey = NOOBJECT Then Return HeldObjects.Count = 0 |
| 898 |
If sObKey = ANYOBJECT Then Return HeldObjects.Count > 0 |
| 899 |
|
| 900 |
With Adventure.htblObjects(sObKey).Location |
| 901 |
Select Case .DynamicExistWhere |
| 902 |
Case clsObjectLocation.DynamicExistsWhereEnum.HeldByCharacter |
| 903 |
If .Key = Me.Key OrElse (.Key = "%Player%" AndAlso Me.eCharacterType = CharacterTypeEnum.Player) Then Return True |
| 904 |
Case clsObjectLocation.DynamicExistsWhereEnum.InObject, clsObjectLocation.DynamicExistsWhereEnum.OnObject |
| 905 |
If Not bDirectly Then |
| 906 |
Return IsHoldingObject(Adventure.htblObjects(sObKey).Location.Key) |
| 907 |
Else |
| 908 |
Return False |
| 909 |
End If |
| 910 |
End Select |
| 911 |
Return False |
| 912 |
End With |
| 913 |
End Get |
| 914 |
End Property |
| 915 |
|
| 916 |
|
| 917 |
Public ReadOnly Property IsAlone() As Boolean |
| 918 |
Get |
| 919 |
For Each chr As clsCharacter In Adventure.htblCharacters.Values |
| 920 |
If chr.Key <> Key AndAlso chr.Location.LocationKey = Location.LocationKey Then Return False |
| 921 |
Next |
| 922 |
Return True |
| 923 |
End Get |
| 924 |
End Property |
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
Friend ReadOnly Property Children(Optional ByVal bRecursive As Boolean = False) As CharacterHashTable |
| 929 |
Get |
| 930 |
Dim htblChildren As New CharacterHashTable |
| 931 |
|
| 932 |
For Each ch As clsCharacter In Adventure.htblCharacters.Values |
| 933 |
If ch.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.OnCharacter Then |
| 934 |
If ch.Location.Key = Me.Key Then |
| 935 |
htblChildren.Add(ch, ch.Key) |
| 936 |
If bRecursive Then |
| 937 |
For Each chChild As clsCharacter In ch.Children(True).Values |
| 938 |
htblChildren.Add(chChild, chChild.Key) |
| 939 |
Next |
| 940 |
End If |
| 941 |
End If |
| 942 |
End If |
| 943 |
Next |
| 944 |
If bRecursive Then |
| 945 |
For Each ob As clsObject In Adventure.htblObjects.Values |
| 946 |
If ob.IsStatic Then |
| 947 |
Select Case ob.Location.StaticExistWhere |
| 948 |
Case clsObjectLocation.StaticExistsWhereEnum.PartOfCharacter |
| 949 |
If ob.Location.Key = Me.Key Then |
| 950 |
For Each chInOrOnObThatIsPartOfChar As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideOrOnObject).Values |
| 951 |
htblChildren.Add(chInOrOnObThatIsPartOfChar, chInOrOnObThatIsPartOfChar.Key) |
| 952 |
Next |
| 953 |
End If |
| 954 |
End Select |
| 955 |
Else |
| 956 |
Select Case ob.Location.DynamicExistWhere |
| 957 |
Case clsObjectLocation.DynamicExistsWhereEnum.HeldByCharacter, clsObjectLocation.DynamicExistsWhereEnum.WornByCharacter |
| 958 |
If ob.Location.Key = Me.Key Then |
| 959 |
For Each chInOrOnObThatIsHeldWornByChar As clsCharacter In ob.ChildrenCharacters(clsObject.WhereChildrenEnum.InsideOrOnObject).Values |
| 960 |
htblChildren.Add(chInOrOnObThatIsHeldWornByChar, chInOrOnObThatIsHeldWornByChar.Key) |
| 961 |
Next |
| 962 |
End If |
| 963 |
End Select |
| 964 |
End If |
| 965 |
Next |
| 966 |
End If |
| 967 |
|
| 968 |
Return htblChildren |
| 969 |
End Get |
| 970 |
End Property |
| 971 |
|
| 972 |
Friend ReadOnly Property HeldObjects(Optional ByVal bRecursive As Boolean = False) As ObjectHashTable |
| 973 |
Get |
| 974 |
Dim htblHeldObjects As New ObjectHashTable |
| 975 |
|
| 976 |
For Each ob As clsObject In Adventure.DynamicObjects ' Adventure.htblObjects.Values |
| 977 |
If ob.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.HeldByCharacter Then |
| 978 |
If ob.Location.Key = Me.Key OrElse (ob.Location.Key = "%Player%" AndAlso Me.eCharacterType = CharacterTypeEnum.Player) Then |
| 979 |
htblHeldObjects.Add(ob, ob.Key) |
| 980 |
If bRecursive Then |
| 981 |
For Each obChild As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideOrOnObject, True).Values |
| 982 |
htblHeldObjects.Add(obChild, obChild.Key) |
| 983 |
Next |
| 984 |
End If |
| 985 |
End If |
| 986 |
End If |
| 987 |
Next |
| 988 |
|
| 989 |
Return htblHeldObjects |
| 990 |
End Get |
| 991 |
End Property |
| 992 |
|
| 993 |
Friend ReadOnly Property WornObjects(Optional ByVal bRecursive As Boolean = False) As ObjectHashTable |
| 994 |
Get |
| 995 |
Dim htblWornObjects As New ObjectHashTable |
| 996 |
|
| 997 |
For Each ob As clsObject In Adventure.htblObjects.Values |
| 998 |
If ob.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.WornByCharacter Then |
| 999 |
If ob.Location.Key = Me.Key OrElse (ob.Location.Key = "%Player%" AndAlso Me.eCharacterType = CharacterTypeEnum.Player) Then |
| 1000 |
htblWornObjects.Add(ob, ob.Key) |
| 1001 |
If bRecursive Then |
| 1002 |
For Each obChild As clsObject In ob.Children(clsObject.WhereChildrenEnum.InsideOrOnObject, True).Values |
| 1003 |
htblWornObjects.Add(obChild, obChild.Key) |
| 1004 |
Next |
| 1005 |
End If |
| 1006 |
End If |
| 1007 |
End If |
| 1008 |
Next |
| 1009 |
|
| 1010 |
Return htblWornObjects |
| 1011 |
End Get |
| 1012 |
End Property |
| 1013 |
|
| 1014 |
Public Function ListExits(Optional ByVal sFromLocation As String = "", Optional ByRef iExitCount As Integer = 0) As String |
| 1015 |
Dim sExits As String = "" |
| 1016 |
|
| 1017 |
If sFromLocation = "" Then sFromLocation = Adventure.Player.Location.LocationKey |
| 1018 |
For d As DirectionsEnum = DirectionsEnum.North To DirectionsEnum.NorthWest ' Adventure.iCompassPoints |
| 1019 |
If Me.HasRouteInDirection(d, False, sFromLocation) Then |
| 1020 |
sExits &= DirectionName(d) & ", " |
| 1021 |
iExitCount += 1 |
| 1022 |
End If |
| 1023 |
Next |
| 1024 |
|
| 1025 |
If Right(sExits, 2) = ", " Then sExits = Left(sExits, sExits.Length - 2) & "" |
| 1026 |
|
| 1027 |
If iExitCount > 1 Then |
| 1028 |
sExits = Left(sExits, sExits.LastIndexOf(", ")) & " and " & Right(sExits, sExits.Length - sExits.LastIndexOf(", ") - 2) |
| 1029 |
End If |
| 1030 |
|
| 1031 |
If sExits = "" Then sExits = "nowhere" |
| 1032 |
|
| 1033 |
Return LCase(sExits) |
| 1034 |
End Function |
| 1035 |
|
| 1036 |
Friend Overrides ReadOnly Property AllDescriptions() As Generic.List(Of SharedModule.Description) |
| 1037 |
Get |
| 1038 |
Dim all As New Generic.List(Of Description) |
| 1039 |
all.Add(oDescription) |
| 1040 |
For Each p As clsProperty In htblProperties.Values |
| 1041 |
all.Add(p.StringData) |
| 1042 |
Next |
| 1043 |
For Each t As clsTopic In htblTopics.Values |
| 1044 |
For Each r As clsRestriction In t.arlRestrictions |
| 1045 |
all.Add(r.oMessage) |
| 1046 |
Next |
| 1047 |
all.Add(t.oConversation) |
| 1048 |
Next |
| 1049 |
For Each w As clsWalk In arlWalks |
| 1050 |
For i As Integer = 0 To w.SubWalks.Length - 1 |
| 1051 |
all.Add(w.SubWalks(i).oDescription) |
| 1052 |
Next |
| 1053 |
Next |
| 1054 |
Return all |
| 1055 |
End Get |
| 1056 |
End Property |
| 1057 |
|
| 1058 |
Protected Overrides ReadOnly Property PropertyGroupType() As clsGroup.GroupTypeEnum |
| 1059 |
Get |
| 1060 |
Return clsGroup.GroupTypeEnum.Characters |
| 1061 |
End Get |
| 1062 |
End Property |
| 1063 |
|
| 1064 |
|
| 1065 |
Public Overrides Function ReferencesKey(ByVal sKey As String) As Integer |
| 1066 |
|
| 1067 |
Dim iCount As Integer = 0 |
| 1068 |
For Each d As Description In AllDescriptions |
| 1069 |
iCount += d.ReferencesKey(sKey) |
| 1070 |
Next |
| 1071 |
For Each w As clsWalk In arlWalks |
| 1072 |
For Each s As clsWalk.clsStep In w.arlSteps |
| 1073 |
If s.sLocation = sKey Then iCount += 1 |
| 1074 |
Next |
| 1075 |
For i As Integer = 0 To w.SubWalks.Length - 1 |
| 1076 |
With w.SubWalks(i) |
| 1077 |
If .sKey2 = sKey OrElse .sKey3 = sKey Then iCount += 1 |
| 1078 |
End With |
| 1079 |
Next |
| 1080 |
For i As Integer = 0 To w.WalkControls.Length - 1 |
| 1081 |
With w.WalkControls(i) |
| 1082 |
If .sTaskKey = sKey Then iCount += 1 |
| 1083 |
End With |
| 1084 |
Next |
| 1085 |
Next |
| 1086 |
For Each t As clsTopic In htblTopics.Values |
| 1087 |
iCount += t.arlRestrictions.ReferencesKey(sKey) |
| 1088 |
iCount += t.arlActions.ReferencesKey(sKey) |
| 1089 |
Next |
| 1090 |
If Location.Key = sKey Then iCount += 1 |
| 1091 |
iCount += htblActualProperties.ReferencesKey(sKey) |
| 1092 |
|
| 1093 |
Return iCount |
| 1094 |
|
| 1095 |
End Function |
| 1096 |
|
| 1097 |
|
| 1098 |
Public Overrides Function DeleteKey(ByVal sKey As String) As Boolean |
| 1099 |
|
| 1100 |
For Each d As Description In AllDescriptions |
| 1101 |
If Not d.DeleteKey(sKey) Then Return False |
| 1102 |
Next |
| 1103 |
For Each w As clsWalk In arlWalks |
| 1104 |
For i As Integer = w.arlSteps.Count - 1 To 0 Step -1 |
| 1105 |
If CType(w.arlSteps(i), clsWalk.clsStep).sLocation = sKey Then w.arlSteps.RemoveAt(i) |
| 1106 |
Next |
| 1107 |
For i As Integer = 0 To w.SubWalks.Length - 1 |
| 1108 |
If w.SubWalks(i).sKey2 = sKey Then w.SubWalks(i).sKey2 = "" |
| 1109 |
If w.SubWalks(i).sKey3 = sKey Then w.SubWalks(i).sKey3 = "" |
| 1110 |
Next |
| 1111 |
For i As Integer = 0 To w.WalkControls.Length - 1 |
| 1112 |
If w.WalkControls(i).sTaskKey = sKey Then |
| 1113 |
For j As Integer = w.WalkControls.Length - 2 To i Step -1 |
| 1114 |
w.WalkControls(j) = w.WalkControls(j + 1) |
| 1115 |
Next |
| 1116 |
ReDim Preserve w.WalkControls(w.WalkControls.Length - 2) |
| 1117 |
End If |
| 1118 |
Next |
| 1119 |
Next |
| 1120 |
For Each t As clsTopic In htblTopics.Values |
| 1121 |
If Not t.arlRestrictions.DeleteKey(sKey) Then Return False |
| 1122 |
If Not t.arlActions.DeleteKey(sKey) Then Return False |
| 1123 |
Next |
| 1124 |
If Location.Key = sKey Then |
| 1125 |
Location.Key = "" |
| 1126 |
Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.Hidden |
| 1127 |
End If |
| 1128 |
If Not htblActualProperties.DeleteKey(sKey) Then Return False |
| 1129 |
|
| 1130 |
Return True |
| 1131 |
|
| 1132 |
End Function |
| 1133 |
|
| 1134 |
|
| 1135 |
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 |
| 1136 |
Dim iCount As Integer = iReplacements |
| 1137 |
iReplacements += MyBase.FindStringInStringProperty(Me.sName, sSearchString, sReplace, bFindAll) |
| 1138 |
iReplacements += MyBase.FindStringInStringProperty(Me.sArticle, sSearchString, sReplace, bFindAll) |
| 1139 |
For i As Integer = arlDescriptors.Count - 1 To 0 Step -1 |
| 1140 |
iReplacements += MyBase.FindStringInStringProperty(Me.arlDescriptors(i), sSearchString, sReplace, bFindAll) |
| 1141 |
Next |
| 1142 |
Return iReplacements - iCount |
| 1143 |
End Function |
| 1144 |
|
| 1145 |
End Class |
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
<DebuggerDisplay("{Summary} : {Keywords}")> |
| 1150 |
Public Class clsTopic |
| 1151 |
|
| 1152 |
Public Key As String |
| 1153 |
Public ParentKey As String |
| 1154 |
Public Summary As String |
| 1155 |
Public Keywords As String |
| 1156 |
Public bIntroduction, bAsk, bTell, bCommand, bFarewell, bStayInNode As Boolean |
| 1157 |
Friend oConversation As Description |
| 1158 |
Friend arlRestrictions As New RestrictionArrayList |
| 1159 |
Friend arlActions As New ActionArrayList |
| 1160 |
|
| 1161 |
Public Sub New() |
| 1162 |
oConversation = New Description |
| 1163 |
End Sub |
| 1164 |
|
| 1165 |
Public Function Clone() As clsTopic |
| 1166 |
Dim topic As clsTopic = CType(Me.MemberwiseClone, clsTopic) |
| 1167 |
topic.arlRestrictions = topic.arlRestrictions.Copy |
| 1168 |
topic.arlActions = topic.arlActions.Copy |
| 1169 |
Return topic |
| 1170 |
End Function |
| 1171 |
|
| 1172 |
End Class |
| 1173 |
|
| 1174 |
|
| 1175 |
Public Class clsWalk |
| 1176 |
|
| 1177 |
Public Class clsStep |
| 1178 |
Public sLocation As String |
| 1179 |
Friend ftTurns As New FromTo |
| 1180 |
End Class |
| 1181 |
|
| 1182 |
Private sDescription As String |
| 1183 |
Private bLoop As Boolean |
| 1184 |
Private sFromDesc As String |
| 1185 |
Private sToDesc As String |
| 1186 |
Private bShowMove As Boolean |
| 1187 |
Private bStartActive As Boolean |
| 1188 |
Friend iTimerToEndOfWalk As Integer |
| 1189 |
Private iLastSubWalkTime As Integer = 0 |
| 1190 |
|
| 1191 |
Public sKey As String ' This is the key of the character |
| 1192 |
|
| 1193 |
Private Enum Command |
| 1194 |
[Nothing] = 0 |
| 1195 |
Start = 1 |
| 1196 |
[Stop] = 2 |
| 1197 |
Pause = 3 |
| 1198 |
[Resume] = 4 |
| 1199 |
Restart = 5 |
| 1200 |
End Enum |
| 1201 |
Private NextCommand As Command = Command.Nothing |
| 1202 |
|
| 1203 |
Public Enum StatusEnum |
| 1204 |
NotYetStarted = 0 |
| 1205 |
Running = 1 |
| 1206 |
Paused = 3 |
| 1207 |
Finished = 4 |
| 1208 |
End Enum |
| 1209 |
Friend Status As StatusEnum |
| 1210 |
|
| 1211 |
|
| 1212 |
Public Class SubWalk |
| 1213 |
Implements ICloneable |
| 1214 |
|
| 1215 |
Public Enum WhenEnum |
| 1216 |
FromLastSubWalk |
| 1217 |
FromStartOfWalk |
| 1218 |
BeforeEndOfWalk |
| 1219 |
ComesAcross |
| 1220 |
End Enum |
| 1221 |
Public eWhen As WhenEnum |
| 1222 |
|
| 1223 |
Public Enum WhatEnum |
| 1224 |
DisplayMessage |
| 1225 |
ExecuteTask |
| 1226 |
UnsetTask |
| 1227 |
End Enum |
| 1228 |
Public eWhat As WhatEnum |
| 1229 |
|
| 1230 |
Friend ftTurns As New FromTo |
| 1231 |
Friend oDescription As New Description |
| 1232 |
Public sKey As String |
| 1233 |
Public sKey2 As String |
| 1234 |
Public sKey3 As String |
| 1235 |
|
| 1236 |
Friend bSameLocationAsChar As Boolean = False |
| 1237 |
|
| 1238 |
Private Function Clone() As Object Implements System.ICloneable.Clone |
| 1239 |
Dim se As SubWalk |
| 1240 |
se = CType(Me.MemberwiseClone, SubWalk) |
| 1241 |
se.ftTurns = ftTurns.CloneMe |
| 1242 |
se.oDescription = oDescription.Copy |
| 1243 |
Return se |
| 1244 |
End Function |
| 1245 |
Public Function CloneMe() As SubWalk |
| 1246 |
Return CType(Me.Clone, SubWalk) |
| 1247 |
End Function |
| 1248 |
|
| 1249 |
End Class |
| 1250 |
Public SubWalks() As SubWalk = {} |
| 1251 |
|
| 1252 |
Public arlSteps As New ArrayList |
| 1253 |
|
| 1254 |
Friend WalkControls() As EventOrWalkControl = {} |
| 1255 |
|
| 1256 |
Public Property Description() As String |
| 1257 |
Get |
| 1258 |
Return sDescription |
| 1259 |
End Get |
| 1260 |
Set(ByVal value As String) |
| 1261 |
sDescription = value |
| 1262 |
End Set |
| 1263 |
End Property |
| 1264 |
|
| 1265 |
Public Property Loops() As Boolean |
| 1266 |
Get |
| 1267 |
Return bLoop |
| 1268 |
End Get |
| 1269 |
Set(ByVal Value As Boolean) |
| 1270 |
bLoop = Value |
| 1271 |
End Set |
| 1272 |
End Property |
| 1273 |
|
| 1274 |
Public Property StartActive() As Boolean |
| 1275 |
Get |
| 1276 |
Return bStartActive |
| 1277 |
End Get |
| 1278 |
Set(ByVal value As Boolean) |
| 1279 |
bStartActive = value |
| 1280 |
End Set |
| 1281 |
End Property |
| 1282 |
|
| 1283 |
|
| 1284 |
Public Function GetDefaultDescription() As String |
| 1285 |
Dim sb As New System.Text.StringBuilder |
| 1286 |
|
| 1287 |
For Each stp As clsStep In arlSteps |
| 1288 |
Select Case stp.sLocation |
| 1289 |
Case "Hidden" |
| 1290 |
sb.Append("Hidden") |
| 1291 |
Case Else |
| 1292 |
Dim sDescription As String = Adventure.GetNameFromKey(stp.sLocation) |
| 1293 |
If Adventure.htblCharacters.ContainsKey(stp.sLocation) Then sDescription = "Follow " & sDescription |
| 1294 |
If sDescription <> "" Then |
| 1295 |
sb.Append(sDescription) |
| 1296 |
Else |
| 1297 |
sb.Append("<" & stp.sLocation & ">") ' Groups may not be defined yet |
| 1298 |
End If |
| 1299 |
End Select |
| 1300 |
If stp.ftTurns.iFrom = stp.ftTurns.iTo Then |
| 1301 |
sb.Append(" [" & stp.ftTurns.iFrom & "]") |
| 1302 |
Else |
| 1303 |
sb.Append(" [" & stp.ftTurns.iFrom & " - " & stp.ftTurns.iTo & "]") |
| 1304 |
End If |
| 1305 |
|
| 1306 |
If stp IsNot arlSteps(arlSteps.Count - 1) Then sb.Append(" -> ") |
| 1307 |
Next |
| 1308 |
If bLoop Then sb.Append(" {L}") |
| 1309 |
|
| 1310 |
If sb.ToString = "" Then sb.Append("Unnamed walk") |
| 1311 |
|
| 1312 |
Return sb.ToString |
| 1313 |
|
| 1314 |
End Function |
| 1315 |
|
| 1316 |
Private Sub ResetLength() |
| 1317 |
For Each [step] As clsWalk.clsStep In Me.arlSteps |
| 1318 |
[step].ftTurns.Reset() |
| 1319 |
Next |
| 1320 |
End Sub |
| 1321 |
Private ReadOnly Property Length() As Integer |
| 1322 |
Get |
| 1323 |
Dim iLength As Integer = 0 |
| 1324 |
For Each [step] As clsWalk.clsStep In Me.arlSteps |
| 1325 |
iLength += [step].ftTurns.Value |
| 1326 |
Next |
| 1327 |
Return iLength |
| 1328 |
End Get |
| 1329 |
End Property |
| 1330 |
|
| 1331 |
|
| 1332 |
Public Property TimerToEndOfWalk() As Integer |
| 1333 |
Get |
| 1334 |
Return iTimerToEndOfWalk |
| 1335 |
End Get |
| 1336 |
Set(ByVal value As Integer) |
| 1337 |
Dim iStartValue As Integer = iTimerToEndOfWalk |
| 1338 |
iTimerToEndOfWalk = value |
| 1339 |
|
| 1340 |
' If we've reached the end of the timer |
| 1341 |
If Status = StatusEnum.Running AndAlso iTimerToEndOfWalk = 0 Then |
| 1342 |
lStop(True, True) |
| 1343 |
End If |
| 1344 |
|
| 1345 |
End Set |
| 1346 |
End Property |
| 1347 |
|
| 1348 |
Private LastSubWalk As SubWalk |
| 1349 |
Private ReadOnly Property TimerFromLastSubWalk() As Integer |
| 1350 |
Get |
| 1351 |
Return TimerFromStartOfWalk - iLastSubWalkTime |
| 1352 |
End Get |
| 1353 |
End Property |
| 1354 |
Private ReadOnly Property TimerFromStartOfWalk() As Integer |
| 1355 |
Get |
| 1356 |
Return Length - TimerToEndOfWalk '+ 1 |
| 1357 |
End Get |
| 1358 |
End Property |
| 1359 |
|
| 1360 |
|
| 1361 |
Public bJustStarted As Boolean = False |
| 1362 |
Public Sub Start(Optional ByVal bForce As Boolean = False) |
| 1363 |
If bForce Then |
| 1364 |
lStart() |
| 1365 |
Else |
| 1366 |
If NextCommand = Command.Stop Then |
| 1367 |
NextCommand = Command.Restart |
| 1368 |
Else |
| 1369 |
NextCommand = Command.Start |
| 1370 |
End If |
| 1371 |
End If |
| 1372 |
End Sub |
| 1373 |
Public Sub lStart(Optional ByVal bRestart As Boolean = False) |
| 1374 |
If Status = StatusEnum.NotYetStarted OrElse Status = StatusEnum.Finished OrElse (Status = StatusEnum.Running AndAlso bRestart) Then |
| 1375 |
If Not bRestart Then UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Low, "Starting walk " & Description) |
| 1376 |
Status = StatusEnum.Running |
| 1377 |
ResetLength() |
| 1378 |
TimerToEndOfWalk = Length |
| 1379 |
|
| 1380 |
If TimerFromStartOfWalk = 0 Then |
| 1381 |
DoAnySteps() |
| 1382 |
DoAnySubWalks() ' To run 'after 0 turns' subevents |
| 1383 |
End If |
| 1384 |
|
| 1385 |
bJustStarted = True |
| 1386 |
Else |
| 1387 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Error, "Can't Start a Walk that isn't waiting!") |
| 1388 |
End If |
| 1389 |
End Sub |
| 1390 |
|
| 1391 |
|
| 1392 |
Public Sub Pause() |
| 1393 |
NextCommand = Command.Pause |
| 1394 |
End Sub |
| 1395 |
Public Sub lPause() |
| 1396 |
If Status = StatusEnum.Running Then |
| 1397 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Low, "Pausing walk " & Description) |
| 1398 |
Status = StatusEnum.Paused |
| 1399 |
Else |
| 1400 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Error, "Can't Pause a Walk that isn't running!") |
| 1401 |
End If |
| 1402 |
End Sub |
| 1403 |
|
| 1404 |
|
| 1405 |
Public sTriggeringTask As String |
| 1406 |
|
| 1407 |
Public Sub [Resume]() |
| 1408 |
NextCommand = Command.Resume |
| 1409 |
End Sub |
| 1410 |
Public Sub lResume() |
| 1411 |
If Status = StatusEnum.Paused Then |
| 1412 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Low, "Resuming walk " & Description) |
| 1413 |
Status = StatusEnum.Running |
| 1414 |
Else |
| 1415 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Error, "Can't Resume a Walk that isn't paused!") |
| 1416 |
End If |
| 1417 |
End Sub |
| 1418 |
|
| 1419 |
|
| 1420 |
Public Sub [Stop]() |
| 1421 |
NextCommand = Command.Stop |
| 1422 |
End Sub |
| 1423 |
Public Sub lStop(Optional ByVal bRunSubEvents As Boolean = False, Optional ByVal bReachedEnd As Boolean = False) |
| 1424 |
|
| 1425 |
If bRunSubEvents Then DoAnySubWalks() |
| 1426 |
Status = StatusEnum.Finished |
| 1427 |
If Me.bLoop AndAlso TimerToEndOfWalk = 0 AndAlso bReachedEnd Then |
| 1428 |
If Length > 0 Then ' Only restart if walk comes to and end and it is set to loop - not if it is terminated by task change |
| 1429 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Low, "Restarting walk " & Description) |
| 1430 |
lStart(True) |
| 1431 |
Else |
| 1432 |
UserSession.DebugPrint(ItemEnum.Event, sKey, DebugDetailLevelEnum.Low, "Not restarting walk " & Description & " otherwise we'd get in an infinite loop as zero length.") |
| 1433 |
End If |
| 1434 |
Else |
| 1435 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Low, "Finishing walk " & Description) |
| 1436 |
End If |
| 1437 |
|
| 1438 |
End Sub |
| 1439 |
|
| 1440 |
|
| 1441 |
Public Sub IncrementTimer() |
| 1442 |
If NextCommand <> Command.Nothing Then |
| 1443 |
Select Case NextCommand |
| 1444 |
Case Command.Start |
| 1445 |
lStart() |
| 1446 |
Case Command.Stop |
| 1447 |
lStop() |
| 1448 |
Case Command.Pause |
| 1449 |
lPause() |
| 1450 |
Case Command.Resume |
| 1451 |
lResume() |
| 1452 |
Case Command.Restart |
| 1453 |
lStart(True) |
| 1454 |
End Select |
| 1455 |
NextCommand = Command.Nothing |
| 1456 |
sTriggeringTask = "" |
| 1457 |
End If |
| 1458 |
|
| 1459 |
If Status = StatusEnum.Running Then UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.High, "Walk " & Description & " [" & TimerFromStartOfWalk + 1 & "/" & Length & "]") |
| 1460 |
|
| 1461 |
' Split this into 2 case statements, as changing timer here may change status |
| 1462 |
Select Case Status |
| 1463 |
Case StatusEnum.NotYetStarted |
| 1464 |
Case StatusEnum.Running |
| 1465 |
If Not bJustStarted Then TimerToEndOfWalk -= 1 |
| 1466 |
Case StatusEnum.Paused |
| 1467 |
Case StatusEnum.Finished |
| 1468 |
End Select |
| 1469 |
|
| 1470 |
If Not bJustStarted Then |
| 1471 |
DoAnySteps() |
| 1472 |
DoAnySubWalks() |
| 1473 |
End If |
| 1474 |
|
| 1475 |
bJustStarted = False |
| 1476 |
|
| 1477 |
End Sub |
| 1478 |
|
| 1479 |
|
| 1480 |
Public Sub DoAnySteps() |
| 1481 |
If Status = StatusEnum.Running Then |
| 1482 |
Dim iStepLength As Integer = 0 |
| 1483 |
For Each [step] As clsStep In arlSteps |
| 1484 |
If iStepLength = TimerFromStartOfWalk Then |
| 1485 |
Dim sDestination As String = "" |
| 1486 |
Dim sDestKey As String = [step].sLocation |
| 1487 |
If sDestKey = THEPLAYER Then sDestKey = Adventure.Player.Key |
| 1488 |
If Adventure.htblGroups.ContainsKey(sDestKey) Then |
| 1489 |
' Get an adjacent location in the group |
| 1490 |
Dim grp As clsGroup = Adventure.htblGroups(sDestKey) |
| 1491 |
Dim ch As clsCharacter = Adventure.htblCharacters(sKey) |
| 1492 |
Dim locCurrent As clsLocation = Nothing |
| 1493 |
If ch.Location.ExistWhere <> clsCharacterLocation.ExistsWhereEnum.Hidden Then locCurrent = Adventure.htblLocations(ch.Location.LocationKey) |
| 1494 |
Dim bHasAdjacent As Boolean = False |
| 1495 |
If locCurrent IsNot Nothing Then |
| 1496 |
For Each sLoc As String In grp.arlMembers |
| 1497 |
If locCurrent.IsAdjacent(sLoc) Then |
| 1498 |
bHasAdjacent = True |
| 1499 |
Exit For |
| 1500 |
End If |
| 1501 |
Next |
| 1502 |
End If |
| 1503 |
If bHasAdjacent Then |
| 1504 |
While sDestination = "" |
| 1505 |
Dim sPossibleDest As String = grp.arlMembers(Random(grp.arlMembers.Count - 1)) |
| 1506 |
If ch.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.Hidden OrElse locCurrent.IsAdjacent(sPossibleDest) Then sDestination = sPossibleDest |
| 1507 |
End While |
| 1508 |
Else |
| 1509 |
' No adjacent room, so just move to a random room in the group |
| 1510 |
sDestination = grp.arlMembers(Random(grp.arlMembers.Count - 1)) |
| 1511 |
End If |
| 1512 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Medium, "Character " & Adventure.htblCharacters(sKey).ProperName & " walks to " & Adventure.GetNameFromKey(sDestKey) & " (" & Adventure.htblLocations(sDestination).ShortDescription.ToString & ")") |
| 1513 |
ElseIf Adventure.htblCharacters.ContainsKey(sDestKey) Then |
| 1514 |
' Only move towards the character if they are in an adjacent room |
| 1515 |
Dim ch As clsCharacter = Adventure.htblCharacters(sKey) |
| 1516 |
Dim ch2 As clsCharacter = Adventure.htblCharacters(sDestKey) |
| 1517 |
|
| 1518 |
If ch.Location.LocationKey <> ch2.Location.LocationKey Then |
| 1519 |
Dim locCurrent As clsLocation = Nothing |
| 1520 |
If ch.Location.ExistWhere <> clsCharacterLocation.ExistsWhereEnum.Hidden Then locCurrent = Adventure.htblLocations(ch.Location.LocationKey) |
| 1521 |
If locCurrent IsNot Nothing AndAlso locCurrent.IsAdjacent(ch2.Location.Key) Then |
| 1522 |
sDestination = ch2.Location.Key |
| 1523 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Medium, "Character " & Adventure.htblCharacters(sKey).ProperName & " walks to " & ch2.ProperName & " (" & Adventure.htblLocations(sDestination).ShortDescription.ToString & ")") |
| 1524 |
Else |
| 1525 |
' Character is not adjacent, so don't move |
| 1526 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Error, "Character " & Adventure.htblCharacters(sKey).ProperName & " can't walk to " & ch2.ProperName & " as " & ch2.Gender.ToString.Replace("Male", "he").Replace("Female", "she").Replace("Unknown", "it") & " is not in an adjacent location.") |
| 1527 |
sDestination = "" |
| 1528 |
End If |
| 1529 |
End If |
| 1530 |
Else |
| 1531 |
sDestination = sDestKey |
| 1532 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Medium, "Character " & Adventure.htblCharacters(sKey).ProperName & " walks to " & Adventure.GetNameFromKey(sDestination)) |
| 1533 |
End If |
| 1534 |
|
| 1535 |
If sDestination = HIDDEN OrElse Adventure.htblLocations.ContainsKey(sDestination) Then |
| 1536 |
With Adventure.htblCharacters(sKey) |
| 1537 |
If .HasProperty("ShowEnterExit") AndAlso .Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.AtLocation Then |
| 1538 |
If .Location.Key = Adventure.Player.Location.LocationKey Then |
| 1539 |
Dim sExits As String = "exits" |
| 1540 |
If .HasProperty("CharExits") Then sExits = .GetPropertyValue("CharExits") '.StringData.ToString |
| 1541 |
Dim sLeaves As String = ToProper(.Name, False) & " " & sExits ' to the North... etc |
| 1542 |
If Adventure.htblLocations(Adventure.Player.Location.LocationKey).IsAdjacent(sDestination) Then |
| 1543 |
Dim sTheDirection As String = Adventure.htblLocations(.Location.LocationKey).DirectionTo(sDestination) |
| 1544 |
If sTheDirection <> "nowhere" Then |
| 1545 |
Select Case sTheDirection |
| 1546 |
Case "outside", "inside" |
| 1547 |
sLeaves &= " " |
| 1548 |
Case Else |
| 1549 |
sLeaves &= " to " |
| 1550 |
End Select |
| 1551 |
sLeaves &= sTheDirection |
| 1552 |
End If |
| 1553 |
End If |
| 1554 |
sLeaves &= "." |
| 1555 |
UserSession.Display(sLeaves) |
| 1556 |
ElseIf sDestination = Adventure.Player.Location.LocationKey Then |
| 1557 |
Dim sEnters As String = "enters" |
| 1558 |
If .HasProperty("CharEnters") Then sEnters = .GetPropertyValue("CharEnters") '.StringData.ToString |
| 1559 |
Dim sArrives As String = ToProper(.Name, False) & " " & sEnters ' from the North... etc |
| 1560 |
If Adventure.htblLocations(Adventure.Player.Location.LocationKey).IsAdjacent(.Location.Key) Then |
| 1561 |
Dim sTheDirection As String = Adventure.htblLocations(sDestination).DirectionTo(.Location.LocationKey) |
| 1562 |
If sTheDirection <> "nowhere" Then sArrives &= " from " & sTheDirection |
| 1563 |
End If |
| 1564 |
sArrives &= "." |
| 1565 |
UserSession.Display(sArrives) |
| 1566 |
End If |
| 1567 |
End If |
| 1568 |
|
| 1569 |
.Move(sDestination) |
| 1570 |
End With |
| 1571 |
End If |
| 1572 |
End If |
| 1573 |
iStepLength += [step].ftTurns.Value |
| 1574 |
Next |
| 1575 |
End If |
| 1576 |
|
| 1577 |
End Sub |
| 1578 |
|
| 1579 |
|
| 1580 |
Public Sub DoAnySubWalks() |
| 1581 |
|
| 1582 |
Select Case Status |
| 1583 |
Case StatusEnum.Running |
| 1584 |
' Check all the subevents to see if we need to do anything |
| 1585 |
Dim iIndex As Integer = 0 |
| 1586 |
For Each sw As SubWalk In SubWalks |
| 1587 |
Dim bRunSubWalk As Boolean = False |
| 1588 |
Select Case sw.eWhen |
| 1589 |
Case SubWalk.WhenEnum.FromStartOfWalk |
| 1590 |
If TimerFromStartOfWalk = sw.ftTurns.Value AndAlso sw.ftTurns.Value <= Length Then bRunSubWalk = True |
| 1591 |
Case SubWalk.WhenEnum.FromLastSubWalk |
| 1592 |
If TimerFromLastSubWalk = sw.ftTurns.Value Then |
| 1593 |
If (LastSubWalk Is Nothing AndAlso iIndex = 0) OrElse (iIndex > 0 AndAlso LastSubWalk Is SubWalks(iIndex - 1)) Then bRunSubWalk = True |
| 1594 |
End If |
| 1595 |
Case SubWalk.WhenEnum.BeforeEndOfWalk |
| 1596 |
If TimerToEndOfWalk = sw.ftTurns.Value Then bRunSubWalk = True |
| 1597 |
Case SubWalk.WhenEnum.ComesAcross |
| 1598 |
Dim bPrevSameLocationAsChar As Boolean = sw.bSameLocationAsChar |
| 1599 |
sw.bSameLocationAsChar = (Adventure.htblCharacters(sKey).Location.LocationKey = Adventure.Player.Location.LocationKey) |
| 1600 |
|
| 1601 |
If Not bPrevSameLocationAsChar AndAlso sw.bSameLocationAsChar Then |
| 1602 |
bRunSubWalk = True |
| 1603 |
End If |
| 1604 |
End Select |
| 1605 |
|
| 1606 |
If bRunSubWalk Then |
| 1607 |
Select Case sw.eWhat |
| 1608 |
Case SubWalk.WhatEnum.DisplayMessage |
| 1609 |
If sw.sKey3 <> "" AndAlso Adventure.Player.IsInGroupOrLocation(sw.sKey3) Then UserSession.Display(sw.oDescription.ToString) |
| 1610 |
Case SubWalk.WhatEnum.ExecuteTask |
| 1611 |
If Adventure.htblTasks.ContainsKey(sw.sKey2) Then |
| 1612 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Medium, "Walk '" & Description & "' attempting to execute task '" & Adventure.htblTasks(sw.sKey2).Description & "'") |
| 1613 |
UserSession.AttemptToExecuteTask(sw.sKey2, True) |
| 1614 |
End If |
| 1615 |
Case SubWalk.WhatEnum.UnsetTask |
| 1616 |
UserSession.DebugPrint(ItemEnum.Character, sKey, DebugDetailLevelEnum.Medium, "Walk '" & Description & "' unsetting task '" & Adventure.htblTasks(sw.sKey2).Description & "'") |
| 1617 |
Adventure.htblTasks(sw.sKey2).Completed = False |
| 1618 |
End Select |
| 1619 |
iLastSubWalkTime = TimerFromStartOfWalk |
| 1620 |
LastSubWalk = sw |
| 1621 |
End If |
| 1622 |
iIndex += 1 |
| 1623 |
Next |
| 1624 |
End Select |
| 1625 |
|
| 1626 |
End Sub |
| 1627 |
|
| 1628 |
End Class |
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
Public Class clsCharacterLocation |
| 1633 |
|
| 1634 |
Private Parent As clsCharacter |
| 1635 |
Public Sub New(ByVal Parent As clsCharacter) |
| 1636 |
If Parent IsNot Nothing AndAlso Parent.Location IsNot Nothing Then sLastLocationKey = Parent.Location.sLastLocationKey |
| 1637 |
Me.Parent = Parent |
| 1638 |
End Sub |
| 1639 |
|
| 1640 |
Public Enum ExistsWhereEnum |
| 1641 |
Uninitialised |
| 1642 |
Hidden |
| 1643 |
AtLocation |
| 1644 |
OnObject |
| 1645 |
InObject |
| 1646 |
OnCharacter |
| 1647 |
End Enum |
| 1648 |
|
| 1649 |
Private eExistsWhere As ExistsWhereEnum = ExistsWhereEnum.Uninitialised |
| 1650 |
Public Property ExistWhere() As ExistsWhereEnum |
| 1651 |
Get |
| 1652 |
If eExistsWhere = ExistsWhereEnum.Uninitialised Then |
| 1653 |
If Parent.HasProperty("CharacterLocation") Then |
| 1654 |
Select Case Parent.GetPropertyValue("CharacterLocation") |
| 1655 |
Case "At Location" |
| 1656 |
eExistsWhere = ExistsWhereEnum.AtLocation |
| 1657 |
Case "Hidden" |
| 1658 |
eExistsWhere = ExistsWhereEnum.Hidden |
| 1659 |
Case "In Object" |
| 1660 |
eExistsWhere = ExistsWhereEnum.InObject |
| 1661 |
Case "On Character" |
| 1662 |
eExistsWhere = ExistsWhereEnum.OnCharacter |
| 1663 |
Case "On Object" |
| 1664 |
eExistsWhere = ExistsWhereEnum.OnObject |
| 1665 |
Case Else |
| 1666 |
' Hmmm.... |
| 1667 |
End Select |
| 1668 |
Else |
| 1669 |
eExistsWhere = ExistsWhereEnum.Hidden |
| 1670 |
End If |
| 1671 |
End If |
| 1672 |
Return eExistsWhere |
| 1673 |
End Get |
| 1674 |
Set(ByVal value As ExistsWhereEnum) |
| 1675 |
If value <> eExistsWhere Then |
| 1676 |
Dim p As clsProperty |
| 1677 |
|
| 1678 |
If Not Parent.HasProperty("CharacterLocation") Then |
| 1679 |
p = Adventure.htblAllProperties("CharacterLocation").Copy |
| 1680 |
p.Selected = True |
| 1681 |
Parent.AddProperty(p) |
| 1682 |
End If |
| 1683 |
|
| 1684 |
Dim sNewLocation As String = "" |
| 1685 |
Select Case value |
| 1686 |
Case ExistsWhereEnum.AtLocation |
| 1687 |
sNewLocation = "At Location" |
| 1688 |
Case ExistsWhereEnum.Hidden |
| 1689 |
sNewLocation = "Hidden" |
| 1690 |
Case ExistsWhereEnum.InObject |
| 1691 |
sNewLocation = "In Object" |
| 1692 |
Case ExistsWhereEnum.OnCharacter |
| 1693 |
sNewLocation = "On Character" |
| 1694 |
Case ExistsWhereEnum.OnObject |
| 1695 |
sNewLocation = "On Object" |
| 1696 |
End Select |
| 1697 |
Parent.SetPropertyValue("CharacterLocation", sNewLocation) |
| 1698 |
|
| 1699 |
For Each sProp As String In New String() {"CharacterAtLocation", "CharInsideWhat", "CharOnWhat", "CharOnWho"} |
| 1700 |
If Parent.HasProperty(sProp) Then Parent.RemoveProperty(sProp) |
| 1701 |
Next |
| 1702 |
|
| 1703 |
If value <> ExistsWhereEnum.Hidden Then |
| 1704 |
Dim sNewProp As String = "" |
| 1705 |
Select Case value |
| 1706 |
Case ExistsWhereEnum.AtLocation |
| 1707 |
sNewProp = "CharacterAtLocation" |
| 1708 |
Case ExistsWhereEnum.InObject |
| 1709 |
sNewProp = "CharInsideWhat" |
| 1710 |
Case ExistsWhereEnum.OnCharacter |
| 1711 |
sNewProp = "CharOnWho" |
| 1712 |
Case ExistsWhereEnum.OnObject |
| 1713 |
sNewProp = "CharOnWhat" |
| 1714 |
End Select |
| 1715 |
If Not Parent.HasProperty(sNewProp) AndAlso Adventure.htblAllProperties.ContainsKey(sNewProp) Then |
| 1716 |
p = Adventure.htblAllProperties(sNewProp).Copy |
| 1717 |
p.Selected = True |
| 1718 |
Parent.AddProperty(p) |
| 1719 |
End If |
| 1720 |
End If |
| 1721 |
|
| 1722 |
eExistsWhere = value |
| 1723 |
End If |
| 1724 |
End Set |
| 1725 |
End Property |
| 1726 |
|
| 1727 |
Public Enum PositionEnum |
| 1728 |
Uninitialised |
| 1729 |
Standing |
| 1730 |
Sitting |
| 1731 |
Lying |
| 1732 |
End Enum |
| 1733 |
Private ePosition As PositionEnum = PositionEnum.Uninitialised |
| 1734 |
|
| 1735 |
Private sKey As String = Nothing |
| 1736 |
Public Property Key() As String ' This could be key of location, object or character |
| 1737 |
Get |
| 1738 |
If sKey Is Nothing Then |
| 1739 |
Select Case ExistWhere |
| 1740 |
Case ExistsWhereEnum.AtLocation |
| 1741 |
If Parent.HasProperty("CharacterAtLocation") Then sKey = Parent.GetPropertyValue("CharacterAtLocation") |
| 1742 |
Case ExistsWhereEnum.Hidden |
| 1743 |
sKey = "" |
| 1744 |
Case ExistsWhereEnum.InObject |
| 1745 |
If Parent.HasProperty("CharInsideWhat") Then sKey = Parent.GetPropertyValue("CharInsideWhat") |
| 1746 |
Case ExistsWhereEnum.OnCharacter |
| 1747 |
If Parent.HasProperty("CharOnWho") Then sKey = Parent.GetPropertyValue("CharOnWho") |
| 1748 |
If sKey = THEPLAYER Then sKey = Adventure.Player.Key |
| 1749 |
Case ExistsWhereEnum.OnObject |
| 1750 |
If Parent.HasProperty("CharOnWhat") Then sKey = Parent.GetPropertyValue("CharOnWhat") |
| 1751 |
End Select |
| 1752 |
End If |
| 1753 |
Return sKey |
| 1754 |
End Get |
| 1755 |
Set(ByVal Value As String) |
| 1756 |
sKey = Value |
| 1757 |
Select Case ExistWhere |
| 1758 |
Case ExistsWhereEnum.AtLocation |
| 1759 |
If Parent.HasProperty("CharacterAtLocation") Then Parent.SetPropertyValue("CharacterAtLocation", Value) |
| 1760 |
Case ExistsWhereEnum.InObject |
| 1761 |
If Parent.HasProperty("CharInsideWhat") Then Parent.SetPropertyValue("CharInsideWhat", Value) |
| 1762 |
Case ExistsWhereEnum.OnCharacter |
| 1763 |
If Parent.HasProperty("CharOnWho") Then Parent.SetPropertyValue("CharOnWho", Value) |
| 1764 |
Case ExistsWhereEnum.OnObject |
| 1765 |
If Parent.HasProperty("CharOnWhat") Then Parent.SetPropertyValue("CharOnWhat", Value) |
| 1766 |
End Select |
| 1767 |
End Set |
| 1768 |
End Property |
| 1769 |
|
| 1770 |
|
| 1771 |
Friend sLastLocationKey As String |
| 1772 |
' Returns the key of the location that the character is ultimately in |
| 1773 |
Public ReadOnly Property LocationKey() As String |
| 1774 |
Get |
| 1775 |
LocationKey = "" |
| 1776 |
Try |
| 1777 |
Select Case ExistWhere |
| 1778 |
Case ExistsWhereEnum.AtLocation |
| 1779 |
Return Key |
| 1780 |
Case ExistsWhereEnum.Hidden |
| 1781 |
' Hmm |
| 1782 |
Return HIDDEN |
| 1783 |
Case ExistsWhereEnum.InObject, ExistsWhereEnum.OnObject |
| 1784 |
Dim ob As clsObject = Nothing |
| 1785 |
If Adventure.htblObjects.TryGetValue(Key, ob) Then |
| 1786 |
If sLastLocationKey <> "" AndAlso ob.LocationRoots.ContainsKey(sLastLocationKey) Then |
| 1787 |
Return sLastLocationKey |
| 1788 |
Else |
| 1789 |
For Each sLocKey As String In ob.LocationRoots.Keys |
| 1790 |
Return sLocKey |
| 1791 |
Next |
| 1792 |
End If |
| 1793 |
End If |
| 1794 |
Return "" |
| 1795 |
Case ExistsWhereEnum.OnCharacter |
| 1796 |
Return Adventure.htblCharacters(Key).Location.LocationKey |
| 1797 |
Case Else |
| 1798 |
Return "" |
| 1799 |
End Select |
| 1800 |
Catch ex As Exception |
| 1801 |
ErrMsg("LocationKey error", ex) |
| 1802 |
Finally |
| 1803 |
If LocationKey <> "" AndAlso LocationKey <> sLastLocationKey Then sLastLocationKey = LocationKey |
| 1804 |
End Try |
| 1805 |
|
| 1806 |
End Get |
| 1807 |
End Property |
| 1808 |
|
| 1809 |
|
| 1810 |
Public Sub ResetPosition() |
| 1811 |
ePosition = PositionEnum.Uninitialised |
| 1812 |
End Sub |
| 1813 |
|
| 1814 |
Public Property Position() As PositionEnum |
| 1815 |
Get |
| 1816 |
If ePosition = PositionEnum.Uninitialised Then |
| 1817 |
If Parent.HasProperty("CharacterPosition") Then |
| 1818 |
Select Case Parent.GetPropertyValue("CharacterPosition") |
| 1819 |
Case "Standing" |
| 1820 |
ePosition = PositionEnum.Standing |
| 1821 |
Case "Sitting" |
| 1822 |
ePosition = PositionEnum.Sitting |
| 1823 |
Case "Lying" |
| 1824 |
ePosition = PositionEnum.Lying |
| 1825 |
Case Else |
| 1826 |
' Hmmm.... |
| 1827 |
End Select |
| 1828 |
Else |
| 1829 |
ePosition = PositionEnum.Standing |
| 1830 |
End If |
| 1831 |
End If |
| 1832 |
Return ePosition |
| 1833 |
End Get |
| 1834 |
Set(ByVal value As PositionEnum) |
| 1835 |
If value <> ePosition Then |
| 1836 |
Parent.SetPropertyValue("CharacterPosition", value.ToString) |
| 1837 |
|
| 1838 |
ePosition = value |
| 1839 |
End If |
| 1840 |
End Set |
| 1841 |
|
| 1842 |
End Property |
| 1843 |
|
| 1844 |
|
| 1845 |
Public Shadows ReadOnly Property ToString() As String |
| 1846 |
Get |
| 1847 |
If ExistWhere = ExistsWhereEnum.Hidden Then Return "Hidden" |
| 1848 |
|
| 1849 |
Dim sWhere As String = "" |
| 1850 |
|
| 1851 |
Select Case Position |
| 1852 |
Case PositionEnum.Standing |
| 1853 |
sWhere = "Standing " |
| 1854 |
Case PositionEnum.Sitting |
| 1855 |
sWhere = "Sitting " |
| 1856 |
Case PositionEnum.Lying |
| 1857 |
sWhere = "Lying " |
| 1858 |
End Select |
| 1859 |
|
| 1860 |
Select Case ExistWhere |
| 1861 |
Case ExistsWhereEnum.AtLocation |
| 1862 |
sWhere = "at " & Adventure.htblLocations(Key).ShortDescription.ToString |
| 1863 |
Case ExistsWhereEnum.OnObject |
| 1864 |
sWhere &= "on " & Adventure.htblObjects(Key).FullName |
| 1865 |
Case ExistsWhereEnum.InObject |
| 1866 |
sWhere &= "in " & Adventure.htblObjects(Key).FullName |
| 1867 |
Case ExistsWhereEnum.OnCharacter |
| 1868 |
sWhere &= "on " & Adventure.htblCharacters(Key).Name(, False) |
| 1869 |
End Select |
| 1870 |
|
| 1871 |
Return sWhere |
| 1872 |
End Get |
| 1873 |
End Property |
| 1874 |
|
| 1875 |
End Class |