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 //背包缓存数据过期时间 ) const ( itemuse_nouse int32 = 1 //不可使用 itemuse_jump int32 = 2 //跳转 itemuse_exchange int32 = 3 //合成/分解(体力,兑换) itemuse_optionalbox int32 = 4 //自选宝箱 itemuse_randombox int32 = 5 //随机宝箱 itemuse_staminapotion int32 = 6 //体力药剂使用 ) var ( NoFoundItemConfig = errors.New("no found itemconfig!") //道具配置未找到 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.GameDropData) (prop *cfg.GameDropData) { 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 }