From aaeb434528676145f934eeeb095ab74c62e1cd56 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 18 Aug 2022 15:11:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=B7=A8=E5=A4=A9=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/gourmet/api_createorder.go | 8 +++++ modules/gourmet/model_gourmet.go | 50 ++++++++++++++++++------------ modules/gourmet/module.go | 5 +++ 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/modules/gourmet/api_createorder.go b/modules/gourmet/api_createorder.go index 8053f6e6d..fe5d32775 100644 --- a/modules/gourmet/api_createorder.go +++ b/modules/gourmet/api_createorder.go @@ -4,6 +4,7 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" + "go_dreamfactory/utils" "time" "google.golang.org/protobuf/proto" @@ -65,6 +66,13 @@ 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-- diff --git a/modules/gourmet/model_gourmet.go b/modules/gourmet/model_gourmet.go index 618fd2bb4..1e6bb1fa0 100644 --- a/modules/gourmet/model_gourmet.go +++ b/modules/gourmet/model_gourmet.go @@ -7,6 +7,7 @@ import ( "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" + "go_dreamfactory/utils" "time" "go.mongodb.org/mongo-driver/bson/primitive" @@ -60,8 +61,8 @@ func (this *modelGourmet) modifyGourmetDataByObjId(uid string, data map[string]i } // todo 调用drop 表 获取掉落信息 -func (this *modelGourmet) GetDropReward(count, dropId int32) (res []*cfg.Gameatn) { - +func (this *modelGourmet) GetDropReward(count, dropId int32, Items []*pb.UserAssets) { + res := make([]*cfg.Gameatn, 0) for i := 0; i < int(count); i++ { data := this.module.configure.GetDropData(dropId) szW := make([]int32, 0) @@ -71,6 +72,22 @@ func (this *modelGourmet) GetDropReward(count, dropId int32) (res []*cfg.Gameatn index := comm.GetRandW(szW) res = append(res, data[index].Prize...) } + for _, v := range res { + bFind := false + for _, v1 := range Items { + if v.A == v1.A && v.T == v1.T { + v1.N += v.N + bFind = true + } + } + if !bFind { + Items = append(Items, &pb.UserAssets{ + A: v.A, + T: v.T, + N: v.N, + }) + } + } return } @@ -105,26 +122,21 @@ func (this *modelGourmet) CalculationGourmet(uid string, gourmet *pb.DBGourmet) _gourmetcfg := this.module.configure.GetGourmetConfigData(foodtype, skillLv) // 美食家配置表 for i := 0; i < int(order.FoodCount); i++ { curTime += _skillCfg.Needtime - order.FoodCount-- - res := this.GetDropReward(_gourmetcfg.Using, _gourmetcfg.Propsgroup) - for _, v := range res { - bFind := false - for _, v1 := range gourmet.Items { - if v.A == v1.A && v.T == v1.T { - v1.N += v.N - bFind = true - } - } - if !bFind { - gourmet.Items = append(gourmet.Items, &pb.UserAssets{ - A: v.A, - T: v.T, - N: v.N, - }) - } + // 判断是不是第二天 + if gourmet.CookingFood.ETime == 0 { + 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 // 清空当天的订单时长 + } + order.FoodCount-- + this.GetDropReward(_gourmetcfg.Using, _gourmetcfg.Propsgroup, gourmet.Items) // 获取掉落奖励 if curTime > costTime { + gourmet.OrderCostTime += int32(curTime - costTime) // 转时间戳 eTimd := time.Now().Unix() + int64(curTime-costTime) gourmet.CookingFood.FoodType = order.FoodType diff --git a/modules/gourmet/module.go b/modules/gourmet/module.go index b4fe7b959..6c6a1dffd 100644 --- a/modules/gourmet/module.go +++ b/modules/gourmet/module.go @@ -1,3 +1,8 @@ +/* +模块名:Gourmet +描述:美食家模块 +开发:梅雄风 +*/ package gourmet import (