From a079a06c7c5063fa03c636c9550264deb6f32d83 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 17 Aug 2023 10:16:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E9=98=9F=E4=BB=BB=E5=8A=A1=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/caravan/api_buyorsell.go | 41 +++++++++++++------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/modules/caravan/api_buyorsell.go b/modules/caravan/api_buyorsell.go index 62736b189..32dca4c3e 100644 --- a/modules/caravan/api_buyorsell.go +++ b/modules/caravan/api_buyorsell.go @@ -20,10 +20,13 @@ func (this *apiComp) BuyOrSellCheck(session comm.IUserSession, req *pb.CaravanBu func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSellReq) (errdata *pb.ErrorData) { var ( - update map[string]interface{} - addScore int32 // 收益 - cityInfo *pb.CityInfo - ok bool + update map[string]interface{} + addScore int32 // 收益 + cityInfo *pb.CityInfo + ok bool + sellValue int32 // 任务统计 贩卖货物价值 + buyValue int32 // 任务统计 贩卖货物价值 + sellSpValue int32 // 任务统计 向指定X城市贩卖货物贩卖货物价值 ) update = make(map[string]interface{}) if errdata = this.BuyOrSellCheck(session, req); errdata != nil { @@ -51,7 +54,6 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe // special 城市卖给玩家的商品 // exspecial 城市想要玩家卖给他的商品库 if !req.IsBuy { // 卖给npc - var cb int32 // 成本价 for k, v := range req.Items { // 校验背包数据够不够 @@ -68,10 +70,11 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe cb = items.Price // 获取成本价 price = items.Price bFound := false - for _, v := range cityInfo.Special { - if v == k { + for _, key := range cityInfo.Special { + if key == k { if cityConf, err := this.module.configure.GetCaravanCity(req.City); err == nil { price = cityConf.Specialnum * price / 1000 + sellSpValue += cityConf.Specialnum * price * v / 1000 bFound = true } else { errdata = &pb.ErrorData{ @@ -97,7 +100,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe return } } - + sellValue += price * v if errdata = this.module.DispenseRes(session, []*cfg.Gameatn{{ A: "attr", T: "merchantmoney", @@ -176,7 +179,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe } bFound := false // 计算均价 - totla := caravan.Items[k].Count * caravan.Items[k].Price + buyValue = caravan.Items[k].Count * caravan.Items[k].Price var price int32 price = caravan.Goods[k].Price for _, v := range cityInfo.Special { @@ -194,8 +197,8 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe } caravan.Items[k].Count += v - totla += price * v - caravan.Items[k].Price = totla / caravan.Items[k].Count + buyValue += price * v + caravan.Items[k].Price = buyValue / caravan.Items[k].Count // 同步更新该城市的 出售货物信息 cityInfo.Count[k] += v @@ -256,19 +259,9 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe szTask = append(szTask, comm.GetBuriedParam(comm.Rtype209, req.City, opCount)) } else { // 卖 //向指定X城市贩卖货物,贩卖货物价值需要X虚拟币以上 - var price int32 - for k, v := range req.Items { - - price += caravan.Items[k].Price * v - } - szTask = append(szTask, comm.GetBuriedParam(comm.Rtype210, req.City, price)) - - // 急需货物 - if v, ok := caravan.City[req.City]; ok { - for range v.Exspecial { - - } - } + szTask = append(szTask, comm.GetBuriedParam(comm.Rtype210, req.City, sellValue)) + // Rtype211 TaskType = 211 // 向指定X城市,贩卖价值X虚拟币以上的对应城市急需货物 + szTask = append(szTask, comm.GetBuriedParam(comm.Rtype211, req.City, sellValue)) } szTask = append(szTask, comm.GetBuriedParam(comm.Rtype212, req.City)) // 接取任务后,商队抵达指定城市 go this.module.ModuleBuried.TriggerBuried(session.Clone(), szTask...)