mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-15 00:15:08 +01:00
fix possible infinite loop in gacha rolls
This commit is contained in:
@@ -358,6 +358,9 @@ func getRandomEntries(entries []GachaEntry, rolls int, isBox bool) ([]GachaEntry
|
|||||||
totalWeight += entries[i].Weight
|
totalWeight += entries[i].Weight
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
|
if rolls == len(chosen) {
|
||||||
|
break
|
||||||
|
}
|
||||||
if !isBox {
|
if !isBox {
|
||||||
result := rand.Float64() * totalWeight
|
result := rand.Float64() * totalWeight
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
@@ -373,9 +376,6 @@ func getRandomEntries(entries []GachaEntry, rolls int, isBox bool) ([]GachaEntry
|
|||||||
entries[result] = entries[len(entries)-1]
|
entries[result] = entries[len(entries)-1]
|
||||||
entries = entries[:len(entries)-1]
|
entries = entries[:len(entries)-1]
|
||||||
}
|
}
|
||||||
if rolls == len(chosen) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return chosen, nil
|
return chosen, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user