| 1 |
--[[ Copyright (c) 2009 Edvin "Lego3" Linge |
| 2 |
|
| 3 |
Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 4 |
this software and associated documentation files (the "Software"), to deal in |
| 5 |
the Software without restriction, including without limitation the rights to |
| 6 |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 7 |
of the Software, and to permit persons to whom the Software is furnished to do |
| 8 |
so, subject to the following conditions: |
| 9 |
|
| 10 |
The above copyright notice and this permission notice shall be included in all |
| 11 |
copies or substantial portions of the Software. |
| 12 |
|
| 13 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 |
SOFTWARE. --]] |
| 20 |
|
| 21 |
class "DieAction" (HumanoidAction) |
| 22 |
|
| 23 |
---@type DieAction |
| 24 |
local DieAction = _G["DieAction"] |
| 25 |
|
| 26 |
function DieAction:DieAction() |
| 27 |
self:HumanoidAction("die") |
| 28 |
end |
| 29 |
|
| 30 |
local action_die_tick; action_die_tick = permanent"action_die_tick"( function(humanoid) |
| 31 |
local action = humanoid:getCurrentAction() |
| 32 |
local phase = action.phase |
| 33 |
local mirror = humanoid.last_move_direction == "east" and 0 or 1 |
| 34 |
if phase == 0 then |
| 35 |
action.phase = 1 |
| 36 |
if humanoid.die_anims.extra_east ~= nil then |
| 37 |
humanoid:setTimer(TheApp.animation_manager:getAnimLength(humanoid.die_anims.extra_east), action_die_tick) |
| 38 |
humanoid:setAnimation(humanoid.die_anims.extra_east, mirror) |
| 39 |
else |
| 40 |
action_die_tick(humanoid) |
| 41 |
end |
| 42 |
elseif phase == 1 then |
| 43 |
action.phase = 2 |
| 44 |
humanoid:setTimer(11, action_die_tick) |
| 45 |
humanoid:setAnimation(humanoid.die_anims.rise_east, mirror) |
| 46 |
elseif phase == 2 then |
| 47 |
-- Female slack tongue head layer is missing from wings animation onwards |
| 48 |
-- So we change the head to its standard equivalent |
| 49 |
if humanoid:isType("Slack Female Patient") then |
| 50 |
humanoid:setLayer(0, humanoid.layers[0] - 8) |
| 51 |
end |
| 52 |
|
| 53 |
action.phase = 3 |
| 54 |
humanoid:setTimer(11, action_die_tick) |
| 55 |
humanoid:setAnimation(humanoid.die_anims.wings_east, mirror) |
| 56 |
elseif phase == 3 then |
| 57 |
action.phase = 4 |
| 58 |
humanoid:setTimer(15, action_die_tick) |
| 59 |
humanoid:setAnimation(humanoid.die_anims.hands_east, mirror) |
| 60 |
elseif phase == 4 then |
| 61 |
action.phase = 5 |
| 62 |
humanoid:setTimer(30, action_die_tick) |
| 63 |
humanoid:setAnimation(humanoid.die_anims.fly_east, mirror) |
| 64 |
humanoid:setTilePositionSpeed(humanoid.tile_x, humanoid.tile_y, nil, nil, 0, -4) |
| 65 |
else |
| 66 |
humanoid:despawn() |
| 67 |
humanoid.world:destroyEntity(humanoid) |
| 68 |
end |
| 69 |
end) |
| 70 |
|
| 71 |
local action_die_tick_reaper; action_die_tick_reaper = permanent"action_die_tick_reaper"( function(humanoid) |
| 72 |
local action = humanoid:getCurrentAction() |
| 73 |
local mirror = humanoid.last_move_direction == "east" and 0 or 1 |
| 74 |
local phase = action.phase |
| 75 |
|
| 76 |
if phase == 0 then |
| 77 |
action.phase = 1 |
| 78 |
|
| 79 |
if humanoid.die_anims.extra_east ~= nil then |
| 80 |
humanoid:setTimer(TheApp.animation_manager:getAnimLength(humanoid.die_anims.extra_east), action_die_tick_reaper) |
| 81 |
humanoid:setAnimation(humanoid.die_anims.extra_east, mirror) |
| 82 |
else |
| 83 |
action_die_tick_reaper(humanoid) |
| 84 |
end |
| 85 |
|
| 86 |
--1: The patient stays on the ground until phase 5: |
| 87 |
elseif phase == 1 then |
| 88 |
action.phase = 2 |
| 89 |
if not humanoid:isType("Standard Male Patient") then |
| 90 |
humanoid:setType("Standard Male Patient") |
| 91 |
end |
| 92 |
humanoid:setAnimation(humanoid.on_ground_anim, mirror) |
| 93 |
action_die_tick_reaper(humanoid) |
| 94 |
|
| 95 |
--2: Spawn the grim reaper and the lava hole, if no suitable spawn points are found a heaven death will be started: |
| 96 |
elseif phase == 2 then |
| 97 |
local holes_orientation |
| 98 |
local hole_x, hole_y |
| 99 |
local grim_x, grim_y |
| 100 |
local grim_use_tile_x, grim_use_tile_y |
| 101 |
local grim_spawn_idle_direction |
| 102 |
local mirror_grim = 0 |
| 103 |
|
| 104 |
local spawn_scenarios = { |
| 105 |
{"south", humanoid.tile_x, humanoid.tile_y + 4, 1, 0, "west", -1, 0, {{after_spawn_idle_direction = "east", hole_x_offset = -5, hole_y_offset = 2}, {hole_x_offset = 0, hole_y_offset = 3}} }, |
| 106 |
{"east", humanoid.tile_x + 4, humanoid.tile_y, 0, 1, "north", 0, -1, {{hole_x_offset = 3, hole_y_offset = 0}} } |
| 107 |
} |
| 108 |
|
| 109 |
--- |
| 110 |
-- @param spawn_scenario {holes_orientation, find_hole_spawn_x, find_hole_spawn_y, g_use_x_offset, g_use_y_offset, grim_face_hole_dir, mirror_grim, p_use_x_offset, p_use_y_offset, find_grim_spawn_attempts} |
| 111 |
--- |
| 112 |
local function tryToUseHellDeathSpawnScenario(spawn_scenario) |
| 113 |
holes_orientation = spawn_scenario[1] |
| 114 |
hole_x, hole_y = humanoid.world.pathfinder:findIdleTile(spawn_scenario[2], spawn_scenario[3], 0) |
| 115 |
|
| 116 |
if hole_x and humanoid.world:canNonSideObjectBeSpawnedAt(hole_x, hole_y, "gates_to_hell", holes_orientation, 0, 0) then |
| 117 |
if holes_orientation == "south" then |
| 118 |
mirror_grim = 1 |
| 119 |
end |
| 120 |
grim_use_tile_x = hole_x + spawn_scenario[4] |
| 121 |
grim_use_tile_y = hole_y + spawn_scenario[5] |
| 122 |
humanoid.hole_use_tile_x = hole_x + spawn_scenario[7] |
| 123 |
humanoid.hole_use_tile_y = hole_y + spawn_scenario[8] |
| 124 |
-- tile can't be in a room and must be accessible by the patient |
| 125 |
if not humanoid.world:getPathDistance(humanoid.tile_x, humanoid.tile_y, humanoid.hole_use_tile_x, humanoid.hole_use_tile_y) |
| 126 |
or humanoid.world:getRoom(humanoid.hole_use_tile_x, humanoid.hole_use_tile_y) then |
| 127 |
return false |
| 128 |
end |
| 129 |
-- ensure grim won't be in a room |
| 130 |
if humanoid.world:getRoom(grim_use_tile_x, grim_use_tile_y) then |
| 131 |
return false |
| 132 |
end |
| 133 |
--Ensure that the lava hole is passable on at least one of its sides to prevent it from blocking 1 tile wide corridors: |
| 134 |
humanoid.world.map:setCellFlags(hole_x, hole_y, {passable = false}) |
| 135 |
local hole_has_passable_side = humanoid.world:getPathDistance(grim_use_tile_x, grim_use_tile_y, humanoid.hole_use_tile_x, humanoid.hole_use_tile_y) == 4 |
| 136 |
humanoid.world.map:setCellFlags(hole_x, hole_y, {passable = true}) |
| 137 |
if not hole_has_passable_side then |
| 138 |
return false |
| 139 |
end |
| 140 |
--Try to find grim a spawn point which will allow him to walk to his lava hole use tile: |
| 141 |
local grim_cant_walk_to_use_tile = true |
| 142 |
for _, find_grim_spawn_attempt in ipairs(spawn_scenario[9]) do |
| 143 |
grim_spawn_idle_direction = find_grim_spawn_attempt.after_spawn_idle_direction or spawn_scenario[6] |
| 144 |
grim_x, grim_y = humanoid.world.pathfinder:findIdleTile(hole_x + find_grim_spawn_attempt.hole_x_offset, hole_y + find_grim_spawn_attempt.hole_y_offset, 0) |
| 145 |
if grim_x and not humanoid.world:getRoom(grim_x, grim_y) |
| 146 |
and humanoid.world:getPathDistance(grim_x, grim_y, grim_use_tile_x, grim_use_tile_y) then |
| 147 |
grim_cant_walk_to_use_tile = false |
| 148 |
break |
| 149 |
end |
| 150 |
end |
| 151 |
-- Else spawn him on it: |
| 152 |
if grim_cant_walk_to_use_tile then |
| 153 |
grim_spawn_idle_direction = spawn_scenario[6] |
| 154 |
grim_x = grim_use_tile_x |
| 155 |
grim_y = grim_use_tile_y |
| 156 |
end |
| 157 |
return true |
| 158 |
end |
| 159 |
return false |
| 160 |
end |
| 161 |
|
| 162 |
local usable_scenario_found = false |
| 163 |
for _, spawn_scenario in ipairs(spawn_scenarios) do |
| 164 |
if not usable_scenario_found then |
| 165 |
usable_scenario_found = tryToUseHellDeathSpawnScenario(spawn_scenario) |
| 166 |
end |
| 167 |
end |
| 168 |
if not usable_scenario_found then |
| 169 |
action_die_tick(humanoid) |
| 170 |
return |
| 171 |
end |
| 172 |
|
| 173 |
--Spawn the grim reaper and the lava hole: |
| 174 |
local lava_hole = humanoid.world:newObject("gates_to_hell", hole_x, hole_y, holes_orientation) |
| 175 |
local grim_reaper = humanoid.world:newEntity("GrimReaper", 1660, 2) |
| 176 |
|
| 177 |
local point_dir = {x = grim_x, y = grim_y, direction = grim_spawn_idle_direction} |
| 178 |
grim_reaper:setNextAction(IdleSpawnAction(1660, point_dir):setCount(40)) |
| 179 |
|
| 180 |
--Initialise the grim reaper: |
| 181 |
grim_reaper:setHospital(humanoid.world:getLocalPlayerHospital()) |
| 182 |
grim_reaper.lava_hole = lava_hole |
| 183 |
grim_reaper.lava_hole.orientation = holes_orientation |
| 184 |
grim_reaper.use_tile_x = grim_use_tile_x |
| 185 |
grim_reaper.use_tile_y = grim_use_tile_y |
| 186 |
grim_reaper.mirror = mirror_grim |
| 187 |
grim_reaper.patient = humanoid |
| 188 |
humanoid.grim_reaper = grim_reaper |
| 189 |
|
| 190 |
action.phase = 3 |
| 191 |
action_die_tick_reaper(humanoid) |
| 192 |
|
| 193 |
--3: The grim reaper walks to his lava hole use tile and then stands idle waiting for phase 6: |
| 194 |
elseif phase == 3 then |
| 195 |
action.phase = 4 |
| 196 |
local grim = humanoid.grim_reaper |
| 197 |
if grim.tile_x ~= grim.use_tile_x or grim.tile_y ~= grim.use_tile_y then |
| 198 |
grim:queueAction(WalkAction(grim.use_tile_x, grim.use_tile_y):disableTruncate()) |
| 199 |
end |
| 200 |
|
| 201 |
local loop_callback_wait = --[[persistable:reaper_wait]]function() |
| 202 |
grim:setAnimation(1002, grim.mirror) |
| 203 |
action_die_tick_reaper(humanoid) |
| 204 |
end |
| 205 |
grim:queueAction(IdleAction():setLoopCallback(loop_callback_wait)) |
| 206 |
|
| 207 |
--4: There will be a brief pause before the patient stands up: |
| 208 |
elseif phase == 4 then |
| 209 |
action.phase = 5 |
| 210 |
humanoid:setTimer(20, action_die_tick_reaper) |
| 211 |
|
| 212 |
-- 5: The dead patient will now stand up: |
| 213 |
elseif phase == 5 then |
| 214 |
action.phase = 6 |
| 215 |
humanoid:setTimer(TheApp.animation_manager:getAnimLength(humanoid.die_anims.rise_hell_east), action_die_tick_reaper) |
| 216 |
humanoid:setAnimation(humanoid.die_anims.rise_hell_east, mirror) |
| 217 |
|
| 218 |
--6: The dead patient will now walk in to the lava hole, falling in as the grim reaper does his "sending patient to hell" animation: |
| 219 |
elseif phase == 6 then |
| 220 |
local grim = humanoid.grim_reaper |
| 221 |
local lava_hole = grim.lava_hole |
| 222 |
--The grim reaper's final actions: |
| 223 |
local loop_callback_swipe =--[[persistable:reaper_swipe]]function() |
| 224 |
grim:setAnimation(1670, grim.mirror) |
| 225 |
end |
| 226 |
grim:queueAction(IdleAction():setCount(TheApp.animation_manager:getAnimLength(1670)):setLoopCallback(loop_callback_swipe)) |
| 227 |
|
| 228 |
local loop_callback_leave =--[[persistable:reaper_leave]]function() |
| 229 |
grim:setAnimation(1678, grim.mirror) |
| 230 |
end |
| 231 |
grim:queueAction(IdleAction():setCount(TheApp.animation_manager:getAnimLength(1678)):setLoopCallback(loop_callback_leave)) |
| 232 |
|
| 233 |
local lava_destroy = --[[persistable:lava_destroy]]function() |
| 234 |
humanoid.world:destroyEntity(lava_hole) |
| 235 |
end |
| 236 |
local loop_callback_destroy =--[[persistable:reaper_destroy]]function() |
| 237 |
lava_hole.playing_sounds_in_random_sequence = false |
| 238 |
lava_hole:setTimer(TheApp.animation_manager:getAnimLength(2552), lava_destroy) |
| 239 |
lava_hole:setAnimation(2552) |
| 240 |
grim.world:destroyEntity(grim) |
| 241 |
end |
| 242 |
grim:queueAction(IdleAction():setLoopCallback(loop_callback_destroy)) |
| 243 |
|
| 244 |
--The patient's final actions: |
| 245 |
humanoid:walkTo(humanoid.hole_use_tile_x, humanoid.hole_use_tile_y, true) |
| 246 |
|
| 247 |
local post_walk_into = --[[persistable:walk_into_lava]]function() |
| 248 |
grim:finishAction() |
| 249 |
end |
| 250 |
|
| 251 |
local use_action = UseObjectAction(lava_hole) |
| 252 |
use_action.destroy_user_after_use = true |
| 253 |
use_action.after_walk_in = post_walk_into |
| 254 |
humanoid:queueAction(use_action) |
| 255 |
humanoid:finishAction() |
| 256 |
end |
| 257 |
end) |
| 258 |
|
| 259 |
local function action_die_start(action, humanoid) |
| 260 |
humanoid:setMoodInfo() -- clear all mood icons |
| 261 |
local preferred_fall_direction |
| 262 |
if math.random(0, 1) == 1 then |
| 263 |
preferred_fall_direction = "east" |
| 264 |
else |
| 265 |
preferred_fall_direction = "south" |
| 266 |
end |
| 267 |
local anims = humanoid.die_anims |
| 268 |
assert(anims, "Error: no death animation for humanoid ".. humanoid.humanoid_class) |
| 269 |
action.must_happen = true |
| 270 |
local fall = anims.fall_east |
| 271 |
|
| 272 |
--If this isn't done their bald head will become bloated instead of suddenly having hair: |
| 273 |
if humanoid.disease.id == "baldness" then humanoid:setLayer(0,2) end |
| 274 |
|
| 275 |
local mirror_fall = preferred_fall_direction == "east" and 0 or 1 |
| 276 |
humanoid.last_move_direction = preferred_fall_direction |
| 277 |
|
| 278 |
humanoid:setAnimation(anims.fall_east, mirror_fall) |
| 279 |
|
| 280 |
action.phase = 0 |
| 281 |
|
| 282 |
local fall_anim_duration = TheApp.animation_manager:getAnimLength(fall) |
| 283 |
if humanoid:isType("Chewbacca Patient") then |
| 284 |
--After 21 ticks the first frame of the buggy falling part of this animation is reached |
| 285 |
--so this animation is ended early, action_die_tick will then use the standard male fall animation: |
| 286 |
fall_anim_duration = 21 |
| 287 |
end |
| 288 |
-- Bloaty head patients can't go to hell because they don't have a |
| 289 |
-- "transform to standard male"/"fall into lava hole" animation. |
| 290 |
if humanoid:isMalePatient() and humanoid.disease.id ~= "bloaty_head" then |
| 291 |
if math.random(1, 100) <= 65 then |
| 292 |
humanoid:setTimer(fall_anim_duration, action_die_tick_reaper) |
| 293 |
else |
| 294 |
humanoid:setTimer(fall_anim_duration, action_die_tick) |
| 295 |
end |
| 296 |
else |
| 297 |
humanoid:setTimer(fall_anim_duration, action_die_tick) |
| 298 |
end |
| 299 |
humanoid.dead = true |
| 300 |
end |
| 301 |
|
| 302 |
return action_die_start |