Files
bl/logic/service/player/pet.go
昔念 f95fd49efd
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
feat(fight): 新增疲惫状态并优化睡眠状态机制

- 实现疲惫状态(StatusTired),仅限制攻击技能,允许属性技能正常使用
- 重构睡眠状态,改为在被攻击且未miss时立即解除,而非技能使用后
- 修复寄生种子效果触发时机,改为回合开始时触发
- 调整寄生效果的目标为技能施放者而非
2026-04-13 21:06:45 +08:00

110 lines
2.8 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"
)
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
}
// AddPetExp 添加宠物经验
func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
if petInfo == nil || addExp <= 0 {
return
}
if petInfo.Level >= 100 {
petInfo.Level = 100
petInfo.Exp = 0
petInfo.Update(false)
petInfo.CalculatePetPane(100)
if petInfo.Hp > petInfo.MaxHp {
petInfo.Hp = petInfo.MaxHp
}
return
}
addExp = utils.Min(addExp, p.Info.ExpPool)
originalLevel := petInfo.Level
exp := int64(petInfo.Exp) + addExp
p.Info.ExpPool -= addExp //减去已使用的经验
gainedExp := exp //已获得的经验
for petInfo.Level < 100 && exp >= int64(petInfo.NextLvExp) {
petInfo.Level++
exp -= int64(petInfo.LvExp)
petInfo.Update(true)
}
if petInfo.Level >= 100 {
p.Info.ExpPool += exp // 超出100级上限的经验退回经验池
gainedExp -= exp
exp = 0
}
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:]...)
}
}