Esempio n. 1
0
        /// <summary>
        /// Configures the spy to call-through to throw the given exception when
        /// the spied-on method is called.
        /// </summary>
        /// <returns>The spy.</returns>
        public SpyWithBehaviour Throw(Exception exception)
        {
            ConstrainPreviousBehaviour();
            var behaviour = new ThrowBehaviour(exception);

            behaviour.ParameterChangesBeforeExecution = _parameterChanges;
            _spy.Behaviours.Enqueue(behaviour);
            return(new SpyWithBehaviour(_spy, behaviour));
        }
Esempio n. 2
0
        /// <summary>
        /// Configures the spy to call-through to throw an exception of the given type
        /// when the spied-on method is called.
        /// </summary>
        /// <returns>The spy.</returns>
        public SpyWithBehaviour Throw <TException>()
            where TException : Exception, new()
        {
            ConstrainPreviousBehaviour();
            var behaviour = new ThrowBehaviour(typeof(TException));

            behaviour.ParameterChangesBeforeExecution = _parameterChanges;
            _spy.Behaviours.Enqueue(behaviour);
            return(new SpyWithBehaviour(_spy, behaviour));
        }
Esempio n. 3
0
        /// <summary>
        /// Configures the spy to call-through to throw the given exception when
        /// the spied-on method is called.
        /// </summary>
        /// <returns>The spy.</returns>
        public SpyWithBehaviour Throw(Exception exception)
        {
            _spy.Behaviours.Clear();
            var behaviour = new ThrowBehaviour(exception);

            behaviour.UpdateLifetime(int.MaxValue);
            behaviour.ParameterChangesBeforeExecution = _parameterChanges;
            _spy.Behaviours.Enqueue(behaviour);
            return(new SpyWithBehaviour(_spy, behaviour));
        }
Esempio n. 4
0
        /// <summary>
        /// Configures the spy to call-through to throw an exception of the given type
        /// when the spied-on method is called.
        /// </summary>
        /// <returns>The spy.</returns>
        public SpyWithBehaviour Throw <TException>()
            where TException : Exception, new()
        {
            _spy.Behaviours.Clear();
            var behaviour = new ThrowBehaviour(typeof(TException));

            behaviour.UpdateLifetime(int.MaxValue);
            behaviour.ParameterChangesBeforeExecution = _parameterChanges;
            _spy.Behaviours.Enqueue(behaviour);
            return(new SpyWithBehaviour(_spy, behaviour));
        }
Esempio n. 5
0
    public bool AddItem(int id)
    {
        ItemData itemToAdd = database.FetchItemByID(id);

        if (itemToAdd != null)
        {
            int existingItemIndex = FindFirstItemInInventory(itemToAdd.ID);

            //stack if item is stackable and already in inventory (-1 = no existing item)
            if (itemToAdd.Stackable && existingItemIndex != -1)
            {
                UIItem existingUIItem = inventorySlots [existingItemIndex].GetComponentInChildren <UIItem> ();
                existingUIItem.amount++;
                existingUIItem.transform.GetComponentInChildren <Text> ().text = existingUIItem.amount.ToString();

                return(true);
            }
            else
            {
                //new item not present in inventory

                for (int i = 0; i < inventoryItems.Count; i++)
                {
                    //if there is a free slot
                    if (inventoryItems [i].ID == -1)
                    {
                        inventoryItems [i] = itemToAdd;

                        //create visualization for item, position relative to parent slot
                        GameObject itemObject   = Instantiate(inventoryItem);
                        UIItem     itemUIObject = itemObject.gameObject.GetComponent <UIItem> ();
                        itemUIObject.item = itemToAdd;

                        //OPTIMISE: remember item original slot for Drag'n'Drop logic, a bit messy
                        itemUIObject.slotID = i;
                        itemUIObject.amount = 1;

                        //positioning and hierarchy
                        itemObject.transform.SetParent(inventorySlots [i].transform);
                        itemObject.transform.localPosition = Vector2.zero;

                        itemObject.GetComponent <Image> ().sprite = itemToAdd.Sprite;
                        itemObject.name = itemToAdd.Title;

                        //UGLY-ASS TEMPORARY CODE FIXME
                        List <string> availableGuns = new List <string> {
                            "revolver", "shotgun", "rifle"
                        };

                        List <string> availableProjectiles = new List <string> {
                            "throwing_knife"
                        };

                        //if gun
                        if (availableGuns.Contains(itemToAdd.Slug))
                        {
                            GunBehaviour gunLogic = itemObject.AddComponent <GunBehaviour> ();
                            gunLogic.GunData = Resources.Load("scriptable_objects/guns/" + itemToAdd.Slug) as GunData;

                            gunLogic.InitialChecks();
                        }
                        //if knifes
                        else if (availableProjectiles.Contains(itemToAdd.Slug))
                        {
                            ThrowBehaviour throwLogic = itemObject.AddComponent <ThrowBehaviour> ();
                            throwLogic.ProjectileData = Resources.Load("scriptable_objects/projectiles/" + itemToAdd.Slug) as ProjectileData;

                            throwLogic.InitialChecks();
                        }

                        //if clothing
                        if (itemToAdd.Type == ItemData.ItemType.clothing)
                        {
                            ClothingBehaviour clothingLogic = itemObject.AddComponent <ClothingBehaviour> ();
                            clothingLogic.associatedItem = itemToAdd;
                            clothingLogic.itemInstance   = itemObject.GetComponent <UIItem> ();
                            clothingLogic.spriteSwitcher = playerAnimationManager.bodySprites[(int)itemToAdd.Clothing];
                        }

                        if (itemToAdd.CanBeEquipped)
                        {
                            //equip this object (and de-equip similar type items if not clothing)
                            EquipItem(itemUIObject, true);
                        }

                        //don't add the item to every free slot: get out of the loop!
                        return(true);
                    }
                }

                return(false);
            }
        }
        else
        {
            Debug.Log("Couldn't find item to add (id = " + id);
            return(false);
        }
    }