liverare Posted September 23, 2017 Share Posted September 23, 2017 Let's work to make Wilderness bots great again! Example code: import java.util.List; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import com.liverare.api.WildernessAPI; @ScriptManifest(author = "", info = "", logo = "", name = "Test", version = 0) public class Test extends Script { WildernessAPI wilderness; @Override public void onStart() throws InterruptedException { wilderness = new WildernessAPI(); wilderness.exchangeContext(bot); } @Override public int onLoop() throws InterruptedException { Player workerBot = players.closest("W0rk3r B0t 5001"); handleRealThreats(); handlePotentialThreats(); saveWorkerBot(workerBot); return 100; } private void handleRealThreats() { List<Player> realThreats = wilderness.findRealThreats(); if (realThreats != null && !realThreats.isEmpty()) { // oh shit they can attack us // better check what they're wearing and what they're doing } } private void handlePotentialThreats() { List<Player> potentialThreats = wilderness.findPotentialThreats(); if (potentialThreats != null && !potentialThreats.isEmpty()) { // oh dear, we may be in trouble // we'd better not go deeper into the Wilderness, they may be // waiting for us to do exactly that! } } private void saveWorkerBot(Player workerBot) { List<Player> realThreatsToWorkerBot = wilderness.findRealThreats(workerBot); if (realThreatsToWorkerBot != null && !realThreatsToWorkerBot.isEmpty()) { // worker bot may be in trouble // perhaps we should attack baddie? lure them away? etc. } } } Methods: public int getSafeWildernessLevel(Player player) public int getSafeWildernessLevel(Player playerA, Player playerB) public List<Player> findPotentialThreats() public List<Player> findPotentialThreats(Player victim) public List<Player> findRealThreats() public List<Player> findRealThreats(Player victim) public static boolean canPlayerAFighterPlayerB(Player playerA, Player playerB) public static int calculateYCoordinate(Vector3D vector3d, boolean upperBound) public static int calculateYCoordinate(int wildernessLevel, boolean upperBound) public static int calculateWildernessLevel(Vector3D vector3d) public static int calculateWildernessLevel(int yCoordinate) Source: package com.liverare.api; import java.util.List; import java.util.stream.Collectors; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.api.model.Vector3D; import org.osbot.rs07.script.API; /** * * @author LiveRare * */ public class WildernessAPI extends API { @Override public void initializeModule() { } /** * Get the safe Wilderness level you need to be in to avoid combat with * another player * * @param player - Player * @return Safe Wilderness level */ public int getSafeWildernessLevel(Player player) { return getSafeWildernessLevel(myPlayer(), player); } /** * Get the safe Wilderness level for two players to avoid combat * * @param playerA * - Player A * @param playerB * - Player B * @return Safe Wilderness level */ public int getSafeWildernessLevel(Player playerA, Player playerB) { int wildernessLevel = 0; int playerACombat; int playerBCombat; if (playerA != null && playerB != null && !playerA.equals(playerB)) { playerACombat = playerA.getCombatLevel(); playerBCombat = playerB.getCombatLevel(); if (playerACombat != playerBCombat) { wildernessLevel = Math.abs(playerACombat - playerBCombat); wildernessLevel--; } } return wildernessLevel; } /** * Find all players who you can be attacked by if approached closer * * @return Players who can't attack you merely because you're not in a * higher enough Wilderness level as them */ public List<Player> findPotentialThreats() { return findPotentialThreats(myPlayer()); } /** * Find all players who the victim can be attacked by if approached closer * * @param victim * - Player * @return Players who can't attack you merely because you're not in a * higher enough Wilderness level as them */ public List<Player> findPotentialThreats(Player victim) { return players.getAll().stream() .filter(player -> canPlayerAFighterPlayerB(player, victim)) .collect(Collectors.toList()); } /** * Find all players who you can be attacked by * * @return Players who can attack you */ public List<Player> findRealThreats() { return findRealThreats(myPlayer()); } /** * Find all players who the victim can be attacked by * * @param victim * - Player * @return Players who can attack */ public List<Player> findRealThreats(Player victim) { return players.getAll().stream() .filter(player -> canPlayerAFighterPlayerB(victim, player)) .collect(Collectors.toList()); } /** * Test whether 'Player A' can fight 'Player B' * * @param playerA - Player A * @param playerB - Player B * @return Player A can fight Player B */ public static boolean canPlayerAFighterPlayerB(Player playerA, Player playerB) { boolean result = false; int playerAWildernessLevel; int playerBWildernessLevel; int playerALevel; int playerBLevel; int minCombat; int maxCombat; if (playerA != null && playerB != null && !playerA.equals(playerB)) { playerAWildernessLevel = calculateWildernessLevel(playerA); playerBWildernessLevel = calculateWildernessLevel(playerB); if (playerAWildernessLevel > 0 && playerBWildernessLevel > 0) { playerALevel = playerA.getCombatLevel(); playerBLevel = playerB.getCombatLevel(); minCombat = (playerALevel - playerAWildernessLevel); maxCombat = (playerALevel + playerAWildernessLevel); if (playerBLevel >= minCombat && playerBLevel <= maxCombat) { result = true; } } } return result; } /** * Calculate Y coordinate by wilderness level. * * Note: This is based of Edgeville Wilderness and there are some zones * where the Wilderness level increments are inconsistent with the rest of * the Wilderness (which is 8 tiles per Wilderness level). * * @param wildernessLevel * - Wilderness level * @param upperBound * - Upper-most tile for that Wilderness level * @return Y coordinate * @see {@link WildernessAPI#calculateYCoordinate(int, boolean)} */ public static int calculateYCoordinate(Vector3D vector3d, boolean upperBound) { return calculateYCoordinate(vector3d.getY(), upperBound); } /** * Calculate Y coordinate by wilderness level. * * Note: This is based of Edgeville Wilderness and there are some zones * where the Wilderness level increments are inconsistent with the rest of * the Wilderness (which is 8 tiles per Wilderness level). * * @param vector3d * - 3D vector * @param upperBound * - Upper-most tile for that Wilderness level * @return Y coordinate */ public static int calculateYCoordinate(int wildernessLevel, boolean upperBound) { int yCoordinate; if (wildernessLevel <= 0) { yCoordinate = 3524; } else if (wildernessLevel <= 1) { yCoordinate = 3527; } else if (wildernessLevel <= 2) { yCoordinate = 3535; } else { wildernessLevel -= 3; yCoordinate = 3535; yCoordinate += (wildernessLevel * 8); if (upperBound) { yCoordinate += 8; } else { yCoordinate++; } } return yCoordinate; } /** * Calculates Wilderness level by Y coordinate * * Note: This is based of Edgeville Wilderness and there are some zones * where the Wilderness level increments are inconsistent with the rest of * the Wilderness (which is 8 tiles per Wilderness level). * * @param vector3d * - 3D vector * @return Wilderness level * @see {@link WildernessAPI#calculateWildernessLevel(int)} */ public static int calculateWildernessLevel(Vector3D vector3d) { return calculateWildernessLevel(vector3d.getY()); } /** * Calculates Wilderness level by Y coordinate * * Note: This is based of Edgeville Wilderness and there are some zones * where the Wilderness level increments are inconsistent with the rest of * the Wilderness (which is 8 tiles per Wilderness level). * * @param yCoordinate * - Y coordinate * @return Wilderness level */ public static int calculateWildernessLevel(int yCoordinate) { int wildernessLevel; if (yCoordinate <= 3524) { // not in wilderness wildernessLevel = 0; } else if (yCoordinate <= 3527) { // Level 1 wilderness wildernessLevel = 1; } else if (yCoordinate <= 3535) { // Level 2 wilderness wildernessLevel = 2; } else { wildernessLevel = (yCoordinate - 3535); wildernessLevel = (int) Math.ceil(wildernessLevel / 8D); wildernessLevel += 2; // can't remember why... } return wildernessLevel; } } Let me know if there are any problems. Have fun! 7 Quote Link to comment Share on other sites More sharing options...
Chris Posted September 23, 2017 Share Posted September 23, 2017 nice i have my own tho but this looks better Dx 1 Quote Link to comment Share on other sites More sharing options...
Explv Posted September 23, 2017 Share Posted September 23, 2017 19 minutes ago, liverare said: Let's work to make Wilderness bots great again! Example code: import java.util.List; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import com.liverare.api.WildernessAPI; @ScriptManifest(author = "", info = "", logo = "", name = "Test", version = 0) public class Test extends Script { WildernessAPI wilderness; @Override public void onStart() throws InterruptedException { wilderness = new WildernessAPI(); wilderness.exchangeContext(bot); } @Override public int onLoop() throws InterruptedException { Player workerBot = players.closest("W0rk3r B0t 5001"); handleRealThreats(); handlePotentialThreats(); saveWorkerBot(workerBot); return 100; } private void handleRealThreats() { List<Player> realThreats = wilderness.findRealThreats(); if (realThreats != null && !realThreats.isEmpty()) { // oh shit they can attack us // better check what they're wearing and what they're doing } } private void handlePotentialThreats() { List<Player> potentialThreats = wilderness.findPotentialThreats(); if (potentialThreats != null && !potentialThreats.isEmpty()) { // oh dear, we may be in trouble // we'd better not go deeper into the Wilderness, they may be // waiting for us to do exactly that! } } private void saveWorkerBot(Player workerBot) { List<Player> realThreatsToWorkerBot = wilderness.findRealThreats(workerBot); if (realThreatsToWorkerBot != null && !realThreatsToWorkerBot.isEmpty()) { // worker bot may be in trouble // perhaps we should attack baddie? lure them away? etc. } } } Methods: public int getSafeWildernessLevel(Player player) public int getSafeWildernessLevel(Player playerA, Player playerB) public List<Player> findPotentialThreats() public List<Player> findPotentialThreats(Player victim) public List<Player> findRealThreats() public List<Player> findRealThreats(Player victim) public static boolean canPlayerAFighterPlayerB(Player playerA, Player playerB) public static int calculateYCoordinate(Vector3D vector3d, boolean upperBound) public static int calculateYCoordinate(int wildernessLevel, boolean upperBound) public static int calculateWildernessLevel(Vector3D vector3d) public static int calculateWildernessLevel(int yCoordinate) Source: Reveal hidden contents package com.liverare.api; import java.util.List; import java.util.stream.Collectors; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.api.model.Vector3D; import org.osbot.rs07.script.API; /** * * @author LiveRare * */ public class WildernessAPI extends API { @Override public void initializeModule() { } /** * Get the safe Wilderness level you need to be in to avoid combat with * another player * * @param player - Player * @return Safe Wilderness level */ public int getSafeWildernessLevel(Player player) { return getSafeWildernessLevel(myPlayer(), player); } /** * Get the safe Wilderness level for two players to avoid combat * * @param playerA * - Player A * @param playerB * - Player B * @return Safe Wilderness level */ public int getSafeWildernessLevel(Player playerA, Player playerB) { int wildernessLevel = 0; int playerACombat; int playerBCombat; if (playerA != null && playerB != null && !playerA.equals(playerB)) { playerACombat = playerA.getCombatLevel(); playerBCombat = playerB.getCombatLevel(); if (playerACombat != playerBCombat) { wildernessLevel = Math.abs(playerACombat - playerBCombat); wildernessLevel--; } } return wildernessLevel; } /** * Find all players who you can be attacked by if approached closer * * @return Players who can't attack you merely because you're not in a * higher enough Wilderness level as them */ public List<Player> findPotentialThreats() { return findPotentialThreats(myPlayer()); } /** * Find all players who the victim can be attacked by if approached closer * * @param victim * - Player * @return Players who can't attack you merely because you're not in a * higher enough Wilderness level as them */ public List<Player> findPotentialThreats(Player victim) { return players.getAll().stream() .filter(player -> canPlayerAFighterPlayerB(player, victim)) .collect(Collectors.toList()); } /** * Find all players who you can be attacked by * * @return Players who can attack you */ public List<Player> findRealThreats() { return findRealThreats(myPlayer()); } /** * Find all players who the victim can be attacked by * * @param victim * - Player * @return Players who can attack */ public List<Player> findRealThreats(Player victim) { return players.getAll().stream() .filter(player -> canPlayerAFighterPlayerB(victim, player)) .collect(Collectors.toList()); } /** * Test whether 'Player A' can fight 'Player B' * * @param playerA - Player A * @param playerB - Player B * @return Player A can fight Player B */ public static boolean canPlayerAFighterPlayerB(Player playerA, Player playerB) { boolean result = false; int playerAWildernessLevel; int playerBWildernessLevel; int playerALevel; int playerBLevel; int minCombat; int maxCombat; if (playerA != null && playerB != null && !playerA.equals(playerB)) { playerAWildernessLevel = calculateWildernessLevel(playerA); playerBWildernessLevel = calculateWildernessLevel(playerB); if (playerAWildernessLevel > 0 && playerBWildernessLevel > 0) { playerALevel = playerA.getCombatLevel(); playerBLevel = playerB.getCombatLevel(); minCombat = (playerALevel - playerAWildernessLevel); maxCombat = (playerALevel + playerAWildernessLevel); if (playerBLevel >= minCombat && playerBLevel <= maxCombat) { result = true; } } } return result; } /** * Calculate Y coordinate by wilderness level. * * Note: This is based of Edgeville Wilderness and there are some zones * where the Wilderness level increments are inconsistent with the rest of * the Wilderness (which is 8 tiles per Wilderness level). * * @param wildernessLevel * - Wilderness level * @param upperBound * - Upper-most tile for that Wilderness level * @return Y coordinate * @see {@link WildernessAPI#calculateYCoordinate(int, boolean)} */ public static int calculateYCoordinate(Vector3D vector3d, boolean upperBound) { return calculateYCoordinate(vector3d.getY(), upperBound); } /** * Calculate Y coordinate by wilderness level. * * Note: This is based of Edgeville Wilderness and there are some zones * where the Wilderness level increments are inconsistent with the rest of * the Wilderness (which is 8 tiles per Wilderness level). * * @param vector3d * - 3D vector * @param upperBound * - Upper-most tile for that Wilderness level * @return Y coordinate */ public static int calculateYCoordinate(int wildernessLevel, boolean upperBound) { int yCoordinate; if (wildernessLevel <= 0) { yCoordinate = 3524; } else if (wildernessLevel <= 1) { yCoordinate = 3527; } else if (wildernessLevel <= 2) { yCoordinate = 3535; } else { wildernessLevel -= 3; yCoordinate = 3535; yCoordinate += (wildernessLevel * 8); if (upperBound) { yCoordinate += 8; } else { yCoordinate++; } } return yCoordinate; } /** * Calculates Wilderness level by Y coordinate * * Note: This is based of Edgeville Wilderness and there are some zones * where the Wilderness level increments are inconsistent with the rest of * the Wilderness (which is 8 tiles per Wilderness level). * * @param vector3d * - 3D vector * @return Wilderness level * @see {@link WildernessAPI#calculateWildernessLevel(int)} */ public static int calculateWildernessLevel(Vector3D vector3d) { return calculateWildernessLevel(vector3d.getY()); } /** * Calculates Wilderness level by Y coordinate * * Note: This is based of Edgeville Wilderness and there are some zones * where the Wilderness level increments are inconsistent with the rest of * the Wilderness (which is 8 tiles per Wilderness level). * * @param yCoordinate * - Y coordinate * @return Wilderness level */ public static int calculateWildernessLevel(int yCoordinate) { int wildernessLevel; if (yCoordinate <= 3524) { // not in wilderness wildernessLevel = 0; } else if (yCoordinate <= 3527) { // Level 1 wilderness wildernessLevel = 1; } else if (yCoordinate <= 3535) { // Level 2 wilderness wildernessLevel = 2; } else { wildernessLevel = (yCoordinate - 3535); wildernessLevel = (int) Math.ceil(wildernessLevel / 8D); wildernessLevel += 2; // can't remember why... } return wildernessLevel; } } Let me know if there are any problems. Have fun! Good job my sweet friend 1 Quote Link to comment Share on other sites More sharing options...
Transporter Posted September 24, 2017 Share Posted September 24, 2017 Thanks for releasing dis! Quote Link to comment Share on other sites More sharing options...
whipz Posted October 3, 2017 Share Posted October 3, 2017 This looks awesome again ! Will look more into it when I get home, thanks for the quality posts (: Quote Link to comment Share on other sites More sharing options...
Deceiver Posted October 6, 2017 Share Posted October 6, 2017 thanks, perfect for what i need Quote Link to comment Share on other sites More sharing options...
Durky Posted January 16, 2019 Share Posted January 16, 2019 Thanks, I'll be using parts of this. Quote Link to comment Share on other sites More sharing options...
liverare Posted January 16, 2019 Author Share Posted January 16, 2019 3 hours ago, Durky said: Thanks, I'll be using parts of this. k just make sure you only use it on the surface Wilderness, cus it won't work in Clan Wars or downstairs in the fire giants spawn in deep wildi Quote Link to comment Share on other sites More sharing options...