mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-27 08:50:51 +01:00
Add random state furni (fixes #305)
This commit is contained in:
parent
f2966b837c
commit
72adc5325d
@ -177,6 +177,7 @@ public class ItemManager {
|
|||||||
this.interactionsList.add(new ItemInteraction("pressureplate_group", InteractionGroupPressurePlate.class));
|
this.interactionsList.add(new ItemInteraction("pressureplate_group", InteractionGroupPressurePlate.class));
|
||||||
this.interactionsList.add(new ItemInteraction("effect_tile_group", InteractionEffectTile.class));
|
this.interactionsList.add(new ItemInteraction("effect_tile_group", InteractionEffectTile.class));
|
||||||
this.interactionsList.add(new ItemInteraction("crackable_subscription_box", InteractionRedeemableSubscriptionBox.class));
|
this.interactionsList.add(new ItemInteraction("crackable_subscription_box", InteractionRedeemableSubscriptionBox.class));
|
||||||
|
this.interactionsList.add(new ItemInteraction("random_state", InteractionRandomState.class));
|
||||||
|
|
||||||
this.interactionsList.add(new ItemInteraction("game_timer", InteractionGameTimer.class));
|
this.interactionsList.add(new ItemInteraction("game_timer", InteractionGameTimer.class));
|
||||||
|
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.eu.habbo.habbohotel.items;
|
||||||
|
|
||||||
|
import com.eu.habbo.Emulator;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class RandomStateParams {
|
||||||
|
private int states = -1;
|
||||||
|
private int delay = -1;
|
||||||
|
|
||||||
|
public RandomStateParams(String customparams) throws Exception {
|
||||||
|
Arrays.stream(customparams.split(",")).forEach(pair -> {
|
||||||
|
String[] keyValue = pair.split("=");
|
||||||
|
|
||||||
|
if (keyValue.length != 2) return;
|
||||||
|
|
||||||
|
switch (keyValue[0]) {
|
||||||
|
case "states":
|
||||||
|
this.states = Integer.parseInt(keyValue[1]);
|
||||||
|
break;
|
||||||
|
case "delay":
|
||||||
|
this.delay = Integer.parseInt(keyValue[1]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Emulator.getLogging().logDebugLine("RandomStateParams: unknown key: " + keyValue[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.states < 0) throw new Exception("RandomStateParams: states not defined");
|
||||||
|
if (this.delay < 0) throw new Exception("RandomStateParams: states not defined");
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStates() {
|
||||||
|
return states;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDelay() {
|
||||||
|
return delay;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
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.RandomStateParams;
|
||||||
|
import com.eu.habbo.habbohotel.rooms.Room;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class InteractionRandomState extends InteractionDefault {
|
||||||
|
public InteractionRandomState(ResultSet set, Item baseItem) throws SQLException {
|
||||||
|
super(set, baseItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InteractionRandomState(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
|
||||||
|
super(id, userId, item, extradata, limitedStack, limitedSells);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlace(Room room) {
|
||||||
|
super.onPlace(room);
|
||||||
|
|
||||||
|
this.setExtradata("");
|
||||||
|
room.updateItemState(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onRandomStateClick(GameClient client, Room room) throws Exception {
|
||||||
|
RandomStateParams params = new RandomStateParams(this.getBaseItem().getCustomParams());
|
||||||
|
|
||||||
|
this.setExtradata("");
|
||||||
|
room.updateItemState(this);
|
||||||
|
|
||||||
|
int randomState = Emulator.getRandom().nextInt(params.getStates()) + 1;
|
||||||
|
|
||||||
|
Emulator.getThreading().run(() -> {
|
||||||
|
this.setExtradata(randomState + "");
|
||||||
|
room.updateItemState(this);
|
||||||
|
}, params.getDelay());
|
||||||
|
}
|
||||||
|
}
|
@ -440,6 +440,7 @@ public class PacketManager {
|
|||||||
this.registerHandler(Incoming.RoomFavoriteEvent, RoomFavoriteEvent.class);
|
this.registerHandler(Incoming.RoomFavoriteEvent, RoomFavoriteEvent.class);
|
||||||
this.registerHandler(Incoming.LoveLockStartConfirmEvent, LoveLockStartConfirmEvent.class);
|
this.registerHandler(Incoming.LoveLockStartConfirmEvent, LoveLockStartConfirmEvent.class);
|
||||||
this.registerHandler(Incoming.RoomUnFavoriteEvent, RoomUnFavoriteEvent.class);
|
this.registerHandler(Incoming.RoomUnFavoriteEvent, RoomUnFavoriteEvent.class);
|
||||||
|
this.registerHandler(Incoming.UseRandomStateItemEvent, UseRandomStateItemEvent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerPolls() throws Exception {
|
void registerPolls() throws Exception {
|
||||||
|
@ -216,6 +216,7 @@ public class Incoming {
|
|||||||
public static final int PostItRequestDataEvent = 3964;
|
public static final int PostItRequestDataEvent = 3964;
|
||||||
public static final int PostItSaveDataEvent = 3666;
|
public static final int PostItSaveDataEvent = 3666;
|
||||||
public static final int PostItDeleteEvent = 3336;
|
public static final int PostItDeleteEvent = 3336;
|
||||||
|
public static final int UseRandomStateItemEvent = 3617;
|
||||||
|
|
||||||
public static final int MySanctionStatusEvent = 2746;
|
public static final int MySanctionStatusEvent = 2746;
|
||||||
|
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.eu.habbo.messages.incoming.rooms.items;
|
||||||
|
|
||||||
|
import com.eu.habbo.Emulator;
|
||||||
|
import com.eu.habbo.habbohotel.items.interactions.InteractionRandomState;
|
||||||
|
import com.eu.habbo.habbohotel.rooms.Room;
|
||||||
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||||
|
import com.eu.habbo.messages.incoming.MessageHandler;
|
||||||
|
|
||||||
|
public class UseRandomStateItemEvent extends MessageHandler {
|
||||||
|
@Override
|
||||||
|
public void handle() throws Exception {
|
||||||
|
try {
|
||||||
|
int itemId = this.packet.readInt();
|
||||||
|
int state = this.packet.readInt();
|
||||||
|
|
||||||
|
Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom();
|
||||||
|
|
||||||
|
HabboItem item = room.getHabboItem(itemId);
|
||||||
|
|
||||||
|
if (item == null || !(item instanceof InteractionRandomState))
|
||||||
|
return;
|
||||||
|
|
||||||
|
InteractionRandomState randomStateItem = (InteractionRandomState)item;
|
||||||
|
randomStateItem.onRandomStateClick(this.client, room);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Emulator.getLogging().logErrorLine(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user