fix(logic/service/fight): 修正状态效果判断逻辑中的类型转换问题
将 StatEffect_Exist 方法的参数类型从 int 改为 info.EnumPetStatus, 并在调用 GetEffect 时进行显式类型转换,以提高代码可读性和类型安全性。 同时清理了部分冗余的类型转换调用。
This commit is contained in:
113
logic/service/fight/effect/effect_133.go
Normal file
113
logic/service/fight/effect/effect_133.go
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
package effect
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/logic/service/fight/info"
|
||||||
|
"blazing/logic/service/fight/input"
|
||||||
|
"blazing/logic/service/fight/node"
|
||||||
|
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// -----------------------------------------------------------
|
||||||
|
// 通用效果:满足特定条件时,附加n点固定伤害
|
||||||
|
// -----------------------------------------------------------
|
||||||
|
// 条件回调函数:判断对方是否满足触发条件(返回true则触发伤害)
|
||||||
|
type conditionFunc func(e *EffectConditionalAddDamage) bool
|
||||||
|
|
||||||
|
type EffectConditionalAddDamage struct {
|
||||||
|
node.EffectNode
|
||||||
|
condition conditionFunc // 差异化:判断触发条件的函数
|
||||||
|
}
|
||||||
|
|
||||||
|
// 工厂函数:创建"条件附加伤害"效果实例,传入条件判断函数
|
||||||
|
func newEffectConditionalAddDamage(cond conditionFunc) *EffectConditionalAddDamage {
|
||||||
|
return &EffectConditionalAddDamage{
|
||||||
|
condition: cond,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化:批量注册所有"条件附加伤害"类效果
|
||||||
|
func init() {
|
||||||
|
registerConditionalAddDamageEffects()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量注册:绑定效果ID与对应的条件函数(可扩展)
|
||||||
|
func registerConditionalAddDamageEffects() {
|
||||||
|
// 效果ID与条件函数的映射:
|
||||||
|
// 133: 对方烧伤时附加伤害;134:对方冻伤时附加伤害;135:对方是X属性时附加伤害;136:对方处于异常状态时附加伤害
|
||||||
|
effectMap := map[int]conditionFunc{
|
||||||
|
133: conditionIsBurned, // Effect133:对方烧伤时
|
||||||
|
141: conditionIsFrozen, // 新增:对方冻伤时
|
||||||
|
135: conditionIsAbnormal, // 新增:对方是X属性时(示例,需根据实际属性枚举调整)
|
||||||
|
130: conditionIsTypeX, // 新增:对方处于任意异常状态时
|
||||||
|
167: conditionprop, //167 若对手处于能力下降状态则附加n点伤害
|
||||||
|
}
|
||||||
|
|
||||||
|
// 循环注册所有效果
|
||||||
|
for effectID, cond := range effectMap {
|
||||||
|
input.InitEffect(input.EffectType.Skill, effectID, newEffectConditionalAddDamage(cond))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------
|
||||||
|
// 核心共性逻辑:命中且满足条件时,附加固定伤害
|
||||||
|
// -----------------------------------------------------------
|
||||||
|
func (e *EffectConditionalAddDamage) OnSkill() bool {
|
||||||
|
// 1. 命中判定失败,不触发
|
||||||
|
if !e.Hit() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 检查是否满足触发条件(调用差异化的条件函数)
|
||||||
|
if !e.condition(e) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 附加固定伤害(伤害值从SideEffectArgs[0]获取,与原Effect133一致)
|
||||||
|
damageValue := decimal.NewFromInt(int64(e.SideEffectArgs[0]))
|
||||||
|
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
||||||
|
Type: info.DamageType.Fixed,
|
||||||
|
Damage: damageValue,
|
||||||
|
})
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------
|
||||||
|
// 差异化条件函数的实现(对应不同效果的判断逻辑)
|
||||||
|
// -----------------------------------------------------------
|
||||||
|
|
||||||
|
// conditionIsBurned:判断对方是否处于烧伤状态(对应原Effect133)
|
||||||
|
func conditionIsBurned(e *EffectConditionalAddDamage) bool {
|
||||||
|
return e.Ctx().Opp.StatEffect_Exist(info.PetStatus.Burned)
|
||||||
|
}
|
||||||
|
|
||||||
|
// conditionIsFrozen:判断对方是否处于冻伤状态(新增效果)
|
||||||
|
func conditionIsFrozen(e *EffectConditionalAddDamage) bool {
|
||||||
|
return e.Ctx().Opp.StatEffect_Exist(info.PetStatus.Frozen)
|
||||||
|
}
|
||||||
|
|
||||||
|
// conditionIsTypeX:判断对方是否为X属性(示例,需根据实际属性枚举调整)
|
||||||
|
// 假设属性枚举为info.PetType,X属性为info.PetType.X
|
||||||
|
func conditionIsTypeX(e *EffectConditionalAddDamage) bool {
|
||||||
|
return e.Ctx().Opp.CurrentPet.Gender == e.Args()[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// conditionIsAbnormal:判断对方是否处于任意异常状态(新增效果)
|
||||||
|
// 假设异常状态包含烧伤、冻伤、麻痹等,通过检查是否存在任意异常状态实现
|
||||||
|
func conditionIsAbnormal(e *EffectConditionalAddDamage) bool {
|
||||||
|
return e.Ctx().Opp.StatEffect_Exist_all()
|
||||||
|
|
||||||
|
}
|
||||||
|
func conditionprop(e *EffectConditionalAddDamage) bool {
|
||||||
|
|
||||||
|
for _, v := range e.Ctx().Opp.Prop {
|
||||||
|
|
||||||
|
if v < 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
|
||||||
|
}
|
||||||
42
logic/service/fight/effect/effect_95.go
Normal file
42
logic/service/fight/effect/effect_95.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package effect
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/logic/service/fight/action"
|
||||||
|
"blazing/logic/service/fight/info"
|
||||||
|
"blazing/logic/service/fight/input"
|
||||||
|
"blazing/logic/service/fight/node"
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对手处于睡眠状态时,致命一击率提升n/16
|
||||||
|
*/
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
input.InitEffect(input.EffectType.Skill, 95, &Effect95{})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type Effect95 struct {
|
||||||
|
node.EffectNode
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Effect95) Skill_Hit_Pre(a, b *action.SelectSkillAction) bool {
|
||||||
|
if !e.Hit() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
//fmt.Println(e.Ctx().SkillEntity)
|
||||||
|
if e.Ctx().SkillEntity == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if e.Ctx().SkillEntity.Category() == info.Category.STATUS {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if !e.Ctx().Opp.StatEffect_Exist(input.StatusSleep) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
e.Ctx().SkillEntity.CritRate += e.Args()[0]
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
@@ -50,31 +50,31 @@ func init() {
|
|||||||
return i.FightC.IsFirst(i.Player)
|
return i.FightC.IsFirst(i.Player)
|
||||||
})
|
})
|
||||||
registerStatusFunc(64, func(i, o *input.Input) bool {
|
registerStatusFunc(64, func(i, o *input.Input) bool {
|
||||||
if i.StatEffect_Exist(int(info.PetStatus.Burned)) {
|
if i.StatEffect_Exist(info.PetStatus.Burned) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if i.StatEffect_Exist(int(info.PetStatus.Frozen)) {
|
if i.StatEffect_Exist(info.PetStatus.Frozen) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if i.StatEffect_Exist(int(info.PetStatus.Poisoned)) {
|
if i.StatEffect_Exist(info.PetStatus.Poisoned) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
registerStatusFunc(96, func(i, o *input.Input) bool {
|
registerStatusFunc(96, func(i, o *input.Input) bool {
|
||||||
return o.StatEffect_Exist(int(info.PetStatus.Burned))
|
return o.StatEffect_Exist(info.PetStatus.Burned)
|
||||||
})
|
})
|
||||||
registerStatusFunc(97, func(i, o *input.Input) bool {
|
registerStatusFunc(97, func(i, o *input.Input) bool {
|
||||||
return o.StatEffect_Exist(int(info.PetStatus.Frozen))
|
return o.StatEffect_Exist(info.PetStatus.Frozen)
|
||||||
})
|
})
|
||||||
registerStatusFunc(102, func(i, o *input.Input) bool {
|
registerStatusFunc(102, func(i, o *input.Input) bool {
|
||||||
return o.StatEffect_Exist(int(info.PetStatus.Paralysis))
|
return o.StatEffect_Exist(info.PetStatus.Paralysis)
|
||||||
})
|
})
|
||||||
registerStatusFunc(132, func(i, o *input.Input) bool {
|
registerStatusFunc(132, func(i, o *input.Input) bool {
|
||||||
return i.CurrentPet.Info.Hp < o.CurrentPet.Info.Hp
|
return i.CurrentPet.Info.Hp < o.CurrentPet.Info.Hp
|
||||||
})
|
})
|
||||||
registerStatusFunc(168, func(i, o *input.Input) bool {
|
registerStatusFunc(168, func(i, o *input.Input) bool {
|
||||||
return o.StatEffect_Exist(int(info.PetStatus.Sleep))
|
return o.StatEffect_Exist(info.PetStatus.Sleep)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ func (our *Input) GetEffect(etype EnumEffectType, id int) Effect {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (our *Input) StatEffect_Exist(id int) bool {
|
func (our *Input) StatEffect_Exist(id info.EnumPetStatus) bool {
|
||||||
t := our.GetEffect(EffectType.Status, id)
|
t := our.GetEffect(EffectType.Status, int(id))
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -102,6 +102,9 @@ func (our *Input) StatEffect_Exist_all() bool {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
func (our *Input) GetCurrAttr(id int) *model.PetInfo {
|
func (our *Input) GetCurrAttr(id int) *model.PetInfo {
|
||||||
|
|
||||||
//todo 获取前GetEffect
|
//todo 获取前GetEffect
|
||||||
|
|||||||
Reference in New Issue
Block a user