Exemplo n.º 1
0
        //reload Ammo
        public bool LoadAmmo(Slot initialSlot, SavableItem itemUnderPointer)
        {
            bool canLoadAmmo = (
                //make sure that the item that you drag and the item in the slot are exixcte
                itemUnderPointer && m_DraggedItem &&
                //make sure that both items have the property ammo type , so you dont get null values
                m_DraggedItem.HasProperty("Ammo Type") && itemUnderPointer.HasProperty("Ammo Type") &&
                //make sure that the weapon and the ammo have the same Ammo type
                m_DraggedItem.GetPropertyValue("Ammo Type").String == itemUnderPointer.GetPropertyValue("Ammo Type").String&&
                //make sure that only the drager item is an Ammo and not the item already in the slot
                m_DraggedItem.HasProperty("Is Ammo") && m_DraggedItem.GetPropertyValue("Is Ammo").Bool&&
                !itemUnderPointer.HasProperty("Is Ammo") && itemUnderPointer.HasProperty("Ammo Capacity") && itemUnderPointer.HasProperty("Ammo "));

            if (canLoadAmmo)
            {
                //define out variables
                //pick up amm stock size
                int ammostack = m_DraggedItem.CurrentInStack;
                //current ammo
                m_AmmoAmount = itemUnderPointer.GetPropertyValue("Ammo");
                var ammo = m_AmmoAmount.Int;
                //capacity
                m_AmmoCapacity = itemUnderPointer.GetPropertyValue("Ammo Capacity");
                //make sure taht the gun is not already full loaded
                if (m_AmmoAmount.Int.Current < m_AmmoCapacity.Int.Current)
                {
                    //check if there ammo in object we pick up
                    if (ammostack > 0)
                    {
                        int needAmmo = m_AmmoCapacity.Int.Current - m_AmmoAmount.Int.Current;
                        //if you need more mmothan what is the enter stack we consule all the ammo
                        if (needAmmo >= ammostack)
                        {
                            //reload the gun
                            ammo.Current += ammostack;//has to be correct type
                            m_AmmoAmount.SetValue(ItemProperty.Type.Int, ammo);
                            GameController.LocalPlayer.Reload.Try(needAmmo);

                            //destroy Ammo
                            Destroy(m_DraggedItemRT.gameObject);
                            m_DraggedItem = null;
                            m_Dragging    = false;
                            initialSlot.Refresh();
                            return(true);
                        }
                        //else we will use all the ammo we can and return what is left
                        else
                        {
                            ammo.Current += needAmmo;//has to correct type
                            m_AmmoAmount.SetValue(ItemProperty.Type.Int, ammo);
                            int remainingAmmo = ammostack - needAmmo;
                            m_DraggedItem.CurrentInStack = remainingAmmo;
                            GameController.LocalPlayer.Reload.Try(needAmmo);

                            //put what it left in our ammo stack where we pick it up
                            PutItemBack(initialSlot);
                            initialSlot.Refresh();

                            //destroy the ammo(because we already put it back)
                            Destroy(m_DraggedItemRT.gameObject);
                            m_DraggedItem = null;
                            m_Dragging    = false;
                            return(true);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    //Gun is full /put the bullet back
                    PutItemBack(initialSlot);
                    initialSlot.Refresh();

                    //destroy the ammo(because we already put it back)
                    Destroy(m_DraggedItemRT.gameObject);
                    m_DraggedItem = null;
                    m_Dragging    = false;
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        private IEnumerator C_Burn()
        {
            while (true)
            {
                yield return(m_UpdateInterval);

                // If the fuel, or the items to burn finished, stop burning.
                if (!FuelSlot.CurrentItem || !InputSlot.CurrentItem)
                {
                    StopBurning();
                    yield break;
                }

                var burnTime = m_BurnTimeProperty.Float;
                burnTime.Current -= UPDATE_INTERVAL;
                m_BurnTimeProperty.SetValue(ItemProperty.Type.Float, burnTime);

                Progress.Set(1f - burnTime.Ratio);

                if (burnTime.Current <= 0f)
                {
                    ItemData resultedItem;
                    if (GameController.ItemDatabase.FindItemByName(m_ItemResult, out resultedItem))
                    {
                        CollectionUtils.AddItem(resultedItem, 1, LootSlots);
                    }
                    else
                    {
                        Debug.LogWarning("The item has burned but no result was given, make sure the item has the 'Burn Result' property, so we know what to add as a result of burning / smelting.", this);
                    }

                    if (InputSlot.CurrentItem.CurrentInStack == 1)
                    {
                        InputSlot.SetItem(null);
                        StopBurning();
                        yield break;
                    }
                    else
                    {
                        burnTime.Current = burnTime.Default;
                        m_BurnTimeProperty.SetValue(ItemProperty.Type.Float, burnTime);
                        InputSlot.CurrentItem.CurrentInStack--;
                    }
                }

                var fuelTime = m_FuelTimeProperty.Float;
                fuelTime.Current -= UPDATE_INTERVAL;
                m_FuelTimeProperty.SetValue(ItemProperty.Type.Float, fuelTime);

                if (fuelTime.Current <= 0f)
                {
                    if (FuelSlot.CurrentItem.CurrentInStack == 1)
                    {
                        FuelSlot.SetItem(null);
                        StopBurning();
                        yield break;
                    }
                    else
                    {
                        fuelTime.Current = fuelTime.Default;
                        m_FuelTimeProperty.SetValue(ItemProperty.Type.Float, fuelTime);
                        FuelSlot.CurrentItem.CurrentInStack--;
                    }
                }
            }
        }