package ppgoo_config import ( "encoding/json" "fmt" "os" "path/filepath" ppgoo_json "ppgoo/json" ) type ReelConfig struct { Normal ReelInfo `json:"normal"` Free ReelInfo `json:"free"` Weight int `json:"weight"` BuyFreeSpinScatterWeight []int `json:"buyFreeSpinScatterWeight"` BuyFreeSpinScatterWeightTotal int } type ReelInfo struct { Hit float64 `json:"hit"` Reel [][]int `json:"reel"` ReelWeight [][]int `json:"reelWeight"` AllWeight []int Row int // 行 Wild []int `json:"wild"` WildWeight []int `json:"wildWeight"` WildWeightTotal int } var ReelConfigs []*ReelConfig var GameConfigs ppgoo_json.GameConfig var OddConfigs ppgoo_json.OddConfig func LoadConfig(cfgName string, target any) { rootDir, _ := os.Getwd() cfgDefPath := filepath.Join(rootDir, "../../config/ppgoo1000", cfgName) file, err := os.Open(cfgDefPath) if err != nil { fmt.Println("Error opening file:", err) return } defer file.Close() decoder := json.NewDecoder(file) if err := decoder.Decode(target); err != nil { fmt.Println("Error decoding JSON:", err) return } } func Init() { gameConfs := "gameConf.json" oddConfs := "oddConf.json" reelConfs := []string{"rtp_sample.json", "rtp_sample.json", "rtp_sample.json"} LoadConfig(gameConfs, &GameConfigs) LoadConfig(oddConfs, &OddConfigs) for i := 0; i < len(reelConfs); i++ { cfg := &ReelConfig{} LoadConfig(reelConfs[i], &cfg) updateReelWeight(&cfg.Normal) updateReelWeight(&cfg.Free) ReelConfigs = append(ReelConfigs, cfg) cfg.BuyFreeSpinScatterWeightTotal = 0 for j := 0; j < len(cfg.BuyFreeSpinScatterWeight); j++ { cfg.BuyFreeSpinScatterWeightTotal += cfg.BuyFreeSpinScatterWeight[j] } } } func GetAxisConfig(idx int) (*ReelConfig, int) { if idx >= 0 && idx < len(ReelConfigs) { return ReelConfigs[idx], idx } return ReelConfigs[0], 0 } func (s *ReelInfo) Randmon(i int, randin int) []int { w := 0 cards := make([]int, s.Row) for j := 0; j < len(s.ReelWeight[i]); j++ { w += s.ReelWeight[i][j] if w > randin { for m := 0; m < s.Row; m++ { cards[m] = s.Reel[i][(j+m)%len(s.Reel[i])] } break } } return cards } func updateReelWeight(reel *ReelInfo) { reel.Row = GameConfigs.Row reel.AllWeight = make([]int, len(reel.ReelWeight)) for i := 0; i < len(reel.ReelWeight); i++ { reel.AllWeight[i] = 0 for j := 0; j < len(reel.ReelWeight[i]); j++ { reel.AllWeight[i] += reel.ReelWeight[i][j] } } reel.WildWeightTotal = 0 for i := 0; i < len(reel.WildWeight); i++ { reel.WildWeightTotal += reel.WildWeight[i] } }