feat(pet): 添加学习力分配功能并优化相关逻辑

- 新增 PetEVdiy 接口用于自定义宠物学习力分配
- 限制单次学习力分配不超过510,单项不超过255
- 学习力池 EVPool 字段添加到 PlayerInfo 结构体
- 使用 github.com/samber/lo 简化数组求和操作
- 更新 fight_boss 逻辑以正确处理 BOSS 战斗后经验与学习力奖励发放
- 调整任务列表中部分
This commit is contained in:
2025-11-25 00:55:10 +08:00
parent 50232339d9
commit 28e0addda0
8 changed files with 73 additions and 27 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/grand"
"github.com/samber/lo"
)
func processMonID(bm string) string {
@@ -156,24 +157,27 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn
fight.NewFight(c, ai, func(foi *info.FightOverInfo) {
c.Done.Exec(model.MilestoneMode.Moster, []uint32{c.Info.MapID, moinfo.PetList[0].ID, uint32(foi.Reason)}, func(results *model.MilestoneEX) uint32 {
if foi.Reason == 0 && foi.WinnerId == c.Info.UserID {
exp := uint32(xmlres.PetMAP[int(mo.ID)].YieldingExp) * mo.Level / 7
items := &info.S2C_GET_BOSS_MONSTER{
//EV: 45,
EXP: exp * 2,
}
if refpet.Item != 0 {
items := &info.S2C_GET_BOSS_MONSTER{}
items.ItemList = c.ItemAdd(model.ItemInfo{
ItemId: refpet.Item,
ItemCnt: uint32(grand.Intn(2) + 1),
})
c.SendPackCmd(8004, items)
}
foi.Winpet.AddEV(gconv.Uint32s(strings.Split(xmlres.PetMAP[int(mo.ID)].YieldingEV, " ")))
exp := uint32(xmlres.PetMAP[int(mo.ID)].YieldingExp) * mo.Level / 7
}
evs := gconv.Uint32s(strings.Split(xmlres.PetMAP[int(mo.ID)].YieldingEV, " "))
items.EV = lo.Sum(evs)
c.Info.EVPool += lo.Sum(evs) //给予累计学习力
foi.Winpet.AddEV(evs)
c.Info.ExpPool += exp * 4
c.AddPetExp(foi.Winpet, uint32(exp)*2)
// c.SendPackCmd(2509, &info.PET_WAR_EXP_NOTICE{
// EXP: exp * 2,
// })
c.SendPackCmd(8004, items)
}
return 0

View File

@@ -11,6 +11,7 @@ import (
"blazing/modules/blazing/model"
"github.com/jinzhu/copier"
"github.com/samber/lo"
)
// 获取精灵信息
@@ -80,7 +81,7 @@ func (h *Controller) PET_ROWEI(
_, _, ok := c.FindPet(data.CatchTime)
//如果背包没找到,再放入背包
if !ok && t.CatchTime != 0 {
if !ok && t.CatchTime != 0 && xmlres.PetMAP[int(data.ID)].FreeForbidden == 0 {
t.Free = 1
}
@@ -252,3 +253,37 @@ func (h Controller) PetBargeList(data *pet.PetBargeListInboundInfo, c *player.Pl
PetBargeList: make([]pet.PetBargeListInfo, 0),
}, 0
}
func (h Controller) PetEVdiy(data *pet.PetEV, c *player.Player) (result *pet.S2C_50001, err errorcode.ErrorCode) {
_, onpet, ok := c.FindPet(data.CacthTime)
if !ok {
return nil, errorcode.ErrorCodes.Err10401
}
//分配超过510的数据
if lo.Sum(data.EVs[:]) > 510 {
return nil, errorcode.ErrorCodes.Err10401
}
for _, v := range data.EVs {
//分配超过255的数据
if v > 255 {
return nil, errorcode.ErrorCodes.Err10401
}
}
if lo.Sum(data.EVs[:]) < lo.Sum(onpet.Ev[:]) {
return nil, errorcode.ErrorCodes.Err10401
}
USEEV1 := lo.Sum(data.EVs[:]) - lo.Sum(onpet.Ev[:])
//加的比池子还多
if USEEV1 > c.Info.EVPool {
return nil, errorcode.ErrorCodes.Err10401
}
onpet.Ev = data.EVs
c.Info.EVPool -= USEEV1
result = &pet.S2C_50001{}
result.UseEV = USEEV1
return result, 0
}