diff --git a/modules/robot/modulerobot_arena.go b/modules/robot/modulerobot_arena.go new file mode 100644 index 000000000..41004c8a2 --- /dev/null +++ b/modules/robot/modulerobot_arena.go @@ -0,0 +1,99 @@ +package robot + +import ( + "errors" + "go_dreamfactory/comm" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + + "google.golang.org/protobuf/proto" +) + +//用户模块 机器人 +type ModuleRobot_Arena struct { + Info *pb.DBArenaUser + players []*pb.ArenaPlayer +} + +func (this *ModuleRobot_Arena) Init() (err error) { + + return +} + +//接收到消息 +func (this *ModuleRobot_Arena) Receive(robot IRobot, stype string, message proto.Message) (err error) { + switch stype { + case "info": + resp := message.(*pb.ArenaInfoResp) + this.Info = resp.Info + break + case "matche": + resp := message.(*pb.ArenaMatcheResp) + this.players = resp.Players + break + } + return +} + +//机器人执行流 +func (this *ModuleRobot_Arena) DoPipeline(robot IRobot) (err error) { + + return +} + +//做任务 +func (this *ModuleRobot_Arena) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) { + var ( + errdata *pb.ErrorData + ) + if _, errdata = robot.SendMessage("arena", "info", &pb.ArenaInfoReq{}); errdata != nil { + err = errors.New(errdata.Message) + return + } + if _, errdata = robot.SendMessage("arena", "matche", &pb.ArenaMatcheReq{}); errdata != nil { + err = errors.New(errdata.Message) + return + } + switch comm.TaskType(condconf.Type) { + case comm.Rtype128, comm.Rtype129, comm.Rtype131: + var ( + heromodule *ModuleRobot_Hero + heros []string + player *pb.ArenaPlayer + resp proto.Message + ) + heromodule = robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero) + heros = heromodule.getbattlehero() + for _, v := range this.players { + player = v + break + } + if resp, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "arena", "challenge", &pb.ArenaChallengeReq{ + Playerid: player.Uid, + Isai: player.Isai, + MformatId: player.Mformatid, + Battle: &pb.BattleFormation{ + Format: heros, + }}); errdata != nil { + err = errors.New(errdata.Message) + return + } + if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "arena", "challengeover", &pb.ArenaChallengeRewardReq{ + Iswin: true, + Isai: player.Isai, + Aiintegral: player.Integral, + Ainame: player.Name, + Report: &pb.BattleReport{ + Info: resp.(*pb.MainlineChallengeResp).Info, + WinSide: 1, + }}); errdata != nil { + err = errors.New(errdata.Message) + return + } + break + default: + + } + + return +} diff --git a/modules/robot/modulerobot_equipment.go b/modules/robot/modulerobot_equipment.go index 11ced196c..bef7d5af3 100644 --- a/modules/robot/modulerobot_equipment.go +++ b/modules/robot/modulerobot_equipment.go @@ -70,7 +70,7 @@ func (this *ModuleRobot_Equipment) DoTask(robot IRobot, taskconf *cfg.GameWorldT heromodule = robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero) heros = heromodule.heros for _, hero = range heros { - if equipments, change, err = this.findcanEquipEquipment(hero); err != nil { + if equipments, change, err = this.findcanEquipEquipment(hero, 0); err != nil { return } if change { @@ -88,7 +88,36 @@ func (this *ModuleRobot_Equipment) DoTask(robot IRobot, taskconf *cfg.GameWorldT } else { err = fmt.Errorf("no fund can use equipments") } - case comm.Rtype92, comm.Rtype96: //强化 + case comm.Rtype41: //穿戴 + var ( + heromodule *ModuleRobot_Hero + heros map[string]*pb.DBHero + equipments []string + hero *pb.DBHero + change bool + ) + heromodule = robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero) + heros = heromodule.heros + for _, hero = range heros { + if equipments, change, err = this.findcanEquipEquipment(hero, condconf.Filter[0]); err != nil { + return + } + if change { + break + } + } + if change { + if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "equipment", "equip", &pb.EquipmentEquipReq{ + HeroCardId: hero.Id, + EquipmentId: equipments, + }); errdata != nil { + err = errors.New(errdata.Message) + return + } + } else { + err = fmt.Errorf("no fund can use equipments") + } + case comm.Rtype43, comm.Rtype92, comm.Rtype96: //强化 var ( equipment *pb.DB_Equipment ) @@ -102,7 +131,63 @@ func (this *ModuleRobot_Equipment) DoTask(robot IRobot, taskconf *cfg.GameWorldT return } case comm.Rtype94: //附魔 - if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "equipment", "ench", &pb.EquipmentEnchReq{}); errdata != nil { + var ( + equipment *pb.DB_Equipment + itemmodule *ModuleRobot_Item + items map[string]*pb.DB_UserItemData + confs []*cfg.GameEquipEnchantingData + item *pb.DB_UserItemData + ) + if equipment, err = this.findmaxlvEquipment(); err != nil { + return + } + + itemmodule = robot.GetModule(comm.ModuleItems).(*ModuleRobot_Item) + items = itemmodule.items + if confs, err = this.getEquipenchantings(); err != nil { + return + } + for _, conf := range confs { + for _, v := range items { + if conf.Item == v.ItemId { //找到消耗道具 + item = v + break + } + } + } + if item != nil { + if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "equipment", "ench", &pb.EquipmentEnchReq{ + Eid: equipment.Id, + Itemid: item.GridId, + Index: 0, + }); errdata != nil { + err = errors.New(errdata.Message) + return + } + } + case comm.Rtype95: //洗练 + var ( + equipment *pb.DB_Equipment + resp proto.Message + pids []int32 + ) + if equipment, err = this.findmaxlvEquipment(); err != nil { + return + } + if resp, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "equipment", "wash", &pb.EquipmentWashReq{ + Eid: equipment.Id, + }); errdata != nil { + err = errors.New(errdata.Message) + return + } + pids = make([]int32, 0) + for _, v := range resp.(*pb.EquipmentWashResp).AdverbEntry { + pids = append(pids, v.Libraryid) + } + if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "equipment", "washconfirm", &pb.EquipmentWashConfirmReq{ + Eid: equipment.Id, + Pids: pids, + }); errdata != nil { err = errors.New(errdata.Message) return } @@ -111,7 +196,7 @@ func (this *ModuleRobot_Equipment) DoTask(robot IRobot, taskconf *cfg.GameWorldT } //查询能穿戴的装备 -func (this *ModuleRobot_Equipment) findcanEquipEquipment(hero *pb.DBHero) (equipments []string, change bool, err error) { +func (this *ModuleRobot_Equipment) findcanEquipEquipment(hero *pb.DBHero, minstar int32) (equipments []string, change bool, err error) { var ( conf *cfg.GameEquipData ) @@ -123,6 +208,9 @@ func (this *ModuleRobot_Equipment) findcanEquipEquipment(hero *pb.DBHero) (equip if conf, err = this.getGameEquipData(equipment.CId); err != nil { return } + if conf.Color < minstar { + continue + } if conf.Pos == int32(i) { //找到匹配装备 equipments[i] = equipment.Id change = true @@ -152,7 +240,7 @@ func (this *ModuleRobot_Equipment) findcanupgrade() (equipment *pb.DB_Equipment, if conf, err = this.getGameEquipData(equipment.CId); err != nil { return } - if upconf, err = this.getEquipmentMaxIntensifyConfigure(conf.EquipId, conf.Color); err == nil && upconf.Level < equipment.Lv { + if upconf, err = this.getEquipmentMaxIntensifyConfigure(conf.EquipId, conf.Color); err == nil && upconf.Level > equipment.Lv { return } } @@ -161,6 +249,25 @@ func (this *ModuleRobot_Equipment) findcanupgrade() (equipment *pb.DB_Equipment, return } +//查询能强化的装备 +func (this *ModuleRobot_Equipment) findmaxlvEquipment() (equipment *pb.DB_Equipment, err error) { + var ( + equipments []*pb.DB_Equipment = make([]*pb.DB_Equipment, 0, len(this.equipments)) + ) + if len(this.equipments) == 0 { + err = fmt.Errorf("no found can use equipment") + return + } + for _, v := range this.equipments { + equipments = append(equipments, v) + } + sort.Slice(equipments, func(i, j int) bool { + return equipments[i].Lv > equipments[j].Lv + }) + equipment = equipments[0] + return +} + // 读取条件任务id配置 func (this *ModuleRobot_Equipment) getGameEquipData(cid string) (conf *cfg.GameEquipData, err error) { var ( diff --git a/modules/robot/modulerobot_item.go b/modules/robot/modulerobot_item.go index af70a0e93..b84a38736 100644 --- a/modules/robot/modulerobot_item.go +++ b/modules/robot/modulerobot_item.go @@ -43,7 +43,7 @@ func (this *ModuleRobot_Item) DoPipeline(robot IRobot) (err error) { var ( errdata *pb.ErrorData ) - if _, errdata = robot.SendMessage("item", "list", &pb.ItemsGetlistReq{}); errdata != nil { + if _, errdata = robot.SendMessage("items", "getlist", &pb.ItemsGetlistReq{}); errdata != nil { err = errors.New(errdata.Message) return } diff --git a/modules/robot/modulerobot_mainline.go b/modules/robot/modulerobot_mainline.go index a71b049dc..4bcdfc345 100644 --- a/modules/robot/modulerobot_mainline.go +++ b/modules/robot/modulerobot_mainline.go @@ -59,8 +59,6 @@ func (this *ModuleRobot_MainLine) DoPipeline(robot IRobot) (err error) { func (this *ModuleRobot_MainLine) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) { var ( errdata *pb.ErrorData - conf *cfg.GameMainStageData - ok bool ) if _, errdata = robot.SendMessage("mainline", "info", &pb.MainlineInfoReq{}); errdata != nil { err = errors.New(errdata.Message) @@ -68,6 +66,10 @@ func (this *ModuleRobot_MainLine) DoTask(robot IRobot, taskconf *cfg.GameWorldTa } switch comm.TaskType(condconf.Type) { case comm.Rtype61: + var ( + conf *cfg.GameMainStageData + ok bool + ) if _, ok = this.info.Level[condconf.Filter[0]]; ok { //已通关 return } @@ -107,9 +109,10 @@ func (this *ModuleRobot_MainLine) DoTask(robot IRobot, taskconf *cfg.GameWorldTa err = errors.New(errdata.Message) return } + default: + err = fmt.Errorf("no fund mainline id:%d type:%d", conf.Id, conf.Episodetype) } - default: - err = fmt.Errorf("no fund mainline id:%d type:%d", conf.Id, conf.Episodetype) + } return diff --git a/modules/robot/modulerobot_pagoda.go b/modules/robot/modulerobot_pagoda.go index bc1b05446..73e390ac9 100644 --- a/modules/robot/modulerobot_pagoda.go +++ b/modules/robot/modulerobot_pagoda.go @@ -40,15 +40,6 @@ func (this *ModuleRobot_Pagoda) Receive(robot IRobot, stype string, message prot //机器人执行流 func (this *ModuleRobot_Pagoda) DoPipeline(robot IRobot) (err error) { - var ( - errdata *pb.ErrorData - ) - // 获取爬塔信息 - if _, errdata = robot.SendMessage("pagoda", "getlist", &pb.PagodaGetListReq{}); errdata != nil { - err = errors.New(errdata.Message) - return - } - return } @@ -59,7 +50,11 @@ func (this *ModuleRobot_Pagoda) DoTask(robot IRobot, taskconf *cfg.GameWorldTask errdata *pb.ErrorData conf *cfg.GamePagodaData ) - + // 获取爬塔信息 + if _, errdata = robot.SendMessage("pagoda", "getlist", &pb.PagodaGetListReq{}); errdata != nil { + err = errors.New(errdata.Message) + return + } switch comm.TaskType(condconf.Type) { case comm.Rtype168: //完成功夫大师挑战塔第X层 var ( diff --git a/modules/robot/modulerobot_wtask.go b/modules/robot/modulerobot_wtask.go index 77c3dae7d..a0d5539b9 100644 --- a/modules/robot/modulerobot_wtask.go +++ b/modules/robot/modulerobot_wtask.go @@ -129,8 +129,12 @@ locp: module = comm.ModulePractice case comm.Rtype61: module = comm.ModuleMainline - case comm.Rtype5, comm.Rtype92, comm.Rtype94, comm.Rtype96: + case comm.Rtype5, comm.Rtype41, comm.Rtype43, comm.Rtype92, comm.Rtype94, comm.Rtype95, comm.Rtype96: module = comm.ModuleEquipment + case comm.Rtype128, comm.Rtype129, comm.Rtype131: + module = comm.ModuleArena + case comm.Rtype168: + module = comm.ModulePagoda 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 6ac6c3bbf..35e611438 100644 --- a/modules/robot/robot.go +++ b/modules/robot/robot.go @@ -51,7 +51,8 @@ func (this *Robot) Init(addr string, client IClient) (err error) { this.modules[comm.ModuleWtask] = new(ModuleRobot_WTask) this.modules[comm.ModulePractice] = new(ModuleRobot_Practice) this.modules[comm.ModuleMainline] = new(ModuleRobot_MainLine) - this.modules[comm.ModuleUser] = new(ModuleRobot_Pagoda) + this.modules[comm.ModuleArena] = new(ModuleRobot_Arena) + this.modules[comm.ModulePagoda] = new(ModuleRobot_Pagoda) for _, v := range this.modules { v.Init() } diff --git a/modules/warorder/modelWarorder.go b/modules/warorder/modelWarorder.go index 4e80d1598..194e01a46 100644 --- a/modules/warorder/modelWarorder.go +++ b/modules/warorder/modelWarorder.go @@ -1,6 +1,7 @@ package warorder import ( + "context" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" @@ -9,8 +10,10 @@ import ( "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" + "go_dreamfactory/utils" "sync" + "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" @@ -124,3 +127,58 @@ func (this *modelWarorder) refreshWeekTask(info *pb.DreamWarorder, confs map[int } info.Weektime = configure.Now().Unix() } + +//战令活动结束 +func (this *modelWarorder) settlement(wtype int32) { + var ( + confs []*cfg.GamePassCheckData + cursor *mongo.Cursor + warorder *pb.Warorder + err error + ok bool + days int32 + awards []*cfg.Gameatn + ) + if confs, err = this.module.configure.getorder(wtype); err != nil { + this.module.Errorln(err) + return + } + if cursor, err = this.module.model.DB.Find(core.SqlTable(this.TableName), bson.M{}); err != nil { + this.module.Errorln(err) + return + } + for cursor.Next(context.Background()) { + temp := &pb.DBWarorders{} + if err = cursor.Decode(temp); err != nil { + this.module.Errorln(err) + continue + } + + if warorder, ok = temp.Warorder[wtype]; !ok { + continue + } + + days = int32(utils.DiffDays(configure.Now().Unix(), warorder.Opentime)) + 1 + awards = make([]*cfg.Gameatn, 0) + for _, v := range confs { + if v.Parameter <= days { + if warorder.Freeprogress < v.Parameter { + awards = append(awards, v.FreeReward) + + } + if warorder.Vip { + if warorder.Payprogress < v.Parameter { + awards = append(awards, v.PayReward...) + } + } + } + } + warorder.Freeprogress = days + if warorder.Vip { + warorder.Payprogress = days + } + if len(awards) > 0 { + this.module.ModuleMail.SendMailByUID(temp.Uid, "", awards, nil) + } + } +} diff --git a/modules/warorder/module.go b/modules/warorder/module.go index ba4f14308..26cfa0412 100644 --- a/modules/warorder/module.go +++ b/modules/warorder/module.go @@ -156,5 +156,15 @@ func (this *Warorder) ActivityOpenNotice(hdlist *pb.DBHuodong) { // 活动关闭 func (this *Warorder) ActivityCloseNotice(hdlist *pb.DBHuodong) { - + switch hdlist.Itype { + case pb.HdType_HdTypeWarorder: + go this.model.settlement(2) + break + case pb.HdType_SupplyWarOrder: + go this.model.settlement(3) + break + case pb.HdType_MoondreamWarOrder: + // this.model.setopentime(4, hdlist) + break + } }