Esempio n. 1
0
    public override void Show()
    {
        NGUITools.SetActive(this.gameObject, true);
        this.IsActive = true;

        QuantitySlider.numberOfSteps = Target.GetQuantity();

        _quanity             = Target.GetQuantity();
        QuantitySlider.value = 0;
        QuantityLabel.text   = "1";      //_quanity.ToString();

        if (Target.Item.IsUsable && Target.IsPlayerOwned)
        {
            Use.isEnabled = true;
        }
        else
        {
            Use.isEnabled = false;
        }

        InputEventHandler.Instance.State = UserInputState.PopupOpen;

        InputEventHandler.OnPopupMouseWheel -= OnMouseWheelInput;
        InputEventHandler.OnPopupMouseWheel += OnMouseWheelInput;

        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("OpenSplitMenu"), 0.5f);
    }
Esempio n. 2
0
    public void OnCloseSplitMenuTake(GridItem item, int quantity)
    {
        _windowPanel.SplitItemPanel.Hide();

        if (quantity > 0 && quantity < item.GetQuantity())
        {
            //reduce the exsiting item's quantity and add new item to selected
            item.SetQuantity(item.GetQuantity() - quantity);
            Item newItem = new Item(item.Item);
            CreateSelectedItem(newItem, quantity, item.IsPlayerOwned);
        }
        else if (quantity >= item.GetQuantity())
        {
            PickupItem(item);
        }
    }
Esempio n. 3
0
    private void DropDiscardedItems()
    {
        foreach (TempSlot slot in DiscardSlots)
        {
            if (slot.Items.Count > 0)
            {
                //create an instance of pickup item near the owner
                GridItem gridItem = slot.Items.First();
                var      resource = Resources.Load(gridItem.Item.PrefabName + "Pickup");
                if (resource != null)
                {
                    GameObject pickup = GameObject.Instantiate(resource) as GameObject;
                    pickup.transform.position = slot.Owner.transform.position + new Vector3(UnityEngine.Random.Range(-0.2f, 0.2f), 1f, UnityEngine.Random.Range(-0.2f, 0.2f));
                    Transform parent = GameManager.Inst.ItemManager.FindPickupItemParent(pickup.transform);
                    if (parent != null)
                    {
                        pickup.transform.parent = parent;
                    }
                    pickup.GetComponent <PickupItem>().Item     = gridItem.Item;
                    pickup.GetComponent <PickupItem>().Quantity = gridItem.GetQuantity();
                }


                GameManager.Inst.UIManager.WindowPanel.InventoryPanel.DestroyItem(gridItem);
                slot.Items.Clear();
            }
        }
    }
Esempio n. 4
0
    public void OnCloseSplitMenuUse(GridItem item, int quantity)
    {
        if (quantity > 0 && quantity <= item.GetQuantity())
        {
            //perform consumption. If consumption successful, reduce item quantity and hide panel
            if (GameManager.Inst.PlayerControl.Survival.UseItem(item.Item, quantity))
            {
                int existingQuantity = item.GetQuantity();
                item.SetQuantity(existingQuantity - quantity);
                _windowPanel.SplitItemPanel.Hide();

                if (existingQuantity <= quantity)
                {
                    InventoryGrid parentGrid = item.GetParentGrid();
                    if (parentGrid != null)
                    {
                        parentGrid.RemoveGridItem(item);
                    }
                    DestroyItem(item);
                }
            }
        }
    }
Esempio n. 5
0
    public void OnPlaceItem(GridItem item)
    {
        if (SelectedItem == item && item.Boundary.alpha == 1)
        {
            if (FocusedTempSlot != null)
            {
                //place in temp slot
                GridItem existingItem = null;
                TempSlot temp         = FocusedTempSlot;
                if (FocusedTempSlot.Items.Count > 0)
                {
                    existingItem = FocusedTempSlot.Items[0];
                }
                FocusedTempSlot.Items.Clear();

                PlaceItemInTempSlot(item);

                if (_selectedItemLastList != null && _selectedItemLastList != temp.Items)
                {
                    _selectedItemLastList.Remove(item);
                    _selectedItemLastList = null;
                }

                if (existingItem != null && existingItem != item)
                {
                    PickupItem(existingItem);
                }
            }
            else if (FocusedBodySlot != null)
            {
                //place in body slot
                GridItem existingItem = null;
                BodySlot temp         = FocusedBodySlot;
                if (FocusedBodySlot.Items.Count > 0)
                {
                    existingItem = FocusedBodySlot.Items[0];
                }


                if (item.Item.Type == ItemType.Ammo && (FocusedBodySlot.AllowedItemType == ItemType.PrimaryWeapon || FocusedBodySlot.AllowedItemType == ItemType.SideArm))
                {
                    if (existingItem != null && (int)existingItem.Item.GetAttributeByName("_LoadedAmmos").Value <= 0 &&
                        (string)item.Item.GetAttributeByName("_Caliber").Value == (string)existingItem.Item.GetAttributeByName("_Caliber").Value)
                    {
                        existingItem.Item.SetAttribute("_LoadedAmmoID", item.Item.ID);
                        GameManager.Inst.UIManager.SetConsoleText("The weapon is now loading " + item.Item.Name);
                        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("LoadAmmo"), 0.05f);
                    }
                    else if ((int)existingItem.Item.GetAttributeByName("_LoadedAmmos").Value > 0)
                    {
                        GameManager.Inst.UIManager.SetConsoleText("Weapon is still loaded, unload ammo first.");
                        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Error1"), 0.05f);
                    }
                    else if ((string)item.Item.GetAttributeByName("_Caliber").Value != (string)existingItem.Item.GetAttributeByName("_Caliber").Value)
                    {
                        GameManager.Inst.UIManager.SetConsoleText("Caliber doesn't match!");
                        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Error1"), 0.05f);
                    }
                }
                else
                {
                    FocusedBodySlot.Items.Clear();
                    PlaceItemInBodySlot(item);

                    if (_selectedItemLastList != null && _selectedItemLastList != temp.Items)
                    {
                        _selectedItemLastList.Remove(item);
                        _selectedItemLastList = null;
                    }


                    if (existingItem != null && existingItem != item)
                    {
                        PickupItem(existingItem);
                    }
                }
            }
            else if (FocusedGrid != null)
            {
                PlaceItem(item);

                if (_selectedItemLastList != null)
                {
                    _selectedItemLastList.Remove(item);
                    _selectedItemLastList = null;
                }

                if (ReplaceItem != null)
                {
                    Debug.Log("Replace item is not null");
                    //if replace item is same as item then try to combine the two
                    if (ReplaceItem.Item.ID == item.Item.ID && item.Item.MaxStackSize > 1)
                    {
                        int fill = item.Item.MaxStackSize - item.GetQuantity();
                        if (fill < ReplaceItem.GetQuantity())
                        {
                            item.SetQuantity(item.Item.MaxStackSize);
                            ReplaceItem.SetQuantity(ReplaceItem.GetQuantity() - fill);

                            PickupItem(ReplaceItem);
                            ReplaceItem.Sprite.alpha = 1;
                            ReplaceItem = null;
                        }
                        else
                        {
                            item.SetQuantity(item.GetQuantity() + ReplaceItem.GetQuantity());
                            FocusedGrid.Items.Remove(ReplaceItem);
                            DestroyItem(ReplaceItem);
                        }

                        RefreshItemTotals();

                        return;
                    }

                    //if replace item is not the same, but selected item is ammo and replace item is an empty gun that can use the ammo
                    //then load the gun with ammo
                    if (item.Item.Type == ItemType.Ammo && (ReplaceItem.Item.Type == ItemType.PrimaryWeapon || ReplaceItem.Item.Type == ItemType.SideArm))
                    {
                        if ((bool)ReplaceItem.Item.GetAttributeByName("_IsRanged").Value == true)
                        {
                            if ((int)ReplaceItem.Item.GetAttributeByName("_LoadedAmmos").Value <= 0 &&
                                (string)item.Item.GetAttributeByName("_Caliber").Value == (string)ReplaceItem.Item.GetAttributeByName("_Caliber").Value)
                            {
                                ReplaceItem.Item.SetAttribute("_LoadedAmmoID", item.Item.ID);
                                GameManager.Inst.UIManager.SetConsoleText("The weapon is now loading " + item.Item.Name);
                                GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("LoadAmmo"), 0.05f);
                            }
                            else if ((int)ReplaceItem.Item.GetAttributeByName("_LoadedAmmos").Value > 0)
                            {
                                GameManager.Inst.UIManager.SetConsoleText("Weapon is still loaded, unload ammo first.");
                                GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Error1"), 0.05f);
                            }
                            else if ((string)item.Item.GetAttributeByName("_Caliber").Value != (string)ReplaceItem.Item.GetAttributeByName("_Caliber").Value)
                            {
                                GameManager.Inst.UIManager.SetConsoleText("Caliber doesn't match!");
                                GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Error1"), 0.05f);
                            }

                            PickupItem(item);
                            RefreshItemTotals();
                            return;
                        }
                    }


                    PickupItem(ReplaceItem);
                    ReplaceItem.Sprite.alpha = 1;
                    ReplaceItem = null;
                }
            }
        }

        RefreshItemTotals();
    }
Esempio n. 6
0
    public void OnHoverItem(GridItem item)
    {
        ItemName.text = item.Item.Name;

        if (item.Item.Type == ItemType.PrimaryWeapon || item.Item.Type == ItemType.SideArm)
        {
            bool isRanged = (bool)item.Item.GetAttributeByName("_IsRanged").Value;
            if (isRanged)
            {
                string ammoID   = (string)item.Item.GetAttributeByName("_LoadedAmmoID").Value;
                string ammoName = GameManager.Inst.ItemManager.GetItemNameFromID(ammoID);
                ItemDescription.text = item.Item.Description + "\n\n" + "Caliber: " + (string)item.Item.GetAttributeByName("_Caliber").Value + "\n" +
                                       "Currently chambering: " + ammoName;
            }
            else
            {
                ItemDescription.text = item.Item.Description;
            }
        }
        else
        {
            ItemDescription.text = item.Item.Description;
        }

        if (item.Item.Type == ItemType.PrimaryWeapon || item.Item.Type == ItemType.SideArm || item.Item.Type == ItemType.Helmet || item.Item.Type == ItemType.Armor)
        {
            ItemDescription.text = ItemDescription.text + "\n\n" + "Durability: " + Mathf.RoundToInt(item.Item.Durability) + " / " + Mathf.RoundToInt(item.Item.MaxDurability);
        }

        //generate item attribute list
        string attributeNames        = "";
        string attributeValues       = "";
        string specialAttributesGood = "";
        string specialAttributesBad  = "";

        foreach (ItemAttribute attribute in item.Item.Attributes)
        {
            if (attribute.Name[0] == '+')
            {
                specialAttributesGood = specialAttributesGood + attribute.Name + "\n";
            }
            else if (attribute.Name[0] == '-')
            {
                specialAttributesBad = specialAttributesBad + attribute.Name + "\n";
            }
            else if (attribute.Name[0] != '_')
            {
                attributeNames  = attributeNames + attribute.Name + "\n";
                attributeValues = attributeValues + attribute.Value.ToString() + "\n";
            }
        }



        attributeNames  = attributeNames + "Weight";
        attributeValues = attributeValues + (item.Item.Weight * item.GetQuantity()).ToString();

        ItemAttributeNames.text  = attributeNames;
        ItemAttributeValues.text = attributeValues;

        ItemSpecialAttrBad.text  = "";
        ItemSpecialAttrGood.text = "";

        if (specialAttributesGood.Length > 0)
        {
            ItemSpecialAttrGood.text = specialAttributesGood.Substring(1, specialAttributesGood.Length - 1);
            ItemSpecialAttrGood.transform.localPosition = ItemAttributeNames.transform.localPosition - new Vector3(0, ItemAttributeNames.height + 5, 0);
        }

        if (specialAttributesBad.Length > 0)
        {
            ItemSpecialAttrBad.text = specialAttributesBad.Substring(1, specialAttributesBad.Length - 1);
            float offset = 0;
            if (specialAttributesGood.Length > 0)
            {
                offset = ItemSpecialAttrGood.height;
            }
            ItemSpecialAttrBad.transform.localPosition = ItemAttributeNames.transform.localPosition - new Vector3(0, ItemAttributeNames.height + offset + 5, 0);
        }

        if (GameManager.Inst.UIManager.WindowPanel.TradingPanel.IsActive)
        {
            if (item.IsPlayerOwned)
            {
                ItemPrice.text = "Sell Price: " + Mathf.FloorToInt(item.PriceTag) + " RU";
            }
            else
            {
                ItemPrice.text = "Purchase Price: " + Mathf.FloorToInt(item.PriceTag) + " RU";
            }
        }
        else
        {
            ItemPrice.text = "";
        }
    }
Esempio n. 7
0
	public void OnCloseSplitMenu(GridItem item, int quantity)
	{
		_windowPanel.SplitItemPanel.Hide();

		if(quantity > 0 && quantity < item.GetQuantity())
		{
			//reduce the exsiting item's quantity and add new item to selected
			item.SetQuantity(item.GetQuantity() - quantity);
			Item newItem = new Item(item.Item);
			CreateSelectedItem(newItem, quantity);
		}
		else if(quantity >= item.GetQuantity())
		{
			PickupItem(item);
		}


	}
Esempio n. 8
0
	public void OnPlaceItem(GridItem item)
	{
		if(SelectedItem == item && item.Boundary.alpha == 1)
		{
			
			if(FocusedTempSlot != null)
			{
				//place in temp slot
				GridItem existingItem = null;
				TempSlot temp = FocusedTempSlot;
				if(FocusedTempSlot.Items.Count > 0)
				{
					existingItem = FocusedTempSlot.Items[0];
				}
				FocusedTempSlot.Items.Clear();

				PlaceItemInTempSlot(item);

				if(_selectedItemLastList != null && _selectedItemLastList != temp.Items)
				{
					_selectedItemLastList.Remove(item);
					_selectedItemLastList = null;
				}

				if(existingItem != null && existingItem != item)
				{
					PickupItem(existingItem);
				}


			}
			else if(FocusedBodySlot != null)
			{
				//place in body slot
				GridItem existingItem = null;
				BodySlot temp = FocusedBodySlot;
				if(FocusedBodySlot.Items.Count > 0)
				{
					existingItem = FocusedBodySlot.Items[0];
				}


				if(item.Item.Type == ItemType.Ammo && (FocusedBodySlot.AllowedItemType == ItemType.PrimaryWeapon || FocusedBodySlot.AllowedItemType == ItemType.SideArm))
				{
					if(existingItem != null && (int)existingItem.Item.GetAttributeByName("_LoadedAmmos").Value <= 0 && 
						(string)item.Item.GetAttributeByName("_Caliber").Value == (string)existingItem.Item.GetAttributeByName("_Caliber").Value)
					{
						existingItem.Item.SetAttribute("_LoadedAmmoID", item.Item.ID);
						GameManager.Inst.UIManager.SetConsoleText("The weapon is now loading " + item.Item.Name);
					}
					else if((int)existingItem.Item.GetAttributeByName("_LoadedAmmos").Value > 0)
					{
						GameManager.Inst.UIManager.SetConsoleText("Weapon is still loaded, unload ammo first.");
					}
					else if((string)item.Item.GetAttributeByName("_Caliber").Value != (string)existingItem.Item.GetAttributeByName("_Caliber").Value)
					{
						GameManager.Inst.UIManager.SetConsoleText("Caliber doesn't match!");
					}

				}
				else
				{
					FocusedBodySlot.Items.Clear();
					PlaceItemInBodySlot(item);

					if(_selectedItemLastList != null && _selectedItemLastList != temp.Items)
					{
						_selectedItemLastList.Remove(item);
						_selectedItemLastList = null;
					}


					if(existingItem != null && existingItem != item)
					{

						PickupItem(existingItem);

					}

				}


			}
			else if(FocusedGrid != null)
			{
				PlaceItem(item);	

				if(_selectedItemLastList != null)
				{
					_selectedItemLastList.Remove(item);
					_selectedItemLastList = null;
				}

				if(ReplaceItem != null)
				{
					Debug.Log("Replace item is not null");
					//if replace item is same as item then try to combine the two
					if(ReplaceItem.Item.ID == item.Item.ID && item.Item.MaxStackSize > 1)
					{
						int fill = item.Item.MaxStackSize - item.GetQuantity();
						if(fill < ReplaceItem.GetQuantity())
						{
							item.SetQuantity(item.Item.MaxStackSize);
							ReplaceItem.SetQuantity(ReplaceItem.GetQuantity() - fill);

							PickupItem(ReplaceItem);
							ReplaceItem.Sprite.alpha = 1;
							ReplaceItem = null;
						}
						else
						{
							item.SetQuantity(item.GetQuantity() + ReplaceItem.GetQuantity());
							FocusedGrid.Items.Remove(ReplaceItem);
							DestroyItem(ReplaceItem);
						}

						return;
					}

					//if replace item is not the same, but selected item is ammo and replace item is an empty gun that can use the ammo
					//then load the gun with ammo
					if(item.Item.Type == ItemType.Ammo && (ReplaceItem.Item.Type == ItemType.PrimaryWeapon || ReplaceItem.Item.Type == ItemType.SideArm))
					{
						if((int)ReplaceItem.Item.GetAttributeByName("_LoadedAmmos").Value <= 0 && 
							(string)item.Item.GetAttributeByName("_Caliber").Value == (string)ReplaceItem.Item.GetAttributeByName("_Caliber").Value)
						{
							ReplaceItem.Item.SetAttribute("_LoadedAmmoID", item.Item.ID);
							GameManager.Inst.UIManager.SetConsoleText("The weapon is now loading " + item.Item.Name);
						}
						else if((int)ReplaceItem.Item.GetAttributeByName("_LoadedAmmos").Value > 0)
						{
							GameManager.Inst.UIManager.SetConsoleText("Weapon is still loaded, unload ammo first.");
						}
						else if((string)item.Item.GetAttributeByName("_Caliber").Value != (string)ReplaceItem.Item.GetAttributeByName("_Caliber").Value)
						{
							GameManager.Inst.UIManager.SetConsoleText("Caliber doesn't match!");
						}

						PickupItem(item);
						return;
					}


					PickupItem(ReplaceItem);
					ReplaceItem.Sprite.alpha = 1;
					ReplaceItem = null;


				}


			}
				

		}
	}