go_dreamfactory/modules/viking/module.go
2022-12-23 19:56:47 +08:00

185 lines
4.8 KiB
Go

/*
模块名:viking
描述:维京远征
开发:梅雄风
*/
package viking
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/db"
"strconv"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type Viking struct {
modules.ModuleBase
modelViking *modelViking
api *apiComp
configure *configureComp
modulerank *ModelRank
battle comm.IBattle
service core.IService
}
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) {
err = this.ModuleBase.Init(service, module, options)
this.service = service
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.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}
// 接口信息
func (this *Viking) ModifyVikingData(uid string, data map[string]interface{}) (code pb.ErrorCode) {
err := this.modelViking.modifyVikingDataByObjId(uid, data)
if err != nil {
code = pb.ErrorCode_DBError
}
return
}
func (this *Viking) 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)
return
}
func (this *Viking) CheckUserBaseVikingInfo(uid string) (data []*pb.DBVikingRank) {
list, err := this.modelViking.getVikingList(uid)
if err != nil {
for k := range list.Boss {
_d := this.modulerank.getVikingRankListByBossType(uid, k)
if _d != nil {
data = append(data, _d)
}
}
}
return
}
func (this *Viking) CheckRank(uid string, boosID int32, difficulty int32, viking *pb.DBViking, report *pb.BattleReport) {
costTime := report.Costtime
key := strconv.Itoa(int(boosID)) + "_" + strconv.Itoa(int(difficulty))
if viking.BossTime[key] > costTime || viking.BossTime[key] == 0 && difficulty >= viking.Boss[boosID] { // 刷新记录
viking.BossTime[key] = costTime
szLine := make([]*pb.LineUp, 5)
Leadpos := 0
if report != nil && report.Info != nil && len(report.Info.Redflist) > 0 {
costTime = report.Costtime
Leadpos = int(report.Info.Redflist[0].Leadpos)
for i, v := range report.Info.Redflist[0].Team {
if v != nil {
szLine[i] = &pb.LineUp{
Cid: v.HeroID,
Star: v.Star,
Lv: v.Lv,
}
}
}
}
// 写入排行榜
objID := ""
bFind := false
ranks := this.modulerank.getVikingRankList(uid)
for _, v := range ranks {
if v.Bosstype == boosID {
mapRankData := make(map[string]interface{}, 0)
mapRankData["difficulty"] = difficulty
mapRankData["bosstype"] = boosID
mapRankData["Leadpos"] = Leadpos
mapRankData["line"] = szLine
mapRankData["costTime"] = costTime
conn_, _ := db.Cross()
dbModel := db.NewDBModel(comm.TableVikingRank, time.Hour, conn_)
dbModel.ChangeList(uid, v.Id, mapRankData)
objID = v.Id
bFind = true
break
}
}
if !bFind {
userinfo := this.ModuleUser.GetUser(uid)
new := &pb.DBVikingRank{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Difficulty: difficulty,
Bosstype: boosID,
Nickname: userinfo.Name,
Icon: "",
Lv: userinfo.Lv,
Leadpos: int32(Leadpos),
Line: szLine,
CostTime: costTime,
}
objID = new.Id
conn_, _ := db.Cross()
dbModel := db.NewDBModel(comm.TableVikingRank, time.Hour, conn_)
dbModel.AddList(uid, new.Id, new)
}
this.modulerank.SetRankListData("vikingRank"+strconv.Itoa(int(boosID)), difficulty<<16+costTime, objID)
}
}
//红点查询
func (this *Viking) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]bool) {
reddot = make(map[comm.ReddotType]bool)
for _, v := range rid {
switch v {
case comm.Reddot31:
reddot[comm.Reddot31] = this.modelViking.checkReddot31(session.GetUserId())
break
}
}
return
}
// 解锁远征所有难度
func (this *Viking) CompleteAllLevel(session comm.IUserSession) (code pb.ErrorCode) {
list, err := this.modelViking.getVikingList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
mapData := make(map[string]interface{}, 0)
// 查配置获取每个Boss的最大难度
for k := range list.Boss {
for i := 1; ; i++ {
conf := this.configure.GetVikingBossConfigData(k, int32(i))
if conf == nil {
list.Boss[k] = int32(i - 1)
}
}
}
mapData["boss"] = list.Boss
code = this.ModifyVikingData(session.GetUserId(), mapData)
session.SendMsg(string(this.GetType()), VikingGetListResp, &pb.VikingGetListResp{Data: list})
return
}