Files
bl/logic/service/fight/input/prop.go
2025-11-15 22:17:43 +00:00

127 lines
3.9 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"
"fmt"
)
// 攻击,防御,特攻,特防,速度,命中
// 施加方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.Prop_Befer(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 { // 反转强化(仅当有强化时生效)
if currentProp <= 0 {
return false
}
// 强化反转当前值currentProp → -currentProp调整量为-2*currentProp
if calcNewValue(prop, -2*currentProp, info.AbilityOpType.ADD) {
target.AttackValue.Prop[prop] = newValue
return true
}
return false
} else { // 反转弱化(仅当有弱化时生效)
if currentProp >= 0 {
return false
}
// 弱化反转当前值currentProp → -currentProp调整量为-2*currentProp
if calcNewValue(prop, -2*currentProp, 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]
adjustLevel := oppProp - target.AttackValue.Prop[prop]
return target.SetProp(source, prop, adjustLevel, info.AbilityOpType.ADD)
default:
// 处理常规操作ADD/SUB/RESET
if calcNewValue(prop, level, opType) {
target.AttackValue.Prop[prop] = newValue
return true
}
return false
}
}