Jump to content

[Snippet] Ore & Smithing Bar data


Botre

Recommended Posts

Example:

	public static void main(String[] args) {
		Map<Ore, Integer> o = SmithingBar.ADAMANTITE.getOres();
		System.out.println("In order to make an adamantite bar I need: ");
		for (Ore ore : o.keySet()) {
			System.out.println("\t" + o.get(ore) + " " + ore);
		}
		System.out.println("... and " +SmithingBar.ADAMANTITE.getRequiredSmithingLevel() + " smithing.");
	}

226b62edfa5239288be65d33faf8a5ce.png

Ore enum:

public enum Ore {

	COPPER("Copper ore"),
	TIN("Tin ore"),
	BLURITE("Blurite ore"),
	IRON("Iron ore"),
	SILVER("Silver ore"),
	COAL("Coal ore"),
	GOLD("Gold ore"),
	MITHRIL("Mithril ore"),
	ADAMANTITE("Adamantite ore"),
	RUNITE("Runite ore");
	
	private String name;
	
	private Ore(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}
	
	@Override
	public String toString() {
		return getName();
	}
	
}

SmithingBar enum:

package org.botre.data;

import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;

public enum SmithingBar {
	
	BRONZE("Bronze bar", 1),
	BLURITE("Blurite bar", 8),
	IRON("Iron bar", 15),
	SILVER("Silver bar", 20),
	STEEL("Steel bar", 30),
	GOLD("Gold bar", 40),
	MITHRIL("Mithril bar", 50),
	ADAMANTITE("Adamantite bar", 70),
	RUNITE("Runite bar", 85);
	
	private static final Map<SmithingBar, Map<Ore, Integer>> ORE_RECIPES = Collections.unmodifiableMap(initOres());
	
	private String name;
	private int requiredSmithingLevel;
	
	private SmithingBar(String name, int requiredSmithingLevel) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}
	
	public int getRequiredSmithingLevel() {
		return requiredSmithingLevel;
	}
	
	public Map<Ore, Integer> getOres() {
		return ORE_RECIPES.get(this);
	}
	
	@Override
	public String toString() {
		return getName();
	}

	private static Map<SmithingBar, Map<Ore, Integer>> initOres() {
		Map<SmithingBar, Map<Ore, Integer>> map = new EnumMap<>(SmithingBar.class);
		for (SmithingBar bar : values()) {
			Map<Ore, Integer> ores = new EnumMap<>(Ore.class);
			switch (bar) {
			case BRONZE:
				ores.put(Ore.COPPER, 1);
				ores.put(Ore.TIN, 1);
				break;
			case BLURITE:
				ores.put(Ore.BLURITE, 1);
				break;
			case IRON:
				ores.put(Ore.IRON, 1);
				break;
			case SILVER:
				ores.put(Ore.SILVER, 1);
				break;
			case STEEL:
				ores.put(Ore.IRON, 1);
				ores.put(Ore.COAL, 2);
				break;
			case GOLD:
				ores.put(Ore.GOLD, 1);
				break;
			case MITHRIL:
				ores.put(Ore.MITHRIL, 1);
				ores.put(Ore.COAL, 4);
				break;
			case ADAMANTITE:
				ores.put(Ore.ADAMANTITE, 1);
				ores.put(Ore.COAL, 6);
				break;
			case RUNITE:
				ores.put(Ore.RUNITE, 1);
				ores.put(Ore.COAL, 8);
				break;
			}
			map.put(bar, ores);
		}
		return map;
	}

	
}

  • Like 2
Link to comment
Share on other sites

Good and clean code release, you planning on releasing a free/premium smithing script maybe too? Or just giving our a release related to smithing?

 

Either way I'm liking this nice clean code style.

 

Needed this data for the Superheat component of my Magic script, figured maybe someone else could benefit from it too :p

 

The data makes writing a smelter a matter of minutes though:

package org.botre.script;

import java.util.Map;

import org.botre.data.Ore;
import org.botre.data.SmithingBar;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;

//MF
public class SmeltingScript extends Script {

	private SmithingBar bar = SmithingBar.STEEL;
	private Map<Ore, Integer> ores = bar.getOres();
	private int barsPerInventory =  -1;
	
	@Override
	public void onStart() throws InterruptedException {
		super.onStart();
		//Find amount of bars that can fit in one 28-slot inventory.
		for (Ore ore : ores.keySet()) {
			barsPerInventory += ores.get(ore);
		}
		barsPerInventory = 28 / barsPerInventory;
	}
	
	@Override
	public int onLoop() throws InterruptedException {
		boolean bank = false;
		for (Ore ore : ores.keySet()) {
			//Bank if inventory does not contain at least enough ores to smelt one bar.
			if(getInventory().getAmount(ore.getName()) < ores.get(ore)) {
				bank = true;
				break;
			}
		}
		if(bank) {
			if(getBank().open()) {
				//Deposit all bars.
				if(getBank().depositAll(bar.getName())) {
					//Withdraw ores.
					for (Ore ore : ores.keySet()) {
						int amount = barsPerInventory * ores.get(ore);
						if(getInventory().getAmount(ore.getName()) < amount) {
							getBank().withdraw(ore.getName(), (int) (amount - getInventory().getAmount(ore.getName())));
						}
					}
				}
			}
			else {
				//Walk to bank.
			}
		}
		else {
			RS2Object furnace = getObjects().closest("Furnace");
			if(furnace != null && furnace.exists()) {
				// Operate furnace.
			}
			else {
				//Walk to furnace.
			}
		}
		return 500;
	}

}

  • Like 3
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...