From 563689aefd6e36b452d54bbd151aa3166acead71 Mon Sep 17 00:00:00 2001 From: 陆恒 Date: Fri, 12 Jun 2020 10:41:29 +0800 Subject: [PATCH] 提交翻牌 --- src/HttpServer/jsonconf/RedCatConfig.json | 2 +- src/HttpServer/jsonconf/jsonconf.go | 10 ++++++++++ src/HttpServer/logic/constdef.go | 15 +++++++-------- src/HttpServer/logic/datadef.go | 29 +++++++++++++++++++++++++++++ src/HttpServer/logic/function.go | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/HttpServer/logic/httpserver.go | 38 ++++++++++++++++++++++++++++++++++++++ src/HttpServer/logic/logic.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 228 insertions(+), 9 deletions(-) diff --git a/src/HttpServer/jsonconf/RedCatConfig.json b/src/HttpServer/jsonconf/RedCatConfig.json index d38d798..54284d0 100644 --- a/src/HttpServer/jsonconf/RedCatConfig.json +++ b/src/HttpServer/jsonconf/RedCatConfig.json @@ -1 +1 @@ -[{"id":1,"name":"全球招财猫","skin":"abonus","money":0,"rate":0.002,"is_37":1,"dec_red":"每天获得平台收益分红20%","dec_get":"1.1周内邀请人数排名前10,
官方将主动联系赠予"},{"id":2,"name":"1天招财猫","skin":"abonus","money":150,"rate":0,"is_37":1,"dec_red":"获得1天平台收益","dec_get":"1.2只36级猫合成可能获得
2.五大神猫合成必得"},{"id":3,"name":"东方招财猫","skin":"dir1","money":0,"rate":300,"is_37":1,"dec_red":"集齐5大神猫,可召唤一天招财猫","dec_get":"1.2只36级猫合成可能获得"},{"id":4,"name":"南方招财猫","skin":"dir2","money":0,"rate":200,"is_37":1,"dec_red":"集齐5大神猫,可召唤一天招财猫","dec_get":"1.2只36级猫合成可能获得"},{"id":5,"name":"西方招财猫","skin":"dir3","money":0,"rate":200,"is_37":1,"dec_red":"集齐5大神猫,可召唤一天招财猫","dec_get":"1.2只36级猫合成可能获得"},{"id":6,"name":"北方招财猫","skin":"dir4","money":0,"rate":100,"is_37":1,"dec_red":"集齐5大神猫,可召唤一天招财猫","dec_get":"1.2只36级猫合成可能获得"},{"id":7,"name":"正中招财猫","skin":"dir5","money":0,"rate":0,"is_37":1,"dec_red":"集齐5大神猫,可召唤一天招财猫","dec_get":"1.2只36级猫合成可能获得"},{"id":8,"name":"情侣猫男","skin":"man","money":0,"rate":120,"is_37":1,"dec_red":"两只不同性别的情侣猫合成可获得52元红包","dec_get":"1.2只36级猫合成可能获得"},{"id":9,"name":"情侣猫女","skin":"woman","money":52,"rate":0,"is_37":1,"dec_red":"两只不同性别的情侣猫合成可获得52元红包","dec_get":"1.2只36级猫合成可能获得"},{"id":10,"name":"红包猫","skin":"redpacket","money":5,"rate":70,"is_37":0,"dec_red":"点击打开将直接获得5元红包","dec_get":"1.2只36级猫合成可能获得
2.幸运扑克牌抽取获得
3.大转盘抽奖获得"},{"id":11,"name":"发财猫","skin":"gambling","money":88,"rate":0,"is_37":0,"dec_red":"每期号码达到150,中午12.00开奖88元红包","dec_get":"1.幸运扑克牌抽取获得"},{"id":12,"name":"限时招财猫","skin":"abonus","money":0.17,"rate":0,"is_37":0,"dec_red":"可获得5-15min全平台分红","dec_get":"1.幸运扑克牌抽取获得"},{"id":13,"name":"10min招财猫","skin":"abonus","money":0.35,"rate":0,"is_37":0,"dec_red":"","dec_get":""},{"id":14,"name":"15min招财猫","skin":"abonus","money":1.563,"rate":0,"is_37":0,"dec_red":"","dec_get":""}] \ No newline at end of file +[{"id":1,"name":"全球招财猫","skin":"abonus","money":0,"rate":0.002,"is_37":1,"dec_red":"每天获得平台收益分红20%","dec_get":"1.1周内邀请人数排名前10,
官方将主动联系赠予"},{"id":2,"name":"1天招财猫","skin":"abonus","money":150,"rate":0,"is_37":1,"dec_red":"获得1天平台收益","dec_get":"1.2只36级猫合成可能获得
2.五大神猫合成必得"},{"id":3,"name":"东方招财猫","skin":"dir1","money":0,"rate":300,"is_37":1,"dec_red":"集齐5大神猫,可召唤一天招财猫","dec_get":"1.2只36级猫合成可能获得"},{"id":4,"name":"南方招财猫","skin":"dir2","money":0,"rate":200,"is_37":1,"dec_red":"集齐5大神猫,可召唤一天招财猫","dec_get":"1.2只36级猫合成可能获得"},{"id":5,"name":"西方招财猫","skin":"dir3","money":0,"rate":200,"is_37":1,"dec_red":"集齐5大神猫,可召唤一天招财猫","dec_get":"1.2只36级猫合成可能获得"},{"id":6,"name":"北方招财猫","skin":"dir4","money":0,"rate":100,"is_37":1,"dec_red":"集齐5大神猫,可召唤一天招财猫","dec_get":"1.2只36级猫合成可能获得"},{"id":7,"name":"正中招财猫","skin":"dir5","money":0,"rate":0,"is_37":1,"dec_red":"集齐5大神猫,可召唤一天招财猫","dec_get":"1.2只36级猫合成可能获得"},{"id":8,"name":"情侣猫男","skin":"man","money":0,"rate":120,"is_37":1,"dec_red":"两只不同性别的情侣猫合成可获得52元红包","dec_get":"1.2只36级猫合成可能获得"},{"id":9,"name":"情侣猫女","skin":"woman","money":52,"rate":0,"is_37":1,"dec_red":"两只不同性别的情侣猫合成可获得52元红包","dec_get":"1.2只36级猫合成可能获得"},{"id":10,"name":"红包猫","skin":"redpacket","money":5,"rate":70,"is_37":0,"dec_red":"点击打开将直接获得5元红包","dec_get":"1.2只36级猫合成可能获得
2.幸运扑克牌抽取获得
3.大转盘抽奖获得"},{"id":11,"name":"发财猫","skin":"gambling","money":88,"rate":0,"is_37":0,"dec_red":"每期号码达到150,中午12.00开奖88元红包","dec_get":"1.幸运扑克牌抽取获得"},{"id":12,"name":"限时招财猫","skin":"abonus","money":0.17,"rate":0,"is_37":0,"dec_red":"可获得5-15min全平台分红","dec_get":"1.幸运扑克牌抽取获得"},{"id":13,"name":"10min招财猫","skin":"abonus","money":0.35,"rate":0,"is_37":0,"dec_red":"","dec_ get":""},{"id":14,"name":"15min招财猫","skin":"abonus","money":1.563,"rate":0,"is_37":0,"dec_red":"","dec_get":""}] \ No newline at end of file diff --git a/src/HttpServer/jsonconf/jsonconf.go b/src/HttpServer/jsonconf/jsonconf.go index 0581b5f..e3f3a8f 100644 --- a/src/HttpServer/jsonconf/jsonconf.go +++ b/src/HttpServer/jsonconf/jsonconf.go @@ -61,6 +61,16 @@ func GetJsonConf() *GameConfig { return g_jsonconf } +func GetCardConfig(time int) *CardDesc { + for _, v := range g_jsonconf.CardConfig { + if v.Time == time { + return &v + } + } + + return &g_jsonconf.CardConfig[len(g_jsonconf.CardConfig)-1] +} + func GetTurnTable(ctype int) []TurnTableDesc { var rtslice []TurnTableDesc for _, v := range g_jsonconf.TurnTableConfig { diff --git a/src/HttpServer/logic/constdef.go b/src/HttpServer/logic/constdef.go index d457f42..ae86383 100644 --- a/src/HttpServer/logic/constdef.go +++ b/src/HttpServer/logic/constdef.go @@ -30,15 +30,14 @@ const ( ) -//奖励类型枚举 +//翻牌类型枚举 const ( - REWARDTYPE_STAR = 1 //星星 - REWARDTYPE_CHUI = 2 - REWARDTYPE_SHUA = 3 - REWARDTYPE_SWAP = 4 - REWARDTYPE_ELIMITE = 5 - REWARDTYPE_EXP = 6 - REWARDTYPE_GOLD = 7 + FLOPTYPE_15MIN = 1 //15min当前产出 + FLOPTYPE_45MIN = 2 //45min当前产出 + FLOPTYPE_FENCAT15MIN = 3 //分红猫15min + FLOPTYPE_FENCAT10MIN = 4 //10min分红猫 + FLOPTYPE_REDCAT = 5 //红包猫 + FLOPTYPE_GLAMCAT = 6 //赌博猫 ) const ( diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index a401c82..880ce05 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -234,6 +234,33 @@ type DrawTableResp struct { Data DrawTableData `json:"data"` } +type QueryFlopData struct { + LeftTimes int `json:"leftTimes"` +} + +type QueryFlopResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data QueryFlopData `json:"data"` +} + +type DoFlopRespReward struct { + RewardId int `json:"rewardId"` + CatId int `json:"catId"` + Coin string `json:"coin"` +} + +type DoFlopRespData struct { + Reward DoFlopRespReward `json:"reward"` + LeftTimes int `json:"leftTimes"` + Coin DoBuyCatCoin `json:"coin"` +} +type DoFlopResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data DoFlopRespData `json:"data"` +} + type AcclecteBoxResp struct { Code int `json:"code"` Message string `json:"message"` @@ -625,6 +652,8 @@ type UserData struct { OfflineLove int64 //离线爱心 LastLoginTime int //上次登陆时间 LastTimingRewardHour int //上次领取整点奖励的时刻 + FlopCardCnt int //翻牌次数计数 + FlopCardLefCnt int //剩余翻拍次数 CatShopInfo CatShopData //猫咖门店数据 Taskinfo TaskData //任务数据 AchieveMent AchieveMentData //成就数据 diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 9f9fae2..d315799 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -125,6 +125,65 @@ func (u *UserData) DrawTable() int { return idx } +func (u *UserData) DoFlopCardd(resp *DoFlopResp) { + cfg := jsonconf.GetCardConfig(u.FlopCardCnt) + if cfg == nil { + logger.Error("HandlerDoFlop getcfg failed=%v", u.FlopCardCnt) + resp.Code = 1 + resp.Message = "getcfg" + return + } + + addgold := int64(0) + var catfg *jsonconf.RedCatDesc + catid := 0 + ctime := 0 + nowt := int(time.Now().Unix()) + switch cfg.Ctype { + case FLOPTYPE_15MIN: + addgold = u.Goldrate * 15 * 60 + + case FLOPTYPE_45MIN: + addgold = u.Goldrate * 15 * 60 + case FLOPTYPE_FENCAT15MIN: + catid = 14 + 100 + ctime = 15 * 60 + catfg = jsonconf.GetRedCatConfig(catid) + u.SetRedCatPos(catid, ctime, catfg.Money, nowt) + case FLOPTYPE_FENCAT10MIN: + catid = 13 + 100 + ctime = 10 * 60 + catfg = jsonconf.GetRedCatConfig(catid) + u.SetRedCatPos(catid, ctime, catfg.Money, nowt) + case FLOPTYPE_REDCAT: + catid = 10 + 100 + catfg = jsonconf.GetRedCatConfig(catid) + u.SetRedCatPos(catid, 0, catfg.Money, 0) + case FLOPTYPE_GLAMCAT: + catid = 11 + 100 + catfg = jsonconf.GetRedCatConfig(catid) + u.SetRedCatPos(catid, 0, catfg.Money, 0) + } + u.Gold += addgold + u.CalcGoldRate() + + u.FlopCardLefCnt-- + u.FlopCardCnt++ + + SaveUserInfo(u, strconv.Itoa(u.UserId)) + + resp.Data.LeftTimes = u.FlopCardLefCnt + resp.Data.Coin.UserId = u.UserId + resp.Data.Coin.Coin = strconv.FormatInt(u.Gold, 10) + resp.Data.Coin.IcomeRate = strconv.FormatInt(u.Goldrate, 10) + resp.Data.Coin.UpdateTime = int(time.Now().Unix()) + + resp.Data.Reward.RewardId = u.FlopCardCnt + resp.Data.Reward.Coin = strconv.FormatInt(addgold, 10) + resp.Data.LeftTimes = u.FlopCardLefCnt + +} + func (u *UserData) HandlePassDay() { isdiffday := false nowtime := time.Now() @@ -221,6 +280,7 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) { udata.DrawTicketTimes = DRAWTICKETGETLIMIT udata.DratMult = 1 udata.DrawTableCount = 1 + udata.FlopCardCnt = 1 //初始化16个猫爬架 for i := 0; i < 16; i++ { @@ -289,6 +349,21 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) { redishandler.GetRedisClient().HSet(redis.USER_LAST_CALC_TIME, strconv.Itoa(uuid), nowtimestr) } +//设置红包猫 +func (u *UserData) SetRedCatPos(catlv, time int, redpack float32, starttime int) { + pos := getCatPutPos(u, catlv) + if pos < 0 || pos >= len(u.PosInfo) { + logger.Error("CleadPos failed pos=%v,posinfo=%v", pos, u.PosInfo) + return + } + + u.PosInfo[pos].Cat = catlv + u.PosInfo[pos].Position = pos + u.PosInfo[pos].StartTime = starttime + u.PosInfo[pos].RedPacket = redpack + u.PosInfo[pos].Time = time +} + //计算购买后猫箱子的位置,将箱子放到对应位置 返回值表示位置 -1表示失败都满了 func getCatPutPos(uinfo *UserData, clv int) int { pos := -1 @@ -437,6 +512,8 @@ func MergeRedBagCat(uinfo *UserData, pos int) int { } } + //翻拍次数+ + uinfo.FlopCardLefCnt++ return rtpos } diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index b9c6253..697101f 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -45,6 +45,8 @@ func startServerHttpServe() { http.HandleFunc("/api/turntable/addTicket", AddTicket) //增加抽奖券 http.HandleFunc("/api/turntable/multiple", Multiple) //增加倍数 http.HandleFunc("/api/turntable/draw", DrawTable) //抽奖 + http.HandleFunc("/api/flop/leftTimes", QueryFlop) //剩余翻牌次数 + http.HandleFunc("/api/flop/flop", DoFlop) //进行翻牌 /////---------------------------------------------------------------------old http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置 @@ -639,6 +641,42 @@ func RedCatList(w http.ResponseWriter, r *http.Request) { //HandlerRecvTimingReward(w, s, Uuid) } +func DoFlop(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("DoFlop , body:%v,uuid=%v", s, Uuid) + + HandlerDoFlop(w, s, Uuid) +} + +func QueryFlop(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("QueryFlop , body:%v,uuid=%v", s, Uuid) + + HandlerQueryFlop(w, s, Uuid) +} + func DrawTable(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 e50e70f..dabf65e 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -403,6 +403,69 @@ func HandlerGetMainPageInfo(w http.ResponseWriter, data string, uuid int) { fmt.Fprint(w, string(respstr)) } +func HandlerDoFlop(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp DoFlopResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerDoFlop getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + //判断一下翻拍次数是否足够 + if uinfo.FlopCardLefCnt <= 0 { + logger.Error("HandlerDoFlop flopcnt failed=%v", err) + resp.Code = 1 + resp.Message = "翻拍次数不足" + break + } + + uinfo.DoFlopCardd(&resp) + + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + +func HandlerQueryFlop(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp QueryFlopResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerQueryFlop getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + resp.Data.LeftTimes = uinfo.FlopCardLefCnt + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + func HandlerDrawTable(w http.ResponseWriter, data string, uuid int) { SetHeader(w) var resp DrawTableResp @@ -1167,6 +1230,9 @@ func HandlerExchangePos(w http.ResponseWriter, data string, uuid int) { uinfo.Highestlv = uinfo.PosInfo[rdata.To].Cat resp.Data.NewCat = uinfo.PosInfo[rdata.To].Cat uinfo.CheckBuyCatSHop() + + //翻拍次数+ + uinfo.FlopCardLefCnt++ } } -- libgit2 0.21.0