Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
33dbbbdebf
@ -24,7 +24,7 @@ var (
|
||||
fmt.Printf("%d- %v\n", (i + 1), v)
|
||||
}
|
||||
},
|
||||
// enabled: true,
|
||||
enabled: true,
|
||||
next: func(robot *Robot, rsp proto.Message) {
|
||||
tcs := []*TestCase{}
|
||||
if _, ok := rsp.(*pb.HeroListResp); ok {
|
||||
@ -33,9 +33,9 @@ var (
|
||||
mainType: string(comm.ModuleHero),
|
||||
subType: hero.StrengthenUplv,
|
||||
req: &pb.HeroStrengthenUplvReq{
|
||||
HeroObjID: "62da4e1ecd19e620141eed75",
|
||||
HeroObjID: "62dabaacd8c5789e2cc8b95e",
|
||||
ExpCards: map[string]int32{
|
||||
"62da4e40cd19e620141eedeb": 1,
|
||||
"62dabac1d8c5789e2cc8b9d3": 1,
|
||||
},
|
||||
},
|
||||
rsp: &pb.HeroStrengthenUplvResp{},
|
||||
|
@ -17,7 +17,7 @@ var (
|
||||
subType: task.TaskSubTypeList,
|
||||
req: &pb.TaskListReq{
|
||||
//设置任务类型
|
||||
// TaskTag: int32(comm.TASK_DAILY), //每天任务
|
||||
TaskTag: int32(comm.TASK_DAILY), //每天任务
|
||||
// TaskTag: int32(comm.TASK_WEEKLY), //周任务
|
||||
// TaskTag: int32(comm.TASK_ACHIEVE),
|
||||
// TaskTag: int32(comm.TASK_STRATEGY),
|
||||
@ -40,7 +40,7 @@ var (
|
||||
subType: task.TaskSubTypeReceive,
|
||||
req: &pb.TaskReceiveReq{
|
||||
TaskTag: int32(comm.TASK_DAILY),
|
||||
Id: "62da4e20cd19e620141eed7b",
|
||||
Id: "62dab21d9efd6536b1cc1bb9",
|
||||
},
|
||||
rsp: &pb.TaskReceiveResp{},
|
||||
// enabled: true,
|
||||
@ -64,7 +64,7 @@ var (
|
||||
fmt.Printf("%v 活跃值:%v\n", v, out.Active)
|
||||
}
|
||||
},
|
||||
enabled: true,
|
||||
// enabled: true,
|
||||
}, {
|
||||
desc: "活跃度领取",
|
||||
mainType: string(comm.ModuleTask),
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
@ -43,7 +42,8 @@ func (this *ModelTask) getTaskList(uid string, taskTag comm.TaskTag) (newlist []
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModelTask) getTaskTypeList(uid string, taskType comm.TaskType) (newlist []*pb.DBTask) {
|
||||
// 获取用户任务
|
||||
func (this *ModelTask) getTaskById(uid string, taskId int32) (newlist []*pb.DBTask) {
|
||||
list := []*pb.DBTask{}
|
||||
if err := this.GetList(uid, &list); err != nil {
|
||||
log.Errorf("getTaskList err %v", err)
|
||||
@ -51,7 +51,7 @@ func (this *ModelTask) getTaskTypeList(uid string, taskType comm.TaskType) (newl
|
||||
}
|
||||
|
||||
for _, v := range list {
|
||||
if v.TypeId == int32(taskType) {
|
||||
if v.TaskId == taskId {
|
||||
newlist = append(newlist, v)
|
||||
}
|
||||
}
|
||||
@ -62,7 +62,6 @@ func (this *ModelTask) getTaskTypeList(uid string, taskType comm.TaskType) (newl
|
||||
func (this *ModelTask) initTask(uid string) error {
|
||||
if data, err := this.moduleTask.configure.getTaskList(); err == nil {
|
||||
for _, cnf := range data {
|
||||
//初始玩家任务数据
|
||||
objId := primitive.NewObjectID().Hex()
|
||||
task := &pb.DBTask{
|
||||
Id: objId,
|
||||
@ -92,9 +91,9 @@ func (this *ModelTask) getUserTask(uid string, taskId string) *pb.DBTask {
|
||||
return userTask
|
||||
}
|
||||
|
||||
//获取未完成的任务列表
|
||||
func (this *ModelTask) getUnFinishTaskList(uid string, taskType comm.TaskType) (list []*pb.DBTask) {
|
||||
taskList := this.getTaskTypeList(uid, taskType)
|
||||
// 获取待处理的任务
|
||||
func (this *ModelTask) getUnFinishTasks(uid string, taskId int32) (list []*pb.DBTask) {
|
||||
taskList := this.getTaskById(uid, taskId)
|
||||
for _, v := range taskList {
|
||||
if v.Status == 0 {
|
||||
list = append(list, v)
|
||||
@ -114,15 +113,14 @@ func (this *ModelTask) countActive(uid string, taskTag comm.TaskTag) (total int3
|
||||
return
|
||||
}
|
||||
|
||||
//检查任务进度 返回未完成的
|
||||
func (this *ModelTask) checkTaskProgress(uid string, config *cfg.Game_taskRoundData) (*pb.DBTask, bool) {
|
||||
taskList := this.getUnFinishTaskList(uid, comm.TaskType(config.TypeId))
|
||||
//检查任务状态 返回等待处理的任务
|
||||
func (this *ModelTask) checkTask(uid string, taskId int32) (*pb.DBTask, bool) {
|
||||
taskList := this.getUnFinishTasks(uid, taskId)
|
||||
for _, v := range taskList {
|
||||
if config.Key == v.TaskId && v.Status == 0 {
|
||||
if taskId == v.TaskId && v.Status == 0 {
|
||||
return v, true
|
||||
}
|
||||
}
|
||||
|
||||
return nil, false
|
||||
}
|
||||
|
||||
@ -135,62 +133,6 @@ func (this *ModelTask) modifyUserTask(uid string, taskId string, data map[string
|
||||
return nil
|
||||
}
|
||||
|
||||
//任务处理
|
||||
func (this *ModelTask) taskHandle(uid string, taskType comm.TaskType, taskParam *pb.TaskParam) (tasks []*pb.DBTask, err error) {
|
||||
data, err := this.moduleTask.configure.getTasks(int32(taskType))
|
||||
if err != nil {
|
||||
log.Errorf("taskHandle err %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, conf := range data {
|
||||
if conf.RestrictiveCondition != 0 {
|
||||
//不满足限定条件
|
||||
if taskParam.First < conf.RestrictiveCondition {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if taskParam.Second < conf.ConditionSecond {
|
||||
continue
|
||||
}
|
||||
|
||||
//检查进度,执行处理器
|
||||
if v, ok := this.checkTaskProgress(uid, conf); ok {
|
||||
if tt, err := this.finishHandle(v, conf, taskParam.Second); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
tasks = append(tasks, tt)
|
||||
}
|
||||
}
|
||||
}
|
||||
return tasks, nil
|
||||
}
|
||||
|
||||
//任务完成处理
|
||||
func (this *ModelTask) finishHandle(userTask *pb.DBTask, config *cfg.Game_taskRoundData, count int32) (*pb.DBTask, error) {
|
||||
var progress int32
|
||||
if count >= userTask.Progress {
|
||||
progress = 0
|
||||
}
|
||||
|
||||
if progress == 0 {
|
||||
//修改玩家任务状态和进度
|
||||
update := map[string]interface{}{
|
||||
"progress": progress,
|
||||
}
|
||||
update["status"] = 1
|
||||
if err := this.modifyUserTask(userTask.Uid, userTask.Id, update); err != nil {
|
||||
log.Errorf("err %v", err)
|
||||
return nil, err
|
||||
}
|
||||
userTask.Progress = progress
|
||||
userTask.Status = 1
|
||||
}
|
||||
|
||||
return userTask, nil
|
||||
}
|
||||
|
||||
//清空任务
|
||||
func (this *ModelTask) clearTask(uid string, taskTag comm.TaskTag) error {
|
||||
taskList := this.getTaskList(uid, taskTag)
|
||||
@ -241,14 +183,67 @@ func (this *ModelTask) inStrategy(uid string, heroCfgId int32) (taskIds []int32,
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModelTask) UpEquip() {
|
||||
|
||||
// 任务类型-装备升级
|
||||
func (this *ModelTask) UpEquip(uid string, taskId int32, tp *pb.TaskParam) *pb.DBTask {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *ModelTask) UpHeroStar() {
|
||||
|
||||
// 任务类型-英雄星级升级
|
||||
func (this *ModelTask) UpHeroStar(uid string, taskId int32, tp *pb.TaskParam) *pb.DBTask {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *ModelTask) UpHeroLevel() {
|
||||
|
||||
// 任务类型-英雄等级升级
|
||||
func (this *ModelTask) UpHeroLevel(uid string, taskId int32, tp *pb.TaskParam) *pb.DBTask {
|
||||
if task, ok := this.checkTask(uid, taskId); ok {
|
||||
var progress int32
|
||||
if tp.Second >= task.Progress {
|
||||
progress = 0
|
||||
//修改玩家任务状态和进度
|
||||
update := map[string]interface{}{
|
||||
"progress": progress,
|
||||
}
|
||||
update["status"] = 1
|
||||
if err := this.modifyUserTask(task.Uid, task.Id, update); err != nil {
|
||||
log.Errorf("err %v", err)
|
||||
return nil
|
||||
}
|
||||
task.Progress = progress
|
||||
task.Status = 1
|
||||
return task
|
||||
} else {
|
||||
progress = task.Progress - tp.Second
|
||||
if progress <= 0 {
|
||||
progress = 0
|
||||
}
|
||||
update := map[string]interface{}{
|
||||
"progress": progress,
|
||||
}
|
||||
if err := this.modifyUserTask(task.Uid, task.Id, update); err != nil {
|
||||
log.Errorf("err %v", err)
|
||||
return nil
|
||||
}
|
||||
task.Progress = progress
|
||||
return task
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 任务处理
|
||||
func (this *ModelTask) doTaskHandle(uid string, taskType comm.TaskType, taskParam *pb.TaskParam) (tasks []*pb.DBTask, err error) {
|
||||
data, err := this.moduleTask.configure.getTasks(int32(taskType))
|
||||
if err != nil {
|
||||
log.Errorf("taskHandle err %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, conf := range data {
|
||||
if handle, ok := this.moduleTask.taskHandleMap[conf.TypeId]; ok {
|
||||
if task := handle(uid, conf.Key, taskParam); task != nil {
|
||||
tasks = append(tasks, task)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -15,10 +15,14 @@ type ModuleTask struct {
|
||||
modelTaskActive *ModelTaskActive
|
||||
api *apiComp
|
||||
configure *configureComp
|
||||
|
||||
taskHandleMap map[int32]taskHandle //任务处理器
|
||||
}
|
||||
|
||||
func NewModule() core.IModule {
|
||||
return &ModuleTask{}
|
||||
return &ModuleTask{
|
||||
taskHandleMap: make(map[int32]taskHandle),
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ModuleTask) GetType() core.M_Modules {
|
||||
@ -27,7 +31,7 @@ func (this *ModuleTask) GetType() core.M_Modules {
|
||||
|
||||
func (this *ModuleTask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
||||
err = this.ModuleBase.Init(service, module, options)
|
||||
// this.initTaskHandle()
|
||||
this.initTaskHandle()
|
||||
return
|
||||
}
|
||||
|
||||
@ -68,7 +72,7 @@ func (this *ModuleTask) ResetTask(uid string, taskTag comm.TaskTag) {
|
||||
|
||||
//任务处理
|
||||
func (this *ModuleTask) SendToTask(session comm.IUserSession, taskType comm.TaskType, taskPram *pb.TaskParam) (code pb.ErrorCode) {
|
||||
if tasks, err := this.modelTask.taskHandle(session.GetUserId(), taskType, taskPram); err != nil {
|
||||
if tasks, err := this.modelTask.doTaskHandle(session.GetUserId(), taskType, taskPram); err != nil {
|
||||
code = pb.ErrorCode_TaskHandle
|
||||
} else {
|
||||
for _, t := range tasks {
|
||||
@ -102,10 +106,12 @@ func (this *ModuleTask) CleanData(uid string) {
|
||||
}
|
||||
|
||||
//任务处理器注册
|
||||
type taskHandle func()
|
||||
type taskHandle func(uid string, taskId int32, tp *pb.TaskParam) *pb.DBTask
|
||||
|
||||
func (this *ModuleTask) register(taskType comm.TaskType, fn taskHandle) {
|
||||
|
||||
if _, ok := this.taskHandleMap[int32(taskType)]; !ok {
|
||||
this.taskHandleMap[int32(taskType)] = fn
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ModuleTask) initTaskHandle() {
|
||||
@ -115,13 +121,12 @@ func (this *ModuleTask) initTaskHandle() {
|
||||
case int32(comm.TaskTypeUpEquip):
|
||||
this.register(comm.TaskTypeUpEquip, this.modelTask.UpEquip)
|
||||
case int32(comm.TaskTypeUpHeroStar):
|
||||
this.register(comm.TaskTypeUpEquip, this.modelTask.UpHeroStar)
|
||||
this.register(comm.TaskTypeUpHeroStar, this.modelTask.UpHeroStar)
|
||||
case int32(comm.TaskTypeUpHeroLevel):
|
||||
this.register(comm.TaskTypeUpEquip, this.modelTask.UpHeroLevel)
|
||||
this.register(comm.TaskTypeUpHeroLevel, this.modelTask.UpHeroLevel)
|
||||
default:
|
||||
log.Error("no ")
|
||||
log.Errorf("%v task type not supported", v.TypeId)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user