public bool Add(Entity item) { if (!_entityContainer.Add(item)) { return(false); } item.ParentId = this.GetEntity(); var abilityData = item.Get <AbilityData>(); if (abilityData == null) { var spellData = item.Get <SpellData>(); if (spellData != null) { AddSpell(spellData, item); } } else { AddAbility(abilityData, item); } item.Get <InventoryItem>().SetContainer(this); var msg = new ContainerStatusChanged(this, item); item.Post(msg); this.GetEntity().Post(msg); OnRefreshItemList.SafeInvoke(); return(true); }
public void Handle(ContainerStatusChanged arg) { for (int i = 0; i < List.Count; i++) { List[i].Handle(arg); } }
public void Clear() { _entityContainer.Clear(); var msg = new ContainerStatusChanged(this, null); this.GetEntity().Post(msg); OnRefreshItemList.SafeInvoke(); }
private void ProcessEntityRemoval(Entity entity) { entity.Get <InventoryItem>()?.SetContainer(null); entity.ParentId = -1; var msg = new ContainerStatusChanged(null, entity); entity.Post(msg); this.GetEntity().Post(msg); }
private void ProcessHolderChange(IEntityContainer holder, Entity item, InventoryItem inventoryItem, int newIndex) { inventoryItem.SetContainer(holder); item.ParentId = holder.Owner; inventoryItem.Index = newIndex; var msg = new ContainerStatusChanged(holder, item); item.Post(msg); holder.Owner.Post(msg); holder.Owner.Post(new ContainerChanged(holder)); }
public bool Remove(Entity entity) { if (!_container.Contains(entity)) { return(false); } var msg = new ContainerStatusChanged(null, entity); entity.Post(msg); this.GetEntity().Post(msg); OnRefreshItemList.SafeInvoke(); return(true); }
public bool Remove(Entity entity) { if (!_entityContainer.Add(entity)) { return(false); } entity.Get <InventoryItem>()?.SetContainer(null); entity.ParentId = -1; var msg = new ContainerStatusChanged(null, entity); entity.Post(msg); this.GetEntity().Post(msg); OnRefreshItemList.SafeInvoke(); return(true); }
private bool SetupNewEntity(Entity entity) { InventoryItem containerItem = entity.Get <InventoryItem>(); if (containerItem == null) { return(false); } if (containerItem.Inventory != null) { containerItem.Inventory.Remove(entity); } containerItem.SetContainer(this); entity.ParentId = this.GetEntity(); var msg = new ContainerStatusChanged(this, entity); entity.Post(msg); this.GetEntity().Post(msg); return(true); }
public bool Remove(Entity entity) { if (!Contains(entity)) { return(false); } _array.Remove(entity); if (_entityLookup.TryGetValue(entity, out var cached)) { _cachePool.Store(cached); _entityLookup.Remove(entity); } entity.Get <InventoryItem>()?.SetContainer(null); entity.ParentId = -1; var msg = new ContainerStatusChanged(null, entity); entity.Post(msg); this.GetEntity().Post(msg); return(true); }
public virtual bool Add(Entity entity) { if (entity == null) { return(false); } if (!CanAdd(entity)) { return(false); } InventoryItem containerItem = entity.Get <InventoryItem>(); if (RequiresInventoryComponent) { if (containerItem == null) { return(false); } if (containerItem.Inventory != null) { containerItem.Inventory.Remove(entity); } } if (containerItem != null) { containerItem.SetContainer(this); } _list.Add(entity); entity.ParentId = Owner; var msg = new ContainerStatusChanged(this, entity); entity.Post(msg); this.GetEntity().Post(msg); OnRefreshItemList.SafeInvoke(); return(true); }