Exemple #1
0
        public bool Run(params object[] args)
        {
            NWPlaceable container = (Object.OBJECT_SELF);
            NWPlayer    oPC       = (_.GetLastDisturbed());
            NWItem      oItem     = (_.GetInventoryDisturbItem());
            int         type      = _.GetInventoryDisturbType();

            if (type == NWScript.INVENTORY_DISTURB_TYPE_ADDED)
            {
                container.AssignCommand(() => _.ActionGiveItem(oItem.Object, oPC.Object));
                return(true);
            }

            int            overflowItemID = oItem.GetLocalInt("TEMP_OVERFLOW_ITEM_ID");
            PCOverflowItem overflowItem   = _data.Get <PCOverflowItem>(overflowItemID);

            _data.SubmitDataChange(overflowItem, DatabaseActionType.Delete);
            oItem.DeleteLocalInt("TEMP_OVERFLOW_ITEM_ID");

            if (!container.InventoryItems.Any())
            {
                container.Destroy();
            }
            return(true);
        }
        public bool Run(params object[] args)
        {
            NWPlaceable container = NWPlaceable.Wrap(Object.OBJECT_SELF);
            NWPlayer    oPC       = NWPlayer.Wrap(_.GetLastDisturbed());
            NWItem      oItem     = NWItem.Wrap(_.GetInventoryDisturbItem());
            int         type      = _.GetInventoryDisturbType();

            if (type == INVENTORY_DISTURB_TYPE_ADDED)
            {
                container.AssignCommand(() => _.ActionGiveItem(oItem.Object, oPC.Object));
                return(true);
            }

            int            overflowItemID = oItem.GetLocalInt("TEMP_OVERFLOW_ITEM_ID");
            PCOverflowItem overflowItem   = _db.PCOverflowItems.Single(x => x.PCOverflowItemID == overflowItemID);

            _db.PCOverflowItems.Remove(overflowItem);
            _db.SaveChanges();

            oItem.DeleteLocalInt("TEMP_OVERFLOW_ITEM_ID");

            if (container.InventoryItems.Count <= 0)
            {
                container.Destroy();
            }
            return(true);
        }
Exemple #3
0
        private void ProcessItem(NWPlayer oPC, NWItem item, Dictionary <string, PCMigrationItem> itemMap, List <int> stripItemList)
        {
            string          resref         = item.Resref;
            int             quantity       = item.StackSize;
            int             baseItemTypeID = item.BaseItemType;
            PCMigrationItem migrationItem  = itemMap[resref];

            if (itemMap.ContainsKey(resref))
            {
                item.Destroy();
                if (!string.IsNullOrWhiteSpace(migrationItem.NewResref))
                {
                    NWItem newItem = NWItem.Wrap(_.CreateItemOnObject(migrationItem.NewResref, oPC.Object, quantity));
                    if (!newItem.Possessor.IsValid)
                    {
                        PCOverflowItem overflow = new PCOverflowItem
                        {
                            ItemResref = newItem.Resref,
                            ItemTag    = newItem.Tag,
                            ItemName   = newItem.Name,
                            ItemObject = _serialization.Serialize(newItem),
                            PlayerID   = oPC.GlobalID
                        };
                        _db.PCOverflowItems.Add(overflow);
                        _db.SaveChanges();

                        newItem.Destroy();
                    }
                }
            }
            else if (stripItemList.Contains(baseItemTypeID))
            {
                _item.StripAllItemProperties(item);
            }
        }
        public void GetByID_OneItem_ReturnsPCOverflowItem()
        {
            // Arrange
            var            id     = Guid.NewGuid();
            PCOverflowItem entity = new PCOverflowItem {
                ID = id
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <PCOverflowItem>(entity));

            // Assert
            Assert.AreNotSame(entity, _cache.GetByID(id));
        }
        public void GetByID_TwoItems_ReturnsCorrectObject()
        {
            // Arrange
            var            id1     = Guid.NewGuid();
            var            id2     = Guid.NewGuid();
            PCOverflowItem entity1 = new PCOverflowItem {
                ID = id1
            };
            PCOverflowItem entity2 = new PCOverflowItem {
                ID = id2
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <PCOverflowItem>(entity1));
            MessageHub.Instance.Publish(new OnCacheObjectSet <PCOverflowItem>(entity2));

            // Assert
            Assert.AreNotSame(entity1, _cache.GetByID(id1));
            Assert.AreNotSame(entity2, _cache.GetByID(id2));
        }
        public void GetByID_RemovedItem_ReturnsCorrectObject()
        {
            // Arrange
            var            id1     = Guid.NewGuid();
            var            id2     = Guid.NewGuid();
            PCOverflowItem entity1 = new PCOverflowItem {
                ID = id1
            };
            PCOverflowItem entity2 = new PCOverflowItem {
                ID = id2
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <PCOverflowItem>(entity1));
            MessageHub.Instance.Publish(new OnCacheObjectSet <PCOverflowItem>(entity2));
            MessageHub.Instance.Publish(new OnCacheObjectDeleted <PCOverflowItem>(entity1));

            // Assert
            Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(id1); });
            Assert.AreNotSame(entity2, _cache.GetByID(id2));
        }
Exemple #7
0
        public void Main()
        {
            NWPlaceable container = (NWGameObject.OBJECT_SELF);
            NWPlayer    oPC       = (_.GetLastDisturbed());
            NWItem      oItem     = (_.GetInventoryDisturbItem());
            int         type      = _.GetInventoryDisturbType();

            if (type == _.INVENTORY_DISTURB_TYPE_ADDED)
            {
                container.AssignCommand(() => _.ActionGiveItem(oItem.Object, oPC.Object));
                return;
            }

            Guid           overflowItemID = new Guid(oItem.GetLocalString("TEMP_OVERFLOW_ITEM_ID"));
            PCOverflowItem overflowItem   = DataService.PCOverflowItem.GetByID(overflowItemID);

            DataService.SubmitDataChange(overflowItem, DatabaseActionType.Delete);
            oItem.DeleteLocalInt("TEMP_OVERFLOW_ITEM_ID");

            if (!container.InventoryItems.Any())
            {
                container.Destroy();
            }
        }