Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
7e6a86024f
@ -51,8 +51,13 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, k1 := range cityInfo.Like {
|
for _, k1 := range cityInfo.Like {
|
||||||
if k == k1 && v < caravan.Items[k].Count {
|
if k == k1 {
|
||||||
caravan.Items[k].Count -= v
|
if v < caravan.Items[k].Count {
|
||||||
|
caravan.Items[k].Count -= v
|
||||||
|
} else {
|
||||||
|
code = pb.ErrorCode_TrollSellMax // 卖出数量不足
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 找到城市想要收购的物品
|
// 找到城市想要收购的物品
|
||||||
@ -94,6 +99,10 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
caravan.Items[k].Count += v
|
caravan.Items[k].Count += v
|
||||||
|
if this.module.ArrayBag(caravan, upperLimit) { // 背包满了
|
||||||
|
code = pb.ErrorCode_TrollMaxItemCount
|
||||||
|
return
|
||||||
|
}
|
||||||
totla += price * v
|
totla += price * v
|
||||||
caravan.Items[k].Price = totla / caravan.Items[k].Count
|
caravan.Items[k].Price = totla / caravan.Items[k].Count
|
||||||
// 同步更新该城市的 出售货物信息
|
// 同步更新该城市的 出售货物信息
|
||||||
@ -116,6 +125,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
|
|||||||
this.module.Errorf("获得虚拟币失败:%d", code)
|
this.module.Errorf("获得虚拟币失败:%d", code)
|
||||||
}
|
}
|
||||||
update["item"] = caravan.Items
|
update["item"] = caravan.Items
|
||||||
|
update["baglimit"] = caravan.Baglimit
|
||||||
this.module.modelCaravan.modifyCaravanDataByObjId(session.GetUserId(), update)
|
this.module.modelCaravan.modifyCaravanDataByObjId(session.GetUserId(), update)
|
||||||
session.SendMsg(string(this.module.GetType()), "buyorsell", &pb.CaravanBuyOrSellResp{
|
session.SendMsg(string(this.module.GetType()), "buyorsell", &pb.CaravanBuyOrSellResp{
|
||||||
Data: caravan,
|
Data: caravan,
|
||||||
|
@ -299,3 +299,26 @@ func (this *Caravan) TaskComplete(session comm.IUserSession, taskid int32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 整理背包 (true 表示背包装不下)
|
||||||
|
func (this *Caravan) ArrayBag(data *pb.DBCaravan, limit int32) (bFull bool) {
|
||||||
|
var count int32
|
||||||
|
for k, v := range data.Items {
|
||||||
|
if v.Count == 0 {
|
||||||
|
delete(data.Items, k)
|
||||||
|
} else {
|
||||||
|
for {
|
||||||
|
count++
|
||||||
|
if v.Count > limit {
|
||||||
|
v.Count -= limit
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if count > data.Baglimit {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user