增加ChangeProperty事件,修正remove (#259)

This commit is contained in:
RalphRad 2023-08-27 20:19:55 +08:00 committed by GitHub
parent efe78811f7
commit fa3fc966a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 162 additions and 40 deletions

View File

@ -60,7 +60,8 @@ function UsableSkill:withinDistanceLimit(player, isattack, card, to)
end end
local temp_suf = table.simpleClone(MarkEnum.TempMarkSuffix) local temp_suf = table.simpleClone(MarkEnum.TempMarkSuffix)
table.insert(temp_suf, "-tmp") table.insert(temp_suf, "-tmp")
return isattack and player:inMyAttackRange(to) or player:distanceTo(to) <= self:getDistanceLimit(player, card, to) or return (isattack and player:inMyAttackRange(to)) or
(player:distanceTo(to) > 0 and player:distanceTo(to) <= self:getDistanceLimit(player, card, to)) or
(player:getMark(MarkEnum.BypassDistancesLimit) ~= 0 or (player:getMark(MarkEnum.BypassDistancesLimit) ~= 0 or
table.find(temp_suf, function(s) table.find(temp_suf, function(s)
return player:getMark(MarkEnum.BypassDistancesLimit .. s) ~= 0 return player:getMark(MarkEnum.BypassDistancesLimit .. s) ~= 0

View File

@ -41,6 +41,9 @@ dofile "lua/server/events/gameflow.lua"
GameEvent.Pindian = 19 GameEvent.Pindian = 19
dofile "lua/server/events/pindian.lua" dofile "lua/server/events/pindian.lua"
GameEvent.ChangeProperty = 21
dofile "lua/server/events/misc.lua"
-- TODO: fix this -- TODO: fix this
GameEvent.BreakEvent = 999 GameEvent.BreakEvent = 999
@ -72,6 +75,8 @@ local eventTranslations = {
[GameEvent.Phase] = "GameEvent.Phase", [GameEvent.Phase] = "GameEvent.Phase",
[GameEvent.Pindian] = "GameEvent.Pindian", [GameEvent.Pindian] = "GameEvent.Pindian",
[GameEvent.ChangeProperty] = "GameEvent.ChangeProperty",
[GameEvent.BreakEvent] = "GameEvent.BreakEvent", [GameEvent.BreakEvent] = "GameEvent.BreakEvent",
} }

114
lua/server/events/misc.lua Normal file
View File

@ -0,0 +1,114 @@
-- SPDX-License-Identifier: GPL-3.0-or-later
GameEvent.functions[GameEvent.ChangeProperty] = function(self)
local data = table.unpack(self.data)
local room = self.room
local player = data.from
local logic = room.logic
logic:trigger(fk.BeforePropertyChange, player, data)
data.sendLog = data.sendLog or false
local skills = {}
if data.general and data.general ~= "" and data.general ~= player.general then
local originalGeneral = Fk.generals[player.general] or Fk.generals["blank_shibing"]
local originalSkills = originalGeneral and originalGeneral:getSkillNameList() or Util.DummyTable
table.insertTableIfNeed(skills, table.map(originalSkills, function(e)
return "-" .. e
end))
local newGeneral = Fk.generals[data.general] or Fk.generals["blank_shibing"]
for _, name in ipairs(newGeneral:getSkillNameList()) do
local s = Fk.skills[name]
if not s.relate_to_place or s.relate_to_place == "m" then
table.insertIfNeed(skills, name)
end
end
if data.sendLog then
room:sendLog{
type = "#ChangeHero",
from = player.id,
arg = player.general,
arg2 = data.general,
arg3 = "mainGeneral",
}
end
data.results["generalChange"] = {player.general, data.general}
room:setPlayerProperty(player, "general", data.general)
end
if data.deputyGeneral and data.deputyGeneral ~= "" and data.deputyGeneral ~= player.deputyGeneral then
local originalDeputy = Fk.generals[player.deputyGeneral] or Fk.generals["blank_shibing"]
local originalSkills = originalDeputy and originalDeputy:getSkillNameList() or Util.DummyTable
table.insertTableIfNeed(skills, table.map(originalSkills, function(e)
return "-" .. e
end))
local newDeputy = Fk.generals[data.deputyGeneral] or Fk.generals["blank_shibing"]
for _, name in ipairs(newDeputy:getSkillNameList()) do
local s = Fk.skills[name]
if not s.relate_to_place or s.relate_to_place == "d" then
table.insertIfNeed(skills, name)
end
end
if data.sendLog then
room:sendLog{
type = "#ChangeHero",
from = player.id,
arg = player.deputyGeneral,
arg2 = data.deputyGeneral,
arg3 = "deputyGeneral",
}
end
data.results["deputyChange"] = {player.deputyGeneral, data.deputyGeneral}
room:setPlayerProperty(player, "deputyGeneral", data.deputyGeneral)
end
if data.gender and data.gender ~= player.gender then
data.results["genderChange"] = {player.gender, data.gender}
room:setPlayerProperty(player, "gender", data.gender)
end
if data.kingdom and data.kingdom ~= "" and data.kingdom ~= player.kingdom then
if data.sendLog then
room:sendLog{
type = "#ChangeKingdom",
from = player.id,
arg = player.kingdom,
arg2 = data.kingdom,
}
end
data.results["kingdomChange"] = {player.kingdom, data.kingdom}
room:setPlayerProperty(player, "kingdom", data.kingdom)
end
for _, s in ipairs(Fk.generals[player.general].skills) do
if #s.attachedKingdom > 0 then
if table.contains(s.attachedKingdom, player.kingdom) then
table.insertIfNeed(skills, s.name)
else
if table.contains(skills, s.name) then
table.removeOne(skills, s.name)
else
table.insertIfNeed(skills, "-"..s.name)
end
end
end
end
if player.deputyGeneral ~= "" then
for _, s in ipairs(Fk.generals[player.deputyGeneral].skills) do
if #s.attachedKingdom > 0 then
if table.contains(s.attachedKingdom, player.kingdom) then
table.insertIfNeed(skills, s.name)
else
if table.contains(skills, s.name) then
table.removeOne(skills, s.name)
else
table.insertIfNeed(skills, "-"..s.name)
end
end
end
end
end
room:handleAddLoseSkills(player, table.concat(skills, "|"), nil, data.sendLog, false)
logic:trigger(fk.AfterPropertyChange, player, data)
end

View File

@ -542,6 +542,12 @@ function Room:removeTag(tag_name)
self.tag[tag_name] = nil self.tag[tag_name] = nil
end end
local function execGameEvent(type, ...)
local event = GameEvent:new(type, ...)
local _, ret = event:exec()
return ret
end
---@param player ServerPlayer ---@param player ServerPlayer
---@param general string ---@param general string
---@param changeKingdom bool ---@param changeKingdom bool
@ -578,33 +584,29 @@ end
---@param sendLog bool @ 是否发Log ---@param sendLog bool @ 是否发Log
---@param maxHpChange bool @ 是否改变体力上限,默认改变 ---@param maxHpChange bool @ 是否改变体力上限,默认改变
function Room:changeHero(player, new_general, full, isDeputy, sendLog, maxHpChange) function Room:changeHero(player, new_general, full, isDeputy, sendLog, maxHpChange)
local orig = isDeputy and (player.deputyGeneral or "") or player.general
orig = Fk.generals[orig]
local orig_skills = orig and orig:getSkillNameList() or Util.DummyTable
local new = Fk.generals[new_general] or Fk.generals["sunce"] or Fk.generals["blank_shibing"] local new = Fk.generals[new_general] or Fk.generals["sunce"] or Fk.generals["blank_shibing"]
local new_skills = {}
for _, sname in ipairs(new:getSkillNameList()) do local kingdom = isDeputy and player.kingdom or new.kingdom
local s = Fk.skills[sname] if not isDeputy and (new.kingdom == "god" or new.subkingdom) then
if not s.relate_to_place or s.relate_to_place == (isDeputy and "d" or "m") then local allKingdoms = {}
table.insert(new_skills, sname) if new.kingdom == "god" then
allKingdoms = {"wei", "shu", "wu", "qun", "jin"}
elseif new.subkingdom then
allKingdoms = { new.kingdom, new.subkingdom }
end end
kingdom = self:askForChoice(player, allKingdoms, "AskForKingdom", "#ChooseInitialKingdom")
end end
table.insertTable(new_skills, table.map(orig_skills, function(e) execGameEvent(GameEvent.ChangeProperty,
return "-" .. e {
end)) from = player,
general = not isDeputy and new_general or "",
self:handleAddLoseSkills(player, table.concat(new_skills, "|"), nil, false) deputyGeneral = isDeputy and new_general or "",
gender = isDeputy and player.gender or new.gender,
if isDeputy then kingdom = kingdom,
self:setPlayerProperty(player, "deputyGeneral", new_general) sendLog = sendLog,
else results = {},
self:setPlayerProperty(player, "general", new_general) })
self:setPlayerProperty(player, "gender", new.gender)
self:setPlayerProperty(player, "kingdom", new.kingdom)
end
maxHpChange = (maxHpChange == nil) and true or maxHpChange maxHpChange = (maxHpChange == nil) and true or maxHpChange
if maxHpChange then if maxHpChange then
@ -613,16 +615,22 @@ function Room:changeHero(player, new_general, full, isDeputy, sendLog, maxHpChan
if full or player.hp > player.maxHp then if full or player.hp > player.maxHp then
self:setPlayerProperty(player, "hp", player.maxHp) self:setPlayerProperty(player, "hp", player.maxHp)
end end
end
if sendLog then ---@param player ServerPlayer @ 要变更势力的玩家
self:sendLog{ ---@param kingdom string @ 要变更的势力
type = "#ChangeHero", ---@param sendLog bool @ 是否发Log
from = player.id, function Room:changeKingdom(player, kingdom, sendLog)
arg = orig and orig.name or "noGeneral", if kingdom == player.kingdom then return end
arg2 = new.name, sendLog = sendLog or false
arg3 = isDeputy and "deputyGeneral" or "mainGeneral"
} execGameEvent(GameEvent.ChangeProperty,
end {
from = player,
kingdom = kingdom,
sendLog = sendLog,
results = {},
})
end end
------------------------------------------------------------------------ ------------------------------------------------------------------------
@ -1486,7 +1494,7 @@ function Room:askForSkillInvoke(player, skill_name, data, prompt)
return invoked return invoked
end end
--枚举法为使用牌重选目标(无距离限制) --为使用牌增减目标
---@param player ServerPlayer @ 执行的玩家 ---@param player ServerPlayer @ 执行的玩家
---@param targets ServerPlayer[] @ 可选的目标范围 ---@param targets ServerPlayer[] @ 可选的目标范围
---@param num integer @ 可选的目标数 ---@param num integer @ 可选的目标数
@ -2104,12 +2112,6 @@ end
-- 使用牌 -- 使用牌
------------------------------------------------------------------------ ------------------------------------------------------------------------
local function execGameEvent(type, ...)
local event = GameEvent:new(type, ...)
local _, ret = event:exec()
return ret
end
--- 根据卡牌使用数据,去实际使用这个卡牌。 --- 根据卡牌使用数据,去实际使用这个卡牌。
---@param cardUseEvent CardUseStruct @ 使用数据 ---@param cardUseEvent CardUseStruct @ 使用数据
---@return boolean ---@return boolean