修改游戏掉落物品配置规则
This commit is contained in:
parent
061ee27ab7
commit
9474b0dc30
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue