public static void InventoryUpdate() { if (OnInventoryUpdate != null) { OnInventoryUpdate.Invoke(); } }
public void Replace(string name, ObjectPartInventoryItem newItem, bool onlyIfExists = false) { ObjectPartInventoryItem oldItem; ScriptInstance script = null; newItem.Name = name; lock (m_DataLock) { if (TryGetValue(name, out oldItem)) { script = oldItem.RemoveScriptInstance; Remove(name); } else if (onlyIfExists) { throw new KeyNotFoundException(); } if (ContainsKey(newItem.ID)) { newItem.SetNewID(UUID.Random); } Add(newItem, false); } script?.Remove(); Interlocked.Increment(ref InventorySerial); if (oldItem != null) { oldItem.UpdateInfo.SetRemovedItem(); OnInventoryUpdate?.Invoke(oldItem.UpdateInfo); } OnInventoryUpdate?.Invoke(newItem.UpdateInfo); OnChange?.Invoke(ChangeAction.Add, PartID, newItem.ID, newItem.Name); }
/// <summary> /// Refreshes the player inventory /// </summary> /// <param name="itemArray">Array with the items</param> internal void RefreshPouch(sItem[] itemArray) { bool updateInventory = false; HashSet <int> set = itemArray.Select(i => i.ItemId).ToHashSet(); // Our Item pouch has 24 slots for (int i = 0; i < 24; i++) { sItem item = itemArray[i]; if (!items.ContainsKey(item.ItemId) || !items[item.ItemId].Equals(item)) { items[item.ItemId] = item; updateInventory = true; } set.Remove(item.ItemId); } // Our Ammo pouch only has 16 slots for (int i = 24; i < itemArray.Length; i++) { sItem item = itemArray[i]; if (!ammo.ContainsKey(item.ItemId) || !ammo[item.ItemId].Equals(item)) { ammo[item.ItemId] = item; updateInventory = true; } set.Remove(item.ItemId); } if (set.Count > 0) { updateInventory = true; } // Now we clear the dictionary to remove items that are not in our inventory anymore foreach (int id in set) { if (items.ContainsKey(id)) { items.Remove(id); } else if (ammo.ContainsKey(id)) { ammo.Remove(id); } } if (updateInventory) { OnInventoryUpdate?.Invoke(this, new InventoryUpdatedEventArgs(this)); } }
/** <summary>Used only within perm change logic</summary> */ public void TriggerItemUpdated(UUID id) { ObjectPartInventoryItem item; if (TryGetValue(id, out item)) { Interlocked.Increment(ref InventorySerial); OnInventoryUpdate?.Invoke(item.UpdateInfo); } }
public new void Add(UUID key1, string key2, ObjectPartInventoryItem item) { item.ParentFolderID = PartID; item.UpdateInfo.UpdateIDs(); base.Add(key1, key2, item); Interlocked.Increment(ref InventorySerial); OnInventoryUpdate?.Invoke(item.UpdateInfo); OnChange?.Invoke(ChangeAction.Add, PartID, item.ID, item.Name); }
public void GetUserInventory(GetUserInventoryResult res) { inventoryItems.Clear(); Instance.virtualCurrency = res.VirtualCurrency; foreach (var item in res.Inventory) { inventoryItems.Add(item); } OnInventoryUpdate?.Invoke(); }
public void SetNextOwnerAssetID(UUID key1, UUID assetID) { ObjectPartInventoryItem item; if (TryGetValue(key1, out item)) { item.NextOwnerAssetID = assetID; Interlocked.Increment(ref InventorySerial); OnInventoryUpdate?.Invoke(item.UpdateInfo); OnChange?.Invoke(ChangeAction.NextOwnerAssetID, PartID, item.ID, item.Name); } }
public new bool Remove(string key2, out ObjectPartInventoryItem item) { if (base.Remove(key2, out item)) { ScriptInstance script = item.RemoveScriptInstance; script?.Remove(); Interlocked.Increment(ref InventorySerial); item.UpdateInfo.SetRemovedItem(); OnInventoryUpdate?.Invoke(item.UpdateInfo); OnChange?.Invoke(ChangeAction.Remove, PartID, item.ID, item.Name); return(true); } return(false); }
public new void ChangeKey(string newKey, string oldKey) { ObjectPartInventoryItem item; lock (m_DataLock) { base.ChangeKey(newKey, oldKey); item = base[newKey]; item.Name = newKey; } Interlocked.Increment(ref InventorySerial); OnInventoryUpdate?.Invoke(item.UpdateInfo); OnChange?.Invoke(ChangeAction.Change, PartID, item.ID, item.Name); }
private void SendInventoryUpdates(SimulationEntity playerEntity) { InventorySlotMessage updates = new InventorySlotMessage(); List <byte> slots = new List <byte>(); if (playerEntity.Inventory == null) { return; } foreach ((byte slotId, IItem item) in playerEntity.Inventory.GetAllItems()) { if (item == null) { playerEntity.Inventory.Remove(slotId); } else { updates.SlotUpdates.Add(new InventorySlot { Count = item.StackSize(), Name = item.ItemConfigKey, ItemType = item.Configuration.ItemType, Mode = false, SlotId = slotId, TextureKey = item.Configuration.TextureKey }); } slots.Add(slotId); } foreach (byte slotId in playerEntity.InventorySlotHistory.Where(slotId => !slots.Contains(slotId))) { updates.SlotUpdates.Add(new InventorySlot { Mode = true, SlotId = slotId }); } playerEntity.InventorySlotHistory = slots; if (updates.SlotUpdates.Any()) { OnInventoryUpdate?.Invoke(playerEntity.EntityId, updates); } }
public virtual bool AddItem(Item item, int count, out int addedIndex) { if (maxVolume != -1 && maxVolume < totalVolume + item.volume * count) { addedIndex = -1; return(false); } else { totalWeight += item.grams * count; totalVolume += item.volume * count; } if (FindItem(item, out InventoryEntry result, out addedIndex)) { result.count += count; inventory[addedIndex] = result; OnInventoryUpdate?.Invoke(addedIndex, inventory[addedIndex]); }
public bool Rename(string newKey, UUID itemid) { bool renamed = false; ObjectPartInventoryItem item; lock (m_DataLock) { if (base.TryGetValue(itemid, out item) && item.Name != newKey) { base.ChangeKey(newKey, item.Name); item.Name = newKey; renamed = true; } } if (renamed) { Interlocked.Increment(ref InventorySerial); OnInventoryUpdate?.Invoke(item.UpdateInfo); OnChange?.Invoke(ChangeAction.Change, PartID, item.ID, item.Name); } return(renamed); }
private void InventoryUpdateCaller(EventArgs args) { OnInventoryUpdate?.Invoke(this, args); }
public void RemoveOnInventoryUpdateListener(OnInventoryUpdate listener) { onInventoryUpdate -= listener; }
public void TriggerInventoryUpdate(List <ItemQuantity> obtainedItems) => OnInventoryUpdate?.Invoke(obtainedItems);
public void InventoryUpdateEvent(Inventory inv) => OnInventoryUpdate?.Invoke(this);
public void AddOnInventoryUpdateListener(OnInventoryUpdate listener) { onInventoryUpdate += listener; }