use lf line endings
This commit is contained in:
@@ -1,486 +1,486 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, Woox <https://github.com/wooxsolo>
|
* Copyright (c) 2018, Woox <https://github.com/wooxsolo>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
* list of conditions and the following disclaimer.
|
* list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* 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
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* 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
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.npcunaggroarea;
|
package net.runelite.client.plugins.npcunaggroarea;
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.awt.Polygon;
|
import java.awt.Polygon;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.geom.Area;
|
import java.awt.geom.Area;
|
||||||
import java.awt.geom.GeneralPath;
|
import java.awt.geom.GeneralPath;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.Constants;
|
import net.runelite.api.Constants;
|
||||||
import net.runelite.api.ItemID;
|
import net.runelite.api.ItemID;
|
||||||
import net.runelite.api.NPC;
|
import net.runelite.api.NPC;
|
||||||
import net.runelite.api.NPCComposition;
|
import net.runelite.api.NPCComposition;
|
||||||
import net.runelite.api.Perspective;
|
import net.runelite.api.Perspective;
|
||||||
import net.runelite.api.coords.LocalPoint;
|
import net.runelite.api.coords.LocalPoint;
|
||||||
import net.runelite.api.coords.WorldArea;
|
import net.runelite.api.coords.WorldArea;
|
||||||
import net.runelite.api.coords.WorldPoint;
|
import net.runelite.api.coords.WorldPoint;
|
||||||
import net.runelite.api.events.ConfigChanged;
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.GameTick;
|
import net.runelite.api.events.GameTick;
|
||||||
import net.runelite.api.events.NpcSpawned;
|
import net.runelite.api.events.NpcSpawned;
|
||||||
import net.runelite.api.geometry.Geometry;
|
import net.runelite.api.geometry.Geometry;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.game.ItemManager;
|
import net.runelite.client.game.ItemManager;
|
||||||
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.ui.overlay.OverlayManager;
|
||||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||||
import net.runelite.client.util.WildcardMatcher;
|
import net.runelite.client.util.WildcardMatcher;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "NPC Aggression Timer",
|
name = "NPC Aggression Timer",
|
||||||
description = "Highlights the unaggressive area of NPCs nearby and timer until it becomes active",
|
description = "Highlights the unaggressive area of NPCs nearby and timer until it becomes active",
|
||||||
tags = {"highlight", "lines", "unaggro", "aggro", "aggressive", "npcs", "area", "slayer"},
|
tags = {"highlight", "lines", "unaggro", "aggro", "aggressive", "npcs", "area", "slayer"},
|
||||||
enabledByDefault = false
|
enabledByDefault = false
|
||||||
)
|
)
|
||||||
public class NpcAggroAreaPlugin extends Plugin
|
public class NpcAggroAreaPlugin extends Plugin
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
How it works: The game remembers 2 tiles. When the player goes >10 steps
|
How it works: The game remembers 2 tiles. When the player goes >10 steps
|
||||||
away from both tiles, the oldest one is moved to under the player and the
|
away from both tiles, the oldest one is moved to under the player and the
|
||||||
NPC aggression timer resets.
|
NPC aggression timer resets.
|
||||||
So to first figure out where the 2 tiles are, we wait until the player teleports
|
So to first figure out where the 2 tiles are, we wait until the player teleports
|
||||||
a long enough distance. At that point it's very likely that the player
|
a long enough distance. At that point it's very likely that the player
|
||||||
moved out of the radius of both tiles, which resets one of them. The other
|
moved out of the radius of both tiles, which resets one of them. The other
|
||||||
should reset shortly after as the player starts moving around.
|
should reset shortly after as the player starts moving around.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private static final int SAFE_AREA_RADIUS = 10;
|
private static final int SAFE_AREA_RADIUS = 10;
|
||||||
private static final int UNKNOWN_AREA_RADIUS = SAFE_AREA_RADIUS * 2;
|
private static final int UNKNOWN_AREA_RADIUS = SAFE_AREA_RADIUS * 2;
|
||||||
private static final int AGGRESSIVE_TIME_SECONDS = 600;
|
private static final int AGGRESSIVE_TIME_SECONDS = 600;
|
||||||
private static final Splitter NAME_SPLITTER = Splitter.on(',').omitEmptyStrings().trimResults();
|
private static final Splitter NAME_SPLITTER = Splitter.on(',').omitEmptyStrings().trimResults();
|
||||||
private static final WorldArea WILDERNESS_ABOVE_GROUND = new WorldArea(2944, 3523, 448, 448, 0);
|
private static final WorldArea WILDERNESS_ABOVE_GROUND = new WorldArea(2944, 3523, 448, 448, 0);
|
||||||
private static final WorldArea WILDERNESS_UNDERGROUND = new WorldArea(2944, 9918, 320, 442, 0);
|
private static final WorldArea WILDERNESS_UNDERGROUND = new WorldArea(2944, 9918, 320, 442, 0);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private NpcAggroAreaConfig config;
|
private NpcAggroAreaConfig config;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private NpcAggroAreaOverlay overlay;
|
private NpcAggroAreaOverlay overlay;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private NpcAggroAreaNotWorkingOverlay notWorkingOverlay;
|
private NpcAggroAreaNotWorkingOverlay notWorkingOverlay;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private OverlayManager overlayManager;
|
private OverlayManager overlayManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ItemManager itemManager;
|
private ItemManager itemManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private InfoBoxManager infoBoxManager;
|
private InfoBoxManager infoBoxManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ConfigManager configManager;
|
private ConfigManager configManager;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final WorldPoint[] safeCenters = new WorldPoint[2];
|
private final WorldPoint[] safeCenters = new WorldPoint[2];
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final GeneralPath[] linesToDisplay = new GeneralPath[Constants.MAX_Z];
|
private final GeneralPath[] linesToDisplay = new GeneralPath[Constants.MAX_Z];
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private boolean active;
|
private boolean active;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private AggressionTimer currentTimer;
|
private AggressionTimer currentTimer;
|
||||||
|
|
||||||
private WorldPoint lastPlayerLocation;
|
private WorldPoint lastPlayerLocation;
|
||||||
private WorldPoint previousUnknownCenter;
|
private WorldPoint previousUnknownCenter;
|
||||||
private boolean loggingIn;
|
private boolean loggingIn;
|
||||||
private List<String> npcNamePatterns;
|
private List<String> npcNamePatterns;
|
||||||
private boolean notWorkingOverlayShown = false;
|
private boolean notWorkingOverlayShown = false;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
NpcAggroAreaConfig provideConfig(ConfigManager configManager)
|
NpcAggroAreaConfig provideConfig(ConfigManager configManager)
|
||||||
{
|
{
|
||||||
return configManager.getConfig(NpcAggroAreaConfig.class);
|
return configManager.getConfig(NpcAggroAreaConfig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
overlayManager.add(overlay);
|
overlayManager.add(overlay);
|
||||||
if (config.showNotWorkingOverlay())
|
if (config.showNotWorkingOverlay())
|
||||||
{
|
{
|
||||||
overlayManager.add(notWorkingOverlay);
|
overlayManager.add(notWorkingOverlay);
|
||||||
notWorkingOverlayShown = true;
|
notWorkingOverlayShown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
npcNamePatterns = NAME_SPLITTER.splitToList(config.npcNamePatterns());
|
npcNamePatterns = NAME_SPLITTER.splitToList(config.npcNamePatterns());
|
||||||
recheckActive();
|
recheckActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutDown() throws Exception
|
protected void shutDown() throws Exception
|
||||||
{
|
{
|
||||||
removeTimer();
|
removeTimer();
|
||||||
overlayManager.remove(overlay);
|
overlayManager.remove(overlay);
|
||||||
if (notWorkingOverlayShown)
|
if (notWorkingOverlayShown)
|
||||||
{
|
{
|
||||||
overlayManager.remove(notWorkingOverlay);
|
overlayManager.remove(notWorkingOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
Arrays.fill(safeCenters, null);
|
Arrays.fill(safeCenters, null);
|
||||||
lastPlayerLocation = null;
|
lastPlayerLocation = null;
|
||||||
currentTimer = null;
|
currentTimer = null;
|
||||||
loggingIn = false;
|
loggingIn = false;
|
||||||
npcNamePatterns = null;
|
npcNamePatterns = null;
|
||||||
active = false;
|
active = false;
|
||||||
|
|
||||||
Arrays.fill(linesToDisplay, null);
|
Arrays.fill(linesToDisplay, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Area generateSafeArea()
|
private Area generateSafeArea()
|
||||||
{
|
{
|
||||||
final Area area = new Area();
|
final Area area = new Area();
|
||||||
|
|
||||||
for (WorldPoint wp : safeCenters)
|
for (WorldPoint wp : safeCenters)
|
||||||
{
|
{
|
||||||
if (wp == null)
|
if (wp == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Polygon poly = new Polygon();
|
Polygon poly = new Polygon();
|
||||||
poly.addPoint(wp.getX() - SAFE_AREA_RADIUS, wp.getY() - SAFE_AREA_RADIUS);
|
poly.addPoint(wp.getX() - SAFE_AREA_RADIUS, wp.getY() - SAFE_AREA_RADIUS);
|
||||||
poly.addPoint(wp.getX() - SAFE_AREA_RADIUS, wp.getY() + SAFE_AREA_RADIUS + 1);
|
poly.addPoint(wp.getX() - SAFE_AREA_RADIUS, wp.getY() + SAFE_AREA_RADIUS + 1);
|
||||||
poly.addPoint(wp.getX() + SAFE_AREA_RADIUS + 1, wp.getY() + SAFE_AREA_RADIUS + 1);
|
poly.addPoint(wp.getX() + SAFE_AREA_RADIUS + 1, wp.getY() + SAFE_AREA_RADIUS + 1);
|
||||||
poly.addPoint(wp.getX() + SAFE_AREA_RADIUS + 1, wp.getY() - SAFE_AREA_RADIUS);
|
poly.addPoint(wp.getX() + SAFE_AREA_RADIUS + 1, wp.getY() - SAFE_AREA_RADIUS);
|
||||||
area.add(new Area(poly));
|
area.add(new Area(poly));
|
||||||
}
|
}
|
||||||
|
|
||||||
return area;
|
return area;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transformWorldToLocal(float[] coords)
|
private void transformWorldToLocal(float[] coords)
|
||||||
{
|
{
|
||||||
final LocalPoint lp = LocalPoint.fromWorld(client, (int)coords[0], (int)coords[1]);
|
final LocalPoint lp = LocalPoint.fromWorld(client, (int)coords[0], (int)coords[1]);
|
||||||
coords[0] = lp.getX() - Perspective.LOCAL_TILE_SIZE / 2f;
|
coords[0] = lp.getX() - Perspective.LOCAL_TILE_SIZE / 2f;
|
||||||
coords[1] = lp.getY() - Perspective.LOCAL_TILE_SIZE / 2f;
|
coords[1] = lp.getY() - Perspective.LOCAL_TILE_SIZE / 2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reevaluateActive()
|
private void reevaluateActive()
|
||||||
{
|
{
|
||||||
if (currentTimer != null)
|
if (currentTimer != null)
|
||||||
{
|
{
|
||||||
currentTimer.setVisible(active && config.showTimer());
|
currentTimer.setVisible(active && config.showTimer());
|
||||||
}
|
}
|
||||||
|
|
||||||
calculateLinesToDisplay();
|
calculateLinesToDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculateLinesToDisplay()
|
private void calculateLinesToDisplay()
|
||||||
{
|
{
|
||||||
if (!active || !config.showAreaLines())
|
if (!active || !config.showAreaLines())
|
||||||
{
|
{
|
||||||
Arrays.fill(linesToDisplay, null);
|
Arrays.fill(linesToDisplay, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle sceneRect = new Rectangle(
|
Rectangle sceneRect = new Rectangle(
|
||||||
client.getBaseX() + 1, client.getBaseY() + 1,
|
client.getBaseX() + 1, client.getBaseY() + 1,
|
||||||
Constants.SCENE_SIZE - 2, Constants.SCENE_SIZE - 2);
|
Constants.SCENE_SIZE - 2, Constants.SCENE_SIZE - 2);
|
||||||
|
|
||||||
for (int i = 0; i < linesToDisplay.length; i++)
|
for (int i = 0; i < linesToDisplay.length; i++)
|
||||||
{
|
{
|
||||||
GeneralPath lines = new GeneralPath(generateSafeArea());
|
GeneralPath lines = new GeneralPath(generateSafeArea());
|
||||||
lines = Geometry.clipPath(lines, sceneRect);
|
lines = Geometry.clipPath(lines, sceneRect);
|
||||||
lines = Geometry.splitIntoSegments(lines, 1);
|
lines = Geometry.splitIntoSegments(lines, 1);
|
||||||
lines = Geometry.transformPath(lines, this::transformWorldToLocal);
|
lines = Geometry.transformPath(lines, this::transformWorldToLocal);
|
||||||
linesToDisplay[i] = lines;
|
linesToDisplay[i] = lines;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeTimer()
|
private void removeTimer()
|
||||||
{
|
{
|
||||||
infoBoxManager.removeInfoBox(currentTimer);
|
infoBoxManager.removeInfoBox(currentTimer);
|
||||||
currentTimer = null;
|
currentTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTimer(Duration duration)
|
private void createTimer(Duration duration)
|
||||||
{
|
{
|
||||||
removeTimer();
|
removeTimer();
|
||||||
BufferedImage image = itemManager.getImage(ItemID.ENSOULED_DEMON_HEAD);
|
BufferedImage image = itemManager.getImage(ItemID.ENSOULED_DEMON_HEAD);
|
||||||
currentTimer = new AggressionTimer(duration, image, this, active && config.showTimer());
|
currentTimer = new AggressionTimer(duration, image, this, active && config.showTimer());
|
||||||
infoBoxManager.addInfoBox(currentTimer);
|
infoBoxManager.addInfoBox(currentTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetTimer()
|
private void resetTimer()
|
||||||
{
|
{
|
||||||
createTimer(Duration.ofSeconds(AGGRESSIVE_TIME_SECONDS));
|
createTimer(Duration.ofSeconds(AGGRESSIVE_TIME_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isInWilderness(WorldPoint location)
|
private static boolean isInWilderness(WorldPoint location)
|
||||||
{
|
{
|
||||||
return WILDERNESS_ABOVE_GROUND.distanceTo2D(location) == 0 || WILDERNESS_UNDERGROUND.distanceTo2D(location) == 0;
|
return WILDERNESS_ABOVE_GROUND.distanceTo2D(location) == 0 || WILDERNESS_UNDERGROUND.distanceTo2D(location) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNpcMatch(NPC npc)
|
private boolean isNpcMatch(NPC npc)
|
||||||
{
|
{
|
||||||
NPCComposition composition = npc.getTransformedComposition();
|
NPCComposition composition = npc.getTransformedComposition();
|
||||||
if (composition == null)
|
if (composition == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Strings.isNullOrEmpty(composition.getName()))
|
if (Strings.isNullOrEmpty(composition.getName()))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Most NPCs stop aggroing when the player has more than double
|
// Most NPCs stop aggroing when the player has more than double
|
||||||
// its combat level.
|
// its combat level.
|
||||||
int playerLvl = client.getLocalPlayer().getCombatLevel();
|
int playerLvl = client.getLocalPlayer().getCombatLevel();
|
||||||
int npcLvl = composition.getCombatLevel();
|
int npcLvl = composition.getCombatLevel();
|
||||||
String npcName = composition.getName().toLowerCase();
|
String npcName = composition.getName().toLowerCase();
|
||||||
if (npcLvl > 0 && playerLvl > npcLvl * 2 && !isInWilderness(npc.getWorldLocation()))
|
if (npcLvl > 0 && playerLvl > npcLvl * 2 && !isInWilderness(npc.getWorldLocation()))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String pattern : npcNamePatterns)
|
for (String pattern : npcNamePatterns)
|
||||||
{
|
{
|
||||||
if (WildcardMatcher.matches(pattern, npcName))
|
if (WildcardMatcher.matches(pattern, npcName))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAreaNpcs(final NPC... npcs)
|
private void checkAreaNpcs(final NPC... npcs)
|
||||||
{
|
{
|
||||||
for (NPC npc : npcs)
|
for (NPC npc : npcs)
|
||||||
{
|
{
|
||||||
if (npc == null)
|
if (npc == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNpcMatch(npc))
|
if (isNpcMatch(npc))
|
||||||
{
|
{
|
||||||
active = true;
|
active = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reevaluateActive();
|
reevaluateActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recheckActive()
|
private void recheckActive()
|
||||||
{
|
{
|
||||||
active = config.alwaysActive();
|
active = config.alwaysActive();
|
||||||
checkAreaNpcs(client.getCachedNPCs());
|
checkAreaNpcs(client.getCachedNPCs());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onNpcSpawned(NpcSpawned event)
|
public void onNpcSpawned(NpcSpawned event)
|
||||||
{
|
{
|
||||||
if (config.alwaysActive())
|
if (config.alwaysActive())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkAreaNpcs(event.getNpc());
|
checkAreaNpcs(event.getNpc());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameTick(GameTick event)
|
public void onGameTick(GameTick event)
|
||||||
{
|
{
|
||||||
WorldPoint newLocation = client.getLocalPlayer().getWorldLocation();
|
WorldPoint newLocation = client.getLocalPlayer().getWorldLocation();
|
||||||
if (lastPlayerLocation != null)
|
if (lastPlayerLocation != null)
|
||||||
{
|
{
|
||||||
if (safeCenters[1] == null && newLocation.distanceTo2D(lastPlayerLocation) > SAFE_AREA_RADIUS * 4)
|
if (safeCenters[1] == null && newLocation.distanceTo2D(lastPlayerLocation) > SAFE_AREA_RADIUS * 4)
|
||||||
{
|
{
|
||||||
safeCenters[0] = null;
|
safeCenters[0] = null;
|
||||||
safeCenters[1] = newLocation;
|
safeCenters[1] = newLocation;
|
||||||
resetTimer();
|
resetTimer();
|
||||||
calculateLinesToDisplay();
|
calculateLinesToDisplay();
|
||||||
|
|
||||||
// We don't know where the previous area was, so if the player e.g.
|
// We don't know where the previous area was, so if the player e.g.
|
||||||
// entered a dungeon and then goes back out, he/she may enter the previous
|
// entered a dungeon and then goes back out, he/she may enter the previous
|
||||||
// area which is unknown and would make the plugin inaccurate
|
// area which is unknown and would make the plugin inaccurate
|
||||||
previousUnknownCenter = lastPlayerLocation;
|
previousUnknownCenter = lastPlayerLocation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (safeCenters[0] == null && previousUnknownCenter != null &&
|
if (safeCenters[0] == null && previousUnknownCenter != null &&
|
||||||
previousUnknownCenter.distanceTo2D(newLocation) <= UNKNOWN_AREA_RADIUS)
|
previousUnknownCenter.distanceTo2D(newLocation) <= UNKNOWN_AREA_RADIUS)
|
||||||
{
|
{
|
||||||
// Player went back to their previous unknown area before the 2nd
|
// Player went back to their previous unknown area before the 2nd
|
||||||
// center point was found, which means we don't know where it is again.
|
// center point was found, which means we don't know where it is again.
|
||||||
safeCenters[1] = null;
|
safeCenters[1] = null;
|
||||||
removeTimer();
|
removeTimer();
|
||||||
calculateLinesToDisplay();
|
calculateLinesToDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (safeCenters[1] != null)
|
if (safeCenters[1] != null)
|
||||||
{
|
{
|
||||||
if (Arrays.stream(safeCenters).noneMatch(
|
if (Arrays.stream(safeCenters).noneMatch(
|
||||||
x -> x != null && x.distanceTo2D(newLocation) <= SAFE_AREA_RADIUS))
|
x -> x != null && x.distanceTo2D(newLocation) <= SAFE_AREA_RADIUS))
|
||||||
{
|
{
|
||||||
safeCenters[0] = safeCenters[1];
|
safeCenters[0] = safeCenters[1];
|
||||||
safeCenters[1] = newLocation;
|
safeCenters[1] = newLocation;
|
||||||
resetTimer();
|
resetTimer();
|
||||||
calculateLinesToDisplay();
|
calculateLinesToDisplay();
|
||||||
previousUnknownCenter = null;
|
previousUnknownCenter = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPlayerLocation = newLocation;
|
lastPlayerLocation = newLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onConfigChanged(ConfigChanged event)
|
public void onConfigChanged(ConfigChanged event)
|
||||||
{
|
{
|
||||||
String key = event.getKey();
|
String key = event.getKey();
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case "npcUnaggroAlwaysActive":
|
case "npcUnaggroAlwaysActive":
|
||||||
recheckActive();
|
recheckActive();
|
||||||
break;
|
break;
|
||||||
case "npcUnaggroShowTimer":
|
case "npcUnaggroShowTimer":
|
||||||
if (currentTimer != null)
|
if (currentTimer != null)
|
||||||
{
|
{
|
||||||
currentTimer.setVisible(active && config.showTimer());
|
currentTimer.setVisible(active && config.showTimer());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "npcUnaggroCollisionDetection":
|
case "npcUnaggroCollisionDetection":
|
||||||
case "npcUnaggroShowAreaLines":
|
case "npcUnaggroShowAreaLines":
|
||||||
calculateLinesToDisplay();
|
calculateLinesToDisplay();
|
||||||
break;
|
break;
|
||||||
case "npcUnaggroNames":
|
case "npcUnaggroNames":
|
||||||
npcNamePatterns = NAME_SPLITTER.splitToList(config.npcNamePatterns());
|
npcNamePatterns = NAME_SPLITTER.splitToList(config.npcNamePatterns());
|
||||||
recheckActive();
|
recheckActive();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConfig()
|
private void loadConfig()
|
||||||
{
|
{
|
||||||
safeCenters[0] = configManager.getConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_CENTER1, WorldPoint.class);
|
safeCenters[0] = configManager.getConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_CENTER1, WorldPoint.class);
|
||||||
safeCenters[1] = configManager.getConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_CENTER2, WorldPoint.class);
|
safeCenters[1] = configManager.getConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_CENTER2, WorldPoint.class);
|
||||||
lastPlayerLocation = configManager.getConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_LOCATION, WorldPoint.class);
|
lastPlayerLocation = configManager.getConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_LOCATION, WorldPoint.class);
|
||||||
|
|
||||||
Duration timeLeft = configManager.getConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_DURATION, Duration.class);
|
Duration timeLeft = configManager.getConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_DURATION, Duration.class);
|
||||||
if (timeLeft != null && !timeLeft.isNegative())
|
if (timeLeft != null && !timeLeft.isNegative())
|
||||||
{
|
{
|
||||||
createTimer(timeLeft);
|
createTimer(timeLeft);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetConfig()
|
private void resetConfig()
|
||||||
{
|
{
|
||||||
configManager.unsetConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_CENTER1);
|
configManager.unsetConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_CENTER1);
|
||||||
configManager.unsetConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_CENTER2);
|
configManager.unsetConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_CENTER2);
|
||||||
configManager.unsetConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_LOCATION);
|
configManager.unsetConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_LOCATION);
|
||||||
configManager.unsetConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_DURATION);
|
configManager.unsetConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_DURATION);
|
||||||
configManager.unsetConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_NOT_WORKING_OVERLAY);
|
configManager.unsetConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_NOT_WORKING_OVERLAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveConfig()
|
private void saveConfig()
|
||||||
{
|
{
|
||||||
if (safeCenters[0] == null || safeCenters[1] == null || lastPlayerLocation == null || currentTimer == null)
|
if (safeCenters[0] == null || safeCenters[1] == null || lastPlayerLocation == null || currentTimer == null)
|
||||||
{
|
{
|
||||||
resetConfig();
|
resetConfig();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
configManager.setConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_CENTER1, safeCenters[0]);
|
configManager.setConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_CENTER1, safeCenters[0]);
|
||||||
configManager.setConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_CENTER2, safeCenters[1]);
|
configManager.setConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_CENTER2, safeCenters[1]);
|
||||||
configManager.setConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_LOCATION, lastPlayerLocation);
|
configManager.setConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_LOCATION, lastPlayerLocation);
|
||||||
configManager.setConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_DURATION, Duration.between(Instant.now(), currentTimer.getEndTime()));
|
configManager.setConfiguration(NpcAggroAreaConfig.CONFIG_GROUP, NpcAggroAreaConfig.CONFIG_DURATION, Duration.between(Instant.now(), currentTimer.getEndTime()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onLogin()
|
private void onLogin()
|
||||||
{
|
{
|
||||||
loadConfig();
|
loadConfig();
|
||||||
resetConfig();
|
resetConfig();
|
||||||
|
|
||||||
WorldPoint newLocation = client.getLocalPlayer().getWorldLocation();
|
WorldPoint newLocation = client.getLocalPlayer().getWorldLocation();
|
||||||
assert newLocation != null;
|
assert newLocation != null;
|
||||||
|
|
||||||
// If the player isn't at the location he/she logged out at,
|
// If the player isn't at the location he/she logged out at,
|
||||||
// the safe unaggro area probably changed, and should be disposed.
|
// the safe unaggro area probably changed, and should be disposed.
|
||||||
if (lastPlayerLocation == null || newLocation.distanceTo(lastPlayerLocation) != 0)
|
if (lastPlayerLocation == null || newLocation.distanceTo(lastPlayerLocation) != 0)
|
||||||
{
|
{
|
||||||
safeCenters[0] = null;
|
safeCenters[0] = null;
|
||||||
safeCenters[1] = null;
|
safeCenters[1] = null;
|
||||||
lastPlayerLocation = newLocation;
|
lastPlayerLocation = newLocation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameStateChanged(GameStateChanged event)
|
public void onGameStateChanged(GameStateChanged event)
|
||||||
{
|
{
|
||||||
switch (event.getGameState())
|
switch (event.getGameState())
|
||||||
{
|
{
|
||||||
case LOGGED_IN:
|
case LOGGED_IN:
|
||||||
if (loggingIn)
|
if (loggingIn)
|
||||||
{
|
{
|
||||||
loggingIn = false;
|
loggingIn = false;
|
||||||
onLogin();
|
onLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
recheckActive();
|
recheckActive();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LOGGING_IN:
|
case LOGGING_IN:
|
||||||
loggingIn = true;
|
loggingIn = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LOGIN_SCREEN:
|
case LOGIN_SCREEN:
|
||||||
if (lastPlayerLocation != null)
|
if (lastPlayerLocation != null)
|
||||||
{
|
{
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
safeCenters[0] = null;
|
safeCenters[0] = null;
|
||||||
safeCenters[1] = null;
|
safeCenters[1] = null;
|
||||||
lastPlayerLocation = null;
|
lastPlayerLocation = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user