diff --git a/modules/dispatch/model_dispatch.go b/modules/dispatch/model_dispatch.go index 08b664a14..bd3185ef7 100644 --- a/modules/dispatch/model_dispatch.go +++ b/modules/dispatch/model_dispatch.go @@ -7,7 +7,6 @@ import ( "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" - "go_dreamfactory/utils" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" @@ -63,7 +62,9 @@ func (this *modelDispatch) getTasksWeight(dispatch *pb.DBDispatch) int32 { confList, err := this.module.configure.getDispatchTaskConfByType(int32(i + 1)) var tIds []int32 + var weights []int32 for _, v := range confList { + weights = append(weights, v.Weight) if v.Completecount == 0 { tIds = append(tIds, v.Id) } else if v.Completecount > 0 { @@ -76,11 +77,13 @@ func (this *modelDispatch) getTasksWeight(dispatch *pb.DBDispatch) int32 { } } } - idex := utils.RandomNumbers(0, len(tIds), 1) - if len(idex) == 0 { - return 0 - } - return tIds[idex[0]] + + idex := comm.GetRandW(weights) + // idex := utils.RandomNumbers(0, len(tIds), 1) + // if len(idex) == 0 { + // return 0 + // } + return tIds[idex] } // 随机任务 diff --git a/sys/configure/structs/Game.Dispatch_TaskData.go b/sys/configure/structs/Game.Dispatch_TaskData.go index c82fee976..cbb7812ff 100644 --- a/sys/configure/structs/Game.Dispatch_TaskData.go +++ b/sys/configure/structs/Game.Dispatch_TaskData.go @@ -13,6 +13,7 @@ import "errors" type GameDispatch_TaskData struct { Id int32 Type int32 + Weight int32 Taskname string Icon string Taskcd int32 @@ -37,6 +38,7 @@ func (*GameDispatch_TaskData) GetTypeId() int32 { func (_v *GameDispatch_TaskData)Deserialize(_buf map[string]interface{}) (err error) { { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["id"].(float64); !_ok_ { err = errors.New("id error"); return }; _v.Id = int32(_tempNum_) } { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["type"].(float64); !_ok_ { err = errors.New("type error"); return }; _v.Type = int32(_tempNum_) } + { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["weight"].(float64); !_ok_ { err = errors.New("weight error"); return }; _v.Weight = int32(_tempNum_) } {var _ok_ bool; var __json_text__ map[string]interface{}; if __json_text__, _ok_ = _buf["taskname"].(map[string]interface{}) ; !_ok_ { err = errors.New("_v.Taskname error"); return }; { var _ok_ bool; if _, _ok_ = __json_text__["key"].(string); !_ok_ { err = errors.New("key error"); return } }; { var _ok_ bool; if _v.Taskname, _ok_ = __json_text__["text"].(string); !_ok_ { err = errors.New("text error"); return } } } { var _ok_ bool; if _v.Icon, _ok_ = _buf["icon"].(string); !_ok_ { err = errors.New("icon error"); return } } { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["taskcd"].(float64); !_ok_ { err = errors.New("taskcd error"); return }; _v.Taskcd = int32(_tempNum_) }