go_dreamfactory/modules/arena/module.go
2022-11-21 13:47:06 +08:00

89 lines
2.3 KiB
Go

package arena
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
/*
模块名:竞技场
描述:pvp相关业务
开发:李伟
*/
func NewModule() core.IModule {
m := new(Arena)
return m
}
type Arena struct {
modules.ModuleBase
service base.IRPCXService
mail comm.Imail
battle comm.IBattle
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) {
err = this.ModuleBase.Init(service, module, options)
this.service = service.(base.IRPCXService)
return
}
func (this *Arena) Start() (err error) {
err = this.ModuleBase.Start()
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)
this.service.RegisterFunctionName(string(comm.Rpc_ModuleArenaRaceSettlement), this.Rpc_ModuleArenaRaceSettlement)
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) {
this.Debug("Rpc_ModuleArenaRaceSettlement", log.Fields{"args": args.String()})
this.modelRank.raceSettlement()
}
//红点需求
func (this *Arena) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (result map[comm.ReddotType]bool) {
result = make(map[comm.ReddotType]bool)
for _, v := range rid {
switch v {
case comm.Reddot19:
if isredot := this.modelArena.reddot(session); isredot {
result[comm.Reddot19] = true
}
break
}
}
return
}