-
-
Notifications
You must be signed in to change notification settings - Fork 46
Cargo Hold Tracker: Restore Deposit-All Tracking #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BBeeaarr
wants to merge
2
commits into
LlemonDuck:main
Choose a base branch
from
BBeeaarr:cargohold-fix-deposit-all
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+79
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,12 +36,15 @@ | |
| import net.runelite.api.events.ItemContainerChanged; | ||
| import net.runelite.api.events.MenuOptionClicked; | ||
| import net.runelite.api.events.OverheadTextChanged; | ||
| import net.runelite.api.Preferences; | ||
| import net.runelite.api.events.SoundEffectPlayed; | ||
| import net.runelite.api.events.StatChanged; | ||
| import net.runelite.api.events.WidgetLoaded; | ||
| import net.runelite.api.gameval.InterfaceID; | ||
| import net.runelite.api.gameval.InventoryID; | ||
| import net.runelite.api.gameval.ItemID; | ||
| import net.runelite.api.gameval.VarbitID; | ||
| import net.runelite.api.gameval.VarPlayerID; | ||
| import net.runelite.api.widgets.Widget; | ||
| import net.runelite.client.config.ConfigManager; | ||
| import net.runelite.client.eventbus.Subscribe; | ||
|
|
@@ -118,6 +121,14 @@ public class CargoHoldTracker | |
|
|
||
| private int lastXp; | ||
| private boolean pendingJenkinsAction; | ||
| //sfx variables | ||
| private boolean sfxVolumeOverridden = false; | ||
| private int previousSfxVolume = -1; | ||
| private static final int SFX_OVERRIDE_VOLUME = 1; | ||
| private static final int SFX_DEPOSIT_ALL_ID = 10905; | ||
| private static final int DEPOSIT_ALL_MAX_TICKS_TIMEOUT = 12; | ||
| private int depositAllTicksRemaining; | ||
| private Multiset<Integer> initialDepositAllInventory; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be able to use |
||
|
|
||
| @Inject | ||
| public CargoHoldTracker(Client client, ConfigManager configManager, BoatTracker boatTracker, CourierTaskTracker courierTaskTracker) | ||
|
|
@@ -283,6 +294,11 @@ public void onGameTick(GameTick e) | |
| { | ||
| pendingJenkinsAction = false; | ||
|
|
||
| if (--depositAllTicksRemaining <= 0) | ||
| { | ||
| resetDepositAllState(); | ||
| } | ||
|
|
||
| if (--pendingInventoryAction < 0) | ||
| { | ||
| sawItemContainerUpdate = false; | ||
|
|
@@ -330,6 +346,13 @@ public void onMenuOptionClicked(MenuOptionClicked e) | |
| { | ||
| return; | ||
| } | ||
| if (e.getMenuOption().equals("Deposit-all")) | ||
| { | ||
| beginSfxOverrideIfMuted(); | ||
| depositAllTicksRemaining = DEPOSIT_ALL_MAX_TICKS_TIMEOUT; | ||
| initialDepositAllInventory = getInventoryMap(); | ||
| log.debug("Initial deposit-all player inventory {}", initialDepositAllInventory); | ||
| } | ||
|
|
||
| Widget cargoHoldWidget = client.getWidget(InterfaceID.SailingBoatCargohold.UNIVERSE); // todo confirm | ||
| if (cargoHoldWidget != null && !cargoHoldWidget.isHidden()) | ||
|
|
@@ -356,6 +379,25 @@ public void onWidgetLoaded(WidgetLoaded e) | |
| } | ||
| } | ||
|
|
||
| @Subscribe | ||
| public void onSoundEffectPlayed(SoundEffectPlayed e) | ||
| { | ||
| if (sfxVolumeOverridden) | ||
| { | ||
| e.consume(); | ||
| } | ||
| if (e.getSoundId() == SFX_DEPOSIT_ALL_ID && depositAllTicksRemaining > 0) | ||
| { | ||
|
|
||
| Multiset<Integer> deposit = Multisets.difference(initialDepositAllInventory, getInventoryMap()); // items missing from inv that were in prior snapshot | ||
| Multiset<Integer> cargoHoldToUpdate = cargoHold(); | ||
| deposit.entrySet().forEach(entry -> cargoHoldToUpdate.add(entry.getElement(), entry.getCount())); | ||
| log.debug("updated cargo hold from deposit-all inventory delta {}", cargoHoldToUpdate); | ||
| writeToConfig(); | ||
| resetDepositAllState(); | ||
| } | ||
| } | ||
|
|
||
| private void resetInventoryDeltaState() | ||
| { | ||
| pendingInventoryAction = 0; | ||
|
|
@@ -497,4 +539,41 @@ private void writeToConfig(int boatSlot) | |
| log.trace("wrote cargoHold {} to config {} = {}", boatSlot, key, configValue); | ||
| } | ||
|
|
||
| private void setSfxVolume(int vol) | ||
| { | ||
| Preferences preferences = client.getPreferences(); | ||
| preferences.setSoundEffectVolume(vol); | ||
|
|
||
| client.getVarps()[VarPlayerID.OPTION_SOUNDS] = vol; | ||
| client.queueChangedVarp(VarPlayerID.OPTION_SOUNDS); | ||
| } | ||
|
|
||
| private void beginSfxOverrideIfMuted() | ||
| { | ||
| Preferences preferences = client.getPreferences(); | ||
| int current = preferences.getSoundEffectVolume(); | ||
| if (current != 0 || sfxVolumeOverridden) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| previousSfxVolume = current; | ||
| sfxVolumeOverridden = true; | ||
|
|
||
| setSfxVolume(SFX_OVERRIDE_VOLUME); | ||
| } | ||
|
|
||
| private void resetDepositAllState() | ||
| { | ||
| if (sfxVolumeOverridden) { | ||
| // if we never captured previous, default to muted | ||
| int restore = previousSfxVolume >= 0 ? previousSfxVolume : 0; | ||
| setSfxVolume(restore); | ||
| sfxVolumeOverridden = false; | ||
| previousSfxVolume = -1; | ||
| } | ||
|
|
||
| depositAllTicksRemaining = 0; | ||
| initialDepositAllInventory = null; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
12 ticks gives ~5 seconds for the deposit to occur. Can adjust if necessary