178 lines
4.7 KiB
Go
178 lines
4.7 KiB
Go
package martialhall
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
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 modelMartialhall struct {
|
|
modules.MCompModel
|
|
module *Martialhall
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *modelMartialhall) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableMartialhall
|
|
this.MCompModel.Init(service, module, comp, opt)
|
|
this.module = module.(*Martialhall)
|
|
//创建uid索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
///询用户的练功房信息
|
|
func (this *modelMartialhall) queryUserMartialhall(uid string) (result *pb.DBMartialhall, err error) {
|
|
result = &pb.DBMartialhall{}
|
|
if err = this.Get(uid, result); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorln(err)
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
unlocknum := this.module.configure.GetGlobalConf().KungfuInitialPracticeStake
|
|
result = &pb.DBMartialhall{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Lv: 1,
|
|
Pillar1: &pb.DBPillar{Index: 1},
|
|
Pillar2: &pb.DBPillar{Index: 2},
|
|
Pillar3: &pb.DBPillar{Index: 3},
|
|
Pillar4: &pb.DBPillar{Index: 4},
|
|
Pillar5: &pb.DBPillar{Index: 5},
|
|
}
|
|
switch unlocknum {
|
|
case 1:
|
|
result.Pillar1.Isunlock = true
|
|
case 2:
|
|
result.Pillar1.Isunlock = true
|
|
result.Pillar2.Isunlock = true
|
|
case 3:
|
|
result.Pillar1.Isunlock = true
|
|
result.Pillar2.Isunlock = true
|
|
result.Pillar3.Isunlock = true
|
|
case 4:
|
|
result.Pillar1.Isunlock = true
|
|
result.Pillar2.Isunlock = true
|
|
result.Pillar3.Isunlock = true
|
|
result.Pillar4.Isunlock = true
|
|
case 5:
|
|
result.Pillar1.Isunlock = true
|
|
result.Pillar2.Isunlock = true
|
|
result.Pillar3.Isunlock = true
|
|
result.Pillar4.Isunlock = true
|
|
result.Pillar5.Isunlock = true
|
|
}
|
|
if err = this.Add(uid, result); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
err = nil
|
|
return
|
|
}
|
|
|
|
//可领取红点
|
|
func (this *modelMartialhall) checkReddot23(seesion comm.IUserSession) bool {
|
|
var (
|
|
err error
|
|
mart *pb.DBMartialhall
|
|
mdata *cfg.GameKungfuMasterworkerData
|
|
code pb.ErrorCode
|
|
)
|
|
if mart, err = this.module.modelMartialhall.queryUserMartialhall(seesion.GetUserId()); err != nil {
|
|
return false
|
|
}
|
|
if mdata, err = this.module.configure.getMasterworker(mart.Lv); err != nil {
|
|
return false
|
|
}
|
|
if code = this.module.CheckRes(seesion, mdata.Deplete); code != pb.ErrorCode_Success {
|
|
return false
|
|
}
|
|
if mart.Pillar1.State == pb.PillarState_NoUse {
|
|
return true
|
|
}
|
|
if mart.Pillar2.State == pb.PillarState_NoUse {
|
|
return true
|
|
}
|
|
if mart.Pillar3.State == pb.PillarState_NoUse {
|
|
return true
|
|
}
|
|
if mart.Pillar4.State == pb.PillarState_NoUse {
|
|
return true
|
|
}
|
|
if mart.Pillar5.State == pb.PillarState_NoUse {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
//可领取红点
|
|
func (this *modelMartialhall) checkReddot24(seesion comm.IUserSession) bool {
|
|
var (
|
|
err error
|
|
mart *pb.DBMartialhall
|
|
mdata *cfg.GameKungfuMasterworkerData
|
|
code pb.ErrorCode
|
|
)
|
|
if mart, err = this.module.modelMartialhall.queryUserMartialhall(seesion.GetUserId()); err != nil {
|
|
return false
|
|
}
|
|
if mdata, err = this.module.configure.getMasterworker(mart.Lv); err != nil {
|
|
return false
|
|
}
|
|
if mdata.LevelDeplete != nil && len(mdata.LevelDeplete) > 0 {
|
|
if code = this.module.CheckRes(seesion, mdata.LevelDeplete); code != pb.ErrorCode_Success {
|
|
return false
|
|
}
|
|
|
|
}
|
|
return false
|
|
}
|
|
|
|
//可领取红点
|
|
func (this *modelMartialhall) checkReddot25(seesion comm.IUserSession) bool {
|
|
var (
|
|
err error
|
|
mart *pb.DBMartialhall
|
|
mdata *cfg.GameKungfuMasterworkerData
|
|
)
|
|
if mart, err = this.module.modelMartialhall.queryUserMartialhall(seesion.GetUserId()); err != nil {
|
|
return false
|
|
}
|
|
if mdata, err = this.module.configure.getMasterworker(mart.Lv); err != nil {
|
|
return false
|
|
}
|
|
check(this.module.ModuleRtask, seesion, mart.Pillar1, mdata)
|
|
if mart.Pillar1.State == pb.PillarState_Receive {
|
|
return true
|
|
}
|
|
check(this.module.ModuleRtask, seesion, mart.Pillar2, mdata)
|
|
if mart.Pillar2.State == pb.PillarState_Receive {
|
|
return true
|
|
}
|
|
check(this.module.ModuleRtask, seesion, mart.Pillar3, mdata)
|
|
|
|
if mart.Pillar3.State == pb.PillarState_Receive {
|
|
return true
|
|
}
|
|
|
|
check(this.module.ModuleRtask, seesion, mart.Pillar4, mdata)
|
|
if mart.Pillar4.State == pb.PillarState_Receive {
|
|
return true
|
|
}
|
|
check(this.module.ModuleRtask, seesion, mart.Pillar5, mdata)
|
|
if mart.Pillar5.State == pb.PillarState_Receive {
|
|
return true
|
|
}
|
|
return false
|
|
}
|