294 lines
8.1 KiB
Go
294 lines
8.1 KiB
Go
package practice
|
|
|
|
import (
|
|
"fmt"
|
|
"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_dreamfactory/sys/db"
|
|
|
|
"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]*pb.DBPracticeRes),
|
|
Gymaction: 0,
|
|
Gymrefresh: 0,
|
|
Pillar1: &pb.DBPracticePillar{Index: 1, Isunlock: 0, Lv: 1},
|
|
Pillar2: &pb.DBPracticePillar{Index: 2, Lv: 1},
|
|
Pillar3: &pb.DBPracticePillar{Index: 3, Lv: 1},
|
|
Pillarf: &pb.DBPracticePillar{Index: 4, Isunlock: 0, Lv: 1},
|
|
Statuers: make([]*pb.DBPracticeStatuer, 0),
|
|
Npcstate: -1,
|
|
Refresh: configure.Now().Unix(),
|
|
}
|
|
// 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
|
|
}
|
|
if err = this.module.atlas.CheckActivatePandaAtlasCollect(uid, "100001"); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
err = nil
|
|
return
|
|
}
|
|
|
|
func (this *modelPandata) queryrooms(uids []string) (results []*pb.DBPracticeRoom, err error) {
|
|
results = make([]*pb.DBPracticeRoom, 0)
|
|
var (
|
|
onfound []string
|
|
newdata map[string]interface{} = make(map[string]interface{})
|
|
)
|
|
if onfound, err = this.Gets(uids, &results); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if len(onfound) > 0 {
|
|
for _, v := range onfound {
|
|
temp := &pb.DBPracticeRoom{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: v,
|
|
Full: make(map[int32]int32),
|
|
Knapsack: make(map[string]*pb.DBPracticeRes),
|
|
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),
|
|
Npcstate: 3,
|
|
Refresh: configure.Now().Unix(),
|
|
}
|
|
// if err = this.refreshnpc(temp); err != nil {
|
|
// this.module.Errorln(err)
|
|
// continue
|
|
// }
|
|
go this.module.atlas.CheckActivatePandaAtlasCollect(v, "100001")
|
|
newdata[v] = temp
|
|
results = append(results, temp)
|
|
}
|
|
if err = this.Adds(newdata); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 刷新npc
|
|
func (this *modelPandata) refreshnpc(room *pb.DBPracticeRoom) (err error) {
|
|
var (
|
|
npcs []*cfg.GameDispatch_BattleData
|
|
wigets []int32
|
|
index int32
|
|
errdata *pb.ErrorData
|
|
)
|
|
|
|
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, errdata = this.module.battle.CreateRolesByFormat(npcs[index].MonsterformatId); errdata != nil {
|
|
err = fmt.Errorf("CreateRolesByFormat fail:%+v", errdata)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 更新埋点数据到db中
|
|
func (this *modelPandata) getpandataModel() (model *pandataModel, err error) {
|
|
var m *db.DBModel
|
|
if !db.IsCross() {
|
|
if m, err = this.module.GetCrossDBModel(this.TableName); err != nil {
|
|
return
|
|
}
|
|
model = &pandataModel{module: this.module, model: m}
|
|
} else {
|
|
model = &pandataModel{module: this.module, model: this.DBModel}
|
|
}
|
|
return
|
|
}
|
|
|
|
//校验好友木桩解锁
|
|
func (this *modelPandata) checkFriendPillar(room *pb.DBPracticeRoom) bool {
|
|
if room.Pillarf.Isunlock == 2 {
|
|
return false
|
|
}
|
|
|
|
if room.Pillar1.Isunlock != 2 && room.Pillar2.Isunlock != 2 && room.Pillar3.Isunlock != 2 {
|
|
return false
|
|
}
|
|
|
|
friendnum := this.module.ModuleFriend.GetFriendCount(room.Uid)
|
|
if friendnum > 10 {
|
|
room.Pillarf.Isunlock = 2
|
|
room.Pillarf.Lv = room.Pillar1.Lv
|
|
if room.Pillarf.Lv < room.Pillar2.Lv {
|
|
room.Pillarf.Lv = room.Pillar2.Lv
|
|
}
|
|
if room.Pillarf.Lv < room.Pillar3.Lv {
|
|
room.Pillarf.Lv = room.Pillar3.Lv
|
|
}
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// 埋点专属模型 会封装特殊的数据转换接口
|
|
type pandataModel struct {
|
|
module *Practice
|
|
model *db.DBModel
|
|
}
|
|
|
|
// /询用户的练功房信息
|
|
func (this *pandataModel) queryUserMartialhall(uid string) (result *pb.DBPracticeRoom, err error) {
|
|
result = &pb.DBPracticeRoom{}
|
|
if err = this.model.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]*pb.DBPracticeRes),
|
|
Gymaction: 0,
|
|
Gymrefresh: 0,
|
|
Pillar1: &pb.DBPracticePillar{Index: 1, Isunlock: 0, Lv: 1},
|
|
Pillar2: &pb.DBPracticePillar{Index: 2, Lv: 1},
|
|
Pillar3: &pb.DBPracticePillar{Index: 3, Lv: 1},
|
|
Pillarf: &pb.DBPracticePillar{Index: 4, Isunlock: 0, Lv: 1},
|
|
Statuers: make([]*pb.DBPracticeStatuer, 0),
|
|
Npcstate: -1,
|
|
Refresh: configure.Now().Unix(),
|
|
}
|
|
// if err = this.refreshnpc(result); err != nil {
|
|
// this.module.Errorln(err)
|
|
// return
|
|
// }
|
|
if err = this.model.Add(uid, result); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if err = this.module.atlas.CheckActivatePandaAtlasCollect(uid, "100001"); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
err = nil
|
|
return
|
|
}
|
|
func (this *pandataModel) queryrooms(uids []string) (results []*pb.DBPracticeRoom, err error) {
|
|
results = make([]*pb.DBPracticeRoom, 0)
|
|
var (
|
|
onfound []string
|
|
newdata map[string]interface{} = make(map[string]interface{})
|
|
)
|
|
if onfound, err = this.model.Gets(uids, &results); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if len(onfound) > 0 {
|
|
for _, v := range onfound {
|
|
temp := &pb.DBPracticeRoom{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: v,
|
|
Full: make(map[int32]int32),
|
|
Knapsack: make(map[string]*pb.DBPracticeRes),
|
|
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),
|
|
Npcstate: 3,
|
|
Refresh: configure.Now().Unix(),
|
|
}
|
|
go this.module.atlas.CheckActivatePandaAtlasCollect(v, "100001")
|
|
newdata[v] = temp
|
|
results = append(results, temp)
|
|
}
|
|
if err = this.model.Adds(newdata); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//校验好友木桩解锁
|
|
func (this *pandataModel) checkFriendPillar(room *pb.DBPracticeRoom) bool {
|
|
if room.Pillarf.Isunlock == 2 {
|
|
return false
|
|
}
|
|
|
|
if room.Pillar1.Isunlock != 2 && room.Pillar2.Isunlock != 2 && room.Pillar3.Isunlock != 2 {
|
|
return false
|
|
}
|
|
|
|
friendnum := this.module.ModuleFriend.GetFriendCount(room.Uid)
|
|
if friendnum > 10 {
|
|
room.Pillarf.Isunlock = 2
|
|
room.Pillarf.Lv = room.Pillar1.Lv
|
|
if room.Pillarf.Lv < room.Pillar2.Lv {
|
|
room.Pillarf.Lv = room.Pillar2.Lv
|
|
}
|
|
if room.Pillarf.Lv < room.Pillar3.Lv {
|
|
room.Pillarf.Lv = room.Pillar3.Lv
|
|
}
|
|
return true
|
|
}
|
|
return false
|
|
}
|