feat(fight): 重构战斗系统技能逻辑与精灵切换功能
- 优化技能执行流程,统一使用 SelectSkillAction 作为技能载体 - 移除冗余的技能 ID 字段,简化数据结构 - 调整命中判断和技能效果触发机制,提升准确性 - 修改精灵切换与捕获相关方法参数格式 - 更新技能列表结构为动态数组以支持灵活长度 - 完善睡眠等异常状态的处理逻辑 - 修复战斗中技能 PP 扣减及副本还原问题 - 清理无用代码,如多余的 FindWithIndex 函数定义 - 强化验证码缓存键命名规则,增强安全性
This commit is contained in:
@@ -3,6 +3,7 @@ package controller
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/common/utils"
|
||||
|
||||
"blazing/logic/service/pet"
|
||||
"blazing/logic/service/player"
|
||||
@@ -122,7 +123,7 @@ func (h *Controller) PlayerShowPet(
|
||||
func (h *Controller) PetOneCure(
|
||||
data *pet.PetOneCureInboundInfo, c *player.Player) (result *pet.PetOneCureOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
|
||||
_, onpet, ok := FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
|
||||
_, onpet, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
|
||||
return item.CatchTime == data.CatchTime
|
||||
})
|
||||
if ok {
|
||||
@@ -158,16 +159,9 @@ func (h *Controller) PetFirst(
|
||||
|
||||
// FindWithIndex 遍历slice,找到第一个满足条件的元素
|
||||
// 返回:索引、元素指针、是否找到
|
||||
func FindWithIndex[T any](slice []T, predicate func(item T) bool) (int, *T, bool) {
|
||||
for i := range slice {
|
||||
if predicate(slice[i]) {
|
||||
return i, &slice[i], true
|
||||
}
|
||||
}
|
||||
return -1, nil, false
|
||||
}
|
||||
|
||||
func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, c *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
|
||||
_, onpet, ok := FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
|
||||
_, onpet, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
|
||||
return item.CatchTime == data.CatchTime
|
||||
})
|
||||
if ok {
|
||||
@@ -180,11 +174,11 @@ func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, c *player.Player)
|
||||
}, 0
|
||||
}
|
||||
func (h Controller) SetPetSkill(data *pet.ChangeSkillInfo, c *player.Player) (result *pet.ChangeSkillOutInfo, err errorcode.ErrorCode) {
|
||||
_, onpet, ok := FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
|
||||
_, onpet, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
|
||||
return item.CatchTime == data.CatchTime
|
||||
})
|
||||
if ok {
|
||||
for i := 0; i < 4; i++ {
|
||||
for i := 0; i < len(onpet.SkillList); i++ {
|
||||
if onpet.SkillList[i].ID == data.HasSkill {
|
||||
onpet.SkillList[i].ID = data.ReplaceSkill
|
||||
onpet.SkillList[i].PP = uint32(xmlres.SkillMap[int(onpet.SkillList[i].ID)].MaxPP)
|
||||
|
||||
Reference in New Issue
Block a user