``` refactor(pet): 优化宠物特性随机逻辑并修复宠物删除数组操作

This commit is contained in:
1
2025-12-30 02:15:33 +00:00
parent 94391abe5f
commit f91b88e90f
5 changed files with 17 additions and 21 deletions

View File

@@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"math"
"math/rand"
"time"
"github.com/gogf/gf/v2/util/gconv"
@@ -240,14 +239,10 @@ func (pet *PetInfo) IsShiny() bool {
}
// 随机特性
func (pet *PetInfo) RnadAN() {
// 随机特性
randomIndex := rand.Intn(len(xmlres.PlayerEffectMAP))
func (pet *PetInfo) RnadEffect() {
var i int
for _, v := range xmlres.PlayerEffectMAP {
if i == randomIndex {
if gconv.Int(v.StarLevel) == 0 {
ret := &PetEffectInfo{
Idx: uint16(gconv.Int16(v.Idx)),
Status: 1,
@@ -264,7 +259,7 @@ func (pet *PetInfo) RnadAN() {
break
}
i++
}
}
@@ -475,14 +470,15 @@ func GenPetInfo(
case abilityTypeEnum == -1:
for _, v := range xmlres.PlayerEffectMAP {
p.EffectInfo = append(p.EffectInfo, PetEffectInfo{
Idx: uint16(gconv.Int16(v.Idx)),
Status: 1,
EID: uint16(gconv.Int16(v.Eid)),
Args: v.ArgsS,
})
break
if gconv.Int(v.StarLevel) == 0 {
p.EffectInfo = append(p.EffectInfo, PetEffectInfo{
Idx: uint16(gconv.Int16(v.Idx)),
Status: 1,
EID: uint16(gconv.Int16(v.Eid)),
Args: v.ArgsS,
})
break
}
}
}

View File

@@ -46,7 +46,7 @@ func (s *PetFusionService) Data(p1, p2, rand uint32) uint32 {
return 0
}
pets := s.def()
res := pets[grand.Intn(len(pets)-1)]
res := pets[grand.Intn(len(pets))]
rr := grand.Intn(100)
if rr < int(res.Probability+int32(rand)) {
return uint32(res.ResultPetID)