RuneHive-Game
Loading...
Searching...
No Matches
FlowerPatch.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.farming.patches.impl;
2
3import com.runehive.content.skill.impl.farming.FarmingConstants;
4import com.runehive.content.skill.impl.farming.patches.WaterablePatch;
5import com.runehive.content.skill.impl.farming.plants.Flower;
6import com.runehive.content.skill.impl.farming.plants.Plant;
7import com.runehive.content.skill.impl.farming.zones.FarmingZone;
8import com.runehive.game.world.Interactable;
9import com.runehive.game.world.World;
10import com.runehive.game.world.entity.mob.player.Player;
11import com.runehive.game.world.items.Item;
12
13/**
14 * A {@link WaterablePatch} that can grow flowers and scarecrows for battling
15 * disease on an {@link AllotmentPatch}.
16 *
17 * @author Michael | Chex
18 */
19public class FlowerPatch extends WaterablePatch {
20
21 /** The scarecrow item id. */
22 public static final int SCARECROW = 6059;
23
24 /**
25 * Constructs a new {@link FlowerPatch} object.
26 *
27 * @param player the player that owns this patch
28 * @param zone the zone this patch belongs to
29 * @param boundaries the boundaries of this patch
30 */
34
35 /**
36 * Plants a scarecrow in this patch if the requirements are met.
37 *
38 * @param item the presumed scarecrow item id
39 * @param index the index of the item
40 * @return {@code true} if the scarecrow was successfully planted
41 */
42 private boolean plantScareCrow(int item, int index) {
43 if (player.locking.locked()) {
44 return false;
45 }
46
47 if (plant == null || item != SCARECROW) {
48 return false;
49 }
50
51 if (!isEmpty()) {
52 player.message("You need to clear the patch before planting a scarecrow.");
53 return false;
54 }
55
56 player.animate(832);
57 player.inventory.remove(new Item(SCARECROW), index, true);
58 player.locking.lock(2 * 3 / 5);
59
60 World.schedule(2, () -> {
61 player.message("You put a scarecrow on the flower patch, and some weeds start to grow around it.");
62 plant = plantForSeed(0x24);
63 timer.reset();
64 zone.sendPatchConfigs(player);
65 });
66 return true;
67 }
68
69 /**
70 * Checks if this flower patch protects an allotment patch from disease.
71 *
72 * @param protect the allotment patch's protect flower id
73 * @return {@code true} if this flower will protect the allotment from
74 * disease
75 */
76 public boolean protectsDisease(int protect) {
77 if (!isDead() && fullyGrown && plant.getSeedId() == protect) {
78 setDead();
79 return true;
80 }
81 return protect == SCARECROW && plant.getSeedId() >= 0x21 && plant.getSeedId() <= 0x24;
82 }
83
84 @Override
85 public Plant plantForSeed(int seedId) {
86 return Flower.forId(seedId);
87 }
88
89 @Override
90 public boolean itemOnObject(Item item, int index) {
91 return plantScareCrow(item.getId(), index) || super.itemOnObject(item, index);
92 }
93
94 @Override
95 protected int getMinAmount() {
96 return 1;
97 }
98
99 @Override
100 protected int getMaxAmount() {
101 return 1;
102 }
103
104 @Override
105 protected int animation() {
107 }
108
109}
WaterablePatch(Player player, FarmingZone zone, Interactable[] boundaries)
Constructs a new WaterablePatch object.
FlowerPatch(Player player, FarmingZone zone, Interactable[] boundaries)
Constructs a new FlowerPatch object.
boolean plantScareCrow(int item, int index)
Plants a scarecrow in this patch if the requirements are met.
boolean protectsDisease(int protect)
Checks if this flower patch protects an allotment patch from disease.
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.