80 lines
2.0 KiB
Go
80 lines
2.0 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 公会BOSS 积分奖励领取
|
|
|
|
func (this *apiComp) BreceiveCheck(session comm.IUserSession, req *pb.SociatyBReceiveReq) (code pb.ErrorCode) {
|
|
if req.TaskId <= 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Breceive(session comm.IUserSession, req *pb.SociatyBReceiveReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
if code = this.BreceiveCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
uid := session.GetUserId()
|
|
sociaty := this.module.modelSociaty.getUserSociaty(uid)
|
|
if sociaty == nil {
|
|
code = pb.ErrorCode_SociatyNoFound
|
|
this.module.Error("当前玩家所在的公会未找到", log.Field{Key: "uid", Value: uid})
|
|
return
|
|
}
|
|
|
|
taskConf := this.module.configure.getBossTask(req.TaskId)
|
|
if taskConf == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
dbr := this.module.modelSociatyBoss.getChallengeRecord(uid)
|
|
var taskId int32
|
|
for _, task := range dbr.Tasks {
|
|
if task.TaskId == req.TaskId {
|
|
taskId = task.TaskId
|
|
if task.Status == 2 { //已领取
|
|
code = pb.ErrorCode_SociatyTaskReceived
|
|
return
|
|
} else if taskId == 0 { //未完成
|
|
code = pb.ErrorCode_SociatyTaskNoFinished
|
|
return
|
|
} else if taskId == 1 { //可领取
|
|
task.Status = 2
|
|
}
|
|
break
|
|
}
|
|
}
|
|
|
|
//更新任务状态
|
|
update := map[string]interface{}{
|
|
"tasks": dbr.Tasks,
|
|
}
|
|
if err := this.module.modelSociatyBoss.Change(uid, update); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
// 奖励
|
|
if code := this.module.DispenseRes(session, taskConf.Reward, true); code != pb.ErrorCode_Success {
|
|
this.module.Error("积分任务奖励领取",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "taskId", Value: taskId},
|
|
log.Field{Key: "reward", Value: taskConf.Reward})
|
|
}
|
|
|
|
rsp := &pb.SociatyBReceiveResp{
|
|
SociatyId: sociaty.Id,
|
|
TaskId: req.TaskId,
|
|
}
|
|
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeBreceive, rsp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
}
|
|
return
|
|
}
|