Advertisement
Aussiemon

SpecialFlavorText.lua

Jan 27th, 2018
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. --[[
  2. author: Aussiemon
  3.  
  4. -----
  5.  
  6. Copyright 2018 Aussiemon
  7.  
  8. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  9.  
  10. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  11.  
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  13.  
  14. -----
  15.  
  16. Provides more information about things that happen to specials.
  17. --]]
  18.  
  19. local mod_name = "SpecialFlavorText"
  20.  
  21. -- ##########################################################
  22. -- ################## Variables #############################
  23.  
  24. local flavor_text_list = {
  25. deactivate_area = {
  26. " left to pursue other targets.",
  27. },
  28. stuck = {
  29. " was caught in a trap.",
  30. },
  31. far_away = {
  32. " lost sight of the heroes.",
  33. },
  34. main_path_blocked = {
  35. " was blocked from pursuing the heroes.",
  36. },
  37. no_path_found = {
  38. " couldn't continue on.",
  39. },
  40. intentionally_destroyed = {
  41. " was murdered by an unseen hand.",
  42. },
  43. out_of_range = {
  44. " lost track of the hunt.",
  45. },
  46. gas_explosion = {
  47. " exploded in a cloud of poison gas.",
  48. },
  49. death_zone = {
  50. " was caught in a dangerous place.",
  51. },
  52. crushed = {
  53. " was crushed by falling debris.",
  54. },
  55. poison = {
  56. " fell to the Callach's Claws.",
  57. },
  58. forced = {
  59. " suffered a hard impact.",
  60. },
  61. push = {
  62. " collapsed.",
  63. },
  64. volume_insta_kill = {
  65. " fell to their death.",
  66. },
  67. globadier_gas_dot = {
  68. " inhaled poison gas.",
  69. },
  70. inside_forbidden_tag_volume = {
  71. " fell out of the world.",
  72. },
  73. kinetic = {
  74. " was killed by a powerful force.",
  75. },
  76. }
  77.  
  78. local special_breeds = {
  79. skaven_gutter_runner = "Gutter Runner",
  80. skaven_ratling_gunner = "Ratling Gunner",
  81. skaven_pack_master = "Packmaster",
  82. skaven_poison_wind_globadier = "Globadier",
  83. skaven_storm_vermin_champion = "Stormvermin Chieftain",
  84. skaven_rat_ogre = "Rat Ogre",
  85. skaven_loot_rat = "Sack Rat",
  86. }
  87.  
  88. local event_colors = {
  89. fade_to = Colors.get_table("white"),
  90. default = Colors.get_table("cheeseburger"),
  91. kill = Colors.get_table("red"),
  92. personal = Colors.get_table("dodger_blue")
  93. }
  94.  
  95. SpecialFlavorText = {}
  96.  
  97. -- ##########################################################
  98. -- ################## Functions #############################
  99.  
  100. SpecialFlavorText.send_message = function(message)
  101. safe_pcall(function()
  102. local managers = Managers
  103. local player_manager = managers.player
  104. local local_player = player_manager:local_player()
  105. local stats_id = local_player.stats_id(local_player)
  106.  
  107. local managers_state = managers.state
  108. local event_manager = managers_state.event
  109.  
  110. event_manager:trigger("add_personal_interaction_warning", stats_id .. message, message)
  111. end)
  112. return
  113. end
  114.  
  115. SpecialFlavorText.choose_message = function(breed_name, reason)
  116. if flavor_text_list[reason] then
  117. local num_options = #flavor_text_list[reason]
  118. if 0 < num_options then
  119. local flavor_text = flavor_text_list[reason][math.random(num_options)]
  120. return "A " .. (special_breeds[breed_name] or "rat") .. flavor_text
  121. end
  122. else
  123. EchoConsole("Unrecognized reason: " .. tostring(reason))
  124. end
  125.  
  126. return ""
  127. end
  128.  
  129. -- ##########################################################
  130. -- #################### Hooks ###############################
  131.  
  132. -- When a unit is destroyed by the director, print a message.
  133. Mods.hook.set(mod_name, "ConflictDirector.destroy_unit", function (func, self, unit, blackboard, reason)
  134. safe_pcall(function()
  135. local breed = blackboard.breed
  136. local breed_name = breed.name
  137. if reason and breed_name and special_breeds[breed_name] then
  138. local send_message = SpecialFlavorText.send_message
  139. local choose_message = SpecialFlavorText.choose_message
  140.  
  141. -- Display flavor text
  142. send_message(choose_message(breed_name, reason))
  143. end
  144. end)
  145.  
  146. local result = func(self, unit, blackboard, reason)
  147. return result
  148. end)
  149.  
  150. Mods.hook.set(mod_name, "AiUtils.poison_explode_unit", function (func, unit, action, blackboard)
  151. safe_pcall(function()
  152. local breed = blackboard.breed
  153. local breed_name = breed.name
  154. if breed_name and special_breeds[breed_name] then
  155. local send_message = SpecialFlavorText.send_message
  156. local choose_message = SpecialFlavorText.choose_message
  157.  
  158. -- Display flavor text
  159. local reason = "gas_explosion"
  160. send_message(choose_message(breed_name, reason))
  161. end
  162. end)
  163.  
  164. local result = func(unit, action, blackboard)
  165. return result
  166. end)
  167.  
  168. Mods.hook.set(mod_name, "AiUtils.kill_unit", function (func, victim_unit, attacker_unit, hit_zone_name, damage_type, damage_direction)
  169. safe_pcall(function()
  170. local AiUtils_breed_name = AiUtils.breed_name
  171. local breed_name = AiUtils_breed_name(victim_unit)
  172. local reason = damage_type
  173. if reason and breed_name and special_breeds[breed_name] then
  174. local send_message = SpecialFlavorText.send_message
  175. local choose_message = SpecialFlavorText.choose_message
  176.  
  177. -- Display flavor text
  178. send_message(choose_message(breed_name, reason))
  179. end
  180. end)
  181.  
  182. local result = func(victim_unit, attacker_unit, hit_zone_name, damage_type, damage_direction)
  183. return result
  184. end)
  185.  
  186. -- Remove localization to just print message as-is.
  187. Mods.hook.set(mod_name, "PositiveReinforcementUI.event_add_interaction_warning", function (func, self, hash, message)
  188. self.add_event(self, hash, true, event_colors.kill, "interaction_warning", message)
  189. return
  190. end)
  191.  
  192. -- ##########################################################
  193. -- ################### Script ###############################
  194.  
  195. -- ##########################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement