Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public void Handle(ContainerStatusChanged arg)
 {
     for (int i = 0; i < List.Count; i++)
     {
         List[i].Handle(arg);
     }
 }
Exemplo n.º 3
0
        public void Clear()
        {
            _entityContainer.Clear();
            var msg = new ContainerStatusChanged(this, null);

            this.GetEntity().Post(msg);
            OnRefreshItemList.SafeInvoke();
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }