RuneHive-Game
Loading...
Searching...
No Matches
Birdhouses.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.hunter.birdhouse;
2
3import com.runehive.game.world.entity.mob.player.Player;
4import com.runehive.game.world.entity.mob.player.persist.PlayerSerializer;
5import com.runehive.game.world.entity.skill.SkillData;
6import com.runehive.game.world.items.Item;
7import com.runehive.game.world.items.ground.GroundItem;
8import com.runehive.game.world.object.CustomGameObject;
9import com.runehive.game.world.object.ObjectDirection;
10import com.runehive.game.world.object.ObjectType;
11import com.runehive.net.packet.out.SendAddObject;
12import com.runehive.net.packet.out.SendRemoveInterface;
13import com.runehive.util.Utility;
14
15import java.util.ArrayList;
16import java.util.Random;
17
18public class Birdhouses {
19 static long SECOND = 1000,
20 MINUTE = SECOND * 60,
21 HOUR = MINUTE * 60,
22 DAY = HOUR * 24;
23
24 public static String getTimeLeft(PlayerBirdHouseData playerBirdHouseData) {
25 long left = playerBirdHouseData.birdhouseTimer - System.currentTimeMillis();
26 long minutes = left / MINUTE;
27 return minutes < 0 ? "rougly 1 minute." : minutes + " minute(s).";
28 }
29
30 public static void receiveLoot(Player player, PlayerBirdHouseData birdHouseData) {
31 player.send(new SendRemoveInterface());
32
33 if(player.inventory.getFreeSlots() < 2) {
34 player.message("You must have two spaces in your inventory to dismantle the birdhouse.");
35 return;
36 }
37
38 ArrayList<Item> receivedItems = new ArrayList<>();
39 player.animate(827);
40
41 player.inventory.addOrDrop(new Item(8792));
42 receivedItems.add(new Item(8792));
43 for(int index = 0; index < 10; index++) {
44 GroundItem.create(player, new Item(9978));
45 receivedItems.add(new Item(9978));
46 }
47 int[] featerAmount = { 30, 40, 50, 60 };
48 int featherAmount = featerAmount[Utility.random(featerAmount.length - 1)];
49
50 player.inventory.addOrDrop(new Item(314, featherAmount));
51 receivedItems.add(new Item(314, featherAmount));
52
53 int nestsReceived = 0;
54
55 player.inventory.addOrDrop(new Item(5073));
56 receivedItems.add(new Item(5073));
57
58 if(wasSuccesful(player, SkillData.HUNTER.ordinal(), 0, 200)) {
59 player.inventory.addOrDrop(new Item(5073));
60 receivedItems.add(new Item(5073));
61 nestsReceived++;
62 }
63
64 for(int index = 0; index < 10; index++) {
65 int hunterLevel = player.skills.getLevel(SkillData.HUNTER.ordinal());
66
67 if(hunterLevel < 50)
68 hunterLevel = 50;
69
70 int nestRate = birdHouseData.birdhouseData.succesRates * (hunterLevel - 1) / 98;
71 int randomRoll = Utility.random(1000);
72
73 if(randomRoll < nestRate) {
74 int nestChance = 100;
75 if(player.equipment.contains(10134))
76 nestChance = 95;
77 int nestRoll = Utility.random(nestChance);
78
79 if(nestRoll < 1) {
80 player.inventory.addOrDrop(new Item(5072));
81 receivedItems.add(new Item(5072));
82 nestsReceived++;
83 }
84 else if(nestRoll < 2) {
85 player.inventory.addOrDrop(new Item(5070));
86 receivedItems.add(new Item(5070));
87 nestsReceived++;
88 } else if(nestRoll < 3) {
89 player.inventory.addOrDrop(new Item(5071));
90 receivedItems.add(new Item(5071));
91 nestsReceived++;
92 } else if(nestRoll < 35) {
93 player.inventory.addOrDrop(new Item(5074));
94 receivedItems.add(new Item(5074));
95 nestsReceived++;
96 } else {
97 player.inventory.addOrDrop(new Item(5075));
98 receivedItems.add(new Item(5075));
99 nestsReceived++;
100 }
101 }
102 }
103
104 player.inventory.refresh();
105
106 player.message("You dismantle and discard the trap, retrieving "+nestsReceived+" nest"+(nestsReceived > 1 ? "s" : "")+", 10 dead birds, "+featherAmount+" feathers and "+birdHouseData.birdhouseData.hunterData[1]+" Hunter XP.");
107 player.skills.addExperience(SkillData.HUNTER.ordinal(), birdHouseData.birdhouseData.hunterData[1]);
108
109 player.send(new SendAddObject(new CustomGameObject(birdHouseData.oldObjectId, birdHouseData.birdhousePosition, ObjectDirection.valueOf(birdHouseData.rotation).get(), ObjectType.valueOf(birdHouseData.type).get())));
110 player.birdHouseData.remove(birdHouseData);
111 PlayerSerializer.save(player);
112 }
113
114 private static boolean wasSuccesful(Player player, int skill, int low, int high) {
115 int level = player.skills.getLevel(skill);
116
117 int odds = 1 + (low * (99 - level) / 98) + (high * (level - 1) / 98);
118 double percent = ((double)odds / 256D) * 100D;
119 int random = new Random().nextInt(256);
120
121 return odds >= random;
122 }
123
124}
static boolean wasSuccesful(Player player, int skill, int low, int high)
static String getTimeLeft(PlayerBirdHouseData playerBirdHouseData)
static void receiveLoot(Player player, PlayerBirdHouseData birdHouseData)
This class represents a character controlled by a player.
Definition Player.java:125
List< PlayerBirdHouseData > birdHouseData
Definition Player.java:129
void addExperience(int id, double experience)
Adds experience to a given skill.
int getLevel(int id)
Gets the level of a skill.
The container class that represents an item that can be interacted with.
Definition Item.java:21
boolean contains(int[] bowsWithNoArrowsRequired)
void refresh()
Refreshes the players inventory.
void addOrDrop(List< Item > items)
Attempts to deposit an item to the players inventory, if there is no space it'll bank the item instea...
Represents a single Ground item on the world map.
static GroundItem create(Player player, Item item)
Creates a new GroundItem object for a player and an item.
Represents a static game object loaded from the map fs.
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
The enumerated type whose elements represent data for the skills.
The enumerated type whose elements represent the directions for objects.
static Optional< ObjectDirection > valueOf(final int id)
Returns a ObjectDirection wrapped in an Optional for the specified id.
The enumerated type whose elements represent all of the object types.
static Optional< ObjectType > valueOf(final int id)
Returns a ObjectType wrapped in an Optional for the specified id.