Added costumegate interaction and refactored other conditional gates

This commit is contained in:
Remco 2020-11-23 11:53:12 +01:00
parent 81d49cc4c4
commit 3353b822e4
7 changed files with 149 additions and 26 deletions

View File

@ -141,6 +141,7 @@ public class ItemManager {
this.interactionsList.add(new ItemInteraction("puzzle_box", InteractionPuzzleBox.class));
this.interactionsList.add(new ItemInteraction("hopper", InteractionHopper.class));
this.interactionsList.add(new ItemInteraction("costume_hopper", InteractionCostumeHopper.class));
this.interactionsList.add(new ItemInteraction("costume_gate", InteractionCostumeGate.class));
this.interactionsList.add(new ItemInteraction("club_hopper", InteractionHabboClubHopper.class));
this.interactionsList.add(new ItemInteraction("club_gate", InteractionHabboClubGate.class));
this.interactionsList.add(new ItemInteraction("club_teleporttile", InteractionHabboClubTeleportTile.class));

View File

@ -0,0 +1,108 @@
package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate;
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.rooms.RoomUnitStatus;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.generic.alerts.CustomNotificationComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
import com.eu.habbo.threading.runnables.CloseGate;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
public class InteractionCostumeGate extends InteractionDefault implements ConditionalGate {
public InteractionCostumeGate(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.setExtradata("0");
}
public InteractionCostumeGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.setExtradata("0");
}
@Override
public boolean isWalkable() {
return true;
}
@Override
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
if (roomUnit == null || room == null)
return false;
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null && habbo.getHabboInfo() != null) {
/*
* Get all figureparts. Figureparts are seperated by dots and each figurepart has this format:
* figureType-partID-colorID1-colorID2...-colorIDn
*/
List<String> figureParts = Arrays.asList(habbo.getHabboInfo().getLook().split("\\."));
List<String> allowedPartIds = Arrays.asList(Emulator.getConfig()
.getValue("hotel.item.condition.costume.partids")
.split(";")
);
// Check if at least one of the figureparts is configured as a costume and thus allowed
return figureParts.stream().anyMatch(figurePart -> {
String[] partInfo = figurePart.split("-");
if (partInfo.length >= 2) {
String partID = partInfo[1]; // index 0 is the part, index 1 is the ID
return allowedPartIds.contains(partID);
}
return false;
});
}
return false;
}
@Override
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOn(roomUnit, room, objects);
if (this.canWalkOn(roomUnit, room, objects)) {
this.setExtradata("1");
room.updateItemState(this);
}
}
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
if (client != null) {
if (this.canWalkOn(client.getHabbo().getRoomUnit(), room, null)) {
super.onClick(client, room, objects);
} else {
client.sendResponse(new CustomNotificationComposer(CustomNotificationComposer.GATE_NO_HC));
}
}
}
@Override
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOff(roomUnit, room, objects);
Emulator.getThreading().run(new CloseGate(this, room), 1000);
}
@Override
public void onRejected(RoomUnit roomUnit, Room room, Object[] objects) {
if (roomUnit == null || room == null)
return;
room.getHabbo(roomUnit).getClient().sendResponse(
new CustomNotificationComposer(CustomNotificationComposer.HOPPER_NO_COSTUME)
);
}
}

View File

@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
@ -13,7 +14,7 @@ import com.eu.habbo.threading.runnables.CloseGate;
import java.sql.ResultSet;
import java.sql.SQLException;
public class InteractionGuildGate extends InteractionGuildFurni {
public class InteractionGuildGate extends InteractionGuildFurni implements ConditionalGate {
public InteractionGuildGate(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.setExtradata("0");
@ -61,4 +62,9 @@ public class InteractionGuildGate extends InteractionGuildFurni {
this.setExtradata("0");
room.updateItemState(this);
}
@Override
public void onRejected(RoomUnit roomUnit, Room room, Object[] objects) {
}
}

View File

@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
@ -12,7 +13,7 @@ import com.eu.habbo.threading.runnables.CloseGate;
import java.sql.ResultSet;
import java.sql.SQLException;
public class InteractionHabboClubGate extends InteractionDefault {
public class InteractionHabboClubGate extends InteractionDefault implements ConditionalGate {
public InteractionHabboClubGate(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.setExtradata("0");
@ -42,14 +43,6 @@ public class InteractionHabboClubGate extends InteractionDefault {
if (this.canWalkOn(roomUnit, room, objects)) {
this.setExtradata("1");
room.updateItemState(this);
} else {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
habbo.getClient().sendResponse(new CustomNotificationComposer(CustomNotificationComposer.GATE_NO_HC));
}
roomUnit.setGoalLocation(roomUnit.getCurrentLocation());
}
}
@ -70,4 +63,14 @@ public class InteractionHabboClubGate extends InteractionDefault {
Emulator.getThreading().run(new CloseGate(this, room), 1000);
}
@Override
public void onRejected(RoomUnit roomUnit, Room room, Object[] objects) {
if (roomUnit == null || room == null)
return;
room.getHabbo(roomUnit).getClient().sendResponse(
new CustomNotificationComposer(CustomNotificationComposer.GATE_NO_HC)
);
}
}

View File

@ -0,0 +1,8 @@
package com.eu.habbo.habbohotel.items.interactions.interfaces;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
public interface ConditionalGate {
public void onRejected(RoomUnit roomUnit, Room room, Object[] objects);
}

View File

@ -3,10 +3,8 @@ package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionGuildGate;
import com.eu.habbo.habbohotel.items.interactions.InteractionHabboClubGate;
import com.eu.habbo.habbohotel.items.interactions.InteractionWater;
import com.eu.habbo.habbohotel.items.interactions.InteractionWaterItem;
import com.eu.habbo.habbohotel.items.interactions.*;
import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate;
import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.pets.RideablePet;
import com.eu.habbo.habbohotel.users.DanceType;
@ -301,17 +299,16 @@ public class RoomUnit {
if (item != habboItem || !RoomLayout.pointInSquare(item.getX(), item.getY(), item.getX() + item.getBaseItem().getWidth() - 1, item.getY() + item.getBaseItem().getLength() - 1, this.getX(), this.getY())) {
if (item.canWalkOn(this, room, null)) {
item.onWalkOn(this, room, new Object[]{this.getCurrentLocation(), next});
} else if (item instanceof InteractionGuildGate || item instanceof InteractionHabboClubGate) {
} else if (item instanceof ConditionalGate) {
this.setRotation(oldRotation);
this.tilesWalked--;
this.setGoalLocation(this.currentLocation);
this.status.remove(RoomUnitStatus.MOVE);
room.sendComposer(new RoomUserStatusComposer(this).compose());
if (item instanceof InteractionHabboClubGate && habbo != null) {
habbo.getClient().sendResponse(new CustomNotificationComposer(CustomNotificationComposer.GATE_NO_HC));
if (habbo != null) {
((ConditionalGate) item).onRejected(this, this.getRoom(), new Object[]{});
}
return false;
}
} else {

View File

@ -4,22 +4,22 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.users.HabboItem;
public class CloseGate implements Runnable {
private final HabboItem guildGate;
private final HabboItem gate;
private final Room room;
public CloseGate(HabboItem guildGate, Room room) {
this.guildGate = guildGate;
public CloseGate(HabboItem gate, Room room) {
this.gate = gate;
this.room = room;
}
@Override
public void run() {
if (this.guildGate.getRoomId() == this.room.getId()) {
if (this.gate.getRoomId() == this.room.getId()) {
if (this.room.isLoaded()) {
if (this.room.getHabbosAt(this.guildGate.getX(), this.guildGate.getY()).isEmpty()) {
this.guildGate.setExtradata("0");
this.room.updateItem(this.guildGate);
this.guildGate.needsUpdate(true);
if (this.room.getHabbosAt(this.gate.getX(), this.gate.getY()).isEmpty()) {
this.gate.setExtradata("0");
this.room.updateItem(this.gate);
this.gate.needsUpdate(true);
}
}
}