Example #1
0
        private static void EventSink_Login(LoginEventArgs args)
        {
            Mobile from = args.Mobile;

            if (from.Backpack != null)
            {
                Item[] plants = from.Backpack.FindItemsByType(typeof(PlantItem));

                foreach (PlantItem plant in plants)
                {
                    if (plant.IsGrowable)
                    {
                        plant.PlantSystem.DoGrowthCheck();
                    }
                }
            }

            BankBox bank = from.FindBankNoCreate();

            if (bank != null)
            {
                Item[] plants = bank.FindItemsByType(typeof(PlantItem));

                foreach (PlantItem plant in plants)
                {
                    if (plant.IsGrowable)
                    {
                        plant.PlantSystem.DoGrowthCheck();
                    }
                }
            }

            //Taran: Check for plants in houses the character owns
            ArrayList houses = new ArrayList(2);

            houses.AddRange(BaseHouse.GetHouses(from));

            for (int i = 0; i < houses.Count; ++i)
            {
                BaseHouse house = (BaseHouse)houses[i];

                foreach (IEntity entity in house.GetHouseEntities())
                {
                    if (entity is Item && !((Item)entity).Deleted)
                    {
                        Item item = (Item)entity;
                        if (item is PlantItem && item.IsLockedDown)
                        {
                            PlantItem plant = (PlantItem)entity;
                            if (plant.IsGrowable)
                            {
                                plant.PlantSystem.DoGrowthCheck();
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        public static void PlayerWealth_OnCommand(CommandEventArgs e)
        {
            string             filename      = "playerwealth.html";
            List <AccountInfo> AccountWealth = new List <AccountInfo>();
            AccountInfo        A;

            A.GrandTotal = 0;
            WealthInfo backpack;
            WealthInfo bank;
            WealthInfo home;
            Mobile     m = null;

            if (e != null)
            {
                m = e.Mobile;
            }
            long   shardtotal          = 0;
            long   totalnotreportedamt = 0;
            uint   totalhomes          = 0;
            uint   totalnotreported    = 0;
            uint   totalaccounts       = 0;
            uint   totalchars          = 0;
            uint   totalvendors        = 0;
            double percent             = 0;

            foreach (Account a in Accounts.GetAccounts())
            {
                if (a != null && a.Username != null && a.AccessLevel == AccessLevel.Player)
                {
                    totalaccounts++;
                    A.acct               = a;
                    A.wealth.TotalGold   = 0;
                    A.wealth.TotalChecks = 0;
                    A.wealth.VendorGold  = 0;
                    backpack.TotalGold   = 0;
                    backpack.TotalChecks = 0;
                    bank.TotalGold       = 0;
                    bank.TotalChecks     = 0;
                    home.TotalGold       = 0;
                    home.TotalChecks     = 0;
                    home.VendorGold      = 0;
                    int money = 0;
                    for (int i = 0; i < a.Length; i++) // First record gold in player's bank/backpack
                    {
                        Mobile cm = a[i];

                        if (cm == null)
                        {
                            continue;
                        }
                        totalchars++;
                        if (cm.Backpack != null)
                        {
                            backpack = SearchContainer(cm.Backpack);
                        }
                        if (cm.BankBox != null)
                        {
                            bank = SearchContainer(cm.BankBox);
                        }
                        A.wealth.TotalGold   += backpack.TotalGold;
                        A.wealth.TotalChecks += backpack.TotalChecks;
                        A.wealth.TotalGold   += bank.TotalGold;
                        A.wealth.TotalChecks += bank.TotalChecks;

                        List <PlayerVendor> vendors = new List <PlayerVendor>();

                        foreach (Mobile mob in World.Mobiles.Values)
                        {
                            if (mob is PlayerVendor)
                            {
                                vendors.Add(mob as PlayerVendor);
                            }
                        }

                        for (int j = 0; j < vendors.Count; ++j)
                        {
                            if (vendors[j].Owner == cm)
                            {
                                money += vendors[j].HoldGold;
                                totalvendors++;
                            }
                        }
                    }
                    ArrayList allHouses = new ArrayList(2);
                    for (int i = 0; i < a.Length; ++i) // Now houses they own
                    {
                        Mobile mob = a[i];

                        if (mob != null)
                        {
                            allHouses.AddRange(BaseHouse.GetHouses(mob));
                        }
                    }
                    for (int i = 0; i < allHouses.Count; ++i)
                    {
                        BaseHouse house = (BaseHouse)allHouses[i];

                        totalhomes++;
                        foreach (IEntity entity in house.GetHouseEntities())
                        {
                            if (entity is Item && !((Item)entity).Deleted)
                            {
                                Item item = (Item)entity;
                                if (item is Gold)
                                {
                                    home.TotalGold += item.Amount;
                                }
                                else if (item is BankCheck)
                                {
                                    home.TotalChecks += ((BankCheck)item).Worth;
                                }
                                else if (item is Container)
                                {
                                    home = SearchContainer((Container)item, home);
                                }
                            }

                            /*else  // Vendors gold belongs to???? Let's skip this...
                             *                          {
                             *                          } */
                        }
                    }
                    A.wealth.TotalGold   += home.TotalGold;
                    A.wealth.TotalChecks += home.TotalChecks;
                    A.wealth.VendorGold  += money;
                    A.GrandTotal          = A.wealth.TotalGold + A.wealth.TotalChecks + A.wealth.VendorGold;
                    shardtotal           += A.GrandTotal;
                    if (A.GrandTotal < 10000)
                    {
                        totalnotreportedamt += A.GrandTotal;
                        totalnotreported++;
                    }
                    else
                    {
                        AccountWealth.Add(A);
                    }
                }
            }
            //AccountWealth.Sort(new SortArray());
            AccountWealth.Sort(delegate(AccountInfo a1, AccountInfo a2) { return(a2.GrandTotal.CompareTo(a1.GrandTotal)); });
            using (StreamWriter op = new StreamWriter(filename))
            {
                op.WriteLine("<html><body><strong>Player Wealth report generated on {0}</strong>", DateTime.Now);
                op.WriteLine("<br/><strong>Total Accounts: {0}</strong>", totalaccounts);
                op.WriteLine("<br/><strong>Total Characters: {0}</strong>", totalchars);
                op.WriteLine("<br/><strong>Total Houses: {0}</strong>", totalhomes);
                op.WriteLine("<br/><strong>Total Vendors: {0}</strong>", totalvendors);
                op.WriteLine("<br/><strong>Total Gold/Checks/Vendors: {0}</strong>", shardtotal.ToString("#,##0", new CultureInfo("en-US")));
                op.WriteLine("<br/><br/>");
                op.WriteLine("<table width=\"500\"  border=\"2\" bordercolor=\"#FFFFFF\" bgcolor=\"#DEB887\"<td colspan=\"5\"><div align=\"left\"><font color=\"#8B0000\" size=\"+2\"><strong>Player Wealth</strong></font></div></td>");
                op.WriteLine("<tr bgcolor=\"#667C3F\"><font color=\"#FFFFFF\" size=\"+1\"><td align=\"center\">Account</td><td width=\"100\" align=\"right\">Gold</td><td width=\"100\" align=\"right\">Checks</td><td width=\"100\" align=\"right\">Vendor(s)</td><td width=\"100\" align=\"right\">Total</td><td width=\"100\" align=\"right\">% of shard</td></tr></font>");
                int count = 0;
                foreach (AccountInfo ai in AccountWealth)
                {
                    count++;
                    percent = ai.GrandTotal / (double)shardtotal * 100.00f;
                    op.WriteLine("<tr bgcolor=\"#{6}\"><td align=\"left\"><pre>{7,-3} {0}</pre></td><td align=\"Right\">{1}</td><td align=\"Right\">{2}</td><td align=\"Right\">{3}</td><td align=\"Right\">{4}</td><td align=\"Right\">{5: ##0.00}%</td></tr></div>", ai.acct.Username, ai.wealth.TotalGold.ToString("#,##0", new CultureInfo("en-US")), ai.wealth.TotalChecks.ToString("#,##0", new CultureInfo("en-US")), ai.wealth.VendorGold.ToString("#,##0", new CultureInfo("en-US")), ai.GrandTotal.ToString("#,##0", new CultureInfo("en-US")), percent, percent > 0.70 ? (percent > 3.5 ? "DC143C" : (percent > 1.0 ? "B22222" : "F08080")) : (percent < 0.25 ? (percent < 0.01 ? "7FFFD4" : "90EE90") : "F0E68C"), count > 50 ? "   " : count + ".");
                }
                percent = totalnotreportedamt / (double)shardtotal * 100.00f;
                op.WriteLine("<tr bgcolor=\"#D3D3D3\"><td align=\"center\" colspan=\"3\">{0} accounts < 10000 not reported.</td><td align=\"Right\">{1: ##,###,###,##0}</td><td align=\"Right\">{2: ##0.00}%</td></tr>", totalnotreported, totalnotreportedamt, percent);
                op.WriteLine("</table></body></html>");
            }
            if (m != null)
            {
                m.SendMessage("Total accounts processed: {0}", totalaccounts);
            }
            else
            {
                Console.WriteLine("Player wealth report generated. Total accounts: {0}", totalaccounts);
            }
        }
Example #3
0
        public static void PlayerWealth_OnCommand(CommandEventArgs e)
        {
            string      filename      = "playerwealth.html";
            ArrayList   AccountWealth = new ArrayList();
            AccountInfo A;

            A.GrandTotal = 0;
            WealthInfo backpack;
            WealthInfo bank;
            WealthInfo home;
            Mobile     m                   = e.Mobile;
            long       shardtotal          = 0;
            long       totalnotreportedamt = 0;
            uint       totalhomes          = 0;
            uint       totalnotreported    = 0;
            uint       totalaccounts       = 0;
            uint       totalchars          = 0;
            double     percent             = 0;

            foreach (Account a in Accounts.GetAccounts())
            {
                if (a != null && a.Username != null)
                {
                    totalaccounts++;
                    A.acct               = a;
                    A.wealth.TotalGold   = 0;
                    A.wealth.TotalChecks = 0;
                    backpack.TotalGold   = 0;
                    backpack.TotalChecks = 0;
                    bank.TotalGold       = 0;
                    bank.TotalChecks     = 0;
                    home.TotalGold       = 0;
                    home.TotalChecks     = 0;
                    for (int i = 0; i < a.Length; i++)                     // First record gold in player's bank/backpack
                    {
                        Mobile cm = a[i];

                        if (cm == null)
                        {
                            continue;
                        }
                        totalchars++;
                        if (cm.Backpack != null)
                        {
                            backpack = SearchContainer(cm.Backpack);
                        }
                        if (cm.BankBox != null)
                        {
                            bank = SearchContainer(cm.BankBox);
                        }
                        A.wealth.TotalGold   += backpack.TotalGold;
                        A.wealth.TotalChecks += backpack.TotalChecks;
                        A.wealth.TotalGold   += bank.TotalGold;
                        A.wealth.TotalChecks += bank.TotalChecks;
                    }
                    List <BaseHouse> allHouses = new List <BaseHouse>(2);
                    for (int i = 0; i < a.Length; ++i)                     // Now houses they own
                    {
                        Mobile mob = a[i];

                        if (mob != null)
                        {
                            allHouses.AddRange(BaseHouse.GetHouses(mob));
                        }
                    }
                    for (int i = 0; i < allHouses.Count; ++i)
                    {
                        BaseHouse house = allHouses[i];

                        totalhomes++;
                        foreach (IEntity entity in house.GetHouseEntities())
                        {
                            if (entity is Item && !((Item)entity).Deleted)
                            {
                                Item item = (Item)entity;
                                if (item is Gold)
                                {
                                    home.TotalGold += item.Amount;
                                }
                                else if (item is BankCheck)
                                {
                                    home.TotalChecks += ((BankCheck)item).Worth;
                                }
                                else if (item is Container)
                                {
                                    home = SearchContainer((Container)item, home);
                                }
                            }

                            /*else  // Vendors gold belongs to???? Let's skip this...
                             * {
                             * } */
                        }
                    }
                    A.wealth.TotalGold   += home.TotalGold;
                    A.wealth.TotalChecks += home.TotalChecks;
                    A.GrandTotal          = A.wealth.TotalGold + A.wealth.TotalChecks;
                    shardtotal           += A.GrandTotal;
                    if (A.GrandTotal < 10000)
                    {
                        totalnotreportedamt += A.GrandTotal;
                        totalnotreported++;
                    }
                    else
                    {
                        AccountWealth.Add(A);
                    }
                }
            }
            AccountWealth.Sort(new SortArray());
            using (StreamWriter op = new StreamWriter(filename))
            {
                op.WriteLine("<html><body><strong>Player Wealth report generated on {0}</strong>", DateTime.Now);
                op.WriteLine("<br/><strong>Total Accounts: {0}</strong>", totalaccounts);
                op.WriteLine("<br/><strong>Total Characters: {0}</strong>", totalchars);
                op.WriteLine("<br/><strong>Total Houses: {0}</strong>", totalhomes);
                op.WriteLine("<br/><strong>Total Gold/Checks: {0: ##,###,###,###}</strong>", shardtotal);
                op.WriteLine("<br/><br/>");
                op.WriteLine("<table width=\"500\"  border=\"2\" bordercolor=\"#FFFFFF\" bgcolor=\"#DEB887\"<td colspan=\"5\"><div align=\"center\"><font color=\"#8B0000\" size=\"+2\"><strong>Player Wealth</strong></font></div></td>");
                op.WriteLine("<tr bgcolor=\"#667C3F\"><font color=\"#FFFFFF\" size=\"+1\"><td align=\"center\">Account</td><td width=\"100\" align=\"right\">Gold</td><td width=\"100\" align=\"right\">Checks</td><td width=\"100\" align=\"right\">Total</td><td width=\"100\" align=\"right\">% of shard</td></tr></font>");
                foreach (AccountInfo ai in AccountWealth)
                {
                    percent = (double)ai.GrandTotal / (double)shardtotal * 100.00f;
                    op.WriteLine("<tr bgcolor=\"#{5}\"><td align=\"center\">{0}</td><td align=\"Right\">{1: ##,###,###,##0}</td><td align=\"Right\">{2: ##,###,###,##0}</td><td align=\"Right\">{3: ##,###,###,##0}</td><td align=\"Right\">{4: ##0.00}%</td></tr></div>", ai.acct.Username, ai.wealth.TotalGold, ai.wealth.TotalChecks, ai.GrandTotal, percent, percent > 0.70 ? (percent > 3.5 ? "DC143C" : (percent > 1.0 ? "B22222" : "F08080")) : (percent < 0.25 ? (percent < 0.01 ? "7FFFD4" : "90EE90") : "F0E68C"));
                }
                percent = (double)totalnotreportedamt / (double)shardtotal * 100.00f;
                op.WriteLine("<tr bgcolor=\"#D3D3D3\"><td align=\"center\" colspan=\"3\">{0} accounts < 10000 not reported.</td><td align=\"Right\">{1: ##,###,###,##0}</td><td align=\"Right\">{2: ##0.00}%</td></tr>", totalnotreported, totalnotreportedamt, percent);
                op.WriteLine("</table></body></html>");
            }
            m.SendMessage("Total accounts processed: {0}", totalaccounts);
        }
Example #4
0
        public static void Run()
        {
            List <Item>   items        = new List <Item>();
            List <Item>   validItems   = new List <Item>();
            List <Mobile> hairCleanup  = new List <Mobile>();
            List <Mobile> mobiles      = new List <Mobile>();
            List <Mobile> validMobiles = new List <Mobile>();

            List <Mobile> orphans = new List <Mobile>();
            int           stabled = 0;

            foreach (Mobile m in World.Mobiles.Values)
            {
                if (m is PlayerMobile)
                {
                    PlayerMobile pm = (PlayerMobile)m;
                    if (pm.Account == null)
                    {
                        orphans.Add(m);
                    }
                    else if (!Ethic.Enabled && pm.EthicPlayer != null)
                    {
                        pm.EthicPlayer.Detach();
                    }
                }
                else
                {
                    BaseCreature pet = m as BaseCreature;
                    if (pet != null && pet.Controlled && !pet.Summoned && pet.ControlMaster != null && !pet.Blessed && pet.ControlMaster.Player && !pet.IsStabled && pet.Map != Map.Internal)
                    {
                        if (pet.IsDeadPet)
                        {
                            pet.Resurrect();
                        }

                        PlayerMobile master = pet.ControlMaster as PlayerMobile;

                        if (master != null)
                        {
                            master.StablePet(pet, true, true);
                            stabled++;
                        }
                    }
                    else                     //Invalid Internalized Mobiles
                    {
                        if (pet != null && (pet.IsStabled || (pet is BaseMount && ((BaseMount)pet).Rider != null)))
                        {
                            continue;
                        }

                        if (m.Spawner != null || m.Blessed)
                        {
                            continue;
                        }

                        if (m is PlayerMobile || m.Player || m is PlayerVendor || m is PlayerBarkeeper)
                        {
                            continue;
                        }

                        if (m.Map != null && m.Map != Map.Internal)
                        {
                            continue;
                        }

                        if (m.Location != Point3D.Zero)
                        {
                            continue;
                        }

                        mobiles.Add(m);
                    }
                }
            }

            int boxes         = 0;
            int emptyboxes    = 0;
            int spawners      = 0;
            int parents       = 0;
            int emptyspawners = 0;

            foreach (Item item in World.Items.Values)
            {
                if (item.Map == null)
                {
                    items.Add(item);
                    continue;
                }
                else if (item is Spawner)
                {
                    if (item.Map == Map.Internal && item.Parent == null)
                    {
                        spawners++;
                        continue;
                    }
                    else if (item.Parent == null && (((Spawner)item).Entries == null || ((Spawner)item).Entries.Count == 0))
                    {
                        items.Add(item);
                        //Console.WriteLine( "Cleanup: Detected invalid spawner {0} at ({1},{2},{3}) [{4}]", item.Serial, item.X, item.Y, item.Z, item.Map );
                        emptyspawners++;
                    }
                }
                else if (item is CommodityDeed)
                {
                    CommodityDeed deed = (CommodityDeed)item;

                    if (deed.CommodityItem != null)
                    {
                        validItems.Add(deed.CommodityItem);
                    }

                    continue;
                }
                else if (item is BaseHouse)
                {
                    BaseHouse house = (BaseHouse)item;

                    List <IEntity> entities = house.GetHouseEntities();

                    foreach (RelocatedEntity relEntity in house.RelocatedEntities)
                    {
                        if (relEntity.Entity is Item)
                        {
                            validItems.Add((Item)relEntity.Entity);
                        }
                    }

                    foreach (VendorInventory inventory in house.VendorInventories)
                    {
                        foreach (Item subItem in inventory.Items)
                        {
                            validItems.Add(subItem);
                        }
                    }
                }
                else if (item is BankBox)
                {
                    BankBox box   = (BankBox)item;
                    Mobile  owner = box.Owner;

                    if (owner == null)
                    {
                        items.Add(box);
                        ++boxes;
                    }
                    else if (box.Items.Count == 0)
                    {
                        items.Add(box);
                        ++emptyboxes;
                    }

                    continue;
                }
                else if ((item.Layer == Layer.Hair || item.Layer == Layer.FacialHair))
                {
                    object rootParent = item.RootParent;

                    if (rootParent is Mobile)
                    {
                        Mobile rootMobile = (Mobile)rootParent;
                        if (item.Parent != rootMobile /*&& rootMobile.AccessLevel == AccessLevel.Player*/)
                        {
                            items.Add(item);
                            continue;
                        }
                        else if (item.Parent == rootMobile)
                        {
                            hairCleanup.Add(rootMobile);
                            continue;
                        }
                    }
                }
                else if (item is Container)
                {
                    List <Item> contitems = item.AcquireItems();

                    for (int i = contitems.Count - 1; i >= 0; i--)
                    {
                        Item child = contitems[i];

                        if (child.Parent != item)
                        {
                            //if ( child is Spawner && child.Parent == null )
                            //	item.Items.RemoveAt( i-- );

                            Console.WriteLine("Cleanup: Detected orphan item {0} ({1}) of {2} ({3}) has parent of {4} ({5})", child.GetType().Name, child.Serial, item.GetType().Name, item.Serial, child.Parent == null ? "(-null-)" : child.Parent.GetType().Name, child.Parent is IEntity ? ((IEntity)child.Parent).Serial.ToString() : "N/A");

                            contitems.RemoveAt(i);                               //Clean this up

                            if (child.Parent is Item)
                            {
                                Item        parent      = (Item)child.Parent;
                                List <Item> parentitems = parent.AcquireItems();
                                parentitems.Add(child);
                            }
                            else if (child.Parent is Mobile)
                            {
                                Mobile parent = (Mobile)child.Parent;
                                parent.Items.Add(child);
                            }

                            parents++;
                        }
                    }
                }
                else if (item.RootParent is BaseTreasureChest)                   //Clear out all items in a treasure chest
                {
                    items.Add(item);
                    continue;
                }
                else if (item is CharacterStatueDeed)
                {
                    CharacterStatueDeed deed = item as CharacterStatueDeed;
                    if (deed.Statue != null)
                    {
                        validMobiles.Add(deed.Statue);
                        if (deed.Statue.Plinth != null)
                        {
                            validItems.Add(deed.Statue.Plinth);
                        }
                    }
                }
                else if (item is KeyRing)
                {
                    validItems.AddRange(((KeyRing)item).Keys);
                }

                if (item.Parent != null || (item.Map != null && item.Map != Map.Internal) || item.HeldBy != null)
                {
                    continue;
                }

                if (item.Location != Point3D.Zero)
                {
                    continue;
                }

                if (!IsBuggable(item))
                {
                    continue;
                }

                if (!item.Movable)
                {
                    continue;
                }

                items.Add(item);
            }

            for (int i = 0; i < validItems.Count; ++i)
            {
                items.Remove(validItems[i]);
            }

            for (int i = 0; i < validMobiles.Count; ++i)
            {
                mobiles.Remove(validMobiles[i]);
            }

            if (items.Count > 0)
            {
                String message = String.Format("Cleanup: Detected {0} inaccessible items, ", items.Count);

                if (boxes > 0)
                {
                    message += String.Format("including {0} bank box{1}, ", boxes, boxes != 1 ? "es" : String.Empty);
                }

                if (emptyboxes > 0)
                {
                    message += String.Format("{1}{0} empty bank box{2}, ", emptyboxes, boxes == 0 ? "including " : String.Empty, emptyboxes != 1 ? "es" : String.Empty);
                }

                if (emptyspawners > 0)
                {
                    message += String.Format("{1} {0} empty/invalid spawner{2}, ", emptyspawners, (emptyboxes == 0 && boxes == 0) ? "including " : String.Empty, emptyspawners != 1 ? "s" : String.Empty);
                }

                message += "removing..";

                Console.WriteLine(message);

                for (int i = 0; i < items.Count; ++i)
                {
                    //Console.WriteLine( "Item: {0} - {2} ({1})", items[i].Name, items[i].Serial, items[i].GetType() );
                    items[i].Delete();
                }
            }

            if (spawners > 0)
            {
                Console.WriteLine("Cleanup: Detected {0} inaccessible spawners..", spawners);
            }

            if (parents > 0)
            {
                Console.WriteLine("Cleanup: Detected {0} invalid parent-child items, fixing references..", parents);
            }

            if (hairCleanup.Count > 0)
            {
                Console.WriteLine("Cleanup: Detected {0} hair and facial hair items being worn, converting to virtual hair..", hairCleanup.Count);

                for (int i = 0; i < hairCleanup.Count; i++)
                {
                    hairCleanup[i].ConvertHair();
                }
            }

            if (orphans.Count > 0)
            {
                Console.WriteLine("Cleanup: Detected {0} orphaned players, removing..", orphans.Count);

                for (int i = 0; i < orphans.Count; ++i)
                {
                    orphans[i].Delete();
                }
            }

            if (stabled > 0)
            {
                Console.WriteLine("Cleanup: Detected {0} pets requiring stables..", stabled);
            }

            if (mobiles.Count > 0)
            {
                Console.WriteLine("Cleanup: Detected {0} invalid mobiles, removing...", mobiles.Count);
                for (int i = 0; i < mobiles.Count; ++i)
                {
                    mobiles[i].Delete();
                }
            }
        }