コード例 #1
0
ファイル: MovingCrate.cs プロジェクト: uotools/xrunuo
        public override void DropItem(Item dropped)
        {
            // 1. Try to stack the item
            foreach (Item item in Items)
            {
                if (item is PackingBox)
                {
                    List <Item> subItems = item.Items;

                    for (int i = 0; i < subItems.Count; i++)
                    {
                        Item subItem = subItems[i];

                        if (!(subItem is Container) && subItem.StackWith(null, dropped, false))
                        {
                            return;
                        }
                    }
                }
            }

            // 2. Try to drop the item into an existing container
            foreach (Item item in this.Items)
            {
                if (item is PackingBox)
                {
                    Container   box      = (Container)item;
                    List <Item> subItems = box.Items;

                    if (subItems.Count < MaxItemsPerSubcontainer)
                    {
                        box.DropItem(dropped);
                        return;
                    }
                }
            }

            // 3. Drop the item into a new container
            Container subContainer = new PackingBox();

            subContainer.DropItem(dropped);

            Point3D location = GetFreeLocation();

            if (location != Point3D.Zero)
            {
                this.AddItem(subContainer);
                subContainer.Location = location;
            }
            else
            {
                base.DropItem(subContainer);
            }
        }
コード例 #2
0
ファイル: MovingCrate.cs プロジェクト: Ravenwolfe/xrunuo
        public override void DropItem( Item dropped )
        {
            // 1. Try to stack the item
            foreach ( Item item in Items )
            {
                if ( item is PackingBox )
                {
                    List<Item> subItems = item.Items;

                    for ( int i = 0; i < subItems.Count; i++ )
                    {
                        Item subItem = subItems[i];

                        if ( !( subItem is Container ) && subItem.StackWith( null, dropped, false ) )
                            return;
                    }
                }
            }

            // 2. Try to drop the item into an existing container
            foreach ( Item item in this.Items )
            {
                if ( item is PackingBox )
                {
                    Container box = (Container) item;
                    List<Item> subItems = box.Items;

                    if ( subItems.Count < MaxItemsPerSubcontainer )
                    {
                        box.DropItem( dropped );
                        return;
                    }
                }
            }

            // 3. Drop the item into a new container
            Container subContainer = new PackingBox();
            subContainer.DropItem( dropped );

            Point3D location = GetFreeLocation();
            if ( location != Point3D.Zero )
            {
                this.AddItem( subContainer );
                subContainer.Location = location;
            }
            else
            {
                base.DropItem( subContainer );
            }
        }