Skip to content

Commit a45d1a0

Browse files
committed
Fixed fishing action spam. Added fishing line autoreplace. (Fix #9, #10)
1 parent 11a79f8 commit a45d1a0

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

main/java/net/ildar/wurm/bot/FisherBot.java

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
public class FisherBot extends Bot
1313
{
1414
private boolean repairInstrument;
15+
private boolean lineBreaks;
1516

1617
public FisherBot()
1718
{
1819
registerInputHandler(FisherBot.InputKey.r, input -> toggleRepairInstrument());
20+
registerInputHandler(FisherBot.InputKey.line, input -> handleAutoLineChange());
1921

2022
repairInstrument = true;
2123
}
@@ -35,7 +37,7 @@ public void work() throws Exception
3537

3638
}
3739
Utils.consolePrint(this.getClass().getSimpleName() + " will use " + fishingRod.getBaseName());
38-
40+
lineBreaks=fishingRod.getBaseName().contains("unstrung");
3941
World world = Mod.hud.getWorld();
4042
long tileId = Tiles.getTileId(
4143
world.getPlayerCurrentTileX(),
@@ -45,6 +47,7 @@ public void work() throws Exception
4547

4648
CreationWindow creationWindow = Mod.hud.getCreationWindow();
4749
Object progressBar = ReflectionUtil.getPrivateField(creationWindow, ReflectionUtil.getField(creationWindow.getClass(), "progressBar"));
50+
registerEventProcessors();
4851
while (isActive())
4952
{
5053
float progress = ReflectionUtil.getPrivateField(progressBar, ReflectionUtil.getField(progressBar.getClass(), "progress"));
@@ -57,8 +60,29 @@ public void work() throws Exception
5760
);
5861
}
5962

60-
if (progress == 0f)
63+
if (progress == 0f && creationWindow.getActionInUse() == 0)
6164
{
65+
if (Tiles.getTileId(world.getPlayerCurrentTileX(), world.getPlayerCurrentTileY(), 0) != tileId)
66+
tileId = Tiles.getTileId(world.getPlayerCurrentTileX(), world.getPlayerCurrentTileY(), 0);
67+
68+
if (lineBreaks)
69+
{
70+
InventoryMetaItem fishingLine = Utils.getInventoryItem("fine fishing line");
71+
if (fishingLine == null)
72+
{
73+
fishingLine = Utils.getInventoryItem("fishing line");
74+
}
75+
if (fishingLine != null)
76+
{
77+
Mod.hud.getWorld().getServerConnection().sendAction(fishingLine.getId(),
78+
new long[]{fishingRod.getId()}, new PlayerAction((short) 132, PlayerAction.ANYTHING));
79+
}
80+
else
81+
{
82+
Utils.consolePrint("You don't have any fishing line");
83+
}
84+
}
85+
6286
world.getServerConnection().sendAction(
6387
fishingRod.getId(),
6488
new long[]{tileId},
@@ -70,17 +94,30 @@ public void work() throws Exception
7094
}
7195
}
7296

73-
private void toggleRepairInstrument(){
97+
private void toggleRepairInstrument() {
7498
repairInstrument = !repairInstrument;
7599
if (repairInstrument)
76100
Utils.consolePrint("Rod auto repairing is on!");
77101
else
78102
Utils.consolePrint("Rod auto repairing is off!");
79103
}
80104

105+
private void handleAutoLineChange() {
106+
Utils.consolePrint(getClass().getSimpleName() + " will try to replace a fishing line.");
107+
lineBreaks = true;
108+
}
109+
110+
private void registerEventProcessors() {
111+
registerEventProcessor(message -> message.contains("You string the "), () -> lineBreaks = false);
112+
registerEventProcessor(message -> message.contains("The line snaps, and the fish escapes!"), () -> lineBreaks = true);
113+
}
114+
115+
81116
private enum InputKey implements Bot.InputKey {
82117
r("Toggle the source item repairing(on the left side of crafting window). " +
83-
"Usually it is an instrument. When the source item gets 10% damage player will repair it automatically", "");
118+
"Usually it is an instrument. When the source item gets 10% damage player will repair it automatically", ""),
119+
line("Replace a fishing line on the current rod",
120+
"");
84121

85122
private String description;
86123
private String usage;

0 commit comments

Comments
 (0)