package entertainment import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" ) func NewModule() core.IModule { m := new(Entertainment) return m } type Entertainment struct { modules.ModuleBase service comm.IService api *apiComp configure *configureComp model *modelComp gameMgr *gameMgrComp //room *Room match *matchComp } // 模块名 func (this *Entertainment) GetType() core.M_Modules { return comm.ModuleEntertainment } // 模块初始化接口 注册用户创建角色事件 func (this *Entertainment) 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 *Entertainment) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.model = this.RegisterComp(new(modelComp)).(*modelComp) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) this.gameMgr = this.RegisterComp(new(gameMgrComp)).(*gameMgrComp) //this.room = this.RegisterComp(new(Room)).(*Room) this.match = this.RegisterComp(new(matchComp)).(*matchComp) } func (this *Entertainment) Start() (err error) { if err = this.ModuleBase.Start(); err != nil { return } return } // 分发资源 func (this *Entertainment) AddXxlCard(session comm.IUserSession, cards map[string]int32, bPush bool) (errdata *pb.ErrorData) { var ( result *pb.DBXXLData err error ) for k := range cards { if _, err := this.model.module.configure.GetGameConsumeHero(k); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: err.Error(), } return } } if result, err = this.model.getEntertainmList(session.GetUserId()); err != nil { return } for k, v := range cards { result.Card[k] += v } this.model.modifyEntertainmList(session.GetUserId(), map[string]interface{}{ "card": result.Card, }) if bPush { session.SendMsg(string(this.GetType()), "titlelist", &pb.EntertainChangePush{ Card: result.Card, }) } return } // 消耗一张卡 func (this *Entertainment) ConsumXxlCard(session comm.IUserSession, card string) (errdata *pb.ErrorData) { var ( result *pb.DBXXLData err error ) if result, err = this.model.getEntertainmList(session.GetUserId()); err != nil { return } if _, ok := result.Card[card]; ok { if result.Card[card] <= 0 { return } result.Card[card] -= 1 this.model.modifyEntertainmList(session.GetUserId(), map[string]interface{}{ "card": result.Card, }) } session.SendMsg(string(this.GetType()), "titlelist", &pb.EntertainChangePush{ Card: result.Card, }) return }