RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
WieldItemPacketListener.java
1package com.osroyale.net.packet.in;
2
3import com.osroyale.content.achievement.AchievementHandler;
4import com.osroyale.content.activity.Activity;
5import com.osroyale.content.itemaction.impl.CelestialRing;
6import com.osroyale.game.event.impl.ItemClickEvent;
7import com.osroyale.game.plugin.PluginManager;
8import com.osroyale.game.world.InterfaceConstants;
9import com.osroyale.game.world.entity.mob.data.PacketType;
10import com.osroyale.game.world.entity.mob.player.Player;
11import com.osroyale.game.world.entity.mob.player.PlayerRight;
12import com.osroyale.game.world.items.Item;
13import com.osroyale.game.world.items.containers.equipment.EquipmentType;
14import com.osroyale.net.codec.ByteModification;
15import com.osroyale.net.packet.GamePacket;
16import com.osroyale.net.packet.PacketListener;
17import com.osroyale.net.packet.PacketListenerMeta;
18import com.osroyale.net.packet.out.SendMessage;
19import com.osroyale.util.MessageColor;
20
50
51public class WieldItemPacketListener implements PacketListener {
52
54 private static final int[] MAX_CAPE_AND_HOOD = {
55 13280, 13337, 13333, 13335, 13329, 20760, 13331, 21285, 13281, 13330,
56 13332, 13334, 13336, 13338, 20764, 21282
57 };
58
59 @Override
60 public void handlePacket(Player player, GamePacket packet) {
61 if (player.locking.locked(PacketType.WIELD_ITEM))
62 return;
63
64 final int wearId = packet.readShort();
65 final int wearSlot = packet.readShort(ByteModification.ADD);
66 final int interfaceId = packet.readShort(ByteModification.ADD);
67
68 switch (interfaceId) {
69
70 case InterfaceConstants.INVENTORY_INTERFACE:
71 final Item item = player.inventory.get(wearSlot);
72
73 if (item == null || item.getId() != wearId) {
74 return;
75 }
76
77 if(PluginManager.getDataBus().publish(player, new ItemClickEvent(4, item, wearSlot))) {
78 return;
79 }
80
81 if (!item.isEquipable()) {
82 return;
83 }
84
85 if (Activity.evaluate(player, it -> !it.canEquipItem(player, item, item.getEquipmentType()))) {
86 return;
87 }
88
89 if (!player.interfaceManager.isClear() && !player.interfaceManager.isInterfaceOpen(15106)) {
90 player.interfaceManager.close(false);
91 }
92
93 if (player.right.equals(PlayerRight.OWNER)) {
94 player.send(new SendMessage("[WearItem] - [id= " + wearId + "] [slot= " + wearSlot + "] [itemcontainer " + interfaceId + "]", MessageColor.DEVELOPER));
95 }
96
97 if (item.getEquipmentType() == EquipmentType.NOT_WIELDABLE) {
98 player.send(new SendMessage("This item cannot be worn."));
99 return;
100 }
101
102 for (int maxCape : MAX_CAPE_AND_HOOD) {
103 if (item.getId() == maxCape && !player.skills.isMaxed()) {
104 player.message("You can not wield this item until you have 99 in all your skills!");
105 return;
106 }
107 }
108
109 if (item.getId() == CelestialRing.CHARGED_RING) {
110 CelestialRing.check(player);
111 return;
112 }
113
114 if (item.getId() == 13069 || item.getId() == 13070) {
115 if (!AchievementHandler.completedAll(player)) {
116 player.send(new SendMessage("You need to have completed all the achievements to wear this."));
117 return;
118 }
119 }
120
121 player.equipment.equip(wearSlot);
122 }
123 }
124}