diff --git a/comm/imodule.go b/comm/imodule.go index ca970482f..4040a4204 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -37,7 +37,7 @@ type ( Imail interface { SendMailByCid(session IUserSession, cid string, res []*pb.UserAssets) bool SendNewMail(mail *pb.DBMailData, uid ...string) bool // 批量发送邮件 支持跨服 - SendMailByUID(uid string, cid string, res []*cfg.Gameatn) bool + SendMailByUID(uid string, cid string, res []*cfg.Gameatn, Param []string) bool IReddot } //道具背包接口 @@ -58,6 +58,8 @@ type ( RecoverTicket(session IUserSession) (code pb.ErrorCode) //出售道具 SellItem(session IUserSession, items map[string]int32, bPush bool) (code pb.ErrorCode, atno []*pb.UserAtno) + + CleanItemById(session IUserSession, t string) (code pb.ErrorCode) } //英雄 diff --git a/modules/caravan/api_getlist.go b/modules/caravan/api_getlist.go index 172ed6806..c611add25 100644 --- a/modules/caravan/api_getlist.go +++ b/modules/caravan/api_getlist.go @@ -4,6 +4,7 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" ) //参数校验 @@ -22,8 +23,11 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListRe } list, err := this.module.modelCaravan.getCaravanList(session.GetUserId()) - if mgo.MongodbNil == err { // 初始化门票和虚拟币 - if code = this.module.InitCaravanTicket(session, 1); code != pb.ErrorCode_Success { + if configure.Now().Unix() >= list.Resettime || err == mgo.MongodbNil { // 初始化门票和虚拟币 + if conf := this.module.configure.GetCaravanLv(list.Lv); conf != nil { + this.module.ModuleItems.CleanItemById(session, conf.Tickettop.T) // 清理之前的门票数据 + } + if code = this.module.InitCaravanTicket(session, list.Lv); code != pb.ErrorCode_Success { return } } diff --git a/modules/caravan/model_caravan.go b/modules/caravan/model_caravan.go index 83d8aa1b5..eeb4457c0 100644 --- a/modules/caravan/model_caravan.go +++ b/modules/caravan/model_caravan.go @@ -8,7 +8,6 @@ import ( "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" - "go_dreamfactory/utils" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" @@ -46,7 +45,8 @@ func (this *modelCaravan) getCaravanList(uid string) (result *pb.DBCaravan, err if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err { // 创建一条数据 result.Id = primitive.NewObjectID().Hex() - result.Resettime = utils.GetZeroTime(configure.Now().Unix()) // 设置起始刷新时间 + + result.Resettime = this.module.service.GetOpentime().Unix() + int64(this.module.ModuleTools.GetGlobalConf().BusinessRewardday*24*3600) result.Citystime = configure.Now().Unix() result.Lv = 1 result.Curcity = this.module.configure.GetCaravanInitCity() // 获取默认城市 diff --git a/modules/caravan/module.go b/modules/caravan/module.go index d7ddfdf19..2a32ccd41 100644 --- a/modules/caravan/module.go +++ b/modules/caravan/module.go @@ -12,6 +12,7 @@ import ( cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/utils" "math" + "strconv" "time" "go.mongodb.org/mongo-driver/bson" @@ -201,7 +202,10 @@ func (this *Caravan) refreshCaravanCityInfo(uid string, caravan *pb.DBCaravan) { } } } - + if configure.Now().Unix() >= caravan.Resettime { + caravan.Resettime = this.service.GetOpentime().Unix() + int64(this.ModuleTools.GetGlobalConf().BusinessRewardday*24*3600) + update["resettime"] = caravan.Resettime + } if bChange { update["city"] = caravan.City update["goods"] = caravan.Goods @@ -317,7 +321,7 @@ func (this *Caravan) ArrayBag(data *pb.DBCaravan, limit int32) (bFull bool) { return false } -// 校验商队等级 +// 获得利润判断是否能提升商队等级 func (this *Caravan) CheckCaravavLvUp(data *pb.DBCaravan) (curLv int32) { curLv = data.Lv for { @@ -347,28 +351,67 @@ func (this *Caravan) TestFunc(session comm.IUserSession) { // 赛季结算 func (this *Caravan) Rpc_ModuleCaravanSettlement(ctx context.Context, args *pb.EmptyReq, reply *pb.EmptyResp) { - sTime := time.Now() - var rankIndex int32 - if _data, err := this.modelCaravan.DB.Find(comm.TableUser, bson.M{}, options.Find().SetSort(bson.M{"merchantmoney": -1}).SetLimit(comm.MaxRankList)); err == nil { - for _data.Next(context.TODO()) { - rankIndex++ - temp := &pb.DBUser{} - if err = _data.Decode(temp); err == nil { - c := this.configure.GetCaravanRank(rankIndex) - if c != nil { - this.mail.SendMailByUID(temp.Uid, "xxx", c.Reward) // 等配置 + go func() { + sTime := time.Now() + var rankIndex int32 + if _data, err := this.modelCaravan.DB.Find(comm.TableUser, bson.M{}, options.Find().SetSort(bson.M{"merchantmoney": -1}).SetLimit(comm.MaxRankList)); err == nil { + for _data.Next(context.TODO()) { + rankIndex++ + temp := &pb.DBUser{} + if err = _data.Decode(temp); err == nil { + c := this.configure.GetCaravanRank(rankIndex) + if c != nil { + this.mail.SendMailByUID(temp.Uid, "CaravanRank", c.Reward, []string{strconv.Itoa(int(rankIndex))}) + } } } } - } + // 发送虚拟币奖励 + if _data, err := this.modelCaravan.DB.Find(comm.TableUser, bson.M{"merchantmoney": bson.M{"$gt": 0}}); err == nil { + for _data.Next(context.TODO()) { + temp := &pb.DBUser{} - Query := bson.M{} - Query["merchantmoney"] = 0 - _, err := this.modelCaravan.DB.UpdateMany(core.SqlTable(comm.TableUser), bson.M{}, bson.M{"$set": Query}, options.MergeUpdateOptions().SetUpsert(true)) //, new(options.UpdateOptions).SetUpsert(true) - if err != nil { - this.Errorf("UpdateMany error: %v", err) - } + if err = _data.Decode(temp); err == nil { + + for _, v := range this.configure.GetCaravanReward() { + s := v.Moneystart + e := v.Moneyend + more := false + if e == -1 { + e = math.MaxInt32 + more = true + } + + if s < temp.Merchantmoney && e <= temp.Merchantmoney { + var res []*cfg.Gameatn + if more { // 超过的部分 + r := this.ModuleTools.GetGlobalConf().BusinessMaxintReward + m := this.ModuleTools.GetGlobalConf().BusinessMaxint + n := (temp.Merchantmoney - s) / m + atn := &cfg.Gameatn{ + A: r.A, + T: r.T, + N: r.N * n, + } + res = append(res, atn) + } + res = append(res, v.Reward...) + this.mail.SendMailByUID(temp.Uid, "CaravanRewards", v.Reward, []string{}) + } + + } + } + } + } + Query := bson.M{} + Query["merchantmoney"] = 0 + _, err := this.modelCaravan.DB.UpdateMany(core.SqlTable(comm.TableUser), bson.M{}, bson.M{"$set": Query}, options.MergeUpdateOptions().SetUpsert(true)) //, new(options.UpdateOptions).SetUpsert(true) + if err != nil { + this.Errorf("UpdateMany error: %v", err) + } + + this.Debugf("sub time:%d", time.Now().Local().Sub(sTime).Milliseconds()) + }() - this.Debugf("sub time:%d", time.Now().Local().Sub(sTime).Milliseconds()) return } diff --git a/modules/items/module.go b/modules/items/module.go index ae5880f34..e0687baf3 100644 --- a/modules/items/module.go +++ b/modules/items/module.go @@ -261,3 +261,21 @@ func (this *Items) itemsChangePush(session comm.IUserSession, items []*pb.DB_Use session.SendMsg(string(this.GetType()), "change", &pb.ItemsChangePush{Grids: items}) return } + +func (this *Items) CleanItemById(session comm.IUserSession, t string) (code pb.ErrorCode) { + + var itmes []*pb.DB_UserItemData + if v, err := this.modelItems.QueryUserPack(session.GetUserId()); err == nil { + for _, v := range v { + if v.ItemId == t { + itmes = append(itmes, v) + break + } + } + this.modelItems.DeleteUserPack(session.GetUserId(), itmes...) + code = pb.ErrorCode_Success + return + } + code = pb.ErrorCode_DataNotFound + return +} diff --git a/modules/mail/module.go b/modules/mail/module.go index 40814baed..e59d9174a 100644 --- a/modules/mail/module.go +++ b/modules/mail/module.go @@ -219,7 +219,6 @@ func (this *Mail) CheckMaxMail(session comm.IUserSession) bool { } func (this *Mail) SendMailByUID(uid string, cid string, res []*cfg.Gameatn) bool { - // 获取额外配置 var reward []*pb.UserAssets for _, v := range res { if v.N > 0 { @@ -230,11 +229,21 @@ func (this *Mail) SendMailByUID(uid string, cid string, res []*cfg.Gameatn) bool }) } } + conf := this.configure.GetMailConf(cid) if conf == nil { this.Errorf("can't found mail by cid: %s", cid) return false } + if len(conf.Reword) > 0 { + for _, v := range conf.Reword { + reward = append(reward, &pb.UserAssets{ + A: v.A, + T: v.T, + N: v.N, + }) + } + } // 构建一个每日奖励邮件对象 mail := &pb.DBMailData{ diff --git a/modules/smithy/api_rise.go b/modules/smithy/api_rise.go index 5d9917971..ced8cf39c 100644 --- a/modules/smithy/api_rise.go +++ b/modules/smithy/api_rise.go @@ -60,6 +60,9 @@ func (this *apiComp) Rise(session comm.IUserSession, req *pb.SmithyRiseReq) (cod update["temperature"] = stove.Temperature this.module.modelStove.updateSmithyStove(session.GetUserId(), update) session.SendMsg(string(this.module.GetType()), "rise", &pb.SmithyRiseResp{Data: stove}) + tasks := make([]*comm.TaskParam, 0) + tasks = append(tasks, comm.GettaskParam(comm.Rtype171, stove.Temperature)) + this.module.ModuleRtask.TriggerTask(session.GetUserId(), tasks...) } return diff --git a/modules/timer/caravanrank.go b/modules/timer/caravanrank.go index 403247008..cc94b6a29 100644 --- a/modules/timer/caravanrank.go +++ b/modules/timer/caravanrank.go @@ -3,13 +3,16 @@ package timer import ( "context" "go_dreamfactory/comm" - "go_dreamfactory/modules" - "go_dreamfactory/pb" - "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" - "go_dreamfactory/lego/sys/cron" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/lego/sys/timewheel" + "go_dreamfactory/modules" + "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" + cfg "go_dreamfactory/sys/configure/structs" + "time" ) // 此组件废弃 @@ -20,6 +23,10 @@ type CaravanRank struct { module *Timer } +const ( + game_global = "game_global.json" //全局配置表 +) + //组件初始化接口 func (this *CaravanRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { @@ -27,18 +34,60 @@ func (this *CaravanRank) Init(service core.IService, module core.IModule, comp c this.MCompModel.Init(service, module, comp, options) this.module = module.(*Timer) this.service = service.(base.IRPCXService) + + err = this.LoadConfigure(game_global, cfg.NewGameGlobal) return } +func (this *CaravanRank) LoadConfigure(name string, fn interface{}) (err error) { + return configure.RegisterConfigure(name, fn, nil) +} +//读取配置数据 +func (this *CaravanRank) GetConfigure(name string) (v interface{}, err error) { + return configure.GetConfigure(name) +} + +//全局配置 +func (this *CaravanRank) GetGlobalConf() *cfg.GameGlobalData { + var ( + configure *cfg.GameGlobal + ok bool + ) + if v, err := this.GetConfigure(game_global); err != nil { + log.Errorf("get global conf err:%v", err) + return nil + } else { + if configure, ok = v.(*cfg.GameGlobal); !ok { + log.Errorf("%T no is *cfg.Game_global", v) + return nil + } + } + return configure.GetDataList()[0] // 返回对象信息 +} func (this *CaravanRank) Start() (err error) { err = this.MCompModel.Start() - cron.AddFunc("30 10 1 * * ?", this.TimerSeason) + opentime := this.service.GetOpentime().Unix() + this.module.Debugf("%d", opentime) + //cron.AddFunc("30 10 1 * * ?", this.TimerSeason) + this.module.Debugf("--%d", time.Now().Unix()) + seasonTime := this.GetGlobalConf().BusinessRewardday + + if configure.Now().Unix() < opentime { // 开服时间是未来可能存在问题 + return + } + subTime := int32(configure.Now().Unix() - opentime) + if subTime < seasonTime { + timewheel.Add(time.Second*time.Duration(subTime), this.TimerSeason, nil) + } else { + s := configure.Now().Unix() - (configure.Now().Unix()-opentime)%int64(subTime) + int64(seasonTime) + timewheel.Add(time.Second*time.Duration(s), this.TimerSeason, nil) + } return } -func (this *CaravanRank) TimerSeason() { - +func (this *CaravanRank) TimerSeason(task *timewheel.Task, args ...interface{}) { + this.module.Debugf("==%d", time.Now().Unix()) if _, err := this.service.RpcGo(context.Background(), comm.Service_Worker, string(comm.Rpc_ModuleCaravanSettlement), @@ -48,6 +97,16 @@ func (this *CaravanRank) TimerSeason() { this.module.Errorln(err) } + // if _data, err := this.DB.Find(comm.TableUser, bson.M{"merchantmoney": bson.M{"$gt": 0}}); err == nil { + // for _data.Next(context.TODO()) { + + // temp := &pb.DBUser{} + // if err = _data.Decode(temp); err == nil { + + // } + // } + // } + // sTime := time.Now() // Query := bson.M{} // Query["merchantmoney"] = 0 diff --git a/services/mainte/main.go b/services/mainte/main.go index fbef66697..67fc17086 100644 --- a/services/mainte/main.go +++ b/services/mainte/main.go @@ -8,12 +8,14 @@ import ( "go_dreamfactory/modules/web" "go_dreamfactory/services" "go_dreamfactory/sys/db" + "time" "go_dreamfactory/lego" "go_dreamfactory/lego/base/rpcx" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/cron" "go_dreamfactory/lego/sys/log" + "go_dreamfactory/lego/sys/timewheel" ) /* @@ -62,7 +64,12 @@ func (this *Service) InitSys() { } else { log.Infof("init sys.cron success!") } - + //定时系统 秒级时间轮 + if err := timewheel.OnInit(nil, timewheel.SetTick(time.Second)); err != nil { + panic(fmt.Sprintf("init sys.timewheel err: %s", err.Error())) + } else { + log.Infof("init sys.timewheel success!") + } //存储系统 if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil { panic(fmt.Sprintf("init sys.db err: %s", err.Error()))