}
public void updateExperience(Player player, int amount) {
amount *= Constants.MULTIPLIER_EXP;
Avatar avatar = player.getAvatar();
avatar.setExperience(Math.min(ExpTable.getExp(Constants.MAX_LEVEL - 1), avatar.getExperience() + amount));
try {
AvatarDAO.updateExperience(avatar);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
int oldLevel = avatar.getLevel(), newLevel = ExpTable.getLevel(avatar.getExperience());
if (newLevel > oldLevel) {
avatar.setLevel(newLevel);
try {
AvatarDAO.updateLevel(avatar);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
ResponseUpdateLevel updateLevelResponse = new ResponseUpdateLevel();
updateLevelResponse.setAmount(newLevel - oldLevel);
updateLevelResponse.setLevel(newLevel);
String range = String.valueOf(ExpTable.getExpToAdvance(oldLevel + 1));
for (int i = oldLevel + 2; i <= newLevel; i++) {
range += "," + ExpTable.getExpToAdvance(i);
}
updateLevelResponse.setRange(range);
addResponseForUser(player.getID(), updateLevelResponse);
updateCash(player, amount);
List<SpeciesType> unlockList = new ArrayList<SpeciesType>();
try {
for (int i = oldLevel + 1; i <= newLevel; i++) {
unlockList.addAll(ShopDAO.getAnimalsByLevel(i));
unlockList.addAll(ShopDAO.getPlantsByLevel(i));
}
ResponseShopUnlock unlockResponse = new ResponseShopUnlock();
unlockResponse.setUnlockList(unlockList);
GameServer.getInstance().addResponseForUser(player.getID(), unlockResponse);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
}
ResponseUpdateXP updateResponse = new ResponseUpdateXP();
updateResponse.setAmount(amount);
updateResponse.setTotal(avatar.getExperience());
addResponseForUser(player.getID(), updateResponse);
}