refactor(fight): 重构战斗准备逻辑并优化战斗启动流程

将 ReadyFight 方法拆分为多个职责清晰的子方法:
- buildFightStartInfo: 构建战斗初始信息
- checkBothPlayersReady: 检查PVP双方是否就绪
- handleNPCFightSpecial: 处理NPC战斗特殊逻辑(如可捕捉标记)
- startBattle: 统一启动战斗流程

同时修复部分逻辑顺序问题,增强代码可读性和扩展性。

feat(fight): 新增精灵王挑战协议支持

增加 StartPetWarInboundInfo 结构体用于接收精灵王挑战请求,
为后续实现相关功能提供基础。

fix(effect): 修正多个技能效果数值引用错误

- effect_37: 技能威力计算使用正确参数索引
- effect_50: 固定减伤比例调整为除以2
- effect_65: 正确比较技能分类类型
- effect_68: 致死保护改为锁定剩余1点生命值
- effect_77: 回复目标由敌方改为己方
- effect_93: 固定伤害值直接取参数

refactor(effect): 移除冗余效果类文件

删除 effect_133.go 和 effect_90.go 文件,其功能已被统一条件伤害和倍率系统取代;
移除 effect_74.go、effect_75.go 中重复的状态随机施加逻辑。

refactor(effect): 更新能力操作枚举命名一致性

重命名 AbilityOpType 枚举项名称,去除前缀,提升语义清晰度:
- AbilityOpStealStrengthen → StealStrengthen
- AbilityOpReverse → Reverse
- AbilityOpBounceWeaken → BounceWeaken

chore(fight): 完善 BattlePetEntity 属性初始化逻辑

在创建 BattlePetEntity 时即设置 PType,避免后续多次查询 PetMAP;
移除 Type() 方法中的冗余配置查找逻辑。

fix(skill): 确保必中技能不参与命中率计算

在 AttackTimeC 方法中添加 return 防止必中技能继续执行命中率公式计算。

refactor(fight): 调整战斗回合结束逻辑

进入新回合时允许玩家更换精灵,并提前跳出循环防止多余处理。

style(effect): 更正拼写及变量命名风格

修改 BaseSataus.Switch 方法签名中的参数命名;
更正 Effect58 中 can 字段首字母大写;
This commit is contained in:
2025-11-14 23:09:16 +08:00
parent efa7ad6f76
commit a86782b1ea
34 changed files with 808 additions and 676 deletions

View File

@@ -6,7 +6,6 @@ import (
"blazing/common/utils"
"blazing/logic/service/fight/action"
"blazing/logic/service/fight/info"
"fmt"
"math/rand"
"github.com/shopspring/decimal"
@@ -186,148 +185,6 @@ func (our *Input) Damage(in *Input, sub *info.DamageZone) {
}
// 攻击,防御,特供,特防,速度,命中
// 施加方,类型,等级,操作类别,是否成功
func (our *Input) SetProp(in *Input, prop, level int8, ptype info.EnumAbilityOpType) (ret bool) {
//in.Our = our //设置属性的角色是我方
canuseskill := our.Exec(func(t Effect) bool { //这个是能否使用技能
//结算状态
return t.Prop_Befer(in, prop, level, ptype) //返回本身结算,如果false,说明不能使用技能了
})
if !canuseskill {
return false
}
var newValue int8
abfunc := func(prop, level int8, ptype info.EnumAbilityOpType) (ret bool) {
switch ptype {
case info.AbilityOpType.ADD:
newValue = utils.Min(our.AttackValue.Prop[prop]+int8(level), 6)
if newValue > our.AttackValue.Prop[prop] {
fmt.Println("属性值会增加")
return true
} else {
fmt.Println("属性值不会增加")
return false
}
case info.AbilityOpType.SUB:
newValue = utils.Max(our.AttackValue.Prop[prop]+int8(level), -6)
if newValue < our.AttackValue.Prop[prop] {
fmt.Println("属性值会减少")
return true
} else {
fmt.Println("属性值不会增加")
return false
}
case info.AbilityOpType.RESET:
if level > 0 && our.AttackValue.Prop[prop] > 0 { //消强
newValue = 0
return true
}
if level < 0 && our.AttackValue.Prop[prop] < 0 { //解弱
newValue = 0
return true
}
}
return false
}
switch ptype {
case info.AbilityOpType.AbilityOpStealStrengthen:
temp := our.Opp.AttackValue.Prop[prop]
if temp <= 0 { //对方没有强化
return false
}
if abfunc(prop, temp, info.AbilityOpType.ADD) { //把对面的强化等级添加自身
our.AttackValue.Prop[prop] = newValue //成功把 强化更新
our.Opp.SetProp(our, prop, 1, info.AbilityOpType.RESET) //吸取后消除对面强化
}
case info.AbilityOpType.AbilityOpReverse:
temp := our.AttackValue.Prop[prop]
switch {
case level > 0: //反转强化
if temp <= 0 { //没有强化
return false
}
if abfunc(prop, temp*2, info.AbilityOpType.SUB) {
our.AttackValue.Prop[prop] = newValue
if temp == -our.AttackValue.Prop[prop] { //成功到对应弱化
return true
} else {
return true
}
} else { //自身免弱或已到-6
return false
}
default: //反转弱化
if temp >= 0 { //没有弱化
return false
}
if abfunc(prop, -temp*2, info.AbilityOpType.ADD) {
our.AttackValue.Prop[prop] = newValue
if temp == -our.AttackValue.Prop[prop] { //成功到对应强化
return true
} else {
return true
}
} else { //自身免弱或已到-6
return false
}
}
case info.AbilityOpType.AbilityOpBounceWeaken:
temp := our.AttackValue.Prop[prop]
if temp >= 0 { //没有弱化
return false
}
if our.Opp.SetProp(our, prop, temp, info.AbilityOpType.SUB) {
our.SetProp(our, prop, -1, info.AbilityOpType.RESET) //消除自身弱化
return true
}
case info.AbilityOpType.COPY:
temp := our.Opp.AttackValue.Prop[prop]
if temp >= 0 {
our.SetProp(our, prop, temp, info.AbilityOpType.ADD)
} else {
our.SetProp(our, prop, -temp, info.AbilityOpType.SUB)
}
default: //增加减少重置
if abfunc(prop, level, ptype) {
// 执行赋值
our.AttackValue.Prop[prop] = newValue
return true
}
}
return false
}
func (our *Input) GetAction(opp *Input) {
// 获取己方当前宠物和对方当前宠物
selfPet := our.FightC.GetCurrPET(our.Player)

View File

@@ -0,0 +1,173 @@
package input
import (
"blazing/common/utils"
"blazing/logic/service/fight/info"
"fmt"
)
// SetProp 处理属性操作(提升/下降/消除/偷取等)
// our当前执行操作的主体操作发起方
// target输入源操作的源头输入对象可能是我方或对方
// prop属性类型
// level操作幅度强化/弱化的程度)
// opType操作类型明确区分提升/下降/消除等)
func (our *Input) SetProp(target *Input, prop int8, level int8, opType info.EnumAbilityOpType) bool {
// 前置检查:输入源是否允许该操作(基于输入源的状态)
if !our.checkPreCondition(target, prop, level, opType) {
return false
}
// 根据操作类型处理(明确区分不同操作的逻辑)
switch opType {
case info.AbilityOpType.ADD: // 能力提升(强化):仅正向增加,不处理负数
return our.handleStrengthen(target, prop, level)
case info.AbilityOpType.SUB: // 能力下降(弱化):仅负向减少,不处理正数
return our.handleWeaken(target, prop, level)
case info.AbilityOpType.RESET: // 能力消除重置清除强化或弱化恢复0
return our.handleReset(target, prop, level)
case info.AbilityOpType.StealStrengthen: // 偷取强化:从对方输入源偷取到自身
return our.handleStealStrengthen(target, prop)
case info.AbilityOpType.Reverse: // 反转:强化转弱化,弱化转强化
return our.handleReverse(target, prop, level)
case info.AbilityOpType.BounceWeaken: // 反弹弱化:将输入源的弱化反弹给对方
return our.handleBounceWeaken(target, prop)
case info.AbilityOpType.COPY: // 复制:复制对方属性到输入源
return our.handleCopy(target, prop)
default:
return false
}
}
// checkPreCondition 检查输入源是否允许操作(基于输入源的状态)
func (our *Input) checkPreCondition(inputSource *Input, prop, level int8, opType info.EnumAbilityOpType) bool {
return our.Exec(func(e Effect) bool {
// 检查输入源是否允许该操作e.Prop_Befer的参数是输入源
return e.Prop_Befer(inputSource, prop, level, opType)
})
}
// ------------------------------
// 1. 能力提升强化仅处理正向增加上限6
// ------------------------------
func (our *Input) handleStrengthen(inputSource *Input, prop, level int8) bool {
if level <= 0 {
fmt.Printf("强化失败幅度必须为正数level=%d\n", level)
return false
}
current := inputSource.AttackValue.Prop[prop]
newVal := utils.Min(current+level, 6) // 强化上限6
if newVal == current {
fmt.Printf("属性[%d]强化无变化(当前%d已达上限6\n", prop, current)
return false
}
inputSource.AttackValue.Prop[prop] = newVal
fmt.Printf("属性[%d]强化:%d → %d+%d\n", prop, current, newVal, level)
return true
}
// ------------------------------
// 2. 能力下降(弱化):仅处理负向减少,下限-6
// ------------------------------
func (our *Input) handleWeaken(inputSource *Input, prop, level int8) bool {
if level >= 0 {
fmt.Printf("弱化失败幅度必须为负数level=%d\n", level)
return false
}
current := inputSource.AttackValue.Prop[prop]
newVal := utils.Max(current+level, -6) // 弱化下限-6
if newVal == current {
fmt.Printf("属性[%d]弱化无变化(当前%d已达下限-6\n", prop, current)
return false
}
inputSource.AttackValue.Prop[prop] = newVal
fmt.Printf("属性[%d]弱化:%d → %d%d\n", prop, current, newVal, level)
return true
}
// ------------------------------
// 3. 能力消除(重置):仅清除对应状态(强化/弱化),不影响正常状态
// ------------------------------
func (our *Input) handleReset(inputSource *Input, prop, level int8) bool {
current := inputSource.AttackValue.Prop[prop]
// 规则level>0清除强化current>0level<0清除弱化current<0不处理正常状态current=0
if (level > 0 && current <= 0) || (level < 0 && current >= 0) {
fmt.Printf("重置失败:属性[%d]当前状态(%d与操作level=%d不匹配\n", prop, current, level)
return false
}
inputSource.AttackValue.Prop[prop] = 0
fmt.Printf("属性[%d]重置:%d → 0level=%d\n", prop, current, level)
return true
}
// ------------------------------
// 4. 偷取强化:从对方输入源偷取强化到自身输入源
// ------------------------------
func (our *Input) handleStealStrengthen(inputSource *Input, prop int8) bool {
// 对方输入源的强化值(必须为正)
oppProp := our.Opp.AttackValue.Prop[prop]
if oppProp <= 0 {
fmt.Printf("偷取失败:对方属性[%d]无强化(%d\n", prop, oppProp)
return false
}
// 自身输入源增加偷取的强化值
if !our.handleStrengthen(inputSource, prop, oppProp) {
return false
}
// 清除对方输入源的强化用level>0重置
our.Opp.SetProp(our.Opp, prop, 1, info.AbilityOpType.RESET)
return true
}
// ------------------------------
// 5. 反转:输入源的强化转弱化,或弱化转强化
// ------------------------------
func (our *Input) handleReverse(inputSource *Input, prop, level int8) bool {
current := inputSource.AttackValue.Prop[prop]
switch {
case level > 0 && current > 0: // 强化转弱化幅度为当前强化值的2倍
// 例:当前+2 → 弱化-4level>0指定强化转弱化
return our.handleWeaken(inputSource, prop, -current*2)
case level < 0 && current < 0: // 弱化转强化幅度为当前弱化值的2倍
// 例:当前-2 → 强化+4level<0指定弱化转强化
return our.handleStrengthen(inputSource, prop, -current*2)
default:
fmt.Printf("反转失败:当前值(%d与操作方向level=%d不匹配\n", current, level)
return false
}
}
// ------------------------------
// 6. 反弹弱化:将输入源的弱化反弹给对方,同时清除输入源的弱化
// ------------------------------
func (our *Input) handleBounceWeaken(inputSource *Input, prop int8) bool {
// 输入源的弱化值(必须为负)
currentWeak := inputSource.AttackValue.Prop[prop]
if currentWeak >= 0 {
fmt.Printf("反弹失败:输入源属性[%d]无弱化(%d\n", prop, currentWeak)
return false
}
// 反弹给对方:对方输入源承受相同弱化(用弱化操作)
if !our.Opp.SetProp(our.Opp, prop, currentWeak, info.AbilityOpType.SUB) {
return false
}
// 清除输入源的弱化用level<0重置
return our.handleReset(inputSource, prop, -1)
}
// ------------------------------
// 7. 复制:将对方属性复制到输入源(强化/弱化均复制)
// ------------------------------
func (our *Input) handleCopy(inputSource *Input, prop int8) bool {
oppProp := our.Opp.AttackValue.Prop[prop]
if oppProp == 0 {
fmt.Printf("复制无变化:对方属性[%d]为0\n", prop)
return true // 无变化也算成功
}
// 根据对方属性类型选择强化/弱化操作
if oppProp > 0 {
return our.handleStrengthen(inputSource, prop, oppProp) // 复制强化
} else {
return our.handleWeaken(inputSource, prop, oppProp) // 复制弱化oppProp是负数
}
}