95 lines
2.4 KiB
Go
95 lines
2.4 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
|
|
//totalstar int32 //
|
|
)
|
|
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 _, ok := info.Data[req.ChapterId]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_UserRepeadReward,
|
|
Title: pb.ErrorCode_UserRepeadReward.ToString(),
|
|
}
|
|
return
|
|
}
|
|
// for _, v := range info.Data[req.ChapterId].Award {
|
|
// totalstar += v
|
|
// }
|
|
// if totalstar < req.Starnum { // 星级不够 不能领奖
|
|
// errdata = &pb.ErrorData{
|
|
// Code: pb.ErrorCode_UserNoReward,
|
|
// Title: pb.ErrorCode_UserNoReward.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
|
|
}
|
|
info.Reward[req.ChapterId] = req.Starnum
|
|
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
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_UserNoReward,
|
|
Title: pb.ErrorCode_UserNoReward.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "award", &pb.MonkeyAwardResp{
|
|
|
|
Award: atno,
|
|
})
|
|
|
|
return
|
|
}
|