package sociaty import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) // 公会任务奖励领取 func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.SociatyReceiveReq) (errdata *pb.ErrorData) { if req.TaskId == 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } this.module.Error("公会任务奖励领取参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()}) } return } func (this *apiComp) Receive(session comm.IUserSession, req *pb.SociatyReceiveReq) (errdata *pb.ErrorData) { var ( conf *cfg.GameGuildTaskData state int32 atno []*pb.UserAtno ok bool ) if errdata = this.ReceiveCheck(session, req); errdata != nil { return } uid := session.GetUserId() sociaty := this.module.modelSociaty.getUserSociaty(uid) if sociaty == nil { this.module.Error("当前玩家所在的公会未找到", log.Field{Key: "uid", Value: uid}) return } sociatyTask, _ := this.module.modelSociatyTask.getUserTask(uid, sociaty.Id) if state, ok = sociatyTask.TaskList[req.TaskId]; ok && state > 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_SociatyRewardReceived, Title: pb.ErrorCode_SociatyRewardReceived.ToString(), Message: "Received!", } return } sociatyTask.TaskList[req.TaskId] = 1 //获取奖励配置 conf, ok = this.module.sociatyTaskConf.GetDataMap()[req.TaskId] if !ok { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: fmt.Sprintf("no found task conf:%d", req.TaskId), } return } if ok, _, _ = this.module.ModuleBuried.CheckCondition(session, conf.TypeId); !ok { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("task:%d is unfish!", req.TaskId), } return } // 发放个人奖励 if errdata, atno = this.module.DispenseAtno(session, conf.Reward, true); errdata != nil { this.module.Error("发放公会个人奖励失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "sociatyId", Value: sociaty.Id}, log.Field{Key: "taskId", Value: req.TaskId}, ) } // 奖励领取 if err := this.module.modelSociatyTask.receive(sociatyTask); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_SociatyRewardReceived, Title: pb.ErrorCode_SociatyRewardReceived.ToString(), } this.module.Error("领取公会任务奖励", log.Field{Key: "uid", Value: uid}, log.Field{Key: "sociatyId", Value: sociaty.Id}, log.Field{Key: "taskId", Value: req.TaskId}, log.Field{Key: "err", Value: err.Error()}, ) return } // 更新公会经验和活跃度 if err := this.module.modelSociaty.updateResourceFromTask(sociaty, conf); err != nil { this.module.Error("更新公会资源", log.Field{Key: "uid", Value: uid}, log.Field{Key: "sociatyId", Value: sociaty.Id}, log.Field{Key: "taskId", Value: req.TaskId}, log.Field{Key: "err", Value: err.Error()}, ) return } // 更新成员贡献值 if err := this.module.modelSociaty.updateMemberContribution(uid, conf.Contribution, sociaty); err != nil { this.module.Error("更新公会成员贡献值", log.Field{Key: "uid", Value: uid}, log.Field{Key: "sociatyId", Value: sociaty.Id}, log.Field{Key: "taskId", Value: req.TaskId}, log.Field{Key: "err", Value: err.Error()}, ) return } rsp := &pb.SociatyReceiveResp{ SociatyId: sociaty.Id, TaskId: req.TaskId, Reward: atno, } session.SendMsg(string(this.module.GetType()), SociatySubTypeReceive, rsp) go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "SociatyReceiveReq", atno) }) return }