RuneHive-Game
Loading...
Searching...
No Matches
DiseasablePatch.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.farming.patches;
2
3import com.google.gson.JsonObject;
4import com.runehive.content.skill.impl.farming.FarmingConstants;
5import com.runehive.content.skill.impl.farming.zones.FarmingZone;
6import com.runehive.game.world.Interactable;
7import com.runehive.game.world.World;
8import com.runehive.game.world.entity.mob.player.Player;
9import com.runehive.game.world.items.Item;
10
11public abstract class DiseasablePatch extends HarvestablePatch {
12 protected boolean watched;
13
17
18 @Override
19 protected void onGrowth() {
20 if (isDead()) {
21 return;
22 }
23
24 /* if (isDiseased()) {
25 setDead();
26 } else if (!fullyGrown) {
27 handleDisease();
28 }*/
29 }
30
31 protected void resetPatch() {
32 super.resetPatch();
33 watched = false;
34 }
35
36 public boolean clickObject(int opcode) {
37 if (opcode == 1 && isDiseased()) {
38 curePlant(-1);
39 return true;
40 }
41 return super.clickObject(opcode);
42 }
43
44 public boolean itemOnObject(Item item, int index) {
46 curePlant(index);
47 return true;
48 }
49 return super.itemOnObject(item, index);
50 }
51
52 /* public boolean rollDisease() {
53 return growth > 0 && !watched && !isWatered() && RandomUtils.success(compost.getProtection());
54 }*/
55
56 /*private void handleDisease() {
57 if (rollDisease()) {
58 setDiseased();
59 player.message("One of your crops is diseased!");
60 }
61 }*/
62
63 private void curePlant(int index) {
64 if (player.locking.locked()) {
65 return;
66 }
67
68 if (plant == null) {
69 return;
70 }
71
72 if (!isDiseased()) {
73 player.message("This plant doesn't need to be cured.");
74 return;
75 }
76
77 if (!player.inventory.contains(FarmingConstants.PLANT_CURE)) {
78 player.message("You need plant cure to cure this plant.");
79 return;
80 }
81
82
83 if (index != -1) {
84 player.inventory.replace(FarmingConstants.PLANT_CURE, 229, index, true);
85 } else {
86 player.inventory.replace(FarmingConstants.PLANT_CURE, 229, true);
87 }
88
89 player.locking.lock(7);
91 setNormal();
92
93 World.schedule(7, () -> {
94 player.resetAnimation();
95 player.message("You cure the plant with a plant cure.");
96 zone.sendPatchConfigs(player);
97 });
98 }
99
100 @Override
101 public JsonObject toJson() {
102 JsonObject object = super.toJson();
103 object.addProperty("watched", watched);
104 return object;
105 }
106
107 @Override
108 public void fromJson(JsonObject object) {
109 watched = object.get("watched").getAsBoolean();
110 super.fromJson(object);
111 }
112
113}
DiseasablePatch(Player player, FarmingZone zone, Interactable[] boundaries)
HarvestablePatch(Player player, FarmingZone zone, Interactable[] boundaries)
Constructs a new HarvestablePatch 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
An object implementing Interactable has uses.