Skip to content

Commit

Permalink
saltscooldown: use varb to detect crush
Browse files Browse the repository at this point in the history
Closes #105
  • Loading branch information
LlemonDuck committed Oct 20, 2024
1 parent 2b1f860 commit a68bbc5
Showing 1 changed file with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.Varbits;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;

Expand All @@ -25,20 +27,23 @@ public class SmellingSaltsCooldown implements PluginLifecycleComponent
private final TombsOfAmascutConfig config;

private long lastSalt;
private boolean clickQueued;
private int lastSaltVarb;
private boolean clickConsumeQueued;

@Override
public boolean isEnabled(TombsOfAmascutConfig config, RaidState raidState)
{
return config.smellingSaltsCooldown() > 0;
return raidState.isInRaid()
&& config.smellingSaltsCooldown() > 0;
}

@Override
public void startUp()
{
clickQueued = false;
clickConsumeQueued = false;
lastSalt = 0;
eventBus.register(this);
lastSaltVarb = client.getVarbitValue(Varbits.BUFF_STAT_BOOST);
}

@Override
Expand All @@ -47,18 +52,29 @@ public void shutDown()
eventBus.unregister(this);
}

@Subscribe
public void onVarbitChanged(VarbitChanged e)
{
if (e.getVarbitId() == Varbits.BUFF_STAT_BOOST && e.getValue() > lastSaltVarb)
{
log.debug("Detected salt consumption");
lastSalt = e.getValue();
lastSalt = System.currentTimeMillis();
}
}

@Subscribe
public void onGameTick(GameTick e)
{
if (clickQueued)
if (clickConsumeQueued)
{
client.addChatMessage(
ChatMessageType.GAMEMESSAGE,
"",
"You are already boosted by smelling salts!",
null
);
clickQueued = false;
clickConsumeQueued = false;
}
}

Expand All @@ -69,15 +85,12 @@ public void onMenuOptionClicked(MenuOptionClicked e)
&& e.getMenuOption().equals("Crush"))
{
long now = System.currentTimeMillis();
if (now - lastSalt > (config.smellingSaltsCooldown() * 1000L))
if (now - lastSalt < (config.smellingSaltsCooldown() * 1000L))
{
lastSalt = now;
return;
// delay the blocking chat message until the next game tick to feel a bit more authentic (and less spammy)
clickConsumeQueued = true;
e.consume();
}

// delay the blocking chat message until the next game tick to feel a bit more authentic (and less spammy)
clickQueued = true;
e.consume();
}
}
}

0 comments on commit a68bbc5

Please sign in to comment.