"refactor(controller): 重构控制器层代码,优化战斗状态检查,规范方法命名并完善注释"

This commit is contained in:
1
2025-12-23 13:56:50 +00:00
11 changed files with 191 additions and 148 deletions

View File

@@ -12,14 +12,19 @@ import (
"github.com/samber/lo"
)
// SetPetSkill 设置宠物技能消耗50赛尔豆
func (h Controller) SetPetSkill(data *pet.ChangeSkillInfo, c *player.Player) (result *pet.ChangeSkillOutInfo, err errorcode.ErrorCode) {
if !c.UseCoins(100) {
return result, errorcode.ErrorCodes.ErrSunDouInsufficient10016
const setSkillCost = 50
if !c.UseCoins(setSkillCost) {
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
c.Info.Coins -= 50
c.Info.Coins -= setSkillCost
_, onpet, ok := c.FindPet(data.CatchTime)
if !ok {
return result, errorcode.ErrorCodes.ErrSystemBusy
return nil, errorcode.ErrorCodes.ErrSystemBusy
}
canleaernskill := onpet.GetLevelRangeCanLearningSkills(1, onpet.Level)
@@ -33,40 +38,46 @@ func (h Controller) SetPetSkill(data *pet.ChangeSkillInfo, c *player.Player) (re
_, _, ok = utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool { //已经存在技能
return item.ID == data.ReplaceSkill
})
if ok {
return result, errorcode.ErrorCodes.ErrSystemBusy
return nil, errorcode.ErrorCodes.ErrSystemBusy
}
_, hasskill, ok := utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool { //已经存在技能
// 查找要学习的技能并替换
_, 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)
hasSkill.ID = data.ReplaceSkill
hasSkill.PP = uint32(xmlres.SkillMap[int(hasSkill.ID)].MaxPP)
}
return &pet.ChangeSkillOutInfo{
CatchTime: data.CatchTime,
}, 0
}
func (h Controller) Skill_Sort(data *pet.C2S_Skill_Sort, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if !c.UseCoins(100) {
return result, errorcode.ErrorCodes.ErrSystemBusy
// 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 -= 50
c.Info.Coins -= skillSortCost
_, onpet, ok := c.FindPet(data.CapTm)
if ok {
var newskill []model.SkillInfo
for _, v := range data.Skill {
_, HasSkill, ok := utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool { //已经存在技能
return item.ID == v
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 ok {
newskill = append(newskill, *HasSkill)
if found {
newSkillList = append(newSkillList, *skill)
}
}
onpet.SkillList = newskill
onpet.SkillList = newSkillList
}
return nil, 0