From 7ceb2fb3d6dc40b96f9fa710166d1ba3837688a8 Mon Sep 17 00:00:00 2001 From: xinian Date: Thu, 26 Feb 2026 13:38:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E6=80=AA?= =?UTF-8?q?=E7=89=A9=E7=94=9F=E6=88=90=E5=92=8C=E5=A4=A9=E6=B0=94=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将怪物捕捉处理逻辑移至OgrePetInfo结构体 提取天气和Boss生成逻辑为独立方法 移除未使用的导入和冗余代码 --- logic/service/player/Monster.go | 29 +------- logic/service/player/player.go | 22 ++++++ logic/service/space/space.go | 118 +++++++++++++++++--------------- 3 files changed, 85 insertions(+), 84 deletions(-) diff --git a/logic/service/player/Monster.go b/logic/service/player/Monster.go index 8d00210a7..7c051d144 100644 --- a/logic/service/player/Monster.go +++ b/logic/service/player/Monster.go @@ -1,14 +1,12 @@ package player import ( - "blazing/common/data/xmlres" "blazing/cool" "blazing/modules/config/model" "blazing/modules/config/service" "sync/atomic" "time" - "github.com/gogf/gf/v2/util/gconv" "github.com/gogf/gf/v2/util/grand" "github.com/samber/lo" ) @@ -67,16 +65,6 @@ func (p *Player) GenMonster() { p.Data[i].Lv = uint32(grand.N(v.MinLevel, v.MaxLevel)) - if v.IsCapture != 0 { - if handleNPCFightSpecial(p.Data[i].ID) == 0 { - p.Data[i].IsCapture = 0 - } else { - p.Data[i].IsCapture = handleNPCFightSpecial(p.Data[i].ID) //施加捕捉率 - } - } else { - p.Data[i].IsCapture = 0 - } - if len(v.RefreshID) == 1 { //说明这里只固定刷一个,概率变尼尔尼奥,不是稀有精灵 nieo := grand.Meet(20, 1000) @@ -88,11 +76,10 @@ func (p *Player) GenMonster() { p.Data[i].Lv = 16 - p.Data[i].IsCapture = handleNPCFightSpecial(p.Data[i].Ext) //解除捕捉限制 } } - + p.Data[i].HandleNPCFightSpecial(v.IsCapture) if cool.Config.ServerInfo.IsVip != 0 { //测试服,百分百异色 p.Data[i].FixSHiny() } else { @@ -205,17 +192,3 @@ func GenerateNormalizedColorMatrix() [20]uint8 { return matrix } - -// handleNPCFightSpecial 处理NPC战斗特殊情况 -func handleNPCFightSpecial(petID uint32) int { - - npcPetID := int(petID) - petCfg, ok := xmlres.PetMAP[npcPetID] - if !ok { - // log.Error(context.Background(), "NPC宠物配置不存在", "petID", npcPetID) - return 0 - } - - catchRate := gconv.Int(petCfg.CatchRate) - return catchRate -} diff --git a/logic/service/player/player.go b/logic/service/player/player.go index f5864521b..f848ed695 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -71,6 +71,28 @@ func (o *OgrePetInfo) RandomByWeightShiny() { } +// handleNPCFightSpecial 处理NPC战斗特殊情况 +func (o *OgrePetInfo) HandleNPCFightSpecial(v int) { + if v == 0 { + o.IsCapture = 0 + return + + } + npcPetID := int(o.ID) + if o.Ext != 0 { + npcPetID = int(o.Ext) + } + + petCfg, ok := xmlres.PetMAP[npcPetID] + if !ok { + + o.IsCapture = 0 + } else { + o.IsCapture = gconv.Int(petCfg.CatchRate) + } + +} + type Player struct { MainConn gnet.Conn baseplayer diff --git a/logic/service/space/space.go b/logic/service/space/space.go index c9b850c18..46ce30e96 100644 --- a/logic/service/space/space.go +++ b/logic/service/space/space.go @@ -39,9 +39,9 @@ type Space struct { Name string //地图名称 Owner ARENA info.MapBossSInfo - IsChange bool - - TimeBoss info.S2C_2022 + IsChange bool + WeatherType []uint32 + TimeBoss info.S2C_2022 //Weather uint32 IsTime bool //CanWeather uint32 @@ -100,29 +100,9 @@ func GetSpace(id uint32) *Space { ret.MapBossSInfo = info.MapBossSInfo{} ret.MapBossSInfo.INFO = make([]info.MapBossInfo, 0) if len(r.WeatherType) > 1 { + ret.WeatherType = r.WeatherType // ret.CanWeather = 1 - cool.Cron.CustomFunc(ret, func() { - //if ret.CanWeather == 1 { - var neww uint32 = 0 - - if len(r.WeatherType) == 2 { - neww, _ = utils.RandomByWeight(r.WeatherType, []uint32{9, 1}) - } else { - neww, _ = utils.RandomByWeight(r.WeatherType, []uint32{8, 1, 1}) - } - - if neww != uint32(ret.MapBossSInfo.Wer) { - ret.IsChange = true - ret.MapBossSInfo.Wer = int32(neww) - println(ret.Name, "change weather", neww) - - } else { - ret.IsChange = false - } - - //} - - }) + cool.Cron.CustomFunc(ret, ret.GenWer) } for _, v := range service.NewMapNodeService().GetData(ret.ID) { @@ -142,37 +122,8 @@ func GetSpace(id uint32) *Space { } if len(ret.MapBossSInfo.INFO) > 0 { - cool.Cron.ScheduleFunc(10*time.Second, func() { - - for i := 0; i < len(ret.MapBossSInfo.INFO); i++ { - s := len(ret.MapBossSInfo.INFO[i].PosInfo) - if s != 0 { - ret.MapBossSInfo.INFO[i].Pos = ret.MapBossSInfo.INFO[i].PosInfo[(grand.Intn(s-1)+1+int(ret.MapBossSInfo.INFO[i].PosIndex))%s] - } - - _, ok := lo.Find(ret.MapBossSInfo.INFO[i].Wer, func(item int32) bool { - return item == ret.MapBossSInfo.Wer - }) - if ok { - ret.MapBossSInfo.INFO[i].IsShow = 1 - if ret.IsChange { - ret.MapBossSInfo.INFO[i].IsShow = 2 - } - } else { - ret.MapBossSInfo.INFO[i].IsShow = 0 - - } - } - - ret.Broadcast(nil, 2021, &ret.MapBossSInfo) - - }) - cool.Cron.ScheduleFunc(300*time.Second, func() { - for _, v := range ret.MapBossSInfo.INFO { - atomic.StoreInt32(&v.Hp, int32(v.MaxHP)) - } - - }) + cool.Cron.ScheduleFunc(10*time.Second, ret.GenBoss) + cool.Cron.ScheduleFunc(300*time.Second, ret.HealHP) } } @@ -232,3 +183,58 @@ func (t *Space) Next(time.Time) time.Time { return time.Now().Add(grand.D(6*time.Second, 30*time.Second)) } +func (ret *Space) GenBoss() { + + for i := 0; i < len(ret.MapBossSInfo.INFO); i++ { + s := len(ret.MapBossSInfo.INFO[i].PosInfo) + if s != 0 { + ret.MapBossSInfo.INFO[i].Pos = ret.MapBossSInfo.INFO[i].PosInfo[(grand.Intn(s-1)+1+int(ret.MapBossSInfo.INFO[i].PosIndex))%s] + } + + _, ok := lo.Find(ret.MapBossSInfo.INFO[i].Wer, func(item int32) bool { + return item == ret.MapBossSInfo.Wer + }) + if ok { + ret.MapBossSInfo.INFO[i].IsShow = 1 + if ret.IsChange { + ret.MapBossSInfo.INFO[i].IsShow = 2 + } + } else { + ret.MapBossSInfo.INFO[i].IsShow = 0 + + } + } + + ret.Broadcast(nil, 2021, &ret.MapBossSInfo) + +} +func (ret *Space) HealHP() { + + for _, v := range ret.MapBossSInfo.INFO { + atomic.StoreInt32(&v.Hp, int32(v.MaxHP)) + } +} +func (ret *Space) GenWer() { + + //if ret.CanWeather == 1 { + var neww uint32 = 0 + + if len(ret.WeatherType) == 2 { + neww, _ = utils.RandomByWeight(ret.WeatherType, []uint32{9, 1}) + } else { + neww, _ = utils.RandomByWeight(ret.WeatherType, []uint32{8, 1, 1}) + } + + if neww != uint32(ret.MapBossSInfo.Wer) { + ret.IsChange = true + ret.MapBossSInfo.Wer = int32(neww) + ret.GenBoss() + println(ret.Name, "change weather", neww) + + } else { + ret.IsChange = false + } + + //} + +}