2023-04-09 13:35:35 +08:00
|
|
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-04-14 18:22:00 +08:00
|
|
|
---@class Client
|
2023-03-26 17:32:45 +08:00
|
|
|
---@field public client fk.Client
|
2023-09-27 21:02:22 +08:00
|
|
|
---@field public players ClientPlayer[] @ 所有参战玩家的数组
|
|
|
|
---@field public alive_players ClientPlayer[] @ 所有存活玩家的数组
|
|
|
|
---@field public observers ClientPlayer[] @ 观察者的数组
|
|
|
|
---@field public current ClientPlayer @ 当前回合玩家
|
|
|
|
---@field public discard_pile integer[] @ 弃牌堆
|
|
|
|
---@field public status_skills Skill[] @ 状态技总和
|
2023-12-06 21:07:35 +08:00
|
|
|
---@field public banners table<string, any> @ 左上角显示的东西
|
2023-06-27 16:50:24 +08:00
|
|
|
---@field public observing boolean
|
2022-03-28 22:24:30 +08:00
|
|
|
Client = class('Client')
|
|
|
|
|
|
|
|
-- load client classes
|
2022-03-30 14:14:40 +08:00
|
|
|
ClientPlayer = require "client.clientplayer"
|
2022-01-24 10:23:08 +08:00
|
|
|
|
2022-03-31 13:29:23 +08:00
|
|
|
fk.client_callback = {}
|
2022-01-24 10:23:08 +08:00
|
|
|
|
2023-06-20 13:37:03 +08:00
|
|
|
-- 总而言之就是会让roomScene.state变为responding或者playing的状态
|
|
|
|
local pattern_refresh_commands = {
|
|
|
|
"PlayCard",
|
|
|
|
"AskForUseActiveSkill",
|
|
|
|
"AskForUseCard",
|
|
|
|
"AskForResponseCard",
|
|
|
|
}
|
|
|
|
|
2022-01-24 10:23:08 +08:00
|
|
|
function Client:initialize()
|
2022-04-30 15:27:56 +08:00
|
|
|
self.client = fk.ClientInstance
|
|
|
|
self.notifyUI = function(self, command, jsonData)
|
|
|
|
fk.Backend:emitNotifyUI(command, jsonData)
|
|
|
|
end
|
2023-06-27 16:50:24 +08:00
|
|
|
self.client.callback = function(_self, command, jsonData, isRequest)
|
2023-08-01 21:01:01 +08:00
|
|
|
if self.recording then
|
|
|
|
table.insert(self.record, {math.floor(os.getms() / 1000), isRequest, command, jsonData})
|
2023-06-27 16:50:24 +08:00
|
|
|
end
|
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
local cb = fk.client_callback[command]
|
2023-04-10 15:55:06 +08:00
|
|
|
|
2023-06-20 13:37:03 +08:00
|
|
|
if table.contains(pattern_refresh_commands, command) then
|
2023-06-07 13:01:19 +08:00
|
|
|
Fk.currentResponsePattern = nil
|
|
|
|
Fk.currentResponseReason = nil
|
|
|
|
end
|
2023-04-10 15:55:06 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
if (type(cb) == "function") then
|
|
|
|
cb(jsonData)
|
|
|
|
else
|
|
|
|
self:notifyUI(command, jsonData);
|
2022-01-24 10:23:08 +08:00
|
|
|
end
|
2022-04-30 15:27:56 +08:00
|
|
|
end
|
2022-03-28 22:24:30 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
self.players = {} -- ClientPlayer[]
|
2022-09-14 13:01:10 +08:00
|
|
|
self.alive_players = {}
|
2023-02-15 19:54:35 +08:00
|
|
|
self.observers = {}
|
2022-09-14 13:01:10 +08:00
|
|
|
self.discard_pile = {}
|
2023-01-04 14:21:29 +08:00
|
|
|
self.status_skills = {}
|
|
|
|
for class, skills in pairs(Fk.global_status_skill) do
|
|
|
|
self.status_skills[class] = {table.unpack(skills)}
|
|
|
|
end
|
2023-06-16 13:26:02 +08:00
|
|
|
|
2023-12-06 21:07:35 +08:00
|
|
|
self.banners = {}
|
|
|
|
|
2023-06-23 22:18:11 +08:00
|
|
|
self.skill_costs = {}
|
|
|
|
self.card_marks = {}
|
|
|
|
self.filtered_cards = {}
|
2023-08-11 03:19:59 +08:00
|
|
|
self.printed_cards = {}
|
2023-06-16 13:26:02 +08:00
|
|
|
self.disabled_packs = {}
|
|
|
|
self.disabled_generals = {}
|
2023-06-27 16:50:24 +08:00
|
|
|
|
|
|
|
self.recording = false
|
2022-01-24 10:23:08 +08:00
|
|
|
end
|
|
|
|
|
2022-04-14 18:22:00 +08:00
|
|
|
---@param id integer
|
|
|
|
---@return ClientPlayer
|
2022-09-14 13:01:10 +08:00
|
|
|
function Client:getPlayerById(id)
|
2023-06-16 23:04:31 +08:00
|
|
|
if id == Self.id then return Self end
|
2022-04-30 15:27:56 +08:00
|
|
|
for _, p in ipairs(self.players) do
|
2022-09-14 13:01:10 +08:00
|
|
|
if p.id == id then return p end
|
2022-04-30 15:27:56 +08:00
|
|
|
end
|
|
|
|
return nil
|
2022-04-14 18:22:00 +08:00
|
|
|
end
|
|
|
|
|
2023-01-29 18:11:41 +08:00
|
|
|
---@param cardId integer | card
|
|
|
|
---@return CardArea
|
|
|
|
function Client:getCardArea(cardId)
|
|
|
|
if type(cardId) ~= "number" then
|
|
|
|
assert(cardId and cardId:isInstanceOf(Card))
|
|
|
|
cardId = cardId:getEffectiveId()
|
|
|
|
end
|
|
|
|
if table.contains(Self.player_cards[Player.Hand], cardId) then
|
|
|
|
return Card.PlayerHand
|
|
|
|
end
|
|
|
|
if table.contains(Self.player_cards[Player.Equip], cardId) then
|
|
|
|
return Card.PlayerEquip
|
|
|
|
end
|
2023-03-05 01:28:59 +08:00
|
|
|
for _, t in pairs(Self.special_cards) do
|
|
|
|
if table.contains(t, cardId) then
|
|
|
|
return Card.PlayerSpecial
|
|
|
|
end
|
|
|
|
end
|
2023-01-29 18:11:41 +08:00
|
|
|
error("Client:getCardArea can only judge cards in your hand or equip area")
|
|
|
|
end
|
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
function Client:moveCards(moves)
|
|
|
|
for _, move in ipairs(moves) do
|
|
|
|
if move.from and move.fromArea then
|
|
|
|
local from = self:getPlayerById(move.from)
|
2023-05-28 18:45:37 +08:00
|
|
|
self:notifyUI("MaxCard", json.encode{
|
|
|
|
pcardMax = from:getMaxCards(),
|
|
|
|
id = move.from,
|
|
|
|
})
|
2023-12-12 19:07:49 +08:00
|
|
|
if move.fromArea == Card.PlayerHand and not Self:isBuddy(self:getPlayerById(move.from)) then
|
|
|
|
for _ = 1, #move.ids do
|
2022-09-14 13:01:10 +08:00
|
|
|
table.remove(from.player_cards[Player.Hand])
|
|
|
|
end
|
|
|
|
else
|
2023-04-13 20:17:39 +08:00
|
|
|
if table.contains({ Player.Hand, Player.Equip, Player.Judge, Player.Special }, move.fromArea) then
|
|
|
|
from:removeCards(move.fromArea, move.ids, move.fromSpecialName)
|
|
|
|
end
|
2022-09-14 13:01:10 +08:00
|
|
|
end
|
|
|
|
elseif move.fromArea == Card.DiscardPile then
|
|
|
|
table.removeOne(self.discard_pile, move.ids[1])
|
|
|
|
end
|
|
|
|
|
|
|
|
if move.to and move.toArea then
|
2023-03-07 10:21:56 +08:00
|
|
|
local ids = move.ids
|
2023-05-28 18:45:37 +08:00
|
|
|
self:notifyUI("MaxCard", json.encode{
|
|
|
|
pcardMax = self:getPlayerById(move.to):getMaxCards(),
|
|
|
|
id = move.to,
|
|
|
|
})
|
2023-08-12 00:50:17 +08:00
|
|
|
if (not Self:isBuddy(self:getPlayerById(move.to)) and move.toArea == Card.PlayerHand) or table.contains(ids, -1) then
|
2023-03-07 10:21:56 +08:00
|
|
|
ids = table.map(ids, function() return -1 end)
|
|
|
|
end
|
|
|
|
self:getPlayerById(move.to):addCards(move.toArea, ids, move.specialName)
|
2022-09-14 13:01:10 +08:00
|
|
|
elseif move.toArea == Card.DiscardPile then
|
|
|
|
table.insert(self.discard_pile, move.ids[1])
|
|
|
|
end
|
2023-02-15 19:54:35 +08:00
|
|
|
|
2023-02-15 21:20:40 +08:00
|
|
|
if (move.ids[1] ~= -1) then
|
|
|
|
Fk:filterCard(move.ids[1], ClientInstance:getPlayerById(move.to))
|
|
|
|
end
|
2022-09-14 13:01:10 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-18 12:52:52 +08:00
|
|
|
---@param msg LogMessage
|
2023-06-10 02:18:51 +08:00
|
|
|
local function parseMsg(msg, nocolor)
|
|
|
|
local self = ClientInstance
|
2022-12-18 12:52:52 +08:00
|
|
|
local data = msg
|
|
|
|
local function getPlayerStr(pid, color)
|
2023-06-10 02:18:51 +08:00
|
|
|
if nocolor then color = "white" end
|
2022-12-18 12:52:52 +08:00
|
|
|
if not pid then
|
|
|
|
return ""
|
|
|
|
end
|
2023-04-23 21:10:07 +08:00
|
|
|
local p = self:getPlayerById(pid)
|
2023-04-27 14:15:08 +08:00
|
|
|
local str = '<font color="%s"><b>%s</b></font>'
|
2023-04-23 21:10:07 +08:00
|
|
|
if p.general == "anjiang" and (p.deputyGeneral == "anjiang"
|
|
|
|
or not p.deputyGeneral) then
|
|
|
|
local ret = Fk:translate("seat#" .. p.seat)
|
|
|
|
return string.format(str, color, ret)
|
|
|
|
end
|
|
|
|
|
|
|
|
local ret = p.general
|
2022-12-18 12:52:52 +08:00
|
|
|
ret = Fk:translate(ret)
|
2023-04-27 14:15:08 +08:00
|
|
|
if p.deputyGeneral and p.deputyGeneral ~= "" then
|
2023-04-23 21:10:07 +08:00
|
|
|
ret = ret .. "/" .. Fk:translate(p.deputyGeneral)
|
|
|
|
end
|
|
|
|
ret = string.format(str, color, ret)
|
2022-12-18 12:52:52 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
local from = getPlayerStr(data.from, "#0C8F0C")
|
|
|
|
|
2023-06-11 16:22:11 +08:00
|
|
|
local to = data.to or Util.DummyTable
|
2022-12-18 12:52:52 +08:00
|
|
|
local to_str = {}
|
|
|
|
for _, id in ipairs(to) do
|
|
|
|
table.insert(to_str, getPlayerStr(id, "#CC3131"))
|
|
|
|
end
|
|
|
|
to = table.concat(to_str, ", ")
|
|
|
|
|
2023-06-11 16:22:11 +08:00
|
|
|
local card = data.card or Util.DummyTable
|
2022-12-18 12:52:52 +08:00
|
|
|
local allUnknown = true
|
|
|
|
local unknownCount = 0
|
|
|
|
for _, id in ipairs(card) do
|
|
|
|
if id ~= -1 then
|
|
|
|
allUnknown = false
|
|
|
|
else
|
|
|
|
unknownCount = unknownCount + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if allUnknown then
|
|
|
|
card = ""
|
|
|
|
else
|
|
|
|
local card_str = {}
|
|
|
|
for _, id in ipairs(card) do
|
2023-02-15 19:54:35 +08:00
|
|
|
table.insert(card_str, Fk:getCardById(id, true):toLogString())
|
2022-12-18 12:52:52 +08:00
|
|
|
end
|
|
|
|
if unknownCount > 0 then
|
|
|
|
table.insert(card_str, Fk:translate("unknown_card")
|
|
|
|
.. unknownCount == 1 and "x" .. unknownCount or "")
|
|
|
|
end
|
|
|
|
card = table.concat(card_str, ", ")
|
|
|
|
end
|
|
|
|
|
|
|
|
local function parseArg(arg)
|
|
|
|
arg = arg or ""
|
|
|
|
arg = Fk:translate(arg)
|
2023-06-10 02:18:51 +08:00
|
|
|
arg = string.format('<font color="%s"><b>%s</b></font>', nocolor and "white" or "#0598BC", arg)
|
2022-12-18 12:52:52 +08:00
|
|
|
return arg
|
|
|
|
end
|
|
|
|
|
|
|
|
local arg = parseArg(data.arg)
|
|
|
|
local arg2 = parseArg(data.arg2)
|
|
|
|
local arg3 = parseArg(data.arg3)
|
|
|
|
|
|
|
|
local log = Fk:translate(data.type)
|
|
|
|
log = string.gsub(log, "%%from", from)
|
|
|
|
log = string.gsub(log, "%%to", to)
|
|
|
|
log = string.gsub(log, "%%card", card)
|
|
|
|
log = string.gsub(log, "%%arg2", arg2)
|
|
|
|
log = string.gsub(log, "%%arg3", arg3)
|
|
|
|
log = string.gsub(log, "%%arg", arg)
|
2023-06-10 02:18:51 +08:00
|
|
|
return log
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param msg LogMessage
|
|
|
|
function Client:appendLog(msg)
|
|
|
|
self:notifyUI("GameLog", parseMsg(msg))
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param msg LogMessage
|
|
|
|
function Client:setCardNote(ids, msg)
|
|
|
|
for _, id in ipairs(ids) do
|
|
|
|
if id ~= -1 then
|
|
|
|
self:notifyUI("SetCardFootnote", json.encode{ id, parseMsg(msg, true) })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-12-06 21:07:35 +08:00
|
|
|
function Client:setBanner(name, value)
|
|
|
|
if value == 0 then value = nil end
|
|
|
|
self.banners[name] = value
|
|
|
|
end
|
|
|
|
|
|
|
|
function Client:getBanner(name)
|
|
|
|
return self.banners[name]
|
|
|
|
end
|
|
|
|
|
2023-06-10 02:18:51 +08:00
|
|
|
fk.client_callback["SetCardFootnote"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
ClientInstance:setCardNote(data[1], data[2]);
|
2022-12-18 12:52:52 +08:00
|
|
|
end
|
|
|
|
|
2022-03-31 13:29:23 +08:00
|
|
|
fk.client_callback["Setup"] = function(jsonData)
|
2022-04-30 15:27:56 +08:00
|
|
|
-- jsonData: [ int id, string screenName, string avatar ]
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local id, name, avatar = data[1], data[2], data[3]
|
|
|
|
local self = fk.Self
|
|
|
|
self:setId(id)
|
|
|
|
self:setScreenName(name)
|
|
|
|
self:setAvatar(avatar)
|
|
|
|
Self = ClientPlayer:new(fk.Self)
|
2022-05-02 14:00:47 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
fk.client_callback["EnterRoom"] = function(jsonData)
|
2022-12-20 12:51:54 +08:00
|
|
|
Self = ClientPlayer:new(fk.Self)
|
2023-03-07 10:21:56 +08:00
|
|
|
ClientInstance = Client:new() -- clear old client data
|
2022-05-02 14:00:47 +08:00
|
|
|
ClientInstance.players = {Self}
|
2022-09-14 13:01:10 +08:00
|
|
|
ClientInstance.alive_players = {Self}
|
|
|
|
ClientInstance.discard_pile = {}
|
2023-03-14 14:12:13 +08:00
|
|
|
|
2023-08-01 21:01:01 +08:00
|
|
|
local _data = json.decode(jsonData)
|
|
|
|
local data = _data[3]
|
|
|
|
ClientInstance.enter_room_data = jsonData;
|
2023-06-04 20:00:35 +08:00
|
|
|
ClientInstance.room_settings = data
|
2023-08-24 21:37:24 +08:00
|
|
|
table.insertTableIfNeed(
|
|
|
|
data.disabledPack,
|
|
|
|
Fk.game_mode_disabled[data.gameMode]
|
|
|
|
)
|
2023-06-16 13:26:02 +08:00
|
|
|
ClientInstance.disabled_packs = data.disabledPack
|
|
|
|
ClientInstance.disabled_generals = data.disabledGenerals
|
2022-05-02 14:00:47 +08:00
|
|
|
ClientInstance:notifyUI("EnterRoom", jsonData)
|
2022-03-27 14:49:41 +08:00
|
|
|
end
|
|
|
|
|
2022-03-31 13:29:23 +08:00
|
|
|
fk.client_callback["AddPlayer"] = function(jsonData)
|
2022-04-30 15:27:56 +08:00
|
|
|
-- jsonData: [ int id, string screenName, string avatar ]
|
|
|
|
-- when other player enter the room, we create clientplayer(C and lua) for them
|
|
|
|
local data = json.decode(jsonData)
|
2023-12-28 12:11:24 +08:00
|
|
|
local id, name, avatar, time = data[1], data[2], data[3], data[5]
|
2022-04-30 15:27:56 +08:00
|
|
|
local player = fk.ClientInstance:addPlayer(id, name, avatar)
|
2023-12-28 13:40:34 +08:00
|
|
|
player:addTotalGameTime(time or 0) -- 以防再次智迟
|
2022-09-14 13:01:10 +08:00
|
|
|
local p = ClientPlayer:new(player)
|
|
|
|
table.insert(ClientInstance.players, p)
|
|
|
|
table.insert(ClientInstance.alive_players, p)
|
2022-04-30 15:27:56 +08:00
|
|
|
ClientInstance:notifyUI("AddPlayer", jsonData)
|
2022-03-28 22:24:30 +08:00
|
|
|
end
|
|
|
|
|
2022-03-31 13:29:23 +08:00
|
|
|
fk.client_callback["RemovePlayer"] = function(jsonData)
|
2022-04-30 15:27:56 +08:00
|
|
|
-- jsonData: [ int id ]
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local id = data[1]
|
|
|
|
for _, p in ipairs(ClientInstance.players) do
|
|
|
|
if p.player:getId() == id then
|
|
|
|
table.removeOne(ClientInstance.players, p)
|
2022-09-14 13:01:10 +08:00
|
|
|
table.removeOne(ClientInstance.alive_players, p)
|
2022-04-30 15:27:56 +08:00
|
|
|
break
|
2022-03-28 22:24:30 +08:00
|
|
|
end
|
2022-04-30 15:27:56 +08:00
|
|
|
end
|
2022-12-18 12:52:52 +08:00
|
|
|
if id ~= Self.id then
|
|
|
|
fk.ClientInstance:removePlayer(id)
|
|
|
|
ClientInstance:notifyUI("RemovePlayer", jsonData)
|
|
|
|
end
|
2022-03-28 22:24:30 +08:00
|
|
|
end
|
|
|
|
|
2023-02-15 19:54:35 +08:00
|
|
|
fk.client_callback["AddObserver"] = function(jsonData)
|
|
|
|
-- jsonData: [ int id, string screenName, string avatar ]
|
|
|
|
-- when observer enter the room, we create lua clientplayer for them
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local id, name, avatar = data[1], data[2], data[3]
|
|
|
|
local player = {
|
|
|
|
getId = function() return id end,
|
|
|
|
getScreenName = function() return name end,
|
|
|
|
getAvatar = function() return avatar end,
|
|
|
|
}
|
|
|
|
local p = ClientPlayer:new(player)
|
|
|
|
table.insert(ClientInstance.observers, p)
|
|
|
|
end
|
|
|
|
|
|
|
|
fk.client_callback["RemoveObserver"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local id = data[1]
|
|
|
|
for _, p in ipairs(ClientInstance.observers) do
|
|
|
|
if p.player:getId() == id then
|
|
|
|
table.removeOne(ClientInstance.observers, p)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-31 13:29:23 +08:00
|
|
|
fk.client_callback["ArrangeSeats"] = function(jsonData)
|
2022-04-30 15:27:56 +08:00
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local n = #ClientInstance.players
|
|
|
|
local players = {}
|
2022-03-28 22:24:30 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
for i = 1, n do
|
2022-09-14 13:01:10 +08:00
|
|
|
local p = ClientInstance:getPlayerById(data[i])
|
|
|
|
p.seat = i
|
|
|
|
table.insert(players, p)
|
2022-04-30 15:27:56 +08:00
|
|
|
end
|
2022-12-20 12:51:54 +08:00
|
|
|
|
|
|
|
for i = 1, #players - 1 do
|
|
|
|
players[i].next = players[i + 1]
|
|
|
|
end
|
|
|
|
players[#players].next = players[1]
|
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
ClientInstance.players = players
|
2022-03-28 22:24:30 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
ClientInstance:notifyUI("ArrangeSeats", jsonData)
|
2022-03-27 14:49:41 +08:00
|
|
|
end
|
|
|
|
|
2022-04-14 18:22:00 +08:00
|
|
|
fk.client_callback["PropertyUpdate"] = function(jsonData)
|
2022-04-30 15:27:56 +08:00
|
|
|
-- jsonData: [ int id, string property_name, value ]
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local id, name, value = data[1], data[2], data[3]
|
2023-06-04 20:00:35 +08:00
|
|
|
local p = ClientInstance:getPlayerById(id)
|
|
|
|
p[name] = value
|
|
|
|
|
|
|
|
if name == "dead" then
|
|
|
|
if value == true then
|
|
|
|
table.removeOne(ClientInstance.alive_players, p)
|
|
|
|
else
|
|
|
|
table.insertIfNeed(ClientInstance.alive_players, p)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
ClientInstance:notifyUI("PropertyUpdate", jsonData)
|
2023-05-28 18:45:37 +08:00
|
|
|
ClientInstance:notifyUI("MaxCard", json.encode{
|
|
|
|
pcardMax = ClientInstance:getPlayerById(id):getMaxCards(),
|
|
|
|
id = id,
|
|
|
|
})
|
2022-04-14 18:22:00 +08:00
|
|
|
end
|
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
fk.client_callback["AskForCardChosen"] = function(jsonData)
|
|
|
|
-- jsonData: [ int target_id, string flag, int reason ]
|
|
|
|
local data = json.decode(jsonData)
|
2023-11-07 21:14:51 +08:00
|
|
|
local id, flag, reason, prompt = data[1], data[2], data[3], data[4]
|
2022-09-14 13:01:10 +08:00
|
|
|
local target = ClientInstance:getPlayerById(id)
|
|
|
|
local hand = target.player_cards[Player.Hand]
|
|
|
|
local equip = target.player_cards[Player.Equip]
|
|
|
|
local judge = target.player_cards[Player.Judge]
|
2023-08-24 21:37:24 +08:00
|
|
|
|
|
|
|
local ui_data = flag
|
|
|
|
if type(flag) == "string" then
|
|
|
|
if not string.find(flag, "h") then
|
|
|
|
hand = {}
|
|
|
|
end
|
|
|
|
if not string.find(flag, "e") then
|
|
|
|
equip = {}
|
|
|
|
end
|
|
|
|
if not string.find(flag, "j") then
|
|
|
|
judge = {}
|
|
|
|
end
|
|
|
|
ui_data = {
|
|
|
|
_reason = reason,
|
|
|
|
card_data = {},
|
2023-11-07 21:14:51 +08:00
|
|
|
_prompt = prompt,
|
2023-08-24 21:37:24 +08:00
|
|
|
}
|
|
|
|
if #hand ~= 0 then table.insert(ui_data.card_data, { "$Hand", hand }) end
|
|
|
|
if #equip ~= 0 then table.insert(ui_data.card_data, { "$Equip", equip }) end
|
|
|
|
if #judge ~= 0 then table.insert(ui_data.card_data, { "$Judge", judge }) end
|
|
|
|
else
|
|
|
|
ui_data._reason = reason
|
2023-11-07 21:14:51 +08:00
|
|
|
ui_data._prompt = prompt
|
2022-09-14 13:01:10 +08:00
|
|
|
end
|
|
|
|
ClientInstance:notifyUI("AskForCardChosen", json.encode(ui_data))
|
|
|
|
end
|
|
|
|
|
2023-03-01 21:41:16 +08:00
|
|
|
fk.client_callback["AskForCardsChosen"] = function(jsonData)
|
|
|
|
-- jsonData: [ int target_id, int min, int max, string flag, int reason ]
|
|
|
|
local data = json.decode(jsonData)
|
2023-11-07 21:14:51 +08:00
|
|
|
local id, min, max, flag, reason, prompt = data[1], data[2], data[3], data[4], data[5], data[6]
|
2023-03-01 21:41:16 +08:00
|
|
|
local target = ClientInstance:getPlayerById(id)
|
|
|
|
local hand = target.player_cards[Player.Hand]
|
|
|
|
local equip = target.player_cards[Player.Equip]
|
|
|
|
local judge = target.player_cards[Player.Judge]
|
2023-08-24 21:37:24 +08:00
|
|
|
|
|
|
|
local ui_data = flag
|
|
|
|
if type(flag) == "string" then
|
|
|
|
if not string.find(flag, "h") then
|
|
|
|
hand = {}
|
|
|
|
end
|
|
|
|
if not string.find(flag, "e") then
|
|
|
|
equip = {}
|
|
|
|
end
|
|
|
|
if not string.find(flag, "j") then
|
|
|
|
judge = {}
|
|
|
|
end
|
|
|
|
ui_data = {
|
|
|
|
_min = min,
|
|
|
|
_max = max,
|
|
|
|
_reason = reason,
|
2023-11-07 21:14:51 +08:00
|
|
|
card_data = {},
|
|
|
|
_prompt = prompt,
|
2023-08-24 21:37:24 +08:00
|
|
|
}
|
|
|
|
if #hand ~= 0 then table.insert(ui_data.card_data, { "$Hand", hand }) end
|
|
|
|
if #equip ~= 0 then table.insert(ui_data.card_data, { "$Equip", equip }) end
|
|
|
|
if #judge ~= 0 then table.insert(ui_data.card_data, { "$Judge", judge }) end
|
|
|
|
else
|
|
|
|
ui_data._min = min
|
|
|
|
ui_data._max = max
|
|
|
|
ui_data._reason = reason
|
2023-11-07 21:14:51 +08:00
|
|
|
ui_data._prompt = prompt
|
2023-03-01 21:41:16 +08:00
|
|
|
end
|
|
|
|
ClientInstance:notifyUI("AskForCardsChosen", json.encode(ui_data))
|
|
|
|
end
|
|
|
|
|
2022-04-14 18:22:00 +08:00
|
|
|
--- separated moves to many moves(one card per move)
|
|
|
|
---@param moves CardsMoveStruct[]
|
|
|
|
local function separateMoves(moves)
|
2022-04-30 15:27:56 +08:00
|
|
|
local ret = {} ---@type CardsMoveInfo[]
|
|
|
|
for _, move in ipairs(moves) do
|
|
|
|
for _, info in ipairs(move.moveInfo) do
|
|
|
|
table.insert(ret, {
|
|
|
|
ids = {info.cardId},
|
|
|
|
from = move.from,
|
|
|
|
to = move.to,
|
|
|
|
toArea = move.toArea,
|
|
|
|
fromArea = info.fromArea,
|
2022-12-18 12:52:52 +08:00
|
|
|
moveReason = move.moveReason,
|
2023-02-21 13:44:24 +08:00
|
|
|
specialName = move.specialName,
|
|
|
|
fromSpecialName = info.fromSpecialName,
|
2022-04-30 15:27:56 +08:00
|
|
|
})
|
2022-04-14 18:22:00 +08:00
|
|
|
end
|
2022-04-30 15:27:56 +08:00
|
|
|
end
|
|
|
|
return ret
|
2022-04-14 18:22:00 +08:00
|
|
|
end
|
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
--- merge separated moves that information is the same
|
2022-04-14 18:22:00 +08:00
|
|
|
local function mergeMoves(moves)
|
2022-04-30 15:27:56 +08:00
|
|
|
local ret = {}
|
|
|
|
local temp = {}
|
|
|
|
for _, move in ipairs(moves) do
|
2023-02-26 16:51:29 +08:00
|
|
|
local info = string.format("%q,%q,%q,%q,%s,%s",
|
2023-02-21 13:44:24 +08:00
|
|
|
move.from, move.to, move.fromArea, move.toArea,
|
|
|
|
move.specialName, move.fromSpecialName)
|
2023-02-26 16:51:29 +08:00
|
|
|
if temp[info] == nil then
|
2022-09-14 13:01:10 +08:00
|
|
|
temp[info] = {
|
2022-04-30 15:27:56 +08:00
|
|
|
ids = {},
|
|
|
|
from = move.from,
|
|
|
|
to = move.to,
|
|
|
|
fromArea = move.fromArea,
|
2022-12-18 12:52:52 +08:00
|
|
|
toArea = move.toArea,
|
|
|
|
moveReason = move.moveReason,
|
2023-02-21 13:44:24 +08:00
|
|
|
specialName = move.specialName,
|
|
|
|
fromSpecialName = move.fromSpecialName,
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
end
|
2022-09-14 13:01:10 +08:00
|
|
|
table.insert(temp[info].ids, move.ids[1])
|
2022-04-30 15:27:56 +08:00
|
|
|
end
|
|
|
|
for _, v in pairs(temp) do
|
|
|
|
table.insert(ret, v)
|
|
|
|
end
|
|
|
|
return ret
|
2022-04-14 18:22:00 +08:00
|
|
|
end
|
|
|
|
|
2022-12-18 12:52:52 +08:00
|
|
|
local function sendMoveCardLog(move)
|
2023-06-10 02:18:51 +08:00
|
|
|
local client = ClientInstance
|
2023-03-18 15:35:44 +08:00
|
|
|
if #move.ids == 0 then return end
|
|
|
|
local hidden = table.contains(move.ids, -1)
|
|
|
|
local msgtype
|
|
|
|
|
2024-01-11 18:36:05 +08:00
|
|
|
if move.toArea == Card.PlayerHand then
|
|
|
|
if move.fromArea == Card.PlayerSpecial then
|
|
|
|
client:appendLog{
|
|
|
|
type = "$GetCardsFromPile",
|
|
|
|
from = move.to,
|
|
|
|
arg = move.fromSpecialName,
|
|
|
|
arg2 = #move.ids,
|
|
|
|
card = move.ids,
|
|
|
|
}
|
|
|
|
elseif move.fromArea == Card.DrawPile then
|
|
|
|
client:appendLog{
|
|
|
|
type = "$DrawCards",
|
|
|
|
from = move.to,
|
|
|
|
card = move.ids,
|
|
|
|
arg = #move.ids,
|
|
|
|
}
|
|
|
|
elseif move.fromArea == Card.Processing then
|
|
|
|
client:appendLog{
|
|
|
|
type = "$GotCardBack",
|
|
|
|
from = move.to,
|
|
|
|
card = move.ids,
|
|
|
|
arg = #move.ids,
|
|
|
|
}
|
|
|
|
elseif move.fromArea == Card.DiscardPile then
|
|
|
|
client:appendLog{
|
|
|
|
type = "$RecycleCard",
|
|
|
|
from = move.to,
|
|
|
|
card = move.ids,
|
|
|
|
arg = #move.ids,
|
|
|
|
}
|
|
|
|
elseif move.from then
|
|
|
|
client:appendLog{
|
|
|
|
type = "$MoveCards",
|
|
|
|
from = move.from,
|
|
|
|
to = { move.to },
|
|
|
|
arg = #move.ids,
|
|
|
|
card = move.ids,
|
|
|
|
}
|
|
|
|
else
|
|
|
|
client:appendLog{
|
|
|
|
type = "$PreyCardsFromPile",
|
|
|
|
from = move.to,
|
|
|
|
card = move.ids,
|
|
|
|
arg = #move.ids,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
elseif move.toArea == Card.PlayerEquip then
|
2023-06-10 02:18:51 +08:00
|
|
|
client:appendLog{
|
2024-01-11 18:36:05 +08:00
|
|
|
type = "$InstallEquip",
|
|
|
|
from = move.to,
|
2023-03-18 15:35:44 +08:00
|
|
|
card = move.ids,
|
|
|
|
}
|
2024-01-11 18:36:05 +08:00
|
|
|
elseif move.toArea == Card.PlayerJudge then
|
|
|
|
if move.from ~= move.to and move.fromArea == Card.PlayerJudge then
|
|
|
|
client:appendLog{
|
|
|
|
type = "$LightningMove",
|
|
|
|
from = move.from,
|
|
|
|
to = { move.to },
|
|
|
|
card = move.ids,
|
|
|
|
}
|
|
|
|
elseif move.from then
|
|
|
|
client:appendLog{
|
|
|
|
type = "$PasteCard",
|
|
|
|
from = move.from,
|
|
|
|
to = { move.to },
|
|
|
|
card = move.ids,
|
|
|
|
}
|
|
|
|
end
|
2023-03-18 15:35:44 +08:00
|
|
|
elseif move.toArea == Card.PlayerSpecial then
|
2023-06-10 02:18:51 +08:00
|
|
|
client:appendLog{
|
2024-01-11 18:36:05 +08:00
|
|
|
type = "$AddToPile",
|
2023-03-18 15:35:44 +08:00
|
|
|
arg = move.specialName,
|
|
|
|
arg2 = #move.ids,
|
|
|
|
from = move.to,
|
|
|
|
card = move.ids,
|
|
|
|
}
|
2024-01-11 18:36:05 +08:00
|
|
|
elseif move.fromArea == Card.PlayerEquip then
|
2023-06-10 02:18:51 +08:00
|
|
|
client:appendLog{
|
2024-01-11 18:36:05 +08:00
|
|
|
type = "$UninstallEquip",
|
|
|
|
from = move.from,
|
2023-03-18 15:35:44 +08:00
|
|
|
card = move.ids,
|
|
|
|
}
|
2024-01-11 18:36:05 +08:00
|
|
|
-- elseif move.toArea == Card.Processing then
|
|
|
|
-- nop
|
|
|
|
elseif move.from and move.toArea == Card.DrawPile then
|
|
|
|
msgtype = hidden and "$PutCard" or "$PutKnownCard"
|
2023-06-10 02:18:51 +08:00
|
|
|
client:appendLog{
|
2024-01-11 18:36:05 +08:00
|
|
|
type = msgtype,
|
|
|
|
from = move.from,
|
2023-03-18 15:35:44 +08:00
|
|
|
card = move.ids,
|
|
|
|
arg = #move.ids,
|
|
|
|
}
|
2024-01-11 18:36:05 +08:00
|
|
|
client:setCardNote(move.ids, {
|
|
|
|
type = "$$PutCard",
|
2023-03-18 15:35:44 +08:00
|
|
|
from = move.from,
|
2024-01-11 18:36:05 +08:00
|
|
|
})
|
|
|
|
elseif move.toArea == Card.DiscardPile then
|
|
|
|
if move.moveReason == fk.ReasonDiscard then
|
2023-06-10 02:18:51 +08:00
|
|
|
client:appendLog{
|
2024-01-11 18:36:05 +08:00
|
|
|
type = "$DiscardCards",
|
2023-03-18 15:35:44 +08:00
|
|
|
from = move.from,
|
|
|
|
card = move.ids,
|
2024-01-11 18:36:05 +08:00
|
|
|
arg = #move.ids,
|
|
|
|
}
|
|
|
|
elseif move.moveReason == fk.ReasonPutIntoDiscardPile then
|
|
|
|
client:appendLog{
|
|
|
|
type = "$PutToDiscard",
|
|
|
|
card = move.ids,
|
|
|
|
arg = #move.ids,
|
2023-03-18 15:35:44 +08:00
|
|
|
}
|
|
|
|
end
|
2024-01-11 18:36:05 +08:00
|
|
|
-- elseif move.toArea == Card.Void then
|
|
|
|
-- nop
|
2023-03-18 15:35:44 +08:00
|
|
|
end
|
|
|
|
|
2024-01-11 18:36:05 +08:00
|
|
|
-- TODO: footnote
|
2023-03-18 15:35:44 +08:00
|
|
|
if move.moveReason == fk.ReasonDiscard then
|
2023-06-10 02:18:51 +08:00
|
|
|
client:setCardNote(move.ids, {
|
|
|
|
type = "$$DiscardCards",
|
|
|
|
from = move.from
|
|
|
|
})
|
2022-12-18 12:52:52 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-14 18:22:00 +08:00
|
|
|
fk.client_callback["MoveCards"] = function(jsonData)
|
2022-04-30 15:27:56 +08:00
|
|
|
-- jsonData: CardsMoveStruct[]
|
|
|
|
local raw_moves = json.decode(jsonData)
|
|
|
|
local separated = separateMoves(raw_moves)
|
2022-09-14 13:01:10 +08:00
|
|
|
ClientInstance:moveCards(separated)
|
2022-04-30 15:27:56 +08:00
|
|
|
local merged = mergeMoves(separated)
|
2023-06-10 02:18:51 +08:00
|
|
|
ClientInstance:notifyUI("MoveCards", json.encode(merged))
|
2022-12-18 12:52:52 +08:00
|
|
|
for _, move in ipairs(merged) do
|
|
|
|
sendMoveCardLog(move)
|
|
|
|
end
|
2022-04-14 18:22:00 +08:00
|
|
|
end
|
|
|
|
|
2023-03-20 20:15:24 +08:00
|
|
|
fk.client_callback["ShowCard"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local from = data.from
|
|
|
|
local cards = data.cards
|
|
|
|
ClientInstance:notifyUI("MoveCards", json.encode{
|
|
|
|
{
|
|
|
|
ids = cards,
|
|
|
|
fromArea = Card.DrawPile,
|
|
|
|
toArea = Card.Processing,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2023-04-05 01:05:06 +08:00
|
|
|
-- 说是限定技,其实也适用于觉醒技、转换技、使命技
|
|
|
|
---@param skill Skill
|
|
|
|
---@param times integer
|
|
|
|
local function updateLimitSkill(pid, skill, times)
|
|
|
|
if not skill.visible then return end
|
2023-05-13 14:20:34 +08:00
|
|
|
if skill:isSwitchSkill() then
|
2023-10-07 23:00:25 +08:00
|
|
|
local _times = ClientInstance:getPlayerById(pid):getSwitchSkillState(skill.switchSkillName) == fk.SwitchYang and 0 or 1
|
|
|
|
if times == -1 then _times = -1 end
|
|
|
|
ClientInstance:notifyUI("UpdateLimitSkill", json.encode{ pid, skill.switchSkillName, _times })
|
2023-05-28 18:45:54 +08:00
|
|
|
elseif skill.frequency == Skill.Limited or skill.frequency == Skill.Wake or skill.frequency == Skill.Quest then
|
2023-04-05 01:05:06 +08:00
|
|
|
ClientInstance:notifyUI("UpdateLimitSkill", json.encode{ pid, skill.name, times })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-08-09 22:25:15 +08:00
|
|
|
fk.client_callback["LoseSkill"] = function(jsonData)
|
|
|
|
-- jsonData: [ int player_id, string skill_name ]
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local id, skill_name, fake = data[1], data[2], data[3]
|
|
|
|
local target = ClientInstance:getPlayerById(id)
|
|
|
|
local skill = Fk.skills[skill_name]
|
|
|
|
|
|
|
|
if not fake then
|
|
|
|
target:loseSkill(skill)
|
|
|
|
if skill.visible then
|
|
|
|
ClientInstance:notifyUI("LoseSkill", jsonData)
|
|
|
|
end
|
|
|
|
elseif skill.visible then
|
|
|
|
-- 按理说能弄得更好的但还是复制粘贴舒服
|
|
|
|
local sks = { table.unpack(skill.related_skills) }
|
|
|
|
--[[ 需要大伙都适配好main_skill或者讨论出更好方案才行。不敢轻举妄动
|
|
|
|
local sks = table.filter(skill.related_skills, function(s)
|
|
|
|
return s.main_skill == skill
|
|
|
|
end)
|
|
|
|
--]]
|
|
|
|
table.insert(sks, skill)
|
|
|
|
table.removeOne(target.player_skills, skill)
|
|
|
|
local chk = false
|
|
|
|
|
|
|
|
if table.find(sks, function(s) return s:isInstanceOf(TriggerSkill) end) then
|
|
|
|
chk = true
|
|
|
|
ClientInstance:notifyUI("LoseSkill", jsonData)
|
|
|
|
end
|
|
|
|
|
|
|
|
local active = table.filter(sks, function(s)
|
|
|
|
return s:isInstanceOf(ActiveSkill) or s:isInstanceOf(ViewAsSkill)
|
|
|
|
end)
|
|
|
|
|
|
|
|
if #active > 0 then
|
|
|
|
chk = true
|
|
|
|
ClientInstance:notifyUI("LoseSkill", json.encode {
|
|
|
|
id, skill_name,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
if not chk then
|
|
|
|
ClientInstance:notifyUI("LoseSkill", json.encode {
|
|
|
|
id, skill_name,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
updateLimitSkill(id, skill, -1)
|
|
|
|
end
|
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
fk.client_callback["AddSkill"] = function(jsonData)
|
|
|
|
-- jsonData: [ int player_id, string skill_name ]
|
|
|
|
local data = json.decode(jsonData)
|
2023-08-09 22:25:15 +08:00
|
|
|
local id, skill_name, fake = data[1], data[2], data[3]
|
2022-09-14 13:01:10 +08:00
|
|
|
local target = ClientInstance:getPlayerById(id)
|
|
|
|
local skill = Fk.skills[skill_name]
|
2023-08-09 22:25:15 +08:00
|
|
|
|
|
|
|
if not fake then
|
|
|
|
target:addSkill(skill)
|
|
|
|
if skill.visible then
|
|
|
|
ClientInstance:notifyUI("AddSkill", jsonData)
|
|
|
|
end
|
|
|
|
elseif skill.visible then
|
|
|
|
-- 添加假技能:服务器只会传一个主技能来。
|
|
|
|
-- 若有主动技则添加按钮,若有触发技则添加预亮按钮。
|
|
|
|
-- 无视状态技。
|
|
|
|
local sks = { table.unpack(skill.related_skills) }
|
|
|
|
table.insert(sks, skill)
|
|
|
|
table.insert(target.player_skills, skill)
|
|
|
|
local chk = false
|
|
|
|
|
|
|
|
if table.find(sks, function(s) return s:isInstanceOf(TriggerSkill) end) then
|
|
|
|
chk = true
|
|
|
|
ClientInstance:notifyUI("AddSkill", jsonData)
|
|
|
|
end
|
|
|
|
|
|
|
|
local active = table.filter(sks, function(s)
|
|
|
|
return s:isInstanceOf(ActiveSkill) or s:isInstanceOf(ViewAsSkill)
|
|
|
|
end)
|
|
|
|
|
|
|
|
if #active > 0 then
|
|
|
|
chk = true
|
|
|
|
ClientInstance:notifyUI("AddSkill", json.encode {
|
|
|
|
id, skill_name,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
-- 面板上总得有点啥东西表明自己有技能吧 = =
|
|
|
|
if not chk then
|
|
|
|
ClientInstance:notifyUI("AddSkill", json.encode {
|
|
|
|
id, skill_name,
|
|
|
|
})
|
|
|
|
end
|
2022-09-14 13:01:10 +08:00
|
|
|
end
|
2023-04-05 01:05:06 +08:00
|
|
|
|
2023-05-28 18:45:54 +08:00
|
|
|
if skill.frequency == Skill.Quest then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-04-05 01:05:06 +08:00
|
|
|
updateLimitSkill(id, skill, target:usedSkillTimes(skill_name, Player.HistoryGame))
|
2022-09-14 13:01:10 +08:00
|
|
|
end
|
|
|
|
|
2022-09-15 11:17:13 +08:00
|
|
|
fk.client_callback["AskForUseActiveSkill"] = function(jsonData)
|
|
|
|
-- jsonData: [ string skill_name, string prompt, bool cancelable. json extra_data ]
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local skill = Fk.skills[data[1]]
|
2023-12-03 18:45:25 +08:00
|
|
|
local extra_data = data[4]
|
2022-09-15 11:17:13 +08:00
|
|
|
for k, v in pairs(extra_data) do
|
|
|
|
skill[k] = v
|
|
|
|
end
|
2023-04-10 15:55:06 +08:00
|
|
|
|
|
|
|
Fk.currentResponseReason = extra_data.skillName
|
2022-09-15 11:17:13 +08:00
|
|
|
ClientInstance:notifyUI("AskForUseActiveSkill", jsonData)
|
|
|
|
end
|
|
|
|
|
2023-04-10 15:55:06 +08:00
|
|
|
fk.client_callback["AskForUseCard"] = function(jsonData)
|
|
|
|
Fk.currentResponsePattern = json.decode(jsonData)[2]
|
|
|
|
ClientInstance:notifyUI("AskForUseCard", jsonData)
|
|
|
|
end
|
|
|
|
|
|
|
|
fk.client_callback["AskForResponseCard"] = function(jsonData)
|
|
|
|
Fk.currentResponsePattern = json.decode(jsonData)[2]
|
|
|
|
ClientInstance:notifyUI("AskForResponseCard", jsonData)
|
|
|
|
end
|
|
|
|
|
2022-12-18 12:52:52 +08:00
|
|
|
fk.client_callback["SetPlayerMark"] = function(jsonData)
|
|
|
|
-- jsonData: [ int id, string mark, int value ]
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local player, mark, value = data[1], data[2], data[3]
|
|
|
|
ClientInstance:getPlayerById(player):setMark(mark, value)
|
|
|
|
|
2023-02-15 19:54:35 +08:00
|
|
|
if string.sub(mark, 1, 1) == "@" then
|
|
|
|
ClientInstance:notifyUI("SetPlayerMark", jsonData)
|
|
|
|
end
|
2022-12-18 12:52:52 +08:00
|
|
|
end
|
|
|
|
|
2023-12-06 21:07:35 +08:00
|
|
|
fk.client_callback["SetBanner"] = function(jsonData)
|
|
|
|
-- jsonData: [ int id, string mark, int value ]
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local mark, value = data[1], data[2]
|
|
|
|
ClientInstance:setBanner(mark, value)
|
|
|
|
|
|
|
|
if string.sub(mark, 1, 1) == "@" then
|
|
|
|
ClientInstance:notifyUI("SetBanner", jsonData)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-21 22:49:49 +08:00
|
|
|
fk.client_callback["SetCardMark"] = function(jsonData)
|
|
|
|
-- jsonData: [ int id, string mark, int value ]
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local card, mark, value = data[1], data[2], data[3]
|
2023-06-23 22:18:11 +08:00
|
|
|
Fk:getCardById(card):setMark(mark, value)
|
2023-04-21 22:49:49 +08:00
|
|
|
|
2023-06-23 22:18:11 +08:00
|
|
|
ClientInstance:notifyUI("UpdateCard", tostring(card))
|
2023-04-21 22:49:49 +08:00
|
|
|
end
|
|
|
|
|
2022-12-18 12:52:52 +08:00
|
|
|
fk.client_callback["Chat"] = function(jsonData)
|
2023-04-05 15:13:58 +08:00
|
|
|
-- jsonData: { int type, int sender, string msg }
|
2022-12-18 12:52:52 +08:00
|
|
|
local data = json.decode(jsonData)
|
2023-04-05 15:13:58 +08:00
|
|
|
if data.type == 1 then
|
|
|
|
data.general = ""
|
|
|
|
data.time = os.date("%H:%M:%S")
|
|
|
|
ClientInstance:notifyUI("Chat", json.encode(data))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local p = ClientInstance:getPlayerById(data.sender)
|
2023-02-15 19:54:35 +08:00
|
|
|
if not p then
|
|
|
|
for _, pl in ipairs(ClientInstance.observers) do
|
2023-04-05 15:13:58 +08:00
|
|
|
if pl.id == data.sender then
|
2023-02-15 19:54:35 +08:00
|
|
|
p = pl; break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not p then return end
|
|
|
|
data.general = ""
|
|
|
|
else
|
|
|
|
data.general = p.general
|
|
|
|
end
|
2022-12-18 12:52:52 +08:00
|
|
|
data.userName = p.player:getScreenName()
|
|
|
|
data.time = os.date("%H:%M:%S")
|
|
|
|
ClientInstance:notifyUI("Chat", json.encode(data))
|
|
|
|
end
|
|
|
|
|
|
|
|
fk.client_callback["GameLog"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
ClientInstance:appendLog(data)
|
|
|
|
end
|
|
|
|
|
2022-12-20 12:51:54 +08:00
|
|
|
fk.client_callback["LogEvent"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
if data.type == "Death" then
|
|
|
|
table.removeOne(
|
|
|
|
ClientInstance.alive_players,
|
|
|
|
ClientInstance:getPlayerById(data.to)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
ClientInstance:notifyUI("LogEvent", jsonData)
|
|
|
|
end
|
|
|
|
|
|
|
|
fk.client_callback["AddCardUseHistory"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
Self:addCardUseHistory(data[1], data[2])
|
|
|
|
end
|
|
|
|
|
2023-01-29 18:11:41 +08:00
|
|
|
fk.client_callback["SetCardUseHistory"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
Self:setCardUseHistory(data[1], data[2], data[3])
|
|
|
|
end
|
|
|
|
|
|
|
|
fk.client_callback["AddSkillUseHistory"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
2023-04-05 01:05:06 +08:00
|
|
|
local playerid, skill_name, time = data[1], data[2], data[3]
|
|
|
|
local player = ClientInstance:getPlayerById(playerid)
|
|
|
|
player:addSkillUseHistory(skill_name, time)
|
2023-05-28 18:45:54 +08:00
|
|
|
|
|
|
|
local skill = Fk.skills[skill_name]
|
|
|
|
if not skill or skill.frequency == Skill.Quest then return end
|
2023-04-05 01:05:06 +08:00
|
|
|
updateLimitSkill(playerid, Fk.skills[skill_name], player:usedSkillTimes(skill_name, Player.HistoryGame))
|
2023-01-29 18:11:41 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
fk.client_callback["SetSkillUseHistory"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
2023-04-05 01:05:06 +08:00
|
|
|
local id, skill_name, time, scope = data[1], data[2], data[3], data[4]
|
|
|
|
local player = ClientInstance:getPlayerById(id)
|
|
|
|
player:setSkillUseHistory(skill_name, time, scope)
|
2023-05-28 18:45:54 +08:00
|
|
|
|
|
|
|
local skill = Fk.skills[skill_name]
|
|
|
|
if not skill or skill.frequency == Skill.Quest then return end
|
2023-04-05 01:05:06 +08:00
|
|
|
updateLimitSkill(id, Fk.skills[skill_name], player:usedSkillTimes(skill_name, Player.HistoryGame))
|
2023-01-29 18:11:41 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
fk.client_callback["AddVirtualEquip"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local cname = data.name
|
|
|
|
local player = ClientInstance:getPlayerById(data.player)
|
|
|
|
local subcards = data.subcards
|
|
|
|
local c = Fk:cloneCard(cname)
|
|
|
|
c:addSubcards(subcards)
|
|
|
|
player:addVirtualEquip(c)
|
|
|
|
end
|
|
|
|
|
|
|
|
fk.client_callback["RemoveVirtualEquip"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local player = ClientInstance:getPlayerById(data.player)
|
|
|
|
player:removeVirtualEquip(data.id)
|
2022-12-20 12:51:54 +08:00
|
|
|
end
|
|
|
|
|
2023-04-05 15:13:58 +08:00
|
|
|
fk.client_callback["Heartbeat"] = function()
|
|
|
|
ClientInstance.client:notifyServer("Heartbeat", "")
|
|
|
|
end
|
|
|
|
|
2023-04-27 14:15:08 +08:00
|
|
|
fk.client_callback["ChangeSelf"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
ClientInstance:getPlayerById(data.id).player_cards[Player.Hand] = data.handcards
|
2023-06-16 13:26:02 +08:00
|
|
|
ClientInstance:getPlayerById(data.id).special_cards = data.special_cards
|
2023-04-27 14:15:08 +08:00
|
|
|
ClientInstance:notifyUI("ChangeSelf", data.id)
|
|
|
|
end
|
|
|
|
|
2023-05-28 18:45:54 +08:00
|
|
|
fk.client_callback["UpdateQuestSkillUI"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local player, skillName, usedTimes = data[1], data[2], data[3]
|
|
|
|
updateLimitSkill(player, Fk.skills[skillName], usedTimes)
|
|
|
|
end
|
|
|
|
|
2023-06-16 23:04:31 +08:00
|
|
|
fk.client_callback["UpdateGameData"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local player, total, win, run = data[1], data[2], data[3], data[4]
|
|
|
|
player = ClientInstance:getPlayerById(player)
|
|
|
|
if player then
|
|
|
|
player.player:setGameData(total, win, run)
|
|
|
|
end
|
2023-06-27 16:50:24 +08:00
|
|
|
|
|
|
|
ClientInstance:notifyUI("UpdateGameData", jsonData)
|
|
|
|
end
|
|
|
|
|
2023-12-28 12:11:24 +08:00
|
|
|
fk.client_callback["AddTotalGameTime"] = function(jsonData)
|
|
|
|
local data = json.decode(jsonData)
|
|
|
|
local player, time = data[1], data[2]
|
|
|
|
player = ClientInstance:getPlayerById(player)
|
|
|
|
if player then
|
|
|
|
player.player:addTotalGameTime(time)
|
|
|
|
if player == Self then
|
|
|
|
ClientInstance:notifyUI("AddTotalGameTime", jsonData)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-27 16:50:24 +08:00
|
|
|
fk.client_callback["StartGame"] = function(jsonData)
|
|
|
|
local c = ClientInstance
|
2023-08-01 21:01:01 +08:00
|
|
|
c.record = {
|
|
|
|
fk.FK_VER,
|
|
|
|
os.date("%Y%m%d%H%M%S"),
|
|
|
|
c.enter_room_data,
|
|
|
|
json.encode { Self.id, fk.Self:getScreenName(), fk.Self:getAvatar() },
|
|
|
|
-- RESERVED
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
}
|
2023-06-27 16:50:24 +08:00
|
|
|
for _, p in ipairs(c.players) do
|
|
|
|
if p.id ~= Self.id then
|
|
|
|
table.insert(c.record, {
|
2023-08-01 21:01:01 +08:00
|
|
|
math.floor(os.getms() / 1000),
|
2023-06-27 16:50:24 +08:00
|
|
|
false,
|
|
|
|
"AddPlayer",
|
|
|
|
json.encode {
|
|
|
|
p.player:getId(),
|
|
|
|
p.player:getScreenName(),
|
|
|
|
p.player:getAvatar(),
|
|
|
|
true,
|
2023-12-28 12:11:24 +08:00
|
|
|
p.player:getTotalGameTime(),
|
2023-06-27 16:50:24 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
c.recording = true
|
|
|
|
c:notifyUI("StartGame", jsonData)
|
|
|
|
end
|
|
|
|
|
|
|
|
fk.client_callback["GameOver"] = function(jsonData)
|
|
|
|
local c = ClientInstance
|
2023-08-01 21:01:01 +08:00
|
|
|
if c.recording then
|
2023-06-27 16:50:24 +08:00
|
|
|
c.recording = false
|
|
|
|
c.record[2] = table.concat({
|
|
|
|
c.record[2],
|
|
|
|
Self.player:getScreenName(),
|
|
|
|
c.room_settings.gameMode,
|
|
|
|
Self.general,
|
|
|
|
Self.role,
|
|
|
|
jsonData,
|
|
|
|
}, ".")
|
|
|
|
-- c.client:saveRecord(json.encode(c.record), c.record[2])
|
|
|
|
end
|
|
|
|
c:notifyUI("GameOver", jsonData)
|
|
|
|
end
|
|
|
|
|
|
|
|
fk.client_callback["EnterLobby"] = function(jsonData)
|
|
|
|
local c = ClientInstance
|
2023-08-01 21:01:01 +08:00
|
|
|
--[[
|
2023-06-27 16:50:24 +08:00
|
|
|
if c.recording and not c.observing then
|
|
|
|
c.recording = false
|
|
|
|
c.record[2] = table.concat({
|
|
|
|
c.record[2],
|
|
|
|
Self.player:getScreenName(),
|
|
|
|
c.room_settings.gameMode,
|
|
|
|
Self.general,
|
|
|
|
Self.role,
|
|
|
|
"",
|
|
|
|
}, ".")
|
|
|
|
-- c.client:saveRecord(json.encode(c.record), c.record[2])
|
|
|
|
end
|
2023-08-01 21:01:01 +08:00
|
|
|
--]]
|
2023-06-27 16:50:24 +08:00
|
|
|
c:notifyUI("EnterLobby", jsonData)
|
2023-06-16 23:04:31 +08:00
|
|
|
end
|
|
|
|
|
2023-08-11 03:19:59 +08:00
|
|
|
fk.client_callback["PrintCard"] = function(j)
|
|
|
|
local data = json.decode(j)
|
|
|
|
local n, s, num = table.unpack(data)
|
|
|
|
local cd = Fk:cloneCard(n, s, num)
|
|
|
|
Fk:_addPrintedCard(cd)
|
|
|
|
end
|
|
|
|
|
2023-08-12 00:50:17 +08:00
|
|
|
fk.client_callback["AddBuddy"] = function(j)
|
|
|
|
local c = ClientInstance
|
|
|
|
local data = json.decode(j)
|
|
|
|
local id, hand = table.unpack(data)
|
|
|
|
local to = c:getPlayerById(id)
|
|
|
|
Self:addBuddy(to)
|
|
|
|
to.player_cards[Player.Hand] = hand
|
|
|
|
end
|
|
|
|
|
|
|
|
fk.client_callback["RmBuddy"] = function(j)
|
|
|
|
local c = ClientInstance
|
|
|
|
local id = tonumber(j)
|
|
|
|
local to = c:getPlayerById(id)
|
|
|
|
Self:removeBuddy(to)
|
|
|
|
to.player_cards[Player.Hand] = table.map(to.player_cards, function() return -1 end)
|
|
|
|
end
|
|
|
|
|
2022-01-24 10:23:08 +08:00
|
|
|
-- Create ClientInstance (used by Lua)
|
|
|
|
ClientInstance = Client:new()
|
2022-04-30 15:27:56 +08:00
|
|
|
dofile "lua/client/client_util.lua"
|