Debian Codegraph @

CorsixTH/Lua/humanoid_actions/sweep_floor.lua

raw
1 --[[ Copyright (c) 2011 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 "SweepFloorAction" (HumanoidAction)
22
23 ---@type SweepFloorAction
24 local SweepFloorAction = _G["SweepFloorAction"]
25
26 function SweepFloorAction:SweepFloorAction(litter)
27 assert(class.is(litter, Litter), "Invalid value for parameter 'litter'")
28
29 self:HumanoidAction("sweep_floor")
30 self.litter = litter
31 end
32
33 -- Set markers for all animations involved.
34 local animation_numbers = {
35 1874,
36 1878,
37 }
38 TheApp.animation_manager:setStaffMarker(animation_numbers, {-1, 0, "px"})
39
40 local finish = permanent"action_sweep_floor_finish"( function(humanoid)
41 humanoid:finishAction()
42 end)
43
44 local remove_litter = permanent"action_sweep_floor_remove_litter"( function(humanoid)
45 humanoid.user_of:remove()
46 humanoid.user_of:setTile(nil)
47 humanoid.user_of = nil
48 humanoid:setTimer(TheApp.animation_manager:getAnimLength(animation_numbers[2]) * 2, finish)
49 end)
50
51 local sweep = permanent"action_sweep_floor_sweep"( function(humanoid)
52 local anim = animation_numbers[2]
53 humanoid:setAnimation(anim)
54 humanoid:setTimer(TheApp.animation_manager:getAnimLength(anim) * 2, remove_litter)
55 end)
56
57 local function action_sweep_floor_start(action, humanoid)
58 action.must_happen = true
59 humanoid.user_of = action.litter
60 -- remove handyman task as soon as action starts - we should be committed to completing this task
61 local litter = action.litter
62 local hospital = litter.hospital
63 local taskIndex = hospital:getIndexOfTask(litter.tile_x, litter.tile_y, "cleaning", litter)
64 hospital:removeHandymanTask(taskIndex, "cleaning")
65 local anim = animation_numbers[1]
66 humanoid:setAnimation(anim)
67 humanoid:setTimer(TheApp.animation_manager:getAnimLength(anim), sweep)
68 end
69
70 return action_sweep_floor_start