You can not use this by itself. This is only a small portion of my project I would like to share. Other programmers can take out my code as they please. This code requires a picturebox. In the pictureBox click event I have another form that lets you change colors of things, but I have not included it.
Radar.cs

Radar.cs
PHP:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ArcheBuddy.Bot.Classes;
using System.Threading;
namespace ArcheAgeIlluminati
{
public partial class Radar : Form
{
private Core core;
private Thread thread;
private int cX, cY;
Bitmap bmp;
System.Drawing.Pen p;
Graphics g;
int pbWidth, pbHeight;
RadarMenu myMenu;
public radarColors colorsStruct;
public Radar()
{
InitializeComponent();
}
public struct radarColors
{
public Color _enemyFactionColor, _collectAbleDoodadColor, _loggingColor, _miningColor, _attackableCreature;
}
private void setupColors()
{
colorsStruct._collectAbleDoodadColor = Color.Yellow;
colorsStruct._loggingColor = Color.Pink;
colorsStruct._miningColor = Color.DarkBlue;
colorsStruct._enemyFactionColor = Color.Red;
colorsStruct._attackableCreature = Color.DarkRed;
}
private void RadarThread()
{
try
{
colorsStruct = new radarColors();
setupColors();
pbWidth = pictureBox1.Width;
pbHeight = pictureBox1.Height;
cX = pbWidth / 2;//center
cY = pbHeight / 2;//center
this.BackColor = System.Drawing.Color.Black;
colorsStruct._enemyFactionColor = Color.Orange;
while (true)
{
if (core.me != null)
{
clearGraphics();
Thread.Sleep(PluginClass.timerDelay);
//draw myself
drawPoint(cX, cY, System.Drawing.Color.DarkViolet);
//draw my point
drawLine(cX, cY - 20, System.Drawing.Color.DarkViolet);
logDoodads();
logCharacters();
Thread.Sleep(PluginClass.timerDelay*3);
disposeGraphics();
}
}
//check surroundings
}
catch (Exception e)
{
core.Log(e.ToString() + " RadarThread()");
}
}
private void clearGraphics()
{
bmp = new Bitmap(pbWidth + 1, pbHeight + 1);
p = new System.Drawing.Pen(System.Drawing.Color.Green, 1f);
g = Graphics.FromImage(bmp);
g.Clear(System.Drawing.Color.Black);
g.DrawEllipse(p, 0, 0, pbWidth, pbHeight);
g.DrawEllipse(p, 80, 80, pbWidth - 160, pbHeight - 160);
}
private void disposeGraphics()
{
//bmp.Dispose();
p.Dispose();
g.Dispose();
}
public void SetCore(Core core)
{
this.core = core;
}
private int findAngle(int angle)
{
angle = (int)(angle * 2.769230769230769);
if (angle > 360)
angle = 360;
angle = angle - 127;
if (angle > 360)
{
int theDiff = angle - 360;
angle = 0 + theDiff;
}
if (angle < 0)
angle = 360 + angle;
return angle;
}
private Point newPosition(int x, int y, int angle)
{
try
{
int x2,y2;
angle = findAngle(angle);
//correct arche age angle
double theX = Convert.ToDouble(x);
double theY = Convert.ToDouble(y);
double theRadian = Math.PI * angle / 180;
double theRadius = getDistanceOfPositions(theX, theY);
x2 = (int)((x) * Math.Cos(theRadian) - (y) * Math.Sin(theRadian));
y2 = (int)((x) * Math.Sin(theRadian) + (y) * Math.Cos(theRadian));
x2 = x2 + cX;
y2 = y2 + cY;
return new Point(x2, y2);
}
catch (Exception e)
{
core.Log(e.ToString() + " newPosition");
return new Point(0, 0);
}
}
private void logDoodads()
{
List<DoodadObject> myDoods = core.getDoodads();
for (int i = 0; i < myDoods.Count; i++)
{
int rX = (int)myDoods[i].X - (int)core.me.X;
int rY = (int)core.me.Y - (int)myDoods[i].Y;
//scale down
rX = Convert.ToInt16(rX / 2);
rY = Convert.ToInt16(rY / 2);
// angle
int myAngle = core.me.turnAngle;//0 - 130
Point correctPoint = newPosition(rX, rY, myAngle);
int pX = Convert.ToInt16(correctPoint.X);
int pY = Convert.ToInt16(correctPoint.Y);
if (myDoods[i].plantZoneId != 0 && myDoods[i].plantZoneId != core.me.zoneId)
continue;
var skills = myDoods[i].getUseSkills();
if (skills == null)
{
//Log("Null doodad skills!");
// Thread.Sleep(timerDelay);
continue;
}
if (skills.Count == 0)
continue;
bool hasLogging = false;
bool hasGathering = false;
bool hasMining = false;
bool hasFruit = false;
bool hasLeaves = false;
bool hasUproot = false;
for (int ii = 0; ii < skills.Count; ii++)
{
// Log("Skill Name " + i.ToString() + " : " + skills[i].name);
// Thread.Sleep(timerDelay * 2);
if (skills[ii].name == "Uproot")
hasUproot = true;
//if (_gatherLeaves)
if (skills[ii].name == "Gather Leaves")
hasLeaves = true;
//if (_findFruit)
if (skills[ii].name == "Find Fruit")
hasFruit = true;
//if (_cutLogs)
if (skills[ii].name == "Chop Tree")
for (int t = 0; t < PluginClass.goodTrees.Count; t++)
if (myDoods[i].name.Contains(PluginClass.goodTrees[t]))
hasLogging = true;
//if (_findGather)
if (skills[ii].name == "Gather")
hasGathering = true;
//if (_findOre)
if (skills[ii].name == "Mine Ore" || skills[ii].name == "Mine the Fortuna Vein")
hasMining = true;
}
//if (Obj.tempGrowthTime == 0 && !hasMining)
// continue;
if (!hasLogging && !hasGathering && !hasMining && !hasFruit && !hasLeaves)
continue;
// core.Log("My X: " + core.me.X.ToString() + " My Y: " + core.me.Y.ToString() + " Enemy X: " + creatures[i].X.ToString() + " Enemy Y: " + creatures[i].Y.ToString() + " rX: " + rX.ToString() + " rY: " + rY.ToString() + " pX: " + pX.ToString() + " pY: " + pY.ToString());
// Thread.Sleep(PluginClass.timerDelay * 5);
Color theColor;
if (hasLogging)
{
theColor = colorsStruct._loggingColor;
}
else if (hasMining)
theColor = colorsStruct._miningColor;
else
theColor = colorsStruct._collectAbleDoodadColor;
drawPoint(pX, pY, theColor);
}
}
private void logCharacters()
{
List<Creature> creatures = core.getCreatures();
for (int i = 0; i < creatures.Count; i++)
{
int rX = (int)creatures[i].X - (int)core.me.X;
int rY = (int)core.me.Y - (int)creatures[i].Y;
//scale down
rX = Convert.ToInt16(rX / 2);
rY = Convert.ToInt16(rY / 2);
// angle
int myAngle = core.me.turnAngle;//0 - 130
Point correctPoint = newPosition(rX, rY, myAngle);
int pX = Convert.ToInt16(correctPoint.X);
int pY = Convert.ToInt16(correctPoint.Y);
// core.Log("My X: " + core.me.X.ToString() + " My Y: " + core.me.Y.ToString() + " Enemy X: " + creatures[i].X.ToString() + " Enemy Y: " + creatures[i].Y.ToString() + " rX: " + rX.ToString() + " rY: " + rY.ToString() + " pX: " + pX.ToString() + " pY: " + pY.ToString());
// Thread.Sleep(PluginClass.timerDelay * 5);
System.Drawing.Color theColor = System.Drawing.Color.Green;
if (creatures[i].factionId == 1)
theColor = System.Drawing.Color.DarkBlue;
if (core.isAttackable(creatures[i]))
theColor = colorsStruct._attackableCreature;
if (creatures[i].charRace == CharRace.None && !core.isAttackable(creatures[i]))
theColor = System.Drawing.Color.White;
//if (creatures[i].type.ToString() == "Npc" && !core.isAttackable(creatures[i]) && creatures[i].charRace.ToString() != "None")
// theColor = System.Drawing.Color.Yellow;
if (core.me.factionId == 109 || core.me.factionId == 113)//west
{
if (creatures[i].type == BotTypes.Player && (creatures[i].factionId != 113 && creatures[i].factionId != 109))
theColor = colorsStruct._enemyFactionColor;
//if (creatures[i].factionId == 113 || creatures[i].fvvvvvvvvvvvvvvvvvvvvvvvvvbactionId == 109)
// theColor = System.Drawing.Color.Green;
}
drawPoint(pX, pY, theColor);
}
if (InvokeRequired)
this.Invoke((MethodInvoker)(() =>
{
this.pictureBox1.Image = bmp;
}));
else
pictureBox1.Image = bmp;
}
private double getDistanceOfPositions(double X, double Y)
{
return Math.Sqrt(Math.Pow(cX - X, 2) + Math.Pow(cY - Y, 2));
}
public void drawPoint(int x, int y, System.Drawing.Color theColor)
{
p = new System.Drawing.Pen(theColor, 1f);
g.DrawEllipse(p, x, y, 2, 2);
//g.DrawLine(p, new Point(x, y), new Point(x+1, y+1));
}
public void drawLine(int x, int y, System.Drawing.Color theColor)
{
p = new System.Drawing.Pen(theColor, 1f);
Point myPos = new Point(cX, cY);
Point myDest = new Point(x,y);
g.DrawLine(p, myPos, myDest);
//g.DrawLine(p, new Point(x, y), new Point(x+1, y+1));
}
private void Radar_Load(object sender, EventArgs e)
{
this.TopMost = true;
thread = new Thread(RadarThread);
thread.Start();
}
public void Stop()
{
try
{
thread.Abort();
this.Dispose();
}
catch (ThreadAbortException) { }
catch (Exception ex)
{
core.Log("Couldn't abort combat thread: " + ex.Message);
}
}
private void Radar_FormClosed(object sender, FormClosedEventArgs e)
{
thread.Abort();
disposeGraphics();
if (!this.IsDisposed)
this.Dispose();
}
private void runRadar()
{
try
{
Application.Run(myMenu);
}
catch (Exception error)
{
core.Log(error.ToString());
}
}
void myMenu_FormClosed(object sender, FormClosedEventArgs e)
{
core.Log("Form closed - stopping the plugin");
}
public bool showOptions = false;
private void pictureBox1_Click(object sender, EventArgs e)
{
try
{
if (showOptions)
showOptions = false;
else
{
showOptions = true;
if (myMenu != null)
{
if(myMenu.IsAccessible)
myMenu.Close();
if(!myMenu.IsDisposed)
myMenu.Dispose();
myMenu = null;
}
}
if (showOptions)
{
if (myMenu == null)
{
myMenu = new RadarMenu();
myMenu.setRadar(this, colorsStruct);
myMenu.FormClosed += myMenu_FormClosed;
}
Thread radarThread = new Thread(runRadar);
radarThread.Start();
}
else
{
if(myMenu != null)
{
myMenu.Close();
myMenu.Dispose();
myMenu = null;
}
}
}
catch (Exception f)
{
core.Log(f.ToString() + " pbClick1");
}
}
}
}