```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(game): 实现扭蛋系统批量物品添加功能并优化地图逻辑

- 新增ItemAddBatch方法用于批量添加物品,支持普通道具和特殊道具的分别处理
- 优化扭蛋游戏玩法中的物品添加逻辑,使用新的批量接口提升性能
- 在扭蛋机器人命令中实现完整的物品检查和批量添加流程

refactor(map): 重构地图控制器代码结构并添加注释

- 为EnterMap、LeaveMap、GetMapPlayerList等方法添加中文注释
- 统一地图相关的命名规范,如enter
This commit is contained in:
昔念
2026-04-01 20:10:29 +08:00
parent 1b6586aedc
commit 5995f0670c
14 changed files with 597 additions and 214 deletions

View File

@@ -9,10 +9,21 @@ const (
TableNameMapModel = "map_model"
)
// 模型类型常量 (1:NPC, 2:精灵)
// 模型类型常量 (0:精灵, 1:NPC)
const (
MapModelTypePet = 0
MapModelTypeNPC = 1
MapModelTypePet = 2
)
const (
MapModelDirectionRight = iota
MapModelDirectionRightDown
MapModelDirectionDown
MapModelDirectionLeftDown
MapModelDirectionLeft
MapModelDirectionLeftUp
MapModelDirectionUp
MapModelDirectionRightUp
)
// MapModelBroadcastNode 地图模型广播节点配置
@@ -20,7 +31,7 @@ type MapModelBroadcastNode struct {
TriggerID uint32 `gorm:"comment:'触发器ID'" json:"trigger_id" description:"触发器ID"`
Pos string `gorm:"type:varchar(255);default:'';comment:'位置'" json:"pos" description:"位置"`
HP int32 `gorm:"type:int;default:0;comment:'血量'" json:"hp" description:"血量"`
Direction int32 `gorm:"type:int;default:0;comment:'方向'" json:"direction" description:"方向"`
Direction int32 `gorm:"type:int;default:2;comment:'BOSS方向(0-7)'" json:"direction" description:"BOSS方向"`
}
// MapModel 地图模型配置表(NPC/宠物)
@@ -34,7 +45,7 @@ type MapModel struct {
ModelID uint32 `gorm:"not null;default:0;comment:'模型ID(NPCID或精灵ID)'" json:"model_id" description:"模型ID"`
ModelType int32 `gorm:"type:int;default:1;comment:'模型类型(1:NPC,2:精灵)'" json:"model_type" description:"模型类型"`
ModelType int32 `gorm:"type:int;default:0;comment:'模型类型(0:精灵,1:NPC)'" json:"model_type" description:"模型类型"`
ModelName string `gorm:"type:varchar(100);default:'';comment:'模型名称'" json:"model_name" description:"模型名称"`

View File

@@ -29,7 +29,7 @@ type MapNode struct {
WinBonusID int `gorm:"type:int;default:0;comment:'胜利奖励ID'" json:"win_bonus_id"`
FailBonusID int `gorm:"type:int;default:0;comment:'失败奖励ID'" json:"fail_bonus_id"`
IsBroadcast uint32 `gorm:"type:int;default:0;comment:'是否需要广播'" json:"is_broadcast"`
IsBroadcast uint32 `gorm:"type:int;default:0;comment:'广播模型ID(0表示不广播)'" json:"is_broadcast"`
TriggerPlotID uint32 `gorm:"default:0;comment:'触发剧情ID0表示无剧情'" json:"trigger_plot_id" description:"触发剧情ID"`

View File

@@ -3,6 +3,10 @@ package service
import (
"blazing/cool"
"blazing/modules/config/model"
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/util/gconv"
)
type MapmodelService struct {
@@ -21,8 +25,57 @@ func NewMapmodelService() *MapmodelService {
}
}
func (s *MapmodelService) GetDataByModelId(modelid uint32) (ret *model.MapModel) {
func (s *MapmodelService) appendShinyFilter(item map[string]interface{}) map[string]interface{} {
if item == nil {
return item
}
shinyID := gconv.Int(item["shiny"])
if shinyID <= 0 {
shinyID = gconv.Int(item["shinyid"])
}
if shinyID <= 0 {
item["shiny_filter"] = nil
return item
}
item["shiny_filter"] = NewShinyService().GetShiny(shinyID)
return item
}
func (s *MapmodelService) ServiceInfo(ctx context.Context, req *cool.InfoReq) (data interface{}, err error) {
result, err := s.Service.ServiceInfo(ctx, req)
if err != nil || result == nil {
return result, err
}
record, ok := result.(gdb.Record)
if !ok || record.IsEmpty() {
return result, err
}
return s.appendShinyFilter(record.Map()), nil
}
func (s *MapmodelService) ServiceList(ctx context.Context, req *cool.ListReq) (data interface{}, err error) {
result, err := s.Service.ServiceList(ctx, req)
if err != nil || result == nil {
return result, err
}
rows, ok := result.(gdb.Result)
if !ok {
return result, err
}
list := make([]map[string]interface{}, 0, len(rows))
for _, row := range rows {
list = append(list, s.appendShinyFilter(row.Map()))
}
return list, nil
}
func (s *MapmodelService) GetDataByModelId(modelid uint32) (ret *model.MapModel) {
dbm_notenable(s.Model).Where("model_id", modelid).Scan(&ret)
return
}