2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.AbstractMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
public class CrackableReward
|
|
|
|
{
|
|
|
|
public final int itemId;
|
|
|
|
public final int count;
|
|
|
|
public final Map<Integer, Map.Entry<Integer, Integer>> prizes;
|
|
|
|
public int totalChance;
|
|
|
|
public final String achievementTick;
|
|
|
|
public final String achievementCracked;
|
2018-12-22 11:39:00 +01:00
|
|
|
public final int requiredEffect;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
public CrackableReward(ResultSet set) throws SQLException
|
|
|
|
{
|
|
|
|
this.itemId = set.getInt("item_id");
|
|
|
|
this.count = set.getInt("count");
|
|
|
|
this.achievementTick = set.getString("achievement_tick");
|
|
|
|
this.achievementCracked = set.getString("achievement_cracked");
|
2018-12-22 11:39:00 +01:00
|
|
|
this.requiredEffect = set.getInt("required_effect");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
String[] prizes = set.getString("prizes").split(";");
|
2018-09-28 21:25:00 +02:00
|
|
|
this.prizes = new HashMap<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
this.totalChance = 0;
|
2019-03-18 02:22:00 +01:00
|
|
|
for (String prize : prizes)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int itemId = 0;
|
|
|
|
int chance = 100;
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
if (prize.contains(":") && prize.split(":").length == 2)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
itemId = Integer.valueOf(prize.split(":")[0]);
|
|
|
|
chance = Integer.valueOf(prize.split(":")[1]);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
itemId = Integer.valueOf(prize.replace(":", ""));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2018-09-28 21:25:00 +02:00
|
|
|
this.prizes.put(itemId, new AbstractMap.SimpleEntry<>(this.totalChance, this.totalChance + chance));
|
2018-07-06 15:30:00 +02:00
|
|
|
this.totalChance += chance;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Emulator.getLogging().logErrorLine(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getRandomReward()
|
|
|
|
{
|
|
|
|
int random = Emulator.getRandom().nextInt(this.totalChance);
|
|
|
|
|
|
|
|
int notFound = 0;
|
|
|
|
for (Map.Entry<Integer, Map.Entry<Integer, Integer>> set : this.prizes.entrySet())
|
|
|
|
{
|
|
|
|
notFound = set.getKey();
|
|
|
|
if (random >= set.getValue().getKey() && random < set.getValue().getValue())
|
|
|
|
{
|
|
|
|
return set.getKey();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return notFound;
|
|
|
|
}
|
|
|
|
}
|