``` feat(pet): 重构宠物繁殖系统,添加蛋孵化功能
This commit is contained in:
@@ -41,7 +41,7 @@ func (h Controller) GetServerOnline(data *user.SidInfo, c gnet.Conn) (result *rp
|
||||
ser := playerservice.NewUserService(data.Head.UserID)
|
||||
f, b := ser.Friend.Get()
|
||||
for _, v := range f {
|
||||
result.FriendInfo = append(result.FriendInfo, rpc.FriendInfo{v, 1})
|
||||
result.FriendInfo = append(result.FriendInfo, rpc.FriendInfo{Userid: v, TimePoke: 1})
|
||||
}
|
||||
result.BlackInfo = b
|
||||
defer func() {
|
||||
|
||||
@@ -5,22 +5,20 @@ import (
|
||||
"blazing/logic/service/fight"
|
||||
"blazing/logic/service/pet"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/player/model"
|
||||
)
|
||||
|
||||
// GetBreedInfo 获取繁殖信息协议
|
||||
// 前端到后端无数据 请求协议
|
||||
func (ctl Controller) GetBreedInfo(
|
||||
data *pet.C2S_GET_BREED_INFO, playerObj *player.Player) (result *pet.S2C_GET_BREED_INFO, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
data *pet.C2S_GET_BREED_INFO, player *player.Player) (result *model.S2C_GET_BREED_INFO, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
|
||||
result = &pet.S2C_GET_BREED_INFO{}
|
||||
result.BreedLeftTime = 5000
|
||||
result.HatchLeftTime = 5000
|
||||
result.HatchState = 1
|
||||
result.BreedState = 1
|
||||
result.EggID = 1
|
||||
result.Intimacy = 1
|
||||
result.FeMalePetID = 1
|
||||
result.MalePetID = 3
|
||||
result = &model.S2C_GET_BREED_INFO{}
|
||||
r := player.Service.Egg.Get()
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
result = &r.Data
|
||||
// TODO: 实现获取繁殖信息的具体逻辑
|
||||
return result, 0
|
||||
|
||||
@@ -45,10 +43,21 @@ func (ctl Controller) GetBreedPet(
|
||||
// StartBreed 开始繁殖协议
|
||||
// 前端到后端
|
||||
func (ctl Controller) StartBreed(
|
||||
data *pet.C2S_START_BREED, playerObj *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
|
||||
data *pet.C2S_START_BREED, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
_, 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
|
||||
}
|
||||
// TODO: 实现开始繁殖的具体逻辑
|
||||
result = &fight.NullOutboundInfo{}
|
||||
r := player.Service.Egg.StartBreed(MalePet, Female)
|
||||
if !r {
|
||||
return nil, errorcode.ErrorCodes.ErrCannotPerformAction
|
||||
}
|
||||
return result, 0
|
||||
|
||||
}
|
||||
@@ -56,15 +65,20 @@ func (ctl Controller) StartBreed(
|
||||
// GetEggList 获取精灵蛋数组
|
||||
// 前端到后端无数据 请求协议
|
||||
func (ctl Controller) GetEggList(
|
||||
data *pet.C2S_GET_EGG_LIST, playerObj *player.Player) (result *pet.S2C_GET_EGG_LIST, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
data *pet.C2S_GET_EGG_LIST, player *player.Player) (result *pet.S2C_GET_EGG_LIST, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
|
||||
result = &pet.S2C_GET_EGG_LIST{}
|
||||
// TODO: 实现获取精灵蛋列表的逻辑
|
||||
// 示例数据,实际应从玩家数据中获取
|
||||
result.EggList = append(result.EggList, pet.EggInfo{EggID: 1, OwnerID: 10001, EggCatchTime: 122123,
|
||||
MalePetID: 1,
|
||||
FeMalePetID: 3,
|
||||
})
|
||||
r := player.Service.Egg.Get()
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range r.EggList {
|
||||
result.EggList = append(result.EggList, v)
|
||||
}
|
||||
|
||||
return result, 0
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
func (h Controller) GetUserSimInfo(data *user.SimUserInfoInboundInfo, player *player.Player) (result *user.SimUserInfoOutboundInfo, err errorcode.ErrorCode) {
|
||||
result = &user.SimUserInfoOutboundInfo{}
|
||||
|
||||
copier.Copy(result, player.Service.Info.Person(data.UserId))
|
||||
copier.Copy(result, player.Service.Info.Person(data.UserId).Data)
|
||||
return result, 0
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func (h Controller) GetUserSimInfo(data *user.SimUserInfoInboundInfo, player *pl
|
||||
func (h Controller) GetUserMoreInfo(data *user.MoreUserInfoInboundInfo, player *player.Player) (result *user.MoreUserInfoOutboundInfo, err errorcode.ErrorCode) {
|
||||
result = &user.MoreUserInfoOutboundInfo{}
|
||||
info := player.Service.Info.Person(data.UserId)
|
||||
copier.CopyWithOption(result, info, copier.Option{IgnoreEmpty: true, DeepCopy: true})
|
||||
copier.CopyWithOption(result, info.Data, copier.Option{IgnoreEmpty: true, DeepCopy: true})
|
||||
|
||||
//todo 待实现
|
||||
return result, 0
|
||||
@@ -56,4 +56,4 @@ func (h Controller) GetPlayerExp(data *item.ExpTotalRemainInboundInfo, player *p
|
||||
|
||||
TotalExp: uint32(player.Info.ExpPool),
|
||||
}, 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,21 @@ func signalHandlerForMain(sig os.Signal) {
|
||||
|
||||
// main 程序主入口函数
|
||||
func main() {
|
||||
// item := model.NeweggConfig()
|
||||
// item.GeneratedPetIDs = []model.GeneratedPetID{
|
||||
// {PetID: 1, Prob: 0.01},
|
||||
// {PetID: 2, Prob: 0.01},
|
||||
// {PetID: 3, Prob: 0.01},
|
||||
// {PetID: 4, Prob: 0.01},
|
||||
// {PetID: 5, Prob: 0.01},
|
||||
// {PetID: 6, Prob: 0.01},
|
||||
// }
|
||||
// item.MalePet = 1
|
||||
// item.FemalePet = 2
|
||||
// _, err := g.DB(item.GroupName()).Model(item.TableName()).FieldsEx("id").Data(item).Insert()
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
//loadAccounts()
|
||||
// if cool.IsRedisMode {
|
||||
// go cool.ListenFunc(gctx.New())
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package pet
|
||||
|
||||
import "blazing/logic/service/common"
|
||||
import (
|
||||
"blazing/logic/service/common"
|
||||
"blazing/modules/player/model"
|
||||
)
|
||||
|
||||
// C2S_GET_BREED_PET 获取繁殖精灵协议
|
||||
// 前端到后端
|
||||
@@ -16,33 +19,6 @@ type S2C_GET_BREED_PET struct {
|
||||
FemaleList []uint32 `json:"femaleList"` // 可繁殖雌性的精灵数组 参数为精灵捕获时间
|
||||
}
|
||||
|
||||
// S2C_GET_BREED_INFO 获取繁殖信息协议
|
||||
// 后端到前端
|
||||
type S2C_GET_BREED_INFO struct {
|
||||
// BreedState 繁殖状态
|
||||
BreedState uint32 `json:"breedState"`
|
||||
// BreedLeftTime 繁殖剩余时间
|
||||
BreedLeftTime uint32 `json:"breedLeftTime"`
|
||||
// BreedCoolTime 繁殖冷却时间
|
||||
BreedCoolTime uint32 `json:"breedCoolTime"`
|
||||
// MalePetCatchTime 雄性精灵捕捉时间
|
||||
MalePetCatchTime uint32 `json:"malePetCatchTime"`
|
||||
// MalePetID 雄性精灵ID
|
||||
MalePetID uint32 `json:"malePetID"`
|
||||
// FeMalePetCatchTime 雌性精灵捕捉时间
|
||||
FeMalePetCatchTime uint32 `json:"feMalePetCatchTime"`
|
||||
// FeMalePetID 雌性精灵ID
|
||||
FeMalePetID uint32 `json:"feMalePetID"`
|
||||
// HatchState 孵化状态
|
||||
HatchState uint32 `json:"hatchState"`
|
||||
// HatchLeftTime 孵化剩余时间
|
||||
HatchLeftTime uint32 `json:"hatchLeftTime"`
|
||||
// EggID 当前孵化的精灵蛋ID
|
||||
EggID uint32 `json:"eggID"`
|
||||
// Intimacy 亲密度 1 = 悲伤 以此类推 ["悲伤","冷淡","平淡","友好","亲密无间"]
|
||||
Intimacy uint32 `json:"intimacy"`
|
||||
}
|
||||
|
||||
// C2S_GET_BREED_INFO 获取繁殖信息协议
|
||||
// 前端到后端无数据 请求协议
|
||||
type C2S_GET_BREED_INFO struct {
|
||||
@@ -58,17 +34,8 @@ type C2S_GET_EGG_LIST struct {
|
||||
// S2C_GET_EGG_LIST 获取精灵蛋数组协议
|
||||
// 后端到前端
|
||||
type S2C_GET_EGG_LIST struct {
|
||||
EggListLen uint32 `struc:"sizeof=EggList"`
|
||||
EggList []EggInfo `json:"eggList"` // 精灵蛋数组 跟其他数组一样 需要给有数量
|
||||
}
|
||||
|
||||
// EggInfo 精灵蛋信息
|
||||
type EggInfo struct {
|
||||
OwnerID uint32 `json:"ownerID"` // 所属人ID
|
||||
EggCatchTime uint32 `json:"eggCatchTime"` // 精灵蛋获得时间
|
||||
EggID uint32 `json:"eggID"` // 精灵蛋ID
|
||||
MalePetID uint32 `json:"male"` // 雄性精灵ID
|
||||
FeMalePetID uint32 `json:"female"` // 雌性精灵ID
|
||||
EggListLen uint32 `struc:"sizeof=EggList"`
|
||||
EggList []model.EggInfo `json:"eggList"` // 精灵蛋数组 跟其他数组一样 需要给有数量
|
||||
}
|
||||
|
||||
// C2S_START_HATCH 开始孵化精灵蛋协议
|
||||
|
||||
@@ -169,9 +169,9 @@ func (p *Player) SendPack(b []byte) error {
|
||||
if p.MainConn == nil {
|
||||
return nil
|
||||
}
|
||||
_, ok := p.MainConn.Context().(*ClientData)
|
||||
psocket, ok := p.MainConn.Context().(*ClientData)
|
||||
if ok {
|
||||
return p.MainConn.Context().(*ClientData).SendPack(b)
|
||||
return psocket.SendPack(b)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user