1package com.osroyale.content.pet;
3import com.osroyale.content.achievement.AchievementHandler;
4import com.osroyale.content.achievement.AchievementKey;
5import com.osroyale.content.collectionlog.CollectionLog;
6import com.osroyale.content.collectionlog.CollectionLogData;
7import com.osroyale.game.Animation;
8import com.osroyale.game.task.Task;
9import com.osroyale.game.world.World;
10import com.osroyale.game.world.entity.mob.npc.Npc;
11import com.osroyale.game.world.entity.mob.player.Player;
12import com.osroyale.game.world.items.Item;
13import com.osroyale.game.world.position.Position;
14import com.osroyale.net.packet.out.SendMessage;
15import com.osroyale.net.packet.out.SendScrollbar;
16import com.osroyale.net.packet.out.SendString;
17import com.osroyale.util.MessageColor;
18import com.osroyale.util.Utility;
71 if (
Utility.random(chance) == 0)
72 onObtain(player, item);
82 onObtain(player, item);
97 if (chance != -1 &&
Utility.random(chance) == 0) {
98 onObtain(player, pet.getItem());
106 private static void onObtain(
Player player,
int item) {
109 player.send(
new SendMessage(
"<col=FF0000>You have a funny feeling like you would've been followed."));
113 if (player.pet ==
null && position !=
null) {
116 player.inventory.
add(item, 1);
117 player.send(
new SendMessage(
"You feel something weird sneaking into your backpack", MessageColor.RED));
119 player.send(
new SendMessage(
"There was no space for the pet, he has vanished.", MessageColor.RED));
123 CollectionLog.logItem(player, CollectionLogData.WINTERTODT, 20693, 1);
131 if (player.pet !=
null) {
132 player.send(
new SendMessage(
"You already have a pet following you!"));
136 if (position ==
null) {
137 player.send(
new SendMessage(
"You cannot drop your pet from your current location!"));
145 player.
face(position);
147 player.inventory.
remove(item, 1);
151 pet.interact(player);
153 pet.instance = player.instance;
157 player.message(
"<col=FF0000>You have a funny feeling like you're being followed.");
158 World.
sendMessage(
"<icon=11> <col=FF0000>Tarnish: <col=" + player.right.getColor() +
">" + player.
getName() +
"</col> has just received a pet " + pet.getName() +
"!");
167 if (!pet.isPresent()) {
170 if (npc.owner ==
null || !npc.owner.equals(player)) {
171 player.send(
new SendMessage(npc.
getName() +
" seems uninterested in speaking to you."));
174 pet.get().dialogue(player.dialogueFactory);
180 Map<PetData, Boolean> lostPets =
new HashMap<>();
181 if (player.pet !=
null) {
183 petData.ifPresent(pet -> {
184 lostPets.put(pet,
true);
187 for (Item items : player.inventory) {
190 petData.ifPresent(pet -> {
191 lostPets.put(pet,
false);
195 for (
PetData pets : lostPets.keySet()) {
196 if (hasInsurance(player, pets)) {
197 player.lostPets.add(pets);
198 player.inventory.
remove(pets.getItem());
199 if (lostPets.get(pets)) {
203 player.message(
"You have lost your pet, luckily you insured it! Speak to the insurance agent to claim.");
205 player.inventory.
remove(pets.getItem());
206 if (lostPets.get(pets)) {
214 player.send(
new SendMessage(
"Your " + pets.getName() +
" has disappeared forever! Make sure to insure it!"));
226 protected void onSchedule() {
232 protected void execute() {
237 if (npc.movement.isMoving()) {
246 protected void onCancel(
boolean logout) {
255 if (player.pet !=
null) {
262 if (player.pet !=
null) {
263 Npc npc = player.pet;
277 if (!petData.isPresent()) {
278 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();
281 if (hasInsurance(player, petData.get())) {
282 player.dialogueFactory.
sendNpcChat(7601,
"You already have insurance for " + petData.get().getName() +
"!").
execute();
290 player.petInsurance.add(petData.get());
291 player.dialogueFactory.
sendNpcChat(7601,
"You can put your trust in my that I will",
"protect your little " + petData.get().getName() +
".").
execute();
296 if (player.lostPets.isEmpty()) {
297 player.dialogueFactory.
sendNpcChat(7601,
"You have no lost pets to claim!");
300 int cost = player.lostPets.size() * 250_000;
301 if (!player.inventory.
contains(995, cost)) {
305 if (player.inventory.
getFreeSlots() < player.lostPets.size()) {
306 player.dialogueFactory.
sendNpcChat(7601,
"You need " + player.lostPets.size() +
" free inventory spaces",
"to claim your pets!");
309 player.inventory.
remove(995, cost);
310 player.lostPets.forEach(petData -> player.inventory.
add(
new Item(petData.getItem(), 1)));
311 player.lostPets.clear();
317 int size =
PetData.values().length;
318 for (
int index = 0,
string = 37115; index < size; index++) {
320 player.send(
new SendString(
"<col=" + (hasInsurance(player, pet) ?
"347043" :
"F24444") +
">" + pet.getName(),
string++));
322 player.send(
new SendString(
"<col=000000>This is a list of all pets that are allowed to be insured", 37111));
324 player.send(
new SendString(
"<col=000000>Red = <col=F24444>Un-insured<col=000000> | Green = <col=347043>Insured", 37113));
326 player.send(
new SendString(
"Total Pets: " + size, 37107));
327 player.send(
new SendString(
"Pet Insurance Information", 37103));
329 player.interfaceManager.
open(37100);
334 List<PetData> pets =
new ArrayList<>();
335 pets.addAll(player.lostPets);
336 int size = pets.size() < 7 ? 7 : pets.size();
337 for (
int index = 0,
string = 37115; index < size; index++) {
338 boolean valid = !pets.isEmpty() && index < pets.size();
339 PetData pet = valid ? pets.get(index) :
null;
340 player.send(
new SendString(valid ?
"<col=255>" + pet.getName() :
"",
string++));
342 int cost = player.lostPets.size() * 250_000;
343 player.send(
new SendString(
"<col=000000>This is a list of all pets available to be claimed", 37111));
346 player.send(
new SendString(pets.isEmpty() ?
"You have no pets to collect!" :
"", 37114));
347 player.send(
new SendString(
"Total Lost: " + pets.size(), 37107));
348 player.send(
new SendString(
"Lost Pets", 37103));
350 player.interfaceManager.
open(37100);
354 private static boolean hasInsurance(
Player player,
PetData pet) {
355 return player.petInsurance.contains(pet);
static void activate(Player player, AchievementKey achievement)
final DialogueFactory sendNpcChat(int id, String... lines)
final DialogueFactory execute()
static void openInsurance(Player player)
static boolean onReward(Player player, PetData pet)
static final int INSRUANCE_COST
static void claimLostPets(Player player)
static boolean onSpawn(Player player, int item, boolean drop)
static void openLostPets(Player player)
static void onReward(Player player, int item)
static void onReward(Player player, int item, int chance)
static void buyInsurance(Player player, Item item)
static void onLogout(Player player)
static void onDeath(Player player)
static void onLogin(Player player)
static boolean dialogue(Player player, Npc npc)
static Task abandon(Npc npc)
static void sendMessage(String... messages)
static void schedule(Task task)
void face(GameObject object)
final void resetWaypoint()
void open(int identification)
boolean remove(Item item)
final boolean hasCapacityFor(Item... item)
Position transform(int diffX, int diffY, int diffZ)
static String formatDigits(final int amount)
static< T > T randomElement(Collection< T > collection)
static Optional< PetData > forOrdinal(int ordinal)
static Optional< PetData > forNpc(int id)
static Optional< PetData > forItem(int id)