public IActionResult GetSurvivalInventory()
        {
            var inv        = InventoryUtils.ReadInventory(User.FindFirstValue(ClaimTypes.NameIdentifier));
            var jsonstring = JsonConvert.SerializeObject(inv);

            return(Content(jsonstring, "application/json"));
        }
示例#2
0
        void EmptyInventory(IMyInventory inventory, int fetchAmount)
        {
            List <MyInventoryItem> items = new List <MyInventoryItem>();

            inventory.GetItems(items);
            items.ForEach(item => InventoryUtils.TransferItemToAvailableInventory(item, item.Amount, inventory, SourceInventories, fetchAmount));
        }
示例#3
0
    public void CollectiblesWork()
    {
        var go = new InventoryUtils();

        go.collectItem(1);
        Assert.AreEqual(1, go.collectedItems());
    }
 public bool HandleTransaction(GETInventoryItemTransactionStart transactionStart, GETInventoryItemTransactionEnd transactionEnd)
 {
     if (transactionEnd.success)
     {
         //after getting item from inventory place it in bank and send update to client
         if (transactionStart.postTransactionAction == (byte)PostTransactionAction.AddToBank)
         {
             if (bank != null)
             {
                 if (transactionEnd.result != null)
                 {
                     Hashtable itemHash = transactionEnd.result as Hashtable;
                     if (itemHash != null)
                     {
                         int cnt     = 0;
                         var itemObj = InventoryUtils.Create(itemHash, out cnt);
                         if (itemObj != null)
                         {
                             bank.AddItem(itemObj, transactionEnd.count);
                             SendBankUpdate();
                             return(true);
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
示例#5
0
文件: Bank.cs 项目: OlegGelezcov/neb
        public bool AddItem(Hashtable item)
        {
            int count = 0;
            var obj   = InventoryUtils.Create(item, out count);

            return(AddItem(obj, count));
        }
示例#6
0
        bool AddItemToInventory(string type, int amountRequired, int fetchAmount)
        {
            int amountRemaining = amountRequired;

            for (int i = 0; i < SourceInventories.Count; i++)
            {
                IMyInventory sourceInventory    = SourceInventories[i];
                Nullable <MyInventoryItem> item = InventoryUtils.FindItemInInventoryBySubType(sourceInventory, type);
                if (item.HasValue)
                {
                    int  amountToAdd = item.Value.Amount.ToIntSafe() > amountRemaining ? amountRemaining : item.Value.Amount.ToIntSafe();
                    bool result      = InventoryUtils.TransferItemToAvailableInventory(item.Value, (MyFixedPoint)amountToAdd, sourceInventory, MyInventories, fetchAmount);
                    if (result)
                    {
                        amountRemaining = amountRemaining - amountToAdd;
                    }
                }
                if (amountRemaining <= 0)
                {
                    return(true);
                }
            }
            ;

            return(false);
        }
示例#7
0
    public void InventoryWorkTest()
    {
        var go = new InventoryUtils();

        go.setInventoryData("VerySeriousKey");
        Assert.AreEqual(true, go.getInventoryData().Contains("VerySeriousKey"));
    }
示例#8
0
        public void Main(string argument, UpdateType updateSource)
        {
            List <IMyShipConnector> connectors = new List <IMyShipConnector>();

            GridTerminalSystem.GetBlocksOfType <IMyShipConnector>(connectors, b => b.IsSameConstructAs(Me));
            if (connectors.Count == 0 || connectors[0].Status != MyShipConnectorStatus.Connected)
            {
                throw new Exception("Ship needs a connector that is connected");
            }

            IMyShipConnector targetConnector = connectors[0].OtherConnector;

            List <IMyTerminalBlock> blocks       = new List <IMyTerminalBlock>();
            List <IMyTerminalBlock> sourceBlocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(blocks, b => b.IsSameConstructAs(Me));
            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(sourceBlocks, b => !b.IsSameConstructAs(Me));

            MyInventories     = InventoryUtils.GetInventoriesFromBlocks(blocks);
            SourceInventories = InventoryUtils.GetInventoriesFromBlocks(sourceBlocks);

            if (argument.Equals("flush"))
            {
                FlushInventories();
            }
            else if (argument.Equals("import"))
            {
                ImportItemsIntoInventory();
            }
        }
示例#9
0
    public void TransferItemsWithFullDestinationInventory_test()
    {
        Inventory   source      = new Inventory(5);
        Inventory   destination = new Inventory(4);
        List <Item> items       = new List <Item> {
            new Item(GetItemDataFixture(0), 2 * Inventory.MAX_STACK),
            new Item(GetItemDataFixture(1), Inventory.MAX_STACK),
            new Item(GetItemDataFixture(2), 2 * Inventory.MAX_STACK)
        };

        source.AddItemsToInventory(items, out List <Item> remainingItemsToBeAdded);
        Assert.That(remainingItemsToBeAdded.Count, Is.EqualTo(0));

        InventoryUtils.TransferItems(source, destination, source.GetItems(), out List <Item> remainingItemsToTransfer);
        Assert.That(remainingItemsToTransfer.Count, Is.EqualTo(1));

        Assert.That(source.GetNumberOfAvailableSlotForItem(GetItemDataFixture(0)), Is.EqualTo(4 * Inventory.MAX_STACK));
        Assert.That(source.GetItemAtIndex(4), Is.EqualTo(new Item(GetItemDataFixture(2), Inventory.MAX_STACK)));

        Assert.That(destination.GetNumberOfAvailableSlotForItem(GetItemDataFixture(0)), Is.EqualTo(0));
        Assert.That(destination.GetItemAtIndex(0), Is.EqualTo(new Item(GetItemDataFixture(0), Inventory.MAX_STACK)));
        Assert.That(destination.GetItemAtIndex(1), Is.EqualTo(new Item(GetItemDataFixture(0), Inventory.MAX_STACK)));
        Assert.That(destination.GetItemAtIndex(2), Is.EqualTo(new Item(GetItemDataFixture(1), Inventory.MAX_STACK)));
        Assert.That(destination.GetItemAtIndex(3), Is.EqualTo(new Item(GetItemDataFixture(2), Inventory.MAX_STACK)));
    }
示例#10
0
 public Hashtable GetInfo()
 {
     m_Raw = InventoryUtils.ItemHash(Id, Level, ObjectColor.white, Type, (PlacingType)placingType, binded, splittable);
     m_Raw.Add((int)SPC.Contract, contractId);
     m_Raw.Add((int)SPC.IsNew, isNew);
     return(m_Raw);
 }
示例#11
0
    public void InventoryShouldntContainData()
    {
        var go = new InventoryUtils();

        go.setInventoryData("VerySeriousKey");
        Assert.AreEqual(false, go.getInventoryData().Contains("dickbutt"));
    }
示例#12
0
        public void CreatingNonStackableItemWithAmountOverOneWillThrowException(int itemAmount)
        {
            var meta = InventoryUtils.CreateItemMeta(flags: ItemFlags.NotStackable);

            Action act = () => this.itemFactory.CreateItem(meta, itemAmount);

            act.Should().Throw <ItemNotStackableException>();
        }
示例#13
0
 public Hashtable GetInfo()
 {
     rawHash = InventoryUtils.ItemHash(Id, Level, ObjectColor.white, Type, (PlacingType)placingType, binded, splittable);
     rawHash.Add((int)SPC.Quest, questId);
     rawHash.Add((int)SPC.IsNew, isNew);
     rawHash.Add((int)SPC.Interactable, interactable);
     return(rawHash);
 }
示例#14
0
        public Hashtable GetInfo()
        {
            var hash = InventoryUtils.ItemHash(Id, Level, ObjectColor.white, InventoryObjectType.credits_bag, PlacingType.Inventory, binded, splittable);

            hash.Add((int)SPC.Value, count);
            hash.Add((int)SPC.IsNew, m_IsNew);
            return(hash);
        }
示例#15
0
    public void TransferItemsWithEmptySourceInventory_test()
    {
        Inventory source      = new Inventory(5);
        Inventory destination = new Inventory(5);

        InventoryUtils.TransferItems(source, destination, source.GetItems(), out List <Item> remainingItemsToTransfer);
        Assert.That(remainingItemsToTransfer.Count, Is.EqualTo(0));
    }
示例#16
0
        public Hashtable GetInfo()
        {
            Hashtable hash = InventoryUtils.ItemHash(Id, Level, Pet2ObjColor(), Type, (PlacingType)placingType, binded, splittable);

            hash.Add((int)SPC.PetColor, (int)petColor);
            hash.Add((int)SPC.IsNew, isNew);
            m_Raw = hash;
            return(hash);
        }
示例#17
0
        public Hashtable GetInfo()
        {
            Hashtable hash = InventoryUtils.ItemHash(Id, Level, ObjectColor.white, Type, (PlacingType)placingType, binded, splittable);

            hash.Add((int)SPC.Skin, skin);
            hash.Add((int)SPC.IsNew, isNew);
            m_Raw = hash;
            return(hash);
        }
示例#18
0
    public void TransferItemWithNegativeAmount_test()
    {
        Inventory source      = new Inventory(1);
        Inventory destination = new Inventory(1);
        ItemData  itemData    = GetItemDataFixture();

        Assert.That(InventoryUtils.TransferItem(source, destination, itemData, -1), Is.False);
        Assert.That(source.CheckIfItemExistsInInventory(itemData), Is.False);
        Assert.That(destination.CheckIfItemExistsInInventory(itemData), Is.False);
    }
示例#19
0
        public async Task <IActionResult> PutItemInHotbar()
        {
            var stream = new StreamReader(Request.Body);
            var body   = await stream.ReadToEndAsync();

            string authtoken    = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var    newHotbar    = JsonConvert.DeserializeObject <InventoryResponse.Hotbar[]>(body);
            var    returnHotbar = InventoryUtils.EditHotbar(authtoken, newHotbar);

            return(Content(JsonConvert.SerializeObject(returnHotbar.Item2)));
        }
示例#20
0
        private Mock <IItem> CreateMockItem(string handle = "item", int weight = 1)
        {
            var mock = new Mock <IItem>();

            mock.SetupGet(x => x.RuntimeId).Returns(Guid.NewGuid());

            mock.SetupGet(x => x.Meta)
            .Returns(InventoryUtils.CreateItemMeta(handle, typeof(FakeItem), "Item", weight));

            return(mock);
        }
示例#21
0
        public virtual Item[] GetDrops(Item tool)
        {
            // Get a bitmask for drops that need metadata values for variant, but not for runtime data (rotation, etc)
            int metadataMax = InventoryUtils.GetCreativeMetadataSlots().Where(item => item.Id == Id).Max(item => item.Metadata);

            for (int i = metadataMax; i != 0; i = i >> 1)
            {
                metadataMax |= i;
            }

            return(new Item[] { new ItemBlock(this, (short)(Metadata & metadataMax))
                                {
                                    Count = 1
                                } });
        }
示例#22
0
 public void SetItems(List <Hashtable> items)
 {
     this._items = new ConcurrentDictionary <InventoryObjectType, ConcurrentDictionary <string, ServerInventoryItem> >();
     foreach (var item in items)
     {
         int       count     = item.GetValue <int>((int)SPC.Count, 0);
         Hashtable info      = item.GetValue <Hashtable>((int)SPC.Info, new Hashtable());
         int       dumpCount = 0;
         var       obj       = InventoryUtils.Create(info, out dumpCount);
         if (count > 0)
         {
             this.Add(obj, count);
         }
     }
 }
示例#23
0
文件: Skins.cs 项目: rustmy/rustylife
 public void LastPage()
 {
     if (page > 0)
     {
         container.itemList.ToList().ForEach(p =>
         {
             removed = false;
             p.RemoveFromContainer();
             p.Remove();
         });
         foreach (var skin in skins[--page])
         {
             insertItem = InventoryUtils.CloneItem(item, skin);
             insertItem.MoveToContainer(container, -1, false);
         }
     }
 }
示例#24
0
        void ImportItemsIntoInventory()
        {
            Config config = new Config(Me);
            Dictionary <string, MyFixedPoint> ItemsToGet = config.ItemList;

            Dictionary <string, MyFixedPoint> .Enumerator en = ItemsToGet.GetEnumerator();
            while (en.MoveNext())
            {
                int CurrentAmountInInventory = InventoryUtils.FindNumberOfItemInInventoriesBySubType(MyInventories, en.Current.Key);
                int amountToGet = en.Current.Value.ToIntSafe() - CurrentAmountInInventory;
                if (amountToGet > 0)
                {
                    Echo($"Getting {amountToGet} {en.Current.Key}");
                    AddItemToInventory(en.Current.Key, amountToGet, config.FetchAmount);
                }
            }
        }
示例#25
0
        public void Setup()
        {
            this.serviceProviderMock = new Mock <IServiceProvider>();

            this.itemRegistry = new ItemRegistry();

            this.defaultMeta             = InventoryUtils.CreateItemMeta(DefaultItemHandle, typeof(FakeItem), "Fake Item");
            this.nonStackableDefaultMeta = InventoryUtils.CreateItemMeta(DefaultNonStackableItemHandle, typeof(FakeItem), "Fake Item", flags: ItemFlags.NotStackable);

            this.itemRegistry.AddItemMeta(this.defaultMeta);
            this.itemRegistry.AddItemMeta(this.nonStackableDefaultMeta);

            this.itemRegistry.ValidateAndCacheItemMeta();

            this.AddItemResolveToServiceProvider <FakeItem>();

            this.itemFactory = new ItemFactory(this.itemRegistry, this.serviceProviderMock.Object);
        }
示例#26
0
        private void UpdateView()
        {
            var alpha = 1f;

            if (_itemStack.GetCount() == 0)
            {
                alpha        = 0f;
                Image.sprite = null;
            }
            else
            {
                Image.sprite = _itemStack.GetItems()[0].GetSprite();
                Text.text    = _itemStack.GetCount().ToString();
            }

            Image.color = InventoryUtils.ChangeAlpha(Image.color, alpha);
            Text.color  = InventoryUtils.ChangeAlpha(Text.color, alpha);
        }
示例#27
0
    public void TransferItemWithFullDestination_test()
    {
        Inventory source      = new Inventory(1);
        Inventory destination = new Inventory(1);

        ItemData itemData = GetItemDataFixture();

        List <int> indexes = new List <int>();

        Assert.That(destination.AddItemToInventory(itemData, Inventory.MAX_STACK, ref indexes), Is.True);
        Assert.That(indexes[0], Is.EqualTo(0));

        Assert.That(InventoryUtils.TransferItem(source, destination, itemData, 15), Is.False);

        Assert.That(source.CheckIfItemExistsInInventory(itemData), Is.False);
        Assert.That(destination.CheckIfItemExistsInInventory(itemData, out int amount), Is.True);
        Assert.That(amount, Is.EqualTo(Inventory.MAX_STACK));
    }
示例#28
0
        public static DCustomEquipment?GetEquipmentFromDreward(DReward reward)
        {
            InventoryData component = Service.Get <CPDataEntityCollection>().GetComponent <InventoryData>(Service.Get <CPDataEntityCollection>().LocalPlayerHandle);

            if (component != null && component.Inventory != null)
            {
                Dictionary <long, InventoryIconModel <DCustomEquipment> > .Enumerator enumerator = component.Inventory.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    InventoryIconModel <DCustomEquipment> value = enumerator.Current.Value;
                    if (InventoryUtils.IsEquipmentEqual(value.Data, reward.EquipmentRequest))
                    {
                        return(value.Data);
                    }
                }
            }
            return(null);
        }
        private void onGetInventoryComplete()
        {
            Reward reward = item.Definition.Reward.ToReward();

            if (reward.TryGetValue <EquipmentInstanceReward>(out var rewardable))
            {
                CustomEquipment[] array = rewardable.EquipmentInstances.ToArray();
                reward.ClearReward(typeof(EquipmentInstanceReward));
                for (int i = 0; i < array.Length; i++)
                {
                    if (InventoryUtils.TryGetDCustomEquipment(array[i], out var equipmentData))
                    {
                        array[i].equipmentId = equipmentData.Id;
                    }
                    reward.Add(new EquipmentInstanceReward(array[i]));
                }
            }
            Service.Get <EventDispatcher>().DispatchEvent(new DisneyStoreEvents.PurchaseComplete(reward));
            hidePurchaseModal();
        }
示例#30
0
        public void ParseInfo(Hashtable info)
        {
            this._maxSlots = info.GetValue <int>((int)SPC.MaxSlots, 0);
            object[] items = info.GetValue <object[]>((int)SPC.Items, new object[] { });
            this._items = new ConcurrentDictionary <InventoryObjectType, ConcurrentDictionary <string, ServerInventoryItem> >();

            if (items != null)
            {
                foreach (object objItem in items)
                {
                    if (objItem is Hashtable)
                    {
                        Hashtable itemInfo = objItem as Hashtable;
                        int       count    = 0;
                        var       obj      = InventoryUtils.Create(itemInfo, out count);
                        if (count > 0 && obj != null)
                        {
                            this.Add(obj, count);
                        }
                    }
                }
            }
        }