This commit is contained in:
liwei1dao 2022-09-02 17:02:30 +08:00
commit cc86067038
10 changed files with 199 additions and 97 deletions

View File

@ -46,7 +46,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10012,
@ -95,7 +95,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10013,
@ -144,7 +144,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10014,
@ -193,7 +193,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10021,
@ -242,7 +242,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10022,
@ -291,7 +291,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10023,
@ -340,7 +340,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10024,
@ -389,7 +389,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10031,
@ -438,7 +438,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10032,
@ -487,7 +487,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10033,
@ -536,7 +536,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10034,
@ -585,7 +585,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10041,
@ -634,7 +634,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10042,
@ -683,7 +683,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10043,
@ -732,7 +732,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10044,
@ -781,7 +781,7 @@
}
],
"using": 1,
"propsgroup": 10001
"propsgroup": 1001
},
{
"id": 10051,

2
go.mod
View File

@ -131,7 +131,7 @@ require (
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/philhofer/fwd v1.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.13.5
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect

2
go.sum
View File

@ -678,12 +678,10 @@ github.com/smallnest/quick v0.0.0-20220103065406-780def6371e6 h1:J8xk0QMMrqfDLqU
github.com/smallnest/quick v0.0.0-20220103065406-780def6371e6/go.mod h1:h+J5yoLzf3XMKtM9l4vOaUtS4e+si6T3sKDtheJ15wc=
github.com/smallnest/rpcx v1.7.4 h1:u6ADk/Ep8BqtAoJZO7LbniWsP+nqeAtcbaPm2D4eOXg=
github.com/smallnest/rpcx v1.7.4/go.mod h1:TSciUoPlm8MYxnC7ErCz5ZymOFxOTbhN9cRgEI6Degs=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=

View File

@ -24,8 +24,9 @@ func (this *apiComp) CreateOrder(session comm.IUserSession, req *pb.GourmetCreat
var (
res []*cfg.Gameatn
costTime int32
szTime map[int32]int32 // 记录每个类型的订单耗时 key 是技能组type value 订单耗时
)
szTime = make(map[int32]int32, 0)
code = this.CreateOrderCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
@ -35,18 +36,44 @@ func (this *apiComp) CreateOrder(session comm.IUserSession, req *pb.GourmetCreat
code = pb.ErrorCode_DBError
return
}
// 记录每个食材耗时
for k, v := range _gourmet.Skill {
var _time int32
// 计算出需要的时间
_skillCfg := this.module.configure.GetGourmetConfigData(k, v)
_time += _skillCfg.Needtime
// 高效制作技能
for k, v := range _gourmet.SpecialSkill {
specalSkill := this.module.configure.GetGourmetConfigData(k, v)
_time += specalSkill.Needtime
}
szTime[k] = _time
}
if !utils.IsToday(_gourmet.Ctime) { // 跨天了
_gourmet.Ctime = time.Now().Unix()
_gourmet.OrderCostTime = 0
}
for _, order := range req.Order {
if order.FoodCount == 0 {
continue
}
foodtype := order.FoodType
// 获取技能等级
skillLv := _gourmet.Skill[foodtype]
// 计算出需要的时间
_skillCfg := this.module.configure.GetGourmetConfigData(foodtype, skillLv)
costTime += _skillCfg.Needtime * order.FoodCount
if v, ok := szTime[order.FoodType]; ok {
costTime += v * order.FoodCount
}
}
// 校验时间
cfgCom := this.module.configure.GetGlobalConf() // 获取总的下单时长
if cfgCom == nil {
return
}
_gourmet.OrderCostTime += costTime
if cfgCom.Gourmet < _gourmet.OrderCostTime { // 大于总时长是不允许的
code = pb.ErrorCode_GourmetMoreOrderTime
return
}
if _gourmet.Foods == nil { // 队列数据为nil 直接将订单数据给ta
_gourmet.Foods = req.Order
} else {
@ -64,49 +91,42 @@ func (this *apiComp) CreateOrder(session comm.IUserSession, req *pb.GourmetCreat
}
}
}
if _gourmet.CookingFood == nil || (_gourmet.CookingFood != nil && _gourmet.CookingFood.ETime == 0) {
if _gourmet.Ctime == 0 {
_gourmet.Ctime = time.Now().Unix()
}
if !utils.IsToday(_gourmet.Ctime) {
_gourmet.Ctime = time.Now().Unix()
_gourmet.OrderCostTime = 0
}
for _, v := range _gourmet.Foods {
if v.FoodCount > 0 {
v.FoodCount--
// 获取生产时间
_skillCfg := this.module.configure.GetGourmetConfigData(v.FoodType, _gourmet.Skill[v.FoodType])
_gourmet.CookingFood = &pb.Cooking{
FoodType: v.FoodType,
ETime: time.Now().Unix() + int64(_skillCfg.Needtime),
STime: time.Now().Unix() - int64(_skillCfg.Needtime),
}
break
}
}
}
// 計算耗時
// 重新计算时间
for _, v := range _gourmet.Foods {
if v.FoodCount > 0 {
_skillCfg := this.module.configure.GetGourmetConfigData(v.FoodType, _gourmet.Skill[v.FoodType])
v.CookTime = _skillCfg.Needtime * v.FoodCount
if v.FoodCount == 0 {
continue
}
if v1, ok := szTime[v.FoodType]; ok {
v.CookTime = v1 * v.FoodCount
costTime += v.CookTime
}
}
if _gourmet.CookingFood != nil && _gourmet.CookingFood.ETime == 0 {
_gourmet.CookingFood = nil
}
// 获取总的下单时长
cfgCom := this.module.configure.GetGlobalConf()
if cfgCom == nil {
return
}
if cfgCom.Gourmet < _gourmet.OrderCostTime+costTime { // 大于总时长是不允许的
code = pb.ErrorCode_GourmetMoreOrderTime
return
if _gourmet.CookingFood == nil {
if _gourmet.Ctime == 0 {
_gourmet.Ctime = time.Now().Unix()
}
for _, v := range _gourmet.Foods {
if v.FoodCount > 0 {
v.FoodCount--
v.CookTime = v.FoodCount * szTime[v.FoodType]
// 获取生产时间
_gourmet.CookingFood = &pb.Cooking{
FoodType: v.FoodType,
ETime: time.Now().Unix() + int64(szTime[v.FoodType]),
STime: time.Now().Unix(),
}
if v.FoodCount == 0 {
v.CookTime = 0
}
break
}
}
}
if code = this.module.ConsumeRes(session, res, true); code != pb.ErrorCode_Success { // 消耗校验
return
}
@ -114,11 +134,13 @@ func (this *apiComp) CreateOrder(session comm.IUserSession, req *pb.GourmetCreat
if code = this.module.DispenseRes(session, res, true); code != pb.ErrorCode_Success { // 真正消耗
return
}
// 校验通过 写数据
mapData := make(map[string]interface{}, 0)
mapData["foods"] = _gourmet.Foods
mapData["orderCostTime"] = _gourmet.OrderCostTime
mapData["cookingFood"] = _gourmet.CookingFood // 正在做的
mapData["ctime"] = _gourmet.Ctime
code = this.module.ModifyGourmetData(session.GetUserId(), mapData)
session.SendMsg(string(this.module.GetType()), GourmetCreateOrderResp, &pb.GourmetCreateOrderResp{Data: _gourmet})

View File

@ -48,10 +48,6 @@ func (this *apiComp) SkillLV(session comm.IUserSession, req *pb.GourmetSkillLvRe
}
_skillCfg := this.module.configure.GetGourmetConfigData(req.SkillType, skilllv) // 获取技能配置
// code = this.module.CheckRes(session, _skillCfg.Consume) // 消耗检测
// if code != pb.ErrorCode_Success {
// return
// }
code = this.module.ConsumeRes(session, _skillCfg.SkillConsume, true) // 消耗检测
if code != pb.ErrorCode_Success {
return

View File

@ -3,6 +3,7 @@ package gourmet
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"time"
"google.golang.org/protobuf/proto"
)
@ -25,6 +26,9 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.GourmetGetListRe
code = pb.ErrorCode_DBError
return
}
if _gourmet.Ctime == 0 {
_gourmet.Ctime = time.Now().Unix()
}
// 计算订单信息
this.module.modelGourmet.CalculationGourmet(session.GetUserId(), _gourmet)
session.SendMsg(string(this.module.GetType()), GourmetGetListResp, &pb.GourmetGetListResp{Data: _gourmet})

View File

@ -67,52 +67,79 @@ func (this *modelGourmet) modifyGourmetDataByObjId(uid string, data map[string]i
// 计算订单信息
func (this *modelGourmet) CalculationGourmet(uid string, gourmet *pb.DBGourmet) {
var (
bCooking bool
costTime int32
curTime int32
bCooking bool
costTime int32
curTime int32
szTime map[int32]int32
zTime int64
nextDay bool
nextDayTime int32
)
mapData := make(map[string]interface{}, 0)
szTime = make(map[int32]int32, 0)
defer this.module.ModifyGourmetData(uid, mapData)
// 记录每个食材耗时
for k, v := range gourmet.Skill {
var _time int32
// 计算出需要的时间
_skillCfg := this.module.configure.GetGourmetConfigData(k, v)
_time += _skillCfg.Needtime
// 高效制作技能
for k, v := range gourmet.SpecialSkill {
specalSkill := this.module.configure.GetGourmetConfigData(k, v)
_time += specalSkill.Needtime
}
szTime[k] = _time
}
if !utils.IsToday(gourmet.Ctime) {
gourmet.Ctime = time.Now().Unix()
zTime = utils.GetZeroTime()
}
if gourmet.CookingFood != nil && gourmet.CookingFood.ETime > 0 {
costTime = int32(time.Now().Unix() - gourmet.CookingFood.ETime) // 当前过去的时间
if costTime < 0 { // 没有完成 不做处理
return
}
}
if gourmet.CookingFood == nil {
gourmet.CookingFood = &pb.Cooking{}
}
for _, order := range gourmet.Foods {
if order.FoodCount == 0 {
continue
}
foodtype := order.FoodType
// 获取技能等级
skillLv := gourmet.Skill[foodtype]
skillLv := gourmet.Skill[foodtype] // 获取技能等级
// 计算出需要的时间
_skillCfg := this.module.configure.GetGourmetConfigData(foodtype, skillLv) // 技能配置表
_gourmetcfg := this.module.configure.GetGourmetConfigData(foodtype, skillLv) // 美食家配置表
for i := 0; i < int(order.FoodCount); i++ {
curTime += _skillCfg.Needtime
// 判断是不是第二天
if gourmet.CookingFood.ETime == 0 {
iCount := int(order.FoodCount)
for i := 0; i < iCount; i++ {
curTime += szTime[order.FoodType]
order.FoodCount--
if order.FoodCount == 0 {
order.CookTime = 0
}
order.CookTime = order.FoodCount * szTime[order.FoodType]
if gourmet.CookingFood == nil {
gourmet.CookingFood = &pb.Cooking{}
gourmet.CookingFood.STime = time.Now().Unix()
gourmet.CookingFood.ETime = time.Now().Unix()
}
if !utils.IsToday(gourmet.CookingFood.ETime + int64(curTime)) { // 判断是不是今天
// 跨天了
gourmet.CookingFood.ETime = gourmet.CookingFood.ETime + int64(curTime) // 设置下单的时间
gourmet.Ctime = gourmet.CookingFood.ETime // 设置创建订单时间
gourmet.OrderCostTime = 0 // 清空当天的订单时长
gourmet.CookingFood.FoodType = order.FoodType
gourmet.CookingFood.STime += int64(szTime[order.FoodType])
gourmet.CookingFood.ETime += int64(szTime[order.FoodType])
if zTime > 0 && gourmet.CookingFood.STime > zTime {
gourmet.OrderCostTime = 0
nextDay = true
}
if nextDay {
nextDayTime += szTime[order.FoodType]
}
order.FoodCount--
gourmet.Items = this.module.configure.GetMultipleDropReward(_gourmetcfg.Using, _gourmetcfg.Propsgroup, gourmet.Items) // 获取掉落奖励
if curTime > costTime {
gourmet.OrderCostTime += int32(curTime - costTime)
// 转时间戳
gourmet.CookingFood.FoodType = order.FoodType
gourmet.CookingFood.ETime = time.Now().Unix() + int64(curTime-costTime)
gourmet.CookingFood.STime = time.Now().Unix() - int64(curTime-costTime)
gourmet.CookingFood.STime = gourmet.CookingFood.ETime - int64(szTime[order.FoodType])
bCooking = true
// 记录下订单时间
@ -120,36 +147,54 @@ func (this *modelGourmet) CalculationGourmet(uid string, gourmet *pb.DBGourmet)
mapData["ctime"] = gourmet.Ctime
break
}
gourmet.OrderCostTime += curTime
gourmet.Items = this.module.configure.GetMultipleDropReward(_gourmetcfg.Using, _gourmetcfg.Propsgroup, gourmet.Items) // 获取掉落奖励
}
if bCooking { // 分配了正在製作的食物
break
}
}
if !bCooking { // 经过计算没有烹饪食物的时候
if nextDay {
gourmet.OrderCostTime += nextDayTime
for _, order := range gourmet.Foods {
if order.FoodCount == 0 {
continue
}
gourmet.OrderCostTime += szTime[order.FoodType] * order.FoodCount
}
}
if gourmet.CookingFood != nil && gourmet.CookingFood.ETime <= time.Now().Unix() { // 当前时间超过正在做的时间
foodtype := gourmet.CookingFood.FoodType
skillLv := gourmet.Skill[foodtype] // 获取技能等级
_gourmetcfg := this.module.configure.GetGourmetConfigData(foodtype, skillLv) // 美食家配置表
gourmet.Items = this.module.configure.GetMultipleDropReward(_gourmetcfg.Using, _gourmetcfg.Propsgroup, gourmet.Items)
gourmet.CookingFood = nil
}
// 保存信息
mapData["items"] = gourmet.Items
mapData["foods"] = gourmet.Foods
mapData["orderCostTime"] = gourmet.OrderCostTime
mapData["cookingFood"] = gourmet.CookingFood // 正在做的
this.module.ModifyGourmetData(uid, mapData)
}
// 技能等级提高了 重新计算订单时间(只对订单中数据有影响)
func (this *modelGourmet) CalculationGourmetbySkiiLv(uid string, gourmet *pb.DBGourmet, skillType int32, skilllv int32) {
mapData := make(map[string]interface{}, 0)
var totalTime int32
for _, v := range gourmet.Foods {
if v.FoodCount > 0 && v.FoodType == skillType {
_skillCfg := this.module.configure.GetGourmetConfigData(skillType, skilllv)
if _skillCfg != nil {
v.CookTime = _skillCfg.Needtime * v.FoodCount
totalTime += _skillCfg.Needtime * v.FoodCount
v.CookTime += totalTime
mapData["foods"] = gourmet.Foods
}
break
}
}
// 总时间也减少了
gourmet.OrderCostTime += totalTime
mapData["orderCostTime"] = gourmet.OrderCostTime
mapData["skill"] = gourmet.Skill
this.module.ModifyGourmetData(uid, mapData)
}
@ -157,11 +202,13 @@ func (this *modelGourmet) CalculationGourmetbySkiiLv(uid string, gourmet *pb.DBG
// 升级高效制作技能重计算时间消耗
func (this *modelGourmet) CalculationSpecialSkillLv(uid string, gourmet *pb.DBGourmet, skillType int32, skilllv int32) {
mapData := make(map[string]interface{}, 0)
var totalTime int32
for _, v := range gourmet.Foods {
if v.FoodCount > 0 {
_skillCfg := this.module.configure.GetGourmetConfigData(skillType, skilllv)
if _skillCfg != nil {
v.CookTime += _skillCfg.Needtime * v.FoodCount
totalTime += _skillCfg.Needtime * v.FoodCount
v.CookTime += totalTime
if v.CookTime < 0 { // 担心配置错误 为负数情况 所以这里做下判断
v.CookTime = 0
}
@ -169,6 +216,9 @@ func (this *modelGourmet) CalculationSpecialSkillLv(uid string, gourmet *pb.DBGo
}
}
}
// 总时间也减少了
gourmet.OrderCostTime += totalTime
mapData["orderCostTime"] = gourmet.OrderCostTime
mapData["specialSkill"] = gourmet.SpecialSkill
this.module.ModifyGourmetData(uid, mapData)
}

View File

@ -4,6 +4,7 @@ import (
"crypto/rand"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
"math/big"
"google.golang.org/protobuf/proto"
@ -178,5 +179,25 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt
ChangeList = append(ChangeList, _hero)
session.SendMsg(string(this.module.GetType()), "change", &pb.HeroChangePush{List: ChangeList})
session.SendMsg(string(this.module.GetType()), StrengthenUpSkill, &pb.HeroStrengthenUpSkillResp{Hero: _hero})
this.module.ModuleRtask.SendToRtask(session, comm.Rtype52, utils.ToInt32(_hero.HeroID), 1)
this.module.ModuleRtask.SendToRtask(session, comm.Rtype53, 1)
// 检查是不是满级技能
maxLv := true
for _, skill := range _hero.NormalSkill {
skillMaxLv := this.module.configure.GetHeroSkillMaxLvConfig(uint32(skill.SkillID))
if skill.SkillLv < skillMaxLv { // 找到没有满级的技能id
maxLv = false
}
}
if maxLv {
this.module.ModuleRtask.SendToRtask(session, comm.Rtype54, 1)
this.module.ModuleRtask.SendToRtask(session, comm.Rtype57, 1)
}
cfg := this.module.configure.GetHero(_hero.HeroID)
if cfg != nil {
this.module.ModuleRtask.SendToRtask(session, comm.Rtype55, cfg.Color, 1)
this.module.ModuleRtask.SendToRtask(session, comm.Rtype56, 1, 1, cfg.Job)
}
return
}

View File

@ -119,6 +119,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.PagodaChalleng
pagoda.Reward = seasonPagoda.Reward
session.SendMsg(string(this.module.GetType()), PagodaChallengeResp, &pb.PagodaChallengeResp{Data: pagoda})
}
this.module.ModuleRtask.SendToRtask(session, comm.Rtype58, 1)
this.module.ModuleRtask.SendToRtask(session, comm.Rtype59, pagoda.PagodaId)
return
}

View File

@ -18,3 +18,13 @@ func IsAfterWeek(d int64) bool {
}
return now.Sub(tt) >= time.Hour*24*7
}
// 获取0点时间戳
func GetZeroTime() int64 {
currentTime := time.Now()
startTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, currentTime.Location())
return startTime.Unix()
}