RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
PlayerDeath.java
1package com.osroyale.game.world.entity.mob.player;
2
3import com.osroyale.Config;
4import com.osroyale.content.achievement.AchievementHandler;
5import com.osroyale.content.achievement.AchievementKey;
6import com.osroyale.content.activity.Activity;
7import com.osroyale.content.activity.ActivityDeathType;
8import com.osroyale.content.bot.BotUtility;
9import com.osroyale.content.bot.PlayerBot;
10import com.osroyale.content.event.EventDispatcher;
11import com.osroyale.content.event.impl.OnKillEvent;
12import com.osroyale.content.itemaction.impl.CrawsBow;
13import com.osroyale.content.itemaction.impl.ThammaronsSceptre;
14import com.osroyale.content.itemaction.impl.ViggorasChainmace;
15import com.osroyale.content.lms.LMSGame;
16import com.osroyale.content.pet.Pets;
17import com.osroyale.content.writer.InterfaceWriter;
18import com.osroyale.content.writer.impl.InformationWriter;
19import com.osroyale.game.Animation;
20import com.osroyale.game.Graphic;
21import com.osroyale.game.UpdatePriority;
22import com.osroyale.game.world.World;
23import com.osroyale.game.world.entity.combat.weapon.WeaponInterface;
24import com.osroyale.game.world.entity.mob.Direction;
25import com.osroyale.game.world.entity.mob.Mob;
26import com.osroyale.game.world.entity.mob.MobDeath;
27import com.osroyale.game.world.entity.mob.UpdateFlag;
28import com.osroyale.game.world.entity.mob.prayer.Prayer;
29import com.osroyale.game.world.items.Item;
30import com.osroyale.game.world.items.ground.GroundItem;
31import com.osroyale.game.world.position.Area;
32import com.osroyale.game.world.position.Position;
33import com.osroyale.net.packet.out.SendCameraReset;
34import com.osroyale.net.packet.out.SendMessage;
35import com.osroyale.util.Utility;
36import plugin.click.item.ImbuedHeartPlugin;
37import plugin.itemon.item.LootingBagPlugin;
38
39import java.util.Arrays;
40import java.util.LinkedList;
41import java.util.List;
42
48public final class PlayerDeath extends MobDeath<Player> {
49 private boolean safe = false;
50
52 private static final String[] DEATH_MESSAGES = {
53 "You have defeated $VICTIM.",
54 "With a crushing blow, you defeat $VICTIM.",
55 "It's a humiliating defeat for $VICTIM.",
56 "$VICTIM didn't stand a chance against you.",
57 "You have defeated $VICTIM.",
58 "It's all over for $VICTIM.",
59 "$VICTIM regrets the day they met you in combat.",
60 "$VICTIM falls before your might.",
61 "Can anyone defeat you? Certainly not $VICTIM.",
62 "You were clearly a better fighter than $VICTIM."
63 };
64
66 PlayerDeath(Player mob) {
67 super(mob, 2);
68 }
69
71 @Override
72 public void preDeath(Mob killer) {
73 mob.animate(new Animation(836, UpdatePriority.VERY_HIGH));
74 mob.graphic(new Graphic(293, UpdatePriority.VERY_HIGH));
75 }
76
78 @Override
79 public void death() {
80 Mob killer = mob.getCombat().getDamageCache().calculateProperKiller().orElse(null);
81
82 if (mob.inActivity()) {
83 ActivityDeathType deathType = mob.activity.deathType();
84
86 safe = true;
87 return;
88 }
89
90 if (deathType == ActivityDeathType.SAFE) {
91 safe = true;
92 } else if (deathType == ActivityDeathType.NORMAL) {
94 calculateDropItems(mob, killer, false);
95 } else if (deathType == ActivityDeathType.PURCHASE) {
96 calculateDropItems(mob, killer, true);
97 mob.message("You have lost your items. Speak to Lord Marshal Brogan at home to claim them!");
98 }
99 return;
100 }
101 if(mob.playTime < 6000) {
102 System.out.println("Safe death");
103 safe = true;
104 mob.message("Your death is safe because you have less than 1 hour of playtime.");
105 return;
106 }
107 if (Area.inZulrah(mob)) {
108 safe = true;
109 return;
110 }
111
112 /* if (Area.inEventArena(mob)) {
113 safe = true;
114 return;
115 }*/
116
117 if(mob.isPlayer() && LMSGame.inGameArea(mob.getPlayer()) && killer != null && killer.isPlayer()) {
118 safe = true;
119 LMSGame.onKill(killer.getPlayer());
120 return;
121 }
122
125 calculateDropItems(mob, killer, false);
126 }
127
128 if (killer == null || !killer.isPlayer())
129 return;
130
131 Player playerKiller = killer.getPlayer();
132
133 if (mob.isBot) {
134 playerKiller.message("<col=295EFF>You were rewarded with 100 blood money for that bot kill.");
135 playerKiller.inventory.addOrDrop(new Item(13307, 100));
136 return;
137 }
138
139 playerKiller.kill++;
140 mob.death++;
141
142 if (!PlayerKilling.contains(playerKiller, mob.lastHost)) {
144 playerKiller.send(new SendMessage(Utility.randomElement(DEATH_MESSAGES).replace("$VICTIM", mob.getName())));
145 PlayerKilling.handle(playerKiller, mob);
146 } else {
147 playerKiller.message("<col=FF0019>You have recently killed " + mob.getName() + " and were not rewarded. You must kill 2 other players to reset this!");
148 }
149
150 EventDispatcher.execute(playerKiller, new OnKillEvent(mob));
151 }
152
154 @Override
155 public void postDeath(Mob killer) {
156 if (mob.isBot) {
157 ((PlayerBot) mob).postDeath();
158 return;
159 }
160
161 mob.playerAssistant.restore();
162
163 if(mob.isPlayer() && LMSGame.isActivePlayer(mob.getPlayer())) {
164 LMSGame.onDeath(mob.getPlayer(), false);
165 return;
166 }
167
168 if (mob.inActivity()) {
169 Activity.forActivity(mob, it -> it.onDeath(mob));
170 return;
171 }
172 if(mob.isPlayer()) {
173 ImbuedHeartPlugin.resetCooldown(mob);
174 }
175 mob.hasPvPTimer = false;
176 mob.move(mob.pvpInstance ? new Position(3093, 3494,4) : Config.DEFAULT_POSITION);
177 mob.send(new SendMessage("Oh dear, you are dead!"));
178 mob.send(new SendCameraReset());
179 mob.face(Direction.SOUTH);
180 mob.equipment.updateAnimation();
181 mob.equipment.refresh();
182 mob.animate(Animation.RESET, true);
183 mob.graphic(Graphic.RESET, true);
185 WeaponInterface.execute(mob, mob.equipment.getWeapon());
187
188 if (!safe) {
189 if (killer != null && killer.isPlayer() && !mob.equals(killer)) {
190 mob.killstreak.end(killer.getPlayer());
191 }
192 if (mob.right == PlayerRight.HARDCORE_IRONMAN) {
193 mob.right = PlayerRight.IRONMAN;
194 mob.updateFlags.add(UpdateFlag.APPEARANCE);
195 mob.send(new SendMessage("You have lost your hardcore iron man status since you died!"));
196 World.sendMessage("<icon=1> <col=FF0000>Tarnish: <col=" + mob.right.getColor() + ">" + mob.getName() + "</col>'s hardcore iron man account was lost!");
197 }
198 }
199
200 if (mob.presetManager.deathOpen) {
201 World.schedule(1, mob.presetManager::open);
202 }
203
204 if (!mob.lostItems.isEmpty()) {
205 mob.dialogueFactory.sendStatement("There are lost items waiting for you!", "Speak to Lord Marshal Brogan at home to claim them!").execute();
206 }
207 }
208
210 private void calculateDropItems(Player character, Mob killer, boolean purchase) {
211 Player theKiller = killer == null || killer.isNpc() ? character : killer.getPlayer();
212
213 if (character.right.equals(PlayerRight.ULTIMATE_IRONMAN)) {
214 List<Item> items = new LinkedList<>();
215 character.equipment.forEach(items::add);
216 character.inventory.forEach(items::add);
217 character.lootingBag.forEach(items::add);
218 character.equipment.clear();
219 character.inventory.clear();
220 character.lootingBag.clear();
221 items.forEach(item -> {
222 if (!item.isTradeable()) {
223 if (!character.lostUntradeables.deposit(item)) {
224 GroundItem.create(character, item);
225 }
226 } else {
227 GroundItem.create(theKiller, item, character.getPosition());
228 }
229 });
230 return;
231 }
232
233 LinkedList<Item> toDrop = new LinkedList<>();
234 List<Item> keep = new LinkedList<>();
235 List<Item> items = new LinkedList<>();
236 character.equipment.forEach(items::add);
237 Item[] lootingBag = character.lootingBag.getDeathItems();
238 character.inventory.forEach(item -> {
239 if (!LootingBagPlugin.isLootingBag(item)) {
240 items.add(item);
241 }
242 });
243 character.equipment.clear();
244 character.inventory.clear();
245
246 if (lootingBag != null) {
247 items.addAll(Arrays.asList(lootingBag));
248 character.lootingBag.clear();
249 }
250
251 toDrop.addAll(items);
252
253 toDrop.sort((first, second) -> second.getValue() - first.getValue());
254
255 if (!character.skulling.isSkulled()) {
256 keep.add(toDrop.pollFirst());
257 keep.add(toDrop.pollFirst());
258 keep.add(toDrop.pollFirst());
259 }
260
261 if (character.prayer.isActive(Prayer.PROTECT_ITEM)) {
262 keep.add(toDrop.pollFirst());
263 }
264
265 keep.forEach(item -> {
266 if (item == null) {
267 return;
268 }
269
270 character.inventory.add(new Item(item.getId()));
271 if (item.isStackable() && item.getAmount() > 1) {
272 toDrop.add(item.createAndDecrement(1));
273 }
274 });
275
276 if (theKiller.isBot) {
277 toDrop.forEach(item -> {
278 if (character.runecraftPouch.death(item))
279 return;
280
281 if (character.runePouch.death(item))
282 return;
283
284 if (!item.isTradeable()) {
285 if (!character.lostUntradeables.deposit(item)) {
286 GroundItem.create(character, item);
287 }
288 return;
289 }
290
291 if (theKiller.isBot && item.getValue() >= 50_000) {
292 return;
293 }
294
295 BotUtility.logLoot(item);
296 });
297
298 GroundItem drop = GroundItem.create(theKiller, new Item(526), character.getPosition());
299 if (!theKiller.equals(character) && PlayerRight.isIronman(theKiller)) {
300 drop.canIronMenPickThisItemUp = false;
301 }
302 return;
303 }
304
305 toDrop.forEach(item -> {
306 if (character.runecraftPouch.death(item))
307 return;
308
309 if (character.runePouch.death(item))
310 return;
311
312 if (purchase) {
313 character.lostItems.add(item);
314 return;
315 }
316
317 if (!item.isTradeable()) {
318 if (!character.lostUntradeables.deposit(item)) {
319 GroundItem.create(character, item);
320 }
321 return;
322 }
323
324 if (theKiller.isBot && item.getValue() >= 50_000) {
325 return;
326 }
327
328 switch(item.getId()) {
329 case CrawsBow.CRAWS_CHARGED_ID -> {
330 item.setId(CrawsBow.CRAWS_UNCHARGED_ID);
331 GroundItem drop = GroundItem.create(theKiller, new Item(CrawsBow.ETHER_ID, 1000 + character.crawsBowCharges), character.getPosition());
332 if (!theKiller.equals(character) && PlayerRight.isIronman(theKiller)) {
333 drop.canIronMenPickThisItemUp = false;
334 }
335 character.crawsBowCharges = 0;
336 }
337 case ViggorasChainmace.VIGGORAS_CHAINMACE_CHARGED_ID -> {
338 item.setId(ViggorasChainmace.VIGGORAS_CHAINMACE_UNCHARGED_ID);
339 GroundItem drop = GroundItem.create(theKiller, new Item(CrawsBow.ETHER_ID, 1000 + character.viggorasChainmaceCharges), character.getPosition());
340 if (!theKiller.equals(character) && PlayerRight.isIronman(theKiller)) {
341 drop.canIronMenPickThisItemUp = false;
342 }
343 character.viggorasChainmaceCharges = 0;
344 }
345 case ThammaronsSceptre.THAMMARONS_SCEPTRE_CHARGED_ID -> {
346 item.setId(ViggorasChainmace.VIGGORAS_CHAINMACE_UNCHARGED_ID);
347 GroundItem drop = GroundItem.create(theKiller, new Item(CrawsBow.ETHER_ID, 1000 + character.thammoranSceptreCharges), character.getPosition());
348 if (!theKiller.equals(character) && PlayerRight.isIronman(theKiller)) {
349 drop.canIronMenPickThisItemUp = false;
350 }
351 character.thammoranSceptreCharges = 0;
352 }
353 }
354
355 GroundItem drop = GroundItem.create(theKiller, item, character.getPosition());
356 if (!theKiller.equals(character) && PlayerRight.isIronman(theKiller)) {
357 drop.canIronMenPickThisItemUp = false;
358 }
359 });
360
361 GroundItem drop = GroundItem.create(theKiller, new Item(526), character.getPosition());
362 if (!theKiller.equals(character) && PlayerRight.isIronman(theKiller)) {
363 drop.canIronMenPickThisItemUp = false;
364 }
365 }
366
367}
static final Position DEFAULT_POSITION
Definition Config.java:235
static void activate(Player player, AchievementKey achievement)
static void onDeath(Player player, boolean forceRemove)
Definition LMSGame.java:671
static boolean inGameArea(Player player)
Definition LMSGame.java:179
static void onKill(Player killer)
Definition LMSGame.java:609
static boolean isActivePlayer(Player player)
Definition LMSGame.java:188
static void onDeath(Player player)
Definition Pets.java:179
static void sendMessage(String... messages)
Definition World.java:433
static void schedule(Task task)
Definition World.java:284
final void forEach(Consumer<? super Item > action)
static GroundItem create(Player player, Item item)
static< T > T randomElement(Collection< T > collection)
Definition Utility.java:285