更新铁匠铺协议
This commit is contained in:
parent
92fd5e34cb
commit
dc5c2729cd
@ -7,7 +7,8 @@
|
||||
"text": ""
|
||||
},
|
||||
"goods": [],
|
||||
"reword": []
|
||||
"reword": [],
|
||||
"weight": 4500
|
||||
},
|
||||
{
|
||||
"customer_id": 2,
|
||||
@ -17,7 +18,8 @@
|
||||
"text": ""
|
||||
},
|
||||
"goods": [],
|
||||
"reword": []
|
||||
"reword": [],
|
||||
"weight": 4500
|
||||
},
|
||||
{
|
||||
"customer_id": 3,
|
||||
@ -27,7 +29,8 @@
|
||||
"text": ""
|
||||
},
|
||||
"goods": [],
|
||||
"reword": []
|
||||
"reword": [],
|
||||
"weight": 500
|
||||
},
|
||||
{
|
||||
"customer_id": 4,
|
||||
@ -37,6 +40,7 @@
|
||||
"text": ""
|
||||
},
|
||||
"goods": [],
|
||||
"reword": []
|
||||
"reword": [],
|
||||
"weight": 500
|
||||
}
|
||||
]
|
@ -1,18 +0,0 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
cfg "go_dreamfactory/cmd/v2/configure/structs"
|
||||
"go_dreamfactory/cmd/v2/lib/common"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGjson(t *testing.T) {
|
||||
if tables, err := cfg.NewTables(common.Loader); err != nil {
|
||||
println(err.Error())
|
||||
} else {
|
||||
for _, v := range tables.TestFlow.GetDataList() {
|
||||
fmt.Println(v.Msg)
|
||||
}
|
||||
}
|
||||
}
|
@ -17,9 +17,10 @@ const (
|
||||
game_smproficiency = "game_smithyproficiency.json" // 铁匠铺熟练度
|
||||
game_smithystove = "game_smithystovev1.json" // 铁匠铺台子 打造配置
|
||||
game_smithytools = "game_smithytool.json" // 铁匠铺工具台
|
||||
game_smithycustomer = "game_smithycustomer.json"
|
||||
)
|
||||
|
||||
///配置管理基础组件
|
||||
// /配置管理基础组件
|
||||
type configureComp struct {
|
||||
modules.MCompConfigure
|
||||
module *Smithy
|
||||
@ -29,7 +30,7 @@ type configureComp struct {
|
||||
_mapProficile map[int64]*cfg.GameSmithyProficiencyData // 熟练度 key 卷轴ID+ 等级
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
// 组件初始化接口
|
||||
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
err = this.MCompConfigure.Init(service, module, comp, options)
|
||||
this.module = module.(*Smithy)
|
||||
@ -55,6 +56,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
|
||||
err = this.LoadConfigure(game_smithystove, cfg.NewGameSmithyStoveV1)
|
||||
err = this.LoadConfigure(game_smithytools, cfg.NewGameSmithyTool)
|
||||
err = this.LoadConfigure(game_smithystoveold, cfg.NewGameSmithyStove)
|
||||
err = this.LoadConfigure(game_smithycustomer, cfg.NewGameSmithyCustomer)
|
||||
|
||||
return
|
||||
}
|
||||
@ -89,7 +91,7 @@ func (this *configureComp) GetSmithyStoveConfigData(level int32) (data *cfg.Game
|
||||
return
|
||||
}
|
||||
|
||||
//加载多个配置文件
|
||||
// 加载多个配置文件
|
||||
func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) {
|
||||
for k, v := range confs {
|
||||
err = configure.RegisterConfigure(k, v, nil)
|
||||
@ -101,7 +103,7 @@ func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err
|
||||
return
|
||||
}
|
||||
|
||||
//读取配置数据
|
||||
// 读取配置数据
|
||||
func (this *configureComp) GetConfigure(name string) (v interface{}, err error) {
|
||||
return configure.GetConfigure(name)
|
||||
}
|
||||
@ -168,22 +170,11 @@ func (this *configureComp) GetSmithyProficileData(reelid int32, proficile int32)
|
||||
return this._mapProficile[int64(reelid<<16)+int64(proficile)]
|
||||
}
|
||||
|
||||
// 获取铁匠铺工作台信息
|
||||
func (this *configureComp) GetSmithyStoveConf(star int32) (data *cfg.GameSmithyStoveV1Data) {
|
||||
if v, err := this.GetConfigure(game_smithystove); err == nil {
|
||||
if configure, ok := v.(*cfg.GameSmithyStoveV1); ok {
|
||||
data = configure.Get(int32(star))
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 获取铁匠铺工作台信息
|
||||
func (this *configureComp) GetSmithyStoveConf1(id int32) (data *cfg.GameSmithyToolData) {
|
||||
if v, err := this.GetConfigure(game_smithytools); err == nil {
|
||||
if configure, ok := v.(*cfg.GameSmithyTool); ok {
|
||||
data = configure.Get(int32(id))
|
||||
// 获取铁匠铺顾客配置
|
||||
func (this *configureComp) GetSmithyCustomerConfList() (data []*cfg.GameSmithyCustomerData) {
|
||||
if v, err := this.GetConfigure(game_smithycustomer); err != nil {
|
||||
if conf, ok := v.(*cfg.GameSmithyCustomer); ok {
|
||||
data = conf.GetDataList()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/modules"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"math/rand"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||
@ -24,4 +26,47 @@ func (this *modelTrade) Init(service core.IService, module core.IModule, comp co
|
||||
})
|
||||
return
|
||||
}
|
||||
//
|
||||
|
||||
// 权重项目
|
||||
type WeightedRandom struct {
|
||||
items []*cfg.GameSmithyCustomerData
|
||||
totalWeight int
|
||||
}
|
||||
|
||||
func newWeightedRandom(items []*cfg.GameSmithyCustomerData) *WeightedRandom {
|
||||
wr := &WeightedRandom{items: items}
|
||||
for _, item := range wr.items {
|
||||
wr.totalWeight += int(item.Weight)
|
||||
}
|
||||
return wr
|
||||
}
|
||||
|
||||
func (wr *WeightedRandom) pick() *cfg.GameSmithyCustomerData {
|
||||
randomNumber := rand.Intn(wr.totalWeight)
|
||||
for _, item := range wr.items {
|
||||
if randomNumber < int(item.Weight) {
|
||||
return item
|
||||
}
|
||||
randomNumber -= int(item.Weight)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 随机顾客
|
||||
func (s *modelTrade) getCustomerRandom() (customerId int32) {
|
||||
items := s.module.configure.GetSmithyCustomerConfList()
|
||||
wr := newWeightedRandom(items)
|
||||
if c := wr.pick(); c != nil {
|
||||
customerId = c.CustomerId
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 更新顾客
|
||||
func(s *modelTrade) updateCustomer(uid string) {
|
||||
|
||||
}
|
||||
|
||||
//顾客类型策略
|
||||
|
||||
//交易
|
||||
|
@ -16,6 +16,7 @@ type GameSmithyCustomerData struct {
|
||||
CustomerSpeak string
|
||||
Goods []*Gameatn
|
||||
Reword []*Gameatn
|
||||
Weight int32
|
||||
}
|
||||
|
||||
const TypeId_GameSmithyCustomerData = 1314583578
|
||||
@ -56,6 +57,7 @@ func (_v *GameSmithyCustomerData)Deserialize(_buf map[string]interface{}) (err e
|
||||
}
|
||||
}
|
||||
|
||||
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["weight"].(float64); !_ok_ { err = errors.New("weight error"); return }; _v.Weight = int32(_tempNum_) }
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user