Jump to content

Identify personal loot from monster drops


BobSmokey

Recommended Posts

Hey guys. I would like to make a script that kills a monster and then picks up valuable drops. The problem, however is that I am ironman. I need a way to idenify whether a drop is owned by my account. How would I do that?

 

[Edit] Osbuddy pro is able to identify personal drops. 

Edited by BobSmokey
Link to comment
Share on other sites

I'd say check for grounditems at the monster's position during the fight and store it in, for example, a list. Update the list only when the grounditems change during the fight. When your monster is dead the newly dropped items should be yours. For a failsafe I'd check for a message that' you can't loot this item" and skip the looting.

This method shouldn't cost to much performance I think.

Hope this helps.

Link to comment
Share on other sites

I don't think there exists a way to differentiate ground items like this. A possible workaround is to cache the ground items and flag the ground items you can't pickup. I wrote untested ad-hoc example you can try:

Example code

public class Test extends Script {

	IronManLootingAPI ironManLootingAPI;
	
	@Override
	public void onStart() throws InterruptedException {
		
		ironManLootingAPI = new IronManLootingAPI();
		ironManLootingAPI.exchangeContext(bot);
		ironManLootingAPI.initializeModule();
	
	}

	@Override
	public int onLoop() throws InterruptedException {
		
		// 1. find all existing ground items by calling "refresh"
		if (ironManLootingAPI.refresh()) {
			// 2. find a specific item
			if (ironManLootingAPI.find("Abyssal whip", "Abyssal dagger", "Gilded platelegs")) {
				// 3. Do your looting here
				if (ironManLootingAPI.getFound().interact("Take")) {
					/*
					 * The IronManLootingAPI has a message listener
					 * if it detects "You're an Iron Man, so you can't take that."
					 */
					if (ironManLootingAPI.isNotYours()) {
						logger.debug("Aww shucks...");
					}
				}
			}
		}
		
		return 250;
	}

}

Iron Man Looting API (IronManLootingAPI.java)

import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.Map.Entry;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.ui.Message;
import org.osbot.rs07.api.ui.Message.MessageType;
import org.osbot.rs07.listener.MessageListener;
import org.osbot.rs07.script.API;

public class IronManLootingAPI extends API implements MessageListener {

	Map<GroundItem, Boolean> groundItems;
	Entry<GroundItem, Boolean> groundItemEntry;

	@Override
	public void initializeModule() {
		groundItems = new WeakHashMap<>();
		bot.addMessageListener(this);
	}

	@Override
	public void onMessage(Message messageObj) throws InterruptedException {
		if (messageObj.getType() == MessageType.GAME) {
			if (messageObj.getMessage().equals("You're an Iron Man, so you can't take that.")) {
				if (groundItemEntry != null) {
					groundItemEntry.setValue(Boolean.FALSE);
				}
			}
		}
	}

	/**
	 * To clear all entries
	 */
	public void reset() {
		groundItems.clear();
	}

	/**
	 * Reload all ground items
	 * 
	 * @return Ground items found
	 */
	public boolean refresh() {

		// turn List<GroundItem> to Map<GroundItem, Boolean.TRUE>
		Map<GroundItem, Boolean> newGroundItems = super.groundItems.getAll().stream()
				.collect(Collectors.toMap(item -> item, item -> Boolean.TRUE));

		removeInvalidGroundItems();

		newGroundItems.forEach(groundItems::putIfAbsent);

		return !groundItems.isEmpty();
	}

	/**
	 * Find item by predicate
	 * 
	 * @param predicate
	 * @return
	 */
	public boolean find(Predicate<GroundItem> predicate) {
		
		removeInvalidGroundItems();
		
		groundItemEntry = groundItems
				.entrySet()
				.stream()
				.filter(entry -> entry.getValue().equals(Boolean.TRUE))
				.filter(entry -> predicate.test(entry.getKey()))
				.findFirst()
				.orElse(null);
		
		return (groundItemEntry != null);
	}
	
	/**
	 * Find item by name
	 * 
	 * @param itemNameArray
	 * @return
	 */
	public boolean find(String... itemNameArray) {
		return find(item -> {
			boolean result = false;
			String itemName = item.getName();
			for (String itemNameElement : itemNameArray) {
				if (itemName.equalsIgnoreCase(itemNameElement)) {
					result = true;
					break;
				}
			}
			return result;
		});
	}

	/**
	 * Remove items that have despawned/been taken
	 */
	private void removeInvalidGroundItems() {
		Iterator<Entry<GroundItem, Boolean>> iterator = groundItems.entrySet().iterator();
		Entry<GroundItem, Boolean> entry;
		GroundItem groundItem;
		while (iterator.hasNext()) {
			entry = iterator.next();
			groundItem = entry.getKey();
			if (groundItem == null || !groundItem.exists()) {
				iterator.remove();
			}
		}
	}
	
	/**
	 * 
	 * @return Cached ground item
	 */
	public GroundItem getFound() {
		return groundItemEntry != null ? groundItemEntry.getKey() : null;
	}
	
	public boolean isNotYours() {
		return groundItemEntry != null && !groundItemEntry.getValue();
	}
}

 

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