This commit is contained in:
@@ -11,9 +11,9 @@ const (
|
||||
// Egg 性别配置模型(替换原宠物融合配方模型)
|
||||
type Egg struct {
|
||||
*cool.Model // 保留通用Model(ID/创建时间/更新时间等)
|
||||
//雄性
|
||||
MalePetIDs []int32 `gorm:"type:int[];comment:'雄性宠物ID列表(如:[1001,1002])'" json:"male_pet_ids"`
|
||||
//雌性
|
||||
MalePetIDs []int32 `gorm:"type:int[];comment:'雄性宠物ID列表(如:[1001,1002])'" json:"male_pet_ids"`
|
||||
//雄性
|
||||
FemalePetIDs []int32 `gorm:"type:int[];comment:'雌性宠物ID列表(如:[1001,1002])'" json:"female_pet_ids"`
|
||||
//子代指定性别配置表名
|
||||
OutputMons []int32 `gorm:"type:int[];not null;comment:'宠物类型ID'" json:"pet_type_id"`
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/common/utils"
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
)
|
||||
@@ -20,13 +21,36 @@ func NewEggService() *EggService {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *EggService) Get(id uint32) *model.Egg {
|
||||
if id == 0 {
|
||||
return nil
|
||||
}
|
||||
var item *model.Egg
|
||||
dbm(s.Model).Where("id", id).Scan(&item)
|
||||
func (s *EggService) GetData(p1 uint32) []int32 {
|
||||
//cacheKey := strings.Join([]string{fmt.Sprintf("%d", p1), fmt.Sprintf("%d", p2)}, ":")
|
||||
m := dbm(s.Model)
|
||||
|
||||
return item
|
||||
var pet []model.Egg //一个特性应该是唯一的,但是我们要获取默认随机特性
|
||||
m.Wheref(`male_pet_ids @> ARRAY[?]::integer[]`, p1).
|
||||
Where("is_enable", 1).Scan(&pet)
|
||||
var petIDs []int32
|
||||
for _, p := range pet {
|
||||
petIDs = append(petIDs, p.FemalePetIDs...)
|
||||
}
|
||||
|
||||
return petIDs
|
||||
|
||||
}
|
||||
func (s *EggService) GetResult(m, f uint32) uint32 {
|
||||
//cacheKey := strings.Join([]string{fmt.Sprintf("%d", p1), fmt.Sprintf("%d", p2)}, ":")
|
||||
md := dbm(s.Model)
|
||||
|
||||
var pet *model.Egg //一个特性应该是唯一的,但是我们要获取默认随机特性
|
||||
md.Wheref(`male_pet_ids @> ARRAY[?]::integer[]`, m).
|
||||
Wheref(`female_pet_ids @> ARRAY[?]::integer[]`, f).
|
||||
Where("is_enable", 1).Scan(&pet)
|
||||
if pet != nil {
|
||||
|
||||
t, _ := utils.RandomByWeight(pet.OutputMons, pet.Probs)
|
||||
return uint32(t)
|
||||
|
||||
}
|
||||
|
||||
return 0
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (s *PetFusionService) Data(p1, p2, rand uint32) uint32 {
|
||||
props = append(props, int(v.Probability))
|
||||
|
||||
}
|
||||
t,_:=utils.RandomByIntProbs(pets, props)
|
||||
t, _ := utils.RandomByWeight(pets, props)
|
||||
return uint32(t)
|
||||
//说明是失败,直接返回失败
|
||||
} else {
|
||||
|
||||
@@ -51,6 +51,7 @@ type EggInfo struct {
|
||||
EggID uint32 `json:"eggID"` // 精灵蛋ID
|
||||
MalePetID uint32 `json:"male"` // 雄性精灵ID
|
||||
FeMalePetID uint32 `json:"female"` // 雌性精灵ID
|
||||
//ShinyCode uint32 `struc:"skip"` //返回记录
|
||||
}
|
||||
|
||||
// TableName 返回表名
|
||||
|
||||
@@ -422,6 +422,9 @@ func GenPetInfo(
|
||||
dv, natureId, abilityTypeEnum, level int, shinyid []data.GlowFilter,
|
||||
gen int,
|
||||
) *PetInfo {
|
||||
if id == 0 {
|
||||
return nil
|
||||
}
|
||||
// 创建随机源
|
||||
//rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
@@ -447,6 +450,9 @@ func GenPetInfo(
|
||||
if gen == -1 {
|
||||
|
||||
p.Gender = grand.N(1, 4)
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
p.Gender = grand.N(1, 2)
|
||||
}
|
||||
if p.Gender == 3 || p.Gender == 4 {
|
||||
p.Gender = 0
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ func (s *RoomService) Get(userid uint32) model.BaseHouseEx {
|
||||
|
||||
}
|
||||
|
||||
|
||||
func (s *RoomService) Set(id []model.FitmentShowInfo) {
|
||||
//todo待测试
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
|
||||
Reference in New Issue
Block a user