refactor(model): 重构 GenPetInfo 函数参数处理逻辑

- 将 GenPetInfo 函数的参数从单个值改为切片,以支持更灵活的配置
- 新增 RandomInRange 函数,用于从切片表示的范围内随机选择值
- 更新了 fight 控制器和 task 控制器中调用 GenPetInfo 函数的代码
- 此重构提高了代码的可读性和可维护性,同时保留了原有的功能
This commit is contained in:
2025-09-05 00:26:42 +08:00
parent d0d897337e
commit a86b69dd1e
3 changed files with 40 additions and 14 deletions

View File

@@ -3,9 +3,6 @@ package controller
import (
"blazing/common/socket/errorcode"
"math/rand"
"time"
"blazing/logic/service"
"blazing/logic/service/fight"
"blazing/logic/service/fight/info"
@@ -35,8 +32,12 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn
ttt.OpponentInfo = info.FightUserInfo{UserID: 0}
refpet := c.OgreInfo.Data[data.Number]
dv := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(32)
mo := model.GenPetInfo(refpet.Id, uint32(dv), 0, 1006, refpet.Shiny, refpet.Lv)
mo := model.GenPetInfo(
int(refpet.Id), []int{0, 31},
[]int{0, 24},
[]int{0}, //野怪没特性
[]int{int(refpet.Shiny)},
[]int{int(refpet.Lv)})
ttt.OpponentPetList = make([]info.ReadyFightPetInfo, 1)
err1 := copier.CopyWithOption(&ttt.OpponentPetList[0], &mo, copier.Option{IgnoreEmpty: true, DeepCopy: true})

View File

@@ -91,7 +91,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *service
}
if data.TaskId == 86 { //新手注册任务
r := model.GenPetInfo(1, 1, 1, 1006, 1, 5)
r := model.GenPetInfo(1, []int{0, 31}, []int{0, 24}, []int{0}, []int{0}, []int{5})
result.CaptureTime = r.CatchTime
result.PetTypeId = r.ID
blservice.NewUserService(c.Info.UserID).PetAdd(*r)