miduo_server/luafight/Modules/Battle/Logic/Buff/PropertyChange.lua

69 lines
2.3 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Modules/Battle/Logic/Base/Buff")
PropertyChange = Buff:New()
--初始化Buff通过传入一些自定义参数控制成长相关的数值
function PropertyChange:SetData(...)
--log("PropertyChange:SetData")
self.propertyName,
self.Value,
self.changeType = ...
self.cover = false --默认不可叠加
self.layer = 1
self.maxLayer = 0
end
--初始化后调用一次
function PropertyChange:OnStart()
--log("PropertyChange:OnStart")
if self.changeType == 1 then --加算
self.delta = self.target.data:AddValue(self.propertyName, self.Value)
self.isBuff = true
elseif self.changeType == 2 then --乘加算(百分比属性加算)
self.delta = self.target.data:AddPencentValue(self.propertyName, self.Value)
self.isBuff = true
elseif self.changeType == 3 then --减算
self.delta = self.target.data:SubValue(self.propertyName, self.Value)
self.isDeBuff = true
elseif self.changeType == 4 then --乘减算(百分比属性减算)
self.delta = self.target.data:SubPencentValue(self.propertyName, self.Value)
self.isDeBuff = true
end
end
--间隔N帧触发返回true时表示继续触发返回false立刻触发OnEnd
function PropertyChange:OnTrigger()
--log("PropertyChange:OnTrigger")
return true
end
--效果结束时调用一次
function PropertyChange:OnEnd()
--log("PropertyChange:OnEnd")
if self.changeType == 3 or self.changeType == 4 then
self.target.data:AddValue(self.propertyName, self.delta)
else
self.target.data:SubDeltaValue(self.propertyName, self.delta)
end
end
--只有当Cover字段为true时触发返回true则被新效果覆盖
function PropertyChange:OnCover(newBuff)
--log("PropertyChange:OnCover")
local b = self.propertyName == newBuff.propertyName and self.changeType == newBuff.changeType
if b then
if newBuff.maxLayer == 0 then
newBuff.layer = self.layer + 1
newBuff.Value = newBuff.Value + self.Value
else
if self.layer < newBuff.maxLayer then
newBuff.Value = newBuff.Value + self.Value
else
newBuff.Value = self.Value
end
newBuff.layer = math.min(self.layer + 1, newBuff.maxLayer)
end
end
return b
end
return PropertyChange