115 lines
3.5 KiB
Go
115 lines
3.5 KiB
Go
package integral
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"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 modelIntegral struct {
|
|
modules.MCompModel
|
|
module *Integral
|
|
}
|
|
|
|
func (this *modelIntegral) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableIntegral)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Integral)
|
|
// uid 创建索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
// 修改基本数据
|
|
func (this *modelIntegral) modifyIntegralData(uid string, data map[string]interface{}) error {
|
|
return this.Change(uid, data)
|
|
}
|
|
|
|
func (this *modelIntegral) queryPlayers(uIds []string) (result []*pb.DBIntegralBoss, err error) {
|
|
result = make([]*pb.DBIntegralBoss, 0)
|
|
if _, err = this.Gets(uIds, &result); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取列表信息
|
|
func (this *modelIntegral) getIntegralList(session comm.IUserSession) (result *pb.DBIntegralBoss, err error) {
|
|
uid := session.GetUserId()
|
|
result = &pb.DBIntegralBoss{
|
|
Buff: map[int32]int32{},
|
|
Score: map[int32]int32{},
|
|
Uinfo: &pb.BaseUserInfo{},
|
|
Line: map[int32]*pb.LineData{},
|
|
Achieve: map[int32]int32{},
|
|
Carrybuff: map[int32]*pb.FreightBuff{},
|
|
}
|
|
if err = this.Get(uid, result); mgo.MongodbNil == err {
|
|
var user *pb.DBUser
|
|
user, err = this.module.GetUserForSession(session)
|
|
if err != nil {
|
|
return
|
|
}
|
|
result.Id = primitive.NewObjectID().Hex()
|
|
result.Uid = uid
|
|
result.Buff = make(map[int32]int32)
|
|
result.Score = make(map[int32]int32)
|
|
result.Line = make(map[int32]*pb.LineData, 0)
|
|
result.Achieve = make(map[int32]int32) // 初始化成就
|
|
result.Carrybuff = make(map[int32]*pb.FreightBuff) // 初始化成就
|
|
result.Uinfo = comm.GetUserBaseInfo(user)
|
|
// 获取当前的hid
|
|
curTime := configure.Now().Unix()
|
|
szConf := this.module.configure.GetIntegralITime()
|
|
// 当前开服时间
|
|
openTime := this.module.service.GetOpentime().Unix()
|
|
openTime = configure.Now().Unix() // 临时校验
|
|
for _, v := range szConf {
|
|
//if curTime >= int64(v.Openday)+openTime && curTime <= int64(v.Endday)+openTime {
|
|
result.Hid = v.Hdid
|
|
result.Etime = int64(v.Endday) + openTime
|
|
result.CTime = curTime
|
|
break
|
|
//}
|
|
}
|
|
|
|
var conf *cfg.GameIntegralBossData
|
|
if conf, err = this.module.configure.GetStageBoss(result.Hid, 1); err == nil {
|
|
result.Itype = conf.Itype // 获取类型 1 难度模式 2 事件模式
|
|
result.Nandu = 1 // 初始难度1
|
|
// 只有 事件模式才有buff
|
|
if result.Itype == 2 {
|
|
var szTaskid []int32
|
|
for _, v := range this.module.configure.GetIntegralCondition() {
|
|
szTaskid = append(szTaskid, v.TaskId) // 获取任务id
|
|
}
|
|
if _, data, err := this.module.ModuleBuried.CheckCondition(session, szTaskid...); err == nil {
|
|
for _, v := range data {
|
|
|
|
if v.State == pb.BuriedItemFinishState_buried_finish {
|
|
if c, e := this.module.configure.GetIntegralConditionByTask(v.Conid); e == nil {
|
|
result.Buff[v.Conid] = c.Id
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
err = this.Add(uid, result) // 入库
|
|
return
|
|
}
|
|
return result, err
|
|
}
|