狩猎 初始化数据

This commit is contained in:
meixiongfeng 2022-12-21 15:01:25 +08:00
parent ea0f567361
commit 93b049704e
6 changed files with 42 additions and 29 deletions

View File

@ -88,8 +88,8 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HuntingBuyReq) (code
list.RecoveryTime = 0 list.RecoveryTime = 0
} }
addCount += req.Count addCount += req.Count
if amount+addCount > conf.VikingNum { if amount+addCount > conf.HuntingNum {
code = pb.ErrorCode_VikingBuyMaxCount code = pb.ErrorCode_HuntingBuyMaxCount
return return
} }
mapData["recoveryTime"] = list.RecoveryTime mapData["recoveryTime"] = list.RecoveryTime

View File

@ -44,10 +44,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.HuntingChallen
code = pb.ErrorCode_HuntingNoChallengeCount code = pb.ErrorCode_HuntingNoChallengeCount
return return
} }
// if hunting.ChallengeCount > this.module.configure.GetGlobalConf().HuntingNum+hunting.BuyCount {
// code = pb.ErrorCode_HuntingMaxChallengeCount
// return
// }
cfgData := this.module.configure.GetHuntingBossConfigData(req.BossType, req.Difficulty) cfgData := this.module.configure.GetHuntingBossConfigData(req.BossType, req.Difficulty)
if cfgData == nil { if cfgData == nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound

View File

@ -2,11 +2,14 @@ package hunting
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"strconv"
"go.mongodb.org/mongo-driver/bson/primitive"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -28,7 +31,38 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.HuntingGetListRe
} }
list, err := this.module.modelHunting.getHuntingList(session.GetUserId()) list, err := this.module.modelHunting.getHuntingList(session.GetUserId())
if err != nil { if mgo.MongodbNil == err {
result := &pb.DBHunting{
Id: primitive.NewObjectID().Hex(),
Uid: session.GetUserId(),
Boss: make(map[int32]int32),
BossTime: make(map[string]int32),
}
_cfg := this.module.configure.GetHuntingBossTypeConfigData()
for k := range _cfg {
result.Boss[k] = 0
str := strconv.Itoa(int(k)) + "_1"
result.BossTime[str] = 0
}
this.module.modelHunting.Add(session.GetUserId(), result)
conf := this.module.configure.GetGlobalConf()
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
iCont := conf.EnchantbossInitial
atn := conf.EnchantbossCos
if iCont > 0 {
this.module.DispenseRes(session, []*cfg.Gameatn{&cfg.Gameatn{
A: atn.A,
T: atn.T,
N: iCont,
}}, true)
}
} else if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }

View File

@ -6,9 +6,7 @@ import (
"go_dreamfactory/lego/sys/mgo" "go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"strconv"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx" "go.mongodb.org/mongo-driver/x/bsonx"
) )
@ -35,27 +33,11 @@ func (this *modelHunting) modifyHuntingDataByObjId(uid string, data map[string]i
// 获取列表信息 // 获取列表信息
func (this *modelHunting) getHuntingList(uid string) (result *pb.DBHunting, err error) { func (this *modelHunting) getHuntingList(uid string) (result *pb.DBHunting, err error) {
result = &pb.DBHunting{ result = &pb.DBHunting{}
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Boss: make(map[int32]int32),
BossTime: make(map[string]int32),
}
if err = this.Get(uid, result); err != nil && mgo.MongodbNil != err { if err = this.Get(uid, result); err != nil && mgo.MongodbNil != err {
return return
} }
if mgo.MongodbNil == err {
if len(result.Boss) == 0 {
_cfg := this.module.configure.GetHuntingBossTypeConfigData()
for k := range _cfg {
result.Boss[k] = 0
str := strconv.Itoa(int(k)) + "_1"
result.BossTime[str] = 0
}
}
this.Add(uid, result)
}
err = nil err = nil
return result, err return result, err
} }

View File

@ -69,7 +69,7 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.VikingBuyReq) (code
if list.RecoveryTime+int64(conf.VikingExpeditionRecoveryTime*60) <= configure.Now().Unix() { if list.RecoveryTime+int64(conf.VikingExpeditionRecoveryTime*60) <= configure.Now().Unix() {
curCount++ curCount++
list.RecoveryTime += int64(conf.VikingExpeditionRecoveryTime * 60) list.RecoveryTime += int64(conf.VikingExpeditionRecoveryTime * 60)
if curCount >= conf.HuntingNum { if curCount >= conf.VikingNum {
list.RecoveryTime = 0 list.RecoveryTime = 0
break break
} }

View File

@ -63,7 +63,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.VikingGetListReq
if list.RecoveryTime+int64(conf.VikingExpeditionRecoveryTime*60) <= configure.Now().Unix() { if list.RecoveryTime+int64(conf.VikingExpeditionRecoveryTime*60) <= configure.Now().Unix() {
curCount++ curCount++
list.RecoveryTime += int64(conf.VikingExpeditionRecoveryTime * 60) list.RecoveryTime += int64(conf.VikingExpeditionRecoveryTime * 60)
if curCount >= conf.HuntingNum { if curCount >= conf.VikingNum {
list.RecoveryTime = 0 list.RecoveryTime = 0
break break
} }