战令关闭结算处理

This commit is contained in:
liwei1dao 2023-08-24 18:45:06 +08:00
parent d2628f0349
commit 3b460674dd
8 changed files with 257 additions and 9 deletions

View File

@ -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
}

View File

@ -102,7 +102,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
}
@ -161,6 +217,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 (

View File

@ -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("item", "getlist", &pb.ItemsGetlistReq{}); errdata != nil {
err = errors.New(errdata.Message)
return
}

View File

@ -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

View File

@ -129,8 +129,10 @@ locp:
module = comm.ModulePractice
case comm.Rtype61:
module = comm.ModuleMainline
case comm.Rtype5, comm.Rtype92, comm.Rtype94, comm.Rtype96:
case comm.Rtype5, comm.Rtype92, comm.Rtype94, comm.Rtype95, comm.Rtype96:
module = comm.ModuleEquipment
case comm.Rtype128, comm.Rtype129, comm.Rtype131:
module = comm.ModuleArena
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

View File

@ -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()
}

View File

@ -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)
}
}
}

View File

@ -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
}
}