2026-01-19 18:51:56 +08:00
|
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"blazing/common/socket/errorcode"
|
|
|
|
|
|
"blazing/logic/service/fight"
|
|
|
|
|
|
"blazing/logic/service/pet"
|
|
|
|
|
|
"blazing/logic/service/player"
|
2026-02-09 01:29:33 +08:00
|
|
|
|
"blazing/modules/config/service"
|
2026-01-20 22:08:36 +00:00
|
|
|
|
"blazing/modules/player/model"
|
2026-02-09 01:29:33 +08:00
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogf/gf/v2/util/grand"
|
|
|
|
|
|
"github.com/samber/lo"
|
|
|
|
|
|
"github.com/yudeguang/ratelimit"
|
2026-01-19 18:51:56 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// GetBreedInfo 获取繁殖信息协议
|
|
|
|
|
|
// 前端到后端无数据 请求协议
|
|
|
|
|
|
func (ctl Controller) GetBreedInfo(
|
2026-01-20 22:08:36 +00:00
|
|
|
|
data *pet.C2S_GET_BREED_INFO, player *player.Player) (result *model.S2C_GET_BREED_INFO, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2026-01-19 18:51:56 +08:00
|
|
|
|
|
2026-01-20 22:08:36 +00:00
|
|
|
|
result = &model.S2C_GET_BREED_INFO{}
|
|
|
|
|
|
r := player.Service.Egg.Get()
|
|
|
|
|
|
if r == nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-02-09 01:29:33 +08:00
|
|
|
|
|
2026-01-20 22:08:36 +00:00
|
|
|
|
result = &r.Data
|
2026-01-19 18:51:56 +08:00
|
|
|
|
// TODO: 实现获取繁殖信息的具体逻辑
|
|
|
|
|
|
return result, 0
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetBreedPet 获取繁殖精灵
|
|
|
|
|
|
// 前端到后端
|
|
|
|
|
|
func (ctl Controller) GetBreedPet(
|
|
|
|
|
|
data *pet.C2S_GET_BREED_PET, playerObj *player.Player) (result *pet.S2C_GET_BREED_PET, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2026-02-09 01:29:33 +08:00
|
|
|
|
_, fPet, found := playerObj.FindPet(data.MaleCatchTime)
|
|
|
|
|
|
if !found {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
|
|
|
|
|
if fPet.Gender != 1 {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
|
|
|
|
|
if fPet.Generation > 9 {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
2026-01-19 18:51:56 +08:00
|
|
|
|
result = &pet.S2C_GET_BREED_PET{}
|
2026-02-09 01:29:33 +08:00
|
|
|
|
|
|
|
|
|
|
MPETS := service.NewEggService().GetData(fPet.ID)
|
|
|
|
|
|
|
2026-01-19 18:51:56 +08:00
|
|
|
|
// 这里只是示例,实际应该根据雄性精灵的catchTime查找可繁殖的雌性精灵
|
|
|
|
|
|
for _, v := range playerObj.Info.PetList {
|
2026-02-09 01:29:33 +08:00
|
|
|
|
if v.Level < 50 {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
//不是雌性
|
|
|
|
|
|
if v.Gender != 2 {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
if v.Generation > 9 {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
_, ok := lo.Find(MPETS, func(item int32) bool {
|
|
|
|
|
|
return item == int32(v.ID)
|
|
|
|
|
|
})
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
2026-01-19 18:51:56 +08:00
|
|
|
|
// 如果是雌性精灵,且可以繁殖,则添加到列表
|
|
|
|
|
|
result.FemaleList = append(result.FemaleList, v.CatchTime)
|
|
|
|
|
|
}
|
|
|
|
|
|
return result, 0
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// StartBreed 开始繁殖协议
|
|
|
|
|
|
// 前端到后端
|
|
|
|
|
|
func (ctl Controller) StartBreed(
|
2026-01-20 22:08:36 +00:00
|
|
|
|
data *pet.C2S_START_BREED, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2026-02-09 01:29:33 +08:00
|
|
|
|
|
|
|
|
|
|
if !player.GetCoins(1000) {
|
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
|
|
|
|
|
}
|
|
|
|
|
|
player.Info.Coins -= 1000
|
2026-01-20 22:08:36 +00:00
|
|
|
|
_, MalePet, found := player.FindPet(data.Male)
|
|
|
|
|
|
if !found {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
|
|
|
|
|
_, Female, found := player.FindPet(data.Female)
|
|
|
|
|
|
if !found {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
}
|
2026-01-19 18:51:56 +08:00
|
|
|
|
// TODO: 实现开始繁殖的具体逻辑
|
|
|
|
|
|
result = &fight.NullOutboundInfo{}
|
2026-01-20 22:08:36 +00:00
|
|
|
|
r := player.Service.Egg.StartBreed(MalePet, Female)
|
|
|
|
|
|
if !r {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrCannotPerformAction
|
|
|
|
|
|
}
|
2026-02-09 01:29:33 +08:00
|
|
|
|
MalePet.Generation++
|
|
|
|
|
|
|
|
|
|
|
|
Female.Generation++
|
|
|
|
|
|
|
|
|
|
|
|
r1 := grand.Meet(1, 2)
|
|
|
|
|
|
if r1 {
|
|
|
|
|
|
MalePet.Gender = 0
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Female.Gender = 0
|
|
|
|
|
|
}
|
2026-01-19 18:51:56 +08:00
|
|
|
|
return result, 0
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetEggList 获取精灵蛋数组
|
|
|
|
|
|
// 前端到后端无数据 请求协议
|
|
|
|
|
|
func (ctl Controller) GetEggList(
|
2026-01-20 22:08:36 +00:00
|
|
|
|
data *pet.C2S_GET_EGG_LIST, player *player.Player) (result *pet.S2C_GET_EGG_LIST, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2026-01-19 18:51:56 +08:00
|
|
|
|
|
|
|
|
|
|
result = &pet.S2C_GET_EGG_LIST{}
|
|
|
|
|
|
// TODO: 实现获取精灵蛋列表的逻辑
|
|
|
|
|
|
// 示例数据,实际应从玩家数据中获取
|
2026-01-20 22:08:36 +00:00
|
|
|
|
r := player.Service.Egg.Get()
|
|
|
|
|
|
if r == nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-09 01:29:33 +08:00
|
|
|
|
result.EggList = append(result.EggList, r.EggList...)
|
2026-01-20 22:08:36 +00:00
|
|
|
|
|
2026-01-19 18:51:56 +08:00
|
|
|
|
return result, 0
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-09 01:29:33 +08:00
|
|
|
|
var limiter *ratelimit.Rule = ratelimit.NewRule()
|
|
|
|
|
|
|
|
|
|
|
|
// 简单规则案例
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
|
|
|
|
//步骤二:增加一条或者多条规则组成复合规则,此复合规则必须至少包含一条规则
|
|
|
|
|
|
limiter.AddRule(time.Second*1, 1)
|
|
|
|
|
|
//步骤三:调用函数判断某用户是否允许访问 allow:= r.AllowVisit(user)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-19 18:51:56 +08:00
|
|
|
|
// EffectHatch 精灵蛋互动协议
|
|
|
|
|
|
// 前端到后端
|
|
|
|
|
|
func (ctl Controller) EffectHatch(
|
|
|
|
|
|
data *pet.C2S_EFFECT_HATCH, playerObj *player.Player) (result *pet.S2C_EFFECT_HATCH, err errorcode.ErrorCode) {
|
2026-02-09 01:29:33 +08:00
|
|
|
|
if !limiter.AllowVisit(data.Head.UserID) {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrCannotPerformAction
|
|
|
|
|
|
}
|
2026-01-19 18:51:56 +08:00
|
|
|
|
result = &pet.S2C_EFFECT_HATCH{}
|
2026-02-09 01:29:33 +08:00
|
|
|
|
tt := uint32(grand.N(1, 4))
|
|
|
|
|
|
if tt == data.Index {
|
|
|
|
|
|
result.Intimacy = playerObj.Service.Egg.EffectHatch()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-19 18:51:56 +08:00
|
|
|
|
return result, 0
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// StartHatch 开始孵化精灵蛋
|
|
|
|
|
|
// 前端到后端
|
|
|
|
|
|
func (ctl Controller) StartHatch(
|
|
|
|
|
|
data *pet.C2S_START_HATCH, playerObj *player.Player) (result *pet.S2C_START_HATCH, err errorcode.ErrorCode) {
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: 实现开始孵化精灵蛋的具体逻辑
|
|
|
|
|
|
result = &pet.S2C_START_HATCH{}
|
2026-02-09 01:29:33 +08:00
|
|
|
|
r := playerObj.Service.Egg.StartEgg(data.OwnerID, data.EggCatchTime)
|
|
|
|
|
|
if !r {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrCannotPerformAction
|
|
|
|
|
|
}
|
2026-01-19 18:51:56 +08:00
|
|
|
|
return result, 0
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetHatchPet 获得孵化精灵协议
|
|
|
|
|
|
// 前端到后端无数据内容 请求协议
|
|
|
|
|
|
func (ctl Controller) GetHatchPet(
|
|
|
|
|
|
data *pet.C2S_GET_HATCH_PET, playerObj *player.Player) (result *pet.S2C_GET_HATCH_PET, err errorcode.ErrorCode) {
|
|
|
|
|
|
|
|
|
|
|
|
result = &pet.S2C_GET_HATCH_PET{}
|
|
|
|
|
|
// TODO: 实现获得孵化精灵的具体逻辑,这里暂时返回默认值
|
2026-02-09 01:29:33 +08:00
|
|
|
|
|
|
|
|
|
|
r := playerObj.Service.Egg.GetEgg()
|
2026-02-12 12:43:28 +08:00
|
|
|
|
if r == nil {
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
|
}
|
2026-03-11 12:19:13 +08:00
|
|
|
|
playerObj.Service.Pet.PetAdd(r, 0)
|
2026-02-09 01:29:33 +08:00
|
|
|
|
|
|
|
|
|
|
result.PetID = r.ID
|
|
|
|
|
|
result.CatchTime = r.CatchTime
|
2026-01-19 18:51:56 +08:00
|
|
|
|
return result, 0
|
|
|
|
|
|
|
2026-01-20 04:40:36 +08:00
|
|
|
|
}
|