public ResourceConsignment[] Remove(int amount) { int newbie = (int)Math.Ceiling(amount * m_SmallestFirstFactor), communal = amount - newbie; ArrayList topay = new ArrayList(); if (amount > TotalCount) { return(null); } for (int i = 0; i < m_ConsignmentList.Count && newbie > 0; i++) { ResourceConsignment rc = (ResourceConsignment)m_ConsignmentList[i]; int delta = rc.ModifyAmount(-newbie); if (delta == -newbie) { continue; } topay.Add(new ResourceConsignment(rc.Type, newbie + delta, rc.Price, rc.Seller)); newbie = -delta; } for (int i = 0; i < m_ConsignmentList.Count && communal > 0; i++) { ResourceConsignment rc = (ResourceConsignment)m_ConsignmentList[i]; int toremove = communal / (m_ConsignmentList.Count - i); if (toremove == 0) { toremove = 1; } int delta = rc.ModifyAmount(-toremove); if (delta == -toremove) { continue; } topay.Add(new ResourceConsignment(rc.Type, toremove + delta, rc.Price, rc.Seller)); communal -= (toremove + delta); } while (m_ConsignmentList.Count > 0 && ((ResourceConsignment)m_ConsignmentList[0]).Amount == 0) { m_ConsignmentList.RemoveAt(0); } return((ResourceConsignment[])topay.ToArray(typeof(ResourceConsignment))); }
public int CompareTo(object obj) { if (obj is ResourceConsignment) { ResourceConsignment rc = (ResourceConsignment)obj; return(m_Amount.CompareTo(((ResourceConsignment)obj).Amount)); } throw new ArgumentException("object is not ResourceConsignment"); }
public int Compare(object x, object y) { ResourceConsignment rc1 = x as ResourceConsignment, rc2 = y as ResourceConsignment; if (rc1 == null && rc2 != null) { return(-1); } if (rc1 == null && rc2 == null) { return(0); } if (rc1 != null && rc2 == null) { return(1); } return(rc1.Seller.Name.CompareTo(rc2.Seller.Name)); }
public static void ResourceTrack_OnCommand(CommandEventArgs e) { DateTime begin = DateTime.Now; if (!Directory.Exists(OUTPUT_DIRECTORY)) { Directory.CreateDirectory(OUTPUT_DIRECTORY); } File.Copy(RESULTS_CSS, OUTPUT_DIRECTORY + "/results.css", true); StreamWriter sw = new StreamWriter(OUTPUT_DIRECTORY + "/" + OUTPUT_FILE); try { Console.Write("ResourceTracker running..."); sw.WriteLine("<html>"); sw.WriteLine("<head>"); sw.WriteLine("<title>ResourceTracker Results</title>"); sw.WriteLine("<link rel='stylesheet' type='text/css' href='results.css'/>"); sw.WriteLine("</head>"); sw.WriteLine("<body>"); sw.WriteLine("<h1>Immediate ResourcePool State</h1>"); sw.WriteLine("<h2>Resources</h2>"); sw.WriteLine("<table width='90%'>"); sw.WriteLine("<tr class='theader'><td>Resource Name</td><td>Count</td><td>Wholesale Price</td><td>Resale Price</td><td>Total Investment</td><td>Total Value</td></tr>"); ArrayList resdatas = new ArrayList(ResourcePool.Resources.Values); resdatas.Sort(); for (int i = 0, m = 0; i < resdatas.Count; i++) { if (!(resdatas[i] is ResourceData) || resdatas[i] is RDRedirect) { continue; } ResourceData res = resdatas[i] as ResourceData; sw.WriteLine("<tr class='tr{6}'><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>", res.Name, res.TotalCount, res.WholesalePrice, res.ResalePrice, res.TotalInvested, res.TotalValue, m++ % 2 + 1); } sw.WriteLine("</table>"); sw.WriteLine("<h2>ResourceData Redirects</h2>"); sw.WriteLine("<table width='90%'>"); sw.WriteLine("<tr class='theader'><td>RDRedirect Name</td><td>Amount Factor</td><td>Price Factor</td><td>Wholesale Price</td></tr>"); ArrayList rddatas = new ArrayList(ResourcePool.Resources.Values); rddatas.Sort(); for (int i = 0, m = 0; i < rddatas.Count; i++) { if (!(rddatas[i] is RDRedirect)) { continue; } RDRedirect rd = rddatas[i] as RDRedirect; sw.WriteLine("<tr class='tr{4}'><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>", rd.Name, rd.AmountFactor, rd.PriceFactor, rd.WholesalePrice, m++ % 2 + 1); } sw.WriteLine("</table>"); sw.WriteLine("<h2>ResourceData Detail</h2>"); for (int i = 0; i < resdatas.Count; i++) { ResourceData rd = resdatas[i] as ResourceData; sw.WriteLine("<a name='{0}'/>", rd.Name); sw.WriteLine("<h3>{0} Detail</h3>", rd.Name); sw.WriteLine("<table width='90%'>"); sw.WriteLine("<tr class='theader'><td>Player Name</td><td>Amount Invested</td><td>Price Sold</td><td>Total Investment</td></tr>"); ArrayList rclist = new ArrayList(rd.ConsignmentList); rclist.Sort(new ConsignmentComparer()); ArrayList histogram = new ArrayList(); for (int a = 0, m = 0; a < rclist.Count; a++) { ResourceConsignment rc = rclist[a] as ResourceConsignment; while (histogram.Count <= rc.Amount) { histogram.Add((double)0); } histogram[rc.Amount] = (double)(histogram[rc.Amount]) + (double)1; sw.WriteLine("<tr class='tr{4}'><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>", rc.Seller.Name, rc.Amount, rc.Price, rc.Amount * rc.Price, m++ % 2 + 1); } if (histogram.Count > 0) { Graph g = new Graph("Consignment Amount Distribution", "Amount of Consignment", "# of Consignments", (double[])histogram.ToArray(typeof(double))); g.Create(OUTPUT_DIRECTORY + "/" + rd.Name + " dist.gif"); sw.WriteLine("<img src='{0} dist.gif'/>", rd.Name); } sw.WriteLine("</table>"); } sw.WriteLine("</body>"); sw.WriteLine("</html>"); } catch (Exception ex) { LogHelper.LogException(ex); Console.WriteLine("Error!"); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); return; } finally { sw.Flush(); sw.Close(); } TimeSpan ts = DateTime.Now - begin; Console.WriteLine("finished in {0} seconds.", (double)ts.Milliseconds / (double)1000); }
public virtual void Load(XmlTextReader reader, GenericReader rcreader) { int version = Int32.Parse(reader.GetAttribute("version")); reader.ReadStartElement("ResourceData"); switch (version) { case 0: { m_Name = reader.ReadElementString("Name"); m_Type = Type.GetType(reader.ReadElementString("Type")); m_BunchName = reader.ReadElementString("BunchName"); m_ResalePrice = Double.Parse(reader.ReadElementString("ResalePrice")); m_WholesalePrice = Double.Parse(reader.ReadElementString("WholesalePrice")); m_ItemID = Int32.Parse(reader.ReadElementString("ItemID")); m_Hue = Int32.Parse(reader.ReadElementString("Hue")); m_SmallestFirstFactor = Double.Parse(reader.ReadElementString("SmallestFirstFactor")); m_ValidFailsafe = bool.Parse(reader.ReadElementString("ValidFailsafe")); if (m_Type == null || m_Type.GetInterface("ICommodity", false) == null) { throw new Exception(String.Format("Error: Type of resource '{0}' does not exist or does not implement ICommodity.", m_Name)); } m_ConsignmentList = new ArrayList(); if (rcreader == null) // || !FindPosition(rcreader)) { break; } ((BinaryFileReader)rcreader).Seek(0, SeekOrigin.Begin); if (rcreader.End()) { break; } int rcversion = rcreader.ReadInt(); switch (rcversion) { case 0: { while (!rcreader.End()) { ResourceConsignment rc = new ResourceConsignment(rcreader); if (rc.Type == m_Type) { m_ConsignmentList.Add(rc); } } break; } default: throw new Exception("ResourcePool error: Invalid file version for Consignments.dat"); } /*if (!rcreader.End() && rcreader.ReadString() == m_Type.FullName) * { * int rcversion = rcreader.ReadInt(); * switch (rcversion) * { * case 0: * { * count = rcreader.ReadInt(); * for (; count > 0; count--) * m_ConsignmentList.Add(new ResourceConsignment(rcreader)); * break; * } * default: * { * throw new Exception("ResourcePool error: Invalid ResourceData entry save version in Consignments.dat"); * } * } * }*/ break; } default: { throw new Exception("Error loading ResourceData: Invalid saveversion"); } } reader.ReadEndElement(); }
public virtual void Load(XmlTextReader reader, GenericReader rcreader) { int version = Int32.Parse(reader.GetAttribute("version")); reader.ReadStartElement("ResourceData"); switch (version) { case 0: { m_Name = reader.ReadElementString("Name"); m_Type = Type.GetType(reader.ReadElementString("Type")); m_BunchName = reader.ReadElementString("BunchName"); m_ResalePrice = Double.Parse(reader.ReadElementString("ResalePrice")); m_WholesalePrice = Double.Parse(reader.ReadElementString("WholesalePrice")); m_ItemID = Int32.Parse(reader.ReadElementString("ItemID")); m_Hue = Int32.Parse(reader.ReadElementString("Hue")); m_SmallestFirstFactor = Double.Parse(reader.ReadElementString("SmallestFirstFactor")); m_ValidFailsafe = bool.Parse(reader.ReadElementString("ValidFailsafe")); if (m_Type == null || m_Type.GetInterface("ICommodity", false) == null) throw new Exception(String.Format("Error: Type of resource '{0}' does not exist or does not implement ICommodity.", m_Name)); m_ConsignmentList = new ArrayList(); if (rcreader == null)// || !FindPosition(rcreader)) break; ((BinaryFileReader)rcreader).Seek(0, SeekOrigin.Begin); if (rcreader.End()) break; int rcversion = rcreader.ReadInt(); switch (rcversion) { case 0: { while (!rcreader.End()) { ResourceConsignment rc = new ResourceConsignment(rcreader); if (rc.Type == m_Type) m_ConsignmentList.Add(rc); } break; } default: throw new Exception("ResourcePool error: Invalid file version for Consignments.dat"); } /*if (!rcreader.End() && rcreader.ReadString() == m_Type.FullName) { int rcversion = rcreader.ReadInt(); switch (rcversion) { case 0: { count = rcreader.ReadInt(); for (; count > 0; count--) m_ConsignmentList.Add(new ResourceConsignment(rcreader)); break; } default: { throw new Exception("ResourcePool error: Invalid ResourceData entry save version in Consignments.dat"); } } }*/ break; } default: { throw new Exception("Error loading ResourceData: Invalid saveversion"); } } reader.ReadEndElement(); }