RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
HarvestablePatch.java
1package com.osroyale.content.skill.impl.farming.patches;
2
3import com.google.gson.JsonObject;
4import com.osroyale.Config;
5import com.osroyale.content.skillcape.SkillCape;
6import com.osroyale.content.skill.impl.farming.FarmingConstants;
7import com.osroyale.content.skill.impl.farming.zones.FarmingZone;
8import com.osroyale.game.action.Action;
9import com.osroyale.game.action.policy.WalkablePolicy;
10import com.osroyale.game.world.Interactable;
11import com.osroyale.game.world.entity.mob.player.Player;
12import com.osroyale.game.world.entity.skill.Skill;
13import com.osroyale.util.RandomUtils;
14
56
57public abstract class HarvestablePatch extends FarmingPatch {
58
60 private int harvest;
61
69 HarvestablePatch(Player player, FarmingZone zone, Interactable[] boundaries) {
70 super(player, zone, boundaries);
71 }
72
81 private boolean harvest(int min, int max) {
82 if (plant == null) {
83 return false;
84 }
85
86 if (!player.inventory.contains(FarmingConstants.SECATEURS) && !player.inventory.contains(FarmingConstants.MAGIC_SECATEURS) &&
87 !player.equipment.contains(FarmingConstants.MAGIC_SECATEURS)) {
88 player.dialogueFactory.sendStatement("You need secateurs to harvest here.").execute();
89 return true;
90 }
91
92 min = min * compost.produceIncrease() / 100;
93 player.action.execute(createHarvestAction(player, min, max));
94 return true;
95 }
96
105 private Action<Player> createHarvestAction(Player player, int min, int max) {
106 return new Action<Player>(player, 2) {
107
108 @Override
109 protected boolean canSchedule() {
110 return !player.locking.locked() && player.inventory.getFreeSlots() > 0;
111 }
112
113 @Override
114 protected void onSchedule() {
115 player.locking.lock(2);
116 player.animate(animation());
117 player.message("You begin to harvest the crop for " + plant.getProductType() + ".");
118 }
119
120 @Override
121 public void execute() {
122 if (player.inventory.getFreeSlots() <= 0) {
123 cancel();
124 return;
125 }
126
127 if (harvest == 0) {
128 harvest = RandomUtils.inclusive(min, max);
129
130 if (player.equipment.contains(FarmingConstants.MAGIC_SECATEURS)) {
131 harvest = harvest * 13 / 12;
132 }
133
134 if (SkillCape.isEquipped(player, SkillCape.FARMING)) {
135 harvest += harvest * 13 / 12;
136 }
137
138 harvest++;
139 }
140
141 if (harvest == 1) {
142 resetPatch();
143 cancel();
144 return;
145 }
146
147 harvest--;
148 if (harvest % 2 == 0)
149 player.animate(animation());
150 player.inventory.add(plant.getHarvestId(), 1);
151 player.skills.addExperience(Skill.FARMING, plant.getHarvestXp() * Config.FARMING_MODIFICATION);
152 }
153
154 @Override
155 public void onCancel(boolean logout) {
156 player.resetAnimation();
157 zone.sendPatchConfigs(player);
158 }
159
160 @Override
161 public WalkablePolicy getWalkablePolicy() {
163 }
164
165 @Override
166 public String getName() {
167 return "Farming Harvest";
168 }
169 };
170 }
171
173 protected abstract int getMinAmount();
174
176 protected abstract int getMaxAmount();
177
179 protected abstract int animation();
180
181 @Override
182 public boolean clickObject(int opcode) {
183 if (opcode == 1 && !isDead() && fullyGrown) {
184 return harvest(getMinAmount(), getMaxAmount());
185 }
186 return super.clickObject(opcode);
187 }
188
189 @Override
190 protected void resetPatch() {
191 super.resetPatch();
192 harvest = 0;
193 }
194
195 @Override
196 public JsonObject toJson() {
197 JsonObject object = super.toJson();
198 object.addProperty("harvest", harvest);
199 return object;
200 }
201
202 @Override
203 public void fromJson(JsonObject object) {
204 harvest = object.get("harvest").getAsInt();
205 super.fromJson(object);
206 }
207
208}
static final double FARMING_MODIFICATION
Definition Config.java:337