```
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

@@ -47,9 +47,8 @@ func (h Controller) EggGamePlay(data1 *C2S_EGG_GAME_PLAY, c *player.Player) (res
}
items := service.NewItemService().GetEgg(int(data1.EggNum))
for _, item := range items {
c.ItemAdd(item.ItemId, item.ItemCnt)
addedItems := c.ItemAddBatch(items)
for _, item := range addedItems {
result.ListInfo = append(result.ListInfo, data.ItemInfo{ItemId: item.ItemId, ItemCnt: item.ItemCnt})
}

View File

@@ -15,65 +15,63 @@ import (
"blazing/logic/service/space"
)
func (h Controller) EnterMap(data *space.InInfo, c *player.Player) (result *info.SimpleInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
// EnterMap 处理玩家进入地图。
func (h Controller) EnterMap(data *space.InInfo, c *player.Player) (result *info.SimpleInfo, err errorcode.ErrorCode) {
if c.Info.MapID != data.MapId {
atomic.StoreUint32(&c.Canmon, 2)
c.MapNPC.Reset(6 * time.Second)
} else {
atomic.StoreUint32(&c.Canmon, 1)
}
c.Info.MapID = data.MapId //登录地图
c.Info.MapID = data.MapId // 更新当前地图ID。
c.Info.Pos = data.Point
if cool.Config.ServerInfo.IsDebug != 0 {
println("进入地图", c.Info.UserID, c.Info.MapID)
println("enter map", c.Info.UserID, c.Info.MapID)
}
// copier.CopyWithOption(result, c.Info, copier.Option{DeepCopy: true})
c.GetSpace().EnterMap(c)
if data.MapId > 10000 && data.MapId != c.Info.UserID {
c.Service.Done.UpdateRoom(1, 0)
service.NewDoneService(data.MapId).UpdateRoom(0, 1)
}
return nil, -1
}
func (h Controller) GetMapHot(data *maphot.InInfo, c *player.Player) (result *maphot.OutInfo, err errorcode.ErrorCode) {
result = &maphot.OutInfo{
HotInfos: space.GetMapHot(),
}
return
}
func (h Controller) LeaveMap(data *space.LeaveMapInboundInfo, c *player.Player) (result *info.LeaveMapOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
// LeaveMap 处理玩家离开地图。
func (h Controller) LeaveMap(data *space.LeaveMapInboundInfo, c *player.Player) (result *info.LeaveMapOutboundInfo, err errorcode.ErrorCode) {
atomic.StoreUint32(&c.Canmon, 0)
c.GetSpace().LeaveMap(c) //玩家离开地图
c.GetSpace().LeaveMap(c) // 从当前空间移除玩家。
// 如果有正在运行的刷怪协程,发送停止信号
//c.Info.MapID = 0 // 重置当前地图
// 这里不直接清空 MapID由后续进入地图流程接管。
return nil, -1
}
func (h Controller) GetMapPlayerList(data *space.ListMapPlayerInboundInfo, c *player.Player) (result *info.ListMapPlayerOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
// GetMapPlayerList 获取当前地图内的玩家列表与地图广播信息。
func (h Controller) GetMapPlayerList(data *space.ListMapPlayerInboundInfo, c *player.Player) (result *info.ListMapPlayerOutboundInfo, err errorcode.ErrorCode) {
result = &info.ListMapPlayerOutboundInfo{
Player: c.GetSpace().GetInfo(c),
}
c.SendPackCmd(2003, result)
if atomic.LoadUint32(&c.GetSpace().TimeBoss.Flag) == 1 {
c.SendPackCmd(2022, &c.GetSpace().TimeBoss)
c.SendPackCmd(2021, &c.GetSpace().TimeBoss)
}
c.SendPackCmd(2021, c.GetSpace().GenBoss(true))
c.SendPackCmd(2022, c.GetSpace().GenBoss(true))
return nil, -1
}
func (h Controller) AttackBoss(data *space.AttackBossInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
// AttackBoss 调试扣减当前地图广播BOSS血量。
func (h Controller) AttackBoss(data *space.AttackBossInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
for i := 0; i < len(c.GetSpace().MapBossSInfo.INFO); i++ {
if atomic.LoadInt32(&c.GetSpace().MapBossSInfo.INFO[i].Hp) > 0 {
atomic.AddInt32(&c.GetSpace().MapBossSInfo.INFO[i].Hp, -1)