refactor(assets): 重构资产同步流程并添加宠物相关功能
- 移除了资产同步到私有 B 仓库的工作流 - 在玩家结构中添加了 IsFighting 字段 - 新增了宠物信息相关功能和数据结构 - 优化了地图进入和怪物刷新逻辑 - 调整了玩家登录和地图数据发送流程 - 重构了部分代码以提高可维护性和性能
This commit is contained in:
@@ -9,64 +9,98 @@ const TableNamePet = "pet"
|
||||
// Pet mapped from table <pet>
|
||||
type Pet struct {
|
||||
*cool.Model
|
||||
PlayerID uint64 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
PlayerID uint32 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
Data string `gorm:"type:text;not null;comment:'精灵全部数据'" json:"data"`
|
||||
}
|
||||
|
||||
// PetInfo 精灵信息结构(合并后的优化版本)
|
||||
type PetInfo struct {
|
||||
// 第一个版本字段
|
||||
CapturePlayerID uint64 `json:"capture_player_id"`
|
||||
CaptureTime int64 `json:"capture_time"`
|
||||
CaptureMap int32 `json:"capture_map"`
|
||||
CaptureRect int16 `json:"capture_rect"`
|
||||
CaptureLevel int16 `json:"capture_level"`
|
||||
PetTypeID int32 `json:"pet_type_id"`
|
||||
IndividualValue int16 `json:"individual_value"`
|
||||
Nature int16 `json:"nature"`
|
||||
AbilityTypeEnum int16 `json:"ability_type_enum"`
|
||||
Shiny int32 `json:"shiny"`
|
||||
Level int16 `json:"level"`
|
||||
CurrentExp int32 `json:"current_exp"`
|
||||
CurrentHP int32 `json:"current_hp"`
|
||||
MaxHP int32 `json:"max_hp"`
|
||||
Attack int32 `json:"attack"`
|
||||
Defense int32 `json:"defense"`
|
||||
SpecialAttack int32 `json:"special_attack"`
|
||||
SpecialDefense int32 `json:"special_defense"`
|
||||
Speed int32 `json:"speed"`
|
||||
EvHP int16 `json:"ev_hp"`
|
||||
EvAttack int16 `json:"ev_attack"`
|
||||
EvDefense int16 `json:"ev_defense"`
|
||||
EvSpecialAttack int16 `json:"ev_special_attack"`
|
||||
EvSpecialDefense int16 `json:"ev_special_defense"`
|
||||
EvSpeed int16 `json:"ev_speed"`
|
||||
PetSkillLen int16 `struc:"sizeof=PetSkill" json:"pet_skill_len"`
|
||||
PetSkill []SkillInfo `json:"pet_skill"`
|
||||
ElementalOrbID int32 `json:"elemental_orb_id"`
|
||||
SpecialOrbID int32 `json:"special_orb_id"`
|
||||
ElementalOrbCount int16 `json:"elemental_orb_count"`
|
||||
SpecialOrbCount int16 `json:"special_orb_count"`
|
||||
IndividualGuarantee int64 `json:"individual_guarantee"`
|
||||
NatureGuarantee int64 `json:"nature_guarantee"`
|
||||
Freed bool `json:"freed"`
|
||||
FreedTime string `json:"freed_time"`
|
||||
// 精灵编号(@UInt long → uint32)
|
||||
ID uint32 `fieldDesc:"精灵编号" `
|
||||
|
||||
// 第二个版本字段
|
||||
ID uint32 `struc:"uint32" json:"id"`
|
||||
Name [16]byte `struc:"[16]byte" json:"name"`
|
||||
DV uint32 `struc:"uint32" json:"dv"`
|
||||
LvExp uint32 `struc:"uint32" json:"lv_exp"`
|
||||
NextLvExp uint32 `struc:"uint32" json:"next_lv_exp"`
|
||||
Defence uint32 `struc:"uint32" json:"defence"`
|
||||
SkillSize uint32 `struc:"uint32" json:"skill_size"`
|
||||
SkillList [4]SkillInfo `json:"skill_list"`
|
||||
CatchTime uint32 `struc:"uint32" json:"catch_time"`
|
||||
CatchRect uint32 `struc:"uint32" json:"catch_rect"`
|
||||
CatchLevel uint32 `struc:"uint32" json:"catch_level"`
|
||||
SkinID uint32 `struc:"uint32" json:"skin_id"`
|
||||
EffectInfoLen uint16 `struc:"sizeof=EffectInfo" json:"effect_info_len"`
|
||||
EffectInfo []PetEffectInfo `json:"effect_info"`
|
||||
// 名字:默认为全0,补齐到16字节(固定长度 → [16]byte)
|
||||
Name [16]byte `fieldDesc:"名字 默认为全0 但要补齐到16字节" serialize:"fixedLength=16,type=byteArray"`
|
||||
|
||||
// 个体值(@UInt long → uint32)
|
||||
Dv uint32 `fieldDesc:"个体值" `
|
||||
|
||||
// 性格(@UInt long → uint32)
|
||||
Nature uint32 `fieldDesc:"性格" `
|
||||
|
||||
// 等级(@UInt long → uint32)
|
||||
Level uint32 `fieldDesc:"等级" `
|
||||
|
||||
// 当前等级已获得经验(@UInt long → uint32)
|
||||
Exp uint32 `fieldDesc:"当前等级已经获得的经验 2538" `
|
||||
|
||||
// 当前等级所需经验(@UInt long → uint32)
|
||||
LvExp uint32 `fieldDesc:"当前等级所需的经验" `
|
||||
|
||||
// 升到下一级的经验(@UInt long → uint32)
|
||||
NextLvExp uint32 `fieldDesc:"升到下一级的经验" `
|
||||
|
||||
// 当前生命(@UInt long → uint32)
|
||||
Hp uint32 `fieldDesc:"当前生命" `
|
||||
|
||||
// 最大生命(@UInt long → uint32)
|
||||
MaxHp uint32 `fieldDesc:"最大生命" `
|
||||
|
||||
// 攻击(@UInt long → uint32)
|
||||
Attack uint32 `fieldDesc:"攻击" `
|
||||
|
||||
// 防御(@UInt long → uint32)
|
||||
Defence uint32 `fieldDesc:"防御" `
|
||||
|
||||
// 特攻(@UInt long → uint32)
|
||||
SpecialAttack uint32 `fieldDesc:"特攻" `
|
||||
|
||||
// 特防(@UInt long → uint32)
|
||||
SpecialDefence uint32 `fieldDesc:"特防" `
|
||||
|
||||
// 速度(@UInt long → uint32)
|
||||
Speed uint32 `fieldDesc:"速度" `
|
||||
|
||||
// 生命学习力(@UInt long → uint32)
|
||||
EvHp uint32 `fieldDesc:"生命学习力" `
|
||||
|
||||
// 攻击学习力(@UInt long → uint32)
|
||||
EvAttack uint32 `fieldDesc:"攻击学习力" `
|
||||
|
||||
// 防御学习力(@UInt long → uint32)
|
||||
EvDefence uint32 `fieldDesc:"防御学习力" `
|
||||
|
||||
// 特攻学习力(@UInt long → uint32)
|
||||
EvSpecialAttack uint32 `fieldDesc:"特攻学习力" `
|
||||
|
||||
// 特防学习力(@UInt long → uint32,注意原Java拼写:evSpecialDefense)
|
||||
EvSpecialDefense uint32 `fieldDesc:"特防学习力" `
|
||||
|
||||
// 速度学习力(@UInt long → uint32)
|
||||
EvSpeed uint32 `fieldDesc:"速度学习力" `
|
||||
SkillListLen uint32
|
||||
// 技能信息:固定4条,空则赋值0(固定长度List → [4]SkillInfo,零值即符合“赋值0”)
|
||||
SkillList [4]SkillInfo `fieldDesc:"32字节 技能信息 必须插入4条skillInfo,若技能信息为空则要赋值成0" serialize:"fixedLength=4,type=structArray"`
|
||||
|
||||
// 捕捉时间(@UInt long → 若为时间戳用uint32;若需时间类型可改为time.Time,需配合序列化处理)
|
||||
CatchTime uint32 `fieldDesc:"捕捉时间" `
|
||||
|
||||
// 捕捉地图(@UInt long → uint32)
|
||||
CatchMap uint32 `fieldDesc:"捕捉地图" `
|
||||
|
||||
// 未知默认0(@UInt long → uint32)
|
||||
CatchRect uint32 `fieldDesc:"未知默认为0" `
|
||||
|
||||
// 捕获等级默认0(@UInt long → uint32)
|
||||
CatchLevel uint32 `fieldDesc:"捕获等级 默认为0" `
|
||||
EffectInfoLen uint16 `struc:"sizeof=EffectInfo"`
|
||||
// 特性列表:长度用UShort存储(变长List → []PetEffectInfo + 长度前缀规则)
|
||||
EffectInfo []PetEffectInfo `fieldDesc:"特性列表, 长度在头部以UShort存储" serialize:"lengthFirst,lengthType=uint16,type=structArray"`
|
||||
|
||||
// 皮肤ID默认0(@UInt long → uint32)
|
||||
SkinID uint32 `fieldDesc:"皮肤id默认为0" `
|
||||
|
||||
// 是否闪光(@UInt long → uint32,0=否,1=是)
|
||||
Shiny uint32 `fieldDesc:"是不是闪" `
|
||||
}
|
||||
|
||||
// PetEffectInfo 精灵特性信息结构
|
||||
|
||||
@@ -85,8 +85,8 @@ type PlayerInfo struct {
|
||||
FightBadge uint32 `struc:"uint32" json:"fight_badge"` // 固定0
|
||||
MapID uint32 `struc:"uint32" default:"1" json:"map_id"` // 上线地图ID
|
||||
Pos Pos `json:"pos"` // 坐标
|
||||
TimeToday uint32 `struc:"uint32" default:"43200" json:"time_today"` // 已消耗时间(秒)
|
||||
TimeLimit uint32 `struc:"uint32" default:"339" json:"time_limit"` // 总电池限制(秒)
|
||||
TimeToday uint32 `struc:"uint32" default:"0" json:"time_today"` // 已消耗时间(秒)
|
||||
TimeLimit uint32 `struc:"uint32" default:"43200" json:"time_limit"` // 总电池限制(秒)
|
||||
IsClothHalfDay byte `struc:"byte" json:"is_cloth_half_day"` // 活动标志0/1
|
||||
IsRoomHalfDay byte `struc:"byte" json:"is_room_half_day"` // 活动标志0/1
|
||||
IFortressHalfDay byte `struc:"byte" json:"i_fortress_half_day"` // 活动标志0/1
|
||||
|
||||
@@ -3,6 +3,12 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type MonsterService struct {
|
||||
@@ -22,9 +28,29 @@ func NewMonsterService() *MonsterService {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *MonsterService) ModifyAfter(ctx g.Ctx, method string, param g.MapStrAny) (err error) {
|
||||
|
||||
gconv.String(param["map_id"])
|
||||
cool.DBM(s.Model).Cache((gdb.CacheOption{
|
||||
Duration: -1,
|
||||
Name: model.TableNameMonsterRefresh + gconv.String(param["map_id"]),
|
||||
Force: false,
|
||||
}))
|
||||
//todo 待测试,缓存优化
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *MonsterService) GetId(mapid uint32) uint32 {
|
||||
|
||||
m := cool.DBM(s.Model).Where("map_id", mapid)
|
||||
//todo 待修改更新时候删除缓存
|
||||
m := cool.DBM(s.Model).Where("map_id", mapid).Cache(
|
||||
gdb.CacheOption{
|
||||
Duration: time.Hour,
|
||||
Name: model.TableNameMonsterRefresh + strconv.Itoa(int(mapid)),
|
||||
Force: false,
|
||||
},
|
||||
)
|
||||
var tt []model.MonsterRefresh
|
||||
m.Scan(&tt)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user