package practice import ( "context" "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/sys/db" "time" "go.mongodb.org/mongo-driver/bson/primitive" ) /* 模块名:熊猫武馆 练功子系统 描述:熊猫武馆 主系统 打桩 以及武馆相关数据管理 开发:李伟 */ var _ comm.IPractice = (*Practice)(nil) func NewModule() core.IModule { m := new(Practice) return m } type Practice struct { modules.ModuleBase service base.IRPCXService pvp comm.IPvp mail comm.Imail atlas comm.IPandaAtlas arena comm.IArena battle comm.IBattle sociaty comm.ISociaty api *apiComp configure *configureComp modelPandata *modelPandata } // 模块名 func (this *Practice) GetType() core.M_Modules { return comm.ModulePractice } // 模块初始化接口 注册用户创建角色事件 func (this *Practice) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { if err = this.ModuleBase.Init(service, module, options); err != nil { return } this.service = service.(base.IRPCXService) return } func (this *Practice) Start() (err error) { if err = this.ModuleBase.Start(); err != nil { return } var module core.IModule if module, err = this.service.GetModule(comm.ModulePvp); err != nil { return } this.pvp = module.(comm.IPvp) if module, err = this.service.GetModule(comm.ModuleMail); err != nil { return } this.mail = module.(comm.Imail) if module, err = this.service.GetModule(comm.ModulePandaAtlas); err != nil { return } this.atlas = module.(comm.IPandaAtlas) if module, err = this.service.GetModule(comm.ModuleArena); err != nil { return } this.arena = module.(comm.IArena) if module, err = this.service.GetModule(comm.ModuleBattle); err != nil { return } this.battle = module.(comm.IBattle) if module, err = this.service.GetModule(comm.ModuleSociaty); err != nil { return } this.sociaty = module.(comm.ISociaty) this.service.RegisterFunctionName(string(comm.RPC_ModulePracticeUnLockPillar), this.RPC_ModulePracticeUnLockPillar) return } // 装备组件 func (this *Practice) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) this.modelPandata = this.RegisterComp(new(modelPandata)).(*modelPandata) } // 添加武馆资源 func (this *Practice) AddItems(session comm.IUserSession, items map[string]int32, bPush bool) (errdata *pb.ErrorData) { var ( err error conn *db.DBConn room *pb.DBPracticeRoom id []string ) if this.IsCross() { if room, err = this.modelPandata.queryUserMartialhall(session.GetUserId()); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } id = make([]string, 0) for k, _ := range items { room.Knapsack[k] = &pb.DBPracticeRes{ Pid: k, State: 0, Usenum: 0, Lastusetime: 0, } id = append(id, k) this.atlas.CheckActivatePandaAtlasCollect(session.GetUserId(), k) } this.modelPandata.Change(session.GetUserId(), map[string]interface{}{ "knapsack": room.Knapsack, }) } else { room := &pb.DBPracticeRoom{ Full: make(map[int32]int32), Knapsack: make(map[string]*pb.DBPracticeRes), } conn, err = db.Cross() if err != nil { this.Errorln(err) return } model := db.NewDBModel(db.CrossTag(), comm.TablePandata, conn) if err = model.Get(session.GetUserId(), room); err != nil && err != mgo.MongodbNil { this.Errorln(err) return } if err == mgo.MongodbNil { room = &pb.DBPracticeRoom{ Id: primitive.NewObjectID().Hex(), Uid: session.GetUserId(), Full: make(map[int32]int32), Knapsack: make(map[string]*pb.DBPracticeRes), Gymaction: 0, Gymrefresh: 0, Pillar1: &pb.DBPracticePillar{Index: 1, Isunlock: 0, Lv: 1}, Pillar2: &pb.DBPracticePillar{Index: 2, Lv: 1}, Pillar3: &pb.DBPracticePillar{Index: 3, Lv: 1}, Pillarf: &pb.DBPracticePillar{Index: 4, Isunlock: 0, Lv: 1}, Statuers: make([]*pb.DBPracticeStatuer, 0), Npcstate: -1, Refresh: configure.Now().Unix(), } id = make([]string, 0) for k, _ := range items { room.Knapsack[k] = &pb.DBPracticeRes{ Pid: k, State: 0, Usenum: 0, Lastusetime: 0, } id = append(id, k) this.atlas.CheckActivatePandaAtlasCollect(session.GetUserId(), k) } if err = model.Add(session.GetUserId(), room); err != nil { this.Errorln(err) return } } else { id = make([]string, 0) for k, _ := range items { room.Knapsack[k] = &pb.DBPracticeRes{ Pid: k, State: 0, Usenum: 0, Lastusetime: 0, } id = append(id, k) this.atlas.CheckActivatePandaAtlasCollect(session.GetUserId(), k) } model.Change(session.GetUserId(), map[string]interface{}{ "knapsack": room.Knapsack, }) } } session.SendMsg(string(this.GetType()), "jxitem", &pb.PracticeJXItemPush{Id: id}) return } // 完成世界任务 func (this *Practice) TaskComplete(session comm.IUserSession, taskid ...int32) { this.Debug("TaskComplete", log.Field{Key: "session", Value: session.GetUserId()}, log.Field{Key: "taskid", Value: taskid}, ) } func (this *Practice) OpenCmdNotice(session comm.IUserSession, keys ...string) { this.Debug("OpenCmdNotice", log.Field{Key: "session", Value: session.GetUserId()}, log.Field{Key: "key", Value: keys}, ) if !this.IsCross() { for _, v := range keys { if v == "practice_ pillar1" || v == "practice_ pillar2" || v == "practice_ pillar3" { err := this.service.AcrossClusterRpcCall(context.Background(), this.GetCrossTag(), comm.Service_Worker, string(comm.RPC_ModulePracticeUnLockPillar), &pb.RPCGeneralReqA2{Param1: session.GetUserId(), Param2: v}, &pb.EmptyResp{}) if err != nil { this.Errorln(err) return } } } } else { for _, v := range keys { if v == "practice_ pillar1" || v == "practice_ pillar2" || v == "practice_ pillar3" { this.RPC_ModulePracticeUnLockPillar(context.Background(), &pb.RPCGeneralReqA2{Param1: session.GetUserId(), Param2: v}, &pb.EmptyResp{}) } } } } func (this *Practice) ChallengeResults(bid, red, bule string, winSide int32) { this.Debug("ChallengeResults", log.Field{Key: "bid", Value: bid}, log.Field{Key: "red", Value: red}, log.Field{Key: "bule", Value: bule}, log.Field{Key: "winSide", Value: winSide}, ) var ( redroom *pb.DBPracticeRoom reduser *pb.DBUser redsociaty string buleroom *pb.DBPracticeRoom buleuser *pb.DBUser bulesociaty string keep bool err error ) if winSide == 0 { return } if reduser, err = this.ModuleUser.GetUser(red); err != nil { return } if buleuser, err = this.ModuleUser.GetUser(bule); err != nil { return } if redroom, err = this.modelPandata.queryUserMartialhall(red); err != nil { this.Errorln(err) return } if buleroom, err = this.modelPandata.queryUserMartialhall(bule); err != nil { this.Errorln(err) return } if rsociaty := this.sociaty.GetSociaty(red); rsociaty != nil { redsociaty = rsociaty.Name } if bsociaty := this.sociaty.GetSociaty(bule); bsociaty != nil { bulesociaty = bsociaty.Name } if winSide == 1 { //红方胜利 keep = false for _, v := range buleroom.Statuers { if v.Uid == red { v.Unionname = redsociaty v.Figure = reduser.Figure v.End = configure.Now().Add(time.Minute * time.Duration(this.ModuleTools.GetGlobalConf().PandamasTiguandiaoxiangCd)).Unix() keep = true break } } if !keep { buleroom.Statuers = append(buleroom.Statuers, &pb.DBPracticeStatuer{ Uid: red, Name: reduser.Name, Unionname: redsociaty, Figure: reduser.Figure, Sex: reduser.Gender, Skin: reduser.CurSkin, End: configure.Now().Add(time.Minute * time.Duration(this.ModuleTools.GetGlobalConf().PandamasTiguandiaoxiangCd)).Unix(), }) } for i, v := range redroom.Statuers { if v.Uid == bule { //移除雕像 redroom.Statuers = append(redroom.Statuers[0:i], redroom.Statuers[i+1:]...) break } } } else { keep = false for _, v := range redroom.Statuers { if v.Uid == bule { v.Unionname = bulesociaty v.Figure = buleuser.Figure v.End = configure.Now().Add(time.Minute * time.Duration(this.ModuleTools.GetGlobalConf().PandamasTiguandiaoxiangCd)).Unix() keep = true break } } if !keep { redroom.Statuers = append(redroom.Statuers, &pb.DBPracticeStatuer{ Uid: bule, Name: buleuser.Name, Unionname: bulesociaty, Figure: buleuser.Figure, Sex: reduser.Gender, Skin: reduser.CurSkin, End: configure.Now().Add(time.Minute * time.Duration(this.ModuleTools.GetGlobalConf().PandamasTiguandiaoxiangCd)).Unix(), }) } for i, v := range buleroom.Statuers { if v.Uid == red { //移除雕像 buleroom.Statuers = append(buleroom.Statuers[0:i], buleroom.Statuers[i+1:]...) break } } } this.modelPandata.Change(red, map[string]interface{}{ "statuers": redroom.Statuers, }) this.modelPandata.Change(bule, map[string]interface{}{ "statuers": buleroom.Statuers, }) } // 解锁武馆柱子 func (this *Practice) RPC_ModulePracticeUnLockPillar(ctx context.Context, args *pb.RPCGeneralReqA2, reply *pb.EmptyResp) (err error) { this.Debug("RPC_ModulePracticeUnLockPillar", log.Field{Key: "uid", Value: args.Param1}, log.Field{Key: "key", Value: args.Param2}, ) var ( room *pb.DBPracticeRoom ) if room, err = this.modelPandata.queryUserMartialhall(args.Param1); err != nil { this.Errorln(err) return } switch args.Param2 { case "practice_ pillar1": room.Pillar1.Isunlock = 2 if room.Pillarf.Isunlock == 0 { room.Pillarf.Isunlock = 2 } this.modelPandata.Change(args.Param1, map[string]interface{}{ "pillar1": room.Pillar1, "pillarf": room.Pillarf, }) this.atlas.CheckActivatePandaAtlasCollect(args.Param1, "100001") break case "practice_ pillar2": room.Pillar2.Isunlock = 2 if room.Pillarf.Isunlock == 0 { room.Pillarf.Isunlock = 2 } this.modelPandata.Change(args.Param1, map[string]interface{}{ "pillar2": room.Pillar2, "pillarf": room.Pillarf, }) this.atlas.CheckActivatePandaAtlasCollect(args.Param1, "100001") break case "practice_ pillar3": room.Pillar3.Isunlock = 2 if room.Pillarf.Isunlock == 0 { room.Pillarf.Isunlock = 2 } this.modelPandata.Change(args.Param1, map[string]interface{}{ "pillar3": room.Pillar3, "pillarf": room.Pillarf, }) this.atlas.CheckActivatePandaAtlasCollect(args.Param1, "100001") break default: return } _session, _ := this.GetUserSession(args.Param1) go this.AsynHandleSession(_session, func(session comm.IUserSession) { this.ModuleBuried.TriggerBuried(_session, comm.GetBuriedParam(comm.Rtype152, 1)) }) return } // 一键踢馆 (跨服) func (this *Practice) CleanUpNpc(uid string) { conn_, _ := db.Cross() // 获取跨服数据库对象 model := db.NewDBModel(db.CrossTag(), comm.TablePandata, conn_) result := &pb.DBPracticeRoom{} if err := model.Get(uid, result); err != nil && err != mgo.MongodbNil { return } result.Refresh = configure.Now().Unix() model.Change(uid, map[string]interface{}{ // 同步状态即可 "npcstate": 3, "refresh": result.Refresh, }) } func (this *Practice) GetAllJxRes() (res []string, err error) { return this.configure.getAllGamePandamasJx() } // 红点 func (this *Practice) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]*pb.ReddotItem) { var ( model *pandataModel room *pb.DBPracticeRoom pconf *cfg.GamePandamasMzData userex *pb.DBUserExpand usenum int32 totalusenum int32 err error ) reddot = make(map[comm.ReddotType]*pb.ReddotItem) if model, err = this.modelPandata.getpandataModel(); err != nil { this.Errorln(err) return } if room, err = model.queryUserMartialhall(session.GetUserId()); err != nil { this.Errorln(err) return } if room.Pillar1.Isunlock == 2 { usenum += room.Pillar1.Usenum if pconf, err = this.configure.getGamePandamasMz(room.Pillar1.Lv); err == nil { totalusenum += pconf.Limitation } } if room.Pillar2.Isunlock == 2 { usenum += room.Pillar2.Usenum if pconf, err = this.configure.getGamePandamasMz(room.Pillar2.Lv); err == nil { totalusenum += pconf.Limitation } } if room.Pillar3.Isunlock == 2 { usenum += room.Pillar3.Usenum if pconf, err = this.configure.getGamePandamasMz(room.Pillar3.Lv); err == nil { totalusenum += pconf.Limitation } } for _, v := range rid { switch v { case comm.Reddot18106: if userex, err = this.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { this.Errorln(err) return } reddot[comm.Reddot18106] = &pb.ReddotItem{ Rid: int32(comm.Reddot18106), Activated: true, Progress: room.Gymrefresh, Total: 1, } if userex.Globalbuff == 0 { reddot[comm.Reddot18106].Progress = 0 } else { reddot[comm.Reddot18106].Progress = 1 } break case comm.Reddot18111: if totalusenum > 0 { reddot[comm.Reddot18111] = &pb.ReddotItem{ Rid: int32(comm.Reddot18111), Activated: true, Progress: usenum, Total: totalusenum, } } else { reddot[comm.Reddot18111] = &pb.ReddotItem{ Rid: int32(comm.Reddot18111), Activated: false, } } break } } return }