package arena import ( "context" "fmt" "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" cfg "go_dreamfactory/sys/configure/structs" ) var _ comm.IArena = (*Arena)(nil) const moduleName = "竞技场" /* 模块名:竞技场 描述:pvp相关业务 开发:李伟 */ func NewModule() core.IModule { m := new(Arena) return m } type Arena struct { modules.ModuleBase service base.IRPCXService mail comm.Imail battle comm.IBattle privilege comm.IPrivilege api *apiComp configure *configureComp modelArena *modelArena modelRank *modelRank } // 模块名 func (this *Arena) GetType() core.M_Modules { return comm.ModuleArena } // 模块初始化接口 注册用户创建角色事件 func (this *Arena) 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 *Arena) Start() (err error) { if err = this.ModuleBase.Start(); err != nil { return } var module core.IModule if module, err = this.service.GetModule(comm.ModuleBattle); err != nil { return } this.battle = module.(comm.IBattle) if module, err = this.service.GetModule(comm.ModuleMail); err != nil { return } this.mail = module.(comm.Imail) if module, err = this.service.GetModule(comm.ModulePrivilege); err != nil { return } this.privilege = module.(comm.IPrivilege) this.service.RegisterFunctionName(string(comm.Rpc_ModuleArenaRaceSettlement), this.Rpc_ModuleArenaRaceSettlement) this.service.RegisterFunctionName(string(comm.Rpc_ModuleArenaModifyIntegral), this.Rpc_ModuleArenaModifyIntegral) return } // 装备组件 func (this *Arena) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) this.modelArena = this.RegisterComp(new(modelArena)).(*modelArena) this.modelRank = this.RegisterComp(new(modelRank)).(*modelRank) } // 比赛结算 func (this *Arena) Rpc_ModuleArenaRaceSettlement(ctx context.Context, args *pb.EmptyReq, reply *pb.EmptyResp) (err error) { this.Debug("Rpc_ModuleArenaRaceSettlement", log.Field{Key: "args", Value: args.String()}, ) this.modelRank.raceSettlement() return } // 修改用户积分 func (this *Arena) Rpc_ModuleArenaModifyIntegral(ctx context.Context, args *pb.RPCModifyIntegralReq, reply *pb.EmptyResp) (err error) { this.Debug("Rpc_ModuleArenaModifyIntegral", log.Field{Key: "args", Value: args.String()}) err = this.modelArena.modifyIntegral(args.Uid, args.Integral) return } // 红点需求 func (this *Arena) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (result map[comm.ReddotType]*pb.ReddotItem) { var ( model *arenaModel info *pb.DBArenaUser = &pb.DBArenaUser{} activated bool ticket int32 err error ) result = make(map[comm.ReddotType]*pb.ReddotItem) if model, err = this.modelArena.getpandataModel(); err != nil { this.Errorln(err) result[comm.Reddot22100] = &pb.ReddotItem{ Rid: int32(comm.Reddot22100), Activated: false, } result[comm.Reddot22102] = &pb.ReddotItem{ Rid: int32(comm.Reddot22102), Activated: false, } result[comm.Reddot22202] = &pb.ReddotItem{ Rid: int32(comm.Reddot22202), Activated: false, } return } if info, ticket, activated = model.reddot(session); info == nil { return } result = make(map[comm.ReddotType]*pb.ReddotItem) for _, v := range rid { switch v { case comm.Reddot22100: result[comm.Reddot22100] = &pb.ReddotItem{ Rid: int32(comm.Reddot22100), } if ticket == this.ModuleTools.GetGlobalConf().ArenaTicketCos.N { result[comm.Reddot22100].Activated = true } break case comm.Reddot22102: result[comm.Reddot22102] = &pb.ReddotItem{ Rid: int32(comm.Reddot22102), } result[comm.Reddot22102].Activated = activated break case comm.Reddot22202: result[comm.Reddot22202] = &pb.ReddotItem{ Rid: int32(comm.Reddot22202), Activated: true, Progress: ticket, } break } } return } func (this *Arena) SetUserIntegral(session comm.IUserSession, Integral int32) (err error) { if this.IsCross() { err = this.modelArena.modifyIntegral(session.GetUserId(), Integral) } else { if _, err = this.service.AcrossClusterRpcGo( context.Background(), this.GetCrossTag(), comm.Service_Worker, string(comm.Rpc_ModuleArenaModifyIntegral), &pb.RPCModifyIntegralReq{Uid: session.GetUserId(), Integral: Integral}, nil); err != nil { this.Errorln(err) } } return } // /获取竞技场匹配目标战斗阵型数据 func (this *Arena) GetMatcheBattleRoles(uid string) (captain int32, rules []*pb.BattleRole, err error) { var ( global *cfg.GameGlobalData info *pb.DBArenaUser players []*pb.ArenaPlayer ais []*pb.ArenaPlayer errdata *pb.ErrorData ) global = this.ModuleTools.GetGlobalConf() if info, err = this.modelArena.queryPlayerInfo(uid); err != nil && err != mgo.MongodbNil { return } if err == mgo.MongodbNil { info = &pb.DBArenaUser{ Uinfo: &pb.BaseUserInfo{Uid: uid}, Integral: global.ArenaInitiaIntegral, Isdef: false, } if info.Dan, err = this.modelArena.computedan(info.Integral); err != nil { return } } if players, err = this.modelArena.matchePlayer(info.Uinfo.Uid, info.Dan, 1); err != nil && err != mgo.MongodbNil { return } if len(players) > 0 { captain = players[0].Defend.Leadpos if rules, errdata = this.battle.CreateRolesByHeros(players[0].Defend.Formt); errdata != nil { err = fmt.Errorf("Player CreateRolesByHeros fail:%v", errdata) return } } else { if ais, err = this.modelArena.matcheAI(info.Dan, 1); err != nil && err != mgo.MongodbNil { return } if len(ais) > 0 { captain = ais[0].Defend.Leadpos if rules, errdata = this.battle.CreateRolesByHeros(ais[0].Defend.Formt); errdata != nil { err = fmt.Errorf("AI CreateRolesByHeros fail:%v", errdata) return } } else { err = fmt.Errorf("matche fail!") } } return }