RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.content.pet.Pets Class Reference

Handles spawning, rewarding and picking up of pets. More...

Static Public Member Functions

static Task abandon (Npc npc)
 The pet abandon task.
static void buyInsurance (Player player, Item item)
 Handles purchasing insurance for a pet.
static void claimLostPets (Player player)
 Claims all the lost pets.
static boolean dialogue (Player player, Npc npc)
 Handles speaking to a pet.
static void onDeath (Player player)
 Handles what happens to a pet when a player dies.
static void onLogin (Player player)
 Handles what happens to a pet when a player logs in.
static void onLogout (Player player)
 Handles what happens to a pet when a player logouts.
static void onReward (Player player, int item)
 Handles rewarding with a 100% a chance.
static void onReward (Player player, int item, int chance)
 Handles calculating the chance of a player receiving a skilling pet.
static boolean onReward (Player player, PetData pet)
 Generates a unique equation for special defined pets.
static boolean onSpawn (Player player, int item, boolean drop)
 Handles spawning a pet.
static void openInsurance (Player player)
 Handles opening the insurance interface.
static void openLostPets (Player player)
 Handles opening the insurance interface.

Static Public Attributes

static final int INSRUANCE_COST = 8000000
 The cost of insuring a pet.

Static Private Member Functions

static boolean hasInsurance (Player player, PetData pet)
 Checks if player already has insurance for a pet.
static void onObtain (Player player, int item)
 Handles a player receiving a pet onReward.

Detailed Description

Handles spawning, rewarding and picking up of pets.

Author
Daniel

Definition at line 27 of file Pets.java.

Member Function Documentation

◆ abandon()

Task com.runehive.content.pet.Pets.abandon ( Npc npc)
static

The pet abandon task.

Definition at line 184 of file Pets.java.

184 {
185 return new Task(5) {
186 int count = 0;
187
188 @Override
189 protected void onSchedule() {
190 npc.resetWaypoint();
191 npc.resetFace();
192 }
193
194 @Override
195 protected void execute() {
196 if (count >= 15) {
197 cancel();
198 return;
199 }
200 if (npc.movement.isMoving()) {
201 return;
202 }
203 Position[] boundaries = Utility.getInnerBoundaries(npc.getPosition().transform(-3, -2), 7, 7);
204 npc.walk(Utility.randomElement(boundaries));
205 count++;
206 }
207
208 @Override
209 protected void onCancel(boolean logout) {
210 npc.unregister();
211 }
212 };
213 }

References com.runehive.util.Utility.getInnerBoundaries(), com.runehive.game.world.entity.Entity.getPosition(), com.runehive.game.world.entity.mob.movement.Movement.isMoving, com.runehive.game.world.entity.mob.Mob.movement, com.runehive.util.Utility.randomElement(), com.runehive.game.world.entity.mob.Mob.resetFace(), com.runehive.game.world.entity.mob.Mob.resetWaypoint(), com.runehive.game.world.position.Position.transform(), com.runehive.game.world.entity.mob.npc.Npc.unregister(), and com.runehive.game.world.entity.mob.npc.Npc.walk.

Referenced by onDeath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ buyInsurance()

void com.runehive.content.pet.Pets.buyInsurance ( Player player,
Item item )
static

Handles purchasing insurance for a pet.

Definition at line 238 of file Pets.java.

238 {
239 Optional<PetData> petData = PetData.forItem(item.getId());
240 if (!petData.isPresent()) {
241 player.dialogueFactory.sendNpcChat(7601, "I can't insure " + item.getName() + "!", "What do I look like to you?", "Show me some respect and use a pet on me.").execute();
242 return;
243 }
244 if (hasInsurance(player, petData.get())) {
245 player.dialogueFactory.sendNpcChat(7601, "You already have insurance for " + petData.get().getName() + "!").execute();
246 return;
247 }
248 if (!player.inventory.contains(995, INSRUANCE_COST)) {
249 player.dialogueFactory.sendNpcChat(7601, "Naw, it's going to cost " + Utility.formatDigits(INSRUANCE_COST) + " coins", "to insure your pet. Start hustling fam.").execute();
250 return;
251 }
252 player.inventory.remove(995, INSRUANCE_COST);
253 player.petInsurance.add(petData.get());
254 player.dialogueFactory.sendNpcChat(7601, "You can put your trust in my that I will", "protect your little " + petData.get().getName() + ".").execute();
255 }

References com.runehive.game.world.items.containers.ItemContainer.contains(), com.runehive.game.world.entity.mob.player.Player.dialogueFactory, com.runehive.content.dialogue.DialogueFactory.execute(), com.runehive.content.pet.PetData.forItem(), com.runehive.util.Utility.formatDigits(), com.runehive.game.world.items.Item.getId(), com.runehive.game.world.items.Item.getName(), hasInsurance(), INSRUANCE_COST, com.runehive.game.world.entity.mob.player.Player.inventory, com.runehive.game.world.entity.mob.player.Player.petInsurance, com.runehive.game.world.items.containers.ItemContainer.remove(), and com.runehive.content.dialogue.DialogueFactory.sendNpcChat().

Here is the call graph for this function:

◆ claimLostPets()

void com.runehive.content.pet.Pets.claimLostPets ( Player player)
static

Claims all the lost pets.

Definition at line 258 of file Pets.java.

258 {
259 if (player.lostPets.isEmpty()) {
260 player.dialogueFactory.sendNpcChat(7601, "You have no lost pets to claim!");
261 return;
262 }
263 int cost = player.lostPets.size() * 250_000;
264 if (!player.inventory.contains(995, cost)) {
265 player.dialogueFactory.sendNpcChat(7601, "You need " + Utility.formatDigits(cost) + " coins to claim all", "of your lost pets.");
266 return;
267 }
268 if (player.inventory.getFreeSlots() < player.lostPets.size()) {
269 player.dialogueFactory.sendNpcChat(7601, "You need " + player.lostPets.size() + " free inventory spaces", "to claim your pets!");
270 return;
271 }
272 player.inventory.remove(995, cost);
273 player.lostPets.forEach(petData -> player.inventory.add(new Item(petData.getItem(), 1)));
274 player.lostPets.clear();
275 player.dialogueFactory.sendNpcChat(7601, "You have claimed all your lost pets for " + Utility.formatDigits(cost) + " coins.");
276 }

References com.runehive.game.world.items.containers.ItemContainer.add(), com.runehive.game.world.items.containers.ItemContainer.contains(), com.runehive.game.world.entity.mob.player.Player.dialogueFactory, com.runehive.util.Utility.formatDigits(), com.runehive.game.world.items.containers.ItemContainer.getFreeSlots(), com.runehive.game.world.entity.mob.player.Player.inventory, com.runehive.game.world.entity.mob.player.Player.lostPets, com.runehive.game.world.items.containers.ItemContainer.remove(), and com.runehive.content.dialogue.DialogueFactory.sendNpcChat().

Here is the call graph for this function:

◆ dialogue()

boolean com.runehive.content.pet.Pets.dialogue ( Player player,
Npc npc )
static

Handles speaking to a pet.

Definition at line 128 of file Pets.java.

128 {
129 Optional<PetData> pet = PetData.forNpc(npc.id);
130 if (!pet.isPresent()) {
131 return false;
132 }
133 if (npc.owner == null || !npc.owner.equals(player)) {
134 player.send(new SendMessage(npc.getName() + " seems uninterested in speaking to you."));
135 return true;
136 }
137 pet.get().dialogue(player.dialogueFactory);
138 return true;
139 }

References com.runehive.game.world.entity.mob.player.Player.dialogueFactory, com.runehive.game.world.entity.Entity.equals(), com.runehive.content.pet.PetData.forNpc(), com.runehive.game.world.entity.mob.npc.Npc.getName(), com.runehive.game.world.entity.mob.Mob.id, com.runehive.game.world.entity.mob.npc.Npc.owner, and com.runehive.game.world.entity.mob.player.Player.send().

Here is the call graph for this function:

◆ hasInsurance()

boolean com.runehive.content.pet.Pets.hasInsurance ( Player player,
PetData pet )
staticprivate

Checks if player already has insurance for a pet.

Definition at line 317 of file Pets.java.

317 {
318 return player.petInsurance.contains(pet);
319 }

References com.runehive.game.world.entity.mob.player.Player.petInsurance.

Referenced by buyInsurance(), onDeath(), and openInsurance().

Here is the caller graph for this function:

◆ onDeath()

void com.runehive.content.pet.Pets.onDeath ( Player player)
static

Handles what happens to a pet when a player dies.

TODO: MULTIPLE OF THE SAME PET

Definition at line 142 of file Pets.java.

142 {
143 Map<PetData, Boolean> lostPets = new HashMap<>();
144 if (player.pet != null) {
145 Optional<PetData> petData = PetData.forNpc(player.pet.id);
146 petData.ifPresent(pet -> {
147 lostPets.put(pet, true);
148 });
149 }
150 for (Item items : player.inventory) {
151 if (items != null) {
152 Optional<PetData> petData = PetData.forItem(items.getId());
153 petData.ifPresent(pet -> {
154 lostPets.put(pet, false);
155 });
156 }
157 }
158 for (PetData pets : lostPets.keySet()) {
159 if (hasInsurance(player, pets)) {
160 player.lostPets.add(pets);
161 player.inventory.remove(pets.getItem());
162 if (lostPets.get(pets)) {
163 player.pet.unregister();
164 player.pet = null;
165 }
166 player.message("You have lost your pet, luckily you insured it! Speak to the insurance agent to claim.");
167 } else {
168 player.inventory.remove(pets.getItem());
169 if (lostPets.get(pets)) {
170 player.pet.unregister();
171 player.pet = null;
172 } else {
173 Npc npc = new Npc(pets.getNpc(), player.getPosition());
174 npc.unregister();
175 World.schedule(abandon(npc));
176 }
177 player.send(new SendMessage("Your " + pets.getName() + " has disappeared forever! Make sure to insure it!"));
178 }
179 }
180 }

References abandon(), com.runehive.content.pet.PetData.forItem(), com.runehive.content.pet.PetData.forNpc(), com.runehive.game.world.items.Item.getId(), com.runehive.game.world.entity.Entity.getPosition(), hasInsurance(), com.runehive.game.world.entity.mob.Mob.id, com.runehive.game.world.entity.mob.player.Player.inventory, com.runehive.game.world.entity.mob.player.Player.lostPets, com.runehive.game.world.entity.mob.player.Player.message(), com.runehive.game.world.entity.mob.player.Player.pet, com.runehive.game.world.items.containers.ItemContainer.remove(), com.runehive.game.world.World.schedule(), com.runehive.game.world.entity.mob.player.Player.send(), and com.runehive.game.world.entity.mob.npc.Npc.unregister().

Referenced by com.runehive.game.world.entity.mob.player.PlayerDeath.death(), and com.runehive.game.world.entity.mob.player.PlayerDeath.postDeath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onLogin()

void com.runehive.content.pet.Pets.onLogin ( Player player)
static

Handles what happens to a pet when a player logs in.

Definition at line 224 of file Pets.java.

224 {
225 if (player.pet != null) {
226 Npc npc = player.pet;
227 npc.owner = player;
228 npc.register();
229 World.schedule(5, () -> {
230 npc.face(player);
231 npc.interact(player);
232 npc.follow(player);
233 });
234 }
235 }

References com.runehive.game.world.entity.mob.Mob.face(), com.runehive.game.world.entity.mob.Mob.follow(), com.runehive.game.world.entity.mob.Mob.interact(), com.runehive.game.world.entity.mob.player.Player.pet, com.runehive.game.world.entity.mob.npc.Npc.register(), and com.runehive.game.world.World.schedule().

Referenced by com.runehive.game.world.entity.mob.player.PlayerAssistant.login().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onLogout()

void com.runehive.content.pet.Pets.onLogout ( Player player)
static

Handles what happens to a pet when a player logouts.

Definition at line 217 of file Pets.java.

217 {
218 if (player.pet != null) {
219 player.pet.unregister();
220 }
221 }

References com.runehive.game.world.entity.mob.player.Player.pet, and com.runehive.game.world.entity.mob.npc.Npc.unregister().

Referenced by com.runehive.game.world.entity.mob.player.Player.unregister().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onObtain()

void com.runehive.content.pet.Pets.onObtain ( Player player,
int item )
staticprivate

Handles a player receiving a pet onReward.

Definition at line 69 of file Pets.java.

69 {
70 Position position = Utility.findAccessableTile(player);
71 if(PetData.forItem(item).isPresent() && (player.inventory.contains(item) || player.bank.contains(item) || (player.pet != null && player.pet.id == PetData.forItem(item).get().getNpc()))) {
72 player.send(new SendMessage("<col=FF0000>You have a funny feeling like you would've been followed."));
73 return;
74
75 }
76 if (player.pet == null && position != null) {
77 onSpawn(player, item, false);
78 } else if (player.inventory.hasCapacityFor(new Item(item, 1))) {
79 player.inventory.add(item, 1);
80 player.send(new SendMessage("You feel something weird sneaking into your backpack", MessageColor.RED));
81 } else {
82 player.send(new SendMessage("There was no space for the pet, he has vanished.", MessageColor.RED));
83 }
84
85 if (item == 20693) { //phoenix pet from wintertodt
86 CollectionLog.logItem(player, CollectionLogData.WINTERTODT, 20693, 1);
87 }
88 }

References com.runehive.game.world.items.containers.ItemContainer.add(), com.runehive.game.world.entity.mob.player.Player.bank, com.runehive.game.world.items.containers.ItemContainer.contains(), com.runehive.util.Utility.findAccessableTile(), com.runehive.content.pet.PetData.forItem(), com.runehive.game.world.items.containers.ItemContainer.hasCapacityFor(), com.runehive.game.world.entity.mob.Mob.id, com.runehive.game.world.entity.mob.player.Player.inventory, com.runehive.content.collectionlog.CollectionLog.logItem(), onSpawn(), com.runehive.game.world.entity.mob.player.Player.pet, com.runehive.util.MessageColor.RED, com.runehive.game.world.entity.mob.player.Player.send(), and com.runehive.content.collectionlog.CollectionLogData.WINTERTODT.

Referenced by onReward(), onReward(), and onReward().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onReward() [1/3]

void com.runehive.content.pet.Pets.onReward ( Player player,
int item )
static

Handles rewarding with a 100% a chance.

Parameters
player
item
chance

Definition at line 44 of file Pets.java.

44 {
45 onObtain(player, item);
46 }

References onObtain().

Here is the call graph for this function:

◆ onReward() [2/3]

void com.runehive.content.pet.Pets.onReward ( Player player,
int item,
int chance )
static

◆ onReward() [3/3]

boolean com.runehive.content.pet.Pets.onReward ( Player player,
PetData pet )
static

Generates a unique equation for special defined pets.

Definition at line 49 of file Pets.java.

49 {
50 int chance = -1;
51 if (pet == PetData.JAD)
52 chance = 200;
53 if (pet == PetData.ROCKY)
54 chance = 5000;
55 if (pet == PetData.ROCK_GOLEM)
56 chance = 6500;
57 if (pet == PetData.BABY_DARTH)
58 chance = 30000;
59
60 if (chance != -1 && Utility.random(chance) == 0) {
61 onObtain(player, pet.getItem());
62 return true;
63 }
64
65 return false;
66 }

References com.runehive.content.pet.PetData.BABY_DARTH, com.runehive.content.pet.PetData.JAD, onObtain(), com.runehive.util.Utility.random(), com.runehive.content.pet.PetData.ROCK_GOLEM, and com.runehive.content.pet.PetData.ROCKY.

Here is the call graph for this function:

◆ onSpawn()

boolean com.runehive.content.pet.Pets.onSpawn ( Player player,
int item,
boolean drop )
static

Handles spawning a pet.

Definition at line 91 of file Pets.java.

91 {
92 if (!PetData.forItem(item).isPresent())
93 return false;
94 if (player.pet != null) {
95 player.send(new SendMessage("You already have a pet following you!"));
96 return true;
97 }
98 Position position = Utility.findAccessableTile(player);
99 if (position == null) {
100 player.send(new SendMessage("You cannot drop your pet from your current location!"));
101 return true;
102 }
103 PetData pets = PetData.forItem(item).get();
104 Npc pet = new Npc(pets.getNpc(), position);
105 pet.owner = player;
106
107 if (drop) {
108 player.face(position);
109 player.animate(new Animation(827));
110 player.inventory.remove(item, 1);
111 }
112
113 pet.register();
114 pet.interact(player);
115 pet.follow(player);
116 pet.instance = player.instance;
117 player.pet = pet;
118
119 if (!drop) {
120 player.message("<col=FF0000>You have a funny feeling like you're being followed.");
121 World.sendMessage("<icon=11> <col=FF0000>osroyale: <col=" + player.right.getColor() + ">" + player.getName() + "</col> has just received a pet " + pet.getName() + "!");
122 AchievementHandler.activate(player, AchievementKey.OBTAIN_PET);
123 }
124 return true;
125 }

References com.runehive.content.achievement.AchievementHandler.activate(), com.runehive.game.world.entity.mob.Mob.animate(), com.runehive.game.world.entity.mob.Mob.face(), com.runehive.util.Utility.findAccessableTile(), com.runehive.content.pet.PetData.forItem(), com.runehive.game.world.entity.mob.player.PlayerRight.getColor(), com.runehive.game.world.entity.mob.player.Player.getName(), com.runehive.content.pet.PetData.getNpc(), com.runehive.game.world.entity.Entity.instance, com.runehive.game.world.entity.mob.player.Player.inventory, com.runehive.game.world.entity.mob.player.Player.message(), com.runehive.content.achievement.AchievementKey.OBTAIN_PET, com.runehive.game.world.entity.mob.player.Player.pet, com.runehive.game.world.items.containers.ItemContainer.remove(), com.runehive.game.world.entity.mob.player.Player.right, com.runehive.game.world.entity.mob.player.Player.send(), and com.runehive.game.world.World.sendMessage().

Referenced by onObtain().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openInsurance()

void com.runehive.content.pet.Pets.openInsurance ( Player player)
static

Handles opening the insurance interface.

Definition at line 279 of file Pets.java.

279 {
280 int size = PetData.values().length;
281 for (int index = 0, string = 37115; index < size; index++) {
282 PetData pet = PetData.forOrdinal(index).get();
283 player.send(new SendString("<col=" + (hasInsurance(player, pet) ? "347043" : "F24444") + ">" + pet.getName(), string++));
284 }
285 player.send(new SendString("<col=000000>This is a list of all pets that are allowed to be insured", 37111));
286 player.send(new SendString("<col=000000>for <col=3c50b2>" + Utility.formatDigits(INSRUANCE_COST) + "<col=000000> gp. Insurance will protect a pet on death.", 37112));
287 player.send(new SendString("<col=000000>Red = <col=F24444>Un-insured<col=000000> | Green = <col=347043>Insured", 37113));
288 player.send(new SendString("", 37114));
289 player.send(new SendString("Total Pets: " + size, 37107));
290 player.send(new SendString("Pet Insurance Information", 37103));
291 player.send(new SendScrollbar(37110, size * 22));
292 player.interfaceManager.open(37100);
293 }
val index

References com.runehive.util.Utility.formatDigits(), com.runehive.content.pet.PetData.forOrdinal(), hasInsurance(), INSRUANCE_COST, com.runehive.game.world.entity.mob.player.Player.interfaceManager, com.runehive.game.world.entity.mob.player.InterfaceManager.open(), and com.runehive.game.world.entity.mob.player.Player.send().

Here is the call graph for this function:

◆ openLostPets()

void com.runehive.content.pet.Pets.openLostPets ( Player player)
static

Handles opening the insurance interface.

Definition at line 296 of file Pets.java.

296 {
297 List<PetData> pets = new ArrayList<>();
298 pets.addAll(player.lostPets);
299 int size = pets.size() < 7 ? 7 : pets.size();
300 for (int index = 0, string = 37115; index < size; index++) {
301 boolean valid = !pets.isEmpty() && index < pets.size();
302 PetData pet = valid ? pets.get(index) : null;
303 player.send(new SendString(valid ? "<col=255>" + pet.getName() : "", string++));
304 }
305 int cost = player.lostPets.size() * 250_000;
306 player.send(new SendString("<col=000000>This is a list of all pets available to be claimed", 37111));
307 player.send(new SendString("<col=000000>Total Free <col=3c50b2>" + Utility.formatDigits(cost) + "<col=000000> gp", 37112));
308 player.send(new SendString("", 37113));
309 player.send(new SendString(pets.isEmpty() ? "You have no pets to collect!" : "", 37114));
310 player.send(new SendString("Total Lost: " + pets.size(), 37107));
311 player.send(new SendString("Lost Pets", 37103));
312 player.send(new SendScrollbar(37110, 0));
313 player.interfaceManager.open(37100);
314 }

References com.runehive.util.Utility.formatDigits(), com.runehive.game.world.entity.mob.player.Player.interfaceManager, com.runehive.game.world.entity.mob.player.Player.lostPets, com.runehive.game.world.entity.mob.player.InterfaceManager.open(), and com.runehive.game.world.entity.mob.player.Player.send().

Here is the call graph for this function:

Member Data Documentation

◆ INSRUANCE_COST

final int com.runehive.content.pet.Pets.INSRUANCE_COST = 8000000
static

The cost of insuring a pet.

Definition at line 30 of file Pets.java.

Referenced by buyInsurance(), and openInsurance().


The documentation for this class was generated from the following file: