Refactor flinching
This commit is contained in:
@@ -32,75 +32,75 @@ import net.runelite.client.config.ConfigItem;
|
|||||||
@ConfigGroup("flinching")
|
@ConfigGroup("flinching")
|
||||||
public interface FlinchingConfig extends Config
|
public interface FlinchingConfig extends Config
|
||||||
{
|
{
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
|
|
||||||
position = 0,
|
position = 0,
|
||||||
keyName = "hexColorFlinch",
|
keyName = "hexColorFlinch",
|
||||||
name = "Overlay Color",
|
name = "Overlay Color",
|
||||||
description = "Color of flinching timer overlay"
|
description = "Color of flinching timer overlay"
|
||||||
)
|
)
|
||||||
default Color getFlinchOverlayColor()
|
default Color getFlinchOverlayColor()
|
||||||
{
|
{
|
||||||
return Color.CYAN;
|
return Color.CYAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
|
|
||||||
position = 1,
|
position = 1,
|
||||||
keyName = "flinchOverlaySize",
|
keyName = "flinchOverlaySize",
|
||||||
name = "Overlay Diameter",
|
name = "Overlay Diameter",
|
||||||
description = "Flinch overlay timer diameter"
|
description = "Flinch overlay timer diameter"
|
||||||
)
|
)
|
||||||
default int getFlinchOverlaySize()
|
default int getFlinchOverlaySize()
|
||||||
{
|
{
|
||||||
return 30;
|
return 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
|
|
||||||
position = 2,
|
position = 2,
|
||||||
keyName = "flinchDelay",
|
keyName = "flinchDelay",
|
||||||
name = "Flinch Timer Delay",
|
name = "Flinch Timer Delay",
|
||||||
description = "Shows the appropriate time to attack while flinching milliseconds"
|
description = "Shows the appropriate time to attack while flinching milliseconds"
|
||||||
)
|
)
|
||||||
default int getFlinchDelay()
|
default int getFlinchDelay()
|
||||||
{
|
{
|
||||||
return 5400;
|
return 5400;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
|
|
||||||
position = 3,
|
position = 3,
|
||||||
keyName = "flinchOnHitReceivedDelay",
|
keyName = "flinchOnHitReceivedDelay",
|
||||||
name = "Flinch Hit Received Delay",
|
name = "Flinch Hit Received Delay",
|
||||||
description = "Slightly longer delay after being attacked milliseconds"
|
description = "Slightly longer delay after being attacked milliseconds"
|
||||||
)
|
)
|
||||||
default int getFlinchAttackedDelay()
|
default int getFlinchAttackedDelay()
|
||||||
{
|
{
|
||||||
return 6600;
|
return 6600;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
|
|
||||||
position = 4,
|
position = 4,
|
||||||
keyName = "flinchResetOnHit",
|
keyName = "flinchResetOnHit",
|
||||||
name = "Reset on Hit",
|
name = "Reset on Hit",
|
||||||
description = "Timer resets after every attack from your character"
|
description = "Timer resets after every attack from your character"
|
||||||
)
|
)
|
||||||
default boolean getFlinchResetOnHit()
|
default boolean getFlinchResetOnHit()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
|
|
||||||
position = 5,
|
position = 5,
|
||||||
keyName = "flinchResetOnHitReceived",
|
keyName = "flinchResetOnHitReceived",
|
||||||
name = "Reset on Hit Received",
|
name = "Reset on Hit Received",
|
||||||
description = "Timer resets when your character gets attacked"
|
description = "Timer resets when your character gets attacked"
|
||||||
)
|
)
|
||||||
default boolean getFlinchResetOnHitReceived()
|
default boolean getFlinchResetOnHitReceived()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,74 +43,74 @@ import net.runelite.client.ui.overlay.components.ProgressPieComponent;
|
|||||||
|
|
||||||
public class FlinchingOverlay extends Overlay
|
public class FlinchingOverlay extends Overlay
|
||||||
{
|
{
|
||||||
private final Client client;
|
private final Client client;
|
||||||
private final FlinchingPlugin plugin;
|
private final FlinchingPlugin plugin;
|
||||||
private final FlinchingConfig config;
|
private final FlinchingConfig config;
|
||||||
|
|
||||||
private Color color;
|
private Color color;
|
||||||
private Color borderColor;
|
private Color borderColor;
|
||||||
|
|
||||||
private int overlaySize = 25;
|
private int overlaySize;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FlinchingOverlay(Client client, FlinchingPlugin plugin, FlinchingConfig config)
|
FlinchingOverlay(Client client, FlinchingPlugin plugin, FlinchingConfig config)
|
||||||
{
|
{
|
||||||
setPosition(OverlayPosition.DYNAMIC);
|
setPosition(OverlayPosition.DYNAMIC);
|
||||||
setLayer(OverlayLayer.ABOVE_SCENE);
|
setLayer(OverlayLayer.ABOVE_SCENE);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
overlaySize = this.config.getFlinchOverlaySize();
|
overlaySize = this.config.getFlinchOverlaySize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics)
|
public Dimension render(Graphics2D graphics)
|
||||||
{
|
{
|
||||||
drawOverlays(graphics);
|
drawOverlays(graphics);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateConfig()
|
public void updateConfig()
|
||||||
{
|
{
|
||||||
borderColor = config.getFlinchOverlayColor();
|
borderColor = config.getFlinchOverlayColor();
|
||||||
color = new Color(borderColor.getRed(), borderColor.getGreen(), borderColor.getBlue(), 100);
|
color = new Color(borderColor.getRed(), borderColor.getGreen(), borderColor.getBlue(), 100);
|
||||||
|
|
||||||
overlaySize = config.getFlinchOverlaySize();
|
overlaySize = config.getFlinchOverlaySize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawOverlays(Graphics2D graphics)
|
private void drawOverlays(Graphics2D graphics)
|
||||||
{
|
{
|
||||||
for (Map.Entry<Integer, FlinchingTarget> entry : plugin.GetTargets().entrySet())
|
for (Map.Entry<Integer, FlinchingTarget> entry : plugin.GetTargets().entrySet())
|
||||||
{
|
{
|
||||||
FlinchingTarget target = entry.getValue();
|
FlinchingTarget target = entry.getValue();
|
||||||
|
|
||||||
drawFlinchTimer(graphics, target.worldLocation, target.GetRemainingTimePercent());
|
drawFlinchTimer(graphics, target.worldLocation, target.GetRemainingTimePercent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void drawFlinchTimer(Graphics2D graphics, WorldPoint targetLocation, double fillAmount)
|
private void drawFlinchTimer(Graphics2D graphics, WorldPoint targetLocation, double fillAmount)
|
||||||
{
|
{
|
||||||
if (targetLocation.getPlane() != client.getPlane())
|
if (targetLocation.getPlane() != client.getPlane())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalPoint localLoc = LocalPoint.fromWorld(client, targetLocation);
|
LocalPoint localLoc = LocalPoint.fromWorld(client, targetLocation);
|
||||||
if (localLoc == null)
|
if (localLoc == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point loc = Perspective.localToCanvas(client, localLoc, client.getPlane());
|
Point loc = Perspective.localToCanvas(client, localLoc, client.getPlane());
|
||||||
|
|
||||||
ProgressPieComponent pie = new ProgressPieComponent();
|
ProgressPieComponent pie = new ProgressPieComponent();
|
||||||
pie.setDiameter(overlaySize);
|
pie.setDiameter(overlaySize);
|
||||||
pie.setFill(color);
|
pie.setFill(color);
|
||||||
pie.setBorderColor(borderColor);
|
pie.setBorderColor(borderColor);
|
||||||
pie.setPosition(loc);
|
pie.setPosition(loc);
|
||||||
pie.setProgress(fillAmount);
|
pie.setProgress(fillAmount);
|
||||||
pie.render(graphics);
|
pie.render(graphics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,262 +24,258 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.flinching;
|
package net.runelite.client.plugins.flinching;
|
||||||
|
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
import com.google.inject.Provides;
|
||||||
import net.runelite.api.Client;
|
|
||||||
import net.runelite.api.Player;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import javax.inject.Inject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.runelite.api.Actor;
|
||||||
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.GameState;
|
||||||
|
import net.runelite.api.NPC;
|
||||||
|
import net.runelite.api.Player;
|
||||||
|
import net.runelite.api.events.ConfigChanged;
|
||||||
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.GameTick;
|
import net.runelite.api.events.GameTick;
|
||||||
|
import net.runelite.api.events.HitsplatApplied;
|
||||||
|
import net.runelite.api.events.NpcDespawned;
|
||||||
|
import net.runelite.client.config.ConfigManager;
|
||||||
|
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.plugins.PluginType;
|
import net.runelite.client.plugins.PluginType;
|
||||||
import net.runelite.client.ui.overlay.OverlayManager;
|
import net.runelite.client.ui.overlay.OverlayManager;
|
||||||
import javax.inject.Inject;
|
|
||||||
import net.runelite.api.Actor;
|
|
||||||
import net.runelite.api.NPC;
|
|
||||||
import net.runelite.api.GameState;
|
|
||||||
import net.runelite.api.events.GameStateChanged;
|
|
||||||
import net.runelite.api.events.NpcDespawned;
|
|
||||||
import net.runelite.client.config.ConfigManager;
|
|
||||||
import net.runelite.api.events.ConfigChanged;
|
|
||||||
import net.runelite.api.events.HitsplatApplied;
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Flinching Timer",
|
name = "Flinching Timer",
|
||||||
description = "Time your attacks while flinching",
|
description = "Time your attacks while flinching",
|
||||||
tags = {"overlay", "flinching", "timers", "combat"},
|
tags = {"overlay", "flinching", "timers", "combat"},
|
||||||
enabledByDefault = false,
|
enabledByDefault = false,
|
||||||
type = PluginType.PVM
|
type = PluginType.PVM
|
||||||
)
|
)
|
||||||
public class FlinchingPlugin extends Plugin
|
public class FlinchingPlugin extends Plugin
|
||||||
{
|
{
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private OverlayManager overlayManager;
|
private OverlayManager overlayManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private FlinchingConfig config;
|
private FlinchingConfig config;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private FlinchingOverlay overlay;
|
private FlinchingOverlay overlay;
|
||||||
|
|
||||||
private int currentWorld = -1;
|
private int currentWorld = -1;
|
||||||
|
|
||||||
private int currentInteractingId = -1;
|
private int currentInteractingId = -1;
|
||||||
private final Map<Integer, FlinchingTarget> flinchingTargets = new HashMap<Integer, FlinchingTarget>();
|
private final Map<Integer, FlinchingTarget> flinchingTargets = new HashMap<>();
|
||||||
|
|
||||||
private boolean resetOnHit = true;
|
private boolean resetOnHit = true;
|
||||||
private boolean resetOnHitReceived = true;
|
private boolean resetOnHitReceived = true;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
FlinchingConfig provideConfig(ConfigManager configManager)
|
FlinchingConfig provideConfig(ConfigManager configManager)
|
||||||
{
|
{
|
||||||
return configManager.getConfig(FlinchingConfig.class);
|
return configManager.getConfig(FlinchingConfig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp()
|
protected void startUp()
|
||||||
{
|
{
|
||||||
overlayManager.add(overlay);
|
overlayManager.add(overlay);
|
||||||
|
|
||||||
overlay.updateConfig();
|
overlay.updateConfig();
|
||||||
resetOnHit = config.getFlinchResetOnHit();
|
resetOnHit = config.getFlinchResetOnHit();
|
||||||
resetOnHitReceived = config.getFlinchResetOnHitReceived();
|
resetOnHitReceived = config.getFlinchResetOnHitReceived();
|
||||||
|
|
||||||
ClearTargets();
|
ClearTargets();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutDown()
|
protected void shutDown()
|
||||||
{
|
{
|
||||||
ClearTargets();
|
ClearTargets();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onConfigChanged(ConfigChanged event)
|
public void onConfigChanged(ConfigChanged event)
|
||||||
{
|
{
|
||||||
if (event.getGroup().equals("flinching"))
|
if (event.getGroup().equals("flinching"))
|
||||||
{
|
{
|
||||||
overlay.updateConfig();
|
overlay.updateConfig();
|
||||||
resetOnHit = config.getFlinchResetOnHit();
|
resetOnHit = config.getFlinchResetOnHit();
|
||||||
resetOnHitReceived = config.getFlinchResetOnHitReceived();
|
resetOnHitReceived = config.getFlinchResetOnHitReceived();
|
||||||
|
|
||||||
Iterator<Map.Entry<Integer, FlinchingTarget>> it = flinchingTargets.entrySet().iterator();
|
for (Map.Entry<Integer, FlinchingTarget> integerFlinchingTargetEntry : flinchingTargets.entrySet())
|
||||||
while (it.hasNext())
|
{
|
||||||
{
|
FlinchingTarget target = integerFlinchingTargetEntry.getValue();
|
||||||
FlinchingTarget target = it.next().getValue();
|
if (target != null)
|
||||||
if(target != null)
|
{
|
||||||
{
|
target.SetDelayTime(config.getFlinchDelay(), config.getFlinchAttackedDelay());
|
||||||
target.SetDelayTime(config.getFlinchDelay(), config.getFlinchAttackedDelay());
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameStateChanged(GameStateChanged event)
|
public void onGameStateChanged(GameStateChanged event)
|
||||||
{
|
{
|
||||||
if (event.getGameState() == GameState.LOGGED_IN)
|
if (event.getGameState() == GameState.LOGGED_IN)
|
||||||
{
|
{
|
||||||
if (currentWorld == -1)
|
if (currentWorld == -1)
|
||||||
{
|
{
|
||||||
currentWorld = client.getWorld();
|
currentWorld = client.getWorld();
|
||||||
}
|
}
|
||||||
else if (currentWorld != client.getWorld())
|
else if (currentWorld != client.getWorld())
|
||||||
{
|
{
|
||||||
ClearTargets();
|
ClearTargets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearTargets()
|
private void ClearTargets()
|
||||||
{
|
{
|
||||||
Iterator<Map.Entry<Integer, FlinchingTarget>> it = flinchingTargets.entrySet().iterator();
|
Iterator<Map.Entry<Integer, FlinchingTarget>> it = flinchingTargets.entrySet().iterator();
|
||||||
|
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void onGameTick(GameTick tick)
|
private void onGameTick(GameTick tick)
|
||||||
{
|
{
|
||||||
if (client.getGameState() != GameState.LOGGED_IN)
|
if (client.getGameState() == GameState.LOGGED_IN)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
TickTargets();
|
||||||
else
|
checkInteracting();
|
||||||
{
|
}
|
||||||
TickTargets();
|
|
||||||
checkInteracting();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onHitsplatApplied(HitsplatApplied hitsplatApplied)
|
public void onHitsplatApplied(HitsplatApplied hitsplatApplied)
|
||||||
{
|
{
|
||||||
Actor actor = hitsplatApplied.getActor();
|
Actor actor = hitsplatApplied.getActor();
|
||||||
|
|
||||||
if (actor instanceof NPC)
|
if (actor instanceof NPC)
|
||||||
{
|
{
|
||||||
NPC hitTarget = (NPC) actor;
|
NPC hitTarget = (NPC) actor;
|
||||||
|
|
||||||
int hitId = hitTarget.getId();
|
int hitId = hitTarget.getId();
|
||||||
if(hitId == currentInteractingId)
|
if (hitId == currentInteractingId)
|
||||||
{
|
{
|
||||||
if (!flinchingTargets.containsKey(hitId))
|
if (!flinchingTargets.containsKey(hitId))
|
||||||
{
|
{
|
||||||
TargetGained(hitTarget);
|
TargetGained(hitTarget);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FlinchingTarget currentTarget = flinchingTargets.get(hitId);
|
FlinchingTarget currentTarget = flinchingTargets.get(hitId);
|
||||||
if(currentTarget != null)
|
if (currentTarget != null)
|
||||||
{
|
{
|
||||||
if(resetOnHit)
|
if (resetOnHit)
|
||||||
{
|
{
|
||||||
currentTarget.TargetHit();
|
currentTarget.TargetHit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(resetOnHitReceived && actor == client.getLocalPlayer())
|
else if (resetOnHitReceived && actor == client.getLocalPlayer())
|
||||||
{
|
{
|
||||||
PlayerHit();
|
PlayerHit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkInteracting()
|
private void checkInteracting()
|
||||||
{
|
{
|
||||||
Player localPlayer = client.getLocalPlayer();
|
Player localPlayer = client.getLocalPlayer();
|
||||||
Actor interacting = localPlayer.getInteracting();
|
Actor interacting = localPlayer.getInteracting();
|
||||||
|
|
||||||
if (interacting instanceof NPC)
|
if (interacting instanceof NPC)
|
||||||
{
|
{
|
||||||
NPC newTarget = (NPC) interacting;
|
NPC newTarget = (NPC) interacting;
|
||||||
currentInteractingId = newTarget.getId();
|
currentInteractingId = newTarget.getId();
|
||||||
|
|
||||||
if(newTarget.getHealth() <= 0 || newTarget.isDead())
|
if (newTarget.getHealth() <= 0 || newTarget.isDead())
|
||||||
{
|
{
|
||||||
if (flinchingTargets.containsKey(currentInteractingId))
|
if (flinchingTargets.containsKey(currentInteractingId))
|
||||||
{
|
{
|
||||||
flinchingTargets.remove(currentInteractingId);
|
flinchingTargets.remove(currentInteractingId);
|
||||||
currentInteractingId = -1;
|
currentInteractingId = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TickTargets()
|
private void TickTargets()
|
||||||
{
|
{
|
||||||
Iterator<Map.Entry<Integer, FlinchingTarget>> it = flinchingTargets.entrySet().iterator();
|
Iterator<Map.Entry<Integer, FlinchingTarget>> it = flinchingTargets.entrySet().iterator();
|
||||||
|
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
FlinchingTarget target = it.next().getValue();
|
FlinchingTarget target = it.next().getValue();
|
||||||
if(target != null)
|
if (target != null)
|
||||||
{
|
{
|
||||||
target.Tick();
|
target.Tick();
|
||||||
if(target.isActive == false)
|
if (!target.isActive)
|
||||||
{
|
{
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onNpcDespawned(NpcDespawned npcDespawned)
|
public void onNpcDespawned(NpcDespawned npcDespawned)
|
||||||
{
|
{
|
||||||
NPC actor = npcDespawned.getNpc();
|
NPC actor = npcDespawned.getNpc();
|
||||||
|
|
||||||
int actorId = actor.getId();
|
int actorId = actor.getId();
|
||||||
if (actor.isDead() && flinchingTargets.containsKey(actorId))
|
if (actor.isDead() && flinchingTargets.containsKey(actorId))
|
||||||
{
|
{
|
||||||
TargetLost(actorId);
|
TargetLost(actorId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TargetLost(int targetId)
|
private void TargetLost(int targetId)
|
||||||
{
|
{
|
||||||
flinchingTargets.remove(targetId);
|
flinchingTargets.remove(targetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TargetGained(NPC _newTarget)
|
private void TargetGained(NPC _newTarget)
|
||||||
{
|
{
|
||||||
FlinchingTarget newTarget = new FlinchingTarget(_newTarget);
|
FlinchingTarget newTarget = new FlinchingTarget(_newTarget);
|
||||||
newTarget.SetDelayTime(config.getFlinchDelay(), config.getFlinchAttackedDelay());
|
newTarget.SetDelayTime(config.getFlinchDelay(), config.getFlinchAttackedDelay());
|
||||||
flinchingTargets.put(_newTarget.getId(), newTarget);
|
flinchingTargets.put(_newTarget.getId(), newTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayerHit()
|
private void PlayerHit()
|
||||||
{
|
{
|
||||||
Iterator<Map.Entry<Integer, FlinchingTarget>> it = flinchingTargets.entrySet().iterator();
|
for (Map.Entry<Integer, FlinchingTarget> integerFlinchingTargetEntry : flinchingTargets.entrySet())
|
||||||
while (it.hasNext())
|
{
|
||||||
{
|
FlinchingTarget target = integerFlinchingTargetEntry.getValue();
|
||||||
FlinchingTarget target = it.next().getValue();
|
if (target != null)
|
||||||
if(target != null)
|
{
|
||||||
{
|
target.PlayerHit();
|
||||||
target.PlayerHit();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Integer, FlinchingTarget> GetTargets()
|
Map<Integer, FlinchingTarget> GetTargets()
|
||||||
{
|
{
|
||||||
return(flinchingTargets);
|
return (flinchingTargets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,113 +32,113 @@ import net.runelite.api.coords.WorldPoint;
|
|||||||
|
|
||||||
public class FlinchingTarget
|
public class FlinchingTarget
|
||||||
{
|
{
|
||||||
private int currentDisplayLength = 5400;
|
private int currentDisplayLength = 5400;
|
||||||
|
|
||||||
private boolean usingHitDelay = false;
|
private boolean usingHitDelay = false;
|
||||||
|
|
||||||
private int displayLength = 5400;
|
private int displayLength = 5400;
|
||||||
private int displayHitReceivedLength = 6600;
|
private int displayHitReceivedLength = 6600;
|
||||||
private Instant lastAttacked;
|
private Instant lastAttacked;
|
||||||
|
|
||||||
public boolean isActive = false;
|
public boolean isActive;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private int objectId;
|
private int objectId;
|
||||||
private NPC targetObject;
|
private NPC targetObject;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public WorldPoint worldLocation;
|
public WorldPoint worldLocation;
|
||||||
|
|
||||||
public FlinchingTarget(NPC target)
|
FlinchingTarget(NPC target)
|
||||||
{
|
{
|
||||||
isActive = true;
|
isActive = true;
|
||||||
|
|
||||||
this.targetObject = target;
|
this.targetObject = target;
|
||||||
this.lastAttacked = Instant.now();
|
this.lastAttacked = Instant.now();
|
||||||
this.objectId = target.getId();
|
this.objectId = target.getId();
|
||||||
this.worldLocation = target.getWorldLocation();
|
this.worldLocation = target.getWorldLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TargetHit()
|
void TargetHit()
|
||||||
{
|
{
|
||||||
boolean shouldHit = true;
|
boolean shouldHit = true;
|
||||||
if(usingHitDelay)
|
if (usingHitDelay)
|
||||||
{
|
{
|
||||||
if(GetRemainingTime() > displayLength)
|
if (GetRemainingTime() > displayLength)
|
||||||
{
|
{
|
||||||
shouldHit = false;
|
shouldHit = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(shouldHit)
|
if (shouldHit)
|
||||||
{
|
{
|
||||||
lastAttacked = Instant.now();
|
lastAttacked = Instant.now();
|
||||||
|
|
||||||
usingHitDelay = false;
|
usingHitDelay = false;
|
||||||
currentDisplayLength = displayLength;
|
currentDisplayLength = displayLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double GetRemainingTimePercent()
|
double GetRemainingTimePercent()
|
||||||
{
|
{
|
||||||
double remainingTime = GetRemainingTime();
|
double remainingTime = GetRemainingTime();
|
||||||
double timePercent = remainingTime / currentDisplayLength;
|
double timePercent = remainingTime / currentDisplayLength;
|
||||||
if(timePercent < 0)
|
if (timePercent < 0)
|
||||||
{
|
{
|
||||||
timePercent = 0;
|
timePercent = 0;
|
||||||
}
|
}
|
||||||
else if(timePercent > 1)
|
else if (timePercent > 1)
|
||||||
{
|
{
|
||||||
timePercent = 1;
|
timePercent = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(timePercent);
|
return (timePercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double GetRemainingTime()
|
private double GetRemainingTime()
|
||||||
{
|
{
|
||||||
Duration duration = Duration.between(lastAttacked, Instant.now());
|
Duration duration = Duration.between(lastAttacked, Instant.now());
|
||||||
return( (currentDisplayLength - ((double)duration.toMillis())));
|
return ((currentDisplayLength - ((double) duration.toMillis())));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
void Tick()
|
||||||
{
|
{
|
||||||
if(targetObject == null)
|
if (targetObject == null)
|
||||||
{
|
{
|
||||||
isActive = false;
|
isActive = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
worldLocation = targetObject.getWorldLocation();
|
worldLocation = targetObject.getWorldLocation();
|
||||||
|
|
||||||
double remainingTime = GetRemainingTime();
|
double remainingTime = GetRemainingTime();
|
||||||
if(remainingTime <= 0)
|
if (remainingTime <= 0)
|
||||||
{
|
{
|
||||||
isActive = false;
|
isActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetDelayTime(int delayTime, int delayHitReceivedTime)
|
void SetDelayTime(int delayTime, int delayHitReceivedTime)
|
||||||
{
|
{
|
||||||
displayLength = delayTime;
|
displayLength = delayTime;
|
||||||
displayHitReceivedLength = delayHitReceivedTime;
|
displayHitReceivedLength = delayHitReceivedTime;
|
||||||
|
|
||||||
if(usingHitDelay)
|
if (usingHitDelay)
|
||||||
{
|
{
|
||||||
currentDisplayLength = displayHitReceivedLength;
|
currentDisplayLength = displayHitReceivedLength;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentDisplayLength = displayLength;
|
currentDisplayLength = displayLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayerHit()
|
void PlayerHit()
|
||||||
{
|
{
|
||||||
usingHitDelay = true;
|
usingHitDelay = true;
|
||||||
currentDisplayLength = displayHitReceivedLength;
|
currentDisplayLength = displayHitReceivedLength;
|
||||||
|
|
||||||
lastAttacked = Instant.now();
|
lastAttacked = Instant.now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user