```
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"` // 抽中物品的物品数组
}

View File

@@ -2,12 +2,13 @@ package controller
import (
"blazing/common/socket/errorcode"
"blazing/logic/service/leiyi"
"blazing/logic/service/common"
"blazing/logic/service/player"
)
func (h Controller) GetLeiyiTrainStatus(data *leiyi.C2s_LEIYI_TRAIN_GET_STATUS, c *player.Player) (result *leiyi.S2C_LEIYI_TRAIN_GET_STATUS, err errorcode.ErrorCode) {
result = &leiyi.S2C_LEIYI_TRAIN_GET_STATUS{}
func (h Controller) GetLeiyiTrainStatus(data *C2s_LEIYI_TRAIN_GET_STATUS, c *player.Player) (result *S2C_LEIYI_TRAIN_GET_STATUS, err errorcode.ErrorCode) {
result = &S2C_LEIYI_TRAIN_GET_STATUS{}
for i := 0; i < 6; i++ {
result.Status[i].Total = 10
@@ -17,3 +18,19 @@ func (h Controller) GetLeiyiTrainStatus(data *leiyi.C2s_LEIYI_TRAIN_GET_STATUS,
return
}
type C2s_LEIYI_TRAIN_GET_STATUS struct {
Head common.TomeeHeader `cmd:"2393" struc:"skip"` //玩家登录
}
// OutInfo 表示地图热度的出站消息
type S2C_LEIYI_TRAIN_GET_STATUS struct {
Status [10]S2C_LEIYI_TRAIN_GET_STATUS_info `json:"status"`
}
type S2C_LEIYI_TRAIN_GET_STATUS_info struct {
// Today uint32 // 今日训练HP次数
Current uint32 // 当前训练HP次数
Total uint32 // 目标训练HP次数
}

View File

@@ -3,8 +3,8 @@ package controller
import (
"blazing/common/socket/errorcode"
"blazing/cool"
"blazing/logic/service/common"
"blazing/logic/service/fight"
"blazing/logic/service/pet"
"blazing/logic/service/player"
"blazing/modules/player/model"
)
@@ -13,7 +13,7 @@ import (
// data: 空输入结构
// c: 当前玩家对象
// 返回: 捕捉结果消耗的EV值和错误码
func (h Controller) HanLiuQiang(data *pet.C2S_2608, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
func (h Controller) HanLiuQiang(data *C2S_2608, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if c.ItemAdd(100245, 1) {
return
@@ -27,3 +27,7 @@ func (h Controller) HanLiuQiang(data *pet.C2S_2608, c *player.Player) (result *f
}
return result, -1
}
type C2S_2608 struct {
Head common.TomeeHeader `cmd:"2608" struc:"skip"`
}

View File

@@ -0,0 +1 @@
package controller

View File

@@ -3,15 +3,16 @@ package controller
import (
"blazing/common/data/xmlres"
"blazing/common/socket/errorcode"
"blazing/logic/service/common"
"blazing/logic/service/fight"
"blazing/logic/service/fight/info"
"blazing/logic/service/pet"
"blazing/logic/service/player"
"github.com/jinzhu/copier"
)
func (h Controller) PetELV(data *pet.C2S_PET_EVOLVTION, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
func (h Controller) PetELV(data *C2S_PET_EVOLVTION, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
_, currentPet, found := c.FindPet(data.CacthTime)
if !found {
return nil, errorcode.ErrorCodes.Err10401
@@ -23,7 +24,7 @@ func (h Controller) PetELV(data *pet.C2S_PET_EVOLVTION, c *player.Player) (resul
return nil, errorcode.ErrorCodes.ErrPokemonNotEvolveReady
}
if xmlres.PetMAP[int(currentPet.ID)].EvolvingLv > int(currentPet.Level) {
return nil, errorcode.ErrorCodes.ErrPokemonNotEvolveReady
return nil, errorcode.ErrorCodes.ErrPokemonNotEvolveReady
}
evinfo := xmlres.EVOLVMAP[flag].Branches[data.Index-1]
@@ -49,3 +50,12 @@ return nil, errorcode.ErrorCodes.ErrPokemonNotEvolveReady
c.SendPackCmd(2508, updateOutbound) //准备包由各自发,因为协议不一样
return nil, -1
}
// C2S_PET_EVOLVTION 精灵进化相关的客户端到服务端的消息结构
type C2S_PET_EVOLVTION struct {
Head common.TomeeHeader `cmd:"2314" struc:"skip"`
CacthTime uint32 // 精灵的捕捉时间
Index uint32 // 进化的分支索引。0代表没选择进化1就是第一种进化形态2就是其他分支进化形态
// 如果没有分支进化只有一种进化形态Index只能为1
// 后端直接判断进化条件的材料,执行进化并扣除材料
}

View File

@@ -2,8 +2,8 @@ package controller
import (
"blazing/common/socket/errorcode"
"blazing/logic/service/common"
"blazing/logic/service/fight"
"blazing/logic/service/pet"
"blazing/logic/service/player"
"github.com/samber/lo"
@@ -13,7 +13,7 @@ import (
// data: 包含宠物捕获时间和EV分配数据的输入信息
// c: 当前玩家对象
// 返回: 分配结果和错误码
func (h Controller) PetEVDiy(data *pet.PetEV, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
func (h Controller) PetEVDiy(data *PetEV, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
_, currentPet, found := c.FindPet(data.CacthTime)
if !found {
return nil, errorcode.ErrorCodes.Err10401
@@ -50,3 +50,9 @@ func (h Controller) PetEVDiy(data *pet.PetEV, c *player.Player) (result *fight.N
// result.UseEV = -int32(usedEV)
return result, 0
}
type PetEV struct {
Head common.TomeeHeader `cmd:"50001" struc:"skip"`
CacthTime uint32 `description:"捕捉时间" codec:"cacthTime"`
EVs [6]uint32 `description:"属性" codec:"evs"`
}

View File

@@ -2,16 +2,36 @@ package controller
import (
"blazing/common/socket/errorcode"
"blazing/logic/service/pet"
"blazing/logic/service/common"
"blazing/logic/service/player"
)
// Exelist 对应C#的List<Exeing 实现获取精灵训练数据
func (h Controller) PetExt(
data *pet.C2S_NONO_EXE_LIST, player *player.Player) (result *pet.S2C_NONO_EXE_LIST, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &pet.S2C_NONO_EXE_LIST{}
data *C2S_NONO_EXE_LIST, player *player.Player) (result *S2C_NONO_EXE_LIST, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &S2C_NONO_EXE_LIST{}
return
}
type C2S_NONO_EXE_LIST struct {
Head common.TomeeHeader `cmd:"9015" struc:"skip"`
}
// S2C_NONO_EXE_LIST 对应C#的同名结构体
type S2C_NONO_EXE_LIST struct {
// Exelist 对应C#的List<ExeingPetInfo>Go中用切片([])替代列表
ExelistLen uint32 `json:"exelistLen" struc:"sizeof=Exelist"`
Exelist []ExeingPetInfo `json:"exelist"` // 若需JSON序列化保留原字段名
}
// ExeingPetInfo 对应C#的同名结构体,存储精灵训练相关信息
type ExeingPetInfo struct {
Flag uint32 `json:"_flag"` // 应该是精灵是否在训练对应原_flag
CapTm uint32 `json:"_capTm"` // 精灵的捕捉时间对应原_capTm
PetId uint32 `json:"_petId"` // 训练精灵的id对应原_petId
RemainDay uint32 `json:"_remainDay"` // 停留天数前端用这个值除以3600疑似时间戳对应原_remainDay
Course uint32 `json:"_course"` // 课程对应原_course
}

View File

@@ -2,12 +2,26 @@ package controller
import (
"blazing/common/socket/errorcode"
"time"
"blazing/logic/service/common"
"blazing/logic/service/player"
"blazing/logic/service/systemtime"
)
func (h Controller) SystemTimeInfo(data *systemtime.InInfo, c *player.Player) (result *systemtime.OutInfo, err errorcode.ErrorCode) {
func (h Controller) SystemTimeInfo(data *InInfo, c *player.Player) (result *OutInfo, err errorcode.ErrorCode) {
return systemtime.NewOutInfo(), 0
return &OutInfo{
SystemTime: uint32(time.Now().Unix()), // 获取当前时间戳(秒)
}, 0
}
// LoginSidInfo 登录携带的凭证结构体
type InInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化
Head common.TomeeHeader `cmd:"1002" struc:"skip"` //玩家登录
}
// OutInfo 表示系统时间的出站消息
type OutInfo struct {
SystemTime uint32 `json:"systemTime"` // @UInt long类型
}