Ejemplo n.º 1
0
 public void SellAll(IInventoryOwner owner, Inventory inv)
 {
     for (int j = 0; j < inv.size; j++)
     {
         Sell(inv, j, owner);
     }
 }
Ejemplo n.º 2
0
        public void Buy(int index, IInventoryOwner owner)
        {
            if (index >= itemShops.Count)
            {
                return;
            }
            var buyItem = itemShops[index];

            if (CanBuy(owner, buyItem))
            {
                return;
            }
            if (OwnerHasSpace(owner, buyItem.Item) == false)
            {
                return;
            }
            var inventories = owner.GetInventories();
            var count       = buyItem.Item.count;

            for (int i = 0; i < inventories.Count; i++)
            {
                var space = inventories[i].CountOfSpaceForItem(buyItem.Item);
                var add   = Mathf.Min(count, space);
                inventories[i].AddItem(buyItem.Item, add);
                count -= add;
            }
            owner.RemoveCurrency(buyItem.Cost);
        }
Ejemplo n.º 3
0
 public void SetShop(InventoryShop shop, IInventoryOwner customer)
 {
     this.shop     = shop;
     this.customer = customer;
     FillGrid(shop.Size);
     UpdateView();
 }
Ejemplo n.º 4
0
 static void RemoveShield(IInventoryOwner character)
 {
     foreach (var item in character.Inventory.GetItems(x => x.Position == CharacterInventoryPositionEnum.ACCESSORY_POSITION_SHIELD))
     {
         character.Inventory.MoveItem(item, CharacterInventoryPositionEnum.INVENTORY_POSITION_NOT_EQUIPED);
     }
 }
Ejemplo n.º 5
0
        public void SellAll(IInventoryOwner owner)
        {
            var inventories = owner.GetInventories();

            for (int i = 0; i < inventories.Count; i++)
            {
                SellAll(owner, inventories[i]);
            }
        }
Ejemplo n.º 6
0
        public bool CanCraft(IInventoryOwner owner, int index)
        {
            int selectRecipe = SelectRecipe(owner, index);

            if (selectRecipe == -1)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 7
0
        public bool CanCraft(IInventoryOwner owner, int index, int recipeIndex)
        {
            var itemCraft   = list[index];
            var inventories = owner.GetInventories();
            var recipes     = itemCraft.GetRecipes();

            var  selectedRecipe = recipes[recipeIndex];
            bool result         = OwnerHasEnoughItemsForRecipe(inventories, selectedRecipe);

            return(result);
        }
Ejemplo n.º 8
0
        public void Craft(IInventoryOwner owner, int index)
        {
            if (index >= list.Count)
            {
                return;
            }
            var select = SelectRecipe(owner, index);

            if (select == -1)
            {
                return;
            }
            Craft(owner, index, select);
        }
Ejemplo n.º 9
0
        bool OwnerHasSpace(IInventoryOwner owner, Item item)
        {
            var inventories = owner.GetInventories();
            var freeSpace   = 0;

            for (int i = 0; i < inventories.Count; i++)
            {
                if (inventories[i].HaveSpaceForItem(item))
                {
                    freeSpace += inventories[i].CountOfSpaceForItem(item);
                }
            }
            return(freeSpace >= item.count);
        }
Ejemplo n.º 10
0
        public void Sell(Inventory inv, int itemIndex, IInventoryOwner owner)
        {
            var item = inv.GetItem(itemIndex);

            if (item == Item.Empty)
            {
                return;
            }
            var count = inv.GetItem(itemIndex).count;

            inv.RemoveItemAt(itemIndex);
            var gain = GetSellValueForItem(item) * count;

            owner.AddCurrency(gain);
        }
Ejemplo n.º 11
0
        private static void RemoveItems(IInventoryOwner owner, CraftingRecipe selectedRecipe)
        {
            var inventories = owner.GetInventories();

            for (int i = 0; i < selectedRecipe.items.Count; i++)
            {
                var count = selectedRecipe.counts[i];
                for (int inv = 0; inv < inventories.Count; inv++)
                {
                    var remove = Mathf.Min(count, inventories[inv].CountOfItem(selectedRecipe.items[i]));
                    inventories[inv].RemoveItem(selectedRecipe.items[i], remove);
                    count -= remove;
                }
            }
        }
Ejemplo n.º 12
0
        private int SelectRecipe(IInventoryOwner owner, int index)
        {
            var itemCraft = list[index];
            var recipes   = itemCraft.GetRecipes();

            for (int r = 0; r < recipes.Count; r++)
            {
                if (CanCraft(owner, index, r) == true)
                {
                    return(r);
                }
            }

            return(-1);
        }
Ejemplo n.º 13
0
        private static void AddItems(ItemCrafting itemCraft, IInventoryOwner owner)
        {
            var inventories = owner.GetInventories();
            var result      = itemCraft.GetItems();

            for (int inv = 0; inv < inventories.Count; inv++)
            {
                for (int i = 0; i < result.Count; i++)
                {
                    if (inventories[inv].HaveSpaceForItem(result[i]))
                    {
                        inventories[inv].AddItem(result[i], result[i].count);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public void Craft(IInventoryOwner owner, int index, int selectRecipe)
        {
            if (index >= list.Count)
            {
                return;
            }
            if (CanCraft(owner, index, selectRecipe) == false)
            {
                return;
            }
            var itemCraft = list[index];
            var recipes   = itemCraft.GetRecipes();

            RemoveItems(owner, recipes[selectRecipe]);
            AddItems(itemCraft, owner);
        }
        private void Switch(ExtendedAction extendedAction)
        {
            List <IInventoryOwner> allies = GetLeftSideAllies();

            if (allies.Count < 2)
            {
                return;
            }

            Int32 newIndex = SwitchCurrentCharacterIndex(extendedAction, allies);

            if (newIndex == -1)
            {
                return;
            }

            IInventoryOwner leftAlly = allies[newIndex];

            ChangeLeftBackpack(leftAlly);

            _hud.TradeBoxText.text = leftAlly.DisplayName;
        }
Ejemplo n.º 16
0
        //public bool InventoryAcceptsItem(Loot loot)
        //{
        //  return true;
        //}

        public virtual bool GetGoldWhenSellingTo(IInventoryOwner other)
        {
            return(false);
        }
Ejemplo n.º 17
0
 public Inventory(IInventoryOwner owner)
 {
     this.Owner = owner;
 }
Ejemplo n.º 18
0
 internal void UpdateView(IInventoryOwner customer, InventoryShop shop, int i)
 {
     text.text      = shop.GetCost(i).ToString();
     display.sprite = shop.GetUIDisplay(i);
     display.color  = shop.CanBuy(customer, i) ? Color.white : Color.gray;
 }
Ejemplo n.º 19
0
 public bool CanBuy(IInventoryOwner owner, int index)
 {
     return(owner.GetCurrentCurency() < itemShops[index].Cost);
 }
Ejemplo n.º 20
0
 public bool CanBuy(IInventoryOwner owner, ItemShop buyItem)
 {
     return(owner.GetCurrentCurency() < buyItem.Cost);
 }
 private void ChangeLeftBackpack(IInventoryOwner character)
 {
     _hud.LeftInventory = character.Inventory;
     _hud.LeftBackpack.SetMaxWeigth(character.MaxCarryWeight);
     _hud.ShowBackpackWithCost(_hud.LeftBackpack, character.Inventory);
 }