package guildgve import ( "context" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) func NewModule() core.IModule { m := new(GuildGve) return m } type GuildGve struct { modules.ModuleBase service comm.IService sociaty comm.ISociaty mail comm.Imail battle comm.IBattle battlerecord comm.IBattleRecord api *apiComp modelGuildGve *ModelUniongve modelUnionroulette *ModelUnionroulette modelGuildMember *ModelGuildMember modelbattlerank *Modelbattlerank modelRank *modelRank configure *MCompConfigure } // 模块名 func (this *GuildGve) GetType() core.M_Modules { return comm.ModuleGuildGve } // 模块初始化接口 注册用户创建角色事件 func (this *GuildGve) 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.(comm.IService) return } func (this *GuildGve) Start() (err error) { if err = this.ModuleBase.Start(); err != nil { return } var module core.IModule if module, err = this.service.GetModule(comm.ModuleSociaty); err != nil { return } this.sociaty = module.(comm.ISociaty) if module, err = this.service.GetModule(comm.ModuleMail); err != nil { return } this.mail = module.(comm.Imail) if module, err = this.service.GetModule(comm.ModuleBattle); err != nil { return } this.battle = module.(comm.IBattle) if module, err = this.service.GetModule(comm.ModuleBattleRecord); err != nil { return } this.battlerecord = module.(comm.IBattleRecord) this.service.RegisterFunctionName(string(comm.Rpc_ModuleGuildBossSettlement), this.Rpc_ModuleGuildBossSettlement) return } // 装备组件 func (this *GuildGve) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.configure = this.RegisterComp(new(MCompConfigure)).(*MCompConfigure) this.modelGuildGve = this.RegisterComp(new(ModelUniongve)).(*ModelUniongve) this.modelGuildMember = this.RegisterComp(new(ModelGuildMember)).(*ModelGuildMember) this.modelbattlerank = this.RegisterComp(new(Modelbattlerank)).(*Modelbattlerank) this.modelUnionroulette = this.RegisterComp(new(ModelUnionroulette)).(*ModelUnionroulette) this.modelRank = this.RegisterComp(new(modelRank)).(*modelRank) } // 工会Boos战结算通知 func (this *GuildGve) Rpc_ModuleGuildBossSettlement(ctx context.Context, req *pb.EmptyReq, resp interface{}) (err error) { this.Debug("Rpc_ModuleGuildBossSettlement 工会Boos战结算通知 !") this.modelRank.raceSettlement() return } // 红点 func (this *GuildGve) Reddot(session comm.IUserSession, rid map[comm.ReddotType]struct{}) (items map[comm.ReddotType]*pb.ReddotItem) { var ( selfrid []comm.ReddotType = []comm.ReddotType{comm.Reddot15301} ok bool member *pb.DBGuildMember err error ) items = make(map[comm.ReddotType]*pb.ReddotItem) for _, v := range selfrid { if _, ok = rid[v]; ok { break } } if ok { return } if member, err = this.modelGuildMember.inquireGuildMember(session.GetUserId()); err != nil { return } for _, v := range selfrid { if _, ok = rid[v]; ok { switch v { case comm.Reddot15301: items[comm.Reddot15301] = &pb.ReddotItem{ Rid: int32(comm.Reddot15301), Activated: true, Progress: member.Boosticket, } break } } } return } func (this *GuildGve) ModifyBooslv(session comm.IUserSession, lv int32) (errdata *pb.ErrorData) { var ( sociaty *pb.DBSociaty info *pb.DBGuildGve members []*pb.SociatyMemberInfo users []string = make([]string, 0) conf *cfg.GameGuildBossData model *guildgveModel err error ) if sociaty = this.ModuleSociaty.GetSociaty(session.GetUserId()); sociaty == nil { return } if model, err = this.modelGuildGve.guildgveModel(); err != nil { this.Error("guildgveModel err!", log.Field{Key: "Unionid", Value: sociaty.Id}, log.Field{Key: "err", Value: err.Error()}) return } lock, _ := model.userlock(sociaty.Id) err = lock.Lock() if err != nil { this.Error("公会战分布式锁 err!", log.Field{Key: "Unionid", Value: sociaty.Id}, log.Field{Key: "err", Value: err.Error()}) return } defer lock.Unlock() if info, err = model.getGuildGve(sociaty.Id); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } info.Currstage = lv for _, v := range info.Boos { if conf, err = this.configure.getguildbossByNext(v.Boosid, info.Currstage); err != nil { this.Errorln(err) return } v.Boosid = conf.BossId v.Hp = conf.Hp v.Record = make([]*pb.DBGveRecord, 0) } if err = model.updateGuildGve(info); err != nil { this.Errorln(err) return } if members, errdata = this.sociaty.MembersBySociatyId(sociaty.Id); errdata != nil { this.Debug("获取工会成员列表!", log.Field{Key: "errdata", Value: errdata}) return } for _, v := range members { users = append(users, v.Uinfo.Uid) } this.SendMsgToUsers(string(this.GetType()), "stagechange", &pb.GuildGveStageChangePush{ Info: info, }, users...) return }