diff --git a/modules/caravan/api_buyorsell.go b/modules/caravan/api_buyorsell.go index 9e7adfb61..d024c5900 100644 --- a/modules/caravan/api_buyorsell.go +++ b/modules/caravan/api_buyorsell.go @@ -26,6 +26,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe sellValue int32 // 任务统计 贩卖货物价值 buyValue int32 // 任务统计 贩卖货物价值 sellSpValue int32 // 任务统计 向指定X城市贩卖货物贩卖货物价值 + profitValue int32 // 盈利 ) update = make(map[string]interface{}) if errdata = this.BuyOrSellCheck(session, req); errdata != nil { @@ -65,31 +66,37 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe } items := caravan.Items[k] var price int32 - + var prePrice int32 // 之前的价格 price = items.Price + prePrice = items.Price bFound := false 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{ - Code: pb.ErrorCode_TrollItemNoEnough, // 道具数量不足 - Title: pb.ErrorCode_TrollItemNoEnough.ToString(), - Message: err.Error(), - } - return } break } } if !bFound { - price = cityInfo.ExspecialPCT * price / 1000 + for _, key := range cityInfo.Exspecial { + if key == k { + bFound = true + price = cityInfo.ExspecialPCT * price / 1000 + break + } + } + } + if !bFound { + if cityConf, err := this.module.configure.GetCaravanCity(req.City); err == nil { + price = cityConf.Orspecial * price / 1000 + } } - sellValue += price * v + if price > prePrice { + profitValue = (price - prePrice) * v + } } var addRes []*cfg.Gameatn @@ -102,13 +109,12 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe addRes = append(addRes, &cfg.Gameatn{ A: "attr", T: "profit", - N: sellValue, + N: profitValue, }) if errdata = this.module.DispenseRes(session, addRes, true); errdata != nil { this.module.Errorf("获得虚拟币失败:%v", errdata) } this.module.ArrayBag(caravan) - //curProfit := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), "profit") // 统计 收益 var lvReward []*cfg.Gameatn @@ -139,20 +145,6 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe if len(lvReward) > 0 { // 商队等级奖励 改发邮件 this.module.mail.SendRewardMailByCid(session, comm.CaravanLvReward, lvReward) } - - // 商队盈利收益奖励 - // reward := this.configure.GetCaravanReward() - // for _, v := range reward { - // if v.Key > 0 { - // if curProfit > int64(v.Key) { - // if _, ok := caravan.Reward[v.Key]; !ok { - // this.module.mail.SendRewardMailByCid(session, comm.CaravanLvReward, v.Reward) - // caravan.Reward[v.Key] = true - // update["reward"] = caravan.Reward - // } - // } - // } - // } } else { // 买入 for k, v := range req.Items { if _, ok := caravan.Items[k]; !ok {