Jump to content

Edible Snippet


Joseph

Recommended Posts

Have fun biggrin.png

edit: updated it

import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.script.Script;

public enum Edible	{
	CAKE("slice of cake", "2/3 cake", "cake"),
	COOKED_MEAT,
	TUNA_POTATO,
	TUNA,
	HERRING,
	TROUT,
	SALMON,
	BASS,
	LOBSTER,
	SWORDFISH,
	MONKFISH,
	MANTA_RAY,
	SHARK;
	
	private String[] names;

	Edible(String...names)	{
		this.names = names.length > 0 ? names: new String[] {super.name().toLowerCase().replace("_", " ")};
	}
	
	@Override
	public String toString()	{
		return super.name().toLowerCase().replace("_", " ");
	}
	
	public boolean contains(Script s)	{
		return s.inventory.contains(names);
	}
	
	public boolean eat(Script s)	{
		Item item = s.inventory.getItem(names);
		return item.interact();
	}		
}
Edited by josedpay
  • Like 1
Link to comment
Share on other sites

wut?

 

Why can't you just interact with anything that has the eat option instead of predefined item names.

 

Poison karambwan

Rock cake

(+ all the healing drinks such as tea, jug of wine, etc... that have a drink option instead of "eat")

 

Here's mine, I like to have heal amount data for smart eating and ids just in case:

package food;

import id.Id;
	
	public enum Food {
				
		TUNA_POTATO("Tuna potato", Id.TUNA_POTATO.getId(), 22),
		MANTA_RAY("Manta ray", Id.MANTA_RAY.getId(), 22),
		SEA_TURTLE("Sea turtle", Id.SEA_TURTLE.getId(), 21),
		SHARK("Shark", Id.SHARK.getId(), 20),
		MONKFISH("Monkfish", Id.MONKFISH.getId(), 16),
		SWORDFISH("Swordfish", Id.SWORDFISH.getId(), 14),
		BASS("Bass", Id.BASS.getId(), 13),
		LOBSTER("Lobster", Id.LOBSTER.getId(), 12),
		RAINBOW_FISH("Rainbow fish", Id.RAINBOW_FISH.getId(), 11),
		JUG_OF_WINE("Jug of wine", Id.JUG_OF_WINE.getId(), 10),
		TUNA("Tuna", Id.TUNA.getId(), 10),
		SALMON("Salmon", Id.SALMON.getId(), 9),
		PIKE("Pike", Id.PIKE.getId(), 8),
		TROUT("Trout", Id.TROUT.getId(), 7),
		COD("Cod", Id.COD.getId(), 7),
		MACKEREL("Mackerel", Id.MACKEREL.getId(), 6),
		CHOCOLATE_CAKE("Chocolate cake", Id.CHOCOLATE_CAKE.getId(), 5),
		TWO_THIRD_CHOCOLATE_CAKE("2/3 chocolate cake", Id.TWO_THIRD_CHOCOLATE_CAKE.getId(), 5),
		CHOCOLATE_SLICE("Chocolate slice", Id.CHOCOLATE_SLICE.getId(), 5),
		HERRING("Herring", Id.HERRING.getId(), 5),
		BREAD("Bread", Id.BREAD.getId(), 5),
		CAKE("Cake", Id.CAKE.getId(), 4),
		TWO_THIRD_CAKE("2/3 cake", Id.TWO_THIRD_CAKE.getId(), 4),
		SLICE_OF_CAKE("Slice of cake", Id.SLICE_OF_CAKE.getId(), 4),
		COOKED_CHICKEN("Cooked chicken", Id.COOKED_CHICKEN.getId(), 4),
		COOKED_MEAT("Cooked meat", Id.COOKED_MEAT.getId(), 4),
		SARDINE("Sardine", Id.SARDINE.getId(), 4),
		KARAMBWANJI("Karambwanji", Id.KARAMBWANJI.getId(), 3),
		SHRIMPS("Shrimps", Id.SHRIMPS.getId(), 3);
	
		private final String name;
		private final int id;
		private final int healAmount;

		Food(final String name, final int id, final int healAmount) {
			this.name = name;
			this.id = id;
			this.healAmount = healAmount;
		}

		public String getName() {
			return name;
		}

		public int getId() {
			return id;
		}

		public int getHealAmount() {
			return healAmount;
		}

		@Override
		public String toString() {
			return name;
		}
		
	}	
Edited by Botrepreneur
Link to comment
Share on other sites

wut?

 

Why can't you just interact with anything that has the eat option instead of predefined item names.

So you could use in a gui. Make it Gui friendly. So people dont have to consistently have to look up the item id, then having to type it in the gui. When they could just choose out of an enum.

 

code:

JComboBox<Edible> list = new JComboBox(Edible.values()); 

for example:

wMKUmE3.png

 

 

 

Poison karambwan

Rock cake

(+ all the healing drinks such as tea, jug of wine, etc... that have a drink option instead of "eat")

 

Here's mine, I like to have heal amount data for smart eating and ids just in case:

		CHOCOLATE_CAKE("Chocolate cake", Id.CHOCOLATE_CAKE.getId(), 5),
		TWO_THIRD_CHOCOLATE_CAKE("2/3 chocolate cake", Id.TWO_THIRD_CHOCOLATE_CAKE.getId(), 5),
		CHOCOLATE_SLICE("Chocolate slice", Id.CHOCOLATE_SLICE.getId(), 5),

		CAKE("Cake", Id.CAKE.getId(), 4),
		TWO_THIRD_CAKE("2/3 cake", Id.TWO_THIRD_CAKE.getId(), 4),
		SLICE_OF_CAKE("Slice of cake", Id.SLICE_OF_CAKE.getId(), 4),

 

why use id when you could use names. Also there no need to create 3 variables when you could create one. And have an array of names. Like i do in my enum. Plus since inventory get item uses an array as its argument to search for items.

s.inventory.getItem(String...names);

 it will search for using the array for the first available item. Which reduces the enum variables sizes.

Edited by josedpay
Link to comment
Share on other sites

 

Have fun biggrin.png

public enum Edible	{
	CAKE("slice of cake", "2/3 cake", "cake"),
	COOK_MEAT,
	TUNA_POTATO,
	TUNA,
	HERRING,
	TROUT,
	SALMON,
	BASS,
	LOBSTER,
	SWORDFISH,
	MONKFISH,
	MANTA_RAY,
	SHARK;
	
	private String[] names;

	Edible(String...names)	{
		this.names = names != null ? names: new String[] {super.name().toLowerCase().replace("_", " ")};
	}
	
	@Override
	public String toString()	{
		return super.name().toLowerCase().replace("_", " ");
	}
	
	public boolean contains(Script s)	{
		return s.inventory.contains(names);
	}
	
	public boolean eat(Script s)	{
		Item item = s.inventory.getItem(names);
		return item.interact();
	}		
}

 

I dont think your snippet will actually work; From just looking at it..

In your constructor you default the name to the lowercase version of the enum name if the param is null; However, varargs parameters are never null even if you dont specify any elements. Eg. Your 'names' param in constructor will never be null, but rather have length 0 for items with no names specified

 

I haven't actually tried it, though

 

EDIT: Also, it's called "Cooked meat"

Edited by FrostBug
  • Like 1
Link to comment
Share on other sites

 

why use id when you could use names. Also there no need to create 3 variables when you could create one. And have an array of names. Like i do in my enum. Plus since inventory get item uses an array as its argument to search for items.

s.inventory.getItem(String...names);

 it will search for using the array for the first available item. Which reduces the enum variables sizes.

 

I use both name and id (id only for failsafe purposes).

I'll probably add varags instead of having multiple entries for multibite foods, not sure why I didn't in the first place...

  • Like 1
Link to comment
Share on other sites

I dont think your snippet will actually work; From just looking at it..

In your constructor you default the name to the lowercase version of the enum name if the param is null; However, varargs parameters are never null even if you dont specify any elements. Eg. Your 'names' param in constructor will never be null, but rather have length 0 for items with no names specified

 

I haven't actually tried it, though

 

EDIT: Also, it's called "Cooked meat"

ya good call, i just change the the null check to size check biggrin.png. Now it works

i updated cooked food

Edited by josedpay
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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