1 Star 1 Fork 1

Hclo/evolution

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
e2v2.lua 5.54 KB
一键复制 编辑 原始数据 按行查看 历史
Hclo512 提交于 2024-11-03 23:34 . 适配4.22版本
local desc_2v2 = [[
# 2v2简介
1、1号位与4号位玩家同队,将身份明置为“骑士”,属于“天启”阵营;2号位与3号位玩家同队,将身份明置为“神官”,属于“神谕”阵营。
2、每队抽取六名备选角色,备选角色同队互通,然后玩家选择角色(可商议)。
3、1号位第一回合少摸一张牌,4号位的起始手牌数+1。
4、同队之间手牌全程互相可见。
5、当一名角色死亡时,其队友可摸一张牌。
]]
local EV = require "packages/evolution/EV"
local U = require "packages/utility/utility"
local ev_2v2_getLogic = function()
local ev_2v2_logic = GameLogic:subclass("ev_2v2_logic") ---@class GameLogic
function ev_2v2_logic:assignRoles()
local room = self.room
local n = #room.players
local roles = table.random {
{ "loyalist", "rebel", "rebel", "loyalist" },
{ "rebel", "loyalist", "loyalist", "rebel"},
}
for i = 1, n do
local p = room.players[i]
p.role = roles[i]
end
---[[
room.players[1]:addBuddy(room.players[4])
room.players[4]:addBuddy(room.players[1])
room.players[2]:addBuddy(room.players[3])
room.players[3]:addBuddy(room.players[2])
--]]
--
self.start_role = roles[1]
-- for adjustSeats
room.players[1].role = "lord"
end
function ev_2v2_logic:chooseGenerals()
local room = self.room
local generalNum = math.min(room.settings.generalNum, 9)
local lord = room:getLord()
room.current = lord
lord.role = self.start_role
for _, p in ipairs(room.players) do
room:setPlayerProperty(p, "role_shown", true)
room:broadcastProperty(p, "role")
end
local nonlord = room.players
local generals = table.map(Fk:getGeneralsRandomly(#nonlord * generalNum), Util.NameMapper)
table.shuffle(generals)
local t1 = table.slice(generals, 1, generalNum + 1)
local t2 = table.slice(generals, generalNum + 1, generalNum * 2 + 1)
local t3 = table.slice(generals, generalNum * 2 + 1, generalNum * 3 + 1)
local t4 = table.slice(generals, generalNum * 3 + 1, generalNum * 4 + 1)
room:askForMiniGame(nonlord, "AskForGeneral", "ev__2v2_sel", {
[nonlord[1].id] = {
friend_id = nonlord[4].id,
me = t1, friend = t4,
},
[nonlord[2].id] = {
friend_id = nonlord[3].id,
me = t2, friend = t3,
},
[nonlord[3].id] = {
friend_id = nonlord[2].id,
me = t3, friend = t2,
},
[nonlord[4].id] = {
friend_id = nonlord[1].id,
me = t4, friend = t1,
},
})
for _, p in ipairs(nonlord) do
local general = json.decode(p.client_reply)
room:setPlayerGeneral(p, general, true, true)
room:findGeneral(general)
end
room:askForChooseKingdom(nonlord)
room:setTag("SkipNormalDeathProcess", true)
end
return ev_2v2_logic
end
local ev_2v2_rule = fk.CreateTriggerSkill{
name = "#ev_2v2_rule",
priority = 0.001,
refresh_events = {fk.DrawInitialCards, fk.DrawNCards, fk.GameOverJudge, fk.Deathed},
can_refresh = function(self, event, target, player, data)
return target == player and not (event == fk.Deathed and player.rest > 0)
end,
on_refresh = function(self, event, target, player, data)
local room = player.room
if event == fk.DrawNCards then
local turnevents = room.logic.event_recorder[GameEvent.Turn] or Util.DummyTable
if #turnevents == 1 and player:getMark(self.name) == 0 then
room:setPlayerMark(player, self.name, 1)
data.n = data.n - 1
end
elseif event == fk.DrawInitialCards then
if player.seat == 4 then
data.num = data.num + 1
end
elseif event == fk.GameOverJudge then
local winner = Fk.game_modes[room.settings.gameMode]:getWinner(player)
if winner ~= "" then
room:gameOver(winner)
return true
end
else
for _, p in ipairs(room.alive_players) do
if p.role == player.role then
p:drawCards(1)
end
end
end
end,
}
Fk:addSkill(ev_2v2_rule)
local ev_2v2_mode = fk.CreateGameMode{
name = "ev_2v2_mode",
minPlayer = 4,
maxPlayer = 4,
rule = ev_2v2_rule,
logic = ev_2v2_getLogic,
surrender_func = function(self, playedTime)
local surrenderJudge = { { text = "time limitation: 1 min", passed = playedTime >= 60 },
{ text = "2v2: left you alive", passed = table.find(Fk:currentRoom().players, function(p)
return p.role == Self.role and p.dead and p.rest == 0
end) and true } }
return surrenderJudge
end,
winner_getter = function(self, victim)
if not victim.surrendered and victim.rest > 0 then
return ""
end
local room = victim.room
local alive = table.filter(room.players, function(p) ---@type Player[]
return not p.surrendered and not (p.dead and p.rest == 0)
end)
local winner = alive[1].role
for _, p in ipairs(alive) do
if p.role ~= winner then
return ""
end
end
return winner
end,
}
Fk:loadTranslationTable{
["ev_2v2_mode"] = "萌战2v2",
[":ev_2v2_mode"] = desc_2v2,
["time limitation: 1 min"] = "游戏时长达到1分钟",
["2v2: left you alive"] = "你所处队伍仅剩你存活",
}
Fk:addMiniGame{
name = "ev__2v2_sel",
qml_path = "packages/evolution/2v2",
default_choice = function(player, data)
return data.me[1]
end,
update_func = function(player, data)
local room = player.room
local d = player.mini_game_data.data
local friend = room:getPlayerById(d.friend_id)
friend:doNotify("UpdateMiniGame", json.encode(data))
end,
}
return ev_2v2_mode
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Hclo512/evolution.git
git@gitee.com:Hclo512/evolution.git
Hclo512
evolution
evolution
master

搜索帮助