[Plugin] [Example] Gatherer Base
Hi guys,
i wrote some small gatherer Base, right now it's more like assisting you in finding trees and iron veins, because i need to find a proper way to navigate around obstacles. (@Out is it possible to generate those paths for GPS on the fly or do i need to create a DB file? i didnt figure out yet)
Bare in mind that this is my first attempt at creating a plugin for ArcheBuddy. It also has some functions not used yet or some debug infos. It's not a finished plugin yet.
To make this work, the client needs to be english. Just turn it on and run around. It will scan the area for DoodadObjects(like clickable nodes) and check if they have the skill "Chop Tree" or "Mine Ore". If thats the case then the bot will approach it and use the skill.
It will run into any obstacle because there is no proper pathing around them yet. It's really just a simple base, and there are probably alot better ways to find nodes to gather, instead of checking for skills. (Like phaseId and stuff)
I couldn't test it much, because i had connection issues and was in queue most of the time. I still hope it will help some people. I will update it with better pathing and also a combat routine tomorrow.
Feel free to join me to create a stable open source gather base.
v1 - walk to target
//UPDATE
v2 Here we go: as requested with map markers instead of walking to target - you can just use the walk system by setting useMarker to false again and it will do the same as before.
This version will scan for trees and iron veins which can be gathered and dont belong to someone and mark them on the map. If it finds something closer it will reset the marker to that target. If you want to mark everything and not just objects that dont belong to anyone then you have to remove the check for ownerId in the getClosestDoodad() function. (Could be used to find hidden farms then)
Feel free to post more suggestions:
v3 - added hasNearbyPlayers to prevent ninja looting - thanks to Karls for contributing
Hi guys,
i wrote some small gatherer Base, right now it's more like assisting you in finding trees and iron veins, because i need to find a proper way to navigate around obstacles. (@Out is it possible to generate those paths for GPS on the fly or do i need to create a DB file? i didnt figure out yet)
Bare in mind that this is my first attempt at creating a plugin for ArcheBuddy. It also has some functions not used yet or some debug infos. It's not a finished plugin yet.
To make this work, the client needs to be english. Just turn it on and run around. It will scan the area for DoodadObjects(like clickable nodes) and check if they have the skill "Chop Tree" or "Mine Ore". If thats the case then the bot will approach it and use the skill.
It will run into any obstacle because there is no proper pathing around them yet. It's really just a simple base, and there are probably alot better ways to find nodes to gather, instead of checking for skills. (Like phaseId and stuff)
I couldn't test it much, because i had connection issues and was in queue most of the time. I still hope it will help some people. I will update it with better pathing and also a combat routine tomorrow.
Feel free to join me to create a stable open source gather base.
v1 - walk to target
Code:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using ArcheBuddy.Bot.Classes;
namespace Gatherer{
public class Gatherer : Core
{
public static string GetPluginAuthor()
{
return "2face";
}
public static string GetPluginVersion()
{
return "1.0.0.0";
}
public static string GetPluginDescription()
{
return "Gather Plugin";
}
public List<DoodadObject> doodList = new List<DoodadObject>();
public List<String> gatherTypes = new List<String>();
public bool isRunning = false;
public Thread mainThread;
//Call on plugin start
public void PluginRun()
{
Log("Done1");
//printDoods();
//Log("dooddist " + getClosestDood().dist(me));
//moveToDood(getClosestDood());
gatherTypes.Add("Chop Tree");
gatherTypes.Add("Mine Ore");
//printDoods();
isRunning = true;
Start();
Log("Nope");
}
public void Start(){
while(isRunning){
Thread.Sleep(500);
try{
DoodadObject dood = getClosestDood();
if(dood != null){
Log("name " + dood.name );
moveToDood(dood);
}
Log("Check");
}catch(Exception e){
Log(e.ToString());
}
}
}
public void getDoodType(DoodadObject dood){
printDoodInfo(dood);
Log("doodtype: " + dood.phaseId);
}
public void printDoodInfo(DoodadObject dood){
Log("name: " + dood.name + " dist: " + dood.dist(me));
}
public void moveToDood(DoodadObject dood){
if(dood == null) return;
Log("Move To: " + dood.name + " dist: " + me.dist(dood));
//printDoodInfo(dood);
while(dood.dist(me) >= 3){
ComeTo(dood, 2);
Thread.Sleep(50);
}
useDoodad(dood);
}
public Skill getDoodadSkill(DoodadObject dood){
Skill skill = null;
if(dood != null){
foreach(var obj in dood.getUseSkills()){
skill = obj;
}
}
return skill;
}
public void useDoodad(DoodadObject dood){
if(dood != null){
Skill skill = getDoodadSkill(dood);
if(skill != null){
Log(skill.name + " " + dood.name);
while(dood != null && dood.dist(me) <= 3){
if(UseDoodadSkill(skill.id, dood, true, 0) == true){
Log("Gathered: " + dood.name);
dood.Dispose();
dood = null;
}
Thread.Sleep(50);
}
}
}
}
public String hasGatherType(DoodadObject dood){
Skill skill = getDoodadSkill(dood);
return "";
}
public DoodadObject getClosestDood(){
DoodadObject dood = null;
double dist = 9999999999;
doodList = getDoodads();
Skill skill = null;
if(doodList.Count > 0){
//printDoods();
foreach(var obj in doodList){
skill = getDoodadSkill(obj);
if(skill != null ){
if(skill.name == "Chop Tree" || skill.name == "Mine Ore"){
if(me.dist(obj) < dist && obj.growthTime <= 0 && obj.uniqOwnerId == 0){
dood = obj;
dist = me.dist(obj);
}
}
}
}
}
Log("TEST");
if(dood != null){
return dood;
}
return null;
}
public void printDoods(){
updateDoodads();
Skill skill = null;
String sName = "";
foreach(var obj in doodList){
Log("---");
skill = getDoodadSkill(obj);
if(skill != null){
sName = skill.name;
}else{
sName = "";
}
Log(obj.name + " Time: " + obj.growthTime + " skill: " + sName);
Log("Type: " + obj.type + "dist: " + me.dist(obj));
Log("ownerId: " + obj.uniqOwnerId);
}
}
public void updateDoodads(){
doodList = getDoodads();
}
//Call on plugin stop
public void PluginStop()
{
}
}
}
//UPDATE
v2 Here we go: as requested with map markers instead of walking to target - you can just use the walk system by setting useMarker to false again and it will do the same as before.
This version will scan for trees and iron veins which can be gathered and dont belong to someone and mark them on the map. If it finds something closer it will reset the marker to that target. If you want to mark everything and not just objects that dont belong to anyone then you have to remove the check for ownerId in the getClosestDoodad() function. (Could be used to find hidden farms then)
Feel free to post more suggestions:
Code:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using ArcheBuddy.Bot.Classes;
namespace Gatherer{
public class Gatherer : Core
{
public static string GetPluginAuthor()
{
return "2face";
}
public static string GetPluginVersion()
{
return "1.0.0.0";
}
public static string GetPluginDescription()
{
return "Gather Plugin";
}
public List<DoodadObject> doodList = new List<DoodadObject>();
public List<String> gatherTypes = new List<String>();
public bool isRunning = false;
public bool useMarker = true;
public bool isMarkerActive = false;
public DoodadObject foundDood = null;
public Thread mainThread;
//Call on plugin start
public void PluginRun()
{
Log("Run");
//printDoods();
//Log("dooddist " + getClosestDood().dist(me));
//moveToDood(getClosestDood());
gatherTypes.Add("Chop Tree");
gatherTypes.Add("Mine Ore");
//printDoods();
isRunning = true;
Start();
}
public void Start(){
while(isRunning){
Thread.Sleep(1000);
try{
DoodadObject dood = getClosestDood();
if(dood != null){
if(useMarker){
markerRoutine(dood);
}else{
Log("name " + dood.name );
moveToDood(dood);
}
}
}catch(Exception){
//Log(e.ToString());
isMarkerActive = false;
}
}
}
public void markerRoutine(DoodadObject dood){
if(dood == null){
isMarkerActive = false;
Log("target removed");
return;
}
if(isMarkerActive){
if(dood != null && me.dist(dood) <= 5){
isMarkerActive = false;
Log("reached " + dood.name);
}else if(dood != null && dood.objId != foundDood.objId){
Log("closer target found");
isMarkerActive = false;
}
}else if(dood != null && me.dist(dood) > 5 ){
isMarkerActive = true;
SetMapPos(dood.X, dood.Y, dood.Z);
Log("marker set on " + dood.name + " dist: " + me.dist(dood));
foundDood = dood;
}
}
public void getDoodType(DoodadObject dood){
printDoodInfo(dood);
Log("doodtype: " + dood.phaseId);
}
public void printDoodInfo(DoodadObject dood){
Log("name: " + dood.name + " dist: " + dood.dist(me));
}
public void moveToDood(DoodadObject dood){
if(dood == null) return;
Log("Move To: " + dood.name + " dist: " + me.dist(dood));
//printDoodInfo(dood);
while(dood.dist(me) >= 3){
ComeTo(dood, 2);
Thread.Sleep(50);
}
useDoodad(dood);
}
public Skill getDoodadSkill(DoodadObject dood){
Skill skill = null;
if(dood != null){
foreach(var obj in dood.getUseSkills()){
skill = obj;
}
}
return skill;
}
public void useDoodad(DoodadObject dood){
if(dood != null){
Skill skill = getDoodadSkill(dood);
if(skill != null){
Log(skill.name + " " + dood.name);
while(dood != null && dood.dist(me) <= 3){
if(UseDoodadSkill(skill.id, dood, true, 0) == true){
Log("Gathered: " + dood.name);
dood.Dispose();
dood = null;
}
Thread.Sleep(50);
}
}
}
}
public String hasGatherType(DoodadObject dood){
Skill skill = getDoodadSkill(dood);
return "";
}
public DoodadObject getClosestDood(){
DoodadObject dood = null;
double dist = 9999999999;
doodList = getDoodads();
Skill skill = null;
if(doodList.Count > 0){
//printDoods();
foreach(var obj in doodList){
skill = getDoodadSkill(obj);
if(skill != null ){
if(skill.name == "Chop Tree" || skill.name == "Mine Ore"){
if(me.dist(obj) < dist && obj.growthTime <= 0 && obj.uniqOwnerId == 0){
dood = obj;
dist = me.dist(obj);
}
}
}
}
}
if(dood != null){
return dood;
}
return null;
}
public void printDoods(){
updateDoodads();
Skill skill = null;
String sName = "";
foreach(var obj in doodList){
Log("---");
skill = getDoodadSkill(obj);
if(skill != null){
sName = skill.name;
}else{
sName = "";
}
Log(obj.name + " Time: " + obj.growthTime + " skill: " + sName);
Log("Type: " + obj.type + "dist: " + me.dist(obj));
Log("ownerId: " + obj.uniqOwnerId);
}
}
public void updateDoodads(){
doodList = getDoodads();
}
//Call on plugin stop
public void PluginStop()
{
}
}
}
v3 - added hasNearbyPlayers to prevent ninja looting - thanks to Karls for contributing
Code:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using ArcheBuddy.Bot.Classes;
namespace Gatherer{
public class Gatherer : Core
{
public static string GetPluginAuthor()
{
return "2face";
}
public static string GetPluginVersion()
{
return "1.0.0.0";
}
public static string GetPluginDescription()
{
return "Gather Plugin";
}
public List<DoodadObject> doodList = new List<DoodadObject>();
public List<String> gatherTypes = new List<String>();
public bool isRunning = false;
public bool useMarker = true;
public bool isMarkerActive = false;
public DoodadObject foundDood = null;
public Thread mainThread;
//Call on plugin start
public void PluginRun()
{
Log("Run");
//printDoods();
//Log("dooddist " + getClosestDood().dist(me));
//moveToDood(getClosestDood());
gatherTypes.Add("Chop Tree");
gatherTypes.Add("Mine Ore");
//printDoods();
isRunning = true;
Start();
}
public void Start(){
while(isRunning){
Thread.Sleep(1000);
try{
DoodadObject dood = getClosestDood();
if(dood != null){
if(useMarker){
markerRoutine(dood);
}else{
Log("name " + dood.name );
moveToDood(dood);
}
}
}catch(Exception){
//Log(e.ToString());
isMarkerActive = false;
}
}
}
public void markerRoutine(DoodadObject dood){
if(dood == null){
isMarkerActive = false;
Log("target removed");
return;
}
if(isMarkerActive){
if(dood != null && me.dist(dood) <= 5){
isMarkerActive = false;
Log("reached " + dood.name);
}else if(dood != null && dood.objId != foundDood.objId){
Log("closer target found");
isMarkerActive = false;
}
}else if(dood != null && me.dist(dood) > 5 ){
isMarkerActive = true;
SetMapPos(dood.X, dood.Y, dood.Z);
Log("marker set on " + dood.name + " dist: " + me.dist(dood));
foundDood = dood;
}
}
public void getDoodType(DoodadObject dood){
printDoodInfo(dood);
Log("doodtype: " + dood.phaseId);
}
public void printDoodInfo(DoodadObject dood){
Log("name: " + dood.name + " dist: " + dood.dist(me));
}
public void moveToDood(DoodadObject dood){
if(dood == null) return;
Log("Move To: " + dood.name + " dist: " + me.dist(dood));
//printDoodInfo(dood);
while(dood.dist(me) >= 3){
ComeTo(dood, 2);
Thread.Sleep(50);
if(hasNearbyPlayers(dood)) return;
}
useDoodad(dood);
}
public Skill getDoodadSkill(DoodadObject dood){
Skill skill = null;
if(dood != null){
foreach(var obj in dood.getUseSkills()){
skill = obj;
}
}
return skill;
}
public void useDoodad(DoodadObject dood){
if(dood != null){
Skill skill = getDoodadSkill(dood);
if(skill != null){
Log(skill.name + " " + dood.name);
while(dood != null && dood.dist(me) <= 3 && !hasNearbyPlayers(dood)){
if(UseDoodadSkill(skill.id, dood, true, 0) == true){
Log("Gathered: " + dood.name);
dood.Dispose();
dood = null;
}
Thread.Sleep(50);
}
}
}
}
public String hasGatherType(DoodadObject dood){
Skill skill = getDoodadSkill(dood);
return "";
}
public DoodadObject getClosestDood(){
DoodadObject dood = null;
double dist = 9999999999;
doodList = getDoodads();
Skill skill = null;
if(doodList.Count > 0){
//printDoods();
foreach(var obj in doodList){
skill = getDoodadSkill(obj);
if(skill != null ){
if(skill.name == "Chop Tree" || skill.name == "Mine Ore"){
if(me.dist(obj) < dist && obj.growthTime <= 0 && obj.uniqOwnerId == 0
&& !hasNearbyPlayers(obj)){
dood = obj;
dist = me.dist(obj);
}
}
}
}
}
if(dood != null){
return dood;
}
return null;
}
public bool hasNearbyPlayers(DoodadObject node)
{
foreach (var obj in getCreatures())
{
if(obj.type == BotTypes.Player && node.dist(obj) <= 4)
{
Log(obj.name + " is too close to " + node.name);
return true;
}
}
return false;
}
public void printDoods(){
updateDoodads();
Skill skill = null;
String sName = "";
foreach(var obj in doodList){
Log("---");
skill = getDoodadSkill(obj);
if(skill != null){
sName = skill.name;
}else{
sName = "";
}
Log(obj.name + " Time: " + obj.growthTime + " skill: " + sName);
Log("Type: " + obj.type + "dist: " + me.dist(obj));
Log("ownerId: " + obj.uniqOwnerId);
}
}
public void updateDoodads(){
doodList = getDoodads();
}
//Call on plugin stop
public void PluginStop()
{
}
}
}
Last edited: