diff --git a/modules/hunting/api_buy.go b/modules/hunting/api_buy.go index 58ba062f7..47ed50155 100644 --- a/modules/hunting/api_buy.go +++ b/modules/hunting/api_buy.go @@ -83,6 +83,9 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HuntingBuyReq) (code list.BuyCount = curByCount mapData["buyCount"] = curByCount code = this.module.ModifyHuntingData(session.GetUserId(), mapData) + for k := range list.Boss { + list.Boss[k] += 1 + } session.SendMsg(string(this.module.GetType()), HuntingBuyResp, &pb.HuntingBuyResp{Data: list}) return } diff --git a/modules/hunting/api_challenge.go b/modules/hunting/api_challenge.go index 4c036ec28..c7e64beb5 100644 --- a/modules/hunting/api_challenge.go +++ b/modules/hunting/api_challenge.go @@ -76,6 +76,19 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.HuntingChallen if code = this.module.DispenseRes(session, reward, true); code != pb.ErrorCode_Success { return } + + mapRankData := make(map[string]interface{}, 0) + mapRankData["difficulty"] = req.Difficulty + mapRankData["bosstype"] = req.BossType + mapRankData["uid"] = session.GetUserId() + userinfo := this.module.ModuleUser.GetUser(session.GetUserId()) + mapRankData["nickname"] = userinfo.Name + mapRankData["lv"] = userinfo.Lv + mapRankData["costTime"] = 120 + this.module.modulerank.ChangeUserRank(session.GetUserId(), mapRankData) + for k := range hunting.Boss { + hunting.Boss[k] += 1 + } session.SendMsg(string(this.module.GetType()), HuntingChallengeResp, &pb.HuntingChallengeResp{Data: hunting}) return } diff --git a/modules/hunting/api_getlist.go b/modules/hunting/api_getlist.go index 8d00074c0..2157c2088 100644 --- a/modules/hunting/api_getlist.go +++ b/modules/hunting/api_getlist.go @@ -47,6 +47,9 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.HuntingGetListRe mapData["challengeCount"] = list.ChallengeCount code = this.module.ModifyHuntingData(session.GetUserId(), mapData) //修改内存信息 } + for k := range list.Boss { + list.Boss[k] += 1 + } session.SendMsg(string(this.module.GetType()), HuntingGetListResp, &pb.HuntingGetListResp{Data: list}) return } diff --git a/modules/timer/huntingrank.go b/modules/timer/huntingrank.go new file mode 100644 index 000000000..3b1c8e168 --- /dev/null +++ b/modules/timer/huntingrank.go @@ -0,0 +1,60 @@ +package timer + +import ( + "context" + "go_dreamfactory/comm" + "go_dreamfactory/modules" + "go_dreamfactory/pb" + + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/cron" + "go_dreamfactory/lego/sys/log" + + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo/options" +) + +type HuntingRank struct { + modules.MCompModel + service core.IService +} + +//组件初始化接口 +func (this *HuntingRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + + this.TableName = comm.TableHuntingRank + this.MCompModel.Init(service, module, comp, options) + this.service = service + return +} + +func (this *HuntingRank) Start() (err error) { + err = this.MCompModel.Start() + cron.AddFunc("*/60 * * * * ?", this.Timer) //每60s执行一次 + return +} + +// 处理排行榜排序 +func (this *HuntingRank) Timer() { + data := make([]interface{}, 0) // options.Find().SetLimit(comm.MaxRankList) + for i := 1; i <= 4; i++ { // boss 类型 1 2 3 4 后面封装 // 时间参数战斗调完后再加进来 + if _data, err := this.DB.Find(comm.TableHuntingRank, bson.M{"bosstype": i}, options.Find().SetSort(bson.M{"difficulty": -1}).SetLimit(comm.MaxRankList)); err == nil { + for _data.Next(context.TODO()) { + temp := &pb.DBPagodaRank{} + if err = _data.Decode(temp); err == nil { + data = append(data, temp) + } + } + } + } + + if len(data) > 0 { + err := this.Redis.RPush(comm.TablePagodaRank, data...) + if err == nil { + err = this.Redis.Ltrim(comm.TablePagodaRank, -1*len(data), -1) //对一个列表进行修剪 + if err != nil { + log.Errorf("delete failed") + } + } + } +} diff --git a/modules/timer/module.go b/modules/timer/module.go index a81d9cb86..6f9040126 100644 --- a/modules/timer/module.go +++ b/modules/timer/module.go @@ -25,6 +25,7 @@ type Timer struct { service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口 rank *PagodaRank rank2 *VikingRank + rank3 *HuntingRank } //模块名 @@ -54,5 +55,5 @@ func (this *Timer) OnInstallComp() { this.ModuleBase.OnInstallComp() this.rank = this.RegisterComp(new(PagodaRank)).(*PagodaRank) this.rank2 = this.RegisterComp(new(VikingRank)).(*VikingRank) - + this.rank3 = this.RegisterComp(new(HuntingRank)).(*HuntingRank) }