Debian Codegraph @

CorsixTH/Lua/humanoid_actions/use_screen.lua

raw
1 --[[ Copyright (c) 2009 Peter "Corsix" Cawley
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 "UseScreenAction" (HumanoidAction)
22
23 ---@type UseScreenAction
24 local UseScreenAction = _G["UseScreenAction"]
25
26 --! Action to use the screen.
27 --!param screen (object) Screen to use.
28 function UseScreenAction:UseScreenAction(screen)
29 assert(class.is(screen, Object) and (
30 screen.object_type.id == "screen" or
31 screen.object_type.id == "surgeon_screen"),
32 "Invalid value for parameter 'screen'")
33
34 self:HumanoidAction("use_screen")
35 self.object = screen
36 end
37
38 local finish = permanent"action_use_screen_finish"( function(humanoid)
39 local screen = humanoid.user_of
40 humanoid.user_of = nil
41 screen:removeUser(humanoid)
42 local offset = screen.object_type.orientations[screen.direction].use_position
43 humanoid:setTile(screen.tile_x + offset[1], screen.tile_y + offset[2])
44 local after_use = humanoid:getCurrentAction().after_use
45 if after_use then
46 after_use()
47 end
48 humanoid:finishAction()
49 end)
50
51 local patient_clothes_state = permanent"action_use_screen_patient_clothes_state"( function(humanoid)
52 humanoid.user_of:setAnimation(1204)
53 humanoid.user_of:setLayer(1, humanoid.layers[1])
54 return finish(humanoid)
55 end)
56
57 local normal_state = permanent"action_use_screen_normal_state"( function(humanoid)
58 humanoid.user_of:setAnimation(1022)
59 humanoid.user_of:setLayer(1, 0)
60 return finish(humanoid)
61 end)
62
63 local surgical_state = permanent"action_use_screen_surgical_state"( function(humanoid)
64 local screen = humanoid.user_of
65 if screen.num_green_outfits > 0 then
66 if screen.num_white_outfits > 0 then
67 screen:setAnimation(2776)
68 else
69 screen:setAnimation(2772)
70 end
71 else
72 screen:setAnimation(2774)
73 end
74 return finish(humanoid)
75 end)
76
77 local function action_use_screen_start(action, humanoid)
78 local screen = action.object
79 local class = humanoid.humanoid_class
80 local anim, when_done
81 local is_surgical = not not screen.num_green_outfits
82 local change_to = math.random(1, 3)
83 if class == "Elvis Patient" then
84 anim, when_done = 946, finish
85 humanoid:setType "Standard Male Patient"
86 humanoid:setLayer(0, 2)
87 humanoid:setLayer(1, math.random(0, 3) * 2)
88 humanoid:setLayer(2, 2)
89 elseif class == "Stripped Male Patient" then
90 humanoid:setType "Standard Male Patient"
91 anim, when_done = 1052, normal_state
92 elseif class == "Stripped Female Patient" then
93 humanoid:setType "Standard Female Patient"
94 anim, when_done = 2844, normal_state
95 elseif class == "Stripped Male Patient 2" then
96 humanoid:setType "Standard Male Patient"
97 anim, when_done = 1052, normal_state
98 elseif class == "Stripped Female Patient 2" then
99 humanoid:setType "Standard Female Patient"
100 anim, when_done = 2844, normal_state
101 elseif class == "Stripped Male Patient 3" then
102 humanoid:setType "Standard Male Patient"
103 anim, when_done = 1052, normal_state
104 elseif class == "Stripped Female Patient 3" then
105 humanoid:setType "Standard Female Patient"
106 anim, when_done = 2844, normal_state
107 elseif class == "Gowned Male Patient" then
108 humanoid:setType "Standard Male Patient"
109 anim, when_done = 4768, finish
110 elseif class == "Gowned Female Patient" then
111 humanoid:setType "Standard Female Patient"
112 anim, when_done = 4770, finish
113 elseif class == "Standard Male Patient" then
114 if is_surgical then
115 humanoid:setType "Gowned Male Patient"
116 anim, when_done = 4760, finish
117 else
118 if change_to == 1 then
119 humanoid:setType "Stripped Male Patient"
120 anim, when_done = 1048, patient_clothes_state
121 elseif change_to == 2 then
122 humanoid:setType "Stripped Male Patient 2"
123 anim, when_done = 1048, patient_clothes_state
124 else
125 humanoid:setType "Stripped Male Patient 3"
126 anim, when_done = 1048, patient_clothes_state
127 end
128 end
129 elseif class == "Standard Female Patient" then
130 if is_surgical then
131 humanoid:setType "Gowned Female Patient"
132 anim, when_done = 4762, finish
133 else
134 if change_to == 1 then
135 humanoid:setType "Stripped Female Patient"
136 anim, when_done = 2848, patient_clothes_state
137 elseif change_to == 2 then
138 humanoid:setType "Stripped Female Patient 2"
139 anim, when_done = 2848, patient_clothes_state
140 else
141 humanoid:setType "Stripped Female Patient 3"
142 anim, when_done = 2848, patient_clothes_state
143 end
144 end
145 elseif class == "Doctor" then
146 humanoid:setType "Surgeon"
147 when_done = surgical_state
148 if screen.num_white_outfits > 0 then
149 if screen.num_green_outfits > 1 then
150 anim = 2780
151 else
152 anim = 2784
153 end
154 else
155 anim = 2782
156 end
157 screen.num_green_outfits = screen.num_green_outfits - 1
158 screen.num_white_outfits = screen.num_white_outfits + 1
159 elseif class == "Surgeon" then
160 humanoid:setType "Doctor"
161 when_done = surgical_state
162 if screen.num_green_outfits > 0 then
163 if screen.num_white_outfits > 1 then
164 anim = 2796
165 else
166 anim = 2790
167 end
168 else
169 anim = 2792
170 end
171 screen.num_green_outfits = screen.num_green_outfits + 1
172 screen.num_white_outfits = screen.num_white_outfits - 1
173 else
174 error(class .. " trying to use screen")
175 end
176
177 humanoid:setAnimation(anim)
178 humanoid:setTile(screen:getRenderAttachTile())
179 local offset = screen.object_type.orientations[screen.direction].animation_offset
180 humanoid:setPosition(offset[1], offset[2])
181 humanoid:setSpeed(0, 0)
182 humanoid:setTimer(TheApp.animation_manager:getAnimLength(anim), when_done)
183
184 screen:setUser(humanoid)
185 humanoid.user_of = screen
186 action.must_happen = true
187
188 if action.todo_interrupt == "high" then
189 humanoid:setTimer(nil)
190 when_done(humanoid)
191 end
192 end
193
194 return action_use_screen_start