2023-04-09 13:35:35 +08:00
|
|
|
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2023-04-12 20:51:09 +08:00
|
|
|
|
-- 用于初始化FreeKill的最基本脚本
|
|
|
|
|
-- 向Lua虚拟机中加载库、游戏中的类,以及加载Mod等等。
|
2022-01-24 10:23:08 +08:00
|
|
|
|
|
2023-04-12 20:51:09 +08:00
|
|
|
|
-- 加载第三方库
|
2024-06-10 15:19:47 +08:00
|
|
|
|
package.path = "./?.lua;./?/init.lua;./lua/lib/?.lua;./lua/?.lua"
|
2022-01-24 10:23:08 +08:00
|
|
|
|
|
2023-04-12 20:51:09 +08:00
|
|
|
|
-- middleclass: 轻量级的面向对象库
|
2022-03-25 12:28:07 +08:00
|
|
|
|
class = require "middleclass"
|
2023-04-12 20:51:09 +08:00
|
|
|
|
|
|
|
|
|
-- json: 提供json处理支持,能解析JSON和生成JSON
|
2024-04-19 20:53:19 +08:00
|
|
|
|
-- 仍借助luajson处理简单类型。
|
|
|
|
|
local luajson = require "json"
|
|
|
|
|
json = {
|
|
|
|
|
encode = function(val, t)
|
|
|
|
|
if type(val) ~= "table" then return luajson.encode(val) end
|
|
|
|
|
t = t or 1 -- Compact
|
|
|
|
|
---@diagnostic disable-next-line
|
|
|
|
|
local doc = fk.QJsonDocument_fromVariant(val)
|
|
|
|
|
local ret = doc:toJson(t)
|
|
|
|
|
return ret
|
|
|
|
|
end,
|
|
|
|
|
decode = function(str)
|
|
|
|
|
if str == "null" then return nil end
|
|
|
|
|
local start = str:sub(1, 1)
|
|
|
|
|
if start ~= "[" and start ~= "{" then
|
|
|
|
|
return luajson.decode(str)
|
|
|
|
|
end
|
|
|
|
|
---@diagnostic disable-next-line
|
|
|
|
|
local doc = fk.QJsonDocument_fromJson(str)
|
|
|
|
|
local ret = doc:toVariant()
|
|
|
|
|
-- if ret == "" then ret = luajson.decode(str) end
|
|
|
|
|
return ret
|
|
|
|
|
end,
|
|
|
|
|
}
|
2022-03-30 16:33:56 +08:00
|
|
|
|
|
2023-04-12 20:51:09 +08:00
|
|
|
|
-- 初始化随机数种子
|
|
|
|
|
math.randomseed(os.time())
|
|
|
|
|
|
|
|
|
|
-- 加载实用类,让Lua编写起来更轻松。
|
2023-04-13 20:17:39 +08:00
|
|
|
|
local Utils = require "core.util"
|
2023-11-07 12:57:00 +08:00
|
|
|
|
-- TargetGroup, AimGroup, Util = table.unpack(Utils)
|
|
|
|
|
TargetGroup, AimGroup, Util = Utils[1], Utils[2], Utils[3]
|
2022-04-01 20:51:01 +08:00
|
|
|
|
dofile "lua/core/debug.lua"
|
2022-03-31 13:29:23 +08:00
|
|
|
|
|
2023-04-12 20:51:09 +08:00
|
|
|
|
-- 加载游戏核心类
|
2022-03-30 14:14:40 +08:00
|
|
|
|
Engine = require "core.engine"
|
|
|
|
|
Package = require "core.package"
|
|
|
|
|
General = require "core.general"
|
|
|
|
|
Card = require "core.card"
|
2023-01-16 19:13:07 +08:00
|
|
|
|
Exppattern = require "core.exppattern"
|
2022-03-30 14:14:40 +08:00
|
|
|
|
Skill = require "core.skill"
|
2023-01-29 18:11:41 +08:00
|
|
|
|
UsableSkill = require "core.skill_type.usable_skill"
|
|
|
|
|
StatusSkill = require "core.skill_type.status_skill"
|
2022-03-30 14:14:40 +08:00
|
|
|
|
Player = require "core.player"
|
2023-03-14 00:12:02 +08:00
|
|
|
|
GameMode = require "core.game_mode"
|
2024-10-22 00:10:53 +08:00
|
|
|
|
AbstractRoom = require "core.room.abstract_room"
|
|
|
|
|
RequestHandler = require "core.request_handler"
|
2023-04-05 00:49:54 +08:00
|
|
|
|
UI = require "ui-util"
|
2022-03-25 12:28:07 +08:00
|
|
|
|
|
2023-04-12 20:51:09 +08:00
|
|
|
|
-- 读取配置文件。
|
|
|
|
|
-- 因为io马上就要被禁用了,所以赶紧先在这里读取配置文件。
|
2023-02-27 10:23:48 +08:00
|
|
|
|
local function loadConf()
|
2024-06-10 15:19:47 +08:00
|
|
|
|
local new_core = FileIO.pwd():endsWith("packages/freekill-core")
|
|
|
|
|
|
|
|
|
|
local cfg = io.open((new_core and "../../" or "") .. "freekill.client.config.json")
|
2023-02-27 10:23:48 +08:00
|
|
|
|
local ret
|
|
|
|
|
if cfg == nil then
|
|
|
|
|
ret = {
|
|
|
|
|
language = "zh_CN",
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ret = json.decode(cfg:read("a"))
|
|
|
|
|
cfg:close()
|
|
|
|
|
end
|
|
|
|
|
return ret
|
|
|
|
|
end
|
|
|
|
|
Config = loadConf()
|
|
|
|
|
|
2023-04-12 20:51:09 +08:00
|
|
|
|
-- 禁用各种危险的函数,尽可能让Lua执行安全的代码。
|
2024-11-09 19:27:41 +08:00
|
|
|
|
os = {
|
2023-03-14 20:50:36 +08:00
|
|
|
|
time = os.time,
|
|
|
|
|
date = os.date,
|
|
|
|
|
clock = os.clock,
|
|
|
|
|
difftime = os.difftime,
|
|
|
|
|
getms = os.getms,
|
|
|
|
|
}
|
2024-11-09 19:27:41 +08:00
|
|
|
|
io = {
|
|
|
|
|
lines = io.lines
|
|
|
|
|
}
|
2023-03-14 20:50:36 +08:00
|
|
|
|
package = nil
|
2024-11-09 19:27:41 +08:00
|
|
|
|
-- load = nil
|
2023-03-14 20:50:36 +08:00
|
|
|
|
loadfile = nil
|
2023-04-30 18:51:05 +08:00
|
|
|
|
local _dofile = dofile
|
|
|
|
|
dofile = function(f)
|
|
|
|
|
local errmsg = "Refusing dofile that not in game directory"
|
|
|
|
|
assert(not f:startsWith("/"), errmsg)
|
|
|
|
|
assert(not f:startsWith(".."), errmsg)
|
|
|
|
|
assert(not f:find(":"), errmsg)
|
|
|
|
|
return _dofile(f)
|
|
|
|
|
end
|
2023-02-27 10:23:48 +08:00
|
|
|
|
|
2023-04-12 20:51:09 +08:00
|
|
|
|
-- 初始化Engine类并置于Fk全局变量中,这里会加载拓展包
|
2022-03-31 13:29:23 +08:00
|
|
|
|
dofile "lua/fk_ex.lua"
|
2022-03-28 22:24:30 +08:00
|
|
|
|
Fk = Engine:new()
|