70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package caninerabbit
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
func (this *apiComp) AwardCheck(session comm.IUserSession, req *pb.CanineRabbitAwardReq) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Award(session comm.IUserSession, req *pb.CanineRabbitAwardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
confs []*cfg.GameCatchrabbitData
|
|
info *pb.DBCanineRabbit
|
|
res []*cfg.Gameatn
|
|
atno []*pb.UserAtno
|
|
ok bool
|
|
err error
|
|
)
|
|
if errdata = this.AwardCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if confs, err = this.module.configure.getGameGColorRewardDatas(req.Type + 1); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if info, err = this.module.model.getModel(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if req.Type == 0 { //兔子
|
|
for _, v := range confs {
|
|
if _, ok = info.Award[v.Key]; !ok && info.Rabbitintegral >= v.Condition {
|
|
res = append(res, v.Reward...)
|
|
info.Award[v.Key] = true
|
|
}
|
|
}
|
|
} else {
|
|
for _, v := range confs {
|
|
if _, ok = info.Award[v.Key]; !ok && info.Houndintegral >= v.Condition {
|
|
res = append(res, v.Reward...)
|
|
info.Award[v.Key] = true
|
|
}
|
|
}
|
|
}
|
|
|
|
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil {
|
|
return
|
|
}
|
|
this.module.model.Change(session.GetUserId(), map[string]interface{}{
|
|
"award": info.Award,
|
|
})
|
|
session.SendMsg(string(this.module.GetType()), "award", &pb.CanineRabbitAwardResp{Type: req.Type, Awardmap: info.Award, Award: atno})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "CanineRabbitAwardReq", res)
|
|
})
|
|
return
|
|
}
|