Files
bl/logic/controller/pet_skill.go
昔念 9baca27033 ```
refactor(controller): 重构控制器代码结构并优化战斗状态检查

- 添加包级注释说明controller包的功能和架构设计
- 重命名Controller结构体注释,使其更清晰明了
- 添加ParseCmd函数的
2025-12-23 10:46:17 +08:00

76 lines
2.0 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 controller
import (
"blazing/common/data/xmlres"
"blazing/common/socket/errorcode"
"blazing/common/utils"
"blazing/logic/service/fight"
"blazing/logic/service/pet"
"blazing/logic/service/player"
"blazing/modules/blazing/model"
)
// SetPetSkill 设置宠物技能消耗50赛尔豆
func (h Controller) SetPetSkill(data *pet.ChangeSkillInfo, c *player.Player) (result *pet.ChangeSkillOutInfo, err errorcode.ErrorCode) {
const setSkillCost = 50
if !c.UseCoins(setSkillCost) {
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
c.Info.Coins -= setSkillCost
_, onpet, ok := c.FindPet(data.CatchTime)
if !ok {
return nil, errorcode.ErrorCodes.ErrSystemBusy
}
// 检查要替换的技能是否已存在
_, _, exists := utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool {
return item.ID == data.ReplaceSkill
})
if exists {
return nil, errorcode.ErrorCodes.ErrSystemBusy
}
// 查找要学习的技能并替换
_, hasSkill, ok := utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool {
return item.ID == data.HasSkill
})
if ok {
hasSkill.ID = data.ReplaceSkill
hasSkill.PP = uint32(xmlres.SkillMap[int(hasSkill.ID)].MaxPP)
}
return &pet.ChangeSkillOutInfo{
CatchTime: data.CatchTime,
}, 0
}
// SkillSort 排序宠物技能消耗50赛尔豆
func (h Controller) SkillSort(data *pet.C2S_Skill_Sort, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
const skillSortCost = 50
if !c.UseCoins(skillSortCost) {
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
c.Info.Coins -= skillSortCost
_, onpet, ok := c.FindPet(data.CapTm)
if ok {
var newSkillList []model.SkillInfo
for _, skillID := range data.Skill {
_, skill, found := utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool {
return item.ID == skillID
})
if found {
newSkillList = append(newSkillList, *skill)
}
}
onpet.SkillList = newSkillList
}
return nil, 0
}