go_dreamfactory/modules/viking/module.go
2024-02-23 13:58:45 +08:00

183 lines
4.4 KiB
Go

/*
模块名:viking
描述:维京远征
开发:梅雄风
*/
package viking
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
type Viking struct {
modules.ModuleBase
modelViking *modelViking
api *apiComp
configure *configureComp
modulerank *ModelRank
battle comm.IBattle
service base.IRPCXService
modelsrank *ModelSRank
mail comm.Imail
battlerecord comm.IBattleRecord // 战报模块
}
const (
Cycle int32 = 14 // 持续14天
Continued int32 = 30
)
func NewModule() core.IModule {
return &Viking{}
}
func (this *Viking) GetType() core.M_Modules {
return comm.ModuleViking
}
func (this *Viking) 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 *Viking) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelViking = this.RegisterComp(new(modelViking)).(*modelViking)
this.modulerank = this.RegisterComp(new(ModelRank)).(*ModelRank)
this.modelsrank = this.RegisterComp(new(ModelSRank)).(*ModelSRank)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}
// 接口信息
func (this *Viking) ModifyVikingData(uid string, data map[string]interface{}) (errdata *pb.ErrorData) {
err := this.modelViking.modifyVikingDataByObjId(uid, data)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
}
return
}
func (this *Viking) Start() (err error) {
if err = this.ModuleBase.Start(); err != nil {
return
}
this.service.RegisterFunctionName(string(comm.Rpc_ModuleVikingFigthEnd), this.Rpc_ModuleVikingFigthEnd)
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.ModuleBattleRecord); err != nil {
return
}
this.battlerecord = module.(comm.IBattleRecord)
return
}
func (this *Viking) Rpc_ModuleVikingFigthEnd(ctx context.Context, args *pb.EmptyReq, reply *pb.EmptyResp) (err error) {
this.Debug("Rpc_ModuleVikingFigthEnd",
log.Field{Key: "args", Value: args.String()},
)
this.modelsrank.raceSettlement()
return
}
func (this *Viking) CheckUserBaseVikingInfo(uid string) (data []*pb.DBVikingRank) {
if d := this.modulerank.getVikingRank(uid); d.Id != "" {
for k, v := range d.Data {
if k <= 3 {
data = append(data, &pb.DBVikingRank{
Uinfo: d.Uinfo,
Line: v.Line[v.Maxnandu],
Difficulty: v.Maxnandu,
Bosstype: k,
Costtime: v.Costime[v.Maxnandu],
})
}
}
}
return
}
//红点查询
func (this *Viking) Reddot(session comm.IUserSession, rid map[comm.ReddotType]struct{}) (items map[comm.ReddotType]*pb.ReddotItem) {
var (
selfrid []comm.ReddotType = []comm.ReddotType{comm.Reddot13102}
ok bool
)
items = make(map[comm.ReddotType]*pb.ReddotItem)
for _, v := range selfrid {
if _, ok = rid[v]; ok {
break
}
}
if ok {
return
}
for _, v := range selfrid {
if _, ok = rid[v]; ok {
switch v {
case comm.Reddot13102:
items[comm.Reddot13102] = &pb.ReddotItem{
Rid: int32(comm.Reddot13102),
Activated: this.modelViking.checkReddot31(session),
}
break
}
}
}
return
}
// 解锁远征所有难度
func (this *Viking) CompleteAllLevel(session comm.IUserSession) (errdata *pb.ErrorData) {
list, err := this.modelViking.getVikingList(session.GetUserId())
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
list.Boss = make(map[int32]int32)
list.BossTime = make(map[string]int32)
conf := this.configure.GetVikingBossAllData()
for k, v := range conf {
list.Boss[k] = v
}
mapData := make(map[string]interface{}, 0)
mapData["boss"] = list.Boss
mapData["bossTime"] = list.BossTime
errdata = this.ModifyVikingData(session.GetUserId(), mapData)
session.SendMsg(string(this.GetType()), VikingGetListResp, &pb.VikingGetListResp{Data: list})
return
}