mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-23 07:20:50 +01:00
Calendar is now fixed. Credits to ItsGiuseppe.
This commit is contained in:
parent
bfda48c22e
commit
fdb367966b
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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)) {
|
||||
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);
|
||||
CalendarRewardObject object = this.calendarRewards.get(day);
|
||||
|
||||
if (object != null) {
|
||||
object.give(habbo);
|
||||
habbo.getClient().sendResponse(new InventoryRefreshComposer());
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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) {
|
||||
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) {
|
||||
expired.forEach(value -> {
|
||||
AdventCalendarDataComposer.this.response.appendInt(value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.response.appendInt(0);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user