2025-09-21 17:01:31 +00:00
|
|
|
package player
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"blazing/common/data/xmlres"
|
2025-10-18 23:58:19 +08:00
|
|
|
"blazing/common/utils"
|
2025-11-19 16:11:02 +08:00
|
|
|
"blazing/logic/service/common"
|
2025-09-26 13:33:55 +08:00
|
|
|
"blazing/logic/service/fight/info"
|
|
|
|
|
|
2026-01-19 18:51:56 +08:00
|
|
|
"blazing/modules/player/model"
|
2025-09-26 13:33:55 +08:00
|
|
|
|
|
|
|
|
"github.com/jinzhu/copier"
|
2025-09-21 17:01:31 +00:00
|
|
|
)
|
|
|
|
|
|
2026-04-05 05:32:39 +08:00
|
|
|
func (player *Player) WarehousePetList() []model.PetInfo {
|
|
|
|
|
allPets := player.Service.Pet.PetInfo(0)
|
|
|
|
|
if len(allPets) == 0 {
|
|
|
|
|
return make([]model.PetInfo, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result := make([]model.PetInfo, 0, len(allPets))
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
// AddPetExp 添加宠物经验
|
2026-02-12 04:28:20 +08:00
|
|
|
func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
2026-04-13 21:06:45 +08:00
|
|
|
if petInfo == nil || addExp <= 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-04-15 03:22:59 +08:00
|
|
|
panelLimit := p.CurrentMapPetLevelLimit()
|
2026-04-14 00:38:50 +08:00
|
|
|
if petInfo.Level > 100 {
|
|
|
|
|
currentHP := petInfo.Hp
|
2026-04-13 21:06:45 +08:00
|
|
|
petInfo.Update(false)
|
2026-04-15 03:22:59 +08:00
|
|
|
petInfo.CalculatePetPane(panelLimit)
|
2026-04-14 00:38:50 +08:00
|
|
|
petInfo.Hp = utils.Min(currentHP, petInfo.MaxHp)
|
2026-02-12 04:28:20 +08:00
|
|
|
}
|
2025-10-18 23:58:19 +08:00
|
|
|
addExp = utils.Min(addExp, p.Info.ExpPool)
|
2025-12-24 19:03:11 +08:00
|
|
|
originalLevel := petInfo.Level
|
2026-02-12 04:28:20 +08:00
|
|
|
exp := int64(petInfo.Exp) + addExp
|
2025-10-17 23:09:26 +00:00
|
|
|
p.Info.ExpPool -= addExp //减去已使用的经验
|
2025-12-24 19:03:11 +08:00
|
|
|
gainedExp := exp //已获得的经验
|
2026-04-14 00:38:50 +08:00
|
|
|
for exp >= int64(petInfo.NextLvExp) {
|
2025-12-24 19:03:11 +08:00
|
|
|
petInfo.Level++
|
|
|
|
|
petInfo.Update(true)
|
2026-04-13 21:06:45 +08:00
|
|
|
}
|
2026-02-12 04:28:20 +08:00
|
|
|
petInfo.Exp = (exp)
|
2025-09-21 17:01:31 +00:00
|
|
|
// 重新计算面板
|
2025-12-24 19:03:11 +08:00
|
|
|
if originalLevel != petInfo.Level {
|
2026-04-15 03:22:59 +08:00
|
|
|
petInfo.CalculatePetPane(panelLimit)
|
2025-10-18 23:58:19 +08:00
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
petInfo.Cure()
|
|
|
|
|
p.Info.PetMaxLevel = utils.Max(petInfo.Level, p.Info.PetMaxLevel)
|
2025-12-13 21:47:07 +08:00
|
|
|
// 处理技能学习
|
2025-12-24 19:03:11 +08:00
|
|
|
learnableSkills := utils.LastFourElements(petInfo.GetLevelRangeCanLearningSkills(originalLevel, petInfo.Level), 4) //获取最后四个技能,如果不足,那就取全部技能
|
2025-09-21 17:01:31 +00:00
|
|
|
|
2025-12-13 21:47:07 +08:00
|
|
|
for i := 0; i < 4; i++ {
|
2025-09-21 17:01:31 +00:00
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
if len(learnableSkills) != 0 {
|
|
|
|
|
skillID := learnableSkills[len(learnableSkills)-1]
|
|
|
|
|
petInfo.SkillList = append(petInfo.SkillList, model.SkillInfo{
|
2025-09-21 17:01:31 +00:00
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
ID: skillID,
|
|
|
|
|
PP: uint32(xmlres.SkillMap[int(skillID)].MaxPP),
|
2025-12-13 21:47:07 +08:00
|
|
|
})
|
2025-10-26 20:56:03 +08:00
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
learnableSkills = learnableSkills[:len(learnableSkills)-1]
|
2025-12-13 21:47:07 +08:00
|
|
|
}
|
2025-09-21 17:01:31 +00:00
|
|
|
|
|
|
|
|
}
|
2025-12-24 19:03:11 +08:00
|
|
|
if len(petInfo.SkillList) > 4 {
|
|
|
|
|
petInfo.SkillList = petInfo.SkillList[:4] //归正到4
|
2025-12-13 21:47:07 +08:00
|
|
|
}
|
2025-12-05 10:04:23 +00:00
|
|
|
}
|
2025-11-01 00:40:19 +08:00
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
header := common.NewTomeeHeader(2508, p.Info.UserID)
|
|
|
|
|
updateOutbound := &info.PetUpdateOutboundInfo{}
|
2025-11-01 00:40:19 +08:00
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
var petUpdateInfo info.UpdatePropInfo
|
2025-11-01 00:40:19 +08:00
|
|
|
|
2025-12-24 19:03:11 +08:00
|
|
|
copier.Copy(&petUpdateInfo, petInfo)
|
2026-02-12 04:28:20 +08:00
|
|
|
petUpdateInfo.Exp = uint32(gainedExp)
|
2025-12-24 19:03:11 +08:00
|
|
|
updateOutbound.Data = append(updateOutbound.Data, petUpdateInfo)
|
|
|
|
|
p.SendPack(header.Pack(updateOutbound)) //准备包由各自发,因为协议不一样
|
2025-10-13 19:46:19 +08:00
|
|
|
|
2025-09-21 17:01:31 +00:00
|
|
|
}
|
2026-03-03 23:40:21 +08:00
|
|
|
|
|
|
|
|
// PetDel 删除指定宠物
|
|
|
|
|
// catchTime: 宠物的捕捉时间戳
|
|
|
|
|
func (f *Player) PetDel(catchTime uint32) {
|
|
|
|
|
index, olpet, ok := f.FindPet(catchTime)
|
|
|
|
|
if ok {
|
|
|
|
|
|
|
|
|
|
//先将背包更新
|
2026-03-26 04:51:36 +08:00
|
|
|
f.Service.Pet.Update(*olpet)
|
|
|
|
|
f.Service.Pet.PetDel(catchTime)
|
2026-03-03 23:40:21 +08:00
|
|
|
f.Info.PetList = append(f.Info.PetList[:index], f.Info.PetList[index+1:]...)
|
|
|
|
|
}
|
|
|
|
|
}
|