This commit is contained in:
Alejandro 2019-07-31 17:47:41 +03:00
commit 86b2e6be91
7 changed files with 46 additions and 42 deletions

View File

@ -1,30 +1,32 @@
package com.eu.habbo.habbohotel.catalog;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer;
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
import java.sql.ResultSet;
import java.sql.SQLException;
public class CalendarRewardObject {
private final int id;
private final String name;
private final String customImage;
private final int credits;
private final int points;
private final int pointsType;
private final String badge;
private final int catalogItemId;
private final int itemId;
public CalendarRewardObject(ResultSet set) throws SQLException {
this.id = set.getInt("id");
this.name = set.getString("name");
this.customImage = set.getString("custom_image");
this.credits = set.getInt("credits");
this.points = set.getInt("points");
this.pointsType = set.getInt("points_type");
this.badge = set.getString("badge");
this.catalogItemId = set.getInt("catalog_item_id");
this.itemId = set.getInt("item_id");
}
public void give(Habbo habbo) {
@ -40,11 +42,19 @@ public class CalendarRewardObject {
habbo.addBadge(this.badge);
}
if (this.catalogItemId > 0) {
CatalogItem item = this.getCatalogItem();
if (this.itemId > 0) {
Item item = getItem();
if (item != null) {
Emulator.getGameEnvironment().getCatalogManager().purchaseItem(null, item, habbo, 1, "", true);
HabboItem habboItem = Emulator.getGameEnvironment().getItemManager().createItem(
habbo.getHabboInfo().getId(),
item,
0,
0,
"");
habbo.getInventory().getItemsComponent().addItem(habboItem);
habbo.getClient().sendResponse(new AddHabboItemComposer(habboItem));
habbo.getClient().sendResponse(new InventoryRefreshComposer());
}
}
}
@ -53,10 +63,6 @@ public class CalendarRewardObject {
return this.id;
}
public String getName() {
return this.name;
}
public String getCustomImage() {
return this.customImage;
}
@ -77,7 +83,7 @@ public class CalendarRewardObject {
return this.badge;
}
public CatalogItem getCatalogItem() {
return Emulator.getGameEnvironment().getCatalogManager().getCatalogItem(this.catalogItemId);
public Item getItem() {
return Emulator.getGameEnvironment().getItemManager().getItem(this.itemId);
}
}

View File

@ -31,6 +31,7 @@ import com.eu.habbo.plugin.events.emulator.EmulatorLoadCatalogManagerEvent;
import com.eu.habbo.plugin.events.users.catalog.UserCatalogFurnitureBoughtEvent;
import com.eu.habbo.plugin.events.users.catalog.UserCatalogItemPurchasedEvent;
import gnu.trove.TCollections;
import gnu.trove.iterator.TIntIterator;
import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.THashMap;
@ -1119,15 +1120,15 @@ public class CatalogManager {
return offers;
}
public void claimCalendarReward(Habbo habbo, int day) {
public void claimCalendarReward(Habbo habbo, int day, boolean force) {
if (!habbo.getHabboStats().calendarRewardsClaimed.contains(day)) {
habbo.getHabboStats().calendarRewardsClaimed.add(day);
CalendarRewardObject object = this.calendarRewards.get(day);
if (object != null) {
object.give(habbo);
habbo.getClient().sendResponse(new InventoryRefreshComposer());
CalendarRewardObject object = this.calendarRewards.get((day+1));
int actualDay = (int) Math.floor((Emulator.getIntUnixTimestamp() - Emulator.getConfig().getInt("hotel.calendar.starttimestamp")) / 86400);
int diff = (actualDay - day);
if (((diff <= 2 && diff >= 0) || force) && object != null) {
habbo.getHabboStats().calendarRewardsClaimed.add(day);
habbo.getClient().sendResponse(new AdventCalendarProductComposer(true, object));
object.give(habbo);
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO calendar_rewards_claimed (user_id, reward_id, timestamp) VALUES (?, ?, ?)")) {
statement.setInt(1, habbo.getHabboInfo().getId());
@ -1138,8 +1139,6 @@ public class CatalogManager {
Emulator.getLogging().logSQLException(e);
}
}
}
}

View File

@ -1,5 +1,6 @@
package com.eu.habbo.messages.incoming.events.calendar;
import com.eu.habbo.Emulator;
import com.eu.habbo.messages.incoming.MessageHandler;
public class AdventCalendarForceOpenEvent extends MessageHandler {
@ -7,5 +8,7 @@ public class AdventCalendarForceOpenEvent extends MessageHandler {
public void handle() throws Exception {
String campaign = this.packet.readString();
int day = this.packet.readInt();
Emulator.getGameEnvironment().getCatalogManager().claimCalendarReward(this.client.getHabbo(), day, true);
}
}

View File

@ -9,6 +9,6 @@ public class AdventCalendarOpenDayEvent extends MessageHandler {
String campaign = this.packet.readString();
int day = this.packet.readInt();
Emulator.getGameEnvironment().getCatalogManager().claimCalendarReward(this.client.getHabbo(), day);
Emulator.getGameEnvironment().getCatalogManager().claimCalendarReward(this.client.getHabbo(), day, false);
}
}

View File

@ -83,8 +83,8 @@ public class UsernameEvent extends MessageHandler {
}
}
if (calendar && Emulator.getConfig().getBoolean("hotel.calendar.enabled")) {
this.client.sendResponse(new AdventCalendarDataComposer("xmas11", Emulator.getGameEnvironment().getCatalogManager().calendarRewards.size(), (int) Math.floor((Emulator.getIntUnixTimestamp() - Emulator.getConfig().getInt("hotel.calendar.starttimestamp")) / 86400), this.client.getHabbo().getHabboStats().calendarRewardsClaimed, true));
if (Emulator.getConfig().getBoolean("hotel.calendar.enabled")) {
this.client.sendResponse(new AdventCalendarDataComposer("xmas15", Emulator.getGameEnvironment().getCatalogManager().calendarRewards.size(), (int) Math.floor((Emulator.getIntUnixTimestamp() - Emulator.getConfig().getInt("hotel.calendar.starttimestamp")) / 86400), this.client.getHabbo().getHabboStats().calendarRewardsClaimed, true));
this.client.sendResponse(new NuxAlertComposer("openView/calendar"));
}

View File

@ -28,33 +28,28 @@ public class AdventCalendarDataComposer extends MessageComposer {
this.response.appendString("");
this.response.appendInt(this.currentDay);
this.response.appendInt(this.totalDays);
this.response.appendInt(this.unlocked.size());
TIntArrayList expired = new TIntArrayList();
for (int i = 0; i < this.totalDays; i++) {
expired.add(i);
expired.remove(this.currentDay);
}
expired.remove(this.currentDay);
if(this.currentDay > 1) expired.remove(this.currentDay - 2);
if(this.currentDay > 0) expired.remove(this.currentDay - 1);
this.unlocked.forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
AdventCalendarDataComposer.this.response.appendInt(value);
expired.remove(value);
return true;
}
this.unlocked.forEach(value -> {
AdventCalendarDataComposer.this.response.appendInt(value);
expired.remove(value);
return true;
});
if (this.lockExpired) {
this.response.appendInt(expired.size());
expired.forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
AdventCalendarDataComposer.this.response.appendInt(value);
return true;
}
expired.forEach(value -> {
AdventCalendarDataComposer.this.response.appendInt(value);
return true;
});
} else {
this.response.appendInt(0);

View File

@ -1,6 +1,7 @@
package com.eu.habbo.messages.outgoing.events.calendar;
import com.eu.habbo.habbohotel.catalog.CalendarRewardObject;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
@ -18,9 +19,9 @@ public class AdventCalendarProductComposer extends MessageComposer {
public ServerMessage compose() {
this.response.init(Outgoing.AdventCalendarProductComposer);
this.response.appendBoolean(this.visible);
this.response.appendString(this.rewardObject.getName());
this.response.appendString(this.rewardObject.getItem().getName());
this.response.appendString(this.rewardObject.getCustomImage());
this.response.appendString(this.rewardObject.getCatalogItem() != null ? this.rewardObject.getCatalogItem().getName() : this.rewardObject.getName());
this.response.appendString(this.rewardObject.getItem().getName());
return this.response;
}
}