client: Damage in XP drop
This commit is contained in:
@@ -33,6 +33,13 @@ import net.runelite.client.config.Units;
|
|||||||
@ConfigGroup("xpdrop")
|
@ConfigGroup("xpdrop")
|
||||||
public interface XpDropConfig extends Config
|
public interface XpDropConfig extends Config
|
||||||
{
|
{
|
||||||
|
enum DamageMode
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
ABOVE_OPPONENT,
|
||||||
|
IN_XP_DROP;
|
||||||
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "hideSkillIcons",
|
keyName = "hideSkillIcons",
|
||||||
name = "Hide skill icons",
|
name = "Hide skill icons",
|
||||||
@@ -96,4 +103,26 @@ public interface XpDropConfig extends Config
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "showdamagedrops",
|
||||||
|
name = "Show Damage on XP Drop",
|
||||||
|
description = "Show what you hit next to the XP drop",
|
||||||
|
position = 5
|
||||||
|
)
|
||||||
|
default DamageMode showdamagedrops()
|
||||||
|
{
|
||||||
|
return DamageMode.NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "damageColor",
|
||||||
|
name = "Damage Color",
|
||||||
|
description = "The color you want the text to be for damage",
|
||||||
|
position = 6
|
||||||
|
)
|
||||||
|
default Color getDamageColor()
|
||||||
|
{
|
||||||
|
return Color.RED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, honeyhoney <https://github.com/honeyhoney>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.client.plugins.experiencedrop;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import net.runelite.api.Actor;
|
||||||
|
import net.runelite.api.Point;
|
||||||
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
|
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||||
|
import net.runelite.client.ui.overlay.OverlayPriority;
|
||||||
|
import net.runelite.client.ui.overlay.OverlayUtil;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class XpDropOverlay extends Overlay
|
||||||
|
{
|
||||||
|
private final XpDropPlugin plugin;
|
||||||
|
private final XpDropConfig config;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private XpDropOverlay(final XpDropPlugin plugin, final XpDropConfig config)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.config = config;
|
||||||
|
|
||||||
|
setPosition(OverlayPosition.DYNAMIC);
|
||||||
|
setPriority(OverlayPriority.MED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension render(Graphics2D graphics)
|
||||||
|
{
|
||||||
|
if (config.showdamagedrops() != XpDropConfig.DamageMode.ABOVE_OPPONENT)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.getTickShow() > 0)
|
||||||
|
{
|
||||||
|
final Actor opponent = plugin.getLastOpponent();
|
||||||
|
if (opponent != null)
|
||||||
|
{
|
||||||
|
int offset = opponent.getLogicalHeight() + 50;
|
||||||
|
String damageStr = String.valueOf(plugin.getDamage());
|
||||||
|
Point textLocation = opponent.getCanvasTextLocation(graphics, damageStr, offset);
|
||||||
|
|
||||||
|
if (textLocation != null && plugin.getDamage() != 0)
|
||||||
|
{
|
||||||
|
OverlayUtil.renderTextLocation(graphics, textLocation, damageStr, config.getDamageColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
package net.runelite.client.plugins.experiencedrop;
|
package net.runelite.client.plugins.experiencedrop;
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import com.openosrs.client.game.NPCManager;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
@@ -32,15 +33,23 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.runelite.api.Actor;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.EnumComposition;
|
import net.runelite.api.EnumComposition;
|
||||||
import net.runelite.api.EnumID;
|
import net.runelite.api.EnumID;
|
||||||
|
import net.runelite.api.NPC;
|
||||||
|
import net.runelite.api.Player;
|
||||||
import static net.runelite.api.ScriptID.XPDROPS_SETDROPSIZE;
|
import static net.runelite.api.ScriptID.XPDROPS_SETDROPSIZE;
|
||||||
import static net.runelite.api.ScriptID.XPDROP_DISABLED;
|
import static net.runelite.api.ScriptID.XPDROP_DISABLED;
|
||||||
import net.runelite.api.Skill;
|
import net.runelite.api.Skill;
|
||||||
import net.runelite.api.SpriteID;
|
import net.runelite.api.SpriteID;
|
||||||
import net.runelite.api.Varbits;
|
import net.runelite.api.Varbits;
|
||||||
|
import net.runelite.api.WorldType;
|
||||||
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.GameTick;
|
import net.runelite.api.events.GameTick;
|
||||||
|
import net.runelite.api.events.ScriptCallbackEvent;
|
||||||
import net.runelite.api.events.ScriptPreFired;
|
import net.runelite.api.events.ScriptPreFired;
|
||||||
import net.runelite.api.events.StatChanged;
|
import net.runelite.api.events.StatChanged;
|
||||||
import net.runelite.api.widgets.Widget;
|
import net.runelite.api.widgets.Widget;
|
||||||
@@ -48,6 +57,8 @@ import net.runelite.client.config.ConfigManager;
|
|||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
|
import net.runelite.client.ui.overlay.OverlayManager;
|
||||||
|
import net.runelite.client.util.ColorUtil;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "XP Drop",
|
name = "XP Drop",
|
||||||
@@ -56,12 +67,24 @@ import net.runelite.client.plugins.PluginDescriptor;
|
|||||||
)
|
)
|
||||||
public class XpDropPlugin extends Plugin
|
public class XpDropPlugin extends Plugin
|
||||||
{
|
{
|
||||||
|
private static final double HITPOINT_RATIO = 1.33; // Base rate of hp xp per point damage
|
||||||
|
private static final double DMM_MULTIPLIER_RATIO = 10;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private XpDropConfig config;
|
private XpDropConfig config;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private NPCManager npcManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private OverlayManager overlayManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private XpDropOverlay overlay;
|
||||||
|
|
||||||
private int tickCounter = 0;
|
private int tickCounter = 0;
|
||||||
private int previousExpGained;
|
private int previousExpGained;
|
||||||
private boolean hasDropped = false;
|
private boolean hasDropped = false;
|
||||||
@@ -69,12 +92,31 @@ public class XpDropPlugin extends Plugin
|
|||||||
private Skill lastSkill = null;
|
private Skill lastSkill = null;
|
||||||
private final Map<Skill, Integer> previousSkillExpTable = new EnumMap<>(Skill.class);
|
private final Map<Skill, Integer> previousSkillExpTable = new EnumMap<>(Skill.class);
|
||||||
|
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
private int damage = 0;
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
private int tickShow = 0;
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
private Actor lastOpponent;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
XpDropConfig provideConfig(ConfigManager configManager)
|
XpDropConfig provideConfig(ConfigManager configManager)
|
||||||
{
|
{
|
||||||
return configManager.getConfig(XpDropConfig.class);
|
return configManager.getConfig(XpDropConfig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void startUp() throws Exception
|
||||||
|
{
|
||||||
|
overlayManager.add(overlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void shutDown() throws Exception
|
||||||
|
{
|
||||||
|
overlayManager.remove(overlay);
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onScriptPreFired(ScriptPreFired scriptPreFired)
|
public void onScriptPreFired(ScriptPreFired scriptPreFired)
|
||||||
{
|
{
|
||||||
@@ -189,9 +231,23 @@ public class XpDropPlugin extends Plugin
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onGameStateChanged(GameStateChanged event)
|
||||||
|
{
|
||||||
|
tickShow = 0;
|
||||||
|
damage = 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameTick(GameTick tick)
|
public void onGameTick(GameTick tick)
|
||||||
{
|
{
|
||||||
|
lastOpponent = client.getLocalPlayer().getInteracting();
|
||||||
|
|
||||||
|
if (tickShow > 0)
|
||||||
|
{
|
||||||
|
tickShow--;
|
||||||
|
}
|
||||||
|
|
||||||
correctPrayer = false;
|
correctPrayer = false;
|
||||||
|
|
||||||
final int fakeTickDelay = config.fakeXpDropDelay();
|
final int fakeTickDelay = config.fakeXpDropDelay();
|
||||||
@@ -233,4 +289,96 @@ public class XpDropPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onScriptCallbackEvent(ScriptCallbackEvent e)
|
||||||
|
{
|
||||||
|
if (config.showdamagedrops() == XpDropConfig.DamageMode.NONE)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String eventName = e.getEventName();
|
||||||
|
|
||||||
|
if (eventName.equals("newXpDrop"))
|
||||||
|
{
|
||||||
|
damage = 0;
|
||||||
|
}
|
||||||
|
// Handles Fake XP drops (Ironman, DMM Cap, 200m xp, etc)
|
||||||
|
else if (eventName.equals("fakeXpDrop"))
|
||||||
|
{
|
||||||
|
final int[] intStack = client.getIntStack();
|
||||||
|
final int intStackSize = client.getIntStackSize();
|
||||||
|
|
||||||
|
final int skillId = intStack[intStackSize - 2];
|
||||||
|
final Skill skill = Skill.values()[skillId];
|
||||||
|
|
||||||
|
if (skill.equals(Skill.HITPOINTS))
|
||||||
|
{
|
||||||
|
final int exp = intStack[intStackSize - 1];
|
||||||
|
calculateDamageDealt(exp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (eventName.equals("hpXpGained"))
|
||||||
|
{
|
||||||
|
final int[] intStack = client.getIntStack();
|
||||||
|
final int intStackSize = client.getIntStackSize();
|
||||||
|
|
||||||
|
final int exp = intStack[intStackSize - 1];
|
||||||
|
calculateDamageDealt(exp);
|
||||||
|
}
|
||||||
|
else if (eventName.equals("xpDropAddDamage")
|
||||||
|
&& config.showdamagedrops() == XpDropConfig.DamageMode.IN_XP_DROP
|
||||||
|
&& damage > 0)
|
||||||
|
{
|
||||||
|
final String[] stringStack = client.getStringStack();
|
||||||
|
final int stringStackSize = client.getStringStackSize();
|
||||||
|
|
||||||
|
String builder =
|
||||||
|
stringStack[stringStackSize - 1]
|
||||||
|
+ ColorUtil.colorTag(config.getDamageColor())
|
||||||
|
+ " ("
|
||||||
|
+ damage
|
||||||
|
+ ")";
|
||||||
|
stringStack[stringStackSize - 1] = builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateDamageDealt(int diff)
|
||||||
|
{
|
||||||
|
double damageDealt = diff / HITPOINT_RATIO;
|
||||||
|
|
||||||
|
// DeadMan mode has an XP modifier
|
||||||
|
if (client.getWorldType().contains(WorldType.DEADMAN))
|
||||||
|
{
|
||||||
|
damageDealt = damageDealt / DMM_MULTIPLIER_RATIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some NPCs have an XP modifier, account for it here.
|
||||||
|
Actor a = client.getLocalPlayer().getInteracting();
|
||||||
|
if (!(a instanceof NPC) && !(a instanceof Player))
|
||||||
|
{
|
||||||
|
// If we are interacting with nothing we may have clicked away at the perfect time fall back
|
||||||
|
// to last tick
|
||||||
|
if (!(lastOpponent instanceof NPC) && !(lastOpponent instanceof Player))
|
||||||
|
{
|
||||||
|
damage = (int) Math.rint(damageDealt);
|
||||||
|
tickShow = 3;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
a = lastOpponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a instanceof Player)
|
||||||
|
{
|
||||||
|
damage = (int) Math.rint(damageDealt);
|
||||||
|
tickShow = 3;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NPC target = (NPC) a;
|
||||||
|
damage = (int) Math.rint(damageDealt / npcManager.getXpModifier(target.getId()));
|
||||||
|
tickShow = 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user