diff --git a/modules/troll/api_buyorsell.go b/modules/troll/api_buyorsell.go index d8ef8ba63..d488b68ae 100644 --- a/modules/troll/api_buyorsell.go +++ b/modules/troll/api_buyorsell.go @@ -36,6 +36,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell } dayMaxCount := this.configure.GetTrollRule(comm.TrollBuyCount) for k, v := range req.Items { + if v == 0 { // 过滤数量为0 的消息 continue } @@ -102,6 +103,12 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell } else { sellPrice = int32(p.Coefficient) * goods.Goodsprice / 1000 } + // 校验是不是惊喜价格 + if d1, ok := trolltrain.SurpriseID[trolltrain.TarinPos-1]; ok { + if d1 == k { + sellPrice = this.configure.GetTrollRule(comm.TrollSurprise) / 1000 + } + } if v < 0 { // 卖出 if sellPrice > trolltrain.Price[k] { // 赚了 earn += (sellPrice - trolltrain.Price[k]) * v diff --git a/modules/troll/api_getlist.go b/modules/troll/api_getlist.go index d956e4aea..9f8f48768 100644 --- a/modules/troll/api_getlist.go +++ b/modules/troll/api_getlist.go @@ -49,7 +49,9 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq) return } // 跨天 则清除 每日交易次数 - if !utils.IsToday(trolltrain.RefreshTime) { + if !utils.IsToday(trolltrain.ResetTime) { + trolltrain.ResetTime = time.Now().Unix() + update["resetTime"] = trolltrain.ResetTime trolltrain.SellCount = 0 update["sellCount"] = trolltrain.SellCount // 重置每日交易次数 trolltrain.AiCount = 0 @@ -77,15 +79,19 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq) trolltrain.Shop = make(map[int32]int32) // 清空商人的购买数据 update["shop"] = trolltrain.Shop circleCount = (int32(t) / circletime) // 经过的周期数 - if circleCount > 1 { - trolltrain.Circle += circleCount + + c := int32((time.Now().Unix() - trolltrain.Ctime)) / circletime + if trolltrain.Circle != c { + trolltrain.SurpriseID = make(map[int32]int32, 0) n, _ := rand.Int(rand.Reader, big.NewInt(int64(trainNum))) n2, _ := rand.Int(rand.Reader, big.NewInt(int64(maxCoefficient))) trolltrain.SurpriseID[int32(n.Int64())+1] = int32(n2.Int64()) + 1 + update["surpriseID"] = trolltrain.SurpriseID + trolltrain.Circle = c + update["circle"] = trolltrain.Circle } leftTime = (int32(t) % circletime) // 循环次数 - index += circleCount * trainNum // 计算火车的位置信息 for _, v := range sz { if leftTime <= v { diff --git a/modules/troll/model_gourmet.go b/modules/troll/model_gourmet.go index c4ef2cd9a..3aa484e08 100644 --- a/modules/troll/model_gourmet.go +++ b/modules/troll/model_gourmet.go @@ -50,6 +50,7 @@ func (this *modelTroll) getTrollList(uid string) (result *pb.DBTrollTrain, err e Ctime: time.Now().Unix(), Circle: 0, SurpriseID: map[int32]int32{}, + ResetTime: time.Now().Unix(), } if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err { // 创建一条数据 diff --git a/pb/troll_db.pb.go b/pb/troll_db.pb.go index 30971521c..b9a80dfbf 100644 --- a/pb/troll_db.pb.go +++ b/pb/troll_db.pb.go @@ -26,25 +26,26 @@ type DBTrollTrain struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID - Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID - Items map[int32]int32 `protobuf:"bytes,3,rep,name=items,proto3" json:"items" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 货物 key 货物ID - Price map[int32]int32 `protobuf:"bytes,4,rep,name=price,proto3" json:"price" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 货物买入价格 key 货物ID - GridNum int32 `protobuf:"varint,5,opt,name=gridNum,proto3" json:"gridNum" bson:"gridNum"` //当前使用格子数量 - TarinPos int32 `protobuf:"varint,6,opt,name=tarinPos,proto3" json:"tarinPos" bson:"tarinPos"` //火车位置 (商人位置) - RangeId int32 `protobuf:"varint,7,opt,name=rangeId,proto3" json:"rangeId" bson:"rangeId"` //增长幅度 - Buy int32 `protobuf:"varint,8,opt,name=buy,proto3" json:"buy"` // 挂机进货标准/千分比 - Sell int32 `protobuf:"varint,9,opt,name=sell,proto3" json:"sell"` //挂机卖出标准/千分比 - NpcLv int32 `protobuf:"varint,10,opt,name=npcLv,proto3" json:"npcLv" bson:"npcLv"` //npc 等级 - NpcReward map[int32]int32 `protobuf:"bytes,11,rep,name=npcReward,proto3" json:"npcReward" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"npcReward"` //npc奖励 - TotalEarn int64 `protobuf:"varint,12,opt,name=totalEarn,proto3" json:"totalEarn" bson:"totalEarn"` //累计赚的钱 - SellCount int32 `protobuf:"varint,13,opt,name=sellCount,proto3" json:"sellCount" bson:"sellCount"` //今天已经卖出次数 - RefreshTime int64 `protobuf:"varint,14,opt,name=refreshTime,proto3" json:"refreshTime" bson:"refreshTime"` //最后一次刷新的时间 通过这个计算下一次刷新时间 - AiCount int32 `protobuf:"varint,15,opt,name=aiCount,proto3" json:"aiCount"` //@go_tags(`bson:"aiCount"` AI 交易次数 - Shop map[int32]int32 `protobuf:"bytes,16,rep,name=shop,proto3" json:"shop" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 商人的限购数量 - Ctime int64 `protobuf:"varint,17,opt,name=ctime,proto3" json:"ctime"` - Circle int32 `protobuf:"varint,18,opt,name=circle,proto3" json:"circle"` // 循环商人的次数 - SurpriseID map[int32]int32 `protobuf:"bytes,19,rep,name=surpriseID,proto3" json:"surpriseID" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` //key商人id value惊喜货物ID + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID + Items map[int32]int32 `protobuf:"bytes,3,rep,name=items,proto3" json:"items" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 货物 key 货物ID + Price map[int32]int32 `protobuf:"bytes,4,rep,name=price,proto3" json:"price" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 货物买入价格 key 货物ID + GridNum int32 `protobuf:"varint,5,opt,name=gridNum,proto3" json:"gridNum" bson:"gridNum"` //当前使用格子数量 + TarinPos int32 `protobuf:"varint,6,opt,name=tarinPos,proto3" json:"tarinPos" bson:"tarinPos"` //火车位置 (商人位置) + RangeId int32 `protobuf:"varint,7,opt,name=rangeId,proto3" json:"rangeId" bson:"rangeId"` //增长幅度 + Buy int32 `protobuf:"varint,8,opt,name=buy,proto3" json:"buy"` // 挂机进货标准/千分比 + Sell int32 `protobuf:"varint,9,opt,name=sell,proto3" json:"sell"` //挂机卖出标准/千分比 + NpcLv int32 `protobuf:"varint,10,opt,name=npcLv,proto3" json:"npcLv" bson:"npcLv"` //npc 等级 + NpcReward map[int32]int32 `protobuf:"bytes,11,rep,name=npcReward,proto3" json:"npcReward" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"npcReward"` //npc奖励 + TotalEarn int64 `protobuf:"varint,12,opt,name=totalEarn,proto3" json:"totalEarn" bson:"totalEarn"` //累计赚的钱 + SellCount int32 `protobuf:"varint,13,opt,name=sellCount,proto3" json:"sellCount" bson:"sellCount"` //今天已经卖出次数 + RefreshTime int64 `protobuf:"varint,14,opt,name=refreshTime,proto3" json:"refreshTime" bson:"refreshTime"` //最后一次刷新的时间 通过这个计算下一次刷新时间 + AiCount int32 `protobuf:"varint,15,opt,name=aiCount,proto3" json:"aiCount" bson:"aiCount"` //AI 交易次数 + Shop map[int32]int32 `protobuf:"bytes,16,rep,name=shop,proto3" json:"shop" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 商人的限购数量 + Ctime int64 `protobuf:"varint,17,opt,name=ctime,proto3" json:"ctime"` // 创建时间 + Circle int32 `protobuf:"varint,18,opt,name=circle,proto3" json:"circle"` // 循环商人的次数 + SurpriseID map[int32]int32 `protobuf:"bytes,19,rep,name=surpriseID,proto3" json:"surpriseID" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"surpriseID"` //key商人id value惊喜货物ID + ResetTime int64 `protobuf:"varint,20,opt,name=resetTime,proto3" json:"resetTime" bson:"resetTime"` //每日重置时间 } func (x *DBTrollTrain) Reset() { @@ -212,11 +213,18 @@ func (x *DBTrollTrain) GetSurpriseID() map[int32]int32 { return nil } +func (x *DBTrollTrain) GetResetTime() int64 { + if x != nil { + return x.ResetTime + } + return 0 +} + var File_troll_troll_db_proto protoreflect.FileDescriptor var file_troll_troll_db_proto_rawDesc = []byte{ 0x0a, 0x14, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5f, 0x64, 0x62, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x94, 0x07, 0x0a, 0x0c, 0x44, 0x42, 0x54, 0x72, 0x6f, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb2, 0x07, 0x0a, 0x0c, 0x44, 0x42, 0x54, 0x72, 0x6f, 0x6c, 0x6c, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x2e, 0x0a, 0x05, 0x69, 0x74, 0x65, @@ -255,26 +263,28 @@ var file_troll_troll_db_proto_rawDesc = []byte{ 0x49, 0x44, 0x18, 0x13, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x44, 0x42, 0x54, 0x72, 0x6f, 0x6c, 0x6c, 0x54, 0x72, 0x61, 0x69, 0x6e, 0x2e, 0x53, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x49, 0x44, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0a, 0x73, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, - 0x65, 0x49, 0x44, 0x1a, 0x38, 0x0a, 0x0a, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, - 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, - 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x38, 0x0a, - 0x0a, 0x50, 0x72, 0x69, 0x63, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, - 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3c, 0x0a, 0x0e, 0x4e, 0x70, 0x63, 0x52, 0x65, - 0x77, 0x61, 0x72, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x65, 0x49, 0x44, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x73, 0x65, 0x74, 0x54, 0x69, 0x6d, 0x65, + 0x18, 0x14, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x72, 0x65, 0x73, 0x65, 0x74, 0x54, 0x69, 0x6d, + 0x65, 0x1a, 0x38, 0x0a, 0x0a, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, + 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, + 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x38, 0x0a, 0x0a, 0x50, + 0x72, 0x69, 0x63, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x37, 0x0a, 0x09, 0x53, 0x68, 0x6f, 0x70, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, - 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3d, - 0x0a, 0x0f, 0x53, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x49, 0x44, 0x45, 0x6e, 0x74, 0x72, - 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, - 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x06, 0x5a, - 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3c, 0x0a, 0x0e, 0x4e, 0x70, 0x63, 0x52, 0x65, 0x77, 0x61, + 0x72, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, + 0x02, 0x38, 0x01, 0x1a, 0x37, 0x0a, 0x09, 0x53, 0x68, 0x6f, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, + 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3d, 0x0a, 0x0f, + 0x53, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x49, 0x44, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, + 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, + 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x06, 0x5a, 0x04, 0x2e, + 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (