```
feat(fight): 增加战斗模式枚举并重构战斗逻辑判断 - 引入完整的 BattleMode 枚举定义,替代原有的 BattleStatus,明确区分各类战斗场景 - 在多个控制器中替换对旧 Status 字段的依赖,统一使用 Mode 判断战斗状态 - 修复部分函数调用前未检查 FightC 是否为空的问题,增加 ErrBattleEnded 错误返回 - 调整
This commit is contained in:
@@ -9,8 +9,9 @@ import (
|
||||
type EnumMilestone int
|
||||
|
||||
var MilestoneMode = enum.New[struct {
|
||||
BOSS EnumMilestone //boss类
|
||||
ITEM EnumMilestone //物品类
|
||||
BOSS EnumMilestone //boss类 地图ID->BOSSID
|
||||
ITEM EnumMilestone //物品类 物品ID 使用精灵
|
||||
Fight EnumMilestone //挑战类 对战模式->对战类型->1是赢,0是总局数
|
||||
}]()
|
||||
|
||||
// 里程碑数据结构,与DoneEvent对应,记录单条里程碑的详细信息
|
||||
@@ -29,7 +30,7 @@ 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:jsonb;not null;comment:'里程碑ID'" json:"args"`
|
||||
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"`
|
||||
@@ -38,7 +39,7 @@ type Milestone struct {
|
||||
// MilestoneEX 里程碑扩展结构体,用于业务层解析后的数据操作
|
||||
type MilestoneEX struct {
|
||||
Milestone
|
||||
Args []uint32 `json:"args"` // 解析后的里程碑详细数据
|
||||
Args []uint32 // 解析后的里程碑详细数据
|
||||
Results []uint32 `json:"results"` // 解析后的里程碑详细数据
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type DoneService struct {
|
||||
@@ -10,15 +13,27 @@ type DoneService struct {
|
||||
}
|
||||
|
||||
func (s *DoneService) Exec(data model.EnumMilestone, id []uint32, fn func(*model.MilestoneEX) bool) {
|
||||
|
||||
m := s.GModel(s.Model).Where("done_type", data).Where("args", id)
|
||||
var tt model.MilestoneEX
|
||||
arss := strings.Join(gconv.Strings(id), "-")
|
||||
m := s.GModel(s.Model).Where("done_type", data).Where("args", arss)
|
||||
var tt *model.MilestoneEX
|
||||
m.Scan(&tt)
|
||||
ook := fn(&tt)
|
||||
if tt == nil {
|
||||
tt = &model.MilestoneEX{
|
||||
Milestone: model.Milestone{
|
||||
DoneType: data,
|
||||
Args: strings.Join(gconv.Strings(id), "-"),
|
||||
Count: 1,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
tt.Args = id
|
||||
ook := fn(tt)
|
||||
if !ook { //不需要保存
|
||||
return
|
||||
}
|
||||
tt.PlayerID = uint64(s.userid)
|
||||
tt.Milestone.Args = strings.Join(gconv.Strings(id), "-")
|
||||
|
||||
_, err := m.Save(tt)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user