This commit is contained in:
liwei1dao 2022-11-07 16:51:40 +08:00
commit 48247e9095
3 changed files with 23 additions and 25 deletions

View File

@ -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

View File

@ -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
//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)
if trolltrain.AiCount+trolltrain.SellCount < aiCount {
this.module.TrollAI(session, trolltrain)
}
maxCoefficient = this.configure.GetTrollMaxCoefficientNux() // 增长幅度的最大值

View File

@ -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
}
}