RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
FarmingZone.java
1package com.osroyale.content.skill.impl.farming.zones;
2
3import com.google.gson.JsonArray;
4import com.google.gson.JsonElement;
5import com.google.gson.JsonObject;
6import com.osroyale.content.skill.impl.farming.patches.FarmingPatch;
7import com.osroyale.game.world.Interactable;
8import com.osroyale.game.world.entity.mob.player.Player;
9import com.osroyale.game.world.items.Item;
10import com.osroyale.game.world.object.GameObject;
11import com.osroyale.game.world.position.Position;
12import com.osroyale.game.world.region.Region;
13import com.osroyale.net.packet.out.SendConfig;
14import com.osroyale.util.Utility;
15
57
58public class FarmingZone {
59
61 private static final int PATCH_CONFIG = 529;
62
64 private final Interactable boundary;
65
67 private final FarmingPatch[] patches;
68
74 FarmingZone(Interactable boundary, int size) {
75 this.boundary = boundary;
76 patches = new FarmingPatch[size];
77 }
78
85 void setPatch(int index, FarmingPatch patch) {
86 patches[index] = patch;
87 }
88
96 public boolean clickObject(GameObject object, int opcode) {
97 boolean success = false;
98 for (FarmingPatch patch : patches) {
99 if (patch.within(object.getPosition())) {
100 success |= patch.clickObject(opcode);
101 }
102 }
103 return success;
104 }
105
114 public boolean itemOnObject(GameObject object, Item item, int slot) {
115 boolean success = false;
116 for (FarmingPatch patch : patches) {
117 if (patch.within(object.getPosition())) {
118 success |= patch.itemOnObject(item, slot);
119 }
120 }
121 return success;
122 }
123
129 public final void sendPatchConfigs(Player player) {
130 if (!isViewable(player.getPosition())) {
131 return;
132 }
133
134 int config = 0;
135 for (int index = 0; index < patches.length; index++) {
136 config |= patches[index].getConfig() << (index << 3);
137 }
138
139 player.send(new SendConfig(PATCH_CONFIG, config));
140 }
141
143 public final void tick() {
144 for (FarmingPatch patch : patches) {
145 patch.tick();
146 }
147 }
148
155 public boolean isViewable(Position position) {
156 return Utility.inside(boundary, position) || Utility.withinDistance(boundary, position, Region.SIZE);
157 }
158
159 public JsonArray toJson() {
160 JsonArray array = new JsonArray();
161 for (FarmingPatch patch : patches) {
162 array.add(patch.toJson());
163 }
164 return array;
165 }
166
167 public void fromJson(JsonArray array) {
168 int index = 0;
169 for (JsonElement element : array) {
170 patches[index++].fromJson((JsonObject) element);
171 }
172 }
173
174}
boolean itemOnObject(GameObject object, Item item, int slot)
boolean clickObject(GameObject object, int opcode)