更新铁匠铺协议

This commit is contained in:
wh_zcy 2023-02-16 15:40:06 +08:00
parent 92fd5e34cb
commit dc5c2729cd
5 changed files with 67 additions and 43 deletions

View File

@ -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
}
]

View File

@ -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)
}
}
}

View File

@ -17,6 +17,7 @@ const (
game_smproficiency = "game_smithyproficiency.json" // 铁匠铺熟练度
game_smithystove = "game_smithystovev1.json" // 铁匠铺台子 打造配置
game_smithytools = "game_smithytool.json" // 铁匠铺工具台
game_smithycustomer = "game_smithycustomer.json"
)
// /配置管理基础组件
@ -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
}
@ -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
}
}

View File

@ -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) {
}
//顾客类型策略
//交易

View File

@ -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
}