Пример #1
0
        private static void OrganizeMe_OnCommand(CommandEventArgs arg)
        {
            Mobile   from = arg.Mobile;
            Backpack bp   = from.Backpack as Backpack;

            if (@from == null || bp == null)
            {
                return;
            }

            var backpackitems     = new List <Item>(bp.Items);
            var subcontaineritems = new List <Item>();
            var oldpouches        = new List <OrganizePouch>();

            foreach (BaseContainer item in backpackitems.OfType <BaseContainer>())
            {
                subcontaineritems.AddRange(item.Items);
            }

            backpackitems.AddRange(subcontaineritems);

            OrganizePouch weaponpouch = new OrganizePouch {
                Name = "Weapons", Hue = Utility.RandomMetalHue()
            };
            OrganizePouch armorpouch = new OrganizePouch {
                Name = "Armor", Hue = Utility.RandomMetalHue()
            };
            OrganizePouch clothingpouch = new OrganizePouch {
                Name = "Clothing", Hue = Utility.RandomBrightHue()
            };
            OrganizePouch jewelpouch = new OrganizePouch {
                Name = "Jewelry", Hue = Utility.RandomPinkHue()
            };
            OrganizePouch potionpouch = new OrganizePouch {
                Name = "Potions", Hue = Utility.RandomOrangeHue()
            };
            OrganizePouch currencypouch = new OrganizePouch {
                Name = "Currency", Hue = Utility.RandomYellowHue()
            };
            OrganizePouch resourcepouch = new OrganizePouch {
                Name = "Resources", Hue = Utility.RandomNondyedHue()
            };
            OrganizePouch toolpouch = new OrganizePouch {
                Name = "Tools", Hue = Utility.RandomMetalHue()
            };
            OrganizePouch regspouch = new OrganizePouch {
                Name = "Reagents", Hue = Utility.RandomGreenHue()
            };
            OrganizePouch miscpouch = new OrganizePouch {
                Name = "Misc"
            };

            var pouches = new List <OrganizePouch>
            {
                weaponpouch,
                armorpouch,
                clothingpouch,
                jewelpouch,
                potionpouch,
                currencypouch,
                resourcepouch,
                toolpouch,
                regspouch,
                miscpouch
            };

            foreach (
                Item item in
                backpackitems.Where(
                    item =>
                    item.LootType != LootType.Blessed && !item.Insured && !(item is Runebook) &&
                    !(item is Spellbook) && item.Movable))
            {
                if (item is BaseWeapon)
                {
                    weaponpouch.DropItem(item);
                }
                else if (item is BaseArmor)
                {
                    armorpouch.DropItem(item);
                }
                else if (item is BaseClothing)
                {
                    clothingpouch.DropItem(item);
                }
                else if (item is BaseJewel)
                {
                    jewelpouch.DropItem(item);
                }
                else if (item is BasePotion)
                {
                    potionpouch.DropItem(item);
                }
                else if (item is Gold || item is Silver)
                {
                    currencypouch.DropItem(item);
                }
                else if (item is BaseIngot || item is BaseOre || item is Feather || item is BaseBoard || item is Log || item is BaseLeather ||
                         item is Sand || item is BaseGranite)
                {
                    resourcepouch.DropItem(item);
                }
                else if (item is BaseTool)
                {
                    toolpouch.DropItem(item);
                }
                else if (item is BaseReagent)
                {
                    regspouch.DropItem(item);
                }
                else if (item is OrganizePouch)
                {
                    oldpouches.Add((OrganizePouch)item);
                }
                else
                {
                    miscpouch.DropItem(item);
                }
            }

            int x = 45;

            foreach (OrganizePouch pouch in pouches)
            {
                from.AddToBackpack(pouch);
                pouch.X = x;
                pouch.Y = 65;

                x += 10;
            }

            var todelete =
                @from.Backpack.Items.OfType <OrganizePouch>()
                .Select(item => item)
                .Where(emptypouch => emptypouch.Items.Count <= 0)
                .ToList();

            foreach (OrganizePouch oldpouch in oldpouches)
            {
                oldpouch.Delete();
            }

            foreach (OrganizePouch packtodelete in todelete)
            {
                packtodelete.Delete();
            }
        }
Пример #2
0
        private static void OrganizeMe_OnCommand(CommandEventArgs arg)
        {
            Console.WriteLine("---------------- OrganizeMe -------------------");

            OrganizePouch weaponPouch   = null;
            OrganizePouch armorPouch    = null;
            OrganizePouch clothingPouch = null;
            OrganizePouch jewelPouch    = null;
            OrganizePouch potionPouch   = null;
            OrganizePouch currencyPouch = null;
            OrganizePouch resourcePouch = null;
            OrganizePouch toolPouch     = null;
            OrganizePouch regsPouch     = null;
            OrganizePouch miscPouch     = null;

            Mobile from = arg.Mobile;
            var    bp   = from.Backpack as Backpack;

            if (@from == null || bp == null)
            {
                return;
            }

            if (bp.TotalWeight >= bp.MaxWeight && from.AccessLevel < AccessLevel.GameMaster)
            {
                if (from is PlayerMobile && from.NetState != null)
                {
                    from.SendMessage("You have too much weight in your pack to use the organizer.");
                }
                return;
            }

            if (bp.TotalItems >= (bp.MaxItems - 10) && from.AccessLevel < AccessLevel.GameMaster)
            {
                if (from is PlayerMobile && from.NetState != null)
                {
                    from.SendMessage("You do not have enough room in your pack to use the organizer.");
                }
                return;
            }

            var backpackitems     = new List <Item>(bp.Items);
            var subcontaineritems = new List <Item>();

            foreach (var item in backpackitems.OfType <BaseContainer>())
            {
                var lockable = item as LockableContainer;
                if (lockable != null)
                {
                    if (lockable.CheckLocked(from))
                    {
                        continue;
                    }
                }

                var trapped = item as TrapableContainer;
                if (trapped != null)
                {
                    if (trapped.TrapType != TrapType.None)
                    {
                        continue;
                    }
                }

                // Skip the pouches that are already created
                if (item is OrganizePouch)
                {
                    if (item.Name == "Weapons")
                    {
                        weaponPouch = item as OrganizePouch;
                    }
                    if (item.Name == "Armor")
                    {
                        armorPouch = item as OrganizePouch;
                    }
                    if (item.Name == "Clothing")
                    {
                        clothingPouch = item as OrganizePouch;
                    }
                    if (item.Name == "Jewelry")
                    {
                        jewelPouch = item as OrganizePouch;
                    }
                    if (item.Name == "Potions")
                    {
                        potionPouch = item as OrganizePouch;
                    }
                    if (item.Name == "Currency")
                    {
                        currencyPouch = item as OrganizePouch;
                    }
                    if (item.Name == "Resources")
                    {
                        resourcePouch = item as OrganizePouch;
                    }
                    if (item.Name == "Tools")
                    {
                        toolPouch = item as OrganizePouch;
                    }
                    if (item.Name == "Reagents")
                    {
                        regsPouch = item as OrganizePouch;
                    }
                    if (item.Name == "Misc")
                    {
                        miscPouch = item as OrganizePouch;
                    }

                    // Skip all the items in the pouches since they should already be organized
                    continue;
                }

                // Add all the subcontainer items, but dont go all the way to comeplete depth
                subcontaineritems.AddRange(item.Items);
            }

            backpackitems.AddRange(subcontaineritems);

            if (weaponPouch == null)
            {
                weaponPouch = new OrganizePouch {
                    Name = "Weapons", Hue = Utility.RandomMetalHue()
                };
            }
            if (armorPouch == null)
            {
                armorPouch = new OrganizePouch {
                    Name = "Armor", Hue = Utility.RandomMetalHue()
                };
            }
            if (clothingPouch == null)
            {
                clothingPouch = new OrganizePouch {
                    Name = "Clothing", Hue = Utility.RandomBrightHue()
                };
            }
            if (jewelPouch == null)
            {
                jewelPouch = new OrganizePouch {
                    Name = "Jewelry", Hue = Utility.RandomPinkHue()
                };
            }
            if (potionPouch == null)
            {
                potionPouch = new OrganizePouch {
                    Name = "Potions", Hue = Utility.RandomOrangeHue()
                };
            }
            if (currencyPouch == null)
            {
                currencyPouch = new OrganizePouch {
                    Name = "Currency", Hue = Utility.RandomYellowHue()
                };
            }
            if (resourcePouch == null)
            {
                resourcePouch = new OrganizePouch {
                    Name = "Resources", Hue = Utility.RandomNondyedHue()
                };
            }
            if (toolPouch == null)
            {
                toolPouch = new OrganizePouch {
                    Name = "Tools", Hue = Utility.RandomMetalHue()
                };
            }
            if (regsPouch == null)
            {
                regsPouch = new OrganizePouch {
                    Name = "Reagents", Hue = Utility.RandomGreenHue()
                };
            }
            if (miscPouch == null)
            {
                miscPouch = new OrganizePouch {
                    Name = "Misc"
                };
            }
            var pouches = new List <OrganizePouch>
            {
                weaponPouch,
                armorPouch,
                clothingPouch,
                jewelPouch,
                potionPouch,
                currencyPouch,
                resourcePouch,
                toolPouch,
                regsPouch,
                miscPouch
            };

            foreach (
                Item item in
                backpackitems.Where(
                    item =>
                    item.LootType != LootType.Blessed &&
                    !(item is Runebook) &&
                    !(item is Spellbook) &&
                    item.Movable &&
                    item.LootType != LootType.Newbied))
            {
                // Lets not add the pouches to themselves
                if (item is OrganizePouch)
                {
                    continue;
                }

                if (item is BaseWeapon)
                {
                    weaponPouch.TryDropItem(from, item, false);
                }
                else if (item is BaseArmor)
                {
                    armorPouch.TryDropItem(from, item, false);
                }
                else if (item is BaseClothing)
                {
                    clothingPouch.TryDropItem(from, item, false);
                }
                else if (item is BaseJewel)
                {
                    jewelPouch.TryDropItem(from, item, false);
                }
                else if (item is BasePotion)
                {
                    potionPouch.TryDropItem(from, item, false);
                }
                else if (item is Gold || item is Silver)
                {
                    currencyPouch.TryDropItem(from, item, false);
                }
                else if (item is BaseIngot || item is BaseOre || item is Feather || item is BaseBoard || item is Log ||
                         item is BaseLeather ||
                         item is Sand || item is BaseGranite)
                {
                    resourcePouch.TryDropItem(from, item, false);
                }
                else if (item is BaseTool)
                {
                    toolPouch.TryDropItem(from, item, false);
                }
                else if (item is BaseReagent)
                {
                    regsPouch.TryDropItem(from, item, false);
                }
                else
                {
                    miscPouch.TryDropItem(from, item, false);
                }
            }

            var x = 45;

            foreach (var pouch in pouches)
            {
                if (pouch.TotalItems <= 0)
                {
                    continue;
                }

                // AddToBackpack doesnt do anything if the item is already in the backpack
                // calls DropItem internally

                if (!from.Backpack.Items.Contains(pouch))
                {
                    from.AddToBackpack(pouch);
                }

                pouch.X = x;
                pouch.Y = 65;

                x += 10;
            }
        }