Files
bl/logic/controller/action_扭蛋.go
昔念 5995f0670c
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
feat(game): 实现扭蛋系统批量物品添加功能并优化地图逻辑

- 新增ItemAddBatch方法用于批量添加物品,支持普通道具和特殊道具的分别处理
- 优化扭蛋游戏玩法中的物品添加逻辑,使用新的批量接口提升性能
- 在扭蛋机器人命令中实现完整的物品检查和批量添加流程

refactor(map): 重构地图控制器代码结构并添加注释

- 为EnterMap、LeaveMap、GetMapPlayerList等方法添加中文注释
- 统一地图相关的命名规范,如enter
2026-04-01 20:10:29 +08:00

77 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package controller
import (
"blazing/common/data"
"blazing/common/socket/errorcode"
"blazing/logic/service/common"
"blazing/logic/service/player"
"blazing/modules/config/service"
"blazing/modules/player/model"
"github.com/gogf/gf/v2/util/grand"
)
func (h Controller) EggGamePlay(data1 *C2S_EGG_GAME_PLAY, c *player.Player) (result *S2C_EGG_GAME_PLAY, err errorcode.ErrorCode) {
switch data1.EggNum {
case 2:
data1.EggNum = 5
case 3:
data1.EggNum = 10
}
r := c.Service.Item.CheakItem(400501)
if data1.EggNum > 10 || data1.EggNum <= 0 {
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrSystemError)
}
if r < 0 {
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
}
if data1.EggNum > r {
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
}
result = &S2C_EGG_GAME_PLAY{ListInfo: []data.ItemInfo{}}
if grand.Meet(int(data1.EggNum), 100) {
r := service.NewPetRewardService().GetEgg()
newPet := model.GenPetInfo(int(r.MonID), int(r.DV), int(r.Nature), int(r.Effect), int(r.Lv), nil, 0)
if grand.Meet(1, 500) {
newPet.RandomByWeightShiny()
}
c.Service.Pet.PetAdd(newPet, 0)
result.HadTime = newPet.CatchTime
result.PetID = newPet.ID
}
items := service.NewItemService().GetEgg(int(data1.EggNum))
addedItems := c.ItemAddBatch(items)
for _, item := range addedItems {
result.ListInfo = append(result.ListInfo, data.ItemInfo{ItemId: item.ItemId, ItemCnt: item.ItemCnt})
}
c.Service.Item.UPDATE(400501, int(-data1.EggNum))
return
}
// C2S_EGG_GAME_PLAY 前端向后端发送的抽蛋请求结构体
// 对应原 C# 的 C2S_EGG_GAME_PLAY
type C2S_EGG_GAME_PLAY struct {
Head common.TomeeHeader `cmd:"3201" struc:"skip"`
EggNum int64 `struc:"uint32"` // 抽蛋次数标识1 = 1次 2 = 5次 3 = 10次
// 注Go 中 uint 是平台相关类型32/64位游戏开发中推荐用 uint32 明确匹配 C# 的 uint
}
// S2C_EGG_GAME_PLAY 后端向前端返回的抽蛋结果结构体
// 对应原 C# 的 S2C_EGG_GAME_PLAY
type S2C_EGG_GAME_PLAY struct {
GiftIN uint32 `struc:"uint32"`
PetID uint32 `struc:"uint32"` // 抽中精灵的id
HadTime uint32 `struc:"uint32"` // 抽中精灵的捕捉时间(若为时间戳,建议改为 uint64
ListInfoLen uint32 `struc:"sizeof=ListInfo"`
ListInfo []data.ItemInfo `json:"listinfo"` // 抽中物品的物品数组
}