ChestService
unknown
java
a year ago
1.1 kB
5
Indexable
package brodev.hu.kinyeri.kinyeri.hu.Services;
import org.springframework.stereotype.Service;
import java.util.Random;
@Service
public class ChestService {
private static final double[] CHANCES = {0.001, 0.05, 0.15, 1, 20.3, 38.499, 40};
private static final String[] REWARDS = {"1500 USDT", "500 USDT", "200 USDT", "100 USDT", "20 USDT", "10 USDT", "100 AP"};
public String[] openChest(int id) {
double randomValue = new Random().nextDouble() * 100;
double cumulativeProbability = 0.0;
String[] reward = new String[2];
int chest = 0;
if (id==365) chest=300+1;
else chest=id+1;
for (int i = 0; i < CHANCES.length; i++) {
cumulativeProbability += CHANCES[i];
if (randomValue <= cumulativeProbability) {
reward[0] = REWARDS[i];
reward[1] = String.valueOf(chest);
return reward;
}
}
return null; // Fallback in case no reward is matched
}
}Editor is loading...
Leave a Comment