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

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 {
return strconv.FormatInt(int64(gameid), 10) + "_" + strconv.FormatInt(int64(basescore), 10)
}
func (this *GameDropMgr) Init() { func (this *GameDropMgr) Init() {
this.GameDropData = make(map[string][]*GameDropData) this.GameDropData = make(map[int32][]*GameDropData)
gdArr := PBDB_Game_DropMgr.Datas.Arr if PBDB_Game_DropMgr.Datas == nil {
if gdArr != nil { return
for _, drop := range gdArr { }
key := this.GetKey(drop.GameId, drop.Bet) for _, v := range PBDB_Game_DropMgr.Datas.Arr {
//道具1 //道具
if drop.Amount1 == nil || len(drop.Amount1) != 2 { if v.Amount1 == nil || len(v.Amount1) != 2 {
continue continue
} }
if v.Rate1 <= 0 {
continue
}
gdd1 := &GameDropData{ gdd1 := &GameDropData{
ItemId: drop.ItemId1, Id: v.Id,
Rate: drop.Rate1, BaseCoin: int64(v.Bet),
MinAmount: drop.Amount1[0], ItemId: v.ItemId1,
MaxAmount: drop.Amount1[1], Rate: v.Rate1,
MinAmount: v.Amount1[0],
MaxAmount: v.Amount1[1],
} }
this.GameDropData[key] = append(this.GameDropData[key], gdd1) this.GameDropData[v.GameId] = append(this.GameDropData[v.GameId], 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)
} }
for _, v := range this.GameDropData {
sort.Slice(v, func(i, j int) bool {
return v[i].BaseCoin < v[j].BaseCoin
})
} }
} }
func (this *GameDropMgr) GetDropInfoByBaseScore(gameid, basescore int32) []*GameDropData { func (this *GameDropMgr) GetDropInfoByBaseScore(gameId, baseCoin int32) []*GameDropData {
key := this.GetKey(gameid, basescore) var ret []*GameDropData
if gdds, exist := this.GameDropData[key]; exist { arr := this.GameDropData[gameId]
return gdds i := sort.Search(len(arr), func(i int) bool {
return arr[i].BaseCoin > int64(baseCoin)
})
if i < len(arr) && i > 0 {
n := arr[i-1].BaseCoin
for i := i - 1; i >= 0; i-- {
if arr[i].BaseCoin == n {
ret = append(ret, arr[i])
} else {
break
} }
return nil }
}
return ret
} }