public int Compare(object x, object y) { if (x == y) { return(0); } GoldTotaller xg = m_Table[x] as GoldTotaller; GoldTotaller yg = m_Table[y] as GoldTotaller; if (xg == null || yg == null) { return(0); } else { if (xg.TotalGold == yg.TotalGold) { if (xg.BankGold > yg.BankGold) { return(-1); } else { return(1); } } else if (xg.TotalGold > yg.TotalGold) { return(-1); } else { return(1); } } }
private static void OnCalculateAndWrite(Mobile cmdmob, int maxtoprint, bool bSupressNames, bool bSupressStaff, bool bIndicateBanned) { if (bInProcess == true) { System.Console.WriteLine("Got GoldTracker call when already processing."); return; } bInProcess = true; DateTime startDateTime = DateTime.Now; if (!Directory.Exists(OUTPUT_DIRECTORY)) { Directory.CreateDirectory(OUTPUT_DIRECTORY); } try { string initmsg = string.Format("Tracking Gold...outputing top {0}", maxtoprint); System.Console.WriteLine(initmsg); SM(cmdmob, initmsg); #if false using (StreamWriter op = new StreamWriter(OUTPUT_DIRECTORY + "/" + OUTPUT_FILE)) { op.WriteLine("<HTML><BODY>"); op.WriteLine("<TABLE BORDER=1 WIDTH=90%><TR>"); op.WriteLine("<TD>Account</TD><TD>Character</TD><TD>Total Worth</TD><TD>Backpack Gold</TD><TD>Bank Gold</TD><TD>House Gold</TD><TD>Number of Houses</TD><TD>Vendor Gold</TD>"); op.WriteLine("</TR>"); foreach (Account acct in Accounts.Table.Values) { string acctname = acct.Username; //System.Console.WriteLine(acctname); //iterate through characters: for (int i = 0; i < 5; ++i) { if (acct[i] != null) { PlayerMobile player = (PlayerMobile)acct[i]; op.WriteLine("<TR><TD><B>" + acctname + "</B></TD>"); op.WriteLine("<TD>" + player.Name + "</TD>"); Container backpack = player.Backpack; BankBox bank = player.BankBox; int backpackgold = 0; int bankgold = 0; //BACKPACK backpackgold = GetGoldInContainer(backpack); //BANK bankgold = GetGoldInContainer(bank); //house? int housetotal = 0; ArrayList list = Multis.BaseHouse.GetHouses(player); for (int j = 0; j < list.Count; ++j) { if (list[j] is BaseHouse) { BaseHouse house = (BaseHouse)list[j]; housetotal += GetGoldInHouse(house); } } //vendors int vendortotal = 0; ArrayList vendors = GetVendors(player); for (int j = 0; j < vendors.Count; j++) { if (vendors[j] is PlayerVendor) { PlayerVendor pv = vendors[j] as PlayerVendor; vendortotal += pv.HoldGold; } } op.WriteLine("<TD>" + (backpackgold + bankgold + housetotal + vendortotal) + "</TD>"); op.WriteLine("<TD>" + backpackgold + "</TD>"); op.WriteLine("<TD>" + bankgold + "</TD>"); op.WriteLine("<TD>" + housetotal + "</TD>"); op.WriteLine("<TD>" + list.Count + "</TD>"); op.WriteLine("<TD>" + vendortotal + " (" + vendors.Count + " vendors)" + "</TD>"); op.WriteLine("</TR>"); } } } op.WriteLine("</BODY></HTML>"); op.Flush(); op.Close(); } #else Hashtable table = new Hashtable(Accounts.Table.Values.Count); System.Console.WriteLine("GT: building hashtable"); SM(cmdmob, "GT: building hashtable"); foreach (Account acct in Accounts.Table.Values) { if (acct == null) { continue; } if ((bSupressStaff && acct.GetAccessLevel() > AccessLevel.Player) == false) { table.Add(acct, new GoldTotaller()); } } System.Console.WriteLine("GT: looping through accounts"); SM(cmdmob, "GT: looping through accounts"); foreach (Account acct in Accounts.Table.Values) { if (acct == null) { continue; } if ((bSupressStaff && acct.GetAccessLevel() > AccessLevel.Player) == false) { //iterate through characters: for (int i = 0; i < 5; ++i) { if (acct[i] != null) { PlayerMobile player = (PlayerMobile)acct[i]; Container backpack = player.Backpack; BankBox bank = player.BankBox; int backpackgold = 0; int bankgold = 0; int housedeedcount = 0; int housedeedworth = 0; int housesworth = 0; //BACKPACK backpackgold = GetGoldInContainer(backpack); housedeedworth = GetHouseDeedsInContainer(backpack, ref housedeedcount); //BANK bankgold = GetGoldInContainer(bank); housedeedworth += GetHouseDeedsInContainer(bank, ref housedeedcount); //house? int housetotal = 0; ArrayList list = Multis.BaseHouse.GetHouses(player); for (int j = 0; j < list.Count; ++j) { if (list[j] is BaseHouse) { BaseHouse house = (BaseHouse)list[j]; housesworth += (int)house.UpgradeCosts; HouseDeed hd = house.GetDeed(); if (hd != null && hd is SiegeTentBag == false && hd is TentBag == false) { housesworth += RealEstateBroker.ComputePriceFor(hd); hd.Delete(); } housetotal += GetGoldInHouse(house); housedeedworth += GetHouseDeedWorthInHouse(house, ref housedeedcount); } } ((GoldTotaller)table[acct]).BackpackGold += backpackgold; ((GoldTotaller)table[acct]).BankGold += bankgold; ((GoldTotaller)table[acct]).HouseGold += housetotal; ((GoldTotaller)table[acct]).HouseCount += list.Count; ((GoldTotaller)table[acct]).CharacterCount += 1; ((GoldTotaller)table[acct]).HouseDeedCount += housedeedcount; ((GoldTotaller)table[acct]).HouseDeedWorth += housedeedworth; ((GoldTotaller)table[acct]).HousesWorth += housesworth; } } } } System.Console.WriteLine("GT: Searching mobiles for PlayerVendors"); SM(cmdmob, "GT: Searching mobiles for PlayerVendors"); foreach (Mobile wm in World.Mobiles.Values) { if (wm == null) { continue; } if (wm is PlayerVendor) { PlayerVendor pv = wm as PlayerVendor; if (pv != null && pv.Owner != null) { Account thisacct = pv.Owner.Account as Account; if (thisacct != null) { if ((bSupressStaff && thisacct.GetAccessLevel() > AccessLevel.Player) == false) { ((GoldTotaller)table[thisacct]).VendorCount += 1; ((GoldTotaller)table[thisacct]).VendorGold += pv.HoldGold; } } } } } System.Console.WriteLine("GT: sorting"); SM(cmdmob, "GT: sorting"); ArrayList keys = new ArrayList(table.Keys); keys.Sort(new GTComparer(table)); System.Console.WriteLine("GT: Outputting html"); SM(cmdmob, "GT: Outputting html"); using (StreamWriter op = new StreamWriter(OUTPUT_DIRECTORY + "/" + OUTPUT_FILE)) { op.WriteLine("<HTML><BODY>"); op.WriteLine("<TABLE BORDER=1 WIDTH=90%><TR>"); if (bSupressNames) { op.WriteLine("<TD>=(char count)</TD>"); } else { op.WriteLine("<TD>Account (char count)</TD>"); } op.WriteLine("<TD>Total Worth</TD>"); op.WriteLine("<TD>Backpack Gold</TD>"); op.WriteLine("<TD>Bank Gold</TD>"); op.WriteLine("<TD>House Gold (house count)</TD>"); op.WriteLine("<TD>Vendor Gold (vendor count)</TD>"); op.WriteLine("<TD>Returnable Deed Worth (deed count)<br>(Included house and storage upgrade deeds</TD>"); op.WriteLine("<TD>House(s) Worth</TD>"); op.WriteLine("</TR>"); for (int i = 0; i < keys.Count && i < maxtoprint; i++) { GoldTotaller gt = table[keys[i]] as GoldTotaller; if (gt != null) { string bannedstr = ""; if (bIndicateBanned) { if (((Account)keys[i]).Banned) { bannedstr = " **banned** "; } } //System.Console.WriteLine( "Acct: {0}, total: {1}", ((Account)keys[i]).Username, gt.TotalGold ); if (bSupressNames) { op.WriteLine("<TR><TD>(" + gt.CharacterCount + ")" + bannedstr + "</TD>"); //Account } else { op.WriteLine("<TR><TD><B>" + ((Account)keys[i]).Username + "</B>(" + gt.CharacterCount + ")" + bannedstr + "</TD>"); //Account } op.WriteLine("<TD>" + gt.TotalGold + "</TD>"); //Total Worth op.WriteLine("<TD>" + gt.BackpackGold + "</TD>"); //Backpack op.WriteLine("<TD>" + gt.BankGold + "</TD>"); //bank op.WriteLine("<TD>" + gt.HouseGold + " (" + gt.HouseCount + ")</TD>"); //houses op.WriteLine("<TD>" + gt.VendorGold + " (" + gt.VendorCount + ")</TD>"); //vendors op.WriteLine("<TD>" + gt.HouseDeedWorth + " (" + gt.HouseDeedCount + ")</TD>"); //housedeeds op.WriteLine("<TD>" + gt.HousesWorth + "</TD>"); //housedeeds op.WriteLine("</TR>"); } } op.WriteLine("</TABLE></BODY></HTML>"); op.Flush(); op.Close(); } #endif } catch (Exception e) { LogHelper.LogException(e); System.Console.WriteLine("Error in GoldTracker: " + e.Message); System.Console.WriteLine(e.StackTrace); } finally { DateTime endDateTime = DateTime.Now; TimeSpan time = endDateTime - startDateTime; string endmsg = "finished in " + ((double)time.TotalMilliseconds / (double)1000) + " seconds."; System.Console.WriteLine(endmsg); SM(cmdmob, endmsg); bInProcess = false; } }