refactor(fight/effect): 重构属性操作逻辑,新增AbilityOpType枚举并优化SetProp方法,支持多种能力操作类型

This commit is contained in:
1
2025-09-25 17:15:06 +00:00
parent 3f37ce63de
commit b62f956371
6 changed files with 62 additions and 24 deletions

View File

@@ -22,7 +22,7 @@ type Effect2 struct {
}
func (e *Effect2) PreSkill(opp *input.Input, skill *info.SkillEntity) {
opp.Prop(e.Input, func() { //我方取敌方防御
opp.Pet(e.Input, func() { //我方取敌方防御
if opp.CurrentPet.Info.Hp < (opp.CurrentPet.Info.MaxHp / 2) {
skill.Power *= 2

View File

@@ -42,13 +42,18 @@ type EffectStat struct {
func (e *EffectStat) AfterSkill(opp *input.Input, skill *info.SkillEntity) {
t, _, _ := e.Input.Player.Roll(e.EffectNode.SideEffectArgs[1], 100)
if t {
if !e.Etype { //自身
e.Input.SetProp(e.EffectNode.SideEffectArgs[0], e.EffectNode.SideEffectArgs[2])
if !t {
return
}
ptype := info.AbilityOpType.AbilityOpIncrease
if e.EffectNode.SideEffectArgs[2] < 0 {
ptype = info.AbilityOpType.AbilityOpDecrease
}
if !e.Etype { //自身
e.Input.SetProp(e.Input, e.EffectNode.SideEffectArgs[0], e.EffectNode.SideEffectArgs[2], ptype)
} else { //对方
opp.SetProp(e.EffectNode.SideEffectArgs[0], e.EffectNode.SideEffectArgs[2])
}
} else { //对方
opp.SetProp(e.Input, e.EffectNode.SideEffectArgs[0], e.EffectNode.SideEffectArgs[2], ptype)
}
}

View File

@@ -86,3 +86,18 @@ type Playerinvite struct { //挂载到[]Playerinvite上? 被邀请者->邀请
InviteID uint32 // 邀请者
InviteTime EnumBattleMode //游戏模式
}
// 能力操作类型枚举
type EnumAbilityOpType string
var AbilityOpType = enum.New[struct {
AbilityOpIncrease EnumAbilityOpType `enum:"1"` // 能力增加(强化)
AbilityOpDecrease EnumAbilityOpType `enum:"2"` // 能力减少(弱化)
AbilityOpCopy EnumAbilityOpType `enum:"3"` // 复制强化/弱化
AbilityOpReset EnumAbilityOpType `enum:"4"` // 能力重置
AbilityOpClearStrengthen EnumAbilityOpType `enum:"5"` // 清除强化
AbilityOpStealStrengthen EnumAbilityOpType `enum:"6"` // 吸取强化
AbilityOpReverse EnumAbilityOpType `enum:"7"` // 反转强化/弱化
AbilityOpClearWeaken EnumAbilityOpType `enum:"8"` // 解除弱化
AbilityOpTransferWeaken EnumAbilityOpType `enum:"9"` // 传递弱化
//AbilityOpBounceWeaken EnumAbilityOpType `enum:"10"` // 弹弱(反弹弱化效果)
}]()

View File

@@ -17,17 +17,15 @@ func (u *Input) Death() {
}
// 1是添加-1是减少0是清除
func (u *Input) SetProp(prop, level int) {
if level == 0 { //说明是消强
//todo 消强交互
func (u *Input) SetProp(in *Input, prop, level int, ptype info.EnumAbilityOpType) {
canuseskill := u.Exec(func(t Effect) bool { //这个是能否使用技能
//结算状态
return t.BeferProp(in, prop, level, ptype) //返回本身结算,如果false,说明不能使用技能了
})
if canuseskill {
u.AttackValue.Prop[prop] = u.AttackValue.Prop[prop] + int8(level)
}
//todo 待交互
u.AttackValue.Prop[prop] = u.AttackValue.Prop[prop] + int8(level)
//todo 待交互
}
func (i *Input) GetAction(opp *Input) {
@@ -38,6 +36,21 @@ func (i *Input) GetAction(opp *Input) {
// todo获取属性待实现获取后改回原属性
func (i *Input) Prop(in *Input, f func()) {
oldourr := deepcopy.Copy(in).(*Input)
in.Exec(func(t Effect) bool { //属性获取后
t.AfterProp(i) //视为xx 需要在里面判断来源
return true
})
f()
in = oldourr
//opp.CurrentPet = oldouo //恢复
}
// todo获取属性待实现获取后改回原属性
func (i *Input) Pet(in *Input, f func()) {
oldour := deepcopy.Copy(i.CurrentPet).(*info.BattlePetEntity)
//oldouo := deepcopy.Copy(opp.CurrentPet).(*info.BattlePetEntity)
i.Exec(func(t Effect) bool { //属性获取前
@@ -86,20 +99,20 @@ func (i *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) decimal.
switch skill.Category() { //判断技能类型
case info.Category.PHYSICAL:
i.Prop(i, func() { //我方取我方攻击
i.Pet(i, func() { //我方取我方攻击
attackDec = decimal.NewFromInt(int64(i.GetProp(0, false)))
})
deftype.Prop(i, func() { //我方取敌方防御
deftype.Pet(i, func() { //我方取敌方防御
defenseDec = decimal.NewFromInt(int64(deftype.GetProp(1, false)))
})
case info.Category.SPECIAL:
i.Prop(i, func() { //我方取我方攻击
i.Pet(i, func() { //我方取我方攻击
attackDec = decimal.NewFromInt(int64(i.GetProp(2, false)))
})
deftype.Prop(i, func() { //我方取敌方防御
deftype.Pet(i, func() { //我方取敌方防御
defenseDec = decimal.NewFromInt(int64(deftype.GetProp(3, false)))
})
@@ -118,7 +131,7 @@ func (i *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) decimal.
var typeRate decimal.Decimal
deftype.Prop(i, func() { //我方取敌方属性,得到敌方的实际和我方的视为
deftype.Pet(i, func() { //我方取敌方属性,得到敌方的实际和我方的视为
t, _ := element.NewElementCalculator().GetOffensiveMultiplier(skill.Type().ID, deftype.CurrentPet.Type().ID)
typeRate = decimal.NewFromFloat(t)

View File

@@ -16,7 +16,8 @@ type Effect interface {
AfterSkill(opp *Input, skill *info.SkillEntity) // 技能命中后触发
// OnSkillPP() bool //技能PP减少节点
AfterProp(t *Input)
BeferProp(in *Input, prop, level int, ptype info.EnumAbilityOpType) bool
AfterAttr(t *info.BattlePetEntity) //在获取属性前,比如重写对方属性AfterAttr
BeferAttr(t *info.BattlePetEntity) //在获取属性后,比如视为对方属性
SetArgs(input *Input, param ...int)

View File

@@ -46,8 +46,12 @@ func (this *EffectNode) PostDamage() bool {
panic("not implemented") // TODO: Implement
}
func (this *EffectNode) OnDefeat() bool {
panic("not implemented") // TODO: Implement
}
func (this *EffectNode) AfterProp(t *input.Input) {
}
func (this *EffectNode) BeferProp(in *input.Input, prop, level int, ptype info.EnumAbilityOpType) bool {
return true
}