113 lines
3.3 KiB
Go
113 lines
3.3 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 公会任务奖励领取
|
|
|
|
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) {
|
|
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)
|
|
for _, v := range sociatyTask.TaskList {
|
|
if v.TaskId == req.TaskId {
|
|
if v.Status != 1 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatyTaskValidation,
|
|
Title: pb.ErrorCode_SociatyTaskValidation.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if v.Received == 1 { //已领取
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatyRewardReceived,
|
|
Title: pb.ErrorCode_SociatyRewardReceived.ToString(),
|
|
}
|
|
return
|
|
}
|
|
break
|
|
}
|
|
}
|
|
|
|
// 奖励领取
|
|
if err := this.module.modelSociatyTask.receive(req.TaskId, sociaty.Id, uid); 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
|
|
}
|
|
|
|
//获取奖励配置
|
|
conf, ok := this.module.sociatyTaskConf.GetDataMap()[req.TaskId]
|
|
if ok {
|
|
// 发放个人奖励
|
|
if errdata = this.module.DispenseRes(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.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,
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), SociatySubTypeReceive, rsp)
|
|
return
|
|
}
|