RuneHive-Game
Loading...
Searching...
No Matches
Farming.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.farming;
2
3import com.google.gson.JsonArray;
4import com.google.gson.JsonObject;
5import com.runehive.content.skill.impl.farming.zones.*;
6import com.runehive.game.world.entity.mob.player.Player;
7import com.runehive.game.world.items.Item;
8import com.runehive.game.world.object.GameObject;
9
10import java.util.LinkedList;
11import java.util.List;
12
13public class Farming {
14 private final List<FarmingZone> zones = new LinkedList<>();
15
16 public Farming(Player player) {
17 zones.add(new CatherbyZone(player));
18 zones.add(new ArdougneZone(player));
19 zones.add(new FaladorZone(player));
20 zones.add(new PhasmatyZone(player));
21 }
22
23 public static boolean itemOnObject(Player player, GameObject object, Item item, int slot) {
24 boolean success = false;
25 for (FarmingZone zone : player.farming.zones) {
26 if (zone.isViewable(player.getPosition())) {
27 success |= zone.itemOnObject(object, item, slot);
28 }
29 }
30 return success;
31 }
32
33 public static double getBonus(Player player) {
34 double bonus = 0;
35 if(player.equipment.getId(0) == 13646)
36 bonus += 0.4;
37 if(player.equipment.getId(4) == 13642)
38 bonus += 0.8;
39 if(player.equipment.getId(7) == 13640)
40 bonus += 0.6;
41 if(player.equipment.getId(10) == 13644)
42 bonus += 0.2;
43
44 if(player.equipment.containsAll(13646, 13642, 13640, 13644))
45 bonus = 2.5;
46
47 return bonus;
48 }
49
50
51 public static boolean firstClickObject(Player player, GameObject object) {
52 boolean success = false;
53 for (FarmingZone zone : player.farming.zones) {
54 if (zone.isViewable(player.getPosition())) {
55 success |= zone.clickObject(object, 1);
56 }
57 }
58 return success;
59 }
60
61 public static boolean secondClickObject(Player player, GameObject object) {
62 boolean success = false;
63 for (FarmingZone zone : player.farming.zones) {
64 if (zone.isViewable(player.getPosition())) {
65 success |= zone.clickObject(object, 2);
66 }
67 }
68 return success;
69 }
70
71 public static void tick(Player player) {
72 player.farming.zones.forEach(FarmingZone::tick);
73 }
74
75 public void regionChange(Player player) {
76 zones.forEach(zone -> zone.sendPatchConfigs(player));
77 }
78
79 public JsonObject toJson() {
80 JsonObject object = new JsonObject();
81 for (FarmingZone zone : zones) {
82 object.add(zone.getClass().getSimpleName(), zone.toJson());
83 }
84 return object;
85 }
86
87 public void fromJson(JsonObject object) {
88 for (FarmingZone zone : zones) {
89 if (!object.has(zone.getClass().getSimpleName())) {
90 continue;
91 }
92
93 JsonArray thing = object.get(zone.getClass().getSimpleName()).getAsJsonArray();
94 zone.fromJson(thing);
95 }
96 }
97
98}
static boolean itemOnObject(Player player, GameObject object, Item item, int slot)
Definition Farming.java:23
static double getBonus(Player player)
Definition Farming.java:33
static boolean secondClickObject(Player player, GameObject object)
Definition Farming.java:61
static boolean firstClickObject(Player player, GameObject object)
Definition Farming.java:51
final void tick()
Ticks the farming patches in this zone.
boolean itemOnObject(GameObject object, Item item, int slot)
Handles using an item on a farming patch.
boolean clickObject(GameObject object, int opcode)
Handles clicking a farming patch.
boolean isViewable(Position position)
Checks if a position can see this farming zone.
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(int index)
Gets the item id located on index.
final boolean containsAll(int... identifiers)
Determines if this container contains all identifiers.