跑商ai自动交易卖出货物后清除单价
This commit is contained in:
parent
0ab84c742d
commit
6c80440450
@ -4,20 +4,20 @@
|
||||
"name": "右屏商人",
|
||||
"information": "这是一位熊猫商人",
|
||||
"ico": "action_11001",
|
||||
"time": 300
|
||||
"time": 10
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "上屏商人",
|
||||
"information": "这是一位波比商人再此",
|
||||
"ico": "action_11003",
|
||||
"time": 300
|
||||
"time": 10
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "左屏商人",
|
||||
"information": "这是一位滑板鞋王子",
|
||||
"ico": "ytx_js_14007",
|
||||
"time": 300
|
||||
"time": 10
|
||||
}
|
||||
]
|
@ -71,6 +71,7 @@ const (
|
||||
ModuleSociaty core.M_Modules = "sociaty" //公会
|
||||
ModulePay core.M_Modules = "pay" //支付
|
||||
ModuleAlliance core.M_Modules = "alliance" //联盟学院
|
||||
ModulePrivilege core.M_Modules = "privilege" //特权
|
||||
)
|
||||
|
||||
//数据表名定义处
|
||||
@ -185,6 +186,9 @@ const (
|
||||
TablePayDaily = "paydaily"
|
||||
// 巨怪列车收益记录
|
||||
TableTrollRecord = "trollrecord"
|
||||
|
||||
// 特权
|
||||
TablePrivilege = "privilege"
|
||||
)
|
||||
|
||||
//RPC服务接口定义处
|
||||
|
@ -38,7 +38,7 @@ func (this *configureComp) GetPrivilegeCard(id int32) (configure *cfg.GamePrivil
|
||||
return
|
||||
} else {
|
||||
if configure, ok = v.(*cfg.GamePrivilegeCard).GetDataMap()[id]; !ok {
|
||||
err = fmt.Errorf("ShopConfigure not found:%d ", id)
|
||||
err = fmt.Errorf("GamePrivilegeCardData not found:%d ", id)
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
}
|
||||
@ -57,7 +57,7 @@ func (this *configureComp) GetPrivilegeData(id int32) (result *cfg.GamePrivilege
|
||||
return
|
||||
} else {
|
||||
if result, ok = v.(*cfg.GamePrivilege).GetDataMap()[id]; !ok {
|
||||
err = fmt.Errorf("ShopConfigure not found:%d ", id)
|
||||
err = fmt.Errorf("GamePrivilegeData not found:%d ", id)
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ type ModelPrivilege struct {
|
||||
func (this *ModelPrivilege) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
||||
this.MCompModel.Init(service, module, comp, opt)
|
||||
this.module = module.(*Privilege)
|
||||
this.TableName = comm.TableShop
|
||||
this.TableName = comm.TablePrivilege
|
||||
//创建uid索引
|
||||
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
||||
|
@ -26,7 +26,7 @@ type Privilege struct {
|
||||
|
||||
//模块名
|
||||
func (this *Privilege) GetType() core.M_Modules {
|
||||
return comm.ModuleShop
|
||||
return comm.ModulePrivilege
|
||||
}
|
||||
|
||||
//模块初始化接口 注册用户创建角色事件
|
||||
|
@ -1,93 +0,0 @@
|
||||
package privilege_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego"
|
||||
"go_dreamfactory/lego/base/rpcx"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/modules/equipment"
|
||||
"go_dreamfactory/modules/hero"
|
||||
"go_dreamfactory/modules/items"
|
||||
"go_dreamfactory/modules/shop"
|
||||
"go_dreamfactory/modules/user"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/services"
|
||||
"go_dreamfactory/sys/configure"
|
||||
"go_dreamfactory/sys/db"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
)
|
||||
|
||||
func newService(ops ...rpcx.Option) core.IService {
|
||||
s := new(TestService)
|
||||
s.Configure(ops...)
|
||||
return s
|
||||
}
|
||||
|
||||
//梦工厂基础服务对象
|
||||
type TestService struct {
|
||||
rpcx.RPCXService
|
||||
}
|
||||
|
||||
//初始化相关系统
|
||||
func (this *TestService) InitSys() {
|
||||
this.RPCXService.InitSys()
|
||||
if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil {
|
||||
panic(fmt.Sprintf("init sys.db err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.db success!")
|
||||
}
|
||||
if err := configure.OnInit(this.GetSettings().Sys["configure"], configure.SetConfigPath("F:/work/go/go_dreamfactory/bin/json")); err != nil {
|
||||
panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.configure success!")
|
||||
}
|
||||
}
|
||||
|
||||
var service core.IService
|
||||
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
|
||||
var module = new(shop.Shop)
|
||||
|
||||
//测试环境下初始化db和cache 系统
|
||||
func TestMain(m *testing.M) {
|
||||
service = newService(
|
||||
rpcx.SetConfPath("../../bin/conf/worker_1.yaml"),
|
||||
rpcx.SetVersion("1.0.0.0"),
|
||||
)
|
||||
service.OnInstallComp( //装备组件
|
||||
s_gateComp, //此服务需要接受用户的消息 需要装备网关组件
|
||||
)
|
||||
go func() {
|
||||
lego.Run(service, //运行模块
|
||||
module,
|
||||
hero.NewModule(),
|
||||
user.NewModule(),
|
||||
items.NewModule(),
|
||||
equipment.NewModule(),
|
||||
)
|
||||
}()
|
||||
time.Sleep(time.Second * 3)
|
||||
defer os.Exit(m.Run())
|
||||
}
|
||||
|
||||
//测试api_getlist
|
||||
func Test_Module_APIGetList(t *testing.T) {
|
||||
data, _ := ptypes.MarshalAny(&pb.ShopGetListReq{SType: pb.ShopType_GoldShop, IsManualRefresh: false})
|
||||
reply := &pb.RPCMessageReply{}
|
||||
s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62b16dda909b2f8faeff788d", MainType: "shop", SubType: "getlist", Message: data}, reply)
|
||||
log.Debugf("reply:%v", reply)
|
||||
}
|
||||
|
||||
//测试api_buy
|
||||
func Test_Module_APIBuy(t *testing.T) {
|
||||
data, _ := ptypes.MarshalAny(&pb.ShopBuyReq{GoodsId: 7})
|
||||
reply := &pb.RPCMessageReply{}
|
||||
s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62b16dda909b2f8faeff788d", MainType: "shop", SubType: "buy", Message: data}, reply)
|
||||
log.Debugf("reply:%v", reply)
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package timer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/modules"
|
||||
@ -14,6 +15,7 @@ import (
|
||||
"go_dreamfactory/lego/core/cbase"
|
||||
"go_dreamfactory/lego/sys/cron"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/lego/sys/redis/pipe"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@ -22,6 +24,7 @@ import (
|
||||
|
||||
var (
|
||||
game_seasonloop = "game_seasonloop.json"
|
||||
game_seasonreward = "game_pagodaseasonreward.json"
|
||||
)
|
||||
|
||||
type SeasonPagoda struct {
|
||||
@ -30,6 +33,7 @@ type SeasonPagoda struct {
|
||||
modules.MCompModel
|
||||
service core.IService
|
||||
module *Timer
|
||||
mail comm.Imail
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
@ -39,6 +43,11 @@ func (this *SeasonPagoda) Init(service core.IService, module core.IModule, comp
|
||||
this.MCompModel.Init(service, module, comp, options)
|
||||
this.service = service
|
||||
this.module = module.(*Timer)
|
||||
|
||||
if module1, err := this.service.GetModule(comm.ModuleMail); err == nil {
|
||||
this.mail = module1.(comm.Imail)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@ -46,6 +55,7 @@ func (this *SeasonPagoda) Start() (err error) {
|
||||
err = this.MCompModel.Start()
|
||||
err = this.MCompConfigure.Start()
|
||||
configure.RegisterConfigure(game_seasonloop, cfg.NewGameSeasonLoop, nil)
|
||||
configure.RegisterConfigure(game_seasonreward, cfg.NewGamePagodaSeasonReward, nil)
|
||||
cron.AddFunc("0 0 23 L * ?", this.TimerSeasonOver) //每月最后一天23点执行一次
|
||||
cron.AddFunc("0 0 5 /* * ?", this.TimerSeasonStar) //每月第一天5点执行一次
|
||||
|
||||
@ -63,7 +73,21 @@ func (this *SeasonPagoda) CreatTestData(index int) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (this *SeasonPagoda) GetSeasonReward() []int32 {
|
||||
sz := make([]int32, 0)
|
||||
if v, err := this.GetConfigure(game_seasonreward); err != nil {
|
||||
log.Errorf("get global conf err:%v", err)
|
||||
return sz
|
||||
} else {
|
||||
if configure, ok := v.(*cfg.GamePagodaSeasonReward); ok {
|
||||
for _, v := range configure.GetDataList() {
|
||||
sz = append(sz, v.Ranking[0])
|
||||
}
|
||||
}
|
||||
log.Errorf("%T no is *cfg.Game_global", v)
|
||||
return sz
|
||||
}
|
||||
}
|
||||
func (this *SeasonPagoda) GetSeasonLoop(id int32) *cfg.GameSeasonLoopData {
|
||||
|
||||
if v, err := this.GetConfigure(game_seasonloop); err != nil {
|
||||
@ -82,6 +106,27 @@ func (this *SeasonPagoda) GetSeasonLoop(id int32) *cfg.GameSeasonLoopData {
|
||||
func (this *SeasonPagoda) TimerSeasonOver() {
|
||||
this.module.Debugf("TimerSeasonOver:%d", time.Now().Unix())
|
||||
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
var (
|
||||
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
||||
)
|
||||
|
||||
rd := pipe.ZRange("pagodaSeasonRank", 0, 50)
|
||||
|
||||
if _, err = pipe.Exec(); err != nil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
_data3 := rd.Val()
|
||||
this.module.Debugf("%v", _data3)
|
||||
//sz := this.GetSeasonReward()
|
||||
|
||||
// this.mail.SendNewMail(&pb.DBMailData{
|
||||
// CreateTime: uint64(time.Now().Unix()),
|
||||
// Items: nil,
|
||||
// }, _data3...)
|
||||
}
|
||||
|
||||
if db.IsCross() {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
if rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{}); rst != nil {
|
||||
|
@ -152,6 +152,9 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell
|
||||
for k, v := range trolltrain.Items {
|
||||
if v == 0 {
|
||||
delete(trolltrain.Items, k)
|
||||
if _, ok := trolltrain.Price[k]; ok {
|
||||
delete(trolltrain.Price, k) // 清除价格
|
||||
}
|
||||
}
|
||||
}
|
||||
trolltrain.TotalEarn += -int64(earn) // 累计获得的金币
|
||||
|
@ -204,7 +204,6 @@ func (this *Troll) BuyAllItem(uid string, troll *pb.DBTrollTrain, price map[int3
|
||||
for {
|
||||
if leftGirdNum > 0 && troll.Shop[v.Id] < v.Max {
|
||||
leftGirdNum--
|
||||
//troll.Items[v.Id] += maxgoods
|
||||
troll.Shop[v.Id] += maxgoods
|
||||
box[v.Id] += maxgoods // 加入篮子
|
||||
} else {
|
||||
@ -216,11 +215,7 @@ func (this *Troll) BuyAllItem(uid string, troll *pb.DBTrollTrain, price map[int3
|
||||
if full != 0 {
|
||||
box[v.Id] += (maxgoods - full) // 格子补满
|
||||
}
|
||||
g := troll.Items[v.Id] * troll.Price[v.Id]
|
||||
g += box[v.Id] * price[v.Id]
|
||||
if (troll.Items[v.Id] + box[v.Id]) != 0 {
|
||||
troll.Price[v.Id] = g / (troll.Items[v.Id] + box[v.Id])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 通过金币来校验哪些物品可以买
|
||||
@ -240,8 +235,15 @@ func (this *Troll) BuyAllItem(uid string, troll *pb.DBTrollTrain, price map[int3
|
||||
if len(buyBox) == 0 {
|
||||
return // 没有可购买的直接返回
|
||||
}
|
||||
for _, v := range goods {
|
||||
for _, v := range goods { // 计算购买后的平均价格
|
||||
g := troll.Items[v.Id] * troll.Price[v.Id]
|
||||
g += buyBox[v.Id] * price[v.Id]
|
||||
troll.Items[v.Id] += buyBox[v.Id]
|
||||
|
||||
if troll.Items[v.Id] != 0 {
|
||||
troll.Price[v.Id] = g / troll.Items[v.Id]
|
||||
}
|
||||
|
||||
}
|
||||
gold = costGold
|
||||
// 统计格子
|
||||
|
Loading…
Reference in New Issue
Block a user