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 } panelLimit := p.CurrentMapPetLevelLimit() if petInfo.Level > 100 { currentHP := petInfo.Hp petInfo.Update(false) petInfo.CalculatePetPane(panelLimit) petInfo.Hp = utils.Min(currentHP, petInfo.MaxHp) } 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++ petInfo.Update(true) } petInfo.Exp = (exp) // 重新计算面板 if originalLevel != petInfo.Level { petInfo.CalculatePetPane(panelLimit) 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:]...) } }