141 lines
3.7 KiB
Go
141 lines
3.7 KiB
Go
package capturesheep
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) OverCheck(session comm.IUserSession, req *pb.CapturesheepOverReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /获取自己的排行榜信息
|
|
func (this *apiComp) Over(session comm.IUserSession, req *pb.CapturesheepOverReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
redScores, blueScores int32
|
|
info *pb.DBCaptureSheep
|
|
lvconf *cfg.GameBuzkashiLvData
|
|
conf *cfg.GameQualifyingData
|
|
isred bool
|
|
iswin bool
|
|
awards []*cfg.Gameatn
|
|
award []*pb.UserAtno
|
|
err error
|
|
)
|
|
|
|
if errdata = this.OverCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if info, err = this.module.modelCaptureSheep.queryInfo(session.GetUserId()); err != nil && err != mgo.MongodbNil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.getActiveRewardById(info.Dan); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if lvconf, err = this.module.configure.getGameBuzkashiLv(req.Rating); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
for _, v := range req.Race.Redmember {
|
|
redScores += v.Scores
|
|
if v.Uid == session.GetUserId() {
|
|
isred = true
|
|
}
|
|
}
|
|
for _, v := range req.Race.Bulemember {
|
|
blueScores += v.Scores
|
|
if v.Uid == session.GetUserId() {
|
|
isred = true
|
|
}
|
|
}
|
|
|
|
if redScores > blueScores && isred { //红方胜利
|
|
info.Integral += conf.WinValue
|
|
iswin = true
|
|
if req.Race.Rtype == pb.CaptureSheepRaceType_train {
|
|
awards = conf.MatewinReward
|
|
} else {
|
|
awards = conf.RankwinReward
|
|
}
|
|
|
|
} else if redScores < blueScores && !isred {
|
|
info.Integral += conf.WinValue
|
|
iswin = true
|
|
if req.Race.Rtype == pb.CaptureSheepRaceType_train {
|
|
awards = conf.MatewinReward
|
|
} else {
|
|
awards = conf.RankwinReward
|
|
}
|
|
} else {
|
|
info.Integral += conf.FailValue
|
|
info.Integral += conf.FailValue
|
|
if req.Race.Rtype == pb.CaptureSheepRaceType_train {
|
|
awards = conf.MatefailReward
|
|
} else {
|
|
awards = conf.RankfailReward
|
|
}
|
|
}
|
|
|
|
if info.Dan, err = this.module.modelCaptureSheep.computedan(info.Integral); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if errdata, award = this.module.DispenseAtno(session, awards, true); errdata != nil {
|
|
return
|
|
}
|
|
info.Weekintegral += lvconf.Point
|
|
info.Weektime = configure.Now().Unix()
|
|
if err = this.module.modelCaptureSheep.Change(session.GetUserId(), map[string]interface{}{
|
|
"integral": info.Integral,
|
|
"dan": info.Dan,
|
|
"weekintegral": info.Weekintegral,
|
|
"weektime": info.Weektime,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "over", &pb.CapturesheepOverResp{
|
|
Iswin: iswin,
|
|
Integral: info.Integral,
|
|
Weekintegral: info.Weekintegral,
|
|
Dan: info.Dan,
|
|
Award: award,
|
|
})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "CapturesheepOverReq", award)
|
|
})
|
|
return
|
|
}
|