Пример #1
0
        public SeedInfoGump(PlayerMobile user, SeedBox box, SeedEntry entry, SeedBoxGump par) : base(user, parent: par)
        {
            Box   = box;
            Entry = entry;

            user.CloseGump(this.GetType());
        }
Пример #2
0
        private void CheckEntries()
        {
            List <Item> toDelete = new List <Item>(Items);

            for (var index = 0; index < toDelete.Count; index++)
            {
                Item item = toDelete[index];

                if (item != null && item.Amount == 0)
                {
                    item.Delete();
                }
            }

            List <SeedEntry> entries = new List <SeedEntry>(Entries);

            for (var index = 0; index < entries.Count; index++)
            {
                SeedEntry entry = entries[index];

                if (entry != null && (entry.Seed == null || entry.Seed.Amount == 0 || entry.Seed.Deleted))
                {
                    Entries.Remove(entry);
                }
            }

            ColUtility.Free(entries);
            ColUtility.Free(toDelete);
        }
Пример #3
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int v = reader.ReadInt();

            Entries = new List <SeedEntry>();

            IsRewardItem = reader.ReadBool();
            Level        = (SecureLevel)reader.ReadInt();

            int count = reader.ReadInt();

            for (int i = 0; i < count; i++)
            {
                switch (reader.ReadInt())
                {
                default:
                case 0:
                    Entries.Add(null);
                    break;

                case 1:
                    SeedEntry entry = new SeedEntry(reader);

                    if (entry.Seed != null)
                    {
                        Entries.Add(entry);
                    }
                    break;
                }
            }

            Timer.DelayCall(TimeSpan.FromSeconds(10), CheckEntries);
        }
Пример #4
0
        public override void OnResponse(RelayInfo info)
        {
            if (Box.Deleted)
            {
                return;
            }

            switch (info.ButtonID)
            {
            case 0: break;

            case 1:     // page back
                Page--;

                if (Page < 1)
                {
                    Page = 1;
                }

                Refresh();
                break;

            case 2:     // page forward
                Page++;

                if (Page > Pages)
                {
                    Page = Pages;
                }

                Refresh();
                break;

            default:

                if (Box.RootParent is PlayerVendor pv && !pv.IsOwner(User))
                {
                    User.SendLocalizedMessage(502402);     // That is inaccessible.
                    return;
                }

                int id = info.ButtonID - 100;

                if (id >= 0 && id < Box.Entries.Count)
                {
                    SeedEntry entry = Box.Entries[id];

                    if (entry == null)
                    {
                        return;
                    }

                    Refresh();
                    SendGump(new SeedInfoGump(User, Box, entry, this));
                }
                break;
            }
        }
Пример #5
0
        public override void OnResponse(RelayInfo info)
        {
            if (Box.Deleted)
            {
                return;
            }

            switch (info.ButtonID)
            {
            case 0: break;

            case 1:     // page back
                Page--;

                if (Page < 1)
                {
                    Page = 1;
                }

                Refresh();
                break;

            case 2:     // page forward
                Page++;

                if (Page > Pages)
                {
                    Page = Pages;
                }

                Refresh();
                break;

            default:
                int id = info.ButtonID - 100;

                if (id >= 0 && id < Box.Entries.Count)
                {
                    SeedEntry entry = Box.Entries[id];

                    if (entry == null)
                    {
                        return;
                    }

                    Refresh();
                    SendGump(new SeedInfoGump(User, Box, entry, this));
                }
                break;
            }
        }
Пример #6
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            reader.ReadInt();

            Entries = new List <SeedEntry>();

            IsRewardItem = reader.ReadBool();
            Level        = (SecureLevel)reader.ReadInt();

            int count = reader.ReadInt();

            for (int i = 0; i < count; i++)
            {
                switch (reader.ReadInt())
                {
                default:
                case 0:
                    Entries.Add(null);
                    break;

                case 1:
                    SeedEntry entry = new SeedEntry(reader);

                    if (entry.Seed != null)
                    {
                        Entries.Add(entry);
                    }
                    break;
                }
            }

            Timer.DelayCall(
                () =>
            {
                for (var index = 0; index < Items.Count; index++)
                {
                    Item item = Items[index];

                    if (item.Movable)
                    {
                        item.Movable = false;
                    }
                }
            });

            Timer.DelayCall(TimeSpan.FromSeconds(10), CheckEntries);
        }
Пример #7
0
        public void DropSeed(Mobile from, SeedEntry entry, int amount)
        {
            if (!from.InRange(GetWorldLocation(), 3))
            {
                return;
            }

            if (amount > entry.Seed.Amount)
            {
                amount = entry.Seed.Amount;
            }

            Seed seed;

            if (amount == entry.Seed.Amount)
            {
                seed       = entry.Seed;
                entry.Seed = null;
            }
            else
            {
                seed = new Seed(entry.Seed.PlantType, entry.Seed.PlantHue, true)
                {
                    Amount = amount
                };

                entry.Seed.Amount -= amount;
            }

            seed.Movable = true;

            if (from.Backpack == null || !from.Backpack.TryDropItem(from, seed, false))
            {
                seed.MoveToWorld(from.Location, from.Map);
                from.SendLocalizedMessage(1151844); // There is not enough room in your backpack!
            }

            if (entry.Seed != null && entry.Seed.Amount <= 0)
            {
                entry.Seed.Delete();
                entry.Seed = null;
            }

            if (entry.Seed == null || entry.Seed.Amount <= 0)
            {
                RemoveEntry(entry);
            }
        }
Пример #8
0
        private void RemoveEntry(SeedEntry entry)
        {
            Entries.Remove(entry);
            TrimEntries();

            if (Entries.Count == 0)
            {
                if (ItemID == 19289)
                {
                    ItemID = 19288;
                }
                else if (ItemID == 19291)
                {
                    ItemID = 19290;
                }
            }
        }
Пример #9
0
        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)1);

            writer.Write(IsRewardItem);
            writer.Write((int)Level);

            writer.Write(Entries.Count);
            for (int i = 0; i < Entries.Count; i++)
            {
                SeedEntry entry = Entries[i];

                if (entry == null)
                {
                    writer.Write(0);
                }
                else
                {
                    writer.Write(1);
                    entry.Serialize(writer);
                }
            }
        }
Пример #10
0
        private void AddEntry(SeedEntry entry, int index = -1)
        {
            if (index == -1)
            {
                TrimEntries();
                Entries.Add(entry);
            }
            else if (index >= 0 && index < Entries.Count)
            {
                Entries.Insert(index, entry);
            }

            if (Entries.Count > 0)
            {
                if (ItemID == 19288)
                {
                    ItemID = 19289;
                }
                else if (ItemID == 19290)
                {
                    ItemID = 19291;
                }
            }
        }
Пример #11
0
        public bool TryAddSeed(Mobile from, Seed seed, int index = -1)
        {
            if (!from.Backpack.CheckHold(from, seed, true, true) || seed.Amount <= 0)
            {
                return(false);
            }
            else if (!from.InRange(this.GetWorldLocation(), 3) || from.Map != this.Map)
            {
                return(false);
            }
            else if (TotalCount + seed.Amount <= MaxSeeds)
            {
                SeedEntry entry    = GetExisting(seed);
                int       oldcount = UniqueCount;

                if (entry != null)
                {
                    entry.Seed.Amount += seed.Amount;
                    seed.Delete();
                }
                else if (UniqueCount < MaxUnique)
                {
                    entry = new SeedEntry(seed);
                    DropItem(seed);

                    seed.Movable = false;
                }
                else
                {
                    from.SendLocalizedMessage(1151839); // There is not enough room in the box.
                }

                if (entry != null)
                {
                    if (Entries.Contains(entry))
                    {
                        if (index > -1 && index < Entries.Count - 1)
                        {
                            Entries.Remove(entry);
                            AddEntry(entry, index);
                        }
                    }
                    else
                    {
                        if (index > -1 && index < Entries.Count)
                        {
                            AddEntry(entry, index);
                        }
                        else
                        {
                            AddEntry(entry);
                        }
                    }

                    from.SendLocalizedMessage(1151846); // You put the seed in the seedbox.

                    if (from is PlayerMobile)
                    {
                        var gump = new SeedBoxGump((PlayerMobile)from, this);
                        gump.CheckPage(entry);

                        BaseGump.SendGump(gump);
                    }

                    InvalidateProperties();
                    return(true);
                }
            }
            else
            {
                from.SendLocalizedMessage(1151839); // There is not enough room in the box.
            }

            return(false);
        }
Пример #12
0
        public void CheckPage(SeedEntry entry)
        {
            int index = Box.Entries.IndexOf(entry);

            Page = (int)Math.Ceiling((double)(index + 1) / 20);
        }
Пример #13
0
        public override void AddGumpLayout()
        {
            AddPage(0);

            AddImage(30, 30, 2172);

            AddPage(1);

            int start = (Page - 1) * 20;
            int index = 0;

            for (int i = start; i < Box.Entries.Count && i < start + 20; i++)
            {
                SeedEntry entry = Box.Entries[i];

                if (entry == null || entry.Seed == null)
                {
                    index++;
                    continue;
                }

                int x; int y;

                if (index < 4)
                {
                    x = 46 + (index * 70);
                    y = 41;
                }
                else if (index < 8)
                {
                    x = 46 + ((index - 4) * 70);
                    y = 106;
                }
                else if (index < 12)
                {
                    x = 46 + ((index - 8) * 70);
                    y = 171;
                }
                else if (index < 16)
                {
                    x = 46 + ((index - 12) * 70);
                    y = 236;
                }
                else
                {
                    x = 46 + ((index - 16) * 70);
                    y = 301;
                }

                AddImageTiledButton(x, y, entry.Image, entry.Image, i + 100, GumpButtonType.Reply, 0, 0xDCF, entry.Seed.Hue, 3, 30);
                AddTooltip(entry.Seed.GetLabel(out string args), args);

                index++;
            }

            if (Pages > 1)
            {
                AddHtmlLocalized(136, 373, 100, 25, 1151850, string.Format("@{0}@{1}", Page.ToString(), Pages.ToString()), 0x6F7B, false, false);

                if (Page > 1)
                {
                    AddButton(66, 375, 5603, 5603, 1, GumpButtonType.Reply, 0);
                }

                if (Page < Pages)
                {
                    AddButton(276, 375, 5601, 5601, 2, GumpButtonType.Reply, 0);
                }
            }
        }
Пример #14
0
 public QuanitityRemovePrompt(SeedBox box, SeedEntry entry)
 {
     m_Box   = box;
     m_Entry = entry;
 }
Пример #15
0
        public bool TryAddSeed(Mobile from, Seed seed, int index = -1)
        {
            if (!CheckAccessible(from, this))
            {
                PrivateOverheadMessage(MessageType.Regular, 946, 1010563, from.NetState); // This container is secure.
                return(false);
            }

            if (!from.Backpack.CheckHold(from, seed, true, true) || seed.Amount <= 0)
            {
                return(false);
            }

            if (!from.InRange(GetWorldLocation(), 3) || from.Map != Map)
            {
                return(false);
            }

            if (TotalCount + seed.Amount <= MaxSeeds)
            {
                SeedEntry entry = GetExisting(seed);

                if (entry != null)
                {
                    entry.Seed.Amount += seed.Amount;
                    seed.Delete();
                }
                else if (UniqueCount < MaxUnique)
                {
                    entry = new SeedEntry(seed);
                    DropItem(seed);

                    seed.Movable = false;
                }
                else
                {
                    from.SendLocalizedMessage(1151839); // There is not enough room in the box.
                }

                if (entry != null)
                {
                    InvalidateProperties();

                    if (Entries.Contains(entry))
                    {
                        if (index > -1 && index < Entries.Count - 1)
                        {
                            Entries.Remove(entry);
                            AddEntry(entry, index);
                        }
                    }
                    else
                    {
                        if (index > -1 && index < Entries.Count)
                        {
                            AddEntry(entry, index);
                        }
                        else
                        {
                            AddEntry(entry);
                        }
                    }

                    from.SendLocalizedMessage(1151846); // You put the seed in the seedbox.

                    if (from is PlayerMobile mobile)
                    {
                        var gump = mobile.FindGump <SeedBoxGump>();

                        if (gump != null)
                        {
                            gump.CheckPage(entry);
                            gump.Refresh();
                        }
                        else
                        {
                            gump = new SeedBoxGump(mobile, this);
                            gump.CheckPage(entry);

                            BaseGump.SendGump(gump);
                        }
                    }

                    return(true);
                }
            }
            else
            {
                from.SendLocalizedMessage(1151839); // There is not enough room in the box.
            }

            return(false);
        }
Пример #16
0
        public override void AddGumpLayout()
        {
            AddImage(0, 0, 2172);

            int start = (Page - 1) * 20;
            int index = 0;

            AddHtmlLocalized(100, 345, 300, 20, 1151850, String.Format("{0}\t{1}", Page.ToString(), Pages.ToString()), 0xFFFF, false, false);

            if (Page > 1)
            {
                AddButton(45, 345, 5603, 5603, 1, GumpButtonType.Reply, 0);
            }

            if (Page < Pages)
            {
                AddButton(235, 345, 5601, 5601, 2, GumpButtonType.Reply, 0);
            }

            for (int i = start; i < Box.Entries.Count && i < start + 20; i++)
            {
                SeedEntry entry = Box.Entries[i];

                if (entry == null || entry.Seed == null)
                {
                    index++;
                    continue;
                }

                int x; int y;

                if (index < 4)
                {
                    x = 15 + (index * 70);
                    y = 15;
                }
                else if (index < 8)
                {
                    x = 15 + ((index - 4) * 70);
                    y = 82;
                }
                else if (index < 12)
                {
                    x = 15 + ((index - 8) * 70);
                    y = 149;
                }
                else if (index < 16)
                {
                    x = 15 + ((index - 12) * 70);
                    y = 216;
                }
                else
                {
                    x = 15 + ((index - 16) * 70);
                    y = 283;
                }

                AddButton(x, y, entry.Image, entry.Image, i + 100, GumpButtonType.Reply, 0);
                AddItem(x, y + 30, 0xDCF, entry.Seed.Hue);

                AddItemProperty(entry.Seed.Serial);

                index++;
            }
        }