diff --git a/src/HttpServer/jsonconf/jsonconf.go b/src/HttpServer/jsonconf/jsonconf.go index 7fa6c57..0581b5f 100644 --- a/src/HttpServer/jsonconf/jsonconf.go +++ b/src/HttpServer/jsonconf/jsonconf.go @@ -12,55 +12,65 @@ var ( ) type CardDesc struct { - Time int `json:"time"` - Ctype int `json:"type"` - Desc string `json:"desc"` + Time int `json:"time"` + Ctype int `json:"type"` + Desc string `json:"desc"` Flop_card string `json:"flop_card"` } type CatDesc struct { - Id int `json:"id"` - Name string `json:"name"` - Level_buy int `json:"level_buy"` - Rec_buy int `json:"rec_buy"` - Price string `json:"price"` - Gold_get string `json:"gold_get"` - Ratio float32 `json:"ratio"` - Increse_limit int `json:"increse_limit"` - Interval float32 `json:"interval"` + Id int `json:"id"` + Name string `json:"name"` + Level_buy int `json:"level_buy"` + Rec_buy int `json:"rec_buy"` + Price string `json:"price"` + Gold_get string `json:"gold_get"` + Ratio float32 `json:"ratio"` + Increse_limit int `json:"increse_limit"` + Interval float32 `json:"interval"` } type RedCatDesc struct { - Id int `json:"id"` - Name string `json:"name"` - Skin string `json:"skin"` - Money float32 `json:"money"` - Rate float32 `json:"rate"` - Is_37 int `json:"is_37"` - Dec_red string `json:"dec_red"` - Dec_get string `json:"dec_get"` + Id int `json:"id"` + Name string `json:"name"` + Skin string `json:"skin"` + Money float32 `json:"money"` + Rate float32 `json:"rate"` + Is_37 int `json:"is_37"` + Dec_red string `json:"dec_red"` + Dec_get string `json:"dec_get"` } type TurnTableDesc struct { - Id int `json:"id"` - Ttype int `json:"type"` - Rate float32 `json:"rate"` - Parameter int `json:"parameter"` - Desc string `json:"desc"` - Idx int `json:"idx"` + Id int `json:"id"` + Ttype int `json:"type"` + Rate float32 `json:"rate"` + Parameter int `json:"parameter"` + Desc string `json:"desc"` + Idx int `json:"idx"` } type GameConfig struct { - CardConfig []CardDesc - CatConfig []CatDesc - RedCatConfig []RedCatDesc - TurnTableConfig []TurnTableDesc + CardConfig []CardDesc + CatConfig []CatDesc + RedCatConfig []RedCatDesc + TurnTableConfig []TurnTableDesc } func GetJsonConf() *GameConfig { return g_jsonconf } +func GetTurnTable(ctype int) []TurnTableDesc { + var rtslice []TurnTableDesc + for _, v := range g_jsonconf.TurnTableConfig { + if v.Ttype == ctype { + rtslice = append(rtslice, v) + } + } + return rtslice +} + func GetCatConfig(lv int) *CatDesc { for _, v := range g_jsonconf.CatConfig { if v.Id == lv { @@ -70,6 +80,16 @@ func GetCatConfig(lv int) *CatDesc { return nil } +//获取转盘配置 +func GetTurnTableCfg(id int) *TurnTableDesc { + for _, v := range g_jsonconf.TurnTableConfig { + if v.Id == id { + return &v + } + } + return nil +} + //获取红包猫配置 func GetRedCatConfig(lv int) *RedCatDesc { reallv := lv - 100 @@ -84,7 +104,6 @@ func GetRedCatConfig(lv int) *RedCatDesc { return nil } - func file_get_contents(path string) ([]byte, error) { f, err := os.Open(path) if err != nil { @@ -148,8 +167,6 @@ func LoadJsonConf() error { return err } - - logger.Info("loadJsonConf success pconf=%v,err=%v", *g_jsonconf, err) return err } diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index bf2e016..a401c82 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -210,6 +210,30 @@ type AddTicketResp struct { Data AddTicketData `json:"data"` } +type MultipleData struct { +} + +type MultipleReq struct { + RewardId int `json:"rewardId"` +} + +type MultipleResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data MultipleData `json:"data"` +} + +type DrawTableData struct { + RewardId int `json:"rewardId"` + Coin string `json:"coin"` +} + +type DrawTableResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data DrawTableData `json:"data"` +} + type AcclecteBoxResp struct { Code int `json:"code"` Message string `json:"message"` @@ -584,6 +608,9 @@ type UserData struct { GetWatchAdsGoldTime int //看广告领金币次数 DrawTicket int //抽奖券次数 DrawTicketTimes int //剩余增加抽奖券次数 + DratMult int //下次抽奖的倍数 + DrawLastRewardId int //上一次的奖励ID + DrawTableCount int //当前抽奖次数 5次以后归零 IsAuto int //当前是否自动合成 IsBoxAcc int //是否处于加速生成箱子状态 RandGiftNum int //当前剩余空投猫粮次数 diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 659594d..fe13564 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -73,6 +73,52 @@ func (u *UserData) GetCatPos(catlv int) int { return pos } +//转盘抽奖 返回抽到的奖项的id +func (u *UserData) DrawTable() int { + idx := -1 + if u.DrawTableCount != 3 { + //抽a类型 + sumrate := float32(0) + tmprate := 0 + rand.Seed(time.Now().UnixNano()) + randnum := rand.Intn(100) + cflist := jsonconf.GetTurnTable(1) + for _, vv := range cflist { + sumrate += vv.Rate + } + + for _, v := range cflist { + tmprate += int(v.Rate / sumrate) + if tmprate >= randnum { + idx = v.Id + break + } + } + + } else { + //抽b类型 + sumrate := float32(0) + tmprate := 0 + rand.Seed(time.Now().UnixNano()) + randnum := rand.Intn(100) + cflist := jsonconf.GetTurnTable(2) + for _, vv := range cflist { + sumrate += vv.Rate + } + + for _, v := range cflist { + tmprate += int(v.Rate / sumrate) + if tmprate >= randnum { + idx = v.Id + break + } + } + } + + logger.Info("DrawTable idx=%v", idx) + return idx +} + func (u *UserData) HandlePassDay() { isdiffday := false nowtime := time.Now() @@ -108,7 +154,7 @@ func (u *UserData) HandlePassDay() { u.DoubleLeftTimes = ACCGOLDRATELIMIT u.GetWatchAdsGoldTime = WATCHADSGOLDLIMIT u.DrawTicket = DRAWTICKETNUM - u.DoubleLeftTimes = DRAWTICKETGETLIMIT + u.DrawTicketTimes = DRAWTICKETGETLIMIT } u.LastLoginTime = int(nowtime.Unix()) @@ -166,7 +212,9 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) { udata.RegTime = int(time.Now().Unix()) udata.LastLoginTime = int(time.Now().Unix()) udata.DrawTicket = DRAWTICKETNUM - udata.DoubleLeftTimes = DRAWTICKETGETLIMIT + udata.DrawTicketTimes = DRAWTICKETGETLIMIT + udata.DratMult = 1 + udata.DrawTableCount = 1 //初始化16个猫爬架 for i := 0; i < 16; i++ { diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index 2e36bc9..b9c6253 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -43,6 +43,8 @@ func startServerHttpServe() { http.HandleFunc("/api/home/limitCatList", LimitCatList) //分红猫列表 http.HandleFunc("/api/turntable/index", QueryTurntable) //转盘主页 http.HandleFunc("/api/turntable/addTicket", AddTicket) //增加抽奖券 + http.HandleFunc("/api/turntable/multiple", Multiple) //增加倍数 + http.HandleFunc("/api/turntable/draw", DrawTable) //抽奖 /////---------------------------------------------------------------------old http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置 @@ -637,6 +639,42 @@ func RedCatList(w http.ResponseWriter, r *http.Request) { //HandlerRecvTimingReward(w, s, Uuid) } +func DrawTable(w http.ResponseWriter, r *http.Request) { + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) + } + if Uuid == 0 { + SetHeader(w) + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("DrawTable , body:%v,uuid=%v", s, Uuid) + + HandlerDrawTable(w, s, Uuid) +} + +func Multiple(w http.ResponseWriter, r *http.Request) { + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) + } + if Uuid == 0 { + SetHeader(w) + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Multiple , body:%v,uuid=%v", s, Uuid) + + HandlerMultiple(w, s, Uuid) +} + func AddTicket(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index fb62775..60ecb40 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -403,6 +403,112 @@ func HandlerGetMainPageInfo(w http.ResponseWriter, data string, uuid int) { fmt.Fprint(w, string(respstr)) } +func HandlerDrawTable(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp DrawTableResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerDrawTable getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + //抽奖券数量是否足够 + if uinfo.DrawTicket <= 0 { + logger.Error("HandlerDrawTable ticketnotenough failed=%v", err) + resp.Code = 1 + resp.Message = "ticketnotenough" + break + } + + //根据抽奖次数 + tid := uinfo.DrawTable() + tablecfg := jsonconf.GetTurnTableCfg(tid) + if tablecfg == nil { + logger.Error("HandlerDrawTable tid failed=%v", tid) + resp.Code = 1 + resp.Message = "tidnotright" + break + } + + //加金币 此处现金概率为零不做处理 + + addgold := int64(tablecfg.Parameter) * uinfo.Goldrate + if uinfo.DratMult != 1 { + addgold = addgold * int64(uinfo.DratMult) + } + + uinfo.DrawTicket-- + uinfo.DratMult = 1 + uinfo.DrawTableCount++ + if uinfo.DrawTableCount > 5 { + uinfo.DrawTableCount = 1 + } + + uinfo.Gold += addgold + + resp.Data.Coin = strconv.FormatInt(uinfo.Gold, 10) + resp.Data.RewardId = tid + resp.Code = 0 + break + } + + //回包 + logger.Info("HandlerDrawTable resp=%+v", resp) + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + +func HandlerMultiple(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp MultipleResp + resp.Code = 0 + resp.Message = "success" + var rdata MultipleReq + + err := json.Unmarshal([]byte(data), &rdata) + for { + if err != nil { + logger.Error("HandlerMultiple json unmarshal failed=%v", err) + resp.Code = 1 + resp.Message = "json failed" + break + } + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerMultiple getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + cfg := jsonconf.GetTurnTableCfg(rdata.RewardId) + if cfg == nil { + logger.Error("HandlerMultiple getcfgfailed failed=%v", rdata.RewardId) + resp.Code = 1 + resp.Message = "getcfgfailed failed" + break + } + + uinfo.DratMult = cfg.Parameter + SaveUserInfo(uinfo, strconv.Itoa(uuid)) + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + func HandlerAddTicket(w http.ResponseWriter, data string, uuid int) { SetHeader(w) var resp AddTicketResp -- libgit2 0.21.0