package com.eu.habbo.habbohotel.rooms; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.ICycleable; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.*; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer; import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTeleporter; import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.gates.InteractionBattleBanzaiGate; import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.scoreboards.InteractionBattleBanzaiScoreboard; import com.eu.habbo.habbohotel.items.interactions.games.football.scoreboards.InteractionFootballScoreboard; import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile; import com.eu.habbo.habbohotel.items.interactions.games.freeze.gates.InteractionFreezeGate; import com.eu.habbo.habbohotel.items.interactions.games.freeze.scoreboards.InteractionFreezeScoreboard; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionNest; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetDrink; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetFood; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetToy; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; import java.awt.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; public class RoomSpecialTypes { private final THashMap banzaiTeleporters; private final THashMap nests; private final THashMap petDrinks; private final THashMap petFoods; private final THashMap petToys; private final THashMap rollers; private final THashMap> wiredTriggers; private final THashMap> wiredEffects; private final THashMap> wiredConditions; private final THashMap wiredExtras; private final THashMap gameScoreboards; private final THashMap gameGates; private final THashMap gameTimers; private final THashMap freezeExitTile; private final THashMap undefined; private final THashSet cycleTasks; public RoomSpecialTypes() { this.banzaiTeleporters = new THashMap<>(0); this.nests = new THashMap<>(0); this.petDrinks = new THashMap<>(0); this.petFoods = new THashMap<>(0); this.petToys = new THashMap<>(0); this.rollers = new THashMap<>(0); this.wiredTriggers = new THashMap<>(0); this.wiredEffects = new THashMap<>(0); this.wiredConditions = new THashMap<>(0); this.wiredExtras = new THashMap<>(0); this.gameScoreboards = new THashMap<>(0); this.gameGates = new THashMap<>(0); this.gameTimers = new THashMap<>(0); this.freezeExitTile = new THashMap<>(0); this.undefined = new THashMap<>(0); this.cycleTasks = new THashSet<>(0); } public InteractionBattleBanzaiTeleporter getBanzaiTeleporter(int itemId) { return this.banzaiTeleporters.get(itemId); } public void addBanzaiTeleporter(InteractionBattleBanzaiTeleporter item) { this.banzaiTeleporters.put(item.getId(), item); } public void removeBanzaiTeleporter(InteractionBattleBanzaiTeleporter item) { this.banzaiTeleporters.remove(item.getId()); } public THashSet getBanzaiTeleporters() { synchronized (this.banzaiTeleporters) { THashSet battleBanzaiTeleporters = new THashSet<>(); battleBanzaiTeleporters.addAll(this.banzaiTeleporters.values()); return battleBanzaiTeleporters; } } public InteractionBattleBanzaiTeleporter getRandomTeleporter(Item baseItem, InteractionBattleBanzaiTeleporter exclude) { List teleporterList = new ArrayList<>(); for (InteractionBattleBanzaiTeleporter teleporter : this.banzaiTeleporters.values()) { if (baseItem == null || teleporter.getBaseItem() == baseItem) { teleporterList.add(teleporter); } } teleporterList.remove(exclude); if (!teleporterList.isEmpty()) { Collections.shuffle(teleporterList); return teleporterList.get(0); } return null; } public InteractionNest getNest(int itemId) { return this.nests.get(itemId); } public void addNest(InteractionNest item) { this.nests.put(item.getId(), item); } public void removeNest(InteractionNest item) { this.nests.remove(item.getId()); } public THashSet getNests() { synchronized (this.nests) { THashSet nests = new THashSet<>(); nests.addAll(this.nests.values()); return nests; } } public InteractionPetDrink getPetDrink(int itemId) { return this.petDrinks.get(itemId); } public void addPetDrink(InteractionPetDrink item) { this.petDrinks.put(item.getId(), item); } public void removePetDrink(InteractionPetDrink item) { this.petDrinks.remove(item.getId()); } public THashSet getPetDrinks() { synchronized (this.petDrinks) { THashSet petDrinks = new THashSet<>(); petDrinks.addAll(this.petDrinks.values()); return petDrinks; } } public InteractionPetFood getPetFood(int itemId) { return this.petFoods.get(itemId); } public void addPetFood(InteractionPetFood item) { this.petFoods.put(item.getId(), item); } public void removePetFood(InteractionPetFood petFood) { this.petFoods.remove(petFood.getId()); } public THashSet getPetFoods() { synchronized (this.petFoods) { THashSet petFoods = new THashSet<>(); petFoods.addAll(this.petFoods.values()); return petFoods; } } public InteractionPetToy getPetToy(int itemId) { return this.petToys.get(itemId); } public void addPetToy(InteractionPetToy item) { this.petToys.put(item.getId(), item); } public void removePetToy(InteractionPetToy petToy) { this.petToys.remove(petToy.getId()); } public THashSet getPetToys() { synchronized (this.petToys) { THashSet petToys = new THashSet<>(); petToys.addAll(this.petToys.values()); return petToys; } } public InteractionRoller getRoller(int itemId) { synchronized (this.rollers) { return this.rollers.get(itemId); } } public void addRoller(InteractionRoller item) { synchronized (this.rollers) { this.rollers.put(item.getId(), item); } } public void removeRoller(InteractionRoller roller) { synchronized (this.rollers) { this.rollers.remove(roller.getId()); } } public THashMap getRollers() { return this.rollers; } public InteractionWiredTrigger getTrigger(int itemId) { synchronized (this.wiredTriggers) { for (Map.Entry> map : this.wiredTriggers.entrySet()) { for (InteractionWiredTrigger trigger : map.getValue()) { if (trigger.getId() == itemId) return trigger; } } return null; } } public THashSet getTriggers() { synchronized (this.wiredTriggers) { THashSet triggers = new THashSet<>(); for (Map.Entry> map : this.wiredTriggers.entrySet()) { triggers.addAll(map.getValue()); } return triggers; } } public THashSet getTriggers(WiredTriggerType type) { return this.wiredTriggers.get(type); } public THashSet getTriggers(int x, int y) { synchronized (this.wiredTriggers) { THashSet triggers = new THashSet<>(); for (Map.Entry> map : this.wiredTriggers.entrySet()) { for (InteractionWiredTrigger trigger : map.getValue()) { if (trigger.getX() == x && trigger.getY() == y) triggers.add(trigger); } } return triggers; } } public void addTrigger(InteractionWiredTrigger trigger) { synchronized (this.wiredTriggers) { if (!this.wiredTriggers.containsKey(trigger.getType())) this.wiredTriggers.put(trigger.getType(), new THashSet<>()); this.wiredTriggers.get(trigger.getType()).add(trigger); } } public void removeTrigger(InteractionWiredTrigger trigger) { synchronized (this.wiredTriggers) { this.wiredTriggers.get(trigger.getType()).remove(trigger); if (this.wiredTriggers.get(trigger.getType()).isEmpty()) { this.wiredTriggers.remove(trigger.getType()); } } } public InteractionWiredEffect getEffect(int itemId) { synchronized (this.wiredEffects) { for (Map.Entry> map : this.wiredEffects.entrySet()) { for (InteractionWiredEffect effect : map.getValue()) { if (effect.getId() == itemId) return effect; } } } return null; } public THashSet getEffects() { synchronized (this.wiredEffects) { THashSet effects = new THashSet<>(); for (Map.Entry> map : this.wiredEffects.entrySet()) { effects.addAll(map.getValue()); } return effects; } } public THashSet getEffects(WiredEffectType type) { return this.wiredEffects.get(type); } public THashSet getEffects(int x, int y) { synchronized (this.wiredEffects) { THashSet effects = new THashSet<>(); for (Map.Entry> map : this.wiredEffects.entrySet()) { for (InteractionWiredEffect effect : map.getValue()) { if (effect.getX() == x && effect.getY() == y) effects.add(effect); } } return effects; } } public void addEffect(InteractionWiredEffect effect) { synchronized (this.wiredEffects) { if (!this.wiredEffects.containsKey(effect.getType())) this.wiredEffects.put(effect.getType(), new THashSet<>()); this.wiredEffects.get(effect.getType()).add(effect); } } public void removeEffect(InteractionWiredEffect effect) { synchronized (this.wiredEffects) { this.wiredEffects.get(effect.getType()).remove(effect); if (this.wiredEffects.get(effect.getType()).isEmpty()) { this.wiredEffects.remove(effect.getType()); } } } public InteractionWiredCondition getCondition(int itemId) { synchronized (this.wiredConditions) { for (Map.Entry> map : this.wiredConditions.entrySet()) { for (InteractionWiredCondition condition : map.getValue()) { if (condition.getId() == itemId) return condition; } } } return null; } public THashSet getConditions() { synchronized (this.wiredConditions) { THashSet conditions = new THashSet<>(); for (Map.Entry> map : this.wiredConditions.entrySet()) { conditions.addAll(map.getValue()); } return conditions; } } public THashSet getConditions(WiredConditionType type) { synchronized (this.wiredConditions) { return this.wiredConditions.get(type); } } public THashSet getConditions(int x, int y) { synchronized (this.wiredConditions) { THashSet conditions = new THashSet<>(); for (Map.Entry> map : this.wiredConditions.entrySet()) { for (InteractionWiredCondition condition : map.getValue()) { if (condition.getX() == x && condition.getY() == y) conditions.add(condition); } } return conditions; } } public void addCondition(InteractionWiredCondition condition) { synchronized (this.wiredConditions) { if (!this.wiredConditions.containsKey(condition.getType())) this.wiredConditions.put(condition.getType(), new THashSet<>()); this.wiredConditions.get(condition.getType()).add(condition); } } public void removeCondition(InteractionWiredCondition condition) { synchronized (this.wiredConditions) { this.wiredConditions.get(condition.getType()).remove(condition); if (this.wiredConditions.get(condition.getType()).isEmpty()) { this.wiredConditions.remove(condition.getType()); } } } public THashSet getExtras() { synchronized (this.wiredExtras) { THashSet conditions = new THashSet<>(); for (Map.Entry map : this.wiredExtras.entrySet()) { conditions.add(map.getValue()); } return conditions; } } public THashSet getExtras(int x, int y) { synchronized (this.wiredExtras) { THashSet extras = new THashSet<>(); for (Map.Entry map : this.wiredExtras.entrySet()) { if (map.getValue().getX() == x && map.getValue().getY() == y) { extras.add(map.getValue()); } } return extras; } } public void addExtra(InteractionWiredExtra extra) { synchronized (this.wiredExtras) { this.wiredExtras.put(extra.getId(), extra); } } public void removeExtra(InteractionWiredExtra extra) { synchronized (this.wiredExtras) { this.wiredExtras.remove(extra.getId()); } } public boolean hasExtraType(short x, short y, Class type) { synchronized (this.wiredExtras) { for (Map.Entry map : this.wiredExtras.entrySet()) { if (map.getValue().getX() == x && map.getValue().getY() == y && map.getValue().getClass().isAssignableFrom(type)) { return true; } } } return false; } public InteractionGameScoreboard getGameScorebord(int itemId) { return this.gameScoreboards.get(itemId); } public void addGameScoreboard(InteractionGameScoreboard scoreboard) { this.gameScoreboards.put(scoreboard.getId(), scoreboard); } public void removeScoreboard(InteractionGameScoreboard scoreboard) { this.gameScoreboards.remove(scoreboard.getId()); } public THashMap getFreezeScoreboards() { synchronized (this.gameScoreboards) { THashMap boards = new THashMap<>(); for (Map.Entry set : this.gameScoreboards.entrySet()) { if (set.getValue() instanceof InteractionFreezeScoreboard) { boards.put(set.getValue().getId(), (InteractionFreezeScoreboard) set.getValue()); } } return boards; } } public THashMap getFreezeScoreboards(GameTeamColors teamColor) { synchronized (this.gameScoreboards) { THashMap boards = new THashMap<>(); for (Map.Entry set : this.gameScoreboards.entrySet()) { if (set.getValue() instanceof InteractionFreezeScoreboard) { if (((InteractionFreezeScoreboard) set.getValue()).teamColor.equals(teamColor)) boards.put(set.getValue().getId(), (InteractionFreezeScoreboard) set.getValue()); } } return boards; } } public THashMap getBattleBanzaiScoreboards() { synchronized (this.gameScoreboards) { THashMap boards = new THashMap<>(); for (Map.Entry set : this.gameScoreboards.entrySet()) { if (set.getValue() instanceof InteractionBattleBanzaiScoreboard) { boards.put(set.getValue().getId(), (InteractionBattleBanzaiScoreboard) set.getValue()); } } return boards; } } public THashMap getBattleBanzaiScoreboards(GameTeamColors teamColor) { synchronized (this.gameScoreboards) { THashMap boards = new THashMap<>(); for (Map.Entry set : this.gameScoreboards.entrySet()) { if (set.getValue() instanceof InteractionBattleBanzaiScoreboard) { if (((InteractionBattleBanzaiScoreboard) set.getValue()).teamColor.equals(teamColor)) boards.put(set.getValue().getId(), (InteractionBattleBanzaiScoreboard) set.getValue()); } } return boards; } } public THashMap getFootballScoreboards() { synchronized (this.gameScoreboards) { THashMap boards = new THashMap<>(); for (Map.Entry set : this.gameScoreboards.entrySet()) { if (set.getValue() instanceof InteractionFootballScoreboard) { boards.put(set.getValue().getId(), (InteractionFootballScoreboard) set.getValue()); } } return boards; } } public THashMap getFootballScoreboards(GameTeamColors teamColor) { synchronized (this.gameScoreboards) { THashMap boards = new THashMap<>(); for (Map.Entry set : this.gameScoreboards.entrySet()) { if (set.getValue() instanceof InteractionFootballScoreboard) { if (((InteractionFootballScoreboard) set.getValue()).teamColor.equals(teamColor)) boards.put(set.getValue().getId(), (InteractionFootballScoreboard) set.getValue()); } } return boards; } } public InteractionGameGate getGameGate(int itemId) { return this.gameGates.get(itemId); } public void addGameGate(InteractionGameGate gameGate) { this.gameGates.put(gameGate.getId(), gameGate); } public void removeGameGate(InteractionGameGate gameGate) { this.gameGates.remove(gameGate.getId()); } public THashMap getFreezeGates() { synchronized (this.gameGates) { THashMap gates = new THashMap<>(); for (Map.Entry set : this.gameGates.entrySet()) { if (set.getValue() instanceof InteractionFreezeGate) { gates.put(set.getValue().getId(), (InteractionFreezeGate) set.getValue()); } } return gates; } } public THashMap getBattleBanzaiGates() { synchronized (this.gameGates) { THashMap gates = new THashMap<>(); for (Map.Entry set : this.gameGates.entrySet()) { if (set.getValue() instanceof InteractionBattleBanzaiGate) { gates.put(set.getValue().getId(), (InteractionBattleBanzaiGate) set.getValue()); } } return gates; } } public InteractionGameTimer getGameTimer(int itemId) { return this.gameTimers.get(itemId); } public void addGameTimer(InteractionGameTimer gameTimer) { this.gameTimers.put(gameTimer.getId(), gameTimer); } public void removeGameTimer(InteractionGameTimer gameTimer) { this.gameTimers.remove(gameTimer.getId()); } public THashMap getGameTimers() { return this.gameTimers; } public InteractionFreezeExitTile getFreezeExitTile() { for (InteractionFreezeExitTile t : this.freezeExitTile.values()) { return t; } return null; } public InteractionFreezeExitTile getRandomFreezeExitTile() { synchronized (this.freezeExitTile) { return (InteractionFreezeExitTile) this.freezeExitTile.values().toArray()[Emulator.getRandom().nextInt(this.freezeExitTile.size())]; } } public void addFreezeExitTile(InteractionFreezeExitTile freezeExitTile) { this.freezeExitTile.put(freezeExitTile.getId(), freezeExitTile); } public THashMap getFreezeExitTiles() { return this.freezeExitTile; } public void removeFreezeExitTile(InteractionFreezeExitTile freezeExitTile) { this.freezeExitTile.remove(freezeExitTile.getId()); } public boolean hasFreezeExitTile() { return !this.freezeExitTile.isEmpty(); } public void addUndefined(HabboItem item) { synchronized (this.undefined) { this.undefined.put(item.getId(), item); } } public void removeUndefined(HabboItem item) { synchronized (this.undefined) { this.undefined.remove(item.getId()); } } public THashSet getItemsOfType(Class type) { THashSet items = new THashSet<>(); synchronized (this.undefined) { for (HabboItem item : this.undefined.values()) { if (item.getClass() == type) items.add(item); } } return items; } public HabboItem getLowestItemsOfType(Class type) { HabboItem i = null; synchronized (this.undefined) { for (HabboItem item : this.undefined.values()) { if (i == null || item.getZ() < i.getZ()) { if (item.getClass().isAssignableFrom(type)) { i = item; } } } } return i; } public THashSet getCycleTasks() { return this.cycleTasks; } public void addCycleTask(ICycleable task) { this.cycleTasks.add(task); } public void removeCycleTask(ICycleable task) { this.cycleTasks.remove(task); } public synchronized void dispose() { this.banzaiTeleporters.clear(); this.nests.clear(); this.petDrinks.clear(); this.petFoods.clear(); this.rollers.clear(); this.wiredTriggers.clear(); this.wiredEffects.clear(); this.wiredConditions.clear(); this.gameScoreboards.clear(); this.gameGates.clear(); this.gameTimers.clear(); this.freezeExitTile.clear(); this.undefined.clear(); this.cycleTasks.clear(); } public Rectangle tentAt(RoomTile location) { for (HabboItem item : this.getItemsOfType(InteractionTent.class)) { Rectangle rectangle = RoomLayout.getRectangle(item.getX(), item.getY(), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); if (RoomLayout.tileInSquare(rectangle, location)) { return rectangle; } } return null; } }