mirror of
https://github.com/Qsgs-Fans/FreeKill.git
synced 2024-11-16 11:42:45 +08:00
9ac89caa1f
* android: dont copy RSA key and test.lua(generated by fkp) * remove debug code * ai think * fixbug: 100% cpu per thread * init ai * fix bug, next step is to remove all feasible * remame vscode -> lsp * add some lsp comment * rewrite feasible * Random AI * fixbug: chooseplayer * liuli * move checkNoHuman to waitForAiReply * prototype for cardLimitation skill * add Exppattern:Parse to static.lua * remove unnecessary static
44 lines
1017 B
Lua
44 lines
1017 B
Lua
-- AI base class.
|
|
-- Do nothing.
|
|
|
|
---@class AI: Object
|
|
---@field room Room
|
|
---@field player ServerPlayer
|
|
---@field command string
|
|
---@field jsonData string
|
|
---@field cb_table table<string, fun(jsonData: string)>
|
|
local AI = class("AI")
|
|
|
|
function AI:initialize(player)
|
|
self.room = RoomInstance
|
|
self.player = player
|
|
local cb_t = {}
|
|
-- default strategy: print command and data, then return ""
|
|
setmetatable(cb_t, {
|
|
__index = function()
|
|
return function()
|
|
print(self.command, self.jsonData)
|
|
return ""
|
|
end
|
|
end,
|
|
})
|
|
self.cb_table = cb_t
|
|
end
|
|
|
|
function AI:readRequestData()
|
|
self.command = self.player.ai_data.command
|
|
self.jsonData = self.player.ai_data.jsonData
|
|
end
|
|
|
|
function AI:makeReply()
|
|
Self = self.player
|
|
local start = os.getms()
|
|
local ret = self.cb_table[self.command] and self.cb_table[self.command](self, self.jsonData) or "__cancel"
|
|
local to_delay = 500 - (os.getms() - start) / 1000
|
|
print(to_delay)
|
|
self.room:delay(to_delay)
|
|
return ret
|
|
end
|
|
|
|
return AI
|