Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ private int getItemIdFromContainer(ItemContainer container, int slotID)
return (item != null) ? item.getId() : -1;
}

private int getWeaponId() {
private int getWeaponId()
{
int weaponId = getItemIdFromContainer(
client.getItemContainer(InventoryID.EQUIPMENT),
EquipmentInventorySlot.WEAPON.getSlotIdx()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
import javax.inject.Inject;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Font;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPriority;
Expand Down
36 changes: 12 additions & 24 deletions src/main/java/com/attacktimer/VariableSpeed/TormentedDemons.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.attacktimer.VariableSpeed;

/*
* Copyright (c) 2024, Lexer747 <https://github.com/Lexer747>
* Copyright (c) 2024-2026, Lexer747 <https://github.com/Lexer747>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -36,7 +36,6 @@
import com.attacktimer.ClientUtils.Utils;
import net.runelite.api.Client;
import net.runelite.api.NPC;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.GameTick;

/**
Expand All @@ -59,10 +58,8 @@ public class TormentedDemons implements IVariableSpeed
{
public int apply(final Client client, final AnimationData curAnimation, final AttackProcedure atkProcedure, final int baseSpeed, final int curSpeed)
{
WorldPoint location = Utils.getLocation(client);
int weaponId = Utils.getWeaponId(client);
int targetId = Utils.getTargetId(client);
if (!attackingTormentedDemon(weaponId, location.getRegionID(), location.getX(), location.getY(), targetId))
if (!isTormentedDemon(targetId))
{
return curSpeed;
}
Expand Down Expand Up @@ -120,22 +117,6 @@ public int apply(final Client client, final AnimationData curAnimation, final At
private static final int TORMENTED_DEMON_ID = 13600;

private static final int TORMENTED_DEMON_2_ID = 13599;
private static final int TORMENTED_DEMON_REGION_ID = 16197;

private static final int TORMENTED_DEMON_REGION_2_ID = 16452;
private static final int TORMENTED_DEMON_MIN_X = 4010;

private static final int TORMENTED_DEMON_MAX_X = 4180;
private static final int TORMENTED_DEMON_MIN_Y = 4320;

private static final int TORMENTED_DEMON_MAX_Y = 4490;

private static boolean attackingTormentedDemon(int equipped, int regionId, int x, int y, int target)
{
boolean correctCoords = x >= TORMENTED_DEMON_MIN_X && x <= TORMENTED_DEMON_MAX_X && y >= TORMENTED_DEMON_MIN_Y && y <= TORMENTED_DEMON_MAX_Y;
boolean correctRegion = regionId == TORMENTED_DEMON_REGION_ID || regionId == TORMENTED_DEMON_REGION_2_ID;
return correctCoords && correctRegion && isTormentedDemon(target);
}

private static boolean isTormentedDemon(int targetId)
{
Expand Down Expand Up @@ -245,25 +226,32 @@ boolean isStale(int tick)
return false;
}


// vulnConsumed returns true if the demon was already attack, false if not and the vuln is still usable
boolean vulnConsumed(int tick)
{
if (this.attacked == tick || this.attacked == -1)
{
this.attacked = tick;
this.consumeVuln(tick);
return false;
}
else if (this.attacked > tick + VulTicksAfterEnd)
{
// already attacked within the window
// already attacked within the window don't consume the vuln again we let update handle this
return true;
}
else
{
this.attacked = tick;
this.consumeVuln(tick);
return false;
}
}

void consumeVuln(int tick)
{
this.attacked = tick;
}

@Override
public String toString()
{
Expand Down
183 changes: 183 additions & 0 deletions src/test/java/com/attacktimer/BasicTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package com.attacktimer;

/*
* Copyright (c) 2026, Lexer747 <https://github.com/Lexer747>
* 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.
*/

import static org.mockito.Mockito.when;

import java.nio.file.Paths;

import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import com.attacktimer.AttackTimerMetronomePlugin.AttackState;

import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;

import net.runelite.api.ChatMessageType;
import net.runelite.api.Player;
import net.runelite.api.events.ChatMessage;

public class BasicTests extends IntegrationTests
{
@Test
public void basicTest() throws Exception
{
ByteArrayDataOutput channel = ByteStreams.newDataOutput();
underTest.writeState(channel);
// Trivial Pre-conditions:
assertSame(AttackState.NOT_ATTACKING, underTest.attackState);

// Basic test case:
// 1. Start by setting up the player
// 2. Mock an attack animation
// 3. Check that the plugin has registered the attack
// 4. Check that the plugin counts down correctly
// 5. Check that the plugin is back to a waiting state and it still counts down

writeTestMessage("1. Start by setting up the player and plugin", channel);
int atkSpeed = 3; // no weapon equipped (4 ticks, plugin starts counting from 3)
int tick = 0;
Player mockedPlayer = pluginMockSetup();
when(mockedClient.getTickCount()).thenReturn(tick);

writeTestMessage("2. Mock an attack animation", channel);

// set the animation to an attack
when(mockedPlayer.getAnimation()).thenReturn(AnimationData.MELEE_GENERIC_SLASH.animationId);
// tell the plugin that a tick occurred
onGameTick(channel);

writeTestMessage("3. Check that the plugin has registered the attack", channel);
assertSame(AttackState.DELAYED_FIRST_TICK, underTest.attackState);
assertSame(atkSpeed, underTest.attackDelayHoldoffTicks);

// clear the animation
when(mockedPlayer.getAnimation()).thenReturn(noAnimation);

writeTestMessage("4. Check that the plugin counts down correctly", channel);
while (atkSpeed > 0)
{
tick++;
atkSpeed--;
when(mockedClient.getTickCount()).thenReturn(tick);
onGameTick(channel);
assertSame(AttackState.DELAYED, underTest.attackState);
assertSame(atkSpeed, underTest.attackDelayHoldoffTicks);
}

writeTestMessage("5. Check that the plugin is back to a waiting state and it still counts down", channel);
tick++;
onGameTick(channel);
assertSame(AttackState.NOT_ATTACKING, underTest.attackState);
while (tick < 30)
{
tick++;
when(mockedClient.getTickCount()).thenReturn(tick);
onGameTick(channel);
assertSame(AttackState.NOT_ATTACKING, underTest.attackState);
assertTrue(underTest.attackDelayHoldoffTicks < 0); // hold off should go negative
}

performStateVerificationOrUpdate(channel, Paths.get(testdata + "basicTest.txt"));
}

@Test
public void eatingFoodTest() throws Exception
{
ByteArrayDataOutput channel = ByteStreams.newDataOutput();
underTest.writeState(channel);
// Trivial Pre-conditions:
assertSame(AttackState.NOT_ATTACKING, underTest.attackState);
writeTestMessage("1. Start by setting up the player and plugin", channel);
int atkSpeed = 3; // no weapon equipped (4 ticks, plugin starts counting from 3)
int tick = 0;
Player mockedPlayer = pluginMockSetup();
when(mockedClient.getTickCount()).thenReturn(tick);

writeTestMessage("2. Mock an attack animation", channel);

// set the animation to an attack
when(mockedPlayer.getAnimation()).thenReturn(AnimationData.MELEE_GENERIC_SLASH.animationId);
// tell the plugin that a tick occurred
onGameTick(channel);

writeTestMessage("3. Check that the plugin has registered the attack", channel);
assertSame(AttackState.DELAYED_FIRST_TICK, underTest.attackState);
assertSame(atkSpeed, underTest.attackDelayHoldoffTicks);

when(mockedPlayer.getAnimation()).thenReturn(noAnimation);
underTest.writeState(channel);

writeTestMessage("Perform an eat", channel);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You eat the shark.", "", 0);
underTest.onChatMessage(chatMessage);
// the plugin wont apply the delay directly it waits until the next game tick
assertSame(3, underTest.pendingEatDelayTicks);
// Should still be same state
assertSame(AttackState.DELAYED_FIRST_TICK, underTest.attackState);
underTest.writeState(channel);

// Subsequent values should be offset by the eat delay
writeTestMessage("Next game tick", channel);
atkSpeed += 2;
onGameTick(channel);
assertSame(AttackState.DELAYED, underTest.attackState);
assertSame(atkSpeed, underTest.attackDelayHoldoffTicks);

// Note that this is essentially a "double" eat test.
writeTestMessage("Perform a fast eat", channel);
chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You eat the halibut.", "", 0);
underTest.onChatMessage(chatMessage);
// the plugin wont apply the delay directly it waits until the next game tick
assertSame(2, underTest.pendingEatDelayTicks);
// Should still be same state
assertSame(AttackState.DELAYED, underTest.attackState);
underTest.writeState(channel);

// Subsequent values should be offset by the eat delay
writeTestMessage("Next game tick", channel);
atkSpeed += 1;
onGameTick(channel);
assertSame(AttackState.DELAYED, underTest.attackState);
assertSame(atkSpeed, underTest.attackDelayHoldoffTicks);

writeTestMessage("4. Check that the plugin counts down correctly", channel);
while (atkSpeed > 0)
{
tick++;
atkSpeed--;
when(mockedClient.getTickCount()).thenReturn(tick);
onGameTick(channel);
assertSame(AttackState.DELAYED, underTest.attackState);
assertSame(atkSpeed, underTest.attackDelayHoldoffTicks);
}

performStateVerificationOrUpdate(channel, Paths.get(testdata + "eatingFoodTest.txt"));
}
}
Loading
Loading