-
Notifications
You must be signed in to change notification settings - Fork 0
/
isolation_chamber.ttslua
68 lines (62 loc) · 2.12 KB
/
isolation_chamber.ttslua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function onLoad()
PRISON_SCRIPTING_ZONE_GUID = "9f1776"
STATUS_PYRAMID_GUID = "92bc43"
NO_ONE = color(0, 0, 0, 0)
ISOLATED_PLAYER = NO_ONE
status_pyramid = getObjectFromGUID(STATUS_PYRAMID_GUID)
status_pyramid.setColorTint(NO_ONE)
update_prison_status_pyramid()
end
function onObjectEnterScriptingZone(zone, enter_object)
if zone.getGUID() ~= PRISON_SCRIPTING_ZONE_GUID then return end
if not object_is_player_token(enter_object) then
printToAll("Objects like that can't be prisoners.")
return false
elseif ISOLATED_PLAYER ~= NO_ONE then
printToAll(ISOLATED_PLAYER .. [[ is already a prisoner!]])
return false
elseif zone.getGUID() ~= PRISON_SCRIPTING_ZONE_GUID then
return
else
prisoner_color = enter_object.getName()
set_isolated_player(prisoner_color)
update_prison_status_pyramid()
return true
end
end
function set_isolated_player(str)
-- consumes a string representing a player-color and updates
-- the global variable ISOLATED_PLAYER
ISOLATED_PLAYER = str
return ISOLATED_PLAYER
end
function update_prison_status_pyramid()
-- consumes nothing and updates the prison status pyramid to match
-- the current ISOLATED_PLAYER
status_pyramid.setColorTint(ISOLATED_PLAYER)
return true
end
function onObjectLeaveScriptingZone(zone, leave_object)
if zone.getGUID() ~= PRISON_SCRIPTING_ZONE_GUID then
return false
end
if not object_is_player_token(leave_object) then
return false
end
if not playerIsCurrentlyImprisonedP(leave_object.getName()) then
return false
end
ISOLATED_PLAYER = NO_ONE
update_prison_status_pyramid()
return true
end
function playerIsCurrentlyImprisonedP(player_color)
-- consumes a player-color and produces 'true' if that player is currently
-- imprisoned, false otherwise.
return player_color == ISOLATED_PLAYER
end
function object_is_player_token(obj)
-- consumes whatever object and produces 'true' if the object is
-- a player token, false otherwise
return obj.getDescription() == "Player token"
end