Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
4a199ed7d1
@ -1259,6 +1259,54 @@
|
|||||||
"data4": 0,
|
"data4": 0,
|
||||||
"data5": 0
|
"data5": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": 304,
|
||||||
|
"type_sp": 1,
|
||||||
|
"tasktxt": "通关维京远征难度1",
|
||||||
|
"type": 73,
|
||||||
|
"valid": 0,
|
||||||
|
"data1": 1,
|
||||||
|
"data2": 1001,
|
||||||
|
"data3": 1,
|
||||||
|
"data4": 0,
|
||||||
|
"data5": 10071
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 305,
|
||||||
|
"type_sp": 1,
|
||||||
|
"tasktxt": "通关主线1-6",
|
||||||
|
"type": 61,
|
||||||
|
"valid": 0,
|
||||||
|
"data1": 1100106,
|
||||||
|
"data2": 0,
|
||||||
|
"data3": 0,
|
||||||
|
"data4": 0,
|
||||||
|
"data5": 102
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 306,
|
||||||
|
"type_sp": 1,
|
||||||
|
"tasktxt": "进行一次10连",
|
||||||
|
"type": 14,
|
||||||
|
"valid": 0,
|
||||||
|
"data1": 10,
|
||||||
|
"data2": 0,
|
||||||
|
"data3": 0,
|
||||||
|
"data4": 0,
|
||||||
|
"data5": 101
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 307,
|
||||||
|
"type_sp": 1,
|
||||||
|
"tasktxt": "打败梦魇!",
|
||||||
|
"type": 70,
|
||||||
|
"valid": 0,
|
||||||
|
"data1": 1,
|
||||||
|
"data2": 102,
|
||||||
|
"data3": 0,
|
||||||
|
"data4": 0,
|
||||||
|
"data5": 10101
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": 10001,
|
"id": 10001,
|
||||||
"type_sp": 0,
|
"type_sp": 0,
|
||||||
|
@ -302,7 +302,7 @@
|
|||||||
"id": 10082,
|
"id": 10082,
|
||||||
"datas": [
|
"datas": [
|
||||||
"GameMain",
|
"GameMain",
|
||||||
"食人鱼",
|
"20080_食人鱼_1",
|
||||||
"901"
|
"901"
|
||||||
],
|
],
|
||||||
"event": [
|
"event": [
|
||||||
@ -354,7 +354,7 @@
|
|||||||
"id": 10101,
|
"id": 10101,
|
||||||
"datas": [
|
"datas": [
|
||||||
"GameMain",
|
"GameMain",
|
||||||
"梦魇",
|
"20100_梦魇_1",
|
||||||
"901"
|
"901"
|
||||||
],
|
],
|
||||||
"event": [
|
"event": [
|
||||||
|
@ -231,7 +231,7 @@
|
|||||||
},
|
},
|
||||||
"npc": 10070,
|
"npc": 10070,
|
||||||
"completetask": [
|
"completetask": [
|
||||||
0
|
304
|
||||||
],
|
],
|
||||||
"deliver_npc": 10072,
|
"deliver_npc": 10072,
|
||||||
"auto_accept": 0,
|
"auto_accept": 0,
|
||||||
@ -266,7 +266,7 @@
|
|||||||
},
|
},
|
||||||
"npc": 10080,
|
"npc": 10080,
|
||||||
"completetask": [
|
"completetask": [
|
||||||
0
|
305
|
||||||
],
|
],
|
||||||
"deliver_npc": 10082,
|
"deliver_npc": 10082,
|
||||||
"auto_accept": 0,
|
"auto_accept": 0,
|
||||||
@ -301,7 +301,7 @@
|
|||||||
},
|
},
|
||||||
"npc": 10090,
|
"npc": 10090,
|
||||||
"completetask": [
|
"completetask": [
|
||||||
0
|
306
|
||||||
],
|
],
|
||||||
"deliver_npc": 0,
|
"deliver_npc": 0,
|
||||||
"auto_accept": 0,
|
"auto_accept": 0,
|
||||||
@ -336,7 +336,7 @@
|
|||||||
},
|
},
|
||||||
"npc": 10100,
|
"npc": 10100,
|
||||||
"completetask": [
|
"completetask": [
|
||||||
0
|
307
|
||||||
],
|
],
|
||||||
"deliver_npc": 10102,
|
"deliver_npc": 10102,
|
||||||
"auto_accept": 1,
|
"auto_accept": 1,
|
||||||
|
@ -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 {
|
tIds = append(tIds, v.Id)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
idex := utils.RandomNumbers(0, len(tIds), 1)
|
||||||
return tIds
|
if len(idex) == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return tIds[idex[0]]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 随机任务
|
// 随机任务
|
||||||
@ -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 {
|
||||||
return nil
|
rid := this.getTasksWeight(uid, dispatch)
|
||||||
|
if rid == 0 {
|
||||||
|
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
|
||||||
|
@ -41,7 +41,7 @@ type ModuleRtask struct {
|
|||||||
modelRtaskRecord *ModelRtaskRecord
|
modelRtaskRecord *ModelRtaskRecord
|
||||||
api *apiComp
|
api *apiComp
|
||||||
configure *configureComp
|
configure *configureComp
|
||||||
handleMap sync.Map //map[int32]*rtaskCondi //任务校验处理器
|
handleMap sync.Map //map[int32]*rtaskCondi //任务校验处理器
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewModule() core.IModule {
|
func NewModule() core.IModule {
|
||||||
@ -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