package worldtask import ( "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/utils" ) var _ comm.IWorldtask = (*Worldtask)(nil) type Worldtask struct { modules.ModuleBase api *apiComp service base.IRPCXService configure *configureComp modelWorldtask *ModelWorldtask worldtaskConf *cfg.GameWorldTask worldBattleConf *cfg.GameWorldBattle } func NewModule() core.IModule { return &Worldtask{} } func (this *Worldtask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service.(base.IRPCXService) return } func (this *Worldtask) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelWorldtask = this.RegisterComp(new(ModelWorldtask)).(*ModelWorldtask) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } func (this *Worldtask) GetType() core.M_Modules { return comm.ModuleWorldtask } func (this *Worldtask) Start() (err error) { err = this.ModuleBase.Start() if this.worldtaskConf, err = this.configure.getWorldtaskCfg(); err != nil { return err } if this.worldBattleConf, err = this.configure.getWorldtaskBattleCfg(); err != nil { return err } return } // 任务条件达成通知 func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condId int32) error { uid := session.GetUserId() // 玩家世界任务 userTask, err := this.modelWorldtask.getWorldtask(uid) if err != nil { this.Error("获取玩家世界任务", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condId", Value: condId}) return err } var groupId, taskId int32 // 检索condId是否是世界任务的完成条件 finishedTaskIds := make(map[int32]int32) //达成的任务条件 for _, c := range this.worldtaskConf.GetDataList() { for _, v := range c.Completetask { if v == condId { //校验任务是否是当前任务 if task, ok := userTask.CurrentTask[c.Group]; ok { if task.NpcStatus == 1 && c.Key == task.TaskId{ finishedTaskIds[c.Group] = c.Key groupId = c.Group taskId = c.Key } } break } } } if len(finishedTaskIds) == 0 { return nil } if userTask.CurrentTask == nil { userTask.CurrentTask = make(map[int32]*pb.Worldtask) } wt, ok := userTask.CurrentTask[groupId] if !ok { wt = &pb.Worldtask{} } if _, ok := utils.Findx(wt.CondiIds, condId); !ok { wt.CondiIds = append(wt.CondiIds, condId) } userTask.CurrentTask[groupId] = wt this.Debug("当前任务更新", log.Field{Key: "currentTask", Value: userTask.CurrentTask}) update := map[string]interface{}{ "currentTask": userTask.CurrentTask, } this.modelWorldtask.Change(uid, update) session.SendMsg(string(this.GetType()), "completecondis", &pb.WorldtaskCompletecondisPush{ GroupId: groupId, TaskId: taskId, CondiIds: wt.CondiIds, }) this.Debug("推送完成条件", log.Field{Key: "condiIds", Value: wt.CondiIds}, log.Field{Key: "taskId", Value: taskId}) // 当前任务配置 curTaskConf, err := this.configure.getWorldtaskById(taskId) if err != nil || curTaskConf == nil { return comm.NewCustomError(pb.ErrorCode_ConfigNoFound) } //结束任务 if curTaskConf.DeliverNpc == 0 { this.modelWorldtask.taskFinish(session, groupId, taskId, userTask, curTaskConf) this.modelWorldtask.taskFinishPush(session, groupId, userTask, curTaskConf) } return nil } // 获取我的世界任务 func (this *Worldtask) GetMyWorldtask(uid string) *pb.DBWorldtask { wt, err := this.modelWorldtask.getWorldtask(uid) if err != nil { log.Errorln(err.Error()) return nil } return wt } func (this *Worldtask) BingoAllTask(session comm.IUserSession) error { // uid := session.GetUserId() // mytask := &pb.DBWorldtask{Uid: uid} // tasklist := this.worldtaskConf.GetDataList() // for _, conf := range tasklist { // //世界任务配置 // wt := &pb.Worldtask{ // TaskId: conf.Key, // TaskType: conf.Des, // } // mytask.TaskList = append(mytask.TaskList, wt) // } // if err := this.modelWorldtask.Add(uid, mytask); err != nil { // return err // } // rsp := &pb.WorldtaskFinishIdsPush{ // TaskList: mytask.TaskList, // } return nil //session.SendMsg(string(this.GetType()), "finishids", rsp) } // bingo世界任务跳跃 支持回退 func (this *Worldtask) BingoJumpTask(session comm.IUserSession, groupId, taskId int32) error { // uid := session.GetUserId() // mytask, err := this.modelWorldtask.getWorldtask(uid) // if err != nil { // return err // } // mytask.Uid = uid // // 更新数据 // update := map[string]interface{}{} // taskConf := this.worldtaskConf.GetDataMap()[taskId] // if taskConf == nil { // return fmt.Errorf("taskId: %v config is nil", taskId) // } // //重置taskList // mytask.TaskList = []*pb.Worldtask{} // //遍历 // if taskConf.Ontxe != 0 && taskConf.IdAfter != 0 { // for _, v := range this.worldtaskConf.GetDataList() { // if v.Group == groupId && v.Key <= taskId { // wt := &pb.Worldtask{ // TaskId: v.Key, // TaskType: v.Des, // } // mytask.TaskList = append(mytask.TaskList, wt) // } // } // } else { // wt := &pb.Worldtask{ // TaskId: taskId, // TaskType: taskConf.Des, // } // mytask.TaskList = append(mytask.TaskList, wt) // } // update = map[string]interface{}{ // "taskList": mytask.TaskList, // } // if err := this.modelWorldtask.Change(uid, update); err != nil { // return err // } // rsp := &pb.WorldtaskFinishIdsPush{ // TaskList: mytask.TaskList, // } return nil //session.SendMsg(string(this.GetType()), "finishids", rsp) }