| 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 "StaffReceptionAction" (HumanoidAction) |
| 22 |
|
| 23 |
---@type StaffReceptionAction |
| 24 |
local StaffReceptionAction = _G["StaffReceptionAction"] |
| 25 |
|
| 26 |
-- Action class for the "staff reception desk" action. |
| 27 |
--!param desk (object) Desk to staff. |
| 28 |
function StaffReceptionAction:StaffReceptionAction(desk) |
| 29 |
assert(class.is(desk, ReceptionDesk), "Invalid value for parameter 'desk'") -- luacheck: ignore 113 |
| 30 |
|
| 31 |
self:HumanoidAction("staff_reception") |
| 32 |
self.object = desk -- Reception desk object. |
| 33 |
self:setMustHappen(true) |
| 34 |
end |
| 35 |
|
| 36 |
local action_staff_reception_interrupt = permanent"action_staff_reception_interrupt"( function(action, humanoid, high_priority) |
| 37 |
local object = action.object |
| 38 |
object.receptionist = nil |
| 39 |
if not object.being_destroyed then -- don't look for replacement if desk was picked up |
| 40 |
object:checkForNearbyStaff() |
| 41 |
end |
| 42 |
humanoid.associated_desk = nil |
| 43 |
local dx, dy = object:getSecondaryUsageTile() |
| 44 |
if high_priority then |
| 45 |
humanoid:setTilePositionSpeed(dx, dy) |
| 46 |
humanoid:finishAction() |
| 47 |
else |
| 48 |
HumanoidRawWalk(humanoid, humanoid.tile_x, humanoid.tile_y, dx, dy, nil, |
| 49 |
--[[persistable:action_staff_reception_walk]] function() |
| 50 |
humanoid:setTilePositionSpeed(dx, dy) |
| 51 |
humanoid:finishAction() |
| 52 |
end) |
| 53 |
end |
| 54 |
end) |
| 55 |
|
| 56 |
local action_staff_reception_idle_phase = permanent"action_staff_reception_idle_phase"( function(humanoid) |
| 57 |
local action = humanoid:getCurrentAction() |
| 58 |
local direction = humanoid.last_move_direction |
| 59 |
local anims = humanoid.walk_anims |
| 60 |
local object = action.object |
| 61 |
if direction == "north" then |
| 62 |
humanoid:setAnimation(anims.idle_north, 0) |
| 63 |
elseif direction == "east" then |
| 64 |
humanoid:setAnimation(anims.idle_east, 0) |
| 65 |
elseif direction == "south" then |
| 66 |
humanoid:setAnimation(anims.idle_east, 1) |
| 67 |
elseif direction == "west" then |
| 68 |
humanoid:setAnimation(anims.idle_north, 1) |
| 69 |
end |
| 70 |
humanoid:setTilePositionSpeed(object.tile_x, object.tile_y) |
| 71 |
object.receptionist = humanoid |
| 72 |
object.reserved_for = nil |
| 73 |
object.th:makeVisible() |
| 74 |
if direction == "north" or direction == "west" then |
| 75 |
-- Place desk behind receptionist in render order (they are on the same tile) |
| 76 |
local map, x, y = object.th:getTile() |
| 77 |
object.th:setTile(map, x, y, object:getDrawingLayer()) |
| 78 |
end |
| 79 |
if action.on_interrupt then |
| 80 |
action.on_interrupt = action_staff_reception_interrupt |
| 81 |
else |
| 82 |
action_staff_reception_interrupt(action, humanoid) |
| 83 |
end |
| 84 |
end) |
| 85 |
|
| 86 |
local action_staff_reception_interrupt_early = permanent"action_staff_reception_interrupt_early"( function(action, humanoid, high_priority) |
| 87 |
if high_priority then |
| 88 |
action.object.reserved_for = nil |
| 89 |
humanoid.associated_desk:checkForNearbyStaff() |
| 90 |
humanoid.associated_desk = nil |
| 91 |
humanoid:setTimer(nil) |
| 92 |
humanoid:setTilePositionSpeed(action.object:getSecondaryUsageTile()) |
| 93 |
humanoid:finishAction() |
| 94 |
end |
| 95 |
end) |
| 96 |
|
| 97 |
local function action_staff_reception_start(action, humanoid) |
| 98 |
if action.todo_interrupt then |
| 99 |
humanoid.associated_desk.reserved_for = nil |
| 100 |
humanoid.associated_desk:checkForNearbyStaff() |
| 101 |
humanoid.associated_desk = nil |
| 102 |
humanoid:finishAction(action) |
| 103 |
return |
| 104 |
end |
| 105 |
local object = action.object |
| 106 |
HumanoidRawWalk(humanoid, humanoid.tile_x, humanoid.tile_y, |
| 107 |
object.tile_x, object.tile_y, nil, action_staff_reception_idle_phase) |
| 108 |
action.must_happen = true |
| 109 |
action.on_interrupt = action_staff_reception_interrupt_early |
| 110 |
end |
| 111 |
|
| 112 |
return action_staff_reception_start |