This commit is contained in:
meixiongfeng 2022-11-02 17:21:52 +08:00
parent b149c733ab
commit 8dbfc3ac6f

View File

@ -84,24 +84,21 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell
if p == nil {
return
}
var sellPrice int32 // 交易价格
if trolltrain.TarinPos == 0 {
sellPrice = goods.Goodsprice * goods.StarMoney / 1000
} else {
sellPrice = int32(p.Coefficient) * goods.Goodsprice / 1000
}
if v < 0 { // 卖出
// 卖出价格
var sellPrice int32
if trolltrain.TarinPos == 0 {
sellPrice = goods.Goodsprice * goods.StarMoney / 1000
} else {
sellPrice = int32(p.Coefficient) * goods.Goodsprice / 1000
}
if sellPrice > trolltrain.Price[k] { // 赚了
earn += (sellPrice - trolltrain.Price[k]) * trolltrain.Items[k]
earn += (sellPrice - trolltrain.Price[k]) * v
}
gold += (sellPrice - trolltrain.Price[k]) * trolltrain.Items[k]
gold += sellPrice * v
} else { // 买入 计算平均价格
totalGold := trolltrain.Items[k] * trolltrain.Price[k]
sellPrice := int32(p.Coefficient) * goods.Goodsprice / 1000
totalGold := (trolltrain.Items[k] - v) * trolltrain.Price[k]
totalGold += v * sellPrice
trolltrain.Price[k] = totalGold / (trolltrain.Items[k] + v)
trolltrain.Price[k] = totalGold / (trolltrain.Items[k])
gold -= v * sellPrice
}
}
@ -110,10 +107,9 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell
grid := this.configure.GetTrollRule(comm.TrollItemCount)
for _, v := range trolltrain.Items {
if v > 0 {
gridNum += int32(math.Ceil(float64(v / grid)))
gridNum += int32(math.Ceil(float64(v) / float64(grid)))
}
}
// 获取背包格子上限配置
trolltrain.GridNum = gridNum
if gridNum > this.configure.GetTrollRule(comm.TrollGridCount) { // 背包格子上限
@ -132,8 +128,13 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell
update["npcLv"] = trolltrain.NpcLv
}
}
trolltrain.TotalEarn += int64(earn) // 累计获得的金币
// 清除数量为0 的
for k, v := range trolltrain.Items {
if v == 0 {
delete(trolltrain.Items, k)
}
}
trolltrain.TotalEarn += -int64(earn) // 累计获得的金币
update["items"] = trolltrain.Items
update["price"] = trolltrain.Price
update["totalEarn"] = trolltrain.TotalEarn