public void AddItem(int id) { Item itemToAdd = database.FetchItemByID(id); // Get the item from the database. //database.PrintDatabase(); /* Works for stackable items */ // Do we have it in our inventory already? Is it stackable? if (itemToAdd.Stackable && CheckIfItemInInventory(itemToAdd)) { for (int i = 0; i < items.Count; i++) { if (items [i].ID == id) { InventoryItemData data = slots [i].transform.GetChild(0).GetComponent <InventoryItemData> (); data.amount++; // We gained 1 of this item. data.transform.GetChild(0).GetComponent <Text> ().text = data.amount.ToString(); // Set stack amnt break; } } // So we don't have it in our inventory. We should add it! } else { for (int i = 0; i < items.Count; i++) { if (items [i].ID == -1) // Check for next empty slot. { items [i] = itemToAdd; GameObject itemObject = Instantiate(inventoryItem); // Put this new item in the slot // Set the item instance's itemData attributes. itemObject.GetComponent <InventoryItemData>().item = itemToAdd; itemObject.GetComponent <InventoryItemData>().slot = i; // 'i' is the inventory slot we're adding to itemObject.transform.SetParent(slots [i].transform); // Set parent to be corresponding slot itemObject.GetComponent <Image> ().sprite = itemToAdd.Sprite; itemObject.name = itemToAdd.Title; // The name of item in each slot InventoryItemData data = itemObject.GetComponent <InventoryItemData> (); data.amount = 1; itemObject.transform.position = slots [i].transform.position; break; // We found and processed the item. Time to leave the loop. } } } }
public Vector2 GetItemLocation(Item i) { foreach (Vector2 v in items.Keys) { InventoryItemData myI = items[v]; if (myI.displayName == i.displayname) { return(v); } } return(new Vector2(-1, -1)); }
public void UpdateInventoryItemCount(InventoryItemData pItemData, int pNewCount, bool pPlaySoundEffect = false) { if (pPlaySoundEffect) { if (_getItemSoundEffect != null) { Helper.PlayAudioIfSoundOn(_getItemSoundEffect); } } _guiContainer.inventoryContainer.UpdateItemCount(pItemData, pNewCount); PlayMakerFSM.BroadcastEvent("SAVE SCENE"); }
// Token: 0x0600F3F9 RID: 62457 RVA: 0x00549E10 File Offset: 0x00548010 public InventoryItemData(string JMMILEFMACB) { TextAsset textAsset = Resources.Load <TextAsset>("Items/" + JMMILEFMACB + "/config"); InventoryItemData inventoryItemData = JsonConvert.DeserializeObject <InventoryItemData>(textAsset.text); this.id = inventoryItemData.id; this.name = inventoryItemData.name; this.description = inventoryItemData.description; this.type = inventoryItemData.type; this.rarity = inventoryItemData.rarity; this.icon = Resources.Load <Sprite>("Items/" + JMMILEFMACB + "/icon"); }
public void UpdateItemCount(InventoryItemData pItemData, int pNewCount) { int index = pItemData.slotNumber - 1; if (index < 0 || index >= _slots.Length) { Debug.LogError("invalid slot " + pItemData.slotNumber); return; } _slots [index].UpdateItemCount(pItemData, pNewCount); }
public InventoryItem GetItem(InventoryItemData data) { if (items.ContainsKey(data.type)) { Dictionary <string, InventoryItem> filteredItems = items[data.type]; if (filteredItems.ContainsKey(data.id)) { return(filteredItems[data.id]); } } return(null); }
public bool Add(InventoryItemData data) { if (!collectables.ContainsKey(data.id)) { if (collectables.Count < kMaxSize) { collectables.Add(data.id, data); RavenhillEvents.OnAddedToWishlist(data); return(true); } } return(false); }
public int SetItem(InventoryItemData item, int amount) { int leftOver = 0; Item = item; Amount = amount; if (Amount > item.MaxStackSize) { leftOver = Amount - Item.MaxStackSize; Amount = item.MaxStackSize; } return(leftOver); }
private void OnWishlistRemoved(InventoryItemData wishdata) { if (data != null) { if (wishdata.type == InventoryItemType.Collectable) { if (wishdata.id == data.id) { Setup(data); } } } }
public void Init(IInventoryDataReadonly inventoryData, InventoryItemData storageData) { if (storageData == null || inventoryData == null) { //TODO: Change to logger Debug.LogError("[InventoryItemView:Init] Invalid data!"); return; } _icon.color = storageData.Color; _count.text = inventoryData.Count.ToString(); _selected.gameObject.SetActive(inventoryData.IsSelected); }
public InventoryItem CreateInventoryItem(InventoryItemData inventoryItemData, Transform parentTransform) { // create new item on map InventoryItem inventoryItem = Instantiate(inventoryItemTemplate, parentTransform).GetComponent <InventoryItem>(); // set item data inventoryItem.InventoryItemData = inventoryItemData; // rename it // Debug.Log("Renaming " + inventoryItemData.inventoryItemID + " inventory item object"); inventoryItem.gameObject.name = inventoryItem.ItemName; // return item return(inventoryItem); }
public int GetItemCount(Item i) { int stack = 0; foreach (Vector2 v in items.Keys) { InventoryItemData myI = items[v]; if (myI.displayName == i.displayname) { stack += myI.EquipmentInstance.CurrentStack; } } return(stack); }
protected override void OnUse(InventoryItemData data) { base.OnUse(data); var searchbaleObj = FindObjectsOfType <BaseSearchableObject>().Where(bso => bso.isActive && !bso.isCollected).FirstOrDefault(); if (searchbaleObj) { Vector3 position = canvasService.GetUIWorldPosition(GetComponent <RectTransform>()); position.z = -30; GameObject instance = Instantiate <GameObject>(effectPrefab, position, Quaternion.identity); instance.GetComponentInChildren <EyeToolObject>().SetTarget(searchbaleObj.transform); searchbaleObj.SetCollectType(CollectType.Eye); } }
public void AddItemAt(string item_id, int slot, int quantity) { InventoryItemData invt_slot = GetItemSlot(slot); if (invt_slot.item_id == item_id) { int amount = invt_slot.quantity + quantity; inventory[slot] = new InventoryItemData(item_id, amount); } else if (invt_slot.quantity <= 0) { inventory[slot] = new InventoryItemData(item_id, quantity); } }
void Update() { if (!inventory) { return; } if (transform.childCount > 1) { itemData = transform.GetChild(1).GetComponent <InventoryItemData>(); transform.GetChild(0).GetComponent <Image>().sprite = inventory.itemSlotSprite; GetComponent <Image>().enabled = true; if (inventory.itemSlotMask) { GetComponent <Image>().sprite = inventory.itemSlotMask; } if (itemData.selected) { GetComponent <Image>().color = inventory.slotSelected; } else if (!isCombining) { GetComponent <Image>().color = inventory.slotNormal; } if (isCombining) { itemData.isDisabled = true; } else { itemData.isDisabled = false;; } } else if (transform.childCount < 2) { itemData = null; GetComponent <Image>().enabled = false; transform.GetChild(0).GetComponent <Image>().sprite = inventory.slotsSprite; transform.GetChild(0).GetComponent <Image>().color = Color.white; } if (isCombining) { inventory.CombineButton.interactable = false; } }
public void Store(InventoryItemData item, string prefab) { if (Hands) { // Store the current item. Player.Local.Holding.Item.RequestDataUpdate(); Player.Local.Holding.CmdDrop(false, false, Player.Local.gameObject, Player.Local.Holding.Item.Data.Serialize()); } else { // Remove from slot noramlly. Player.Local.GearMap[Slot].GetGearItem().Item.RequestDataUpdate(); Player.Local.NetUtils.CmdSetGear(Slot, null, null, true); } }
public void Activate(InventoryItemData pItemData, int pNewCount, RectTransform pDestinationRect, AudioClip pSoundEffect) { _newCount = pNewCount; _itemData = pItemData; Helper.LocalizeKeyToTopBar(pItemData.localizationKey); HutongGames.PlayMaker.Actions.SetEventProperties.properties = new Dictionary <string, object> { { "sprite", _itemData.sprite }, { "sound", pSoundEffect }, { "destinationIcon", pDestinationRect.gameObject }, }; _fsm.SendEvent("activate"); }
private static void UponQuickSlotSelect(int number) { if (tempSlotData.Data == null) { tempSlotData.Data = new ItemData(); tempSlotData.Data.Add("Quick Slot", number); } else { tempSlotData.Data.Update("Quick Slot", number); } tempSlotData = null; PlayerInventory.inv.Inventory.Refresh = true; }
public void Load(UXMLElement element) { collectables.Clear(); foreach (UXMLElement itemElement in element.Elements("item")) { string id = itemElement.GetString("id"); InventoryItemType type = itemElement.GetEnum <InventoryItemType>("type"); InventoryItemData data = resourceService.GetInventoryItemData(type, id); if (data != null) { collectables[data.id] = data; } } }
public void Setup(InventoryItemData data) { if (data == null) { iconImage.overrideSprite = resourceService.transparent; removeWishButton.DeactivateSelf(); } else { iconImage.overrideSprite = resourceService.GetSprite(data); removeWishButton.ActivateSelf(); removeWishButton.SetListener(() => { playerService.RemoveFromWishlist(data); }, engine.GetService <IAudioService>()); } }
//Use an item in your inventory and build it on the map public void BuildItem(int slot, Vector3 pos) { InventoryItemData invdata = PlayerData.Get().GetItemSlot(slot); ItemData idata = ItemData.Get(invdata.item_id); if (idata != null) { ConstructionData construct = idata.construction_data; if (construct != null) { PlayerData.Get().RemoveItemAt(slot, 1); Construction.Create(construct, pos); TheUI.Get().CancelSelection(); } } }
public void OnPointerClick(PointerEventData pEventData) { bool selected = !_selectedBackground.gameObject.activeSelf; SetSelected(selected); InventoryItemData itemData = GetTopMostItemData(); if (selected && itemData != null) { Helper.LocalizeKeyToTopBar(itemData.localizationKey, "Sheet1", false, true); } if (OnSelectInventoryItem != null) { OnSelectInventoryItem(this, selected); } }
public void RemoveItemAt(int slot, int quantity) { InventoryItemData invt_slot = GetItemSlot(slot); if (invt_slot.quantity > 0) { int amount = invt_slot.quantity - quantity; if (amount <= 0) { inventory.Remove(slot); } else { inventory[slot] = new InventoryItemData(invt_slot.item_id, amount); } } }
public bool TryGetItem(ushort id, out InventoryItemData iid) { if (items != null) { foreach (var ire in items) { if (ire.itemData.id == id) { iid = ire.itemData; return(true); } } } iid = null; return(false); }
private void RefreshInventory() { PlayerData pdata = PlayerData.Get(); for (int i = 0; i < slots.Length; i++) { InventoryItemData invdata = pdata.GetItemSlot(i); ItemData idata = ItemData.Get(invdata.item_id); if (idata != null) { slots[i].SetSlot(idata, invdata.quantity, selected_slot == i || selected_right_slot == i); } else { slots[i].SetSlot(null, 0, false); } } }
public Item GetItemInSlot(string slotname) { Vector2 nullSlot = new Vector2(-1, -1); foreach (InventoryContainer m_container in m_containers.Values) { Vector2 slot = m_container.getSlot(slotname); if (slot != nullSlot) { InventoryItemData i = m_container.GetItem(slot); if (i != null) { return(i.EquipmentInstance); } } } return(null); }
public void Anim_Done() { if (!hasAuthority) { return; } // Remove from holding, completely destroy... GetComponentInParent <PlayerHolding>().CmdDrop(false, true, Player.Local.gameObject, null); // Completely destroy this object... // Look for new throwable of same type in inventory, and if we find one... InventoryItemData i = PlayerInventory.inv.Inventory.GetOfType(Item.Prefab); if (i != null) { // Equip it! Item.Option_Equip(i, i.Prefab); } }
public void Setup(ChatMessage message, ChatAttachment attachment) { itemData = resourceService.GetInventoryItemData((InventoryItemType)attachment.item_type, attachment.id); this.message = message; this.sender = message.GetSender(); if (itemData != null) { iconImage.overrideSprite = resourceService.GetSprite(itemData); nameText.text = resourceService.GetString(itemData.nameId); giftButton.SetListener(() => { netService.SendGift(new Gift(netService.LocalPlayer, sender, itemData)); }, engine.GetService <IAudioService>()); UpdateIconImage(sender, itemData); UpdateGiftButtonState(sender, itemData); } }
public static void Option_ApplyAttachment(InventoryItemData x, string prefab) { // Set attachment... var attachment = x.Item.GetComponent <Attachment>(); if (attachment == null) { Debug.LogError("Attachment is null! What?"); return; } bool worked = Player.Local.Holding.Item.GetComponent <GunAttachments>().SetAttachment(Player.Local.gameObject, attachment.Type, attachment, x.Data); // Remove from inventory if (worked) { PlayerInventory.Remove(x.Prefab, Vector2.zero, false, 1); } }
public override void Setup(object objdata = null) { base.Setup(objdata); data = objdata as InventoryItemData; nameText.text = resourceService.GetString(data.nameId); descriptionText.text = resourceService.GetString(data.descriptionId); iconImage.overrideSprite = resourceService.GetSprite(data); priceText.text = data.price.price.ToString(); priceIconImage.overrideSprite = resourceService.GetPriceSprite(data.price); closeBigButton.SetListener(Close, engine.GetService <IAudioService>()); buyButton.SetListener(() => { if (playerService.Buy(data)) { Close(); } }, engine.GetService <IAudioService>()); }