Implemented Falador cannonball bot that contributes stock to the GE
This commit is contained in:
@@ -13,6 +13,7 @@ public abstract class Script {
|
||||
public ArrayList<Item> inventory = new ArrayList<>(20);
|
||||
public ArrayList<Item> equipment = new ArrayList<>(20);
|
||||
public Map<Integer, Integer> skills = new HashMap<>();
|
||||
public ArrayList<String> quests = new ArrayList<>(20);
|
||||
|
||||
|
||||
public Player bot;
|
||||
@@ -25,6 +26,13 @@ public abstract class Script {
|
||||
scriptAPI = new ScriptAPI(bot);
|
||||
|
||||
if(!isPlayer) {
|
||||
// Skills and quests need to be set before equipment in case equipment has level or quest requirements
|
||||
for (Map.Entry<Integer, Integer> skill : skills.entrySet()) {
|
||||
setLevel(skill.getKey(), skill.getValue());
|
||||
}
|
||||
for (String quest : quests) {
|
||||
bot.getQuestRepository().setStage(bot.getQuestRepository().getQuest(quest), 100);
|
||||
}
|
||||
for (Item i : equipment) {
|
||||
bot.getEquipment().add(i, true, false);
|
||||
}
|
||||
@@ -32,9 +40,6 @@ public abstract class Script {
|
||||
for (Item i : inventory) {
|
||||
bot.getInventory().add(i);
|
||||
}
|
||||
for (Map.Entry<Integer, Integer> skill : skills.entrySet()) {
|
||||
setLevel(skill.getKey(), skill.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,4 +59,4 @@ public abstract class Script {
|
||||
|
||||
// This does not get called and all implementations should be removed
|
||||
public abstract Script newInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package core.game.bots
|
||||
|
||||
import core.api.*
|
||||
import core.game.interaction.NodeUsageEvent
|
||||
import core.game.interaction.PluginInteractionManager
|
||||
import core.game.interaction.UseWithHandler
|
||||
import core.cache.def.impl.ItemDefinition
|
||||
import core.game.component.Component
|
||||
import core.game.consumable.Consumable
|
||||
@@ -88,6 +91,36 @@ class ScriptAPI(private val bot: Player) {
|
||||
if(!InteractionListeners.run(node.id, type, option, bot, node)) node.interaction.handle(bot, opt)
|
||||
}
|
||||
|
||||
fun useWith(bot: Player, itemId: Int, node: Node?) {
|
||||
if(node == null) return
|
||||
|
||||
val type = when(node){
|
||||
is Scenery -> IntType.SCENERY
|
||||
is NPC -> IntType.NPC
|
||||
is Item -> IntType.ITEM
|
||||
else -> null
|
||||
} ?: return
|
||||
|
||||
val item = bot.inventory.getItem(Item(itemId))
|
||||
|
||||
val childNode = node.asScenery()?.getChild(bot)
|
||||
|
||||
if (InteractionListeners.run(item, node, type, bot))
|
||||
return
|
||||
if (childNode != null && childNode.id != node.id) {
|
||||
if (InteractionListeners.run(item, childNode, type, bot))
|
||||
return
|
||||
}
|
||||
val flipped = type == IntType.ITEM && item.id < node.id
|
||||
val event = if (flipped)
|
||||
NodeUsageEvent(bot, 0, node, item)
|
||||
else
|
||||
NodeUsageEvent(bot, 0, item, childNode ?: node)
|
||||
if (PluginInteractionManager.handle(bot, event))
|
||||
return
|
||||
UseWithHandler.run(event)
|
||||
}
|
||||
|
||||
fun sendChat(message: String) {
|
||||
bot.sendChat(message)
|
||||
bot.updateMasks.register(EntityFlag.Chat, ChatMessage(bot, message, 0, 0))
|
||||
@@ -144,7 +177,11 @@ class ScriptAPI(private val bot: Player) {
|
||||
return processEvaluationList(RegionManager.forId(bot.location.regionId).planes[bot.location.z].entities, acceptedName = listOf(name))
|
||||
}
|
||||
|
||||
fun evaluateViability (e: Node?, minDistance: Double, maxDistance: Double, acceptedNames: List<String>? = null, acceptedId: Int = -1): Boolean {
|
||||
fun getNearestObjectByPredicate(predicate: (Node?) -> Boolean): Node? {
|
||||
return processEvaluationList(RegionManager.forId(bot.location.regionId).planes[bot.location.z].objectList, acceptedPredicate = predicate)
|
||||
}
|
||||
|
||||
fun evaluateViability (e: Node?, minDistance: Double, maxDistance: Double, acceptedNames: List<String>? = null, acceptedId: Int = -1, acceptedPredicate: ((Node?) -> Boolean)? = null): Boolean {
|
||||
if (e == null || !e.isActive)
|
||||
return false
|
||||
if (acceptedId != -1 && e.id != acceptedId)
|
||||
@@ -154,16 +191,20 @@ class ScriptAPI(private val bot: Player) {
|
||||
if (dist > maxDistance || dist > minDistance)
|
||||
return false
|
||||
|
||||
val name = e?.name
|
||||
return (acceptedNames?.contains(name) ?: true && !Pathfinder.find(bot, e).isMoveNear)
|
||||
if (acceptedPredicate != null) {
|
||||
return acceptedPredicate(e) && !Pathfinder.find(bot, e).isMoveNear;
|
||||
} else {
|
||||
val name = e?.name
|
||||
return (acceptedNames?.stream()?.anyMatch({ s -> s.equals(name, true) }) ?: true && !Pathfinder.find(bot, e).isMoveNear)
|
||||
}
|
||||
}
|
||||
|
||||
fun processEvaluationList (list: List<Node>, acceptedName: List<String>? = null, acceptedId: Int = -1): Node? {
|
||||
fun processEvaluationList (list: List<Node>, acceptedName: List<String>? = null, acceptedId: Int = -1, acceptedPredicate: ((Node?) -> Boolean)? = null): Node? {
|
||||
var entity: Node? = null
|
||||
var minDistance = Double.MAX_VALUE
|
||||
val maxDistance = ServerConstants.MAX_PATHFIND_DISTANCE.toDouble()
|
||||
for (e in list) {
|
||||
if (evaluateViability(e, minDistance, maxDistance, acceptedName, acceptedId)) {
|
||||
if (evaluateViability(e, minDistance, maxDistance, acceptedName, acceptedId, acceptedPredicate)) {
|
||||
entity = e
|
||||
minDistance = distance(bot, e)
|
||||
}
|
||||
@@ -583,15 +624,21 @@ class ScriptAPI(private val bot: Player) {
|
||||
* @param none
|
||||
* @author cfunnyman joe
|
||||
*/
|
||||
fun bankAll(){
|
||||
fun bankAll(onComplete: (() -> Unit)? = null){
|
||||
class BankingPulse() : Pulse(20){
|
||||
override fun pulse(): Boolean {
|
||||
for(item in bot.inventory.toArray()){
|
||||
var itemAmount = bot.inventory.getAmount(item)
|
||||
if(item != null) {
|
||||
var itemAmount = bot.inventory.getAmount(item)
|
||||
|
||||
bot.inventory.remove(item)
|
||||
bot.bank.add(item)
|
||||
if(bot.inventory.remove(item)) {
|
||||
bot.bank.add(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
if(onComplete != null) {
|
||||
onComplete?.invoke()
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,9 @@ class SkillingBotAssembler {
|
||||
val item = Item(i)
|
||||
val configs = item.definition.handlers
|
||||
val slot = configs["equipment_slot"] ?: continue
|
||||
bot.equipment.add(item, slot as Int,
|
||||
false,false)
|
||||
if(bot.inventory.get(slot as Int) == null) {
|
||||
bot.equipment.add(item, slot as Int,false,false)
|
||||
}
|
||||
val reqs = configs["requirements"]
|
||||
if(reqs != null)
|
||||
for(req in configs["requirements"] as HashMap<Int,Int>)
|
||||
@@ -41,4 +42,4 @@ class SkillingBotAssembler {
|
||||
val POORSETS = arrayOf(listOf(542,544), listOf(581), listOf(6654,6655,6656), listOf(6654,6656), listOf(636,646), listOf(638,648), listOf(), listOf(), listOf())
|
||||
val AVGSETS = arrayOf(listOf(2649,342,344), listOf(2651,542,544), listOf(6654,6655,6656), listOf(6139,6141), listOf(9923,9924,9925), listOf(10400,10402,2649), listOf(10404,10406), listOf(12971,12978))
|
||||
val RICHSETS = arrayOf(listOf(10330,10332,2649), listOf(12873,12880,1046), listOf(13858,13861,13864), listOf(13887,13893), listOf(3481,3483), listOf(2653,2655), listOf(2661,2663), listOf(2591,2593), listOf(14490,14492))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,10 +359,24 @@ class GrandExchange : StartupListener, Commands {
|
||||
return offers
|
||||
}
|
||||
|
||||
fun getBotstockForId(itemId: Int): Int {
|
||||
var total = 0
|
||||
GEDB.run { conn ->
|
||||
val stmt = conn.prepareStatement("SELECT sum(amount) FROM bot_offers WHERE amount > 0 AND item_id = ?")
|
||||
stmt.setInt(1, itemId)
|
||||
|
||||
val results = stmt.executeQuery()
|
||||
while (results.next()) {
|
||||
total += results.getInt(1)
|
||||
}
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun startup(){
|
||||
GEDB.init()
|
||||
boot()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ class ImmerseWorld : StartupListener {
|
||||
immerseWilderness()
|
||||
immerseFishingGuild()
|
||||
immerseAdventurer()
|
||||
immerseFalador()
|
||||
// immerseSlayer()
|
||||
immerseGE()
|
||||
}
|
||||
@@ -211,6 +212,10 @@ class ImmerseWorld : StartupListener {
|
||||
CoalMiner(),
|
||||
skillingBotAssembler.produce(SkillingBotAssembler.Wealth.POOR, Location.create(3037, 9737, 0))
|
||||
)
|
||||
GeneralBotCreator(
|
||||
CannonballSmelter(),
|
||||
skillingBotAssembler.produce(SkillingBotAssembler.Wealth.AVERAGE, Location.create(3013, 3356, 0))
|
||||
)
|
||||
}
|
||||
|
||||
fun immerseSlayer() {
|
||||
|
||||
Reference in New Issue
Block a user