From a0ddd89b5a1a747f3507f1255dca242046ae321b Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 7 Nov 2022 16:46:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=91=E5=95=86=E6=94=B6=E7=9B=8Abug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/troll/api_buyorsell.go | 36 ++++++++++++++++------------------ modules/troll/api_getlist.go | 8 ++++---- modules/troll/module.go | 4 ++-- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/modules/troll/api_buyorsell.go b/modules/troll/api_buyorsell.go index 6b19d3fd3..520179d89 100644 --- a/modules/troll/api_buyorsell.go +++ b/modules/troll/api_buyorsell.go @@ -35,7 +35,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell return } dayMaxCount := this.configure.GetTrollRule(comm.TrollBuyCount) - //aiMaxCount := this.configure.GetTrollRule(comm.TrollAIBuyCount) + aiMaxCount := this.configure.GetTrollRule(comm.TrollAIBuyCount) for k, v := range req.Items { if v == 0 { // 过滤数量为0 的消息 @@ -49,19 +49,14 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell if !bSell { bSell = true trolltrain.SellCount += 1 // 交易次数+1 - if trolltrain.AiCount+trolltrain.SellCount >= dayMaxCount { - //if trolltrain.SellCount > aiMaxCount-trolltrain.AiCount { + if trolltrain.SellCount > dayMaxCount || (trolltrain.SellCount+trolltrain.AiCount) > aiMaxCount { code = pb.ErrorCode_TrollMaxSellCount // 达到最大交易次数 直接返回 return } update["sellCount"] = trolltrain.SellCount } } - if _, ok := trolltrain.Items[k]; !ok { - trolltrain.Items[k] = v - } else { - trolltrain.Items[k] += v - } + if _, ok := trolltrain.Shop[k]; !ok { if v > 0 { trolltrain.Shop[k] = v // 限购 @@ -80,7 +75,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell // 买入上限 直接返回 code = pb.ErrorCode_TrollBuyMax return - } else if trolltrain.Items[k] < 0 { //卖出数量不足 + } else if trolltrain.Items[k]+v < 0 { //卖出数量不足 code = pb.ErrorCode_TrollSellMax return } @@ -95,7 +90,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell //消耗的金币 gold -= trolltrain.Price[k] * trolltrain.Items[k] } else { - p := this.configure.GetTrollCoefficient(trolltrain.TarinPos) + p := this.configure.GetTrollCoefficient(trolltrain.RangeId) if p == nil { return } @@ -112,14 +107,16 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell } } if v < 0 { // 卖出 + trolltrain.Items[k] += v if sellPrice > trolltrain.Price[k] { // 赚了 earn += (sellPrice - trolltrain.Price[k]) * v } gold += sellPrice * v } else { // 买入 计算平均价格 - totalGold := (trolltrain.Items[k] - v) * trolltrain.Price[k] + totalGold := trolltrain.Items[k] * trolltrain.Price[k] totalGold += v * sellPrice - trolltrain.Price[k] = totalGold / (trolltrain.Items[k]) + trolltrain.Items[k] += v + trolltrain.Price[k] = totalGold / trolltrain.Items[k] gold -= v * sellPrice } } @@ -142,13 +139,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell code = pb.ErrorCode_GoldNoEnough return } - // check npc level - if confLv := this.configure.GetTrollLv(trolltrain.GetNpcLv() + 1); confLv != nil { - if earn >= confLv.Money { - trolltrain.NpcLv += 1 // npc levelUp - update["npcLv"] = trolltrain.NpcLv - } - } + // 清除数量为0 的 for k, v := range trolltrain.Items { if v == 0 { @@ -159,6 +150,13 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell } } trolltrain.TotalEarn += -int64(earn) // 累计获得的金币 + // check npc level + if confLv := this.configure.GetTrollLv(trolltrain.GetNpcLv() + 1); confLv != nil { + if trolltrain.TotalEarn >= int64(confLv.Money) { + trolltrain.NpcLv += 1 // npc levelUp + update["npcLv"] = trolltrain.NpcLv + } + } update["items"] = trolltrain.Items update["price"] = trolltrain.Price update["totalEarn"] = trolltrain.TotalEarn diff --git a/modules/troll/api_getlist.go b/modules/troll/api_getlist.go index 235c4e4b6..2095b5320 100644 --- a/modules/troll/api_getlist.go +++ b/modules/troll/api_getlist.go @@ -32,10 +32,10 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq) code = pb.ErrorCode_DBError return } - dayMaxCount := this.configure.GetTrollRule(comm.TrollBuyCount) // 8 - aiCount := this.configure.GetTrollRule(comm.TrollAIBuyCount) // 10 - if trolltrain.AiCount+trolltrain.SellCount < dayMaxCount { - this.module.TrollAI(session, trolltrain, aiCount) + //dayMaxCount := this.configure.GetTrollRule(comm.TrollBuyCount) // 8 + aiCount := this.configure.GetTrollRule(comm.TrollAIBuyCount) // 10 + if trolltrain.AiCount+trolltrain.SellCount < aiCount { + this.module.TrollAI(session, trolltrain) } maxCoefficient = this.configure.GetTrollMaxCoefficientNux() // 增长幅度的最大值 diff --git a/modules/troll/module.go b/modules/troll/module.go index 99afaf158..8cf6afffa 100644 --- a/modules/troll/module.go +++ b/modules/troll/module.go @@ -57,7 +57,7 @@ func (this *Troll) ModifyTrollData(uid string, data map[string]interface{}) (cod return } -func (this *Troll) TrollAI(session comm.IUserSession, troll *pb.DBTrollTrain, aiCount int32) (code pb.ErrorCode) { +func (this *Troll) TrollAI(session comm.IUserSession, troll *pb.DBTrollTrain) (code pb.ErrorCode) { var ( sellPrice map[int32]int32 // 出售货物价格 totalGold int32 @@ -122,7 +122,7 @@ func (this *Troll) TrollAI(session comm.IUserSession, troll *pb.DBTrollTrain, ai troll.AiCount++ aiMaxCount := this.configure.GetTrollRule(comm.TrollAIBuyCount) - if troll.AiCount > aiMaxCount { //达到最大交易次数 + if troll.AiCount+troll.SellCount > aiMaxCount { //达到最大交易次数 break } }