Files
bl/logic/service/player/pet.go
昔念 18378a3ab6 feat(logic): 添加玩家外观与聊天功能并优化宠物生成逻辑
- 在 `logic/controller/item.go` 中添加了更换玩家服装后广播结果的逻辑
- 在 `logic/controller/user.go` 中新增多个控制器方法:
  - `Aimat`:瞄准操作处理
  - `Chat`:支持消息发送及过滤
  - `ChangePlayerColor`:修改玩家颜色并扣除金币
  - `ChangePlayerDoodle`:更改玩家涂鸦并扣费
  - `ChangeNONOColor`:改变 NONO 颜色
- 移动宠物信息生成函数 `GenPetInfo` 至 `modules/blazing/model/pet.go` 并重构其实现
- 更新 `logic/service/player/pet.go` 和相关引用以适应新结构
-
2025-10-24 00:31:38 +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 < 4; 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)
petinfo.SkillListLen += 1
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)
}