refactor: 重构怪物刷新和地图节点配置模型
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

将怪物刷新配置拆分为独立的 map_monster 和 map_moster_node 模型
新增 mapnode 模型用于管理地图节点配置
优化坑位绑定和刷新规则的数据结构
This commit is contained in:
xinian
2026-02-22 07:51:37 +08:00
committed by cnb
parent 4e313f02c7
commit f16838a916
4 changed files with 233 additions and 52 deletions

View File

@@ -0,0 +1,100 @@
package model
import (
"blazing/cool"
)
const (
TableNameMonsterRefresh = "config_monster_refresh" // 怪物刷新规则表(地图-精灵等级-刷新脚本配置)
)
// MonsterRefresh 怪物刷新规则模型(对应前端配置的地图/精灵/等级/脚本配置)
type MonsterRefresh struct {
*BaseConfig
MapID int32 `gorm:"not null;comment:'地图ID'" json:"map_id"`
// 坑位绑定配置(支持多坑位绑定,循环刷新)
PitID1 []int32 `gorm:"type:int8[];not null;comment:'坑位1绑定的坑位ID列表多绑循环刷'" json:"pit_id_1"`
PitID2 []int32 `gorm:"type:int8[];not null;comment:'坑位2绑定的坑位ID列表多绑循环刷'" json:"pit_id_2"`
PitID3 []int32 `gorm:"type:int8[];not null;comment:'坑位3绑定的坑位ID列表多绑循环刷'" json:"pit_id_3"`
PitID4 []int32 `gorm:"type:int8[];not null;comment:'坑位4绑定的坑位ID列表多绑循环刷'" json:"pit_id_4"`
PitID5 []int32 `gorm:"type:int8[];not null;comment:'坑位5绑定的坑位ID列表多绑循环刷'" json:"pit_id_5"`
PitID6 []int32 `gorm:"type:int8[];not null;comment:'坑位6绑定的坑位ID列表多绑循环刷'" json:"pit_id_6"`
PitID7 []int32 `gorm:"type:int8[];not null;comment:'坑位7绑定的坑位ID列表多绑循环刷'" json:"pit_id_7"`
PitID8 []int32 `gorm:"type:int8[];not null;comment:'坑位8绑定的坑位ID列表多绑循环刷'" json:"pit_id_8"`
PitID9 []int32 `gorm:"type:int8[];not null;comment:'坑位9绑定的坑位ID列表多绑循环刷'" json:"pit_id_9"`
}
type MonsterRefreshEX struct {
MonsterRefresh
MonsterID []uint32 `json:"monster_id"`
ShinyID []uint32 `json:"shiny_id"`
// 扩展便于批量处理9个坑位
PitIDs [9][]uint32 `json:"pit_ids"` // 整合所有坑位ID前端/业务层批量处理用
}
// TableName 指定MonsterRefresh对应的数据库表名
func (*MonsterRefresh) TableName() string {
return TableNameMonsterRefresh
}
// GroupName 指定表所属的分组(保持和参考示例一致)
func (*MonsterRefresh) GroupName() string {
return "default"
}
// NewMonsterRefresh 创建一个新的MonsterRefresh实例初始化通用Model
func NewMonsterRefresh() *MonsterRefresh {
return &MonsterRefresh{
BaseConfig: NewBaseConfig(),
}
}
// GetAllPitIDs 获取所有9个坑位的绑定ID列表辅助方法便于批量处理
func (m *MonsterRefresh) GetAllPitIDs() [9][]int32 {
return [9][]int32{
m.PitID1,
m.PitID2,
m.PitID3,
m.PitID4,
m.PitID5,
m.PitID6,
m.PitID7,
m.PitID8,
m.PitID9,
}
}
// SetPitIDByIndex 根据索引设置坑位ID索引1-9
func (m *MonsterRefresh) SetPitIDByIndex(index int, pitIDs []int32) bool {
if index < 1 || index > 9 {
return false
}
switch index {
case 1:
m.PitID1 = pitIDs
case 2:
m.PitID2 = pitIDs
case 3:
m.PitID3 = pitIDs
case 4:
m.PitID4 = pitIDs
case 5:
m.PitID5 = pitIDs
case 6:
m.PitID6 = pitIDs
case 7:
m.PitID7 = pitIDs
case 8:
m.PitID8 = pitIDs
case 9:
m.PitID9 = pitIDs
}
return true
}
// init 初始化表结构(程序启动时自动创建/同步表)
func init() {
cool.CreateTable(&MonsterRefresh{})
}