コード例 #1
0
    public bool StickSticker(
        Script_Sticker sticker,
        Script_Equipment equipment,
        Script_Inventory inventory,
        int itemSlot,
        bool isBackground = false
        )
    {
        /// Try to equip, checking if we can equip it & if equipment is full
        int equipmentSlotId;

        if (equipment.HasSpace() && equipment.AddSticker(sticker, out equipmentSlotId))
        {
            /// On successful equip, remove sticker from Inventory
            /// and also update Sticker Holster (done in Equipment)
            inventory.RemoveItemInSlot(itemSlot);

            if (!isBackground)
            {
                StickerOnSFX();
            }

            return(true);
        }
        else
        {
            Debug.Log("Failed to equip sticker");
            GetComponent <Script_InventoryManager>().ErrorDullSFX();
            return(false);
        }
    }
コード例 #2
0
    public bool UnstickSticker(
        Script_Sticker sticker,
        Script_Equipment equipment,
        Script_Inventory inventory,
        int stickerSlotId,
        bool isBackground = false
        )
    {
        // try to unequip, checking if inventory is full
        if (equipment.RemoveStickerInSlot(stickerSlotId))
        {
            /// On successful unequip, remove sticker from Equipment
            /// and also update Sticker Holster (done in Equipment)
            inventory.AddItem(sticker);

            if (!isBackground)
            {
                StickerOffSFX();
            }

            return(true);
        }
        else
        {
            Debug.LogWarning("Failed to unstick sticker; no space in inventory or not found");
            // TODO: show messaging or SFX
            GetComponent <Script_InventoryManager>().ErrorDullSFX();

            return(false);
        }
    }
コード例 #3
0
 bool UnstickSticker(
     Script_Sticker sticker,
     Script_Equipment equipment,
     Script_Inventory inventory,
     int stickerSlotId,
     bool isBackground = false
     )
 {
     return(stickersHandler.UnstickSticker(sticker, equipment, inventory, stickerSlotId, isBackground));
 }
コード例 #4
0
    private bool StickSticker(
        Script_Sticker sticker,
        Script_Equipment equipment,
        Script_Inventory inventory,
        int itemSlotId
        )
    {
        if (stickersHandler.StickSticker(sticker, equipment, inventory, itemSlotId))
        {
            /// Hide ItemChoices must come before hydrating slots;
            /// otherwise, will trigger a deselect and select on the slot
            /// due to exiting its EventSystem causing a flicker
            HideItemChoices();
            EnterInventory();
            return(true);
        }

        return(false);
    }
コード例 #5
0
    // Use this for initialization
    void Awake()
    {
        if (_instance != null)
        {
            Debug.LogError("Creating multiple GameManagers!");
        }
        _instance = this;

        Inventory         = new Script_Inventory();
        CharacterManager  = new Script_CharacterManager();
        UIManager         = new Script_UIManager();
        CombatTextManager = new Script_CombatTextManager();

        Inventory.AddItem(new Script_HealthPotion(), 15);
        //Give player sword to start with
        var sword = new Script_Sword();

        Inventory.AddItem(sword);
        CharacterManager.GetCharacters()[0].EquipItem(sword);
    }
コード例 #6
0
    public bool HotKeyStickUnstick(
        Script_Equipment equipment,
        Script_Inventory inventory,
        int inventorySlot,
        int equipmentSlot,
        bool isBackground = false
        )
    {
        try
        {
            // Cache and remove the sticker if it is not Active Sticker
            Script_Sticker equipmentSticker = equipment.GetStickerInSlot(equipmentSlot);
            var            activeSticker    = Script_ActiveStickerManager.Control.ActiveSticker;

            // If there is an Active Sticker, warn Player if it's the equipment sticker trying
            // to be switched out.
            if (activeSticker != null && activeSticker == equipmentSticker)
            {
                return(OnIsActiveEquippedError());
            }

            equipment.RemoveStickerInSlot(equipmentSlot);

            // Cache and remove the sticker in specified inventory slot.
            Script_Sticker inventorySticker = inventory.GetItemInSlot(inventorySlot) as Script_Sticker;
            inventory.RemoveItemInSlot(inventorySlot);

            if (inventorySticker != null)
            {
                equipment.AddStickerInSlot(inventorySticker, equipmentSlot);
            }

            if (equipmentSticker != null)
            {
                inventory.AddItemInSlot(equipmentSticker, inventorySlot);
            }

            // Error SFX if trying to hotkey switch when both designated slots are empty.
            if (inventorySticker == null && equipmentSticker == null)
            {
                return(OnError());
            }

            if (!isBackground)
            {
                // If we only removed from equipment and added to inventory,
                // it's an unequip event.
                if (inventorySticker == null && equipmentSticker != null)
                {
                    StickerOffSFX();
                }
                else
                {
                    StickerOnSFX();
                }
            }

            return(true);
        }
        catch (System.Exception e)
        {
            Debug.LogError($"Failed HotKeyStickUnstick with Error:\n{e}");

            return(OnError());
        }

        bool OnIsActiveEquippedError()
        {
            GetComponent <Script_InventoryManager>().ErrorUnableSFX();
            return(false);
        }

        bool OnError()
        {
            GetComponent <Script_InventoryManager>().ErrorDullSFX();
            return(false);
        }
    }