Jump to content

Appearance API


liverare

Recommended Posts

Find people wearing stuff. Note: doesn't work with ammo and rings.

Example code:

import java.util.List;

import org.osbot.rs07.api.def.ItemDefinition;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import com.liverare.api.AppearanceAPI;

@ScriptManifest(author = "", info = "", logo = "", name = "Test", version = 0)
public class Test extends Script {

	AppearanceAPI appearance;
	
	@Override
	public void onStart() throws InterruptedException {
		appearance = new AppearanceAPI();
		appearance.exchangeContext(bot);
	}

	@Override
	public int onLoop() throws InterruptedException {
		
		pesterRichPeopleForFreeStuff();
		
		return 100;
	}
	
	private void pesterRichPeopleForFreeStuff() {
		
		List<Player> richPeople = appearance.findPlayersWielding(Test::isExpensiveItem);
		
		if (richPeople != null && !richPeople.isEmpty()) {
			
			// rich people spotted!
			// prepare for pestering
			// in 3...
		}
	}
	
	private static boolean isExpensiveItem(ItemDefinition itemDefinition) {
		
		String itemName = itemDefinition.getName();
		
		return itemName.equals("Twisted bow")
				|| itemName.equals("3rd age longsword")
				|| itemName.equals("3rd age pickaxe")
				|| itemName.equals("3rd age axe")
				|| itemName.equals("3rd age cloak")
				|| itemName.equals("Elysian spirit shield")
				|| itemName.equals("3rd age bow");
	}
}

Methods:

public List<Player> findPlayersWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter)
public List<Player> findPlayersWielding(Predicate<ItemDefinition> itemDefinitionFilter)
public Player findPlayerWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter)
public Player findPlayerWielding(Predicate<ItemDefinition> itemDefinitionFilter)
public static boolean isDefined(Player player, Predicate<ItemDefinition> itemDefinitionFilter)
private static boolean isDefined(int[] appearance, Predicate<ItemDefinition> itemDefinitionFilter)

Source:

package com.liverare.api;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

import org.osbot.rs07.api.def.ItemDefinition;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.API;

/**
 * Appearance API
 * 
 * @author LiveRare
 *
 */
public class AppearanceAPI extends API {

	@Override
	public void initializeModule() {
	}

	/**
	 * Find players wielding specific items
	 * 
	 * Note: rings are not retrieved
	 * 
	 * @param players
	 *            - Players to filter
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return List of filtered players
	 * @see {@link AppearanceAPI#isDefined(Player, Predicate)}
	 */
	public List<Player> findPlayersWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) {
		
		List<Player> results = null;

		if (players != null && !players.isEmpty() && itemDefinitionFilter != null) {

			results = new ArrayList<>();
			
			for (Player player : players) {
				
				if (isDefined(player, itemDefinitionFilter)) {
					
					results.add(player);
				}
			}
		}
		
		return results;
	}
	
	/**
	 * Find players wielding specific items
	 * 
	 * Note: rings are not retrieved
	 * 
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return List of filtered players
	 * @see {@link AppearanceAPI#findPlayersWielding(List, Predicate)}
	 */
	public List<Player> findPlayersWielding(Predicate<ItemDefinition> itemDefinitionFilter) {
		return findPlayersWielding(players.getAll(), itemDefinitionFilter);
	}
	
	/**
	 * Find first player wielding specific items
	 * 
	 * Note: rings are not retrieved
	 * 
	 * @param players
	 *            - Players to filter
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return List of filtered players
	 * @see {@link AppearanceAPI#findPlayersWielding(List, Predicate)}
	 */
	public Player findPlayerWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) {
		
		Player result = null;
		List<Player> filtered = findPlayersWielding(players, itemDefinitionFilter);
		
		if (filtered != null && !filtered.isEmpty()) {
			
			result = filtered.get(0);
		}
		
		return result;
	}
	
	/**
	 * Find first player wielding specific items
	 * 
	 * Note: rings are not retrieved
	 * 
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return List of filtered players
	 * @see {@link AppearanceAPI#findPlayerWielding(List, Predicate)}
	 */
	public Player findPlayerWielding(Predicate<ItemDefinition> itemDefinitionFilter) {
		return findPlayerWielding(players.getAll(), itemDefinitionFilter);
	}

	/**
	 * Test whether player is wielding a particular item
	 * 
	 * @param player
	 *            - Player
	 * @param itemDefinitionFilter
	 *            - Item filter
	 * @return <tt>Item found on player</tt>
	 * @see {@link AppearanceAPI#isDefined(int[], Predicate)}
	 */
	public static boolean isDefined(Player player, Predicate<ItemDefinition> itemDefinitionFilter) {
		return isDefined(player.getDefinition().getAppearance(), itemDefinitionFilter);
	}

	/**
	 * Gets item definitions for the items IDs in 'appearance' and tests them
	 * against the ItemDefinition filter
	 * 
	 * @param appearance
	 *            - Item IDs
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return <tt>Item found</tt>
	 */
	private static boolean isDefined(int[] appearance, Predicate<ItemDefinition> itemDefinitionFilter) {
		
		boolean result = false;
		ItemDefinition itemDefinition = null;
		
		if (appearance != null && appearance.length > 0) {
			
			for (int itemId : appearance) {
				
				if (itemId > 0) {
					
					itemId -= 512;
					
					itemDefinition = ItemDefinition.forId(itemId);
					
					if (itemDefinition != null && itemDefinitionFilter.test(itemDefinition)) {
						
						result = true;
						break;
					}
				}
			}
			
		}
		
		return result;
	}
	
}

  • Like 8
Link to comment
Share on other sites

8 minutes ago, liverare said:

Find people wearing stuff. Note: doesn't work with ammo and rings.

Example code:


import java.util.List;

import org.osbot.rs07.api.def.ItemDefinition;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import com.liverare.api.AppearanceAPI;

@ScriptManifest(author = "", info = "", logo = "", name = "Test", version = 0)
public class Test extends Script {

	AppearanceAPI appearance;
	
	@Override
	public void onStart() throws InterruptedException {
		appearance = new AppearanceAPI();
		appearance.exchangeContext(bot);
	}

	@Override
	public int onLoop() throws InterruptedException {
		
		pesterRichPeopleForFreeStuff();
		
		return 100;
	}
	
	private void pesterRichPeopleForFreeStuff() {
		
		List<Player> richPeople = appearance.findPlayersWielding(Test::isExpensiveItem);
		
		if (richPeople != null && !richPeople.isEmpty()) {
			
			// rich people spotted!
			// prepare for pestering
			// in 3...
		}
	}
	
	private static boolean isExpensiveItem(ItemDefinition itemDefinition) {
		
		String itemName = itemDefinition.getName();
		
		return itemName.equals("Twisted bow")
				|| itemName.equals("3rd age longsword")
				|| itemName.equals("3rd age pickaxe")
				|| itemName.equals("3rd age axe")
				|| itemName.equals("3rd age cloak")
				|| itemName.equals("Elysian spirit shield")
				|| itemName.equals("3rd age bow");
	}
}

Methods:


public List<Player> findPlayersWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter)
public List<Player> findPlayersWielding(Predicate<ItemDefinition> itemDefinitionFilter)
public Player findPlayerWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter)
public Player findPlayerWielding(Predicate<ItemDefinition> itemDefinitionFilter)
public static boolean isDefined(Player player, Predicate<ItemDefinition> itemDefinitionFilter)
private static boolean isDefined(int[] appearance, Predicate<ItemDefinition> itemDefinitionFilter)

Source:

 

  Reveal hidden contents

 



package com.liverare.api;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

import org.osbot.rs07.api.def.ItemDefinition;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.script.API;

/**
 * Appearance API
 * 
 * @author LiveRare
 *
 */
public class AppearanceAPI extends API {

	@Override
	public void initializeModule() {
	}

	/**
	 * Find players wielding specific items
	 * 
	 * Note: rings are not retrieved
	 * 
	 * @param players
	 *            - Players to filter
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return List of filtered players
	 * @see {@link AppearanceAPI#isDefined(Player, Predicate)}
	 */
	public List<Player> findPlayersWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) {
		
		List<Player> results = null;

		if (players != null && !players.isEmpty() && itemDefinitionFilter != null) {

			results = new ArrayList<>();
			
			for (Player player : players) {
				
				if (isDefined(player, itemDefinitionFilter)) {
					
					results.add(player);
				}
			}
		}
		
		return results;
	}
	
	/**
	 * Find players wielding specific items
	 * 
	 * Note: rings are not retrieved
	 * 
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return List of filtered players
	 * @see {@link AppearanceAPI#findPlayersWielding(List, Predicate)}
	 */
	public List<Player> findPlayersWielding(Predicate<ItemDefinition> itemDefinitionFilter) {
		return findPlayersWielding(players.getAll(), itemDefinitionFilter);
	}
	
	/**
	 * Find first player wielding specific items
	 * 
	 * Note: rings are not retrieved
	 * 
	 * @param players
	 *            - Players to filter
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return List of filtered players
	 * @see {@link AppearanceAPI#findPlayersWielding(List, Predicate)}
	 */
	public Player findPlayerWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) {
		
		Player result = null;
		List<Player> filtered = findPlayersWielding(players, itemDefinitionFilter);
		
		if (filtered != null && !filtered.isEmpty()) {
			
			result = filtered.get(0);
		}
		
		return result;
	}
	
	/**
	 * Find first player wielding specific items
	 * 
	 * Note: rings are not retrieved
	 * 
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return List of filtered players
	 * @see {@link AppearanceAPI#findPlayerWielding(List, Predicate)}
	 */
	public Player findPlayerWielding(Predicate<ItemDefinition> itemDefinitionFilter) {
		return findPlayerWielding(players.getAll(), itemDefinitionFilter);
	}

	/**
	 * Test whether player is wielding a particular item
	 * 
	 * @param player
	 *            - Player
	 * @param itemDefinitionFilter
	 *            - Item filter
	 * @return <tt>Item found on player</tt>
	 * @see {@link AppearanceAPI#isDefined(int[], Predicate)}
	 */
	public static boolean isDefined(Player player, Predicate<ItemDefinition> itemDefinitionFilter) {
		return isDefined(player.getDefinition().getAppearance(), itemDefinitionFilter);
	}

	/**
	 * Gets item definitions for the items IDs in 'appearance' and tests them
	 * against the ItemDefinition filter
	 * 
	 * @param appearance
	 *            - Item IDs
	 * @param itemDefinitionFilter
	 *            - Filter
	 * @return <tt>Item found</tt>
	 */
	private static boolean isDefined(int[] appearance, Predicate<ItemDefinition> itemDefinitionFilter) {
		
		boolean result = false;
		ItemDefinition itemDefinition = null;
		
		if (appearance != null && appearance.length > 0) {
			
			for (int itemId : appearance) {
				
				if (itemId > 0) {
					
					itemId -= 512;
					
					itemDefinition = ItemDefinition.forId(itemId);
					
					if (itemDefinition != null && itemDefinitionFilter.test(itemDefinition)) {
						
						result = true;
						break;
					}
				}
			}
			
		}
		
		return result;
	}
	
}

 

 

Good job kid I'm proud of you

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