Exemple #1
0
    private InventoryCellsGroup FindFreeGroup(Item item, int req_x, int req_y)
    {
        InventoryCell[,] cells = this.m_Cells;
        int upperBound  = cells.GetUpperBound(0);
        int upperBound2 = cells.GetUpperBound(1);

        for (int i = cells.GetLowerBound(0); i <= upperBound; i++)
        {
            for (int j = cells.GetLowerBound(1); j <= upperBound2; j++)
            {
                InventoryCell inventoryCell = cells[i, j];
                if (inventoryCell.m_IndexX + req_x <= (int)this.m_GridSize.x && inventoryCell.m_IndexY + req_y <= (int)this.m_GridSize.y)
                {
                    InventoryCellsGroup inventoryCellsGroup = new InventoryCellsGroup(this.m_Pocked);
                    for (int k = inventoryCell.m_IndexX; k < inventoryCell.m_IndexX + req_x; k++)
                    {
                        for (int l = inventoryCell.m_IndexY; l < inventoryCell.m_IndexY + req_y; l++)
                        {
                            inventoryCellsGroup.m_Cells.Add(this.m_Cells[k, l]);
                        }
                    }
                    if (inventoryCellsGroup.m_Cells.Count != 0 && inventoryCellsGroup.IsFree())
                    {
                        inventoryCellsGroup.Setup();
                        return(inventoryCellsGroup);
                    }
                }
            }
        }
        return(null);
    }
Exemple #2
0
    private InventoryCellsGroup FindFreeGroup(Item item, int req_x, int req_y)
    {
        InventoryCell[,] cells = this.m_Cells;
        int length  = cells.GetLength(0);
        int length2 = cells.GetLength(1);

        for (int i = 0; i < length; i++)
        {
            for (int j = 0; j < length2; j++)
            {
                InventoryCell inventoryCell = cells[i, j];
                if (inventoryCell.m_IndexX + req_x <= (int)this.m_GridSize.x)
                {
                    if (inventoryCell.m_IndexY + req_y <= (int)this.m_GridSize.y)
                    {
                        InventoryCellsGroup inventoryCellsGroup = new InventoryCellsGroup();
                        for (int k = inventoryCell.m_IndexX; k < inventoryCell.m_IndexX + req_x; k++)
                        {
                            for (int l = inventoryCell.m_IndexY; l < inventoryCell.m_IndexY + req_y; l++)
                            {
                                inventoryCellsGroup.m_Cells.Add(this.m_Cells[k, l]);
                            }
                        }
                        if (inventoryCellsGroup.m_Cells.Count != 0 && inventoryCellsGroup.IsFree())
                        {
                            inventoryCellsGroup.Setup();
                            return(inventoryCellsGroup);
                        }
                    }
                }
            }
        }
        return(null);
    }
Exemple #3
0
 public bool InsertItem(Item item, ItemSlot slot, InventoryCellsGroup group, bool can_stack, bool can_auto_select_group, Storage storage = null)
 {
     if (item.m_Info.m_FakeItem)
     {
         return(true);
     }
     if (slot)
     {
         if (slot.CanInsertItem(item))
         {
             if (slot.IsStack() && slot.m_ItemParent && slot.m_ItemParent.m_Info.m_InventoryRotated != item.m_Info.m_InventoryRotated)
             {
                 Inventory3DManager.Get().RotateItem(item, true);
             }
             slot.InsertItem(item);
             return(true);
         }
         if (!slot.IsOccupied())
         {
             return(false);
         }
     }
     if (group == null)
     {
         if (can_stack)
         {
             List <Item> list = storage ? storage.m_Items : InventoryBackpack.Get().m_Items;
             for (int i = 0; i < list.Count; i++)
             {
                 Item item2 = list[i];
                 if (item2.m_InventorySlot && !item2.m_CurrentSlot && item2.m_InventorySlot.CanInsertItem(item))
                 {
                     if (item2.m_Info.m_InventoryRotated != item.m_Info.m_InventoryRotated)
                     {
                         Inventory3DManager.Get().RotateItem(item, true);
                     }
                     item2.m_InventorySlot.InsertItem(item);
                     return(true);
                 }
             }
         }
         if (can_auto_select_group)
         {
             group = this.FindFreeGroup(item);
             if (group != null && group.IsFree())
             {
                 group.Insert(item, this.m_Grid);
                 return(true);
             }
         }
         return(false);
     }
     if (group.IsFree())
     {
         group.Insert(item, this.m_Grid);
         return(true);
     }
     return(false);
 }
Exemple #4
0
 public InsertResult InsertItem(Item item, ItemSlot slot, InventoryCellsGroup group, bool notify_if_cant = true, bool drop_if_cant = true)
 {
     if (!this.m_Storage)
     {
         return(InsertResult.CantInsert);
     }
     return(this.m_Storage.InsertItem(item, slot, group, notify_if_cant, drop_if_cant));
 }
Exemple #5
0
 private InsertResult InsertItemFront(Item item, ItemSlot slot, InventoryCellsGroup group, bool can_stack, bool can_auto_select_group)
 {
     if (this.m_FrontPocketGrid.InsertItem(item, slot, group, can_stack, can_auto_select_group, null))
     {
         return(InsertResult.Ok);
     }
     return(InsertResult.NoSpace);
 }
Exemple #6
0
    public override void Eat()
    {
        if (this.m_Hallucination)
        {
            base.Disappear(true);
            return;
        }
        base.Eat();
        if (base.transform.parent != null)
        {
            DestroyIfNoChildren component = base.transform.parent.GetComponent <DestroyIfNoChildren>();
            if (component)
            {
                component.OnObjectDestroyed();
            }
        }
        Player.Get().GetComponent <EatingController>().Eat(this.m_FInfo);
        UnityEngine.Object.Destroy(base.gameObject);
        bool          flag = InventoryBackpack.Get().Contains(this);
        List <ItemID> eatingResultItems = ((FoodInfo)this.m_Info).m_EatingResultItems;

        for (int i = 0; i < eatingResultItems.Count; i++)
        {
            ItemID item_id = eatingResultItems[i];
            if (flag)
            {
                Item item = ItemsManager.Get().CreateItem(item_id, false, Vector3.zero, Quaternion.identity);
                InventoryBackpack.Get().InsertItem(item, null, null, true, true, true, true, false);
            }
            else if (this.m_Storage != null)
            {
                Item item2 = ItemsManager.Get().CreateItem(item_id, false, Vector3.zero, Quaternion.identity);
                InventoryCellsGroup inventoryCellsGroup = this.m_Info.m_InventoryCellsGroup;
                Storage             storage             = this.m_Storage;
                storage.RemoveItem(this, false);
                storage.InsertItem(item2, base.m_CurrentSlot, inventoryCellsGroup, true, true);
                item2.gameObject.SetActive(true);
            }
            else
            {
                GameObject prefab = GreenHellGame.Instance.GetPrefab(item_id.ToString());
                if (!prefab)
                {
                    DebugUtils.Assert("[Item:Harvest] Can't find prefab - " + item_id.ToString(), true, DebugUtils.AssertType.Info);
                }
                else
                {
                    UnityEngine.Object.Instantiate <GameObject>(prefab, base.transform.position, base.transform.rotation);
                }
            }
        }
        if (this.m_Acre)
        {
            this.m_Acre.OnEat(this);
        }
    }
Exemple #7
0
    public void OnSetSelectedGroup(InventoryCellsGroup group)
    {
        InventoryCell[,] cells = this.m_Cells;
        int upperBound  = cells.GetUpperBound(0);
        int upperBound2 = cells.GetUpperBound(1);

        for (int i = cells.GetLowerBound(0); i <= upperBound; i++)
        {
            for (int j = cells.GetLowerBound(1); j <= upperBound2; j++)
            {
                cells[i, j].m_Renderer.enabled = false;
            }
        }
        if (group == null)
        {
            return;
        }
        for (int k = 0; k < (int)this.m_GridSize.y; k++)
        {
            for (int l = 0; l < (int)this.m_GridSize.x; l++)
            {
                this.m_Cells[l, k].m_Renderer.material.color = Color.white;
            }
        }
        if (group.IsFree())
        {
            for (int m = 0; m < group.m_Cells.Count; m++)
            {
                group.m_Cells[m].m_Renderer.enabled        = true;
                group.m_Cells[m].m_Renderer.material.color = InventoryBackpack.Get().m_FreeColor;
            }
            return;
        }
        for (int n = 0; n < group.m_Cells.Count; n++)
        {
            group.m_Cells[n].m_Renderer.enabled        = true;
            group.m_Cells[n].m_Renderer.material.color = InventoryBackpack.Get().m_OccupiedColor;
            if (group.m_Cells[n].m_Items.Count > 0)
            {
                for (int num = 0; num < group.m_Cells[n].m_Items.Count; num++)
                {
                    InventoryCellsGroup inventoryCellsGroup = group.m_Cells[n].m_Items[num].m_Info.m_InventoryCellsGroup;
                    if (this.m_Pocked != BackpackPocket.Storage || !group.m_Cells[n].m_Items[num].m_Storage || !(group.m_Cells[n].m_Items[num].m_Storage != Storage3D.Get().m_Storage))
                    {
                        for (int num2 = 0; num2 < inventoryCellsGroup.m_Cells.Count; num2++)
                        {
                            inventoryCellsGroup.m_Cells[num2].m_Renderer.enabled        = true;
                            inventoryCellsGroup.m_Cells[num2].m_Renderer.material.color = InventoryBackpack.Get().m_OccupiedColor;
                        }
                    }
                }
            }
        }
    }
Exemple #8
0
    public InsertResult InsertItem(Item item, ItemSlot slot, InventoryCellsGroup group, bool notify_if_cant, bool drop_if_cant)
    {
        if (this.m_Items.Contains(item))
        {
            return(InsertResult.CantInsert);
        }
        bool isStatic = item.gameObject.isStatic;

        item.gameObject.isStatic = false;
        item.transform.parent    = null;
        InsertResult insertResult = InsertResult.None;

        if (Storage3D.Get().GetGrid(this.m_Type).InsertItem(item, slot, group, true, true, this))
        {
            insertResult = InsertResult.Ok;
        }
        else
        {
            insertResult = InsertResult.NoSpace;
        }
        if (insertResult == InsertResult.Ok)
        {
            this.m_Items.Add(item);
            if (!item.m_CurrentSlot)
            {
                item.transform.parent = Storage3D.Get().transform;
            }
            item.OnAddToStorage(this);
            item.gameObject.SetActive(Inventory3DManager.Get().gameObject.activeSelf&& item.m_Info.m_BackpackPocket == Inventory3DManager.Get().m_ActivePocket);
            using (List <Item> .Enumerator enumerator = this.m_Items.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Item item2 = enumerator.Current;
                    item2.UpdatePhx();
                    item2.UpdateScale(false);
                    item.UpdateLayer();
                }
                return(insertResult);
            }
        }
        item.gameObject.isStatic = isStatic;
        if (notify_if_cant)
        {
            ((HUDMessages)HUDManager.Get().GetHUD(typeof(HUDMessages))).AddMessage(GreenHellGame.Instance.GetLocalization().Get("HUD_NoSpaceInStorage", true), new Color?(Color.red), HUDMessageIcon.None, "", null);
            HUDManager.Get().PlaySound("Sounds/HUD/GH_Inventory_Full");
        }
        if (drop_if_cant)
        {
            Inventory3DManager.Get().DropItem(item);
        }
        return(insertResult);
    }
Exemple #9
0
 public void OnSetSelectedGroup(BackpackPocket pocket, InventoryCellsGroup group)
 {
     if (pocket == BackpackPocket.Main)
     {
         this.m_MainPocketGrid.OnSetSelectedGroup(group);
         return;
     }
     if (pocket != BackpackPocket.Front)
     {
         return;
     }
     this.m_FrontPocketGrid.OnSetSelectedGroup(group);
 }
Exemple #10
0
    public void OnSetSelectedGroup(InventoryCellsGroup group)
    {
        InventoryCell[,] cells = this.m_Cells;
        int length  = cells.GetLength(0);
        int length2 = cells.GetLength(1);

        for (int i = 0; i < length; i++)
        {
            for (int j = 0; j < length2; j++)
            {
                InventoryCell inventoryCell = cells[i, j];
                inventoryCell.m_Renderer.enabled = false;
            }
        }
        if (group == null)
        {
            return;
        }
        bool flag = group.IsFree();

        if (flag)
        {
            for (int k = 0; k < group.m_Cells.Count; k++)
            {
                group.m_Cells[k].m_Renderer.enabled        = true;
                group.m_Cells[k].m_Renderer.material.color = InventoryBackpack.Get().m_FreeColor;
            }
        }
        else
        {
            for (int l = 0; l < group.m_Cells.Count; l++)
            {
                group.m_Cells[l].m_Renderer.enabled        = true;
                group.m_Cells[l].m_Renderer.material.color = InventoryBackpack.Get().m_OccupiedColor;
                if (group.m_Cells[l].m_Items.Count > 0)
                {
                    for (int m = 0; m < group.m_Cells[l].m_Items.Count; m++)
                    {
                        InventoryCellsGroup inventoryCellsGroup = group.m_Cells[l].m_Items[m].m_Info.m_InventoryCellsGroup;
                        for (int n = 0; n < inventoryCellsGroup.m_Cells.Count; n++)
                        {
                            inventoryCellsGroup.m_Cells[n].m_Renderer.enabled        = true;
                            inventoryCellsGroup.m_Cells[n].m_Renderer.material.color = InventoryBackpack.Get().m_OccupiedColor;
                        }
                    }
                }
            }
        }
    }
Exemple #11
0
    public void Setup()
    {
        this.m_MatchingGroups.Clear();
        Item carriedItem = Inventory3DManager.Get().m_CarriedItem;

        if (!carriedItem)
        {
            return;
        }
        if (carriedItem.m_Info.m_InventoryCellsGroup != null)
        {
            carriedItem.m_Info.m_InventoryCellsGroup.Remove(carriedItem);
        }
        int num  = 0;
        int num2 = 0;

        this.CalcRequiredCells(carriedItem, ref num, ref num2);
        InventoryCell[,] cells = this.m_Cells;
        int length  = cells.GetLength(0);
        int length2 = cells.GetLength(1);

        for (int i = 0; i < length; i++)
        {
            for (int j = 0; j < length2; j++)
            {
                InventoryCell inventoryCell = cells[i, j];
                if (inventoryCell.m_IndexX + num <= (int)this.m_GridSize.x)
                {
                    if (inventoryCell.m_IndexY + num2 <= (int)this.m_GridSize.y)
                    {
                        InventoryCellsGroup inventoryCellsGroup = new InventoryCellsGroup();
                        for (int k = inventoryCell.m_IndexX; k < inventoryCell.m_IndexX + num; k++)
                        {
                            for (int l = inventoryCell.m_IndexY; l < inventoryCell.m_IndexY + num2; l++)
                            {
                                inventoryCellsGroup.m_Cells.Add(this.m_Cells[k, l]);
                            }
                        }
                        if (inventoryCellsGroup.m_Cells.Count != 0)
                        {
                            inventoryCellsGroup.Setup();
                            this.m_MatchingGroups.Add(inventoryCellsGroup);
                        }
                    }
                }
            }
        }
    }
Exemple #12
0
    private void UpdateSelectedGroup()
    {
        InventoryCellsGroup selectedGroup = this.m_SelectedGroup;

        if (!this.m_SelectedSlot && (this.m_ActivePocket == BackpackPocket.Main || this.m_ActivePocket == BackpackPocket.Front))
        {
            this.m_SelectedGroup = InventoryBackpack.Get().FindBestGroup(this.m_ActivePocket);
        }
        else
        {
            this.m_SelectedGroup = null;
        }
        if (selectedGroup != this.m_SelectedGroup)
        {
            InventoryBackpack.Get().OnSetSelectedGroup(this.m_ActivePocket, this.m_SelectedGroup);
        }
    }
Exemple #13
0
 public bool InsertItem(Item item, ItemSlot slot, InventoryCellsGroup group, bool can_stack, bool can_auto_select_group)
 {
     if (slot)
     {
         if (slot.CanInsertItem(item))
         {
             slot.InsertItem(item);
             return(true);
         }
         return(false);
     }
     else
     {
         if (group == null)
         {
             if (can_stack)
             {
                 for (int i = 0; i < InventoryBackpack.Get().m_Items.Count; i++)
                 {
                     Item item2 = InventoryBackpack.Get().m_Items[i];
                     if (item2.m_InventorySlot && !item2.m_CurrentSlot && item2.m_InventorySlot.CanInsertItem(item))
                     {
                         item2.m_InventorySlot.InsertItem(item);
                         return(true);
                     }
                 }
             }
             if (can_auto_select_group)
             {
                 group = this.FindFreeGroup(item);
                 if (group != null && group.IsFree())
                 {
                     group.Insert(item, this.m_Grid);
                     return(true);
                 }
             }
             return(false);
         }
         if (group.IsFree())
         {
             group.Insert(item, this.m_Grid);
             return(true);
         }
         return(false);
     }
 }
Exemple #14
0
    public void Setup()
    {
        this.m_MatchingGroups.Clear();
        Item carriedItem = Inventory3DManager.Get().m_CarriedItem;

        if (!carriedItem)
        {
            return;
        }
        if (this.m_Pocked == BackpackPocket.Storage && !Storage3D.Get().CanInsertItem(Inventory3DManager.Get().m_CarriedItem))
        {
            return;
        }
        int num  = 0;
        int num2 = 0;

        this.CalcRequiredCells(carriedItem, ref num, ref num2);
        InventoryCell[,] cells = this.m_Cells;
        int upperBound  = cells.GetUpperBound(0);
        int upperBound2 = cells.GetUpperBound(1);

        for (int i = cells.GetLowerBound(0); i <= upperBound; i++)
        {
            for (int j = cells.GetLowerBound(1); j <= upperBound2; j++)
            {
                InventoryCell inventoryCell = cells[i, j];
                if (inventoryCell.m_IndexX + num <= (int)this.m_GridSize.x && inventoryCell.m_IndexY + num2 <= (int)this.m_GridSize.y)
                {
                    InventoryCellsGroup inventoryCellsGroup = new InventoryCellsGroup(this.m_Pocked);
                    for (int k = inventoryCell.m_IndexX; k < inventoryCell.m_IndexX + num; k++)
                    {
                        for (int l = inventoryCell.m_IndexY; l < inventoryCell.m_IndexY + num2; l++)
                        {
                            inventoryCellsGroup.m_Cells.Add(this.m_Cells[k, l]);
                        }
                    }
                    if (inventoryCellsGroup.m_Cells.Count != 0)
                    {
                        inventoryCellsGroup.Setup();
                        this.m_MatchingGroups.Add(inventoryCellsGroup);
                    }
                }
            }
        }
    }
Exemple #15
0
    private InventoryCellsGroup FindFreeGroup(Item item)
    {
        if (!item.m_Info.m_CanBeAddedToInventory)
        {
            return(null);
        }
        int req_x = 0;
        int req_y = 0;

        this.CalcRequiredCells(item, ref req_x, ref req_y);
        InventoryCellsGroup inventoryCellsGroup = this.FindFreeGroup(item, req_x, req_y);

        if (inventoryCellsGroup == null)
        {
            Inventory3DManager.Get().RotateItem(item, true);
            this.CalcRequiredCells(item, ref req_x, ref req_y);
            inventoryCellsGroup = this.FindFreeGroup(item, req_x, req_y);
        }
        return(inventoryCellsGroup);
    }
Exemple #16
0
    private InventoryCellsGroup FindFreeGroup(Item item)
    {
        if (!item.m_Info.m_CanBeAddedToInventory)
        {
            return(null);
        }
        int num  = 0;
        int num2 = 0;

        item.m_Info.m_InventoryRotated = false;
        item.transform.rotation        = Quaternion.identity;
        this.CalcRequiredCells(item, ref num, ref num2);
        InventoryCellsGroup inventoryCellsGroup = this.FindFreeGroup(item, num, num2);

        if (inventoryCellsGroup == null)
        {
            Inventory3DManager.Get().RotateItem(item);
            inventoryCellsGroup = this.FindFreeGroup(item, num2, num);
        }
        return(inventoryCellsGroup);
    }
Exemple #17
0
    public void SortItemsBySize()
    {
        if (this.m_ActivePocket != BackpackPocket.Front && this.m_ActivePocket != BackpackPocket.Main)
        {
            return;
        }
        PocketGrid pocketGrid = (this.m_ActivePocket == BackpackPocket.Front) ? this.m_FrontPocketGrid : this.m_MainPocketGrid;

        this.m_TempSortItems.Clear();
        foreach (Item item in this.m_Items)
        {
            if (item.m_Info.m_BackpackPocket == this.m_ActivePocket)
            {
                this.m_TempSortItems.Add(item);
            }
        }
        foreach (Item item2 in this.m_TempSortItems)
        {
            this.RemoveItem(item2, false);
        }
        this.m_TempSortItems.Sort(new Comparison <Item>(InventoryBackpack.CompareBySize));
        foreach (Item item3 in this.m_TempSortItems)
        {
            ItemSlot itemSlot = null;
            for (int i = 0; i < this.m_Items.Count; i++)
            {
                Item item4 = this.m_Items[i];
                if (item4.m_InventorySlot && !item4.m_CurrentSlot && item4.m_InventorySlot.CanInsertItem(item3))
                {
                    if (item4.m_Info.m_InventoryRotated != item3.m_Info.m_InventoryRotated)
                    {
                        Inventory3DManager.Get().RotateItem(item3, true);
                    }
                    itemSlot = item4.m_InventorySlot;
                    break;
                }
            }
            if (itemSlot)
            {
                this.InsertItem(item3, itemSlot, null, true, true, false, true, true);
            }
            else
            {
                List <InventoryCellsGroup> list = new List <InventoryCellsGroup>();
                int num  = 0;
                int num2 = 0;
                item3.m_Info.m_InventoryRotated = false;
                pocketGrid.CalcRequiredCells(item3, ref num, ref num2);
                int num3 = 0;
                int num4 = 0;
                item3.m_Info.m_InventoryRotated = true;
                pocketGrid.CalcRequiredCells(item3, ref num3, ref num4);
                item3.m_Info.m_InventoryRotated = (num3 > num);
                int num5 = item3.m_Info.m_InventoryRotated ? num3 : num;
                int num6 = item3.m_Info.m_InventoryRotated ? num4 : num2;
                InventoryCell[,] cells = pocketGrid.m_Cells;
                int upperBound  = cells.GetUpperBound(0);
                int upperBound2 = cells.GetUpperBound(1);
                for (int j = cells.GetLowerBound(0); j <= upperBound; j++)
                {
                    for (int k = cells.GetLowerBound(1); k <= upperBound2; k++)
                    {
                        InventoryCell inventoryCell = cells[j, k];
                        if (inventoryCell.m_IndexX + num5 <= (int)pocketGrid.m_GridSize.x && inventoryCell.m_IndexY + num6 <= (int)pocketGrid.m_GridSize.y)
                        {
                            InventoryCellsGroup inventoryCellsGroup = new InventoryCellsGroup(this.m_ActivePocket);
                            for (int l = inventoryCell.m_IndexX; l < inventoryCell.m_IndexX + num5; l++)
                            {
                                for (int m = inventoryCell.m_IndexY; m < inventoryCell.m_IndexY + num6; m++)
                                {
                                    inventoryCellsGroup.m_Cells.Add(pocketGrid.m_Cells[l, m]);
                                }
                            }
                            if (inventoryCellsGroup.m_Cells.Count != 0 && inventoryCellsGroup.IsFree())
                            {
                                inventoryCellsGroup.Setup();
                                list.Add(inventoryCellsGroup);
                            }
                        }
                    }
                }
                if (list.Count == 0)
                {
                    this.InsertItem(item3, null, null, true, true, false, true, true);
                }
                else
                {
                    InventoryCellsGroup inventoryCellsGroup2 = null;
                    foreach (InventoryCellsGroup inventoryCellsGroup3 in list)
                    {
                        if (inventoryCellsGroup2 == null || inventoryCellsGroup3.m_Cells[0].m_IndexY < inventoryCellsGroup2.m_Cells[0].m_IndexY)
                        {
                            inventoryCellsGroup2 = inventoryCellsGroup3;
                        }
                    }
                    foreach (InventoryCellsGroup inventoryCellsGroup4 in list)
                    {
                        if (inventoryCellsGroup4.m_Cells[0].m_IndexX > inventoryCellsGroup2.m_Cells[0].m_IndexX && inventoryCellsGroup4.m_Cells[0].m_IndexY == inventoryCellsGroup2.m_Cells[0].m_IndexY)
                        {
                            inventoryCellsGroup2 = inventoryCellsGroup4;
                        }
                    }
                    InsertResult insertResult = this.InsertItem(item3, null, inventoryCellsGroup2, true, true, false, true, true);
                    if (insertResult != InsertResult.Ok)
                    {
                        insertResult = this.InsertItem(item3, null, null, true, true, false, true, true);
                    }
                    if (insertResult != InsertResult.Ok)
                    {
                        DebugUtils.Assert(DebugUtils.AssertType.Info);
                    }
                }
            }
        }
    }
Exemple #18
0
    public InventoryCellsGroup FindBestGroup()
    {
        if (this.m_MatchingGroups.Count == 0)
        {
            return(null);
        }
        Vector3       zero          = Vector3.zero;
        RectTransform rectTransform = Inventory3DManager.Get().m_InventoryImage.rectTransform;
        Vector2       zero2         = Vector2.zero;

        if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, null, out zero2))
        {
            return(null);
        }
        zero.x = CJTools.Math.GetProportionalClamp(0f, 1f, zero2.x, -rectTransform.sizeDelta.x * 0.5f, rectTransform.sizeDelta.x * 0.5f);
        zero.y = CJTools.Math.GetProportionalClamp(0f, 1f, zero2.y, -rectTransform.sizeDelta.y * 0.5f, rectTransform.sizeDelta.y * 0.5f);
        GameObject gameObject = null;
        Vector3    vector     = Vector3.zero;

        Inventory3DManager.Get().m_Camera.ViewportPointToRay(zero);
        RaycastHit[] backpackHits = Inventory3DManager.Get().m_BackpackHits;
        for (int i = 0; i < Inventory3DManager.Get().m_BackpackHitsCnt; i++)
        {
            if (backpackHits[i].collider.gameObject.transform.parent == this.m_Grid.transform)
            {
                gameObject = backpackHits[i].collider.gameObject;
                vector     = backpackHits[i].point;
                break;
            }
        }
        if (!gameObject)
        {
            return(null);
        }
        List <InventoryCellsGroup> list = new List <InventoryCellsGroup>();

        for (int j = 0; j < this.m_MatchingGroups.Count; j++)
        {
            if (this.m_MatchingGroups[j].Contains(gameObject))
            {
                list.Add(this.m_MatchingGroups[j]);
            }
        }
        if (list.Count == 0)
        {
            return(null);
        }
        InventoryCellsGroup result = null;
        float num = float.MaxValue;

        foreach (InventoryCellsGroup inventoryCellsGroup in list)
        {
            float num2 = vector.Distance(inventoryCellsGroup.m_CenterWorld);
            if (num2 < num)
            {
                result = inventoryCellsGroup;
                num    = num2;
            }
        }
        return(result);
    }
Exemple #19
0
    public InsertResult InsertItem(Item item, ItemSlot slot = null, InventoryCellsGroup group = null, bool can_stack = true, bool drop_if_cant = true, bool notify_if_cant = true, bool can_auto_select_group = true, bool set_pocket = true)
    {
        if (item.m_IsBeingDestroyed)
        {
            return(InsertResult.CantInsert);
        }
        if (!item.m_Info.m_CanBeAddedToInventory)
        {
            Inventory3DManager.Get().DropItem(item);
            return(InsertResult.CantInsert);
        }
        if (this.m_Items.Contains(item))
        {
            return(InsertResult.AllreadyInInventory);
        }
        bool isStatic = item.gameObject.isStatic;

        item.gameObject.isStatic  = false;
        item.transform.parent     = null;
        item.transform.localScale = item.m_InventoryLocalScale;
        this.SetBackpackTransform(item.m_Info.m_BackpackPocket);
        if (set_pocket && Inventory3DManager.Get().gameObject.activeSelf)
        {
            Inventory3DManager.Get().SetupPocket(item.m_Info.m_BackpackPocket);
        }
        InsertResult insertResult = InsertResult.None;

        if (item.m_Info.m_BackpackPocket == BackpackPocket.Top)
        {
            insertResult = this.InsertItemTop(item, slot);
        }
        else if (item.m_Info.m_BackpackPocket == BackpackPocket.Left)
        {
            insertResult = this.InsertItemLeft(item, slot);
        }
        else if (item.m_Info.m_BackpackPocket == BackpackPocket.Right)
        {
            insertResult = this.InsertItemRight(item, slot);
        }
        else if (item.m_Info.m_BackpackPocket == BackpackPocket.Main)
        {
            insertResult = this.InsertItemMain(item, slot, group, can_stack, can_auto_select_group);
        }
        else if (item.m_Info.m_BackpackPocket == BackpackPocket.Front)
        {
            insertResult = this.InsertItemFront(item, slot, group, can_stack, can_auto_select_group);
        }
        if (insertResult == InsertResult.Ok)
        {
            this.m_Items.Add(item);
            if (!item.m_CurrentSlot)
            {
                item.transform.parent = base.transform;
            }
            else if (item.m_CurrentSlot == this.m_EquippedItemSlot)
            {
                this.m_EquippedItem = item;
            }
            item.OnAddToInventory();
            item.gameObject.SetActive(Inventory3DManager.Get().gameObject.activeSelf&& item.m_Info.m_BackpackPocket == Inventory3DManager.Get().m_ActivePocket);
            this.OnInventoryChanged();
        }
        else
        {
            item.gameObject.isStatic = isStatic;
            if (notify_if_cant)
            {
                ((HUDMessages)HUDManager.Get().GetHUD(typeof(HUDMessages))).AddMessage(GreenHellGame.Instance.GetLocalization().Get("HUD_NoSpaceInBackpack", true), new Color?(Color.red), HUDMessageIcon.None, "", null);
                HUDManager.Get().PlaySound("Sounds/HUD/GH_Inventory_Full");
                if (!drop_if_cant)
                {
                    item.ApplyImpulse(new Vector3(0f, 100f, 0f), new Vector3(0f, 0f, UnityEngine.Random.Range(-100f, 100f)));
                }
            }
            if (drop_if_cant)
            {
                Inventory3DManager.Get().DropItem(item);
            }
        }
        this.SetBackpackTransform(Inventory3DManager.Get().m_ActivePocket);
        item.UpdateScale(false);
        return(insertResult);
    }
Exemple #20
0
 public void OnSetSelectedGroup(InventoryCellsGroup group)
 {
     this.m_ActiveData.m_Grid.OnSetSelectedGroup(group);
 }
Exemple #21
0
    private void Spoil()
    {
        if (GreenHellGame.ROADSHOW_DEMO)
        {
            return;
        }
        if (this.m_FInfo.m_SpoilEffectID == ItemID.None)
        {
            return;
        }
        bool       inventoryRotated = this.m_Info.m_InventoryRotated;
        Quaternion rotation         = base.transform.rotation;
        Vector3    position         = base.transform.position;
        Item       item             = ItemsManager.Get().CreateItem(this.m_FInfo.m_SpoilEffectID, !base.m_InInventory && !base.m_InStorage && !base.m_OnCraftingTable, base.transform.position, base.transform.rotation);

        if (Inventory3DManager.Get().m_CarriedItem == this)
        {
            foreach (Item item2 in Inventory3DManager.Get().m_StackItems)
            {
                Quaternion localRotation = item2.transform.localRotation;
                Vector3    localPosition = item2.transform.localPosition;
                item2.transform.parent        = item.transform;
                item2.transform.localRotation = localRotation;
                item2.transform.localPosition = localPosition;
            }
            Inventory3DManager.Get().SetCarriedItem(null, false);
            Inventory3DManager.Get().SetCarriedItem(item, false);
            ItemsManager.Get().ActivateItem(item);
        }
        else if (Inventory3DManager.Get().m_StackItems.Contains(this))
        {
            Inventory3DManager.Get().m_StackItems.Remove(this);
            this.UpdateLayer();
            item.transform.parent        = item.transform;
            item.transform.localRotation = base.transform.localRotation;
            item.transform.localPosition = base.transform.localPosition;
            Inventory3DManager.Get().m_StackItems.Add(item);
            item.UpdateLayer();
            ItemsManager.Get().ActivateItem(item);
        }
        else if (base.m_CurrentSlot && base.m_CurrentSlot.m_InventoryStackSlot)
        {
            ItemSlot currentSlot = base.m_CurrentSlot;
            InventoryBackpack.Get().m_Items.Remove(this);
            if (this.m_Info.m_InventoryCellsGroup != null)
            {
                this.m_Info.m_InventoryCellsGroup.Remove(this);
            }
            ((ItemSlotStack)currentSlot).ReplaceItem(this, item);
            item.gameObject.isStatic = false;
            if (base.m_InInventory)
            {
                InventoryBackpack.Get().m_Items.Add(item);
                item.OnAddToInventory();
                item.gameObject.SetActive(base.gameObject.activeSelf);
                InventoryBackpack.Get().OnInventoryChanged();
            }
            else
            {
                this.m_Storage.m_Items.Add(item);
                item.OnAddToStorage(this.m_Storage);
                item.gameObject.SetActive(base.gameObject.activeSelf);
            }
        }
        else
        {
            if (base.m_InInventory)
            {
                ItemSlot            currentSlot2        = base.m_CurrentSlot;
                InventoryCellsGroup inventoryCellsGroup = this.m_Info.m_InventoryCellsGroup;
                List <Item>         list = this.m_InventorySlot ? new List <Item>(this.m_InventorySlot.m_Items) : new List <Item>();
                InventoryBackpack.Get().RemoveItem(this, false);
                if (!base.m_CurrentSlot && this.m_InventorySlot && list.Count > 0)
                {
                    using (List <Item> .Enumerator enumerator = list.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            Item item3 = enumerator.Current;
                            if (item3.m_Info.m_InventoryCellsGroup != null)
                            {
                                item3.m_Info.m_InventoryCellsGroup.Remove(item3);
                            }
                        }
                        goto IL_3A3;
                    }
                }
                if (base.m_CurrentSlot)
                {
                    if (base.m_CurrentSlot.m_InventoryStackSlot)
                    {
                        base.m_CurrentSlot.RemoveItem(this, false);
                    }
                    else
                    {
                        base.m_CurrentSlot.RemoveItem();
                    }
                }
IL_3A3:
                InventoryBackpack.Get().InsertItem(item, currentSlot2, inventoryCellsGroup, true, true, true, true, true);
                if (!item.m_InventorySlot || list.Count <= 0)
                {
                    goto IL_5BD;
                }
                using (List <Item> .Enumerator enumerator = list.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Item item4 = enumerator.Current;
                        item.m_InventorySlot.InsertItem(item4);
                    }
                    goto IL_5BD;
                }
            }
            if (base.m_OnCraftingTable)
            {
                CraftingManager.Get().RemoveItem(this, false);
                CraftingManager.Get().AddItem(item, false);
            }
            else if (base.m_CurrentSlot)
            {
                ItemSlot currentSlot3 = base.m_CurrentSlot;
                currentSlot3.RemoveItem();
                currentSlot3.InsertItem(item);
            }
            else if (base.m_InStorage && this.m_Storage)
            {
                Storage             storage              = this.m_Storage;
                ItemSlot            currentSlot4         = base.m_CurrentSlot;
                InventoryCellsGroup inventoryCellsGroup2 = this.m_Info.m_InventoryCellsGroup;
                List <Item>         list2 = this.m_InventorySlot ? new List <Item>(this.m_InventorySlot.m_Items) : new List <Item>();
                storage.RemoveItem(this, false);
                if (!base.m_CurrentSlot && this.m_InventorySlot && list2.Count > 0)
                {
                    using (List <Item> .Enumerator enumerator = list2.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            Item item5 = enumerator.Current;
                            item5.m_Info.m_InventoryCellsGroup.Remove(item5);
                        }
                        goto IL_559;
                    }
                }
                if (base.m_CurrentSlot)
                {
                    if (base.m_CurrentSlot.m_InventoryStackSlot)
                    {
                        base.m_CurrentSlot.RemoveItem(this, false);
                    }
                    else
                    {
                        base.m_CurrentSlot.RemoveItem();
                    }
                }
IL_559:
                storage.InsertItem(item, base.m_CurrentSlot, inventoryCellsGroup2, true, true);
                if (item.m_InventorySlot && list2.Count > 0)
                {
                    foreach (Item item6 in list2)
                    {
                        item.m_InventorySlot.InsertItem(item6);
                    }
                }
            }
        }
IL_5BD:
        if (inventoryRotated)
        {
            Inventory3DManager.Get().RotateItem(item, true);
        }
        if (HUDItem.Get().m_Item == this)
        {
            HUDItem.Get().Activate(item);
        }
        UnityEngine.Object.Destroy(base.gameObject);
        item.transform.rotation = rotation;
        item.transform.position = position;
    }
Exemple #22
0
    private bool ExecuteAction(HUDItem.Action action, Item item)
    {
        if (action != HUDItem.Action.Close && this.m_ItemReplacer != null)
        {
            item = this.m_ItemReplacer.ReplaceItem();
            this.m_ItemReplacer = null;
        }
        switch (action)
        {
        case HUDItem.Action.Close:
            this.SetActive(false);
            break;

        case HUDItem.Action.Take:
            if (item)
            {
                item.Take();
            }
            else if (this.m_PlantFruit)
            {
                this.m_PlantFruit.Take();
            }
            break;

        case HUDItem.Action.PickUp:
            item.PickUp(true);
            break;

        case HUDItem.Action.Eat:
            if (item)
            {
                item.Eat();
            }
            else if (this.m_PlantFruit)
            {
                this.m_PlantFruit.Eat();
            }
            break;

        case HUDItem.Action.Drink:
            if (item)
            {
                item.Drink();
            }
            else if (this.m_LiquidSource)
            {
                this.m_LiquidSource.Drink();
            }
            break;

        case HUDItem.Action.Harvest:
            Player.Get().HideWeapon();
            HarvestingSmallAnimalController.Get().SetItem(item);
            Player.Get().StartController(PlayerControllerType.HarvestingSmallAnimal);
            break;

        case HUDItem.Action.Craft:
            if (Player.Get().CanStartCrafting())
            {
                if (WalkieTalkieController.Get().IsActive())
                {
                    WalkieTalkieController.Get().Stop();
                }
                if (Player.Get().GetCurrentItem(Hand.Left) == item)
                {
                    Player.Get().SetWantedItem(Hand.Left, null, true);
                }
                else if (Player.Get().GetCurrentItem(Hand.Right) == item)
                {
                    Player.Get().SetWantedItem(Hand.Right, null, true);
                }
                else if (!item.m_CurrentSlot && item.m_InventorySlot && item.m_InventorySlot.m_Items.Count > 0)
                {
                    item.m_InventorySlot.RemoveItem(item, false);
                }
                else if (item.m_CurrentSlot && item.m_CurrentSlot.m_InventoryStackSlot)
                {
                    item.m_CurrentSlot.RemoveItem(item, false);
                }
                else if (item.m_CurrentSlot && item.m_CurrentSlot.m_WeaponRackParent)
                {
                    item.m_CurrentSlot.RemoveItem(item, false);
                }
                if (InventoryBackpack.Get().m_EquippedItem == item)
                {
                    InventoryBackpack.Get().m_EquippedItem = null;
                }
                InventoryBackpack.Get().RemoveItem(item, false);
                Storage3D.Get().RemoveItem(item, false);
                CraftingManager.Get().Activate();
                CraftingManager.Get().AddItem(item, true);
            }
            break;

        case HUDItem.Action.Fill:
            this.m_LiquidSource.TakeLiquid();
            break;

        case HUDItem.Action.Equip:
            Player.Get().Equip(item.m_CurrentSlot);
            break;

        case HUDItem.Action.Drop:
            if (CraftingManager.Get().gameObject.activeSelf&& CraftingManager.Get().ContainsItem(item))
            {
                CraftingManager.Get().RemoveItem(item, false);
            }
            if (!item.m_CurrentSlot && item.m_InventorySlot && item.m_InventorySlot.m_Items.Count > 0)
            {
                item.m_InventorySlot.RemoveItem(item, false);
            }
            else if (item.m_CurrentSlot && item.m_CurrentSlot.m_InventoryStackSlot)
            {
                item.m_CurrentSlot.RemoveItem(item, false);
            }
            if (InventoryBackpack.Get().m_EquippedItem == item)
            {
                InventoryBackpack.Get().m_EquippedItem = null;
            }
            InventoryBackpack.Get().RemoveItem(item, false);
            Inventory3DManager.Get().DropItem(item);
            break;

        case HUDItem.Action.Swap:
            item.Swap();
            break;

        case HUDItem.Action.Use:
            if (this.m_Item.IsStorage())
            {
                Storage3D.Get().Activate((Storage)this.m_Item);
            }
            else if (MakeFireController.Get().IsActive())
            {
                InventoryBackpack.Get().RemoveItem(this.m_Item, false);
                MakeFireController.Get().InsertItemToKindlingSlot(this.m_Item);
            }
            else
            {
                Item currentItem = Player.Get().GetCurrentItem();
                if (currentItem)
                {
                    InventoryBackpack.Get().InsertItem(currentItem, InventoryBackpack.Get().m_EquippedItemSlot, null, true, true, true, true, false);
                    Player.Get().SetWantedItem(currentItem.m_Info.IsBow() ? Hand.Left : Hand.Right, null, true);
                    if (Player.Get().m_ControllerToStart != PlayerControllerType.Unknown)
                    {
                        Player.Get().StartControllerInternal();
                    }
                }
                Player.Get().SetWantedItem(this.m_Item, true);
            }
            break;

        case HUDItem.Action.Spill:
            ((LiquidContainer)this.m_Item).Spill(-1f);
            break;

        case HUDItem.Action.Destroy:
            if (GreenHellGame.IsPadControllerActive() && !this.m_DestroyButton.confirm.gameObject.activeSelf)
            {
                this.m_DestroyButton.confirm.gameObject.SetActive(true);
                this.m_DestroyButton.confirm_sel.gameObject.SetActive(true);
                return(false);
            }
            if (!this.m_DestroyButton.confirm_sel.gameObject.activeSelf)
            {
                return(true);
            }
            if (CraftingManager.Get().gameObject.activeSelf&& CraftingManager.Get().ContainsItem(item))
            {
                CraftingManager.Get().RemoveItem(item, false);
            }
            if (!item.m_CurrentSlot && item.m_InventorySlot && item.m_InventorySlot.m_Items.Count > 0)
            {
                item.m_InventorySlot.RemoveItem(item, false);
            }
            else if (item.m_CurrentSlot && item.m_CurrentSlot.m_InventoryStackSlot)
            {
                item.m_CurrentSlot.RemoveItem(item, false);
            }
            if (InventoryBackpack.Get().m_EquippedItem == item)
            {
                InventoryBackpack.Get().m_EquippedItem = null;
            }
            InventoryBackpack.Get().RemoveItem(item, false);
            UnityEngine.Object.Destroy(item.gameObject);
            break;

        case HUDItem.Action.Take3:
            if (item)
            {
                item.Take3();
            }
            break;

        case HUDItem.Action.TakeAll:
            if (item)
            {
                item.TakeAll();
            }
            break;

        case HUDItem.Action.TakeClay:
            if (this.m_LiquidSource)
            {
                this.m_LiquidSource.TakeClay();
            }
            break;

        case HUDItem.Action.CleanUp:
            PlayerArmorModule.Get().SetMeshesVisible(true);
            BodyInspectionController.Get().OnArmorMeshesEnabled();
            Player.Get().m_Animator.SetBool(Player.Get().m_CleanUpHash, false);
            break;

        case HUDItem.Action.DestroyStack:
            if (GreenHellGame.IsPadControllerActive() && !this.m_DestroyStackButton.confirm.gameObject.activeSelf)
            {
                this.m_DestroyStackButton.confirm.gameObject.SetActive(true);
                this.m_DestroyStackButton.confirm_sel.gameObject.SetActive(true);
                return(false);
            }
            if (!this.m_DestroyStackButton.confirm_sel.gameObject.activeSelf)
            {
                return(true);
            }
            if (!item.m_CurrentSlot && item.m_InventorySlot && item.m_InventorySlot.m_Items.Count > 0)
            {
                UnityEngine.Object.Destroy(item.gameObject);
            }
            else if (item.m_CurrentSlot && item.m_CurrentSlot.m_InventoryStackSlot)
            {
                UnityEngine.Object.Destroy(item.m_CurrentSlot.m_ItemParent.gameObject);
            }
            else if (item.m_CurrentSlot && item.m_CurrentSlot.m_BackpackSlot && item.m_CurrentSlot.IsStack())
            {
                for (int i = 0; i < ((ItemSlotStack)item.m_CurrentSlot).m_Items.Count; i++)
                {
                    UnityEngine.Object.Destroy(((ItemSlotStack)item.m_CurrentSlot).m_Items[i].gameObject);
                }
            }
            break;

        case HUDItem.Action.SwapArmor:
        {
            Limb      selectedLimb  = HUDBodyInspection.Get().GetSelectedLimb();
            ArmorData armorData     = PlayerArmorModule.Get().GetArmorData(selectedLimb);
            Item      attachedArmor = armorData.m_AttachedArmor;
            ItemSlot  currentSlot   = attachedArmor.m_CurrentSlot;
            if (currentSlot != null)
            {
                currentSlot.RemoveItem();
            }
            PlayerArmorModule.Get().ArmorCarryStarted(attachedArmor);
            InventoryCellsGroup inventoryCellsGroup = this.m_Item.m_Info.m_InventoryCellsGroup;
            InventoryBackpack.Get().RemoveItem(this.m_Item, false);
            if (attachedArmor.m_Info.m_InventoryRotated != this.m_Item.m_Info.m_InventoryRotated)
            {
                Inventory3DManager.Get().RotateItem(attachedArmor, false);
            }
            InventoryBackpack.Get().InsertItem(attachedArmor, null, inventoryCellsGroup, true, true, true, true, true);
            armorData.m_Slot.InsertItem(this.m_Item);
            break;
        }

        case HUDItem.Action.EquipArmor:
            InventoryBackpack.Get().RemoveItem(this.m_Item, false);
            PlayerArmorModule.Get().GetArmorData(HUDBodyInspection.Get().GetSelectedLimb()).m_Slot.InsertItem(this.m_Item);
            break;

        case HUDItem.Action.Insert:
            if (HUDItemSlot.Get().m_SelectedSlotData == null)
            {
                return(false);
            }
            if (!HUDItemSlot.Get().m_SelectedSlotData.slot.CanInsertItem(this.m_Item))
            {
                ((HUDMessages)HUDManager.Get().GetHUD(typeof(HUDMessages))).AddMessage(GreenHellGame.Instance.GetLocalization().Get("HUD_CannotInsertItem", true), new Color?(Color.red), HUDMessageIcon.None, "", null);
                return(true);
            }
            if (this.m_Item.m_Storage)
            {
                this.m_Item.m_Storage.RemoveItem(this.m_Item, false);
            }
            InventoryBackpack.Get().RemoveItem(this.m_Item, false);
            HUDItemSlot.Get().m_SelectedSlotData.slot.InsertItem(this.m_Item);
            break;

        case HUDItem.Action.Pick:
            Inventory3DManager.Get().StartCarryItem(this.m_Item, false);
            break;

        case HUDItem.Action.TakeOffArmor:
        {
            Item attachedArmor2 = PlayerArmorModule.Get().GetArmorData(HUDBodyInspection.Get().GetSelectedLimb()).m_AttachedArmor;
            if (attachedArmor2)
            {
                PlayerArmorModule.Get().ArmorCarryStarted(attachedArmor2);
                InventoryBackpack.Get().InsertItem(attachedArmor2, null, null, true, true, true, true, true);
            }
            break;
        }

        case HUDItem.Action.Plow:
        {
            Acre acre = (this.m_Item && this.m_Item.IsAcre()) ? ((Acre)this.m_Item) : null;
            if (!acre)
            {
                return(true);
            }
            acre.Plow();
            break;
        }

        case HUDItem.Action.PickStack:
            Inventory3DManager.Get().StartCarryItem(this.m_Item, true);
            break;
        }
        return(true);
    }