go_dreamfactory/modules/arena/module.go
2022-12-19 16:25:22 +08:00

115 lines
3.2 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)
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]bool) {
result = make(map[comm.ReddotType]bool)
for _, v := range rid {
switch v {
case comm.Reddot19:
result[comm.Reddot19] = this.modelArena.reddot(session)
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_ModuleChatPushChat),
&pb.RPCModifyIntegralReq{Uid: session.GetUserId(), Integral: Integral},
nil); err != nil {
this.Errorln(err)
}
}
return
}