Merge pull request #717 from deathbeam/hunter-remove-anim-checks

Remove animation checks and catchrate from hunter
This commit is contained in:
Adam
2018-02-28 18:02:01 -05:00
committed by GitHub
2 changed files with 58 additions and 178 deletions

View File

@@ -1,72 +0,0 @@
/*
* Copyright (c) 2017, Robin Weymans <Robin.weymans@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 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
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* 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
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.hunter;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.time.Duration;
import java.time.Instant;
import javax.inject.Inject;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.PanelComponent;
/**
* Represents the overlay that shows the catch rate (percentage).
*/
public class CatchrateOverlay extends Overlay
{
/**
* The time after which the catch rate panel disappears, if the player
* stops hunting.
*/
private final Duration catchRatePanelTimeOut = Duration.ofSeconds(30);
private final PanelComponent catchRatePanel = new PanelComponent();
private final HunterPlugin plugin;
@Inject
CatchrateOverlay(HunterPlugin plugin)
{
setPosition(OverlayPosition.BOTTOM_RIGHT);
this.plugin = plugin;
}
@Override
public Dimension render(Graphics2D graphics, Point parent)
{
if (Duration.between(plugin.getLastActionTime(), Instant.now()).compareTo(catchRatePanelTimeOut) < 0)
{
final String attackStyleString = String.format("%.2f", plugin.getCatchRate() * 100) + " %";
catchRatePanel.setTitle(attackStyleString);
catchRatePanel.setWidth(80);
return catchRatePanel.render(graphics, parent);
}
return null;
}
}

View File

@@ -28,7 +28,6 @@ import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -36,7 +35,6 @@ import java.util.Set;
import javax.inject.Inject;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.AnimationID;
import net.runelite.api.Client;
import net.runelite.api.GameObject;
import net.runelite.api.ObjectID;
@@ -51,7 +49,6 @@ import net.runelite.client.Notifier;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.util.QueryRunner;
@Slf4j
@@ -67,10 +64,8 @@ public class HunterPlugin extends Plugin
private QueryRunner queryRunner;
@Inject
private TrapOverlay trapOverlay;
@Inject
private CatchrateOverlay catchrateOverlay;
@Getter
private TrapOverlay overlay;
@Inject
private Notifier notifier;
@@ -81,9 +76,6 @@ public class HunterPlugin extends Plugin
@Getter
private final Set<HunterTrap> traps = new HashSet<>();
private double catchAtempts = 0;
private double catchSuccess = 0;
@Getter
private Instant lastActionTime = Instant.ofEpochMilli(0);
@@ -93,23 +85,15 @@ public class HunterPlugin extends Plugin
return configManager.getConfig(HunterConfig.class);
}
@Override
public Collection<Overlay> getOverlays()
{
return Arrays.asList(trapOverlay, catchrateOverlay);
}
@Override
protected void startUp()
{
trapOverlay.updateConfig();
overlay.updateConfig();
}
@Override
protected void shutDown() throws Exception
{
catchAtempts = 0;
catchSuccess = 0;
lastActionTime = Instant.ofEpochMilli(0);
traps.clear();
}
@@ -117,9 +101,9 @@ public class HunterPlugin extends Plugin
@Subscribe
public void onGameObjectSpawned(GameObjectSpawned event)
{
GameObject gameObject = event.getGameObject();
HunterTrap myTrap = getTrapFromCollection(gameObject);
Player localPlayer = client.getLocalPlayer();
final GameObject gameObject = event.getGameObject();
final HunterTrap myTrap = getTrapFromCollection(gameObject);
final Player localPlayer = client.getLocalPlayer();
switch (gameObject.getId())
{
@@ -129,22 +113,15 @@ public class HunterPlugin extends Plugin
* ------------------------------------------------------------------------------
*/
case ObjectID.DEADFALL: // Deadfall trap placed
if (localPlayer.getWorldLocation().distanceTo(gameObject.getWorldLocation()) <= 2
&& localPlayer.getAnimation() == AnimationID.HUNTER_LAY_DEADFALLTRAP)
{
log.debug("Deadfall trap placed by \"{}\" on {}", localPlayer.getName(), gameObject.getWorldLocation());
traps.add(new HunterTrap(gameObject));
lastActionTime = Instant.now();
}
break;
case ObjectID.MONKEY_TRAP: // Maniacal monkey trap placed
if (localPlayer.getWorldLocation().distanceTo(gameObject.getWorldLocation()) < 2)
// If player is right next to "object" trap assume that player placed the trap
if (localPlayer.getWorldLocation().distanceTo(gameObject.getWorldLocation()) <= 1)
{
log.debug("Maniacal monkey trap placed by \"{}\" on {} of {}", localPlayer.getName(),
gameObject.getWorldLocation(), gameObject);
log.debug("Trap placed by \"{}\" on {}", localPlayer.getName(), gameObject.getWorldLocation());
traps.add(new HunterTrap(gameObject));
lastActionTime = Instant.now();
}
break;
case ObjectID.MAGIC_BOX: // Imp box placed
case ObjectID.BOX_TRAP_9380: // Box trap placed
@@ -154,28 +131,17 @@ public class HunterPlugin extends Plugin
case ObjectID.NET_TRAP_8992: // Net trap placed at red sallys
case ObjectID.NET_TRAP_9002: // Net trap placed at black sallys
// Look for players that are on the same tile
PlayerQuery playerQuery = new PlayerQuery().atLocalLocation(gameObject.getLocalLocation());
List<Player> possiblePlayers = Arrays.asList(queryRunner.runQuery(playerQuery));
final PlayerQuery playerQuery = new PlayerQuery().atLocalLocation(gameObject.getLocalLocation());
final List<Player> possiblePlayers = Arrays.asList(queryRunner.runQuery(playerQuery));
/* If the player is on that tile, and it has the correct animation, assume he is the one that placed the trap
* Special case: if you herb+tar, then move and place the trap, it does not detect laying the trap. It does work
* if you herb+tar en then place the trap.
*/
// If the player is on that tile, assume he is the one that placed the trap
if (possiblePlayers.contains(localPlayer))
{
switch (localPlayer.getAnimation())
{
case AnimationID.HUNTER_LAY_BOXTRAP_BIRDSNARE:
case AnimationID.HUNTER_LAY_NETTRAP:
case AnimationID.HERBLORE_MAKE_TAR: // When 3 ticking
log.debug("Trap placed by \"{}\" on {}", localPlayer.getName(), localPlayer.getWorldLocation());
traps.add(new HunterTrap(gameObject));
lastActionTime = Instant.now();
break;
}
}
break;
/*
* ------------------------------------------------------------------------------
@@ -203,10 +169,7 @@ public class HunterPlugin extends Plugin
case ObjectID.LARGE_BOULDER_28831: // Maniacal monkey tail obtained
if (myTrap != null)
{
log.debug("Yay, you caught something");
myTrap.setState(HunterTrap.State.FULL);
catchAtempts++;
catchSuccess++;
lastActionTime = Instant.now();
if (config.maniacalMonkeyNotify() && myTrap.getGameObject().getId() == ObjectID.MONKEY_TRAP)
@@ -214,6 +177,7 @@ public class HunterPlugin extends Plugin
notifier.notify("You've caught part of a monkey's tail.");
}
}
break;
/*
* ------------------------------------------------------------------------------
@@ -225,13 +189,11 @@ public class HunterPlugin extends Plugin
case ObjectID.BIRD_SNARE: //Empty box trap
if (myTrap != null)
{
log.debug("Your trap didn't catch anything");
myTrap.setState(HunterTrap.State.EMPTY);
myTrap.resetTimer();
catchAtempts++;
lastActionTime = Instant.now();
}
break;
/*
* ------------------------------------------------------------------------------
@@ -345,7 +307,7 @@ public class HunterPlugin extends Plugin
{
if (event.getGroup().equals("hunterplugin"))
{
trapOverlay.updateConfig();
overlay.updateConfig();
}
}
@@ -353,13 +315,14 @@ public class HunterPlugin extends Plugin
* Looks for a trap in the local players trap collection, on the same
* place as the given GameObject.
*
* @param gameObject
* @param gameObject game object
* @return A HunterTrap object if the player has a trap on the same
* location as the GameObject. Otherwise it returns null.
*/
private HunterTrap getTrapFromCollection(GameObject gameObject)
{
Point gameObjectLocation = gameObject.getWorldLocation();
final Point gameObjectLocation = gameObject.getWorldLocation();
for (HunterTrap trap : traps)
{
if (gameObjectLocation.equals(trap.getGameObject().getWorldLocation()))
@@ -367,18 +330,7 @@ public class HunterPlugin extends Plugin
return trap;
}
}
return null;
}
/**
* Calculates the catch rate, i.e. the attempts to catch something
* compared to the times you succeed.
*
* @return Value between 0 (none) and 1 (all).
*/
public double getCatchRate()
{
return catchAtempts != 0 ? catchSuccess / catchAtempts : 0;
}
}