2025-12-08 00:17:04 +08:00
|
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2025-12-26 20:38:08 +08:00
|
|
|
|
"blazing/common/data"
|
2025-12-08 00:17:04 +08:00
|
|
|
|
"blazing/common/socket/errorcode"
|
2026-03-04 02:24:25 +08:00
|
|
|
|
"blazing/logic/service/common"
|
|
|
|
|
|
|
2025-12-08 00:17:04 +08:00
|
|
|
|
"blazing/logic/service/player"
|
2025-12-26 20:38:08 +08:00
|
|
|
|
"blazing/modules/config/service"
|
2026-01-19 18:51:56 +08:00
|
|
|
|
"blazing/modules/player/model"
|
2025-12-26 20:38:08 +08:00
|
|
|
|
|
|
|
|
|
|
"github.com/gogf/gf/v2/util/grand"
|
2025-12-08 00:17:04 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2026-04-05 23:13:06 +08:00
|
|
|
|
// EggGamePlay 处理控制器请求。
|
2026-03-04 02:24:25 +08:00
|
|
|
|
func (h Controller) EggGamePlay(data1 *C2S_EGG_GAME_PLAY, c *player.Player) (result *S2C_EGG_GAME_PLAY, err errorcode.ErrorCode) {
|
2025-12-26 20:38:08 +08:00
|
|
|
|
|
|
|
|
|
|
switch data1.EggNum {
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
data1.EggNum = 5
|
|
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
data1.EggNum = 10
|
|
|
|
|
|
}
|
2025-12-31 00:29:38 +08:00
|
|
|
|
r := c.Service.Item.CheakItem(400501)
|
2026-02-10 10:49:01 +08:00
|
|
|
|
if data1.EggNum > 10 || data1.EggNum <= 0 {
|
2026-02-10 10:49:23 +08:00
|
|
|
|
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrSystemError)
|
2026-02-10 10:49:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
if r < 0 {
|
|
|
|
|
|
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
|
|
|
|
|
|
}
|
2026-02-10 11:30:41 +08:00
|
|
|
|
if data1.EggNum > r {
|
2026-02-03 23:57:06 +08:00
|
|
|
|
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
|
2025-12-31 00:29:38 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2026-03-04 02:24:25 +08:00
|
|
|
|
result = &S2C_EGG_GAME_PLAY{ListInfo: []data.ItemInfo{}}
|
2025-12-26 20:38:08 +08:00
|
|
|
|
if grand.Meet(int(data1.EggNum), 100) {
|
|
|
|
|
|
r := service.NewPetRewardService().GetEgg()
|
2026-02-08 17:57:42 +08:00
|
|
|
|
newPet := model.GenPetInfo(int(r.MonID), int(r.DV), int(r.Nature), int(r.Effect), int(r.Lv), nil, 0)
|
2026-02-21 17:32:40 +08:00
|
|
|
|
if grand.Meet(1, 500) {
|
|
|
|
|
|
newPet.RandomByWeightShiny()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-11 12:19:13 +08:00
|
|
|
|
c.Service.Pet.PetAdd(newPet, 0)
|
2025-12-30 00:10:59 +08:00
|
|
|
|
|
2025-12-26 20:38:08 +08:00
|
|
|
|
result.HadTime = newPet.CatchTime
|
|
|
|
|
|
result.PetID = newPet.ID
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-24 01:52:56 +08:00
|
|
|
|
items := service.NewItemService().GetEgg(int(data1.EggNum))
|
2026-04-01 20:10:29 +08:00
|
|
|
|
addedItems := c.ItemAddBatch(items)
|
|
|
|
|
|
for _, item := range addedItems {
|
2025-12-26 20:38:08 +08:00
|
|
|
|
result.ListInfo = append(result.ListInfo, data.ItemInfo{ItemId: item.ItemId, ItemCnt: item.ItemCnt})
|
|
|
|
|
|
}
|
2025-12-08 00:17:04 +08:00
|
|
|
|
|
2025-12-26 20:38:08 +08:00
|
|
|
|
c.Service.Item.UPDATE(400501, int(-data1.EggNum))
|
2025-12-08 00:17:04 +08:00
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2026-03-04 02:24:25 +08:00
|
|
|
|
|
|
|
|
|
|
// 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"` // 抽中物品的物品数组
|
|
|
|
|
|
}
|