158 lines
3.9 KiB
Go
158 lines
3.9 KiB
Go
package enchant
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/redis/pipe"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/db"
|
|
"strconv"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
type Enchant struct {
|
|
modules.ModuleBase
|
|
modelEnchant *modelEnchant
|
|
api *apiComp
|
|
configure *configureComp
|
|
modulerank *ModelRank
|
|
battle comm.IBattle
|
|
service core.IService
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &Enchant{}
|
|
}
|
|
|
|
func (this *Enchant) GetType() core.M_Modules {
|
|
return comm.ModuleEnchant
|
|
}
|
|
|
|
func (this *Enchant) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
func (this *Enchant) Start() (err error) {
|
|
err = this.ModuleBase.Start()
|
|
var module core.IModule
|
|
if module, err = this.service.GetModule(comm.ModuleBattle); err != nil {
|
|
return
|
|
}
|
|
|
|
this.battle = module.(comm.IBattle)
|
|
return
|
|
}
|
|
|
|
func (this *Enchant) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelEnchant = this.RegisterComp(new(modelEnchant)).(*modelEnchant)
|
|
this.modulerank = this.RegisterComp(new(ModelRank)).(*ModelRank)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
// 接口信息
|
|
func (this *Enchant) ModifyEnchantData(uid string, data map[string]interface{}) (code pb.ErrorCode) {
|
|
err := this.modelEnchant.modifyEnchantDataByObjId(uid, data)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *Enchant) CheckUserBaseEnchantInfo(uid string) (data []*pb.DBEnchantRank) {
|
|
list, err := this.modelEnchant.getEnchantList(uid)
|
|
if err != nil {
|
|
for k := range list.Boss {
|
|
_d := this.modulerank.getEnchantRankListByBossType(uid, k)
|
|
if _d != nil {
|
|
data = append(data, _d)
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
func (this *Enchant) CheckRank(uid string, boosID int32, report *pb.BattleReport, userinfo *pb.DBUser, score int64) {
|
|
conn_, _ := db.Cross() // 获取跨服数据库对象
|
|
|
|
model := db.NewDBModel(comm.TableEnchantRank, 0, conn_)
|
|
|
|
costTime := report.Costtime
|
|
szLine := make([]*pb.LineUp, len(report.Info.Redflist[0].Team))
|
|
Leadpos := 0
|
|
if report != nil && report.Info != nil && len(report.Info.Redflist) > 0 {
|
|
costTime = report.Costtime
|
|
Leadpos = int(report.Info.Redflist[0].Leadpos)
|
|
for _, v := range report.Info.Redflist[0].Team {
|
|
if v != nil {
|
|
szLine = append(szLine, &pb.LineUp{
|
|
Cid: v.HeroID,
|
|
Star: v.Star,
|
|
Lv: v.Lv,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
// 写入排行榜
|
|
objID := ""
|
|
bFind := false
|
|
ranks := this.modulerank.getEnchantRankList(uid)
|
|
for _, v := range ranks {
|
|
if v.Bosstype == boosID {
|
|
mapRankData := make(map[string]interface{}, 0)
|
|
mapRankData["bosstype"] = boosID
|
|
mapRankData["Leadpos"] = Leadpos
|
|
mapRankData["line"] = szLine
|
|
mapRankData["costTime"] = costTime
|
|
mapRankData["score"] = score
|
|
|
|
model.ChangeList(uid, v.Id, mapRankData)
|
|
objID = v.Id
|
|
bFind = true
|
|
break
|
|
}
|
|
}
|
|
if !bFind {
|
|
userinfo := this.ModuleUser.GetUser(uid)
|
|
new := &pb.DBEnchantRank{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Bosstype: boosID,
|
|
Nickname: userinfo.Name,
|
|
Lv: userinfo.Lv,
|
|
Leadpos: int32(Leadpos),
|
|
Line: szLine,
|
|
CostTime: costTime,
|
|
Score: score,
|
|
}
|
|
objID = new.Id
|
|
model.AddList(uid, new.Id, new)
|
|
}
|
|
var (
|
|
pipe *pipe.RedisPipe = conn_.Redis.RedisPipe(context.TODO())
|
|
menbers *redis.Z
|
|
tableName string
|
|
)
|
|
tableName = "enchantRank" + strconv.Itoa(int(boosID))
|
|
strKey := "enchantRank:" + uid + "-" + objID
|
|
menbers = &redis.Z{Score: float64(costTime), Member: strKey}
|
|
|
|
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
|
|
|
|
dock, err1 := cmd.Result()
|
|
if err1 != nil {
|
|
this.Errorln(dock, err1)
|
|
}
|
|
}
|
|
if _, err := pipe.Exec(); err != nil {
|
|
this.Errorln(err)
|
|
return
|
|
}
|
|
}
|