mirror of
https://github.com/Qsgs-Fans/FreeKill.git
synced 2024-11-15 19:22:25 +08:00
增加ChangeProperty事件,修正remove (#259)
This commit is contained in:
parent
efe78811f7
commit
fa3fc966a9
|
@ -60,7 +60,8 @@ function UsableSkill:withinDistanceLimit(player, isattack, card, to)
|
|||
end
|
||||
local temp_suf = table.simpleClone(MarkEnum.TempMarkSuffix)
|
||||
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
|
||||
table.find(temp_suf, function(s)
|
||||
return player:getMark(MarkEnum.BypassDistancesLimit .. s) ~= 0
|
||||
|
|
|
@ -41,6 +41,9 @@ dofile "lua/server/events/gameflow.lua"
|
|||
GameEvent.Pindian = 19
|
||||
dofile "lua/server/events/pindian.lua"
|
||||
|
||||
GameEvent.ChangeProperty = 21
|
||||
dofile "lua/server/events/misc.lua"
|
||||
|
||||
-- TODO: fix this
|
||||
GameEvent.BreakEvent = 999
|
||||
|
||||
|
@ -72,6 +75,8 @@ local eventTranslations = {
|
|||
[GameEvent.Phase] = "GameEvent.Phase",
|
||||
[GameEvent.Pindian] = "GameEvent.Pindian",
|
||||
|
||||
[GameEvent.ChangeProperty] = "GameEvent.ChangeProperty",
|
||||
|
||||
[GameEvent.BreakEvent] = "GameEvent.BreakEvent",
|
||||
}
|
||||
|
||||
|
|
114
lua/server/events/misc.lua
Normal file
114
lua/server/events/misc.lua
Normal 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
|
|
@ -542,6 +542,12 @@ function Room:removeTag(tag_name)
|
|||
self.tag[tag_name] = nil
|
||||
end
|
||||
|
||||
local function execGameEvent(type, ...)
|
||||
local event = GameEvent:new(type, ...)
|
||||
local _, ret = event:exec()
|
||||
return ret
|
||||
end
|
||||
|
||||
---@param player ServerPlayer
|
||||
---@param general string
|
||||
---@param changeKingdom bool
|
||||
|
@ -578,33 +584,29 @@ end
|
|||
---@param sendLog bool @ 是否发Log
|
||||
---@param maxHpChange bool @ 是否改变体力上限,默认改变
|
||||
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_skills = {}
|
||||
for _, sname in ipairs(new:getSkillNameList()) do
|
||||
local s = Fk.skills[sname]
|
||||
if not s.relate_to_place or s.relate_to_place == (isDeputy and "d" or "m") then
|
||||
table.insert(new_skills, sname)
|
||||
|
||||
local kingdom = isDeputy and player.kingdom or new.kingdom
|
||||
if not isDeputy and (new.kingdom == "god" or new.subkingdom) then
|
||||
local allKingdoms = {}
|
||||
if new.kingdom == "god" then
|
||||
allKingdoms = {"wei", "shu", "wu", "qun", "jin"}
|
||||
elseif new.subkingdom then
|
||||
allKingdoms = { new.kingdom, new.subkingdom }
|
||||
end
|
||||
kingdom = self:askForChoice(player, allKingdoms, "AskForKingdom", "#ChooseInitialKingdom")
|
||||
end
|
||||
|
||||
table.insertTable(new_skills, table.map(orig_skills, function(e)
|
||||
return "-" .. e
|
||||
end))
|
||||
|
||||
self:handleAddLoseSkills(player, table.concat(new_skills, "|"), nil, false)
|
||||
|
||||
if isDeputy then
|
||||
self:setPlayerProperty(player, "deputyGeneral", new_general)
|
||||
else
|
||||
self:setPlayerProperty(player, "general", new_general)
|
||||
self:setPlayerProperty(player, "gender", new.gender)
|
||||
self:setPlayerProperty(player, "kingdom", new.kingdom)
|
||||
end
|
||||
execGameEvent(GameEvent.ChangeProperty,
|
||||
{
|
||||
from = player,
|
||||
general = not isDeputy and new_general or "",
|
||||
deputyGeneral = isDeputy and new_general or "",
|
||||
gender = isDeputy and player.gender or new.gender,
|
||||
kingdom = kingdom,
|
||||
sendLog = sendLog,
|
||||
results = {},
|
||||
})
|
||||
|
||||
maxHpChange = (maxHpChange == nil) and true or maxHpChange
|
||||
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
|
||||
self:setPlayerProperty(player, "hp", player.maxHp)
|
||||
end
|
||||
end
|
||||
|
||||
if sendLog then
|
||||
self:sendLog{
|
||||
type = "#ChangeHero",
|
||||
from = player.id,
|
||||
arg = orig and orig.name or "noGeneral",
|
||||
arg2 = new.name,
|
||||
arg3 = isDeputy and "deputyGeneral" or "mainGeneral"
|
||||
}
|
||||
end
|
||||
---@param player ServerPlayer @ 要变更势力的玩家
|
||||
---@param kingdom string @ 要变更的势力
|
||||
---@param sendLog bool @ 是否发Log
|
||||
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 = {},
|
||||
})
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
@ -1486,7 +1494,7 @@ function Room:askForSkillInvoke(player, skill_name, data, prompt)
|
|||
return invoked
|
||||
end
|
||||
|
||||
--枚举法为使用牌重选目标(无距离限制)
|
||||
--为使用牌增减目标
|
||||
---@param player ServerPlayer @ 执行的玩家
|
||||
---@param targets ServerPlayer[] @ 可选的目标范围
|
||||
---@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 @ 使用数据
|
||||
---@return boolean
|
||||
|
|
Loading…
Reference in New Issue
Block a user