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则置0),level<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 } }