```
refactor(common/rpc): 移除Redis PubSub心跳机制并优化连接管理 移除Redis PubSub连接的心跳保活功能,因为PubSub连接只应负责订阅和接收, 避免在同一连接上并发执行PING操作。更新了ListenFunc和ListenFight函数, 统一代码结构,移除了context包依赖,并添加了相关注释说明。 feat(logic/pet): 新增宠物技能提交功能 新增CommitPetSkills接口用于一次性提交宠物技能学习/替换/排序结果。 实现技能验证、费用计算和状态更新逻辑,包括新技能学习成本和排序费用。 添加isSameUint32Slice辅助函数用于比较技能数组。 ```
This commit is contained in:
@@ -99,6 +99,12 @@ type GetPetLearnableSkillsInboundInfo struct {
|
||||
CatchTime uint32 `json:"catchTime"`
|
||||
}
|
||||
|
||||
type CommitPetSkillsInboundInfo struct {
|
||||
Head common.TomeeHeader `cmd:"52313" struc:"skip"`
|
||||
CatchTime uint32 `json:"catchTime"`
|
||||
Skill [4]uint32 `json:"skill"`
|
||||
}
|
||||
|
||||
type C2S_PetFusion struct {
|
||||
Head common.TomeeHeader `cmd:"2351" struc:"skip"`
|
||||
Mcatchtime uint32 `json:"mcatchtime" msgpack:"mcatchtime"`
|
||||
|
||||
@@ -15,6 +15,18 @@ type GetPetLearnableSkillsOutboundInfo struct {
|
||||
SkillList []uint32 `json:"skillList"`
|
||||
}
|
||||
|
||||
func isSameUint32Slice(a []uint32, b []uint32) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for index := range a {
|
||||
if a[index] != b[index] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func collectPetLearnableSkillList(currentPet *model.PetInfo) []uint32 {
|
||||
skillSet := make(map[uint32]struct{})
|
||||
skills := make([]uint32, 0)
|
||||
@@ -184,3 +196,88 @@ func (h Controller) SortPetSkills(data *C2S_Skill_Sort, c *player.Player) (resul
|
||||
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
// CommitPetSkills 按最终技能列表一次性提交学习/替换/排序结果。
|
||||
func (h Controller) CommitPetSkills(
|
||||
data *CommitPetSkillsInboundInfo,
|
||||
c *player.Player,
|
||||
) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
const setSkillCost = 50
|
||||
const skillSortCost = 50
|
||||
|
||||
_, currentPet, ok := c.FindPet(data.CatchTime)
|
||||
if !ok {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
|
||||
currentSkillSet := make(map[uint32]model.SkillInfo, len(currentPet.SkillList))
|
||||
currentSkillOrder := make([]uint32, 0, len(currentPet.SkillList))
|
||||
for _, skill := range currentPet.SkillList {
|
||||
if skill.ID == 0 {
|
||||
continue
|
||||
}
|
||||
currentSkillSet[skill.ID] = skill
|
||||
currentSkillOrder = append(currentSkillOrder, skill.ID)
|
||||
}
|
||||
|
||||
finalSkillIDs := make([]uint32, 0, 4)
|
||||
usedSkillSet := make(map[uint32]struct{}, 4)
|
||||
for _, skillID := range data.Skill {
|
||||
if skillID == 0 {
|
||||
continue
|
||||
}
|
||||
if _, exists := usedSkillSet[skillID]; exists {
|
||||
continue
|
||||
}
|
||||
usedSkillSet[skillID] = struct{}{}
|
||||
finalSkillIDs = append(finalSkillIDs, skillID)
|
||||
}
|
||||
|
||||
if len(finalSkillIDs) == 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemBusy
|
||||
}
|
||||
if len(finalSkillIDs) > 4 {
|
||||
finalSkillIDs = finalSkillIDs[:4]
|
||||
}
|
||||
if isSameUint32Slice(currentSkillOrder, finalSkillIDs) {
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
learnableSkillSet := make(map[uint32]struct{})
|
||||
for _, skillID := range collectPetLearnableSkillList(currentPet) {
|
||||
learnableSkillSet[skillID] = struct{}{}
|
||||
}
|
||||
|
||||
newSkillCount := 0
|
||||
finalSkillList := make([]model.SkillInfo, 0, len(finalSkillIDs))
|
||||
for _, skillID := range finalSkillIDs {
|
||||
if skill, exists := currentSkillSet[skillID]; exists {
|
||||
finalSkillList = append(finalSkillList, skill)
|
||||
continue
|
||||
}
|
||||
if _, exists := learnableSkillSet[skillID]; !exists {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemBusy
|
||||
}
|
||||
skillInfo, exists := xmlres.SkillMap[int(skillID)]
|
||||
if !exists {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemBusy
|
||||
}
|
||||
newSkillCount++
|
||||
finalSkillList = append(finalSkillList, model.SkillInfo{
|
||||
ID: skillID,
|
||||
PP: uint32(skillInfo.MaxPP),
|
||||
})
|
||||
}
|
||||
|
||||
totalCost := int64(newSkillCount * setSkillCost)
|
||||
if newSkillCount == 0 {
|
||||
totalCost += int64(skillSortCost)
|
||||
}
|
||||
if totalCost > 0 && !c.GetCoins(totalCost) {
|
||||
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
||||
}
|
||||
c.Info.Coins -= totalCost
|
||||
currentPet.SkillList = finalSkillList
|
||||
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
@@ -23,3 +23,9 @@ type C2S_Skill_Sort struct {
|
||||
Skill [4]uint32 `json:"skill_1"` // 技能1(对应C# uint skill_1)
|
||||
|
||||
}
|
||||
|
||||
type CommitPetSkillsInfo struct {
|
||||
Head common.TomeeHeader `cmd:"52313" struc:"skip"`
|
||||
CatchTime uint32 `json:"catchTime"`
|
||||
Skill [4]uint32 `json:"skill"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user