mirror of
https://github.com/2006-Scape/Parabot-Randoms.git
synced 2026-07-03 00:38:07 +00:00
[TASK]Improved solving and implemented usage of Items class
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
package org.parabot.randoms.oswar;
|
package org.parabot.randoms.oswar;
|
||||||
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.parabot.core.Core;
|
import org.parabot.core.Core;
|
||||||
import org.parabot.environment.api.utils.Time;
|
import org.parabot.environment.api.utils.Time;
|
||||||
import org.parabot.environment.api.utils.WebUtil;
|
|
||||||
import org.parabot.environment.randoms.Random;
|
import org.parabot.environment.randoms.Random;
|
||||||
import org.parabot.environment.randoms.RandomType;
|
import org.parabot.environment.randoms.RandomType;
|
||||||
import org.rev317.min.api.methods.Game;
|
import org.rev317.min.api.methods.Game;
|
||||||
import org.rev317.min.api.methods.Interfaces;
|
import org.rev317.min.api.methods.Interfaces;
|
||||||
|
import org.rev317.min.api.methods.Items;
|
||||||
import org.rev317.min.api.methods.Menu;
|
import org.rev317.min.api.methods.Menu;
|
||||||
|
|
||||||
|
|
||||||
@@ -16,11 +15,12 @@ import org.rev317.min.api.methods.Menu;
|
|||||||
*/
|
*/
|
||||||
public class ItemPicker implements Random {
|
public class ItemPicker implements Random {
|
||||||
private final int INTERFACE_ID = 33300;
|
private final int INTERFACE_ID = 33300;
|
||||||
private final String URL = "http://bdn.parabot.org/api/v2/data/items/";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activate() {
|
public boolean activate() {
|
||||||
return Game.isLoggedIn() && Interfaces.getOpenInterfaceId() == INTERFACE_ID;
|
return Game.isLoggedIn()
|
||||||
|
&& Interfaces.getOpenInterfaceId() == INTERFACE_ID
|
||||||
|
&& !Interfaces.getInterface(INTERFACE_ID + 3).getMessage().contains("0:00");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -31,16 +31,15 @@ public class ItemPicker implements Random {
|
|||||||
String message = Interfaces.getInterface(INTERFACE_ID + 2).getMessage();
|
String message = Interfaces.getInterface(INTERFACE_ID + 2).getMessage();
|
||||||
String itemName = message.substring(message.indexOf("'") + 1, message.indexOf("'", message.indexOf("'") + 1));
|
String itemName = message.substring(message.indexOf("'") + 1, message.indexOf("'", message.indexOf("'") + 1));
|
||||||
|
|
||||||
|
Core.verbose("Have to select item: "+itemName);
|
||||||
|
|
||||||
for(int i = INTERFACE_ID + 11; i <= INTERFACE_ID + 17; i += 3) {
|
for(int i = INTERFACE_ID + 11; i <= INTERFACE_ID + 17; i += 3) {
|
||||||
try {
|
try {
|
||||||
int id = Interfaces.getInterface(i).getItems()[0];
|
int id = Interfaces.getInterface(i).getItems()[0];
|
||||||
|
String name = Items.getName(id);
|
||||||
|
|
||||||
String response = WebUtil.getContents(URL.concat("" + id));
|
if(name != null && name.toLowerCase().startsWith(itemName.toLowerCase())) {
|
||||||
JSONObject json = (JSONObject) WebUtil.getJsonParser().parse(response);
|
Core.verbose("Attempting solution: "+name);
|
||||||
JSONObject result = (JSONObject) WebUtil.getJsonParser().parse(json.get("result").toString());
|
|
||||||
|
|
||||||
if(result.get("name").equals(itemName)) {
|
|
||||||
Core.verbose("Attempting solution");
|
|
||||||
Menu.sendAction(315,0,0,i+1,2);
|
Menu.sendAction(315,0,0,i+1,2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -63,4 +62,4 @@ public class ItemPicker implements Random {
|
|||||||
public RandomType getRandomType() {
|
public RandomType getRandomType() {
|
||||||
return RandomType.SCRIPT;
|
return RandomType.SCRIPT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user