mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-02-18 19:32:36 +01:00
Fix vending machine behaviour
This commit is contained in:
parent
fe6679c109
commit
0e53d703b3
@ -4,6 +4,7 @@ import com.eu.habbo.Emulator;
|
|||||||
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.*;
|
import com.eu.habbo.habbohotel.rooms.*;
|
||||||
|
import com.eu.habbo.habbohotel.users.Habbo;
|
||||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||||
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer;
|
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer;
|
||||||
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
|
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
|
||||||
@ -16,7 +17,7 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class InteractionEffectVendingMachine extends InteractionDefault {
|
public class InteractionEffectVendingMachine extends InteractionVendingMachine {
|
||||||
public InteractionEffectVendingMachine(ResultSet set, Item baseItem) throws SQLException {
|
public InteractionEffectVendingMachine(ResultSet set, Item baseItem) throws SQLException {
|
||||||
super(set, baseItem);
|
super(set, baseItem);
|
||||||
this.setExtradata("0");
|
this.setExtradata("0");
|
||||||
@ -28,58 +29,7 @@ public class InteractionEffectVendingMachine extends InteractionDefault {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
|
public void giveVendingMachineItem(Habbo habbo, Room room) {
|
||||||
super.onClick(client, room, objects);
|
room.giveEffect(habbo.getRoomUnit(), this.getBaseItem().getRandomVendingItem(), 30);
|
||||||
|
|
||||||
if (client != null) {
|
|
||||||
RoomTile tile = getSquareInFront(room.getLayout(), this);
|
|
||||||
|
|
||||||
if (tile != null) {
|
|
||||||
if (tile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) {
|
|
||||||
if (this.getExtradata().equals("0") || this.getExtradata().length() == 0) {
|
|
||||||
room.updateHabbo(client.getHabbo());
|
|
||||||
if (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.SIT)) {
|
|
||||||
client.getHabbo().getRoomUnit().setRotation(RoomUserRotation.values()[Rotation.Calculate(client.getHabbo().getRoomUnit().getX(), client.getHabbo().getRoomUnit().getY(), this.getX(), this.getY())]);
|
|
||||||
client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE);
|
|
||||||
room.scheduledComposers.add(new RoomUserStatusComposer(client.getHabbo().getRoomUnit()).compose());
|
|
||||||
}
|
|
||||||
this.setExtradata("1");
|
|
||||||
room.scheduledComposers.add(new FloorItemUpdateComposer(this).compose());
|
|
||||||
Emulator.getThreading().run(this, 1000);
|
|
||||||
HabboItem instance = this;
|
|
||||||
Emulator.getThreading().run(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
room.giveEffect(client.getHabbo().getRoomUnit(), instance.getBaseItem().getRandomVendingItem(), 30);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!tile.isWalkable() && tile.state != RoomTileState.SIT && tile.state != RoomTileState.LAY) {
|
|
||||||
for (RoomTile t : room.getLayout().getTilesAround(room.getLayout().getTile(this.getX(), this.getY()))) {
|
|
||||||
if (t != null && t.isWalkable()) {
|
|
||||||
tile = t;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Runnable> onSuccess = new ArrayList<>();
|
|
||||||
List<Runnable> onFail = new ArrayList<>();
|
|
||||||
|
|
||||||
onSuccess.add(() -> Emulator.getThreading().run(() -> {
|
|
||||||
try {
|
|
||||||
this.onClick(client, room, objects);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}, 500));
|
|
||||||
|
|
||||||
client.getHabbo().getRoomUnit().setGoalLocation(tile);
|
|
||||||
Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), tile, room, onSuccess, onFail));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,13 +4,13 @@ import com.eu.habbo.Emulator;
|
|||||||
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.*;
|
import com.eu.habbo.habbohotel.rooms.*;
|
||||||
|
import com.eu.habbo.habbohotel.users.Habbo;
|
||||||
import com.eu.habbo.habbohotel.users.HabboGender;
|
import com.eu.habbo.habbohotel.users.HabboGender;
|
||||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||||
import com.eu.habbo.messages.ServerMessage;
|
import com.eu.habbo.messages.ServerMessage;
|
||||||
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer;
|
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer;
|
||||||
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
|
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
|
||||||
import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem;
|
import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem;
|
||||||
import com.eu.habbo.threading.runnables.RoomUnitVendingMachineAction;
|
|
||||||
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
|
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
|
||||||
import com.eu.habbo.util.pathfinding.Rotation;
|
import com.eu.habbo.util.pathfinding.Rotation;
|
||||||
|
|
||||||
@ -18,6 +18,7 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
public class InteractionVendingMachine extends HabboItem {
|
public class InteractionVendingMachine extends HabboItem {
|
||||||
public InteractionVendingMachine(ResultSet set, Item baseItem) throws SQLException {
|
public InteractionVendingMachine(ResultSet set, Item baseItem) throws SQLException {
|
||||||
@ -52,21 +53,25 @@ public class InteractionVendingMachine extends HabboItem {
|
|||||||
if (this.getExtradata().equals("0") || this.getExtradata().length() == 0) {
|
if (this.getExtradata().equals("0") || this.getExtradata().length() == 0) {
|
||||||
if (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.SIT) && (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || tile.equals(client.getHabbo().getRoomUnit().getGoal()))) {
|
if (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.SIT) && (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || tile.equals(client.getHabbo().getRoomUnit().getGoal()))) {
|
||||||
room.updateHabbo(client.getHabbo());
|
room.updateHabbo(client.getHabbo());
|
||||||
client.getHabbo().getRoomUnit().setRotation(RoomUserRotation.values()[Rotation.Calculate(client.getHabbo().getRoomUnit().getX(), client.getHabbo().getRoomUnit().getY(), this.getX(), this.getY())]);
|
this.rotateToMachine(client.getHabbo().getRoomUnit());
|
||||||
client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE);
|
client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE);
|
||||||
room.scheduledComposers.add(new RoomUserStatusComposer(client.getHabbo().getRoomUnit()).compose());
|
room.scheduledComposers.add(new RoomUserStatusComposer(client.getHabbo().getRoomUnit()).compose());
|
||||||
}
|
}
|
||||||
this.setExtradata("1");
|
|
||||||
room.scheduledComposers.add(new FloorItemUpdateComposer(this).compose());
|
|
||||||
Emulator.getThreading().run(this, 1000);
|
|
||||||
Emulator.getThreading().run(new RoomUnitGiveHanditem(client.getHabbo().getRoomUnit(), room, this.getBaseItem().getRandomVendingItem()));
|
|
||||||
|
|
||||||
if (this.getBaseItem().getEffectM() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.M)
|
|
||||||
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectM(), -1);
|
|
||||||
if (this.getBaseItem().getEffectF() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.F)
|
|
||||||
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectF(), -1);
|
|
||||||
|
|
||||||
super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"});
|
super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"});
|
||||||
|
|
||||||
|
this.setExtradata("1");
|
||||||
|
room.scheduledComposers.add(new FloorItemUpdateComposer(this).compose());
|
||||||
|
|
||||||
|
Emulator.getThreading().run(() -> {
|
||||||
|
Emulator.getThreading().run(this, 1000);
|
||||||
|
this.giveVendingMachineItem(client.getHabbo(), room);
|
||||||
|
|
||||||
|
if (this.getBaseItem().getEffectM() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.M)
|
||||||
|
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectM(), -1);
|
||||||
|
if (this.getBaseItem().getEffectF() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.F)
|
||||||
|
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectF(), -1);
|
||||||
|
}, 500);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!tile.isWalkable() && tile.state != RoomTileState.SIT && tile.state != RoomTileState.LAY) {
|
if (!tile.isWalkable() && tile.state != RoomTileState.SIT && tile.state != RoomTileState.LAY) {
|
||||||
@ -81,13 +86,42 @@ public class InteractionVendingMachine extends HabboItem {
|
|||||||
List<Runnable> onSuccess = new ArrayList<>();
|
List<Runnable> onSuccess = new ArrayList<>();
|
||||||
List<Runnable> onFail = new ArrayList<>();
|
List<Runnable> onFail = new ArrayList<>();
|
||||||
|
|
||||||
onSuccess.add(() -> Emulator.getThreading().run(() -> {
|
RoomTile finalTile = tile;
|
||||||
|
onSuccess.add(() -> {
|
||||||
|
this.setExtradata("1");
|
||||||
|
room.scheduledComposers.add(new FloorItemUpdateComposer(this).compose());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.onClick(client, room, objects);
|
super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}, 500));
|
|
||||||
|
Emulator.getThreading().run(() -> {
|
||||||
|
Runnable procedure = () -> {
|
||||||
|
if (client.getHabbo().getRoomUnit().getCurrentLocation().equals(finalTile)) {
|
||||||
|
this.rotateToMachine(client.getHabbo().getRoomUnit());
|
||||||
|
room.sendComposer(new RoomUserStatusComposer(client.getHabbo().getRoomUnit()).compose());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Emulator.getThreading().run(() -> {
|
||||||
|
Emulator.getThreading().run(this, 1000);
|
||||||
|
this.giveVendingMachineItem(client.getHabbo(), room);
|
||||||
|
|
||||||
|
if (this.getBaseItem().getEffectM() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.M)
|
||||||
|
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectM(), -1);
|
||||||
|
if (this.getBaseItem().getEffectF() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.F)
|
||||||
|
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectF(), -1);
|
||||||
|
}, 500).get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
client.getHabbo().getRoomUnit().setMoveBlockingTask(Emulator.getThreading().run(procedure, 300));
|
||||||
|
}, 250);
|
||||||
|
});
|
||||||
|
|
||||||
client.getHabbo().getRoomUnit().setGoalLocation(tile);
|
client.getHabbo().getRoomUnit().setGoalLocation(tile);
|
||||||
Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), tile, room, onSuccess, onFail));
|
Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), tile, room, onSuccess, onFail));
|
||||||
@ -136,4 +170,41 @@ public class InteractionVendingMachine extends HabboItem {
|
|||||||
public boolean isUsable() {
|
public boolean isUsable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void rotateToMachine(RoomUnit unit) {
|
||||||
|
RoomUserRotation rotation = RoomUserRotation.values()[Rotation.Calculate(unit.getX(), unit.getY(), this.getX(), this.getY())];
|
||||||
|
boolean onlyHead = false;
|
||||||
|
|
||||||
|
switch (unit.getBodyRotation()) {
|
||||||
|
case NORTH_EAST:
|
||||||
|
if (rotation.equals(RoomUserRotation.NORTH) || rotation.equals(RoomUserRotation.EAST))
|
||||||
|
onlyHead = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NORTH_WEST:
|
||||||
|
if (rotation.equals(RoomUserRotation.NORTH) || rotation.equals(RoomUserRotation.WEST))
|
||||||
|
onlyHead = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SOUTH_EAST:
|
||||||
|
if (rotation.equals(RoomUserRotation.SOUTH) || rotation.equals(RoomUserRotation.EAST))
|
||||||
|
onlyHead = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SOUTH_WEST:
|
||||||
|
if (rotation.equals(RoomUserRotation.SOUTH) || rotation.equals(RoomUserRotation.WEST))
|
||||||
|
onlyHead = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onlyHead) {
|
||||||
|
unit.setHeadRotation(rotation);
|
||||||
|
} else {
|
||||||
|
unit.setRotation(rotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void giveVendingMachineItem(Habbo habbo, Room room) {
|
||||||
|
Emulator.getThreading().run(new RoomUnitGiveHanditem(habbo.getRoomUnit(), room, this.getBaseItem().getRandomVendingItem()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import gnu.trove.set.hash.THashSet;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
public class RoomUnit {
|
public class RoomUnit {
|
||||||
private final ConcurrentHashMap<RoomUnitStatus, String> status;
|
private final ConcurrentHashMap<RoomUnitStatus, String> status;
|
||||||
@ -65,6 +66,7 @@ public class RoomUnit {
|
|||||||
private int walkTimeOut;
|
private int walkTimeOut;
|
||||||
private int effectId;
|
private int effectId;
|
||||||
private int effectEndTimestamp;
|
private int effectEndTimestamp;
|
||||||
|
private ScheduledFuture moveBlockingTask;
|
||||||
|
|
||||||
private int idleTimer;
|
private int idleTimer;
|
||||||
private Room room;
|
private Room room;
|
||||||
@ -768,4 +770,12 @@ public class RoomUnit {
|
|||||||
.filter(t -> t != null && t.isWalkable() && !room.hasHabbosAt(t.x, t.y))
|
.filter(t -> t != null && t.isWalkable() && !room.hasHabbosAt(t.x, t.y))
|
||||||
.min(Comparator.comparingDouble(a -> a.distance(this.getCurrentLocation()))).orElse(null);
|
.min(Comparator.comparingDouble(a -> a.distance(this.getCurrentLocation()))).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ScheduledFuture getMoveBlockingTask() {
|
||||||
|
return moveBlockingTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMoveBlockingTask(ScheduledFuture moveBlockingTask) {
|
||||||
|
this.moveBlockingTask = moveBlockingTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,9 @@ public class RoomUserWalkEvent extends MessageHandler {
|
|||||||
|
|
||||||
// This is where we set the end location and begin finding a path
|
// This is where we set the end location and begin finding a path
|
||||||
if (tile.isWalkable() || room.canSitOrLayAt(tile.x, tile.y)) {
|
if (tile.isWalkable() || room.canSitOrLayAt(tile.x, tile.y)) {
|
||||||
|
if (roomUnit.getMoveBlockingTask() != null) roomUnit.getMoveBlockingTask().get();
|
||||||
|
System.out.println(roomUnit.getMoveBlockingTask());
|
||||||
|
|
||||||
roomUnit.setGoalLocation(tile);
|
roomUnit.setGoalLocation(tile);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -29,17 +29,17 @@ public class RoomUnitWalkToLocation implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.walker.getGoal().equals(this.goalTile)) {
|
|
||||||
onFail();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.walker.getCurrentLocation().equals(this.goalTile)) {
|
if (this.walker.getCurrentLocation().equals(this.goalTile)) {
|
||||||
onSuccess();
|
onSuccess();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Emulator.getThreading().run(this, 500);
|
if (!this.walker.getGoal().equals(this.goalTile)) {
|
||||||
|
onFail();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Emulator.getThreading().run(this, 250);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSuccess() {
|
private void onSuccess() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user