package realarena import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" "sync" "go.mongodb.org/mongo-driver/bson/primitive" ) /* 模块名:红点系统 描述:统一获取红点信息 开发:李伟 */ func NewModule() core.IModule { m := new(RealArena) return m } type RealArena struct { modules.ModuleBase service base.IRPCXService pvp comm.IPvp apicomp *apiComp model *modelComp match *matchComp lock sync.RWMutex rooms map[string]*Room } // 模块名 func (this *RealArena) GetType() core.M_Modules { return comm.ModuleReddot } // 模块初始化接口 注册用户创建角色事件 func (this *RealArena) 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 *RealArena) 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) return } // 装备组件 func (this *RealArena) OnInstallComp() { this.ModuleBase.OnInstallComp() this.apicomp = this.RegisterComp(new(apiComp)).(*apiComp) this.model = this.RegisterComp(new(modelComp)).(*modelComp) this.match = this.RegisterComp(new(matchComp)).(*matchComp) } //创建房间 func (this *RealArena) createroom(red, bule *pb.DBRealArenaMember) (room *Room, err error) { var ( session comm.IUserSession ok bool ) room = &Room{ Id: primitive.NewObjectID().Hex(), sessions: make([]comm.IUserSession, 0), members: make([]*pb.DBRealArenaMember, 0), } room.members = append(room.members, red, bule) if session, ok = this.GetUserSession(red.User.Uid); ok { room.sessions = append(room.sessions, session) } else { err = fmt.Errorf("player:%s is Offline", red.User.Uid) return } if session, ok = this.GetUserSession(bule.User.Uid); ok { room.sessions = append(room.sessions, session) } else { err = fmt.Errorf("player:%s is Offline", bule.User.Uid) return } this.lock.Lock() this.rooms[room.Id] = room this.lock.Unlock() return }