```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

refactor(controller): 移除独立的服务模块并将结构体定义内联到控制器中

移除了 egg、leiyi、pet 和 systemtime 独立服务包中的结构体定义,
将所有 C2S 和 S2C 结构体直接定义在相应的控制器文件中,同时更新了
导入路径和服务调用方式,统一使用 common.TomeeHeader 并优化了代码组织结构。

BREAKING CHANGE: 结构体定义从独立的服务包移动到控制器文件内部
This commit is contained in:
昔念
2026-03-04 02:24:25 +08:00
parent aefef6a456
commit 10af34fdad
13 changed files with 110 additions and 124 deletions

View File

@@ -3,7 +3,8 @@ package controller
import (
"blazing/common/data"
"blazing/common/socket/errorcode"
"blazing/logic/service/egg"
"blazing/logic/service/common"
"blazing/logic/service/player"
"blazing/modules/config/service"
"blazing/modules/player/model"
@@ -11,7 +12,7 @@ import (
"github.com/gogf/gf/v2/util/grand"
)
func (h Controller) EggGamePlay(data1 *egg.C2S_EGG_GAME_PLAY, c *player.Player) (result *egg.S2C_EGG_GAME_PLAY, err errorcode.ErrorCode) {
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:
@@ -31,7 +32,7 @@ func (h Controller) EggGamePlay(data1 *egg.C2S_EGG_GAME_PLAY, c *player.Player)
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
}
result = &egg.S2C_EGG_GAME_PLAY{ListInfo: []data.ItemInfo{}}
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)
@@ -58,3 +59,21 @@ func (h Controller) EggGamePlay(data1 *egg.C2S_EGG_GAME_PLAY, c *player.Player)
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"` // 抽中物品的物品数组
}