Better trigger (#45)

* set gamerule a refresh trigger skill

* cost and use of trigger skill
This commit is contained in:
notify 2023-01-16 21:04:28 +08:00 committed by GitHub
parent 1dd9abda14
commit 2ab79a26fb
4 changed files with 42 additions and 12 deletions

View File

@ -41,15 +41,42 @@ function TriggerSkill:triggerable(event, target, player, data)
and (self.global or (target:isAlive() and target:hasSkill(self))) and (self.global or (target:isAlive() and target:hasSkill(self)))
end end
---Trigger this skill -- Determine how to cost this skill.
---@param event Event @ TriggerEvent ---@param event Event @ TriggerEvent
---@param target ServerPlayer @ Player who triggered this event ---@param target ServerPlayer @ Player who triggered this event
---@param player ServerPlayer @ Player who is operating ---@param player ServerPlayer @ Player who is operating
---@param data any @ useful data of the event ---@param data any @ useful data of the event
---@return boolean @ returns true if trigger is broken ---@return boolean @ returns true if trigger is broken
function TriggerSkill:trigger(event, target, player, data) function TriggerSkill:trigger(event, target, player, data)
return self:doCost(event, target, player, data)
end
-- do cost and skill effect.
-- DO NOT modify this function
function TriggerSkill:doCost(event, target, player, data)
local ret = self:cost(event, target, player, data)
if ret then
local room = player.room
room:notifySkillInvoked(player, self.name)
ret = self:use(event, target, player, data)
return ret
end
end
-- ask player how to use this skill.
---@param event Event @ TriggerEvent
---@param target ServerPlayer @ Player who triggered this event
---@param player ServerPlayer @ Player who is operating
---@param data any @ useful data of the event
---@return boolean @ returns true if trigger is broken
function TriggerSkill:cost(event, target, player, data)
local ret = false
if self.frequency == Skill.Compulsory then
return true
end
if player.room:askForSkillInvoke(player, self.name) then if player.room:askForSkillInvoke(player, self.name) then
return self:use(event, target, player, data) return true
end end
return false return false
end end

View File

@ -26,6 +26,8 @@ _, Weapon, Armor, DefensiveRide, OffensiveRide, Treasure = table.unpack(Equip)
---@field priority number | table<Event, number> ---@field priority number | table<Event, number>
---@field on_trigger TrigFunc ---@field on_trigger TrigFunc
---@field can_trigger TrigFunc ---@field can_trigger TrigFunc
---@field on_cost TrigFunc
---@field on_use TrigFunc
---@field on_refresh TrigFunc ---@field on_refresh TrigFunc
---@field can_refresh TrigFunc ---@field can_refresh TrigFunc
@ -59,6 +61,9 @@ function fk.CreateTriggerSkill(spec)
skill.triggerable = spec.can_trigger skill.triggerable = spec.can_trigger
end end
if spec.on_cost then skill.cost = spec.on_cost end
if spec.on_use then skill.use = spec.on_use end
if spec.can_refresh then if spec.can_refresh then
skill.canRefresh = spec.can_refresh skill.canRefresh = spec.can_refresh
end end

View File

@ -38,7 +38,7 @@ end
GameRule = fk.CreateTriggerSkill{ GameRule = fk.CreateTriggerSkill{
name = "game_rule", name = "game_rule",
events = { refresh_events = {
fk.GameStart, fk.DrawInitialCards, fk.TurnStart, fk.GameStart, fk.DrawInitialCards, fk.TurnStart,
fk.EventPhaseProceeding, fk.EventPhaseEnd, fk.EventPhaseChanging, fk.EventPhaseProceeding, fk.EventPhaseEnd, fk.EventPhaseChanging,
fk.AskForPeaches, fk.AskForPeachesDone, fk.AskForPeaches, fk.AskForPeachesDone,
@ -46,11 +46,11 @@ GameRule = fk.CreateTriggerSkill{
}, },
priority = 0, priority = 0,
can_trigger = function(self, event, target, player, data) can_refresh = function(self, event, target, player, data)
return (target == player) or (target == nil) return (target == player) or (target == nil)
end, end,
on_trigger = function(self, event, target, player, data) on_refresh = function(self, event, target, player, data)
if RoomInstance.tag["SkipGameRule"] then if RoomInstance.tag["SkipGameRule"] then
RoomInstance.tag["SkipGameRule"] = false RoomInstance.tag["SkipGameRule"] = false
return false return false

View File

@ -31,16 +31,14 @@ local fankui = fk.CreateTriggerSkill{
local from = room:getPlayerById(data.from) local from = room:getPlayerById(data.from)
return from ~= nil and return from ~= nil and
target == player and target == player and
target:hasSkill(self.name) target:hasSkill(self.name) and
not target.dead
end, end,
on_trigger = function(self, event, target, player, data) on_use = function(self, event, target, player, data)
local room = player.room local room = player.room
local from = room:getPlayerById(data.from) local from = room:getPlayerById(data.from)
if (not from) or from:isNude() then return false end local card = room:askForCardChosen(player, from, "he", self.name)
if room:askForSkillInvoke(player, self.name) then room:obtainCard(player.id, card, false)
local card = room:askForCardChosen(player, from, "he", self.name)
room:obtainCard(player.id, card, false, fk.ReasonPrey)
end
end end
} }
local simayi = General:new(extension, "simayi", "wei", 3) local simayi = General:new(extension, "simayi", "wei", 3)