From 56cd53a09c0ef44c7d0fb0c171b80bc798a6cb1d Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 25 Oct 2022 16:39:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/arena/api_info.go | 38 ++++++++++++++++++++++++++++++++++--- modules/arena/modelarena.go | 16 +++++----------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/modules/arena/api_info.go b/modules/arena/api_info.go index 5e3b61e3a..1101900c6 100644 --- a/modules/arena/api_info.go +++ b/modules/arena/api_info.go @@ -2,7 +2,11 @@ package arena import ( "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + "go_dreamfactory/sys/db" + "time" "google.golang.org/protobuf/proto" ) @@ -16,16 +20,44 @@ func (this *apiComp) InfoCheck(session comm.IUserSession, req *pb.ArenaInfoReq) ///获取自己的排行榜信息 func (this *apiComp) Info(session comm.IUserSession, req *pb.ArenaInfoReq) (code pb.ErrorCode, data proto.Message) { var ( - info *pb.DBArenaUser - err error + global *cfg.GameGlobalData + info *pb.DBArenaUser + user *pb.DBUser + model *db.DBModel + err error ) if code = this.InfoCheck(session, req); code != pb.ErrorCode_Success { return } - if info, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil { + if info, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil && err != mgo.MongodbNil { code = pb.ErrorCode_DBError return } + if err == mgo.MongodbNil { + global = this.module.configure.GetGlobalConf() + if model, err = this.module.GetDBNodule(session, comm.TableUser, time.Hour); err != nil { + code = pb.ErrorCode_DBError + this.module.Errorln(err) + return + } + user = &pb.DBUser{} + if err = model.Get(session.GetUserId(), user); err != nil { + code = pb.ErrorCode_DBError + this.module.Errorln(err) + return + } + info = &pb.DBArenaUser{ + Uid: session.GetUserId(), + Name: user.Name, + Integral: global.ArenaInitiaIntegral, + Ticket: 10, + Record: make([]*pb.DBArenaBattleRecord, 0), + } + if err = this.module.modelArena.Add(session.GetUserId(), info); err != nil { + this.module.Errorln(err) + } + } + session.SendMsg(string(this.module.GetType()), "info", &pb.ArenaInfoResp{Info: info}) return } diff --git a/modules/arena/modelarena.go b/modules/arena/modelarena.go index fa9863ef1..1b946f9c3 100644 --- a/modules/arena/modelarena.go +++ b/modules/arena/modelarena.go @@ -44,17 +44,6 @@ func (this *modelArena) queryPlayerInfo(uId string) (result *pb.DBArenaUser, err this.module.Errorln(err) return } - if err == mgo.MongodbNil { - result = &pb.DBArenaUser{ - Uid: uId, - Integral: 0, - Ticket: 10, - Record: make([]*pb.DBArenaBattleRecord, 0), - } - if err = this.Add(uId, result); err != nil { - this.module.Errorln(err) - } - } return } @@ -281,3 +270,8 @@ func (this *modelArena) getAI(mformatId int32) (ai *pb.ArenaPlayer, err error) { } return } + +//积分计算 +func (this *modelArena) integralCompute(red, bule *pb.ArenaPlayer, iswin bool) { + +}