刷新挑战卷
This commit is contained in:
parent
b331ac8ddb
commit
f8e1f5fa84
@ -3,9 +3,6 @@ package enchant
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"go_dreamfactory/utils"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@ -19,119 +16,9 @@ func (this *apiComp) BuyCheck(session comm.IUserSession, req *pb.EnchantBuyReq)
|
||||
return
|
||||
}
|
||||
|
||||
// 协议废除 走通用购买逻辑
|
||||
func (this *apiComp) Buy(session comm.IUserSession, req *pb.EnchantBuyReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
curByCount int32
|
||||
costRes *cfg.Gameatn // 门票atn 类型 只取T
|
||||
mapData map[string]interface{}
|
||||
szCostRes []*cfg.Gameatn // 购买累计消耗
|
||||
curCount int32 // 当前门票数量
|
||||
addCount int32 //获得数量
|
||||
)
|
||||
mapData = make(map[string]interface{}, 0)
|
||||
code = this.BuyCheck(session, req)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
list, err := this.module.modelEnchant.getEnchantList(session.GetUserId())
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
|
||||
// 校验是不是今天
|
||||
if !utils.IsToday(list.CTime) {
|
||||
list.CTime = configure.Now().Unix()
|
||||
list.BuyCount = 0
|
||||
mapData["cTime"] = list.CTime
|
||||
mapData["buyCount"] = list.BuyCount
|
||||
} else {
|
||||
curByCount = list.BuyCount
|
||||
}
|
||||
curByCount += req.Count // 当前需要购买的数量
|
||||
if this.configure.GetMaxBuyChallengeCount() < curByCount {
|
||||
code = pb.ErrorCode_EnchantBuyMaxCount
|
||||
return
|
||||
}
|
||||
conf := this.module.configure.GetGlobalConf()
|
||||
if conf == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
costRes = conf.EnchantbossCos
|
||||
if costRes == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
|
||||
curCount = amount
|
||||
if amount < conf.EnchantbossMax {
|
||||
if list.RecoveryTime == 0 {
|
||||
list.RecoveryTime = configure.Now().Unix()
|
||||
}
|
||||
for { // 计算恢复时间
|
||||
if list.RecoveryTime+int64(conf.EnchantbossRecovery*60) <= configure.Now().Unix() {
|
||||
curCount++
|
||||
list.RecoveryTime += int64(conf.EnchantbossRecovery * 60)
|
||||
if curCount >= conf.EnchantbossMax {
|
||||
list.RecoveryTime = 0
|
||||
break
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if curCount-amount > 0 {
|
||||
addCount = curCount - amount
|
||||
}
|
||||
} else {
|
||||
list.RecoveryTime = 0
|
||||
}
|
||||
addCount += req.Count
|
||||
if amount+addCount > conf.EnchantbossMax {
|
||||
code = pb.ErrorCode_EnchantBuyMaxCount
|
||||
return
|
||||
}
|
||||
mapData["recoveryTime"] = list.RecoveryTime
|
||||
|
||||
for i := list.BuyCount + 1; i <= curByCount; i++ {
|
||||
_cfg := this.configure.GetBuyChallengeCount(i)
|
||||
if _cfg == nil {
|
||||
code = pb.ErrorCode_EnchantBuyMaxCount
|
||||
return
|
||||
}
|
||||
szCostRes = append(szCostRes, _cfg.Need...)
|
||||
}
|
||||
sz := make([]*cfg.Gameatn, 0)
|
||||
for _, v := range szCostRes {
|
||||
bFound := false
|
||||
for _, v1 := range sz {
|
||||
if v.A == v1.A && v.T == v1.T {
|
||||
v1.N += v.N
|
||||
bFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !bFound {
|
||||
sz = append(sz, v)
|
||||
}
|
||||
}
|
||||
//消耗
|
||||
if code = this.module.ConsumeRes(session, sz, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
res := &cfg.Gameatn{
|
||||
A: "item",
|
||||
T: costRes.T,
|
||||
N: addCount,
|
||||
}
|
||||
if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
list.BuyCount = curByCount
|
||||
mapData["buyCount"] = curByCount
|
||||
code = this.module.ModifyEnchantData(session.GetUserId(), mapData)
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), EnchantBuyResp, &pb.EnchantBuyResp{Data: list})
|
||||
session.SendMsg(string(this.module.GetType()), EnchantBuyResp, &pb.EnchantBuyResp{})
|
||||
return
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package enchant
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@ -30,26 +29,21 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.EnchantChallen
|
||||
code = pb.ErrorCode_PagodaNotFound
|
||||
return
|
||||
}
|
||||
conf := this.module.configure.GetGlobalConf()
|
||||
if conf == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
costRes := conf.EnchantbossCos
|
||||
if costRes == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
if code = this.module.CheckRes(session, []*cfg.Gameatn{costRes}); code != pb.ErrorCode_Success {
|
||||
code = pb.ErrorCode_EnchantNoChallengeCount
|
||||
return
|
||||
}
|
||||
|
||||
cfgData := this.module.configure.GetEnchantBossConfigData(req.BossType)
|
||||
if cfgData == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
if len(cfgData) <= 0 {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
if code = this.module.CheckRes(session, cfgData[0].PsConsume); code != pb.ErrorCode_Success {
|
||||
|
||||
code = pb.ErrorCode_VikingMaxChallengeCount
|
||||
return
|
||||
}
|
||||
_, ok := enchant.Boss[req.BossType]
|
||||
if !ok { // 类型校验
|
||||
enchant.Boss[req.BossType] = 0
|
||||
|
@ -3,8 +3,6 @@ package enchant
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@ -37,21 +35,6 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.EnchantCha
|
||||
code = pb.ErrorCode_PagodaNotFound
|
||||
return
|
||||
}
|
||||
conf := this.module.configure.GetGlobalConf()
|
||||
if conf == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
costRes := conf.EnchantbossCos
|
||||
if costRes == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
|
||||
if code = this.module.CheckRes(session, []*cfg.Gameatn{costRes}); code != pb.ErrorCode_Success {
|
||||
code = pb.ErrorCode_EnchantNoChallengeCount
|
||||
return
|
||||
}
|
||||
|
||||
cfgEnchant := this.module.configure.GetEnchantBossConfigData(req.BossType)
|
||||
if cfgEnchant == nil {
|
||||
@ -59,21 +42,21 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.EnchantCha
|
||||
return
|
||||
}
|
||||
|
||||
// 校验门票数量够不够
|
||||
if code = this.module.ConsumeRes(session, []*cfg.Gameatn{costRes}, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
// check
|
||||
code, bWin = this.module.battle.CheckBattleReport(session, req.Report)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
|
||||
amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
|
||||
|
||||
if amount < conf.EnchantbossMax { // 挑战卷 小于副本最大存储数的时候开始恢复
|
||||
enchant.RecoveryTime = configure.Now().Unix()
|
||||
mapData["recoveryTime"] = enchant.RecoveryTime
|
||||
if !bWin { // 战斗失败了 直接返回
|
||||
if code = this.module.ConsumeRes(session, cfgEnchant[0].PsMg, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), EnchantChallengeOverResp, &pb.EnchantChallengeOverResp{Data: enchant})
|
||||
return
|
||||
}
|
||||
if code = this.module.ConsumeRes(session, cfgEnchant[0].PsConsume, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
if bWin {
|
||||
this.module.CheckRank(session.GetUserId(), req.BossType, enchant, req.Report, req.Score)
|
||||
|
@ -4,9 +4,6 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/mgo"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"go_dreamfactory/utils"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"google.golang.org/protobuf/proto"
|
||||
@ -19,16 +16,17 @@ func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.EnchantGetL
|
||||
}
|
||||
|
||||
func (this *apiComp) GetList(session comm.IUserSession, req *pb.EnchantGetListReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
mapData map[string]interface{}
|
||||
curCount int32
|
||||
)
|
||||
mapData = make(map[string]interface{}, 0)
|
||||
|
||||
code = this.GetListCheck(session, req)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
|
||||
// 刷新挑战卷
|
||||
if code = this.module.ModuleItems.RecoverTicket(session); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
|
||||
list, err := this.module.modelEnchant.getEnchantList(session.GetUserId())
|
||||
if mgo.MongodbNil == err {
|
||||
|
||||
@ -43,79 +41,11 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.EnchantGetListRe
|
||||
}
|
||||
|
||||
this.module.modelEnchant.Add(session.GetUserId(), list)
|
||||
conf := this.module.configure.GetGlobalConf()
|
||||
if conf == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
iCont := conf.EnchantbossInitial
|
||||
atn := conf.EnchantbossCos
|
||||
if iCont > 0 {
|
||||
res := &cfg.Gameatn{
|
||||
A: atn.A,
|
||||
T: atn.T,
|
||||
N: iCont,
|
||||
}
|
||||
this.module.DispenseRes(session, []*cfg.Gameatn{res}, true)
|
||||
}
|
||||
|
||||
} else if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
// 校验 是不是当天
|
||||
if !utils.IsToday(list.CTime) {
|
||||
list.CTime = configure.Now().Unix()
|
||||
list.BuyCount = 0
|
||||
mapData["cTime"] = list.CTime
|
||||
mapData["buyCount"] = list.BuyCount
|
||||
|
||||
}
|
||||
// 检查恢复时间
|
||||
conf := this.module.configure.GetGlobalConf()
|
||||
if conf == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
costRes := conf.EnchantbossCos
|
||||
if costRes == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
|
||||
curCount = amount
|
||||
if amount < conf.EnchantbossMax {
|
||||
if list.RecoveryTime == 0 {
|
||||
list.RecoveryTime = configure.Now().Unix()
|
||||
}
|
||||
for { // 计算恢复时间
|
||||
if list.RecoveryTime+int64(conf.EnchantbossRecovery*60) <= configure.Now().Unix() {
|
||||
curCount++
|
||||
list.RecoveryTime += int64(conf.EnchantbossRecovery * 60)
|
||||
if curCount >= conf.EnchantbossMax {
|
||||
list.RecoveryTime = 0
|
||||
break
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
addCount := curCount - amount
|
||||
if addCount > 0 {
|
||||
res := &cfg.Gameatn{
|
||||
A: "item",
|
||||
T: costRes.T,
|
||||
N: addCount,
|
||||
}
|
||||
if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
list.RecoveryTime = 0
|
||||
}
|
||||
mapData["recoveryTime"] = list.RecoveryTime
|
||||
code = this.module.ModifyEnchantData(session.GetUserId(), mapData) //修改内存信息
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), EnchantGetListResp, &pb.EnchantGetListResp{Data: list})
|
||||
return
|
||||
|
@ -3,9 +3,6 @@ package hunting
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"go_dreamfactory/utils"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@ -20,121 +17,7 @@ func (this *apiComp) BuyCheck(session comm.IUserSession, req *pb.HuntingBuyReq)
|
||||
}
|
||||
|
||||
func (this *apiComp) Buy(session comm.IUserSession, req *pb.HuntingBuyReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
curByCount int32
|
||||
costRes *cfg.Gameatn // 门票atn 类型 只取T
|
||||
mapData map[string]interface{}
|
||||
szCostRes []*cfg.Gameatn // 购买累计消耗
|
||||
curCount int32 // 当前门票数量
|
||||
addCount int32 //获得数量
|
||||
PrivilegeBuyCount int32 // 特权购买次数
|
||||
)
|
||||
mapData = make(map[string]interface{}, 0)
|
||||
code = this.BuyCheck(session, req)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
list, err := this.module.modelHunting.getHuntingList(session.GetUserId())
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
|
||||
// 校验是不是今天
|
||||
if !utils.IsToday(list.CTime) {
|
||||
list.CTime = configure.Now().Unix()
|
||||
list.BuyCount = 0
|
||||
mapData["cTime"] = list.CTime
|
||||
mapData["buyCount"] = list.BuyCount
|
||||
} else {
|
||||
curByCount = list.BuyCount
|
||||
}
|
||||
|
||||
PrivilegeBuyCount = this.module.ModulePrivilege.GetCountByPrivilegeId(session.GetUserId(), comm.PrivilegeType4)
|
||||
curByCount += req.Count // 当前需要购买的数量
|
||||
if this.configure.GetMaxBuyChallengeCount()+PrivilegeBuyCount < curByCount {
|
||||
code = pb.ErrorCode_HuntingBuyMaxCount
|
||||
return
|
||||
}
|
||||
conf := this.module.configure.GetGlobalConf()
|
||||
if conf == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
costRes = conf.HuntingCos
|
||||
if costRes == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
|
||||
curCount = amount
|
||||
if amount < conf.HuntingNum {
|
||||
if list.RecoveryTime == 0 {
|
||||
list.RecoveryTime = configure.Now().Unix()
|
||||
}
|
||||
for { // 计算恢复时间
|
||||
if list.RecoveryTime+int64(conf.HuntingRecovery*60) <= configure.Now().Unix() {
|
||||
curCount++
|
||||
list.RecoveryTime += int64(conf.HuntingRecovery * 60)
|
||||
if curCount >= conf.HuntingNum {
|
||||
list.RecoveryTime = 0
|
||||
break
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if curCount-amount > 0 {
|
||||
addCount = curCount - amount
|
||||
}
|
||||
} else {
|
||||
list.RecoveryTime = 0
|
||||
}
|
||||
addCount += req.Count
|
||||
if amount+addCount > conf.HuntingNum {
|
||||
code = pb.ErrorCode_HuntingBuyMaxCount
|
||||
return
|
||||
}
|
||||
mapData["recoveryTime"] = list.RecoveryTime
|
||||
|
||||
for i := list.BuyCount + 1; i <= curByCount; i++ {
|
||||
_cfg := this.configure.GetBuyChallengeCount(i)
|
||||
if _cfg == nil {
|
||||
// 取最后一条
|
||||
_cfg = this.configure.GetLastBuyChallenge()
|
||||
}
|
||||
szCostRes = append(szCostRes, _cfg.Need...)
|
||||
}
|
||||
sz := make([]*cfg.Gameatn, 0)
|
||||
for _, v := range szCostRes {
|
||||
bFound := false
|
||||
for _, v1 := range sz {
|
||||
if v.A == v1.A && v.T == v1.T {
|
||||
v1.N += v.N
|
||||
bFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !bFound {
|
||||
sz = append(sz, v)
|
||||
}
|
||||
}
|
||||
//消耗
|
||||
if code = this.module.ConsumeRes(session, sz, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
res := &cfg.Gameatn{
|
||||
A: "item",
|
||||
T: costRes.T,
|
||||
N: addCount,
|
||||
}
|
||||
if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
list.BuyCount = curByCount
|
||||
mapData["buyCount"] = curByCount
|
||||
code = this.module.ModifyHuntingData(session.GetUserId(), mapData)
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), HuntingBuyResp, &pb.HuntingBuyResp{Data: list})
|
||||
session.SendMsg(string(this.module.GetType()), HuntingBuyResp, &pb.HuntingBuyResp{})
|
||||
return
|
||||
}
|
||||
|
@ -4,9 +4,6 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/mgo"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"go_dreamfactory/utils"
|
||||
"strconv"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@ -20,16 +17,15 @@ func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.HuntingGetL
|
||||
}
|
||||
|
||||
func (this *apiComp) GetList(session comm.IUserSession, req *pb.HuntingGetListReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
mapData map[string]interface{}
|
||||
curCount int32
|
||||
)
|
||||
mapData = make(map[string]interface{}, 0)
|
||||
|
||||
code = this.GetListCheck(session, req)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
|
||||
// 刷新挑战卷
|
||||
if code = this.module.ModuleItems.RecoverTicket(session); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
list, err := this.module.modelHunting.getHuntingList(session.GetUserId())
|
||||
if mgo.MongodbNil == err {
|
||||
list = &pb.DBHunting{
|
||||
@ -46,80 +42,13 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.HuntingGetListRe
|
||||
}
|
||||
|
||||
this.module.modelHunting.Add(session.GetUserId(), list)
|
||||
conf := this.module.configure.GetGlobalConf()
|
||||
if conf == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
iCont := conf.HuntingNum
|
||||
atn := conf.HuntingCos
|
||||
if iCont > 0 {
|
||||
res := &cfg.Gameatn{
|
||||
A: atn.A,
|
||||
T: atn.T,
|
||||
N: iCont,
|
||||
}
|
||||
this.module.DispenseRes(session, []*cfg.Gameatn{res}, true)
|
||||
}
|
||||
|
||||
} else if err != nil {
|
||||
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
// 校验 是不是当天
|
||||
if !utils.IsToday(list.CTime) {
|
||||
list.CTime = configure.Now().Unix()
|
||||
list.BuyCount = 0
|
||||
mapData["cTime"] = list.CTime
|
||||
mapData["buyCount"] = list.BuyCount
|
||||
|
||||
}
|
||||
// 检查恢复时间
|
||||
conf := this.module.configure.GetGlobalConf()
|
||||
if conf == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
costRes := conf.HuntingCos
|
||||
if costRes == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
|
||||
curCount = amount
|
||||
if amount < conf.HuntingNum {
|
||||
if list.RecoveryTime == 0 {
|
||||
list.RecoveryTime = configure.Now().Unix()
|
||||
}
|
||||
for { // 计算恢复时间
|
||||
if list.RecoveryTime+int64(conf.HuntingRecovery*60) <= configure.Now().Unix() {
|
||||
curCount++
|
||||
list.RecoveryTime += int64(conf.HuntingRecovery * 60)
|
||||
if curCount >= conf.HuntingNum {
|
||||
list.RecoveryTime = 0
|
||||
break
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
addCount := curCount - amount
|
||||
if addCount > 0 {
|
||||
res := &cfg.Gameatn{
|
||||
A: "item",
|
||||
T: costRes.T,
|
||||
N: addCount,
|
||||
}
|
||||
if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
list.RecoveryTime = 0
|
||||
}
|
||||
mapData["recoveryTime"] = list.RecoveryTime
|
||||
code = this.module.ModifyHuntingData(session.GetUserId(), mapData) //修改内存信息
|
||||
session.SendMsg(string(this.module.GetType()), HuntingGetListResp, &pb.HuntingGetListResp{Data: list})
|
||||
return
|
||||
}
|
||||
|
@ -66,11 +66,11 @@ func (this *SeasonPagoda) Start() (err error) {
|
||||
if db.IsCross() {
|
||||
return
|
||||
}
|
||||
time.Sleep(time.Second * 1)
|
||||
//time.Sleep(time.Second * 1)
|
||||
//this.DbTest()
|
||||
conn, err := db.Cross()
|
||||
if err == nil {
|
||||
this.DbTest()
|
||||
//this.DbTest()
|
||||
model := db.NewDBModel(comm.TableServerData, 0, conn)
|
||||
|
||||
_len, err1 := model.DB.CountDocuments(comm.TableServerData, bson.M{})
|
||||
@ -274,7 +274,7 @@ func (this *SeasonPagoda) DbTest() {
|
||||
// szRank = append(szRank, v2)
|
||||
// }
|
||||
}
|
||||
this.module.Debugf("%v", szRank)
|
||||
//this.module.Debugf("%v", szRank)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,9 +3,6 @@ package viking
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"go_dreamfactory/utils"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@ -19,124 +16,9 @@ func (this *apiComp) BuyCheck(session comm.IUserSession, req *pb.VikingBuyReq) (
|
||||
return
|
||||
}
|
||||
|
||||
// 协议废弃 走通用字段
|
||||
func (this *apiComp) Buy(session comm.IUserSession, req *pb.VikingBuyReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
curByCount int32
|
||||
costRes *cfg.Gameatn
|
||||
mapData map[string]interface{}
|
||||
curCount int32 // 当前门票数量
|
||||
szcostRes []*cfg.Gameatn // 购买累计消耗
|
||||
addCount int32 //获得数量
|
||||
PrivilegeBuyCount int32 // 特权购买次数
|
||||
)
|
||||
mapData = make(map[string]interface{}, 0)
|
||||
code = this.BuyCheck(session, req)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
list, err := this.module.modelViking.getVikingList(session.GetUserId())
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
|
||||
// 校验是不是今天
|
||||
if !utils.IsToday(list.CTime) {
|
||||
list.CTime = configure.Now().Unix()
|
||||
list.BuyCount = 0
|
||||
mapData["cTime"] = list.CTime
|
||||
mapData["buyCount"] = list.BuyCount
|
||||
|
||||
} else {
|
||||
curByCount = list.BuyCount
|
||||
}
|
||||
PrivilegeBuyCount = this.module.ModulePrivilege.GetCountByPrivilegeId(session.GetUserId(), comm.PrivilegeType3)
|
||||
|
||||
conf := this.module.configure.GetGlobalConf()
|
||||
if conf == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
costRes = conf.VikingExpeditionCos
|
||||
if costRes == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
|
||||
curCount = amount
|
||||
if amount < conf.VikingNum {
|
||||
if list.RecoveryTime == 0 {
|
||||
list.RecoveryTime = configure.Now().Unix()
|
||||
}
|
||||
for { // 计算恢复时间
|
||||
if list.RecoveryTime+int64(conf.VikingExpeditionRecoveryTime*60) <= configure.Now().Unix() {
|
||||
curCount++
|
||||
list.RecoveryTime += int64(conf.VikingExpeditionRecoveryTime * 60)
|
||||
if curCount >= conf.VikingNum {
|
||||
list.RecoveryTime = 0
|
||||
break
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if curCount-amount > 0 {
|
||||
addCount = curCount - amount
|
||||
|
||||
}
|
||||
} else {
|
||||
list.RecoveryTime = 0
|
||||
}
|
||||
addCount += req.Count
|
||||
if amount+addCount > conf.VikingNum {
|
||||
code = pb.ErrorCode_VikingBuyMaxCount
|
||||
return
|
||||
}
|
||||
mapData["recoveryTime"] = list.RecoveryTime // 更新刷新时间
|
||||
curByCount += req.Count // 当前需要购买的数量
|
||||
|
||||
if this.configure.GetMaxBuyChallengeCount()+PrivilegeBuyCount < curByCount {
|
||||
code = pb.ErrorCode_VikingBuyMaxCount
|
||||
return
|
||||
}
|
||||
|
||||
// 消耗资源整合
|
||||
for i := list.BuyCount + 1; i <= curByCount; i++ {
|
||||
_cfg := this.configure.GetBuyChallengeCount(i)
|
||||
if _cfg == nil {
|
||||
// 取最后一条
|
||||
_cfg = this.configure.GetLastBuyChallenge()
|
||||
}
|
||||
szcostRes = append(szcostRes, _cfg.Need...)
|
||||
}
|
||||
sz := make([]*cfg.Gameatn, 0)
|
||||
for _, v := range szcostRes {
|
||||
bFound := false
|
||||
for _, v1 := range sz {
|
||||
if v.A == v1.A && v.T == v1.T {
|
||||
v1.N += v.N
|
||||
bFound = true
|
||||
}
|
||||
}
|
||||
if !bFound {
|
||||
sz = append(sz, v)
|
||||
}
|
||||
}
|
||||
//消耗
|
||||
if code = this.module.ConsumeRes(session, sz, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
res := &cfg.Gameatn{
|
||||
A: "item",
|
||||
T: costRes.T,
|
||||
N: addCount,
|
||||
}
|
||||
if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
list.BuyCount = curByCount
|
||||
mapData["buyCount"] = curByCount
|
||||
code = this.module.ModifyVikingData(session.GetUserId(), mapData)
|
||||
session.SendMsg(string(this.module.GetType()), VikingBuyResp, &pb.VikingBuyResp{Data: list})
|
||||
session.SendMsg(string(this.module.GetType()), VikingBuyResp, &pb.VikingBuyResp{})
|
||||
return
|
||||
}
|
||||
|
@ -4,9 +4,6 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/mgo"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"go_dreamfactory/utils"
|
||||
"strconv"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@ -20,16 +17,14 @@ func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.VikingGetLi
|
||||
}
|
||||
|
||||
func (this *apiComp) GetList(session comm.IUserSession, req *pb.VikingGetListReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
mapData map[string]interface{}
|
||||
curCount int32
|
||||
)
|
||||
mapData = make(map[string]interface{}, 0)
|
||||
code = this.GetListCheck(session, req)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
|
||||
// 刷新挑战卷
|
||||
if code = this.module.ModuleItems.RecoverTicket(session); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
list, err := this.module.modelViking.getVikingList(session.GetUserId())
|
||||
if mgo.MongodbNil == err {
|
||||
list = &pb.DBViking{
|
||||
@ -46,78 +41,8 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.VikingGetListReq
|
||||
}
|
||||
|
||||
this.module.modelViking.Add(session.GetUserId(), list)
|
||||
conf := this.module.configure.GetGlobalConf()
|
||||
if conf == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
iCont := conf.VikingNum
|
||||
atn := conf.VikingExpeditionCos
|
||||
if iCont > 0 {
|
||||
res := &cfg.Gameatn{
|
||||
A: atn.A,
|
||||
T: atn.T,
|
||||
N: iCont,
|
||||
}
|
||||
this.module.DispenseRes(session, []*cfg.Gameatn{res}, true)
|
||||
}
|
||||
}
|
||||
|
||||
// 校验 是不是当天
|
||||
if !utils.IsToday(list.CTime) {
|
||||
list.CTime = configure.Now().Unix()
|
||||
list.BuyCount = 0
|
||||
mapData["cTime"] = list.CTime
|
||||
mapData["buyCount"] = list.BuyCount
|
||||
|
||||
}
|
||||
// 检查恢复时间
|
||||
conf := this.module.configure.GetGlobalConf()
|
||||
if conf == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
costRes := conf.VikingExpeditionCos
|
||||
if costRes == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
|
||||
curCount = amount
|
||||
// 道具上限
|
||||
if amount < conf.VikingNum {
|
||||
if list.RecoveryTime == 0 {
|
||||
list.RecoveryTime = configure.Now().Unix()
|
||||
}
|
||||
for { // 计算恢复时间
|
||||
if list.RecoveryTime+int64(conf.VikingExpeditionRecoveryTime*60) <= configure.Now().Unix() {
|
||||
curCount++
|
||||
list.RecoveryTime += int64(conf.VikingExpeditionRecoveryTime * 60)
|
||||
if curCount >= conf.VikingNum {
|
||||
list.RecoveryTime = 0
|
||||
break
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
addCount := curCount - amount
|
||||
if addCount > 0 {
|
||||
res := &cfg.Gameatn{
|
||||
A: "item",
|
||||
T: costRes.T,
|
||||
N: addCount,
|
||||
}
|
||||
if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
list.RecoveryTime = 0
|
||||
}
|
||||
mapData["recoveryTime"] = list.RecoveryTime
|
||||
code = this.module.ModifyVikingData(session.GetUserId(), mapData) //修改内存信息
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), VikingGetListResp, &pb.VikingGetListResp{Data: list})
|
||||
return
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"go_dreamfactory/lego/sys/redis/pipe"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"go_dreamfactory/sys/db"
|
||||
"math"
|
||||
@ -261,22 +260,12 @@ func (this *Viking) AutoBattleOver(session comm.IUserSession, Report *pb.BattleR
|
||||
if code = this.ConsumeRes(session, []*cfg.Gameatn{costRes}, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
amount := int32(this.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
|
||||
viking, err := this.modelViking.getVikingList(session.GetUserId())
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_VikingBoosType
|
||||
return
|
||||
}
|
||||
conf := this.configure.GetGlobalConf()
|
||||
if conf != nil {
|
||||
|
||||
if amount < conf.VikingNum && viking.RecoveryTime == 0 {
|
||||
mapData := make(map[string]interface{}, 0)
|
||||
viking.RecoveryTime = configure.Now().Unix()
|
||||
mapData["recoveryTime"] = viking.RecoveryTime
|
||||
code = this.ModifyVikingData(session.GetUserId(), mapData)
|
||||
}
|
||||
}
|
||||
code, bWin := this.battle.CheckBattleReport(session, Report)
|
||||
if !bWin { // 战斗失败了 直接返回
|
||||
code = pb.ErrorCode_BattleNoWin
|
||||
|
Loading…
Reference in New Issue
Block a user