Files
bl/modules/blazing/model/done.go
昔念 1dbd4169e9 feat(xmlres): 更新 BOSS 配置结构并优化字段注释
新增多个 BOSS 相关配置字段,包括任务关联、奖励机制与挑战限制等,
增强 BOSS 精灵的可配置性与业务表达能力。同时完善字段注释以对齐 XML
实际使用情况,并保留原有部分字段用于兼容历史配置。

fix(fight): 调整战斗胜利回调执行顺序以确保数据一致性

将战斗结束回调移至广播之前执行,保证在发送战斗结果前已完成所有状态
更新,尤其是针对胜利宠物的信息同步
2025-11-22 22:57:32 +08:00

88 lines
3.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}]()
// 里程碑数据结构与DoneEvent对应记录单条里程碑的详细信息
// type MilestoneData struct {
// DoneType EnumMilestone `json:"done_type"` // 里程碑类型0-地图解锁1-BOSS击杀2-物品收集等)
// Args []uint32 `json:"args"` // 关联ID列表如地图ID、BOSSID、物品ID等
// Results []uint32 `json:"results"` // 完成情况参数(如:击杀次数、收集数量阈值等)
// Count uint32 `json:"count"` // 累计完成次数某BOSS累计击杀3次
// //IsCompleted bool `json:"is_completed"` // 是否完全达成(用于区分阶段性里程碑)
// }
const TableNameMilestone = "milestone"
// Milestone 数据库存储结构体映射milestone表
type Milestone struct {
*cool.Model
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{
Model: cool.NewModel(),
}
}
// init 初始化表
func init() {
cool.CreateTable(&Milestone{})
}