From 892f9207df7b055bf80077798b0ef681154b2fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Sat, 20 Sep 2025 13:12:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(pet):=20=E4=BC=98=E5=8C=96=E7=B2=BE?= =?UTF-8?q?=E7=81=B5=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=9A=8F=E6=9C=BA=E4=B8=AA=E4=BD=93=E4=B8=8E=E7=89=B9?= =?UTF-8?q?=E6=80=A7=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 `GenPetInfo` 函数参数类型,从数组改为单个整数,简化调用方式 - 支持传入 -1 表示随机生成个体值、性格等属性 - 统一战斗野怪和任务精灵的生成逻辑,确保一致性 - 添加注释说明参数含义,提升代码可读性 - 修复野怪无特性时的处理逻辑,避免空数组引发问题 --- logic/controller/fight.go | 22 +++++++++------- logic/controller/task.go | 2 +- modules/blazing/model/pet.go | 51 +++++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 23 deletions(-) diff --git a/logic/controller/fight.go b/logic/controller/fight.go index 919898cb..ab2f8397 100644 --- a/logic/controller/fight.go +++ b/logic/controller/fight.go @@ -26,11 +26,11 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla } mo = model.GenPetInfo( - int(petid), []int{0, 31}, - []int{0, 24}, - []int{0}, //野怪没特性 - []int{int(0)}, - []int{int(2)}) + int(petid), 24, //24个体 + -1, + 0, //野怪没特性 + 0, + 2) } if c.FightC != nil { @@ -41,6 +41,8 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla return nil, -1 } + +// 战斗野怪 func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { refpet := c.OgreInfo.Data[data.Number] @@ -49,11 +51,11 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn return nil, errorcode.ErrorCodes.ErrPokemonNotExists } mo := model.GenPetInfo( - int(refpet.Id), []int{0, 31}, - []int{0, 24}, - []int{0}, //野怪没特性 - []int{int(refpet.Shiny)}, - []int{int(refpet.Lv)}) + int(refpet.Id), -1, + -1, + 0, //野怪没特性 + int(refpet.Shiny), + int(refpet.Lv)) if c.FightC != nil { return nil, errorcode.ErrorCodes.ErrOnlineOver6HoursCannotFight diff --git a/logic/controller/task.go b/logic/controller/task.go index c406d46f..aebe9ddf 100644 --- a/logic/controller/task.go +++ b/logic/controller/task.go @@ -102,7 +102,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player. case 3: petid = 4 } - r := model.GenPetInfo(petid, []int{0, 31}, []int{0, 24}, []int{0, 39}, []int{0}, []int{5}) + r := model.GenPetInfo(petid, 31, -1, 0, 0, 5) result.CaptureTime = r.CatchTime result.PetTypeId = r.ID c.Service.PetAdd(*r) diff --git a/modules/blazing/model/pet.go b/modules/blazing/model/pet.go index b218cdc2..34a918d8 100644 --- a/modules/blazing/model/pet.go +++ b/modules/blazing/model/pet.go @@ -72,6 +72,7 @@ func LastFourElements[T any](s []T) []T { return s[n-4:] } +// -1是随机 // * @param petTypeId 精灵类型ID // * @param individualValue 个体值 // * @param natureId 性格ID @@ -79,33 +80,58 @@ func LastFourElements[T any](s []T) []T { // * @param isShiny 是否为闪光 // * @param level 等级 // * @return 生成的精灵实体 -func GenPetInfo(id int, dv, natureId, abilityTypeEnum, shinyid, level []int) *PetInfo { +func GenPetInfo(id int, dv, natureId, abilityTypeEnum, shinyid, level int) *PetInfo { + // 设置随机数种子,确保每次运行生成不同的随机数序列 + rand.Seed(time.Now().UnixNano()) p := &PetInfo{ID: uint32(id), - Shiny: uint32(RandomInRange(shinyid)), //闪光 - Nature: uint32(RandomInRange(natureId)), //性格 - Dv: uint32(RandomInRange(dv)), + EffectInfo: make([]PetEffectInfo, 0), CatchTime: uint32(time.Now().Unix()), - Level: uint32(RandomInRange(level))} //等级 + Level: uint32(level)} //等级 naxml := xmlres.NatureRootMap[int(p.Nature)] petxml := xmlres.PetMAP[int(id)] + if shinyid != -1 { + p.Shiny = uint32(shinyid) + } else { - if abilityTypeEnum != nil { + } + if natureId != -1 { + p.Nature = uint32(natureId) + } else { + p.Nature = uint32(rand.Intn(25)) + } + if dv != -1 { + p.Dv = uint32(dv) + } else { + p.Dv = uint32(GetGaussRandomNum(int64(0), int64(31))) + } + if abilityTypeEnum != -1 { + if abilityTypeEnum != 0 { + v := xmlres.PlayerEffectMAP[int(abilityTypeEnum)] + p.EffectInfo = append(p.EffectInfo, PetEffectInfo{ + Idx: uint16(gconv.Int16(v.Idx)), + Status: 1, + EID: uint16(gconv.Int16(v.Eid)), + Args: v.ArgsS, + }) + } + + } else { for i, v := range xmlres.PlayerEffectMAP { - if RandomInRange(abilityTypeEnum) == i { + if rand.Intn(len(xmlres.PlayerEffectMAP)) == i { p.EffectInfo = append(p.EffectInfo, PetEffectInfo{ - EID: uint16(gconv.Int16(v.Eid)), - Args: v.ArgsS, + Idx: uint16(gconv.Int16(v.Idx)), + Status: 1, + EID: uint16(gconv.Int16(v.Eid)), + Args: v.ArgsS, }) } } - //p.EffectInfo[0].Args = []int{petxml.Type, 5} //默认等级1 - } tttt := make([]uint32, 0) for _, v := range petxml.LearnableMoves.Moves { @@ -292,7 +318,8 @@ type PetInfo struct { // // type PetEffectInfo struct { - ItemID uint32 `struc:"uint32" json:"item_id"` //如果是能量珠,就显示 + ItemID uint32 `struc:"uint32" json:"item_id"` //如果是能量珠,就显示 + Idx uint16 `struc:"skip" json:"new_se_idx"` Status byte `struc:"byte" json:"status"` //特性为1,能量珠为2 LeftCount byte `struc:"byte" json:"left_count"` //剩余次数 EID uint16 `struc:"uint16" json:"effect_id"` //特效ID