From 1829a454fbcad8b745721337f47af549801c8542 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Thu, 8 Dec 2022 18:05:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=85=AC=E4=BC=9Abingo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 2 ++ modules/gm/module.go | 8 ++--- modules/sociaty/model_sociaty.go | 21 +++++++++-- modules/sociaty/module.go | 60 +++++++++++++++++++++++++++++--- 4 files changed, 80 insertions(+), 11 deletions(-) diff --git a/comm/const.go b/comm/const.go index df91ddb2f..18d3f397c 100644 --- a/comm/const.go +++ b/comm/const.go @@ -242,6 +242,8 @@ const ( //Rpc Rpc_ModuleSeasonPagodaReward core.Rpc_Key = "Rpc_ModuleSeasonPagodaReward" // 公会信息 Rpc_ModuleSociaty core.Rpc_Key = "Rpc_ModuleSociaty" + // 公会更新 + Rpc_ModuleSociatyUpdate core.Rpc_Key = "Rpc_ModuleSociatyUpdate" ) //事件类型定义处 diff --git a/modules/gm/module.go b/modules/gm/module.go index d57a15b8d..b3b7c01d4 100644 --- a/modules/gm/module.go +++ b/modules/gm/module.go @@ -207,7 +207,7 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC } module1.(comm.IMoonFantasy).TriggerMF(session, datas[1]) - this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) + this.Debug("使用bingo命令", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) } else if len(datas) == 2 && (datas[0] == "arena") { // 设置竞技场用户积分 module1, err := this.service.GetModule(comm.ModuleArena) if err != nil { @@ -219,7 +219,7 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC return } module1.(comm.IArena).SetUserIntegral(session, int32(num)) - this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) + this.Debug("使用bingo命令", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) } else if len(datas) == 2 && (datas[0] == "sociatyexp") { // 设置工会经验 module1, err := this.service.GetModule(comm.ModuleSociaty) if err != nil { @@ -231,7 +231,7 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC return } module1.(comm.ISociaty).BingoSetExp(session, int32(num)) - this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) + this.Debug("使用bingo命令", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) } else if len(datas) == 2 && (datas[0] == "sociatyactivity") { // 设置工会活跃度 module1, err := this.service.GetModule(comm.ModuleSociaty) if err != nil { @@ -243,7 +243,7 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC return } module1.(comm.ISociaty).BingoSetActivity(session, int32(num)) - this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) + this.Debug("使用bingo命令", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) } } diff --git a/modules/sociaty/model_sociaty.go b/modules/sociaty/model_sociaty.go index fb0b47de8..344183051 100644 --- a/modules/sociaty/model_sociaty.go +++ b/modules/sociaty/model_sociaty.go @@ -328,9 +328,26 @@ func (this *ModelSociaty) isRight(uid string, sociaty *pb.DBSociaty, jobs ...pb. return false } -// 更新公会 +// 更新公会经验 func (this *ModelSociaty) updateSociaty(sociatyId string, update map[string]interface{}) error { - return this.ChangeList("", sociatyId, update) + if this.moduleSociaty.IsCross() { + return this.ChangeList(comm.RDS_EMPTY, sociatyId, update) + } else { + req := &SociatyUpdateParam{ + SociatyId: sociatyId, + Update: update, + } + if err := this.moduleSociaty.service.AcrossClusterRpcCall( + context.Background(), + this.moduleSociaty.GetCrossTag(), + comm.Service_Worker, + string(comm.Rpc_ModuleSociatyUpdate), + req, + &pb.EmptyResp{}); err != nil { + this.moduleSociaty.Errorln(err) + } + } + return nil } // 退出公会 diff --git a/modules/sociaty/module.go b/modules/sociaty/module.go index 180ec8f10..696b478c6 100644 --- a/modules/sociaty/module.go +++ b/modules/sociaty/module.go @@ -59,6 +59,7 @@ func (this *Sociaty) OnInstallComp() { func (this *Sociaty) Start() (err error) { err = this.ModuleBase.Start() this.service.RegisterFunctionName(string(comm.Rpc_ModuleSociaty), this.RpcGetSociaty) + this.service.RegisterFunctionName(string(comm.Rpc_ModuleSociatyUpdate), this.RpcUpdateSociaty) this.globalConf = this.configure.GetGlobalConf() if this.globalConf == nil { err = errors.New("global config not found") @@ -156,17 +157,66 @@ func (this *Sociaty) Reddot(session comm.IUserSession, rid ...comm.ReddotType) ( func (this *Sociaty) RpcGetSociaty(ctx context.Context, req *pb.RPCGeneralReqA1, reply *pb.DBSociaty) error { this.Debug("Rpc_ModuleSociaty", log.Fields{"req": req}) sociaty := this.modelSociaty.getSociaty(req.Param1) - *reply = *sociaty - log.Debug("跨服公会", log.Fields{"sociaty": reply}) + reply.Id = sociaty.Id + reply.Lv = sociaty.Lv + reply.Exp = sociaty.Exp + reply.Members = sociaty.Members + reply.DismissCD = sociaty.DismissCD + reply.Name = sociaty.Name + reply.Icon = sociaty.Icon + reply.Notice = sociaty.Notice + reply.DismissTime = sociaty.DismissTime + reply.IsApplyCheck = sociaty.IsApplyCheck + reply.SignIds = sociaty.SignIds + reply.LastSignCount = sociaty.LastSignCount + reply.ApplyLv = sociaty.ApplyLv + reply.Activity = sociaty.Activity + reply.AccuseTime = sociaty.AccuseTime + reply.ApplyRecord = sociaty.ApplyRecord return nil } +type SociatyUpdateParam struct { + SociatyId string + Update map[string]interface{} +} + +//跨服更新数据 +func (this *Sociaty) RpcUpdateSociaty(ctx context.Context, req *SociatyUpdateParam, reply *pb.DBSociaty) error { + return this.modelSociaty.ChangeList(comm.RDS_EMPTY, req.SociatyId, req.Update) +} + // 设置工会经验 func (this *Sociaty) BingoSetExp(session comm.IUserSession, exp int32) error { - return nil + sociaty := this.modelSociaty.getUserSociaty(session.GetUserId()) + if sociaty == nil || sociaty.Id == "" { + log.Warn("未获得公会信息", log.Fields{"uid": session.GetUserId()}) + return comm.NewCustomError(pb.ErrorCode_SociatyNoFound) + } + sociaty.Exp += exp + update := map[string]interface{}{ + "exp": sociaty.Exp, + } + + err := this.modelSociaty.updateSociaty(sociaty.Id, update) + if err != nil { + return err + } + + return this.modelSociaty.changeLv(sociaty) } -// 设置工会经验 +// 设置工会活跃度 func (this *Sociaty) BingoSetActivity(session comm.IUserSession, activity int32) error { - return nil + sociaty := this.modelSociaty.getUserSociaty(session.GetUserId()) + if sociaty == nil || sociaty.Id == "" { + log.Warn("未获得公会信息", log.Fields{"uid": session.GetUserId()}) + return comm.NewCustomError(pb.ErrorCode_SociatyNoFound) + } + + activity += sociaty.Activity + update := map[string]interface{}{ + "activity": activity, + } + return this.modelSociaty.updateSociaty(sociaty.Id, update) }