This commit is contained in:
DESKTOP-C7UTUBQ\32064 2023-09-23 13:48:09 +08:00
parent 3767ab6f8a
commit 1f446fa9b8
4 changed files with 1136 additions and 1130 deletions

View File

@ -3,3 +3,4 @@
AI = require "server.ai.ai" AI = require "server.ai.ai"
TrustAI = require "server.ai.trust_ai" TrustAI = require "server.ai.trust_ai"
RandomAI = require "server.ai.random_ai" RandomAI = require "server.ai.random_ai"
SmartAI = require "server.ai.smart_ai"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -45,7 +45,7 @@ function ServerPlayer:initialize(_self)
self._prelighted_skills = {} self._prelighted_skills = {}
self._timewaste_count = 0 self._timewaste_count = 0
self.ai = TrustAI:new(self) self.ai = SmartAI:new(self)
end end
---@param command string ---@param command string
@ -284,25 +284,25 @@ function ServerPlayer:marshal(player, observe)
end end
for k, v in pairs(self.mark) do for k, v in pairs(self.mark) do
player:doNotify("SetPlayerMark", json.encode{self.id, k, v}) player:doNotify("SetPlayerMark", json.encode { self.id, k, v })
end end
for _, s in ipairs(self.player_skills) do for _, s in ipairs(self.player_skills) do
player:doNotify("AddSkill", json.encode{self.id, s.name}) player:doNotify("AddSkill", json.encode { self.id, s.name })
end end
for k, v in pairs(self.cardUsedHistory) do for k, v in pairs(self.cardUsedHistory) do
if v[1] > 0 then if v[1] > 0 then
player:doNotify("AddCardUseHistory", json.encode{k, v[1]}) player:doNotify("AddCardUseHistory", json.encode { k, v[1] })
end end
end end
for k, v in pairs(self.skillUsedHistory) do for k, v in pairs(self.skillUsedHistory) do
if v[4] > 0 then if v[4] > 0 then
player:doNotify("SetSkillUseHistory", json.encode{self.id, k, v[1], 1}) player:doNotify("SetSkillUseHistory", json.encode { self.id, k, v[1], 1 })
player:doNotify("SetSkillUseHistory", json.encode{self.id, k, v[2], 2}) player:doNotify("SetSkillUseHistory", json.encode { self.id, k, v[2], 2 })
player:doNotify("SetSkillUseHistory", json.encode{self.id, k, v[3], 3}) player:doNotify("SetSkillUseHistory", json.encode { self.id, k, v[3], 3 })
player:doNotify("SetSkillUseHistory", json.encode{self.id, k, v[4], 4}) player:doNotify("SetSkillUseHistory", json.encode { self.id, k, v[4], 4 })
end end
end end
@ -319,13 +319,13 @@ function ServerPlayer:reconnect()
local room = self.room local room = self.room
self.serverplayer:setState(fk.Player_Online) self.serverplayer:setState(fk.Player_Online)
self:doNotify("Setup", json.encode{ self:doNotify("Setup", json.encode {
self.id, self.id,
self._splayer:getScreenName(), self._splayer:getScreenName(),
self._splayer:getAvatar(), self._splayer:getAvatar(),
}) })
self:doNotify("EnterLobby", "") self:doNotify("EnterLobby", "")
self:doNotify("EnterRoom", json.encode{ self:doNotify("EnterRoom", json.encode {
#room.players, room.timeout, room.settings, #room.players, room.timeout, room.settings,
}) })
self:doNotify("StartGame", "") self:doNotify("StartGame", "")
@ -333,7 +333,7 @@ function ServerPlayer:reconnect()
-- send player data -- send player data
for _, p in ipairs(room:getOtherPlayers(self, false, true)) do for _, p in ipairs(room:getOtherPlayers(self, false, true)) do
self:doNotify("AddPlayer", json.encode{ self:doNotify("AddPlayer", json.encode {
p.id, p.id,
p._splayer:getScreenName(), p._splayer:getScreenName(),
p._splayer:getAvatar(), p._splayer:getAvatar(),
@ -350,13 +350,13 @@ function ServerPlayer:reconnect()
for i = -2, -math.huge, -1 do for i = -2, -math.huge, -1 do
local c = Fk.printed_cards[i] local c = Fk.printed_cards[i]
if not c then break end if not c then break end
self:doNotify("PrintCard", json.encode{ c.name, c.suit, c.number }) self:doNotify("PrintCard", json.encode { c.name, c.suit, c.number })
end end
-- send card marks -- send card marks
for id, marks in pairs(room.card_marks) do for id, marks in pairs(room.card_marks) do
for k, v in pairs(marks) do for k, v in pairs(marks) do
self:doNotify("SetCardMark", json.encode{ id, k, v }) self:doNotify("SetCardMark", json.encode { id, k, v })
end end
end end
@ -371,9 +371,9 @@ function ServerPlayer:reconnect()
-- send fake skills -- send fake skills
for _, s in ipairs(self._manually_fake_skills) do for _, s in ipairs(self._manually_fake_skills) do
self:doNotify("AddSkill", json.encode{ self.id, s.name, true }) self:doNotify("AddSkill", json.encode { self.id, s.name, true })
if table.contains(self.prelighted_skills, s) then if table.contains(self.prelighted_skills, s) then
self:doNotify("PrelightSkill", json.encode{ s.name, true }) self:doNotify("PrelightSkill", json.encode { s.name, true })
end end
end end
@ -392,7 +392,7 @@ function ServerPlayer:turnOver()
self.faceup = not self.faceup self.faceup = not self.faceup
self.room:broadcastProperty(self, "faceup") self.room:broadcastProperty(self, "faceup")
self.room:sendLog{ self.room:sendLog {
type = "#TurnOver", type = "#TurnOver",
from = self.id, from = self.id,
arg = self.faceup and "face_up" or "face_down", arg = self.faceup and "face_up" or "face_down",
@ -408,12 +408,12 @@ function ServerPlayer:showCards(cards)
end end
local room = self.room local room = self.room
room:sendLog{ room:sendLog {
type = "#ShowCard", type = "#ShowCard",
from = self.id, from = self.id,
card = cards, card = cards,
} }
room:doBroadcastNotify("ShowCard", json.encode{ room:doBroadcastNotify("ShowCard", json.encode {
from = self.id, from = self.id,
cards = cards, cards = cards,
}) })
@ -478,7 +478,7 @@ function ServerPlayer:gainAnExtraPhase(phase, delay)
self.phase = phase self.phase = phase
room:broadcastProperty(self, "phase") room:broadcastProperty(self, "phase")
room:sendLog{ room:sendLog {
type = "#GainAnExtraPhase", type = "#GainAnExtraPhase",
from = self.id, from = self.id,
arg = phase_name_table[phase], arg = phase_name_table[phase],
@ -553,7 +553,7 @@ function ServerPlayer:play(phase_table)
if (not skip) or (cancel_skip) then if (not skip) or (cancel_skip) then
GameEvent(GameEvent.Phase, self, self.phase):exec() GameEvent(GameEvent.Phase, self, self.phase):exec()
else else
room:sendLog{ room:sendLog {
type = "#PhaseSkipped", type = "#PhaseSkipped",
from = self.id, from = self.id,
arg = phase_name_table[self.phase], arg = phase_name_table[self.phase],
@ -597,7 +597,7 @@ function ServerPlayer:gainAnExtraTurn(delay)
end end
end end
room:sendLog{ room:sendLog {
type = "#GainAnExtraTurn", type = "#GainAnExtraTurn",
from = self.id from = self.id
} }
@ -664,7 +664,7 @@ end
function ServerPlayer:addVirtualEquip(card) function ServerPlayer:addVirtualEquip(card)
Player.addVirtualEquip(self, card) Player.addVirtualEquip(self, card)
self.room:doBroadcastNotify("AddVirtualEquip", json.encode{ self.room:doBroadcastNotify("AddVirtualEquip", json.encode {
player = self.id, player = self.id,
name = card.name, name = card.name,
subcards = card.subcards, subcards = card.subcards,
@ -673,7 +673,7 @@ end
function ServerPlayer:removeVirtualEquip(cid) function ServerPlayer:removeVirtualEquip(cid)
local ret = Player.removeVirtualEquip(self, cid) local ret = Player.removeVirtualEquip(self, cid)
self.room:doBroadcastNotify("RemoveVirtualEquip", json.encode{ self.room:doBroadcastNotify("RemoveVirtualEquip", json.encode {
player = self.id, player = self.id,
id = cid, id = cid,
}) })
@ -682,22 +682,22 @@ end
function ServerPlayer:addCardUseHistory(cardName, num) function ServerPlayer:addCardUseHistory(cardName, num)
Player.addCardUseHistory(self, cardName, num) Player.addCardUseHistory(self, cardName, num)
self:doNotify("AddCardUseHistory", json.encode{cardName, num}) self:doNotify("AddCardUseHistory", json.encode { cardName, num })
end end
function ServerPlayer:setCardUseHistory(cardName, num, scope) function ServerPlayer:setCardUseHistory(cardName, num, scope)
Player.setCardUseHistory(self, cardName, num, scope) Player.setCardUseHistory(self, cardName, num, scope)
self:doNotify("SetCardUseHistory", json.encode{cardName, num, scope}) self:doNotify("SetCardUseHistory", json.encode { cardName, num, scope })
end end
function ServerPlayer:addSkillUseHistory(cardName, num) function ServerPlayer:addSkillUseHistory(cardName, num)
Player.addSkillUseHistory(self, cardName, num) Player.addSkillUseHistory(self, cardName, num)
self.room:doBroadcastNotify("AddSkillUseHistory", json.encode{self.id, cardName, num}) self.room:doBroadcastNotify("AddSkillUseHistory", json.encode { self.id, cardName, num })
end end
function ServerPlayer:setSkillUseHistory(cardName, num, scope) function ServerPlayer:setSkillUseHistory(cardName, num, scope)
Player.setSkillUseHistory(self, cardName, num, scope) Player.setSkillUseHistory(self, cardName, num, scope)
self.room:doBroadcastNotify("SetSkillUseHistory", json.encode{self.id, cardName, num, scope}) self.room:doBroadcastNotify("SetSkillUseHistory", json.encode { self.id, cardName, num, scope })
end end
---@param chained boolean ---@param chained boolean
@ -710,7 +710,7 @@ function ServerPlayer:setChainState(chained)
self.chained = chained self.chained = chained
room:broadcastProperty(self, "chained") room:broadcastProperty(self, "chained")
room:sendLog{ room:sendLog {
type = "#ChainStateChange", type = "#ChainStateChange",
from = self.id, from = self.id,
arg = self.chained and "chained" or "un-chained" arg = self.chained and "chained" or "un-chained"
@ -721,7 +721,7 @@ function ServerPlayer:setChainState(chained)
end end
function ServerPlayer:reset() function ServerPlayer:reset()
self.room:sendLog{ self.room:sendLog {
type = "#ChainStateChange", type = "#ChainStateChange",
from = self.id, from = self.id,
arg = "reset-general" arg = "reset-general"
@ -775,7 +775,7 @@ function ServerPlayer:addFakeSkill(skill)
end end
-- TODO -- TODO
self:doNotify("AddSkill", json.encode{ self.id, skill.name, true }) self:doNotify("AddSkill", json.encode { self.id, skill.name, true })
end end
---@param skill Skill ---@param skill Skill
@ -794,7 +794,7 @@ function ServerPlayer:loseFakeSkill(skill)
end end
-- TODO -- TODO
self:doNotify("LoseSkill", json.encode{ self.id, skill.name, true }) self:doNotify("LoseSkill", json.encode { self.id, skill.name, true })
end end
function ServerPlayer:isFakeSkill(skill) function ServerPlayer:isFakeSkill(skill)
@ -830,7 +830,7 @@ function ServerPlayer:prelightSkill(skill, isPrelight)
end end
end end
self:doNotify("PrelightSkill", json.encode{ skill.name, isPrelight }) self:doNotify("PrelightSkill", json.encode { skill.name, isPrelight })
end end
---@param isDeputy bool ---@param isDeputy bool
@ -854,7 +854,8 @@ function ServerPlayer:revealGeneral(isDeputy, no_trigger)
local ret = true local ret = true
if not ((isDeputy and self.general ~= "anjiang") or (not isDeputy and self.deputyGeneral ~= "anjiang")) then if not ((isDeputy and self.general ~= "anjiang") or (not isDeputy and self.deputyGeneral ~= "anjiang")) then
local other = Fk.generals[self:getMark(isDeputy and "__heg_general" or "__heg_deputy")] or Fk.generals["blank_shibing"] local other = Fk.generals[self:getMark(isDeputy and "__heg_general" or "__heg_deputy")] or
Fk.generals["blank_shibing"]
for _, sname in ipairs(other:getSkillNameList()) do for _, sname in ipairs(other:getSkillNameList()) do
local s = Fk.skills[sname] local s = Fk.skills[sname]
if s.frequency == Skill.Compulsory and s.relate_to_place ~= (isDeputy and "m" or "d") then if s.frequency == Skill.Compulsory and s.relate_to_place ~= (isDeputy and "m" or "d") then
@ -887,7 +888,7 @@ function ServerPlayer:revealGeneral(isDeputy, no_trigger)
self.gender = general.gender self.gender = general.gender
end end
room:sendLog{ room:sendLog {
type = "#RevealGeneral", type = "#RevealGeneral",
from = self.id, from = self.id,
arg = isDeputy and "deputyGeneral" or "mainGeneral", arg = isDeputy and "deputyGeneral" or "mainGeneral",
@ -926,7 +927,7 @@ function ServerPlayer:hideGeneral(isDeputy)
local mark = isDeputy and "__heg_deputy" or "__heg_general" local mark = isDeputy and "__heg_deputy" or "__heg_general"
self:setMark(mark, generalName) self:setMark(mark, generalName)
self:doNotify("SetPlayerMark", json.encode{ self.id, mark, generalName}) self:doNotify("SetPlayerMark", json.encode { self.id, mark, generalName })
if isDeputy then if isDeputy then
room:setDeputyGeneral(self, "anjiang") room:setDeputyGeneral(self, "anjiang")
@ -961,6 +962,7 @@ function ServerPlayer:hideGeneral(isDeputy)
room.logic:trigger(fk.GeneralHidden, room, generalName) room.logic:trigger(fk.GeneralHidden, room, generalName)
end end
-- 神貂蝉 -- 神貂蝉
---@param p ServerPlayer ---@param p ServerPlayer
@ -980,7 +982,7 @@ function ServerPlayer:addBuddy(other)
other = self.room:getPlayerById(other) other = self.room:getPlayerById(other)
end end
Player.addBuddy(self, other) Player.addBuddy(self, other)
self:doNotify("AddBuddy", json.encode{ other.id, other.player_cards[Player.Hand] }) self:doNotify("AddBuddy", json.encode { other.id, other.player_cards[Player.Hand] })
end end
function ServerPlayer:removeBuddy(other) function ServerPlayer:removeBuddy(other)