Revert "opponentinfo: Show health bar of actors attacking the player"
This reverts commit 48ea01dd28.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2018, Adam <Adam@sigterm.info>
|
||||
* Copyright (c) 2018, Jordan Atwood <jordan.atwood423@gmail.com>
|
||||
* Copyright (c) 2021, Andre Araya <araya.andre7@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -138,50 +137,33 @@ public class OpponentInfoPlugin extends Plugin
|
||||
@Subscribe
|
||||
public void onInteractingChanged(InteractingChanged event)
|
||||
{
|
||||
final Actor player = client.getLocalPlayer();
|
||||
if (player == null)
|
||||
if (event.getSource() != client.getLocalPlayer())
|
||||
{
|
||||
return;
|
||||
}
|
||||
final Actor opponent = player.getInteracting();
|
||||
final Actor source = event.getSource();
|
||||
final Actor target = event.getTarget();
|
||||
|
||||
if (source == player)
|
||||
{
|
||||
// You have attacked an enemy
|
||||
if (target != null)
|
||||
{
|
||||
lastOpponent = target;
|
||||
lastTime = null;
|
||||
}
|
||||
// You have stopped attacking an enemy which is not attacking you
|
||||
else if (lastOpponent != null && lastOpponent.getInteracting() != player)
|
||||
{
|
||||
lastTime = Instant.now();
|
||||
}
|
||||
}
|
||||
// You are attacked while not attacking anything
|
||||
else if (target == player && opponent == null)
|
||||
{
|
||||
lastOpponent = source;
|
||||
lastTime = null;
|
||||
}
|
||||
// An enemy which was previously attacking you (which you were not attacking back) has changed its target
|
||||
else if (source == lastOpponent && opponent != lastOpponent)
|
||||
Actor opponent = event.getTarget();
|
||||
|
||||
if (opponent == null)
|
||||
{
|
||||
lastTime = Instant.now();
|
||||
return;
|
||||
}
|
||||
|
||||
lastOpponent = opponent;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameTick(GameTick gameTick)
|
||||
{
|
||||
if (lastTime != null
|
||||
&& Duration.between(lastTime, Instant.now()).compareTo(WAIT) > 0)
|
||||
if (lastOpponent != null
|
||||
&& lastTime != null
|
||||
&& client.getLocalPlayer().getInteracting() == null)
|
||||
{
|
||||
if (Duration.between(lastTime, Instant.now()).compareTo(WAIT) > 0)
|
||||
{
|
||||
lastOpponent = null;
|
||||
lastTime = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Jordan Atwood <jordan.atwood423@gmail.com>
|
||||
* Copyright (c) 2021, Andre Araya <araya.andre7@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -89,14 +88,13 @@ public class OpponentInfoPluginTest
|
||||
|
||||
interactingChanged(npc, localPlayer);
|
||||
|
||||
assertSame(npc, plugin.getLastOpponent());
|
||||
assertNull(plugin.getLastOpponent());
|
||||
assertNull(plugin.getLastTime());
|
||||
|
||||
interactingChanged(npc, null);
|
||||
|
||||
// last opponent is remembered for 5 seconds
|
||||
assertSame(npc, plugin.getLastOpponent());
|
||||
assertNotNull(plugin.getLastTime());
|
||||
assertNull(plugin.getLastOpponent());
|
||||
assertNull(plugin.getLastTime());
|
||||
|
||||
interactingChanged(localPlayer, npc);
|
||||
|
||||
@@ -110,9 +108,9 @@ public class OpponentInfoPluginTest
|
||||
|
||||
interactingChanged(localPlayer, null);
|
||||
|
||||
// last opponent is remembered as it is still attacking the player
|
||||
// last opponent is remembered for 5 seconds
|
||||
assertSame(npc, plugin.getLastOpponent());
|
||||
assertNull(plugin.getLastTime());
|
||||
assertNotNull(plugin.getLastTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,14 +120,13 @@ public class OpponentInfoPluginTest
|
||||
|
||||
interactingChanged(otherPlayer, localPlayer);
|
||||
|
||||
assertSame(otherPlayer, plugin.getLastOpponent());
|
||||
assertNull(plugin.getLastOpponent());
|
||||
assertNull(plugin.getLastTime());
|
||||
|
||||
interactingChanged(otherPlayer, null);
|
||||
|
||||
// last opponent is remembered for 5 seconds
|
||||
assertSame(otherPlayer, plugin.getLastOpponent());
|
||||
assertNotNull(plugin.getLastTime());
|
||||
assertNull(plugin.getLastOpponent());
|
||||
assertNull(plugin.getLastTime());
|
||||
|
||||
interactingChanged(localPlayer, otherPlayer);
|
||||
|
||||
@@ -143,9 +140,9 @@ public class OpponentInfoPluginTest
|
||||
|
||||
interactingChanged(localPlayer, null);
|
||||
|
||||
// last opponent is remembered as it is still attacking the player
|
||||
// last opponent is remembered for 5 seconds
|
||||
assertSame(otherPlayer, plugin.getLastOpponent());
|
||||
assertNull(plugin.getLastTime());
|
||||
assertNotNull(plugin.getLastTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,180 +172,6 @@ public class OpponentInfoPluginTest
|
||||
assertNull(plugin.getLastTime());
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that the current opponent in multi is always the npc that the player is attacking
|
||||
*/
|
||||
@Test
|
||||
public void testAttackingEnemyInMulti()
|
||||
{
|
||||
final Player otherPlayer = mock(Player.class);
|
||||
final NPC aggro = mock(NPC.class), attacked = mock(NPC.class);
|
||||
|
||||
interactingChanged(localPlayer, null);
|
||||
|
||||
// verify that there is currently no opponent
|
||||
assertNull(plugin.getLastOpponent());
|
||||
|
||||
// some npc attacks the player
|
||||
interactingChanged(aggro, localPlayer);
|
||||
|
||||
// verify that the current opponent is the aggressive npc
|
||||
assertSame(aggro, plugin.getLastOpponent());
|
||||
|
||||
// the player attacks a different npc
|
||||
interactingChanged(localPlayer, attacked);
|
||||
|
||||
// verify the attacked npc is now considered the current opponent
|
||||
assertSame(attacked, plugin.getLastOpponent());
|
||||
|
||||
// the npc attacks them back
|
||||
interactingChanged(attacked, localPlayer);
|
||||
|
||||
// verify that the current opponent is still the attacked npc
|
||||
assertSame(attacked, plugin.getLastOpponent());
|
||||
|
||||
// the player is attacked by an aggressive npc while attacking a different npc
|
||||
interactingChanged(aggro, localPlayer);
|
||||
|
||||
// verify that the current opponent is still the npc the player is attacking
|
||||
assertSame(attacked, plugin.getLastOpponent());
|
||||
|
||||
// the npc attacking the player that is not the current opponent attacks a different player
|
||||
interactingChanged(aggro, otherPlayer);
|
||||
|
||||
// verify that the current opponent is still the npc the player is attacking
|
||||
assertSame(attacked, plugin.getLastOpponent());
|
||||
|
||||
// the npc the player is attacking, the current opponent, attacks a different player
|
||||
interactingChanged(attacked, otherPlayer);
|
||||
|
||||
// verify that the current opponent is still the npc the player is attacking
|
||||
assertSame(attacked, plugin.getLastOpponent());
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that the current opponent is the expected npc while the player is not attacking anything
|
||||
*/
|
||||
@Test
|
||||
public void testIdleInMulti()
|
||||
{
|
||||
final Player otherPlayer = mock(Player.class);
|
||||
final NPC aggroFirst = mock(NPC.class), aggroRecent = mock(NPC.class);
|
||||
|
||||
interactingChanged(localPlayer, null);
|
||||
|
||||
// verify that there is currently no opponent
|
||||
assertNull(plugin.getLastOpponent());
|
||||
|
||||
// some npc attacks the player
|
||||
interactingChanged(aggroFirst, localPlayer);
|
||||
|
||||
// verify that the current opponent is the aggressive npc
|
||||
assertSame(aggroFirst, plugin.getLastOpponent());
|
||||
|
||||
// the player is attacked by a different npc
|
||||
interactingChanged(aggroRecent, localPlayer);
|
||||
|
||||
// verify that the current opponent is the most recent aggressor
|
||||
assertSame(aggroRecent, plugin.getLastOpponent());
|
||||
|
||||
// an npc that is not the current opponent targets another player
|
||||
interactingChanged(aggroFirst, otherPlayer);
|
||||
|
||||
// verify that the current opponent is still the most recent aggressor
|
||||
assertSame(aggroRecent, plugin.getLastOpponent());
|
||||
|
||||
// the current opponent switches targets to another player
|
||||
interactingChanged(aggroRecent, otherPlayer);
|
||||
|
||||
// verify that there is no longer an opponent
|
||||
// (if lastTime is not null, then the lastOpponent will become null after OpponentInfoPlugin.WAIT time)
|
||||
assertNotNull(plugin.getLastTime());
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that the current opponent is the expected npc in singles
|
||||
*/
|
||||
@Test
|
||||
public void testSingles()
|
||||
{
|
||||
final Player otherPlayer = mock(Player.class);
|
||||
final NPC npc = mock(NPC.class);
|
||||
|
||||
interactingChanged(localPlayer, null);
|
||||
|
||||
// verify that there is currently no opponent
|
||||
assertNull(plugin.getLastOpponent());
|
||||
|
||||
// some npc attacks the player
|
||||
interactingChanged(npc, localPlayer);
|
||||
|
||||
// verify that the attacking npc is the current opponent
|
||||
assertSame(npc, plugin.getLastOpponent());
|
||||
|
||||
// the npc stops attacking the player
|
||||
interactingChanged(npc, null);
|
||||
|
||||
// verify that there is no longer an opponent
|
||||
// (if lastTime is not null, then the lastOpponent will become null after OpponentInfoPlugin.WAIT time)
|
||||
assertNotNull(plugin.getLastTime());
|
||||
|
||||
// the player attacks the npc
|
||||
interactingChanged(localPlayer, npc);
|
||||
|
||||
// verify that the attacked npc is the current opponent
|
||||
assertSame(npc, plugin.getLastOpponent());
|
||||
// verify that the hp bar will no longer be hidden
|
||||
assertNull(plugin.getLastTime());
|
||||
|
||||
// the npc attacks them back
|
||||
interactingChanged(npc, localPlayer);
|
||||
|
||||
// verify that the attacked npc is still the current opponent
|
||||
assertSame(npc, plugin.getLastOpponent());
|
||||
|
||||
// the player stops attacking the npc
|
||||
interactingChanged(localPlayer, null);
|
||||
|
||||
// verify that the npc attacking the player is still the current opponent
|
||||
assertSame(npc, plugin.getLastOpponent());
|
||||
// verify that the hp bar will not be hidden (because the npc is still attacking the player)
|
||||
assertNull(plugin.getLastTime());
|
||||
|
||||
// the player attacks the npc again
|
||||
interactingChanged(localPlayer, npc);
|
||||
|
||||
// verify the npc is still the opponent
|
||||
assertSame(npc, plugin.getLastOpponent());
|
||||
|
||||
// the npc stops attacking the player
|
||||
interactingChanged(npc, null);
|
||||
|
||||
// verify that the attacked npc is still the current opponent
|
||||
assertSame(npc, plugin.getLastOpponent());
|
||||
|
||||
// the player stops attacking the npc while the npc is not attacking the player
|
||||
interactingChanged(localPlayer, null);
|
||||
|
||||
// verify that there is no longer an opponent
|
||||
// (if lastTime is not null, then the lastOpponent will become null after OpponentInfoPlugin.WAIT time)
|
||||
assertNotNull(plugin.getLastTime());
|
||||
|
||||
// the npc attacks a different player
|
||||
interactingChanged(npc, otherPlayer);
|
||||
|
||||
// verify there is still no opponent
|
||||
// (if lastTime is not null, then the lastOpponent will become null after OpponentInfoPlugin.WAIT time)
|
||||
assertNotNull(plugin.getLastTime());
|
||||
|
||||
// the npc stops attacking the other player
|
||||
interactingChanged(npc, null);
|
||||
|
||||
// verify there is still no opponent
|
||||
// (if lastTime is not null, then the lastOpponent will become null after OpponentInfoPlugin.WAIT time)
|
||||
assertNotNull(plugin.getLastTime());
|
||||
}
|
||||
|
||||
private void interactingChanged(final Actor source, final Actor target)
|
||||
{
|
||||
when(source.getInteracting()).thenReturn(target);
|
||||
|
||||
Reference in New Issue
Block a user