Files
bl/logic/service/player/pet.go

103 lines
2.3 KiB
Go

package player
import (
"blazing/common/data/xmlres"
"blazing/modules/blazing/model"
"math"
)
// calculateExperience 根据公式计算指定等级所需的经验值
func calculateExperience(level uint32) uint32 {
var x float64
// 判断等级奇偶性确定x的值
if level%2 == 1 { // 奇数
x = 0.5
} else { // 偶数
x = -0.5
}
// 应用公式计算
lvFloat := float64(level)
experience := 3.75*lvFloat*lvFloat + 3.75*lvFloat + 1 + x
// 四舍五入为整数
return uint32(math.Round(experience))
}
// 主函数实现
// 添加经验
// 超NO 加成
func (p *Player) AddPetExp(pet *model.PetInfo, addExp uint32) {
originalLevel := pet.Level
for {
needExp := calculateExperience(pet.Level)
if addExp >= needExp {
addExp -= needExp
pet.Level++
} else {
break
}
}
pet.Exp = addExp
pet.NextLvExp = calculateExperience(pet.Level)
pet.LvExp = pet.NextLvExp - pet.Exp
// 处理进化逻辑
for {
basic := xmlres.PetMAP[int(pet.ID)]
// 检查是否可以进化
if basic.EvolvesTo == 0 ||
basic.EvolvingLv == 0 ||
basic.EvolvingLv >= int(pet.Level) ||
basic.IsLarge != 0 {
break
}
// 获取进化后的资产
pet.ID = uint32(basic.EvolvesTo)
}
// 重新计算面板
if originalLevel != pet.Level {
pet.CalculatePetPane()
}
// 发送经验更新消息
//player.SendMessage(generatePetUpdateInfo(petEntity, originalExp+addExp-exp, addition))
// 处理技能学习
canLearnSkillList := model.LastFourElements(pet.GetLevelRangeCanLearningSkills(originalLevel, pet.Level)) //获取最后四个技能,如果不足,那就取全部技能
for i := 0; i < 4; i++ {
if pet.SkillList[i].ID == 0 {
if len(canLearnSkillList) != 0 {
skid := canLearnSkillList[len(canLearnSkillList)-1]
pet.SkillList[i].ID = skid
pet.SkillList[i].PP = uint32(xmlres.SkillMap[int(skid)].MaxPP)
canLearnSkillList = canLearnSkillList[:len(canLearnSkillList)-1]
}
}
}
//todo 待实现
// // 发送技能更新消息
// updateSkillInfo := UpdateSkillInfo{
// PetCatchTime: petEntity.captureTime,
// ActiveSkillNum: activeSkillNum,
// UnActiveSkillNum: unActiveSkillNum,
// SkillArray: canLearnSkillList,
// }
// player.SendMessage(UpdateSkillOutboundInfo{
// InfoArray: []UpdateSkillInfo{updateSkillInfo},
// })
// return exp
}