Jump to content

switching case if store contains items


Recommended Posts

Posted

practicing with a shop buyer. Looking to hop worlds if store doesnt contain items.

 

 

i.e 

 
 
final String items[] = new String[] {"Small fishing net", "Harpoon", "Lobster Pot",   };
 
 
private State getState() {
if (!inventory.isFull())
return State.BUY;
if (inventory.isFull())
return State.BANK;
if (!store.contains(items))
return State.HOP;
return State.WAIT;
}
Posted (edited)

 

practicing with a shop buyer. Looking to hop worlds if store doesnt contain items.

 

 

i.e 

 
 
final String items[] = new String[] {"Small fishing net", "Harpoon", "Lobster Pot",   };
 
 
private State getState() {
if (!inventory.isFull())
return State.BUY;
if (inventory.isFull())
return State.BANK;
if (!store.contains(items))
return State.HOP;
return State.WAIT;
}
if inventory is full
    if not in bank
        walk to bank
    else if bank is not open
        open bank
    else deposit items
else if not in store
    walk to store
else if store is not open
    open store
else if store contains items
    buy items
else 
    world hop

You are trying to pass an array of strings but if you read the api it shows you it expects a single String.

 

75dac7d3c82b351082c92a3111d5523d.png

 

It accepts String... and List<String> as well because Store extends ItemContainer, and those methods can be found in ItemContainer

Edited by Explv
  • Like 1
Posted

You are trying to pass an array of strings but if you read the api it shows you it expects a single String.

 

75dac7d3c82b351082c92a3111d5523d.png

 

 

so it would look more like:

private State getState() {
if (!inventory.isFull())
return State.BUY;
if (inventory.isFull())
return State.BANK;
if (store.getAmount("Pot") == 0 && store.getAmount("Vial of water") == 0)
return State.HOP;
return State.WAIT;
}

?

Posted (edited)

so it would look more like:

private State getState() {
if (!inventory.isFull())
return State.BUY;
if (inventory.isFull())
return State.BANK;
if (store.getAmount("Pot") == 0 && store.getAmount("Vial of water") == 0)
return State.HOP;
return State.WAIT;
}

?

 

Well does it work?

 

Create a method called isShopEmpty.

have a for loop and if any of the items have an amount > 0 return as false;

 

Edited by House
Posted
if inventory is full
    if not in bank
        walk to bank
    else if bank is not open
        open bank
    else deposit items
else if not in store
    walk to store
else if store is not open
    open store
else if store contains items
    buy items
else 
    world hop

It accepts String... and List<String> as well because Store extends ItemContainer, and those methods can be found in ItemContainer

 

ok i see what you done there

it will hop if no other statement is true (compared to my wait if no other statement is true)

  • Like 1
Posted

so it would look more like:

private State getState() {
if (!inventory.isFull())
return State.BUY;
if (inventory.isFull())
return State.BANK;
if (store.getAmount("Pot") == 0 && store.getAmount("Vial of water") == 0)
return State.HOP;
return State.WAIT;
}

?

 

That logic will not work. Look at your first two conditions. Your inventory is either full, or not full, therefore your script will always be in the BUY or BANK state.

Posted

if(getStore().isOpen()) {
if(getStore().getAmount(items) <= 0) {
return State.HOP;
}
}

That logic will not work. Look at your first two conditions. Your inventory is either full, or not full, therefore your script will always be in the BUY or BANK state.

Like he said. It can never reach your hop state because the first or second one are always true

Posted (edited)
if(getStore().isOpen()) {
if(getStore().getAmount(items) <= 0) {
return State.HOP;
}
}

Like he said. It can never reach your hop state because the first or second one are always true

 

 

 

That logic will not work. Look at your first two conditions. Your inventory is either full, or not full, therefore your script will always be in the BUY or BANK state.

 

 

Does this look better

private State getState() {
if (shop.contains(myPlayer()))
return State.BUY;
if (inventory.isFull())
return State.BANK;
if(getStore().isOpen()) {
if(getStore().getAmount(items) <= 0) {
return State.HOP;
}
}
return State.WAIT;
}
Edited by Lewis
Posted (edited)

 

Does this look better

private State getState() {
if (shop.contains(myPlayer()))
return State.BUY;
if (inventory.isFull())
return State.BANK;
if(getStore().isOpen()) {
if(getStore().getAmount(items) <= 0) {
return State.HOP;
}
}
return State.WAIT;
}

 

Still not right, what if your inventory is full, and you are in the store? Your bot will carry on trying to buy even though it has no space

Edited by Explv
Posted (edited)

Still not right, what if your inventory is full, and you are in the store? Your bot will carry on trying to buy even though it has no space

 

 

Hows this logic looking:

private State getState() {
if (shop.contains(myPlayer()) && !inventory.isFull())
return State.BUY;
if (shop.contains(myPlayer()) && inventory.isFull())
return State.WALK_BANK;
if (depositBox.contains(myPlayer()) && inventory.isFull())
return State.BANK;
if (!shop.contains(myPlayer()) && !inventory.isFull())
return State.WALK_SHOP;
if(getStore().isOpen()) {
if(getStore().getAmount(items) <= 0) {
return State.HOP;
}
}
return State.WAIT;
}
Edited by Lewis
Posted
if (wydinShop.contains(myPlayer()) && inventory.isFull())
return State.WALK_BANK;

^^ This will make your script get stuck. What if your script lags out half way to the bank. Then it's not in the shop anymore and its not in the bank and you're inventory is full. Do if (!Bank.contains(myPlayer) instead of checking if in the shop to start webWalk. 

Posted (edited)
if (wydinShop.contains(myPlayer()) && inventory.isFull())
return State.WALK_BANK;

^^ This will make your script get stuck. What if your script lags out half way to the bank. Then it's not in the shop anymore and its not in the bank and you're inventory is full. Do if (!Bank.contains(myPlayer) instead of checking if in the shop to start webWalk. 

 

 

ohh right, like so

private State getState() {
if (wydinShop.contains(myPlayer()) && !inventory.isFull())
return State.BUY;
if (!depositBox.contains(myPlayer()) && inventory.isFull())
return State.WALK_BANK;
if (depositBox.contains(myPlayer()) && inventory.isFull())
return State.BANK;
if (!wydinShop.contains(myPlayer()) && !inventory.isFull())
return State.WALK_SHOP;
if(getStore().isOpen()) {
if(getStore().getAmount(items) <= 0) {
return State.HOP;
}
}
return State.WAIT;
}
Edited by Lewis

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...