-
Notifications
You must be signed in to change notification settings - Fork 1
/
weightchgsymbol.go
153 lines (113 loc) · 4.41 KB
/
weightchgsymbol.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package lowcode
import (
"log/slog"
"os"
"github.com/zhs007/goutils"
"github.com/zhs007/slotsgamecore7/asciigame"
sgc7game "github.com/zhs007/slotsgamecore7/game"
sgc7plugin "github.com/zhs007/slotsgamecore7/plugin"
"gopkg.in/yaml.v2"
)
const WeightChgSymbolTypeName = "weightChgSymbol"
// const (
// WCSCVMapChgWeight string = "mapChgWeight" // 可以修改配置项里的mapChgWeight,这里因为是个map,所以要当成 mapChgWeight:S 这样传递
// )
// WeightChgSymbolConfig - configuration for WeightChgSymbol feature
type WeightChgSymbolConfig struct {
BasicComponentConfig `yaml:",inline" json:",inline"`
MapChgWeight map[string]string `yaml:"mapChgWeight" json:"mapChgWeight"`
MapChgWeightVW map[int]*sgc7game.ValWeights2 `yaml:"-" json:"-"`
}
type WeightChgSymbol struct {
*BasicComponent `json:"-"`
Config *WeightChgSymbolConfig `json:"config"`
}
// Init -
func (weightChgSymbol *WeightChgSymbol) Init(fn string, pool *GamePropertyPool) error {
data, err := os.ReadFile(fn)
if err != nil {
goutils.Error("WeightChgSymbol.Init:ReadFile",
slog.String("fn", fn),
goutils.Err(err))
return err
}
cfg := &WeightChgSymbolConfig{}
err = yaml.Unmarshal(data, cfg)
if err != nil {
goutils.Error("WeightChgSymbol.Init:Unmarshal",
slog.String("fn", fn),
goutils.Err(err))
return err
}
return weightChgSymbol.InitEx(cfg, pool)
}
// InitEx -
func (weightChgSymbol *WeightChgSymbol) InitEx(cfg any, pool *GamePropertyPool) error {
weightChgSymbol.Config = cfg.(*WeightChgSymbolConfig)
weightChgSymbol.Config.ComponentType = WeightChgSymbolTypeName
weightChgSymbol.Config.MapChgWeightVW = make(map[int]*sgc7game.ValWeights2)
for s, fn := range weightChgSymbol.Config.MapChgWeight {
sc := pool.DefaultPaytables.MapSymbols[s]
vw2, err := pool.LoadSymbolWeights(fn, "val", "weight", pool.DefaultPaytables, weightChgSymbol.Config.UseFileMapping)
if err != nil {
goutils.Error("WeightChgSymbol.InitEx:LoadIntWeights",
slog.String("Weight", fn),
goutils.Err(err))
return err
}
weightChgSymbol.Config.MapChgWeightVW[sc] = vw2
}
weightChgSymbol.onInit(&weightChgSymbol.Config.BasicComponentConfig)
return nil
}
func (weightChgSymbol *WeightChgSymbol) getChgWeight(gameProp *GameProperty, basicCD *BasicComponentData, symbol int) *sgc7game.ValWeights2 {
str := basicCD.GetConfigVal(CCVMapChgWeight + ":" + gameProp.Pool.Config.GetDefaultPaytables().GetStringFromInt(symbol))
if str != "" {
vw2, _ := gameProp.Pool.LoadSymbolWeights(str, "val", "weight", gameProp.Pool.DefaultPaytables, weightChgSymbol.Config.UseFileMapping)
return vw2
}
return weightChgSymbol.Config.MapChgWeightVW[symbol]
}
// playgame
func (weightChgSymbol *WeightChgSymbol) OnPlayGame(gameProp *GameProperty, curpr *sgc7game.PlayResult, gp *GameParams, plugin sgc7plugin.IPlugin,
cmd string, param string, ps sgc7game.IPlayerState, stake *sgc7game.Stake, prs []*sgc7game.PlayResult, icd IComponentData) (string, error) {
// weightChgSymbol.onPlayGame(gameProp, curpr, gp, plugin, cmd, param, ps, stake, prs)
cd := icd.(*BasicComponentData)
gs := weightChgSymbol.GetTargetScene3(gameProp, curpr, prs, 0)
cgs := gs.CloneEx(gameProp.PoolScene)
for x, arr := range cgs.Arr {
for y, s := range arr {
vw := weightChgSymbol.getChgWeight(gameProp, cd, s)
// vw, isok := weightChgSymbol.Config.MapChgWeightVW[s]
if vw != nil {
cr, err := vw.RandVal(plugin)
if err != nil {
goutils.Error("WeightChgSymbol.OnPlayGame:RandVal",
goutils.Err(err))
return "", err
}
cgs.Arr[x][y] = cr.Int()
}
}
}
weightChgSymbol.AddScene(gameProp, curpr, cgs, cd)
nc := weightChgSymbol.onStepEnd(gameProp, curpr, gp, "")
return nc, nil
}
// OnAsciiGame - outpur to asciigame
func (weightChgSymbol *WeightChgSymbol) OnAsciiGame(gameProp *GameProperty, pr *sgc7game.PlayResult, lst []*sgc7game.PlayResult, mapSymbolColor *asciigame.SymbolColorMap, icd IComponentData) error {
cd := icd.(*BasicComponentData)
if len(cd.UsedScenes) > 0 {
asciigame.OutputScene("After WeightChgSymbol", pr.Scenes[cd.UsedScenes[0]], mapSymbolColor)
}
return nil
}
// // OnStats
// func (weightChgSymbol *WeightChgSymbol) OnStats(feature *sgc7stats.Feature, stake *sgc7game.Stake, lst []*sgc7game.PlayResult) (bool, int64, int64) {
// return false, 0, 0
// }
func NewWeightChgSymbol(name string) IComponent {
return &WeightChgSymbol{
BasicComponent: NewBasicComponent(name, 1),
}
}