101 lines
2.8 KiB
Go
101 lines
2.8 KiB
Go
package moonlv
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) AwardCheck(session comm.IUserSession, req *pb.MoonlvAwardReq) (errdata *pb.ErrorData) {
|
|
if req.Lv == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 领取等级奖励
|
|
func (this *apiComp) Award(session comm.IUserSession, req *pb.MoonlvAwardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameMoonLvData
|
|
tconfs []*cfg.GameMoonTaskData
|
|
update map[string]interface{}
|
|
atno []*pb.UserAtno
|
|
)
|
|
update = make(map[string]interface{}, 0)
|
|
list, err := this.module.modelMoonlv.getMoonlvList(session)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.GetMoonLvConf(list.Lv); err == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
if tconfs, err = this.module.configure.GetMoonLvTaskConf(conf.TaskGroupId); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range tconfs {
|
|
if _, ok := list.Tasks[v.TaskId]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_TaskRepeatedReward,
|
|
Title: pb.ErrorCode_TaskRepeatedReward.ToString(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
if _, ok := list.Reward[req.Lv]; ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_TaskRepeatedReward,
|
|
Title: pb.ErrorCode_TaskRepeatedReward.ToString(),
|
|
}
|
|
return
|
|
}
|
|
list.Reward[req.Lv] = true
|
|
if _, err = this.module.configure.GetMoonLvConf(list.Lv + 1); err == nil { // 查看能不能继续升级
|
|
list.Lv += 1
|
|
update["lv"] = list.Lv
|
|
if errdata = this.module.ModuleUser.ChangeUserMoonLv(session, list.Lv); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
update["reward"] = list.Reward
|
|
if err := this.module.modelMoonlv.modifyMoonlvList(session.GetUserId(), update); err != nil {
|
|
this.module.Error(err.Error())
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if errdata, atno = this.module.DispenseAtno(session, conf.Reward, true); errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "award", &pb.MoonlvAwardResp{
|
|
Data: list,
|
|
Res: atno,
|
|
})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
// this.module.ModuleSys.CheckOpenCond(session.Clone(), comm.OpencondTypeMoonLv, list.Lv)
|
|
this.module.ModuleBuried.TriggerBuried(session, comm.GetBuriedParam(comm.Rtype242, list.Lv))
|
|
})
|
|
return
|
|
}
|