Files
bl/logic/controller/pet_skill.go
昔念 d9112c1510 ```
refactor(controller): 重构控制器函数命名和代码注释

- 重命名 EGG 函数为 EggGamePlay,更新宠物生成逻辑
- 重命名 Leiyi 函数为 GetLeiyiTrainStatus
- 重命名 Cacthpet 函数为 CatchPet,添加详细函数注释
- 为 ArenaSetOwner、ArenaFightOwner、ArenaGetInfo、ArenaUpfight、ArenaOwnerAcce
  等擂台相关函数添加注释前缀
- 重命名 PETKing 函数为 PetKing
- 重命名 FRESH_CHOICE_FIGHT_LEVEL 函数为 FreshChoiceFightLevel,添加详细参数说明
- 重命名 BuyMItem 函数为 BuyMultipleItems
- 重命名 ITEM_SALE 函数为 ItemSale,优化代码结构
- 重命名 UserItemList 函数为 GetUserItemList,重命名 ItemUsePet 为 UsePetItemOutOfFight
 添加 ResetNature 函数注释
- 重命名 COMMEND_ONLINE 函数为 GetServerOnline
- 重命名 Login 函数,优化变量命名
- 重命名 MapEnter 为 EnterMap,MapHot 为 GetMapHot,MapLeave 为 LeaveMap
  MapList 为 GetMapPlayerList,Attack_Boss 为 AttackBoss
- 为 GetNonoInfo 函数添加注释前缀
- 重命名 IS_COLLECT 函数为 IsCollect
- 重命名 PetEVdiy 函数为 PetEVDiy,添加详细注释
- 为 GetPetInfo、GetPetList、GetPetReleaseList、PetReleaseToWarehouse、
  PetRetrieveFromWarehouse、TogglePetBagWarehouse、PlayerShowPet、
  PetOneCure、PetFirst、GetPetBargeList 等宠物相关函数添加注释
- 重命名 SetPetSkill 为 SetPetSkill,SkillSort 为 SortPetSkills
- 重命名 BUY_FITMENT 为 BuyFitment,添加函数注释
```
2025-12-24 19:03:49 +08:00

85 lines
2.2 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"
"github.com/samber/lo"
)
// 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
_, currentPet, ok := c.FindPet(data.CatchTime)
if !ok {
return nil, errorcode.ErrorCodes.ErrSystemBusy
}
canleaernskill := onpet.GetLevelRangeCanLearningSkills(1, onpet.Level)
_, ok = lo.Find(canleaernskill, func(item uint32) bool {
return item == data.ReplaceSkill
})
if !ok {
return result, errorcode.ErrorCodes.ErrSystemBusy
}
_, _, ok = utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool { //已经存在技能
return item.ID == data.ReplaceSkill
})
if ok {
return nil, errorcode.ErrorCodes.ErrSystemBusy
}
// 查找要学习的技能并替换
_, targetSkill, ok := utils.FindWithIndex(currentPet.SkillList, func(item model.SkillInfo) bool {
return item.ID == data.HasSkill
})
if ok {
targetSkill.ID = data.ReplaceSkill
targetSkill.PP = uint32(xmlres.SkillMap[int(targetSkill.ID)].MaxPP)
}
return &pet.ChangeSkillOutInfo{
CatchTime: data.CatchTime,
}, 0
}
// SortPetSkills 排序宠物技能消耗50赛尔豆
func (h Controller) SortPetSkills(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
_, currentPet, ok := c.FindPet(data.CapTm)
if ok {
var newSkillList []model.SkillInfo
for _, skillID := range data.Skill {
_, skill, found := utils.FindWithIndex(currentPet.SkillList, func(item model.SkillInfo) bool {
return item.ID == skillID
})
if found {
newSkillList = append(newSkillList, *skill)
}
}
currentPet.SkillList = newSkillList
}
return nil, 0
}