Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java

474 lines
22 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.wired;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.catalog.CatalogItem;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredExtra;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset;
import com.eu.habbo.habbohotel.items.interactions.wired.effects.WiredEffectGiveReward;
2019-03-18 02:22:00 +01:00
import com.eu.habbo.habbohotel.items.interactions.wired.effects.WiredEffectTriggerStacks;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredExtraRandom;
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredExtraUnseen;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboBadge;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.outgoing.catalog.PurchaseOKComposer;
import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer;
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
import com.eu.habbo.messages.outgoing.users.AddUserBadgeComposer;
2019-05-26 20:14:53 +02:00
import com.eu.habbo.messages.outgoing.wired.WiredRewardAlertComposer;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.plugin.events.furniture.wired.WiredConditionFailedEvent;
import com.eu.habbo.plugin.events.furniture.wired.WiredStackExecutedEvent;
import com.eu.habbo.plugin.events.furniture.wired.WiredStackTriggeredEvent;
import com.eu.habbo.plugin.events.users.UserWiredRewardReceived;
2020-11-16 12:12:24 +01:00
import com.google.gson.GsonBuilder;
2018-07-06 15:30:00 +02:00
import gnu.trove.set.hash.THashSet;
2020-05-04 22:24:09 +02:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2018-07-06 15:30:00 +02:00
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
2019-05-26 20:14:53 +02:00
public class WiredHandler {
2020-05-04 22:24:09 +02:00
private static final Logger LOGGER = LoggerFactory.getLogger(WiredHandler.class);
2018-07-06 15:30:00 +02:00
//Configuration. Loaded from database & updated accordingly.
public static int MAXIMUM_FURNI_SELECTION = 5;
public static int TELEPORT_DELAY = 500;
2020-11-16 12:12:24 +01:00
private static GsonBuilder gsonBuilder = null;
2019-05-26 20:14:53 +02:00
public static boolean handle(WiredTriggerType triggerType, RoomUnit roomUnit, Room room, Object[] stuff) {
2019-03-18 02:22:00 +01:00
if (triggerType == WiredTriggerType.CUSTOM) return false;
2018-07-06 15:30:00 +02:00
boolean talked = false;
2018-12-22 11:39:00 +01:00
if (!Emulator.isReady)
return false;
2018-07-06 15:30:00 +02:00
if (room == null)
return false;
2019-05-26 20:14:53 +02:00
if (!room.isLoaded())
2018-07-06 15:30:00 +02:00
return false;
2019-05-26 20:14:53 +02:00
if (room.getRoomSpecialTypes() == null)
2018-07-06 15:30:00 +02:00
return false;
2019-05-26 20:14:53 +02:00
THashSet<InteractionWiredTrigger> triggers = room.getRoomSpecialTypes().getTriggers(triggerType);
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
if (triggers == null || triggers.isEmpty())
2018-07-06 15:30:00 +02:00
return false;
2020-10-31 03:11:33 +01:00
long millis = System.currentTimeMillis();
THashSet<InteractionWiredEffect> effectsToExecute = new THashSet<InteractionWiredEffect>();
2018-07-06 15:30:00 +02:00
List<RoomTile> triggeredTiles = new ArrayList<>();
2019-05-26 20:14:53 +02:00
for (InteractionWiredTrigger trigger : triggers) {
2018-07-06 15:30:00 +02:00
RoomTile tile = room.getLayout().getTile(trigger.getX(), trigger.getY());
if (triggeredTiles.contains(tile))
continue;
2020-10-31 03:11:33 +01:00
THashSet<InteractionWiredEffect> tEffectsToExecute = new THashSet<InteractionWiredEffect>();
if (handle(trigger, roomUnit, room, stuff, tEffectsToExecute)) {
effectsToExecute.addAll(tEffectsToExecute);
2019-05-26 20:14:53 +02:00
if (triggerType.equals(WiredTriggerType.SAY_SOMETHING))
2018-07-06 15:30:00 +02:00
talked = true;
triggeredTiles.add(tile);
}
}
2020-10-31 03:11:33 +01:00
for (InteractionWiredEffect effect : effectsToExecute) {
triggerEffect(effect, roomUnit, room, stuff, millis);
}
2018-07-06 15:30:00 +02:00
return talked;
}
2019-05-26 20:14:53 +02:00
public static boolean handleCustomTrigger(Class<? extends InteractionWiredTrigger> triggerType, RoomUnit roomUnit, Room room, Object[] stuff) {
2019-03-18 02:22:00 +01:00
if (!Emulator.isReady)
return false;
if (room == null)
return false;
2019-05-26 20:14:53 +02:00
if (!room.isLoaded())
2019-03-18 02:22:00 +01:00
return false;
2019-05-26 20:14:53 +02:00
if (room.getRoomSpecialTypes() == null)
2019-03-18 02:22:00 +01:00
return false;
2019-05-26 20:14:53 +02:00
THashSet<InteractionWiredTrigger> triggers = room.getRoomSpecialTypes().getTriggers(WiredTriggerType.CUSTOM);
2019-03-18 02:22:00 +01:00
2019-05-26 20:14:53 +02:00
if (triggers == null || triggers.isEmpty())
2019-03-18 02:22:00 +01:00
return false;
2020-10-31 03:11:33 +01:00
long millis = System.currentTimeMillis();
THashSet<InteractionWiredEffect> effectsToExecute = new THashSet<InteractionWiredEffect>();
2019-03-18 02:22:00 +01:00
List<RoomTile> triggeredTiles = new ArrayList<>();
2019-05-26 20:14:53 +02:00
for (InteractionWiredTrigger trigger : triggers) {
2019-03-18 02:22:00 +01:00
if (trigger.getClass() != triggerType) continue;
RoomTile tile = room.getLayout().getTile(trigger.getX(), trigger.getY());
if (triggeredTiles.contains(tile))
continue;
2020-10-31 03:11:33 +01:00
THashSet<InteractionWiredEffect> tEffectsToExecute = new THashSet<InteractionWiredEffect>();
if (handle(trigger, roomUnit, room, stuff, tEffectsToExecute)) {
effectsToExecute.addAll(tEffectsToExecute);
2019-03-18 02:22:00 +01:00
triggeredTiles.add(tile);
}
}
2020-10-31 03:11:33 +01:00
for (InteractionWiredEffect effect : effectsToExecute) {
triggerEffect(effect, roomUnit, room, stuff, millis);
}
return effectsToExecute.size() > 0;
2019-03-18 02:22:00 +01:00
}
2019-05-26 20:14:53 +02:00
public static boolean handle(InteractionWiredTrigger trigger, final RoomUnit roomUnit, final Room room, final Object[] stuff) {
2020-10-31 03:11:33 +01:00
long millis = System.currentTimeMillis();
THashSet<InteractionWiredEffect> effectsToExecute = new THashSet<InteractionWiredEffect>();
if(handle(trigger, roomUnit, room, stuff, effectsToExecute)) {
for (InteractionWiredEffect effect : effectsToExecute) {
triggerEffect(effect, roomUnit, room, stuff, millis);
}
return true;
}
return false;
}
public static boolean handle(InteractionWiredTrigger trigger, final RoomUnit roomUnit, final Room room, final Object[] stuff, final THashSet<InteractionWiredEffect> effectsToExecute) {
2018-07-08 23:32:00 +02:00
long millis = System.currentTimeMillis();
int roomUnitId = roomUnit != null ? roomUnit.getId() : -1;
if (Emulator.isReady && ((Emulator.getConfig().getBoolean("wired.custom.enabled", false) && (trigger.canExecute(millis) || roomUnitId > -1) && trigger.userCanExecute(roomUnitId, millis)) || (!Emulator.getConfig().getBoolean("wired.custom.enabled", false) && trigger.canExecute(millis))) && trigger.execute(roomUnit, room, stuff)) {
trigger.activateBox(room, roomUnit, millis);
2018-07-06 15:30:00 +02:00
THashSet<InteractionWiredCondition> conditions = room.getRoomSpecialTypes().getConditions(trigger.getX(), trigger.getY());
THashSet<InteractionWiredEffect> effects = room.getRoomSpecialTypes().getEffects(trigger.getX(), trigger.getY());
2019-05-26 20:14:53 +02:00
if (Emulator.getPluginManager().fireEvent(new WiredStackTriggeredEvent(room, roomUnit, trigger, effects, conditions)).isCancelled())
2018-07-06 15:30:00 +02:00
return false;
2019-05-26 20:14:53 +02:00
if (!conditions.isEmpty()) {
2018-12-22 11:39:00 +01:00
ArrayList<WiredConditionType> matchedConditions = new ArrayList<>(conditions.size());
2019-05-26 20:14:53 +02:00
for (InteractionWiredCondition searchMatched : conditions) {
if (!matchedConditions.contains(searchMatched.getType()) && searchMatched.operator() == WiredConditionOperator.OR && searchMatched.execute(roomUnit, room, stuff)) {
2018-12-22 11:39:00 +01:00
matchedConditions.add(searchMatched.getType());
}
2018-07-06 15:30:00 +02:00
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
for (InteractionWiredCondition condition : conditions) {
if (!((condition.operator() == WiredConditionOperator.OR && matchedConditions.contains(condition.getType())) ||
(condition.operator() == WiredConditionOperator.AND && condition.execute(roomUnit, room, stuff))) &&
!Emulator.getPluginManager().fireEvent(new WiredConditionFailedEvent(room, roomUnit, trigger, condition)).isCancelled()) {
return false;
2018-12-22 11:39:00 +01:00
}
2018-07-06 15:30:00 +02:00
}
}
trigger.setCooldown(millis);
2018-07-06 15:30:00 +02:00
boolean hasExtraRandom = room.getRoomSpecialTypes().hasExtraType(trigger.getX(), trigger.getY(), WiredExtraRandom.class);
boolean hasExtraUnseen = room.getRoomSpecialTypes().hasExtraType(trigger.getX(), trigger.getY(), WiredExtraUnseen.class);
THashSet<InteractionWiredExtra> extras = room.getRoomSpecialTypes().getExtras(trigger.getX(), trigger.getY());
2019-05-26 20:14:53 +02:00
for (InteractionWiredExtra extra : extras) {
extra.activateBox(room, roomUnit, millis);
2018-07-06 15:30:00 +02:00
}
List<InteractionWiredEffect> effectList = new ArrayList<>(effects);
2019-05-26 20:14:53 +02:00
if (hasExtraRandom || hasExtraUnseen) {
2018-07-06 15:30:00 +02:00
Collections.shuffle(effectList);
}
2019-05-26 20:14:53 +02:00
if (hasExtraUnseen) {
for (InteractionWiredExtra extra : room.getRoomSpecialTypes().getExtras(trigger.getX(), trigger.getY())) {
if (extra instanceof WiredExtraUnseen) {
2018-07-06 15:30:00 +02:00
extra.setExtradata(extra.getExtradata().equals("1") ? "0" : "1");
InteractionWiredEffect effect = ((WiredExtraUnseen) extra).getUnseenEffect(effectList);
2020-10-31 03:11:33 +01:00
effectsToExecute.add(effect); // triggerEffect(effect, roomUnit, room, stuff, millis);
2018-07-06 15:30:00 +02:00
break;
}
}
2019-05-26 20:14:53 +02:00
} else {
for (final InteractionWiredEffect effect : effectList) {
2020-10-31 03:11:33 +01:00
boolean executed = effectsToExecute.add(effect); //triggerEffect(effect, roomUnit, room, stuff, millis);
2019-05-26 20:14:53 +02:00
if (hasExtraRandom && executed) {
2018-07-06 15:30:00 +02:00
break;
}
}
}
return !Emulator.getPluginManager().fireEvent(new WiredStackExecutedEvent(room, roomUnit, trigger, effects, conditions)).isCancelled();
}
return false;
}
2019-05-26 20:14:53 +02:00
private static boolean triggerEffect(InteractionWiredEffect effect, RoomUnit roomUnit, Room room, Object[] stuff, long millis) {
2018-07-06 15:30:00 +02:00
boolean executed = false;
2021-09-02 14:59:33 +02:00
if (effect != null && (effect.canExecute(millis) || (roomUnit != null && effect.requiresTriggeringUser() && Emulator.getConfig().getBoolean("wired.custom.enabled", false) && effect.userCanExecute(roomUnit.getId(), millis)))) {
2018-07-06 15:30:00 +02:00
executed = true;
2019-05-26 20:14:53 +02:00
if (!effect.requiresTriggeringUser() || (roomUnit != null && effect.requiresTriggeringUser())) {
2020-02-08 13:02:34 +01:00
Emulator.getThreading().run(() -> {
if (room.isLoaded()) {
try {
if (!effect.execute(roomUnit, room, stuff)) return;
effect.setCooldown(millis);
} catch (Exception e) {
2020-05-04 22:24:09 +02:00
LOGGER.error("Caught exception", e);
2018-07-06 15:30:00 +02:00
}
2020-02-08 13:02:34 +01:00
effect.activateBox(room, roomUnit, millis);
2018-07-06 15:30:00 +02:00
}
}, effect.getDelay() * 500);
}
}
2019-05-26 20:14:53 +02:00
return executed;
2018-07-06 15:30:00 +02:00
}
2020-11-16 12:12:24 +01:00
public static GsonBuilder getGsonBuilder() {
if(gsonBuilder == null) {
gsonBuilder = new GsonBuilder();
}
return gsonBuilder;
}
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public static boolean executeEffectsAtTiles(THashSet<RoomTile> tiles, final RoomUnit roomUnit, final Room room, final Object[] stuff) {
for (RoomTile tile : tiles) {
if (room != null) {
2018-07-06 15:30:00 +02:00
THashSet<HabboItem> items = room.getItemsAt(tile);
2019-03-18 02:22:00 +01:00
long millis = room.getCycleTimestamp();
2019-05-26 20:14:53 +02:00
for (final HabboItem item : items) {
if (item instanceof InteractionWiredEffect && !(item instanceof WiredEffectTriggerStacks)) {
2018-07-06 15:30:00 +02:00
triggerEffect((InteractionWiredEffect) item, roomUnit, room, stuff, millis);
2019-03-18 02:22:00 +01:00
((InteractionWiredEffect) item).setCooldown(millis);
2018-07-06 15:30:00 +02:00
}
}
}
}
return true;
}
2019-05-26 20:14:53 +02:00
public static void dropRewards(int wiredId) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM wired_rewards_given WHERE wired_item = ?")) {
2018-07-06 15:30:00 +02:00
statement.setInt(1, wiredId);
statement.execute();
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2020-05-04 22:24:09 +02:00
LOGGER.error("Caught SQL exception", e);
2018-07-06 15:30:00 +02:00
}
}
2019-05-26 20:14:53 +02:00
private static void giveReward(Habbo habbo, WiredEffectGiveReward wiredBox, WiredGiveRewardItem reward) {
if (wiredBox.limit > 0)
2018-07-06 15:30:00 +02:00
wiredBox.given++;
2019-05-26 20:14:53 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO wired_rewards_given (wired_item, user_id, reward_id, timestamp) VALUES ( ?, ?, ?, ?)")) {
2018-07-06 15:30:00 +02:00
statement.setInt(1, wiredBox.getId());
statement.setInt(2, habbo.getHabboInfo().getId());
statement.setInt(3, reward.id);
statement.setInt(4, Emulator.getIntUnixTimestamp());
statement.execute();
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2020-05-04 22:24:09 +02:00
LOGGER.error("Caught SQL exception", e);
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
if (reward.badge) {
2018-07-06 15:30:00 +02:00
UserWiredRewardReceived rewardReceived = new UserWiredRewardReceived(habbo, wiredBox, "badge", reward.data);
2019-05-26 20:14:53 +02:00
if (Emulator.getPluginManager().fireEvent(rewardReceived).isCancelled())
2018-07-06 15:30:00 +02:00
return;
2019-05-26 20:14:53 +02:00
if (rewardReceived.value.isEmpty())
2018-07-06 15:30:00 +02:00
return;
HabboBadge badge = new HabboBadge(0, rewardReceived.value, 0, habbo);
Emulator.getThreading().run(badge);
habbo.getInventory().getBadgesComponent().addBadge(badge);
habbo.getClient().sendResponse(new AddUserBadgeComposer(badge));
habbo.getClient().sendResponse(new WiredRewardAlertComposer(WiredRewardAlertComposer.REWARD_RECEIVED_BADGE));
2019-05-26 20:14:53 +02:00
} else {
2018-07-06 15:30:00 +02:00
String[] data = reward.data.split("#");
2019-05-26 20:14:53 +02:00
if (data.length == 2) {
2018-07-06 15:30:00 +02:00
UserWiredRewardReceived rewardReceived = new UserWiredRewardReceived(habbo, wiredBox, data[0], data[1]);
2019-05-26 20:14:53 +02:00
if (Emulator.getPluginManager().fireEvent(rewardReceived).isCancelled())
2018-07-06 15:30:00 +02:00
return;
2019-05-26 20:14:53 +02:00
if (rewardReceived.value.isEmpty())
2018-07-06 15:30:00 +02:00
return;
2019-05-26 20:14:53 +02:00
if (rewardReceived.type.equalsIgnoreCase("credits")) {
2018-07-06 15:30:00 +02:00
int credits = Integer.valueOf(rewardReceived.value);
habbo.giveCredits(credits);
2019-05-26 20:14:53 +02:00
} else if (rewardReceived.type.equalsIgnoreCase("pixels")) {
2018-07-06 15:30:00 +02:00
int pixels = Integer.valueOf(rewardReceived.value);
habbo.givePixels(pixels);
2019-05-26 20:14:53 +02:00
} else if (rewardReceived.type.startsWith("points")) {
2018-07-06 15:30:00 +02:00
int points = Integer.valueOf(rewardReceived.value);
2018-10-07 00:28:00 +02:00
int type = 5;
2019-05-26 20:14:53 +02:00
try {
type = Integer.valueOf(rewardReceived.type.replace("points", ""));
} catch (Exception e) {
}
2018-10-07 00:28:00 +02:00
habbo.givePoints(type, points);
2019-05-26 20:14:53 +02:00
} else if (rewardReceived.type.equalsIgnoreCase("furni")) {
2018-07-06 15:30:00 +02:00
Item baseItem = Emulator.getGameEnvironment().getItemManager().getItem(Integer.valueOf(rewardReceived.value));
2019-05-26 20:14:53 +02:00
if (baseItem != null) {
2018-07-06 15:30:00 +02:00
HabboItem item = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getHabboInfo().getId(), baseItem, 0, 0, "");
2019-05-26 20:14:53 +02:00
if (item != null) {
2018-07-06 15:30:00 +02:00
habbo.getClient().sendResponse(new AddHabboItemComposer(item));
habbo.getClient().getHabbo().getInventory().getItemsComponent().addItem(item);
habbo.getClient().sendResponse(new PurchaseOKComposer(null));
habbo.getClient().sendResponse(new InventoryRefreshComposer());
habbo.getClient().sendResponse(new WiredRewardAlertComposer(WiredRewardAlertComposer.REWARD_RECEIVED_ITEM));
}
}
2019-05-26 20:14:53 +02:00
} else if (rewardReceived.type.equalsIgnoreCase("respect")) {
2018-07-06 15:30:00 +02:00
habbo.getHabboStats().respectPointsReceived += Integer.valueOf(rewardReceived.value);
2019-05-26 20:14:53 +02:00
} else if (rewardReceived.type.equalsIgnoreCase("cata")) {
2018-07-06 15:30:00 +02:00
CatalogItem item = Emulator.getGameEnvironment().getCatalogManager().getCatalogItem(Integer.valueOf(rewardReceived.value));
2019-05-26 20:14:53 +02:00
if (item != null) {
2018-07-06 15:30:00 +02:00
Emulator.getGameEnvironment().getCatalogManager().purchaseItem(null, item, habbo, 1, "", true);
}
habbo.getClient().sendResponse(new WiredRewardAlertComposer(WiredRewardAlertComposer.REWARD_RECEIVED_ITEM));
}
}
}
}
2019-05-26 20:14:53 +02:00
public static boolean getReward(Habbo habbo, WiredEffectGiveReward wiredBox) {
if (wiredBox.limit > 0) {
if (wiredBox.limit - wiredBox.given == 0) {
2018-07-06 15:30:00 +02:00
habbo.getClient().sendResponse(new WiredRewardAlertComposer(WiredRewardAlertComposer.LIMITED_NO_MORE_AVAILABLE));
return false;
}
}
2019-05-26 20:14:53 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT COUNT(*) as row_count, wired_rewards_given.* FROM wired_rewards_given WHERE user_id = ? AND wired_item = ? ORDER BY timestamp DESC LIMIT ?")) {
2018-07-06 15:30:00 +02:00
statement.setInt(1, habbo.getHabboInfo().getId());
statement.setInt(2, wiredBox.getId());
statement.setInt(3, wiredBox.rewardItems.size());
2019-05-26 20:14:53 +02:00
try (ResultSet set = statement.executeQuery()) {
if (set.first()) {
if (set.getInt("row_count") >= 1) {
if (wiredBox.rewardTime == WiredEffectGiveReward.LIMIT_ONCE) {
2018-07-06 15:30:00 +02:00
habbo.getClient().sendResponse(new WiredRewardAlertComposer(WiredRewardAlertComposer.REWARD_ALREADY_RECEIVED));
return false;
}
}
set.beforeFirst();
2019-05-26 20:14:53 +02:00
if (set.next()) {
if (wiredBox.rewardTime == WiredEffectGiveReward.LIMIT_N_MINUTES) {
if (Emulator.getIntUnixTimestamp() - set.getInt("timestamp") <= 60) {
2018-07-06 15:30:00 +02:00
habbo.getClient().sendResponse(new WiredRewardAlertComposer(WiredRewardAlertComposer.REWARD_ALREADY_RECEIVED_THIS_MINUTE));
return false;
}
}
2019-05-26 20:14:53 +02:00
if (wiredBox.uniqueRewards) {
if (set.getInt("row_count") == wiredBox.rewardItems.size()) {
2018-07-06 15:30:00 +02:00
habbo.getClient().sendResponse(new WiredRewardAlertComposer(WiredRewardAlertComposer.REWARD_ALL_COLLECTED));
return false;
}
}
2019-05-26 20:14:53 +02:00
if (wiredBox.rewardTime == WiredEffectGiveReward.LIMIT_N_HOURS) {
if (!(Emulator.getIntUnixTimestamp() - set.getInt("timestamp") >= (3600 * wiredBox.limitationInterval))) {
2018-07-06 15:30:00 +02:00
habbo.getClient().sendResponse(new WiredRewardAlertComposer(WiredRewardAlertComposer.REWARD_ALREADY_RECEIVED_THIS_HOUR));
return false;
}
}
2019-05-26 20:14:53 +02:00
if (wiredBox.rewardTime == WiredEffectGiveReward.LIMIT_N_DAY) {
if (!(Emulator.getIntUnixTimestamp() - set.getInt("timestamp") >= (86400 * wiredBox.limitationInterval))) {
2018-07-06 15:30:00 +02:00
habbo.getClient().sendResponse(new WiredRewardAlertComposer(WiredRewardAlertComposer.REWARD_ALREADY_RECEIVED_THIS_TODAY));
return false;
}
}
}
2019-05-26 20:14:53 +02:00
if (wiredBox.uniqueRewards) {
for (WiredGiveRewardItem item : wiredBox.rewardItems) {
2018-07-06 15:30:00 +02:00
set.beforeFirst();
boolean found = false;
2019-05-26 20:14:53 +02:00
while (set.next()) {
2018-07-06 15:30:00 +02:00
if (set.getInt("reward_id") == item.id)
found = true;
}
2019-05-26 20:14:53 +02:00
if (!found) {
2018-07-06 15:30:00 +02:00
giveReward(habbo, wiredBox, item);
return true;
}
}
2019-05-26 20:14:53 +02:00
} else {
2018-07-06 15:30:00 +02:00
int randomNumber = Emulator.getRandom().nextInt(101);
int count = 0;
2019-05-26 20:14:53 +02:00
for (WiredGiveRewardItem item : wiredBox.rewardItems) {
if (randomNumber >= count && randomNumber <= (count + item.probability)) {
2018-07-06 15:30:00 +02:00
giveReward(habbo, wiredBox, item);
return true;
}
count += item.probability;
}
}
}
}
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2020-05-04 22:24:09 +02:00
LOGGER.error("Caught SQL exception", e);
2018-07-06 15:30:00 +02:00
}
return false;
}
2019-05-26 20:14:53 +02:00
public static void resetTimers(Room room) {
2020-02-01 19:32:29 +01:00
if (!room.isLoaded() || room.getRoomSpecialTypes() == null)
2018-07-06 15:30:00 +02:00
return;
2020-02-01 19:32:29 +01:00
room.getRoomSpecialTypes().getTriggers().forEach(t -> {
if (t == null) return;
if (t.getType() == WiredTriggerType.AT_GIVEN_TIME || t.getType() == WiredTriggerType.PERIODICALLY || t.getType() == WiredTriggerType.PERIODICALLY_LONG) {
((WiredTriggerReset) t).resetTimer();
2018-07-06 15:30:00 +02:00
}
});
2018-07-06 15:30:00 +02:00
room.setLastTimerReset(Emulator.getIntUnixTimestamp());
}
}