103 lines
2.6 KiB
Go
103 lines
2.6 KiB
Go
package stonehenge
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) BookAwardCheck(session comm.IUserSession, req *pb.StonehengeBookAwardReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) BookAward(session comm.IUserSession, req *pb.StonehengeBookAwardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
info *pb.DBStonehengeBook
|
|
confs []*cfg.GameStoneIllustratedData
|
|
bookAward *pb.DBStonehengeBookAward
|
|
conf *cfg.GameStoneIllustratedData
|
|
award []*pb.UserAssets
|
|
ok bool
|
|
err error
|
|
atno []*pb.UserAtno
|
|
)
|
|
if errdata = this.BookAwardCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if info, err = this.module.modelStonehengeBook.getStonehengeBook(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.String(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if confs, err = this.module.configure.getGameStoneIllustratedDatas(); err == nil {
|
|
for _, v := range confs {
|
|
if v.Type == req.Btype && v.ColltectionNum == req.Stage {
|
|
conf = v
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
if conf == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.String(),
|
|
Message: "no found stage",
|
|
}
|
|
return
|
|
}
|
|
|
|
if bookAward, ok = info.Award[req.Btype]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.String(),
|
|
Message: "book is emtry",
|
|
}
|
|
return
|
|
}
|
|
|
|
if len(bookAward.Books) < int(conf.ColltectionNum) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.String(),
|
|
Message: "book is not enough",
|
|
}
|
|
return
|
|
}
|
|
bookAward.Stage[conf.ColltectionNum] = true
|
|
|
|
if errdata, atno = this.module.DispenseAtno(session, conf.Reward, true); errdata != nil {
|
|
return
|
|
}
|
|
award = make([]*pb.UserAssets, 0)
|
|
for _, v := range atno {
|
|
award = append(award, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
|
|
if err = this.module.modelStonehengeBook.Change(session.GetUserId(), map[string]interface{}{
|
|
"award": info.Award,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.String(),
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "bookaward", &pb.StonehengeBookAwardResp{Btype: req.Btype, Stage: req.Stage, Award: award})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "StonehengeBookAwardReq", atno)
|
|
})
|
|
return
|
|
}
|