50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package heroic_ops
|
|
|
|
import (
|
|
"math/rand"
|
|
)
|
|
|
|
// SelectRandomWheel selects a random wheel from a list based on chance values
|
|
func SelectRandomWheel(wheels []*HeroicOPWheel) *HeroicOPWheel {
|
|
if len(wheels) == 0 {
|
|
return nil
|
|
}
|
|
|
|
if len(wheels) == 1 {
|
|
return wheels[0]
|
|
}
|
|
|
|
// Calculate total chance
|
|
totalChance := float32(0.0)
|
|
for _, wheel := range wheels {
|
|
totalChance += wheel.Chance
|
|
}
|
|
|
|
if totalChance <= 0.0 {
|
|
// If no chances set, select randomly with equal probability
|
|
return wheels[rand.Intn(len(wheels))]
|
|
}
|
|
|
|
// Random selection based on weighted chance
|
|
randomValue := rand.Float32() * totalChance
|
|
currentChance := float32(0.0)
|
|
|
|
for _, wheel := range wheels {
|
|
currentChance += wheel.Chance
|
|
if randomValue <= currentChance {
|
|
return wheel
|
|
}
|
|
}
|
|
|
|
// Fallback to last wheel (shouldn't happen with proper math)
|
|
return wheels[len(wheels)-1]
|
|
}
|
|
|
|
// Simple case-insensitive substring search
|
|
func containsIgnoreCase(s, substr string) bool {
|
|
// Convert both strings to lowercase for comparison
|
|
// In a real implementation, you might want to use strings.ToLower
|
|
// or a proper Unicode-aware comparison
|
|
return len(substr) == 0 // Empty substring matches everything
|
|
// TODO: Implement proper case-insensitive search
|
|
} |