diff --git a/comm/imodule.go b/comm/imodule.go index 5953cadf1..9dfab7861 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -645,7 +645,7 @@ type ( } //战斗记录模块 IBattleRecord interface { - WrietBattleRecord(uid string, report *pb.BattleReport) + WrietBattleRecord(uid string, report *pb.BattleReport, expire int64) } IDragon interface { //获取玩家坐骑列表 diff --git a/modules/battlerecord/model.go b/modules/battlerecord/model.go index e55e4ef93..8ec304d67 100644 --- a/modules/battlerecord/model.go +++ b/modules/battlerecord/model.go @@ -9,6 +9,7 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" + mgooptions "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/x/bsonx" ) @@ -25,6 +26,11 @@ func (this *modelComp) Init(service core.IService, module core.IModule, comp cor this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) + indexModel := mongo.IndexModel{ + Keys: bson.M{"expireAt": 1}, // 设置TTL索引列"expire_date" + Options: mgooptions.Index().SetExpireAfterSeconds(0), // 设置过期时间(单位:秒) + } + _, err = this.DB.CreateIndex(core.SqlTable(this.TableName), indexModel) //设置 验证码过期时间索引 return } diff --git a/modules/battlerecord/module.go b/modules/battlerecord/module.go index 02d5a3602..c1febad96 100644 --- a/modules/battlerecord/module.go +++ b/modules/battlerecord/module.go @@ -50,7 +50,7 @@ func (this *BattleRecord) Start() (err error) { } //写入战斗记录 -func (this *BattleRecord) WrietBattleRecord(uid string, report *pb.BattleReport) { +func (this *BattleRecord) WrietBattleRecord(uid string, report *pb.BattleReport, expire int64) { var ( result *pb.DBBattlePlayRecord model *recordModel @@ -62,8 +62,9 @@ func (this *BattleRecord) WrietBattleRecord(uid string, report *pb.BattleReport) return } result = &pb.DBBattlePlayRecord{ - Id: report.Info.Id, - Record: data, + Id: report.Info.Id, + Record: data, + ExpireAt: expire, } if model, err = this.model.getrecordModel(uid); err != nil { this.Errorln(err) diff --git a/modules/guildgve/api_challengefinish.go b/modules/guildgve/api_challengefinish.go index 86b4a9823..76c0468c5 100644 --- a/modules/guildgve/api_challengefinish.go +++ b/modules/guildgve/api_challengefinish.go @@ -7,6 +7,7 @@ import ( "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" + "time" ) // 参数校验 @@ -184,7 +185,7 @@ func (this *apiComp) ChallengeFinish(session comm.IUserSession, req *pb.GuildGve } } //写入战斗记录 - go this.module.battlerecord.WrietBattleRecord(session.GetUserId(), req.Report) + go this.module.battlerecord.WrietBattleRecord(session.GetUserId(), req.Report, time.Now().Add(time.Hour*24*8).Unix()) session.SendMsg(string(this.module.GetType()), "challengefinish", &pb.GuildGveChallengeFinishResp{ Guildid: req.Guildid, Boosid: req.Boosid, diff --git a/modules/robot/modulerobot_chat.go b/modules/robot/modulerobot_chat.go new file mode 100644 index 000000000..999cbd161 --- /dev/null +++ b/modules/robot/modulerobot_chat.go @@ -0,0 +1,59 @@ +package robot + +import ( + "errors" + "fmt" + "go_dreamfactory/comm" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + + "google.golang.org/protobuf/proto" +) + +//用户模块 机器人 +type ModuleRobot_Chat struct { +} + +func (this *ModuleRobot_Chat) Init() (err error) { + + return +} + +//接收到消息 +func (this *ModuleRobot_Chat) Receive(robot IRobot, stype string, message proto.Message) (err error) { + switch stype { + } + return +} + +//机器人执行流 +func (this *ModuleRobot_Chat) DoPipeline(robot IRobot) (err error) { + + return +} + +//做任务 +func (this *ModuleRobot_Chat) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) { + var ( + errdata *pb.ErrorData + ) + switch comm.TaskType(condconf.Type) { + case comm.Rtype62: + var ( + usermodule *ModuleRobot_User + ) + usermodule = robot.GetModule(comm.ModuleUser).(*ModuleRobot_User) + if _, errdata = robot.SendMessage("chat", "send", &pb.ChatSendReq{ + Avatar: usermodule.user.Avatar, + Uname: usermodule.user.Name, + Ulv: usermodule.user.Lv, + Channel: pb.ChatChannel_World, + Ctype: pb.ChatType_Text, + Content: fmt.Sprintf("你好!我是%s", robot.Account()), + }); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + } + return +} diff --git a/modules/robot/modulerobot_shop.go b/modules/robot/modulerobot_shop.go new file mode 100644 index 000000000..1a32717e4 --- /dev/null +++ b/modules/robot/modulerobot_shop.go @@ -0,0 +1,74 @@ +package robot + +import ( + "errors" + "fmt" + "go_dreamfactory/comm" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + + "google.golang.org/protobuf/proto" +) + +//用户模块 机器人 +type ModuleRobot_Shop struct { + goods map[pb.ShopType][]*pb.ShopItem +} + +func (this *ModuleRobot_Shop) Init() (err error) { + this.goods = make(map[pb.ShopType][]*pb.ShopItem) + return +} + +//接收到消息 +func (this *ModuleRobot_Shop) Receive(robot IRobot, stype string, message proto.Message) (err error) { + switch stype { + case "getlist": + resp := message.(*pb.ShopGetListResp) + this.goods[resp.SType] = resp.Goods + break + } + return +} + +//机器人执行流 +func (this *ModuleRobot_Shop) DoPipeline(robot IRobot) (err error) { + + return +} + +//做任务 +func (this *ModuleRobot_Shop) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) { + var ( + errdata *pb.ErrorData + ) + switch comm.TaskType(condconf.Type) { + case comm.Rtype104: + var ( + usermodule *ModuleRobot_User + ) + usermodule = robot.GetModule(comm.ModuleUser).(*ModuleRobot_User) + if _, errdata = robot.SendMessage("shop", "getlist", &pb.ShopGetListReq{ + SType: pb.ShopType_DiamondShop, + }); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + + for _, v := range this.goods[pb.ShopType_DiamondShop] { + if v.LeftBuyNum > 0 && usermodule.user.Diamond >= int64(v.Consume[0].N) { + if _, errdata = robot.SendMessage("shop", "buy", &pb.ShopBuyReq{ + ShopType: pb.ShopType_DiamondShop, + Gid: v.Gid, + BuyNum: 1, + }); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + break + } + } + + } + return +} diff --git a/modules/robot/modulerobot_wtask.go b/modules/robot/modulerobot_wtask.go index e952f1bca..07b37ba08 100644 --- a/modules/robot/modulerobot_wtask.go +++ b/modules/robot/modulerobot_wtask.go @@ -140,6 +140,10 @@ locp: module = comm.ModuleViking case comm.Rtype199: module = comm.ModuleHero + case comm.Rtype62: + module = comm.ModuleChat + case comm.Rtype104: + module = comm.ModuleShop default: log.Error("[Robot DoTask]", log.Field{Key: "ctype", Value: cconf.Type}, log.Field{Key: "conld", Value: cconf.Id}, log.Field{Key: "err", Value: "Not Achieved !"}) break locp diff --git a/modules/robot/robot.go b/modules/robot/robot.go index d61249de9..ce0b96a6f 100644 --- a/modules/robot/robot.go +++ b/modules/robot/robot.go @@ -54,6 +54,8 @@ func (this *Robot) Init(addr string, client IClient) (err error) { this.modules[comm.ModuleArena] = new(ModuleRobot_Arena) this.modules[comm.ModulePagoda] = new(ModuleRobot_Pagoda) this.modules[comm.ModuleViking] = new(ModuleRobot_Viking) + this.modules[comm.ModuleChat] = new(ModuleRobot_Chat) + this.modules[comm.ModuleShop] = new(ModuleRobot_Shop) for _, v := range this.modules { v.Init() diff --git a/pb/battlerecord_db.pb.go b/pb/battlerecord_db.pb.go index 2c3af37c0..58f9f720c 100644 --- a/pb/battlerecord_db.pb.go +++ b/pb/battlerecord_db.pb.go @@ -26,8 +26,9 @@ type DBBattlePlayRecord struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //唯一ID - Record []byte `protobuf:"bytes,5,opt,name=record,proto3" json:"record"` //BattleReport 的序列化数据 + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //唯一ID + ExpireAt int64 `protobuf:"varint,2,opt,name=expireAt,proto3" json:"expireAt" bson:"expireAt"` //过期时间 + Record []byte `protobuf:"bytes,3,opt,name=record,proto3" json:"record"` //BattleReport 的序列化数据 } func (x *DBBattlePlayRecord) Reset() { @@ -69,6 +70,13 @@ func (x *DBBattlePlayRecord) GetId() string { return "" } +func (x *DBBattlePlayRecord) GetExpireAt() int64 { + if x != nil { + return x.ExpireAt + } + return 0 +} + func (x *DBBattlePlayRecord) GetRecord() []byte { if x != nil { return x.Record @@ -81,12 +89,13 @@ var File_battlerecord_battlerecord_db_proto protoreflect.FileDescriptor var file_battlerecord_battlerecord_db_proto_rawDesc = []byte{ 0x0a, 0x22, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2f, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x5f, 0x64, 0x62, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3c, 0x0a, 0x12, 0x44, 0x42, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, + 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x58, 0x0a, 0x12, 0x44, 0x42, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x50, 0x6c, 0x61, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, - 0x63, 0x6f, 0x72, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f, - 0x72, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x78, + 0x70, 0x69, 0x72, 0x65, 0x41, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x65, 0x78, + 0x70, 0x69, 0x72, 0x65, 0x41, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x42, 0x06, + 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (