refactor: 重构怪物掉落和闪光处理逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

移除OgrePetInfo中与物品和闪光相关的冗余代码,将闪光处理逻辑整合到HandleNPCFightSpecial方法中
新增CanGetXUAN和CanGetItem方法用于判断是否获得特殊物品
添加S2C_GET_BOSS_MONSTER的ADD
This commit is contained in:
xinian
2026-02-27 14:48:10 +08:00
committed by cnb
parent ad43fc8173
commit 8dec37a474
5 changed files with 91 additions and 74 deletions

View File

@@ -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, " "))

View File

@@ -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),
})
}

View File

@@ -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))]))
}
}
}

View File

@@ -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 {

View File

@@ -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
}