public bool AddItem(ItemStats item, int initialAmount) { bool canStore = false; int amount = initialAmount; // Can I store new pickup? for (int i = 0, n = slots.Count; i < n; i++) { amount -= slots[i].SpaceLeft(item); if (amount <= 0) { canStore = true; break; } } if (!canStore) { return(false); } // Add item amount = initialAmount; for (int i = 0, n = slots.Count; i < n; i++) { amount -= slots[i].AddStackPortion(item, amount); if (amount == 0) { break; } } OnItemAdd?.Invoke(item, initialAmount); return(canStore); }
private void Add_AtAllClients(NameNetworkData data) { // if (!NetworkMagic.IsServer) // return; itemListServer.Add(data.Name); OnItemAdd?.Invoke(data.Name); }
private void HandleInitialize_AtClient(ListOfStringData data) { foreach (var name in data.ItemList) { itemListServer.Add(name); OnItemAdd?.Invoke(name); } DebugLog.Warning($"[SyncedListOfString-{EntityId}] Initialized, data: {string.Join(", ", itemListServer)}"); }
/// <summary> /// Adds a quantity of an item to the inventory /// </summary> /// <param name="name">The name of the item</param> /// <param name="amount">The amount to add</param> public void Add(string name, int amount) { var index = entities.FindIndex(e => e.name == name); if (index > -1) { quantities[index] += amount; OnItemAdd?.Invoke(entities[index], amount); } }
public void AddFragmentItem(FragmentName _name, GameObject ItemPrefab, Sprite _sprite) { if (_name == FragmentName.Null) { return; } ItemChild = Instantiate(ItemPrefab, transform).transform; ItemChild.GetComponent <Image>().sprite = _sprite; ItemChild.GetComponent <FragmentItem>().ItemFragment = FragmentFactory.GetFragment(_name); isEmpty = false; ItemChild.localPosition = Vector3.zero; OnItemAdd.Invoke(this, ItemChild.GetComponent <FragmentItem>()); }
public void AddItem(Item item) { if (inventory.Contains(item)) { Debug.Log(item.GetName() + " already exists. Call UpdateItem to modify " + item.GetName()); return; } inventory.Add(item); DisplayGrid(); OnItemAdd?.Invoke(item); }
private void OnAddEntity(EntityEventArgs args) { var ability = args.Entity as Ability; if (ability != null && ability.IsValid && ability.Id != AbilityId.ability_base) { var isMine = ability.Owner?.Handle == MyHero.Handle; if (isMine) { MyHero.AddAbility(ability); var type = types.FirstOrDefault( x => x.GetCustomAttributes <AbilityAttribute>().Any(z => z.AbilityId == ability.Id)); if (type != null) { MyHero.UsableAbilities.Add((UsableAbility)Activator.CreateInstance(type, ability, this)); } } OnAbilityAdd?.Invoke(null, new AbilityEventArgs(ability, isMine)); } var item = args.Entity as Item; if (item != null && item.IsValid && item.Id != AbilityId.ability_base) { var isMine = item.Purchaser?.Hero?.Handle == MyHero.Handle; if (isMine) { MyHero.AddItem(item); } OnItemAdd?.Invoke(null, new ItemEventArgs(item, isMine)); return; } var unit = args.Entity as Unit; if (unit != null && unit.IsValid && unit.IsRealUnit()) { Units.Add(unit); OnUnitAdd?.Invoke(null, new UnitEventArgs(unit)); } }
/// <summary> /// Adds an entity to the inventory /// </summary> /// <param name="obj">The entity to add</param> /// <param name="amount">The amount to add</param> public void Add(Entity obj, int amount) { var index = entities.IndexOf(obj); if (index > -1) { quantities[index] += amount; } else { entities.Add(obj); quantities.Add(amount); } // storedEntities[obj] += amount; OnItemAdd?.Invoke(obj, amount); }
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e) { if (OnItemRemove != null && e.OldItems != null) { foreach (var item in e.OldItems.Cast <TItem>()) { OnItemRemove?.Invoke(item); } } if (OnItemAdd != null && e.NewItems != null) { foreach (var item in e.NewItems.Cast <TItem>()) { OnItemAdd?.Invoke(item); } } if (!SuppressNotification) { base.OnCollectionChanged(e); } }