Files
bl/logic/service/fight/input/prop.go
2026-04-04 06:27:15 +08:00

223 lines
6.6 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
func (our *Input) HasPropADD() bool {
for _, v := range our.Prop[:] {
if v > 0 {
return true
}
}
return false
}
func (our *Input) HasPropSub() bool {
for _, v := range our.Prop[:] {
if v < 0 {
return true
}
}
return false
}
func (target *Input) SetProp(source *Input, index, level int8) bool {
// 前置状态结算:判断是否允许执行属性操作
canExecute := target.ExecWithOpponent(source, func(effect Effect) bool {
// 执行前置效果返回true表示可以继续操作
return effect.PropBefer(source, index, level)
})
if !canExecute {
return false
}
switch {
case level < 0:
if target.AttackValue.Prop[index] > -6 {
target.AttackValue.Prop[index] += level
if target.AttackValue.Prop[index] < -6 {
target.AttackValue.Prop[index] = -6
}
} else {
return false
}
case level > 0:
if target.AttackValue.Prop[index] < 6 {
target.AttackValue.Prop[index] += level
if target.AttackValue.Prop[index] > 6 {
target.AttackValue.Prop[index] = 6
}
} else {
return false
}
case level == 0:
if target.AttackValue.Prop[index] != 0 {
target.AttackValue.Prop[index] = 0
return true
} else {
return false
}
// // 重置属性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 true
}
return true
}
// // 攻击,防御,特攻,特防,速度,命中
// // 施加方source属性类型prop等级level 返回是否成功
// func (target *Input) SetProp(source *Input, prop, level int8) bool {
// // 前置状态结算:判断是否允许执行属性操作
// canExecute := target.Exec(func(effect Effect) bool {
// // 执行前置效果返回true表示可以继续操作
// return effect.PropBefer(source, prop, level)
// })
// if !canExecute {
// return false
// }
// var newValue int8
// // 计算新属性值并判断操作是否有效(属性是否会发生变化)
// calcNewValue := func(p, l int8, t info.EnumAbilityOpType) bool {
// switch t {
// case info.AbilityOpType.ADD:
// // 属性提升上限为6
// if l < 0 {
// l = -l
// }
// 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:
// if l > 0 {
// l = -l
// }
// // 属性降低,下限为-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
// }
// }