private bool RegionCollected(Region r, out RegionWatcherObject foundObject)
        {
            RegionWatcherObject found = null;

            if (r.Name == "Isles of Jun'kol")
            {
                found = _regions.Find(
                    delegate(RegionWatcherObject obj)
                {
                    return(obj.Name == "Jun'kol");
                });
            }
            else
            {
                for (int i = 0; found == null && i < _regions.Count; i++)
                {
                    if (_regions[i].Name == r.Name && _regions[i].Map == r.Map)
                    {
                        found = _regions[i];
                    }
                }
            }

            foundObject = found;
            return(found != null);
        }
Esempio n. 2
0
        private static uint GetRegionColor(RegionWatcherObject obj, Dictionary <string, uint> colorList)
        {
            string name  = obj.Name.Replace(" ", "");
            uint   color = colorList["default"];

            if (colorList.ContainsKey(name))
            {
                color = colorList[name];
            }

            return(color);
        }
        protected override void OnTick()
        {
            List <NetState>     users = new List <NetState>(NetState.Instances);
            Mobile              m;
            Region              reg;
            RegionWatcherObject obj;

            for (int i = 0; i < users.Count; i++)
            {
                reg = null;
                obj = null;

                m = users[i].Mobile;

                if (m == null || IgnoreMap(m.Map))
                {
                    continue;
                }

                reg = FindRegion(m.Location, m.Map);

                if (reg == null)
                {
                    continue;
                }

                _totalRegionChecks++;

                if (RegionCollected(reg, out obj))
                {
                    obj.Count++;
                }
                else
                {
                    obj = new RegionWatcherObject(reg.Name, reg.Map, 1);
                    _regions.Add(obj);
                }
            }

            CalculatePopularity();

            try
            {
                SortStats(_regions);
                SaveStats(_regions, _totalRegionChecks);
            }
            catch (Exception e)
            {
                ExceptionManager.LogException("RegionPopularityWatcher", e);
            }
        }
        public static List <RegionWatcherObject> Load(bool autoStart)
        {
            RegionPopularityWatcher watcher = new RegionPopularityWatcher();

            watcher.Regions     = new List <RegionWatcherObject>();
            watcher.TotalChecks = 0;

            if (File.Exists(PersistancePath))
            {
                XmlDocument         doc = new XmlDocument();
                XmlElement          root;
                RegionWatcherObject obj;

                try
                {
                    doc.Load(PersistancePath);
                    root = doc[RootElementName];

                    watcher.TotalChecks = Convert.ToInt32(root.GetAttribute("totalChecks"));

                    foreach (XmlElement node in root.GetElementsByTagName(ChildElementName))
                    {
                        obj                   = new RegionWatcherObject(node["name"].InnerText, Util.GetMapByName(node["map"].InnerText));
                        obj.Count             = Convert.ToInt32(node["count"].InnerText);
                        obj.PopularityPercent = Convert.ToInt32(node["popularityPercentage"].InnerText);

                        if (IgnoreMap(obj.Map))
                        {
                            watcher.TotalChecks -= obj.Count;
                        }
                        else
                        {
                            watcher.Regions.Add(obj);
                        }
                    }
                }
                catch (Exception e)
                {
                    ExceptionManager.LogException("RegionPopularityWatcher", e);
                }
            }

            SortStats(watcher.Regions);

            if (autoStart)
            {
                watcher.Start();
            }

            return(watcher.Regions);
        }
		protected override void OnTick()
		{
			List<NetState> users = new List<NetState>( NetState.Instances );
			Mobile m;
			Region reg;
			RegionWatcherObject obj;

			for( int i = 0; i < users.Count; i++ )
			{
				reg = null;
				obj = null;

				m = users[i].Mobile;

				if( m == null || IgnoreMap( m.Map ) )
					continue;

				reg = FindRegion( m.Location, m.Map );

				if( reg == null )
					continue;

				_totalRegionChecks++;

				if( RegionCollected( reg, out obj ) )
					obj.Count++;
				else
				{
					obj = new RegionWatcherObject( reg.Name, reg.Map, 1 );
					_regions.Add( obj );
				}
			}

			CalculatePopularity();

			try
			{
				SortStats( _regions );
				SaveStats( _regions, _totalRegionChecks );
			}
			catch( Exception e )
			{
				ExceptionManager.LogException( "RegionPopularityWatcher", e );
			}
		}
Esempio n. 6
0
		private static uint GetRegionColor( RegionWatcherObject obj, Dictionary<string, uint> colorList )
		{
			string name = obj.Name.Replace( " ", "" );
			uint color = colorList["default"];

			if( colorList.ContainsKey( name ) )
				color = colorList[name];

			return color;
		}
		public static List<RegionWatcherObject> Load( bool autoStart )
		{
			RegionPopularityWatcher watcher = new RegionPopularityWatcher();
			watcher.Regions = new List<RegionWatcherObject>();
			watcher.TotalChecks = 0;

			if( File.Exists( PersistancePath ) )
			{
				XmlDocument doc = new XmlDocument();
				XmlElement root;
				RegionWatcherObject obj;

				try
				{
					doc.Load( PersistancePath );
					root = doc[RootElementName];

					watcher.TotalChecks = Convert.ToInt32( root.GetAttribute( "totalChecks" ) );

					foreach( XmlElement node in root.GetElementsByTagName( ChildElementName ) )
					{
						obj = new RegionWatcherObject( node["name"].InnerText, Util.GetMapByName( node["map"].InnerText ) );
						obj.Count = Convert.ToInt32( node["count"].InnerText );
						obj.PopularityPercent = Convert.ToInt32( node["popularityPercentage"].InnerText );

						if( IgnoreMap( obj.Map ) )
							watcher.TotalChecks -= obj.Count;
						else
							watcher.Regions.Add( obj );
					}
				}
				catch( Exception e )
				{
					ExceptionManager.LogException( "RegionPopularityWatcher", e );
				}
			}

			SortStats( watcher.Regions );

			if( autoStart )
				watcher.Start();

			return watcher.Regions;
		}
		private bool RegionCollected( Region r, out RegionWatcherObject foundObject )
		{
			RegionWatcherObject found = null;

			if( r.Name == "Isles of Jun'kol" )
			{
				found = _regions.Find(
					delegate( RegionWatcherObject obj )
					{
						return (obj.Name == "Jun'kol");
					} );
			}
			else
			{
				for( int i = 0; found == null && i < _regions.Count; i++ )
				{
					if( _regions[i].Name == r.Name && _regions[i].Map == r.Map )
						found = _regions[i];
				}
			}

			foundObject = found;
			return (found != null);
		}