feat(pet): 优化精灵生成逻辑,支持随机个体与特性配置
- 修改 `GenPetInfo` 函数参数类型,从数组改为单个整数,简化调用方式 - 支持传入 -1 表示随机生成个体值、性格等属性 - 统一战斗野怪和任务精灵的生成逻辑,确保一致性 - 添加注释说明参数含义,提升代码可读性 - 修复野怪无特性时的处理逻辑,避免空数组引发问题
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
// <!-- Args: 特效参数, 不超过8个 (注意: 每个参数不能超过 65535) -->
|
||||
// <!-- AdditionType:特效加成类型 1 种族值加成 2 技能威力加成 -->
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user