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