This commit is contained in:
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/cool"
|
||||
"blazing/logic/service/fight"
|
||||
"blazing/logic/service/pet"
|
||||
"blazing/logic/service/player"
|
||||
@@ -16,5 +17,9 @@ func (h Controller) HanLiuQiang(data *pet.C2S_2608, c *player.Player) (result *f
|
||||
if c.ItemAdd(100245, 1) {
|
||||
return
|
||||
}
|
||||
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
c.ItemAdd(500655, 1)
|
||||
}
|
||||
return result, -1
|
||||
}
|
||||
|
||||
@@ -157,6 +157,9 @@ func (Controller) OnPlayerFightNpcMonster(data1 *fight.FightNpcMonsterInboundInf
|
||||
if !p.CanFight() {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
if data1.Number > 9 {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
refPet := p.OgreInfo.Data[data1.Number]
|
||||
if refPet.ID == 0 {
|
||||
|
||||
|
||||
@@ -5,7 +5,13 @@ import (
|
||||
"blazing/logic/service/fight"
|
||||
"blazing/logic/service/pet"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/config/service"
|
||||
"blazing/modules/player/model"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
"github.com/samber/lo"
|
||||
"github.com/yudeguang/ratelimit"
|
||||
)
|
||||
|
||||
// GetBreedInfo 获取繁殖信息协议
|
||||
@@ -18,6 +24,7 @@ func (ctl Controller) GetBreedInfo(
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
|
||||
result = &r.Data
|
||||
// TODO: 实现获取繁殖信息的具体逻辑
|
||||
return result, 0
|
||||
@@ -28,11 +35,38 @@ func (ctl Controller) GetBreedInfo(
|
||||
// 前端到后端
|
||||
func (ctl Controller) GetBreedPet(
|
||||
data *pet.C2S_GET_BREED_PET, playerObj *player.Player) (result *pet.S2C_GET_BREED_PET, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
|
||||
_, 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
|
||||
}
|
||||
result = &pet.S2C_GET_BREED_PET{}
|
||||
// TODO: 实现获取可繁殖雌性精灵列表的逻辑
|
||||
|
||||
MPETS := service.NewEggService().GetData(fPet.ID)
|
||||
|
||||
// 这里只是示例,实际应该根据雄性精灵的catchTime查找可繁殖的雌性精灵
|
||||
for _, v := range playerObj.Info.PetList {
|
||||
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
|
||||
}
|
||||
// 如果是雌性精灵,且可以繁殖,则添加到列表
|
||||
result.FemaleList = append(result.FemaleList, v.CatchTime)
|
||||
}
|
||||
@@ -44,6 +78,11 @@ func (ctl Controller) GetBreedPet(
|
||||
// 前端到后端
|
||||
func (ctl Controller) StartBreed(
|
||||
data *pet.C2S_START_BREED, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
|
||||
if !player.GetCoins(1000) {
|
||||
return result, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
||||
}
|
||||
player.Info.Coins -= 1000
|
||||
_, MalePet, found := player.FindPet(data.Male)
|
||||
if !found {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
@@ -58,6 +97,16 @@ func (ctl Controller) StartBreed(
|
||||
if !r {
|
||||
return nil, errorcode.ErrorCodes.ErrCannotPerformAction
|
||||
}
|
||||
MalePet.Generation++
|
||||
|
||||
Female.Generation++
|
||||
|
||||
r1 := grand.Meet(1, 2)
|
||||
if r1 {
|
||||
MalePet.Gender = 0
|
||||
} else {
|
||||
Female.Gender = 0
|
||||
}
|
||||
return result, 0
|
||||
|
||||
}
|
||||
@@ -75,22 +124,36 @@ func (ctl Controller) GetEggList(
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range r.EggList {
|
||||
result.EggList = append(result.EggList, v)
|
||||
}
|
||||
result.EggList = append(result.EggList, r.EggList...)
|
||||
|
||||
return result, 0
|
||||
|
||||
}
|
||||
|
||||
var limiter *ratelimit.Rule = ratelimit.NewRule()
|
||||
|
||||
// 简单规则案例
|
||||
func init() {
|
||||
|
||||
//步骤二:增加一条或者多条规则组成复合规则,此复合规则必须至少包含一条规则
|
||||
limiter.AddRule(time.Second*1, 1)
|
||||
//步骤三:调用函数判断某用户是否允许访问 allow:= r.AllowVisit(user)
|
||||
|
||||
}
|
||||
|
||||
// EffectHatch 精灵蛋互动协议
|
||||
// 前端到后端
|
||||
func (ctl Controller) EffectHatch(
|
||||
data *pet.C2S_EFFECT_HATCH, playerObj *player.Player) (result *pet.S2C_EFFECT_HATCH, err errorcode.ErrorCode) {
|
||||
|
||||
if !limiter.AllowVisit(data.Head.UserID) {
|
||||
return nil, errorcode.ErrorCodes.ErrCannotPerformAction
|
||||
}
|
||||
result = &pet.S2C_EFFECT_HATCH{}
|
||||
// TODO: 实现精灵蛋互动逻辑,根据互动ID更新亲密度
|
||||
result.Intimacy = 1 // 悲伤
|
||||
tt := uint32(grand.N(1, 4))
|
||||
if tt == data.Index {
|
||||
result.Intimacy = playerObj.Service.Egg.EffectHatch()
|
||||
}
|
||||
|
||||
return result, 0
|
||||
|
||||
}
|
||||
@@ -102,6 +165,10 @@ func (ctl Controller) StartHatch(
|
||||
|
||||
// TODO: 实现开始孵化精灵蛋的具体逻辑
|
||||
result = &pet.S2C_START_HATCH{}
|
||||
r := playerObj.Service.Egg.StartEgg(data.OwnerID, data.EggCatchTime)
|
||||
if !r {
|
||||
return nil, errorcode.ErrorCodes.ErrCannotPerformAction
|
||||
}
|
||||
return result, 0
|
||||
|
||||
}
|
||||
@@ -113,8 +180,12 @@ func (ctl Controller) GetHatchPet(
|
||||
|
||||
result = &pet.S2C_GET_HATCH_PET{}
|
||||
// TODO: 实现获得孵化精灵的具体逻辑,这里暂时返回默认值
|
||||
result.PetID = 0
|
||||
result.CatchTime = 0
|
||||
|
||||
r := playerObj.Service.Egg.GetEgg()
|
||||
playerObj.Service.Pet.PetAdd(r)
|
||||
|
||||
result.PetID = r.ID
|
||||
result.CatchTime = r.CatchTime
|
||||
return result, 0
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user