更新派遣概率
This commit is contained in:
parent
7253886ac5
commit
7c709ccca7
@ -78,57 +78,36 @@ func (this *modelDispatch) getDBDispatch(uid string) (dis *pb.DBDispatch) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取任务权重数据
|
// 获取随机任务ID
|
||||||
func (this *modelDispatch) getTasksWeight(uid string, d *pb.DBDispatch) []int32 {
|
func (this *modelDispatch) getTasksWeight(uid string, d *pb.DBDispatch) int32 {
|
||||||
if d == nil {
|
if d == nil {
|
||||||
return []int32{}
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.Nb == nil {
|
if d.Nb == nil {
|
||||||
return []int32{}
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
conf, err := this.module.configure.getDispatchLvConf(d.Nb.Lv)
|
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 0
|
||||||
}
|
}
|
||||||
|
|
||||||
items := make([]*comm.WeightItem, 0)
|
// 取权重数组下标
|
||||||
for i, v := range conf.Probability {
|
i := comm.GetRandW(conf.Probability)
|
||||||
items = append(items, &comm.WeightItem{Id: (i + 1), Weight: int(v)})
|
this.module.Debug("随机下标", log.Field{Key: "idx", Value: i})
|
||||||
}
|
confList, err := this.module.configure.getDispatchTaskConfByType(int32(i + 1))
|
||||||
|
|
||||||
wr := comm.NewWeightedRandom(items)
|
|
||||||
//根据权重选出任务类型
|
|
||||||
var taskType int
|
|
||||||
if c := wr.Pick(); c != nil {
|
|
||||||
taskType = c.Id.(int)
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
tIds = append(tIds, v.Id)
|
tIds = append(tIds, v.Id)
|
||||||
}
|
}
|
||||||
|
idex := utils.RandomNumbers(0, len(tIds), 1)
|
||||||
|
if len(idex) == 0 {
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
} else {
|
return tIds[idex[0]]
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 随机任务
|
// 随机任务
|
||||||
@ -137,19 +116,33 @@ func (this *modelDispatch) taskRandom(uid string, dispatch *pb.DBDispatch) (task
|
|||||||
dispatch.Nb.Lv = 1
|
dispatch.Nb.Lv = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
tIds := this.getTasksWeight(uid, dispatch)
|
|
||||||
if len(tIds) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//判断随机数量
|
//判断随机数量
|
||||||
var n int
|
var n int
|
||||||
n = len(dispatch.Nb.Tasks)
|
n = len(dispatch.Nb.Tasks)
|
||||||
|
|
||||||
|
var existIds []int32
|
||||||
|
for _, v := range dispatch.Nb.Tasks {
|
||||||
|
existIds = append(existIds, v.TaskId)
|
||||||
|
}
|
||||||
|
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
//随机6个任务
|
//随机6个任务
|
||||||
ids := utils.RandomNumbers(1, len(tIds), 6)
|
total := 0
|
||||||
for _, id := range ids {
|
for total < 6 {
|
||||||
|
tId := this.getTasksWeight(uid, dispatch)
|
||||||
|
if tId == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//去重
|
||||||
|
if _, ok := utils.Findx(existIds, int32(tId)); !ok {
|
||||||
|
existIds = append(existIds, int32(tId))
|
||||||
|
total++
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, id := range existIds {
|
||||||
taskConf, err := this.module.configure.getDispatchTaskConf(int32(id))
|
taskConf, err := this.module.configure.getDispatchTaskConf(int32(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
@ -162,13 +155,12 @@ func (this *modelDispatch) taskRandom(uid string, dispatch *pb.DBDispatch) (task
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tasks = dispatch.Nb.Tasks
|
|
||||||
var randCount int
|
var randCount int
|
||||||
for i := 0; i < len(tasks); i++ {
|
for i := 0; i < len(dispatch.Nb.Tasks); i++ {
|
||||||
//只随机未接取的任务
|
//只随机未接取的任务
|
||||||
if tasks[i].Status == 0 {
|
if dispatch.Nb.Tasks[i].Status == 0 {
|
||||||
//删除
|
//删除
|
||||||
tasks = append(tasks[:i], tasks[i+1:]...)
|
dispatch.Nb.Tasks = append(dispatch.Nb.Tasks[:i], dispatch.Nb.Tasks[i+1:]...)
|
||||||
i--
|
i--
|
||||||
randCount++
|
randCount++
|
||||||
}
|
}
|
||||||
@ -185,18 +177,27 @@ func (this *modelDispatch) addRandomTask(uid string, dispatch *pb.DBDispatch, n
|
|||||||
tasks = dispatch.Nb.Tasks
|
tasks = dispatch.Nb.Tasks
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
randomTaskIds := this.getTasksWeight(uid, dispatch)
|
|
||||||
if len(randomTaskIds) == 0 {
|
var existIds []int32
|
||||||
return nil
|
for _, v := range dispatch.Nb.Tasks {
|
||||||
|
existIds = append(existIds, v.TaskId)
|
||||||
}
|
}
|
||||||
|
|
||||||
//追加n条随机任务
|
total := 0
|
||||||
ids := utils.RandomNumbers(1, len(randomTaskIds), n)
|
|
||||||
if len(ids) <= 0 {
|
for total < n {
|
||||||
|
rid := this.getTasksWeight(uid, dispatch)
|
||||||
|
if rid == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
//去重
|
||||||
|
if _, ok := utils.Findx(existIds, int32(rid)); !ok {
|
||||||
|
existIds = append(existIds, int32(rid))
|
||||||
|
total++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, id := range ids {
|
for _, id := range existIds {
|
||||||
taskConf, err := this.module.configure.getDispatchTaskConf(int32(id))
|
taskConf, err := this.module.configure.getDispatchTaskConf(int32(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -556,21 +556,22 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *ModuleRtask) TriggerTask(uid string, taskParams ...*comm.TaskParam) {
|
func (this *ModuleRtask) TriggerTask(uid string, taskParams ...*comm.TaskParam) {
|
||||||
|
this.Debug("任务处理",
|
||||||
|
log.Field{Key: "uid", Value: uid},
|
||||||
|
log.Field{Key: "params", Value: taskParams})
|
||||||
session, ok := this.GetUserSession(uid)
|
session, ok := this.GetUserSession(uid)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tp := range taskParams {
|
for _, tp := range taskParams {
|
||||||
if code := this.processOneTask(session, tp.TT, tp.Params...); code != pb.ErrorCode_Success {
|
if code := this.processOneTask(session, tp.TT, tp.Params...); code != pb.ErrorCode_Success {
|
||||||
// this.Debug("任务处理",
|
|
||||||
// log.Field{Key: "uid", Value: uid},
|
|
||||||
// log.Field{Key: "taskType", Value: tp.TT},
|
|
||||||
// log.Field{Key: "params", Value: tp.Params},
|
|
||||||
// log.Field{Key: "code", Value: code})
|
|
||||||
}
|
}
|
||||||
session.Push()
|
session.Push()
|
||||||
comm.PuttaskParam(tp)
|
comm.PuttaskParam(tp)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.PutUserSession(session)
|
this.PutUserSession(session)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user