Merge branch 'fix/fireworks' into 'dev'

Fireworks working like Habbo

See merge request morningstar/Arcturus-Community!360
This commit is contained in:
Harmonic 2021-01-10 17:54:35 -05:00
commit fc93da68ea
2 changed files with 115 additions and 25 deletions

View File

@ -5,14 +5,28 @@ import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomLayout;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class InteractionFireworks extends InteractionDefault {
private static final Logger LOGGER = LoggerFactory.getLogger(InteractionFireworks.class);
private static final String STATE_EMPTY = "0"; // Not used since the removal of pixels
private static final String STATE_CHARGED = "1";
private static final String STATE_EXPLOSION = "2";
public class InteractionFireworks extends HabboItem {
public InteractionFireworks(ResultSet set, Item baseItem) throws SQLException { public InteractionFireworks(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
} }
@ -26,35 +40,103 @@ public class InteractionFireworks extends HabboItem {
return false; return false;
} }
@Override /**
public boolean isWalkable() { * Checked in Habbo on 2021-01-03
return this.getBaseItem().allowWalk(); * - Fireworks should be charged to be able to detonate them
} * - Habbos with Rights can detonate fireworks from anywhere in a room
* - Habbos without rights have to walk to an adjecent tile to be able to detonate (see Interaction Switch)
@Override * - Wired can always detonate fireworks
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { */
}
@Override
public void serializeExtradata(ServerMessage serverMessage) {
serverMessage.appendInt((this.isLimited() ? 256 : 0));
serverMessage.appendString(this.getExtradata());
super.serializeExtradata(serverMessage); //Design flaw ;(
}
@Override @Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception { public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
if (room == null)
return;
// Wireds can always detonate fireworks if charged
if (objects.length >= 2 && objects[1] instanceof WiredEffectType && objects[1] == WiredEffectType.TOGGLE_STATE) {
if (this.getExtradata().equalsIgnoreCase(STATE_CHARGED)) {
super.onClick(client, room, objects); super.onClick(client, room, objects);
if (client != null && this.getExtradata().equalsIgnoreCase("2")) //2 explodes I think (0 = empty, 1 = charged, 2 = effect) if (this.getExtradata().equalsIgnoreCase(STATE_EXPLOSION)) {
this.reCharge(room);
}
}
return;
}
if (client == null)
return;
// Habbos without rights have to walk to an adjecent tile to be able to detonate the fireworks
if (!this.canToggle(client.getHabbo(), room)) {
RoomTile closestTile = null;
for (RoomTile tile : room.getLayout().getTilesAround(room.getLayout().getTile(this.getX(), this.getY()))) {
if (tile.isWalkable() && (closestTile == null || closestTile.distance(client.getHabbo().getRoomUnit().getCurrentLocation()) > tile.distance(client.getHabbo().getRoomUnit().getCurrentLocation()))) {
closestTile = tile;
}
}
if (closestTile != null && !closestTile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) {
List<Runnable> onSuccess = new ArrayList<>();
onSuccess.add(() -> {
try {
this.onClick(client, room, objects);
} catch (Exception e) {
e.printStackTrace();
}
});
client.getHabbo().getRoomUnit().setGoalLocation(closestTile);
Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), closestTile, room, onSuccess, new ArrayList<>()));
}
}
if (this.getExtradata().equalsIgnoreCase(STATE_CHARGED)) {
super.onClick(client, room, objects);
if (this.getExtradata().equalsIgnoreCase(STATE_EXPLOSION))
{ {
this.reCharge(room);
AchievementManager.progressAchievement(client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FireworksCharger")); AchievementManager.progressAchievement(client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FireworksCharger"));
} }
} }
}
@Override @Override
public boolean allowWiredResetState() { public boolean allowWiredResetState() {
return true; return false;
}
@Override
public void onPlace(Room room) {
super.onPlace(room);
this.setExtradata(STATE_CHARGED);
}
@Override
public boolean canToggle(Habbo habbo, Room room) {
return room.hasRights(habbo) || RoomLayout.tilesAdjecent(
room.getLayout().getTile(this.getX(), this.getY()),
habbo.getRoomUnit().getCurrentLocation()
);
}
private void reCharge(Room room) {
// Default = 5000, Nuclear Firework should have 10000 in its custom params according to Habbo
int explodeDuration = 5000;
if (!this.getBaseItem().getCustomParams().isEmpty()) {
try {
explodeDuration = Integer.parseInt(this.getBaseItem().getCustomParams());
} catch (NumberFormatException e) {
LOGGER.error("Incorrect customparams (" + this.getBaseItem().getCustomParams() + ") for base item ID (" + this.getBaseItem().getId() + ") of type (" + this.getBaseItem().getName() + ")");
}
}
Emulator.getThreading().run(() -> {
this.setExtradata(STATE_CHARGED);
this.needsUpdate(true);
room.updateItemState(this);
}, explodeDuration);
} }
} }

View File

@ -383,6 +383,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
this.updateItem(item); this.updateItem(item);
} }
} }
for (HabboItem item : this.roomSpecialTypes.getItemsOfType(InteractionFireworks.class)) {
item.setExtradata("1");
this.updateItem(item);
}
} }
Emulator.getPluginManager().fireEvent(new RoomLoadedEvent(this)); Emulator.getPluginManager().fireEvent(new RoomLoadedEvent(this));
@ -2422,7 +2427,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
this.roomSpecialTypes.addUndefined(item); this.roomSpecialTypes.addUndefined(item);
} else if (item instanceof InteractionSnowboardSlope) { } else if (item instanceof InteractionSnowboardSlope) {
this.roomSpecialTypes.addUndefined(item); this.roomSpecialTypes.addUndefined(item);
} else if (item instanceof InteractionFireworks) {
this.roomSpecialTypes.addUndefined(item);
} }
} }
} }