Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.EventSystems;
- namespace UltimateSurvival.GUISystem
- {
- public class ItemUnload : GUIBehaviour
- {
- //Get the main ItemInspector
- // chama a função loadammo usando o item no slot atual
- private ItemInspector itemInspector;
- //Audio for Reload
- // Áudio para recarregar
- [SerializeField]
- [Tooltip("Sounds that will play when trying to unload")]
- private SoundPlayer m_UnloadAudio;
- private void Awake()
- {
- itemInspector = transform.GetComponentInParent<ItemInspector>();
- }
- // empty the weapon
- // esvazie a arma
- public void emptyAmmo(SavableItem weaponItem, int ammoStack)
- {
- if (weaponItem.HasProperty ("Ammo") && weaponItem.HasProperty ("Ammo Type") && weaponItem.HasProperty ("Ammo Capacity"))
- {
- //put ammo from the gun in the maggazine
- // coloca munição da arma no maggazine
- var m_AmmoAmount = weaponItem.GetPropertyValue ("Ammo");
- var ammo = m_AmmoAmount.Int;
- ammo.Current = ammoStack;
- m_AmmoAmount.SetValue (ItemProperty.Type.Int, ammo);
- }
- }
- //Set capacity of itemInspector
- // Definir capacidade do itemInspector
- public void setCapacity(SavableItem ammoMagItem, int ammoCapacity){
- //set the magazine capacity
- // define a capacidade do magazine
- if (ammoMagItem.HasProperty ("Ammo Capacity")){
- var m_AmmoCapacity = ammoMagItem.GetPropertyValue ("Ammo Capacity");
- var AmmoCapacity = m_AmmoCapacity.Int;
- AmmoCapacity.Current = ammoCapacity;
- m_AmmoCapacity.SetValue (ItemProperty.Type.Int, AmmoCapacity);
- }
- }
- //Create ammo magazine
- // Criar revista de munição
- public bool unloadMag(string magName, string ammoType, int ammoStack, int ammoCapacity, out SavableItem savableItem)
- {
- savableItem = null;
- SavableItem ammoMagItem;
- ItemData ItemData;
- //find the item by its namespace
- // localiza o item pelo seu namespace
- InventoryController.Instance.Database.FindItemByName (magName, out ItemData);
- //only 1 magazine in a stack
- // apenas uma magazine em uma pilha
- ammoMagItem = new SavableItem (ItemData, 1);
- ammoMagItem.CurrentInStack = 1;
- if (ammoMagItem.HasProperty ("Ammo") && ammoMagItem.HasProperty ("Ammo Type") && ammoMagItem.HasProperty ("Ammo Capacity")) {
- //put ammo from the gun un the magazine
- // coloca munição da arma na magazine
- emptyAmmo (ammoMagItem, ammoStack);
- //set the ammo type
- // define o tipo de munição
- var m_AmmoType = ammoMagItem.GetPropertyValue ("Ammo Type");
- m_AmmoType.SetValue (ItemProperty.Type.String, ammoType);
- //set the magazine capacity
- // define a capacidade do magazine
- setCapacity(ammoMagItem, ammoCapacity);
- //output the magazine
- // produz a magazine
- return savableItem = ammoMagItem;
- } else {
- return false;
- }
- }
- // UNLOAD ITEM >>
- // DESCARREGAR ITEM >>
- public void On_UnloadClicked()
- {
- bool wasUnloaded = false;
- var item = itemInspector.InspectedSlot.CurrentItem;
- SavableItem ammoMagItem;
- //just make sure that item has the properties we will use the IF statement
- // apenas certifique-se de que o item tenha as propriedades, usaremos a instrução IF
- if (item.HasProperty("Ammo Type") && item.HasProperty("Ammo") && item.HasProperty("Ammo Capacity"))
- {
- //"Ammo Magazine" is the generic magazine item
- // "magazine Munição" é o item genérico da magazine
- string magName = "Ammo Magazine";
- string ammoType = item.GetPropertyValue ("Ammo Type").String;
- //how much ammo is in the item
- // quanta munição há no item
- int ammoStack = item.GetPropertyValue ("Ammo").Int.Current;
- //get the current capacity of the item
- // obtém a capacidade atual do item
- int ammoCapacity = item.GetPropertyValue ("Ammo Capacity").Int.Current;
- //check if the item requires an ammo mag, which mean it is likely a weapon
- // verifica se o item requer uma munição, o que significa que provavelmente é uma arma
- if (item.HasProperty ("Requires Ammo Mag")) {
- if (item.HasProperty ("Has Ammo Mag") && item.GetPropertyValue ("Has Ammo Mag").Bool) {
- //flag that the magazine has been ejected from the weapon
- // sinaliza que a revista foi ejetada da arma
- var hasAmmo = item.GetPropertyValue ("Has Ammo Mag");
- hasAmmo.SetValue (ItemProperty.Type.Bool, false);
- //empty ane ammo from the weapon
- // esvazie munição ane da arma
- emptyAmmo (item, 0);
- //can use generic ammo magazine or specific
- // pode usar uma revista de munição genérica ou específica
- unloadMag (magName, ammoType, ammoStack, ammoCapacity, out ammoMagItem);
- itemInspector.m_InventoryContainer.TryAddItem (ammoMagItem);
- //set that the item was unloaded
- // define que o item foi descarregado
- wasUnloaded = true;
- }
- }
- //if item doesnt require an ammo mag
- // se o item não exigir uma munição
- else if (ammoStack > 0 && wasUnloaded == false) //only upload ammo mag if it has ammo // só carrega munição de munição se ela tiver munição
- {
- //unload ammo that match what was in the magazine
- // descarrega munição que corresponde ao que estava na revista
- itemInspector.m_InventoryContainer.TryAddItem (ammoType, ammoStack);
- //empty ane ammo from the weapon
- // esvazie munição ane da arma
- emptyAmmo (item, 0);
- //check if it is an ammo mag itself
- // verifica se é uma própria munição
- if (item.HasProperty ("Is Ammo Mag")) {
- //if the item is amm the remove the original item in the slot
- // se o item for amm, remova o item original no slot
- itemInspector.InspectedSlot.ItemHolder.SetItem (null);
- //can use generic ammo magazine or especific
- // pode usar uma revista de munição genérica ou específica
- unloadMag (magName, ammoType, 0, ammoCapacity, out ammoMagItem);
- itemInspector.m_InventoryContainer.TryAddItem (ammoMagItem);
- }
- //set that the item was unloaded
- // define que o item foi descarregado
- wasUnloaded = true;
- }
- }
- //get the name of the object, if it has a displayname the use it
- // obtém o nome do objeto, se ele tiver um nome de exibição, use-o
- string itemName;
- if (item.ItemData.DisplayName.Length > 0 && item.ItemData.DisplayName != null) {
- itemName = item.ItemData.DisplayName;
- } else {
- //else use its item name // use o nome do item
- itemName = item.ItemData.Name;
- }
- //only show message that ammo was unloaded if the bool is true
- // mostra apenas a mensagem de que a munição foi descarregada se o bool for verdadeiro
- if (wasUnloaded) {
- MessageDisplayer.Instance.PushMessage (string.Format ("<color=yellow{0}</color> Has been unloaded", itemName));
- m_UnloadAudio.Play2D ();
- } else {
- MessageDisplayer.Instance.PushMessage (string.Format ("<color=yellow{0}</color> Has nothing to unload", itemName));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement