From 8dec37a4749a1a8ef8e28953b6aca919dbfb5731 Mon Sep 17 00:00:00 2001 From: xinian Date: Fri, 27 Feb 2026 14:48:10 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E6=80=AA?= =?UTF-8?q?=E7=89=A9=E6=8E=89=E8=90=BD=E5=92=8C=E9=97=AA=E5=85=89=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中与物品和闪光相关的冗余代码,将闪光处理逻辑整合到HandleNPCFightSpecial方法中 新增CanGetXUAN和CanGetItem方法用于判断是否获得特殊物品 添加S2C_GET_BOSS_MONSTER的ADD --- logic/controller/fight_boss野怪和地图怪.go | 49 +++++++++++-------- logic/service/fight/info/over.go | 7 +++ logic/service/player/Monster.go | 16 +------ logic/service/player/player.go | 55 +++++++++------------- logic/service/player/save.go | 38 +++++++++++++-- 5 files changed, 91 insertions(+), 74 deletions(-) diff --git a/logic/controller/fight_boss野怪和地图怪.go b/logic/controller/fight_boss野怪和地图怪.go index d24d4e95..ccd40548 100644 --- a/logic/controller/fight_boss野怪和地图怪.go +++ b/logic/controller/fight_boss野怪和地图怪.go @@ -161,35 +161,44 @@ func (Controller) OnPlayerFightNpcMonster(data1 *fight.FightNpcMonsterInboundInf fight.NewFight(p, ai, func(foi info.FightOverInfo) { //p.Done.Exec(model.MilestoneMode.Moster, []uint32{p.Info.MapID, monsterInfo.PetList[0].ID, uint32(foi.Reason)}, nil) - if foi.Reason == 0 && foi.WinnerId == p.Info.UserID { + if foi.Reason == 0 && foi.WinnerId == p.Info.UserID && p.CanGet() { exp := uint32(xmlres.PetMAP[int(monster.ID)].YieldingExp) * monster.Level / 7 addlevel, poolevel := p.CanGetExp() addexp := gconv.Float32(addlevel * gconv.Float32(exp)) - if addexp != 0 { - poolexp := gconv.Float32(poolevel) * gconv.Float32((exp)) - items := &info.S2C_GET_BOSS_MONSTER{} - p.ItemAdd(3, int64(poolexp+addexp)) - items.ItemList = append(items.ItemList, data.ItemInfo{ - ItemId: 3, - ItemCnt: int64(poolexp), - }) - p.AddPetExp(foi.Winpet, int64(addexp)) - for _, v := range refPet.Item { - count := int64(grand.Intn(2) + 1) - ok := p.ItemAdd(v, count) - if ok { - items.ItemList = append(items.ItemList, data.ItemInfo{ - ItemId: v, - ItemCnt: count, - }) - } + poolexp := gconv.Float32(poolevel) * gconv.Float32((exp)) + items := &info.S2C_GET_BOSS_MONSTER{} + p.ItemAdd(3, int64(poolexp+addexp)) + items.ADDitem(3, uint32(poolexp)) + + p.AddPetExp(foi.Winpet, int64(addexp)) + + if p.CanGetXUAN() { + xuan := 400686 + int64(xmlres.PetMAP[int(refPet.GetID())].Type) + ok := p.ItemAdd(xuan, 1) + if ok { + items.ADDitem(uint32(xuan), 1) } - p.SendPackCmd(8004, items) } + if p.CanGetItem() { + mapinfo := service.NewMapService().GetData(p.Info.MapID) + + if len(mapinfo.DropItemIds) > 0 { + + item := int64(mapinfo.DropItemIds[grand.Intn(len(mapinfo.DropItemIds))]) + count := int64(grand.Intn(2) + 1) + ok := p.ItemAdd(item, count) + if ok { + items.ADDitem(uint32(item),uint32 (count)) + } + } + + } + + p.SendPackCmd(8004, items) evs := gconv.Int64s(strings.Split(xmlres.PetMAP[int(monster.ID)].YieldingEV, " ")) diff --git a/logic/service/fight/info/over.go b/logic/service/fight/info/over.go index 54fb1310..2cdd5a4e 100644 --- a/logic/service/fight/info/over.go +++ b/logic/service/fight/info/over.go @@ -15,3 +15,10 @@ type S2C_GET_BOSS_MONSTER struct { // 2. 发放多个物品时:序列化时先写入 uint 类型的数组长度,再依次写入每个ItemInfo元素 // 3. 该List结构参考PetInfo的特性List(长度为Uint型,非int) } + +func (s *S2C_GET_BOSS_MONSTER) ADDitem(id, count uint32) { + s.ItemList = append(s.ItemList, data.ItemInfo{ + ItemId: int64(id), + ItemCnt: int64(count), + }) +} diff --git a/logic/service/player/Monster.go b/logic/service/player/Monster.go index f5db4b18..a112be1f 100644 --- a/logic/service/player/Monster.go +++ b/logic/service/player/Monster.go @@ -1,7 +1,6 @@ package player import ( - "blazing/cool" "blazing/modules/config/model" "blazing/modules/config/service" "sync/atomic" @@ -78,21 +77,8 @@ func (p *Player) GenMonster() { } p.Data[i].HandleNPCFightSpecial(v.IsCapture) - if cool.Config.ServerInfo.IsVip != 0 { //测试服,百分百异色 - p.Data[i].FixSHiny() - } else { - if p.Data[i].IsCapture != 0 && grand.Meet(1, 500) { - p.Data[i].RandomByWeightShiny() - - } - } - - if grand.Meet(3, 10) && len(mapinfo.DropItemIds) > 0 { - - p.Data[i].Item = append(p.Data[i].Item, int64(mapinfo.DropItemIds[grand.Intn(len(mapinfo.DropItemIds))])) - - } + } } diff --git a/logic/service/player/player.go b/logic/service/player/player.go index e4727356..f12a6be6 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -34,9 +34,10 @@ type OgrePetInfo struct { ShinyLen uint32 `json:"-" struc:"sizeof=ShinyInfo"` ShinyInfo []data.GlowFilter `json:"ShinyInfo,omitempty"` Lv uint32 `struc:"skip"` //等级 - Item []int64 `struc:"skip"` //奖励,如果有的话 - Ext uint32 `struc:"skip"` //是否变尼尔尼奥 - IsCapture int `struc:"skip"` + //XUANCAI int64 `struc:"skip"` + //Item int64 `struc:"skip"` //奖励,如果有的话 + Ext uint32 `struc:"skip"` //是否变尼尔尼奥 + IsCapture int `struc:"skip"` } func (o *OgrePetInfo) GetID() int { @@ -53,37 +54,6 @@ func (o *OgrePetInfo) GetLevel() int { } return int(o.Lv) } -func (o *OgrePetInfo) FixSHiny() { - var co *data.GlowFilter - if o.Ext == 0 { - - co = config.NewShinyService().RandShiny(o.ID) - } - - if co != nil && len(o.ShinyInfo) == 0 { - o.ShinyInfo = append(o.ShinyInfo, *co) - if grand.Meet(1, 2) { - o.Item = append(o.Item, 400686+int64(xmlres.PetMAP[int(o.ID)].Type)) - } - - } - -} -func (o *OgrePetInfo) RandomByWeightShiny() { - var co *data.GlowFilter - if o.Ext == 0 { - - co = config.NewShinyService().RandomByWeightShiny(o.ID) - } - - if co != nil && len(o.ShinyInfo) == 0 { - o.ShinyInfo = append(o.ShinyInfo, *co) - if grand.Meet(1, 2) { - o.Item = append(o.Item, 400686+int64(xmlres.PetMAP[int(o.ID)].Type)) - } - } - -} // handleNPCFightSpecial 处理NPC战斗特殊情况 func (o *OgrePetInfo) HandleNPCFightSpecial(v int) { @@ -106,7 +76,24 @@ func (o *OgrePetInfo) HandleNPCFightSpecial(v int) { } else { o.IsCapture = gconv.Int(petCfg.CatchRate) } + if o.Ext != 0 { + return + } + var co *data.GlowFilter + if cool.Config.ServerInfo.IsVip != 0 { //测试服,百分百异色 + co = config.NewShinyService().RandShiny(o.ID) + } else { + if o.IsCapture != 0 && grand.Meet(1, 500) { + + co = config.NewShinyService().RandomByWeightShiny(o.ID) + + } + } + if co != nil && len(o.ShinyInfo) == 0 { + o.ShinyInfo = append(o.ShinyInfo, *co) + + } } type Player struct { diff --git a/logic/service/player/save.go b/logic/service/player/save.go index c0f4ea1d..cf8b94b7 100644 --- a/logic/service/player/save.go +++ b/logic/service/player/save.go @@ -9,6 +9,8 @@ import ( "blazing/logic/service/space" "context" "time" + + "github.com/gogf/gf/v2/util/grand" ) // Save 保存玩家数据 @@ -62,18 +64,22 @@ func (p *Player) Save() { share.ShareManager.DeleteUserOnline(p.Info.UserID) //设置用户登录服务器 } - -// 经验倍数返回 -func (p *Player) CanGetExp() (float32, float32) { +func (p *Player) CanGet() bool { if p.Info.TimeToday >= p.Info.TimeLimit { - return 0, 0 + return false } islogintime := (int64(time.Now().Unix()) - int64(p.Logintime)) if islogintime > (p.Info.TimeLimit - p.Info.TimeToday) { - return 0, 0 + return false } + return true +} + +// 经验倍数返回 +func (p *Player) CanGetExp() (float32, float32) { + var base float32 = 1 if p.Info.TwoTimes != 0 { p.Info.TwoTimes-- @@ -87,3 +93,25 @@ func (p *Player) CanGetExp() (float32, float32) { } return (base), 0.2 } +func (p *Player) CanGetXUAN() bool { + var base = 1 + if p.Info.EnergyTime != 0 { + base = 2 + p.Info.EnergyTime-- + } + if grand.Meet(base, 2) { + return true + } + return false +} +func (p *Player) CanGetItem() bool { + var base = 3 + if p.Info.EnergyTime != 0 { + base = 6 + p.Info.EnergyTime-- + } + if grand.Meet(base, 10) { + return true + } + return false +}