Remove animation checks

Remove animation checks from hunter plugin because animations are
unreliable and do not work during 3ticking. Reasoning is it is better to
have shown extra traps sometimes than not registering own traps
sometimes

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-02-27 12:38:27 +01:00
parent 79e53bb3eb
commit 70916be164

View File

@@ -36,7 +36,6 @@ import java.util.Set;
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.AnimationID;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.GameObject; import net.runelite.api.GameObject;
import net.runelite.api.ObjectID; import net.runelite.api.ObjectID;
@@ -117,9 +116,9 @@ public class HunterPlugin extends Plugin
@Subscribe @Subscribe
public void onGameObjectSpawned(GameObjectSpawned event) public void onGameObjectSpawned(GameObjectSpawned event)
{ {
GameObject gameObject = event.getGameObject(); final GameObject gameObject = event.getGameObject();
HunterTrap myTrap = getTrapFromCollection(gameObject); final HunterTrap myTrap = getTrapFromCollection(gameObject);
Player localPlayer = client.getLocalPlayer(); final Player localPlayer = client.getLocalPlayer();
switch (gameObject.getId()) switch (gameObject.getId())
{ {
@@ -128,54 +127,36 @@ public class HunterPlugin extends Plugin
* Placing traps * Placing traps
* ------------------------------------------------------------------------------ * ------------------------------------------------------------------------------
*/ */
case ObjectID.DEADFALL: //Deadfall trap placed 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 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(), log.debug("Trap placed by \"{}\" on {}", localPlayer.getName(), gameObject.getWorldLocation());
gameObject.getWorldLocation(), gameObject);
traps.add(new HunterTrap(gameObject)); traps.add(new HunterTrap(gameObject));
lastActionTime = Instant.now(); lastActionTime = Instant.now();
} }
break; break;
case ObjectID.MAGIC_BOX: // Imp box placed case ObjectID.MAGIC_BOX: // Imp box placed
case ObjectID.BOX_TRAP_9380: //Box trap placed case ObjectID.BOX_TRAP_9380: // Box trap placed
case ObjectID.BIRD_SNARE_9345: //Bird snare placed case ObjectID.BIRD_SNARE_9345: // Bird snare placed
case ObjectID.NET_TRAP_9343: //Net trap placed at green sallys case ObjectID.NET_TRAP_9343: // Net trap placed at green sallys
case ObjectID.NET_TRAP: //Net trap placed at orange sallys case ObjectID.NET_TRAP: // Net trap placed at orange sallys
case ObjectID.NET_TRAP_8992: //Net trap placed at red sallys case ObjectID.NET_TRAP_8992: // Net trap placed at red sallys
case ObjectID.NET_TRAP_9002: //Net trap placed at black sallys case ObjectID.NET_TRAP_9002: // Net trap placed at black sallys
//Look for players that are on the same tile // Look for players that are on the same tile
PlayerQuery playerQuery = new PlayerQuery().atLocalLocation(gameObject.getLocalLocation()); final PlayerQuery playerQuery = new PlayerQuery().atLocalLocation(gameObject.getLocalLocation());
List<Player> possiblePlayers = Arrays.asList(queryRunner.runQuery(playerQuery)); 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 // If the player is on that tile, 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 (possiblePlayers.contains(localPlayer)) 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()); log.debug("Trap placed by \"{}\" on {}", localPlayer.getName(), localPlayer.getWorldLocation());
traps.add(new HunterTrap(gameObject)); traps.add(new HunterTrap(gameObject));
lastActionTime = Instant.now(); lastActionTime = Instant.now();
break;
} }
}
break; break;
/* /*
* ------------------------------------------------------------------------------ * ------------------------------------------------------------------------------
@@ -183,27 +164,26 @@ public class HunterPlugin extends Plugin
* ------------------------------------------------------------------------------ * ------------------------------------------------------------------------------
*/ */
case ObjectID.MAGIC_BOX_19226: // Imp caught case ObjectID.MAGIC_BOX_19226: // Imp caught
case ObjectID.SHAKING_BOX: //Black chinchompa caught case ObjectID.SHAKING_BOX: // Black chinchompa caught
case ObjectID.SHAKING_BOX_9382: // Grey chinchompa caught case ObjectID.SHAKING_BOX_9382: // Grey chinchompa caught
case ObjectID.SHAKING_BOX_9383: //Red chinchompa caught case ObjectID.SHAKING_BOX_9383: // Red chinchompa caught
case ObjectID.BOULDER_20648: //Prickly kebbit caught case ObjectID.BOULDER_20648: // Prickly kebbit caught
case ObjectID.BOULDER_20649: //Sabre-tooth kebbit caught case ObjectID.BOULDER_20649: // Sabre-tooth kebbit caught
case ObjectID.BOULDER_20650: //Barb-tailed kebbit caught case ObjectID.BOULDER_20650: // Barb-tailed kebbit caught
case ObjectID.BOULDER_20651: //Wild kebbit caught case ObjectID.BOULDER_20651: // Wild kebbit caught
case ObjectID.BIRD_SNARE_9373: //Crimson swift caught case ObjectID.BIRD_SNARE_9373: // Crimson swift caught
case ObjectID.BIRD_SNARE_9375: //Cerulean twitch caught case ObjectID.BIRD_SNARE_9375: // Cerulean twitch caught
case ObjectID.BIRD_SNARE_9377: //Golden warbler caught case ObjectID.BIRD_SNARE_9377: // Golden warbler caught
case ObjectID.BIRD_SNARE_9379: //Copper longtail caught case ObjectID.BIRD_SNARE_9379: // Copper longtail caught
case ObjectID.BIRD_SNARE_9348: //Tropical wagtail caught case ObjectID.BIRD_SNARE_9348: // Tropical wagtail caught
case ObjectID.NET_TRAP_9004: //Green sally caught case ObjectID.NET_TRAP_9004: // Green sally caught
case ObjectID.NET_TRAP_8986: //Red sally caught case ObjectID.NET_TRAP_8986: // Red sally caught
case ObjectID.NET_TRAP_8734: //Orange sally caught case ObjectID.NET_TRAP_8734: // Orange sally caught
case ObjectID.NET_TRAP_8996: //Black sally caught case ObjectID.NET_TRAP_8996: // Black sally caught
case ObjectID.LARGE_BOULDER_28830: // Maniacal monkey tail obtained case ObjectID.LARGE_BOULDER_28830: // Maniacal monkey tail obtained
case ObjectID.LARGE_BOULDER_28831: // Maniacal monkey tail obtained case ObjectID.LARGE_BOULDER_28831: // Maniacal monkey tail obtained
if (myTrap != null) if (myTrap != null)
{ {
log.debug("Yay, you caught something");
myTrap.setState(HunterTrap.State.FULL); myTrap.setState(HunterTrap.State.FULL);
catchAtempts++; catchAtempts++;
catchSuccess++; catchSuccess++;
@@ -214,6 +194,7 @@ public class HunterPlugin extends Plugin
notifier.notify("You've caught part of a monkey's tail."); notifier.notify("You've caught part of a monkey's tail.");
} }
} }
break; break;
/* /*
* ------------------------------------------------------------------------------ * ------------------------------------------------------------------------------
@@ -225,13 +206,13 @@ public class HunterPlugin extends Plugin
case ObjectID.BIRD_SNARE: //Empty box trap case ObjectID.BIRD_SNARE: //Empty box trap
if (myTrap != null) if (myTrap != null)
{ {
log.debug("Your trap didn't catch anything");
myTrap.setState(HunterTrap.State.EMPTY); myTrap.setState(HunterTrap.State.EMPTY);
myTrap.resetTimer(); myTrap.resetTimer();
catchAtempts++; catchAtempts++;
lastActionTime = Instant.now(); lastActionTime = Instant.now();
} }
break; break;
/* /*
* ------------------------------------------------------------------------------ * ------------------------------------------------------------------------------
@@ -241,25 +222,25 @@ public class HunterPlugin extends Plugin
// Imp entering box // Imp entering box
case ObjectID.MAGIC_BOX_19225: case ObjectID.MAGIC_BOX_19225:
//Black chin shaking box // Black chin shaking box
case ObjectID.BOX_TRAP: case ObjectID.BOX_TRAP:
case ObjectID.BOX_TRAP_2026: case ObjectID.BOX_TRAP_2026:
case ObjectID.BOX_TRAP_2028: case ObjectID.BOX_TRAP_2028:
case ObjectID.BOX_TRAP_2029: case ObjectID.BOX_TRAP_2029:
//Red chin shaking box // Red chin shaking box
case ObjectID.BOX_TRAP_9381: case ObjectID.BOX_TRAP_9381:
case ObjectID.BOX_TRAP_9390: case ObjectID.BOX_TRAP_9390:
case ObjectID.BOX_TRAP_9391: case ObjectID.BOX_TRAP_9391:
case ObjectID.BOX_TRAP_9392: case ObjectID.BOX_TRAP_9392:
case ObjectID.BOX_TRAP_9393: case ObjectID.BOX_TRAP_9393:
//Grey chin shaking box // Grey chin shaking box
case ObjectID.BOX_TRAP_9386: case ObjectID.BOX_TRAP_9386:
case ObjectID.BOX_TRAP_9387: case ObjectID.BOX_TRAP_9387:
case ObjectID.BOX_TRAP_9388: case ObjectID.BOX_TRAP_9388:
//Bird traps // Bird traps
case ObjectID.BIRD_SNARE_9346: case ObjectID.BIRD_SNARE_9346:
case ObjectID.BIRD_SNARE_9347: case ObjectID.BIRD_SNARE_9347:
case ObjectID.BIRD_SNARE_9349: case ObjectID.BIRD_SNARE_9349:
@@ -267,7 +248,7 @@ public class HunterPlugin extends Plugin
case ObjectID.BIRD_SNARE_9376: case ObjectID.BIRD_SNARE_9376:
case ObjectID.BIRD_SNARE_9378: case ObjectID.BIRD_SNARE_9378:
//Deadfall trap // Deadfall trap
case ObjectID.DEADFALL_19218: case ObjectID.DEADFALL_19218:
case ObjectID.DEADFALL_19851: case ObjectID.DEADFALL_19851:
case ObjectID.DEADFALL_20128: case ObjectID.DEADFALL_20128:
@@ -275,7 +256,7 @@ public class HunterPlugin extends Plugin
case ObjectID.DEADFALL_20130: case ObjectID.DEADFALL_20130:
case ObjectID.DEADFALL_20131: case ObjectID.DEADFALL_20131:
//Net trap // Net trap
case ObjectID.NET_TRAP_9003: case ObjectID.NET_TRAP_9003:
case ObjectID.NET_TRAP_9005: case ObjectID.NET_TRAP_9005:
case ObjectID.NET_TRAP_8972: case ObjectID.NET_TRAP_8972:
@@ -304,23 +285,23 @@ public class HunterPlugin extends Plugin
@Subscribe @Subscribe
public void onGameTick(GameTick event) public void onGameTick(GameTick event)
{ {
//Check if all traps are still there, and remove the ones that are not. // Check if all traps are still there, and remove the ones that are not.
//TODO: use despawn events // TODO: use despawn events
Iterator<HunterTrap> it = traps.iterator(); Iterator<HunterTrap> it = traps.iterator();
while (it.hasNext()) while (it.hasNext())
{ {
HunterTrap trap = it.next(); HunterTrap trap = it.next();
//Look for gameobjects that are on the same location as the trap // Look for gameobjects that are on the same location as the trap
GameObjectQuery goQuery = new GameObjectQuery() GameObjectQuery goQuery = new GameObjectQuery()
.atWorldLocation(trap.getGameObject().getWorldLocation()); .atWorldLocation(trap.getGameObject().getWorldLocation());
//This is for placeable traps like box traps. There are no gameobjects on that location if the trap collapsed // This is for placeable traps like box traps. There are no gameobjects on that location if the trap collapsed
if (queryRunner.runQuery(goQuery).length == 0) if (queryRunner.runQuery(goQuery).length == 0)
{ {
it.remove(); it.remove();
log.debug("Trap removed from personal trap collection, {} left", traps.size()); log.debug("Trap removed from personal trap collection, {} left", traps.size());
} }
else //For traps like deadfalls. This is different because when the trap is gone, there is still a GameObject (boulder) else // For traps like deadfalls. This is different because when the trap is gone, there is still a GameObject (boulder)
{ {
goQuery = goQuery.idEquals(ObjectID.BOULDER_19215, ObjectID.LARGE_BOULDER); goQuery = goQuery.idEquals(ObjectID.BOULDER_19215, ObjectID.LARGE_BOULDER);
if (queryRunner.runQuery(goQuery).length != 0) if (queryRunner.runQuery(goQuery).length != 0)
@@ -353,13 +334,14 @@ public class HunterPlugin extends Plugin
* Looks for a trap in the local players trap collection, on the same * Looks for a trap in the local players trap collection, on the same
* place as the given GameObject. * place as the given GameObject.
* *
* @param gameObject * @param gameObject game object
* @return A HunterTrap object if the player has a trap on the same * @return A HunterTrap object if the player has a trap on the same
* location as the GameObject. Otherwise it returns null. * location as the GameObject. Otherwise it returns null.
*/ */
private HunterTrap getTrapFromCollection(GameObject gameObject) private HunterTrap getTrapFromCollection(GameObject gameObject)
{ {
Point gameObjectLocation = gameObject.getWorldLocation(); final Point gameObjectLocation = gameObject.getWorldLocation();
for (HunterTrap trap : traps) for (HunterTrap trap : traps)
{ {
if (gameObjectLocation.equals(trap.getGameObject().getWorldLocation())) if (gameObjectLocation.equals(trap.getGameObject().getWorldLocation()))
@@ -367,6 +349,7 @@ public class HunterPlugin extends Plugin
return trap; return trap;
} }
} }
return null; return null;
} }