2023-08-27 13:22:03 +00:00
|
|
|
|
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2024-06-10 07:19:47 +00:00
|
|
|
|
---@class GameEvent.Game : GameEvent
|
|
|
|
|
local Game = GameEvent:subclass("GameEvent.Game")
|
|
|
|
|
function Game:main()
|
2024-01-10 14:51:29 +00:00
|
|
|
|
self.room.logic:run()
|
|
|
|
|
end
|
|
|
|
|
|
2024-06-10 07:19:47 +00:00
|
|
|
|
---@class GameEvent.ChangeProperty : GameEvent
|
|
|
|
|
local ChangeProperty = GameEvent:subclass("GameEvent.Game")
|
|
|
|
|
function ChangeProperty:main()
|
2023-08-27 13:22:03 +00:00
|
|
|
|
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 = {}
|
2023-09-27 13:02:22 +00:00
|
|
|
|
if logic:trigger(fk.PropertyChange, player, data) then
|
|
|
|
|
logic:breakEvent()
|
|
|
|
|
end
|
2023-08-27 13:22:03 +00:00
|
|
|
|
|
|
|
|
|
if data.general and data.general ~= "" and data.general ~= player.general then
|
|
|
|
|
local originalGeneral = Fk.generals[player.general] or Fk.generals["blank_shibing"]
|
2024-01-24 19:13:57 +00:00
|
|
|
|
local originalSkills = originalGeneral and originalGeneral:getSkillNameList(true) or Util.DummyTable
|
2023-08-27 13:22:03 +00:00
|
|
|
|
table.insertTableIfNeed(skills, table.map(originalSkills, function(e)
|
|
|
|
|
return "-" .. e
|
|
|
|
|
end))
|
|
|
|
|
local newGeneral = Fk.generals[data.general] or Fk.generals["blank_shibing"]
|
2024-01-24 19:13:57 +00:00
|
|
|
|
for _, name in ipairs(newGeneral:getSkillNameList(data.isLord)) do
|
2023-08-27 13:22:03 +00:00
|
|
|
|
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
|
|
|
|
|
|
2023-12-10 10:55:16 +00:00
|
|
|
|
if data.deputyGeneral and data.deputyGeneral ~= player.deputyGeneral then
|
2023-08-27 13:22:03 +00:00
|
|
|
|
local originalDeputy = Fk.generals[player.deputyGeneral] or Fk.generals["blank_shibing"]
|
2024-01-24 19:13:57 +00:00
|
|
|
|
local originalSkills = originalDeputy and originalDeputy:getSkillNameList(true) or Util.DummyTable
|
2023-08-27 13:22:03 +00:00
|
|
|
|
table.insertTableIfNeed(skills, table.map(originalSkills, function(e)
|
|
|
|
|
return "-" .. e
|
|
|
|
|
end))
|
2023-12-10 10:55:16 +00:00
|
|
|
|
|
|
|
|
|
if data.deputyGeneral ~= "" then
|
|
|
|
|
local newDeputy = Fk.generals[data.deputyGeneral] or Fk.generals["blank_shibing"]
|
2024-01-24 19:13:57 +00:00
|
|
|
|
for _, name in ipairs(newDeputy:getSkillNameList(data.isLord)) do
|
2023-12-10 10:55:16 +00:00
|
|
|
|
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",
|
|
|
|
|
}
|
2023-08-27 13:22:03 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2023-12-10 10:55:16 +00:00
|
|
|
|
|
2023-08-27 13:22:03 +00:00
|
|
|
|
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, false, false)
|
|
|
|
|
|
|
|
|
|
logic:trigger(fk.AfterPropertyChange, player, data)
|
|
|
|
|
end
|
2024-01-10 14:51:29 +00:00
|
|
|
|
|
2024-06-10 07:19:47 +00:00
|
|
|
|
---@class GameEvent.ClearEvent : GameEvent
|
|
|
|
|
local ClearEvent = GameEvent:subclass("GameEvent.ClearEvent")
|
|
|
|
|
function ClearEvent:main()
|
2024-01-10 14:51:29 +00:00
|
|
|
|
local event = self.data[1]
|
|
|
|
|
local logic = self.room.logic
|
2024-01-24 19:23:29 +00:00
|
|
|
|
-- 不可中断
|
2024-06-10 07:19:47 +00:00
|
|
|
|
Pcall(event.clear, event)
|
|
|
|
|
for _, f in ipairs(event.extra_clear) do
|
2024-01-24 19:23:29 +00:00
|
|
|
|
if type(f) == "function" then Pcall(f, event) end
|
2024-01-10 14:51:29 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- cleaner顺利执行完了,出栈吧
|
|
|
|
|
local end_id = logic.current_event_id + 1
|
|
|
|
|
if event.id ~= end_id - 1 then
|
|
|
|
|
logic.all_game_events[end_id] = event.event
|
|
|
|
|
logic.current_event_id = end_id
|
|
|
|
|
event.end_id = end_id
|
|
|
|
|
else
|
|
|
|
|
event.end_id = event.id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
logic.game_event_stack:pop()
|
|
|
|
|
logic.cleaner_stack:pop()
|
|
|
|
|
end
|
2024-06-10 07:19:47 +00:00
|
|
|
|
|
|
|
|
|
return { Game, ChangeProperty, ClearEvent }
|