package wtask import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) // 参数校验 func (this *apiComp) AcceptCheck(session comm.IUserSession, req *pb.WTaskAcceptReq) (errdata *pb.ErrorData) { return } // /获取系统公告 func (this *apiComp) Accept(session comm.IUserSession, req *pb.WTaskAcceptReq) (errdata *pb.ErrorData) { var ( wtask *pb.DBWTask conf *cfg.GameWorldTaskData progress []*pb.DBWTaskItem update map[string]interface{} = make(map[string]interface{}) boxs map[int32]int32 ok bool err error ) if errdata = this.AcceptCheck(session, req); errdata != nil { return } if conf, err = this.module.configure.gettaskconfconfigure(req.Tid); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } if wtask, err = this.module.modelwtask.getUserWTasks(session.GetUserId()); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } ok = false for _, v := range wtask.Activations { if req.Tid == v { ok = true } } if !ok { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("task:%d no fund in Activations:%v", req.Tid, wtask.Activations), } return } for i, v := range wtask.Activations { if v == req.Tid { wtask.Activations = append(wtask.Activations[0:i], wtask.Activations[i+1:]...) break } } wtask.Accepts = append(wtask.Accepts, req.Tid) update["activations"] = wtask.Activations update["accepts"] = wtask.Accepts if errdata = this.module.ModuleBuried.ActiveCondition(session.GetUserId(), conf.Completetask...); err != nil { return } if conf.Trigger == 1 { //触发宝箱 if boxs, err = this.module.configure.getGameSearchitemAll(conf.Key); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: fmt.Sprintf("getGameSearchitemAll uid:%s taskid:%v", session.GetUserId(), conf.Key), } return } wtask.Boxs[conf.Key] = &pb.DBWTaskBox{ Boxs: boxs, } update["boxs"] = wtask.Boxs session.SendMsg(string(this.module.GetType()), "boxchange", &pb.WTaskBoxChangePush{Boxs: wtask.Boxs}) } if len(conf.GetItem) > 0 { //接取 获得物品 if errdata = this.module.DispenseRes(session, conf.GetItem, true); errdata != nil { return } } if progress, errdata = this.module.pushtaskprogress(session, wtask, false); errdata != nil { return } session.SendMsg(string(this.module.GetType()), "accept", &pb.WTaskAcceptResp{Tid: req.Tid, Activations: wtask.Activations, Accepts: progress}) if err = this.module.modelwtask.Change(session.GetUserId(), update); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "WTaskAcceptReq", conf.GetItem) }) return }