修改游戏掉落物品配置规则

This commit is contained in:
sk 2024-05-10 14:47:38 +08:00
parent 061ee27ab7
commit 9474b0dc30
2 changed files with 53 additions and 45 deletions

View File

@ -2119,7 +2119,7 @@ func (this *Scene) TryBillExGameDrop(p *Player) {
if baseScore == 0 { if baseScore == 0 {
return return
} }
dropInfo := srvdata.GameDropMgrSington.GetDropInfoByBaseScore(int32(this.GameId), baseScore) dropInfo := srvdata.GameDropMgrSingleton.GetDropInfoByBaseScore(int32(this.GameId), baseScore)
if dropInfo != nil && len(dropInfo) != 0 && p.Items != nil { if dropInfo != nil && len(dropInfo) != 0 && p.Items != nil {
realDrop := make(map[int32]int32) realDrop := make(map[int32]int32)
for _, drop := range dropInfo { for _, drop := range dropInfo {

View File

@ -1,32 +1,34 @@
package srvdata package srvdata
import ( import (
"strconv" "sort"
) )
func init() { func init() {
DataMgr.RegisterLoader("DB_Game_Drop.dat", GameDropMgrSington) DataMgr.RegisterLoader("DB_Game_Drop.dat", GameDropMgrSingleton)
} }
var GameDropMgrSington = &GameDropMgr{ var GameDropMgrSingleton = &GameDropMgr{
GameDropData: make(map[string][]*GameDropData), GameDropData: make(map[int32][]*GameDropData),
} }
type GameDropMgr struct { type GameDropMgr struct {
GameDropData map[string][]*GameDropData GameDropData map[int32][]*GameDropData // gameId:[]*GameDropData
} }
func (this *GameDropMgr) Load(fileFullPath string) error { func (this *GameDropMgr) Load(fileFullPath string) error {
GameDropMgrSington.Init() GameDropMgrSingleton.Init()
return nil return nil
} }
func (this *GameDropMgr) Reload(fileFullPath string) error { func (this *GameDropMgr) Reload(fileFullPath string) error {
GameDropMgrSington.Init() GameDropMgrSingleton.Init()
return nil return nil
} }
type GameDropData struct { type GameDropData struct {
Id int32
BaseCoin int64
ItemId int32 ItemId int32
Rate int32 Rate int32
MinAmount int32 MinAmount int32
@ -37,46 +39,52 @@ func (this *GameDropMgr) ModuleName() string {
return "GameDropMgr" return "GameDropMgr"
} }
func (this *GameDropMgr) GetKey(gameid, basescore int32) string { func (this *GameDropMgr) Init() {
return strconv.FormatInt(int64(gameid), 10) + "_" + strconv.FormatInt(int64(basescore), 10) this.GameDropData = make(map[int32][]*GameDropData)
if PBDB_Game_DropMgr.Datas == nil {
return
}
for _, v := range PBDB_Game_DropMgr.Datas.Arr {
//道具
if v.Amount1 == nil || len(v.Amount1) != 2 {
continue
}
if v.Rate1 <= 0 {
continue
}
gdd1 := &GameDropData{
Id: v.Id,
BaseCoin: int64(v.Bet),
ItemId: v.ItemId1,
Rate: v.Rate1,
MinAmount: v.Amount1[0],
MaxAmount: v.Amount1[1],
}
this.GameDropData[v.GameId] = append(this.GameDropData[v.GameId], gdd1)
}
for _, v := range this.GameDropData {
sort.Slice(v, func(i, j int) bool {
return v[i].BaseCoin < v[j].BaseCoin
})
}
} }
func (this *GameDropMgr) Init() { func (this *GameDropMgr) GetDropInfoByBaseScore(gameId, baseCoin int32) []*GameDropData {
this.GameDropData = make(map[string][]*GameDropData) var ret []*GameDropData
gdArr := PBDB_Game_DropMgr.Datas.Arr arr := this.GameDropData[gameId]
if gdArr != nil { i := sort.Search(len(arr), func(i int) bool {
for _, drop := range gdArr { return arr[i].BaseCoin > int64(baseCoin)
key := this.GetKey(drop.GameId, drop.Bet) })
//道具1 if i < len(arr) && i > 0 {
if drop.Amount1 == nil || len(drop.Amount1) != 2 { n := arr[i-1].BaseCoin
continue for i := i - 1; i >= 0; i-- {
if arr[i].BaseCoin == n {
ret = append(ret, arr[i])
} else {
break
} }
gdd1 := &GameDropData{
ItemId: drop.ItemId1,
Rate: drop.Rate1,
MinAmount: drop.Amount1[0],
MaxAmount: drop.Amount1[1],
}
this.GameDropData[key] = append(this.GameDropData[key], gdd1)
//道具2
//if drop.Amount2 == nil || len(drop.Amount2) != 2 {
// continue
//}
//gdd2 := &GameDropData{
// ItemId: drop.ItemId2,
// Rate: drop.Rate2,
// MinAmount: drop.Amount2[0],
// MaxAmount: drop.Amount2[1],
//}
//this.GameDropData[key] = append(this.GameDropData[key], gdd2)
} }
} }
} return ret
func (this *GameDropMgr) GetDropInfoByBaseScore(gameid, basescore int32) []*GameDropData {
key := this.GetKey(gameid, basescore)
if gdds, exist := this.GameDropData[key]; exist {
return gdds
}
return nil
} }