```
feat(pet): 添加学习力分配功能并优化相关逻辑 - 新增 PetEVdiy 接口用于自定义宠物学习力分配 - 限制单次学习力分配不超过510,单项不超过255 - 学习力池 EVPool 字段添加到 PlayerInfo 结构体 - 使用 github.com/samber/lo 简化数组求和操作 - 更新 fight_boss 逻辑以正确处理 BOSS 战斗后经验与学习力奖励发放 - 调整任务列表中部分
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package info
|
||||
import "blazing/modules/blazing/model"
|
||||
|
||||
type S2C_GET_BOSS_MONSTER struct {
|
||||
BonusID uint32 // 奖金ID:未知作用,填写0即可
|
||||
BonusID uint32 // 激活前端任务的ID
|
||||
EXP uint32 `json:"exp" description:"奖励经验"`
|
||||
EV uint32 `json:"ev" description:"奖励累计学习力"`
|
||||
PetID uint32 // 发放精灵的ID
|
||||
CaptureTm uint32 // 发放精灵的捕获时间
|
||||
ItemListLen uint32 `struc:"sizeof=ItemList"`
|
||||
@@ -13,6 +15,3 @@ type S2C_GET_BOSS_MONSTER struct {
|
||||
// 2. 发放多个物品时:序列化时先写入 uint 类型的数组长度,再依次写入每个ItemInfo元素
|
||||
// 3. 该List结构参考PetInfo的特性List(长度为Uint型,非int)
|
||||
}
|
||||
type PET_WAR_EXP_NOTICE struct {
|
||||
EXP uint32 // 奖金ID:未知作用,填写0即可
|
||||
}
|
||||
|
||||
@@ -21,3 +21,11 @@ type PetBargeListOutboundInfo struct {
|
||||
PetBargeListLen uint32 `struc:"sizeof=PetBargeList"`
|
||||
PetBargeList []PetBargeListInfo `description:"返回的精灵信息" codec:"petBargeList"`
|
||||
}
|
||||
type PetEV struct {
|
||||
Head common.TomeeHeader `cmd:"50001" struc:"skip"`
|
||||
CacthTime uint32 `description:"捕捉时间" codec:"cacthTime"`
|
||||
EVs [6]uint32 `description:"属性" codec:"evs"`
|
||||
}
|
||||
type S2C_50001 struct {
|
||||
UseEV uint32 //用掉的学习力
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"blazing/cool"
|
||||
"blazing/logic/service/common"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"sync"
|
||||
|
||||
"context"
|
||||
@@ -68,7 +69,7 @@ func (h *ClientData) Recv(data common.TomeeHeader) {
|
||||
// fmt.Println(tt1)
|
||||
err := struc.Unpack(bytes.NewBuffer(data.Data), tt1)
|
||||
if err != nil {
|
||||
cool.Loger.Error(context.Background(), data.UserID, data.CMD, "解包失败")
|
||||
cool.Loger.Error(context.Background(), data.UserID, data.CMD, "解包失败,", hex.EncodeToString(data.Data))
|
||||
return
|
||||
}
|
||||
//fmt.Println(tt1)
|
||||
|
||||
@@ -41,7 +41,7 @@ func init() {
|
||||
{3, 50000}, // 累积经验x50000
|
||||
{5, 20}, // 金豆x20
|
||||
{300650, 3}, // 全能学习力遗忘器x3
|
||||
{300651, 6}, // 全能学习力注入器x6
|
||||
// {300651, 6}, // 全能学习力注入器x6
|
||||
}, 0)
|
||||
|
||||
// -------------------------- 普通任务(无精灵奖励) --------------------------
|
||||
@@ -58,8 +58,8 @@ func init() {
|
||||
RegisterTask(25, 0, []model.ItemInfo{{400501, 10}}, 0) // 新船员的考验(神奇扭蛋牌x10)
|
||||
|
||||
RegisterTask(37, 0, []model.ItemInfo{ // 帕诺星系星球测绘
|
||||
{1, 3000}, // 赛尔豆x3000
|
||||
{700452, 1}, // 中型智慧芯片x1
|
||||
{1, 3000}, // 赛尔豆x3000
|
||||
// {700452, 1}, // 中型智慧芯片x1
|
||||
{100178, 1}, // 勘察头盔x1
|
||||
{100179, 1}, // 勘察护腕x1
|
||||
{100180, 1}, // 勘察腰带x1
|
||||
@@ -73,9 +73,9 @@ func init() {
|
||||
}, 0)
|
||||
|
||||
RegisterTask(48, 0, []model.ItemInfo{ // 神秘失踪的爱丽丝
|
||||
{3, 3000}, // 累积经验x3000
|
||||
{1, 2000}, // 赛尔豆x2000
|
||||
{700452, 2}, // 中型智慧芯片x2
|
||||
{3, 3000}, // 累积经验x3000
|
||||
{1, 2000}, // 赛尔豆x2000
|
||||
//{700452, 2}, // 中型智慧芯片x2
|
||||
}, 0)
|
||||
|
||||
RegisterTask(52, 0, []model.ItemInfo{ // 谁偷走了雪球能源?
|
||||
@@ -222,7 +222,7 @@ func init() {
|
||||
RegisterTask(40, 0, []model.ItemInfo{}, 139) // 时空之门(迪卢卡,类型139)
|
||||
|
||||
RegisterTask(49, 0, []model.ItemInfo{ // 密林中的托尼(托尼+物品)
|
||||
{700452, 2}, // 中型智慧芯片x2
|
||||
// {700452, 2}, // 中型智慧芯片x2
|
||||
}, 158) // 托尼(类型158)
|
||||
|
||||
RegisterTask(71, 0, []model.ItemInfo{ // 赛尔号大整修(TOE+物品)
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
const TableNamePet = "pet"
|
||||
@@ -130,10 +131,7 @@ func (pet *PetInfo) AddEV(evadd []uint32) (bool, error) {
|
||||
}
|
||||
|
||||
// 3. 计算增量后的总和,检查是否超过510
|
||||
totalTemp := uint32(0)
|
||||
for _, v := range tempEV {
|
||||
totalTemp += v
|
||||
}
|
||||
totalTemp := lo.Sum(tempEV[:])
|
||||
|
||||
// 4. 若总和超额,按索引顺序(0→5)削减(优先削减前面的字段)
|
||||
hasCut := false
|
||||
|
||||
@@ -83,6 +83,7 @@ type PlayerInfo struct {
|
||||
Texture uint32 `struc:"uint32" json:"texture"` // 固定0
|
||||
Energy uint32 `struc:"uint32" default:"3000" json:"energy"` // 固定3000
|
||||
Coins uint32 `struc:"uint32" json:"coins"` // 赛尔豆
|
||||
EVPool uint32 `struc:"uint32" json:"ev_pool"` //累计学习力
|
||||
FightBadge uint32 `struc:"uint32" json:"fight_badge"` // 固定0
|
||||
MapID uint32 `struc:"uint32" default:"1" json:"map_id"` // 上线地图ID
|
||||
Pos Pos `json:"pos"` // 坐标
|
||||
|
||||
Reference in New Issue
Block a user