package sociaty import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "google.golang.org/protobuf/proto" ) // 公会任务奖励领取 func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.SociatyReceiveReq) (code pb.ErrorCode) { if req.TaskId == 0 { code = pb.ErrorCode_ReqParameterError 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) (code pb.ErrorCode, data proto.Message) { if code = this.ReceiveCheck(session, req); code != pb.ErrorCode_Success { return } uid := session.GetUserId() sociaty := this.module.modelSociaty.getUserSociaty(uid) if sociaty != nil && sociaty.Id == "" { code = pb.ErrorCode_SociatyNoFound this.module.Error("当前玩家所在的公会未找到", log.Field{Key: "uid", Value: uid}) return } sociatyTask := this.module.modelSociatyTask.getUserTask(uid, sociaty.Id) for _, v := range sociatyTask.TaskList { if v.TaskId == req.TaskId { if v.Status != 1 { code = pb.ErrorCode_SociatyTaskValidation return } if v.Received == 1 { //已领取 code = pb.ErrorCode_SociatyRewardReceived return } break } } // 奖励领取 if err := this.module.modelSociatyTask.receive(req.TaskId, sociaty.Id, uid); err != nil { code = pb.ErrorCode_SociatyRewardReceive 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 } //获取奖励配置 conf, ok := this.module.sociatyTaskConf.GetDataMap()[req.TaskId] if ok { // 发放个人奖励 if code = this.module.DispenseRes(session, conf.Reward, true); code != pb.ErrorCode_Success { 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: "code", Value: code}, ) } } // 更新公会经验和活跃度 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, } if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeReceive, rsp); err != nil { code = pb.ErrorCode_SystemError } return }