コード例 #1
0
        public static void Organizer(string name)
        {
            OrganizerManager manager = OrganizerManager.GetInstance();

            OrganizerEntry agent = manager.Items.FirstOrDefault(oa => oa.Name.ToLower().Equals(name.ToLower()));

            if (agent == null)
            {
                UOC.SystemMessage(string.Format(Strings.Organizer___0___not_found___, name));
                return;
            }

            agent.Action.Invoke(agent);
        }
コード例 #2
0
        public static int GetNumberInputWidth()
        {
            int width = 3;

            if (Controller != null && Controller.Entries.Any())
            {
                OrganizerEntry lastEntry = Controller.Entries.Last();
                width = (int)Math.Floor(Math.Log10(lastEntry.Number)) + 1;

                if (width < 3)
                {
                    width = 3;
                }
            }

            return(width);
        }
コード例 #3
0
        public static void SetOrganizerContainers(string entryName, object sourceContainer = null,
                                                  object destinationContainer = null)
        {
            int sourceSerial      = AliasCommands.ResolveSerial(sourceContainer, false);
            int destinationSerial = AliasCommands.ResolveSerial(destinationContainer, false);

            OrganizerManager manager = OrganizerManager.GetInstance();

            OrganizerEntry entry = manager.Items.FirstOrDefault(e => e.Name.ToLower().Equals(entryName.ToLower()));

            if (entry == null)
            {
                UOC.SystemMessage(Strings.Invalid_organizer_agent_name___, true);
                return;
            }

            entry.SourceContainer      = sourceSerial;
            entry.DestinationContainer = destinationSerial;

            UOC.SystemMessage(Strings.Organizer_containers_set___, true);
        }
コード例 #4
0
        public static void Organizer(string name, object sourceContainer = null, object destinationContainer = null)
        {
            OrganizerManager manager = OrganizerManager.GetInstance();

            OrganizerEntry entry = manager.Items.FirstOrDefault(oa => oa.Name.ToLower().Equals(name.ToLower()));

            if (entry == null)
            {
                UOC.SystemMessage(string.Format(Strings.Organizer___0___not_found___, name));
                return;
            }

            if (sourceContainer != null && destinationContainer != null)
            {
                int sourceContainerSerial     = AliasCommands.ResolveSerial(sourceContainer);
                int destinatinContainerSerial = AliasCommands.ResolveSerial(destinationContainer);

                manager.Organize(entry, sourceContainerSerial, destinatinContainerSerial).Wait();
            }
            else
            {
                manager.Organize(entry).Wait();
            }
        }
コード例 #5
0
        public void WillOrganizeLimitAmount()
        {
            AppDomain appDomain = AppDomain.CreateDomain("WillOrganizeLimitAmount",
                                                         AppDomain.CurrentDomain.Evidence,
                                                         AppDomain.CurrentDomain.SetupInformation);

            appDomain.DoCallBack(() =>
            {
                Dictionary <int, int> serialAmount = new Dictionary <int, int>();

                void OnInternalPacketSentEvent(byte[] data, int length)
                {
                    if (data[0] == 0x07)
                    {
                        int serial = (data[1] << 24) | (data[2] << 16) | (data[3] << 8) | data[4];
                        int amount = (data[5] << 8) | data[6];

                        if (serialAmount.ContainsKey(serial))
                        {
                            serialAmount.Remove(serial);
                        }

                        serialAmount.Add(serial, amount);
                    }

                    if (data[0] == 0x08)
                    {
                        int serial          = (data[1] << 24) | (data[2] << 16) | (data[3] << 8) | data[4];
                        int containerSerial = (data[11] << 24) | (data[12] << 16) | (data[13] << 8) | data[14];

                        Item sourceItem    = Engine.Items.GetItem(serial);
                        Item containerItem = Engine.Items.GetItem(containerSerial);

                        if (serialAmount.ContainsKey(serial))
                        {
                            sourceItem.Count = serialAmount[serial];
                        }

                        containerItem.Container.Add(sourceItem);
                    }
                }

                Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;

                OrganizerEntry entry = new OrganizerEntry();

                entry.Items.Add(new OrganizerItem {
                    ID = 0xff, Item = "Shmoo", Amount = 10
                });

                Item sourceContainer = new Item(0x40000004)
                {
                    Container = new ItemCollection(0x40000004)
                };
                sourceContainer.Container.Add(
                    new Item(0x40000005, 0x40000004)
                {
                    ID = 0xff, Count = 5, Owner = 0x40000004
                });
                sourceContainer.Container.Add(
                    new Item(0x40000006, 0x40000004)
                {
                    ID = 0xff, Count = 100, Owner = 0x40000004
                });

                Engine.Items.Add(sourceContainer);

                Item destinationContainer = new Item(0x40000007)
                {
                    Container = new ItemCollection(0x40000007)
                };

                Engine.Items.Add(destinationContainer);

                entry.SourceContainer      = sourceContainer.Serial;
                entry.DestinationContainer = destinationContainer.Serial;

                Engine.PacketWaitEntries = new PacketWaitEntries();

                OrganizerManager.GetInstance().Organize(entry).Wait();

                Item[] destinationItems = destinationContainer.Container.GetItems();

                Assert.AreEqual(entry.Items[0].Amount,
                                destinationItems.Sum(i => i.ID == entry.Items[0].ID ? i.Count : 0));

                Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
                Engine.Items.Clear();
                Engine.PacketWaitEntries = null;
            });
        }
コード例 #6
0
        public void WillOrganizeAnyHue()
        {
            Engine.Items.Clear();

            Item container = new Item(0x40000000)
            {
                Container = new ItemCollection(0x40000000)
            };

            container.Container.Add(new Item(0x40000001)
            {
                ID = 0xf06, Hue = 1000
            });
            container.Container.Add(new Item(0x40000002)
            {
                ID = 0xf06, Hue = 1161
            });
            Engine.Items.Add(container);

            Engine.PacketWaitEntries = new PacketWaitEntries();

            OrganizerManager manager = OrganizerManager.GetInstance();

            OrganizerEntry entry = new OrganizerEntry();

            entry.Items.Add(new OrganizerItem {
                ID = 0xf06, Hue = -1, Amount = -1, Item = "Test"
            });

            AutoResetEvent are = new AutoResetEvent(false);

            void OnInternalPacketSentEvent(byte[] data, int length)
            {
                if (data[0] == 0x06)
                {
                    int serial = (data[1] << 24) | (data[2] << 16) | (data[3] << 8) | data[4];

                    PacketWriter writer = new PacketWriter();
                    writer.Write(0x3C);
                    writer.Seek(19, SeekOrigin.Begin);
                    writer.Write(serial);

                    Engine.SendPacketToClient(writer);
                }

                if (data[0] == 0x07)
                {
                    are.Set();
                }
            }

            Engine.InternalPacketSentEvent += OnInternalPacketSentEvent;

            Task.Run(() => manager.Organize(entry, container.Serial, container.Serial)).Wait();

            bool result = are.WaitOne(4000);

            Assert.IsTrue(result);

            manager.Items.Clear();
            Engine.InternalPacketSentEvent -= OnInternalPacketSentEvent;
            Engine.PacketWaitEntries        = null;
            Engine.Items.Clear();
        }