This commit is contained in:
liwei1dao 2023-03-24 17:52:07 +08:00
commit 41c8b08bbc
3 changed files with 104 additions and 73 deletions

View File

@ -82,3 +82,25 @@ func (this *configureComp) getDispatchListConf() (list []*cfg.GameDispatch_TaskD
} }
return return
} }
func (this *configureComp) getDispatchTaskConfByType(typeId int32) (list []*cfg.GameDispatch_TaskData, err error) {
var v interface{}
if v, err = this.GetConfigure(gameDispatchTask); err != nil {
err = fmt.Errorf("%T no is *cfg.GameDispatchTask", v)
return
} else {
d, ok := v.(*cfg.GameDispatch_Task)
if !ok {
err = fmt.Errorf("%T is not *cfg.GameDispatchTask", v)
return
}
for _, v := range d.GetDataList() {
if v.Type == typeId {
list = append(list, v)
}
}
}
return
}

View File

@ -79,7 +79,7 @@ func (this *modelDispatch) getDBDispatch(uid string) (dis *pb.DBDispatch) {
} }
// 获取任务权重数据 // 获取任务权重数据
func (this *modelDispatch) getTasksWeight(uid string, noticeLv int32) []int32 { func (this *modelDispatch) getTasksWeight(uid string, d *pb.DBDispatch) []int32 {
dispatch := this.getDBDispatch(uid) dispatch := this.getDBDispatch(uid)
if dispatch == nil { if dispatch == nil {
return []int32{} return []int32{}
@ -89,7 +89,7 @@ func (this *modelDispatch) getTasksWeight(uid string, noticeLv int32) []int32 {
return []int32{} return []int32{}
} }
conf, err := this.module.configure.getDispatchLvConf(noticeLv) conf, err := this.module.configure.getDispatchLvConf(d.Nb.Lv)
if err != nil || conf == nil { if err != nil || conf == nil {
this.module.Error("配置不存在", log.Field{Key: "error", Value: err}) this.module.Error("配置不存在", log.Field{Key: "error", Value: err})
return []int32{} return []int32{}
@ -101,19 +101,33 @@ func (this *modelDispatch) getTasksWeight(uid string, noticeLv int32) []int32 {
} }
wr := comm.NewWeightedRandom(items) wr := comm.NewWeightedRandom(items)
//任务类型 //根据权重选出任务类型
var taskType int var taskType int
if c := wr.Pick(); c != nil { if c := wr.Pick(); c != nil {
taskType = c.Id.(int) taskType = c.Id.(int)
} }
confList := this.module.configure.getDispatchListConf() confList, err := this.module.configure.getDispatchTaskConfByType(int32(taskType))
var tIds []int32 var tIds []int32
if len(d.Nb.Tasks) == 0 {
for _, v := range confList { for _, v := range confList {
if int(v.Type) == taskType { if int(v.Type) == taskType {
tIds = append(tIds, v.Id) tIds = append(tIds, v.Id)
} }
} }
} else {
var existIds []int32
for _, v := range d.Nb.Tasks {
existIds = append(existIds, v.TaskId)
}
for _, v := range confList {
if int(v.Type) == taskType {
if _, ok := utils.Findx(existIds, v.Id); !ok {
tIds = append(tIds, v.Id)
}
}
}
}
return tIds return tIds
} }
@ -124,29 +138,33 @@ func (this *modelDispatch) taskRandom(uid string, dispatch *pb.DBDispatch) (task
dispatch.Nb.Lv = 1 dispatch.Nb.Lv = 1
} }
conf, err := this.module.configure.getDispatchLvConf(dispatch.Nb.Lv) // conf, err := this.module.configure.getDispatchLvConf(dispatch.Nb.Lv)
if err != nil || conf == nil { // if err != nil || conf == nil {
return nil, err // return nil, err
} // }
var items []*comm.WeightItem // var items []*comm.WeightItem
for i, v := range conf.Probability { // for i, v := range conf.Probability {
items = append(items, &comm.WeightItem{Id: (i + 1), Weight: int(v)}) // items = append(items, &comm.WeightItem{Id: (i + 1), Weight: int(v)})
} // }
wr := comm.NewWeightedRandom(items) // wr := comm.NewWeightedRandom(items)
//任务类型 // //任务类型
var taskType int // var taskType int
if c := wr.Pick(); c != nil { // if c := wr.Pick(); c != nil {
taskType = c.Id.(int) // taskType = c.Id.(int)
} // }
confList := this.module.configure.getDispatchListConf() // confList := this.module.configure.getDispatchListConf()
var tIds []int32 // var tIds []int32
for _, v := range confList { // for _, v := range confList {
if int(v.Type) == taskType { // if int(v.Type) == taskType {
tIds = append(tIds, v.Id) // tIds = append(tIds, v.Id)
} // }
// }
tIds := this.getTasksWeight(uid, dispatch)
if len(tIds) == 0 {
return
} }
//判断随机数量 //判断随机数量
@ -181,40 +199,44 @@ func (this *modelDispatch) taskRandom(uid string, dispatch *pb.DBDispatch) (task
} }
} }
//追加随机 //追加随机
for i := 0; i < randCount; i++ { tasks = this.addRandomTask(uid, dispatch, randCount)
task := this.addRandomTask(uid, dispatch)
if task != nil {
tasks = append(tasks, task)
}
}
} }
return return
} }
func (this *modelDispatch) addRandomTask(uid string, dispatch *pb.DBDispatch) *pb.DispatchTask { func (this *modelDispatch) addRandomTask(uid string, dispatch *pb.DBDispatch, n int) (tasks []*pb.DispatchTask) {
randomTaskIds := this.getTasksWeight(uid, dispatch.Nb.Lv) if n <= 0 {
tasks = dispatch.Nb.Tasks
return
}
randomTaskIds := this.getTasksWeight(uid, dispatch)
if len(randomTaskIds) == 0 { if len(randomTaskIds) == 0 {
return nil return nil
} }
//追加一条随机任务
ids := utils.RandomNumbers(1, len(randomTaskIds), 1) //追加n条随机任务
ids := utils.RandomNumbers(1, len(randomTaskIds), n)
if len(ids) <= 0 { if len(ids) <= 0 {
return nil return nil
} }
taskId := ids[0]
taskConf, err := this.module.configure.getDispatchTaskConf(int32(taskId)) for _, id := range ids {
taskConf, err := this.module.configure.getDispatchTaskConf(int32(id))
if err != nil { if err != nil {
return nil return nil
} }
//公告持续截至时间 //公告持续截至时间
duration := configure.Now().Unix() + int64(taskConf.Taskcd) duration := configure.Now().Unix() + int64(taskConf.Taskcd)
return &pb.DispatchTask{ dt := &pb.DispatchTask{
TaskId: int32(taskId), TaskId: int32(id),
Duration: duration, Duration: duration,
} }
tasks = append(tasks, dt)
}
return
} }
// 替换指定的已完成任务 // 替换指定的已完成任务
@ -235,12 +257,9 @@ func (this *modelDispatch) replaceTask(uid string, taskId int32, dispatch *pb.DB
break break
} }
} }
if randCount > 0 {
task := this.addRandomTask(uid, dispatch) tasks = this.addRandomTask(uid, dispatch, randCount)
if task != nil {
tasks = append(tasks, task)
}
}
return return
} }
@ -261,12 +280,7 @@ func (this *modelDispatch) replaceFinishedTask(uid string, dispatch *pb.DBDispat
} }
} }
for i := 0; i < randCount; i++ { tasks = this.addRandomTask(uid, dispatch, randCount)
task := this.addRandomTask(uid, dispatch)
if task != nil {
tasks = append(tasks, task)
}
}
return return
} }
@ -433,12 +447,8 @@ func (this *modelDispatch) updateNotice(uid string, dispatch *pb.DBDispatch) err
if count < 6 { if count < 6 {
randCount = 6 - count randCount = 6 - count
} }
for i := 0; i < randCount; i++ {
task := this.addRandomTask(uid, dispatch) dispatch.Nb.Tasks = this.addRandomTask(uid, dispatch, randCount)
if task != nil {
dispatch.Nb.Tasks = append(dispatch.Nb.Tasks, task)
}
}
//判断是否有下一等级 //判断是否有下一等级
nextConf, err := this.module.configure.getDispatchLvConf(dispatch.Nb.Lv + 1) nextConf, err := this.module.configure.getDispatchLvConf(dispatch.Nb.Lv + 1)

View File

@ -330,8 +330,7 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
} }
stime := time.Now() stime := time.Now()
// this.gateway.Debugf("----------3 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType) // this.gateway.Debugf("----------3 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType)
// ctx, _ := context.WithTimeout(context.Background(), time.Second*5) ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
ctx:=context.Background()
if len(serviceTag) == 0 { if len(serviceTag) == 0 {
// this.gateway.Debugf("----------4 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType) // this.gateway.Debugf("----------4 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType)
if err = this.gateway.Service().RpcCall(ctx, servicePath, string(comm.Rpc_GatewayRoute), req, reply); err != nil { if err = this.gateway.Service().RpcCall(ctx, servicePath, string(comm.Rpc_GatewayRoute), req, reply); err != nil {