game_sync/gamesrv/slotspkg/slots/desc/machine_desc.go

233 lines
6.6 KiB
Go

package desc
import (
"github.com/tomas-qstarrs/boost/config"
"github.com/tomas-qstarrs/boost/randx"
"mongo.games.com/game/gamesrv/slotspkg/internal/exported/excel2go/structs"
"mongo.games.com/game/gamesrv/slotspkg/internal/generic/errors"
"mongo.games.com/game/gamesrv/slotspkg/internal/module/shell"
"sort"
)
type (
MachineDesc struct {
Theme string
Category string
DataSet *shell.Shell
}
)
func NewMachineDesc(theme, category string, shell *shell.Shell) *MachineDesc {
return &MachineDesc{
Theme: theme,
Category: category,
DataSet: shell,
}
}
// DefaultSheet gets default machine config by excel name
func (n *MachineDesc) DefaultSheet(excel string) interface{} {
return n.DataSet.GetMachineDefaultSheet(n.Theme, excel, 0)
}
// Sheet gets machine config by excel name & sheet name
func (n *MachineDesc) Sheet(excel string, sheet string) interface{} {
return n.DataSet.GetMachineSheet(n.Theme, excel, sheet, 0)
}
func (n *MachineDesc) GetLineBet(betSizeIndex, betLevelIndex, betLineIndex int64) int64 {
betSizeRows, ok := n.Sheet("Bet", "BetSize").(map[int64]*structs.BetSize)
if !ok {
panic(errors.ConfigTypeError.ErrorWith(n.Theme, "BetSize"))
}
betSizeRow, ok := betSizeRows[betSizeIndex]
if !ok {
panic(errors.ConfigRowNoMatch.ErrorWith(n.Theme, "BetSize", betSizeIndex))
}
betLevelRows, ok := n.Sheet("Bet", "BetLevel").(map[int64]*structs.BetLevel)
if !ok {
panic(errors.ConfigTypeError.ErrorWith(n.Theme, "BetLevel"))
}
betLevelRow, ok := betLevelRows[betLevelIndex]
if !ok {
panic(errors.ConfigRowNoMatch.ErrorWith(n.Theme, "BetLevel", betLevelIndex))
}
betLineRows, ok := n.Sheet("Bet", "BetLine").(map[int64]*structs.BetLine)
if !ok {
panic(errors.ConfigTypeError.ErrorWith(n.Theme, "BetLine"))
}
betLineRow, ok := betLineRows[betLineIndex]
if !ok {
panic(errors.ConfigRowNoMatch.ErrorWith(n.Theme, "BetLine", betLineIndex))
}
return betSizeRow.BetSize * betLevelRow.BetLevel * betLineRow.BaseBet
}
func (n *MachineDesc) BetSizes() []int64 {
betSizeRows, ok := n.Sheet("Bet", "BetSize").(map[int64]*structs.BetSize)
if !ok {
panic(errors.ConfigTypeError.ErrorWith(n.Theme, "BetSize"))
}
var lists []int64
for _, list := range betSizeRows {
lists = append(lists, list.BetSize)
}
sort.Slice(lists, func(i, j int) bool { return lists[i] < lists[j] })
return lists
}
func (n *MachineDesc) BetLevels() []int64 {
betLevelRows, ok := n.Sheet("Bet", "BetLevel").(map[int64]*structs.BetLevel)
if !ok {
panic(errors.ConfigTypeError.ErrorWith(n.Theme, "BetLevel"))
}
var lists []int64
for _, list := range betLevelRows {
lists = append(lists, list.BetLevel)
}
sort.Slice(lists, func(i, j int) bool { return lists[i] < lists[j] })
return lists
}
func (n *MachineDesc) BetLines() []int64 {
betLineRows, ok := n.Sheet("Bet", "BetLine").(map[int64]*structs.BetLine)
if !ok {
panic(errors.ConfigTypeError.ErrorWith(n.Theme, "BetLine"))
}
var lists []int64
for _, list := range betLineRows {
lists = append(lists, list.BetLine)
}
sort.Slice(lists, func(i, j int) bool { return lists[i] < lists[j] })
return lists
}
func (n *MachineDesc) BaseBets() []int64 {
baseBetRows, ok := n.Sheet("Bet", "BetLine").(map[int64]*structs.BetLine)
if !ok {
panic(errors.ConfigTypeError.ErrorWith(n.Theme, "BaseBet"))
}
var lists []int64
for _, list := range baseBetRows {
lists = append(lists, list.BaseBet)
}
sort.Slice(lists, func(i, j int) bool { return lists[i] < lists[j] })
return lists
}
func (n *MachineDesc) BetChangeList() []float64 {
betChangeListRows, ok := n.Sheet("Bet", "BetChangeList").(map[int64]*structs.BetChangeList)
if !ok {
panic(errors.ConfigTypeError.ErrorWith(n.Theme, "BetChangeList"))
}
var lists []float64
for _, list := range betChangeListRows {
lists = append(lists, list.BetChangeList)
}
sort.Slice(lists, func(i, j int) bool { return lists[i] < lists[j] })
return lists
}
func (n *MachineDesc) GetBetIndexByVal(val float64) []int64 {
betChangeListRows, ok := n.Sheet("Bet", "BetChangeList").(map[int64]*structs.BetChangeList)
if !ok {
panic(errors.ConfigTypeError.ErrorWith(n.Theme, "BetChangeList"))
}
for _, list := range betChangeListRows {
if list.BetChangeList == val {
return []int64{list.BetSizeIndex, list.BetLevelIndex}
}
}
return nil
}
func (n *MachineDesc) GetBetIndexByTwoVal(betSizeVal float64, betLevelVal int64) (index []int64) {
betSizes := n.BetSizes()
betLevels := n.BetLevels()
for k, v := range betSizes {
if v == int64(betSizeVal*10000) {
index = append(index, int64(k))
break
}
}
for k, v := range betLevels {
if v == betLevelVal {
index = append(index, int64(k))
break
}
}
return
}
func (n *MachineDesc) GetVector(choice int64, minRatio, maxRatio float64, isForceWin bool) (int64, []int64) {
if vectorIndex := config.GetInt64("slots.vectorIndex"); vectorIndex > 0 {
rows := n.DefaultSheet("Vector").([]*structs.Vector)
return vectorIndex, rows[vectorIndex].Vector
}
if minRatio < 0 {
minRatio = 0
}
if maxRatio < 1 {
maxRatio = 1
}
if isForceWin {
rows := n.Sheet("Vector", "ForceWin").([]*structs.VectorForceWin)
var indexWeightMap = make(map[int]float64)
for index, row := range rows {
if choice == row.Choice && minRatio <= row.MinRatio && row.MaxRatio <= maxRatio {
indexWeightMap[index] = row.Weight
}
}
if len(indexWeightMap) == 0 {
return n.GetVector(choice, 0, maxRatio, false)
}
index := randx.WeightMap(indexWeightMap)
return n.GetVector(choice, rows[index].MinRatio, rows[index].MaxRatio, false)
} else {
rows := n.DefaultSheet("Vector").([]*structs.Vector)
var indexes = make([]int, 0, len(rows))
for index, row := range rows {
if choice == row.Choice && minRatio <= row.Ratio && row.Ratio <= maxRatio {
indexes = append(indexes, index)
}
}
if len(indexes) == 0 {
if minRatio == 0 {
return n.GetVector(0, 0, maxRatio, false)
}
return n.GetVector(choice, 0, maxRatio, false)
}
index := indexes[randx.Intn(len(indexes))]
return int64(index), rows[index].Vector
}
}
// GetSpinType gets spin type by node type
func (n *MachineDesc) GetSpinType(typ string) int64 {
v := n.DefaultSheet("Formation")
formations, ok := v.([]*structs.Formation)
if !ok {
panic(errors.ConfigTypeError.ErrorWith(n.Theme, "Formation"))
}
for _, formation := range formations {
if formation.NodeType == typ {
return formation.SpinType
}
}
panic(errors.ConfigRowNoMatch.ErrorWith(n.Theme, "Formation", typ))
}
func (n *MachineDesc) GetPrizeModel() map[int64]*structs.PrizeModel {
v := n.DefaultSheet("PrizeModel")
rows, ok := v.(map[int64]*structs.PrizeModel)
if !ok {
panic(errors.ConfigTypeError.ErrorWith(n.Theme, "PrizeModel"))
}
return rows
}