Refactor flinching
This commit is contained in:
@@ -50,7 +50,7 @@ public class FlinchingOverlay extends Overlay
|
||||
private Color color;
|
||||
private Color borderColor;
|
||||
|
||||
private int overlaySize = 25;
|
||||
private int overlaySize;
|
||||
|
||||
@Inject
|
||||
FlinchingOverlay(Client client, FlinchingPlugin plugin, FlinchingConfig config)
|
||||
|
||||
@@ -24,28 +24,28 @@
|
||||
*/
|
||||
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
|
||||
@@ -73,7 +73,7 @@ public class FlinchingPlugin extends Plugin
|
||||
private int currentWorld = -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 resetOnHitReceived = true;
|
||||
@@ -111,11 +111,10 @@ public class FlinchingPlugin extends Plugin
|
||||
resetOnHit = config.getFlinchResetOnHit();
|
||||
resetOnHitReceived = config.getFlinchResetOnHitReceived();
|
||||
|
||||
Iterator<Map.Entry<Integer, FlinchingTarget>> it = flinchingTargets.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
for (Map.Entry<Integer, FlinchingTarget> integerFlinchingTargetEntry : flinchingTargets.entrySet())
|
||||
{
|
||||
FlinchingTarget target = it.next().getValue();
|
||||
if(target != null)
|
||||
FlinchingTarget target = integerFlinchingTargetEntry.getValue();
|
||||
if (target != null)
|
||||
{
|
||||
target.SetDelayTime(config.getFlinchDelay(), config.getFlinchAttackedDelay());
|
||||
}
|
||||
@@ -152,16 +151,14 @@ public class FlinchingPlugin extends Plugin
|
||||
@Subscribe
|
||||
private void onGameTick(GameTick tick)
|
||||
{
|
||||
if (client.getGameState() != GameState.LOGGED_IN)
|
||||
if (client.getGameState() == GameState.LOGGED_IN)
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
TickTargets();
|
||||
checkInteracting();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onHitsplatApplied(HitsplatApplied hitsplatApplied)
|
||||
@@ -173,7 +170,7 @@ public class FlinchingPlugin extends Plugin
|
||||
NPC hitTarget = (NPC) actor;
|
||||
|
||||
int hitId = hitTarget.getId();
|
||||
if(hitId == currentInteractingId)
|
||||
if (hitId == currentInteractingId)
|
||||
{
|
||||
if (!flinchingTargets.containsKey(hitId))
|
||||
{
|
||||
@@ -182,9 +179,9 @@ public class FlinchingPlugin extends Plugin
|
||||
else
|
||||
{
|
||||
FlinchingTarget currentTarget = flinchingTargets.get(hitId);
|
||||
if(currentTarget != null)
|
||||
if (currentTarget != null)
|
||||
{
|
||||
if(resetOnHit)
|
||||
if (resetOnHit)
|
||||
{
|
||||
currentTarget.TargetHit();
|
||||
}
|
||||
@@ -192,7 +189,7 @@ public class FlinchingPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(resetOnHitReceived && actor == client.getLocalPlayer())
|
||||
else if (resetOnHitReceived && actor == client.getLocalPlayer())
|
||||
{
|
||||
PlayerHit();
|
||||
}
|
||||
@@ -208,7 +205,7 @@ public class FlinchingPlugin extends Plugin
|
||||
NPC newTarget = (NPC) interacting;
|
||||
currentInteractingId = newTarget.getId();
|
||||
|
||||
if(newTarget.getHealth() <= 0 || newTarget.isDead())
|
||||
if (newTarget.getHealth() <= 0 || newTarget.isDead())
|
||||
{
|
||||
if (flinchingTargets.containsKey(currentInteractingId))
|
||||
{
|
||||
@@ -226,10 +223,10 @@ public class FlinchingPlugin extends Plugin
|
||||
while (it.hasNext())
|
||||
{
|
||||
FlinchingTarget target = it.next().getValue();
|
||||
if(target != null)
|
||||
if (target != null)
|
||||
{
|
||||
target.Tick();
|
||||
if(target.isActive == false)
|
||||
if (!target.isActive)
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
@@ -265,21 +262,20 @@ public class FlinchingPlugin extends Plugin
|
||||
flinchingTargets.put(_newTarget.getId(), newTarget);
|
||||
}
|
||||
|
||||
public void PlayerHit()
|
||||
private void PlayerHit()
|
||||
{
|
||||
Iterator<Map.Entry<Integer, FlinchingTarget>> it = flinchingTargets.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
for (Map.Entry<Integer, FlinchingTarget> integerFlinchingTargetEntry : flinchingTargets.entrySet())
|
||||
{
|
||||
FlinchingTarget target = it.next().getValue();
|
||||
if(target != null)
|
||||
FlinchingTarget target = integerFlinchingTargetEntry.getValue();
|
||||
if (target != null)
|
||||
{
|
||||
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 Instant lastAttacked;
|
||||
|
||||
public boolean isActive = false;
|
||||
public boolean isActive;
|
||||
|
||||
@Getter
|
||||
private int objectId;
|
||||
@@ -49,7 +49,7 @@ public class FlinchingTarget
|
||||
@Getter
|
||||
public WorldPoint worldLocation;
|
||||
|
||||
public FlinchingTarget(NPC target)
|
||||
FlinchingTarget(NPC target)
|
||||
{
|
||||
isActive = true;
|
||||
|
||||
@@ -59,18 +59,18 @@ public class FlinchingTarget
|
||||
this.worldLocation = target.getWorldLocation();
|
||||
}
|
||||
|
||||
public void TargetHit()
|
||||
void TargetHit()
|
||||
{
|
||||
boolean shouldHit = true;
|
||||
if(usingHitDelay)
|
||||
if (usingHitDelay)
|
||||
{
|
||||
if(GetRemainingTime() > displayLength)
|
||||
if (GetRemainingTime() > displayLength)
|
||||
{
|
||||
shouldHit = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(shouldHit)
|
||||
if (shouldHit)
|
||||
{
|
||||
lastAttacked = Instant.now();
|
||||
|
||||
@@ -79,31 +79,31 @@ public class FlinchingTarget
|
||||
}
|
||||
}
|
||||
|
||||
public double GetRemainingTimePercent()
|
||||
double GetRemainingTimePercent()
|
||||
{
|
||||
double remainingTime = GetRemainingTime();
|
||||
double timePercent = remainingTime / currentDisplayLength;
|
||||
if(timePercent < 0)
|
||||
if (timePercent < 0)
|
||||
{
|
||||
timePercent = 0;
|
||||
}
|
||||
else if(timePercent > 1)
|
||||
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())));
|
||||
return ((currentDisplayLength - ((double) duration.toMillis())));
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
void Tick()
|
||||
{
|
||||
if(targetObject == null)
|
||||
if (targetObject == null)
|
||||
{
|
||||
isActive = false;
|
||||
}
|
||||
@@ -112,19 +112,19 @@ public class FlinchingTarget
|
||||
worldLocation = targetObject.getWorldLocation();
|
||||
|
||||
double remainingTime = GetRemainingTime();
|
||||
if(remainingTime <= 0)
|
||||
if (remainingTime <= 0)
|
||||
{
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDelayTime(int delayTime, int delayHitReceivedTime)
|
||||
void SetDelayTime(int delayTime, int delayHitReceivedTime)
|
||||
{
|
||||
displayLength = delayTime;
|
||||
displayHitReceivedLength = delayHitReceivedTime;
|
||||
|
||||
if(usingHitDelay)
|
||||
if (usingHitDelay)
|
||||
{
|
||||
currentDisplayLength = displayHitReceivedLength;
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public class FlinchingTarget
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayerHit()
|
||||
void PlayerHit()
|
||||
{
|
||||
usingHitDelay = true;
|
||||
currentDisplayLength = displayHitReceivedLength;
|
||||
|
||||
Reference in New Issue
Block a user