-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
276 lines (238 loc) · 7.9 KB
/
main.lua
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
STRICT = true
DEBUG = true
config = require 'config'
configBaseDir = {}
table.insert(configBaseDir, "./");
table.insert(configBaseDir, love.filesystem.getSaveDirectory() .. "/");
--assert(false, love.filesystem.getSaveDirectory())
function findFile(file, dirs)
if file then
for k,v in pairs(dirs) do
local f = v .. file
if f then
local h = io.open(f)
if h then
io.close(h)
return f
end
end
end
end
return nil
end
function readConfig(file)
local f = findFile(file, configBaseDir)
if not f then f = findFile("localconfig.lua", configBaseDir) end
assert(f, "no config found, please place your config at:\n" .. love.filesystem.getSaveDirectory() .. "/localconfig.lua")
print("using config file", f)
local h = io.open(f)
local s = h:read("*a")
io.close(h)
return loadstring(s)()
end
localconfig = readConfig(arg[2])
--require "enet"
love.graphics.setMode(localconfig.screenWidth, localconfig.screenHeight, localconfig.fullscreen)
local luaPrint = print
print = function (...)
if not config or config.show_prints then
luaPrint(...)
end
end
if arg[#arg] == "-debug" then require("mobdebug").start() end
-- local profiler = require 'profiler'
--~ profiler.start('profile.out')
require 'zoetrope'
vector = require 'vector'
str = require 'str'
storage = require 'storage'
collision = require 'collision'
utils = require 'utils'
input = require 'input'
profile = require 'profile'
list = require 'list'
json = require 'dkjson'
bson = require 'bson'
--~ action_definitions = require 'action_definitions'
object_manager = require 'object_manager'
--~ action_handling = require 'action_handling'
tools = require 'tools'
--~ require 'actions'
--~ require 'audio'
require 'network'
require 'debug_utils'
require 'GameObject'
require 'GameObjectCommons'
--~ require 'FogOfWarObject'
require 'MonitorChanges'
--~ require 'Buffs'
--~ require 'Skill'
--~ require 'SkillIcon'
--~ require 'SkillBar'
--~ require 'TargetDummy'
--~ require 'Character'
--~ require 'Ghost'
--~ require 'Player'
--~ require 'Npc'
--~ require 'FocusSprite'
--~ require 'Projectile'
require 'GameView'
require 'TestView'
require 'PhaseManager'
require 'Clan'
require 'Character'
--~ require 'Footstep'
--~ require 'Barrier'
--~ require 'Ressource'
require 'ConnectView'
--~ require 'Effect'
--~ require 'EffectCircle'
--~ require 'EffectImage'
--~ require 'Arrow'
require 'ui'
require 'loveframes'
require 'Character'
require 'Camp'
require 'Ressource'
require 'Sidebar'
require 'City'
require 'Treasure'
-- stats ----------------------------
gameStats = storage.load("stats.json") or {}
gameStatsInc = function (key, inc)
inc = inc or 1
gameStats[key] = (gameStats[key] or 0) + inc
end
gameStatsSet = function (key, val)
gameStats[key] = val
end
gameStatsInc("times_started")
-- ------------------------------------
function track(event, ...)
network.send({channel = "server", cmd = "track", event = event, params = list.concat({network.client_id}, {...})})
end
the.app = App:new
{
deactivateOnBlur = false,
numGamepads = love.joystick and 1 or 0,
name = "Combat Prototype",
icon = '/graphics/icon.png',
running = true,
onUpdate = function (self, elapsed)
collectgarbage("step", 1)
profile.start("network.update")
network.update(elapsed)
profile.stop()
-- set input mode
if the.keys:justPressed ("f1") then print("input mode: mouse+keyboard") input.setMode (input.MODE_MOUSE_KEYBOARD) end
--~ if the.keys:justPressed ("f2") then
--~ switchBetweenGhostAndPlayer()
--~ end
--~ if the.keys:justPressed ("f3") then
--~ local l = object_manager.find_where(function(oid, o)
--~ return o.class and NetworkSyncedObjects[o.class]
--~ end)
--~ for _,o in pairs(l) do o:die() end
--~ end
-- show the highscore table
if the.keys:justPressed (localconfig.showHighscore) then the.barrier:showHighscore() end
-- resync
if the.keys:justPressed ("f7") then the.app.view:resyncAllLocalObjects() end
-- show object list
if the.keys:justPressed ("f8") then config.show_object_list = not config.show_object_list end
-- show Fog of War
--~ if the.keys:justPressed ("f9") then config.show_fog_of_war = true the.app.view:fogOn() end
-- toggle fullscreen
if the.keys:justPressed (localconfig.toggleFullscreen) then self:toggleFullscreen() end
-- toggle profile
if not the.keys:pressed("lctrl") and the.keys:justPressed ("f11") then config.show_profile_info = not config.show_profile_info end
-- toggle debug draw
if not the.keys:pressed("lctrl") and the.keys:justPressed ("f12") then config.draw_debug_info = not config.draw_debug_info end
-- admin
if the.keys:pressed("lctrl") and the.keys:justPressed ("f11") then
if the.phaseManager then object_manager.send(the.phaseManager.oid, "force_next_phase") end
end
if the.keys:pressed("lctrl") and the.keys:justPressed ("f12") then
network.send({channel = "server", cmd = "restart", password = localconfig.adminPassword })
end
-- easy exit
if the.keys:justPressed(localconfig.quitGame) then
if not the.quitGameButton then
-- make me a frame
the.buttonFrame = loveframes.Create("frame")
the.buttonFrame:SetSize(200, 50)
the.buttonFrame:Center()
the.buttonFrame:SetName("Do you really want to quit?")
-- make me a quit button
the.quitGameButton = loveframes.Create("button")
the.quitGameButton:SetSize(100, 25)
the.quitGameButton:SetPos(love.graphics.getWidth() / 2 - 100, love.graphics.getHeight() / 2)
the.quitGameButton:SetText("Yes, quit the game")
the.quitGameButton.OnClick = function(object)
--~ profiler.stop()
track("client_quit")
network.send({channel = "server", cmd = "bye"})
-- wait a little bit to ensure bye delivery
local t = love.timer.getTime()
while love.timer.getTime() - t < 1 do
network.update(1)
end
network.shutdown()
if the.phaseManager and the.phaseManager.storePlayerState then
print("STORE STATE")
the.phaseManager:storePlayerState()
end
if gameStats then storage.save("stats.json", gameStats) end
os.exit()
end
-- make me a cancel button
the.cancelButton = loveframes.Create("button")
the.cancelButton:SetSize(100, 25)
the.cancelButton:SetPos(love.graphics.getWidth() / 2, love.graphics.getHeight() / 2)
the.cancelButton:SetText("Nope")
the.cancelButton.OnClick = function(object)
the.buttonFrame:Remove()
the.buttonFrame = nil
the.quitGameButton:Remove()
the.quitGameButton = nil
the.cancelButton:Remove()
the.cancelButton = nil
end
else
the.buttonFrame:Remove()
the.buttonFrame = nil
the.quitGameButton:Remove()
the.quitGameButton = nil
the.cancelButton:Remove()
the.cancelButton = nil
end
end
--~ if the.player then
--~ print("ZONE", the.player.zone, "ZONES", json.encode(the.player.zones))
--~ end
end,
onRun = function (self)
self:useSysCursor(true)
network.connect(config.server_hostname, config.server_port)
--~ the.app.console:watch("viewx", "the.app.view.translate.x")
--~ the.app.console:watch("viewy", "the.app.view.translate.y")
-- setup connect view
self.view = ConnectView:new()
-- overload to disable drawing
local oldDraw = self.draw
self.draw = function()
if localconfig.is_bot and not config.draw_debug_info then
-- nop
else
love.graphics.push()
local m = math.min(love.graphics.getWidth(), love.graphics.getHeight())
local f = m/1024
-- global
inputScale = 1/f
love.graphics.scale( f, f )
oldDraw(self)
love.graphics.pop()
end
end
end,
}