This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/common/utils"
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/service"
|
||||
"blazing/modules/player/model"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
)
|
||||
|
||||
type EggService struct {
|
||||
@@ -23,6 +27,16 @@ func NewEggService(id uint32) *EggService {
|
||||
func (s *EggService) Get() (out *model.Egg) {
|
||||
|
||||
s.TestModel(s.Model).Scan(&out)
|
||||
if out != nil {
|
||||
BreedLeftTime := int64(out.Data.StartTime+out.CurEgg.EggID*uint32(time.Hour/1000000000)) - (time.Now().Unix())
|
||||
//判断是否繁殖完成
|
||||
if BreedLeftTime < 0 && out.Data.HatchState == 1 {
|
||||
out.Data.HatchState = 2
|
||||
} else {
|
||||
out.Data.HatchLeftTime = uint32(BreedLeftTime)
|
||||
}
|
||||
s.TestModel(s.Model).Save(out)
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
@@ -33,16 +47,124 @@ func (s *EggService) StartBreed(m, f *model.PetInfo) bool {
|
||||
s.TestModel(s.Model).Scan(&tt)
|
||||
if tt == nil {
|
||||
tt = &model.Egg{}
|
||||
tt.IsVip = cool.Config.ServerInfo.IsVip
|
||||
}
|
||||
//如果正在孵化中或者蛋列表超过4个了,就不能再开始新的繁殖了
|
||||
if len(tt.EggList) > 4 {
|
||||
return false
|
||||
}
|
||||
|
||||
cureff := model.EggInfo{FeMalePetID: f.ID, MalePetID: m.ID}
|
||||
|
||||
cureff.EggCatchTime = uint32(time.Now().Unix())
|
||||
|
||||
cureff.EggID = (uint32(m.Generation) + uint32(f.Generation)) / 2
|
||||
if cureff.EggID == 0 {
|
||||
cureff.EggID = 1
|
||||
}
|
||||
cureff.OwnerID = uint32(s.userid)
|
||||
|
||||
cureff.FeMalePetID = f.ID
|
||||
|
||||
cureff.MalePetID = m.ID
|
||||
tt.PlayerID = uint64(s.userid)
|
||||
//tt.CurEgg = cureff
|
||||
tt.EggList = append(tt.EggList, cureff)
|
||||
|
||||
s.TestModel(s.Model).Save(tt)
|
||||
return true
|
||||
}
|
||||
func (s *EggService) StartEgg(owner, eggc uint32) bool {
|
||||
|
||||
var tt *model.Egg
|
||||
s.TestModel(s.Model).Scan(&tt)
|
||||
if tt == nil {
|
||||
return false
|
||||
}
|
||||
if tt.Data.HatchState != 0 {
|
||||
return false
|
||||
|
||||
}
|
||||
|
||||
index, v, ok := utils.FindWithIndex(tt.EggList, func(item model.EggInfo) bool {
|
||||
return item.EggCatchTime == eggc
|
||||
})
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
tt.EggList = append(tt.EggList[:index], tt.EggList[index+1:]...) //删除精灵蛋
|
||||
tt.Data.StartTime = uint32(time.Now().Unix())
|
||||
|
||||
tt.Data.HatchState = 1
|
||||
tt.Data.FeMalePetCatchTime = f.CatchTime
|
||||
tt.Data.MalePetCatchTime = m.CatchTime
|
||||
tt.Data.FeMalePetID = f.ID
|
||||
tt.Data.MalePetID = m.ID
|
||||
|
||||
tt.Data.EggID = v.EggID
|
||||
|
||||
tt.Data.FeMalePetID = v.FeMalePetID
|
||||
|
||||
tt.Data.MalePetID = v.MalePetID
|
||||
|
||||
tt.PlayerID = uint64(s.userid)
|
||||
tt.CurEgg = *v
|
||||
|
||||
tt.Data.Intimacy = 1
|
||||
s.TestModel(s.Model).Save(tt)
|
||||
return true
|
||||
|
||||
}
|
||||
func (s *EggService) EffectHatch() uint32 {
|
||||
|
||||
var tt *model.Egg
|
||||
s.TestModel(s.Model).Scan(&tt)
|
||||
if tt == nil {
|
||||
return 1
|
||||
}
|
||||
if tt.Data.HatchState != 1 {
|
||||
return 1
|
||||
|
||||
}
|
||||
tt.Data.Intimacy += 1
|
||||
if tt.Data.Intimacy > 5 {
|
||||
tt.Data.Intimacy = 5
|
||||
}
|
||||
s.TestModel(s.Model).Save(tt)
|
||||
return tt.Data.Intimacy
|
||||
}
|
||||
func (s *EggService) GetEgg() *model.PetInfo {
|
||||
|
||||
var tt *model.Egg
|
||||
s.TestModel(s.Model).Scan(&tt)
|
||||
if tt == nil {
|
||||
return nil
|
||||
}
|
||||
if tt.Data.HatchState != 2 {
|
||||
return nil
|
||||
|
||||
}
|
||||
if tt.CurEgg.EggCatchTime == 0 {
|
||||
return nil
|
||||
|
||||
}
|
||||
mpets := service.NewEggService().GetResult(tt.CurEgg.MalePetID, tt.CurEgg.FeMalePetID)
|
||||
if mpets == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
dv := grand.N(int(tt.Data.Intimacy+tt.CurEgg.EggID*2), 31)
|
||||
p := model.GenPetInfo(int(mpets), dv, -1, 0, 1, nil, -1)
|
||||
shinycont := 0
|
||||
|
||||
if mpets != tt.CurEgg.MalePetID && mpets != tt.CurEgg.FeMalePetID {
|
||||
shinycont = int(tt.CurEgg.EggID)
|
||||
}
|
||||
|
||||
if grand.Meet(shinycont, 100) {
|
||||
p.FixShiny()
|
||||
}
|
||||
//直接覆盖当前蛋
|
||||
tt.Data.HatchState = 0
|
||||
p.Generation = uint16(tt.CurEgg.EggID) + 1
|
||||
tt.CurEgg = model.EggInfo{}
|
||||
s.TestModel(s.Model).Save(tt)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user