feat(cache): 添加复合键缓存操作支持 添加了基于 uint32+string 组合键的缓存操作方法,包括 GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和 ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景 fix(vscode): 添加 cSpell 配置支持 struc 词汇 refactor(session): 移除过时的会话管理方法 移除了基于单一字符串键的会话管理方法,因为已迁移到使用 复合键的缓存操作方式 ```
85 lines
2.2 KiB
Go
85 lines
2.2 KiB
Go
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/player/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.GetCoins(setSkillCost) {
|
||
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
||
}
|
||
|
||
c.Info.Coins -= setSkillCost
|
||
|
||
_, currentPet, ok := c.FindPet(data.CatchTime)
|
||
if !ok {
|
||
return nil, errorcode.ErrorCodes.ErrSystemBusy
|
||
}
|
||
canleaernskill := currentPet.GetLevelRangeCanLearningSkills(1, currentPet.Level)
|
||
|
||
_, ok = lo.Find(canleaernskill, func(item uint32) bool {
|
||
return item == data.ReplaceSkill
|
||
})
|
||
|
||
if !ok {
|
||
return result, errorcode.ErrorCodes.ErrSystemBusy
|
||
}
|
||
_, _, ok = utils.FindWithIndex(currentPet.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.GetCoins(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
|
||
}
|