113 lines
3.1 KiB
Go
113 lines
3.1 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 签到
|
|
func (this *apiComp) SignCheck(session comm.IUserSession, req *pb.SociatySignReq) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Sign(session comm.IUserSession, req *pb.SociatySignReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
atnotemp []*pb.UserAtno
|
|
atno []*pb.UserAtno
|
|
)
|
|
|
|
if errdata = this.SignCheck(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
|
|
}
|
|
|
|
// 不是该公会成员
|
|
if !this.module.modelSociaty.isMember(uid, sociaty) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatyNoAdded,
|
|
Title: pb.ErrorCode_SociatyNoAdded.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
// 判断是否已签到
|
|
if this.module.modelSociaty.IsSign(uid, sociaty) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatySigned,
|
|
Title: pb.ErrorCode_SociatySigned.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
// 签到
|
|
if err := this.module.modelSociaty.sign(uid, sociaty); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatySign,
|
|
Title: pb.ErrorCode_SociatySign.ToString(),
|
|
}
|
|
this.module.Error("签到失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "sociatyId", Value: sociaty.Id}, log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
|
|
// 发奖
|
|
lastSignCount := sociaty.LastSignCount
|
|
var signCfgId int32 //签到配置ID
|
|
for _, v := range this.module.sociatySignConf.GetDataList() {
|
|
if lastSignCount >= v.Down && lastSignCount < v.Up {
|
|
// 发放签到奖励
|
|
if errdata, atnotemp = this.module.DispenseAtno(session, v.Reward, true); errdata != nil {
|
|
return
|
|
}
|
|
atno = append(atno, atnotemp...)
|
|
signCfgId = v.Id
|
|
break
|
|
}
|
|
}
|
|
|
|
if cfg, ok := this.module.sociatySignConf.GetDataMap()[signCfgId]; ok {
|
|
// 更新公会经验
|
|
if cfg.Exp.T == "guildexp" {
|
|
update := map[string]interface{}{}
|
|
this.module.modelSociaty.updateSociatyExp(cfg.Exp.N, sociaty, update)
|
|
// 更新等级
|
|
if changelv, err := this.module.modelSociaty.changeLv(sociaty, update); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
} else if changelv {
|
|
this.module.modelSociaty.EventApp.Dispatch(comm.EventSociatyRankChanged, &SociatyListen{
|
|
sociaty: sociaty,
|
|
})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.ModuleSys.CheckOpenCond(session.Clone(), comm.OpencondTypeWorldtaskid, sociaty.Lv)
|
|
})
|
|
}
|
|
if err := this.module.modelSociaty.updateSociaty(sociaty.Id, update); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
rsp := &pb.SociatySignResp{
|
|
Uid: uid,
|
|
SociatyId: sociaty.Id,
|
|
Reward: atno,
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), SociatySubTypeSign, rsp)
|
|
return
|
|
}
|