Refactor flinching
This commit is contained in:
@@ -50,7 +50,7 @@ public class FlinchingOverlay extends Overlay
|
|||||||
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)
|
||||||
|
|||||||
@@ -24,28 +24,28 @@
|
|||||||
*/
|
*/
|
||||||
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
|
||||||
@@ -73,7 +73,7 @@ public class FlinchingPlugin extends Plugin
|
|||||||
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;
|
||||||
@@ -111,11 +111,10 @@ public class FlinchingPlugin extends Plugin
|
|||||||
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 = it.next().getValue();
|
FlinchingTarget target = integerFlinchingTargetEntry.getValue();
|
||||||
if(target != null)
|
if (target != null)
|
||||||
{
|
{
|
||||||
target.SetDelayTime(config.getFlinchDelay(), config.getFlinchAttackedDelay());
|
target.SetDelayTime(config.getFlinchDelay(), config.getFlinchAttackedDelay());
|
||||||
}
|
}
|
||||||
@@ -152,16 +151,14 @@ public class FlinchingPlugin extends Plugin
|
|||||||
@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;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
TickTargets();
|
TickTargets();
|
||||||
checkInteracting();
|
checkInteracting();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onHitsplatApplied(HitsplatApplied hitsplatApplied)
|
public void onHitsplatApplied(HitsplatApplied hitsplatApplied)
|
||||||
@@ -173,7 +170,7 @@ public class FlinchingPlugin extends Plugin
|
|||||||
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))
|
||||||
{
|
{
|
||||||
@@ -182,9 +179,9 @@ public class FlinchingPlugin extends Plugin
|
|||||||
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();
|
||||||
}
|
}
|
||||||
@@ -192,7 +189,7 @@ public class FlinchingPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(resetOnHitReceived && actor == client.getLocalPlayer())
|
else if (resetOnHitReceived && actor == client.getLocalPlayer())
|
||||||
{
|
{
|
||||||
PlayerHit();
|
PlayerHit();
|
||||||
}
|
}
|
||||||
@@ -208,7 +205,7 @@ public class FlinchingPlugin extends Plugin
|
|||||||
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))
|
||||||
{
|
{
|
||||||
@@ -226,10 +223,10 @@ public class FlinchingPlugin extends Plugin
|
|||||||
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();
|
||||||
}
|
}
|
||||||
@@ -265,21 +262,20 @@ public class FlinchingPlugin extends Plugin
|
|||||||
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 = it.next().getValue();
|
FlinchingTarget target = integerFlinchingTargetEntry.getValue();
|
||||||
if(target != null)
|
if (target != null)
|
||||||
{
|
{
|
||||||
target.PlayerHit();
|
target.PlayerHit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, FlinchingTarget> GetTargets()
|
Map<Integer, FlinchingTarget> GetTargets()
|
||||||
{
|
{
|
||||||
return(flinchingTargets);
|
return (flinchingTargets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class FlinchingTarget
|
|||||||
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;
|
||||||
@@ -49,7 +49,7 @@ public class FlinchingTarget
|
|||||||
@Getter
|
@Getter
|
||||||
public WorldPoint worldLocation;
|
public WorldPoint worldLocation;
|
||||||
|
|
||||||
public FlinchingTarget(NPC target)
|
FlinchingTarget(NPC target)
|
||||||
{
|
{
|
||||||
isActive = true;
|
isActive = true;
|
||||||
|
|
||||||
@@ -59,18 +59,18 @@ public class FlinchingTarget
|
|||||||
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();
|
||||||
|
|
||||||
@@ -79,31 +79,31 @@ public class FlinchingTarget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -112,19 +112,19 @@ public class FlinchingTarget
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ public class FlinchingTarget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayerHit()
|
void PlayerHit()
|
||||||
{
|
{
|
||||||
usingHitDelay = true;
|
usingHitDelay = true;
|
||||||
currentDisplayLength = displayHitReceivedLength;
|
currentDisplayLength = displayHitReceivedLength;
|
||||||
|
|||||||
Reference in New Issue
Block a user