package pptdhm_config import ( "encoding/json" "fmt" "os" "path/filepath" pptdhm_json "pptdhm/json" ) type ReelConfig struct { Normal ReelInfo `json:"normal"` FreeSticky ReelInfo `json:"freeSticky"` FreeRain ReelInfo `json:"freeRain"` 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 Col int // 行 Wild []int `json:"wild"` WildWeight []int `json:"wildWeight"` WildWeightTotal int RowWeight []int `json:"rowWeight"` RowWeightTotal int StickyWildHit map[int][]float64 `json:"wildSpawnHit"` StickyWildHitWeight map[int][]int `json:"wildSpawnHitWeight"` StickyWildHitWeightTotal map[int]int RainingWildHit []int `json:"rainingWild"` RainingWildWeight []int `json:"rainingWildWeight"` RainingWildWeightTotal int } var ReelConfigs []*ReelConfig var GameConfigs pptdhm_json.GameConfig var OddConfigs pptdhm_json.OddConfig func LoadConfig(cfgName string, target any) { rootDir, _ := os.Getwd() cfgDefPath := filepath.Join(rootDir, "../../config/pptdhm", 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_100.json", "rtp_sample_buyfree.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.FreeSticky) updateReelWeight(&cfg.FreeRain) 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 (axisConfig *ReelConfig) GetFreeReelInfo(freeSpinMode int) *ReelInfo { if freeSpinMode == 1 { return &axisConfig.FreeSticky } else { return &axisConfig.FreeRain } } func (s *ReelInfo) Randmon(i int, row int, j int) []int { cards := make([]int, row) for m := 0; m < row; m++ { cards[m] = s.Reel[i][(j+m)%len(s.Reel[i])] } return cards } func updateReelWeight(reel *ReelInfo) { reel.Col = 3 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] } reel.RowWeightTotal = 0 for i := 0; i < len(reel.RowWeight); i++ { reel.RowWeightTotal += reel.RowWeight[i] } if reel.StickyWildHitWeight != nil { reel.StickyWildHitWeightTotal = map[int]int{} for k, v := range reel.StickyWildHitWeight { reel.StickyWildHitWeightTotal[k] = 0 for _, weight := range v { reel.StickyWildHitWeightTotal[k] += weight } } } if reel.RainingWildWeight != nil { reel.RainingWildWeightTotal = 0 for _, weight := range reel.RainingWildWeight { reel.RainingWildWeightTotal += weight } } }