commit
1d70b506ce
|
@ -324,7 +324,7 @@ function CanUseCardToTarget(card, to_select, selected)
|
|||
local selected_cards
|
||||
if type(card) == "number" then
|
||||
c = Fk:getCardById(card)
|
||||
selected_cards = {card}
|
||||
selected_cards = { card }
|
||||
else
|
||||
local t = json.decode(card)
|
||||
return ActiveTargetFilter(t.skill, to_select, selected, t.subcards)
|
||||
|
@ -343,7 +343,7 @@ function CanSelectCardForSkill(card, to_select, selected_targets)
|
|||
local selected_cards
|
||||
if type(card) == "number" then
|
||||
c = Fk:getCardById(card)
|
||||
selected_cards = {card}
|
||||
selected_cards = { card }
|
||||
else
|
||||
error()
|
||||
end
|
||||
|
@ -359,7 +359,7 @@ function CardFeasible(card, selected_targets)
|
|||
local selected_cards
|
||||
if type(card) == "number" then
|
||||
c = Fk:getCardById(card)
|
||||
selected_cards = {card}
|
||||
selected_cards = { card }
|
||||
else
|
||||
local t = json.decode(card)
|
||||
return ActiveFeasible(t.skill, selected_targets, t.subcards)
|
||||
|
@ -637,8 +637,8 @@ function ResetClientLua()
|
|||
local data = ClientInstance.room_settings
|
||||
Self = ClientPlayer:new(fk.Self)
|
||||
ClientInstance = Client:new() -- clear old client data
|
||||
ClientInstance.players = {Self}
|
||||
ClientInstance.alive_players = {Self}
|
||||
ClientInstance.players = { Self }
|
||||
ClientInstance.alive_players = { Self }
|
||||
ClientInstance.discard_pile = {}
|
||||
|
||||
ClientInstance.enter_room_data = _data;
|
||||
|
@ -691,12 +691,7 @@ function CheckSurrenderAvailable(playedTime)
|
|||
end
|
||||
|
||||
function SaveRecord()
|
||||
<<<<<<< HEAD
|
||||
local c = ClientInstance
|
||||
c.client:saveRecord(json.encode(c.record), c.record[2])
|
||||
=======
|
||||
local c = ClientInstance
|
||||
c.client:saveRecord(json.encode(c.record), c.record[2])
|
||||
ClientInstance.client:saveRecord(json.encode(ClientInstance.record), ClientInstance.record[2])
|
||||
end
|
||||
|
||||
function GetCardProhibitReason(cid, method, pattern)
|
||||
|
@ -747,7 +742,6 @@ function PoxiFeasible(poxi_type, selected, data)
|
|||
local poxi = Fk.poxi_methods[poxi_type]
|
||||
if not poxi then return "false" end
|
||||
return json.encode(poxi.feasible(selected, data))
|
||||
>>>>>>> 30b363ef775598c6c6510ceb17e70ca01bd2f677
|
||||
end
|
||||
|
||||
dofile "lua/client/i18n/init.lua"
|
||||
|
|
|
@ -43,7 +43,7 @@ local function useActiveSkill(self, skill, card)
|
|||
avail_targets = table.map(avail_targets, function(p)
|
||||
return p.id
|
||||
end)
|
||||
local avail_cards = table.filter(player:getCardIds{Player.Hand, Player.Equip}, function(id)
|
||||
local avail_cards = table.filter(player:getCardIds { Player.Hand, Player.Equip }, function(id)
|
||||
return filter_func(skill, id, selected_cards, selected_targets)
|
||||
end)
|
||||
|
||||
|
@ -110,7 +110,7 @@ local function useVSSkill(self, skill, pattern, cancelable, extra_data)
|
|||
local max_try_time = 100
|
||||
|
||||
for _ = 0, max_try_time do
|
||||
local avail_cards = table.filter(player:getCardIds{Player.Hand, Player.Equip}, function(id)
|
||||
local avail_cards = table.filter(player:getCardIds { Player.Hand, Player.Equip }, function(id)
|
||||
return skill:cardFilter(id, selected_cards)
|
||||
end)
|
||||
if #avail_cards == 0 then
|
||||
|
@ -144,7 +144,7 @@ random_cb.AskForUseActiveSkill = function(self, jsonData)
|
|||
end
|
||||
|
||||
random_cb.AskForSkillInvoke = function(self, jsonData)
|
||||
return table.random {"1", ""}
|
||||
return table.random { "1", "" }
|
||||
end
|
||||
|
||||
random_cb.AskForUseCard = function(self, jsonData)
|
||||
|
@ -174,11 +174,11 @@ random_cb.AskForUseCard = function(self, jsonData)
|
|||
local min_card = skill:getMinCardNum()
|
||||
local max_card = skill:getMaxCardNum()
|
||||
for _ = 0, max_try_times do
|
||||
if skill:feasible(selected_targets, {card.id}, self.player, card) then
|
||||
if skill:feasible(selected_targets, { card.id }, self.player, card) then
|
||||
break
|
||||
end
|
||||
local avail_targets = table.filter(self.room:getAlivePlayers(), function(p)
|
||||
local ret = skill:targetFilter(p.id, selected_targets, {card}, card or Fk:cloneCard 'zixing')
|
||||
local ret = skill:targetFilter(p.id, selected_targets, { card }, card or Fk:cloneCard 'zixing')
|
||||
return ret
|
||||
end)
|
||||
avail_targets = table.map(avail_targets, function(p)
|
||||
|
@ -190,7 +190,7 @@ random_cb.AskForUseCard = function(self, jsonData)
|
|||
end
|
||||
table.insertIfNeed(selected_targets, table.random(avail_targets))
|
||||
end
|
||||
if skill:feasible(selected_targets, {card.id}, self.player, card) then
|
||||
if skill:feasible(selected_targets, { card.id }, self.player, card) then
|
||||
return json.encode {
|
||||
card = table.random(avail_cards),
|
||||
targets = selected_targets
|
||||
|
@ -207,7 +207,7 @@ random_cb.AskForResponseCard = function(self, jsonData)
|
|||
local pattern = data[2]
|
||||
local cancelable = true
|
||||
local exp = Exppattern:Parse(pattern)
|
||||
local avail_cards = table.filter(self.player:getCardIds{Player.Hand, Player.Equip}, function(id)
|
||||
local avail_cards = table.filter(self.player:getCardIds { Player.Hand, Player.Equip }, function(id)
|
||||
return exp:match(Fk:getCardById(id))
|
||||
end)
|
||||
if #avail_cards > 0 then
|
||||
|
|
|
@ -8,328 +8,6 @@ local trust_cb = {}
|
|||
function TrustAI:initialize(player)
|
||||
AI.initialize(self, player)
|
||||
self.cb_table = trust_cb
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
self.player = player
|
||||
self.room = RoomInstance or ClientInstance
|
||||
|
||||
fk.ai_role[player.id] = "neutral"
|
||||
fk.roleValue[player.id] = {
|
||||
lord = 0,
|
||||
loyalist = 0,
|
||||
rebel = 0,
|
||||
renegade = 0
|
||||
}
|
||||
self:updatePlayers()
|
||||
end
|
||||
|
||||
function TrustAI:isRolePredictable()
|
||||
return self.room.settings.gameMode ~= "aaa_role_mode"
|
||||
end
|
||||
|
||||
local function aliveRoles(room)
|
||||
fk.alive_roles = {
|
||||
lord = 0,
|
||||
loyalist = 0,
|
||||
rebel = 0,
|
||||
renegade = 0
|
||||
}
|
||||
for _, ap in ipairs(room:getAllPlayers(false)) do
|
||||
fk.alive_roles[ap.role] = 0
|
||||
end
|
||||
for _, ap in ipairs(room:getAlivePlayers(false)) do
|
||||
fk.alive_roles[ap.role] = fk.alive_roles[ap.role] + 1
|
||||
end
|
||||
return fk.alive_roles
|
||||
end
|
||||
|
||||
function TrustAI:objectiveLevel(to)
|
||||
if self.player.id == to.id then
|
||||
return -2
|
||||
elseif #self.room:getAlivePlayers(false) < 3 then
|
||||
return 5
|
||||
end
|
||||
local ars = aliveRoles(self.room)
|
||||
if self:isRolePredictable() then
|
||||
fk.ai_role[self.player.id] = self.role
|
||||
fk.roleValue[self.player.id][self.role] = 666
|
||||
if self.role == "renegade" then
|
||||
fk.explicit_renegade = true
|
||||
end
|
||||
for _, p in ipairs(self.room:getAlivePlayers()) do
|
||||
if
|
||||
p.role == self.role or p.role == "lord" and self.role == "loyalist" or
|
||||
p.role == "loyalist" and self.role == "lord"
|
||||
then
|
||||
table.insert(self.friends, p)
|
||||
if p.id ~= self.player.id then
|
||||
table.insert(self.friends_noself, p)
|
||||
end
|
||||
else
|
||||
table.insert(self.enemies, p)
|
||||
end
|
||||
end
|
||||
elseif self.role == "renegade" then
|
||||
if to.role == "lord" then
|
||||
return -1
|
||||
elseif ars.rebel < 1 then
|
||||
return 4
|
||||
elseif fk.ai_role[to.id] == "loyalist" then
|
||||
return ars.lord + ars.loyalist - ars.rebel
|
||||
elseif fk.ai_role[to.id] == "rebel" then
|
||||
local r = ars.rebel - ars.lord + ars.loyalist
|
||||
if r >= 0 then
|
||||
return 3
|
||||
else
|
||||
return r
|
||||
end
|
||||
end
|
||||
elseif self.role == "lord" or self.role == "loyalist" then
|
||||
if fk.ai_role[to.id] == "rebel" then
|
||||
return 5
|
||||
elseif to.role == "lord" then
|
||||
return -2
|
||||
elseif ars.rebel < 1 then
|
||||
if self.role == "lord" then
|
||||
return fk.explicit_renegade and fk.ai_role[to.id] == "renegade" and 4 or to.hp > 1 and 2 or 0
|
||||
elseif fk.explicit_renegade then
|
||||
return fk.ai_role[to.id] == "renegade" and 4 or -1
|
||||
else
|
||||
return 3
|
||||
end
|
||||
elseif fk.ai_role[to.id] == "loyalist" then
|
||||
return -2
|
||||
elseif fk.ai_role[to.id] == "renegade" then
|
||||
local r = ars.lord + ars.loyalist - ars.rebel
|
||||
if r <= 0 then
|
||||
return r
|
||||
else
|
||||
return 3
|
||||
end
|
||||
end
|
||||
elseif self.role == "rebel" then
|
||||
if to.role == "lord" then
|
||||
return 5
|
||||
elseif fk.ai_role[to.id] == "loyalist" then
|
||||
return 4
|
||||
elseif fk.ai_role[to.id] == "rebel" then
|
||||
return -2
|
||||
elseif fk.ai_role[to.id] == "renegade" then
|
||||
local r = ars.rebel - ars.lord + ars.loyalist
|
||||
if r > 0 then
|
||||
return 1
|
||||
else
|
||||
return r
|
||||
end
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function TrustAI:updatePlayers(update)
|
||||
self.role = self.player.role
|
||||
local neutrality = {}
|
||||
self.enemies = {}
|
||||
self.friends = {}
|
||||
self.friends_noself = {}
|
||||
|
||||
local aps = self.room:getAlivePlayers()
|
||||
local function compare_func(a, b)
|
||||
local v1 = fk.roleValue[a.id].rebel
|
||||
local v2 = fk.roleValue[b.id].rebel
|
||||
if v1 == v2 then
|
||||
v1 = fk.roleValue[a.id].renegade
|
||||
v2 = fk.roleValue[b.id].renegade
|
||||
end
|
||||
return v1 > v2
|
||||
end
|
||||
table.sort(aps, compare_func)
|
||||
fk.explicit_renegade = false
|
||||
local ars = aliveRoles(self.room)
|
||||
local rebel, renegade, loyalist = 0, 0, 0
|
||||
for _, ap in ipairs(aps) do
|
||||
if ap.role == "lord" then
|
||||
fk.ai_role[ap.id] = "loyalist"
|
||||
elseif fk.roleValue[ap.id].rebel > 50 and ars.rebel > rebel then
|
||||
rebel = rebel + 1
|
||||
fk.ai_role[ap.id] = "rebel"
|
||||
elseif fk.roleValue[ap.id].renegade > 50 and ars.renegade > renegade then
|
||||
renegade = renegade + 1
|
||||
fk.ai_role[ap.id] = "renegade"
|
||||
fk.explicit_renegade = fk.roleValue[ap.id].renegade > 100
|
||||
elseif fk.roleValue[ap.id].rebel < -50 and ars.loyalist > loyalist then
|
||||
loyalist = loyalist + 1
|
||||
fk.ai_role[ap.id] = "loyalist"
|
||||
else
|
||||
fk.ai_role[ap.id] = "neutral"
|
||||
end
|
||||
end
|
||||
|
||||
for n, p in ipairs(self.room:getAlivePlayers(false)) do
|
||||
n = self:objectiveLevel(p)
|
||||
if n < 0 then
|
||||
table.insert(self.friends, p)
|
||||
if p.id ~= self.player.id then
|
||||
table.insert(self.friends_noself, p)
|
||||
end
|
||||
elseif n > 0 then
|
||||
table.insert(self.enemies, p)
|
||||
else
|
||||
table.insert(neutrality, p)
|
||||
end
|
||||
end
|
||||
self:assignValue()
|
||||
--[[
|
||||
if self.enemies<1 and #neutrality>0
|
||||
and#self.toUse<3 and self:getOverflow()>0
|
||||
then
|
||||
function compare_func(a,b)
|
||||
return sgs.getDefense(a)<sgs.getDefense(b)
|
||||
end
|
||||
table.sort(neutrality,compare_func)
|
||||
table.insert(self.enemies,neutrality[1])
|
||||
end-]]
|
||||
end
|
||||
|
||||
local function updateIntention(player, to, intention)
|
||||
if player.id == to.id then
|
||||
return
|
||||
elseif player.role == "lord" then
|
||||
fk.roleValue[to.id].rebel = fk.roleValue[to.id].rebel + intention * (200 - fk.roleValue[to.id].rebel) / 200
|
||||
else
|
||||
if to.role == "lord" or fk.ai_role[to.id] == "loyalist" then
|
||||
fk.roleValue[player.id].rebel = fk.roleValue[player.id].rebel +
|
||||
intention * (200 - fk.roleValue[player.id].rebel) / 200
|
||||
elseif fk.ai_role[to.id] == "rebel" then
|
||||
fk.roleValue[player.id].rebel = fk.roleValue[player.id].rebel -
|
||||
intention * (fk.roleValue[player.id].rebel + 200) / 200
|
||||
end
|
||||
if fk.roleValue[player.id].rebel < 0 and intention > 0 or fk.roleValue[player.id].rebel > 0 and intention < 0 then
|
||||
fk.roleValue[player.id].renegade = fk.roleValue[player.id].renegade +
|
||||
intention * (100 - fk.roleValue[player.id].renegade) / 200
|
||||
end
|
||||
local aps = player.room:getAlivePlayers()
|
||||
local function compare_func(a, b)
|
||||
local v1 = fk.roleValue[a.id].rebel
|
||||
local v2 = fk.roleValue[b.id].rebel
|
||||
if v1 == v2 then
|
||||
v1 = fk.roleValue[a.id].renegade
|
||||
v2 = fk.roleValue[b.id].renegade
|
||||
end
|
||||
return v1 > v2
|
||||
end
|
||||
table.sort(aps, compare_func)
|
||||
fk.explicit_renegade = false
|
||||
local ars = aliveRoles(player.room)
|
||||
local rebel, renegade, loyalist = 0, 0, 0
|
||||
for _, ap in ipairs(aps) do
|
||||
if ap.role == "lord" then
|
||||
fk.ai_role[ap.id] = "loyalist"
|
||||
elseif fk.roleValue[ap.id].rebel > 50 and ars.rebel > rebel then
|
||||
rebel = rebel + 1
|
||||
fk.ai_role[ap.id] = "rebel"
|
||||
elseif fk.roleValue[ap.id].renegade > 50 and ars.renegade > renegade then
|
||||
renegade = renegade + 1
|
||||
fk.ai_role[ap.id] = "renegade"
|
||||
fk.explicit_renegade = fk.roleValue[ap.id].renegade > 100
|
||||
elseif fk.roleValue[ap.id].rebel < -50 and ars.loyalist > loyalist then
|
||||
loyalist = loyalist + 1
|
||||
fk.ai_role[ap.id] = "loyalist"
|
||||
else
|
||||
fk.ai_role[ap.id] = "neutral"
|
||||
end
|
||||
end
|
||||
fk.qWarning(
|
||||
player.general ..
|
||||
" " ..
|
||||
intention ..
|
||||
" " ..
|
||||
fk.ai_role[player.id] ..
|
||||
" rebelValue:" .. fk.roleValue[player.id].rebel .. " renegadeValue:" .. fk.roleValue[player.id].renegade
|
||||
) --]]
|
||||
end
|
||||
end
|
||||
|
||||
function TrustAI:filterEvent(event, player, data)
|
||||
if event == fk.TargetSpecified then
|
||||
local callback = fk.ai_card[data.card.name]
|
||||
callback = callback and callback.intention
|
||||
if type(callback) == "function" then
|
||||
for _, p in ipairs(TargetGroup:getRealTargets(data.tos)) do
|
||||
p = self.room:getPlayerById(p)
|
||||
local intention = callback(p.ai, data.card, self.room:getPlayerById(data.from))
|
||||
if type(intention) == "number" then
|
||||
updateIntention(self.room:getPlayerById(data.from), p, intention)
|
||||
end
|
||||
end
|
||||
elseif type(callback) == "number" then
|
||||
for _, p in ipairs(TargetGroup:getRealTargets(data.tos)) do
|
||||
p = self.room:getPlayerById(p)
|
||||
updateIntention(self.room:getPlayerById(data.from), p, callback)
|
||||
end
|
||||
end
|
||||
elseif event == fk.StartJudge then
|
||||
fk.trick_judge[data.reason] = data.pattern
|
||||
elseif event == fk.AfterCardsMove then
|
||||
end
|
||||
end
|
||||
|
||||
function TrustAI:isWeak(player, getAP)
|
||||
player = player or self.player
|
||||
if type(player) == "number" then
|
||||
player = self.room:getPlayerById(player)
|
||||
end
|
||||
return player.hp < 2 or player.hp <= 2 and #player:getCardIds("&h") <= 2
|
||||
end
|
||||
|
||||
function TrustAI:isFriend(pid, tid)
|
||||
if tid then
|
||||
local bt = self:isFriend(pid)
|
||||
return bt ~= nil and bt == self:isFriend(tid)
|
||||
end
|
||||
if type(pid) == "number" then
|
||||
pid = self.room:getPlayerById(pid)
|
||||
end
|
||||
local ve = self:objectiveLevel(pid)
|
||||
if ve < 0 then
|
||||
return true
|
||||
elseif ve > 0 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function TrustAI:isEnemie(pid, tid)
|
||||
if tid then
|
||||
local bt = self:isFriend(pid)
|
||||
return bt ~= nil and bt ~= self:isFriend(tid)
|
||||
end
|
||||
if type(pid) == "number" then
|
||||
pid = self.room:getPlayerById(pid)
|
||||
end
|
||||
local ve = self:objectiveLevel(pid)
|
||||
if ve > 0 then
|
||||
return true
|
||||
elseif ve < 0 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function TrustAI:eventData(game_event)
|
||||
local event = self.room.logic:getCurrentEvent():findParent(GameEvent[game_event], true)
|
||||
return event and event.data[1]
|
||||
end
|
||||
|
||||
for _, n in ipairs(FileIO.ls("packages")) do
|
||||
if FileIO.isDir("packages/" .. n) and FileIO.exists("packages/" .. n .. "/" .. n .. "_ai.lua") then
|
||||
dofile("packages/" .. n .. "/" .. n .. "_ai.lua")
|
||||
end
|
||||
end
|
||||
-- 加载两次拓展是为了能够引用,例如属性杀的使用直接套入普通杀的使用
|
||||
for _, n in ipairs(FileIO.ls("packages")) do
|
||||
if FileIO.isDir("packages/" .. n) and FileIO.exists("packages/" .. n .. "/" .. n .. "_ai.lua") then
|
||||
dofile("packages/" .. n .. "/" .. n .. "_ai.lua")
|
||||
end
|
||||
>>>>>>> 79d3213cc0aa996c9072ae5696e387a9bda210d8
|
||||
end
|
||||
|
||||
return TrustAI
|
||||
|
|
|
@ -129,3 +129,121 @@ fk.GeneralRevealed = 89
|
|||
fk.GeneralHidden = 90
|
||||
|
||||
fk.NumOfEvents = 91
|
||||
--[[
|
||||
local events = {
|
||||
"NonTrigger",
|
||||
"GamePrepared",
|
||||
"GameStart",
|
||||
"BeforeTurnStart",
|
||||
"TurnStart",
|
||||
"TurnEnd",
|
||||
"AfterTurnEnd",
|
||||
"EventPhaseStart",
|
||||
"EventPhaseProceeding",
|
||||
"EventPhaseEnd",
|
||||
"AfterPhaseEnd",
|
||||
"EventPhaseChanging",
|
||||
"EventPhaseSkipping",
|
||||
|
||||
"BeforeCardsMove",
|
||||
"AfterCardsMove",
|
||||
|
||||
"DrawNCards",
|
||||
"AfterDrawNCards",
|
||||
"DrawInitialCards",
|
||||
"AfterDrawInitialCards",
|
||||
|
||||
"PreHpRecover",
|
||||
"HpRecover",
|
||||
"PreHpLost",
|
||||
"HpLost",
|
||||
"BeforeHpChanged",
|
||||
"HpChanged",
|
||||
"MaxHpChanged",
|
||||
|
||||
"EventLoseSkill",
|
||||
"EventAcquireSkill",
|
||||
|
||||
"StartJudge",
|
||||
"AskForRetrial",
|
||||
"FinishRetrial",
|
||||
"FinishJudge",
|
||||
|
||||
"RoundStart",
|
||||
"RoundEnd",
|
||||
"BeforeTurnOver",
|
||||
"TurnedOver",
|
||||
"BeforeChainStateChange",
|
||||
"ChainStateChanged",
|
||||
|
||||
"PreDamage",
|
||||
"DamageCaused",
|
||||
"DamageInflicted",
|
||||
"Damage",
|
||||
"Damaged",
|
||||
"DamageFinished",
|
||||
|
||||
"EnterDying",
|
||||
"Dying",
|
||||
"AfterDying",
|
||||
|
||||
"PreCardUse",
|
||||
"AfterCardUseDeclared",
|
||||
"AfterCardTargetDeclared",
|
||||
"CardUsing",
|
||||
"BeforeCardUseEffect",
|
||||
"TargetSpecifying",
|
||||
"TargetConfirming",
|
||||
"TargetSpecified",
|
||||
"TargetConfirmed",
|
||||
"CardUseFinished",
|
||||
|
||||
"PreCardRespond",
|
||||
"CardResponding",
|
||||
"CardRespondFinished",
|
||||
|
||||
"PreCardEffect",
|
||||
"BeforeCardEffect",
|
||||
"CardEffecting",
|
||||
"CardEffectFinished",
|
||||
"CardEffectCancelledOut",
|
||||
|
||||
"AskForPeaches",
|
||||
"AskForPeachesDone",
|
||||
"Death",
|
||||
"BuryVictim",
|
||||
"Deathed",
|
||||
"BeforeGameOverJudge",
|
||||
"GameOverJudge",
|
||||
"GameFinished",
|
||||
|
||||
"AskForCardUse",
|
||||
"AskForCardResponse",
|
||||
|
||||
"StartPindian",
|
||||
"PindianCardsDisplayed",
|
||||
"PindianResultConfirmed",
|
||||
"PindianFinished",
|
||||
|
||||
"AfterDrawPileShuffle",
|
||||
|
||||
"BeforeTriggerSkillUse",
|
||||
|
||||
"BeforeDrawCard",
|
||||
|
||||
"CardShown",
|
||||
|
||||
"SkillEffect",
|
||||
"AfterSkillEffect",
|
||||
|
||||
"AreaAborted",
|
||||
"AreaResumed",
|
||||
|
||||
"GeneralRevealed",
|
||||
"GeneralHidden",
|
||||
|
||||
"NumOfEvents"
|
||||
}
|
||||
for i, event in ipairs(events) do
|
||||
fk[event] = i
|
||||
end --]]
|
||||
|
|
|
@ -194,16 +194,15 @@ end
|
|||
GameEvent.functions[GameEvent.UseCard] = function(self)
|
||||
local cardUseEvent = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
||||
if cardUseEvent.card.skill then
|
||||
cardUseEvent.card.skill:onUse(room, cardUseEvent)
|
||||
end
|
||||
|
||||
if logic:trigger(fk.PreCardUse, room:getPlayerById(cardUseEvent.from), cardUseEvent) then
|
||||
if room.logic:trigger(fk.PreCardUse, room:getPlayerById(cardUseEvent.from), cardUseEvent) then
|
||||
cardUseEvent.breakEvent = true
|
||||
self.data = { cardUseEvent }
|
||||
logic:breakEvent()
|
||||
room.logic:breakEvent()
|
||||
end
|
||||
|
||||
room:moveCardTo(cardUseEvent.card, Card.Processing, nil, fk.ReasonUse)
|
||||
|
@ -223,7 +222,7 @@ GameEvent.functions[GameEvent.UseCard] = function(self)
|
|||
break
|
||||
end
|
||||
|
||||
logic:trigger(event, room:getPlayerById(cardUseEvent.from), cardUseEvent)
|
||||
room.logic:trigger(event, room:getPlayerById(cardUseEvent.from), cardUseEvent)
|
||||
if event == fk.CardUsing then
|
||||
room:doCardUseEffect(cardUseEvent)
|
||||
end
|
||||
|
@ -232,13 +231,12 @@ end
|
|||
|
||||
GameEvent.cleaners[GameEvent.UseCard] = function(self)
|
||||
local cardUseEvent = table.unpack(self.data)
|
||||
local room = self.room
|
||||
|
||||
room.logic:trigger(fk.CardUseFinished, room:getPlayerById(cardUseEvent.from), cardUseEvent)
|
||||
self.room.logic:trigger(fk.CardUseFinished, self.room:getPlayerById(cardUseEvent.from), cardUseEvent)
|
||||
|
||||
local leftRealCardIds = room:getSubcardsByRule(cardUseEvent.card, { Card.Processing })
|
||||
local leftRealCardIds = self.room:getSubcardsByRule(cardUseEvent.card, { Card.Processing })
|
||||
if #leftRealCardIds > 0 then
|
||||
room:moveCards({
|
||||
self.room:moveCards({
|
||||
ids = leftRealCardIds,
|
||||
toArea = Card.DiscardPile,
|
||||
moveReason = fk.ReasonUse
|
||||
|
@ -249,12 +247,11 @@ end
|
|||
GameEvent.functions[GameEvent.RespondCard] = function(self)
|
||||
local cardResponseEvent = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
||||
if logic:trigger(fk.PreCardRespond, room:getPlayerById(cardResponseEvent.from), cardResponseEvent) then
|
||||
if room.logic:trigger(fk.PreCardRespond, room:getPlayerById(cardResponseEvent.from), cardResponseEvent) then
|
||||
cardResponseEvent.breakEvent = true
|
||||
self.data = { cardResponseEvent }
|
||||
logic:breakEvent()
|
||||
room.logic:breakEvent()
|
||||
end
|
||||
|
||||
local from = cardResponseEvent.customFrom or cardResponseEvent.from
|
||||
|
@ -296,19 +293,18 @@ GameEvent.functions[GameEvent.RespondCard] = function(self)
|
|||
if cardResponseEvent.retrial ~= true then
|
||||
playCardEmotionAndSound(room, room:getPlayerById(from), card)
|
||||
end
|
||||
logic:trigger(fk.CardResponding, room:getPlayerById(cardResponseEvent.from), cardResponseEvent)
|
||||
room.logic:trigger(fk.CardResponding, room:getPlayerById(cardResponseEvent.from), cardResponseEvent)
|
||||
self.data = { cardResponseEvent }
|
||||
end
|
||||
|
||||
GameEvent.cleaners[GameEvent.RespondCard] = function(self)
|
||||
local cardResponseEvent = table.unpack(self.data)
|
||||
local room = self.room
|
||||
|
||||
room.logic:trigger(fk.CardRespondFinished, room:getPlayerById(cardResponseEvent.from), cardResponseEvent)
|
||||
self.room.logic:trigger(fk.CardRespondFinished, self.room:getPlayerById(cardResponseEvent.from), cardResponseEvent)
|
||||
|
||||
local realCardIds = room:getSubcardsByRule(cardResponseEvent.card, { Card.Processing })
|
||||
local realCardIds = self.room:getSubcardsByRule(cardResponseEvent.card, { Card.Processing })
|
||||
if #realCardIds > 0 and not cardResponseEvent.skipDrop then
|
||||
room:moveCards({
|
||||
self.room:moveCards({
|
||||
ids = realCardIds,
|
||||
toArea = Card.DiscardPile,
|
||||
moveReason = fk.ReasonResonpse
|
||||
|
@ -319,34 +315,33 @@ end
|
|||
GameEvent.functions[GameEvent.CardEffect] = function(self)
|
||||
local cardEffectEvent = table.unpack(self.data)
|
||||
local room = self.room
|
||||
local logic = room.logic
|
||||
|
||||
for _, event in ipairs({ fk.PreCardEffect, fk.BeforeCardEffect, fk.CardEffecting, fk.CardEffectFinished }) do
|
||||
local user = cardEffectEvent.from and room:getPlayerById(cardEffectEvent.from) or nil
|
||||
if cardEffectEvent.isCancellOut then
|
||||
if logic:trigger(fk.CardEffectCancelledOut, user, cardEffectEvent) then
|
||||
if room.logic:trigger(fk.CardEffectCancelledOut, user, cardEffectEvent) then
|
||||
cardEffectEvent.isCancellOut = false
|
||||
else
|
||||
logic:breakEvent()
|
||||
room.logic:breakEvent()
|
||||
end
|
||||
end
|
||||
|
||||
if not cardEffectEvent.toCard and
|
||||
(not (room:getPlayerById(cardEffectEvent.to):isAlive() and cardEffectEvent.to) or
|
||||
#room:deadPlayerFilter(TargetGroup:getRealTargets(cardEffectEvent.tos)) == 0) then
|
||||
logic:breakEvent()
|
||||
room.logic:breakEvent()
|
||||
end
|
||||
|
||||
if table.contains((cardEffectEvent.nullifiedTargets or Util.DummyTable), cardEffectEvent.to) then
|
||||
logic:breakEvent()
|
||||
room.logic:breakEvent()
|
||||
end
|
||||
|
||||
if event == fk.PreCardEffect then
|
||||
if cardEffectEvent.from and logic:trigger(event, room:getPlayerById(cardEffectEvent.from), cardEffectEvent) then
|
||||
logic:breakEvent()
|
||||
if cardEffectEvent.from and room.logic:trigger(event, room:getPlayerById(cardEffectEvent.from), cardEffectEvent) then
|
||||
room.logic:breakEvent()
|
||||
end
|
||||
elseif cardEffectEvent.to and logic:trigger(event, room:getPlayerById(cardEffectEvent.to), cardEffectEvent) then
|
||||
logic:breakEvent()
|
||||
elseif cardEffectEvent.to and room.logic:trigger(event, room:getPlayerById(cardEffectEvent.to), cardEffectEvent) then
|
||||
room.logic:breakEvent()
|
||||
end
|
||||
|
||||
room:handleCardEffect(event, cardEffectEvent)
|
||||
|
|
|
@ -23,11 +23,11 @@ function GameLogic:initialize(room)
|
|||
self.event_recorder = {}
|
||||
self.current_event_id = 0
|
||||
|
||||
self.role_table = {{"lord"}, {"lord", "rebel"}, {"lord", "rebel", "renegade"},
|
||||
{"lord", "loyalist", "rebel", "renegade"}, {"lord", "loyalist", "rebel", "rebel", "renegade"},
|
||||
{"lord", "loyalist", "rebel", "rebel", "rebel", "renegade"},
|
||||
{"lord", "loyalist", "loyalist", "rebel", "rebel", "rebel", "renegade"},
|
||||
{"lord", "loyalist", "loyalist", "rebel", "rebel", "rebel", "rebel", "renegade"}}
|
||||
self.role_table = { { "lord" }, { "lord", "rebel" }, { "lord", "rebel", "renegade" },
|
||||
{ "lord", "loyalist", "rebel", "renegade" }, { "lord", "loyalist", "rebel", "rebel", "renegade" },
|
||||
{ "lord", "loyalist", "rebel", "rebel", "rebel", "renegade" },
|
||||
{ "lord", "loyalist", "loyalist", "rebel", "rebel", "rebel", "renegade" },
|
||||
{ "lord", "loyalist", "loyalist", "rebel", "rebel", "rebel", "rebel", "renegade" } }
|
||||
end
|
||||
|
||||
function GameLogic:run()
|
||||
|
@ -117,11 +117,11 @@ function GameLogic:chooseGenerals()
|
|||
lord_general = lord_generals[1]
|
||||
else
|
||||
lord_general = lord_generals
|
||||
lord_generals = {lord_general}
|
||||
lord_generals = { lord_general }
|
||||
end
|
||||
|
||||
room:setPlayerGeneral(lord, lord_general, true)
|
||||
room:askForChooseKingdom({lord})
|
||||
room:askForChooseKingdom({ lord })
|
||||
room:broadcastProperty(lord, "general")
|
||||
room:broadcastProperty(lord, "kingdom")
|
||||
room:setDeputyGeneral(lord, deputy)
|
||||
|
@ -136,7 +136,7 @@ function GameLogic:chooseGenerals()
|
|||
for i = 1, generalNum do
|
||||
table.insert(arg, table.remove(generals, 1).name)
|
||||
end
|
||||
p.request_data = json.encode {arg, n}
|
||||
p.request_data = json.encode { arg, n }
|
||||
p.default_reply = table.random(arg, n)
|
||||
end
|
||||
|
||||
|
@ -163,7 +163,7 @@ end
|
|||
function GameLogic:buildPlayerCircle()
|
||||
local room = self.room
|
||||
local players = room.players
|
||||
room.alive_players = {table.unpack(players)}
|
||||
room.alive_players = { table.unpack(players) }
|
||||
for i = 1, #players - 1 do
|
||||
players[i].next = players[i + 1]
|
||||
end
|
||||
|
@ -264,7 +264,7 @@ function GameLogic:prepareForStart()
|
|||
self:addTriggerSkill(trig)
|
||||
end
|
||||
|
||||
self.room:sendLog{
|
||||
self.room:sendLog {
|
||||
type = "$GameStart"
|
||||
}
|
||||
end
|
||||
|
@ -324,7 +324,6 @@ function GameLogic:addTriggerSkill(skill)
|
|||
end
|
||||
|
||||
if not table.contains(self.skill_priority_table[event], skill.priority_table[event]) then
|
||||
|
||||
table.insert(self.skill_priority_table[event], skill.priority_table[event])
|
||||
end
|
||||
end
|
||||
|
@ -498,7 +497,6 @@ function GameLogic:dumpAllEvents(from, to)
|
|||
from = from or 1
|
||||
to = to or #self.all_game_events
|
||||
assert(from <= to)
|
||||
|
||||
local indent = 0
|
||||
local tab = " "
|
||||
for i = from, to, 1 do
|
||||
|
|
Loading…
Reference in New Issue