go_dreamfactory/modules/integral/model_integral.go
2023-12-07 16:09:07 +08:00

86 lines
2.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) getIntegralList(uid string) (result *pb.DBIntegralBoss, err error) {
result = &pb.DBIntegralBoss{}
if err = this.Get(uid, result); mgo.MongodbNil == err {
result.Id = primitive.NewObjectID().Hex()
result.Uid = uid
result.Buff = make(map[int32]int32)
result.Score = make(map[int32]int64)
// 获取当前的hid
curTime := configure.Now().Unix()
szConf := this.module.configure.GetIntegralITime()
// 当前开服时间
openTime := this.module.service.GetOpentime().Unix()
for _, v := range szConf {
if curTime >= int64(v.Openday)+openTime && curTime <= int64(v.Endday)+openTime {
result.Hid = v.Endday
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 // 获取类型
result.Nandu = 1 // 初始难度1
var szTaskid []int32
for _, v := range this.module.configure.GetIntegralCondition() {
szTaskid = append(szTaskid, v.TaskId) // 获取任务id
}
if data, err := this.module.ModuleBuried.CheckCondition(uid, 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
}