修复了rpc模块中日志输出时参数拼接错误的问题,同时修正了RegisterLogic函数中端口映射的逻辑错误。 feat(socket): 替换错误处理方式为panic 在ServerEvent.go中将网络启动失败的返回错误改为panic处理,提高错误可见性。 feat(fight): 增加战斗加载进度控制 在LoadPercent函数中增加对FightC非
114 lines
3.0 KiB
Go
114 lines
3.0 KiB
Go
package player
|
||
|
||
import (
|
||
"blazing/common/data/xmlres"
|
||
"blazing/common/utils"
|
||
"blazing/logic/service/fight/info"
|
||
|
||
"blazing/modules/blazing/model"
|
||
|
||
"github.com/jinzhu/copier"
|
||
)
|
||
|
||
// 主函数实现
|
||
// 添加经验
|
||
// 禁止发包
|
||
func (p *Player) AddPetExp(petinfo *model.PetInfo, addExp uint32) {
|
||
addExp = utils.Min(addExp, p.Info.ExpPool)
|
||
originalLevel := petinfo.Level
|
||
Exp := petinfo.Exp + addExp
|
||
petinfo.Update()
|
||
p.Info.ExpPool -= addExp //减去已使用的经验
|
||
for Exp >= petinfo.NextLvExp {
|
||
petinfo.Level++
|
||
petinfo.Update()
|
||
Exp -= petinfo.LvExp
|
||
if originalLevel < 100 && petinfo.Level == 100 { //升到100了
|
||
p.Info.ExpPool += Exp //减去已使用的经验
|
||
Exp = 0
|
||
break //停止升级
|
||
}
|
||
|
||
}
|
||
|
||
petinfo.Exp = Exp
|
||
// 重新计算面板
|
||
if originalLevel != petinfo.Level {
|
||
|
||
petinfo.CalculatePetPane()
|
||
petinfo.Cure()
|
||
}
|
||
|
||
// 处理技能学习
|
||
canLearnSkillList := LastFourElements(petinfo.GetLevelRangeCanLearningSkills(originalLevel, petinfo.Level)) //获取最后四个技能,如果不足,那就取全部技能
|
||
|
||
for i := 0; i < 4; i++ {
|
||
|
||
if len(canLearnSkillList) != 0 {
|
||
skid := canLearnSkillList[len(canLearnSkillList)-1]
|
||
petinfo.SkillList = append(petinfo.SkillList, model.SkillInfo{
|
||
|
||
ID: skid,
|
||
PP: uint32(xmlres.SkillMap[int(skid)].MaxPP),
|
||
})
|
||
|
||
canLearnSkillList = canLearnSkillList[:len(canLearnSkillList)-1]
|
||
}
|
||
|
||
}
|
||
petinfo.SkillList = petinfo.SkillList[:4] //归正到4
|
||
|
||
t1 := NewTomeeHeader(2508, p.Info.UserID)
|
||
rrr := &info.PetUpdateOutboundInfo{}
|
||
|
||
var petinfwo info.UpdatePropInfo
|
||
|
||
copier.Copy(&petinfwo, petinfo)
|
||
rrr.Data = append(rrr.Data, petinfwo)
|
||
p.SendPack(t1.Pack(rrr)) //准备包由各自发,因为协议不一样
|
||
// 发送经验更新消息
|
||
//player.SendMessage(generatePetUpdateInfo(petEntity, originalExp+addExp-exp, addition))
|
||
|
||
// // 发送技能更新消息
|
||
// updateSkillInfo := UpdateSkillInfo{
|
||
// PetCatchTime: petEntity.captureTime,
|
||
// ActiveSkillNum: activeSkillNum,
|
||
// UnActiveSkillNum: unActiveSkillNum,
|
||
// SkillArray: canLearnSkillList,
|
||
// }
|
||
|
||
// player.SendMessage(UpdateSkillOutboundInfo{
|
||
// InfoArray: []UpdateSkillInfo{updateSkillInfo},
|
||
// })
|
||
|
||
// return exp
|
||
|
||
}
|
||
|
||
func LastFourElements[T any](s []T) []T {
|
||
n := len(s)
|
||
if n <= 4 {
|
||
// 切片长度小于等于4时,返回整个切片
|
||
return s
|
||
}
|
||
// 切片长度大于4时,返回最后4个元素(从n-4索引到末尾)
|
||
return s[n-4:]
|
||
}
|
||
|
||
// GenPetInfo 生成一个新的精灵实例
|
||
// - 参数为 -1 时表示随机生成对应属性
|
||
// * @param petTypeId 精灵类型ID
|
||
// * @param individualValue 个体值(0-31)
|
||
// * @param natureId 性格ID(0-24)
|
||
// * @param abilityTypeEnum 特性类型ID(0=无, >0=指定, -1=随机)
|
||
// * @param shinyid 闪光ID(-1=随机)
|
||
// * @param level 等级(1-100)
|
||
// * @return 生成的精灵实体
|
||
func (player *Player) GenPetInfo(
|
||
id int,
|
||
dv, natureId, abilityTypeEnum, shinyid, level int,
|
||
) *model.PetInfo {
|
||
|
||
return model.GenPetInfo(id, dv, natureId, abilityTypeEnum, shinyid, level)
|
||
}
|