1--[[ Copyright (c) 2009 Peter "Corsix" Cawley 2 3Permission is hereby granted, free of charge, to any person obtaining a copy of 4this software and associated documentation files (the "Software"), to deal in 5the Software without restriction, including without limitation the rights to 6use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7of the Software, and to permit persons to whom the Software is furnished to do 8so, subject to the following conditions: 9 10The above copyright notice and this permission notice shall be included in all 11copies or substantial portions of the Software. 12 13THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19SOFTWARE. --]] 20 21class "UseScreenAction" (HumanoidAction) 22 23---@type UseScreenAction 24local UseScreenAction = _G["UseScreenAction"] 25 26--! Action to use the screen. 27--!param screen (object) Screen to use. 28function 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 36end 37 38local 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() 49end) 50 51-- Set markers for all animations involved. 52local animation_numbers = { 53 946, 54 --1022, 55 1048, 56 1052, 57 --1204, 58 --2772, 59 --2774, 60 --2776, 61 2780, 62 2782, 63 2784, 64 2790, 65 2792, 66 2794, 67 2796, 68 2844, 69 2848, 70 4760, 71 4762, 72 4768, 73 4770, 74} 75TheApp.animation_manager:setMarker(animation_numbers, {-1.05, -0.05}) 76 77local patient_clothes_state = permanent"action_use_screen_patient_clothes_state"( function(humanoid) 78 humanoid.user_of:setAnimation(1204) 79 humanoid.user_of:setLayer(1, humanoid.layers[1]) 80 return finish(humanoid) 81end) 82 83local normal_state = permanent"action_use_screen_normal_state"( function(humanoid) 84 humanoid.user_of:setAnimation(1022) 85 humanoid.user_of:setLayer(1, 0) 86 return finish(humanoid) 87end) 88 89local surgical_state = permanent"action_use_screen_surgical_state"( function(humanoid) 90 local screen = humanoid.user_of 91 if screen.num_green_outfits > 0 then 92 if screen.num_white_outfits > 0 then 93 screen:setAnimation(2776) 94 else 95 screen:setAnimation(2772) 96 end 97 else 98 screen:setAnimation(2774) 99 end 100 return finish(humanoid) 101end) 102 103local function action_use_screen_start(action, humanoid) 104 local screen = action.object 105 local class = humanoid.humanoid_class 106 local anim, when_done 107 local is_surgical = not not screen.num_green_outfits 108 local change_to = math.random(1, 3) 109 if class == "Elvis Patient" then 110 anim, when_done = 946, finish 111 humanoid:setType "Standard Male Patient" 112 humanoid:setLayer(0, 2) 113 humanoid:setLayer(1, math.random(0, 3) * 2) 114 humanoid:setLayer(2, 2) 115 elseif class == "Stripped Male Patient" then 116 humanoid:setType "Standard Male Patient" 117 anim, when_done = 1052, normal_state 118 elseif class == "Stripped Female Patient" then 119 humanoid:setType "Standard Female Patient" 120 anim, when_done = 2844, normal_state 121 elseif class == "Stripped Male Patient 2" then 122 humanoid:setType "Standard Male Patient" 123 anim, when_done = 1052, normal_state 124 elseif class == "Stripped Female Patient 2" then 125 humanoid:setType "Standard Female Patient" 126 anim, when_done = 2844, normal_state 127 elseif class == "Stripped Male Patient 3" then 128 humanoid:setType "Standard Male Patient" 129 anim, when_done = 1052, normal_state 130 elseif class == "Stripped Female Patient 3" then 131 humanoid:setType "Standard Female Patient" 132 anim, when_done = 2844, normal_state 133 elseif class == "Gowned Male Patient" then 134 humanoid:setType "Standard Male Patient" 135 anim, when_done = 4768, finish 136 elseif class == "Gowned Female Patient" then 137 humanoid:setType "Standard Female Patient" 138 anim, when_done = 4770, finish 139 elseif class == "Standard Male Patient" then 140 if is_surgical then 141 humanoid:setType "Gowned Male Patient" 142 anim, when_done = 4760, finish 143 else 144 if change_to == 1 then 145 humanoid:setType "Stripped Male Patient" 146 anim, when_done = 1048, patient_clothes_state 147 elseif change_to == 2 then 148 humanoid:setType "Stripped Male Patient 2" 149 anim, when_done = 1048, patient_clothes_state 150 else 151 humanoid:setType "Stripped Male Patient 3" 152 anim, when_done = 1048, patient_clothes_state 153 end 154 end 155 elseif class == "Standard Female Patient" then 156 if is_surgical then 157 humanoid:setType "Gowned Female Patient" 158 anim, when_done = 4762, finish 159 else 160 if change_to == 1 then 161 humanoid:setType "Stripped Female Patient" 162 anim, when_done = 2848, patient_clothes_state 163 elseif change_to == 2 then 164 humanoid:setType "Stripped Female Patient 2" 165 anim, when_done = 2848, patient_clothes_state 166 else 167 humanoid:setType "Stripped Female Patient 3" 168 anim, when_done = 2848, patient_clothes_state 169 end 170 end 171 elseif class == "Doctor" then 172 humanoid:setType "Surgeon" 173 when_done = surgical_state 174 if screen.num_white_outfits > 0 then 175 if screen.num_green_outfits > 1 then 176 anim = 2780 177 else 178 anim = 2784 179 end 180 else 181 anim = 2782 182 end 183 screen.num_green_outfits = screen.num_green_outfits - 1 184 screen.num_white_outfits = screen.num_white_outfits + 1 185 elseif class == "Surgeon" then 186 humanoid:setType "Doctor" 187 when_done = surgical_state 188 if screen.num_green_outfits > 0 then 189 if screen.num_white_outfits > 1 then 190 anim = 2796 191 else 192 anim = 2790 193 end 194 else 195 anim = 2792 196 end 197 screen.num_green_outfits = screen.num_green_outfits + 1 198 screen.num_white_outfits = screen.num_white_outfits - 1 199 else 200 error(class .. " trying to use screen") 201 end 202 203 humanoid:setAnimation(anim) 204 local mood_info = humanoid.mood_info 205 humanoid.mood_info = nil -- Do not move mood_info 206 humanoid:setTile(screen:getRenderAttachTile()) 207 local offset = screen.object_type.orientations[screen.direction].animation_offset 208 humanoid:setPosition(offset[1], offset[2]) 209 humanoid.mood_info = mood_info 210 humanoid:setSpeed(0, 0) 211 humanoid:setTimer(humanoid.world:getAnimLength(anim), when_done) 212 213 screen:setUser(humanoid) 214 humanoid.user_of = screen 215 action.must_happen = true 216 217 if action.todo_interrupt == "high" then 218 humanoid:setTimer(nil) 219 when_done(humanoid) 220 end 221end 222 223return action_use_screen_start 224