Files
bl/logic/service/fight/input/prop.go
昔念 562bf380eb 根据提供的code differences信息,由于没有具体的代码变更内容,我将生成一个通用的commit message模板:
```
docs(changelog): 更新版本更新日志

- 添加新功能说明
- 修复已知问题记录
- 更新相关文档内容
```
2026-01-20 02:25:02 +08:00

152 lines
4.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package input
import (
"blazing/common/utils"
"blazing/logic/service/fight/info"
)
// 攻击,防御,特攻,特防,速度,命中
// 施加方source属性类型prop等级level操作类别opType返回是否成功
func (target *Input) SetProp(source *Input, prop, level int8, opType info.EnumAbilityOpType) bool {
// 前置状态结算:判断是否允许执行属性操作
canExecute := target.Exec(func(effect Effect) bool {
// 执行前置效果返回true表示可以继续操作
return effect.PropBefer(source, prop, level, opType)
})
if !canExecute {
return false
}
var newValue int8
// 计算新属性值并判断操作是否有效(属性是否会发生变化)
calcNewValue := func(p, l int8, t info.EnumAbilityOpType) bool {
switch t {
case info.AbilityOpType.ADD:
// 属性提升上限为6
newValue = utils.Min(target.AttackValue.Prop[p]+l, 6)
if newValue > target.AttackValue.Prop[p] {
//fmt.Println("属性值会增加")
return true
}
//fmt.Println("属性值不会增加")
return false
case info.AbilityOpType.SUB:
// 属性降低,下限为-6
newValue = utils.Max(target.AttackValue.Prop[p]+l, -6)
if newValue < target.AttackValue.Prop[p] {
//fmt.Println("属性值会减少")
return true
}
//fmt.Println("属性值不会减少")
return false
case info.AbilityOpType.RESET:
// 重置属性level>0时清除强化属性>0则置0level<0时清除弱化属性<0则置0
if (level > 0 && target.AttackValue.Prop[p] > 0) ||
(level < 0 && target.AttackValue.Prop[p] < 0) {
newValue = 0
return true
}
return false
}
return false
}
switch opType {
case info.AbilityOpType.StealStrengthen:
// 窃取强化:获取对手的强化属性并转移到自身
oppProp := target.Opp.AttackValue.Prop[prop]
if oppProp <= 0 { // 对手无强化,无法窃取
return false
}
// 尝试添加对手的强化值到自身
if calcNewValue(prop, oppProp, info.AbilityOpType.ADD) {
target.AttackValue.Prop[prop] = newValue
// 窃取后清除对手的强化
target.Opp.SetProp(source, prop, 1, info.AbilityOpType.RESET)
return true
}
return false
case info.AbilityOpType.Reverse:
currentProp := target.AttackValue.Prop[prop]
if level > 0 { // 反转强化(仅当有强化时生效:+N → -N需扣除2*N
if currentProp <= 0 {
return false
}
// 强化反转:调整量为-2*currentProp从+N到-N需要减少2N用SUB操作
adjustLevel := -2 * currentProp
if calcNewValue(prop, adjustLevel, info.AbilityOpType.SUB) {
target.AttackValue.Prop[prop] = newValue
return true
}
return false
} else { // 反转弱化(仅当有弱化时生效:-N → +N需增加2*N
if currentProp >= 0 {
return false
}
// 弱化反转:调整量为-2*currentProp从-N到+N需要增加2N用ADD操作
adjustLevel := -2 * currentProp
if calcNewValue(prop, adjustLevel, info.AbilityOpType.ADD) {
target.AttackValue.Prop[prop] = newValue
return true
}
return false
}
case info.AbilityOpType.BounceWeaken:
// 反弹弱化:将自身弱化转移给对手并清除自身弱化
currentProp := target.AttackValue.Prop[prop]
if currentProp >= 0 { // 无弱化可反弹
return false
}
// 向对手施加同等弱化
if target.Opp.SetProp(source, prop, currentProp, info.AbilityOpType.SUB) {
// 清除自身弱化
target.SetProp(source, prop, -1, info.AbilityOpType.RESET)
return true
}
return false
case info.AbilityOpType.COPY:
// 复制对手属性:将对手的强化/弱化值叠加到自身(遵守上下限)
oppProp := target.Opp.AttackValue.Prop[prop] // 对手的属性值(可正可负)
currentProp := target.AttackValue.Prop[prop] // 自身当前属性值
// 1. 计算叠加后的目标值(自身+对手)
targetProp := currentProp + oppProp
// 2. 限制目标值在 [-6, 6] 范围内
if targetProp > 6 {
targetProp = 6
} else if targetProp < -6 {
targetProp = -6
}
// 3. 若目标值与当前值一致,无需操作
if targetProp == currentProp {
return false
}
// 4. 根据目标值与当前值的差异,选择 ADD 或 SUB 操作叠加
if targetProp > currentProp {
// 目标值更高:用 ADD 操作提升(调整量为差值)
adjustLevel := targetProp - currentProp
return target.SetProp(source, prop, adjustLevel, info.AbilityOpType.ADD)
} else {
// 目标值更低:用 SUB 操作降低(调整量为差值的绝对值)
adjustLevel := currentProp - targetProp
return target.SetProp(source, prop, adjustLevel, info.AbilityOpType.SUB)
}
default:
// 处理常规操作ADD/SUB/RESET
if calcNewValue(prop, level, opType) {
target.AttackValue.Prop[prop] = newValue
return true
}
return false
}
}