[SerializeField] private bool _fillEmpty = false; // Should the inventory get completely filled? void Start() { // Create inventory var inventory = new InventoryManager(_width, _height); // Fill inventory with random items var tries = (_width * _height) / 3; for (var i = 0; i < tries; i++) { inventory.Add(_definitions[Random.Range(0, _definitions.Length)].CreateInstance()); } // Fill empty slots with first (1x1) item if (_fillEmpty) { for (var i = 0; i < _width * _height; i++) { inventory.Add(_definitions[0].CreateInstance()); } } // Sets the renderers's inventory to trigger drawing GetComponent <InventoryRenderer>().SetInventory(inventory); // Log items being dropped on the ground inventory.OnItemDropped += (item) => { Debug.Log(item.Name + " was dropped on the ground"); }; }
private void SellButton_Click(object sender, EventArgs e) { try { if (_stockOutList == null) { MessageBox.Show("Stock-out list is empty. Please add some item!"); return; } foreach (var item in _stockOutList) { item.StockOutType = (int)StockOutTypes.Sell; } int isAdded = _inventoryManager.Add(_stockOutList); if (isAdded > 0) { MessageBox.Show(isAdded + " Transaction for Stock-Out Added!"); _stockOutList.Clear(); stockOutDataGridView.Rows.Clear(); Reset(this.Controls); } else { MessageBox.Show("Error Occured While Saving!"); } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
/// <summary> /// Used to make random loot drops after events are resolved. /// Amount integer determines how many items are generated. /// </summary> /// <param name="amount"></param> public void GenerateRandomItems(int amount) { // Fill inventory with random items for (int i = 0; i < amount; i++) { inventory.Add(_definitions[Random.Range(0, _definitions.Length)].CreateInstance()); } }
/// <summary> /// 1.诊断试剂购进 /// </summary> private void ManagerZDSJGJ() { bool bolState = false; try { KPS.Model.GouJinInfo _Modelinfo = (KPS.Model.GouJinInfo)_control.GetSaveData(); _Modelinfo.DataType = thisdeviceinfo.DeviceID; KPS.BLL.GouJinManager gjmanager = new GouJinManager(); if (ModelData != null) { _Modelinfo.ID = ((GouJinInfo)ModelData).ID; bolState = gjmanager.Update(_Modelinfo); } else { bolState = gjmanager.Add(_Modelinfo); if (bolState) { //库存中新增购进记录 KPS.BLL.InventoryManager inventorymg = new InventoryManager(); inventorymg.Add(_Modelinfo); } } } catch (Exception ex) { bolState = false; } ShowMsgStateInfo(bolState, ModelData); }
private void SaveButton_Click(object sender, EventArgs e) { try { Inventory stockIn = new Inventory(); stockIn.ItemId = Convert.ToInt32(itemNameComboBox.SelectedValue.ToString()); if (stockIn.ItemId <= 0) { errorProvider.SetError(itemNameComboBox, "Please Select a Item!"); } stockIn.StockAvailable = Convert.ToInt32(availableQuantityLabel.Text) + Convert.ToInt32(stockInTextBox.Text); stockIn.StockTransaction = Convert.ToInt32(stockInTextBox.Text); if (stockIn.ItemId <= 0) { errorProvider.SetError(itemNameComboBox, "Please input valid transaction value!"); } stockIn.StockType = (int)StockTypes.In; bool isAdded = _inventoryManager.Add(stockIn); if (isAdded) { MessageBox.Show("Stock Updated!"); Reset(this.Controls); } else { MessageBox.Show("Error Occured While Saving!"); } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
static void Main(string[] args) { IInventoryItem item; //add listeners to Removed and Expired events. manager.Removed += ManagerOnRemoved; manager.Expired += ManagerOnExpired; //Add some items to the inventory for (var i = 0; i < 10; i++) { item = manager.Add(new InventoryItem() { Label = Guid.NewGuid().ToString(), Expires = DateTime.Now.AddSeconds(random.Next(1, 10)) }); Console.WriteLine("Added item {0}", item.Label); manager.CheckExpiration(); System.Threading.Thread.Sleep(1000); } //Additional Ten Seconds for Completion of Expirations. for (var i = 0; i < 10; i++) { manager.CheckExpiration(); System.Threading.Thread.Sleep(1000); } Console.WriteLine("Press any key to exit...."); Console.ReadKey(); }
public override bool Drop(Draggable dragged) { // Move item to end of inventory // TODO when this knows about contents, instead figure out index based on position? InventoryManager inventory = GameController.Instance.inventory; DraggableItem draggedItem = (DraggableItem)dragged; int index = IndexAtPosition(Input.mousePosition); if (draggedItem != null && draggedItem.itemBox != this) { Item item = draggedItem.itemBox.ContainedItem; if (draggedItem.itemBox is InventorySlot) { return(inventory.MoveItem(item, index)); } else if (draggedItem.itemBox is EquipmentSlotUI) { EquipmentSlotUI slot = (EquipmentSlotUI)draggedItem.itemBox; item = slot.equipmentSlot.Unequip(); if (item != null) { inventory.Add(item, index); return(true); } } } return(false); }
private void OnTriggerEnter2D(Collider2D hit) { // Checks if the collider is valid if (!hit) { return; } // Checks if the object can be picked up if (hit.CompareTag("PickUp")) { // Pickup the object _source.PlayOneShot(pickUpSound); var item = hit.GetComponent <PickUp>(); _inventoryManager.Add(item); Destroy(hit.gameObject); } else if (hit.CompareTag("Heart")) { // Pickup heart to regain lives if (TotalLives > _remainingLives) { _source.PlayOneShot(HeartSound); _remainingLives++; _playerHeartDisplay.OnChangeHeart(TotalLives, _remainingLives); // Destroys the game object Destroy(hit.gameObject); } } }
// When the player unequips an item public void UnEquip(int slotIndex) { if (currentEquipment[slotIndex] != null) { Equipment oldItem = currentEquipment[slotIndex]; inventory.Add(oldItem); // Nullify equipped item currentEquipment[slotIndex] = null; // Remove weapon from equipment slot if (oldItem.equipmentSlot == EquipmentSlot.Weapon) { weaponQuality.sprite = defaultQuality; weaponIcon.sprite = defaultWeaponIcon; Destroy(weaponInstance); } // Remove shield from equipment slot if (oldItem.equipmentSlot == EquipmentSlot.Shield) { shieldQuality.sprite = defaultQuality; shieldIcon.sprite = defaultShieldIcon; Destroy(shieldInstance); } // Call onEquipmentChanged if (onEquipmentChanged != null) { onEquipmentChanged.Invoke(null, oldItem); } } }
public void GenerateItem(int level) { //Silly fun FIND BETTER WAY List <string> savageModifiers = new List <string> { "Destruction", "Annihilation", "Carnage", "Ruin", "Slaughter", "Eradication", "Fun" }; //Make an empty gameIcon //THIS WILL LITTER THE SCENE IF NOT CAREFUL GameObject itemIcon = Instantiate(itemIconBase); itemIcon.GetComponent <Image>().sprite = possibleTurretSprites[Random.Range(0, possibleTurretSprites.Length)]; //Make an empty item script and add it to the empty gameicon. Item emptyItem = itemIcon.AddComponent(typeof(Item)) as Item; itemIcon.AddComponent(typeof(ItemUIHandler)); //Add the item handler. // ~~~~~~~~~~~~~~~~~~~~~ // BUILDING THE OBJECT ~ // ~~~~~~~~~~~~~~~~~~~~~ //Set the name emptyItem.itemName = "Turret of " + savageModifiers[Random.Range(0, savageModifiers.Count)]; //Add ammo emptyItem.bullet = bullet; //Create a new damage attribute. DamageItemAttribute damage = ScriptableObject.CreateInstance <DamageItemAttribute>(); damage.Initialize(1, 0); emptyItem.attributes.Add(damage); //Create a new health attribute. HealthItemAttribute health = ScriptableObject.CreateInstance <HealthItemAttribute>(); health.Initialize(1, 0); emptyItem.attributes.Add(health); // ~~~~~~~~~~~~~~~~~~ // ADD TO INVENTORY ~ // ~~~~~~~~~~~~~~~~~~ //BAD PRACTICE, ADDING IT DIRECTLY TO INVENTORY GameObject inventory = GameObject.FindGameObjectWithTag("Inventory"); InventoryManager inventoryManager = inventory.GetComponent <InventoryManager>(); inventoryManager.Add(itemIcon); }
protected void Awake() { manager = GetComponent <InventoryManager>(); for (int i = 0; i < inventory.Length; ++i) { manager.Add(new MarkedInventoryItem(inventory[i].ToItem(), markRadius, markDuration)); } }
public void PickUp() { if (inventoryManager.Add(item)) { Debug.Log("Item picked: " + item.name); Destroy(gameObject); } }
void OnTriggerEnter2D(Collider2D hit) { if (hit.CompareTag("Pickup")) { PickUp item = hit.GetComponent <PickUp>(); inventoryManager.Add(item); Destroy(hit.gameObject); } }
private void RewardPlayer() { Debug.Log("Now you've got reward"); foreach (Item reward in rewards) { inventory.Add(reward); } }
public bool AutoAddItem(ItemDefinition newItem) { if (newItem == null) { Debug.LogError("Item is missing in conveyer belt!"); } IInventoryItem item = newItem.CreateInstance(); return(inventory.Add(item)); }
private void Collect(CollectAble col) { currentGold += col.data.value; currentWeight += col.data.weight; weightBar.ChangeWeight(currentWeight); goldScript.UpdateGold(currentGold); inventoryManager.Add(col.data); }
public void InvalidItem_IncrementDay_ExpectInvalidItem(string itemName, string expectedItemDescription) { var sut = new InventoryManager(); sut.Add(itemName, 1, 2); var item = sut.IncrementDay(); Assert.AreEqual(expectedItemDescription, item.First().Name); }
public void ShouldAddItemToInventory() { // arrange // act var actual = manager.Add(item); // assert Assert.AreEqual(item.Label, actual.Label, "Should add item to inventory"); }
private void Start() { // Initialize inventory inventory = new InventoryManager(_width, _height); // Sets the renderers's inventory to trigger drawing GetComponent <InventoryRenderer>().SetInventory(inventory); // Set weapon to Pistol inventory.Add(_definitions[1]); }
private void Start() { // Initialize inventory inventory = new InventoryManager(_width, _height); // Sets the renderers's inventory to trigger drawing GetComponent <InventoryRenderer>().SetInventory(inventory); // Set armor to Leather Jacket inventory.Add(_definitions[0]); }
public void Equip(Equipment newItem) { int slotIndex = (int)newItem.equipType; Equipment oldItem = null; if (equipment.currentEquipment[slotIndex] != null) { oldItem = equipment.currentEquipment[slotIndex]; inventory.Add(oldItem); } equipment.currentEquipment[slotIndex] = newItem; if (onEquipmentChanged != null) { onEquipmentChanged.Invoke(); } PassEquipStats(); }
[TestCase("INVALID ITEM", 2, 0)] //Invalid item doesn't track days to sell public void IncrementDay_ExpectSellinDecreasedByOne(string itemName, int sellin, int expectedSellin) { //Arrange var sut = new InventoryManager(); sut.Add(itemName, sellin, 1); //Act var item = sut.IncrementDay(); //Assert Assert.AreEqual(expectedSellin, item.First().Sellin); }
[TestCase("INVALID ITEM", 2, 2, 0)] //Invalid item doesn't track quality public void IncrementDay_ExpectQualityModification(string itemName, int sellin, int quality, int expectedQuality) { //Arrange var sut = new InventoryManager(); sut.Add(itemName, sellin, quality); //Act var item = sut.IncrementDay(); //Assert Assert.AreEqual(expectedQuality, item.First().Quality); }
public void TestFromRemit() { var sut = new InventoryManager(); sut.Add("Aged Brie", 1, 1); //0 sut.Add("Backstage passes", -1, 2); //1 sut.Add("Backstage passes", 9, 2); //2 sut.Add("Sulfras", 2, 2); //3 sut.Add("Normal Item", -1, 55); //4 sut.Add("Normal Item", 2, 2); //5 sut.Add("INVALID ITEM", 2, 2); //6 sut.Add("Conjured", 2, 2); //7 sut.Add("Conjured", -1, 5); //8 var items = sut.IncrementDay(); Assert.AreEqual(0, items[0].Sellin); Assert.AreEqual(2, items[0].Quality); Assert.AreEqual(-2, items[1].Sellin); Assert.AreEqual(0, items[1].Quality); Assert.AreEqual(8, items[2].Sellin); Assert.AreEqual(4, items[2].Quality); Assert.AreEqual(0, items[3].Sellin); Assert.AreEqual(0, items[3].Quality); Assert.AreEqual(-2, items[4].Sellin); Assert.AreEqual(50, items[4].Quality); Assert.AreEqual(1, items[5].Sellin); Assert.AreEqual(1, items[5].Quality); Assert.AreEqual(0, items[6].Sellin); Assert.AreEqual(0, items[6].Quality); Assert.AreEqual(1, items[7].Sellin); Assert.AreEqual(0, items[7].Quality); Assert.AreEqual(-2, items[8].Sellin); Assert.AreEqual(1, items[8].Quality); }
public void Equip(Equipment newItem) { /* variable to indicate which slot would be used depending on the type of the equipment */ int slotIndex = (int)newItem.equipmentSlot; /* variable to keep previous equipped item */ Equipment oldItem = null; /* if current equipment slot is already occupied (character is already equipped) */ if (currentEquipment [slotIndex] != null) { /* store the equipment to take off */ oldItem = currentEquipment [slotIndex]; /* add old equipment to the inventory */ inventory.Add(oldItem); /* deactivate old equipment */ ObjectPool.instance.DeActivate(oldItem.gameObject); } /* if delegate function exists (currently not used, 2018.01.20) */ if (onEquipmentChangedCallback != null) { onEquipmentChangedCallback.Invoke(newItem, oldItem); } /* change the current equipment slot to the new item */ currentEquipment [slotIndex] = newItem; /* Activate new item */ int resultIndex = ObjectPool.instance.GetIndex(newItem.gameObject); if (resultIndex != 9999999) // ERROR_CODE, wtf { ObjectPool.instance.Activate(resultIndex); } }
public IInventoryItem AddItem(string itemName) { foreach (ThoughtItem item in _definitions) { if (item.Name == itemName) { IInventoryItem newItem = item.CreateInstance(); inventory.Add(newItem); return(newItem); } } Debug.Log("Did not find " + itemName); return(null); }
private InventoryManager inventory; // variable to keep InventoryManager reference // Use this for initialization void Start() { maxHealth = 100; damage = 10; currentHealth = maxHealth; destination = transform.position; characterSprite = transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>(); anim = transform.GetChild(0).gameObject.GetComponent <SpriteAnimator>(); equipmentAnim = transform.GetChild(0).GetComponentsInChildren <SpriteAnimator> (); Equipment.UpdateEquipmentAnimReferenceCallback += UpdateAnimReference; inventory = InventoryManager.instance; /* temporary code */ inventory.Add(ObjectPool.instance.GetObject(1, 0).GetComponent <Equipment> ()); inventory.Add(ObjectPool.instance.GetObject(2, 0).GetComponent <Equipment> ()); inventory.Add(ObjectPool.instance.GetObject(6, 0).GetComponent <Equipment> ()); inventory.Add(ObjectPool.instance.GetObject(7, 0).GetComponent <Equipment> ()); inventory.items [0].Use(); // shirts equip inventory.items [0].Use(); // pants equip /* temporary code */ }
public void Equip(Equipement newItem) { Equipement olditem = null; int slotindex = (int)newItem.equipslot; if (currentEquipment[slotindex] != null) { olditem = currentEquipment[slotindex]; inventory.Add(olditem); } currentEquipment[slotindex] = newItem; if (newItem.equipslot == EquipmentSlot.HELMET) { HELMETI.sprite = newItem.buttonicon; HELMETT.text = newItem.IName; } if (newItem.equipslot == EquipmentSlot.CHEST) { CHESTI.sprite = newItem.buttonicon; CHESTT.text = newItem.IName; } if (newItem.equipslot == EquipmentSlot.GLOVES) { GLOVESI.sprite = newItem.buttonicon; GLOVEST.text = newItem.IName; } if (newItem.equipslot == EquipmentSlot.WEAPON) { WEAPONI.sprite = newItem.buttonicon; WEAPONT.text = newItem.IName; } if (newItem.equipslot == EquipmentSlot.BOOTS) { BOOTSI.sprite = newItem.buttonicon; BOOTST.text = newItem.IName; } }
public void HandleInteraction() { if (interactionAction == InteractionAction.PutInInventory) { if (inventoryManager) { //TODO: inventoryManager.Add(this.gameObject.GetComponent<InteractiveObj>()); GameObject go = this.gameObject; InteractiveObj iObj = go.GetComponent <InteractiveObj> (); Debug.Log("In ObjectInteraction.HandleInteraction:"); Debug.Log(iObj); //inventoryManager.Add(this.gameObject.GetComponent<InteractiveObj>()); inventoryManager.Add(iObj); } } }
//---------------------- // actions for when parent GameObject (Player) has hit a 2D collider inside another object void OnTriggerEnter2D(Collider2D hit) { // IF we hit something taqgged 'Pickup' if (hit.CompareTag("Pickup")) { // THEN do the following: // - get reference to PickUp object inside the hit Gameobject PickUp item = hit.GetComponent <PickUp> (); // add this PickUp item to our List 'inventory' inventoryManager.Add(item); // destroy the hit GameObject Destroy(hit.gameObject); } }