商队任务统计
This commit is contained in:
parent
a15be334b0
commit
a079a06c7c
@ -20,10 +20,13 @@ func (this *apiComp) BuyOrSellCheck(session comm.IUserSession, req *pb.CaravanBu
|
|||||||
|
|
||||||
func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSellReq) (errdata *pb.ErrorData) {
|
func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSellReq) (errdata *pb.ErrorData) {
|
||||||
var (
|
var (
|
||||||
update map[string]interface{}
|
update map[string]interface{}
|
||||||
addScore int32 // 收益
|
addScore int32 // 收益
|
||||||
cityInfo *pb.CityInfo
|
cityInfo *pb.CityInfo
|
||||||
ok bool
|
ok bool
|
||||||
|
sellValue int32 // 任务统计 贩卖货物价值
|
||||||
|
buyValue int32 // 任务统计 贩卖货物价值
|
||||||
|
sellSpValue int32 // 任务统计 向指定X城市贩卖货物贩卖货物价值
|
||||||
)
|
)
|
||||||
update = make(map[string]interface{})
|
update = make(map[string]interface{})
|
||||||
if errdata = this.BuyOrSellCheck(session, req); errdata != nil {
|
if errdata = this.BuyOrSellCheck(session, req); errdata != nil {
|
||||||
@ -51,7 +54,6 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
|
|||||||
// special 城市卖给玩家的商品
|
// special 城市卖给玩家的商品
|
||||||
// exspecial 城市想要玩家卖给他的商品库
|
// exspecial 城市想要玩家卖给他的商品库
|
||||||
if !req.IsBuy { // 卖给npc
|
if !req.IsBuy { // 卖给npc
|
||||||
|
|
||||||
var cb int32 // 成本价
|
var cb int32 // 成本价
|
||||||
for k, v := range req.Items {
|
for k, v := range req.Items {
|
||||||
// 校验背包数据够不够
|
// 校验背包数据够不够
|
||||||
@ -68,10 +70,11 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
|
|||||||
cb = items.Price // 获取成本价
|
cb = items.Price // 获取成本价
|
||||||
price = items.Price
|
price = items.Price
|
||||||
bFound := false
|
bFound := false
|
||||||
for _, v := range cityInfo.Special {
|
for _, key := range cityInfo.Special {
|
||||||
if v == k {
|
if key == k {
|
||||||
if cityConf, err := this.module.configure.GetCaravanCity(req.City); err == nil {
|
if cityConf, err := this.module.configure.GetCaravanCity(req.City); err == nil {
|
||||||
price = cityConf.Specialnum * price / 1000
|
price = cityConf.Specialnum * price / 1000
|
||||||
|
sellSpValue += cityConf.Specialnum * price * v / 1000
|
||||||
bFound = true
|
bFound = true
|
||||||
} else {
|
} else {
|
||||||
errdata = &pb.ErrorData{
|
errdata = &pb.ErrorData{
|
||||||
@ -97,7 +100,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sellValue += price * v
|
||||||
if errdata = this.module.DispenseRes(session, []*cfg.Gameatn{{
|
if errdata = this.module.DispenseRes(session, []*cfg.Gameatn{{
|
||||||
A: "attr",
|
A: "attr",
|
||||||
T: "merchantmoney",
|
T: "merchantmoney",
|
||||||
@ -176,7 +179,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
|
|||||||
}
|
}
|
||||||
bFound := false
|
bFound := false
|
||||||
// 计算均价
|
// 计算均价
|
||||||
totla := caravan.Items[k].Count * caravan.Items[k].Price
|
buyValue = caravan.Items[k].Count * caravan.Items[k].Price
|
||||||
var price int32
|
var price int32
|
||||||
price = caravan.Goods[k].Price
|
price = caravan.Goods[k].Price
|
||||||
for _, v := range cityInfo.Special {
|
for _, v := range cityInfo.Special {
|
||||||
@ -194,8 +197,8 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
|
|||||||
}
|
}
|
||||||
caravan.Items[k].Count += v
|
caravan.Items[k].Count += v
|
||||||
|
|
||||||
totla += price * v
|
buyValue += price * v
|
||||||
caravan.Items[k].Price = totla / caravan.Items[k].Count
|
caravan.Items[k].Price = buyValue / caravan.Items[k].Count
|
||||||
// 同步更新该城市的 出售货物信息
|
// 同步更新该城市的 出售货物信息
|
||||||
cityInfo.Count[k] += v
|
cityInfo.Count[k] += v
|
||||||
|
|
||||||
@ -256,19 +259,9 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
|
|||||||
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype209, req.City, opCount))
|
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype209, req.City, opCount))
|
||||||
} else { // 卖
|
} else { // 卖
|
||||||
//向指定X城市贩卖货物,贩卖货物价值需要X虚拟币以上
|
//向指定X城市贩卖货物,贩卖货物价值需要X虚拟币以上
|
||||||
var price int32
|
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype210, req.City, sellValue))
|
||||||
for k, v := range req.Items {
|
// Rtype211 TaskType = 211 // 向指定X城市,贩卖价值X虚拟币以上的对应城市急需货物
|
||||||
|
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype211, req.City, sellValue))
|
||||||
price += caravan.Items[k].Price * v
|
|
||||||
}
|
|
||||||
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype210, req.City, price))
|
|
||||||
|
|
||||||
// 急需货物
|
|
||||||
if v, ok := caravan.City[req.City]; ok {
|
|
||||||
for range v.Exspecial {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype212, req.City)) // 接取任务后,商队抵达指定城市
|
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype212, req.City)) // 接取任务后,商队抵达指定城市
|
||||||
go this.module.ModuleBuried.TriggerBuried(session.Clone(), szTask...)
|
go this.module.ModuleBuried.TriggerBuried(session.Clone(), szTask...)
|
||||||
|
Loading…
Reference in New Issue
Block a user