refactor: 重构怪物刷新和地图节点配置模型
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
将怪物刷新配置拆分为独立的 map_monster 和 map_moster_node 模型 新增 mapnode 模型用于管理地图节点配置 优化坑位绑定和刷新规则的数据结构
This commit is contained in:
100
modules/config/model/map_monster.go
Normal file
100
modules/config/model/map_monster.go
Normal 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{})
|
||||
}
|
||||
46
modules/config/model/map_moster_node.go
Normal file
46
modules/config/model/map_moster_node.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
const (
|
||||
TableNameMapPit = "config_map_pit" // 地图坑位配置表(记录坑位归属、类型、属性、关联刷新规则等)
|
||||
)
|
||||
|
||||
// MapPit 地图坑位核心配置模型(参照MonsterRefresh实现风格)
|
||||
type MapPit struct {
|
||||
*BaseConfig // 复用通用基础配置(ID/创建时间/更新时间等)
|
||||
|
||||
PitName string `gorm:"type:varchar(100);default:'';comment:'坑位名称'" json:"pit_name"`
|
||||
|
||||
RefreshID []int `gorm:"type:int[];comment:'关联刷新规则ID列表'" json:"refresh_id"`
|
||||
//最小等级
|
||||
MinLevel int `gorm:"type:int;default:0;comment:'最小等级'" json:"min_level"`
|
||||
//最大等级
|
||||
MaxLevel int `gorm:"type:int;default:0;comment:'最大等级'" json:"max_level"`
|
||||
|
||||
Script string `gorm:"type:text;not null;comment:'刷新脚本(JS格式,对应前端编辑器配置)'" json:"value"`
|
||||
}
|
||||
|
||||
// TableName 指定MapPit对应的数据库表名(遵循原模型规范)
|
||||
func (*MapPit) TableName() string {
|
||||
return TableNameMapPit
|
||||
}
|
||||
|
||||
// GroupName 指定表所属的分组(保持和原模型一致)
|
||||
func (*MapPit) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewMapPit 创建一个新的MapPit实例(初始化通用BaseConfig)
|
||||
func NewMapPit() *MapPit {
|
||||
return &MapPit{
|
||||
BaseConfig: NewBaseConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
// init 初始化表结构(程序启动时自动创建/同步表)
|
||||
func init() {
|
||||
cool.CreateTable(&MapPit{})
|
||||
}
|
||||
87
modules/config/model/mapnode.go
Normal file
87
modules/config/model/mapnode.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
// 这个是替换盖亚的实现,因为是单独类的
|
||||
const (
|
||||
|
||||
// 新增地图节点表常量
|
||||
TableNameMapNode = "config_map_node" // 地图节点配置表(记录地图各节点的类型、绑定BOSS、剧情等信息)
|
||||
)
|
||||
|
||||
// 节点类型常量定义
|
||||
const (
|
||||
MapNodeTypeBoss = 1 // BOSS节点
|
||||
MapNodeTypeNPC = 2 // NPC节点
|
||||
MapNodeTypeScene = 3 // 场景触发节点
|
||||
MapNodeTypePortal = 4 // 传送门节点
|
||||
)
|
||||
|
||||
// MapNode 地图节点配置模型
|
||||
type MapNode struct {
|
||||
*BaseConfig
|
||||
|
||||
// 基础关联字段
|
||||
MapID uint32 `gorm:"not null;index;comment:'所属地图ID'" json:"map_id" description:"地图ID"`
|
||||
NodeName string `gorm:"type:varchar(100);default:'';comment:'节点名称'" json:"node_name" description:"节点名称"`
|
||||
//节点激活脚本
|
||||
NodeActiveScript string `gorm:"type:text;comment:'节点激活脚本'" json:"node_active_script" description:"节点激活脚本"`
|
||||
|
||||
// 节点核心配置
|
||||
NodeType int `gorm:"not null;default:0;comment:'节点类型(1-BOSS,2-NPC,3-场景触发,4-传送门)'" json:"node_type" description:"节点类型"`
|
||||
PositionX float64 `gorm:"not null;default:0;comment:'节点X坐标'" json:"position_x" description:"X坐标"`
|
||||
PositionY float64 `gorm:"not null;default:0;comment:'节点Y坐标'" json:"position_y" description:"Y坐标"`
|
||||
|
||||
// 剧情相关配置
|
||||
TriggerPlotID uint32 `gorm:"default:0;comment:'触发剧情ID(0表示无剧情)'" json:"trigger_plot_id" description:"触发剧情ID"`
|
||||
BindPlotIDs []uint32 `gorm:"type:int[];comment:'绑定的剧情ID列表'" json:"bind_plot_ids" description:"绑定剧情ID列表"`
|
||||
//完成后的脚本回调,比如战胜和击败绑定不同的任务ID,以及剧情绑定不同的ID
|
||||
PlotFinishScript string `gorm:"type:text;comment:'剧情完成后脚本回调'" json:"plot_finish_script" description:"剧情完成后脚本回调"`
|
||||
|
||||
// BOSS相关配置
|
||||
BindBossID uint32 `gorm:"default:0;comment:'绑定的BOSS ID(0表示无BOSS)'" json:"bind_boss_id" description:"绑定BOSS ID"`
|
||||
}
|
||||
|
||||
// -------------------------- MapNode 配套方法(遵循项目规范)--------------------------
|
||||
// TableName 指定数据库表名
|
||||
func (*MapNode) TableName() string {
|
||||
return TableNameMapNode
|
||||
}
|
||||
|
||||
// GroupName 指定分组名称(与原有规范保持一致)
|
||||
func (*MapNode) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewMapNode 创建MapNode实例
|
||||
func NewMapNode() *MapNode {
|
||||
return &MapNode{
|
||||
BaseConfig: NewBaseConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
// GetNodeTypeName 获取节点类型的中文名称(方便展示)
|
||||
func (m *MapNode) GetNodeTypeName() string {
|
||||
switch m.NodeType {
|
||||
case MapNodeTypeBoss:
|
||||
return "BOSS节点"
|
||||
case MapNodeTypeNPC:
|
||||
return "NPC节点"
|
||||
case MapNodeTypeScene:
|
||||
return "场景触发节点"
|
||||
case MapNodeTypePortal:
|
||||
return "传送门节点"
|
||||
default:
|
||||
return "未知节点"
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------- 表结构自动同步 --------------------------
|
||||
func init() {
|
||||
// 同步原有地图配置表
|
||||
cool.CreateTable(&MapConfig{})
|
||||
// 同步新增的地图节点配置表
|
||||
cool.CreateTable(&MapNode{})
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
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"`
|
||||
MonsterID string `gorm:"not null;comment:'精灵ID,填0为填充数组'" json:"monster_id"`
|
||||
MinLevel int32 `gorm:"not null;comment:'精灵最低等级'" json:"min_level"`
|
||||
MaxLevel int32 `gorm:"not null;comment:'精灵最高等级'" json:"max_level"`
|
||||
FixPos int32 `gorm:"not null;comment:'固定位置刷新(0:随机位置,没有固定位置的时候就会取一个随机位置,如果没有随机位置就不刷新,1-9:固定位置)'" json:"fix_pos"`
|
||||
Script string `gorm:"type:text;not null;comment:'刷新脚本(JS格式,对应前端编辑器配置)'" json:"value"`
|
||||
|
||||
// 以下为原模型保留的异色相关字段(前端暂未配置,如需移除可删除)
|
||||
ShinyID string `gorm:"not null;comment:'异色唯一标识ID'" json:"shiny_id"`
|
||||
}
|
||||
|
||||
type MonsterRefreshEX struct {
|
||||
MonsterRefresh
|
||||
MonsterID []uint32 `json:"monster_id"`
|
||||
ShinyID []uint32 `json:"shiny_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(),
|
||||
}
|
||||
}
|
||||
|
||||
// init 初始化表结构(程序启动时自动创建/同步表)
|
||||
func init() {
|
||||
cool.CreateTable(&MonsterRefresh{})
|
||||
}
|
||||
Reference in New Issue
Block a user