136 lines
3.5 KiB
Go
136 lines
3.5 KiB
Go
package capturesheep
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/lego/utils/container/id"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"math/rand"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type ModelCaptureSheep struct {
|
|
modules.MCompModel
|
|
module *CaptureSheep
|
|
}
|
|
|
|
func (this *ModelCaptureSheep) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.TableName = comm.TableCapturesheep
|
|
this.module = module.(*CaptureSheep)
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
// 查询用户装备数据
|
|
// 获取用户全部的埋点数据
|
|
func (this *ModelCaptureSheep) queryInfo(uid string) (results *pb.DBCaptureSheep, err error) {
|
|
results = &pb.DBCaptureSheep{}
|
|
if err = this.Get(uid, results); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
results = &pb.DBCaptureSheep{
|
|
Uid: uid,
|
|
Weekreward: map[int32]bool{},
|
|
}
|
|
if results.Dan, err = this.computedan(results.Integral); err != nil {
|
|
return
|
|
}
|
|
err = this.Add(uid, results)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取目标去陪数据
|
|
func (this *ModelCaptureSheep) matchePlayer(uid string, dan, num int32) (results []*pb.CaptureSheepRaceMember, err error) {
|
|
var (
|
|
cursor *mongo.Cursor
|
|
)
|
|
results = make([]*pb.CaptureSheepRaceMember, 0)
|
|
port := []float64{float64(dan), float64(rand.Int31n(100)) / 1000.0}
|
|
if cursor, err = this.DBModel.DB.Find(comm.TableArena, bson.M{
|
|
"isdef": true,
|
|
"uid": bson.M{"$ne": uid},
|
|
"dan": dan,
|
|
"loc": bson.M{
|
|
"$near": bson.M{
|
|
"$geometry": bson.M{"type": "Point", "coordinates": port},
|
|
"$maxDistance": 100000,
|
|
},
|
|
},
|
|
}, options.Find().SetSkip(0).SetLimit(int64(num))); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
} else {
|
|
for cursor.Next(context.Background()) {
|
|
temp := &pb.DBCaptureSheep{}
|
|
if err = cursor.Decode(temp); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
results = append(results, &pb.CaptureSheepRaceMember{
|
|
Uid: temp.Uid,
|
|
Name: temp.Name,
|
|
Skin: temp.Skin,
|
|
})
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 匹配机器人
|
|
func (this *ModelCaptureSheep) matcheAI(dan, num int32) (results []*pb.CaptureSheepRaceMember, err error) {
|
|
var (
|
|
robots []*cfg.GameRobotData
|
|
dragon *pb.DBDragon
|
|
)
|
|
results = make([]*pb.CaptureSheepRaceMember, num)
|
|
if robots, err = this.module.ModuleTools.RandRobotConfig(num); err != nil {
|
|
return
|
|
}
|
|
for i, v := range robots {
|
|
if dragon, err = this.module.dragon.CreateRobotDragon(v.Mtsid.T, v.Mtsid.N); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
results[i] = &pb.CaptureSheepRaceMember{
|
|
Uid: fmt.Sprintf("ai_%s", id.NewXId()),
|
|
Name: v.Name,
|
|
Sex: v.Sex,
|
|
Skin: v.Showid,
|
|
Mount: dragon.Dragonid,
|
|
Mlv: dragon.Lv,
|
|
Maxhp: dragon.Property[comm.Dhp],
|
|
Currhp: dragon.Property[comm.Dhp],
|
|
Isai: true,
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *ModelCaptureSheep) computedan(integral int32) (dan int32, err error) {
|
|
var (
|
|
active *cfg.GameQualifyingData
|
|
)
|
|
|
|
if active, err = this.module.configure.getActiveReward(integral); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
dan = active.LvId
|
|
return
|
|
}
|