package srvdata import ( "sort" ) func init() { DataMgr.RegisterLoader("DB_Game_Drop.dat", GameDropMgrSingleton) } var GameDropMgrSingleton = &GameDropMgr{} type GameDropMgr struct { GameDropData []*GameDropData } func (this *GameDropMgr) Load(fileFullPath string) error { GameDropMgrSingleton.Init() return nil } func (this *GameDropMgr) Reload(fileFullPath string) error { GameDropMgrSingleton.Init() return nil } type GameDropData struct { Id int32 BaseCoin int64 ItemId int32 Rate int32 MinAmount int32 MaxAmount int32 } func (this *GameDropMgr) ModuleName() string { return "GameDropMgr" } func (this *GameDropMgr) Init() { this.GameDropData = this.GameDropData[:0] 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 = append(this.GameDropData, gdd1) } sort.Slice(this.GameDropData, func(i, j int) bool { return this.GameDropData[i].BaseCoin < this.GameDropData[j].BaseCoin }) } func (this *GameDropMgr) GetDropInfoByBaseScore(baseCoin int32) []*GameDropData { var ret []*GameDropData arr := this.GameDropData if len(arr) == 0 { return ret } i := sort.Search(len(arr), func(i int) bool { return arr[i].BaseCoin > int64(baseCoin) }) f := func(n int64, i int) { for ; i >= 0; i-- { if arr[i].BaseCoin == n { ret = append(ret, arr[i]) } else { break } } } // 找到 if i < len(arr) && i > 0 { n := arr[i-1].BaseCoin f(n, i-1) } if len(ret) == 0 { // 没找到,最大底注是否可用 i = len(arr) - 1 n := arr[i].BaseCoin if n <= int64(baseCoin) { f(n, i) } } return ret }