コード例 #1
0
    public void ActivateButton()
    {
        if (selected < 0)
        {
            return;
        }
        refreshNeeded = false;
        InventoryItem item = data.inventory[selected];

        if (item.itemType == "Weapon")
        {
            EquipWeapon();
        }
        else if (item.itemType == "Armor")
        {
            EquipArmor();
        }
        else if (item.itemType == "Potion")
        {
            item.Activate(player);
            if (item.count == 0)
            {
                data.inventory.RemoveAt(selected);
                refreshNeeded = true;
            }
            UpdateBars();
        }
        else if (item.itemType == "Food")
        {
            if ((item as Food).damage >= player.hp)  // Not enough hp!
            {
                button.text = "No HP";
                return;
            }
            item.Activate(player);
            if (item.count == 0)
            {
                data.inventory.RemoveAt(selected);
                refreshNeeded = true;
            }
            UpdateBars();
        }
        // End the player's turn if in combat
        if (player.inCombat)
        {
            BackToScene();
            player.EndTurn();
        }
        else
        {
            RefreshItems();
        }
    }
コード例 #2
0
    private void ScrollWeapons()
    {
        // Scroll up, through the item slots
        if (Input.GetAxis("Mouse ScrollWheel") > 0.0f)
        {
            int currentSlot = items.IndexOf(currentItem);

            // At the first slot
            if (currentSlot == 0)
            {
                // Deactivate previous item, and activate new item
                currentItem.Deactivate();
                currentItem = items[items.Count - 1];
                currentItem.Activate();
            }
            // Not at the first slot
            else if ((currentSlot > 0) && (currentSlot < items.Count))
            {
                // Deactivate previous item, and activate new item
                currentItem.Deactivate();
                currentItem = items[currentSlot - 1];
                currentItem.Activate();
            }
            // At an invalid slot
            else if ((currentSlot < 0) || (currentSlot >= items.Count))
            {
                Debug.LogError("Invalid item slot in use!");
            }
        }
        // Scroll down, through the item slots
        else if (Input.GetAxis("Mouse ScrollWheel") < 0.0f)
        {
            int currentSlot = items.IndexOf(currentItem);

            // At the last slot
            if (currentSlot == (items.Count - 1))
            {
                // Deactivate previous item, and activate new item
                currentItem.Deactivate();
                currentItem = items[0];
                currentItem.Activate();
            }
            // Not at the last slot
            else if ((currentSlot >= 0) && (currentSlot < (items.Count - 1)))
            {
                // Deactivate previous item, and activate new item
                currentItem.Deactivate();
                currentItem = items[currentSlot + 1];
                currentItem.Activate();
            }
            // At an invalid slot
            else if ((currentSlot < 0) || (currentSlot >= items.Count))
            {
                Debug.LogError("Invalid item slot in use!");
            }
        }
    }
コード例 #3
0
    // Use this for initialization
    void Start()
    {
        // Start with item in the first item slot
        currentItem = items[0];
        //currentItem.gameObject.SetActive(true);
        currentItem.Activate();

        // Make sure all other items are diabled, except for the first one
        for (int i = 1; i < items.Count; i++)
        {
            //items[i].gameObject.SetActive(false);
            items[i].Deactivate();
        }
    }
コード例 #4
0
        public override void Handle(ActivateInventoryItemCommand command)
        {
            IEnumerable <IEvent> nonAppliedEvents = _repository.GetNonAppliedEvents(command.Id, command.Version);

            bool conflicting = _conflictRegistry.IsConflicting(nonAppliedEvents, command);

            if (conflicting)
            {
                throw new Exception();
            }

            InventoryItem inventoryItem = _repository.GetById(command.Id);

            inventoryItem.LoadFromHistory(nonAppliedEvents);

            inventoryItem.Activate();

            _repository.Save(inventoryItem);
        }