98 lines
3.0 KiB
Go
98 lines
3.0 KiB
Go
package moonfantasy
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
///论坛 数据组件
|
|
type modelUserMF struct {
|
|
modules.MCompModel
|
|
module *Moonfantasy
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *modelUserMF) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
|
this.MCompModel.Init(service, module, comp, opt)
|
|
this.module = module.(*Moonfantasy)
|
|
this.TableName = comm.TableUserMFantasy
|
|
//创建uid索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
///查询用户秘境列表
|
|
func (this *modelUserMF) queryUsermfantasy(uId string) (info *pb.DBUserMFantasy, err error) {
|
|
info = &pb.DBUserMFantasy{}
|
|
if err = this.Get(uId, info); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorf("err:%v", err)
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
global := this.module.ModuleTools.GetGlobalConf()
|
|
info = &pb.DBUserMFantasy{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uId,
|
|
TriggerNum: 0,
|
|
LastTrigger: 0,
|
|
BuyNum: global.DreamlandFightnum,
|
|
// Ticket: global.DreamlandFightnum,
|
|
Lastrtickettime: configure.Now().Unix(),
|
|
}
|
|
if err = this.Add(uId, info); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
err = nil
|
|
}
|
|
return
|
|
}
|
|
|
|
///保存用户竞技场信息
|
|
func (this *modelUserMF) updateUserInfo(info *pb.DBUserMFantasy) (err error) {
|
|
this.Change(info.Uid, map[string]interface{}{
|
|
"triggerNum": info.TriggerNum,
|
|
"buyNum": info.BuyNum,
|
|
"lastTrigger": info.LastTrigger,
|
|
"lastrtickettime": info.Lastrtickettime,
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *modelUserMF) recoverTicket(session comm.IUserSession, info *pb.DBUserMFantasy) {
|
|
var (
|
|
// duration time.Duration
|
|
// ticket int32
|
|
// ticketNum int32
|
|
)
|
|
if time.Unix(info.LastTrigger, 0).Day() < configure.Now().Day() {
|
|
info.TriggerNum = 0
|
|
info.LastTrigger = configure.Now().Unix()
|
|
info.BuyNum = 0
|
|
}
|
|
this.module.ModuleItems.RecoverTicket(session)
|
|
// global := this.module.ModuleTools.GetGlobalConf()
|
|
// ticket = int32(this.module.ModuleItems.QueryItemAmount(info.Uid, comm.MoonFantasyTicket))
|
|
// if ticket < global.DreamlandFightnum && info.Lastrtickettime > 0 {
|
|
// duration = configure.Now().Sub(time.Unix(info.Lastrtickettime, 0))
|
|
// ticketNum = int32(math.Floor(duration.Minutes() / float64(global.ArenaTicketRecoveryTime)))
|
|
// if ticketNum > 0 {
|
|
// if ticketNum+ticket > global.ArenaTicketMax {
|
|
// ticketNum = global.ArenaTicketMax - ticket
|
|
// }
|
|
// // this.module.DispenseRes(session, []*cfg.Gameatn{&cfg.Gameatn{A: comm.ItemType, T: comm.MoonFantasyTicket, N: ticketNum}}, true)
|
|
// info.Lastrtickettime = time.Unix(info.Lastrtickettime, 0).Add(time.Duration(ticketNum) * time.Minute).Unix()
|
|
// }
|
|
// }
|
|
}
|