206 lines
5.4 KiB
Go
206 lines
5.4 KiB
Go
package mainline
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type ModelMline struct {
|
|
modules.MCompModel
|
|
module *Mainline
|
|
}
|
|
|
|
func (this *ModelMline) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableMainline
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Mainline)
|
|
//创建uid索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *ModelMline) getMainlineData(uid string) (results *pb.DBMainline, err error) {
|
|
results = &pb.DBMainline{}
|
|
if err = this.Get(uid, results); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
err = nil
|
|
results = &pb.DBMainline{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Lastlevel: make(map[int32]int32),
|
|
Level: make(map[int32]int32),
|
|
Chapteraward: make(map[int32]*pb.DBMainlineAward),
|
|
Exploreaward: make(map[int32]*pb.DBMainlineAward),
|
|
Groupaward: make(map[int32]*pb.DBMainlineAward),
|
|
Ps: make(map[int32]int32),
|
|
Chapterboos: make(map[int32]int32),
|
|
}
|
|
err = this.Add(uid, results)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *ModelMline) updateMainlineData(uid string, data *pb.DBMainline) (err error) {
|
|
if err = this.Change(uid, map[string]interface{}{
|
|
"level": data.Level,
|
|
"lastlevel": data.Lastlevel,
|
|
"chapteraward": data.Chapteraward,
|
|
"exploreaward": data.Exploreaward,
|
|
"groupaward": data.Groupaward,
|
|
"ps": data.Ps,
|
|
}); err != nil {
|
|
this.module.Error("更新用户任务数据 错误!", log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 更新主线进度
|
|
func (this *ModelMline) updateprogress(data *pb.DBMainline) {
|
|
var (
|
|
conf *cfg.GameMainStageData
|
|
chapteraward map[int32]*pb.DBMainlineAward = make(map[int32]*pb.DBMainlineAward)
|
|
exploreaward map[int32]*pb.DBMainlineAward = make(map[int32]*pb.DBMainlineAward)
|
|
groupaward map[int32]*pb.DBMainlineAward = make(map[int32]*pb.DBMainlineAward)
|
|
err error
|
|
ok bool
|
|
)
|
|
for k, v := range data.Level {
|
|
if conf, err = this.module.configure.GetMainStageConf(k); err != nil { // 配置文件校验
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if conf.Episodetype != 9 {
|
|
if _, ok = chapteraward[conf.Chapterid]; !ok {
|
|
chapteraward[conf.Chapterid] = &pb.DBMainlineAward{}
|
|
}
|
|
chapteraward[conf.Chapterid].Stage += conf.Progress
|
|
}
|
|
|
|
if conf.Episodetype != 8 && conf.Episodetype != 9 && conf.Episodetype != 0 {
|
|
if _, ok = exploreaward[conf.Chapterid]; !ok {
|
|
exploreaward[conf.Chapterid] = &pb.DBMainlineAward{}
|
|
}
|
|
exploreaward[conf.Chapterid].Stage++
|
|
}
|
|
if _, ok = groupaward[conf.GroupId]; !ok {
|
|
groupaward[conf.GroupId] = &pb.DBMainlineAward{}
|
|
}
|
|
|
|
for i := 0; i < len(conf.Star); i++ {
|
|
if (1<<i)&v > 0 {
|
|
groupaward[conf.GroupId].Stage++
|
|
}
|
|
}
|
|
}
|
|
|
|
for k, v := range chapteraward {
|
|
if _, ok = data.Chapteraward[k]; !ok {
|
|
data.Chapteraward[k] = v
|
|
} else {
|
|
data.Chapteraward[k].Stage = v.Stage
|
|
}
|
|
}
|
|
for k, v := range exploreaward {
|
|
if _, ok = data.Exploreaward[k]; !ok {
|
|
data.Exploreaward[k] = v
|
|
} else {
|
|
data.Exploreaward[k].Stage = v.Stage
|
|
}
|
|
}
|
|
for k, v := range groupaward {
|
|
if _, ok = data.Groupaward[k]; !ok {
|
|
data.Groupaward[k] = v
|
|
} else {
|
|
data.Groupaward[k].Stage = v.Stage
|
|
}
|
|
}
|
|
}
|
|
|
|
// 校验管卡是否触发
|
|
func (this *ModelMline) checklevel(level int32, data *pb.DBMainline) (err error) {
|
|
var (
|
|
conf *cfg.GameMainStageData
|
|
ok bool
|
|
)
|
|
if conf, err = this.module.configure.GetMainStageConf(level); err != nil { // 配置文件校验
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
|
|
if conf.Previoustage != 0 {
|
|
if _, ok = data.Level[conf.Previoustage]; !ok {
|
|
err = fmt.Errorf("previoustage:%d no pass", conf.Previoustage)
|
|
return
|
|
}
|
|
}
|
|
if conf.PreviousGroupId != nil && len(conf.PreviousGroupId) > 0 {
|
|
for _, gid := range conf.PreviousGroupId {
|
|
if _, ok = data.Groupaward[gid]; !ok {
|
|
err = fmt.Errorf("PreviousGroupId:%d no pass", gid)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 随机boos
|
|
func (this *ModelMline) randomboos(data *pb.DBMainline) (err error) {
|
|
var (
|
|
chapters []int32 = make([]int32, 0)
|
|
weight []int32 = make([]int32, 0)
|
|
conf *cfg.GameMainChapterData
|
|
index int32
|
|
ok bool
|
|
)
|
|
|
|
for k, levles := range this.module.configure.getchapterMap() {
|
|
for _, v := range levles {
|
|
if v.Progress == 1 {
|
|
if _, ok = data.Level[v.Id]; !ok {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
if !ok {
|
|
continue
|
|
}
|
|
chapters = append(chapters, k)
|
|
}
|
|
if len(chapters) == 0 {
|
|
return
|
|
}
|
|
for _, v := range chapters {
|
|
if conf, err = this.module.configure.GetMainChapterConf(v); err != nil {
|
|
return
|
|
}
|
|
weight = append(weight, conf.Bosspro)
|
|
}
|
|
|
|
index = comm.GetRandW(weight)
|
|
if conf, err = this.module.configure.GetMainChapterConf(chapters[index]); err != nil {
|
|
return
|
|
}
|
|
data.Currboosmodel = conf.Models[comm.GetRandW(conf.Models)]
|
|
data.Currbooschapter = chapters[index]
|
|
data.Lastboosrefresh = configure.Now().Unix()
|
|
return
|
|
}
|