/// <summary> /// Populates the container based on what is linked to the objInt /// </summary> /// <param name="cn">Cn.</param> /// <param name="objInt">Object int.</param> public static void PopulateContainer(Container cn, ObjectInteraction objInt, ObjectLoader objList) { //cn.ObjectsAccepted=-1;//For now default to accept all cn.Capacity = 40; for (int i = 0; i <= cn.MaxCapacity(); i++) { //init the variables. if (cn.items[i] == null) { cn.items[i] = ""; } } if (objInt.link != 0) //Container has objects { ObjectLoaderInfo tmpobj = ObjectLoader.getObjectInfoAt(objInt.link, objList); //int count = 0; if (ObjectLoader.GetItemTypeAt(objInt.link, objList) != ObjectInteraction.LOCK) { cn.AddItemToContainer(ObjectLoader.UniqueObjectName(tmpobj)); } while (tmpobj.next != 0) { tmpobj = ObjectLoader.getObjectInfoAt((int)tmpobj.next, objList); //objList[tmpobj.next]; cn.AddItemToContainer(ObjectLoader.UniqueObjectName(tmpobj)); } } }
public void CollectAll() { Container loot = lootPanel.GetComponentInChildren <Container>(); for (int i = 0; i < loot.containerItems.Count; i++) { if (loot.containerItems[i].ItemType != ItemType.NULL) { if (loot.containerItems[i].ItemType == ItemType.CURRENCY) { AddMoney(loot.containerItems[i].ItemAmount * loot.containerItems[i].ItemCost); loot.containerItems[i] = new Item(); } else { if (loot.containerItems[i].IsStackable) { if (inventory.AddItemToContainer(loot.containerItems[i].ItemId, loot.containerItems[i].ItemAmount)) { loot.containerItems[i] = new Item(); } } else { if (inventory.AddItemToContainer(loot.containerItems[i].ItemId, 1)) { loot.containerItems[i] = new Item(); } } } } } }
/// <summary> /// Swaps two objects with each other /// </summary> /// <param name="ObjInSlot"></param> /// <param name="slotIndex"></param> /// <param name="cObjectInHand"></param> public void SwapObjects(ObjectInteraction ObjInSlot, short slotIndex, ObjectInteraction cObjectInHand) { RemoveItem(ObjInSlot); SetObjectAtSlot(slotIndex, cObjectInHand); if (slotIndex >= 11) { currentContainer.AddItemToContainer(cObjectInHand, ContainerOffset + slotIndex - 11); } ObjectInHand = ObjInSlot; Refresh(); }
/// <summary> /// Populates the container based on what is linked to the objInt /// </summary> /// <param name="cn">Cn.</param> /// <param name="objInt">Object int.</param> public static void PopulateContainer(Container cn, ObjectInteraction objInt, ObjectLoader objList) { if (objInt.link != 0) //Container has objects { ObjectLoaderInfo tmpobj = ObjectLoader.getObjectInfoAt(objInt.link, objList); //int count = 0; if (ObjectLoader.GetItemTypeAt(objInt.link, objList) != ObjectInteraction.LOCK) { cn.AddItemToContainer(tmpobj.instance); //ObjectLoader.UniqueObjectName(tmpobj)); } else { cn.LockObject = objInt.link;//To preserve the containers lock. } while (tmpobj.next != 0) { tmpobj = ObjectLoader.getObjectInfoAt((int)tmpobj.next, objList); //objList[tmpobj.next]; cn.AddItemToContainer(tmpobj.instance); //ObjectLoader.UniqueObjectName(tmpobj)); } } }
public void SwapObjects(GameObject ObjInSlot, short slotIndex, string cObjectInHand) { //Swaps specified game object as the slot wth the passed object //Debug.Log ("Swapping " + ObjInSlot.name + " with " + cObjectInHand + " at slot " +slotIndex); Container cn = GameObject.Find(currentContainer).GetComponent <Container>(); //cn.RemoveItemFromContainer(cObjectInHand); //cn.RemoveItemFromContainer(ObjInSlot.name);//removed this when adding equip events. RemoveItem(ObjInSlot.name); SetObjectAtSlot(slotIndex, cObjectInHand); if (slotIndex >= 11) { cn.AddItemToContainer(cObjectInHand, ContainerOffset + slotIndex - 11); } ObjectInHand = ObjInSlot.name; UWHUD.instance.CursorIcon = ObjInSlot.GetComponent <ObjectInteraction>().GetInventoryDisplay().texture; //playerUW.CurrObjectSprite = ObjInSlot.GetComponent<ObjectInteraction>().InventoryString; Refresh(); }
public static void SortContainer(Container cn) { //Debug.Log ("Sorting container"); //Flattens the contents of a container so that they occupy the first slots int currFreeSlot = -1; string ItemName; bool GetNextSlot = true; for (short i = 0; i <= cn.MaxCapacity(); i++) { //Find the first free slot if (GetNextSlot == true) { for (short j = 0; j <= cn.MaxCapacity(); j++) { ItemName = cn.GetItemAt(j); if (ItemName == "") { currFreeSlot = j; GetNextSlot = false; break; } } } if ((i > currFreeSlot) && (currFreeSlot != -1)) { ItemName = cn.GetItemAt(i); if (ItemName != "") { //Move this item to the free slot cn.RemoveItemFromContainer(i); cn.AddItemToContainer(ItemName, currFreeSlot); GetNextSlot = true; currFreeSlot = -1; } } } }
public void OnClick() { if (Dragging == true) { return; } if ((UWCharacter.Instance.isRoaming == true) || (Quest.instance.InDreamWorld)) {//No inventory use while using wizard eye. return; } if (UWCharacter.Instance.playerInventory.currentContainer == UWCharacter.Instance.playerInventory.playerContainer) // UWCharacter.Instance.name) { //Don't do anything on the top level UWCharacter.Instance.playerInventory.ContainerOffset = 0; BackpackBg.SetActive(false); return; } if (CurrentObjectInHand == null) {//Player has no object in their hand. We close up the container. ScrollButtonInventory.ScrollValue = 0; UWCharacter.Instance.playerInventory.ContainerOffset = 0; Container currentContainerObj = UWCharacter.Instance.playerInventory.currentContainer; UWCharacter.Instance.playerInventory.currentContainer = currentContainerObj.ContainerParent; currentContainerObj.isOpenOnPanel = false; //Close child containers as well CloseChildContainer(currentContainerObj); Container DestinationContainer = UWCharacter.Instance.playerInventory.currentContainer; if (UWCharacter.Instance.playerInventory.currentContainer == UWCharacter.Instance.playerInventory.playerContainer) { GetComponent <RawImage>().texture = UWCharacter.Instance.playerInventory.Blank; BackpackBg.SetActive(false); if ((DestinationContainer.CountItems() >= 8) && (DestinationContainer != UWCharacter.Instance.playerInventory.playerContainer)) { InvUp.SetActive(true); InvDown.SetActive(true); } else { InvUp.SetActive(false); InvDown.SetActive(false); } } else { GetComponent <RawImage>().texture = DestinationContainer.transform.GetComponent <ObjectInteraction>().GetEquipDisplay().texture; BackpackBg.SetActive(true); if ((DestinationContainer.CountItems() >= 8) && (DestinationContainer != UWCharacter.Instance.playerInventory.playerContainer)) { InvUp.SetActive(true); InvDown.SetActive(true); } else { InvUp.SetActive(false); InvDown.SetActive(false); } } for (short i = 0; i < 8; i++) { UWCharacter.Instance.playerInventory.SetObjectAtSlot((short)(i + 11), DestinationContainer.GetItemAt(i)); } } else { if (UWCharacter.InteractionMode != UWCharacter.InteractionModePickup) {//Only allow this to happen when in pickup mode. return; } //Move the contents out of the container into the parent. //Container CurrentContainer = UWCharacter.Instance.playerInventory.currentContainer; //GameObject.Find(UWCharacter.Instance.playerInventory.currentContainer).GetComponent<Container>(); Container DestinationContainer = UWCharacter.Instance.playerInventory.currentContainer.ContainerParent; //GameObject.Find(CurrentContainer.ContainerParent).GetComponent<Container>(); if (Container.TestContainerRules(DestinationContainer, 11, false)) { if (!CurrentObjectInHand.IsStackable()) { if (DestinationContainer.AddItemToContainer(CurrentObjectInHand)) {//Object has moved CurrentObjectInHand = null; } } else { if (DestinationContainer.AddItemMergedItemToContainer(CurrentObjectInHand)) {//Object has moved CurrentObjectInHand = null; } } } } }
void OnClick() { if (playerUW.playerInventory.currentContainer == playerUW.name) { //Don't do anything on the top level playerUW.playerInventory.ContainerOffset = 0; return; } if (playerUW.playerInventory.ObjectInHand == "") { //Player has no object in their hand. We close up the container. ScrollButtonInventory.ScrollValue = 0; playerUW.playerInventory.ContainerOffset = 0; Container currentContainerObj = playerUW.playerInventory.GetCurrentContainer(); playerUW.playerInventory.currentContainer = currentContainerObj.ContainerParent; currentContainerObj.isOpenOnPanel = false; //Close child containers as well CloseChildContainer(currentContainerObj); Container DestinationContainer = playerUW.playerInventory.GetCurrentContainer(); if (playerUW.playerInventory.currentContainer == "Gronk") { GetComponent <UITexture>().mainTexture = playerUW.playerInventory.Blank; } else { GetComponent <UITexture>().mainTexture = DestinationContainer.transform.GetComponent <ObjectInteraction>().GetInventoryDisplay().texture; } for (int i = 0; i < 8; i++) { string sItem = DestinationContainer.GetItemAt(i); playerUW.playerInventory.SetObjectAtSlot(i + 11, sItem); } } else { if (UWCharacter.InteractionMode != UWCharacter.InteractionModePickup) { //Only allow this to happen when in pickup mode. return; } //Move the contents out of the container into the parent. Container CurrentContainer = GameObject.Find(playerUW.playerInventory.currentContainer).GetComponent <Container>(); Container DestinationContainer = GameObject.Find(CurrentContainer.ContainerParent).GetComponent <Container>(); ObjectInteraction item = GameObject.Find(playerUW.playerInventory.ObjectInHand).GetComponent <ObjectInteraction>(); if (Container.TestContainerRules(DestinationContainer, 11)) { if ((item.isQuant == false) || (item.isEnchanted)) { if (DestinationContainer.AddItemToContainer(playerUW.playerInventory.ObjectInHand)) { //Object has moved playerUW.CursorIcon = playerUW.CursorIconDefault; playerUW.playerInventory.ObjectInHand = ""; } } else { if (DestinationContainer.AddItemMergedItemToContainer(item.gameObject)) { //Object has moved playerUW.CursorIcon = playerUW.CursorIconDefault; playerUW.playerInventory.ObjectInHand = ""; } } } } }
public static void SortContainer(Container cn) { //Debug.Log ("Sorting container"); //Flattens the contents of a container so that they occupy the first slots int currFreeSlot=-1; string ItemName; bool GetNextSlot=true; for (int i=0;i<=cn.MaxCapacity();i++) { //Find the first free slot if (GetNextSlot==true) { for (int j=0;j<=cn.MaxCapacity();j++) { ItemName=cn.GetItemAt(j); if (ItemName=="") { currFreeSlot=j; GetNextSlot=false; break; } } } if ((i>currFreeSlot) &&(currFreeSlot!=-1)) { ItemName=cn.GetItemAt(i); if (ItemName!="") {//Move this item to the free slot cn.RemoveItemFromContainer(i); cn.AddItemToContainer(ItemName,currFreeSlot); GetNextSlot=true; currFreeSlot=-1; } } } }
public void OnClick() { if (Dragging == true) { return; } if (UWCharacter.Instance.playerInventory.currentContainer == UWCharacter.Instance.name) { //Don't do anything on the top level UWCharacter.Instance.playerInventory.ContainerOffset = 0; BackpackBg.SetActive(false); return; } if (UWCharacter.Instance.playerInventory.ObjectInHand == "") { //Player has no object in their hand. We close up the container. ScrollButtonInventory.ScrollValue = 0; UWCharacter.Instance.playerInventory.ContainerOffset = 0; Container currentContainerObj = UWCharacter.Instance.playerInventory.GetCurrentContainer(); UWCharacter.Instance.playerInventory.currentContainer = currentContainerObj.ContainerParent; currentContainerObj.isOpenOnPanel = false; //Close child containers as well CloseChildContainer(currentContainerObj); Container DestinationContainer = UWCharacter.Instance.playerInventory.GetCurrentContainer(); if (UWCharacter.Instance.playerInventory.currentContainer == UWCharacter.Instance.name) { GetComponent <RawImage>().texture = UWCharacter.Instance.playerInventory.Blank; BackpackBg.SetActive(false); if ((DestinationContainer.CountItems() >= 8) && (DestinationContainer != UWCharacter.Instance.playerInventory.playerContainer)) { InvUp.SetActive(true); InvDown.SetActive(true); } else { InvUp.SetActive(false); InvDown.SetActive(false); } } else { GetComponent <RawImage>().texture = DestinationContainer.transform.GetComponent <ObjectInteraction>().GetEquipDisplay().texture; BackpackBg.SetActive(true); if ((DestinationContainer.CountItems() >= 8) && (DestinationContainer != UWCharacter.Instance.playerInventory.playerContainer)) { InvUp.SetActive(true); InvDown.SetActive(true); } else { InvUp.SetActive(false); InvDown.SetActive(false); } } for (short i = 0; i < 8; i++) { string sItem = DestinationContainer.GetItemAt(i); UWCharacter.Instance.playerInventory.SetObjectAtSlot((short)(i + 11), sItem); } } else { if (UWCharacter.InteractionMode != UWCharacter.InteractionModePickup) { //Only allow this to happen when in pickup mode. return; } //Move the contents out of the container into the parent. Container CurrentContainer = GameObject.Find(UWCharacter.Instance.playerInventory.currentContainer).GetComponent <Container>(); Container DestinationContainer = GameObject.Find(CurrentContainer.ContainerParent).GetComponent <Container>(); ObjectInteraction item = GameObject.Find(UWCharacter.Instance.playerInventory.ObjectInHand).GetComponent <ObjectInteraction>(); if (Container.TestContainerRules(DestinationContainer, 11, false)) { //if ((item.isQuant()==false) || (item.isEnchanted())) if (!item.IsStackable()) { if (DestinationContainer.AddItemToContainer(UWCharacter.Instance.playerInventory.ObjectInHand)) { //Object has moved UWHUD.instance.CursorIcon = UWHUD.instance.CursorIconDefault; UWCharacter.Instance.playerInventory.ObjectInHand = ""; } } else { if (DestinationContainer.AddItemMergedItemToContainer(item.gameObject)) { //Object has moved UWHUD.instance.CursorIcon = UWHUD.instance.CursorIconDefault; UWCharacter.Instance.playerInventory.ObjectInHand = ""; } } } } }
public void AddItem() { int randi = Random.Range(4, 60); inventory.AddItemToContainer(randi, 1); }