Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. var weather = Connect("MeteorologyServer")
  2. var doors = Connect("SteeringComputer")
  3. var locator = Connect("MissingPersonFinder")
  4. var playstation = Connect("LongsonPlaystation")
  5. var extractor = Connect("Extractor")
  6. var teleporter = Connect("Teleporter")
  7. var hugin = Connect("Hugin")
  8.  
  9. # Unlock()
  10. # Lock()
  11. # Locate()
  12. # SetRain(0)
  13. # Move()
  14. # Teleport()
  15.  
  16. #
  17. # Helper Methods.
  18. #
  19. void Unlock(string doorName)
  20. doors.Unlock(doorName)
  21. end
  22.  
  23. void Lock(string doorName)
  24. doors.Lock(doorName)
  25. end
  26.  
  27. void Locate(string thing)
  28. var position = playstation.GetPosition(thing)
  29. extractor.CopyToClipboard(position)
  30. Print(position)
  31. end
  32.  
  33. var Move(string source, string location)
  34. playstation.SetPosition(source, location)
  35. end
  36.  
  37. void SetRain(number rain)
  38. weather.SetRain(rain)
  39. end
  40.  
  41. void Teleport(string room, number x, number y)
  42. teleporter.SetWorldPosition(room, x ,y)
  43. end
  44.  
  45. string Replace(string text, string phrase, string replace)
  46. array result = []
  47. array matches = FindInString(text, phrase)
  48.  
  49.  
  50. loop c in text
  51. Append(result, c)
  52. end
  53.  
  54. loop match in matches
  55. number inc = 0
  56. number replaceLength = Count(replace)
  57. number matchLength = Count(Range(match[0], match[1]))
  58.  
  59. if matchLength < replaceLength
  60. array temp = []
  61. loop c in replace
  62. Append(temp, c)
  63. end
  64. loop index in Range(match[1] + 1, Count(result) - 1)
  65. Append(temp, result[index])
  66. end
  67. result = temp
  68.  
  69. else
  70. loop index in Range(match[0], match[1])
  71. if inc < replaceLength - 1
  72. result[index] = replace[inc]
  73. else
  74. Remove(result, index)
  75. end
  76. end
  77. end
  78. end
  79.  
  80. return ArrayToString(result)
  81. end
  82.  
  83. string ArrayToString(array source)
  84. string result
  85. loop c in source
  86. result += c
  87. end
  88. return result
  89. end
  90.  
  91. array FindInString(string source, string phrase)
  92. array rawSource = []
  93. array rawPhrase = []
  94. array matches = []
  95. array possible = []
  96. number currentIndex = 0
  97. number phraseLength = -1
  98.  
  99. loop c in source
  100. Append(rawSource, CharToInt(c))
  101. end
  102.  
  103. loop c in phrase
  104. Append(rawPhrase, CharToInt(c))
  105. phraseLength++
  106. end
  107.  
  108. loop c in rawSource
  109. if currentIndex > phraseLength
  110. break
  111. end
  112. number endIndex = currentIndex + phraseLength
  113.  
  114. if c == rawPhrase[0] and rawSource[endIndex] == rawPhrase[phraseLength]
  115. Append(possible, [currentIndex, endIndex])
  116. end
  117.  
  118. currentIndex++
  119. end
  120.  
  121. # Now verify that our matches are true.
  122. loop match in possible
  123. bool hasErrors = false
  124. number inc = 0
  125. loop index in Range(match[0], match[1])
  126. if rawSource[index] == rawPhrase[inc]
  127. inc++
  128. else
  129. hasErrors = true
  130. inc = 0
  131. end
  132. end
  133.  
  134. if !hasErrors
  135. Append(matches, match)
  136. end
  137. end
  138.  
  139. return matches
  140. end
  141.  
  142. number CharToInt(string char)
  143. return locator.CharToInt(char)
  144. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement