Merge branch 'fix-usage-policy' into 'ms4/dev'

Add extra usage policy + new logic found for switches which can be activated...

See merge request morningstar/Arcturus-Community!61
This commit is contained in:
John 2023-02-08 01:30:02 +00:00
commit b4e14cce35
4 changed files with 67 additions and 6 deletions

View File

@ -172,6 +172,7 @@ public class ItemManager {
this.interactionsList.add(new ItemInteraction("youtube", InteractionYoutubeTV.class));
this.interactionsList.add(new ItemInteraction("jukebox", InteractionJukeBox.class));
this.interactionsList.add(new ItemInteraction("switch", InteractionSwitch.class));
this.interactionsList.add(new ItemInteraction("switch_remote_control", InteractionSwitchRemoteControl.class));
this.interactionsList.add(new ItemInteraction("fx_box", InteractionFXBox.class));
this.interactionsList.add(new ItemInteraction("blackhole", InteractionBlackHole.class));
this.interactionsList.add(new ItemInteraction("effect_toggle", InteractionEffectToggle.class));

View File

@ -0,0 +1,62 @@
package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomLayout;
import com.eu.habbo.habbohotel.users.Habbo;
import lombok.extern.slf4j.Slf4j;
import java.sql.ResultSet;
import java.sql.SQLException;
@Slf4j
public class InteractionSwitchRemoteControl extends InteractionDefault {
public InteractionSwitchRemoteControl(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
public InteractionSwitchRemoteControl(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean canToggle(Habbo habbo, Room room) {
return RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getX(), this.getY()), habbo.getRoomUnit().getCurrentLocation());
}
@Override
public boolean allowWiredResetState() {
return true;
}
@Override
public boolean isUsable() {
return true;
}
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
if (room != null) {
super.onClick(client, room, objects);
if (this.getExtradata().length() == 0)
this.setExtradata("0");
if (this.getBaseItem().getStateCount() > 0) {
int currentState = 0;
try {
currentState = Integer.parseInt(this.getExtradata());
} catch (NumberFormatException e) {
log.error("Incorrect extradata (" + this.getExtradata() + ") for item ID (" + this.getId() + ") of type (" + this.getBaseItem().getName() + ")");
}
this.setExtradata("" + (currentState + 1) % this.getBaseItem().getStateCount());
this.needsUpdate(true);
room.updateItemState(this);
}
}
}
}

View File

@ -1,7 +1,6 @@
package com.eu.habbo.messages.outgoing.rooms.items;
import com.eu.habbo.habbohotel.items.interactions.InteractionGift;
import com.eu.habbo.habbohotel.items.interactions.InteractionMusicDisc;
import com.eu.habbo.habbohotel.items.interactions.*;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
@ -21,7 +20,7 @@ public class ObjectAddMessageComposer extends MessageComposer {
this.response.appendInt(this.item instanceof InteractionGift ? ((((InteractionGift) this.item).getColorId() * 1000) + ((InteractionGift) this.item).getRibbonId()) : (this.item instanceof InteractionMusicDisc ? ((InteractionMusicDisc) this.item).getSongId() : 1));
this.item.serializeExtradata(this.response);
this.response.appendInt(-1);
this.response.appendInt(this.item.isUsable());
this.response.appendInt(this.item instanceof InteractionTeleport || this.item instanceof InteractionSwitch || this.item instanceof InteractionSwitchRemoteControl || this.item instanceof InteractionVendingMachine || this.item instanceof InteractionInformationTerminal || this.item instanceof InteractionPostIt || this.item instanceof InteractionSpinningBottle || this.item instanceof InteractionPuzzleBox ? 2 : this.item.isUsable() ? 1 : 0);
this.response.appendInt(this.item.getUserId());
this.response.appendString(this.itemOwnerName);
return this.response;

View File

@ -1,7 +1,6 @@
package com.eu.habbo.messages.outgoing.rooms.items;
import com.eu.habbo.habbohotel.items.interactions.InteractionGift;
import com.eu.habbo.habbohotel.items.interactions.InteractionMusicDisc;
import com.eu.habbo.habbohotel.items.interactions.*;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
@ -43,7 +42,7 @@ public class ObjectsMessageComposer extends MessageComposer {
this.response.appendInt(item instanceof InteractionGift ? ((((InteractionGift) item).getColorId() * 1000) + ((InteractionGift) item).getRibbonId()) : (item instanceof InteractionMusicDisc ? ((InteractionMusicDisc) item).getSongId() : 1));
item.serializeExtradata(this.response);
this.response.appendInt(-1);
this.response.appendInt(item.isUsable() ? 1 : 0);
this.response.appendInt(item instanceof InteractionTeleport || item instanceof InteractionSwitch || item instanceof InteractionSwitchRemoteControl || item instanceof InteractionVendingMachine || item instanceof InteractionInformationTerminal || item instanceof InteractionPostIt || item instanceof InteractionSpinningBottle || item instanceof InteractionPuzzleBox ? 2 : item.isUsable() ? 1 : 0);
this.response.appendInt(item.getUserId());
}
return this.response;