driftnet: Improve fish shoal highlighting

This commit increases the default highlight length for fish shoals as
they are often active for much longer than 10 ticks, and also untags
fish shoals more accurately when they are adjacent to nets which cannot
catch fish.
This commit is contained in:
Bart Peeters
2020-06-15 00:25:14 -07:00
committed by Jordan Atwood
parent bed1bfcd79
commit f975e0415d
3 changed files with 56 additions and 12 deletions

View File

@@ -25,10 +25,13 @@
*/
package net.runelite.client.plugins.driftnet;
import java.util.Set;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.runelite.api.GameObject;
import net.runelite.api.Varbits;
import net.runelite.api.coords.WorldPoint;
@Data
@RequiredArgsConstructor
@@ -37,10 +40,23 @@ class DriftNet
private final int objectId;
private final Varbits statusVarbit;
private final Varbits countVarbit;
private final Set<WorldPoint> adjacentTiles;
private GameObject net;
private DriftNetStatus status;
private int count;
@Setter
private DriftNetStatus prevTickStatus;
// Nets that are not accepting fish are those currently not accepting, or those which were not
// accepting in the previous tick. (When a fish shoal is 2 tiles adjacent to a drift net and is
// moving to a net that is just being setup it will be denied even though the net is currently
// in the CATCHING status)
boolean isNotAcceptingFish()
{
return (status != DriftNetStatus.CATCH && status != DriftNetStatus.SET) ||
(prevTickStatus != DriftNetStatus.CATCH && prevTickStatus != DriftNetStatus.SET);
}
String getFormattedCountText()
{

View File

@@ -76,12 +76,12 @@ public interface DriftNetConfig extends Config
)
@Range(
min = 1,
max = 60
max = 100
)
@Units(Units.TICKS)
default int timeoutDelay()
{
return 10;
return 60;
}
@ConfigItem(

View File

@@ -26,12 +26,15 @@
package net.runelite.client.plugins.driftnet;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Provides;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject;
import lombok.Getter;
import net.runelite.api.Actor;
@@ -99,8 +102,19 @@ public class DriftNetPlugin extends Plugin
private Map<NPC, Integer> taggedFish = new HashMap<>();
@Getter
private final List<DriftNet> NETS = ImmutableList.of(
new DriftNet(NullObjectID.NULL_31433, Varbits.NORTH_NET_STATUS, Varbits.NORTH_NET_CATCH_COUNT),
new DriftNet(NullObjectID.NULL_31434, Varbits.SOUTH_NET_STATUS, Varbits.SOUTH_NET_CATCH_COUNT));
new DriftNet(NullObjectID.NULL_31433, Varbits.NORTH_NET_STATUS, Varbits.NORTH_NET_CATCH_COUNT, ImmutableSet.of(
new WorldPoint(3746, 10297, 1),
new WorldPoint(3747, 10297, 1),
new WorldPoint(3748, 10297, 1),
new WorldPoint(3749, 10297, 1)
)),
new DriftNet(NullObjectID.NULL_31434, Varbits.SOUTH_NET_STATUS, Varbits.SOUTH_NET_CATCH_COUNT, ImmutableSet.of(
new WorldPoint(3742, 10288, 1),
new WorldPoint(3742, 10289, 1),
new WorldPoint(3742, 10290, 1),
new WorldPoint(3742, 10291, 1),
new WorldPoint(3742, 10292, 1)
)));
@Getter
private boolean inDriftNetArea;
@@ -190,12 +204,6 @@ public class DriftNetPlugin extends Plugin
net.setStatus(status);
net.setCount(count);
}
// When you collect any loot, all tags become invalidated
if (client.getVar(Varbits.DRIFT_NET_COLLECT) != 0)
{
taggedFish.clear();
}
}
@Subscribe
@@ -211,6 +219,17 @@ public class DriftNetPlugin extends Plugin
}
}
private boolean isFishNextToNet(NPC fish, Collection<DriftNet> nets)
{
final WorldPoint fishTile = WorldPoint.fromLocalInstance(client, fish.getLocalLocation());
return nets.stream().anyMatch(net -> net.getAdjacentTiles().contains(fishTile));
}
private boolean isTagExpired(Integer tick)
{
return tick + config.timeoutDelay() < client.getTickCount();
}
@Subscribe
public void onGameTick(GameTick tick)
{
@@ -219,8 +238,16 @@ public class DriftNetPlugin extends Plugin
return;
}
final int currentTickCount = client.getTickCount();
taggedFish.entrySet().removeIf(entry -> entry.getValue() + config.timeoutDelay() < currentTickCount);
List<DriftNet> closedNets = NETS.stream()
.filter(DriftNet::isNotAcceptingFish)
.collect(Collectors.toList());
taggedFish.entrySet().removeIf(entry ->
isTagExpired(entry.getValue()) ||
isFishNextToNet(entry.getKey(), closedNets)
);
NETS.forEach(net -> net.setPrevTickStatus(net.getStatus()));
armInteraction = false;
}
@@ -271,6 +298,7 @@ public class DriftNetPlugin extends Plugin
{
final NPC npc = event.getNpc();
fish.remove(npc);
taggedFish.remove(npc);
}
@Subscribe