Пример #1
0
        public void InventoryEventsTest()
        {
            BaseItem herb = ItemDatabase.GetItemByName("Herb");
            BaseItem coin = ItemDatabase.GetItemByName("Coin");

            // Simple Inventory
            simpleInventory = new SimpleInventory();

            simpleInventory.OnItemAdded   += new ItemAddedHandler(ItemAdded);
            simpleInventory.OnItemRemoved += new ItemRemovedHandler(ItemRemoved);

            simpleInventory.AddItem(herb.Id);
            simpleInventory.AddItem(herb.Id);
            simpleInventory.RemoveItem(herb.Id);
            simpleInventory.RemoveItem(herb.Id);
            simpleInventory.RemoveItem(herb.Id);

            Assert.AreEqual(2, _itemAddedCalled);
            Assert.AreEqual(2, _itemRemovedCalled);

            // Player Inventory
            playerInventory = new PlayerInventory();

            playerInventory.OnItemAdded   += new ItemAddedHandler(ItemAdded);
            playerInventory.OnItemRemoved += new ItemRemovedHandler(ItemRemoved);

            playerInventory.AddItem(herb.Id);
            playerInventory.AddItem(herb.Id);
            playerInventory.RemoveItem(herb.Id);
            playerInventory.RemoveItem(herb.Id);
            playerInventory.RemoveItem(herb.Id);

            Assert.AreEqual(4, _itemAddedCalled);
            Assert.AreEqual(4, _itemRemovedCalled);
        }
Пример #2
0
        /// <summary>
        /// Returns inventory of a steam user
        /// </summary>
        /// <param name="steamid">SteamId64 of user</param>
        /// <returns>Returns simple inventory items list</returns>
        public List <SimpleInventory.InventoryItem> GetUserInventory(ulong steamid)
        {
            var inv = new SimpleInventory(mSteam.Web);

            inv.Load(steamid, 730, 2);

            mLog.Write(Log.LogLevel.Debug, $"Loaded {inv.Items.Count} items from {steamid}'s inventory");
            return(inv.Items);
        }
Пример #3
0
    // Run this when new level loaded
    public void NewLevelStuff()
    {
        // Setting player's position to a specific position everytime camera is loaded (every scene)
        // y axis is 5 so player doesn't get stuck in floor when downward force is applied
        player.position = new Vector3(0, 5, 0);

        // assigning reference to inventory script
        inventoryRef = player.GetComponent <SimpleInventory>();

        StartCoroutine(SetEnv());
    }
Пример #4
0
        public void MergeInventoriesTest()
        {
            playerInventory = new PlayerInventory();
            Assert.AreEqual(0, playerInventory.ItemCount);
            BaseItem herb = ItemDatabase.GetItemByName("Herb");

            simpleInventory = new SimpleInventory(new int[] { herb.Id },
                                                  new int[] { 10 });
            playerInventory.AddInventory(simpleInventory);
            Assert.AreEqual(1, playerInventory.ItemCount);
            Assert.AreEqual(10, playerInventory.GetQuantity(herb.Id));
        }
Пример #5
0
        public override void Interact(GameObject interacter)
        {
            SimpleInventory inventory = interacter.GetComponent <Interacter>().inventory;

            if (!inventory)
            {
                return;
            }

            inventory.AddItem(item);
            Take();
        }
Пример #6
0
        public void ResetInventoryTest()
        {
            BaseItem herb = ItemDatabase.GetItemByName("Herb");
            BaseItem coin = ItemDatabase.GetItemByName("Coin");

            simpleInventory = new SimpleInventory(new int[] { herb.Id },
                                                  new int[] { 1 });
            playerInventory = new PlayerInventory(new int[] { herb.Id },
                                                  new int[] { 1 });
            Assert.AreEqual(1, playerInventory.ItemCount);
            Assert.AreEqual(1, simpleInventory.ItemCount);
            simpleInventory.Reset();
            playerInventory.Reset();
            Assert.AreEqual(0, playerInventory.ItemCount);
            Assert.AreEqual(0, simpleInventory.ItemCount);
        }
Пример #7
0
    // Start is called before the first frame update
    void Start()
    {
        inventory    = GetComponent <SimpleInventory>();
        navMeshAgent = GetComponent <NavMeshAgent>();

        if (!inventory.CurrentItem)
        {
            // find closest item to you in the scene. Might be good to do this with a K-d tree, but actually you
            // want the distance by navmesh, so it will have to be O(n).

            // could also be done with boids if we have enough AIs

            GameObject itemToGet = GameManager.instance.FindClosestItem(transform.position);

            navMeshAgent.destination = itemToGet.transform.position;
        }

        inventory.onCurrentItemChanged += CurrentItemChanged;
    }
Пример #8
0
        public void SimpleInventoryTest()
        {
            BaseItem herb = ItemDatabase.GetItemByName("Herb");
            BaseItem coin = ItemDatabase.GetItemByName("Coin");

            simpleInventory = new SimpleInventory(new int[] { herb.Id },
                                                  new int[] { 1 });
            Assert.AreEqual(1, simpleInventory.ItemCount);
            Assert.AreEqual(1, simpleInventory.GetQuantity(herb.Id));
            Assert.AreEqual(0, simpleInventory.GetQuantity(coin.Id));

            // Adding and removing to and from a simple Inventory have no effect.
            simpleInventory.AddItem(coin.Id);
            Assert.AreEqual(1, simpleInventory.GetQuantity(coin.Id));
            simpleInventory.RemoveItem(herb.Id);
            Assert.AreEqual(0, simpleInventory.GetQuantity(herb.Id));

            // Test the pretty representation
            simpleInventory.ToString();
        }
Пример #9
0
        public void SerializeInventoryTest()
        {
            BaseItem herb = ItemDatabase.GetItemByName("Herb");
            BaseItem coin = ItemDatabase.GetItemByName("Coin");

            simpleInventory = new SimpleInventory(new int[] { herb.Id, coin.Id },
                                                  new int[] { 1, 2 });
            playerInventory = new PlayerInventory(new int[] { herb.Id, coin.Id },
                                                  new int[] { 1, 2 });

            // Deserialize
            BinarySerialize(simpleInventory);
            var deserializedSimpleInventory = (SimpleInventory)BinaryDeserialize(simpleInventory);

            TestInventory(simpleInventory, deserializedSimpleInventory);
            BinarySerialize(playerInventory);
            var deserializedPlayerInventory = (PlayerInventory)BinaryDeserialize(playerInventory);

            TestInventory(playerInventory, deserializedPlayerInventory);
        }
Пример #10
0
 // Use this for initialization
 void Start()
 {
     dialog = GetComponent <TextMesh>();
     gm     = GameObject.FindGameObjectWithTag("GameMaster").GetComponent <GameMaster>();
     inv    = GameObject.Find("Player").GetComponent <SimpleInventory>();
 }