2025-11-25 12:29:50 +08:00
|
|
|
|
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"
|
2026-01-19 18:51:56 +08:00
|
|
|
|
"blazing/modules/player/model"
|
2025-12-23 13:53:34 +00:00
|
|
|
|
|
|
|
|
|
|
"github.com/samber/lo"
|
2025-11-25 12:29:50 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
|
// SetPetSkill 设置宠物技能,消耗50赛尔豆
|
2026-04-05 07:24:36 +08:00
|
|
|
|
func (h Controller) SetPetSkill(data *ChangeSkillInfo, c *player.Player) (result *pet.ChangeSkillOutInfo, err errorcode.ErrorCode) {
|
2025-12-23 10:46:17 +08:00
|
|
|
|
const setSkillCost = 50
|
|
|
|
|
|
|
2026-01-03 13:53:38 +00:00
|
|
|
|
if !c.GetCoins(setSkillCost) {
|
2025-12-23 10:46:17 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
2025-11-25 12:29:50 +08:00
|
|
|
|
}
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
|
|
|
|
|
c.Info.Coins -= setSkillCost
|
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
_, currentPet, ok := c.FindPet(data.CatchTime)
|
2025-11-25 16:36:55 +08:00
|
|
|
|
if !ok {
|
2025-12-23 10:46:17 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemBusy
|
2025-11-25 16:36:55 +08:00
|
|
|
|
}
|
2025-12-24 19:04:21 +08:00
|
|
|
|
canleaernskill := currentPet.GetLevelRangeCanLearningSkills(1, currentPet.Level)
|
2025-12-23 13:53:34 +00:00
|
|
|
|
|
|
|
|
|
|
_, ok = lo.Find(canleaernskill, func(item uint32) bool {
|
|
|
|
|
|
return item == data.ReplaceSkill
|
|
|
|
|
|
})
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
2025-11-25 16:36:55 +08:00
|
|
|
|
if !ok {
|
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrSystemBusy
|
|
|
|
|
|
}
|
2025-12-24 19:04:21 +08:00
|
|
|
|
_, _, ok = utils.FindWithIndex(currentPet.SkillList, func(item model.SkillInfo) bool { //已经存在技能
|
2025-11-26 15:25:10 +08:00
|
|
|
|
return item.ID == data.ReplaceSkill
|
|
|
|
|
|
})
|
|
|
|
|
|
if ok {
|
2025-12-23 10:46:17 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemBusy
|
2025-11-26 15:25:10 +08:00
|
|
|
|
}
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
|
|
|
|
|
// 查找要学习的技能并替换
|
2025-12-24 19:03:11 +08:00
|
|
|
|
_, targetSkill, ok := utils.FindWithIndex(currentPet.SkillList, func(item model.SkillInfo) bool {
|
2025-11-25 16:36:55 +08:00
|
|
|
|
return item.ID == data.HasSkill
|
|
|
|
|
|
})
|
2025-11-26 15:25:10 +08:00
|
|
|
|
if ok {
|
2025-12-24 19:03:11 +08:00
|
|
|
|
targetSkill.ID = data.ReplaceSkill
|
|
|
|
|
|
targetSkill.PP = uint32(xmlres.SkillMap[int(targetSkill.ID)].MaxPP)
|
2025-11-25 12:29:50 +08:00
|
|
|
|
}
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
2025-11-25 12:29:50 +08:00
|
|
|
|
return &pet.ChangeSkillOutInfo{
|
|
|
|
|
|
CatchTime: data.CatchTime,
|
|
|
|
|
|
}, 0
|
|
|
|
|
|
}
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
// SortPetSkills 排序宠物技能,消耗50赛尔豆
|
2026-04-05 07:24:36 +08:00
|
|
|
|
func (h Controller) SortPetSkills(data *C2S_Skill_Sort, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-12-23 10:46:17 +08:00
|
|
|
|
const skillSortCost = 50
|
|
|
|
|
|
|
2026-01-03 13:53:38 +00:00
|
|
|
|
if !c.GetCoins(skillSortCost) {
|
2025-12-23 10:46:17 +08:00
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
2025-11-25 12:29:50 +08:00
|
|
|
|
}
|
2025-12-23 10:46:17 +08:00
|
|
|
|
|
|
|
|
|
|
c.Info.Coins -= skillSortCost
|
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
|
_, currentPet, ok := c.FindPet(data.CapTm)
|
2025-11-25 12:29:50 +08:00
|
|
|
|
if ok {
|
2025-12-23 10:46:17 +08:00
|
|
|
|
var newSkillList []model.SkillInfo
|
|
|
|
|
|
for _, skillID := range data.Skill {
|
2025-12-24 19:03:11 +08:00
|
|
|
|
_, skill, found := utils.FindWithIndex(currentPet.SkillList, func(item model.SkillInfo) bool {
|
2025-12-23 10:46:17 +08:00
|
|
|
|
return item.ID == skillID
|
2025-11-25 12:29:50 +08:00
|
|
|
|
})
|
2025-12-23 10:46:17 +08:00
|
|
|
|
if found {
|
|
|
|
|
|
newSkillList = append(newSkillList, *skill)
|
2025-11-25 12:29:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-24 19:03:11 +08:00
|
|
|
|
currentPet.SkillList = newSkillList
|
2025-11-25 12:29:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil, 0
|
|
|
|
|
|
}
|