Fix unseen item count not appearing. Closes #18

This commit is contained in:
Alejandro 2019-05-17 23:07:22 +03:00
parent aa64bc1aef
commit 487ad76ee2
5 changed files with 95 additions and 14 deletions

View File

@ -295,6 +295,8 @@ public class AchievementManager
}
}
habbo.getClient().sendResponse(new AddHabboItemComposer(badge.getId(), AddHabboItemComposer.AddHabboItemCategory.BADGE));
habbo.getHabboStats().addAchievementScore(newLevel.points);
if (newLevel.rewardAmount > 0)

View File

@ -41,6 +41,7 @@ import gnu.trove.set.hash.THashSet;
import java.sql.*;
import java.util.*;
import java.util.stream.Collectors;
public class CatalogManager
{
@ -1077,7 +1078,9 @@ public class CatalogManager
if (totalPoints > 0 && habbo.getHabboInfo().getCurrencyAmount(item.getPointsType()) - totalPoints < 0) return;
List<String> badges = new ArrayList<>();
Map<AddHabboItemComposer.AddHabboItemCategory, List<Integer>> unseenItems = new HashMap<>();
boolean badgeFound = false;
for (int i = 0; i < amount; i++) {
habbo.getHabboStats().addLtdLog(item.getId(), Emulator.getIntUnixTimestamp());
@ -1105,6 +1108,12 @@ public class CatalogManager
Emulator.getThreading().run(bot);
habbo.getClient().getHabbo().getInventory().getBotsComponent().addBot(bot);
habbo.getClient().sendResponse(new AddBotComposer(bot));
if (!unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.BOT)) {
unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.BOT, new ArrayList<>());
}
unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.BOT).add(bot.getId());
} else {
throw new Exception("Failed to create bot of type: " + type);
}
@ -1144,6 +1153,12 @@ public class CatalogManager
habbo.getClient().sendResponse(new PetBoughtNotificationComposer(pet, false));
AchievementManager.progressAchievement(habbo.getClient().getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("PetLover"));
if (!unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.PET)) {
unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.PET, new ArrayList<>());
}
unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.PET).add(pet.getId());
} else if (baseItem.getType() == FurnitureType.BADGE) {
if (!habbo.getInventory().getBadgesComponent().hasBadge(baseItem.getName())) {
if (!badges.contains(baseItem.getName())) {
@ -1256,12 +1271,10 @@ public class CatalogManager
}
}
if (purchasedEvent.itemsList != null)
if (purchasedEvent.itemsList != null && !purchasedEvent.itemsList.isEmpty())
{
habbo.getClient().sendResponse(new AddHabboItemComposer(purchasedEvent.itemsList));
habbo.getClient().getHabbo().getInventory().getItemsComponent().addItems(purchasedEvent.itemsList);
habbo.getClient().sendResponse(new PurchaseOKComposer(purchasedEvent.catalogItem));
habbo.getClient().sendResponse(new InventoryRefreshComposer());
unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.OWNED_FURNI, purchasedEvent.itemsList.stream().map(HabboItem::getId).collect(Collectors.toList()));
Emulator.getPluginManager().fireEvent(new UserCatalogFurnitureBoughtEvent(habbo, item, purchasedEvent.itemsList));
@ -1274,6 +1287,10 @@ public class CatalogManager
}
}
if (!purchasedEvent.badges.isEmpty() && !unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.BOT)) {
unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.BADGE, new ArrayList<>());
}
for (String b : purchasedEvent.badges)
{
HabboBadge badge = new HabboBadge(0, b, 0, habbo);
@ -1285,9 +1302,15 @@ public class CatalogManager
keys.put("image", "${image.library.url}album1584/" + badge.getCode() + ".gif");
keys.put("message", Emulator.getTexts().getValue("commands.generic.cmd_badge.received"));
habbo.getClient().sendResponse(new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys));
unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.BADGE).add(badge.getId());
}
habbo.getClient().getHabbo().getHabboStats().addPurchase(purchasedEvent.catalogItem);
habbo.getClient().sendResponse(new AddHabboItemComposer(unseenItems));
habbo.getClient().sendResponse(new PurchaseOKComposer(purchasedEvent.catalogItem));
habbo.getClient().sendResponse(new InventoryRefreshComposer());
} catch (Exception e)
{
Emulator.getLogging().logPacketError(e);

View File

@ -414,6 +414,7 @@ public class Habbo implements Runnable
HabboBadge badge = BadgesComponent.createBadge(code, this);
this.habboInventory.getBadgesComponent().addBadge(badge);
this.client.sendResponse(new AddUserBadgeComposer(badge));
this.client.sendResponse(new AddHabboItemComposer(badge.getId(), AddHabboItemComposer.AddHabboItemCategory.BADGE));
THashMap<String, String> keys = new THashMap<>();
keys.put("display", "BUBBLE");

View File

@ -6,19 +6,57 @@ import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
import gnu.trove.set.hash.THashSet;
import java.util.List;
import java.util.Map;
public class AddHabboItemComposer extends MessageComposer
{
public enum AddHabboItemCategory {
OWNED_FURNI(1),
RENTED_FURNI(2),
PET(3),
BADGE(4),
BOT(5),
GAME(6);
public final int number;
AddHabboItemCategory(int number)
{
this.number = number;
}
}
private THashSet<HabboItem> itemsList;
private HabboItem item;
public AddHabboItemComposer(THashSet<HabboItem> itemsList)
{
private int[] ids;
private AddHabboItemCategory category;
private Map<AddHabboItemCategory, List<Integer>> entries;
public AddHabboItemComposer(THashSet<HabboItem> itemsList) {
this.itemsList = itemsList;
this.category = AddHabboItemCategory.OWNED_FURNI;
}
public AddHabboItemComposer(HabboItem item)
{
public AddHabboItemComposer(HabboItem item) {
this.item = item;
this.category = AddHabboItemCategory.OWNED_FURNI;
}
public AddHabboItemComposer(int[] ids, AddHabboItemCategory category) {
this.ids = ids;
this.category = category;
}
public AddHabboItemComposer(int id, AddHabboItemCategory category) {
this.ids = new int[]{id};
this.category = category;
}
public AddHabboItemComposer(Map<AddHabboItemCategory, List<Integer>> entries) {
this.entries = entries;
}
@Override
@ -26,22 +64,39 @@ public class AddHabboItemComposer extends MessageComposer
{
this.response.init(Outgoing.AddHabboItemComposer);
if(this.item == null)
{
if (this.ids != null) {
this.response.appendInt(1);
this.response.appendInt(this.category.number);
this.response.appendInt(this.ids.length);
for (int id : this.ids) {
this.response.appendInt(id);
}
} else if (this.entries != null) {
this.response.appendInt(this.entries.size());
for (Map.Entry<AddHabboItemCategory, List<Integer>> item : this.entries.entrySet()) {
this.response.appendInt(item.getKey().number);
this.response.appendInt(item.getValue().size());
for (int id : item.getValue()) {
this.response.appendInt(id);
}
}
} else if (this.item == null) {
this.response.appendInt(1);
this.response.appendInt(1);
this.response.appendInt(this.itemsList.size());
for (HabboItem habboItem : this.itemsList) {
this.response.appendInt(habboItem.getId());
}
}
else
{
} else {
this.response.appendInt(1);
this.response.appendInt(1);
this.response.appendInt(1);
this.response.appendInt(this.item.getId());
}
return this.response;
}
}

View File

@ -18,7 +18,7 @@ public class AddUserBadgeComposer extends MessageComposer
public ServerMessage compose()
{
this.response.init(Outgoing.AddUserBadgeComposer);
this.response.appendInt(this.badge.getSlot());
this.response.appendInt(this.badge.getId());
this.response.appendString(this.badge.getCode());
return this.response;
}