mirror of
https://github.com/2006-Scape/Parabot-Randoms.git
synced 2026-07-02 16:49:09 +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;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.parabot.core.Core;
|
||||
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.RandomType;
|
||||
import org.rev317.min.api.methods.Game;
|
||||
import org.rev317.min.api.methods.Interfaces;
|
||||
import org.rev317.min.api.methods.Items;
|
||||
import org.rev317.min.api.methods.Menu;
|
||||
|
||||
|
||||
@@ -16,11 +15,12 @@ import org.rev317.min.api.methods.Menu;
|
||||
*/
|
||||
public class ItemPicker implements Random {
|
||||
private final int INTERFACE_ID = 33300;
|
||||
private final String URL = "http://bdn.parabot.org/api/v2/data/items/";
|
||||
|
||||
@Override
|
||||
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
|
||||
@@ -31,16 +31,15 @@ public class ItemPicker implements Random {
|
||||
String message = Interfaces.getInterface(INTERFACE_ID + 2).getMessage();
|
||||
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) {
|
||||
try {
|
||||
int id = Interfaces.getInterface(i).getItems()[0];
|
||||
String name = Items.getName(id);
|
||||
|
||||
String response = WebUtil.getContents(URL.concat("" + id));
|
||||
JSONObject json = (JSONObject) WebUtil.getJsonParser().parse(response);
|
||||
JSONObject result = (JSONObject) WebUtil.getJsonParser().parse(json.get("result").toString());
|
||||
|
||||
if(result.get("name").equals(itemName)) {
|
||||
Core.verbose("Attempting solution");
|
||||
if(name != null && name.toLowerCase().startsWith(itemName.toLowerCase())) {
|
||||
Core.verbose("Attempting solution: "+name);
|
||||
Menu.sendAction(315,0,0,i+1,2);
|
||||
break;
|
||||
}
|
||||
@@ -63,4 +62,4 @@ public class ItemPicker implements Random {
|
||||
public RandomType getRandomType() {
|
||||
return RandomType.SCRIPT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user