Пример #1
0
        public static InventoryPosition MaterialSelector(int materialId)
        {
            InventoryPosition pos = new InventoryPosition();

            pos.type       = InventoryPositionType.MaterialSelector;
            pos.MaterialId = materialId;
            return(pos);
        }
Пример #2
0
        public static InventoryPosition MainArea(Point point)
        {
            InventoryPosition pos = new InventoryPosition();

            pos.type  = InventoryPositionType.MainArea;
            pos.AreaX = point.X;
            pos.AreaY = point.Y;
            return(pos);
        }
Пример #3
0
 public void WearItem(InventoryPosition from, InventoryPosition to)
 {
     //todo
     if (from.type == InventoryPositionType.MainArea &&
         to.type == InventoryPositionType.MaterialSelector &&
         d_Inventory.RightHand[to.MaterialId] == null &&
         d_Items.CanWear(WearPlace.RightHand, d_Inventory.Items[new ProtoPoint(from.AreaX, from.AreaY)]))
     {
         d_Inventory.RightHand[to.MaterialId] = d_Inventory.Items[new ProtoPoint(from.AreaX, from.AreaY)];
         d_Inventory.Items.Remove(new ProtoPoint(from.AreaX, from.AreaY));
     }
 }
Пример #4
0
        public void MoveToInventory(InventoryPosition from)
        {
            //todo
            if (from.type == InventoryPositionType.MaterialSelector)
            {
                //duplicate code with GrabItem().

                Item item = d_Inventory.RightHand[from.MaterialId];
                //grab to main area - stacking
                for (int x = 0; x < d_InventoryUtil.CellCount.X; x++)
                {
                    for (int y = 0; y < d_InventoryUtil.CellCount.Y; y++)
                    {
                        var p = d_InventoryUtil.ItemsAtArea(new Point(x, y), d_Items.ItemSize(item));
                        if (p != null && p.Length == 1)
                        {
                            var stacked = d_Items.Stack(d_Inventory.Items[new ProtoPoint(p[0])], item);
                            if (stacked != null)
                            {
                                d_Inventory.Items[new ProtoPoint(x, y)] = stacked;
                                d_Inventory.RightHand[from.MaterialId]  = null;
                                return;
                            }
                        }
                    }
                }
                //grab to main area - adding
                for (int x = 0; x < d_InventoryUtil.CellCount.X; x++)
                {
                    for (int y = 0; y < d_InventoryUtil.CellCount.Y; y++)
                    {
                        var p = d_InventoryUtil.ItemsAtArea(new Point(x, y), d_Items.ItemSize(item));
                        if (p != null && p.Length == 0)
                        {
                            d_Inventory.Items[new ProtoPoint(x, y)] = item;
                            d_Inventory.RightHand[from.MaterialId]  = null;
                            return;
                        }
                    }
                }
            }
        }
Пример #5
0
 public void InventoryClick(InventoryPosition pos)
 {
     if (pos.type == InventoryPositionType.MainArea)
     {
         Point?selected = null;
         foreach (var k in d_Inventory.Items)
         {
             if (pos.AreaX >= k.Key.X && pos.AreaY >= k.Key.Y &&
                 pos.AreaX < k.Key.X + d_Items.ItemSize(k.Value).X &&
                 pos.AreaY < k.Key.Y + d_Items.ItemSize(k.Value).Y)
             {
                 selected = k.Key.ToPoint();
             }
         }
         //drag
         if (selected != null && d_Inventory.DragDropItem == null)
         {
             d_Inventory.DragDropItem = d_Inventory.Items[new ProtoPoint(selected.Value)];
             d_Inventory.Items.Remove(new ProtoPoint(selected.Value));
             SendInventory();
         }
         //drop
         else if (d_Inventory.DragDropItem != null)
         {
             //make sure there is nothing blocking drop.
             Point[] itemsAtArea = d_InventoryUtil.ItemsAtArea(new Point(pos.AreaX, pos.AreaY),
                                                               d_Items.ItemSize(d_Inventory.DragDropItem));
             if (itemsAtArea == null || itemsAtArea.Length > 1)
             {
                 //invalid area
                 return;
             }
             if (itemsAtArea.Length == 0)
             {
                 d_Inventory.Items.Add(new ProtoPoint(pos.AreaX, pos.AreaY), d_Inventory.DragDropItem);
                 d_Inventory.DragDropItem = null;
             }
             else //1
             {
                 var swapWith = itemsAtArea[0];
                 //try to stack
                 Item stackResult = d_Items.Stack(d_Inventory.Items[new ProtoPoint(swapWith)], d_Inventory.DragDropItem);
                 if (stackResult != null)
                 {
                     d_Inventory.Items[new ProtoPoint(swapWith)] = stackResult;
                     d_Inventory.DragDropItem = null;
                 }
                 else
                 {
                     //try to swap
                     //swap (swapWith, dragdropitem)
                     Item z = d_Inventory.Items[new ProtoPoint(swapWith)];
                     d_Inventory.Items.Remove(new ProtoPoint(swapWith));
                     d_Inventory.Items[new ProtoPoint(pos.AreaX, pos.AreaY)] = d_Inventory.DragDropItem;
                     d_Inventory.DragDropItem = z;
                 }
             }
             SendInventory();
         }
     }
     else if (pos.type == InventoryPositionType.Ground)
     {
         if (d_Inventory.DragDropItem != null)
         {
             d_DropItem.DropItem(ref d_Inventory.DragDropItem,
                                 new Vector3i(pos.GroundPositionX, pos.GroundPositionY, pos.GroundPositionZ));
             SendInventory();
         }
     }
     else if (pos.type == InventoryPositionType.MaterialSelector)
     {
         if (d_Inventory.DragDropItem == null && d_Inventory.RightHand[pos.MaterialId] != null)
         {
             d_Inventory.DragDropItem = d_Inventory.RightHand[pos.MaterialId];
             d_Inventory.RightHand[pos.MaterialId] = null;
         }
         else if (d_Inventory.DragDropItem != null && d_Inventory.RightHand[pos.MaterialId] == null)
         {
             if (d_Items.CanWear(WearPlace.RightHand, d_Inventory.DragDropItem))
             {
                 d_Inventory.RightHand[pos.MaterialId] = d_Inventory.DragDropItem;
                 d_Inventory.DragDropItem = null;
             }
         }
         else if (d_Inventory.DragDropItem != null && d_Inventory.RightHand[pos.MaterialId] != null)
         {
             if (d_Items.CanWear(WearPlace.RightHand, d_Inventory.DragDropItem))
             {
                 Item oldHand = d_Inventory.RightHand[pos.MaterialId];
                 d_Inventory.RightHand[pos.MaterialId] = d_Inventory.DragDropItem;
                 d_Inventory.DragDropItem = oldHand;
             }
         }
         SendInventory();
     }
     else if (pos.type == InventoryPositionType.WearPlace)
     {
         //just swap.
         Item wear = d_InventoryUtil.ItemAtWearPlace((WearPlace)pos.WearPlace, pos.ActiveMaterial);
         if (d_Items.CanWear((WearPlace)pos.WearPlace, d_Inventory.DragDropItem))
         {
             d_InventoryUtil.SetItemAtWearPlace((WearPlace)pos.WearPlace, pos.ActiveMaterial, d_Inventory.DragDropItem);
             d_Inventory.DragDropItem = wear;
         }
         SendInventory();
     }
     else
     {
         throw new Exception();
     }
 }