RuneHive-Game
Loading...
Searching...
No Matches
PlayerDeath.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.mob.player;
2
3import com.runehive.Config;
4import com.runehive.content.achievement.AchievementHandler;
5import com.runehive.content.achievement.AchievementKey;
6import com.runehive.content.activity.Activity;
7import com.runehive.content.activity.ActivityDeathType;
8import com.runehive.content.bot.BotUtility;
9import com.runehive.content.bot.PlayerBot;
10import com.runehive.content.event.EventDispatcher;
11import com.runehive.content.event.impl.OnKillEvent;
12import com.runehive.content.itemaction.impl.CrawsBow;
13import com.runehive.content.itemaction.impl.ThammaronsSceptre;
14import com.runehive.content.itemaction.impl.ViggorasChainmace;
15import com.runehive.content.lms.LMSGame;
16import com.runehive.content.pet.Pets;
17import com.runehive.content.writer.InterfaceWriter;
18import com.runehive.content.writer.impl.InformationWriter;
19import com.runehive.game.Animation;
20import com.runehive.game.Graphic;
21import com.runehive.game.UpdatePriority;
22import com.runehive.game.world.World;
23import com.runehive.game.world.entity.combat.weapon.WeaponInterface;
24import com.runehive.game.world.entity.mob.Direction;
25import com.runehive.game.world.entity.mob.Mob;
26import com.runehive.game.world.entity.mob.MobDeath;
27import com.runehive.game.world.entity.mob.UpdateFlag;
28import com.runehive.game.world.entity.mob.prayer.Prayer;
29import com.runehive.game.world.items.Item;
30import com.runehive.game.world.items.ground.GroundItem;
31import com.runehive.game.world.position.Area;
32import com.runehive.game.world.position.Position;
33import com.runehive.net.packet.out.SendCameraReset;
34import com.runehive.net.packet.out.SendMessage;
35import com.runehive.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
43/**
44 * Handles the player death listener.
45 *
46 * @author Daniel
47 */
48public final class PlayerDeath extends MobDeath<Player> {
49 private boolean safe = false;
50
51 /** Array of all death messages. */
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
65 /** Creates a new {@link MobDeath}. */
67 super(mob, 2);
68 }
69
70 /** The part of the death process where the character is prepared for the rest of the death tick. */
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
77 /** The main part of the death process where the killer is found for the character. */
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
153 /** The last part of the death process where the character is reset. */
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>osroyale: <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
209 /** Calculates and drops all of the items from {@code character} for {@code killer}. */
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()) {
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 }
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 }
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}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final Position DEFAULT_POSITION
The default, i.e.
Definition Config.java:197
static void activate(Player player, AchievementKey achievement)
Activates the achievement for the individual player.
A Activity object constructs an in-game activity and sequences it through the start() and finish() me...
Definition Activity.java:31
static void forActivity(Mob mob, Consumer< Activity > consumer)
Definition Activity.java:78
Holds all the constants used by bot.
static void logLoot(Item item)
static boolean execute(Player player, InteractionEvent event)
static boolean isActivePlayer(Player player)
Checks if a player is a active player within the LMS game.
Definition LMSGame.java:151
static boolean inGameArea(Player player)
Handles checking if the player is in the LMS game area.
Definition LMSGame.java:142
static void onDeath(Player player, boolean forceRemove)
Handles when a player within the LMS game dies.
Definition LMSGame.java:634
static void onKill(Player killer)
Handles the killers stuff.
Definition LMSGame.java:572
Handles spawning, rewarding and picking up of pets.
Definition Pets.java:27
static void onDeath(Player player)
Handles what happens to a pet when a player dies.
Definition Pets.java:142
boolean death(Item item)
Handles player dying with a rune pouch.
Handles writing on an itemcontainer.
static void write(InterfaceWriter writer)
Class handles writing on the quest tab itemcontainer.
Class that models a single animation used by an entity.
static final Animation RESET
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
static final Graphic RESET
Definition Graphic.java:17
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
static void sendMessage(String... messages)
Sends a global message.
Definition World.java:396
MobDeath(T mob, int delay)
Creates a new MobDeath.
Definition MobDeath.java:24
Handles the mob class.
Definition Mob.java:66
final boolean isNpc()
Check if an entity is an npc.
Definition Mob.java:550
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
void calculateDropItems(Player character, Mob killer, boolean purchase)
Calculates and drops all of the items from character for killer.
void postDeath(Mob killer)
The last part of the death process where the character is reset.
static final String[] DEATH_MESSAGES
Array of all death messages.
void preDeath(Mob killer)
The part of the death process where the character is prepared for the rest of the death tick.
PlayerDeath(Player mob)
Creates a new MobDeath.
void death()
The main part of the death process where the killer is found for the character.
This class represents a character controlled by a player.
Definition Player.java:125
static boolean contains(Player player, String host)
static void handle(Player killer, Player victim)
boolean isActive(Prayer... prayers)
Checks if all given prayers are active.
The container class that represents an item that can be interacted with.
Definition Item.java:21
final void forEach(Consumer<? super Item > action)
Iterates through all of the Items within this container and performs action on them,...
boolean add(Item item)
Attempts to deposit item into this container.
void clear()
Removes all of the items from this container.
void clear()
Removes all of the items from this container.
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.
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inZulrah(Interactable entity)
Definition Area.java:320
Represents a single tile on the game world.
Definition Position.java:14
The OutgoingPacket resets the camera position for Player.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
Represents different priorities for updating.
The enumerated type whose elements represent the weapon interfaces.
static void execute(Player player, Item item)
The method executed when weapon item is equipped or unequipped that assigns a weapon interface to pla...
Represents the enumerated directions an entity can walk or face.
static boolean isIronman(Player player)
Checks if the player is an ironman.
static boolean isAdministrator(Player player)
Checks if the player is a privileged member.