RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
DiseasablePatch.java
1package com.osroyale.content.skill.impl.farming.patches;
2
3import com.google.gson.JsonObject;
4import com.osroyale.content.skill.impl.farming.FarmingConstants;
5import com.osroyale.content.skill.impl.farming.zones.FarmingZone;
6import com.osroyale.game.world.Interactable;
7import com.osroyale.game.world.World;
8import com.osroyale.game.world.entity.mob.player.Player;
9import com.osroyale.game.world.items.Item;
10
39
40public abstract class DiseasablePatch extends HarvestablePatch {
41 protected boolean watched;
42
43 protected DiseasablePatch(Player player, FarmingZone zone, Interactable[] boundaries) {
44 super(player, zone, boundaries);
45 }
46
47 @Override
48 protected void onGrowth() {
49 if (isDead()) {
50 return;
51 }
52
53 /* if (isDiseased()) {
54 setDead();
55 } else if (!fullyGrown) {
56 handleDisease();
57 }*/
58 }
59
60 protected void resetPatch() {
61 super.resetPatch();
62 watched = false;
63 }
64
65 public boolean clickObject(int opcode) {
66 if (opcode == 1 && isDiseased()) {
67 curePlant(-1);
68 return true;
69 }
70 return super.clickObject(opcode);
71 }
72
73 public boolean itemOnObject(Item item, int index) {
74 if (item.matchesId(FarmingConstants.PLANT_CURE)) {
75 curePlant(index);
76 return true;
77 }
78 return super.itemOnObject(item, index);
79 }
80
81 /* public boolean rollDisease() {
82 return growth > 0 && !watched && !isWatered() && RandomUtils.success(compost.getProtection());
83 }*/
84
85 /*private void handleDisease() {
86 if (rollDisease()) {
87 setDiseased();
88 player.message("One of your crops is diseased!");
89 }
90 }*/
91
92 private void curePlant(int index) {
93 if (player.locking.locked()) {
94 return;
95 }
96
97 if (plant == null) {
98 return;
99 }
100
101 if (!isDiseased()) {
102 player.message("This plant doesn't need to be cured.");
103 return;
104 }
105
106 if (!player.inventory.contains(FarmingConstants.PLANT_CURE)) {
107 player.message("You need plant cure to cure this plant.");
108 return;
109 }
110
111
112 if (index != -1) {
113 player.inventory.replace(FarmingConstants.PLANT_CURE, 229, index, true);
114 } else {
115 player.inventory.replace(FarmingConstants.PLANT_CURE, 229, true);
116 }
117
118 player.locking.lock(7);
119 player.animate(FarmingConstants.CURING_ANIM);
120 setNormal();
121
122 World.schedule(7, () -> {
123 player.resetAnimation();
124 player.message("You cure the plant with a plant cure.");
125 zone.sendPatchConfigs(player);
126 });
127 }
128
129 @Override
130 public JsonObject toJson() {
131 JsonObject object = super.toJson();
132 object.addProperty("watched", watched);
133 return object;
134 }
135
136 @Override
137 public void fromJson(JsonObject object) {
138 watched = object.get("watched").getAsBoolean();
139 super.fromJson(object);
140 }
141
142}
static void schedule(Task task)
Definition World.java:284