``` feat(pet): 重构宠物繁殖系统,添加蛋孵化功能
This commit is contained in:
@@ -16,7 +16,7 @@ type PlayerPetSpecialEffect struct {
|
||||
SeIdx uint32 `gorm:"not null;uniqueIndex:idx_se_idx;comment:'精灵特效索引(XML中的Idx)'" json:"se_idx"`
|
||||
//Stat uint32 `gorm:"not null;default:0;comment:'精灵特效状态(XML中的Stat)'" json:"stat"`
|
||||
Eid uint32 `gorm:"not null;index:idx_eid;comment:'精灵特效Eid(XML中的Eid)'" json:"eid"`
|
||||
Args []int `gorm:"type:json;comment:'精灵特效参数(XML中的Args)'" json:"args"`
|
||||
Args []int `gorm:"type:jsonb;comment:'精灵特效参数(XML中的Args)'" json:"args"`
|
||||
Desc string `gorm:"type:varchar(255);default:'';comment:'精灵特效描述(XML中的Desc)'" json:"desc"`
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ type CDKConfig struct {
|
||||
|
||||
//cdk可兑换次数,where不等于0
|
||||
ExchangeRemainCount int64 `gorm:"not null;default:1;comment:'CDK剩余可兑换次数(不能为0才允许兑换,支持查询where !=0)'" json:"exchange_remain_count" description:"剩余可兑换次数"`
|
||||
ItemRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励物品ID数组,关联item_gift表主键'" json:"item_reward_ids" description:"奖励物品数组"`
|
||||
ElfRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励精灵ID数组,关联config_pet_boss表主键'" json:"elf_reward_ids" description:"奖励精灵数组"`
|
||||
ItemRewardIds []uint32 `gorm:"not null;type:jsonb;default:'[]';comment:'绑定奖励物品ID数组,关联item_gift表主键'" json:"item_reward_ids" description:"奖励物品数组"`
|
||||
ElfRewardIds []uint32 `gorm:"not null;type:jsonb;default:'[]';comment:'绑定奖励精灵ID数组,关联config_pet_boss表主键'" json:"elf_reward_ids" description:"奖励精灵数组"`
|
||||
TitleRewardIds uint32 `gorm:"not null;default:0;comment:'绑定奖励称号'" json:"title_reward_ids" description:"绑定奖励称号"`
|
||||
|
||||
ValidEndTime time.Time `gorm:"not null;comment:'CDK有效结束时间'" json:"valid_end_time" description:"有效结束时间"`
|
||||
|
||||
52
modules/config/model/egg.go
Normal file
52
modules/config/model/egg.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
// 表名常量定义:egg配置表
|
||||
const (
|
||||
TableNameeggConfig = "config_pet_egg" // egg配置表(记录egg编号、可兑换次数、奖励配置等核心信息)
|
||||
)
|
||||
|
||||
// EggConfig egg核心配置模型(含可兑换次数,满足查询`where 可兑换次数 != 0`需求)
|
||||
type EggConfig struct {
|
||||
*cool.Model
|
||||
|
||||
//雄性
|
||||
|
||||
MalePet int32 `gorm:"not null;comment:'雄性宠物ID'" json:"male_pet"`
|
||||
//雌性
|
||||
FemalePet int32 `gorm:"not null;comment:'雌性宠物ID'" json:"female_pet"`
|
||||
|
||||
// 生成的精灵ID及对应概率
|
||||
GeneratedPetIDs []GeneratedPetID `gorm:"type:jsonb;comment:'生成的精灵ID及概率配置'" json:"generated_pet_ids"`
|
||||
|
||||
Remark string `gorm:"size:512;default:'';comment:'egg备注'" json:"remark" description:"备注信息"`
|
||||
//ItemGift []*ItemGift `gorm:"-" orm:"with:item_id=id"`
|
||||
}
|
||||
type GeneratedPetID struct {
|
||||
PetID int32 `json:"pet_id" comment:"生成的精灵ID"`
|
||||
Prob float64 `json:"prob" comment:"该精灵生成概率"`
|
||||
}
|
||||
|
||||
// -------------------------- 核心配套方法(遵循项目规范)--------------------------
|
||||
func (*EggConfig) TableName() string {
|
||||
return TableNameeggConfig
|
||||
}
|
||||
|
||||
func (*EggConfig) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
func NeweggConfig() *EggConfig {
|
||||
return &EggConfig{
|
||||
Model: cool.NewModel(),
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------- 表结构自动同步 --------------------------
|
||||
func init() {
|
||||
|
||||
cool.CreateTable(&EggConfig{})
|
||||
}
|
||||
@@ -32,7 +32,7 @@ type TaskConfig struct {
|
||||
IsAcceptable uint32 `gorm:"not null;default:1;comment:'是否可以被接受'" json:"is_acceptable" description:"是否可以被接受"`
|
||||
|
||||
// 奖励配置
|
||||
ItemRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励物品ID数组,关联item_gift表主键'" json:"item_reward_ids" description:"奖励物品数组"`
|
||||
ItemRewardIds []uint32 `gorm:"not null;type:jsonb;default:'[]';comment:'绑定奖励物品ID数组,关联item_gift表主键'" json:"item_reward_ids" description:"奖励物品数组"`
|
||||
ElfRewardIds uint32 `gorm:"not null;default:0;comment:'绑定奖励精灵ID,关联elf_gift表主键'" json:"elf_reward_ids" description:"绑定奖励精灵ID"`
|
||||
|
||||
//绑定奖励
|
||||
|
||||
76
modules/player/model/egg.go
Normal file
76
modules/player/model/egg.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
// 表名常量
|
||||
const TableNamePlayerEgg = "player_egg"
|
||||
|
||||
// Egg 对应数据库表 player_cdk_log,用于记录CDK兑换日志
|
||||
type Egg struct {
|
||||
Base
|
||||
PlayerID uint64 `gorm:"not null;index:idx_player_Egg_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
Data S2C_GET_BREED_INFO `gorm:"type:jsonb;not null;comment:'全部数据'" json:"data"`
|
||||
CurEgg EggInfo `gorm:"type:jsonb;not null;comment:'当前蛋'" json:"cur_egg"`
|
||||
EggList []EggInfo `gorm:"type:jsonb;not null;comment:'蛋列表'" json:"egg_list"`
|
||||
}
|
||||
|
||||
// S2C_GET_BREED_INFO 获取繁殖信息协议
|
||||
// 后端到前端
|
||||
type S2C_GET_BREED_INFO struct {
|
||||
// BreedState 繁殖状态
|
||||
BreedState uint32 `json:"breedState"`
|
||||
StartTime uint32 `struc:"skip"` //返回记录
|
||||
// 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 孵化状态 ,0=未孵化 1=孵化中 2=已孵化
|
||||
HatchState uint32 `json:"hatchState"`
|
||||
// HatchLeftTime 孵化剩余时间
|
||||
HatchLeftTime uint32 `json:"hatchLeftTime"`
|
||||
// EggID 当前孵化的精灵蛋ID
|
||||
EggID uint32 `json:"eggID"`
|
||||
// Intimacy 亲密度 1 = 悲伤 以此类推 ["悲伤","冷淡","平淡","友好","亲密无间"]
|
||||
Intimacy uint32 `json:"intimacy"`
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// TableName 返回表名
|
||||
func (*Egg) TableName() string {
|
||||
return TableNamePlayerEgg
|
||||
}
|
||||
|
||||
// GroupName 返回表组名
|
||||
func (*Egg) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewEgg 创建一个新的CDK记录
|
||||
func NewEgg() *Egg {
|
||||
return &Egg{
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
// init 程序启动时自动创建表
|
||||
func init() {
|
||||
cool.CreateTable(&Egg{})
|
||||
}
|
||||
@@ -18,7 +18,7 @@ type SignInRecord struct {
|
||||
|
||||
IsCompleted bool `gorm:"not null;default:false;comment:'签到是否完成(0-未完成 1-已完成)'" json:"is_completed"`
|
||||
//通过bitset来实现签到的进度记录
|
||||
SignInProgress []uint32 `gorm:"type:json;not null;comment:'签到进度(状压实现,存储每日签到状态)'" json:"sign_in_progress"`
|
||||
SignInProgress []uint32 `gorm:"type:jsonb;not null;comment:'签到进度(状压实现,存储每日签到状态)'" json:"sign_in_progress"`
|
||||
}
|
||||
|
||||
// TableName 指定表名(遵循现有规范)
|
||||
|
||||
48
modules/player/service/egg.go
Normal file
48
modules/player/service/egg.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/player/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
type EggService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func NewEggService(id uint32) *EggService {
|
||||
return &EggService{
|
||||
|
||||
BaseService: BaseService{userid: id,
|
||||
|
||||
Service: &cool.Service{Model: model.NewEgg()},
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
func (s *EggService) Get() (out *model.Egg) {
|
||||
|
||||
s.TestModel(s.Model).Scan(&out)
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
func (s *EggService) StartBreed(m, f *model.PetInfo) bool {
|
||||
|
||||
var tt *model.Egg
|
||||
s.TestModel(s.Model).Scan(&tt)
|
||||
if tt == nil {
|
||||
tt = &model.Egg{}
|
||||
}
|
||||
if tt.Data.HatchState != 0 {
|
||||
return false
|
||||
|
||||
}
|
||||
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
|
||||
return true
|
||||
}
|
||||
@@ -53,17 +53,11 @@ func (s *InfoService) Reg(nick string, color uint32) {
|
||||
//go s.InitTask()
|
||||
}
|
||||
|
||||
func (s *InfoService) Person(userid uint32) *model.PlayerInfo {
|
||||
func (s *InfoService) Person(userid uint32) (out *model.PlayerEX) {
|
||||
|
||||
m := cool.DBM(s.Model).Where("player_id", userid)
|
||||
var tt model.PlayerEX
|
||||
err := m.Scan(&tt)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
cool.DBM(s.Model).Where("player_id", userid).Scan(&out)
|
||||
|
||||
ret := tt.Data
|
||||
return &ret
|
||||
return
|
||||
|
||||
}
|
||||
func (s *InfoService) GetCache() *model.PlayerInfo {
|
||||
|
||||
@@ -116,7 +116,7 @@ RETURNING max_ts;
|
||||
`, service.NewBaseSysUserService().Model.TableName())
|
||||
|
||||
// 执行 Raw SQL 并扫描返回值
|
||||
ret, err := cool.DBM(service.NewBaseSysUserService().Model).Raw(sql, s.userid).All()
|
||||
ret, _ := cool.DBM(service.NewBaseSysUserService().Model).Raw(sql, s.userid).All()
|
||||
//fmt.Println(ret, err)
|
||||
y.CatchTime = ret.Array()[0].Uint32()
|
||||
m1 := cool.DBM(s.Model).Where("player_id", s.userid)
|
||||
@@ -127,7 +127,7 @@ RETURNING max_ts;
|
||||
player.Free = 0
|
||||
player.IsVip = cool.Config.ServerInfo.IsVip
|
||||
|
||||
_, err = m1.Insert(player)
|
||||
_, err := m1.Insert(player)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ type UserService struct {
|
||||
Title *TitleService
|
||||
Cdk *CdkService
|
||||
Friend *FriendService
|
||||
Egg *EggService
|
||||
}
|
||||
|
||||
func NewUserService(id uint32) *UserService {
|
||||
@@ -38,6 +39,7 @@ func NewUserService(id uint32) *UserService {
|
||||
Title: NewTitleService(id),
|
||||
Cdk: NewCdkService(id),
|
||||
Friend: NewFriendService(id),
|
||||
Egg: NewEggService(id),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user