private void ConsumeItem(ItemData draggedItem) { if (draggedItem.ItemIns == null) { return; } switch (draggedItem.ItemIns.Item.Type) { case ItemContainer.ItemType.Consumable: //Use all the stack if (_inv.UseItem(draggedItem.ItemIns)) { //_inv.DeleteFromInventory(draggedItem.ItemIns); draggedItem.ItemIns.UserItem.StackCnt = 0; } break; case ItemContainer.ItemType.Equipment: case ItemContainer.ItemType.Weapon: case ItemContainer.ItemType.Tool: case ItemContainer.ItemType.Substance: _inv.PrintMessage("You can not consume this item", Color.yellow); break; default: _GUIManager.PrintMessage(draggedItem.ItemIns.Item.Name + " can not be used", Color.yellow); break; } }
// Update is called once per frame void Update() { if (ItemLocked) { TextMeshProUGUI[] texts = this.transform.parent.GetComponentsInChildren <TextMeshProUGUI>(); //texts[1].color = Color.magenta; texts[1].text = TimeHandler.PrintTime(_time - DateTime.Now); if (DateTime.Now > _time) { //texts[1].color = Color.green; texts[1].text = "Ready"; ItemLocked = false; _inv.PrintMessage(ItemIns.Item.Name + " Is ready", Color.green); } } }
// Update is called once per frame void Update () { var pos = transform.position; InLineOfSight(pos); pos.z += 0.01f; if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { var touchLocation = Camera.main.ScreenToWorldPoint(Input.mousePosition); float distance = Vector2.Distance(touchLocation, pos); _popupAction.SetActive(false); //AttackTarget Also check TerrainAction var monster = _building.GetMonster(touchLocation,0.3f).FirstOrDefault(); if (monster != null) { if (distance < (int) _characterManager.MyCharacter.AttackR) { _popupAction.GetComponent<ActionHandler>().SetActiveMonster(monster, transform, "Inside"); _popupAction.GetComponent<ActionHandler>().AttackMonster(); //Less click approach //CreateFloatingAction(touchLocation, "Monster"); } else _inv.PrintMessage("Too Far from this Target!", Color.yellow); return; } var currentItem = _building.GetItem(touchLocation).FirstOrDefault(); if (currentItem != null) { if (distance < 1) { _popupAction.GetComponent<ActionHandler>().SetActiveItem(currentItem, "Inside"); _popupAction.GetComponent<ActionHandler>().GrabItem(); //Less click approach //CreateFloatingAction(touchLocation, "Item"); return; } } CreateFloatingAction(touchLocation, "Map"); } }
public void OnDrop(PointerEventData eventData) { ItemData draggedItem = eventData.pointerDrag.GetComponent <ItemData>(); ItemMixture mixedItem = eventData.pointerDrag.GetComponent <ItemMixture>(); ItemEquipment equipedItem = eventData.pointerDrag.GetComponent <ItemEquipment>(); if (mixedItem == null && draggedItem == null && equipedItem == null) { return; } if (mixedItem != null) { if (mixedItem.ItemIns == null) { return; } if (!mixedItem.ReadyToUse()) { return; } } if (draggedItem != null) { if (draggedItem.ItemIns == null) { return; } } if (equipedItem != null) { if (equipedItem.ItemIns == null) { return; } } ItemData existingItem = this.transform.GetComponentInChildren <ItemData>(); if (existingItem == null) { return; } //Item from Mixture Area if (mixedItem != null) { if (mixedItem.ItemIns != null) { //#################################### not empty slot if (existingItem.ItemIns != null && existingItem.ItemIns.Item.Id != mixedItem.ItemIns.Item.Id) { _inv.PrintMessage("New item should be placed in an empty inventory slot", Color.yellow); } //#################################### empty slot else { if (_inv.AddItemToInventory(mixedItem.ItemIns.Item, mixedItem.ItemIns.UserItem.StackCnt, existingItem.SlotIndex)) { //Delete mixedItem Item mixedItem.LoadEmpty(); _inv.UpdateInventory(); } } return; } } //Item from equipments Area if (equipedItem != null) { if (equipedItem.ItemIns != null) { //#################################### not empty slot if (existingItem.ItemIns != null) { _inv.PrintMessage("New item should be placed in an empty inventory slot", Color.yellow); } //#################################### empty slot else { //Set the slot Item existingItem.ItemIns = equipedItem.ItemIns; existingItem.transform.parent.name = existingItem.transform.name = existingItem.ItemIns.Item.Name; existingItem.GetComponent <Image>().sprite = existingItem.ItemIns.Item.GetSprite(); var stackCntText = existingItem.transform.GetComponentInChildren <TextMeshProUGUI>(); stackCntText.text = existingItem.ItemIns.UserItem.StackCnt > 1 ? existingItem.ItemIns.UserItem.StackCnt.ToString() : ""; existingItem.ItemIns.UserItem.Order = existingItem.SlotIndex; existingItem.ItemIns.UserItem.Equipped = false; //unload new Item to equipments equipedItem.LoadItem(null); _inv.UpdateInventory(); } return; } } if (draggedItem != null) { if (SlotIndex != draggedItem.SlotIndex) { //#################################### Empty slot logic swap if (existingItem.ItemIns == null) { //Swap Parent draggedItem.transform.SetParent(existingItem.transform.parent); existingItem.transform.SetParent(draggedItem.Parent); draggedItem.Parent = null; //Swap positions existingItem.transform.position = existingItem.transform.parent.position; draggedItem.transform.position = draggedItem.transform.parent.position; //Swap SlotIndex var temp2 = existingItem.SlotIndex; existingItem.SlotIndex = draggedItem.SlotIndex; draggedItem.ItemIns.UserItem.Order = draggedItem.SlotIndex = temp2; //Swapping names existingItem.transform.parent.name = "Empty"; draggedItem.transform.parent.name = draggedItem.ItemIns.Item.Name; _inv.UpdateInventory(); } //#################################### Stacking: Same items Stack them together else if (existingItem.ItemIns.Item.Id == draggedItem.ItemIns.Item.Id) { if (existingItem.ItemIns.UserItem.StackCnt + draggedItem.ItemIns.UserItem.StackCnt > existingItem.ItemIns.Item.MaxStackCnt) { draggedItem.ItemIns.UserItem.StackCnt = draggedItem.ItemIns.UserItem.StackCnt - (existingItem.ItemIns.Item.MaxStackCnt - existingItem.ItemIns.UserItem.StackCnt); existingItem.ItemIns.UserItem.StackCnt = existingItem.ItemIns.Item.MaxStackCnt; } else { existingItem.ItemIns.UserItem.StackCnt = draggedItem.ItemIns.UserItem.StackCnt + existingItem.ItemIns.UserItem.StackCnt; draggedItem.ItemIns.UserItem.StackCnt = 0; } var stackCntText = existingItem.transform.GetComponentInChildren <TextMeshProUGUI>(); if (existingItem.ItemIns.UserItem.StackCnt > 1) { stackCntText.text = existingItem.ItemIns.UserItem.StackCnt.ToString(); } _inv.UpdateInventory(); } else { Recipe newRecipe = _inv.CheckRecipes(existingItem.ItemIns.Item.Id, draggedItem.ItemIns.Item.Id); //#################################### Mixing if (newRecipe != null) { if (newRecipe.FirstItemCnt <= existingItem.ItemIns.UserItem.StackCnt) { if (newRecipe.SecondItemCnt <= draggedItem.ItemIns.UserItem.StackCnt) { if (_itemMixture.ItemIns != null) { _inv.PrintMessage("You are already making an Item", Color.yellow); } else { //Mixing items Logic (Lambda) can also be 2 func in it : () => { InstantiateObject(thingToSpawn); InstantiateObject(thingToSpawn, thingToSpawn); } _messagePanelHandler.ShowMessage(newRecipe.GetDescription(), MessagePanel.PanelType.YesCancel, () => { MixItemData(ref existingItem, ref draggedItem, newRecipe); }); } } else //Not enough materials { _inv.PrintMessage("Not enough " + draggedItem.ItemIns.Item.Name + " in the inventory, You need " + (newRecipe.SecondItemCnt - draggedItem.ItemIns.UserItem.StackCnt) + " more", Color.yellow); } } else //Not enough materials { _inv.PrintMessage("Not enough " + existingItem.ItemIns.Item.Name + " in the inventory, You need " + (newRecipe.FirstItemCnt - existingItem.ItemIns.UserItem.StackCnt) + " more", Color.yellow); } } //#################################### Swaping: Unmixable items Stack them together else { //Swap Parent draggedItem.transform.SetParent(existingItem.transform.parent); existingItem.transform.SetParent(draggedItem.Parent); draggedItem.Parent = null; //Swap positions existingItem.transform.position = existingItem.transform.parent.position; draggedItem.transform.position = draggedItem.transform.parent.position; //Swap SlotIndex var temp2 = existingItem.SlotIndex; existingItem.ItemIns.UserItem.Order = existingItem.SlotIndex = draggedItem.SlotIndex; draggedItem.ItemIns.UserItem.Order = draggedItem.SlotIndex = temp2; //Swapping names existingItem.transform.parent.name = existingItem.ItemIns.Item.Name; draggedItem.transform.parent.name = draggedItem.ItemIns.Item.Name; _inv.UpdateInventory(); } } } } }
public void ShowMapInfo() { _inv.PrintMessage(_terrainManager.Region.MapInfo(), Color.black); }
public void OnDrop(PointerEventData eventData) { ItemData draggedItem = eventData.pointerDrag.GetComponent <ItemData>(); if (draggedItem == null) { return; } if (draggedItem.ItemIns == null) { return; } var item = draggedItem.ItemIns.Item; var userItem = draggedItem.ItemIns.UserItem; //Wearing Equipment if (EquType != ItemContainer.PlaceType.None) { switch (item.Type) { case ItemContainer.ItemType.Equipment: if (item.PlaceHolder == EquType) { if (userItem.StackCnt == item.MaxStackCnt) { ItemEquipment existingEquipment = this.transform.GetComponentInChildren <ItemEquipment>(); if (_inv.UseItem(draggedItem.ItemIns)) { //Swap ItemIns var itemEquipment = existingEquipment.ItemIns; draggedItem.ItemIns.UserItem.Order = (int)EquType; draggedItem.ItemIns.UserItem.Equipped = true; existingEquipment.LoadItem(draggedItem.ItemIns); draggedItem.LoadItem(itemEquipment); } } else { _inv.PrintMessage("You need " + (item.MaxStackCnt - userItem.StackCnt) + " of this item to equip", Color.yellow); } } else { _inv.PrintMessage("You cannot equip this item here", Color.yellow); } break; case ItemContainer.ItemType.Weapon: case ItemContainer.ItemType.Tool: //Todo: Add the logic of two hand item if (EquType == ItemContainer.PlaceType.Left || EquType == ItemContainer.PlaceType.Right) { if (item.CarryType == ItemContainer.Hands.OneHand) { //Todo: Add logic of hands carry ItemEquipment existingEquipment = this.transform.GetComponentInChildren <ItemEquipment>(); if (_inv.UseItem(draggedItem.ItemIns)) { //Swap ItemIns var itemEquipment = existingEquipment.ItemIns; draggedItem.ItemIns.UserItem.Order = (int)EquType; draggedItem.ItemIns.UserItem.Equipped = true; existingEquipment.LoadItem(draggedItem.ItemIns); draggedItem.LoadItem(itemEquipment); } } else { _inv.PrintMessage("It is not possible to carry this weapon yet", Color.yellow); } } else { _inv.PrintMessage("You cannot equip this item here", Color.yellow); } break; } } }