package ppwwgm_config import ( "encoding/json" "fmt" "os" "path/filepath" ppwwgm_json "ppwwgm/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"` ScatterHit float64 `json:"scatterHit"` 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 } var ReelConfigs []*ReelConfig var GameConfigs ppwwgm_json.GameConfig var OddConfigs ppwwgm_json.OddConfig var allWeight = 0 func LoadConfig(cfgName string, target any) { rootDir, _ := os.Getwd() cfgDefPath := filepath.Join(rootDir, "../../config/ppwwgm", 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_100_extra.json", "rtp_100_shop.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) allWeight += cfg.Weight 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, row int, randin int) []int { w := 0 cards := []int{} for j := 0; j < len(s.ReelWeight[i]); j++ { w += s.ReelWeight[i][j] if w > randin { for m := 0; m < row; m++ { cards = append(cards, s.Reel[i][(j+m)%len(s.Reel[i])]) } break } } return cards } func updateReelWeight(reel *ReelInfo) { reel.Col = 6 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] } }