Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java

162 lines
5.8 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
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.rooms.*;
import com.eu.habbo.threading.runnables.KickBallAction;
import java.sql.ResultSet;
import java.sql.SQLException;
2018-10-07 00:28:00 +02:00
public abstract class InteractionPushable extends InteractionDefault {
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
private KickBallAction currentThread;
2018-10-07 00:28:00 +02:00
2019-05-26 20:14:53 +02:00
public InteractionPushable(ResultSet set, Item baseItem) throws SQLException {
2018-07-06 15:30:00 +02:00
super(set, baseItem);
this.setExtradata("0");
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public InteractionPushable(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
2018-07-06 15:30:00 +02:00
super(id, userId, item, extradata, limitedStack, limitedSells);
this.setExtradata("0");
2018-07-06 15:30:00 +02:00
}
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
@Override
2019-05-26 20:14:53 +02:00
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
2018-07-06 15:30:00 +02:00
return true;
}
@Override
2019-05-26 20:14:53 +02:00
public boolean isWalkable() {
2018-07-06 15:30:00 +02:00
return true;
}
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
@Override
2019-05-26 20:14:53 +02:00
public void onWalkOff(RoomUnit roomUnit, final Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
super.onWalkOff(roomUnit, room, objects);
2018-10-07 00:28:00 +02:00
2019-05-26 20:14:53 +02:00
if (!(this.currentThread == null || this.currentThread.dead))
2018-07-06 15:30:00 +02:00
return;
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
int velocity = this.getWalkOffVelocity(roomUnit, room);
RoomUserRotation direction = this.getWalkOffDirection(roomUnit, room);
this.onKick(room, roomUnit, velocity, direction);
2018-10-07 00:28:00 +02:00
2019-05-26 20:14:53 +02:00
if (velocity > 0) {
if (this.currentThread != null)
2019-03-18 02:22:00 +01:00
this.currentThread.dead = true;
2018-10-07 00:28:00 +02:00
2020-09-13 07:25:05 +02:00
this.currentThread = new KickBallAction(this, room, roomUnit, direction, velocity, false);
2019-03-18 02:22:00 +01:00
Emulator.getThreading().run(this.currentThread, 0);
2018-07-06 15:30:00 +02:00
}
}
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
@Override
2019-05-26 20:14:53 +02:00
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
super.onClick(client, room, objects);
2018-10-07 00:28:00 +02:00
2019-04-22 01:42:00 +02:00
if (client == null) return;
2019-05-26 20:14:53 +02:00
if (RoomLayout.tilesAdjecent(client.getHabbo().getRoomUnit().getCurrentLocation(), room.getLayout().getTile(this.getX(), this.getY()))) {
2018-07-06 15:30:00 +02:00
int velocity = this.getTackleVelocity(client.getHabbo().getRoomUnit(), room);
RoomUserRotation direction = this.getWalkOnDirection(client.getHabbo().getRoomUnit(), room);
this.onTackle(room, client.getHabbo().getRoomUnit(), velocity, direction);
2018-10-07 00:28:00 +02:00
2019-05-26 20:14:53 +02:00
if (velocity > 0) {
if (this.currentThread != null)
2019-03-18 02:22:00 +01:00
this.currentThread.dead = true;
2018-10-07 00:28:00 +02:00
2020-09-13 07:25:05 +02:00
this.currentThread = new KickBallAction(this, room, client.getHabbo().getRoomUnit(), direction, velocity, false);
2019-03-18 02:22:00 +01:00
Emulator.getThreading().run(this.currentThread, 0);
2018-07-06 15:30:00 +02:00
}
}
}
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
@Override
2019-05-26 20:14:53 +02:00
public void onWalkOn(RoomUnit roomUnit, final Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
super.onWalkOn(roomUnit, room, objects);
2018-10-07 00:28:00 +02:00
2018-07-06 15:30:00 +02:00
int velocity;
2020-09-13 07:25:05 +02:00
boolean isDrag = false;
2018-07-06 15:30:00 +02:00
RoomUserRotation direction;
2018-10-07 00:28:00 +02:00
2019-05-26 20:14:53 +02:00
if (this.getX() == roomUnit.getGoal().x && this.getY() == roomUnit.getGoal().y) //User clicked on the tile the ball is on, they want to kick it
2018-07-06 15:30:00 +02:00
{
velocity = this.getWalkOnVelocity(roomUnit, room);
direction = this.getWalkOnDirection(roomUnit, room);
this.onKick(room, roomUnit, velocity, direction);
2019-05-26 20:14:53 +02:00
} else //User is walking past the ball, they want to drag it with them
2018-07-06 15:30:00 +02:00
{
velocity = this.getDragVelocity(roomUnit, room);
direction = this.getDragDirection(roomUnit, room);
this.onDrag(room, roomUnit, velocity, direction);
2020-09-13 07:25:05 +02:00
isDrag = true;
2018-07-06 15:30:00 +02:00
}
2018-10-07 00:28:00 +02:00
2019-05-26 20:14:53 +02:00
if (velocity > 0) {
if (this.currentThread != null)
2019-03-18 02:22:00 +01:00
this.currentThread.dead = true;
2018-10-07 00:28:00 +02:00
2020-09-13 07:25:05 +02:00
this.currentThread = new KickBallAction(this, room, roomUnit, direction, velocity, isDrag);
2019-03-18 02:22:00 +01:00
Emulator.getThreading().run(this.currentThread, 0);
2018-07-06 15:30:00 +02:00
}
}
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract int getWalkOnVelocity(RoomUnit roomUnit, Room room);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract RoomUserRotation getWalkOnDirection(RoomUnit roomUnit, Room room);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract int getWalkOffVelocity(RoomUnit roomUnit, Room room);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract RoomUserRotation getWalkOffDirection(RoomUnit roomUnit, Room room);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract int getDragVelocity(RoomUnit roomUnit, Room room);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract RoomUserRotation getDragDirection(RoomUnit roomUnit, Room room);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract int getTackleVelocity(RoomUnit roomUnit, Room room);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract RoomUserRotation getTackleDirection(RoomUnit roomUnit, Room room);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract int getNextRollDelay(int currentStep, int totalSteps); //The length in milliseconds when the ball should next roll
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract RoomUserRotation getBounceDirection(Room room, RoomUserRotation currentDirection); //Returns the new direction to move the ball when the ball cannot move
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract boolean validMove(Room room, RoomTile from, RoomTile to); //Checks if the next move is valid
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract void onDrag(Room room, RoomUnit roomUnit, int velocity, RoomUserRotation direction);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract void onKick(Room room, RoomUnit roomUnit, int velocity, RoomUserRotation direction);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract void onTackle(Room room, RoomUnit roomUnit, int velocity, RoomUserRotation direction);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract void onMove(Room room, RoomTile from, RoomTile to, RoomUserRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract void onBounce(Room room, RoomUserRotation oldDirection, RoomUserRotation newDirection, RoomUnit kicker);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract void onStop(Room room, RoomUnit kicker, int currentStep, int totalSteps);
2018-10-07 00:28:00 +02:00
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public abstract boolean canStillMove(Room room, RoomTile from, RoomTile to, RoomUserRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps);
2018-10-07 00:28:00 +02:00
}