From d4551a8c356f5d3fdc612c36deceaad249485465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <12574910+72wo@users.noreply.github.com> Date: Tue, 3 Mar 2026 01:07:30 +0800 Subject: [PATCH] =?UTF-8?q?```=20refactor(space):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=B9=B6=E4=BF=AE=E5=A4=8D=E5=8F=98=E9=87=8F=E4=BD=9C=E7=94=A8?= =?UTF-8?q?=E5=9F=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将tips和pits的初始化移到循环外部,避免重复创建 - 修复Name赋值位置,确保在正确时机设置空间名称 - 添加条件判断ret.Super != 0,优化性能 - 调整代码结构,提高可读性和维护性 - 移除注释掉的无用代码 ``` --- logic/service/space/space.go | 62 +++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/logic/service/space/space.go b/logic/service/space/space.go index f0546834..00989ed0 100644 --- a/logic/service/space/space.go +++ b/logic/service/space/space.go @@ -146,36 +146,6 @@ func (ret *Space) init() { maphot[ret.Super].TipInfoS = make(map[uint32]*TipInfo, 0) } - tips := &TipInfo{} - r := service.NewMapService().GetData(ret.ID) - if r != nil { - tips.Diao = service.NewMapService().GetData(ret.ID).DropItemIds - } - - pits := service.NewMapPitService().GetDataALL(ret.ID) - ret.PitS = csmap.New[int, []model.MapPit]() - - for _, v := range pits { - - tips.Pet = append(tips.Pet, v.RefreshID...) - for _, vp := range v.Pos { - t, ok := ret.PitS.Load(vp) - if ok { - t = append(t, v) - ret.PitS.Store(vp, t) - } else { - ret.PitS.Store(vp, []model.MapPit{v}) - } - - } - - } - - tips.Pet = lo.Union(tips.Pet) - tips.Talk = service.NewTalkConfigService().GetTip(ret.ID) - tips.Boss = service.NewMapNodeService().GetTip(ret.ID) - maphot[ret.Super].TipInfoS[ret.ID] = tips - ret.Name = v.Name //ogreconfig := service.NewMapPitService().GetData(ret.ID, uint32(i)) @@ -183,6 +153,38 @@ func (ret *Space) init() { } } + tips := &TipInfo{} + r := service.NewMapService().GetData(ret.ID) + if r != nil { + tips.Diao = service.NewMapService().GetData(ret.ID).DropItemIds + } + + pits := service.NewMapPitService().GetDataALL(ret.ID) + ret.PitS = csmap.New[int, []model.MapPit]() + + for _, v := range pits { + + tips.Pet = append(tips.Pet, v.RefreshID...) + for _, vp := range v.Pos { + t, ok := ret.PitS.Load(vp) + if ok { + t = append(t, v) + ret.PitS.Store(vp, t) + } else { + ret.PitS.Store(vp, []model.MapPit{v}) + } + + } + + } + + if ret.Super != 0 { + tips.Pet = lo.Union(tips.Pet) + tips.Talk = service.NewTalkConfigService().GetTip(ret.ID) + tips.Boss = service.NewMapNodeService().GetTip(ret.ID) + maphot[ret.Super].TipInfoS[ret.ID] = tips + } + } r := service.NewMapService().GetData(ret.ID)