Jump to content

switching case if store contains items


Lewis

Recommended Posts

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;
}
Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

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;
}

?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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