Improved lootshare so that drops are awarded to clan members near a slain NPC, participation in combat is not necessary

Reconnecting in combat will no longer cause lost drops
This commit is contained in:
Player Name
2024-08-10 11:09:43 +00:00
committed by Ryan
parent d15b47fc65
commit 37836ae992
5 changed files with 49 additions and 30 deletions
@@ -263,7 +263,7 @@ public final class DuelSession extends ComponentPlugin {
Player o = getOpposite(p);
o.getImpactHandler().setDisabledTicks(6);
o.teleport(RandomFunction.getRandomElement(DuelArea.RESPAWN_LOCATIONS));
boolean victory = type == 0 || type == 2 || type == 1 && p.getImpactHandler().getImpactLog().containsKey(o);
boolean victory = type == 0 || type == 2 || type == 1 && p.getImpactHandler().getPlayerImpactLog().containsKey(o.getDetails().getUid());
fightState = 2;
p.removeExtension(DuelSession.class);
end();
@@ -82,8 +82,8 @@ public final class DeathTask extends NodeTask {
e.getProperties().setTeleportLocation(spawn);
e.unlock();
e.finalizeDeath(killer);
e.getImpactHandler().getImpactLog().clear();// check if this needs to be
// before finalize
e.getImpactHandler().getNpcImpactLog().clear();// check if this needs to be before finalize
e.getImpactHandler().getPlayerImpactLog().clear();// check if this needs to be before finalize
e.getImpactHandler().setDisabledTicks(4);
e.dispatch(new SelfDeathEvent(killer));
}
@@ -6,7 +6,6 @@ import core.game.node.entity.skill.Skills;
import content.global.skill.summoning.familiar.Familiar;
import content.global.skill.summoning.pet.Pet;
import core.game.node.entity.Entity;
import core.game.node.entity.npc.NPC;
import core.game.node.entity.player.Player;
import core.game.node.entity.player.link.prayer.PrayerType;
import core.game.node.item.Item;
@@ -14,13 +13,13 @@ import core.game.system.task.Pulse;
import core.game.bots.AIPlayer;
import core.game.world.GameWorld;
import core.game.world.map.zone.ZoneType;
import core.game.world.repository.Repository;
import org.rs09.consts.Items;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.stream.Collectors;
/**
* Class used for handling combat impacts.
@@ -39,9 +38,14 @@ public final class ImpactHandler {
private int disabledTicks;
/**
* The impact log.
* The NPC impact log.
*/
private final Map<Entity, Integer> impactLog = new HashMap<>();
private final Map<Entity, Integer> npcImpactLog = new HashMap<>();
/**
* The player impact log. This is by player uid to cope with players relogging.
*/
private final Map<Integer, Integer> playerImpactLog = new HashMap<>();
/**
* Gets the current hitsplats to show.
@@ -167,11 +171,14 @@ public final class ImpactHandler {
return null;
}
if (hit > 0) {
Integer value = impactLog.get(source);
if (value == null) {
value = 0;
if (source instanceof Player) {
int uid = source.asPlayer().getDetails().getUid();
Integer value = playerImpactLog.get(uid);
playerImpactLog.put(uid, value == null ? hit : hit + value);
} else {
Integer value = npcImpactLog.get(source);
npcImpactLog.put(source, value == null ? hit : hit + value);
}
impactLog.put(source, hit + value);
}
if (style != null && style.getSwingHandler() != null && source instanceof Player) {
Player player = source.asPlayer();
@@ -248,35 +255,47 @@ public final class ImpactHandler {
if (entity instanceof Player) {
return killer;
}
int damage = -1;
for (Entity e : impactLog.keySet()) {
if (e == this.entity) {
continue;
if (playerImpactLog.isEmpty()) {
for (Entity e : npcImpactLog.keySet()) {
if (e == this.entity) {
continue;
}
int amount = npcImpactLog.get(e);
if (amount > damage) {
damage = amount;
entity = e;
}
}
int amount = impactLog.get(e);
if (amount > damage || (entity instanceof NPC && e instanceof Player)) {
return entity;
}
int player = 0; //needs to be fake-initialized because java is dumb
for (int uid : playerImpactLog.keySet()) {
int amount = playerImpactLog.get(uid);
if (amount > damage) {
damage = amount;
entity = e;
player = uid;
}
}
return entity;
return Repository.getPlayerByUid(player);
}
/**
* Gets the impact log.
* @return The impact log.
* Gets the npc impact log.
* @return The npc impact log.
*/
public Map<Entity, Integer> getImpactLog() {
return impactLog;
public Map<Entity, Integer> getNpcImpactLog() {
return npcImpactLog;
}
/**
* Gets the impact log filtered for Player objects
* @return The impact log of each Player and their damage
* Gets the player impact log.
* @return The player impact log.
*/
public Map<Player, Integer> getPlayerImpactLog() {
return impactLog.entrySet().stream().filter(entry -> entry.getKey() instanceof Player).collect(
Collectors.toMap(m -> m.getKey().asPlayer(), m -> m.getValue()));
public Map<Integer, Integer> getPlayerImpactLog() {
return playerImpactLog;
}
/**
@@ -575,7 +575,7 @@ public class NPC extends Entity {
handleDrops(p, killer);
if (!isRespawn())
clear();
isRespawning = true;
isRespawning = true;
behavior.onDeathFinished(this, killer);
killer.dispatch(new NPCKillEvent(this));
setRespawnTick(GameWorld.getTicks() + definition.getConfiguration(NPCConfigParser.RESPAWN_DELAY, 17));
@@ -147,7 +147,7 @@ public final class NPCDropTables {
List<Player> players = RegionManager.getLocalPlayers(npc, 16);
List<Player> looters = new ArrayList<>(20);
for (Player p : players) {
if (p != null && p.getCommunication().getClan() != null && p.getCommunication().getClan() == player.getCommunication().getClan() && p.getCommunication().isLootShare() && p.getCommunication().getLootRequirement().ordinal() >= p.getCommunication().getClan().getLootRequirement().ordinal() && npc.getImpactHandler().getImpactLog().containsKey(p)) {
if (p != null && p.getCommunication().getClan() != null && p.getCommunication().getClan() == player.getCommunication().getClan() && p.getCommunication().isLootShare() && p.getCommunication().getLootRequirement().ordinal() >= p.getCommunication().getClan().getLootRequirement().ordinal() && !p.getIronmanManager().isIronman()) {
looters.add(p);
}
}