142 lines
3.8 KiB
Go
142 lines
3.8 KiB
Go
package hunting
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/db"
|
|
"strconv"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
type Hunting struct {
|
|
modules.ModuleBase
|
|
modelHunting *modelHunting
|
|
api *apiComp
|
|
configure *configureComp
|
|
modulerank *ModelRank
|
|
battle comm.IBattle
|
|
service core.IService
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &Hunting{}
|
|
}
|
|
|
|
func (this *Hunting) GetType() core.M_Modules {
|
|
return comm.ModuleHunting
|
|
}
|
|
|
|
func (this *Hunting) 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 *Hunting) 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 *Hunting) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelHunting = this.RegisterComp(new(modelHunting)).(*modelHunting)
|
|
this.modulerank = this.RegisterComp(new(ModelRank)).(*ModelRank)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
// 接口信息
|
|
func (this *Hunting) ModifyHuntingData(uid string, data map[string]interface{}) (code pb.ErrorCode) {
|
|
err := this.modelHunting.modifyHuntingDataByObjId(uid, data)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *Hunting) CheckUserBaseHuntingInfo(uid string) (data []*pb.DBHuntingRank) {
|
|
list, err := this.modelHunting.getHuntingList(uid)
|
|
if err != nil {
|
|
for k := range list.Boss {
|
|
_d := this.modulerank.getHuntingRankListByBossType(uid, k)
|
|
if _d != nil {
|
|
data = append(data, _d)
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
func (this *Hunting) CheckRank(uid string, boosID int32, difficulty int32, hunting *pb.DBHunting, report *pb.BattleReport) {
|
|
costTime := report.Costtime
|
|
key := strconv.Itoa(int(boosID)) + "_" + strconv.Itoa(int(difficulty))
|
|
|
|
if hunting.BossTime[key] > costTime || hunting.BossTime[key] == 0 && difficulty >= hunting.Boss[boosID] { // 刷新记录
|
|
hunting.BossTime[key] = costTime
|
|
szLine := make([]*pb.LineUp, 5)
|
|
Leadpos := 0
|
|
if report != nil && report.Info != nil && len(report.Info.Redflist) > 0 {
|
|
costTime = report.Costtime
|
|
Leadpos = int(report.Info.Redflist[0].Leadpos)
|
|
for i, v := range report.Info.Redflist[0].Team {
|
|
if v != nil {
|
|
szLine[i] = &pb.LineUp{
|
|
Cid: v.HeroID,
|
|
Star: v.Star,
|
|
Lv: v.Lv,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 写入排行榜
|
|
objID := ""
|
|
bFind := false
|
|
ranks := this.modulerank.getHuntingRankList(uid)
|
|
for _, v := range ranks {
|
|
if v.Bosstype == boosID {
|
|
mapRankData := make(map[string]interface{}, 0)
|
|
mapRankData["difficulty"] = difficulty
|
|
mapRankData["bosstype"] = boosID
|
|
mapRankData["Leadpos"] = Leadpos
|
|
mapRankData["line"] = szLine
|
|
mapRankData["costTime"] = costTime
|
|
conn_, _ := db.Cross()
|
|
dbModel := db.NewDBModel(comm.TableHuntingRank, time.Hour, conn_)
|
|
dbModel.ChangeList(uid, v.Id, mapRankData)
|
|
objID = v.Id
|
|
bFind = true
|
|
break
|
|
}
|
|
}
|
|
if !bFind {
|
|
userinfo := this.ModuleUser.GetUser(uid)
|
|
new := &pb.DBHuntingRank{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Difficulty: difficulty,
|
|
Bosstype: boosID,
|
|
Nickname: userinfo.Name,
|
|
Icon: "",
|
|
Lv: userinfo.Lv,
|
|
Leadpos: int32(Leadpos),
|
|
Line: szLine,
|
|
CostTime: costTime,
|
|
}
|
|
objID = new.Id
|
|
conn_, _ := db.Cross()
|
|
dbModel := db.NewDBModel(comm.TableHuntingRank, time.Hour, conn_)
|
|
dbModel.AddList(uid, new.Id, new)
|
|
}
|
|
this.modulerank.SetRankListData("huntingRank"+strconv.Itoa(int(boosID)), difficulty<<16+costTime, objID)
|
|
}
|
|
}
|