From 9474b0dc300e927c1e09eef1bdda6e41486b04ab Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Fri, 10 May 2024 14:47:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B8=B8=E6=88=8F=E6=8E=89?= =?UTF-8?q?=E8=90=BD=E7=89=A9=E5=93=81=E9=85=8D=E7=BD=AE=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gamesrv/base/scene.go | 2 +- srvdata/gamedropmgr.go | 96 +++++++++++++++++++++++------------------- 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/gamesrv/base/scene.go b/gamesrv/base/scene.go index e72a4a3..1622d65 100644 --- a/gamesrv/base/scene.go +++ b/gamesrv/base/scene.go @@ -2119,7 +2119,7 @@ func (this *Scene) TryBillExGameDrop(p *Player) { if baseScore == 0 { 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 { realDrop := make(map[int32]int32) for _, drop := range dropInfo { diff --git a/srvdata/gamedropmgr.go b/srvdata/gamedropmgr.go index a036ebf..557d4a3 100644 --- a/srvdata/gamedropmgr.go +++ b/srvdata/gamedropmgr.go @@ -1,32 +1,34 @@ package srvdata import ( - "strconv" + "sort" ) func init() { - DataMgr.RegisterLoader("DB_Game_Drop.dat", GameDropMgrSington) + DataMgr.RegisterLoader("DB_Game_Drop.dat", GameDropMgrSingleton) } -var GameDropMgrSington = &GameDropMgr{ - GameDropData: make(map[string][]*GameDropData), +var GameDropMgrSingleton = &GameDropMgr{ + GameDropData: make(map[int32][]*GameDropData), } type GameDropMgr struct { - GameDropData map[string][]*GameDropData + GameDropData map[int32][]*GameDropData // gameId:[]*GameDropData } func (this *GameDropMgr) Load(fileFullPath string) error { - GameDropMgrSington.Init() + GameDropMgrSingleton.Init() return nil } func (this *GameDropMgr) Reload(fileFullPath string) error { - GameDropMgrSington.Init() + GameDropMgrSingleton.Init() return nil } type GameDropData struct { + Id int32 + BaseCoin int64 ItemId int32 Rate int32 MinAmount int32 @@ -37,46 +39,52 @@ func (this *GameDropMgr) ModuleName() string { 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() { + 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() { - this.GameDropData = make(map[string][]*GameDropData) - gdArr := PBDB_Game_DropMgr.Datas.Arr - if gdArr != nil { - for _, drop := range gdArr { - key := this.GetKey(drop.GameId, drop.Bet) - //道具1 - if drop.Amount1 == nil || len(drop.Amount1) != 2 { - continue +func (this *GameDropMgr) GetDropInfoByBaseScore(gameId, baseCoin int32) []*GameDropData { + var ret []*GameDropData + arr := this.GameDropData[gameId] + 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 } - 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) } } -} - -func (this *GameDropMgr) GetDropInfoByBaseScore(gameid, basescore int32) []*GameDropData { - key := this.GetKey(gameid, basescore) - if gdds, exist := this.GameDropData[key]; exist { - return gdds - } - return nil + return ret }