77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
package viking
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/redis"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelViking struct {
|
|
modules.MCompModel
|
|
module *Viking
|
|
}
|
|
|
|
func (this *modelViking) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableViking)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Viking)
|
|
// uid 创建索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *modelViking) getVikingList(uid string) (result *pb.DBViking, err error) {
|
|
result = &pb.DBViking{}
|
|
if err = this.Get(uid, result); err != nil && redis.RedisNil != err {
|
|
return
|
|
}
|
|
err = nil
|
|
return result, err
|
|
}
|
|
|
|
func (this *modelViking) modifyVikingDataByObjId(uid string, data map[string]interface{}) error {
|
|
return this.Change(uid, data)
|
|
}
|
|
|
|
// todo 调用drop 表 获取掉落信息
|
|
func (this *modelViking) GetDropReward(count, dropId int32, Items []*pb.UserAssets) {
|
|
res := make([]*cfg.Gameatn, 0)
|
|
for i := 0; i < int(count); i++ {
|
|
data := this.module.configure.GetDropData(dropId)
|
|
szW := make([]int32, 0)
|
|
for _, value := range data {
|
|
szW = append(szW, value.P)
|
|
}
|
|
if len(szW) > 0 {
|
|
index := comm.GetRandW(szW)
|
|
res = append(res, data[index].Prize...)
|
|
}
|
|
}
|
|
for _, v := range res {
|
|
bFind := false
|
|
for _, v1 := range Items {
|
|
if v.A == v1.A && v.T == v1.T {
|
|
v1.N += v.N
|
|
bFind = true
|
|
}
|
|
}
|
|
if !bFind {
|
|
Items = append(Items, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|