This commit is contained in:
meixiongfeng 2023-05-17 15:24:01 +08:00
parent 7246ba738a
commit dbad4c408a
3 changed files with 33 additions and 5 deletions

View File

@ -52,7 +52,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
}
for _, k1 := range cityInfo.Like {
if k == k1 {
if v < caravan.Items[k].Count {
if v <= caravan.Items[k].Count {
caravan.Items[k].Count -= v
} else {
code = pb.ErrorCode_TrollSellMax // 卖出数量不足
@ -73,6 +73,13 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
}
addScore += price * v // 卖出收益
}
if this.module.ArrayBag(caravan, upperLimit) { // 背包满了
code = pb.ErrorCode_TrollMaxItemCount
return
}
// 统计 收益
caravan.Profit += int64(addScore)
update["profit"] = caravan.Profit
} else { // 买入
for k, v := range req.Items {
items, ok := caravan.Items[k]
@ -99,10 +106,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
}
}
caravan.Items[k].Count += v
if this.module.ArrayBag(caravan, upperLimit) { // 背包满了
code = pb.ErrorCode_TrollMaxItemCount
return
}
totla += price * v
caravan.Items[k].Price = totla / caravan.Items[k].Count
// 同步更新该城市的 出售货物信息
@ -116,6 +120,10 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
}
addScore -= price * v
}
if this.module.ArrayBag(caravan, upperLimit) { // 背包满了
code = pb.ErrorCode_TrollMaxItemCount
return
}
}
if code = this.module.DispenseRes(session, []*cfg.Gameatn{{
A: "attr",
@ -126,6 +134,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
}
update["item"] = caravan.Items
update["baglimit"] = caravan.Baglimit
update["useCount"] = caravan.UseCount // 更新背包使用数量
this.module.modelCaravan.modifyCaravanDataByObjId(session.GetUserId(), update)
session.SendMsg(string(this.module.GetType()), "buyorsell", &pb.CaravanBuyOrSellResp{
Data: caravan,

View File

@ -43,6 +43,7 @@ func (this *modelCaravan) getCaravanList(uid string) (result *pb.DBCaravan, err
result.Id = primitive.NewObjectID().Hex()
result.Resettime = configure.Now().Unix() // 设置起始刷新时间
result.Lv = 1
if conf := this.module.configure.GetCaravanLv(1); conf != nil {
result.Baglimit = conf.Bagtop
}

View File

@ -320,5 +320,23 @@ func (this *Caravan) ArrayBag(data *pb.DBCaravan, limit int32) (bFull bool) {
if count > data.Baglimit {
return false
}
data.UseCount = count
return true
}
// 校验商队等级
func (this *Caravan) CheckCaravavLvUp(data *pb.DBCaravan) (curLv int32) {
curLv = data.Lv
for {
curLv++
if conf := this.configure.GetCaravanLv(curLv); conf != nil {
if conf.Newmoneyexp > int32(data.Profit) {
curLv -= 1
break
}
} else {
break
}
}
return curLv
}