RuneHive-Game
Loading...
Searching...
No Matches
WaterablePatch.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.farming.patches;
2
3import com.runehive.content.skill.impl.farming.FarmingConstants;
4import com.runehive.content.skill.impl.farming.zones.FarmingZone;
5import com.runehive.game.world.Interactable;
6import com.runehive.game.world.World;
7import com.runehive.game.world.entity.mob.player.Player;
8import com.runehive.game.world.items.Item;
9
10/**
11 * A {@link DiseasablePatch} that can prevent disease with water.
12 *
13 * @author Michael | Chex
14 */
15public abstract class WaterablePatch extends DiseasablePatch {
16
17 /**
18 * Constructs a new {@link WaterablePatch} object.
19 *
20 * @param player the player that owns this patch
21 * @param zone the zone this patch belongs in
22 * @param boundaries the boundaries of this patch
23 */
27
28 /**
29 * Waters this patch to prevent disease if requirements are met.
30 *
31 * @param itemId the presumed watering can item id
32 * @param index the inventory index of the item
33 * @return {@code true} if this patch was successfully watered
34 */
35 private boolean waterPatch(int itemId, int index) {
36 if (player.locking.locked()) {
37 return false;
38 }
39
40 if (itemId != 5331 && (itemId < 5333 || itemId > 5340)) {
41 return false;
42 }
43
44 if (!isGrowing()) {
45 player.message("This patch needs to be growing something first.");
46 return true;
47 }
48
49 if (isWatered() || fullyGrown) {
50 player.message("This patch doesn't need watering.");
51 return true;
52 }
53
54 if (itemId == 5331) {
55 player.dialogueFactory.sendStatement("This watering can is empty.").execute();
56 return true;
57 }
58
59 player.message("You water the patch.");
61 player.inventory.replace(itemId, itemId == 5333 ? itemId - 2 : itemId - 1, index, true);
62 player.locking.lock(5 * 3 / 5);
63 setWatered();
64
65 World.schedule(5, () -> {
66 player.resetAnimation();
67 zone.sendPatchConfigs(player);
68 });
69 return true;
70 }
71
72 @Override
73 public boolean itemOnObject(Item item, int index) {
74 return waterPatch(item.getId(), index) || super.itemOnObject(item, index);
75 }
76
77/*
78 @Override
79 public boolean rollDisease() {
80 return !isWatered() && super.rollDisease();
81 }
82*/
83
84 @Override
85 protected void onGrowth() {
86 super.onGrowth();
87 if (isWatered()) {
88 setNormal();
89 }
90 }
91
92}
DiseasablePatch(Player player, FarmingZone zone, Interactable[] boundaries)
boolean waterPatch(int itemId, int index)
Waters this patch to prevent disease if requirements are met.
WaterablePatch(Player player, FarmingZone zone, Interactable[] boundaries)
Constructs a new WaterablePatch object.
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21
final int getId()
Gets the identification of this item.
Definition Item.java:324
An object implementing Interactable has uses.