初始化提交
This commit is contained in:
71
Content/Lua/GamePlay/Ability/Common/RoleConsume.lua
Normal file
71
Content/Lua/GamePlay/Ability/Common/RoleConsume.lua
Normal file
@ -0,0 +1,71 @@
|
||||
local Ability = {}
|
||||
local Reactive = require("Core.Reactive")
|
||||
local GetGameplayTag = require("GamePlay.Utils").GetGameplayTag
|
||||
local AbilitySystemBlueprintLibrary = import("AbilitySystemBlueprintLibrary")
|
||||
|
||||
local hunger_consume_tag_name = "Buff.RoleConsume.Hunger"
|
||||
local health_consume_tag_name = "Buff.RoleConsume.Health"
|
||||
|
||||
function Ability:K2_ActivateAbilityFromEvent(_)
|
||||
print("Role Consume Ability:K2_ActivateAbility")
|
||||
if self.hunger_watcher ~= nil then
|
||||
self.hunger_watcher:Destroy()
|
||||
end
|
||||
self.hunger_watcher = Reactive.Watcher(function() self:ConsumeWatcher() end)
|
||||
end
|
||||
|
||||
function Ability:ConsumeWatcher()
|
||||
local owner = self:GetOwningActorFromActorInfo()
|
||||
local asc = owner["RoleAbility"]
|
||||
if owner.LuaRoleAttribute.Hunger > 0 then
|
||||
if not asc:IsGameplayCueActive(GetGameplayTag(hunger_consume_tag_name)) then
|
||||
self:ApplyHungerConsume(asc)
|
||||
end
|
||||
if asc:IsGameplayCueActive(GetGameplayTag(health_consume_tag_name)) then
|
||||
if self.health_consume_handle ~= nil then
|
||||
asc:RemoveActiveGameplayEffect(self.health_consume_handle, -1)
|
||||
end
|
||||
self.health_consume_handle = nil
|
||||
end
|
||||
elseif owner.LuaRoleAttribute.Hunger <= 0 then
|
||||
if not asc:IsGameplayCueActive(GetGameplayTag(health_consume_tag_name)) then
|
||||
self:ApplyHealthConsume(asc)
|
||||
end
|
||||
if asc:IsGameplayCueActive(GetGameplayTag(hunger_consume_tag_name)) then
|
||||
if self.hunger_consume_handle ~= nil then
|
||||
asc:RemoveActiveGameplayEffect(self.hunger_consume_handle, -1)
|
||||
end
|
||||
self.hunger_consume_handle = nil
|
||||
owner.LuaRoleAttribute.Hunger = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Ability:ApplyConsumeEffect(asc, effect_tag_name, value)
|
||||
local spec_handle = asc:MakeOutgoingSpec(
|
||||
self.EffectConfigs:Get(GetGameplayTag(effect_tag_name)),
|
||||
1, asc:MakeEffectContext()
|
||||
)
|
||||
AbilitySystemBlueprintLibrary.AssignTagSetByCallerMagnitude(
|
||||
spec_handle, GetGameplayTag(effect_tag_name), value
|
||||
)
|
||||
return asc:BP_ApplyGameplayEffectSpecToSelf(spec_handle)
|
||||
end
|
||||
|
||||
function Ability:ApplyHungerConsume(asc)
|
||||
local owner = asc:GetOwner()
|
||||
local consume_speed_peer_second = owner.RoleConfig.HungerConsumeSpeed
|
||||
self.hunger_consume_handle = self:ApplyConsumeEffect(
|
||||
asc, hunger_consume_tag_name, -consume_speed_peer_second / 10
|
||||
)
|
||||
end
|
||||
|
||||
function Ability:ApplyHealthConsume(asc)
|
||||
local owner = asc:GetOwner()
|
||||
local consume_speed_peer_second = owner.RoleConfig.HungerConsumeSpeed
|
||||
self.health_consume_handle = self:ApplyConsumeEffect(
|
||||
asc, health_consume_tag_name, -consume_speed_peer_second/10
|
||||
)
|
||||
end
|
||||
|
||||
return Class(nil, nil, Ability)
|
||||
Reference in New Issue
Block a user