-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.script
161 lines (123 loc) · 4.26 KB
/
player.script
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
local input = require "input.input"
local h = require "utilities.h"
local pathfinder = require "utilities.pathfinder"
local guest_manager = require "guest.guest_manager"
local party_supplies = require "party_supplies.party_supplies"
go.property("allow_actions", true)
local function manage_direction(self)
position = go.get_position()
sprite.set_hflip("#sprite", position.x > self.previous_position.x)
self.previous_position = position
end
local function manage_anim(self)
local anim = h.IDLE
if pathfinder.is_walk_in_progress(self.my_id) then
anim = h.WALK
end
if anim ~= self.anim then
msg.post("#sprite", "play_animation", {id = anim})
end
self.anim = anim
end
local function check_for_action_trigger(self)
if self.queued_action == h.TALK then
msg.post("ui", "action", {action_id = self.queued_action, icon_id = party_supplies.icon_ids[self.queued_action], action_time = party_supplies.action_times[self.queued_action]})
self.queued_action = nil
else
local position = go.get_position()
if vmath.length_sqr(party_supplies.positions[self.queued_action] - position) < 10 and pathfinder.get_location(position) == party_supplies.locations[self.queued_action] then
msg.post("ui", "action", {action_id = self.queued_action, icon_id = party_supplies.icon_ids[self.queued_action], action_time = party_supplies.action_times[self.queued_action]})
self.allow_actions = false
self.queued_action = nil
end
end
end
local function check_for_guest_trigger(self)
if not self.allow_actions then
return
end
local guest_position = go.get_position(self.guest_target)
local position = go.get_position()
if vmath.length_sqr(guest_position - position) < 10 and pathfinder.get_location(position) == pathfinder.get_location(guest_position) then
msg.post("ui", "load_character", {object = self.guest_target})
self.allow_actions = false
end
end
local function complete_action(self, action_id)
if action_id == h.COCKTAIL then
party_supplies.make_cocktail()
elseif action_id == h.BOTTLE then
party_supplies.replenish_drink_stocks()
elseif action_id == h.MUSIC then
party_supplies.switch_music()
elseif action_id == h.TALK then
print("talk completed")
if self.guest_target then
msg.post("guest_runner", "release_target", {id = self.guest_target})
self.guest_target = nil
end
elseif action_id == h.PHONE then
party_supplies.request_powder()
elseif action_id == h.POWDER then
party_supplies.collect_powder()
end
end
function init(self)
party_supplies.set_variables()
self.my_id = go.get_id()
self.previous_position = go.get_position()
self.walk_speed = pathfinder.walk_speed * 3
go.set("#sprite", "blend", vmath.vector4(1,0.8,0.2,1))
self.allow_actions = true
--hide phone in beginning
msg.post("ui", "hide_button", {id = h.PHONE, hide_immediately = true})
end
function final(self)
end
function update(self, dt)
if input.check(h.MOUSE_BUTTON_RIGHT).pressed and self.allow_actions then
pathfinder.walk_to(self.my_id, go.get_position(), input.mouse_location, false, self.walk_speed)
if self.queued_action then
self.queued_action = nil
end
if self.guest_target then
msg.post("guest_runner", "release_target", {id = self.guest_target})
self.guest_target = nil
end
end
manage_anim(self)
manage_direction(self)
if self.queued_action then
check_for_action_trigger(self)
end
if self.guest_target then
check_for_guest_trigger(self)
end
end
function on_message(self, message_id, message, sender)
if message_id == h.GO_TO then
if self.allow_actions then
pathfinder.walk_to(self.my_id, go.get_position(), message.position, true, self.walk_speed)
end
elseif message_id == h.QUEUED_ACTION then
if self.allow_actions then
self.queued_action = message.action
end
elseif message_id == h.ACTION_COMPLETE then
self.allow_actions = true
complete_action(self, message.action_id)
elseif message_id == h.GUEST_TARGET then
self.guest_target = message.id
elseif message_id == h.GUEST_COMPLETE then
if self.queued_action ~= h.TALK then
self.allow_actions = true
msg.post("guest_runner", "release_target", {id = self.guest_target})
self.guest_target = nil
end
elseif message_id == h.TRIGGER_TALK then
self.queued_action = h.TALK
if self.guest_target then
guest_manager.guests[self.guest_target].talk = 100
end
end
end