feat(cache): 添加复合键缓存操作支持 添加了基于 uint32+string 组合键的缓存操作方法,包括 GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和 ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景 fix(vscode): 添加 cSpell 配置支持 struc 词汇 refactor(session): 移除过时的会话管理方法 移除了基于单一字符串键的会话管理方法,因为已迁移到使用 复合键的缓存操作方式 ```
80 lines
2.4 KiB
Go
80 lines
2.4 KiB
Go
package model
|
||
|
||
import (
|
||
"blazing/cool"
|
||
|
||
"github.com/samber/lo"
|
||
"github.com/tnnmigga/enum"
|
||
)
|
||
|
||
type EnumMilestone int
|
||
|
||
var MilestoneMode = enum.New[struct {
|
||
BOSS EnumMilestone //boss类 地图ID->BOSSID ,胜利次数 mapid bossid petid,防止换boss后数据不可用
|
||
ITEM EnumMilestone //物品类 物品ID 使用精灵
|
||
Fight EnumMilestone //挑战类 对战模式->对战类型->1是赢,0是总局数
|
||
Moster EnumMilestone //野怪统计 地图ID->怪物ID
|
||
Task EnumMilestone
|
||
}]()
|
||
|
||
const TableNameMilestone = "player_milestone"
|
||
|
||
// Milestone 数据库存储结构体,映射milestone表
|
||
type Milestone struct {
|
||
Base
|
||
PlayerID uint64 `gorm:"not null;index:idx_milestone_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||
DoneType EnumMilestone `gorm:"not null;comment:'里程碑类型'" json:"done_type"`
|
||
Args string `gorm:"type:text;not null;comment:'里程碑ID'" json:"args"`
|
||
// 注:不单独设置"里程碑ID",通过 PlayerID + DoneType + IDs 组合唯一标识一个里程碑(更灵活)
|
||
Results string `gorm:"type:jsonb;not null;comment:'里程碑参数'" json:"results"`
|
||
Count uint32 `gorm:"not null;comment:'里程碑完成次数'" json:"count"`
|
||
}
|
||
|
||
// MilestoneEX 里程碑扩展结构体,用于业务层解析后的数据操作
|
||
type MilestoneEX struct {
|
||
Milestone
|
||
Args []uint32 // 解析后的里程碑详细数据
|
||
Results []uint32 `json:"results"` // 解析后的里程碑详细数据
|
||
}
|
||
|
||
// 检查是否触发过,成功返回触发的次数,失败返回0
|
||
func (m *MilestoneEX) CheakNoNumber(count uint32) bool {
|
||
// if v.DoneType == model.MilestoneMode.BOSS && IsPrefixBasicSlice(v.Args, []uint32{mapid, bossid}) && v.Count == count {
|
||
|
||
_, ok := lo.Find(m.Results, func(v1 uint32) bool { //寻找是否触发过
|
||
//大于触发值就触发,然后1的返回false,因为没有奖励,这样就可以一直触发
|
||
return v1 == count //大于等于就触发
|
||
})
|
||
//没找到且次数满足才能返回真
|
||
if !ok && m.Count >= count {
|
||
return true
|
||
}
|
||
|
||
//已经触发过
|
||
return false
|
||
|
||
// }
|
||
}
|
||
|
||
// TableName 返回表名
|
||
func (*Milestone) TableName() string {
|
||
return TableNameMilestone
|
||
}
|
||
|
||
// GroupName 返回表组名
|
||
func (*Milestone) GroupName() string {
|
||
return "default"
|
||
}
|
||
|
||
// NewMilestone 创建新里程碑实例
|
||
func NewMilestone() *Milestone {
|
||
return &Milestone{
|
||
Base: *NewBase(),
|
||
}
|
||
}
|
||
|
||
// init 初始化表
|
||
func init() {
|
||
cool.CreateTable(&Milestone{})
|
||
}
|