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