Esempio n. 1
0
            public void ItemSlot_With_3_Quant_Gets_Added_To_Next_Slot_If_First_Full()
            {
                var itemContainer = new ItemContainer(2);
                var invItemStub   = InventoryItemFake(5);
                var itemSlot      = new ItemSlot(invItemStub.Object, 5);
                var expectedSlot  = new ItemSlot(invItemStub.Object, 3);

                itemContainer.AddItem(itemSlot);
                itemContainer.AddItem(expectedSlot);

                Assert.AreEqual(expectedSlot, itemContainer[1]);
            }
Esempio n. 2
0
            public void ItemSlot_Returned_With_6_Quantity_MaxStack_5_When_Added_To_2_With_9_And_Container_Full()
            {
                var itemContainer = new ItemContainer(1);
                var invItemStub   = InventoryItemFake(5);
                var itemSlot      = new ItemSlot(invItemStub.Object, 9);
                var expectedSlot  = new ItemSlot(invItemStub.Object, 6);

                itemContainer.AddItem(new ItemSlot(invItemStub.Object, 2));
                ItemSlot slot = itemContainer.AddItem(itemSlot);

                Assert.AreEqual(expectedSlot, slot);
            }
Esempio n. 3
0
            public void Adds_To_Next_Slot_If_ItemSlots_MaxStack_3_Quant_2_MaxStack_4_Quant_3_With_Different_Items()
            {
                var itemContainer = new ItemContainer(3);
                var invItemStub1  = InventoryItemFake(3);
                var invItemStub2  = InventoryItemFake(4);
                var itemSlot1     = new ItemSlot(invItemStub1.Object, 2);
                var itemSlot2     = new ItemSlot(invItemStub2.Object, 3);

                itemContainer.AddItem(itemSlot1);
                itemContainer.AddItem(itemSlot2);

                Assert.AreEqual(itemSlot2, itemContainer[1]);
            }
    private void BtnRightClick(ButtonExpand buttonExpand, PointerEventData eventData)
    {
        //Debug.Log("Right Click");
        EventSystem.current.SetSelectedGameObject(null);
        SlotData      curSlotData  = (SlotData)buttonExpand.transform.parent.GetComponent <ItemSlot>().data;
        ItemContainer curContainer = GetTagContainer(curSlotData.slotType);

        if (curDragItem != null)
        {
            curContainer.AddItem(DragItem(null));
        }
        else
        {
            ItemEntity oldItem = curContainer.GetItemFromSlot(curSlotData.slotIndex);
            if (oldItem != null)
            {
                if (oldItem.itemCount > 1)
                {
                    int halfCount = oldItem.itemCount / 2;
                    oldItem.Cost(halfCount);
                    ItemEntity tagItem = new ItemEntity(oldItem, halfCount);
                    DragItem(tagItem);
                }
                else
                {
                    curContainer.RemoveItemFromSlot(curSlotData.slotIndex);
                    DragItem(oldItem);
                }
            }
        }
        RefreshInventory();
    }
Esempio n. 5
0
            public void Call_With_Same_Positive_InBounds_Index_Returns_With_No_Change_In_Container(int index)
            {
                var itemContainer = new ItemContainer(20);
                var invItemStub   = InventoryItemFake(4);
                var slotOne       = new ItemSlot(invItemStub.Object, 4);
                var slotTwo       = new ItemSlot(invItemStub.Object, 2);

                itemContainer.AddItem(slotOne);
                itemContainer.AddItem(slotTwo);
                itemContainer.Swap(index, index);

                var itemOneEquivalent = itemContainer[0] == slotOne;
                var itemTwoEquivalent = itemContainer[1] == slotTwo;

                Assert.True(itemOneEquivalent && itemTwoEquivalent);
            }
Esempio n. 6
0
        protected override void PostItemContainerTick()
        {
            // Check the things that are on the ground at our position
            // If the thing can be moved and the destination is empty it can be added to our container
            // This should fix the "pawn carry items to the loader all the time"-bug
            foreach (var thing in Find.ThingGrid.ThingsAt(parent.Position))
            {
                if ((thing.def.category == EntityCategory.Item) && (thing != parent))
                {
                    var destination = GetDestinationForThing(thing);
                    var destBelt    = destination.GetBeltComponent();

                    if (destBelt == null)
                    {
                        continue;
                    }

                    // Do not load items unless the next element can accept it
                    if (!destBelt.CanAcceptFrom(this))
                    {
                        continue;
                    }

                    ItemContainer.AddItem(thing, BeltSpeed / 2);
                }
            }
        }
Esempio n. 7
0
        protected override void OnItemActivated(bool activated)
        {
            base.OnItemActivated(activated);
            if (activated)
            {
                this.m_IsReloading = false;

                if (this.m_CurrentClipSize > 0)
                {
                    CreateCurrentProjectile();
                }
            }
            else
            {
                if (this.m_ResetClipSize)
                {
                    if (this.m_CurrentClipSize > 0)
                    {
                        Item item = Instantiate(m_ProjectileItem);
                        item.Stack = this.m_CurrentClipSize;
                        ItemContainer.AddItem(this.m_ProjectileItemWindow, item);
                    }
                    this.m_CurrentClipSize = 0;
                }
                if (this.m_CurrentProjectile != null)
                {
                    Destroy(this.m_CurrentProjectile);
                }
            }
        }
Esempio n. 8
0
            public void Does_Nothing_If_Called_With_Negative_Quant(int xQuant)
            {
                var itemContainer = new ItemContainer(3);
                var invItemStub   = InventoryItemFake(3);
                var itemSlot      = new ItemSlot(invItemStub.Object, xQuant);

                itemContainer.AddItem(itemSlot);

                Assert.AreEqual(ItemSlot.Empty, itemContainer[0]);
            }
Esempio n. 9
0
            public void Returns_Same_Slot_If_No_Space_In_Container(int xQuant)
            {
                var itemContainer = new ItemContainer(0);
                var invItemStub   = InventoryItemFake(5);
                var itemSlot      = new ItemSlot(invItemStub.Object, xQuant);

                var newSlot = itemContainer.AddItem(itemSlot);

                Assert.AreEqual(itemSlot, newSlot);
            }
Esempio n. 10
0
            public void ItemSlot_With_Max_Quant_Gets_Added_To_Empty_Slot(int xQuant)
            {
                var itemContainer = new ItemContainer(2);
                var invItemStub   = InventoryItemFake(xQuant);
                var itemSlot      = new ItemSlot(invItemStub.Object, xQuant);

                itemContainer.AddItem(itemSlot);

                Assert.AreEqual(itemSlot, itemContainer[0]);
            }
    void Pickup()
    {
        if (registeredItems.Count == 0)
        {
            return;
        }

        container.AddItem(registeredItems[0]);
        registeredItems[0].OutlineOff();
    }
Esempio n. 12
0
    private void TransferToItemContainer(BaseItemSlot itemSlot)
    {
        Item item = itemSlot.Item;

        if (item != null && openItemContainer.CanAddItem(item))
        {
            Inventory.RemoveItem(item);
            openItemContainer.AddItem(item);
        }
    }
Esempio n. 13
0
            public void Swapping_Separate_Items_Swaps_Their_Positions()
            {
                var itemContainer  = new ItemContainer(20);
                var invItemStubOne = InventoryItemFake(5, "Stringo mock");
                var invItemStubTwo = InventoryItemFake(5, "Mujahadeenoo");
                var slotOne        = new ItemSlot(invItemStubOne.Object, 1);
                var slotTwo        = new ItemSlot(invItemStubTwo.Object, 2);

                itemContainer.AddItem(slotOne);
                itemContainer.AddItem(slotTwo);
                itemContainer.Swap(0, 1);

                var indexOneSlot      = itemContainer[0];
                var indexTwoSlot      = itemContainer[1];
                var itemOneEquivalent = indexOneSlot == slotTwo;
                var itemTwoEquivalent = indexTwoSlot == slotOne;

                Assert.True(itemOneEquivalent && itemTwoEquivalent);
            }
Esempio n. 14
0
            public void Adding_Positive_X_Quantity_Returns_X(int xQuant)
            {
                var itemContainer = new ItemContainer(20);
                var invItemStub   = InventoryItemFake(5);

                itemContainer.AddItem(new ItemSlot(invItemStub.Object, xQuant));
                int totalQuant = itemContainer.GetTotalQuantity(invItemStub.Object);

                Assert.AreEqual(xQuant, totalQuant);
            }
Esempio n. 15
0
            public void Returns_True_After_Item_Is_Added()
            {
                ItemContainer itemContainer = new ItemContainer(20);
                var           invItemStub   = InventoryItemFake();
                var           itemSlot      = new ItemSlot(invItemStub.Object, 3);

                itemContainer.AddItem(itemSlot);
                bool hasItem = itemContainer.HasItem(itemSlot.invItem);

                Assert.True(hasItem);
            }
Esempio n. 16
0
            public void ItemSlot_With_6_Quantity_MaxStack_5_Fills_Container_With_1_Space_Up()
            {
                var itemContainer = new ItemContainer(1);
                var invItemStub   = InventoryItemFake(5);
                var itemSlot      = new ItemSlot(invItemStub.Object, 6);
                var expectedSlot  = new ItemSlot(invItemStub.Object, invItemStub.Object.MaxStack);

                itemContainer.AddItem(itemSlot);

                Assert.AreEqual(expectedSlot, itemContainer[0]);
            }
Esempio n. 17
0
            // this test needs to be renamed properly
            public void ItemSlot_Returned_With_0_Quantity_When_Added_With_Positive_X_Quant_Slot(int xQuant)
            {
                var itemContainer = new ItemContainer(20);
                var invItemStub   = InventoryItemFake(5);
                var itemSlot      = new ItemSlot(invItemStub.Object, xQuant);
                var expectedSlot  = new ItemSlot(invItemStub.Object, 0);

                ItemSlot slot = itemContainer.AddItem(itemSlot);

                Assert.AreEqual(expectedSlot, slot);
            }
Esempio n. 18
0
            public void Calling_With_Index_10_Clears_Slot_At_Index_10()
            {
                var itemContainer = new ItemContainer(20);
                var invItemStub   = InventoryItemFake(1);

                itemContainer.AddItem(new ItemSlot(invItemStub.Object, 12));
                itemContainer.RemoveAt(10, 12);
                var slot = itemContainer[10];

                Assert.AreEqual(ItemSlot.Empty, slot);
            }
Esempio n. 19
0
            public void Swapping_Quantity_5_With_3_Sets_Slots_Second_To_5_First_To_3_With_MaxStack_5()
            {
                var itemContainer   = new ItemContainer(20);
                var invItemStub     = InventoryItemFake(5);
                var slotOne         = new ItemSlot(invItemStub.Object, 5);
                var slotTwo         = new ItemSlot(invItemStub.Object, 3);
                var expectedSlotOne = new ItemSlot(invItemStub.Object, 3);
                var expectedSlotTwo = new ItemSlot(invItemStub.Object, 5);

                itemContainer.AddItem(slotOne);
                itemContainer.AddItem(slotTwo);
                itemContainer.Swap(0, 1);

                var indexOneSlot      = itemContainer[0];
                var indexTwoSlot      = itemContainer[1];
                var itemOneEquivalent = indexOneSlot == expectedSlotOne;
                var itemTwoEquivalent = indexTwoSlot == expectedSlotTwo;

                Assert.True(itemOneEquivalent && itemTwoEquivalent);
            }
Esempio n. 20
0
        public override ActionStatus OnUpdate()
        {
            Item instance = InventoryManager.CreateInstance(this.m_Item);

            instance.Stack = this.m_Amount;
            if (ItemContainer.AddItem(this.m_WindowName, instance))
            {
                return(ActionStatus.Success);
            }
            return(ActionStatus.Failure);
        }
Esempio n. 21
0
            public void Calling_With_Less_Than_MaxStack_Doesnt_Remove_Entire_Stack()
            {
                var itemContainer = new ItemContainer(20);
                var invItemStub   = InventoryItemFake(5);
                var slot          = new ItemSlot(invItemStub.Object, 5);
                var expectedSlot  = new ItemSlot(invItemStub.Object, 3);

                itemContainer.AddItem(slot);
                slot = itemContainer.Remove(new ItemSlot(invItemStub.Object, 8));

                Assert.AreEqual(expectedSlot, slot);
            }
Esempio n. 22
0
            public void Calling_With_MaxStack_Removes_MaxStack()
            {
                var itemContainer = new ItemContainer(20);
                var invItemStub   = InventoryItemFake(5);
                var slot          = new ItemSlot(invItemStub.Object, 5);

                itemContainer.AddItem(slot);
                itemContainer.Remove(slot);
                slot = itemContainer[0];

                Assert.AreEqual(ItemSlot.Empty, slot);
            }
Esempio n. 23
0
            public void Calling_With_Index_4_Clears_Slot_At_Index_4()
            {
                var itemContainer = new ItemContainer(20);
                var invItemStub   = InventoryItemFake(4);
                var expectedSlot  = new ItemSlot(invItemStub.Object, 3);

                itemContainer.AddItem(new ItemSlot(invItemStub.Object, 5));
                itemContainer.RemoveAt(0);
                var slot = itemContainer[0];

                Assert.AreEqual(expectedSlot, slot);
            }
Esempio n. 24
0
 public void AddItem(Item item)
 {
     itemContainer.AddItem(item);
     if (isDeath)
     {
         StartCoroutine(itemContainer.ShowItemDialog(itemDialogs.Random()));
     }
     else
     {
         StartCoroutine(itemContainer.ShowItemDialog(item));
     }
 }
Esempio n. 25
0
        //
        // Add custom item to quarries on fuel consumed
        //
        void OnItemUse(Item item, int amountToUse)
        {
            try
            {
                if (BaseNetworkable.serverEntities.Find(item.parent.entityOwner.parentEntity.uid) is MiningQuarry)
                {
                    MiningQuarry quarry = BaseNetworkable.serverEntities.Find(item.parent.entityOwner.parentEntity.uid) as MiningQuarry;

                    if (quarry.canExtractLiquid)
                    {
                        return;
                    }

                    if (!permission.UserHasPermission(quarry.OwnerID.ToString(), "oldschoolquarries.customloot"))
                    {
                        return;
                    }

                    ItemContainer hopper = (quarry.hopperPrefab.instance as StorageContainer).inventory;

                    double value = (rng.Next(0, 100) + rng.NextDouble());
                    if (value > 100d)
                    {
                        value = 100d;
                    }
                    if (config.Custom_Items == null)
                    {
                        return;
                    }
                    foreach (CustomItem cItem in config.Custom_Items)
                    {
                        if (!cItem.valid || cItem.chance == 0 || cItem.amount == 0)
                        {
                            continue;
                        }
                        if (value <= cItem.chance)
                        {
                            try
                            {
                                hopper.AddItem(ItemManager.itemList.Find(x => x.shortname == cItem.shortname), cItem.amount);
                            }
                            catch { }
                        }
                    }
                }
            }
            catch { }
        }
Esempio n. 26
0
        public override ActionStatus OnUpdate()
        {
            Item instance = ScriptableObject.Instantiate(this.m_Item);

            if (this.m_Item.IsCraftable)
            {
                for (int j = 0; j < this.m_Item.ingredients.Count; j++)
                {
                    instance.ingredients[j].item       = ScriptableObject.Instantiate(this.m_Item.ingredients[j].item);
                    instance.ingredients[j].item.Stack = this.m_Item.ingredients[j].amount;
                }
            }
            if (ItemContainer.AddItem(this.m_WindowName, instance))
            {
                return(ActionStatus.Success);
            }
            return(ActionStatus.Failure);
        }
Esempio n. 27
0
    // Update is called once per frame
    void Update()
    {
        #region Movement
        horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

        if (Input.GetButtonDown("Jump"))
        {
            jump = true;
        }
        #endregion

        #region Break and place

        #region mouse
        MouseDistance = Vector3.Distance(mousePos, transform.position);
        mousePos      = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        #endregion

        if (Input.GetButtonDown("Fire1"))
        {
            if (MouseDistance < 11.5)
            {
                string Tilename = TileMap1.GetTile(TileMap1.WorldToCell(mousePos)).name;
                if (Tilename == null)
                {
                    Tilename = TileMap2.GetTile(TileMap2.WorldToCell(mousePos)).name;


                    TileMap2.SetTile(TileMap2.WorldToCell(mousePos), null);
                    Debug.Log(Tilename);

                    string[] GetTiles;
                    GetTiles = AssetDatabase.FindAssets($"{Tilename}", new[] { "Assets/Resources/Items" });

                    string        itemPath = AssetDatabase.GUIDToAssetPath(GetTiles[0]);
                    InventoryItem item     = (InventoryItem)AssetDatabase.LoadAssetAtPath(itemPath, typeof(InventoryItem));

                    itemContainer.AddItem(new ItemSlot(item, 1));
                }

                if (Tilename != null)
                {
                    TileMap1.SetTile(TileMap1.WorldToCell(mousePos), null);
                    Debug.Log(Tilename);

                    string[] GetTiles;
                    GetTiles = AssetDatabase.FindAssets($"{Tilename}", new[] { "Assets/Resources/Items" });

                    string        itemPath = AssetDatabase.GUIDToAssetPath(GetTiles[0]);
                    InventoryItem item     = (InventoryItem)AssetDatabase.LoadAssetAtPath(itemPath, typeof(InventoryItem));

                    itemContainer.AddItem(new ItemSlot(item, 1));
                }
            }
        }

        if (Input.GetButtonDown("Fire2"))
        {
            if (hotbar.selected.SlotItem is InventoryItem inventoryItem)
            {
                if (itemContainer.HasItem(inventoryItem))
                {
                    if (MouseDistance < 11.5)
                    {
                        string[] GetTiles;
                        if (PlaceBlock.name == "log")
                        {
                            GetTiles = AssetDatabase.FindAssets("Tree", new[] { "Assets/Resources/Items" });
                        }
                        else
                        {
                            GetTiles = AssetDatabase.FindAssets($"{PlaceBlock.name}", new[] { "Assets/Resources/Items" });
                        }
                        string        itemPath = AssetDatabase.GUIDToAssetPath(GetTiles[0]);
                        InventoryItem item     = (InventoryItem)AssetDatabase.LoadAssetAtPath(itemPath, typeof(InventoryItem));

                        if (TileMap1.GetTile(TileMap1.WorldToCell(mousePos)) == null)
                        {
                            TileMap1.SetTile(TileMap1.WorldToCell(mousePos), PlaceBlock);
                            itemContainer.UpdatedRemove(item, 1);
                        }
                    }
                }
            }
        }
        #endregion

        #region Block Selection

        #region KeyPresses
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            hotbar.Select(0);
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            hotbar.Select(1);
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            hotbar.Select(2);
        }
        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            hotbar.Select(3);
        }
        if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            hotbar.Select(4);
        }
        if (Input.GetKeyDown(KeyCode.Alpha6))
        {
            hotbar.Select(5);
        }
        if (Input.GetKeyDown(KeyCode.Alpha7))
        {
            hotbar.Select(6);
        }
        if (Input.GetKeyDown(KeyCode.Alpha8))
        {
            hotbar.Select(7);
        }
        if (Input.GetKeyDown(KeyCode.Alpha9))
        {
            hotbar.Select(8);
        }
        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            hotbar.Select(9);
        }
        #endregion

        hotbar.GetSelected();

        PlaceBlock = hotbar.selected.SlotItem.PlaceTile;
        #endregion
    }
Esempio n. 28
0
 private void FixedUpdate()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         if (!hasGrabd)
         {
             RaycastHit hit;
             if (Physics.Raycast(transform.position, transform.forward, out hit, Range))
             {
                 rb   = hit.transform.GetComponent <Rigidbody>();
                 ITEM = hit.transform.GetComponent <ItemInfo>();
                 if (rb != null && ITEM != null)
                 {
                     Vieta.position = rb.position;
                     rb.useGravity  = false;
                     hasGrabd       = true;
                 }
             }
         }
         else
         {
             if (ITEM.usable == true)
             {
                 ITEM.Use();
             }
             else
             {
                 rb.rotation   = Player.transform.rotation;
                 hasGrabd      = false;
                 rb.useGravity = true;
                 rb.AddForce(transform.forward * dropForce, ForceMode.Impulse);
             }
         }
     }
     if (Input.GetButtonDown("Fire2"))
     {
         if (hasGrabd)
         {
             rb.rotation   = Player.transform.rotation;
             hasGrabd      = false;
             rb.useGravity = true;
         }
         else
         {
             RaycastHit hit2;
             if (Physics.Raycast(transform.position, transform.forward, out hit2, Range))
             {
                 ITEM    = hit2.transform.GetComponent <ItemInfo>();
                 ITEM_Go = hit2.transform.gameObject;
                 if (ITEM != null && ITEM_Go != null)
                 {
                     ItemContainer.AddItem(ItemContainer.Contents, ITEM.Item);
                     ITEM_Go.SetActive(false);
                 }
             }
         }
     }
     if (hasGrabd)
     {
         Vector3 SmothPosition = Vector3.Lerp(rb.position, Vieta.position, GrabSpeed);
         rb.position = SmothPosition;
         rb.rotation = Player.transform.rotation;
     }
 }
Esempio n. 29
0
        public void LootItem(ItemObject lootItemObject, bool fillOnly = false)
        {
            if (lootItemObject.Item.IsStackEmpty)
            {
                return;
            }

            if (lootItemObject.Item is ShieldItem && lootItemObject.Item.Data is ArmorData)
            {
                EquipArmor(lootItemObject.Item as ShieldItem);
                LootAnimator.Instance.CreateNewLootAnimation(this, lootItemObject);
                lootItemObject.RequestDestroy();
            }
            else if (lootItemObject.Item.Data is BackpackData)
            {
                EquipBackpack(lootItemObject.Item);
                LootAnimator.Instance.CreateNewLootAnimation(this, lootItemObject);
                lootItemObject.RequestDestroy();
            }
            else if (lootItemObject.Item.Data is WeaponData)
            {
                EquipWeapon(lootItemObject.Item);
                LootAnimator.Instance.CreateNewLootAnimation(this, lootItemObject);
                lootItemObject.RequestDestroy();
            }
            else
            {
                int  previousStack = lootItemObject.Item.CurrentStack;
                Item remainItem    = fillOnly ? ItemContainer.FillItem(lootItemObject.Item) : ItemContainer.AddItem(lootItemObject.Item);

                if (previousStack != remainItem.CurrentStack)
                {
                    LootAnimator.Instance.CreateNewLootAnimation(this, lootItemObject);
                    lootItemObject.Item = remainItem;

                    if (lootItemObject.Item.IsStackEmpty)
                    {
                        lootItemObject.RequestDestroy();
                    }
                    else
                    {
                        lootItemObject.NotifyUpdateCurrentStack();
                    }
                }
            }
        }
 private void AddCouponRewardItem(CouponRedeemedItemModel couponRewardItem)
 {
     itemsContainer.AddItem(itemPrefab).GetComponent <CouponRewardItemUI>().Initialize(couponRewardItem);
 }