68public abstract class Activity implements InteractionEventListener {
71 protected static final int START = 0;
74 protected static final int FINISH = -1;
77 protected static final int PAUSE = -2;
80 private final int cooldown;
93 this.instance = instance;
94 this.cooldown = cooldown;
97 public static <T extends Activity> Optional<T> search(
Player player, Class<T> clazz) {
98 final Activity activity = player.activity;
100 if (activity ==
null) {
101 return Optional.empty();
104 if (clazz.isInstance(activity)) {
105 return Optional.of(clazz.cast(activity));
108 return Optional.empty();
111 public static boolean evaluate(
Mob mob, Predicate<Activity> predicate) {
112 return mob !=
null && mob.activity !=
null && predicate.test(mob.activity);
115 public static void forActivity(
Mob mob, Consumer<Activity> consumer) {
120 if (mob.activity ==
null) {
124 consumer.accept(mob.activity);
127 public boolean canEquipItem(Player player, Item item, EquipmentType type) {
131 public boolean canEat(Player player, FoodData foodType) {
135 public boolean canUseSpecial(Player player) {
139 public boolean canUsePrayer(Player player) {
143 public boolean canDrinkPotions(Player player) {
147 public boolean canLogout(Player player) {
151 public boolean canSpellCast(Player player) {
159 if (ticks ==
PAUSE) {
165 }
else if (ticks ==
START) {
167 }
else if (ticks ==
FINISH) {
206 protected void restart(
int delay, Runnable runnable) {
210 public boolean onStep(
Mob mob) {
221 return Optional.ofNullable(panel);
236 if (mob.
isNpc() && !mob.isRegistered()) {
241 mob.setActivity(
this);
242 mob.instance = instance;
247 public void remove(
Mob mob) {
253 mob.instance =
Entity.DEFAULT_INSTANCE;
254 mob.getPlayer().setActivity(
null);
255 mob.getPlayer().graphic(
Graphic.RESET,
true);
256 mob.getPlayer().animate(
Animation.RESET,
true);
263 if (mobs.length != 0)
264 for (
Mob mob : mobs) {
265 if (mob.isRegistered())
282 this.ticks = cooldown;
297 return ticks ==
PAUSE;
309 public void setInstance(
int instance) {
310 this.instance = instance;
319 protected Optional<? extends ActivityListener<? extends Activity>>
getListener() {
320 return Optional.empty();
343 protected boolean pickupItem(Player player, PickupItemInteractionEvent event) {
347 protected boolean useItem(Player player, ItemOnObjectInteractionEvent event) {
351 protected boolean itemContainerAction(Player player, ItemContainerInteractionEvent event) {
356 public boolean onEvent(Player player, InteractionEvent interactionEvent) {
357 final EventDispatcher dispatcher =
new EventDispatcher(interactionEvent);
358 dispatcher.dispatch(InteractionEvent.InteractionType.CLICK_BUTTON, e -> clickButton(player, (ClickButtonInteractionEvent) e));
359 dispatcher.dispatch(InteractionEvent.InteractionType.ITEM_ON_ITEM, e -> useItem(player, (ItemOnItemInteractionEvent) e));
360 dispatcher.dispatch(InteractionEvent.InteractionType.ITEM_ON_OBJECT, e -> useItem(player, (ItemOnObjectInteractionEvent) e));
361 dispatcher.dispatch(InteractionEvent.InteractionType.FIRST_ITEM_CLICK, e -> clickItem(player, (FirstItemClickInteractionEvent) e));
362 dispatcher.dispatch(InteractionEvent.InteractionType.SECOND_ITEM_CLICK, e -> clickItem(player, (SecondItemClickInteractionEvent) e));
363 dispatcher.dispatch(InteractionEvent.InteractionType.THIRD_ITEM_CLICK, e -> clickItem(player, (ThirdItemClickInteractionEvent) e));
365 dispatcher.dispatch(InteractionEvent.InteractionType.FIRST_CLICK_NPC, e -> clickNpc(player, (FirstNpcClick) e));
366 dispatcher.dispatch(InteractionEvent.InteractionType.SECOND_CLICK_NPC, e -> clickNpc(player, (SecondNpcClick) e));
369 dispatcher.dispatch(InteractionEvent.InteractionType.FIRST_CLICK_OBJECT, e -> clickObject(player, (FirstObjectClick) e));
370 dispatcher.dispatch(InteractionEvent.InteractionType.SECOND_CLICK_OBJECT, e -> clickObject(player, (SecondObjectClick) e));
371 dispatcher.dispatch(InteractionEvent.InteractionType.THIRD_CLICK_OBJECT, e -> clickObject(player, (ThirdObjectClick) e));
372 dispatcher.dispatch(InteractionEvent.InteractionType.PICKUP_ITEM, e -> pickupItem(player, (PickupItemInteractionEvent) e));
373 dispatcher.dispatch(InteractionEvent.InteractionType.ITEM_CONTAINER_INTERACTION_EVENT, e -> itemContainerAction(player, (ItemContainerInteractionEvent) e));
374 return interactionEvent.isHandled();
Optional<? extends ActivityListener<? extends Activity > > getListener()
Activity(int cooldown, int instance)