92 lines
2.4 KiB
Go
92 lines
2.4 KiB
Go
package practice
|
|
|
|
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 modelPandata struct {
|
|
modules.MCompModel
|
|
module *Practice
|
|
}
|
|
|
|
func (this *modelPandata) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TablePandata
|
|
this.MCompModel.Init(service, module, comp, opt)
|
|
this.module = module.(*Practice)
|
|
//创建uid索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
///询用户的练功房信息
|
|
func (this *modelPandata) queryUserMartialhall(uid string) (result *pb.DBPracticeRoom, err error) {
|
|
result = &pb.DBPracticeRoom{}
|
|
if err = this.Get(uid, result); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
result = &pb.DBPracticeRoom{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Full: make(map[int32]int32),
|
|
Knapsack: make(map[string]int32),
|
|
Gymaction: 0,
|
|
Gymrefresh: 0,
|
|
Pillar1: &pb.DBPracticePillar{Index: 1, Isunlock: 2, Lv: 1},
|
|
Pillar2: &pb.DBPracticePillar{Index: 2, Lv: 1},
|
|
Pillar3: &pb.DBPracticePillar{Index: 3, Lv: 1},
|
|
Pillarf: &pb.DBPracticePillar{Index: 4, Isunlock: 2, Lv: 1},
|
|
Statuers: make([]*pb.DBPracticeStatuer, 0),
|
|
}
|
|
if err = this.refreshnpc(result); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if err = this.Add(uid, result); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
err = nil
|
|
return
|
|
}
|
|
|
|
//刷新npc
|
|
func (this *modelPandata) refreshnpc(room *pb.DBPracticeRoom) (err error) {
|
|
var (
|
|
npcs []*cfg.GameDispatch_BattleData
|
|
wigets []int32
|
|
index int32
|
|
)
|
|
|
|
if npcs, err = this.module.configure.getDispatchBattle(); err != nil {
|
|
return
|
|
}
|
|
wigets = make([]int32, len(npcs))
|
|
for i, v := range npcs {
|
|
wigets[i] = v.Weight
|
|
}
|
|
|
|
index = comm.GetRandW(wigets)
|
|
room.Currnpc = npcs[index].Id
|
|
room.Npcstate = 0
|
|
room.Battlenum = 0
|
|
if room.Captain, room.Formation, err = this.module.arena.GetMatcheBattleRoles(room.Uid); err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|