2023-04-09 05:35:35 +00:00
|
|
|
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- Room是fk游戏逻辑运行的主要场所,同时也提供了许多API函数供编写技能使用。
|
|
|
|
|
---
|
|
|
|
|
--- 一个房间中只有一个Room实例,保存在RoomInstance全局变量中。
|
2024-02-17 01:46:48 +00:00
|
|
|
|
---@class Room : AbstractRoom
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@field public room fk.Room @ C++层面的Room类实例,别管他就是了,用不着
|
2023-06-16 02:56:33 +00:00
|
|
|
|
---@field public id integer @ 房间的id
|
|
|
|
|
---@field private main_co any @ 本房间的主协程
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@field public players ServerPlayer[] @ 这个房间中所有参战玩家
|
|
|
|
|
---@field public alive_players ServerPlayer[] @ 所有还活着的玩家
|
|
|
|
|
---@field public observers fk.ServerPlayer[] @ 旁观者清单,这是c++玩家列表,别乱动
|
|
|
|
|
---@field public current ServerPlayer @ 当前回合玩家
|
|
|
|
|
---@field public game_started boolean @ 游戏是否已经开始
|
|
|
|
|
---@field public game_finished boolean @ 游戏是否已经结束
|
|
|
|
|
---@field public timeout integer @ 出牌时长上限
|
|
|
|
|
---@field public tag table<string, any> @ Tag清单,其实跟Player的标记是差不多的东西
|
2023-09-27 13:02:22 +00:00
|
|
|
|
---@field public general_pile string[] @ 武将牌堆,这是可用武将名的数组
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@field public draw_pile integer[] @ 摸牌堆,这是卡牌id的数组
|
|
|
|
|
---@field public discard_pile integer[] @ 弃牌堆,也是卡牌id的数组
|
|
|
|
|
---@field public processing_area integer[] @ 处理区,依然是卡牌id数组
|
|
|
|
|
---@field public void integer[] @ 从游戏中除外区,一样的是卡牌id数组
|
|
|
|
|
---@field public card_place table<integer, CardArea> @ 每个卡牌的id对应的区域,一张表
|
|
|
|
|
---@field public owner_map table<integer, integer> @ 每个卡牌id对应的主人,表的值是那个玩家的id,可能是nil
|
|
|
|
|
---@field public settings table @ 房间的额外设置,差不多是json对象
|
|
|
|
|
---@field public logic GameLogic @ 这个房间使用的游戏逻辑,可能根据游戏模式而变动
|
2023-04-27 06:15:08 +00:00
|
|
|
|
---@field public request_queue table<userdata, table>
|
|
|
|
|
---@field public request_self table<integer, integer>
|
2023-06-16 02:56:33 +00:00
|
|
|
|
---@field public skill_costs table<string, any> @ 存放skill.cost_data用
|
2023-06-23 14:18:11 +00:00
|
|
|
|
---@field public card_marks table<integer, any> @ 存放card.mark之用
|
2024-02-17 01:46:48 +00:00
|
|
|
|
local Room = AbstractRoom:subclass("Room")
|
2022-03-25 04:28:07 +00:00
|
|
|
|
|
2022-04-01 12:51:01 +00:00
|
|
|
|
-- load classes used by the game
|
2023-02-28 17:43:44 +00:00
|
|
|
|
GameEvent = require "server.gameevent"
|
|
|
|
|
dofile "lua/server/events/init.lua"
|
2022-04-01 12:51:01 +00:00
|
|
|
|
GameLogic = require "server.gamelogic"
|
|
|
|
|
ServerPlayer = require "server.serverplayer"
|
|
|
|
|
|
2023-02-26 07:01:14 +00:00
|
|
|
|
---@type Player
|
|
|
|
|
Self = nil -- `Self' is client-only, but we need it in AI
|
|
|
|
|
dofile "lua/server/ai/init.lua"
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
--[[--------------------------------------------------------------------
|
2023-04-12 12:51:09 +00:00
|
|
|
|
Room 保存着服务器端游戏房间的所有信息,比如说玩家、卡牌,以及其他信息。
|
|
|
|
|
同时它也提供大量方法,以便于游戏能够顺利运转。
|
2022-09-15 03:17:13 +00:00
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
class Room 的大概内容:
|
|
|
|
|
* 构造方法
|
2022-09-15 03:17:13 +00:00
|
|
|
|
* getter/setters
|
2023-04-12 12:51:09 +00:00
|
|
|
|
* 基本的网络通信相关方法、通知用方法
|
|
|
|
|
* 交互式方法
|
|
|
|
|
* 各种触发游戏事件的方法
|
|
|
|
|
|
|
|
|
|
另请参考:
|
|
|
|
|
gamelogic.lua (游戏逻辑的主循环、触发时机等)
|
|
|
|
|
gameevent.lua (游戏事件的执行逻辑,以及各种事件的执行方法)
|
|
|
|
|
game_rule.lua (基础游戏规则,包括执行阶段、决胜负等)
|
|
|
|
|
aux_skills.lua (某些交互方法是套壳askForUseActiveSkill,就是在这定义的)
|
2024-04-01 16:56:04 +00:00
|
|
|
|
aux_poxi.lua (有了Poxi之后,一些交互方法改成了以各种PoxiMethod为基础的交互)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
]]----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- 构造函数
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
2022-04-01 12:51:01 +00:00
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 构造函数。别去构造
|
2022-04-01 12:51:01 +00:00
|
|
|
|
---@param _room fk.Room
|
2022-03-27 06:49:41 +00:00
|
|
|
|
function Room:initialize(_room)
|
2024-02-17 01:46:48 +00:00
|
|
|
|
AbstractRoom.initialize(self)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
self.room = _room
|
2023-06-16 02:56:33 +00:00
|
|
|
|
self.id = _room:getId()
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2023-02-15 16:54:39 +00:00
|
|
|
|
self.game_started = false
|
2022-04-30 07:27:56 +00:00
|
|
|
|
self.game_finished = false
|
|
|
|
|
self.timeout = _room:getTimeout()
|
|
|
|
|
self.tag = {}
|
2023-09-27 13:02:22 +00:00
|
|
|
|
self.general_pile = {}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
self.draw_pile = {}
|
|
|
|
|
self.discard_pile = {}
|
|
|
|
|
self.processing_area = {}
|
|
|
|
|
self.void = {}
|
|
|
|
|
self.card_place = {}
|
2022-09-14 05:01:10 +00:00
|
|
|
|
self.owner_map = {}
|
2023-04-27 06:15:08 +00:00
|
|
|
|
self.request_queue = {}
|
|
|
|
|
self.request_self = {}
|
2023-06-16 02:56:33 +00:00
|
|
|
|
|
|
|
|
|
self.settings = json.decode(self.room:settings())
|
2023-06-16 05:26:02 +00:00
|
|
|
|
self.disabled_packs = self.settings.disabledPack
|
2023-08-02 13:40:00 +00:00
|
|
|
|
if not Fk.game_modes[self.settings.gameMode] then
|
|
|
|
|
self.settings.gameMode = "aaa_role_mode"
|
|
|
|
|
end
|
|
|
|
|
|
2023-07-14 14:17:54 +00:00
|
|
|
|
table.insertTable(self.disabled_packs, Fk.game_mode_disabled[self.settings.gameMode])
|
2023-06-16 05:26:02 +00:00
|
|
|
|
self.disabled_generals = self.settings.disabledGenerals
|
2023-06-16 02:56:33 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 供调度器使用的函数。能让房间开始运行/从挂起状态恢复。
|
|
|
|
|
function Room:resume()
|
|
|
|
|
-- 如果还没运行的话就先创建自己的主协程
|
|
|
|
|
if not self.main_co then
|
|
|
|
|
self.main_co = coroutine.create(function()
|
2023-09-27 13:02:22 +00:00
|
|
|
|
self:makeGeneralPile()
|
2023-06-16 02:56:33 +00:00
|
|
|
|
self:run()
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local ret, err_msg, rest_time = true, true, nil
|
|
|
|
|
local main_co = self.main_co
|
|
|
|
|
|
|
|
|
|
if self:checkNoHuman() then
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if not self.game_finished then
|
|
|
|
|
ret, err_msg, rest_time = coroutine.resume(main_co, err_msg)
|
|
|
|
|
|
|
|
|
|
-- handle error
|
|
|
|
|
if ret == false then
|
2023-10-27 14:53:25 +00:00
|
|
|
|
fk.qCritical(err_msg .. "\n" .. debug.traceback(main_co))
|
2023-06-16 02:56:33 +00:00
|
|
|
|
goto GAME_OVER
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if rest_time == "over" then
|
|
|
|
|
goto GAME_OVER
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return false, rest_time
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
::GAME_OVER::
|
2023-06-30 20:12:19 +00:00
|
|
|
|
self:gameOver("")
|
|
|
|
|
-- coroutine.close(main_co)
|
|
|
|
|
-- self.main_co = nil
|
2023-06-16 02:56:33 +00:00
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2023-09-27 13:02:22 +00:00
|
|
|
|
-- 构造武将牌堆
|
|
|
|
|
function Room:makeGeneralPile()
|
|
|
|
|
local trueNames = {}
|
|
|
|
|
local ret = {}
|
|
|
|
|
if self.game_started then
|
|
|
|
|
for _, player in ipairs(self.players) do
|
|
|
|
|
trueNames[Fk.generals[player.general].trueName] = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
for name, general in pairs(Fk.generals) do
|
|
|
|
|
if Fk:canUseGeneral(name) and not trueNames[general.trueName] then
|
|
|
|
|
table.insert(ret, name)
|
|
|
|
|
trueNames[general.trueName] = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
table.shuffle(ret)
|
|
|
|
|
self.general_pile = ret
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2023-06-16 02:56:33 +00:00
|
|
|
|
-- 供调度器使用的函数,用来指示房间是否就绪。
|
|
|
|
|
-- 如果没有就绪的话,可能会返回第二个值来告诉调度器自己还有多久就绪。
|
|
|
|
|
function Room:isReady()
|
|
|
|
|
-- 没有活人了?那就告诉调度器我就绪了,恢复时候就会自己杀掉
|
|
|
|
|
if self:checkNoHuman(true) then
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 因为delay函数而延时:判断延时是否已经结束。
|
|
|
|
|
-- 注意整个delay函数的实现都搬到这来了,delay本身只负责挂起协程了。
|
|
|
|
|
if self.in_delay then
|
|
|
|
|
local rest = self.delay_duration - (os.getms() - self.delay_start) / 1000
|
|
|
|
|
if rest <= 0 then
|
|
|
|
|
self.in_delay = false
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
return false, rest
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 剩下的就是因为等待应答而未就绪了
|
|
|
|
|
-- 检查所有正在等回答的玩家,如果已经过了烧条时间
|
|
|
|
|
-- 那么就不认为他还需要时间就绪了
|
|
|
|
|
-- 然后在调度器第二轮刷新的时候就应该能返回自己已就绪
|
|
|
|
|
local ret = true
|
|
|
|
|
local rest
|
|
|
|
|
for _, p in ipairs(self.players) do
|
|
|
|
|
-- 这里判断的话需要用_splayer了,不然一控多的情况下会导致重复判断
|
|
|
|
|
if p._splayer:thinking() then
|
|
|
|
|
ret = false
|
|
|
|
|
-- 烧条烧光了的话就把thinking设为false
|
|
|
|
|
rest = p.request_timeout * 1000 - (os.getms() -
|
|
|
|
|
p.request_start) / 1000
|
|
|
|
|
|
2023-06-30 20:12:19 +00:00
|
|
|
|
if rest <= 0 or p.serverplayer:getState() ~= fk.Player_Online then
|
2023-06-16 02:56:33 +00:00
|
|
|
|
p._splayer:setThinking(false)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-07-16 07:32:16 +00:00
|
|
|
|
|
|
|
|
|
if self.race_request_list and table.contains(self.race_request_list, p) then
|
|
|
|
|
local result = p.serverplayer:waitForReply(0)
|
|
|
|
|
if result ~= "__notready" and result ~= "__cancel" and result ~= "" then
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-06-16 02:56:33 +00:00
|
|
|
|
end
|
|
|
|
|
return ret, (rest and rest > 1) and rest or nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Room:checkNoHuman(chkOnly)
|
|
|
|
|
if #self.players == 0 then return end
|
|
|
|
|
|
|
|
|
|
for _, p in ipairs(self.players) do
|
|
|
|
|
-- TODO: trust
|
|
|
|
|
if p.serverplayer:getState() == fk.Player_Online then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if not chkOnly then
|
|
|
|
|
self:gameOver("")
|
|
|
|
|
end
|
|
|
|
|
return true
|
2022-03-27 06:49:41 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-06-16 02:56:33 +00:00
|
|
|
|
function Room:__tostring()
|
|
|
|
|
return string.format("<Room #%d>", self.id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--[[ 敢删就寄,算了
|
|
|
|
|
function Room:__gc()
|
|
|
|
|
self.room:checkAbandoned()
|
|
|
|
|
end
|
|
|
|
|
--]]
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 正式在这个房间中开始游戏。
|
|
|
|
|
---
|
|
|
|
|
--- 当这个函数返回之后,整个Room线程也宣告结束。
|
|
|
|
|
---@return nil
|
2022-03-27 06:49:41 +00:00
|
|
|
|
function Room:run()
|
2023-06-30 20:12:19 +00:00
|
|
|
|
self.start_time = os.time()
|
2022-04-30 07:27:56 +00:00
|
|
|
|
for _, p in fk.qlist(self.room:getPlayers()) do
|
|
|
|
|
local player = ServerPlayer:new(p)
|
|
|
|
|
player.room = self
|
|
|
|
|
table.insert(self.players, player)
|
|
|
|
|
end
|
2022-03-28 14:24:30 +00:00
|
|
|
|
|
2023-03-13 16:12:02 +00:00
|
|
|
|
local mode = Fk.game_modes[self.settings.gameMode]
|
2024-01-10 14:51:29 +00:00
|
|
|
|
local logic = (mode.logic and mode.logic() or GameLogic):new(self)
|
|
|
|
|
self.logic = logic
|
|
|
|
|
if mode.rule then logic:addTriggerSkill(mode.rule) end
|
|
|
|
|
-- GameEvent(GameEvent.Game):exec()
|
|
|
|
|
logic:start()
|
2022-03-27 06:49:41 +00:00
|
|
|
|
end
|
2022-03-25 04:28:07 +00:00
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- getters/setters
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 基本算是私有函数,别去用
|
2022-09-15 03:17:13 +00:00
|
|
|
|
---@param cardId integer
|
|
|
|
|
---@param cardArea CardArea
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param owner? integer
|
2022-09-15 03:17:13 +00:00
|
|
|
|
function Room:setCardArea(cardId, cardArea, owner)
|
|
|
|
|
self.card_place[cardId] = cardArea
|
|
|
|
|
self.owner_map[cardId] = owner
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 获取一张牌所处的区域。
|
|
|
|
|
---@param cardId integer | Card @ 要获得区域的那张牌,可以是Card或者一个id
|
|
|
|
|
---@return CardArea @ 这张牌的区域
|
2022-09-15 03:17:13 +00:00
|
|
|
|
function Room:getCardArea(cardId)
|
2023-01-21 16:49:11 +00:00
|
|
|
|
if type(cardId) ~= "number" then
|
|
|
|
|
assert(cardId and cardId:isInstanceOf(Card))
|
|
|
|
|
cardId = cardId:getEffectiveId()
|
|
|
|
|
end
|
2022-09-15 03:17:13 +00:00
|
|
|
|
return self.card_place[cardId] or Card.Unknown
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 获得拥有某一张牌的玩家。
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param cardId integer | Card @ 要获得主人的那张牌,可以是Card实例或者id
|
|
|
|
|
---@return ServerPlayer? @ 这张牌的主人,可能返回nil
|
2023-02-15 11:54:35 +00:00
|
|
|
|
function Room:getCardOwner(cardId)
|
|
|
|
|
if type(cardId) ~= "number" then
|
|
|
|
|
assert(cardId and cardId:isInstanceOf(Card))
|
|
|
|
|
cardId = cardId:getEffectiveId()
|
|
|
|
|
end
|
|
|
|
|
return self.owner_map[cardId] and self:getPlayerById(self.owner_map[cardId]) or nil
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 根据玩家id,获得那名玩家本人。
|
|
|
|
|
---@param id integer @ 玩家的id
|
|
|
|
|
---@return ServerPlayer @ 这个id对应的ServerPlayer实例
|
2022-09-15 03:17:13 +00:00
|
|
|
|
function Room:getPlayerById(id)
|
2023-01-29 10:11:41 +00:00
|
|
|
|
if not id then return nil end
|
2022-09-15 03:17:13 +00:00
|
|
|
|
assert(type(id) == "number")
|
|
|
|
|
|
|
|
|
|
for _, p in ipairs(self.players) do
|
|
|
|
|
if p.id == id then
|
|
|
|
|
return p
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-02-15 11:54:35 +00:00
|
|
|
|
return nil
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-12-09 13:57:47 +00:00
|
|
|
|
--- 将房间中的玩家按照行动顺序重新排序。
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@param playerIds integer[] @ 玩家id列表,这个数组会被这个函数排序
|
2023-05-13 06:20:34 +00:00
|
|
|
|
function Room:sortPlayersByAction(playerIds, isTargetGroup)
|
|
|
|
|
table.sort(playerIds, function(prev, next)
|
|
|
|
|
local prevSeat = self:getPlayerById(isTargetGroup and prev[1] or prev).seat
|
|
|
|
|
local nextSeat = self:getPlayerById(isTargetGroup and next[1] or next).seat
|
2022-09-15 03:17:13 +00:00
|
|
|
|
|
2023-05-13 06:20:34 +00:00
|
|
|
|
return prevSeat < nextSeat
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
if
|
|
|
|
|
self.current and
|
|
|
|
|
table.find(isTargetGroup and TargetGroup:getRealTargets(playerIds) or playerIds, function(id)
|
|
|
|
|
return self:getPlayerById(id).seat >= self.current.seat
|
|
|
|
|
end)
|
|
|
|
|
then
|
|
|
|
|
while self:getPlayerById(isTargetGroup and playerIds[1][1] or playerIds[1]).seat < self.current.seat do
|
|
|
|
|
local toPlayerId = table.remove(playerIds, 1)
|
|
|
|
|
table.insert(playerIds, toPlayerId)
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Room:deadPlayerFilter(playerIds)
|
|
|
|
|
local newPlayerIds = {}
|
|
|
|
|
for _, playerId in ipairs(playerIds) do
|
|
|
|
|
if self:getPlayerById(playerId):isAlive() then
|
|
|
|
|
table.insert(newPlayerIds, playerId)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return newPlayerIds
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 获得当前房间中的所有玩家。
|
|
|
|
|
---
|
|
|
|
|
--- 返回的数组的第一个元素是当前回合玩家,并且按行动顺序进行排序。
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param sortBySeat? boolean @ 是否无视按座位排序直接返回
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@return ServerPlayer[] @ 房间中玩家的数组
|
2023-01-16 11:14:14 +00:00
|
|
|
|
function Room:getAllPlayers(sortBySeat)
|
2023-02-15 16:54:39 +00:00
|
|
|
|
if not self.game_started then
|
|
|
|
|
return { table.unpack(self.players) }
|
|
|
|
|
end
|
2023-01-16 11:14:14 +00:00
|
|
|
|
if sortBySeat == nil or sortBySeat then
|
|
|
|
|
local current = self.current
|
|
|
|
|
local temp = current.next
|
|
|
|
|
local ret = {current}
|
|
|
|
|
while temp ~= current do
|
2022-12-20 04:51:54 +00:00
|
|
|
|
table.insert(ret, temp)
|
2023-01-16 11:14:14 +00:00
|
|
|
|
temp = temp.next
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
else
|
|
|
|
|
return { table.unpack(self.players) }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 获得所有存活玩家,参看getAllPlayers
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param sortBySeat? boolean
|
2023-01-16 11:14:14 +00:00
|
|
|
|
---@return ServerPlayer[]
|
|
|
|
|
function Room:getAlivePlayers(sortBySeat)
|
|
|
|
|
if sortBySeat == nil or sortBySeat then
|
|
|
|
|
local current = self.current
|
|
|
|
|
local temp = current.next
|
2023-01-29 10:11:41 +00:00
|
|
|
|
|
|
|
|
|
-- did not arrange seat, use default
|
|
|
|
|
if temp == nil then
|
|
|
|
|
return { table.unpack(self.players) }
|
|
|
|
|
end
|
2023-01-16 11:14:14 +00:00
|
|
|
|
local ret = {current}
|
|
|
|
|
while temp ~= current do
|
|
|
|
|
if not temp.dead then
|
|
|
|
|
table.insert(ret, temp)
|
|
|
|
|
end
|
|
|
|
|
temp = temp.next
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
2023-01-16 11:14:14 +00:00
|
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
else
|
|
|
|
|
return { table.unpack(self.alive_players) }
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 获得除一名玩家外的其他玩家。
|
|
|
|
|
---@param player ServerPlayer @ 要排除的玩家
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param sortBySeat? boolean @ 是否要按座位排序?
|
|
|
|
|
---@param include_dead? boolean @ 是否要把死人也算进去?
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@return ServerPlayer[] @ 其他玩家列表
|
2023-01-16 11:14:14 +00:00
|
|
|
|
function Room:getOtherPlayers(player, sortBySeat, include_dead)
|
|
|
|
|
if sortBySeat == nil then
|
|
|
|
|
sortBySeat = true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local players = include_dead and self:getAllPlayers(sortBySeat) or self:getAlivePlayers(sortBySeat)
|
|
|
|
|
for _, p in ipairs(players) do
|
2022-09-15 03:17:13 +00:00
|
|
|
|
if p.id == player.id then
|
2023-01-16 11:14:14 +00:00
|
|
|
|
table.removeOne(players, player)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-16 11:14:14 +00:00
|
|
|
|
return players
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 获得当前房间中的主公。
|
|
|
|
|
---
|
|
|
|
|
--- 由于某些游戏模式没有主公,该函数可能返回nil。
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@return ServerPlayer? @ 主公
|
2022-09-15 03:17:13 +00:00
|
|
|
|
function Room:getLord()
|
|
|
|
|
local lord = self.players[1]
|
|
|
|
|
if lord.role == "lord" then return lord end
|
|
|
|
|
for _, p in ipairs(self.players) do
|
|
|
|
|
if p.role == "lord" then return p end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 从摸牌堆中获取若干张牌。
|
|
|
|
|
---
|
|
|
|
|
--- 注意了,这个函数会对牌堆进行实际操作,也就是说它返回一系列id后,牌堆中就会少这么多id。
|
|
|
|
|
---
|
|
|
|
|
--- 如果牌堆中没有足够的牌可以获得,那么会触发洗牌;还是不够的话,游戏就平局。
|
|
|
|
|
---@param num integer @ 要获得的牌的数量
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param from? string @ 获得牌的位置,可以是 ``"top"`` 或者 ``"bottom"``,表示牌堆顶还是牌堆底
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@return integer[] @ 得到的id
|
2022-09-15 03:17:13 +00:00
|
|
|
|
function Room:getNCards(num, from)
|
|
|
|
|
from = from or "top"
|
|
|
|
|
assert(from == "top" or from == "bottom")
|
2023-10-27 14:19:30 +00:00
|
|
|
|
if #self.draw_pile < num then
|
|
|
|
|
self:shuffleDrawPile()
|
|
|
|
|
if #self.draw_pile < num then
|
2024-04-01 16:56:04 +00:00
|
|
|
|
self:sendLog{
|
|
|
|
|
type = "#NoCardDraw",
|
|
|
|
|
toast = true,
|
|
|
|
|
}
|
2023-10-27 14:19:30 +00:00
|
|
|
|
self:gameOver("")
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-09-15 03:17:13 +00:00
|
|
|
|
|
|
|
|
|
local cardIds = {}
|
|
|
|
|
while num > 0 do
|
|
|
|
|
|
|
|
|
|
local index = from == "top" and 1 or #self.draw_pile
|
|
|
|
|
table.insert(cardIds, self.draw_pile[index])
|
|
|
|
|
table.remove(self.draw_pile, index)
|
|
|
|
|
|
|
|
|
|
num = num - 1
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-19 16:19:48 +00:00
|
|
|
|
self:doBroadcastNotify("UpdateDrawPile", #self.draw_pile)
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
return cardIds
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 将一名玩家的某种标记数量相应的值。
|
|
|
|
|
---
|
|
|
|
|
--- 在设置之后,会通知所有客户端也更新一下标记的值。之后的两个相同
|
|
|
|
|
---@param player ServerPlayer @ 要被更新标记的那个玩家
|
|
|
|
|
---@param mark string @ 标记的名称
|
2023-07-14 15:12:46 +00:00
|
|
|
|
---@param value any @ 要设为的值,其实也可以设为字符串
|
2022-12-18 04:52:52 +00:00
|
|
|
|
function Room:setPlayerMark(player, mark, value)
|
|
|
|
|
player:setMark(mark, value)
|
|
|
|
|
self:doBroadcastNotify("SetPlayerMark", json.encode{
|
|
|
|
|
player.id,
|
|
|
|
|
mark,
|
|
|
|
|
value
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 将一名玩家的mark标记增加count个。
|
|
|
|
|
---@param player ServerPlayer @ 要加标记的玩家
|
|
|
|
|
---@param mark string @ 标记名称
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param count? integer @ 要增加的数量,默认为1
|
2022-12-18 04:52:52 +00:00
|
|
|
|
function Room:addPlayerMark(player, mark, count)
|
|
|
|
|
count = count or 1
|
|
|
|
|
local num = player:getMark(mark)
|
|
|
|
|
num = num or 0
|
|
|
|
|
self:setPlayerMark(player, mark, math.max(num + count, 0))
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 将一名玩家的mark标记减少count个。
|
|
|
|
|
---@param player ServerPlayer @ 要减标记的玩家
|
|
|
|
|
---@param mark string @ 标记名称
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param count? integer @ 要减少的数量,默认为1
|
2022-12-18 04:52:52 +00:00
|
|
|
|
function Room:removePlayerMark(player, mark, count)
|
|
|
|
|
count = count or 1
|
|
|
|
|
local num = player:getMark(mark)
|
|
|
|
|
num = num or 0
|
|
|
|
|
self:setPlayerMark(player, mark, math.max(num - count, 0))
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-21 14:49:49 +00:00
|
|
|
|
--- 将一张卡牌的某种标记数量相应的值。
|
|
|
|
|
---
|
|
|
|
|
--- 在设置之后,会通知所有客户端也更新一下标记的值。之后的两个相同
|
|
|
|
|
---@param card Card @ 要被更新标记的那张牌
|
|
|
|
|
---@param mark string @ 标记的名称
|
2023-07-14 15:12:46 +00:00
|
|
|
|
---@param value any @ 要设为的值,其实也可以设为字符串
|
2023-04-21 14:49:49 +00:00
|
|
|
|
function Room:setCardMark(card, mark, value)
|
|
|
|
|
card:setMark(mark, value)
|
2023-06-23 14:18:11 +00:00
|
|
|
|
if not card:isVirtual() then
|
|
|
|
|
self:doBroadcastNotify("SetCardMark", json.encode{
|
|
|
|
|
card.id,
|
|
|
|
|
mark,
|
|
|
|
|
value
|
|
|
|
|
})
|
|
|
|
|
end
|
2023-04-21 14:49:49 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 将一张卡牌的mark标记增加count个。
|
|
|
|
|
---@param card Card @ 要被增加标记的那张牌
|
|
|
|
|
---@param mark string @ 标记名称
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param count? integer @ 要增加的数量,默认为1
|
2023-04-21 14:49:49 +00:00
|
|
|
|
function Room:addCardMark(card, mark, count)
|
|
|
|
|
count = count or 1
|
|
|
|
|
local num = card:getMark(mark)
|
|
|
|
|
num = num or 0
|
|
|
|
|
self:setCardMark(card, mark, math.max(num + count, 0))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 将一名玩家的mark标记减少count个。
|
|
|
|
|
---@param card Card @ 要被减少标记的那张牌
|
|
|
|
|
---@param mark string @ 标记名称
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param count? integer @ 要减少的数量,默认为1
|
2023-04-21 14:49:49 +00:00
|
|
|
|
function Room:removeCardMark(card, mark, count)
|
|
|
|
|
count = count or 1
|
|
|
|
|
local num = card:getMark(mark)
|
|
|
|
|
num = num or 0
|
|
|
|
|
self:setCardMark(card, mark, math.max(num - count, 0))
|
|
|
|
|
end
|
|
|
|
|
|
2023-06-09 18:18:51 +00:00
|
|
|
|
---@param player ServerPlayer
|
|
|
|
|
function Room:setPlayerProperty(player, property, value)
|
|
|
|
|
player[property] = value
|
|
|
|
|
self:broadcastProperty(player, property)
|
|
|
|
|
end
|
2023-04-21 14:49:49 +00:00
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 将房间中某个tag设为特定值。
|
|
|
|
|
---
|
|
|
|
|
--- 当在编程中想在服务端搞点全局变量的时候哦,不要自己设置全局变量或者上值,而是应该使用room的tag。
|
|
|
|
|
---@param tag_name string @ tag名字
|
|
|
|
|
---@param value any @ 值
|
2023-03-13 16:12:02 +00:00
|
|
|
|
function Room:setTag(tag_name, value)
|
|
|
|
|
self.tag[tag_name] = value
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 获得某个tag的值。
|
|
|
|
|
---@param tag_name string @ tag名字
|
2023-03-13 16:12:02 +00:00
|
|
|
|
function Room:getTag(tag_name)
|
|
|
|
|
return self.tag[tag_name]
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 删除某个tag。
|
|
|
|
|
---@param tag_name string @ tag名字
|
2023-03-13 16:12:02 +00:00
|
|
|
|
function Room:removeTag(tag_name)
|
|
|
|
|
self.tag[tag_name] = nil
|
|
|
|
|
end
|
|
|
|
|
|
2023-12-06 13:07:35 +00:00
|
|
|
|
function Room:setBanner(name, value)
|
2024-02-17 01:46:48 +00:00
|
|
|
|
AbstractRoom.setBanner(self, name, value)
|
2023-12-06 13:07:35 +00:00
|
|
|
|
self:doBroadcastNotify("SetBanner", json.encode{ name, value })
|
|
|
|
|
end
|
|
|
|
|
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@return boolean
|
2023-08-27 12:19:55 +00:00
|
|
|
|
local function execGameEvent(type, ...)
|
|
|
|
|
local event = GameEvent:new(type, ...)
|
|
|
|
|
local _, ret = event:exec()
|
|
|
|
|
return ret
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-04 18:21:59 +00:00
|
|
|
|
---@param player ServerPlayer
|
|
|
|
|
---@param general string
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param changeKingdom? boolean
|
|
|
|
|
---@param noBroadcast? boolean
|
2023-04-30 10:55:59 +00:00
|
|
|
|
function Room:setPlayerGeneral(player, general, changeKingdom, noBroadcast)
|
2023-04-04 18:21:59 +00:00
|
|
|
|
if Fk.generals[general] == nil then return end
|
|
|
|
|
player.general = general
|
|
|
|
|
player.gender = Fk.generals[general].gender
|
|
|
|
|
self:notifyProperty(player, player, "general")
|
|
|
|
|
self:broadcastProperty(player, "gender")
|
|
|
|
|
|
|
|
|
|
if changeKingdom then
|
|
|
|
|
player.kingdom = Fk.generals[general].kingdom
|
2023-04-30 10:55:59 +00:00
|
|
|
|
if noBroadcast then
|
|
|
|
|
self:notifyProperty(player, player, "kingdom")
|
|
|
|
|
else
|
|
|
|
|
self:broadcastProperty(player, "kingdom")
|
|
|
|
|
end
|
2023-04-04 18:21:59 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-19 06:07:16 +00:00
|
|
|
|
---@param player ServerPlayer
|
|
|
|
|
---@param general string
|
|
|
|
|
function Room:setDeputyGeneral(player, general)
|
|
|
|
|
if Fk.generals[general] == nil then return end
|
|
|
|
|
player.deputyGeneral = general
|
|
|
|
|
self:notifyProperty(player, player, "deputyGeneral")
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-23 13:10:07 +00:00
|
|
|
|
---@param player ServerPlayer @ 要换将的玩家
|
2023-08-02 13:50:47 +00:00
|
|
|
|
---@param new_general string @ 要变更的武将,若不存在则变身为孙策,孙策不存在变身为士兵
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param full? boolean @ 是否血量满状态变身
|
|
|
|
|
---@param isDeputy? boolean @ 是否变的是副将
|
|
|
|
|
---@param sendLog? boolean @ 是否发Log
|
|
|
|
|
---@param maxHpChange? boolean @ 是否改变体力上限,默认改变
|
2023-09-30 03:51:17 +00:00
|
|
|
|
function Room:changeHero(player, new_general, full, isDeputy, sendLog, maxHpChange, kingdomChange)
|
2023-08-02 13:50:47 +00:00
|
|
|
|
local new = Fk.generals[new_general] or Fk.generals["sunce"] or Fk.generals["blank_shibing"]
|
2023-04-23 13:10:07 +00:00
|
|
|
|
|
2023-09-30 03:51:17 +00:00
|
|
|
|
kingdomChange = (kingdomChange == nil) and true or kingdomChange
|
|
|
|
|
local kingdom = (isDeputy or not kingdomChange) and player.kingdom or new.kingdom
|
2024-04-01 16:56:04 +00:00
|
|
|
|
if not isDeputy and kingdomChange then
|
2023-08-27 12:19:55 +00:00
|
|
|
|
local allKingdoms = {}
|
2024-04-01 16:56:04 +00:00
|
|
|
|
if new.subkingdom then
|
2023-08-27 12:19:55 +00:00
|
|
|
|
allKingdoms = { new.kingdom, new.subkingdom }
|
2024-04-01 16:56:04 +00:00
|
|
|
|
else
|
|
|
|
|
allKingdoms = Fk:getKingdomMap(new.kingdom)
|
|
|
|
|
end
|
|
|
|
|
if #allKingdoms > 0 then
|
|
|
|
|
kingdom = self:askForChoice(player, allKingdoms, "AskForKingdom", "#ChooseInitialKingdom")
|
2023-08-27 12:19:55 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
execGameEvent(GameEvent.ChangeProperty,
|
|
|
|
|
{
|
|
|
|
|
from = player,
|
2023-12-12 12:06:07 +00:00
|
|
|
|
general = not isDeputy and new_general or nil,
|
|
|
|
|
deputyGeneral = isDeputy and new_general or nil,
|
2023-08-27 12:19:55 +00:00
|
|
|
|
gender = isDeputy and player.gender or new.gender,
|
|
|
|
|
kingdom = kingdom,
|
|
|
|
|
sendLog = sendLog,
|
|
|
|
|
results = {},
|
|
|
|
|
})
|
2023-04-23 13:10:07 +00:00
|
|
|
|
|
2023-08-24 13:37:06 +00:00
|
|
|
|
maxHpChange = (maxHpChange == nil) and true or maxHpChange
|
|
|
|
|
if maxHpChange then
|
|
|
|
|
self:setPlayerProperty(player, "maxHp", player:getGeneralMaxHp())
|
|
|
|
|
end
|
2023-07-16 07:29:20 +00:00
|
|
|
|
if full or player.hp > player.maxHp then
|
2023-08-02 13:50:47 +00:00
|
|
|
|
self:setPlayerProperty(player, "hp", player.maxHp)
|
2023-04-23 13:10:07 +00:00
|
|
|
|
end
|
2023-08-27 12:19:55 +00:00
|
|
|
|
end
|
2023-08-24 13:37:06 +00:00
|
|
|
|
|
2023-08-27 12:19:55 +00:00
|
|
|
|
---@param player ServerPlayer @ 要变更势力的玩家
|
|
|
|
|
---@param kingdom string @ 要变更的势力
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param sendLog? boolean @ 是否发Log
|
2023-08-27 12:19:55 +00:00
|
|
|
|
function Room:changeKingdom(player, kingdom, sendLog)
|
|
|
|
|
if kingdom == player.kingdom then return end
|
|
|
|
|
sendLog = sendLog or false
|
|
|
|
|
|
|
|
|
|
execGameEvent(GameEvent.ChangeProperty,
|
|
|
|
|
{
|
|
|
|
|
from = player,
|
|
|
|
|
kingdom = kingdom,
|
|
|
|
|
sendLog = sendLog,
|
|
|
|
|
results = {},
|
|
|
|
|
})
|
2023-04-23 13:10:07 +00:00
|
|
|
|
end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- 网络通信有关
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 向所有角色广播一名角色的某个property,让大家都知道
|
|
|
|
|
---@param player ServerPlayer @ 要被广而告之的那名角色
|
|
|
|
|
---@param property string @ 这名角色的某种属性,像是"hp"之类的,其实就是Player类的属性名
|
2022-03-28 14:24:30 +00:00
|
|
|
|
function Room:broadcastProperty(player, property)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
for _, p in ipairs(self.players) do
|
|
|
|
|
self:notifyProperty(p, player, property)
|
|
|
|
|
end
|
2022-03-25 04:28:07 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 将player的属性property告诉p。
|
|
|
|
|
---@param p ServerPlayer @ 要被告知相应属性的那名玩家
|
|
|
|
|
---@param player ServerPlayer @ 拥有那个属性的玩家
|
|
|
|
|
---@param property string @ 属性名称
|
2022-03-28 14:24:30 +00:00
|
|
|
|
function Room:notifyProperty(p, player, property)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
p:doNotify("PropertyUpdate", json.encode{
|
2022-05-02 06:00:47 +00:00
|
|
|
|
player.id,
|
2022-04-30 07:27:56 +00:00
|
|
|
|
property,
|
|
|
|
|
player[property],
|
|
|
|
|
})
|
2022-03-28 14:24:30 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 向多名玩家广播一条消息。
|
|
|
|
|
---@param command string @ 发出这条消息的消息类型
|
|
|
|
|
---@param jsonData string @ 消息的数据,一般是JSON字符串,也可以是普通字符串,取决于client怎么处理了
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param players? ServerPlayer[] @ 要告知的玩家列表,默认为所有人
|
2022-03-30 06:14:40 +00:00
|
|
|
|
function Room:doBroadcastNotify(command, jsonData, players)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
players = players or self.players
|
|
|
|
|
for _, p in ipairs(players) do
|
2023-02-15 11:54:35 +00:00
|
|
|
|
p:doNotify(command, jsonData)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
2022-03-30 06:14:40 +00:00
|
|
|
|
end
|
|
|
|
|
|
2024-02-26 18:28:13 +00:00
|
|
|
|
---@param room Room
|
|
|
|
|
local function surrenderCheck(room)
|
|
|
|
|
if not room.hasSurrendered then return end
|
|
|
|
|
local player = table.find(room.players, function(p)
|
|
|
|
|
return p.surrendered
|
|
|
|
|
end)
|
|
|
|
|
if not player then
|
|
|
|
|
room.hasSurrendered = false
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
room:broadcastProperty(player, "surrendered")
|
|
|
|
|
local mode = Fk.game_modes[room.settings.gameMode]
|
|
|
|
|
local winner = Pcall(mode.getWinner, mode, player)
|
|
|
|
|
if winner ~= "" then
|
|
|
|
|
room:gameOver(winner)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 以防万一
|
|
|
|
|
player.surrendered = false
|
|
|
|
|
room:broadcastProperty(player, "surrendered")
|
|
|
|
|
room.hasSurrendered = false
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 向某个玩家发起一次Request。
|
|
|
|
|
---@param player ServerPlayer @ 发出这个请求的目标玩家
|
|
|
|
|
---@param command string @ 请求的类型
|
|
|
|
|
---@param jsonData string @ 请求的数据
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param wait? boolean @ 是否要等待答复,默认为true
|
|
|
|
|
---@return string @ 收到的答复,如果wait为false的话就返回nil
|
2022-03-30 06:14:40 +00:00
|
|
|
|
function Room:doRequest(player, command, jsonData, wait)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
if wait == nil then wait = true end
|
2023-04-27 06:15:08 +00:00
|
|
|
|
self.request_queue = {}
|
2023-07-16 07:32:16 +00:00
|
|
|
|
self.race_request_list = nil
|
2022-04-30 07:27:56 +00:00
|
|
|
|
player:doRequest(command, jsonData, self.timeout)
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
if wait then
|
2023-04-27 06:15:08 +00:00
|
|
|
|
local ret = player:waitForReply(self.timeout)
|
|
|
|
|
player.serverplayer:setBusy(false)
|
2023-06-18 16:20:50 +00:00
|
|
|
|
player.serverplayer:setThinking(false)
|
2024-02-26 18:28:13 +00:00
|
|
|
|
surrenderCheck(self)
|
2023-04-27 06:15:08 +00:00
|
|
|
|
return ret
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
2022-03-30 06:14:40 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 向多名玩家发出请求。
|
|
|
|
|
---@param command string @ 请求类型
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param players? ServerPlayer[] @ 发出请求的玩家列表
|
|
|
|
|
---@param jsonData? string @ 请求数据
|
2022-12-18 04:52:52 +00:00
|
|
|
|
function Room:doBroadcastRequest(command, players, jsonData)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
players = players or self.players
|
2023-04-27 06:15:08 +00:00
|
|
|
|
self.request_queue = {}
|
2023-07-16 07:32:16 +00:00
|
|
|
|
self.race_request_list = nil
|
2022-04-30 07:27:56 +00:00
|
|
|
|
for _, p in ipairs(players) do
|
2023-04-27 06:15:08 +00:00
|
|
|
|
p:doRequest(command, jsonData or p.request_data)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local remainTime = self.timeout
|
|
|
|
|
local currentTime = os.time()
|
|
|
|
|
local elapsed = 0
|
|
|
|
|
for _, p in ipairs(players) do
|
|
|
|
|
elapsed = os.time() - currentTime
|
2022-12-18 04:52:52 +00:00
|
|
|
|
p:waitForReply(remainTime - elapsed)
|
|
|
|
|
end
|
2023-04-27 06:15:08 +00:00
|
|
|
|
|
|
|
|
|
for _, p in ipairs(players) do
|
|
|
|
|
p.serverplayer:setBusy(false)
|
2023-06-18 16:20:50 +00:00
|
|
|
|
p.serverplayer:setThinking(false)
|
2023-04-27 06:15:08 +00:00
|
|
|
|
end
|
2024-02-26 18:28:13 +00:00
|
|
|
|
|
|
|
|
|
surrenderCheck(self)
|
2022-12-18 04:52:52 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 向多名玩家发出竞争请求。
|
|
|
|
|
---
|
|
|
|
|
--- 他们都可以做出答复,但是服务器只认可第一个做出回答的角色。
|
|
|
|
|
---
|
|
|
|
|
--- 返回获胜的角色,可以通过属性获得回复的具体内容。
|
|
|
|
|
---@param command string @ 请求类型
|
|
|
|
|
---@param players ServerPlayer[] @ 要竞争这次请求的玩家列表
|
|
|
|
|
---@param jsonData string @ 请求数据
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@return ServerPlayer? @ 在这次竞争请求中获胜的角色,可能是nil
|
2022-12-18 04:52:52 +00:00
|
|
|
|
function Room:doRaceRequest(command, players, jsonData)
|
|
|
|
|
players = players or self.players
|
2023-04-27 06:15:08 +00:00
|
|
|
|
players = table.simpleClone(players)
|
|
|
|
|
local player_len = #players
|
2022-12-18 13:19:35 +00:00
|
|
|
|
-- self:notifyMoveFocus(players, command)
|
2023-04-27 06:15:08 +00:00
|
|
|
|
self.request_queue = {}
|
2023-07-16 07:32:16 +00:00
|
|
|
|
self.race_request_list = players
|
2022-12-18 04:52:52 +00:00
|
|
|
|
for _, p in ipairs(players) do
|
2023-04-27 06:15:08 +00:00
|
|
|
|
p:doRequest(command, jsonData or p.request_data)
|
2022-12-18 04:52:52 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local remainTime = self.timeout
|
|
|
|
|
local currentTime = os.time()
|
|
|
|
|
local elapsed = 0
|
|
|
|
|
local winner
|
2022-12-18 13:19:35 +00:00
|
|
|
|
local canceled_players = {}
|
2023-04-27 06:15:08 +00:00
|
|
|
|
local ret
|
2022-12-18 04:52:52 +00:00
|
|
|
|
while true do
|
|
|
|
|
elapsed = os.time() - currentTime
|
|
|
|
|
if remainTime - elapsed <= 0 then
|
2023-04-27 06:15:08 +00:00
|
|
|
|
break
|
2022-12-18 04:52:52 +00:00
|
|
|
|
end
|
|
|
|
|
for _, p in ipairs(players) do
|
|
|
|
|
p:waitForReply(0)
|
|
|
|
|
if p.reply_ready == true then
|
|
|
|
|
winner = p
|
|
|
|
|
break
|
|
|
|
|
end
|
2022-12-18 13:19:35 +00:00
|
|
|
|
|
|
|
|
|
if p.reply_cancel then
|
2023-04-27 06:15:08 +00:00
|
|
|
|
table.removeOne(players, p)
|
2022-12-18 13:19:35 +00:00
|
|
|
|
table.insertIfNeed(canceled_players, p)
|
2023-06-18 08:24:12 +00:00
|
|
|
|
elseif p.id > 0 then
|
|
|
|
|
-- 骗过调度器让他以为自己尚未就绪
|
2023-06-16 02:56:33 +00:00
|
|
|
|
p.request_timeout = remainTime - elapsed
|
|
|
|
|
p.serverplayer:setThinking(true)
|
|
|
|
|
end
|
2022-12-18 04:52:52 +00:00
|
|
|
|
end
|
|
|
|
|
if winner then
|
|
|
|
|
self:doBroadcastNotify("CancelRequest", "")
|
2023-04-27 06:15:08 +00:00
|
|
|
|
ret = winner
|
|
|
|
|
break
|
2022-12-18 04:52:52 +00:00
|
|
|
|
end
|
2022-12-18 13:19:35 +00:00
|
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
|
if player_len == #canceled_players then
|
|
|
|
|
break
|
2022-12-18 13:19:35 +00:00
|
|
|
|
end
|
2023-04-08 12:45:55 +00:00
|
|
|
|
|
2023-05-18 23:45:21 +00:00
|
|
|
|
coroutine.yield("__handleRequest", (remainTime - elapsed) * 1000)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
2023-04-27 06:15:08 +00:00
|
|
|
|
|
|
|
|
|
for _, p in ipairs(self.players) do
|
|
|
|
|
p.serverplayer:setBusy(false)
|
2023-06-18 16:20:50 +00:00
|
|
|
|
p.serverplayer:setThinking(false)
|
2023-04-27 06:15:08 +00:00
|
|
|
|
end
|
|
|
|
|
|
2024-02-26 18:28:13 +00:00
|
|
|
|
surrenderCheck(self)
|
2023-04-27 06:15:08 +00:00
|
|
|
|
return ret
|
2022-03-30 06:14:40 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-01-17 14:34:15 +00:00
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 延迟一段时间。
|
|
|
|
|
---
|
2023-06-16 02:56:33 +00:00
|
|
|
|
--- 这个函数不应该在请求处理协程中使用。
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@param ms integer @ 要延迟的毫秒数
|
2023-01-17 14:34:15 +00:00
|
|
|
|
function Room:delay(ms)
|
2023-02-21 05:44:24 +00:00
|
|
|
|
local start = os.getms()
|
2023-06-16 02:56:33 +00:00
|
|
|
|
self.delay_start = start
|
|
|
|
|
self.delay_duration = ms
|
|
|
|
|
self.in_delay = true
|
|
|
|
|
coroutine.yield("__handleRequest", ms)
|
2023-01-17 14:34:15 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 向多名玩家告知一次移牌行为。
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param players? ServerPlayer[] @ 要被告知的玩家列表,默认为全员
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@param card_moves CardsMoveStruct[] @ 要告知的移牌信息列表
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param forceVisible? boolean @ 是否让所有牌对告知目标可见
|
2022-04-14 10:22:00 +00:00
|
|
|
|
function Room:notifyMoveCards(players, card_moves, forceVisible)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
if players == nil or players == {} then players = self.players end
|
|
|
|
|
for _, p in ipairs(players) do
|
|
|
|
|
local arg = table.clone(card_moves)
|
|
|
|
|
for _, move in ipairs(arg) do
|
|
|
|
|
-- local to = self:getPlayerById(move.to)
|
|
|
|
|
|
2023-07-16 11:18:43 +00:00
|
|
|
|
for _, info in ipairs(move.moveInfo) do
|
|
|
|
|
local realFromArea = self:getCardArea(info.cardId)
|
|
|
|
|
local playerAreas = { Player.Hand, Player.Equip, Player.Judge, Player.Special }
|
|
|
|
|
local virtualEquip
|
|
|
|
|
|
|
|
|
|
if table.contains(playerAreas, realFromArea) and move.from then
|
|
|
|
|
virtualEquip = self:getPlayerById(move.from):getVirualEquip(info.cardId)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if table.contains(playerAreas, move.toArea) and move.to and virtualEquip then
|
|
|
|
|
self:getPlayerById(move.to):addVirtualEquip(virtualEquip)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-08-03 07:26:52 +00:00
|
|
|
|
local function containArea(area, relevant) --处理区的处理?
|
|
|
|
|
local areas = relevant
|
2023-08-11 16:50:17 +00:00
|
|
|
|
and {Card.PlayerEquip, Card.PlayerJudge, Card.DiscardPile, Card.Processing, Card.PlayerHand, Card.PlayerSpecial}
|
2023-08-03 07:26:52 +00:00
|
|
|
|
or {Card.PlayerEquip, Card.PlayerJudge, Card.DiscardPile, Card.Processing}
|
|
|
|
|
return table.contains(areas, area)
|
|
|
|
|
end
|
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
-- forceVisible make the move visible
|
2023-08-03 07:26:52 +00:00
|
|
|
|
-- if move is relevant to player's hands or equips, it should be open
|
2022-04-30 07:27:56 +00:00
|
|
|
|
-- cards move from/to equip/judge/discard/processing should be open
|
2023-08-03 07:26:52 +00:00
|
|
|
|
|
2023-08-13 07:05:45 +00:00
|
|
|
|
if not (move.moveVisible or forceVisible or containArea(move.toArea, move.to and p.isBuddy and p:isBuddy(move.to))) then
|
2022-04-30 07:27:56 +00:00
|
|
|
|
for _, info in ipairs(move.moveInfo) do
|
2023-08-03 07:26:52 +00:00
|
|
|
|
if not containArea(info.fromArea, move.from == p.id) then
|
2024-02-04 07:30:27 +00:00
|
|
|
|
info.cardId = -1
|
|
|
|
|
end
|
2022-04-14 10:22:00 +00:00
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
2022-04-14 10:22:00 +00:00
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
|
p:doNotify("MoveCards", json.encode(arg))
|
|
|
|
|
end
|
2022-04-14 10:22:00 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 将焦点转移给一名或者多名角色,并广而告之。
|
|
|
|
|
---
|
|
|
|
|
--- 形象点说,就是在那些玩家下面显示一个“弃牌 思考中...”之类的烧条提示。
|
|
|
|
|
---@param players ServerPlayer | ServerPlayer[] @ 要获得焦点的一名或者多名角色
|
|
|
|
|
---@param command string @ 烧条的提示文字
|
2022-09-15 03:17:13 +00:00
|
|
|
|
function Room:notifyMoveFocus(players, command)
|
|
|
|
|
if (players.class) then
|
|
|
|
|
players = {players}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
local ids = {}
|
|
|
|
|
for _, p in ipairs(players) do
|
|
|
|
|
table.insert(ids, p.id)
|
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2023-08-09 14:25:15 +00:00
|
|
|
|
local tempSk = Fk.skills[command]
|
|
|
|
|
if tempSk and #players == 1 then
|
|
|
|
|
local p = players[1]
|
|
|
|
|
if p:isFakeSkill(tempSk) then
|
|
|
|
|
command = ""
|
|
|
|
|
ids = table.map(self.alive_players, Util.IdMapper)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
self:doBroadcastNotify("MoveFocus", json.encode{
|
|
|
|
|
ids,
|
|
|
|
|
command
|
|
|
|
|
})
|
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 向战报中发送一条log。
|
|
|
|
|
---@param log LogMessage @ Log的实际内容
|
2022-12-18 04:52:52 +00:00
|
|
|
|
function Room:sendLog(log)
|
|
|
|
|
self:doBroadcastNotify("GameLog", json.encode(log))
|
|
|
|
|
end
|
|
|
|
|
|
2023-06-09 18:18:51 +00:00
|
|
|
|
function Room:sendFootnote(ids, log)
|
|
|
|
|
self:doBroadcastNotify("SetCardFootnote", json.encode{ ids, log })
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Room:sendCardVirtName(ids, name)
|
|
|
|
|
self:doBroadcastNotify("SetCardVirtName", json.encode{ ids, name })
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 播放某种动画效果给players看。
|
|
|
|
|
---@param type string @ 动画名字
|
|
|
|
|
---@param data any @ 这个动画附加的额外信息,在这个函数将会被转成json字符串
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param players? ServerPlayer[] @ 要观看动画的玩家们,默认为全员
|
2022-12-20 04:51:54 +00:00
|
|
|
|
function Room:doAnimate(type, data, players)
|
|
|
|
|
players = players or self.players
|
|
|
|
|
data.type = type
|
|
|
|
|
self:doBroadcastNotify("Animate", json.encode(data), players)
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 在player脸上展示名为name的emotion动效。
|
|
|
|
|
---
|
|
|
|
|
--- 这就是“杀”、“闪”之类的那个动画。
|
|
|
|
|
---@param player ServerPlayer @ 被播放动画的那个角色
|
|
|
|
|
---@param name string @ emotion名字,可以是一个路径
|
2022-12-20 04:51:54 +00:00
|
|
|
|
function Room:setEmotion(player, name)
|
|
|
|
|
self:doAnimate("Emotion", {
|
|
|
|
|
player = player.id,
|
|
|
|
|
emotion = name
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 在一张card上播放一段emotion动效。
|
|
|
|
|
---
|
|
|
|
|
--- 这张card必须在处理区里面,或者至少客户端觉得它在处理区。
|
|
|
|
|
---@param cid integer @ 被播放动效的那个牌的id
|
|
|
|
|
---@param name string @ emotion名字,可以是一个路径
|
2023-01-29 10:11:41 +00:00
|
|
|
|
function Room:setCardEmotion(cid, name)
|
|
|
|
|
self:doAnimate("Emotion", {
|
|
|
|
|
player = cid,
|
|
|
|
|
emotion = name,
|
|
|
|
|
is_card = true,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 播放一个全屏大动画。可以自己指定qml文件路径和额外的信息。
|
|
|
|
|
---@param path string @ qml文件的路径,有默认值
|
|
|
|
|
---@param extra_data any @ 要传递的额外信息
|
2023-02-21 05:44:24 +00:00
|
|
|
|
function Room:doSuperLightBox(path, extra_data)
|
|
|
|
|
path = path or "RoomElement/SuperLightBox.qml"
|
|
|
|
|
self:doAnimate("SuperLightBox", {
|
|
|
|
|
path = path,
|
|
|
|
|
data = extra_data,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 基本上是个不常用函数就是了
|
2022-12-20 04:51:54 +00:00
|
|
|
|
function Room:sendLogEvent(type, data, players)
|
|
|
|
|
players = players or self.players
|
|
|
|
|
data.type = type
|
|
|
|
|
self:doBroadcastNotify("LogEvent", json.encode(data), players)
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 播放技能的语音。
|
2023-08-24 13:37:24 +00:00
|
|
|
|
---@param skill_name nil @ 技能名
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param index? integer @ 语音编号,默认为-1(也就是随机播放)
|
2023-01-29 10:11:41 +00:00
|
|
|
|
function Room:broadcastSkillInvoke(skill_name, index)
|
2023-10-27 14:53:25 +00:00
|
|
|
|
fk.qCritical 'Room:broadcastSkillInvoke deprecated; use SPlayer:broadcastSkillInvoke'
|
2023-01-29 10:11:41 +00:00
|
|
|
|
index = index or -1
|
|
|
|
|
self:sendLogEvent("PlaySkillSound", {
|
|
|
|
|
name = skill_name,
|
|
|
|
|
i = index
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 播放一段音频。
|
|
|
|
|
---@param path string @ 音频文件路径
|
2023-01-29 10:11:41 +00:00
|
|
|
|
function Room:broadcastPlaySound(path)
|
|
|
|
|
self:sendLogEvent("PlaySound", {
|
|
|
|
|
name = path,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 在player的脸上播放技能发动的特效。
|
|
|
|
|
---
|
|
|
|
|
--- 与此同时,在战报里面发一条“xxx发动了xxx”
|
|
|
|
|
---@param player ServerPlayer @ 发动技能的那个玩家
|
|
|
|
|
---@param skill_name string @ 技能名
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param skill_type? string @ 技能的动画效果,默认是那个技能的anim_type
|
2023-01-16 11:13:07 +00:00
|
|
|
|
function Room:notifySkillInvoked(player, skill_name, skill_type)
|
2023-08-01 17:57:08 +00:00
|
|
|
|
local bigAnim = false
|
2023-01-29 10:11:41 +00:00
|
|
|
|
if not skill_type then
|
|
|
|
|
local skill = Fk.skills[skill_name]
|
|
|
|
|
if not skill then skill_type = "" end
|
2023-08-01 17:57:08 +00:00
|
|
|
|
|
|
|
|
|
if skill.frequency == Skill.Limited or skill.frequency == Skill.Wake then
|
|
|
|
|
bigAnim = true
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
|
skill_type = skill.anim_type
|
|
|
|
|
end
|
2023-08-01 17:57:08 +00:00
|
|
|
|
|
|
|
|
|
if skill_type == "big" then bigAnim = true end
|
|
|
|
|
|
2023-01-16 11:13:07 +00:00
|
|
|
|
self:sendLog{
|
|
|
|
|
type = "#InvokeSkill",
|
|
|
|
|
from = player.id,
|
|
|
|
|
arg = skill_name,
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-01 17:57:08 +00:00
|
|
|
|
if not bigAnim then
|
|
|
|
|
self:doAnimate("InvokeSkill", {
|
|
|
|
|
name = skill_name,
|
|
|
|
|
player = player.id,
|
|
|
|
|
skill_type = skill_type,
|
|
|
|
|
})
|
|
|
|
|
else
|
|
|
|
|
self:doAnimate("InvokeUltSkill", {
|
|
|
|
|
name = skill_name,
|
|
|
|
|
player = player.id,
|
2024-01-24 19:13:57 +00:00
|
|
|
|
deputy = player.deputyGeneral and player.deputyGeneral ~= "" and table.contains(Fk.generals[player.deputyGeneral]:getSkillNameList(true), skill_name),
|
2023-08-01 17:57:08 +00:00
|
|
|
|
})
|
|
|
|
|
self:delay(2000)
|
|
|
|
|
end
|
2023-01-29 10:11:41 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 播放从source指到targets的指示线效果。
|
|
|
|
|
---@param source integer @ 指示线开始的那个玩家的id
|
|
|
|
|
---@param targets integer[] @ 指示线目标玩家的id列表
|
2023-01-29 10:11:41 +00:00
|
|
|
|
function Room:doIndicate(source, targets)
|
|
|
|
|
local target_group = {}
|
|
|
|
|
for _, id in ipairs(targets) do
|
|
|
|
|
table.insert(target_group, { id })
|
|
|
|
|
end
|
|
|
|
|
self:doAnimate("Indicate", {
|
|
|
|
|
from = source,
|
|
|
|
|
to = target_group,
|
|
|
|
|
})
|
2023-01-16 11:13:07 +00:00
|
|
|
|
end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- 交互方法
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问player是否要发动一个主动技。
|
|
|
|
|
---
|
|
|
|
|
--- 如果发动的话,那么会执行一下技能的onUse函数,然后返回选择的牌和目标等。
|
|
|
|
|
---@param player ServerPlayer @ 询问目标
|
|
|
|
|
---@param skill_name string @ 主动技的技能名
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param prompt? string @ 烧条上面显示的提示文本内容
|
|
|
|
|
---@param cancelable? boolean @ 是否可以点取消
|
|
|
|
|
---@param extra_data? table @ 额外信息,因技能而异了
|
|
|
|
|
---@param no_indicate? boolean @ 是否不显示指示线
|
|
|
|
|
---@return boolean, table?
|
2023-06-10 15:51:09 +00:00
|
|
|
|
function Room:askForUseActiveSkill(player, skill_name, prompt, cancelable, extra_data, no_indicate)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
prompt = prompt or ""
|
2023-06-09 18:18:51 +00:00
|
|
|
|
cancelable = (cancelable == nil) and true or cancelable
|
2023-06-10 15:51:09 +00:00
|
|
|
|
no_indicate = (no_indicate == nil) and true or no_indicate
|
2023-06-11 08:22:11 +00:00
|
|
|
|
extra_data = extra_data or Util.DummyTable
|
2022-09-15 03:17:13 +00:00
|
|
|
|
local skill = Fk.skills[skill_name]
|
2023-05-19 15:03:39 +00:00
|
|
|
|
if not (skill and (skill:isInstanceOf(ActiveSkill) or skill:isInstanceOf(ViewAsSkill))) then
|
2022-09-15 03:17:13 +00:00
|
|
|
|
print("Attempt ask for use non-active skill: " .. skill_name)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
local command = "AskForUseActiveSkill"
|
2023-02-26 07:01:14 +00:00
|
|
|
|
self:notifyMoveFocus(player, extra_data.skillName or skill_name) -- for display skill name instead of command name
|
2023-12-03 10:45:25 +00:00
|
|
|
|
local data = {skill_name, prompt, cancelable, extra_data}
|
2023-04-10 07:55:06 +00:00
|
|
|
|
|
|
|
|
|
Fk.currentResponseReason = extra_data.skillName
|
2022-09-15 03:17:13 +00:00
|
|
|
|
local result = self:doRequest(player, command, json.encode(data))
|
2023-04-10 07:55:06 +00:00
|
|
|
|
Fk.currentResponseReason = nil
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
if result == "" then
|
|
|
|
|
return false
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
2022-04-08 10:39:58 +00:00
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
data = json.decode(result)
|
|
|
|
|
local card = data.card
|
|
|
|
|
local targets = data.targets
|
|
|
|
|
local card_data = json.decode(card)
|
|
|
|
|
local selected_cards = card_data.subcards
|
2023-12-28 04:15:01 +00:00
|
|
|
|
local interaction
|
2023-06-10 15:51:09 +00:00
|
|
|
|
if not no_indicate then
|
|
|
|
|
self:doIndicate(player.id, targets)
|
|
|
|
|
end
|
2023-05-19 15:03:39 +00:00
|
|
|
|
|
|
|
|
|
if skill.interaction then
|
2023-12-28 04:15:01 +00:00
|
|
|
|
interaction = data.interaction_data
|
|
|
|
|
skill.interaction.data = interaction
|
2023-05-19 15:03:39 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if skill:isInstanceOf(ActiveSkill) then
|
|
|
|
|
skill:onUse(self, {
|
|
|
|
|
from = player.id,
|
|
|
|
|
cards = selected_cards,
|
|
|
|
|
tos = targets,
|
|
|
|
|
})
|
|
|
|
|
end
|
2022-04-08 10:39:58 +00:00
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
return true, {
|
|
|
|
|
cards = selected_cards,
|
2023-12-28 04:15:01 +00:00
|
|
|
|
targets = targets,
|
|
|
|
|
interaction = interaction
|
2022-09-15 03:17:13 +00:00
|
|
|
|
}
|
2022-04-08 10:39:58 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-05-19 15:03:39 +00:00
|
|
|
|
Room.askForUseViewAsSkill = Room.askForUseActiveSkill
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问一名角色弃牌。
|
|
|
|
|
---
|
2023-06-04 11:39:20 +00:00
|
|
|
|
--- 在这个函数里面牌已经被弃掉了(除非skipDiscard为true)。
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@param player ServerPlayer @ 弃牌角色
|
|
|
|
|
---@param minNum integer @ 最小值
|
|
|
|
|
---@param maxNum integer @ 最大值
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param includeEquip? boolean @ 能不能弃装备区?
|
|
|
|
|
---@param skillName? string @ 引发弃牌的技能名
|
|
|
|
|
---@param cancelable? boolean @ 能不能点取消?
|
|
|
|
|
---@param pattern? string @ 弃牌需要符合的规则
|
|
|
|
|
---@param prompt? string @ 提示信息
|
|
|
|
|
---@param skipDiscard? boolean @ 是否跳过弃牌(即只询问选择可以弃置的牌)
|
|
|
|
|
---@param no_indicate? boolean @ 是否不显示指示线
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@return integer[] @ 弃掉的牌的id列表,可能是空的
|
2023-06-10 15:51:09 +00:00
|
|
|
|
function Room:askForDiscard(player, minNum, maxNum, includeEquip, skillName, cancelable, pattern, prompt, skipDiscard, no_indicate)
|
2023-06-09 18:18:51 +00:00
|
|
|
|
cancelable = (cancelable == nil) and true or cancelable
|
2023-06-10 15:51:09 +00:00
|
|
|
|
no_indicate = no_indicate or false
|
2023-08-02 13:50:47 +00:00
|
|
|
|
pattern = pattern or "."
|
2023-04-10 07:55:06 +00:00
|
|
|
|
|
|
|
|
|
local canDiscards = table.filter(
|
|
|
|
|
player:getCardIds{ Player.Hand, includeEquip and Player.Equip or nil }, function(id)
|
|
|
|
|
local checkpoint = true
|
|
|
|
|
local card = Fk:getCardById(id)
|
|
|
|
|
|
2023-06-11 08:22:11 +00:00
|
|
|
|
local status_skills = Fk:currentRoom().status_skills[ProhibitSkill] or Util.DummyTable
|
2023-04-10 07:55:06 +00:00
|
|
|
|
for _, skill in ipairs(status_skills) do
|
|
|
|
|
if skill:prohibitDiscard(player, card) then
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-06-04 11:39:20 +00:00
|
|
|
|
if skillName == "game_rule" then
|
2023-06-11 08:22:11 +00:00
|
|
|
|
status_skills = Fk:currentRoom().status_skills[MaxCardsSkill] or Util.DummyTable
|
2023-06-04 11:39:20 +00:00
|
|
|
|
for _, skill in ipairs(status_skills) do
|
|
|
|
|
if skill:excludeFrom(player, card) then
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-04-10 07:55:06 +00:00
|
|
|
|
|
|
|
|
|
if pattern ~= "" then
|
|
|
|
|
checkpoint = checkpoint and (Exppattern:Parse(pattern):match(card))
|
|
|
|
|
end
|
|
|
|
|
return checkpoint
|
|
|
|
|
end
|
|
|
|
|
)
|
|
|
|
|
|
2023-06-14 05:40:50 +00:00
|
|
|
|
-- maxNum = math.min(#canDiscards, maxNum)
|
|
|
|
|
-- minNum = math.min(#canDiscards, minNum)
|
2023-04-10 07:55:06 +00:00
|
|
|
|
|
2023-06-15 13:19:57 +00:00
|
|
|
|
if minNum >= #canDiscards and not cancelable then
|
|
|
|
|
if not skipDiscard then
|
|
|
|
|
self:throwCard(canDiscards, skillName, player, player)
|
|
|
|
|
end
|
|
|
|
|
return canDiscards
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local toDiscard = {}
|
2022-09-15 03:17:13 +00:00
|
|
|
|
local data = {
|
|
|
|
|
num = maxNum,
|
|
|
|
|
min_num = minNum,
|
|
|
|
|
include_equip = includeEquip,
|
2023-04-10 07:55:06 +00:00
|
|
|
|
skillName = skillName,
|
2023-03-20 12:15:24 +00:00
|
|
|
|
pattern = pattern,
|
2022-09-15 03:17:13 +00:00
|
|
|
|
}
|
2023-04-04 07:59:21 +00:00
|
|
|
|
local prompt = prompt or ("#AskForDiscard:::" .. maxNum .. ":" .. minNum)
|
2023-06-10 15:51:09 +00:00
|
|
|
|
local _, ret = self:askForUseActiveSkill(player, "discard_skill", prompt, cancelable, data, no_indicate)
|
2023-04-10 07:55:06 +00:00
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
if ret then
|
|
|
|
|
toDiscard = ret.cards
|
|
|
|
|
else
|
2023-02-15 11:54:35 +00:00
|
|
|
|
if cancelable then return {} end
|
2024-02-04 07:30:27 +00:00
|
|
|
|
toDiscard = table.random(canDiscards, minNum) ---@type integer[]
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-05-28 10:45:54 +00:00
|
|
|
|
if not skipDiscard then
|
|
|
|
|
self:throwCard(toDiscard, skillName, player, player)
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-21 16:49:11 +00:00
|
|
|
|
return toDiscard
|
2022-04-08 10:39:58 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问一名玩家从targets中选择若干名玩家出来。
|
|
|
|
|
---@param player ServerPlayer @ 要做选择的玩家
|
|
|
|
|
---@param targets integer[] @ 可以选的目标范围,是玩家id数组
|
|
|
|
|
---@param minNum integer @ 最小值
|
|
|
|
|
---@param maxNum integer @ 最大值
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param prompt? string @ 提示信息
|
|
|
|
|
---@param skillName? string @ 技能名
|
|
|
|
|
---@param cancelable? boolean @ 能否点取消
|
|
|
|
|
---@param no_indicate? boolean @ 是否不显示指示线
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@return integer[] @ 选择的玩家id列表,可能为空
|
2023-06-10 15:51:09 +00:00
|
|
|
|
function Room:askForChoosePlayers(player, targets, minNum, maxNum, prompt, skillName, cancelable, no_indicate)
|
2023-01-29 10:11:41 +00:00
|
|
|
|
if maxNum < 1 then
|
|
|
|
|
return {}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
2023-06-09 18:18:51 +00:00
|
|
|
|
cancelable = (cancelable == nil) and true or cancelable
|
2023-06-10 15:51:09 +00:00
|
|
|
|
no_indicate = no_indicate or false
|
2022-04-08 10:39:58 +00:00
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
local data = {
|
|
|
|
|
targets = targets,
|
|
|
|
|
num = maxNum,
|
|
|
|
|
min_num = minNum,
|
2023-02-26 07:01:14 +00:00
|
|
|
|
pattern = "",
|
|
|
|
|
skillName = skillName
|
2022-09-15 03:17:13 +00:00
|
|
|
|
}
|
2023-06-10 15:51:09 +00:00
|
|
|
|
local _, ret = self:askForUseActiveSkill(player, "choose_players_skill", prompt or "", cancelable, data, no_indicate)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
if ret then
|
|
|
|
|
return ret.targets
|
|
|
|
|
else
|
2023-04-04 07:59:21 +00:00
|
|
|
|
if cancelable then
|
|
|
|
|
return {}
|
|
|
|
|
else
|
|
|
|
|
return table.random(targets, minNum)
|
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
2022-03-30 06:14:40 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问一名玩家选择自己的几张牌。
|
|
|
|
|
---
|
|
|
|
|
--- 与askForDiscard类似,但是不对选择的牌进行操作就是了。
|
|
|
|
|
---@param player ServerPlayer @ 要询问的玩家
|
|
|
|
|
---@param minNum integer @ 最小值
|
|
|
|
|
---@param maxNum integer @ 最大值
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param includeEquip? boolean @ 能不能选装备
|
|
|
|
|
---@param skillName? string @ 技能名
|
|
|
|
|
---@param cancelable? boolean @ 能否点取消
|
|
|
|
|
---@param pattern? string @ 选牌规则
|
|
|
|
|
---@param prompt? string @ 提示信息
|
|
|
|
|
---@param expand_pile? string @ 可选私人牌堆名称
|
|
|
|
|
---@param no_indicate? boolean @ 是否不显示指示线
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@return integer[] @ 选择的牌的id列表,可能是空的
|
2023-06-10 15:51:09 +00:00
|
|
|
|
function Room:askForCard(player, minNum, maxNum, includeEquip, skillName, cancelable, pattern, prompt, expand_pile, no_indicate)
|
2023-03-14 12:48:08 +00:00
|
|
|
|
if minNum < 1 then
|
2023-12-03 11:35:14 +00:00
|
|
|
|
return {}
|
2023-03-14 12:48:08 +00:00
|
|
|
|
end
|
2023-06-09 18:18:51 +00:00
|
|
|
|
cancelable = (cancelable == nil) and true or cancelable
|
2023-06-10 15:51:09 +00:00
|
|
|
|
no_indicate = no_indicate or false
|
2023-08-02 13:50:47 +00:00
|
|
|
|
pattern = pattern or "."
|
2023-03-14 12:48:08 +00:00
|
|
|
|
|
|
|
|
|
local chosenCards = {}
|
|
|
|
|
local data = {
|
|
|
|
|
num = maxNum,
|
|
|
|
|
min_num = minNum,
|
|
|
|
|
include_equip = includeEquip,
|
2023-04-10 07:55:06 +00:00
|
|
|
|
skillName = skillName,
|
2023-03-20 12:15:24 +00:00
|
|
|
|
pattern = pattern,
|
2023-04-04 08:25:37 +00:00
|
|
|
|
expand_pile = expand_pile,
|
2023-03-14 12:48:08 +00:00
|
|
|
|
}
|
2024-02-04 07:30:27 +00:00
|
|
|
|
prompt = prompt or ("#AskForCard:::" .. maxNum .. ":" .. minNum)
|
2023-06-11 08:22:11 +00:00
|
|
|
|
local _, ret = self:askForUseActiveSkill(player, "choose_cards_skill", prompt, cancelable, data, no_indicate)
|
2023-03-14 12:48:08 +00:00
|
|
|
|
if ret then
|
|
|
|
|
chosenCards = ret.cards
|
|
|
|
|
else
|
|
|
|
|
if cancelable then return {} end
|
2023-12-09 13:57:47 +00:00
|
|
|
|
local cards = player:getCardIds("he&")
|
2023-09-27 13:02:22 +00:00
|
|
|
|
local exp = Exppattern:Parse(pattern)
|
2023-12-09 13:57:47 +00:00
|
|
|
|
cards = table.filter(cards, function(cid)
|
2023-09-27 13:02:22 +00:00
|
|
|
|
return exp:match(Fk:getCardById(cid))
|
|
|
|
|
end)
|
2023-12-09 13:57:47 +00:00
|
|
|
|
chosenCards = table.random(cards, minNum)
|
2023-03-14 12:48:08 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return chosenCards
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问玩家选择1张牌和若干名角色。
|
|
|
|
|
---
|
|
|
|
|
--- 返回两个值,第一个是选择的目标列表,第二个是选择的那张牌的id
|
|
|
|
|
---@param player ServerPlayer @ 要询问的玩家
|
|
|
|
|
---@param targets integer[] @ 选择目标的id范围
|
|
|
|
|
---@param minNum integer @ 选目标最小值
|
|
|
|
|
---@param maxNum integer @ 选目标最大值
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param pattern? string @ 选牌规则
|
|
|
|
|
---@param prompt? string @ 提示信息
|
|
|
|
|
---@param cancelable? boolean @ 能否点取消
|
|
|
|
|
---@param no_indicate? boolean @ 是否不显示指示线
|
2023-02-26 07:01:14 +00:00
|
|
|
|
---@return integer[], integer
|
2023-06-10 15:51:09 +00:00
|
|
|
|
function Room:askForChooseCardAndPlayers(player, targets, minNum, maxNum, pattern, prompt, skillName, cancelable, no_indicate)
|
2023-02-26 07:01:14 +00:00
|
|
|
|
if maxNum < 1 then
|
|
|
|
|
return {}
|
|
|
|
|
end
|
2023-06-09 18:18:51 +00:00
|
|
|
|
cancelable = (cancelable == nil) and true or cancelable
|
2023-06-10 15:51:09 +00:00
|
|
|
|
no_indicate = no_indicate or false
|
2023-04-08 01:43:59 +00:00
|
|
|
|
pattern = pattern or "."
|
2023-02-26 07:01:14 +00:00
|
|
|
|
|
2023-04-04 07:59:21 +00:00
|
|
|
|
local pcards = table.filter(player:getCardIds({ Player.Hand, Player.Equip }), function(id)
|
|
|
|
|
local c = Fk:getCardById(id)
|
|
|
|
|
return c:matchPattern(pattern)
|
|
|
|
|
end)
|
2023-08-12 11:19:03 +00:00
|
|
|
|
if #pcards == 0 and not cancelable then return {} end
|
2023-04-04 07:59:21 +00:00
|
|
|
|
|
2023-02-26 07:01:14 +00:00
|
|
|
|
local data = {
|
|
|
|
|
targets = targets,
|
|
|
|
|
num = maxNum,
|
|
|
|
|
min_num = minNum,
|
2023-04-08 01:32:51 +00:00
|
|
|
|
pattern = pattern,
|
2023-02-26 07:01:14 +00:00
|
|
|
|
skillName = skillName
|
|
|
|
|
}
|
2023-06-10 15:51:09 +00:00
|
|
|
|
local _, ret = self:askForUseActiveSkill(player, "choose_players_skill", prompt or "", cancelable, data, no_indicate)
|
2023-02-26 07:01:14 +00:00
|
|
|
|
if ret then
|
|
|
|
|
return ret.targets, ret.cards[1]
|
|
|
|
|
else
|
2023-04-04 07:59:21 +00:00
|
|
|
|
if cancelable then
|
|
|
|
|
return {}
|
|
|
|
|
else
|
|
|
|
|
return table.random(targets, minNum), table.random(pcards)
|
|
|
|
|
end
|
2023-02-26 07:01:14 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-11-07 04:57:00 +00:00
|
|
|
|
--- 询问玩家选择X张牌和Y名角色。
|
|
|
|
|
---
|
2023-12-28 04:15:01 +00:00
|
|
|
|
--- 返回两个值,第一个是选择的目标列表,第二个是选择的牌id列表
|
2023-11-07 04:57:00 +00:00
|
|
|
|
---@param player ServerPlayer @ 要询问的玩家
|
|
|
|
|
---@param minCardNum integer @ 选卡牌最小值
|
|
|
|
|
---@param maxCardNum integer @ 选卡牌最大值
|
|
|
|
|
---@param targets integer[] @ 选择目标的id范围
|
|
|
|
|
---@param minTargetNum integer @ 选目标最小值
|
|
|
|
|
---@param maxTargetNum integer @ 选目标最大值
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param pattern? string @ 选牌规则
|
|
|
|
|
---@param prompt? string @ 提示信息
|
|
|
|
|
---@param cancelable? boolean @ 能否点取消
|
|
|
|
|
---@param no_indicate? boolean @ 是否不显示指示线
|
2023-11-07 04:57:00 +00:00
|
|
|
|
---@return integer[], integer[]
|
2023-12-06 13:07:35 +00:00
|
|
|
|
function Room:askForChooseCardsAndPlayers(player, minCardNum, maxCardNum, targets, minTargetNum, maxTargetNum, pattern, prompt, skillName, cancelable, no_indicate)
|
2023-11-07 04:57:00 +00:00
|
|
|
|
if minCardNum < 1 or minTargetNum < 1 then
|
2023-12-06 13:07:35 +00:00
|
|
|
|
return {}, {}
|
2023-11-07 04:57:00 +00:00
|
|
|
|
end
|
|
|
|
|
cancelable = (cancelable == nil) and true or cancelable
|
|
|
|
|
no_indicate = no_indicate or false
|
|
|
|
|
pattern = pattern or "."
|
|
|
|
|
|
|
|
|
|
local pcards = table.filter(player:getCardIds({ Player.Hand, Player.Equip }), function(id)
|
|
|
|
|
local c = Fk:getCardById(id)
|
|
|
|
|
return c:matchPattern(pattern)
|
|
|
|
|
end)
|
2023-12-28 04:15:01 +00:00
|
|
|
|
if #pcards < minCardNum and not cancelable then return {}, {} end
|
2023-11-07 04:57:00 +00:00
|
|
|
|
|
|
|
|
|
local data = {
|
|
|
|
|
targets = targets,
|
2024-04-01 16:56:04 +00:00
|
|
|
|
max_t_num = maxTargetNum,
|
|
|
|
|
min_t_num = minTargetNum,
|
|
|
|
|
max_c_num = maxCardNum,
|
|
|
|
|
min_c_num = minCardNum,
|
2023-11-07 04:57:00 +00:00
|
|
|
|
pattern = pattern,
|
|
|
|
|
skillName = skillName,
|
2023-12-28 04:15:01 +00:00
|
|
|
|
-- include_equip = includeEquip, -- FIXME: 预定一个破坏性更新
|
|
|
|
|
-- expand_pile = expandPile,
|
2023-11-07 04:57:00 +00:00
|
|
|
|
}
|
|
|
|
|
local _, ret = self:askForUseActiveSkill(player, "ex__choose_skill", prompt or "", cancelable, data, no_indicate)
|
|
|
|
|
if ret then
|
|
|
|
|
return ret.targets, ret.cards
|
|
|
|
|
else
|
|
|
|
|
if cancelable then
|
2023-12-06 13:07:35 +00:00
|
|
|
|
return {}, {}
|
2023-11-07 04:57:00 +00:00
|
|
|
|
else
|
|
|
|
|
return table.random(targets, minTargetNum), table.random(pcards, minCardNum)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-02-17 01:48:42 +00:00
|
|
|
|
--- 询问将卡牌分配给任意角色。
|
|
|
|
|
---@param player ServerPlayer @ 要询问的玩家
|
|
|
|
|
---@param cards? integer[] @ 要分配的卡牌。默认拥有的所有牌
|
|
|
|
|
---@param targets? ServerPlayer[] @ 可以获得卡牌的角色。默认所有存活角色
|
|
|
|
|
---@param skillName? string @ 技能名,影响焦点信息。默认为“分配”
|
|
|
|
|
---@param minNum? integer @ 最少交出的卡牌数,默认0
|
|
|
|
|
---@param maxNum? integer @ 最多交出的卡牌数,默认所有牌
|
|
|
|
|
---@param prompt? string @ 询问提示信息
|
|
|
|
|
---@param expand_pile? string @ 可选私人牌堆名称,如要分配你武将牌上的牌请填写
|
|
|
|
|
---@param skipMove? boolean @ 是否跳过移动。默认不跳过
|
|
|
|
|
---@param single_max? integer|table @ 限制每人能获得的最大牌数。输入整数或(以角色id为键以整数为值)的表
|
|
|
|
|
---@return table<integer[]> @ 返回一个表,键为角色id,值为分配给其的牌id数组
|
|
|
|
|
function Room:askForYiji(player, cards, targets, skillName, minNum, maxNum, prompt, expand_pile, skipMove, single_max)
|
|
|
|
|
targets = targets or self.alive_players
|
|
|
|
|
cards = cards or player:getCardIds("he")
|
|
|
|
|
local _cards = table.simpleClone(cards)
|
|
|
|
|
targets = table.map(targets, Util.IdMapper)
|
|
|
|
|
self:sortPlayersByAction(targets)
|
|
|
|
|
skillName = skillName or "distribution_select_skill"
|
|
|
|
|
minNum = minNum or 0
|
|
|
|
|
maxNum = maxNum or #cards
|
|
|
|
|
local list = {}
|
|
|
|
|
for _, pid in ipairs(targets) do
|
|
|
|
|
list[pid] = {}
|
|
|
|
|
end
|
|
|
|
|
local toStr = function(int) return string.format("%d", int) end
|
|
|
|
|
local residueMap = {}
|
|
|
|
|
if type(single_max) == "table" then
|
|
|
|
|
for pid, v in pairs(single_max) do
|
|
|
|
|
residueMap[toStr(pid)] = v
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
local residue_sum = 0
|
|
|
|
|
local residue_num = type(single_max) == "number" and single_max or 9999
|
|
|
|
|
for _, pid in ipairs(targets) do
|
|
|
|
|
residueMap[toStr(pid)] = residueMap[toStr(pid)] or residue_num
|
|
|
|
|
residue_sum = residue_sum + residueMap[toStr(pid)]
|
|
|
|
|
end
|
|
|
|
|
minNum = math.min(minNum, #_cards, residue_sum)
|
|
|
|
|
local data = {
|
|
|
|
|
cards = _cards,
|
|
|
|
|
max_num = maxNum,
|
|
|
|
|
targets = targets,
|
|
|
|
|
residued_list = residueMap,
|
|
|
|
|
expand_pile = expand_pile
|
|
|
|
|
}
|
|
|
|
|
p(json.encode(residueMap))
|
|
|
|
|
|
|
|
|
|
while maxNum > 0 and #_cards > 0 do
|
|
|
|
|
data.max_num = maxNum
|
|
|
|
|
prompt = prompt or ("#AskForDistribution:::"..minNum..":"..maxNum)
|
|
|
|
|
local success, dat = self:askForUseActiveSkill(player, "distribution_select_skill", prompt, minNum == 0, data, true)
|
|
|
|
|
if success and dat then
|
|
|
|
|
local to = dat.targets[1]
|
|
|
|
|
local give_cards = dat.cards
|
|
|
|
|
for _, id in ipairs(give_cards) do
|
|
|
|
|
table.insert(list[to], id)
|
|
|
|
|
table.removeOne(_cards, id)
|
|
|
|
|
self:setCardMark(Fk:getCardById(id), "@DistributionTo", Fk:translate(self:getPlayerById(to).general))
|
|
|
|
|
end
|
|
|
|
|
minNum = math.max(0, minNum - #give_cards)
|
|
|
|
|
maxNum = maxNum - #give_cards
|
|
|
|
|
residueMap[toStr(to)] = residueMap[toStr(to)] - #give_cards
|
|
|
|
|
else
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for _, id in ipairs(cards) do
|
|
|
|
|
self:setCardMark(Fk:getCardById(id), "@DistributionTo", 0)
|
|
|
|
|
end
|
|
|
|
|
for _, pid in ipairs(targets) do
|
|
|
|
|
if minNum == 0 or #_cards == 0 then break end
|
|
|
|
|
local num = math.min(residueMap[toStr(pid)] or 0, minNum, #_cards)
|
|
|
|
|
if num > 0 then
|
|
|
|
|
for i = num, 1, -1 do
|
|
|
|
|
local c = table.remove(_cards, i)
|
|
|
|
|
table.insert(list[pid], c)
|
|
|
|
|
minNum = minNum - 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if not skipMove then
|
|
|
|
|
self:doYiji(self, list, player.id, skillName)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return list
|
|
|
|
|
end
|
2023-09-27 13:02:22 +00:00
|
|
|
|
--- 抽个武将
|
|
|
|
|
---
|
|
|
|
|
--- 同getNCards,抽出来就没有了,所以记得放回去。
|
|
|
|
|
---@param n number @ 数量
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param position? string @位置,top/bottom,默认top
|
2023-09-27 13:02:22 +00:00
|
|
|
|
---@return string[] @ 武将名数组
|
|
|
|
|
function Room:getNGenerals(n, position)
|
|
|
|
|
position = position or "top"
|
|
|
|
|
assert(position == "top" or position == "bottom")
|
|
|
|
|
|
|
|
|
|
local generals = {}
|
|
|
|
|
while n > 0 do
|
|
|
|
|
|
|
|
|
|
local index = position == "top" and 1 or #self.general_pile
|
|
|
|
|
table.insert(generals, table.remove(self.general_pile, index))
|
|
|
|
|
|
|
|
|
|
n = n - 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if #generals < 1 then
|
2024-04-01 16:56:04 +00:00
|
|
|
|
self:sendLog{
|
|
|
|
|
type = "#NoGeneralDraw",
|
|
|
|
|
toast = true,
|
|
|
|
|
}
|
2023-09-27 13:02:22 +00:00
|
|
|
|
self:gameOver("")
|
|
|
|
|
end
|
|
|
|
|
return generals
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 把武将牌塞回去(……)
|
|
|
|
|
---@param g string[] @ 武将名数组
|
2024-02-27 08:33:00 +00:00
|
|
|
|
---@param position? string @位置,top/bottom/random,默认random
|
2023-09-27 13:02:22 +00:00
|
|
|
|
---@return boolean @ 是否成功
|
|
|
|
|
function Room:returnToGeneralPile(g, position)
|
2024-02-27 08:33:00 +00:00
|
|
|
|
position = position or "random"
|
|
|
|
|
assert(position == "top" or position == "bottom" or position == "random")
|
2023-09-27 13:02:22 +00:00
|
|
|
|
if position == "bottom" then
|
|
|
|
|
table.insertTable(self.general_pile, g)
|
|
|
|
|
elseif position == "top" then
|
|
|
|
|
while #g > 0 do
|
|
|
|
|
table.insert(self.general_pile, 1, table.remove(g))
|
|
|
|
|
end
|
2024-02-27 08:33:00 +00:00
|
|
|
|
elseif position == "random" then
|
|
|
|
|
while #g > 0 do
|
|
|
|
|
table.insert(self.general_pile, math.random(1, #self.general_pile),
|
|
|
|
|
table.remove(g))
|
|
|
|
|
end
|
2023-09-27 13:02:22 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 抽特定名字的武将(抽了就没了)
|
|
|
|
|
---@param name string @ 武将name,如找不到则查找truename,再找不到则返回nil
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@return string? @ 抽出的武将名
|
2023-09-27 13:02:22 +00:00
|
|
|
|
function Room:findGeneral(name)
|
2024-02-26 18:27:59 +00:00
|
|
|
|
if not Fk.generals[name] then return nil end
|
2023-09-27 13:02:22 +00:00
|
|
|
|
for i, g in ipairs(self.general_pile) do
|
|
|
|
|
if g == name or Fk.generals[g].trueName == Fk.generals[name].trueName then
|
|
|
|
|
return table.remove(self.general_pile, i)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- 自上而下抽符合特定情况的N个武将(抽了就没了)
|
|
|
|
|
---@param func fun(name: string):any @ 武将筛选函数
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param n? integer @ 抽取数量,数量不足则直接抽干净
|
2023-09-27 13:02:22 +00:00
|
|
|
|
---@return string[] @ 武将组合,可能为空
|
|
|
|
|
function Room:findGenerals(func, n)
|
|
|
|
|
n = n or 1
|
|
|
|
|
local ret = {}
|
|
|
|
|
local index = 1
|
2024-02-26 18:27:59 +00:00
|
|
|
|
while #ret < n and index <= #self.general_pile do
|
2023-09-27 13:02:22 +00:00
|
|
|
|
if func(self.general_pile[index]) then
|
|
|
|
|
table.insert(ret, table.remove(self.general_pile, index))
|
|
|
|
|
else
|
|
|
|
|
index = index + 1
|
|
|
|
|
end
|
2024-02-26 18:27:59 +00:00
|
|
|
|
end
|
2023-09-27 13:02:22 +00:00
|
|
|
|
return ret
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问玩家选择一名武将。
|
|
|
|
|
---@param player ServerPlayer @ 询问目标
|
|
|
|
|
---@param generals string[] @ 可选武将
|
2023-06-04 11:39:20 +00:00
|
|
|
|
---@param n integer @ 可选数量,默认为1
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param noConvert? boolean @ 可否变更,默认可
|
2023-07-16 11:17:03 +00:00
|
|
|
|
---@return string|string[] @ 选择的武将
|
2023-08-24 13:37:06 +00:00
|
|
|
|
function Room:askForGeneral(player, generals, n, noConvert)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
local command = "AskForGeneral"
|
|
|
|
|
self:notifyMoveFocus(player, command)
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
2023-04-19 06:07:16 +00:00
|
|
|
|
n = n or 1
|
|
|
|
|
if #generals == n then return n == 1 and generals[1] or generals end
|
|
|
|
|
local defaultChoice = table.random(generals, n)
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
2023-06-16 02:56:33 +00:00
|
|
|
|
if (player.serverplayer:getState() == fk.Player_Online) then
|
2023-08-24 13:37:06 +00:00
|
|
|
|
local result = self:doRequest(player, command, json.encode{ generals, n, noConvert })
|
2023-04-19 06:07:16 +00:00
|
|
|
|
local choices
|
2022-04-30 07:27:56 +00:00
|
|
|
|
if result == "" then
|
2023-04-19 06:07:16 +00:00
|
|
|
|
choices = defaultChoice
|
2022-04-30 07:27:56 +00:00
|
|
|
|
else
|
2023-04-19 06:07:16 +00:00
|
|
|
|
choices = json.decode(result)
|
2022-03-30 06:14:40 +00:00
|
|
|
|
end
|
2023-04-19 06:07:16 +00:00
|
|
|
|
if #choices == 1 then return choices[1] end
|
|
|
|
|
return choices
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
2022-03-30 06:14:40 +00:00
|
|
|
|
|
2023-12-12 13:20:35 +00:00
|
|
|
|
return n == 1 and defaultChoice[1] or defaultChoice
|
2022-03-30 06:14:40 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-07-16 11:17:03 +00:00
|
|
|
|
--- 询问玩家若为神将、双势力需选择一个势力。
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param players? ServerPlayer[] @ 询问目标
|
2023-07-16 11:17:03 +00:00
|
|
|
|
function Room:askForChooseKingdom(players)
|
|
|
|
|
players = players or self.alive_players
|
|
|
|
|
local specialKingdomPlayers = table.filter(players, function(p)
|
2024-04-01 16:56:04 +00:00
|
|
|
|
return Fk.generals[p.general].subkingdom or #Fk:getKingdomMap(p.kingdom) > 0
|
2023-07-16 11:17:03 +00:00
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
if #specialKingdomPlayers > 0 then
|
|
|
|
|
local choiceMap = {}
|
|
|
|
|
for _, p in ipairs(specialKingdomPlayers) do
|
|
|
|
|
local allKingdoms = {}
|
2024-04-01 16:56:04 +00:00
|
|
|
|
local curGeneral = Fk.generals[p.general]
|
|
|
|
|
if curGeneral.subkingdom then
|
2023-07-16 11:17:03 +00:00
|
|
|
|
allKingdoms = { curGeneral.kingdom, curGeneral.subkingdom }
|
2024-04-01 16:56:04 +00:00
|
|
|
|
else
|
|
|
|
|
allKingdoms = Fk:getKingdomMap(p.kingdom)
|
2023-07-16 11:17:03 +00:00
|
|
|
|
end
|
2024-04-01 16:56:04 +00:00
|
|
|
|
if #allKingdoms > 0 then
|
|
|
|
|
choiceMap[p.id] = allKingdoms
|
2023-07-16 11:17:03 +00:00
|
|
|
|
|
2024-04-01 16:56:04 +00:00
|
|
|
|
local data = json.encode({ allKingdoms, allKingdoms, "AskForKingdom", "#ChooseInitialKingdom" })
|
|
|
|
|
p.request_data = data
|
|
|
|
|
end
|
2023-07-16 11:17:03 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self:notifyMoveFocus(players, "AskForKingdom")
|
|
|
|
|
self:doBroadcastRequest("AskForChoice", specialKingdomPlayers)
|
|
|
|
|
|
|
|
|
|
for _, p in ipairs(specialKingdomPlayers) do
|
|
|
|
|
local kingdomChosen
|
|
|
|
|
if p.reply_ready then
|
|
|
|
|
kingdomChosen = p.client_reply
|
|
|
|
|
else
|
|
|
|
|
kingdomChosen = choiceMap[p.id][1]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
p.kingdom = kingdomChosen
|
|
|
|
|
self:notifyProperty(p, p, "kingdom")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问chooser,选择target的一张牌。
|
|
|
|
|
---@param chooser ServerPlayer @ 要被询问的人
|
|
|
|
|
---@param target ServerPlayer @ 被选牌的人
|
2023-08-24 13:37:24 +00:00
|
|
|
|
---@param flag any @ 用"hej"三个字母的组合表示能选择哪些区域, h 手牌区, e - 装备区, j - 判定区
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@param reason string @ 原因,一般是技能名
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param prompt? string @ 提示信息
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@return integer @ 选择的卡牌id
|
2023-11-07 13:14:51 +00:00
|
|
|
|
function Room:askForCardChosen(chooser, target, flag, reason, prompt)
|
2022-09-14 05:01:10 +00:00
|
|
|
|
local command = "AskForCardChosen"
|
2023-11-07 13:14:51 +00:00
|
|
|
|
prompt = prompt or ""
|
2022-09-14 05:01:10 +00:00
|
|
|
|
self:notifyMoveFocus(chooser, command)
|
2023-11-07 13:14:51 +00:00
|
|
|
|
local data = {target.id, flag, reason, prompt}
|
2022-09-14 05:01:10 +00:00
|
|
|
|
local result = self:doRequest(chooser, command, json.encode(data))
|
|
|
|
|
|
|
|
|
|
if result == "" then
|
2023-03-01 13:41:16 +00:00
|
|
|
|
local areas = {}
|
2023-08-24 13:37:24 +00:00
|
|
|
|
local handcards
|
|
|
|
|
if type(flag) == "string" then
|
|
|
|
|
if string.find(flag, "h") then table.insert(areas, Player.Hand) end
|
|
|
|
|
if string.find(flag, "e") then table.insert(areas, Player.Equip) end
|
|
|
|
|
if string.find(flag, "j") then table.insert(areas, Player.Judge) end
|
|
|
|
|
handcards = target:getCardIds(areas)
|
|
|
|
|
else
|
|
|
|
|
handcards = {}
|
|
|
|
|
for _, t in ipairs(flag.card_data) do
|
|
|
|
|
table.insertTable(handcards, t[2])
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-03-01 13:41:16 +00:00
|
|
|
|
if #handcards == 0 then return end
|
|
|
|
|
result = handcards[math.random(1, #handcards)]
|
2022-09-14 05:01:10 +00:00
|
|
|
|
else
|
|
|
|
|
result = tonumber(result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if result == -1 then
|
2023-03-01 13:41:16 +00:00
|
|
|
|
local handcards = target:getCardIds(Player.Hand)
|
|
|
|
|
if #handcards == 0 then return end
|
|
|
|
|
result = table.random(handcards)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
end
|
|
|
|
|
|
2023-09-19 06:27:54 +00:00
|
|
|
|
--- 谋askForCardsChosen,需使用Fk:addPoxiMethod定义好方法
|
|
|
|
|
---
|
|
|
|
|
--- 选卡规则和返回值啥的全部自己想办法解决,data填入所有卡的列表(类似ui.card_data)
|
|
|
|
|
---
|
|
|
|
|
--- 注意一定要返回一个表,毕竟本质上是选卡函数
|
|
|
|
|
---@param player ServerPlayer
|
|
|
|
|
---@param poxi_type string
|
|
|
|
|
---@param data any
|
2023-10-27 14:19:30 +00:00
|
|
|
|
---@param extra_data any
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param cancelable? boolean
|
2023-09-19 06:27:54 +00:00
|
|
|
|
---@return integer[]
|
2023-10-27 14:19:30 +00:00
|
|
|
|
function Room:askForPoxi(player, poxi_type, data, extra_data, cancelable)
|
2023-09-19 06:27:54 +00:00
|
|
|
|
local poxi = Fk.poxi_methods[poxi_type]
|
|
|
|
|
if not poxi then return {} end
|
|
|
|
|
|
|
|
|
|
local command = "AskForPoxi"
|
|
|
|
|
self:notifyMoveFocus(player, poxi_type)
|
|
|
|
|
local result = self:doRequest(player, command, json.encode {
|
|
|
|
|
type = poxi_type,
|
|
|
|
|
data = data,
|
2023-10-27 14:19:30 +00:00
|
|
|
|
extra_data = extra_data,
|
|
|
|
|
cancelable = (cancelable == nil) and true or cancelable
|
2023-09-19 06:27:54 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if result == "" then
|
2023-10-27 14:19:30 +00:00
|
|
|
|
return poxi.default_choice(data, extra_data)
|
2023-09-19 06:27:54 +00:00
|
|
|
|
else
|
2023-10-27 14:19:30 +00:00
|
|
|
|
return poxi.post_select(json.decode(result), data, extra_data)
|
2023-09-19 06:27:54 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-04-01 16:56:04 +00:00
|
|
|
|
--- 完全类似askForCardChosen,但是可以选择多张牌。
|
|
|
|
|
--- 相应的,返回的是id的数组而不是单个id。
|
|
|
|
|
---@param chooser ServerPlayer @ 要被询问的人
|
|
|
|
|
---@param target ServerPlayer @ 被选牌的人
|
|
|
|
|
---@param min integer @ 最小选牌数
|
|
|
|
|
---@param max integer @ 最大选牌数
|
|
|
|
|
---@param flag any @ 用"hej"三个字母的组合表示能选择哪些区域, h 手牌区, e - 装备区, j - 判定区
|
|
|
|
|
---可以通过flag.card_data = {{牌堆1名, 牌堆1ID表},...}来定制能选择的牌
|
|
|
|
|
---@param reason string @ 原因,一般是技能名
|
|
|
|
|
---@param prompt? string @ 提示信息
|
|
|
|
|
---@return integer[] @ 选择的id
|
|
|
|
|
function Room:askForCardsChosen(chooser, target, min, max, flag, reason, prompt)
|
|
|
|
|
if min == 1 and max == 1 then
|
|
|
|
|
return { self:askForCardChosen(chooser, target, flag, reason) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- local command = "AskForCardsChosen"
|
|
|
|
|
-- prompt = prompt or ""
|
|
|
|
|
-- self:notifyMoveFocus(chooser, command)
|
|
|
|
|
-- local data = {target.id, min, max, flag, reason, prompt}
|
|
|
|
|
-- local result = self:doRequest(chooser, command, json.encode(data))
|
|
|
|
|
|
|
|
|
|
-- local ret
|
|
|
|
|
-- if result ~= "" then
|
|
|
|
|
-- ret = json.decode(result)
|
|
|
|
|
-- else
|
|
|
|
|
-- local areas = {}
|
|
|
|
|
-- local handcards
|
|
|
|
|
-- if type(flag) == "string" then
|
|
|
|
|
-- if string.find(flag, "h") then table.insert(areas, Player.Hand) end
|
|
|
|
|
-- if string.find(flag, "e") then table.insert(areas, Player.Equip) end
|
|
|
|
|
-- if string.find(flag, "j") then table.insert(areas, Player.Judge) end
|
|
|
|
|
-- handcards = target:getCardIds(areas)
|
|
|
|
|
-- else
|
|
|
|
|
-- handcards = {}
|
|
|
|
|
-- for _, t in ipairs(flag.card_data) do
|
|
|
|
|
-- table.insertTable(handcards, t[2])
|
|
|
|
|
-- end
|
|
|
|
|
-- end
|
|
|
|
|
-- if #handcards == 0 then return {} end
|
|
|
|
|
-- ret = table.random(handcards, math.min(min, #handcards))
|
|
|
|
|
-- end
|
|
|
|
|
|
|
|
|
|
-- local new_ret = table.filter(ret, function(id) return id ~= -1 end)
|
|
|
|
|
-- local hand_num = #ret - #new_ret
|
|
|
|
|
-- if hand_num > 0 then
|
|
|
|
|
-- table.insertTable(new_ret, table.random(target:getCardIds(Player.Hand), hand_num))
|
|
|
|
|
-- end
|
|
|
|
|
|
|
|
|
|
-- return new_ret
|
|
|
|
|
local areas = {}
|
|
|
|
|
local cards
|
|
|
|
|
local data = {
|
|
|
|
|
to = target.id,
|
|
|
|
|
min = min,
|
|
|
|
|
max = max,
|
|
|
|
|
skillName = reason,
|
|
|
|
|
prompt = prompt,
|
|
|
|
|
}
|
|
|
|
|
if type(flag) == "string" then
|
|
|
|
|
if string.find(flag, "h") then table.insert(areas, Player.Hand) end
|
|
|
|
|
if string.find(flag, "e") then table.insert(areas, Player.Equip) end
|
|
|
|
|
if string.find(flag, "j") then table.insert(areas, Player.Judge) end
|
|
|
|
|
cards = target:getCardIds(areas)
|
|
|
|
|
else
|
|
|
|
|
cards = {}
|
|
|
|
|
for _, t in ipairs(flag.card_data) do
|
|
|
|
|
table.insertTable(cards, t[2])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if #cards <= min then return table.random(cards, math.min(min, #cards)) end
|
|
|
|
|
local cards_data = {}
|
|
|
|
|
if type(flag) == "string" then
|
|
|
|
|
if string.find(flag, "h") and #target:getCardIds(Player.Hand) > 0 then
|
|
|
|
|
local handcards = {}
|
|
|
|
|
for _, _ in ipairs(target:getCardIds(Player.Hand)) do
|
|
|
|
|
table.insert(handcards, -1)
|
|
|
|
|
end
|
|
|
|
|
table.insert(cards_data, {"$Hand", handcards})
|
|
|
|
|
end
|
|
|
|
|
if string.find(flag, "e") and #target:getCardIds(Player.Equip) > 0 then table.insert(cards_data, {"$Equip", target:getCardIds(Player.Equip)}) end
|
|
|
|
|
if string.find(flag, "j") and #target:getCardIds(Player.Judge) > 0 then table.insert(cards_data, {"$Judge", target:getCardIds(Player.Judge)}) end
|
|
|
|
|
local ret = self:askForPoxi(chooser, "AskForCardsChosen", cards_data, data, false)
|
|
|
|
|
local new_ret = table.filter(ret, function(id) return id ~= -1 end)
|
|
|
|
|
local hidden_num = #ret - #new_ret
|
|
|
|
|
if hidden_num > 0 then
|
|
|
|
|
table.insertTable(new_ret, table.random(target:getCardIds(Player.Hand), hidden_num))
|
|
|
|
|
end
|
|
|
|
|
return new_ret
|
|
|
|
|
else
|
|
|
|
|
for _, t in ipairs(flag.card_data) do
|
|
|
|
|
table.insert(cards_data, t)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return self:askForPoxi(chooser, "AskForCardsChosen", cards_data, data, false)
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问一名玩家从众多选项中选择一个。
|
|
|
|
|
---@param player ServerPlayer @ 要询问的玩家
|
|
|
|
|
---@param choices string[] @ 可选选项列表
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param skill_name? string @ 技能名
|
|
|
|
|
---@param prompt? string @ 提示信息
|
|
|
|
|
---@param detailed? boolean @ 选项详细描述
|
|
|
|
|
---@param all_choices? string[] @ 所有选项(不可选变灰)
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@return string @ 选择的选项
|
2023-07-16 07:29:20 +00:00
|
|
|
|
function Room:askForChoice(player, choices, skill_name, prompt, detailed, all_choices)
|
|
|
|
|
if #choices == 1 and not all_choices then return choices[1] end
|
|
|
|
|
assert(not all_choices or table.every(choices, function(c) return table.contains(all_choices, c) end))
|
2022-04-30 07:27:56 +00:00
|
|
|
|
local command = "AskForChoice"
|
2023-01-29 10:11:41 +00:00
|
|
|
|
prompt = prompt or ""
|
2023-07-16 07:29:20 +00:00
|
|
|
|
all_choices = all_choices or choices
|
2022-04-30 07:27:56 +00:00
|
|
|
|
self:notifyMoveFocus(player, skill_name)
|
|
|
|
|
local result = self:doRequest(player, command, json.encode{
|
2023-07-16 07:29:20 +00:00
|
|
|
|
choices, all_choices, skill_name, prompt, detailed
|
2022-04-30 07:27:56 +00:00
|
|
|
|
})
|
|
|
|
|
if result == "" then result = choices[1] end
|
|
|
|
|
return result
|
2022-04-02 07:11:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-11-07 04:57:00 +00:00
|
|
|
|
--- 询问一名玩家从众多选项中勾选任意项。
|
|
|
|
|
---@param player ServerPlayer @ 要询问的玩家
|
|
|
|
|
---@param choices string[] @ 可选选项列表
|
|
|
|
|
---@param minNum number @ 最少选择项数
|
|
|
|
|
---@param maxNum number @ 最多选择项数
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param skill_name? string @ 技能名
|
|
|
|
|
---@param prompt? string @ 提示信息
|
|
|
|
|
---@param cancelable? boolean @ 是否可取消
|
|
|
|
|
---@param detailed? boolean @ 选项详细描述
|
|
|
|
|
---@param all_choices? string[] @ 所有选项(不可选变灰)
|
2023-11-07 04:57:00 +00:00
|
|
|
|
---@return string[] @ 选择的选项
|
2023-12-06 13:07:35 +00:00
|
|
|
|
function Room:askForChoices(player, choices, minNum, maxNum, skill_name, prompt, cancelable, detailed, all_choices)
|
2023-11-07 04:57:00 +00:00
|
|
|
|
cancelable = (cancelable == nil) and true or cancelable
|
2023-12-28 04:15:01 +00:00
|
|
|
|
if #choices <= minNum and not all_choices and not cancelable then return choices end
|
2023-11-07 04:57:00 +00:00
|
|
|
|
assert(minNum <= maxNum)
|
|
|
|
|
assert(not all_choices or table.every(choices, function(c) return table.contains(all_choices, c) end))
|
2023-12-06 13:07:35 +00:00
|
|
|
|
local command = "AskForChoices"
|
2023-11-07 04:57:00 +00:00
|
|
|
|
skill_name = skill_name or ""
|
|
|
|
|
prompt = prompt or ""
|
|
|
|
|
all_choices = all_choices or choices
|
|
|
|
|
detailed = detailed or false
|
|
|
|
|
self:notifyMoveFocus(player, skill_name)
|
|
|
|
|
local result = self:doRequest(player, command, json.encode{
|
|
|
|
|
choices, all_choices, {minNum, maxNum}, cancelable, skill_name, prompt, detailed
|
|
|
|
|
})
|
2023-12-28 04:15:01 +00:00
|
|
|
|
if result == "" then
|
|
|
|
|
if cancelable then
|
|
|
|
|
return {}
|
|
|
|
|
else
|
|
|
|
|
return table.random(choices, math.min(minNum, #choices))
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-11-07 04:57:00 +00:00
|
|
|
|
return json.decode(result)
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问玩家是否发动技能。
|
|
|
|
|
---@param player ServerPlayer @ 要询问的玩家
|
|
|
|
|
---@param skill_name string @ 技能名
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param data? any @ 未使用
|
|
|
|
|
---@param prompt? string @ 提示信息
|
2022-04-02 07:11:13 +00:00
|
|
|
|
---@return boolean
|
2023-04-04 07:59:21 +00:00
|
|
|
|
function Room:askForSkillInvoke(player, skill_name, data, prompt)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
local command = "AskForSkillInvoke"
|
|
|
|
|
self:notifyMoveFocus(player, skill_name)
|
|
|
|
|
local invoked = false
|
2023-04-04 07:59:21 +00:00
|
|
|
|
local result = self:doRequest(player, command, json.encode{ skill_name, prompt })
|
2022-04-30 07:27:56 +00:00
|
|
|
|
if result ~= "" then invoked = true end
|
|
|
|
|
return invoked
|
2022-04-01 12:51:01 +00:00
|
|
|
|
end
|
|
|
|
|
|
2024-02-04 07:55:44 +00:00
|
|
|
|
-- 获取使用牌的合法额外目标(【借刀杀人】等带副目标的卡牌除外)
|
|
|
|
|
---@param data CardUseStruct @ 使用事件的data
|
|
|
|
|
---@param bypass_distances boolean? @ 是否无距离关系的限制
|
|
|
|
|
---@param use_AimGroup boolean? @ 某些场合需要使用AimGroup,by smart Ho-spair
|
|
|
|
|
---@return integer[] @ 返回满足条件的player的id列表
|
|
|
|
|
function Room:getUseExtraTargets(data, bypass_distances, use_AimGroup)
|
|
|
|
|
if not (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) then return {} end
|
|
|
|
|
if data.card.skill:getMinTargetNum() > 1 then return {} end --stupid collateral
|
|
|
|
|
local tos = {}
|
|
|
|
|
local current_targets = use_AimGroup and AimGroup:getAllTargets(data.tos) or TargetGroup:getRealTargets(data.tos)
|
|
|
|
|
for _, p in ipairs(self.alive_players) do
|
|
|
|
|
if not table.contains(current_targets, p.id) and not self:getPlayerById(data.from):isProhibited(p, data.card) then
|
|
|
|
|
if data.card.skill:modTargetFilter(p.id, {}, data.from, data.card, not bypass_distances) then
|
|
|
|
|
table.insert(tos, p.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return tos
|
|
|
|
|
end
|
|
|
|
|
|
2023-08-27 12:19:55 +00:00
|
|
|
|
--为使用牌增减目标
|
2023-08-01 18:19:51 +00:00
|
|
|
|
---@param player ServerPlayer @ 执行的玩家
|
|
|
|
|
---@param targets ServerPlayer[] @ 可选的目标范围
|
|
|
|
|
---@param num integer @ 可选的目标数
|
|
|
|
|
---@param can_minus boolean @ 是否可减少
|
|
|
|
|
---@param distance_limited boolean @ 是否受距离限制
|
|
|
|
|
---@param prompt string @ 提示信息
|
|
|
|
|
---@param skillName string @ 技能名
|
|
|
|
|
---@param data CardUseStruct @ 使用数据
|
|
|
|
|
function Room:askForAddTarget(player, targets, num, can_minus, distance_limited, prompt, skillName, data)
|
|
|
|
|
num = num or 1
|
|
|
|
|
can_minus = can_minus or false
|
|
|
|
|
prompt = prompt or ""
|
|
|
|
|
skillName = skillName or ""
|
|
|
|
|
local room = player.room
|
|
|
|
|
local tos = {}
|
|
|
|
|
local orig_tos = table.simpleClone(AimGroup:getAllTargets(data.tos))
|
|
|
|
|
if can_minus and #orig_tos > 1 then --默认不允许减目标至0
|
|
|
|
|
tos = table.map(table.filter(targets, function(p)
|
|
|
|
|
return table.contains(AimGroup:getAllTargets(data.tos), p.id) end), Util.IdMapper)
|
|
|
|
|
end
|
|
|
|
|
for _, p in ipairs(targets) do
|
|
|
|
|
if not table.contains(AimGroup:getAllTargets(data.tos), p.id) and not room:getPlayerById(data.from):isProhibited(p, data.card) then
|
2023-08-02 15:01:28 +00:00
|
|
|
|
if data.card.skill:modTargetFilter(p.id, orig_tos, data.from, data.card, distance_limited) then
|
2023-08-01 18:19:51 +00:00
|
|
|
|
table.insertIfNeed(tos, p.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if #tos > 0 then
|
|
|
|
|
tos = room:askForChoosePlayers(player, tos, 1, num, prompt, skillName, true)
|
|
|
|
|
--借刀……!
|
|
|
|
|
if data.card.name ~= "collateral" then
|
|
|
|
|
return tos
|
|
|
|
|
else
|
|
|
|
|
local result = {}
|
|
|
|
|
for _, id in ipairs(tos) do
|
|
|
|
|
local to = room:getPlayerById(id)
|
|
|
|
|
local target = room:askForChoosePlayers(player, table.map(table.filter(room:getOtherPlayers(player), function(v)
|
|
|
|
|
return to:inMyAttackRange(v) end), function(p) return p.id end), 1, 1,
|
|
|
|
|
"#collateral-choose::"..to.id..":"..data.card:toLogString(), "collateral_skill", true)
|
|
|
|
|
if #target > 0 then
|
|
|
|
|
table.insert(result, {id, target[1]})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if #result > 0 then
|
|
|
|
|
return result
|
|
|
|
|
else
|
|
|
|
|
return {}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return {}
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-29 10:11:41 +00:00
|
|
|
|
-- TODO: guanxing type
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问玩家对若干牌进行观星。
|
|
|
|
|
---
|
|
|
|
|
--- 观星完成后,相关的牌会被置于牌堆顶或者牌堆底。所以这些cards最好不要来自牌堆,一般先用getNCards从牌堆拿出一些牌。
|
|
|
|
|
---@param player ServerPlayer @ 要询问的玩家
|
|
|
|
|
---@param cards integer[] @ 可以被观星的卡牌id列表
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param top_limit? integer[] @ 置于牌堆顶的牌的限制(下限,上限),不填写则不限
|
|
|
|
|
---@param bottom_limit? integer[] @ 置于牌堆底的牌的限制(下限,上限),不填写则不限
|
|
|
|
|
---@param customNotify? string @ 自定义读条操作提示
|
|
|
|
|
---param prompt? string @ 观星框的标题(暂时雪藏)
|
|
|
|
|
---@param noPut? boolean @ 是否进行放置牌操作
|
|
|
|
|
---@param areaNames? string[] @ 左侧提示信息
|
2023-06-23 14:18:11 +00:00
|
|
|
|
---@return table<"top"|"bottom", integer[]>
|
2023-06-04 11:39:20 +00:00
|
|
|
|
function Room:askForGuanxing(player, cards, top_limit, bottom_limit, customNotify, noPut, areaNames)
|
2023-04-25 11:02:17 +00:00
|
|
|
|
-- 这一大堆都是来提前报错的
|
2023-06-11 08:22:11 +00:00
|
|
|
|
top_limit = top_limit or Util.DummyTable
|
|
|
|
|
bottom_limit = bottom_limit or Util.DummyTable
|
2023-04-25 11:02:17 +00:00
|
|
|
|
if #top_limit > 0 then
|
2023-06-11 08:22:11 +00:00
|
|
|
|
assert(top_limit[1] >= 0 and top_limit[2] >= 0, "limits error: The lower limit should be greater than 0")
|
|
|
|
|
assert(top_limit[1] <= top_limit[2], "limits error: The upper limit should be less than the lower limit")
|
2023-04-25 11:02:17 +00:00
|
|
|
|
end
|
|
|
|
|
if #bottom_limit > 0 then
|
2023-06-11 08:22:11 +00:00
|
|
|
|
assert(bottom_limit[1] >= 0 and bottom_limit[2] >= 0, "limits error: The lower limit should be greater than 0")
|
|
|
|
|
assert(bottom_limit[1] <= bottom_limit[2], "limits error: The upper limit should be less than the lower limit")
|
2023-04-25 11:02:17 +00:00
|
|
|
|
end
|
|
|
|
|
if #top_limit > 0 and #bottom_limit > 0 then
|
2023-06-11 08:22:11 +00:00
|
|
|
|
assert(#cards >= top_limit[1] + bottom_limit[1] and #cards <= top_limit[2] + bottom_limit[2], "limits Error: No enough space")
|
2023-04-25 11:02:17 +00:00
|
|
|
|
end
|
2023-06-04 11:39:20 +00:00
|
|
|
|
if areaNames then
|
2023-06-11 08:22:11 +00:00
|
|
|
|
assert(#areaNames == 2, "areaNames error: Should have 2 elements")
|
2023-06-04 11:39:20 +00:00
|
|
|
|
end
|
2023-01-29 10:11:41 +00:00
|
|
|
|
local command = "AskForGuanxing"
|
2023-05-13 06:20:34 +00:00
|
|
|
|
self:notifyMoveFocus(player, customNotify or command)
|
2023-01-29 10:11:41 +00:00
|
|
|
|
local data = {
|
2023-07-14 14:17:54 +00:00
|
|
|
|
prompt = "",
|
2023-01-29 10:11:41 +00:00
|
|
|
|
cards = cards,
|
2023-04-25 11:02:17 +00:00
|
|
|
|
min_top_cards = top_limit and top_limit[1] or 0,
|
|
|
|
|
max_top_cards = top_limit and top_limit[2] or #cards,
|
|
|
|
|
min_bottom_cards = bottom_limit and bottom_limit[1] or 0,
|
|
|
|
|
max_bottom_cards = bottom_limit and bottom_limit[2] or #cards,
|
2023-06-04 11:39:20 +00:00
|
|
|
|
top_area_name = areaNames and areaNames[1] or "Top",
|
|
|
|
|
bottom_area_name = areaNames and areaNames[2] or "Bottom",
|
2023-01-29 10:11:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local result = self:doRequest(player, command, json.encode(data))
|
|
|
|
|
local top, bottom
|
|
|
|
|
if result ~= "" then
|
|
|
|
|
local d = json.decode(result)
|
2023-06-04 11:39:20 +00:00
|
|
|
|
if #top_limit > 0 and top_limit[2] == 0 then
|
2023-08-10 19:24:22 +00:00
|
|
|
|
top = Util.DummyTable
|
2023-04-25 11:02:17 +00:00
|
|
|
|
bottom = d[1]
|
|
|
|
|
else
|
|
|
|
|
top = d[1]
|
2023-08-10 19:24:22 +00:00
|
|
|
|
bottom = d[2] or Util.DummyTable
|
2023-04-25 11:02:17 +00:00
|
|
|
|
end
|
2023-01-29 10:11:41 +00:00
|
|
|
|
else
|
2023-06-11 08:22:11 +00:00
|
|
|
|
top = table.random(cards, top_limit and top_limit[2] or #cards) or Util.DummyTable
|
|
|
|
|
bottom = table.shuffle(table.filter(cards, function(id) return not table.contains(top, id) end)) or Util.DummyTable
|
2023-01-29 10:11:41 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-05-13 06:20:34 +00:00
|
|
|
|
if not noPut then
|
|
|
|
|
for i = #top, 1, -1 do
|
|
|
|
|
table.insert(self.draw_pile, 1, top[i])
|
|
|
|
|
end
|
2023-06-04 11:39:20 +00:00
|
|
|
|
for i = #bottom, 1, -1 do
|
|
|
|
|
table.insert(self.draw_pile, bottom[i])
|
2023-05-13 06:20:34 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self:sendLog{
|
|
|
|
|
type = "#GuanxingResult",
|
|
|
|
|
from = player.id,
|
|
|
|
|
arg = #top,
|
|
|
|
|
arg2 = #bottom,
|
|
|
|
|
}
|
2023-01-29 10:11:41 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-05-13 06:20:34 +00:00
|
|
|
|
return { top = top, bottom = bottom }
|
2023-01-29 10:11:41 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-06-07 05:02:53 +00:00
|
|
|
|
--- 询问玩家任意交换几堆牌堆。
|
|
|
|
|
---
|
|
|
|
|
---@param player ServerPlayer @ 要询问的玩家
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param piles table<string, integer[]> @ 卡牌id列表的列表,也就是……几堆牌堆的集合
|
2023-06-07 05:02:53 +00:00
|
|
|
|
---@param piles_name string[] @ 牌堆名,必须一一对应,否则统一替换为“牌堆X”
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param customNotify? string @ 自定义读条操作提示
|
|
|
|
|
---@return table<string, integer[]>
|
2023-06-11 08:22:11 +00:00
|
|
|
|
function Room:askForExchange(player, piles, piles_name, customNotify)
|
2023-06-07 05:02:53 +00:00
|
|
|
|
local command = "AskForExchange"
|
2023-06-11 08:22:11 +00:00
|
|
|
|
piles_name = piles_name or Util.DummyTable
|
2023-06-07 05:02:53 +00:00
|
|
|
|
if #piles_name ~= #piles then
|
|
|
|
|
piles_name = {}
|
|
|
|
|
for i, _ in ipairs(piles) do
|
2023-06-11 08:22:11 +00:00
|
|
|
|
table.insert(piles_name, "Pile" .. i)
|
2023-06-07 05:02:53 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self:notifyMoveFocus(player, customNotify or command)
|
|
|
|
|
local data = {
|
|
|
|
|
piles = piles,
|
|
|
|
|
piles_name = piles_name,
|
|
|
|
|
}
|
|
|
|
|
local result = self:doRequest(player, command, json.encode(data))
|
|
|
|
|
if result ~= "" then
|
|
|
|
|
local d = json.decode(result)
|
|
|
|
|
return d
|
|
|
|
|
else
|
|
|
|
|
return piles
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 平时写DIY用不到的函数。
|
2022-12-18 13:19:35 +00:00
|
|
|
|
---@param player ServerPlayer
|
2023-01-16 11:13:07 +00:00
|
|
|
|
---@param data string
|
|
|
|
|
---@return CardUseStruct
|
|
|
|
|
function Room:handleUseCardReply(player, data)
|
|
|
|
|
data = json.decode(data)
|
|
|
|
|
local card = data.card
|
|
|
|
|
local targets = data.targets
|
|
|
|
|
if type(card) == "string" then
|
|
|
|
|
local card_data = json.decode(card)
|
|
|
|
|
local skill = Fk.skills[card_data.skill]
|
|
|
|
|
local selected_cards = card_data.subcards
|
2023-04-08 12:45:55 +00:00
|
|
|
|
if skill.interaction then skill.interaction.data = data.interaction_data end
|
2023-01-16 11:13:07 +00:00
|
|
|
|
if skill:isInstanceOf(ActiveSkill) then
|
2023-02-21 05:44:24 +00:00
|
|
|
|
self:useSkill(player, skill, function()
|
|
|
|
|
self:doIndicate(player.id, targets)
|
|
|
|
|
skill:onUse(self, {
|
|
|
|
|
from = player.id,
|
|
|
|
|
cards = selected_cards,
|
|
|
|
|
tos = targets,
|
|
|
|
|
})
|
|
|
|
|
end)
|
2023-01-16 11:13:07 +00:00
|
|
|
|
return nil
|
|
|
|
|
elseif skill:isInstanceOf(ViewAsSkill) then
|
2023-03-13 12:51:12 +00:00
|
|
|
|
Self = player
|
2023-01-16 11:13:07 +00:00
|
|
|
|
local c = skill:viewAs(selected_cards)
|
|
|
|
|
if c then
|
|
|
|
|
local use = {} ---@type CardUseStruct
|
|
|
|
|
use.from = player.id
|
|
|
|
|
use.tos = {}
|
|
|
|
|
for _, target in ipairs(targets) do
|
|
|
|
|
table.insert(use.tos, { target })
|
|
|
|
|
end
|
2023-01-29 10:11:41 +00:00
|
|
|
|
if #use.tos == 0 then
|
|
|
|
|
use.tos = nil
|
|
|
|
|
end
|
2023-01-16 11:13:07 +00:00
|
|
|
|
use.card = c
|
2023-04-30 10:55:59 +00:00
|
|
|
|
|
2023-07-01 15:14:30 +00:00
|
|
|
|
self:useSkill(player, skill, Util.DummyFunc)
|
2024-02-04 07:29:39 +00:00
|
|
|
|
use.attachedSkillAndUser = { skillName = skill.name, user = player.id }
|
2023-07-01 15:14:30 +00:00
|
|
|
|
|
2023-12-10 10:55:16 +00:00
|
|
|
|
local rejectSkillName = skill:beforeUse(player, use)
|
|
|
|
|
if type(rejectSkillName) == "string" then
|
|
|
|
|
return rejectSkillName
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-16 11:13:07 +00:00
|
|
|
|
return use
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
2023-03-20 12:15:24 +00:00
|
|
|
|
if data.special_skill then
|
|
|
|
|
local skill = Fk.skills[data.special_skill]
|
|
|
|
|
assert(skill:isInstanceOf(ActiveSkill))
|
|
|
|
|
skill:onUse(self, {
|
|
|
|
|
from = player.id,
|
|
|
|
|
cards = { card },
|
|
|
|
|
tos = targets,
|
|
|
|
|
})
|
|
|
|
|
return nil
|
|
|
|
|
end
|
2023-01-16 11:13:07 +00:00
|
|
|
|
local use = {} ---@type CardUseStruct
|
|
|
|
|
use.from = player.id
|
|
|
|
|
use.tos = {}
|
|
|
|
|
for _, target in ipairs(targets) do
|
|
|
|
|
table.insert(use.tos, { target })
|
|
|
|
|
end
|
|
|
|
|
if #use.tos == 0 then
|
|
|
|
|
use.tos = nil
|
|
|
|
|
end
|
2023-07-01 15:14:30 +00:00
|
|
|
|
Fk:filterCard(card, player)
|
2023-01-16 11:13:07 +00:00
|
|
|
|
use.card = Fk:getCardById(card)
|
|
|
|
|
return use
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- available extra_data:
|
|
|
|
|
-- * must_targets: integer[]
|
2023-06-15 13:19:57 +00:00
|
|
|
|
-- * exclusive_targets: integer[]
|
2023-06-20 11:04:14 +00:00
|
|
|
|
-- * bypass_distances: boolean
|
|
|
|
|
-- * bypass_times: boolean
|
2023-12-12 13:20:35 +00:00
|
|
|
|
---
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问玩家使用一张牌。
|
|
|
|
|
---@param player ServerPlayer @ 要询问的玩家
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param card_name? string @ 使用牌的牌名,若pattern指定了则可随意写,它影响的是烧条的提示信息
|
|
|
|
|
---@param pattern? string @ 使用牌的规则,默认就是card_name的值
|
|
|
|
|
---@param prompt? string @ 提示信息
|
|
|
|
|
---@param cancelable? boolean @ 能否点取消
|
2023-12-03 10:45:25 +00:00
|
|
|
|
---@param extra_data? UseExtraData @ 额外信息
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param event_data? CardEffectEvent @ 事件信息
|
|
|
|
|
---@return CardUseStruct? @ 返回关于本次使用牌的数据,以便后续处理
|
2023-03-05 17:07:54 +00:00
|
|
|
|
function Room:askForUseCard(player, card_name, pattern, prompt, cancelable, extra_data, event_data)
|
2024-01-24 19:13:57 +00:00
|
|
|
|
pattern = pattern or card_name
|
2023-06-11 08:22:11 +00:00
|
|
|
|
if event_data and (event_data.disresponsive or table.contains(event_data.disresponsiveList or Util.DummyTable, player.id)) then
|
2023-05-28 10:45:54 +00:00
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
2024-01-24 19:13:57 +00:00
|
|
|
|
if event_data and event_data.prohibitedCardNames then
|
|
|
|
|
local exp = Exppattern:Parse(pattern)
|
|
|
|
|
for _, matcher in ipairs(exp.matchers) do
|
|
|
|
|
matcher.name = table.filter(matcher.name, function(name)
|
|
|
|
|
return not table.contains(event_data.prohibitedCardNames, name)
|
|
|
|
|
end)
|
|
|
|
|
if #matcher.name == 0 then return nil end
|
2023-05-28 10:45:54 +00:00
|
|
|
|
end
|
2024-01-24 19:13:57 +00:00
|
|
|
|
pattern = tostring(exp)
|
2023-05-28 10:45:54 +00:00
|
|
|
|
end
|
|
|
|
|
|
2022-12-18 13:19:35 +00:00
|
|
|
|
local command = "AskForUseCard"
|
|
|
|
|
self:notifyMoveFocus(player, card_name)
|
2023-06-09 18:18:51 +00:00
|
|
|
|
cancelable = (cancelable == nil) and true or cancelable
|
2023-06-11 08:22:11 +00:00
|
|
|
|
extra_data = extra_data or Util.DummyTable
|
2023-01-29 10:11:41 +00:00
|
|
|
|
prompt = prompt or ""
|
2022-12-18 13:19:35 +00:00
|
|
|
|
|
2023-03-05 17:07:54 +00:00
|
|
|
|
local askForUseCardData = {
|
|
|
|
|
user = player,
|
|
|
|
|
cardName = card_name,
|
|
|
|
|
pattern = pattern,
|
|
|
|
|
extraData = extra_data,
|
|
|
|
|
eventData = event_data,
|
|
|
|
|
}
|
|
|
|
|
self.logic:trigger(fk.AskForCardUse, player, askForUseCardData)
|
|
|
|
|
|
|
|
|
|
if askForUseCardData.result and type(askForUseCardData.result) == 'table' then
|
|
|
|
|
return askForUseCardData.result
|
|
|
|
|
else
|
2023-12-10 10:55:16 +00:00
|
|
|
|
local useResult
|
|
|
|
|
local disabledSkillNames = {}
|
2023-04-10 07:55:06 +00:00
|
|
|
|
|
2023-12-10 10:55:16 +00:00
|
|
|
|
repeat
|
|
|
|
|
useResult = nil
|
|
|
|
|
local data = {card_name, pattern, prompt, cancelable, extra_data, disabledSkillNames}
|
2023-04-10 07:55:06 +00:00
|
|
|
|
|
2023-12-10 10:55:16 +00:00
|
|
|
|
Fk.currentResponsePattern = pattern
|
|
|
|
|
local result = self:doRequest(player, command, json.encode(data))
|
|
|
|
|
Fk.currentResponsePattern = nil
|
|
|
|
|
|
|
|
|
|
if result ~= "" then
|
|
|
|
|
useResult = self:handleUseCardReply(player, result)
|
|
|
|
|
|
|
|
|
|
if type(useResult) == "string" and useResult ~= "" then
|
|
|
|
|
table.insertIfNeed(disabledSkillNames, useResult)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
until type(useResult) ~= "string"
|
|
|
|
|
return useResult
|
2022-12-18 13:19:35 +00:00
|
|
|
|
end
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问一名玩家打出一张牌。
|
|
|
|
|
---@param player ServerPlayer @ 要询问的玩家
|
|
|
|
|
---@param card_name string @ 牌名
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param pattern? string @ 牌的规则
|
|
|
|
|
---@param prompt? string @ 提示信息
|
|
|
|
|
---@param cancelable? boolean @ 能否取消
|
|
|
|
|
---@param extra_data? any @ 额外数据
|
|
|
|
|
---@param effectData? CardEffectEvent @ 关联的卡牌生效流程
|
|
|
|
|
---@return Card? @ 打出的牌
|
2023-05-28 10:45:54 +00:00
|
|
|
|
function Room:askForResponse(player, card_name, pattern, prompt, cancelable, extra_data, effectData)
|
2023-06-11 08:22:11 +00:00
|
|
|
|
if effectData and (effectData.disresponsive or table.contains(effectData.disresponsiveList or Util.DummyTable, player.id)) then
|
2023-05-28 10:45:54 +00:00
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-18 13:19:35 +00:00
|
|
|
|
local command = "AskForResponseCard"
|
|
|
|
|
self:notifyMoveFocus(player, card_name)
|
2023-06-09 18:18:51 +00:00
|
|
|
|
cancelable = (cancelable == nil) and true or cancelable
|
2023-06-11 08:22:11 +00:00
|
|
|
|
extra_data = extra_data or Util.DummyTable
|
2023-01-16 11:13:07 +00:00
|
|
|
|
pattern = pattern or card_name
|
2023-01-29 10:11:41 +00:00
|
|
|
|
prompt = prompt or ""
|
2022-12-18 13:19:35 +00:00
|
|
|
|
|
2023-03-05 17:07:54 +00:00
|
|
|
|
local eventData = {
|
|
|
|
|
user = player,
|
|
|
|
|
cardName = card_name,
|
|
|
|
|
pattern = pattern,
|
|
|
|
|
extraData = extra_data,
|
|
|
|
|
}
|
|
|
|
|
self.logic:trigger(fk.AskForCardResponse, player, eventData)
|
|
|
|
|
|
|
|
|
|
if eventData.result then
|
|
|
|
|
return eventData.result
|
|
|
|
|
else
|
2023-12-10 10:55:16 +00:00
|
|
|
|
local useResult
|
|
|
|
|
local disabledSkillNames = {}
|
2023-04-10 07:55:06 +00:00
|
|
|
|
|
2023-12-10 10:55:16 +00:00
|
|
|
|
repeat
|
|
|
|
|
useResult = nil
|
|
|
|
|
local data = {card_name, pattern, prompt, cancelable, extra_data, disabledSkillNames}
|
2023-04-10 07:55:06 +00:00
|
|
|
|
|
2023-12-10 10:55:16 +00:00
|
|
|
|
Fk.currentResponsePattern = pattern
|
|
|
|
|
local result = self:doRequest(player, command, json.encode(data))
|
|
|
|
|
Fk.currentResponsePattern = nil
|
|
|
|
|
|
|
|
|
|
if result ~= "" then
|
|
|
|
|
useResult = self:handleUseCardReply(player, result)
|
|
|
|
|
|
|
|
|
|
if type(useResult) == "string" and useResult ~= "" then
|
|
|
|
|
table.insertIfNeed(disabledSkillNames, useResult)
|
|
|
|
|
end
|
2023-03-05 17:07:54 +00:00
|
|
|
|
end
|
2023-12-10 10:55:16 +00:00
|
|
|
|
until type(useResult) ~= "string"
|
|
|
|
|
|
|
|
|
|
if useResult then
|
|
|
|
|
return useResult.card
|
2022-12-18 13:19:35 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 同时询问多名玩家是否使用某一张牌。
|
|
|
|
|
---
|
|
|
|
|
--- 函数名字虽然是“询问无懈可击”,不过其实也可以给别的牌用就是了。
|
|
|
|
|
---@param players ServerPlayer[] @ 要询问的玩家列表
|
|
|
|
|
---@param card_name string @ 询问的牌名,默认为无懈
|
|
|
|
|
---@param pattern string @ 牌的规则
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param prompt? string @ 提示信息
|
|
|
|
|
---@param cancelable? boolean @ 能否点取消
|
|
|
|
|
---@param extra_data? any @ 额外信息
|
|
|
|
|
---@return CardUseStruct? @ 最终决胜出的卡牌使用信息
|
2023-01-16 11:13:07 +00:00
|
|
|
|
function Room:askForNullification(players, card_name, pattern, prompt, cancelable, extra_data)
|
2022-12-18 13:19:35 +00:00
|
|
|
|
if #players == 0 then
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local command = "AskForUseCard"
|
|
|
|
|
card_name = card_name or "nullification"
|
2023-06-09 18:18:51 +00:00
|
|
|
|
cancelable = (cancelable == nil) and true or cancelable
|
2023-06-11 08:22:11 +00:00
|
|
|
|
extra_data = extra_data or Util.DummyTable
|
2023-01-29 10:11:41 +00:00
|
|
|
|
prompt = prompt or ""
|
2023-01-16 11:13:07 +00:00
|
|
|
|
pattern = pattern or card_name
|
2022-12-18 13:19:35 +00:00
|
|
|
|
|
2023-12-10 10:55:16 +00:00
|
|
|
|
local useResult
|
|
|
|
|
local disabledSkillNames = {}
|
2022-12-18 13:19:35 +00:00
|
|
|
|
|
2023-12-10 10:55:16 +00:00
|
|
|
|
repeat
|
|
|
|
|
useResult = nil
|
|
|
|
|
self:notifyMoveFocus(self.alive_players, card_name)
|
|
|
|
|
self:doBroadcastNotify("WaitForNullification", "")
|
2023-04-10 07:55:06 +00:00
|
|
|
|
|
2023-12-10 10:55:16 +00:00
|
|
|
|
local data = {card_name, pattern, prompt, cancelable, extra_data, disabledSkillNames}
|
2023-04-10 07:55:06 +00:00
|
|
|
|
|
2023-12-10 10:55:16 +00:00
|
|
|
|
Fk.currentResponsePattern = pattern
|
|
|
|
|
local winner = self:doRaceRequest(command, players, json.encode(data))
|
|
|
|
|
|
|
|
|
|
if winner then
|
|
|
|
|
local result = winner.client_reply
|
|
|
|
|
useResult = self:handleUseCardReply(winner, result)
|
|
|
|
|
|
|
|
|
|
if type(useResult) == "string" and useResult ~= "" then
|
|
|
|
|
table.insertIfNeed(disabledSkillNames, useResult)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
Fk.currentResponsePattern = nil
|
|
|
|
|
until type(useResult) ~= "string"
|
|
|
|
|
|
|
|
|
|
return useResult
|
2022-12-18 13:19:35 +00:00
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2023-03-01 13:41:16 +00:00
|
|
|
|
-- AG(a.k.a. Amazing Grace) functions
|
|
|
|
|
-- Popup a box that contains many cards, then ask player to choose one
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 询问玩家从AG中选择一张牌。
|
|
|
|
|
---@param player ServerPlayer @ 要询问的玩家
|
|
|
|
|
---@param id_list integer[] | Card[] @ 可选的卡牌列表
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param cancelable? boolean @ 能否点取消
|
|
|
|
|
---@param reason? string @ 原因
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@return integer @ 选择的卡牌
|
2023-03-01 13:41:16 +00:00
|
|
|
|
function Room:askForAG(player, id_list, cancelable, reason)
|
|
|
|
|
id_list = Card:getIdList(id_list)
|
|
|
|
|
if #id_list == 1 and not cancelable then
|
|
|
|
|
return id_list[1]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local command = "AskForAG"
|
|
|
|
|
self:notifyMoveFocus(player, reason or command)
|
|
|
|
|
local data = { id_list, cancelable, reason }
|
|
|
|
|
local ret = self:doRequest(player, command, json.encode(data))
|
|
|
|
|
if ret == "" and not cancelable then
|
|
|
|
|
ret = table.random(id_list)
|
|
|
|
|
end
|
|
|
|
|
return tonumber(ret)
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 给player发一条消息,在他的窗口中用一系列卡牌填充一个AG。
|
|
|
|
|
---@param player ServerPlayer @ 要通知的玩家
|
|
|
|
|
---@param id_list integer[] | Card[] @ 要填充的卡牌
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param disable_ids? integer[] | Card[] @ 未使用
|
2023-03-01 13:41:16 +00:00
|
|
|
|
function Room:fillAG(player, id_list, disable_ids)
|
|
|
|
|
id_list = Card:getIdList(id_list)
|
|
|
|
|
-- disable_ids = Card:getIdList(disable_ids)
|
|
|
|
|
player:doNotify("FillAG", json.encode{ id_list, disable_ids })
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 告诉一些玩家,AG中的牌被taker取走了。
|
|
|
|
|
---@param taker ServerPlayer @ 拿走牌的玩家
|
|
|
|
|
---@param id integer @ 被拿走的牌
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param notify_list? ServerPlayer[] @ 要告知的玩家,默认为全员
|
2023-03-01 13:41:16 +00:00
|
|
|
|
function Room:takeAG(taker, id, notify_list)
|
|
|
|
|
self:doBroadcastNotify("TakeAG", json.encode{ taker.id, id }, notify_list)
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 关闭player那侧显示的AG。
|
|
|
|
|
---
|
|
|
|
|
--- 若不传参(即player为nil),那么关闭所有玩家的AG。
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param player? ServerPlayer @ 要关闭AG的玩家
|
2023-03-01 13:41:16 +00:00
|
|
|
|
function Room:closeAG(player)
|
|
|
|
|
if player then player:doNotify("CloseAG", "")
|
|
|
|
|
else self:doBroadcastNotify("CloseAG", "") end
|
|
|
|
|
end
|
|
|
|
|
|
2024-01-11 10:36:05 +00:00
|
|
|
|
-- TODO: 重构request机制,不然这个还得手动拿client_reply
|
|
|
|
|
---@param players ServerPlayer[]
|
|
|
|
|
---@param focus string
|
|
|
|
|
---@param game_type string
|
|
|
|
|
---@param data_table table<integer, any> @ 对应每个player
|
|
|
|
|
function Room:askForMiniGame(players, focus, game_type, data_table)
|
|
|
|
|
local command = "MiniGame"
|
|
|
|
|
local game = Fk.mini_games[game_type]
|
|
|
|
|
if #players == 0 or not game then return end
|
|
|
|
|
for _, p in ipairs(players) do
|
|
|
|
|
local data = data_table[p.id]
|
|
|
|
|
p.mini_game_data = { type = game_type, data = data }
|
|
|
|
|
p.request_data = json.encode(p.mini_game_data)
|
|
|
|
|
p.default_reply = game.default_choice and json.encode(game.default_choice(p, data)) or ""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self:notifyMoveFocus(players, focus)
|
|
|
|
|
self:doBroadcastRequest(command, players)
|
|
|
|
|
|
|
|
|
|
for _, p in ipairs(players) do
|
|
|
|
|
p.mini_game_data = nil
|
|
|
|
|
if not p.reply_ready then
|
|
|
|
|
p.client_reply = p.default_reply
|
|
|
|
|
p.reply_ready = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-02-21 05:44:24 +00:00
|
|
|
|
-- Show a qml dialog and return qml's ClientInstance.replyToServer
|
|
|
|
|
-- Do anything you like through this function
|
|
|
|
|
|
|
|
|
|
---@param player ServerPlayer
|
|
|
|
|
---@param focustxt string
|
|
|
|
|
---@param qmlPath string
|
|
|
|
|
---@param extra_data any
|
|
|
|
|
---@return string
|
|
|
|
|
function Room:askForCustomDialog(player, focustxt, qmlPath, extra_data)
|
|
|
|
|
local command = "CustomDialog"
|
|
|
|
|
self:notifyMoveFocus(player, focustxt)
|
|
|
|
|
return self:doRequest(player, command, json.encode{
|
|
|
|
|
path = qmlPath,
|
|
|
|
|
data = extra_data,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2023-06-04 11:39:20 +00:00
|
|
|
|
---@param player ServerPlayer @ 移动的操作
|
|
|
|
|
---@param targetOne ServerPlayer @ 移动的目标1玩家
|
|
|
|
|
---@param targetTwo ServerPlayer @ 移动的目标2玩家
|
|
|
|
|
---@param skillName string @ 技能名
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param flag? string @ 限定可移动的区域,值为nil(装备区和判定区)、‘e’或‘j’
|
|
|
|
|
---@param moveFrom? ServerPlayer @ 是否只是目标1移动给目标2
|
|
|
|
|
---@param excludeIds? integer[] @ 本次不可移动的卡牌id
|
|
|
|
|
---@return table<"card"|"from"|"to">? @ 选择的卡牌、起点玩家id和终点玩家id列表
|
2023-07-16 11:18:43 +00:00
|
|
|
|
function Room:askForMoveCardInBoard(player, targetOne, targetTwo, skillName, flag, moveFrom, excludeIds)
|
2023-05-28 10:45:54 +00:00
|
|
|
|
if flag then
|
|
|
|
|
assert(flag == "e" or flag == "j")
|
|
|
|
|
end
|
|
|
|
|
|
2023-07-16 11:18:43 +00:00
|
|
|
|
excludeIds = type(excludeIds) == "table" and excludeIds or {}
|
|
|
|
|
|
2023-05-20 08:00:03 +00:00
|
|
|
|
local cards = {}
|
|
|
|
|
local cardsPosition = {}
|
2023-05-28 10:45:54 +00:00
|
|
|
|
|
|
|
|
|
if not flag or flag == "e" then
|
|
|
|
|
if not moveFrom or moveFrom == targetOne then
|
|
|
|
|
for _, equipId in ipairs(targetOne:getCardIds(Player.Equip)) do
|
2023-07-16 11:18:43 +00:00
|
|
|
|
if not table.contains(excludeIds, equipId) and targetOne:canMoveCardInBoardTo(targetTwo, equipId) then
|
2023-05-28 10:45:54 +00:00
|
|
|
|
table.insert(cards, equipId)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-05-20 08:00:03 +00:00
|
|
|
|
end
|
2023-05-28 10:45:54 +00:00
|
|
|
|
if not moveFrom or moveFrom == targetTwo then
|
|
|
|
|
for _, equipId in ipairs(targetTwo:getCardIds(Player.Equip)) do
|
2023-07-16 11:18:43 +00:00
|
|
|
|
if not table.contains(excludeIds, equipId) and targetTwo:canMoveCardInBoardTo(targetOne, equipId) then
|
2023-05-28 10:45:54 +00:00
|
|
|
|
table.insert(cards, equipId)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-05-20 08:00:03 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-05-28 10:45:54 +00:00
|
|
|
|
if #cards > 0 then
|
|
|
|
|
table.sort(cards, function(prev, next)
|
|
|
|
|
local prevSubType = Fk:getCardById(prev).sub_type
|
|
|
|
|
local nextSubType = Fk:getCardById(next).sub_type
|
2023-05-20 08:00:03 +00:00
|
|
|
|
|
2023-05-28 10:45:54 +00:00
|
|
|
|
return prevSubType < nextSubType
|
|
|
|
|
end)
|
2023-05-20 08:00:03 +00:00
|
|
|
|
|
2023-05-28 10:45:54 +00:00
|
|
|
|
for _, id in ipairs(cards) do
|
|
|
|
|
table.insert(cardsPosition, self:getCardOwner(id) == targetOne and 0 or 1)
|
|
|
|
|
end
|
2023-05-20 08:00:03 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-28 10:45:54 +00:00
|
|
|
|
if not flag or flag == "j" then
|
|
|
|
|
if not moveFrom or moveFrom == targetOne then
|
|
|
|
|
for _, trickId in ipairs(targetOne:getCardIds(Player.Judge)) do
|
2023-07-16 11:18:43 +00:00
|
|
|
|
if not table.contains(excludeIds, trickId) and targetOne:canMoveCardInBoardTo(targetTwo, trickId) then
|
2023-05-28 10:45:54 +00:00
|
|
|
|
table.insert(cards, trickId)
|
|
|
|
|
table.insert(cardsPosition, 0)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-05-20 08:00:03 +00:00
|
|
|
|
end
|
2023-05-28 10:45:54 +00:00
|
|
|
|
if not moveFrom or moveFrom == targetTwo then
|
|
|
|
|
for _, trickId in ipairs(targetTwo:getCardIds(Player.Judge)) do
|
2023-07-16 11:18:43 +00:00
|
|
|
|
if not table.contains(excludeIds, trickId) and targetTwo:canMoveCardInBoardTo(targetOne, trickId) then
|
2023-05-28 10:45:54 +00:00
|
|
|
|
table.insert(cards, trickId)
|
|
|
|
|
table.insert(cardsPosition, 1)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-05-20 08:00:03 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if #cards == 0 then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local firstGeneralName = targetOne.general + (targetOne.deputyGeneral ~= "" and ("/" .. targetOne.deputyGeneral) or "")
|
|
|
|
|
local secGeneralName = targetTwo.general + (targetTwo.deputyGeneral ~= "" and ("/" .. targetTwo.deputyGeneral) or "")
|
|
|
|
|
|
2023-07-16 11:18:43 +00:00
|
|
|
|
local data = {
|
|
|
|
|
cards = cards,
|
|
|
|
|
cardsPosition = cardsPosition,
|
|
|
|
|
generalNames = { firstGeneralName, secGeneralName },
|
|
|
|
|
playerIds = { targetOne.id, targetTwo.id }
|
|
|
|
|
}
|
2023-05-20 08:00:03 +00:00
|
|
|
|
local command = "AskForMoveCardInBoard"
|
|
|
|
|
self:notifyMoveFocus(player, command)
|
|
|
|
|
local result = self:doRequest(player, command, json.encode(data))
|
|
|
|
|
|
|
|
|
|
if result == "" then
|
|
|
|
|
local randomIndex = math.random(1, #cards)
|
|
|
|
|
result = { cardId = cards[randomIndex], pos = cardsPosition[randomIndex] }
|
|
|
|
|
else
|
|
|
|
|
result = json.decode(result)
|
|
|
|
|
end
|
|
|
|
|
|
2023-09-27 13:02:22 +00:00
|
|
|
|
local from, to
|
|
|
|
|
if result.pos == 0 then
|
|
|
|
|
from, to = targetOne, targetTwo
|
|
|
|
|
else
|
|
|
|
|
from, to = targetTwo, targetOne
|
|
|
|
|
end
|
2023-07-16 11:18:43 +00:00
|
|
|
|
local cardToMove = self:getCardOwner(result.cardId):getVirualEquip(result.cardId) or Fk:getCardById(result.cardId)
|
2023-05-20 08:00:03 +00:00
|
|
|
|
self:moveCardTo(
|
|
|
|
|
cardToMove,
|
|
|
|
|
cardToMove.type == Card.TypeEquip and Player.Equip or Player.Judge,
|
2023-07-16 07:29:20 +00:00
|
|
|
|
to,
|
2023-05-20 08:00:03 +00:00
|
|
|
|
fk.ReasonPut,
|
|
|
|
|
skillName,
|
|
|
|
|
nil,
|
2023-08-02 13:50:47 +00:00
|
|
|
|
true,
|
|
|
|
|
player.id
|
2023-05-20 08:00:03 +00:00
|
|
|
|
)
|
2023-07-16 07:29:20 +00:00
|
|
|
|
|
|
|
|
|
return { card = cardToMove, from = from.id, to = to.id }
|
2023-05-20 08:00:03 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-06-04 11:39:20 +00:00
|
|
|
|
--- 询问一名玩家从targets中选择出若干名玩家来移动场上的牌。
|
2023-05-28 10:45:54 +00:00
|
|
|
|
---@param player ServerPlayer @ 要做选择的玩家
|
|
|
|
|
---@param prompt string @ 提示信息
|
|
|
|
|
---@param skillName string @ 技能名
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param cancelable? boolean @ 是否可以取消选择
|
|
|
|
|
---@param flag? string @ 限定可移动的区域,值为nil(装备区和判定区)、‘e’或‘j’
|
|
|
|
|
---@param no_indicate? boolean @ 是否不显示指示线
|
2023-05-28 10:45:54 +00:00
|
|
|
|
---@return integer[] @ 选择的玩家id列表,可能为空
|
2023-07-16 11:18:43 +00:00
|
|
|
|
function Room:askForChooseToMoveCardInBoard(player, prompt, skillName, cancelable, flag, no_indicate, excludeIds)
|
2023-05-28 10:45:54 +00:00
|
|
|
|
if flag then
|
|
|
|
|
assert(flag == "e" or flag == "j")
|
|
|
|
|
end
|
2023-06-09 18:18:51 +00:00
|
|
|
|
cancelable = (cancelable == nil) and true or cancelable
|
2023-06-10 15:51:09 +00:00
|
|
|
|
no_indicate = (no_indicate == nil) and true or no_indicate
|
2023-07-16 11:18:43 +00:00
|
|
|
|
excludeIds = type(excludeIds) == "table" and excludeIds or {}
|
2023-05-28 10:45:54 +00:00
|
|
|
|
|
|
|
|
|
local data = {
|
|
|
|
|
flag = flag,
|
|
|
|
|
skillName = skillName,
|
2023-07-16 11:18:43 +00:00
|
|
|
|
excludeIds = excludeIds,
|
2023-05-28 10:45:54 +00:00
|
|
|
|
}
|
|
|
|
|
local _, ret = self:askForUseActiveSkill(
|
|
|
|
|
player,
|
|
|
|
|
"choose_players_to_move_card_in_board",
|
|
|
|
|
prompt or "",
|
|
|
|
|
cancelable,
|
2023-06-10 15:51:09 +00:00
|
|
|
|
data,
|
|
|
|
|
no_indicate
|
2023-05-28 10:45:54 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if ret then
|
|
|
|
|
return ret.targets
|
|
|
|
|
else
|
|
|
|
|
if cancelable then
|
|
|
|
|
return {}
|
|
|
|
|
else
|
2023-07-16 11:18:43 +00:00
|
|
|
|
return self:canMoveCardInBoard(flag, excludeIds)
|
2023-05-28 10:45:54 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- 使用牌
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 根据卡牌使用数据,去实际使用这个卡牌。
|
|
|
|
|
---@param cardUseEvent CardUseStruct @ 使用数据
|
2023-02-28 17:43:44 +00:00
|
|
|
|
---@return boolean
|
|
|
|
|
function Room:useCard(cardUseEvent)
|
2024-02-04 14:29:54 +00:00
|
|
|
|
return execGameEvent(GameEvent.UseCard, cardUseEvent)
|
2023-01-16 11:13:07 +00:00
|
|
|
|
end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
---@param room Room
|
|
|
|
|
---@param cardUseEvent CardUseStruct
|
|
|
|
|
---@param aimEventCollaborators table<string, AimStruct[]>
|
|
|
|
|
---@return boolean
|
|
|
|
|
local onAim = function(room, cardUseEvent, aimEventCollaborators)
|
|
|
|
|
local eventStages = { fk.TargetSpecifying, fk.TargetConfirming, fk.TargetSpecified, fk.TargetConfirmed }
|
|
|
|
|
for _, stage in ipairs(eventStages) do
|
2022-12-18 13:19:35 +00:00
|
|
|
|
if (not cardUseEvent.tos) or #cardUseEvent.tos == 0 then
|
2022-09-15 03:17:13 +00:00
|
|
|
|
return false
|
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2023-05-13 06:20:34 +00:00
|
|
|
|
room:sortPlayersByAction(cardUseEvent.tos, true)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
local aimGroup = AimGroup:initAimGroup(TargetGroup:getRealTargets(cardUseEvent.tos))
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
local collaboratorsIndex = {}
|
|
|
|
|
local firstTarget = true
|
|
|
|
|
repeat
|
|
|
|
|
local toId = AimGroup:getUndoneOrDoneTargets(aimGroup)[1]
|
|
|
|
|
---@type AimStruct
|
|
|
|
|
local aimStruct
|
|
|
|
|
local initialEvent = false
|
2022-12-18 04:52:52 +00:00
|
|
|
|
collaboratorsIndex[toId] = collaboratorsIndex[toId] or 1
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2022-12-18 04:52:52 +00:00
|
|
|
|
if not aimEventCollaborators[toId] or collaboratorsIndex[toId] > #aimEventCollaborators[toId] then
|
2022-09-15 03:17:13 +00:00
|
|
|
|
aimStruct = {
|
|
|
|
|
from = cardUseEvent.from,
|
2023-01-16 11:13:07 +00:00
|
|
|
|
card = cardUseEvent.card,
|
2022-09-15 03:17:13 +00:00
|
|
|
|
to = toId,
|
|
|
|
|
targetGroup = cardUseEvent.tos,
|
|
|
|
|
nullifiedTargets = cardUseEvent.nullifiedTargets or {},
|
|
|
|
|
tos = aimGroup,
|
|
|
|
|
firstTarget = firstTarget,
|
2023-03-20 12:49:23 +00:00
|
|
|
|
additionalDamage = cardUseEvent.additionalDamage,
|
2023-05-28 10:45:54 +00:00
|
|
|
|
additionalRecover = cardUseEvent.additionalRecover,
|
2024-02-04 07:29:39 +00:00
|
|
|
|
additionalEffect = cardUseEvent.additionalEffect,
|
2023-03-20 12:49:23 +00:00
|
|
|
|
extra_data = cardUseEvent.extra_data,
|
2022-09-15 03:17:13 +00:00
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2022-12-20 13:15:49 +00:00
|
|
|
|
local index = 1
|
|
|
|
|
for _, targets in ipairs(cardUseEvent.tos) do
|
|
|
|
|
if index > collaboratorsIndex[toId] then
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if #targets > 1 then
|
|
|
|
|
for i = 2, #targets do
|
|
|
|
|
aimStruct.subTargets = {}
|
|
|
|
|
table.insert(aimStruct.subTargets, targets[i])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
collaboratorsIndex[toId] = 1
|
|
|
|
|
initialEvent = true
|
|
|
|
|
else
|
|
|
|
|
aimStruct = aimEventCollaborators[toId][collaboratorsIndex[toId]]
|
|
|
|
|
aimStruct.from = cardUseEvent.from
|
2023-01-16 11:13:07 +00:00
|
|
|
|
aimStruct.card = cardUseEvent.card
|
2022-04-30 07:27:56 +00:00
|
|
|
|
aimStruct.tos = aimGroup
|
|
|
|
|
aimStruct.targetGroup = cardUseEvent.tos
|
|
|
|
|
aimStruct.nullifiedTargets = cardUseEvent.nullifiedTargets or {}
|
|
|
|
|
aimStruct.firstTarget = firstTarget
|
2024-02-04 07:29:39 +00:00
|
|
|
|
aimStruct.additionalEffect = cardUseEvent.additionalEffect
|
2023-03-20 12:49:23 +00:00
|
|
|
|
aimStruct.extra_data = cardUseEvent.extra_data
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
firstTarget = false
|
|
|
|
|
|
2023-12-10 10:55:16 +00:00
|
|
|
|
room.logic:trigger(stage, (stage == fk.TargetSpecifying or stage == fk.TargetSpecified) and room:getPlayerById(aimStruct.from) or room:getPlayerById(aimStruct.to), aimStruct)
|
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
AimGroup:removeDeadTargets(room, aimStruct)
|
|
|
|
|
|
|
|
|
|
local aimEventTargetGroup = aimStruct.targetGroup
|
|
|
|
|
if aimEventTargetGroup then
|
2023-05-13 06:20:34 +00:00
|
|
|
|
room:sortPlayersByAction(aimEventTargetGroup, true)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
cardUseEvent.from = aimStruct.from
|
|
|
|
|
cardUseEvent.tos = aimEventTargetGroup
|
|
|
|
|
cardUseEvent.nullifiedTargets = aimStruct.nullifiedTargets
|
2024-02-04 07:29:39 +00:00
|
|
|
|
cardUseEvent.additionalEffect = aimStruct.additionalEffect
|
2023-03-20 12:49:23 +00:00
|
|
|
|
cardUseEvent.extra_data = aimStruct.extra_data
|
2022-12-18 04:52:52 +00:00
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
|
if #AimGroup:getAllTargets(aimStruct.tos) == 0 then
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local cancelledTargets = AimGroup:getCancelledTargets(aimStruct.tos)
|
|
|
|
|
if #cancelledTargets > 0 then
|
|
|
|
|
for _, target in ipairs(cancelledTargets) do
|
|
|
|
|
aimEventCollaborators[target] = {}
|
2022-12-18 04:52:52 +00:00
|
|
|
|
collaboratorsIndex[target] = 1
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
aimStruct.tos[AimGroup.Cancelled] = {}
|
|
|
|
|
|
|
|
|
|
aimEventCollaborators[toId] = aimEventCollaborators[toId] or {}
|
2022-12-18 04:52:52 +00:00
|
|
|
|
if room:getPlayerById(toId):isAlive() then
|
2022-04-30 07:27:56 +00:00
|
|
|
|
if initialEvent then
|
|
|
|
|
table.insert(aimEventCollaborators[toId], aimStruct)
|
|
|
|
|
else
|
|
|
|
|
aimEventCollaborators[toId][collaboratorsIndex[toId]] = aimStruct
|
|
|
|
|
end
|
2022-12-18 04:52:52 +00:00
|
|
|
|
|
|
|
|
|
collaboratorsIndex[toId] = collaboratorsIndex[toId] + 1
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
AimGroup:setTargetDone(aimStruct.tos, toId)
|
|
|
|
|
aimGroup = aimStruct.tos
|
|
|
|
|
until #AimGroup:getUndoneOrDoneTargets(aimGroup) == 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 对卡牌使用数据进行生效
|
2023-02-21 05:44:24 +00:00
|
|
|
|
---@param cardUseEvent CardUseStruct
|
|
|
|
|
function Room:doCardUseEffect(cardUseEvent)
|
|
|
|
|
---@type table<string, AimStruct>
|
|
|
|
|
local aimEventCollaborators = {}
|
|
|
|
|
if cardUseEvent.tos and not onAim(self, cardUseEvent, aimEventCollaborators) then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local realCardIds = self:getSubcardsByRule(cardUseEvent.card, { Card.Processing })
|
|
|
|
|
|
2023-09-27 13:02:22 +00:00
|
|
|
|
self.logic:trigger(fk.BeforeCardUseEffect, self:getPlayerById(cardUseEvent.from), cardUseEvent)
|
2023-02-21 05:44:24 +00:00
|
|
|
|
-- If using Equip or Delayed trick, move them to the area and return
|
|
|
|
|
if cardUseEvent.card.type == Card.TypeEquip then
|
|
|
|
|
if #realCardIds == 0 then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if self:getPlayerById(TargetGroup:getRealTargets(cardUseEvent.tos)[1]).dead then
|
2023-08-12 18:25:04 +00:00
|
|
|
|
self:moveCards({
|
2023-02-21 05:44:24 +00:00
|
|
|
|
ids = realCardIds,
|
|
|
|
|
toArea = Card.DiscardPile,
|
|
|
|
|
moveReason = fk.ReasonPutIntoDiscardPile,
|
|
|
|
|
})
|
|
|
|
|
else
|
|
|
|
|
local target = TargetGroup:getRealTargets(cardUseEvent.tos)[1]
|
|
|
|
|
local existingEquipId = self:getPlayerById(target):getEquipment(cardUseEvent.card.sub_type)
|
|
|
|
|
if existingEquipId then
|
|
|
|
|
self:moveCards(
|
|
|
|
|
{
|
|
|
|
|
ids = { existingEquipId },
|
|
|
|
|
from = target,
|
2022-04-30 07:27:56 +00:00
|
|
|
|
toArea = Card.DiscardPile,
|
|
|
|
|
moveReason = fk.ReasonPutIntoDiscardPile,
|
2023-02-21 05:44:24 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ids = realCardIds,
|
|
|
|
|
to = target,
|
|
|
|
|
toArea = Card.PlayerEquip,
|
|
|
|
|
moveReason = fk.ReasonUse,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
self:moveCards({
|
|
|
|
|
ids = realCardIds,
|
|
|
|
|
to = target,
|
|
|
|
|
toArea = Card.PlayerEquip,
|
|
|
|
|
moveReason = fk.ReasonUse,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2023-02-21 05:44:24 +00:00
|
|
|
|
return
|
|
|
|
|
elseif cardUseEvent.card.sub_type == Card.SubtypeDelayedTrick then
|
|
|
|
|
if #realCardIds == 0 then
|
|
|
|
|
return
|
|
|
|
|
end
|
2023-02-26 08:51:29 +00:00
|
|
|
|
|
2023-02-21 05:44:24 +00:00
|
|
|
|
local target = TargetGroup:getRealTargets(cardUseEvent.tos)[1]
|
|
|
|
|
if not self:getPlayerById(target).dead then
|
|
|
|
|
local findSameCard = false
|
|
|
|
|
for _, cardId in ipairs(self:getPlayerById(target):getCardIds(Player.Judge)) do
|
|
|
|
|
if Fk:getCardById(cardId).trueName == cardUseEvent.card.trueName then
|
|
|
|
|
findSameCard = true
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
2023-02-21 05:44:24 +00:00
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2023-02-21 05:44:24 +00:00
|
|
|
|
if not findSameCard then
|
|
|
|
|
if cardUseEvent.card:isVirtual() then
|
|
|
|
|
self:getPlayerById(target):addVirtualEquip(cardUseEvent.card)
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self:moveCards({
|
2023-01-16 11:13:07 +00:00
|
|
|
|
ids = realCardIds,
|
2023-02-21 05:44:24 +00:00
|
|
|
|
to = target,
|
|
|
|
|
toArea = Card.PlayerJudge,
|
|
|
|
|
moveReason = fk.ReasonUse,
|
2022-04-30 07:27:56 +00:00
|
|
|
|
})
|
|
|
|
|
|
2023-02-21 05:44:24 +00:00
|
|
|
|
return
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
2023-02-21 05:44:24 +00:00
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2023-02-21 05:44:24 +00:00
|
|
|
|
self:moveCards({
|
|
|
|
|
ids = realCardIds,
|
|
|
|
|
toArea = Card.DiscardPile,
|
|
|
|
|
moveReason = fk.ReasonPutIntoDiscardPile,
|
|
|
|
|
})
|
2022-12-18 04:52:52 +00:00
|
|
|
|
|
2023-02-21 05:44:24 +00:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if not cardUseEvent.card.skill then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2024-02-04 07:30:27 +00:00
|
|
|
|
---@class CardEffectEvent
|
2023-02-21 05:44:24 +00:00
|
|
|
|
local cardEffectEvent = {
|
|
|
|
|
from = cardUseEvent.from,
|
|
|
|
|
tos = cardUseEvent.tos,
|
|
|
|
|
card = cardUseEvent.card,
|
|
|
|
|
toCard = cardUseEvent.toCard,
|
|
|
|
|
responseToEvent = cardUseEvent.responseToEvent,
|
|
|
|
|
nullifiedTargets = cardUseEvent.nullifiedTargets,
|
|
|
|
|
disresponsiveList = cardUseEvent.disresponsiveList,
|
|
|
|
|
unoffsetableList = cardUseEvent.unoffsetableList,
|
2023-03-14 12:48:08 +00:00
|
|
|
|
additionalDamage = cardUseEvent.additionalDamage,
|
2023-05-28 10:45:54 +00:00
|
|
|
|
additionalRecover = cardUseEvent.additionalRecover,
|
2023-06-11 04:45:12 +00:00
|
|
|
|
cardsResponded = cardUseEvent.cardsResponded,
|
2023-05-28 10:45:54 +00:00
|
|
|
|
prohibitedCardNames = cardUseEvent.prohibitedCardNames,
|
2023-03-14 12:48:08 +00:00
|
|
|
|
extra_data = cardUseEvent.extra_data,
|
2023-02-21 05:44:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-- If using card to other card (like jink or nullification), simply effect and return
|
|
|
|
|
if cardUseEvent.toCard ~= nil then
|
|
|
|
|
self:doCardEffect(cardEffectEvent)
|
2023-12-28 04:15:01 +00:00
|
|
|
|
|
|
|
|
|
if cardEffectEvent.cardsResponded then
|
|
|
|
|
cardUseEvent.cardsResponded = cardUseEvent.cardsResponded or {}
|
|
|
|
|
for _, card in ipairs(cardEffectEvent.cardsResponded) do
|
|
|
|
|
table.insertIfNeed(cardUseEvent.cardsResponded, card)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-02-21 05:44:24 +00:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2024-02-04 07:29:39 +00:00
|
|
|
|
for i = 1, (cardUseEvent.additionalEffect or 0) + 1 do
|
|
|
|
|
if #TargetGroup:getRealTargets(cardUseEvent.tos) > 0 and cardUseEvent.card.skill.onAction then
|
|
|
|
|
cardUseEvent.card.skill:onAction(self, cardUseEvent)
|
2024-02-04 14:29:54 +00:00
|
|
|
|
cardEffectEvent.extra_data = cardUseEvent.extra_data
|
2024-02-04 07:29:39 +00:00
|
|
|
|
end
|
2023-06-04 11:40:14 +00:00
|
|
|
|
|
2024-02-04 07:29:39 +00:00
|
|
|
|
-- Else: do effect to all targets
|
|
|
|
|
local collaboratorsIndex = {}
|
|
|
|
|
for _, toId in ipairs(TargetGroup:getRealTargets(cardUseEvent.tos)) do
|
|
|
|
|
if not table.contains(cardUseEvent.nullifiedTargets, toId) and self:getPlayerById(toId):isAlive() then
|
|
|
|
|
if aimEventCollaborators[toId] then
|
|
|
|
|
cardEffectEvent.to = toId
|
|
|
|
|
collaboratorsIndex[toId] = collaboratorsIndex[toId] or 1
|
|
|
|
|
local curAimEvent = aimEventCollaborators[toId][collaboratorsIndex[toId]]
|
|
|
|
|
|
|
|
|
|
cardEffectEvent.subTargets = curAimEvent.subTargets
|
|
|
|
|
cardEffectEvent.additionalDamage = curAimEvent.additionalDamage
|
|
|
|
|
cardEffectEvent.additionalRecover = curAimEvent.additionalRecover
|
|
|
|
|
|
|
|
|
|
if curAimEvent.disresponsiveList then
|
|
|
|
|
cardEffectEvent.disresponsiveList = cardEffectEvent.disresponsiveList or {}
|
|
|
|
|
|
|
|
|
|
for _, disresponsivePlayer in ipairs(curAimEvent.disresponsiveList) do
|
|
|
|
|
if not table.contains(cardEffectEvent.disresponsiveList, disresponsivePlayer) then
|
|
|
|
|
table.insert(cardEffectEvent.disresponsiveList, disresponsivePlayer)
|
|
|
|
|
end
|
2022-12-18 04:52:52 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
|
|
2024-02-04 07:29:39 +00:00
|
|
|
|
if curAimEvent.unoffsetableList then
|
|
|
|
|
cardEffectEvent.unoffsetableList = cardEffectEvent.unoffsetableList or {}
|
2023-06-04 11:40:14 +00:00
|
|
|
|
|
2024-02-04 07:29:39 +00:00
|
|
|
|
for _, unoffsetablePlayer in ipairs(curAimEvent.unoffsetableList) do
|
|
|
|
|
if not table.contains(cardEffectEvent.unoffsetableList, unoffsetablePlayer) then
|
|
|
|
|
table.insert(cardEffectEvent.unoffsetableList, unoffsetablePlayer)
|
|
|
|
|
end
|
2023-02-21 05:44:24 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2023-01-16 11:13:07 +00:00
|
|
|
|
|
2024-02-04 07:29:39 +00:00
|
|
|
|
cardEffectEvent.disresponsive = curAimEvent.disresponsive
|
|
|
|
|
cardEffectEvent.unoffsetable = curAimEvent.unoffsetable
|
|
|
|
|
cardEffectEvent.fixedResponseTimes = curAimEvent.fixedResponseTimes
|
|
|
|
|
cardEffectEvent.fixedAddTimesResponsors = curAimEvent.fixedAddTimesResponsors
|
2023-02-21 05:44:24 +00:00
|
|
|
|
|
2024-02-04 07:29:39 +00:00
|
|
|
|
collaboratorsIndex[toId] = collaboratorsIndex[toId] + 1
|
2023-02-21 05:44:24 +00:00
|
|
|
|
|
2024-02-04 07:29:39 +00:00
|
|
|
|
local curCardEffectEvent = table.simpleClone(cardEffectEvent)
|
|
|
|
|
self:doCardEffect(curCardEffectEvent)
|
2023-06-11 04:45:12 +00:00
|
|
|
|
|
2024-02-04 07:29:39 +00:00
|
|
|
|
if curCardEffectEvent.cardsResponded then
|
|
|
|
|
cardUseEvent.cardsResponded = cardUseEvent.cardsResponded or {}
|
|
|
|
|
for _, card in ipairs(curCardEffectEvent.cardsResponded) do
|
|
|
|
|
table.insertIfNeed(cardUseEvent.cardsResponded, card)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if type(curCardEffectEvent.nullifiedTargets) == 'table' then
|
|
|
|
|
table.insertTableIfNeed(cardUseEvent.nullifiedTargets, curCardEffectEvent.nullifiedTargets)
|
2023-06-11 04:45:12 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2023-02-21 05:44:24 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2024-02-04 07:29:39 +00:00
|
|
|
|
|
|
|
|
|
if #TargetGroup:getRealTargets(cardUseEvent.tos) > 0 and cardUseEvent.card.skill.onAction then
|
|
|
|
|
cardUseEvent.card.skill:onAction(self, cardUseEvent, true)
|
|
|
|
|
end
|
2022-04-30 07:27:56 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 对卡牌效果数据进行生效
|
2022-12-18 04:52:52 +00:00
|
|
|
|
---@param cardEffectEvent CardEffectEvent
|
|
|
|
|
function Room:doCardEffect(cardEffectEvent)
|
2023-05-28 10:45:54 +00:00
|
|
|
|
return execGameEvent(GameEvent.CardEffect, cardEffectEvent)
|
|
|
|
|
end
|
2022-12-18 04:52:52 +00:00
|
|
|
|
|
2023-05-28 10:45:54 +00:00
|
|
|
|
---@param cardEffectEvent CardEffectEvent
|
|
|
|
|
function Room:handleCardEffect(event, cardEffectEvent)
|
|
|
|
|
if event == fk.PreCardEffect then
|
|
|
|
|
if cardEffectEvent.card.skill:aboutToEffect(self, cardEffectEvent) then return end
|
|
|
|
|
if
|
|
|
|
|
cardEffectEvent.card.trueName == "slash" and
|
2023-06-11 08:22:11 +00:00
|
|
|
|
not (cardEffectEvent.unoffsetable or table.contains(cardEffectEvent.unoffsetableList or Util.DummyTable, cardEffectEvent.to))
|
2023-05-28 10:45:54 +00:00
|
|
|
|
then
|
|
|
|
|
local loopTimes = 1
|
|
|
|
|
if cardEffectEvent.fixedResponseTimes then
|
|
|
|
|
if type(cardEffectEvent.fixedResponseTimes) == "table" then
|
|
|
|
|
loopTimes = cardEffectEvent.fixedResponseTimes["jink"] or 1
|
|
|
|
|
elseif type(cardEffectEvent.fixedResponseTimes) == "number" then
|
|
|
|
|
loopTimes = cardEffectEvent.fixedResponseTimes
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-06-14 05:40:50 +00:00
|
|
|
|
Fk.currentResponsePattern = "jink"
|
2022-12-18 04:52:52 +00:00
|
|
|
|
|
2023-05-28 10:45:54 +00:00
|
|
|
|
for i = 1, loopTimes do
|
|
|
|
|
local to = self:getPlayerById(cardEffectEvent.to)
|
|
|
|
|
local prompt = ""
|
|
|
|
|
if cardEffectEvent.from then
|
2024-01-11 10:35:10 +00:00
|
|
|
|
if loopTimes == 1 then
|
|
|
|
|
prompt = "#slash-jink:" .. cardEffectEvent.from
|
|
|
|
|
else
|
|
|
|
|
prompt = "#slash-jink-multi:" .. cardEffectEvent.from .. "::" .. i .. ":" .. loopTimes
|
|
|
|
|
end
|
2023-01-29 10:11:41 +00:00
|
|
|
|
end
|
2023-03-05 17:07:54 +00:00
|
|
|
|
|
2023-05-28 10:45:54 +00:00
|
|
|
|
local use = self:askForUseCard(
|
|
|
|
|
to,
|
|
|
|
|
"jink",
|
|
|
|
|
nil,
|
|
|
|
|
prompt,
|
|
|
|
|
true,
|
|
|
|
|
nil,
|
|
|
|
|
cardEffectEvent
|
|
|
|
|
)
|
|
|
|
|
if use then
|
|
|
|
|
use.toCard = cardEffectEvent.card
|
|
|
|
|
use.responseToEvent = cardEffectEvent
|
|
|
|
|
self:useCard(use)
|
|
|
|
|
end
|
2023-03-05 17:07:54 +00:00
|
|
|
|
|
2023-06-19 13:56:06 +00:00
|
|
|
|
if not cardEffectEvent.isCancellOut then
|
2023-05-28 10:45:54 +00:00
|
|
|
|
break
|
|
|
|
|
end
|
2023-03-05 17:07:54 +00:00
|
|
|
|
|
2023-06-19 13:56:06 +00:00
|
|
|
|
cardEffectEvent.isCancellOut = i == loopTimes
|
2023-05-28 10:45:54 +00:00
|
|
|
|
end
|
|
|
|
|
elseif
|
|
|
|
|
cardEffectEvent.card.type == Card.TypeTrick and
|
|
|
|
|
not (cardEffectEvent.disresponsive or cardEffectEvent.unoffsetable) and
|
2023-06-11 08:22:11 +00:00
|
|
|
|
not table.contains(cardEffectEvent.prohibitedCardNames or Util.DummyTable, "nullification")
|
2023-05-28 10:45:54 +00:00
|
|
|
|
then
|
|
|
|
|
local players = {}
|
2023-06-14 05:40:50 +00:00
|
|
|
|
Fk.currentResponsePattern = "nullification"
|
2024-01-29 02:19:10 +00:00
|
|
|
|
local cardCloned = Fk:cloneCard("nullification")
|
2023-05-28 10:45:54 +00:00
|
|
|
|
for _, p in ipairs(self.alive_players) do
|
2024-01-29 02:19:10 +00:00
|
|
|
|
if not p:prohibitUse(cardCloned) then
|
|
|
|
|
local cards = p:getHandlyIds()
|
|
|
|
|
for _, cid in ipairs(cards) do
|
2023-05-28 10:45:54 +00:00
|
|
|
|
if
|
2024-01-29 02:19:10 +00:00
|
|
|
|
Fk:getCardById(cid).trueName == "nullification" and
|
2023-05-28 10:45:54 +00:00
|
|
|
|
not (
|
2023-06-11 08:22:11 +00:00
|
|
|
|
table.contains(cardEffectEvent.disresponsiveList or Util.DummyTable, p.id) or
|
|
|
|
|
table.contains(cardEffectEvent.unoffsetableList or Util.DummyTable, p.id)
|
2023-05-28 10:45:54 +00:00
|
|
|
|
)
|
|
|
|
|
then
|
2022-12-18 13:19:35 +00:00
|
|
|
|
table.insert(players, p)
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-01-29 02:19:10 +00:00
|
|
|
|
if not table.contains(players, p) then
|
|
|
|
|
Self = p -- for enabledAtResponse
|
|
|
|
|
for _, s in ipairs(table.connect(p.player_skills, p._fake_skills)) do
|
|
|
|
|
if
|
|
|
|
|
s.pattern and
|
|
|
|
|
Exppattern:Parse("nullification"):matchExp(s.pattern) and
|
|
|
|
|
not (s.enabledAtResponse and not s:enabledAtResponse(p)) and
|
|
|
|
|
not (
|
|
|
|
|
table.contains(cardEffectEvent.disresponsiveList or Util.DummyTable, p.id) or
|
|
|
|
|
table.contains(cardEffectEvent.unoffsetableList or Util.DummyTable, p.id)
|
|
|
|
|
)
|
|
|
|
|
then
|
|
|
|
|
table.insert(players, p)
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-12-18 13:19:35 +00:00
|
|
|
|
end
|
2022-12-18 04:52:52 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-05-28 10:45:54 +00:00
|
|
|
|
local prompt = ""
|
|
|
|
|
if cardEffectEvent.to then
|
|
|
|
|
prompt = "#AskForNullification::" .. cardEffectEvent.to .. ":" .. cardEffectEvent.card.name
|
|
|
|
|
elseif cardEffectEvent.from then
|
|
|
|
|
prompt = "#AskForNullificationWithoutTo:" .. cardEffectEvent.from .. "::" .. cardEffectEvent.card.name
|
2022-12-18 04:52:52 +00:00
|
|
|
|
end
|
2023-07-16 11:18:43 +00:00
|
|
|
|
|
|
|
|
|
local extra_data
|
|
|
|
|
if #TargetGroup:getRealTargets(cardEffectEvent.tos) > 1 then
|
|
|
|
|
local parentUseEvent = self.logic:getCurrentEvent():findParent(GameEvent.UseCard)
|
|
|
|
|
if parentUseEvent then
|
|
|
|
|
extra_data = { useEventId = parentUseEvent.id, effectTo = cardEffectEvent.to }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
local use = self:askForNullification(players, nil, nil, prompt, true, extra_data)
|
2023-05-28 10:45:54 +00:00
|
|
|
|
if use then
|
|
|
|
|
use.toCard = cardEffectEvent.card
|
|
|
|
|
use.responseToEvent = cardEffectEvent
|
|
|
|
|
self:useCard(use)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-06-17 02:45:53 +00:00
|
|
|
|
Fk.currentResponsePattern = nil
|
2023-05-28 10:45:54 +00:00
|
|
|
|
elseif event == fk.CardEffecting then
|
|
|
|
|
if cardEffectEvent.card.skill then
|
|
|
|
|
execGameEvent(GameEvent.SkillEffect, function ()
|
|
|
|
|
cardEffectEvent.card.skill:onEffect(self, cardEffectEvent)
|
2023-06-08 17:10:16 +00:00
|
|
|
|
end, self:getPlayerById(cardEffectEvent.from), cardEffectEvent.card.skill)
|
2022-12-18 04:52:52 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 对“打出牌”进行处理
|
2022-12-20 13:15:49 +00:00
|
|
|
|
---@param cardResponseEvent CardResponseEvent
|
|
|
|
|
function Room:responseCard(cardResponseEvent)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
return execGameEvent(GameEvent.RespondCard, cardResponseEvent)
|
2022-12-20 13:15:49 +00:00
|
|
|
|
end
|
2023-03-29 15:27:11 +00:00
|
|
|
|
|
2023-04-13 12:17:39 +00:00
|
|
|
|
---@param card_name string @ 想要视为使用的牌名
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param subcards? integer[] @ 子卡,可以留空或者直接nil
|
2023-04-13 12:17:39 +00:00
|
|
|
|
---@param from ServerPlayer @ 使用来源
|
|
|
|
|
---@param tos ServerPlayer | ServerPlayer[] @ 目标角色(列表)
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param skillName? string @ 技能名
|
|
|
|
|
---@param extra? boolean @ 是否不计入次数
|
2023-04-13 12:17:39 +00:00
|
|
|
|
function Room:useVirtualCard(card_name, subcards, from, tos, skillName, extra)
|
|
|
|
|
local card = Fk:cloneCard(card_name)
|
|
|
|
|
card.skillName = skillName
|
|
|
|
|
|
|
|
|
|
if from:prohibitUse(card) then return false end
|
|
|
|
|
|
|
|
|
|
if tos.class then tos = { tos } end
|
|
|
|
|
for i, p in ipairs(tos) do
|
|
|
|
|
if from:isProhibited(p, card) then
|
|
|
|
|
table.remove(tos, i)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if #tos == 0 then return false end
|
|
|
|
|
|
|
|
|
|
if subcards then card:addSubcards(Card:getIdList(subcards)) end
|
|
|
|
|
|
|
|
|
|
local use = {} ---@type CardUseStruct
|
|
|
|
|
use.from = from.id
|
|
|
|
|
use.tos = table.map(tos, function(p) return { p.id } end)
|
|
|
|
|
use.card = card
|
|
|
|
|
use.extraUse = extra
|
|
|
|
|
self:useCard(use)
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- 移动牌
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
2022-09-14 05:01:10 +00:00
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 传入一系列移牌信息,去实际移动这些牌
|
2022-09-15 03:17:13 +00:00
|
|
|
|
---@vararg CardsMoveInfo
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@return boolean?
|
2022-09-15 03:17:13 +00:00
|
|
|
|
function Room:moveCards(...)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
return execGameEvent(GameEvent.MoveCards, ...)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 让一名玩家获得一张牌
|
|
|
|
|
---@param player integer|ServerPlayer @ 要拿牌的玩家
|
2024-02-04 07:55:44 +00:00
|
|
|
|
---@param cid integer|Card|integer[] @ 要拿到的卡牌
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param unhide? boolean @ 是否明着拿
|
|
|
|
|
---@param reason? CardMoveReason @ 卡牌移动的原因
|
2024-02-04 07:30:27 +00:00
|
|
|
|
---@param proposer? integer @ 移动操作者的id
|
|
|
|
|
function Room:obtainCard(player, cid, unhide, reason, proposer)
|
2023-01-21 16:49:11 +00:00
|
|
|
|
if type(cid) ~= "number" then
|
2024-02-26 18:27:59 +00:00
|
|
|
|
assert(cid and type(cid) == "table")
|
2024-04-01 16:56:04 +00:00
|
|
|
|
if cid[1] == nil then
|
2024-02-26 18:27:59 +00:00
|
|
|
|
cid = cid:isVirtual() and cid.subcards or {cid.id}
|
|
|
|
|
end
|
2023-01-21 16:49:11 +00:00
|
|
|
|
else
|
|
|
|
|
cid = {cid}
|
|
|
|
|
end
|
|
|
|
|
if #cid == 0 then return end
|
2023-03-18 07:34:42 +00:00
|
|
|
|
|
|
|
|
|
if type(player) == "table" then
|
|
|
|
|
player = player.id
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
self:moveCards({
|
2023-01-21 16:49:11 +00:00
|
|
|
|
ids = cid,
|
2023-01-29 10:11:41 +00:00
|
|
|
|
from = self.owner_map[cid[1]],
|
2022-09-15 03:17:13 +00:00
|
|
|
|
to = player,
|
|
|
|
|
toArea = Card.PlayerHand,
|
|
|
|
|
moveReason = reason or fk.ReasonJustMove,
|
2024-02-04 07:30:27 +00:00
|
|
|
|
proposer = proposer or player,
|
2022-09-15 03:17:13 +00:00
|
|
|
|
moveVisible = unhide or false,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 让玩家摸牌
|
|
|
|
|
---@param player ServerPlayer @ 摸牌的玩家
|
|
|
|
|
---@param num integer @ 摸牌数
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param skillName? string @ 技能名
|
|
|
|
|
---@param fromPlace? string @ 摸牌的位置,"top" 或者 "bottom"
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@return integer[] @ 摸到的牌
|
2022-09-15 03:17:13 +00:00
|
|
|
|
function Room:drawCards(player, num, skillName, fromPlace)
|
2023-05-13 06:20:34 +00:00
|
|
|
|
local drawData = {
|
|
|
|
|
who = player,
|
|
|
|
|
num = num,
|
|
|
|
|
skillName = skillName,
|
|
|
|
|
fromPlace = fromPlace,
|
|
|
|
|
}
|
2023-08-03 07:26:52 +00:00
|
|
|
|
if self.logic:trigger(fk.BeforeDrawCard, player, drawData) then
|
2023-07-16 07:29:20 +00:00
|
|
|
|
self.logic:breakEvent(false)
|
|
|
|
|
end
|
2023-05-13 06:20:34 +00:00
|
|
|
|
|
|
|
|
|
num = drawData.num
|
|
|
|
|
fromPlace = drawData.fromPlace
|
2023-09-30 03:51:17 +00:00
|
|
|
|
player = drawData.who
|
2023-05-13 06:20:34 +00:00
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
local topCards = self:getNCards(num, fromPlace)
|
|
|
|
|
self:moveCards({
|
|
|
|
|
ids = topCards,
|
|
|
|
|
to = player.id,
|
|
|
|
|
toArea = Card.PlayerHand,
|
|
|
|
|
moveReason = fk.ReasonDraw,
|
|
|
|
|
proposer = player.id,
|
|
|
|
|
skillName = skillName,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return { table.unpack(topCards) }
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 将一张或多张牌移动到某处
|
2023-12-09 13:57:47 +00:00
|
|
|
|
---@param card integer | integer[] | Card | Card[] @ 要移动的牌
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@param to_place integer @ 移动的目标位置
|
2023-12-09 13:57:47 +00:00
|
|
|
|
---@param target? ServerPlayer @ 移动的目标角色
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param reason? integer @ 移动时使用的移牌原因
|
|
|
|
|
---@param skill_name? string @ 技能名
|
|
|
|
|
---@param special_name? string @ 私人牌堆名
|
|
|
|
|
---@param visible? boolean @ 是否明置
|
2023-12-09 13:57:47 +00:00
|
|
|
|
---@param proposer? integer @ 移动操作者的id
|
2023-08-02 13:50:47 +00:00
|
|
|
|
function Room:moveCardTo(card, to_place, target, reason, skill_name, special_name, visible, proposer)
|
2022-12-18 04:52:52 +00:00
|
|
|
|
reason = reason or fk.ReasonJustMove
|
|
|
|
|
skill_name = skill_name or ""
|
|
|
|
|
special_name = special_name or ""
|
2023-02-21 05:44:24 +00:00
|
|
|
|
local ids = Card:getIdList(card)
|
2022-12-18 04:52:52 +00:00
|
|
|
|
|
|
|
|
|
local to
|
|
|
|
|
if table.contains(
|
|
|
|
|
{Card.PlayerEquip, Card.PlayerHand,
|
2023-08-02 13:50:47 +00:00
|
|
|
|
Card.PlayerJudge, Card.PlayerSpecial}, to_place) then
|
2022-12-18 04:52:52 +00:00
|
|
|
|
to = target.id
|
|
|
|
|
end
|
|
|
|
|
|
2023-08-12 18:25:04 +00:00
|
|
|
|
local movesSplitedByOwner = {}
|
|
|
|
|
for _, cardId in ipairs(ids) do
|
|
|
|
|
local moveFound = table.find(movesSplitedByOwner, function(move)
|
|
|
|
|
return move.from == self.owner_map[cardId]
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
if moveFound then
|
|
|
|
|
table.insert(moveFound.ids, cardId)
|
|
|
|
|
else
|
|
|
|
|
table.insert(movesSplitedByOwner, {
|
|
|
|
|
ids = { cardId },
|
|
|
|
|
from = self.owner_map[cardId],
|
|
|
|
|
to = to,
|
|
|
|
|
toArea = to_place,
|
|
|
|
|
moveReason = reason,
|
|
|
|
|
skillName = skill_name,
|
|
|
|
|
specialName = special_name,
|
|
|
|
|
moveVisible = visible,
|
|
|
|
|
proposer = proposer,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self:moveCards(table.unpack(movesSplitedByOwner))
|
2022-12-18 04:52:52 +00:00
|
|
|
|
end
|
|
|
|
|
|
2024-02-17 01:48:42 +00:00
|
|
|
|
--- 将一些卡牌同时分配给一些角色。
|
|
|
|
|
---@param room Room @ 房间
|
|
|
|
|
---@param list table<integer[]> @ 分配牌和角色的数据表,键为角色id,值为分配给其的牌id数组
|
|
|
|
|
---@param proposer? integer @ 操作者的id。默认为空
|
|
|
|
|
---@param skillName? string @ 技能名。默认为“分配”
|
|
|
|
|
---@return table<integer[]> @ 返回成功分配的卡牌
|
|
|
|
|
function Room:doYiji(room, list, proposer, skillName)
|
|
|
|
|
skillName = skillName or "distribution_skill"
|
|
|
|
|
local moveInfos = {}
|
|
|
|
|
local move_ids = {}
|
|
|
|
|
for to, cards in pairs(list) do
|
|
|
|
|
local toP = room:getPlayerById(to)
|
|
|
|
|
local handcards = toP:getCardIds("h")
|
|
|
|
|
cards = table.filter(cards, function (id) return not table.contains(handcards, id) end)
|
|
|
|
|
if #cards > 0 then
|
|
|
|
|
table.insertTable(move_ids, cards)
|
|
|
|
|
local moveMap = {}
|
|
|
|
|
local noFrom = {}
|
|
|
|
|
for _, id in ipairs(cards) do
|
|
|
|
|
local from = room.owner_map[id]
|
|
|
|
|
if from then
|
|
|
|
|
moveMap[from] = moveMap[from] or {}
|
|
|
|
|
table.insert(moveMap[from], id)
|
|
|
|
|
else
|
|
|
|
|
table.insert(noFrom, id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
for from, _cards in pairs(moveMap) do
|
|
|
|
|
table.insert(moveInfos, {
|
|
|
|
|
ids = _cards,
|
|
|
|
|
moveInfo = table.map(_cards, function(id)
|
|
|
|
|
return {cardId = id, fromArea = room:getCardArea(id), fromSpecialName = room:getPlayerById(from):getPileNameOfId(id)}
|
|
|
|
|
end),
|
|
|
|
|
from = from,
|
|
|
|
|
to = to,
|
|
|
|
|
toArea = Card.PlayerHand,
|
|
|
|
|
moveReason = fk.ReasonGive,
|
|
|
|
|
proposer = proposer,
|
|
|
|
|
skillName = skillName,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
if #noFrom > 0 then
|
|
|
|
|
table.insert(moveInfos, {
|
|
|
|
|
ids = noFrom,
|
|
|
|
|
to = to,
|
|
|
|
|
toArea = Card.PlayerHand,
|
|
|
|
|
moveReason = fk.ReasonGive,
|
|
|
|
|
proposer = proposer,
|
|
|
|
|
skillName = skillName,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if #moveInfos > 0 then
|
|
|
|
|
room:moveCards(table.unpack(moveInfos))
|
|
|
|
|
end
|
|
|
|
|
return move_ids
|
|
|
|
|
end
|
|
|
|
|
|
2024-02-26 18:27:59 +00:00
|
|
|
|
--- 将一张牌移动至某角色的装备区,若不合法则置入弃牌堆。目前没做相同副类别装备同时置入的适配(甘露神典韦)
|
|
|
|
|
---@param target ServerPlayer @ 接受牌的角色
|
|
|
|
|
---@param cards integer|integer[] @ 移动的牌
|
|
|
|
|
---@param skillName? string @ 技能名
|
|
|
|
|
---@param convert? boolean @ 是否可以替换装备(默认可以)
|
|
|
|
|
---@param proposer? ServerPlayer @ 操作者
|
|
|
|
|
function Room:moveCardIntoEquip(target, cards, skillName, convert, proposer)
|
|
|
|
|
convert = (convert == nil) and true or convert
|
|
|
|
|
skillName = skillName or ""
|
|
|
|
|
cards = type(cards) == "table" and cards or {cards}
|
|
|
|
|
local moves = {}
|
|
|
|
|
for _, cardId in ipairs(cards) do
|
|
|
|
|
local card = Fk:getCardById(cardId)
|
|
|
|
|
local fromId = self.owner_map[cardId]
|
|
|
|
|
local proposerId = proposer and proposer.id or nil
|
|
|
|
|
if target:canMoveCardIntoEquip(cardId, convert) then
|
|
|
|
|
if target:hasEmptyEquipSlot(card.sub_type) then
|
|
|
|
|
table.insert(moves,{ids = {cardId}, from = fromId, to = target.id, toArea = Card.PlayerEquip, moveReason = fk.ReasonPut,skillName = skillName,proposer = proposerId})
|
|
|
|
|
else
|
|
|
|
|
local existingEquip = target:getEquipments(card.sub_type)
|
|
|
|
|
local throw = #existingEquip == 1 and existingEquip[1] or
|
|
|
|
|
self:askForCardChosen(proposer or target, target, {card_data = { {Util.convertSubtypeAndEquipSlot(card.sub_type),existingEquip} } }, "replaceEquip","#replaceEquip")
|
|
|
|
|
table.insert(moves,{ids = {throw}, from = target.id, toArea = Card.DiscardPile, moveReason = fk.ReasonPutIntoDiscardPile, skillName = skillName,proposer = proposerId})
|
|
|
|
|
table.insert(moves,{ids = {cardId}, from = fromId, to = target.id, toArea = Card.PlayerEquip, moveReason = fk.ReasonPut,skillName = skillName,proposer = proposerId})
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
table.insert(moves,{ids = {cardId}, from = fromId, toArea = Card.DiscardPile, moveReason = fk.ReasonPutIntoDiscardPile,skillName = skillName})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self:moveCards(table.unpack(moves))
|
|
|
|
|
end
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- 其他游戏事件
|
2022-09-15 03:17:13 +00:00
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- 与体力值等有关的事件
|
2022-09-15 03:17:13 +00:00
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 改变一名玩家的体力。
|
|
|
|
|
---@param player ServerPlayer @ 玩家
|
|
|
|
|
---@param num integer @ 变化量
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param reason? string @ 原因
|
|
|
|
|
---@param skillName? string @ 技能名
|
|
|
|
|
---@param damageStruct? DamageStruct @ 伤害数据
|
2022-09-15 03:17:13 +00:00
|
|
|
|
---@return boolean
|
|
|
|
|
function Room:changeHp(player, num, reason, skillName, damageStruct)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
return execGameEvent(GameEvent.ChangeHp, player, num, reason, skillName, damageStruct)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-04-13 12:17:39 +00:00
|
|
|
|
--- 改变玩家的护甲数
|
|
|
|
|
---@param player ServerPlayer
|
|
|
|
|
---@param num integer @ 变化量
|
|
|
|
|
function Room:changeShield(player, num)
|
|
|
|
|
if num == 0 then return end
|
|
|
|
|
player.shield = math.max(player.shield + num, 0)
|
|
|
|
|
player.shield = math.min(player.shield, 5)
|
|
|
|
|
self:broadcastProperty(player, "shield")
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 令一名玩家失去体力。
|
|
|
|
|
---@param player ServerPlayer @ 玩家
|
|
|
|
|
---@param num integer @ 失去的数量
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param skillName? string @ 技能名
|
2022-09-15 03:17:13 +00:00
|
|
|
|
---@return boolean
|
|
|
|
|
function Room:loseHp(player, num, skillName)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
return execGameEvent(GameEvent.LoseHp, player, num, skillName)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 改变一名玩家的体力上限。
|
|
|
|
|
---@param player ServerPlayer @ 玩家
|
|
|
|
|
---@param num integer @ 变化量
|
2022-09-15 03:17:13 +00:00
|
|
|
|
---@return boolean
|
|
|
|
|
function Room:changeMaxHp(player, num)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
return execGameEvent(GameEvent.ChangeMaxHp, player, num)
|
2022-09-14 05:01:10 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 根据伤害数据造成伤害。
|
2022-09-15 03:17:13 +00:00
|
|
|
|
---@param damageStruct DamageStruct
|
|
|
|
|
---@return boolean
|
|
|
|
|
function Room:damage(damageStruct)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
return execGameEvent(GameEvent.Damage, damageStruct)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 根据回复数据回复体力。
|
2022-09-15 03:17:13 +00:00
|
|
|
|
---@param recoverStruct RecoverStruct
|
|
|
|
|
---@return boolean
|
|
|
|
|
function Room:recover(recoverStruct)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
return execGameEvent(GameEvent.Recover, recoverStruct)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 根据濒死数据让人进入濒死。
|
2022-09-15 03:17:13 +00:00
|
|
|
|
---@param dyingStruct DyingStruct
|
|
|
|
|
function Room:enterDying(dyingStruct)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
return execGameEvent(GameEvent.Dying, dyingStruct)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 根据死亡数据杀死角色。
|
2022-09-15 03:17:13 +00:00
|
|
|
|
---@param deathStruct DeathStruct
|
|
|
|
|
function Room:killPlayer(deathStruct)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
return execGameEvent(GameEvent.Death, deathStruct)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- 与失去/获得技能有关的事件
|
2022-09-15 03:17:13 +00:00
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 令一名玩家获得/失去技能。
|
|
|
|
|
---
|
|
|
|
|
--- skill_names 是字符串数组或者用管道符号(|)分割的字符串。
|
|
|
|
|
---
|
|
|
|
|
--- 每个skill_name都是要获得的技能的名。如果在skill_name前面加上"-",那就是失去技能。
|
|
|
|
|
---@param player ServerPlayer @ 玩家
|
|
|
|
|
---@param skill_names string[] | string @ 要获得/失去的技能
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param source_skill? string | Skill @ 源技能
|
|
|
|
|
---@param no_trigger? boolean @ 是否不触发相关时机
|
2023-02-15 13:20:40 +00:00
|
|
|
|
function Room:handleAddLoseSkills(player, skill_names, source_skill, sendlog, no_trigger)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
if type(skill_names) == "string" then
|
|
|
|
|
skill_names = skill_names:split("|")
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-18 04:52:52 +00:00
|
|
|
|
if sendlog == nil then sendlog = true end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
if #skill_names == 0 then return end
|
|
|
|
|
local losts = {} ---@type boolean[]
|
|
|
|
|
local triggers = {} ---@type Skill[]
|
2024-02-04 07:55:44 +00:00
|
|
|
|
local lost_piles = {} ---@type integer[]
|
2022-09-15 03:17:13 +00:00
|
|
|
|
for _, skill in ipairs(skill_names) do
|
|
|
|
|
if string.sub(skill, 1, 1) == "-" then
|
|
|
|
|
local actual_skill = string.sub(skill, 2, #skill)
|
2023-03-20 12:49:23 +00:00
|
|
|
|
if player:hasSkill(actual_skill, true, true) then
|
2022-09-15 03:17:13 +00:00
|
|
|
|
local lost_skills = player:loseSkill(actual_skill, source_skill)
|
|
|
|
|
for _, s in ipairs(lost_skills) do
|
|
|
|
|
self:doBroadcastNotify("LoseSkill", json.encode{
|
|
|
|
|
player.id,
|
|
|
|
|
s.name
|
|
|
|
|
})
|
2022-12-18 04:52:52 +00:00
|
|
|
|
|
2023-03-18 15:37:21 +00:00
|
|
|
|
if sendlog and s.visible then
|
2022-12-18 04:52:52 +00:00
|
|
|
|
self:sendLog{
|
|
|
|
|
type = "#LoseSkill",
|
|
|
|
|
from = player.id,
|
|
|
|
|
arg = s.name
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
table.insert(losts, true)
|
|
|
|
|
table.insert(triggers, s)
|
2024-02-04 07:55:44 +00:00
|
|
|
|
if s.derived_piles then
|
|
|
|
|
for _, pile_name in ipairs(s.derived_piles) do
|
|
|
|
|
table.insertTableIfNeed(lost_piles, player:getPile(pile_name))
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
local sk = Fk.skills[skill]
|
2023-03-20 12:49:23 +00:00
|
|
|
|
if sk and not player:hasSkill(sk, true, true) then
|
2024-02-04 07:55:44 +00:00
|
|
|
|
local got_skills = player:addSkill(sk, source_skill)
|
2022-09-15 03:17:13 +00:00
|
|
|
|
|
|
|
|
|
for _, s in ipairs(got_skills) do
|
|
|
|
|
-- TODO: limit skill mark
|
|
|
|
|
|
|
|
|
|
self:doBroadcastNotify("AddSkill", json.encode{
|
|
|
|
|
player.id,
|
|
|
|
|
s.name
|
|
|
|
|
})
|
2022-12-18 04:52:52 +00:00
|
|
|
|
|
2023-03-18 15:37:21 +00:00
|
|
|
|
if sendlog and s.visible then
|
2022-12-18 04:52:52 +00:00
|
|
|
|
self:sendLog{
|
|
|
|
|
type = "#AcquireSkill",
|
|
|
|
|
from = player.id,
|
|
|
|
|
arg = s.name
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
table.insert(losts, false)
|
|
|
|
|
table.insert(triggers, s)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-02-15 13:20:40 +00:00
|
|
|
|
if (not no_trigger) and #triggers > 0 then
|
2022-09-15 03:17:13 +00:00
|
|
|
|
for i = 1, #triggers do
|
|
|
|
|
local event = losts[i] and fk.EventLoseSkill or fk.EventAcquireSkill
|
|
|
|
|
self.logic:trigger(event, player, triggers[i])
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-02-04 07:55:44 +00:00
|
|
|
|
|
|
|
|
|
if #lost_piles > 0 then
|
|
|
|
|
self:moveCards({
|
|
|
|
|
ids = lost_piles,
|
|
|
|
|
from = player.id,
|
|
|
|
|
toArea = Card.DiscardPile,
|
|
|
|
|
moveReason = fk.ReasonPutIntoDiscardPile,
|
|
|
|
|
})
|
|
|
|
|
end
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- 判定
|
2022-12-18 04:52:52 +00:00
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 根据判定数据进行判定。判定的结果直接保存在这个数据中。
|
2023-01-21 16:49:11 +00:00
|
|
|
|
---@param data JudgeStruct
|
2022-12-18 04:52:52 +00:00
|
|
|
|
function Room:judge(data)
|
2023-02-28 17:43:44 +00:00
|
|
|
|
return execGameEvent(GameEvent.Judge, data)
|
2022-12-18 04:52:52 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 改判。
|
|
|
|
|
---@param card Card @ 改判的牌
|
|
|
|
|
---@param player ServerPlayer @ 改判的玩家
|
|
|
|
|
---@param judge JudgeStruct @ 要被改判的判定数据
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param skillName? string @ 技能名
|
|
|
|
|
---@param exchange? boolean @ 是否要替换原有判定牌(即类似鬼道那样)
|
2023-01-29 10:11:41 +00:00
|
|
|
|
function Room:retrial(card, player, judge, skillName, exchange)
|
|
|
|
|
if not card then return end
|
|
|
|
|
local triggerResponded = self.owner_map[card:getEffectiveId()] == player
|
|
|
|
|
local isHandcard = (triggerResponded and self:getCardArea(card:getEffectiveId()) == Card.PlayerHand)
|
|
|
|
|
|
|
|
|
|
if triggerResponded then
|
2023-12-10 10:56:50 +00:00
|
|
|
|
local resp = {} ---@type CardResponseEvent
|
|
|
|
|
resp.from = player.id
|
|
|
|
|
resp.card = card
|
|
|
|
|
resp.skipDrop = true
|
|
|
|
|
self:responseCard(resp)
|
|
|
|
|
else
|
|
|
|
|
local move1 = {} ---@type CardsMoveInfo
|
|
|
|
|
move1.ids = { card:getEffectiveId() }
|
|
|
|
|
move1.from = player.id
|
|
|
|
|
move1.toArea = Card.Processing
|
|
|
|
|
move1.moveReason = fk.ReasonJustMove
|
|
|
|
|
move1.skillName = skillName
|
|
|
|
|
self:moveCards(move1)
|
2023-01-29 10:11:41 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-12-10 10:56:50 +00:00
|
|
|
|
local oldJudge = judge.card
|
|
|
|
|
judge.card = card
|
|
|
|
|
local rebyre = judge.retrial_by_response
|
|
|
|
|
judge.retrial_by_response = player
|
2023-01-29 10:11:41 +00:00
|
|
|
|
|
|
|
|
|
self:sendLog{
|
|
|
|
|
type = "#ChangedJudge",
|
|
|
|
|
from = player.id,
|
|
|
|
|
to = { judge.who.id },
|
2023-12-10 10:56:50 +00:00
|
|
|
|
arg2 = card:toLogString(),
|
2023-01-29 10:11:41 +00:00
|
|
|
|
arg = skillName,
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-12 13:20:35 +00:00
|
|
|
|
Fk:filterCard(judge.card.id, judge.who, judge)
|
2024-01-29 02:19:10 +00:00
|
|
|
|
|
|
|
|
|
exchange = exchange and not player.dead
|
|
|
|
|
|
|
|
|
|
local move2 = {} ---@type CardsMoveInfo
|
|
|
|
|
move2.ids = { oldJudge:getEffectiveId() }
|
|
|
|
|
move2.toArea = exchange and Card.PlayerHand or Card.DiscardPile
|
|
|
|
|
move2.moveReason = exchange and fk.ReasonJustMove or fk.ReasonJudge
|
|
|
|
|
move2.to = exchange and player.id or nil
|
|
|
|
|
move2.skillName = skillName
|
|
|
|
|
|
|
|
|
|
self:moveCards(move2)
|
2023-01-29 10:11:41 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-05-13 05:23:18 +00:00
|
|
|
|
--- 弃置一名角色的牌。
|
2024-02-04 07:55:44 +00:00
|
|
|
|
---@param card_ids integer[]|integer @ 被弃掉的牌
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param skillName? string @ 技能名
|
2023-03-29 15:27:11 +00:00
|
|
|
|
---@param who ServerPlayer @ 被弃牌的人
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param thrower? ServerPlayer @ 弃别人牌的人
|
2022-12-20 04:51:54 +00:00
|
|
|
|
function Room:throwCard(card_ids, skillName, who, thrower)
|
|
|
|
|
if type(card_ids) == "number" then
|
|
|
|
|
card_ids = {card_ids}
|
|
|
|
|
end
|
|
|
|
|
skillName = skillName or ""
|
|
|
|
|
thrower = thrower or who
|
|
|
|
|
self:moveCards({
|
|
|
|
|
ids = card_ids,
|
|
|
|
|
from = who.id,
|
|
|
|
|
toArea = Card.DiscardPile,
|
|
|
|
|
moveReason = fk.ReasonDiscard,
|
|
|
|
|
proposer = thrower.id,
|
|
|
|
|
skillName = skillName
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-13 05:23:18 +00:00
|
|
|
|
--- 重铸一名角色的牌。
|
|
|
|
|
---@param card_ids integer[] @ 被重铸的牌
|
|
|
|
|
---@param who ServerPlayer @ 重铸的角色
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param skillName? string @ 技能名,默认为“重铸”
|
2023-12-06 13:08:56 +00:00
|
|
|
|
---@return integer[] @ 摸到的牌
|
2023-05-13 05:23:18 +00:00
|
|
|
|
function Room:recastCard(card_ids, who, skillName)
|
|
|
|
|
if type(card_ids) == "number" then
|
|
|
|
|
card_ids = {card_ids}
|
|
|
|
|
end
|
|
|
|
|
skillName = skillName or "recast"
|
|
|
|
|
self:moveCards({
|
|
|
|
|
ids = card_ids,
|
|
|
|
|
from = who.id,
|
|
|
|
|
toArea = Card.DiscardPile,
|
|
|
|
|
skillName = skillName,
|
2023-12-06 13:08:56 +00:00
|
|
|
|
moveReason = fk.ReasonRecast,
|
2023-05-13 05:23:18 +00:00
|
|
|
|
proposer = who.id
|
|
|
|
|
})
|
2023-10-06 19:22:57 +00:00
|
|
|
|
self:broadcastPlaySound("./audio/system/recast")
|
2023-05-13 05:23:18 +00:00
|
|
|
|
self:sendLog{
|
|
|
|
|
type = skillName == "recast" and "#Recast" or "#RecastBySkill",
|
|
|
|
|
from = who.id,
|
|
|
|
|
card = card_ids,
|
|
|
|
|
arg = skillName,
|
|
|
|
|
}
|
2023-12-06 13:08:56 +00:00
|
|
|
|
return self:drawCards(who, #card_ids, skillName)
|
2023-05-13 05:23:18 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 根据拼点信息开始拼点。
|
2023-03-14 12:48:08 +00:00
|
|
|
|
---@param pindianData PindianStruct
|
|
|
|
|
function Room:pindian(pindianData)
|
|
|
|
|
return execGameEvent(GameEvent.Pindian, pindianData)
|
2023-02-21 05:44:24 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-04-12 12:51:09 +00:00
|
|
|
|
-- 杂项函数
|
2022-09-15 03:17:13 +00:00
|
|
|
|
|
|
|
|
|
function Room:adjustSeats()
|
|
|
|
|
local players = {}
|
|
|
|
|
local p = 0
|
|
|
|
|
|
|
|
|
|
for i = 1, #self.players do
|
|
|
|
|
if self.players[i].role == "lord" then
|
|
|
|
|
p = i
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
for j = p, #self.players do
|
|
|
|
|
table.insert(players, self.players[j])
|
|
|
|
|
end
|
|
|
|
|
for j = 1, p - 1 do
|
|
|
|
|
table.insert(players, self.players[j])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self.players = players
|
|
|
|
|
|
|
|
|
|
local player_circle = {}
|
|
|
|
|
for i = 1, #self.players do
|
|
|
|
|
self.players[i].seat = i
|
|
|
|
|
table.insert(player_circle, self.players[i].id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self:doBroadcastNotify("ArrangeSeats", json.encode(player_circle))
|
|
|
|
|
end
|
|
|
|
|
|
2023-04-27 06:15:08 +00:00
|
|
|
|
---@param a ServerPlayer
|
|
|
|
|
---@param b ServerPlayer
|
|
|
|
|
function Room:swapSeat(a, b)
|
|
|
|
|
local ai, bi
|
|
|
|
|
local players = self.players
|
|
|
|
|
for i, v in ipairs(self.players) do
|
|
|
|
|
if v == a then ai = i end
|
|
|
|
|
if v == b then bi = i end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
players[ai] = b
|
|
|
|
|
players[bi] = a
|
|
|
|
|
a.seat, b.seat = b.seat, a.seat
|
|
|
|
|
|
|
|
|
|
local player_circle = {}
|
|
|
|
|
for _, v in ipairs(players) do
|
|
|
|
|
table.insert(player_circle, v.id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
for i = 1, #players - 1 do
|
|
|
|
|
players[i].next = players[i + 1]
|
|
|
|
|
end
|
|
|
|
|
players[#players].next = players[1]
|
|
|
|
|
|
|
|
|
|
self:doBroadcastNotify("ArrangeSeats", json.encode(player_circle))
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 洗牌。
|
2022-09-15 03:17:13 +00:00
|
|
|
|
function Room:shuffleDrawPile()
|
|
|
|
|
if #self.draw_pile + #self.discard_pile == 0 then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
table.insertTable(self.draw_pile, self.discard_pile)
|
|
|
|
|
for _, id in ipairs(self.discard_pile) do
|
|
|
|
|
self:setCardArea(id, Card.DrawPile, nil)
|
|
|
|
|
end
|
|
|
|
|
self.discard_pile = {}
|
|
|
|
|
table.shuffle(self.draw_pile)
|
2023-05-13 06:20:34 +00:00
|
|
|
|
|
2024-01-24 19:13:57 +00:00
|
|
|
|
self:doBroadcastNotify("UpdateDrawPile", #self.draw_pile)
|
|
|
|
|
|
2023-05-13 06:20:34 +00:00
|
|
|
|
self.logic:trigger(fk.AfterDrawPileShuffle, nil, {})
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 使用技能。先增加技能发动次数,再执行相应的函数。
|
|
|
|
|
---@param player ServerPlayer @ 发动技能的玩家
|
|
|
|
|
---@param skill Skill @ 发动的技能
|
|
|
|
|
---@param effect_cb fun() @ 实际要调用的函数
|
2023-02-21 05:44:24 +00:00
|
|
|
|
function Room:useSkill(player, skill, effect_cb)
|
2023-04-23 13:10:07 +00:00
|
|
|
|
player:revealBySkillName(skill.name)
|
2023-02-21 05:44:24 +00:00
|
|
|
|
if not skill.mute then
|
|
|
|
|
if skill.attached_equip then
|
2023-12-09 13:57:47 +00:00
|
|
|
|
local equip = Fk.all_card_types[skill.attached_equip]
|
2023-02-21 05:44:24 +00:00
|
|
|
|
local pkgPath = "./packages/" .. equip.package.extensionName
|
|
|
|
|
local soundName = pkgPath .. "/audio/card/" .. equip.name
|
|
|
|
|
self:broadcastPlaySound(soundName)
|
2023-12-09 13:57:47 +00:00
|
|
|
|
self:sendLog{
|
|
|
|
|
type = "#InvokeSkill",
|
|
|
|
|
from = player.id,
|
|
|
|
|
arg = skill.name,
|
|
|
|
|
}
|
2023-02-21 05:44:24 +00:00
|
|
|
|
self:setEmotion(player, pkgPath .. "/image/anim/" .. equip.name)
|
|
|
|
|
else
|
2023-08-24 13:37:24 +00:00
|
|
|
|
player:broadcastSkillInvoke(skill.name)
|
2023-02-21 05:44:24 +00:00
|
|
|
|
self:notifySkillInvoked(player, skill.name)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-05-13 06:20:34 +00:00
|
|
|
|
|
|
|
|
|
if skill:isSwitchSkill() then
|
|
|
|
|
local switchSkillName = skill.switchSkillName
|
|
|
|
|
self:setPlayerMark(
|
|
|
|
|
player,
|
|
|
|
|
MarkEnum.SwithSkillPreName .. switchSkillName,
|
|
|
|
|
player:getSwitchSkillState(switchSkillName, true)
|
|
|
|
|
)
|
|
|
|
|
end
|
2023-04-30 10:55:59 +00:00
|
|
|
|
|
2023-02-21 05:44:24 +00:00
|
|
|
|
if effect_cb then
|
2023-06-08 17:10:16 +00:00
|
|
|
|
return execGameEvent(GameEvent.SkillEffect, effect_cb, player, skill)
|
2023-02-21 05:44:24 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-06-09 18:18:51 +00:00
|
|
|
|
---@param player ServerPlayer
|
2023-12-10 10:55:16 +00:00
|
|
|
|
---@param sendLog? bool
|
|
|
|
|
function Room:revivePlayer(player, sendLog, reason)
|
|
|
|
|
return execGameEvent(GameEvent.Revive, player, sendLog, reason)
|
2023-06-09 18:18:51 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-05-13 06:45:23 +00:00
|
|
|
|
---@param room Room
|
|
|
|
|
local function shouldUpdateWinRate(room)
|
2023-06-27 08:50:24 +00:00
|
|
|
|
if room.settings.enableFreeAssign then
|
|
|
|
|
return false
|
|
|
|
|
end
|
2023-06-30 20:12:19 +00:00
|
|
|
|
if os.time() - room.start_time < 45 then
|
|
|
|
|
return false
|
|
|
|
|
end
|
2023-05-13 06:45:23 +00:00
|
|
|
|
for _, p in ipairs(room.players) do
|
|
|
|
|
if p.id < 0 then return false end
|
|
|
|
|
end
|
2023-08-01 18:19:51 +00:00
|
|
|
|
return Fk.game_modes[room.settings.gameMode]:countInFunc(room)
|
2023-05-13 06:45:23 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-29 15:27:11 +00:00
|
|
|
|
--- 结束一局游戏。
|
|
|
|
|
---@param winner string @ 获胜的身份,空字符串表示平局
|
2022-12-20 04:51:54 +00:00
|
|
|
|
function Room:gameOver(winner)
|
2023-06-16 02:56:33 +00:00
|
|
|
|
if not self.game_started then return end
|
|
|
|
|
|
2024-02-17 01:47:17 +00:00
|
|
|
|
if table.contains(
|
|
|
|
|
{ "running", "normal" },
|
|
|
|
|
coroutine.status(self.main_co)
|
|
|
|
|
) then
|
|
|
|
|
self.logic:trigger(fk.GameFinished, nil, winner)
|
|
|
|
|
end
|
|
|
|
|
|
2023-02-15 16:54:39 +00:00
|
|
|
|
self.game_started = false
|
2022-09-15 03:17:13 +00:00
|
|
|
|
self.game_finished = true
|
2022-12-20 04:51:54 +00:00
|
|
|
|
|
|
|
|
|
for _, p in ipairs(self.players) do
|
|
|
|
|
self:broadcastProperty(p, "role")
|
|
|
|
|
end
|
|
|
|
|
self:doBroadcastNotify("GameOver", winner)
|
|
|
|
|
|
2023-05-13 06:45:23 +00:00
|
|
|
|
if shouldUpdateWinRate(self) then
|
|
|
|
|
for _, p in ipairs(self.players) do
|
|
|
|
|
local id = p.id
|
|
|
|
|
local general = p.general
|
|
|
|
|
local mode = self.settings.gameMode
|
|
|
|
|
|
|
|
|
|
if p.id > 0 then
|
|
|
|
|
if table.contains(winner:split("+"), p.role) then
|
2023-06-16 15:04:31 +00:00
|
|
|
|
self.room:updateWinRate(id, general, mode, 1, p.dead)
|
2023-05-13 06:45:23 +00:00
|
|
|
|
elseif winner == "" then
|
2023-06-16 15:04:31 +00:00
|
|
|
|
self.room:updateWinRate(id, general, mode, 3, p.dead)
|
2023-05-13 06:45:23 +00:00
|
|
|
|
else
|
2023-06-16 15:04:31 +00:00
|
|
|
|
self.room:updateWinRate(id, general, mode, 2, p.dead)
|
2023-05-13 06:45:23 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-15 03:17:13 +00:00
|
|
|
|
self.room:gameOver()
|
2023-06-16 02:56:33 +00:00
|
|
|
|
|
|
|
|
|
if table.contains(
|
|
|
|
|
{ "running", "normal" },
|
|
|
|
|
coroutine.status(self.main_co)
|
|
|
|
|
) then
|
|
|
|
|
coroutine.yield("__handleRequest", "over")
|
|
|
|
|
else
|
|
|
|
|
coroutine.close(self.main_co)
|
|
|
|
|
self.main_co = nil
|
|
|
|
|
end
|
2022-09-15 03:17:13 +00:00
|
|
|
|
end
|
|
|
|
|
|
2023-01-16 11:13:07 +00:00
|
|
|
|
---@param card Card
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param fromAreas? CardArea[]
|
2023-01-16 11:13:07 +00:00
|
|
|
|
---@return integer[]
|
|
|
|
|
function Room:getSubcardsByRule(card, fromAreas)
|
|
|
|
|
if card:isVirtual() and #card.subcards == 0 then
|
|
|
|
|
return {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local cardIds = {}
|
2023-06-11 08:22:11 +00:00
|
|
|
|
fromAreas = fromAreas or Util.DummyTable
|
2023-01-16 11:13:07 +00:00
|
|
|
|
for _, cardId in ipairs(card:isVirtual() and card.subcards or { card.id }) do
|
|
|
|
|
if #fromAreas == 0 or table.contains(fromAreas, self:getCardArea(cardId)) then
|
|
|
|
|
table.insert(cardIds, cardId)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return cardIds
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-13 06:20:34 +00:00
|
|
|
|
---@param pattern string
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param num? number
|
|
|
|
|
---@param fromPile? string @ 查找的来源区域,值为drawPile|discardPile|allPiles
|
|
|
|
|
---@return integer[] @ id列表 可能空
|
2023-05-13 07:03:35 +00:00
|
|
|
|
function Room:getCardsFromPileByRule(pattern, num, fromPile)
|
2023-05-13 06:20:34 +00:00
|
|
|
|
num = num or 1
|
2023-05-13 07:03:35 +00:00
|
|
|
|
local pileToSearch = self.draw_pile
|
|
|
|
|
if fromPile == "discardPile" then
|
|
|
|
|
pileToSearch = self.discard_pile
|
|
|
|
|
elseif fromPile == "allPiles" then
|
2023-07-02 12:39:42 +00:00
|
|
|
|
pileToSearch = table.simpleClone(self.draw_pile)
|
2023-05-13 07:03:35 +00:00
|
|
|
|
table.insertTable(pileToSearch, self.discard_pile)
|
|
|
|
|
end
|
2023-05-13 06:20:34 +00:00
|
|
|
|
|
2023-06-11 04:45:12 +00:00
|
|
|
|
if #pileToSearch == 0 then
|
|
|
|
|
return {}
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-13 06:20:34 +00:00
|
|
|
|
local cardPack = {}
|
|
|
|
|
if num < 3 then
|
|
|
|
|
for i = 1, num do
|
|
|
|
|
local randomIndex = math.random(1, #pileToSearch)
|
|
|
|
|
local curIndex = randomIndex
|
|
|
|
|
repeat
|
|
|
|
|
local curCardId = pileToSearch[curIndex]
|
|
|
|
|
if Fk:getCardById(curCardId):matchPattern(pattern) and not table.contains(cardPack, curCardId) then
|
|
|
|
|
table.insert(cardPack, pileToSearch[curIndex])
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
curIndex = curIndex + 1
|
|
|
|
|
if curIndex > #pileToSearch then
|
|
|
|
|
curIndex = 1
|
|
|
|
|
end
|
|
|
|
|
until curIndex == randomIndex
|
|
|
|
|
|
2023-06-04 11:39:20 +00:00
|
|
|
|
if #cardPack == 0 then
|
2023-05-13 06:20:34 +00:00
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
local matchedIds = {}
|
|
|
|
|
for _, id in ipairs(pileToSearch) do
|
|
|
|
|
if Fk:getCardById(id):matchPattern(pattern) then
|
|
|
|
|
table.insert(matchedIds, id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local loopTimes = math.min(num, #matchedIds)
|
|
|
|
|
for i = 1, loopTimes do
|
|
|
|
|
local randomCardId = matchedIds[math.random(1, #matchedIds)]
|
|
|
|
|
table.insert(cardPack, randomCardId)
|
|
|
|
|
table.removeOne(matchedIds, randomCardId)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return cardPack
|
|
|
|
|
end
|
|
|
|
|
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param flag? string
|
|
|
|
|
---@param players? ServerPlayer[]
|
|
|
|
|
---@param excludeIds? integer[]
|
|
|
|
|
---@return integer[] @ 玩家id列表 可能为空
|
2023-07-16 11:18:43 +00:00
|
|
|
|
function Room:canMoveCardInBoard(flag, players, excludeIds)
|
2023-05-28 10:45:54 +00:00
|
|
|
|
if flag then
|
|
|
|
|
assert(flag == "e" or flag == "j")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
players = players or self.alive_players
|
2023-07-16 11:18:43 +00:00
|
|
|
|
excludeIds = type(excludeIds) == "table" and excludeIds or {}
|
2023-05-28 10:45:54 +00:00
|
|
|
|
|
|
|
|
|
local targets = {}
|
|
|
|
|
table.find(players, function(p)
|
|
|
|
|
local canMoveTo = table.find(players, function(another)
|
2023-07-16 11:18:43 +00:00
|
|
|
|
return p ~= another and p:canMoveCardsInBoardTo(another, flag, excludeIds)
|
2023-05-28 10:45:54 +00:00
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
if canMoveTo then
|
|
|
|
|
targets = {p.id, canMoveTo.id}
|
|
|
|
|
end
|
|
|
|
|
return canMoveTo
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
return targets
|
|
|
|
|
end
|
|
|
|
|
|
2023-08-10 19:19:59 +00:00
|
|
|
|
--- 现场印卡。当然了,这个卡只和这个房间有关。
|
|
|
|
|
---@param name string @ 牌名
|
2023-12-03 11:35:14 +00:00
|
|
|
|
---@param suit? Suit @ 花色
|
|
|
|
|
---@param number? integer @ 点数
|
2023-08-10 19:19:59 +00:00
|
|
|
|
---@return Card
|
|
|
|
|
function Room:printCard(name, suit, number)
|
|
|
|
|
local cd = Fk:cloneCard(name, suit, number)
|
|
|
|
|
Fk:_addPrintedCard(cd)
|
|
|
|
|
table.insert(self.void, cd.id)
|
|
|
|
|
self:setCardArea(cd.id, Card.Void, nil)
|
|
|
|
|
self:doBroadcastNotify("PrintCard", json.encode{ name, suit, number })
|
|
|
|
|
return cd
|
|
|
|
|
end
|
|
|
|
|
|
2024-02-04 07:30:27 +00:00
|
|
|
|
--- 刷新使命技状态
|
|
|
|
|
---@param player ServerPlayer
|
|
|
|
|
---@param skillName Suit
|
|
|
|
|
---@param failed? boolean
|
2023-05-28 10:45:54 +00:00
|
|
|
|
function Room:updateQuestSkillState(player, skillName, failed)
|
|
|
|
|
assert(Fk.skills[skillName].frequency == Skill.Quest)
|
|
|
|
|
|
|
|
|
|
self:setPlayerMark(player, MarkEnum.QuestSkillPreName .. skillName, failed and "failed" or "succeed")
|
|
|
|
|
local updateValue = failed and 2 or 1
|
|
|
|
|
|
|
|
|
|
self:doBroadcastNotify("UpdateQuestSkillUI", json.encode{
|
|
|
|
|
player.id,
|
|
|
|
|
skillName,
|
|
|
|
|
updateValue,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2024-02-04 07:30:27 +00:00
|
|
|
|
--- 废除区域
|
|
|
|
|
---@param player ServerPlayer
|
|
|
|
|
---@param playerSlots string | string[]
|
2023-08-12 18:25:04 +00:00
|
|
|
|
function Room:abortPlayerArea(player, playerSlots)
|
|
|
|
|
assert(type(playerSlots) == "string" or type(playerSlots) == "table")
|
|
|
|
|
|
|
|
|
|
if type(playerSlots) == "string" then
|
|
|
|
|
playerSlots = { playerSlots }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local cardsToDrop = {}
|
|
|
|
|
local slotsSealed = {}
|
|
|
|
|
local slotsToSeal = {}
|
|
|
|
|
for _, slot in ipairs(playerSlots) do
|
|
|
|
|
if slot == Player.JudgeSlot then
|
|
|
|
|
if not table.contains(player.sealedSlots, Player.JudgeSlot) then
|
|
|
|
|
table.insertIfNeed(slotsToSeal, slot)
|
|
|
|
|
|
|
|
|
|
local delayedTricks = player:getCardIds(Player.Judge)
|
|
|
|
|
if #delayedTricks > 0 then
|
|
|
|
|
table.insertTable(cardsToDrop, delayedTricks)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
local subtype = Util.convertSubtypeAndEquipSlot(slot)
|
|
|
|
|
if #player:getAvailableEquipSlots(subtype) > 0 then
|
|
|
|
|
table.insert(slotsToSeal, slot)
|
|
|
|
|
|
|
|
|
|
local equipmentIndex = (slotsSealed[tostring(subtype)] or 0) + 1
|
|
|
|
|
slotsSealed[tostring(subtype)] = equipmentIndex
|
|
|
|
|
|
|
|
|
|
if equipmentIndex <= #player:getEquipments(subtype) then
|
|
|
|
|
table.insert(cardsToDrop, player:getEquipments(subtype)[equipmentIndex])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-08-13 04:35:23 +00:00
|
|
|
|
if #slotsToSeal == 0 then
|
2023-08-12 18:25:04 +00:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self:moveCards({
|
|
|
|
|
ids = cardsToDrop,
|
|
|
|
|
from = player.id,
|
|
|
|
|
toArea = Card.DiscardPile,
|
|
|
|
|
moveReason = fk.ReasonPutIntoDiscardPile,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
table.insertTable(player.sealedSlots, slotsToSeal)
|
|
|
|
|
self:broadcastProperty(player, "sealedSlots")
|
2023-08-13 04:35:23 +00:00
|
|
|
|
|
|
|
|
|
self.logic:trigger(fk.AreaAborted, player, { slots = slotsSealed })
|
|
|
|
|
end
|
|
|
|
|
|
2024-02-04 07:30:27 +00:00
|
|
|
|
--- 恢复区域
|
|
|
|
|
---@param player ServerPlayer
|
|
|
|
|
---@param playerSlots string | string[]
|
2023-08-13 04:35:23 +00:00
|
|
|
|
function Room:resumePlayerArea(player, playerSlots)
|
|
|
|
|
assert(type(playerSlots) == "string" or type(playerSlots) == "table")
|
|
|
|
|
|
|
|
|
|
if type(playerSlots) == "string" then
|
|
|
|
|
playerSlots = { playerSlots }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local slotsToResume = {}
|
|
|
|
|
for _, slot in ipairs(playerSlots) do
|
|
|
|
|
for i = 1, #player.sealedSlots do
|
|
|
|
|
if player.sealedSlots[i] == slot then
|
|
|
|
|
table.remove(player.sealedSlots, i)
|
|
|
|
|
table.insert(slotsToResume, slot)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if #slotsToResume > 0 then
|
|
|
|
|
self:broadcastProperty(player, "sealedSlots")
|
|
|
|
|
self.logic:trigger(fk.AreaResumed, player, { slots = slotsToResume })
|
|
|
|
|
end
|
2023-08-12 18:25:04 +00:00
|
|
|
|
end
|
|
|
|
|
|
2024-02-04 07:30:27 +00:00
|
|
|
|
--- 设置休整
|
|
|
|
|
---@param player ServerPlayer
|
|
|
|
|
---@param roundNum integer
|
2023-12-10 10:55:16 +00:00
|
|
|
|
function Room:setPlayerRest(player, roundNum)
|
|
|
|
|
player.rest = roundNum
|
|
|
|
|
self:broadcastProperty(player, "rest")
|
|
|
|
|
end
|
|
|
|
|
|
2023-06-16 02:56:33 +00:00
|
|
|
|
return Room
|