71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package monkey
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
func (this *apiComp) AwardCheck(session comm.IUserSession, req *pb.MonkeyAwardReq) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Award(session comm.IUserSession, req *pb.MonkeyAwardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
err error
|
|
info *pb.DBMonkey
|
|
conf []*cfg.GameMonkeyRewardData
|
|
res []*cfg.Gameatn
|
|
atno []*pb.UserAtno
|
|
)
|
|
if errdata = this.AwardCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if info, err = this.module.model.getMonkeyData(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if info.Reward[req.ChapterId] >= req.Starnum { // 重复领取
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_UserRepeadReward,
|
|
Title: pb.ErrorCode_UserRepeadReward.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.getGameMonkeyRewardData(req.ChapterId); err != nil {
|
|
for _, v := range conf {
|
|
if v.Starnum > info.Reward[req.ChapterId] && v.Starnum <= req.Starnum {
|
|
res = append(res, v.Reward...)
|
|
}
|
|
}
|
|
}
|
|
if len(res) > 0 {
|
|
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil {
|
|
return
|
|
}
|
|
if err = this.module.model.changeMonkeyData(session.GetUserId(), map[string]interface{}{ // 更新
|
|
"reward": info.Reward,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "award", &pb.MonkeyAwardResp{
|
|
Data: info,
|
|
Award: atno,
|
|
})
|
|
|
|
return
|
|
}
|