What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

[Plugin] Node Database

Smarter

Member
Joined
Jan 15, 2010
Messages
763
Reaction score
9
I have began a plugin to record the locations of all nodes my bot sees while running. I later plan to add the ability to count the times it has seen the node in that location. To then later be able to plot this data and create an optimized flight path based on spawn rate and location (for example, if a node re-spawns every 10-15 minutes, and you know that is almost always re-spawns in the same spot or within the bots view of that area (100m) you could create a smaller flight path that takes around 10-15 minutes to travel from each furthest node).


Code:
using System;
using System.Collections.Generic;
using Styx.Helpers;
using Styx.Plugins.PluginClass;
using System.Data.SqlClient;
using Styx.WoWInternals;
using System.Linq;
using Styx.WoWInternals.WoWObjects;


namespace GatherMateBuddy
{
    public class GatherMateBuddy : HBPlugin
    {
        private bool _firstPulse = true;
        private List<WoWGameObject> _nodeList = new List<WoWGameObject>();
        private Dictionary<ulong,DateTime> _seenList = new Dictionary<ulong, DateTime>();
        private WaitTimer _refreshTimer = WaitTimer.FiveSeconds;
        private WaitTimer _updateTimer = WaitTimer.TenSeconds;
        private WaitTimer _seenTimer = new WaitTimer(new TimeSpan(0,0,10,0));
        private SqlConnection _sqlConnection;
        private NodeDatabaseDataSet _nodeDataSet = new NodeDatabaseDataSet();
        private SqlDataAdapter _dataAdapter;

        public override void Dispose()
        {
            _sqlConnection.Close();
        }

        public override void Pulse()
        {
            if (_firstPulse)
            {
                _sqlConnection = new SqlConnection(@"Data Source=C:\Users\Smarter\Desktop\Botting\Development\GatherMateBuddy\GatherMateBuddy\NodeDatabase.sdf");
                _dataAdapter = new SqlDataAdapter("Select * from NodeData", _sqlConnection);
                // Other Startup Stuff?
                _firstPulse = false;
            }

            if (_refreshTimer.IsFinished)
            {
                var nearbyNodes =
                    ObjectManager.GetObjectsOfType<WoWGameObject>().Where(o => o.IsHerb || o.IsMineral).OrderBy(
                        o => o.Distance);
                if (nearbyNodes.Count() > 1)
                {
                    lock (_nodeList)
                    {
                        foreach (var node in nearbyNodes.Where(node => !_nodeList.Contains(node) && !_seenList.ContainsKey(node.Guid)))
                        {
                            _nodeList.Add(node);
                        }
                    }
                }
                _refreshTimer.Reset();
            }


            if (_updateTimer.IsFinished)
            {
                var nodeList = _nodeList;
                _nodeDataSet.Clear();
                _dataAdapter.Fill(_nodeDataSet);
                foreach (WoWGameObject o in nodeList)
                {
                    _nodeDataSet.Tables["Node Data"].Rows.Add(new object[] {o.Name, o.Entry, o.X, o.Y, o.Z, 0});
                }
                _dataAdapter.Update(_nodeDataSet);

                _updateTimer.Reset();
            }


            if (_seenTimer.IsFinished)
            {
                var seenList = _seenList;
                foreach (KeyValuePair<ulong, DateTime> pair in
                    from pair in seenList
                    let duration = DateTime.Now.Subtract(pair.Value)
                    where duration.Minutes >= 10
                    select pair)
                {
                    lock (_seenList)
                    {
                        _seenList.Remove(pair.Key);
                    }
                }

                _seenTimer.Reset();
            }

        }

        public override string Name
        {
            get { return "GatherMateBuddy"; }
        }

        public override string Author
        {
            get { return "Smarter"; }
        }

        public override Version Version
        {
            get { return new Version(0,0,1,0); }
        }
    }
}

I have decided to use just a Local Database (SQL Compact) ....I was wondering if anyone had any suggestions or improvements or insults to assist me in my planning of this? :cool:
 
would be nice if GB2 could use this info in a smart way to find/scan for node's...
 
if u plan to use this later for optimizing flightpathes u should store some more data
as i see u only store name entry and coordinates
but u'll maybe nee continent / map id (for easier filtering) and a second table with timestamps / dates to query how often u've seen the node and maybe to calculate respawn rates
 
There's game addons for this`

Yeah, but I'd prefer it be specifically gathered by where I fly and not a mass of information I don't need to process.

I was hoping for comments on Code, not method actually :-D.
 
Back
Top