Files
bl/logic/service/player/pet.go
昔念 619e4b50ca
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
refactor(pet): 重构宠物服务方法命名和优化数据库操作

- 统一PetService中方法命名规范,将驼峰命名改为标准驼峰格式
- 修复拼写错误:UPdate -> Update, UPdateFree -> UpdateFree等
- 重命名查询方法:PetInfo_One -> PetInfoOneByCatchTime,
  PetInfo_One_ID -> PetInfoOneByID, PetInfo_One_ohter -> PetInfoOneOther
- 优化BuyPet方法中的事务处理逻辑,使用
2026-03-26 04:51:36 +08:00

91 lines
2.3 KiB
Go

package player
import (
"blazing/common/data/xmlres"
"blazing/common/utils"
"blazing/logic/service/common"
"blazing/logic/service/fight/info"
"blazing/modules/player/model"
"github.com/jinzhu/copier"
)
// AddPetExp 添加宠物经验
func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
if addExp < 0 {
return
}
addExp = utils.Min(addExp, p.Info.ExpPool)
originalLevel := petInfo.Level
exp := int64(petInfo.Exp) + addExp
p.Info.ExpPool -= addExp //减去已使用的经验
gainedExp := exp //已获得的经验
for exp >= int64(petInfo.NextLvExp) {
petInfo.Level++
exp -= int64(petInfo.LvExp)
petInfo.Update(true)
if originalLevel < 100 && petInfo.Level == 100 { //升到100了
p.Info.ExpPool += exp //减去已使用的经验
gainedExp -= exp
exp = 0
break //停止升级
}
}
petInfo.Exp = (exp)
// 重新计算面板
if originalLevel != petInfo.Level {
petInfo.CalculatePetPane(100)
petInfo.Cure()
p.Info.PetMaxLevel = utils.Max(petInfo.Level, p.Info.PetMaxLevel)
// 处理技能学习
learnableSkills := utils.LastFourElements(petInfo.GetLevelRangeCanLearningSkills(originalLevel, petInfo.Level), 4) //获取最后四个技能,如果不足,那就取全部技能
for i := 0; i < 4; i++ {
if len(learnableSkills) != 0 {
skillID := learnableSkills[len(learnableSkills)-1]
petInfo.SkillList = append(petInfo.SkillList, model.SkillInfo{
ID: skillID,
PP: uint32(xmlres.SkillMap[int(skillID)].MaxPP),
})
learnableSkills = learnableSkills[:len(learnableSkills)-1]
}
}
if len(petInfo.SkillList) > 4 {
petInfo.SkillList = petInfo.SkillList[:4] //归正到4
}
}
header := common.NewTomeeHeader(2508, p.Info.UserID)
updateOutbound := &info.PetUpdateOutboundInfo{}
var petUpdateInfo info.UpdatePropInfo
copier.Copy(&petUpdateInfo, petInfo)
petUpdateInfo.Exp = uint32(gainedExp)
updateOutbound.Data = append(updateOutbound.Data, petUpdateInfo)
p.SendPack(header.Pack(updateOutbound)) //准备包由各自发,因为协议不一样
}
// PetDel 删除指定宠物
// catchTime: 宠物的捕捉时间戳
func (f *Player) PetDel(catchTime uint32) {
index, olpet, ok := f.FindPet(catchTime)
if ok {
//先将背包更新
f.Service.Pet.Update(*olpet)
f.Service.Pet.PetDel(catchTime)
f.Info.PetList = append(f.Info.PetList[:index], f.Info.PetList[index+1:]...)
}
}