96 lines
2.8 KiB
Go
96 lines
2.8 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 活跃度领取
|
|
func (this *apiComp) ActivityreceiveCheck(session comm.IUserSession, req *pb.SociatyActivityReceiveReq) (errdata *pb.ErrorData) {
|
|
if req.Id == 0 {
|
|
this.module.Error("活跃度领取参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Activityreceive(session comm.IUserSession, req *pb.SociatyActivityReceiveReq) (errdata *pb.ErrorData) {
|
|
|
|
var (
|
|
state int32
|
|
atno []*pb.UserAtno
|
|
ok bool
|
|
)
|
|
if errdata = this.ActivityreceiveCheck(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})
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatyNoFound,
|
|
Title: pb.ErrorCode_SociatyNoFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
// 判断奖励是否已领
|
|
sociatyTask := this.module.modelSociaty.getUserTaskList(uid, sociaty.Id)
|
|
if state, ok = sociatyTask.ActivityList[req.Id]; ok && state > 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatyRewardReceived,
|
|
Title: pb.ErrorCode_SociatyRewardReceived.ToString(),
|
|
Message: "Received!",
|
|
}
|
|
return
|
|
}
|
|
sociatyTask.ActivityList[req.Id] = 1
|
|
conf, ok := this.module.sociatyActivityConf.GetDataMap()[req.Id]
|
|
if !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
//是否满足领取条件
|
|
if sociaty.Activity < conf.Activity {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatyActivityNoEnough,
|
|
Title: pb.ErrorCode_SociatyActivityNoEnough.ToString(),
|
|
Message: fmt.Sprintf("活跃度不足 实际:%d 期望:%d", sociaty.Activity, conf.Activity),
|
|
}
|
|
return
|
|
}
|
|
// 发放个人奖励
|
|
if errdata, atno = this.module.DispenseAtno(session, conf.Reward, true); errdata != nil {
|
|
return
|
|
}
|
|
// 活跃度领取
|
|
if err := this.module.modelSociatyTask.ChangeList(sociatyTask.SociatyId, sociatyTask.Uid, map[string]interface{}{"activityList": sociatyTask.ActivityList}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), SociatySubTypeActivityReceive, &pb.SociatyActivityReceiveResp{
|
|
Id: req.Id,
|
|
SociatyId: sociaty.Id,
|
|
Reward: atno,
|
|
})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "SociatyActivityReceiveReq", atno)
|
|
})
|
|
return
|
|
}
|