Files
bl/logic/service/player/pet.go
昔念 e75ecd413d feat(fight): 重构战斗系统技能逻辑与精灵切换功能
- 优化技能执行流程,统一使用 SelectSkillAction 作为技能载体
- 移除冗余的技能 ID 字段,简化数据结构
- 调整命中判断和技能效果触发机制,提升准确性
- 修改精灵切换与捕获相关方法参数格式
- 更新技能列表结构为动态数组以支持灵活长度
- 完善睡眠等异常状态的处理逻辑
- 修复战斗中技能 PP 扣减及副本还原问题
- 清理无用代码,如多余的 FindWithIndex 函数定义
- 强化验证码缓存键命名规则,增强安全性
2025-10-26 20:56:03 +08:00

116 lines
3.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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, bro bool) {
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()
}
if bro {
return
}
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))
// 处理技能学习
canLearnSkillList := LastFourElements(petinfo.GetLevelRangeCanLearningSkills(originalLevel, petinfo.Level)) //获取最后四个技能,如果不足,那就取全部技能
for i := 0; i < len(petinfo.SkillList); i++ {
if petinfo.SkillList[i].ID == 0 {
if len(canLearnSkillList) != 0 {
skid := canLearnSkillList[len(canLearnSkillList)-1]
petinfo.SkillList[i].ID = skid
petinfo.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
}
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 性格ID0-24
// * @param abilityTypeEnum 特性类型ID0=无, >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)
}