197 lines
5.1 KiB
Go
197 lines
5.1 KiB
Go
package mainline
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"sort"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
type Mainline struct {
|
|
modules.ModuleBase
|
|
modelMainline *ModelMainline
|
|
service core.IService
|
|
api *apiComp
|
|
configure *configureComp
|
|
battle comm.IBattle
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &Mainline{}
|
|
}
|
|
|
|
func (this *Mainline) GetType() core.M_Modules {
|
|
return comm.ModuleMainline
|
|
}
|
|
|
|
func (this *Mainline) 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 *Mainline) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelMainline = this.RegisterComp(new(ModelMainline)).(*ModelMainline)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
// 接口信息 给其他模块调用 用来修改主线关卡信息
|
|
func (this *Mainline) ModifyMainlineData(uid string, id int32) (code pb.ErrorCode) {
|
|
|
|
conf := this.configure.GetMainlineConfigData(id, 1)
|
|
list, err := this.modelMainline.getMainlineList(uid)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
for _, v := range list {
|
|
if v.ChapterId == conf.Chapter {
|
|
data := make(map[string]interface{}, 0)
|
|
data["mainlineId"] = id
|
|
data["chapterId"] = v.ChapterId
|
|
this.modelMainline.modifyMainlineData(uid, v.Id, data)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
}
|
|
|
|
return
|
|
}
|
|
}
|
|
//add
|
|
_data := &pb.DBMainline{}
|
|
_data.Id = primitive.NewObjectID().Hex()
|
|
_data.ChapterId = conf.Chapter
|
|
_data.MainlineId = conf.Id
|
|
_mData := make(map[string]interface{}, 0)
|
|
_data.Uid = uid
|
|
_data.Intensity = 1 // 难度1
|
|
_mData[_data.Id] = _data
|
|
|
|
this.modelMainline.addNewChapter(uid, _mData)
|
|
return
|
|
}
|
|
|
|
func (this *Mainline) GetUsermainLineData(uid string) (mainlineId int32) {
|
|
|
|
_szData, err := this.modelMainline.getMainlineList(uid)
|
|
if err == nil {
|
|
sort.SliceStable(_szData, func(i, j int) bool { // 排序
|
|
return _szData[i].ChapterId > _szData[j].ChapterId
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (this *Mainline) 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 *Mainline) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]bool) {
|
|
reddot = make(map[comm.ReddotType]bool)
|
|
for _, v := range rid {
|
|
if v == comm.Reddot5 {
|
|
reddot[comm.Reddot5] = this.CheckPoint(session.GetUserId())
|
|
break
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 红点检测
|
|
func (this *Mainline) CheckPoint(uid string) bool {
|
|
list, err := this.modelMainline.getMainlineList(uid)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
for _, v := range list {
|
|
conf := this.configure.GetMainlineChapter(v.ChapterId)
|
|
if conf == nil {
|
|
continue
|
|
}
|
|
if len(conf.Episode) != len(v.BranchID) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// 参数 难度 + 关卡id
|
|
func (this *Mainline) ModifyMainlineDataByNanduID(uid string, nandu, id int32) (code pb.ErrorCode) {
|
|
|
|
conf := this.configure.GetMainlineConfigData(id, nandu)
|
|
if conf != nil {
|
|
code = pb.ErrorCode_ConfigNoFound // 找不到配置
|
|
return
|
|
}
|
|
// 已现在设置的为准 删除之前的所有数据
|
|
this.modelMainline.cleanChapter(uid)
|
|
// 获取当前的章节数据
|
|
jumpCap := conf.Chapter
|
|
// 先加所有难度小于1 的章节
|
|
for ndIndex := 1; ndIndex < int(nandu)-1; ndIndex++ {
|
|
max := this.configure.GetMaxMainlineChapter()
|
|
for i := 1; i <= int(max); i++ {
|
|
_data := &pb.DBMainline{}
|
|
_data.Id = primitive.NewObjectID().Hex()
|
|
_data.ChapterId = conf.Chapter
|
|
_data.MainlineId = conf.Id
|
|
_mData := make(map[string]interface{}, 0)
|
|
_data.Uid = uid
|
|
_data.Intensity = int32(ndIndex) // 难度1
|
|
confCap := this.configure.GetMainlineChapter(int32(i))
|
|
for _, v := range confCap.Episode {
|
|
_data.BranchID = append(_data.BranchID, v)
|
|
}
|
|
|
|
_mData[_data.Id] = _data
|
|
|
|
this.modelMainline.addNewChapter(uid, _mData)
|
|
}
|
|
}
|
|
// 加当前难度 的章节数据
|
|
for i := 1; i < int(jumpCap-1); i++ {
|
|
confCap := this.configure.GetMainlineChapter(int32(i))
|
|
_data := &pb.DBMainline{}
|
|
_data.Id = primitive.NewObjectID().Hex()
|
|
_data.ChapterId = conf.Chapter
|
|
_data.MainlineId = conf.Id
|
|
_mData := make(map[string]interface{}, 0)
|
|
_data.Uid = uid
|
|
_data.Intensity = int32(nandu) // 难度1
|
|
for _, v := range confCap.Episode {
|
|
_data.BranchID = append(_data.BranchID, v)
|
|
}
|
|
_mData[_data.Id] = _data
|
|
this.modelMainline.addNewChapter(uid, _mData)
|
|
}
|
|
// 加当前难度 当前章节的前置关卡数据
|
|
_data := &pb.DBMainline{}
|
|
_data.Id = primitive.NewObjectID().Hex()
|
|
_data.ChapterId = conf.Chapter
|
|
_data.MainlineId = conf.Id
|
|
_mData := make(map[string]interface{}, 0)
|
|
_data.Uid = uid
|
|
_data.Intensity = int32(nandu) // 难度1
|
|
// for _, v := range confCap.Episode {
|
|
// _data.BranchID = append(_data.BranchID, v)
|
|
// }
|
|
_mData[_data.Id] = _data
|
|
this.modelMainline.addNewChapter(uid, _mData)
|
|
|
|
return
|
|
}
|