Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
48247e9095
@ -35,7 +35,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
dayMaxCount := this.configure.GetTrollRule(comm.TrollBuyCount)
|
dayMaxCount := this.configure.GetTrollRule(comm.TrollBuyCount)
|
||||||
//aiMaxCount := this.configure.GetTrollRule(comm.TrollAIBuyCount)
|
aiMaxCount := this.configure.GetTrollRule(comm.TrollAIBuyCount)
|
||||||
for k, v := range req.Items {
|
for k, v := range req.Items {
|
||||||
|
|
||||||
if v == 0 { // 过滤数量为0 的消息
|
if v == 0 { // 过滤数量为0 的消息
|
||||||
@ -49,19 +49,14 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell
|
|||||||
if !bSell {
|
if !bSell {
|
||||||
bSell = true
|
bSell = true
|
||||||
trolltrain.SellCount += 1 // 交易次数+1
|
trolltrain.SellCount += 1 // 交易次数+1
|
||||||
if trolltrain.AiCount+trolltrain.SellCount >= dayMaxCount {
|
if trolltrain.SellCount > dayMaxCount || (trolltrain.SellCount+trolltrain.AiCount) > aiMaxCount {
|
||||||
//if trolltrain.SellCount > aiMaxCount-trolltrain.AiCount {
|
|
||||||
code = pb.ErrorCode_TrollMaxSellCount // 达到最大交易次数 直接返回
|
code = pb.ErrorCode_TrollMaxSellCount // 达到最大交易次数 直接返回
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
update["sellCount"] = trolltrain.SellCount
|
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 _, ok := trolltrain.Shop[k]; !ok {
|
||||||
if v > 0 {
|
if v > 0 {
|
||||||
trolltrain.Shop[k] = v // 限购
|
trolltrain.Shop[k] = v // 限购
|
||||||
@ -80,7 +75,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell
|
|||||||
// 买入上限 直接返回
|
// 买入上限 直接返回
|
||||||
code = pb.ErrorCode_TrollBuyMax
|
code = pb.ErrorCode_TrollBuyMax
|
||||||
return
|
return
|
||||||
} else if trolltrain.Items[k] < 0 { //卖出数量不足
|
} else if trolltrain.Items[k]+v < 0 { //卖出数量不足
|
||||||
code = pb.ErrorCode_TrollSellMax
|
code = pb.ErrorCode_TrollSellMax
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -95,7 +90,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell
|
|||||||
//消耗的金币
|
//消耗的金币
|
||||||
gold -= trolltrain.Price[k] * trolltrain.Items[k]
|
gold -= trolltrain.Price[k] * trolltrain.Items[k]
|
||||||
} else {
|
} else {
|
||||||
p := this.configure.GetTrollCoefficient(trolltrain.TarinPos)
|
p := this.configure.GetTrollCoefficient(trolltrain.RangeId)
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -112,14 +107,16 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v < 0 { // 卖出
|
if v < 0 { // 卖出
|
||||||
|
trolltrain.Items[k] += v
|
||||||
if sellPrice > trolltrain.Price[k] { // 赚了
|
if sellPrice > trolltrain.Price[k] { // 赚了
|
||||||
earn += (sellPrice - trolltrain.Price[k]) * v
|
earn += (sellPrice - trolltrain.Price[k]) * v
|
||||||
}
|
}
|
||||||
gold += sellPrice * v
|
gold += sellPrice * v
|
||||||
} else { // 买入 计算平均价格
|
} else { // 买入 计算平均价格
|
||||||
totalGold := (trolltrain.Items[k] - v) * trolltrain.Price[k]
|
totalGold := trolltrain.Items[k] * trolltrain.Price[k]
|
||||||
totalGold += v * sellPrice
|
totalGold += v * sellPrice
|
||||||
trolltrain.Price[k] = totalGold / (trolltrain.Items[k])
|
trolltrain.Items[k] += v
|
||||||
|
trolltrain.Price[k] = totalGold / trolltrain.Items[k]
|
||||||
gold -= v * sellPrice
|
gold -= v * sellPrice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,13 +139,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell
|
|||||||
code = pb.ErrorCode_GoldNoEnough
|
code = pb.ErrorCode_GoldNoEnough
|
||||||
return
|
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 的
|
// 清除数量为0 的
|
||||||
for k, v := range trolltrain.Items {
|
for k, v := range trolltrain.Items {
|
||||||
if v == 0 {
|
if v == 0 {
|
||||||
@ -159,6 +150,13 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
trolltrain.TotalEarn += -int64(earn) // 累计获得的金币
|
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["items"] = trolltrain.Items
|
||||||
update["price"] = trolltrain.Price
|
update["price"] = trolltrain.Price
|
||||||
update["totalEarn"] = trolltrain.TotalEarn
|
update["totalEarn"] = trolltrain.TotalEarn
|
||||||
|
@ -32,10 +32,10 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq)
|
|||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dayMaxCount := this.configure.GetTrollRule(comm.TrollBuyCount) // 8
|
//dayMaxCount := this.configure.GetTrollRule(comm.TrollBuyCount) // 8
|
||||||
aiCount := this.configure.GetTrollRule(comm.TrollAIBuyCount) // 10
|
aiCount := this.configure.GetTrollRule(comm.TrollAIBuyCount) // 10
|
||||||
if trolltrain.AiCount+trolltrain.SellCount < dayMaxCount {
|
if trolltrain.AiCount+trolltrain.SellCount < aiCount {
|
||||||
this.module.TrollAI(session, trolltrain, aiCount)
|
this.module.TrollAI(session, trolltrain)
|
||||||
}
|
}
|
||||||
|
|
||||||
maxCoefficient = this.configure.GetTrollMaxCoefficientNux() // 增长幅度的最大值
|
maxCoefficient = this.configure.GetTrollMaxCoefficientNux() // 增长幅度的最大值
|
||||||
|
@ -57,7 +57,7 @@ func (this *Troll) ModifyTrollData(uid string, data map[string]interface{}) (cod
|
|||||||
return
|
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 (
|
var (
|
||||||
sellPrice map[int32]int32 // 出售货物价格
|
sellPrice map[int32]int32 // 出售货物价格
|
||||||
totalGold int32
|
totalGold int32
|
||||||
@ -122,7 +122,7 @@ func (this *Troll) TrollAI(session comm.IUserSession, troll *pb.DBTrollTrain, ai
|
|||||||
|
|
||||||
troll.AiCount++
|
troll.AiCount++
|
||||||
aiMaxCount := this.configure.GetTrollRule(comm.TrollAIBuyCount)
|
aiMaxCount := this.configure.GetTrollRule(comm.TrollAIBuyCount)
|
||||||
if troll.AiCount > aiMaxCount { //达到最大交易次数
|
if troll.AiCount+troll.SellCount > aiMaxCount { //达到最大交易次数
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user