package items import ( "crypto/rand" "errors" "go_dreamfactory/lego/core" cfg "go_dreamfactory/sys/configure/structs" "math/big" ) const ( //Redis Redis_PackCache string = "pack:%s" //背包缓存数据存放key DB_PackTable core.SqlTable = "pack" //背包数据库定义表 ) const ( // GridCapMaxNum = 99 //单个格子的最大容量 GridMaxNUm = 1000 //背包格子数量上限 Pack_Expiration = -1 //背包缓存数据过期时间 ) var ( ItemNotEnoughError = errors.New("item not enough!") //物品不足 NoFoundGirdError = errors.New("no found gvrid!") //未找到格子 PackGridNumUpper = errors.New("grid amount upper!") //背包格子达到上限 GirdAmountUpper = errors.New("grid amount upper!") //格子容量达到上限 ) //随机权重宝箱 func RandomProps(group []*cfg.GamePropsgroupData) (prop *cfg.GamePropsgroupData) { if group == nil || len(group) == 0 { return } var ( totle int64 curr int64 temp int64 ) for _, v := range group { totle += int64(v.P) } n, _ := rand.Int(rand.Reader, big.NewInt(totle)) curr = n.Int64() for _, v := range group { temp += int64(v.P) if curr <= temp { prop = v return } } return }