private void EquipItem(EquipableItem pickedUpItem, bool swapItems) { EquipableItem equippedItem; equipInventory.TryGetValue(pickedUpItem.equipSlot, out equippedItem); if (equippedItem == null && !swapItems) { equipInventory[pickedUpItem.equipSlot] = pickedUpItem; pickedUpItem.transform.SetParent(getEquipmentSlot(pickedUpItem.equipSlot).transform); pickedUpItem.setInventoryManager(this); pickedUpItem.setItemState(Item.ItemState.Equiped); } else if (swapItems) { Item tempItem = equipInventory[pickedUpItem.equipSlot]; inventory[inventory.IndexOf(pickedUpItem)] = tempItem; if (tempItem != null) { tempItem.transform.SetParent(inventorySlots[inventory.IndexOf(tempItem)].transform); tempItem.setItemState(Item.ItemState.InInventory); } equipInventory[pickedUpItem.equipSlot] = null; EquipItem(pickedUpItem, false); } else { AddToInventory(pickedUpItem); } }
public void UpdateStats() { CharacterStats statsCopy = null; if (selectedCharacter.currentEquipment.currentArmor != null && selectedItem != null && selectedItem.equipType.Equals(EquipType.Armor)) { EquipableItem currentArmor = selectedCharacter.currentEquipment.currentArmor; StatName statToDecrease = currentArmor.characterStat; statsCopy = ApplyValue(statToDecrease, selectedCharacter.charStats, -currentArmor.value); } else if (selectedCharacter.currentEquipment.currentWeapon != null && selectedItem != null && selectedItem.equipType.Equals(EquipType.Weapon)) { EquipableItem currentWeapon = selectedCharacter.currentEquipment.currentWeapon; StatName statToDecrease = currentWeapon.characterStat; statsCopy = ApplyValue(statToDecrease, selectedCharacter.charStats, -currentWeapon.value); } else { statsCopy = selectedCharacter.charStats; } PrintUpdatedStats(statsCopy); }
public bool IsEquipped(EquipableItem item) { if (helmet == item) { return(true); } if (chest == item) { return(true); } if (boots == item) { return(true); } if (gloves == item) { return(true); } if (weapon == item) { return(true); } if (accessory == item) { return(true); } return(false); }
public void Deserialize(string repr, PlayerComponent owner) { this.Clear(); int pos = 0; repr = repr.Trim(';'); string[] savedItems = repr.Split(';'); for (int i = 1; i < savedItems.Length; i++) { if (savedItems[i] != "") { if (HardcodedItems.items[savedItems[i]] is EquipableItem) { items[pos] = new EquipableItem(HardcodedItems.items[savedItems[i]] as EquipableItem); } else { items[pos] = new UsableItem((UsableItem)HardcodedItems.items[savedItems[i]]); } items[pos].SetOwner(owner); items[pos].inventoryPlace = pos; } pos++; } }
private void UnequipItem(EquipableItem equipableItem) { if (equipableItem != null) { equipableItem.UnequipItem(selectedCharacter); } }
void LoadCharacterData(PlayableCharacter character) { CharacterStats characterStats = character.charStats; //Character base avatarImage.sprite = characterStats.avatar; EquipableItem weapon = character.currentEquipment.currentWeapon; if (weapon != null) { charWeaponText.text = weapon.itemName; } else { charWeaponText.text = ""; } EquipableItem armor = character.currentEquipment.currentArmor; if (armor != null) { charArmorText.text = armor.itemName; } else { charArmorText.text = ""; } //Character stats currentAttackText.text = characterStats.totalAttack.ToString(); currentDefenseText.text = characterStats.totalDefense.ToString(); currentSpeedText.text = characterStats.totalSpeed.ToString(); currentMagicText.text = characterStats.totalMagic.ToString(); PrintUpdatedStats(characterStats); }
public void Dequip(EquipableItem item) { if (helmet == item) { helmet = null; } if (chest == item) { chest = null; } if (gloves == item) { gloves = null; } if (boots == item) { boots = null; } if (weapon == item) { weapon = null; } if (accessory == item) { accessory = null; } if (OnChange != null) { Debug.Log("hero equipment changed"); OnChange.Invoke(this); } }
public void Equip(EquipableItem equipable) { if (_currentEquipableItem == null) { currentEquipmentObject = Instantiate(equipable.Prefab, Camera.main.transform); _currentEquipableItem = equipable; return; } //We have an item already equiped if (_currentEquipableItem.Equals(equipable)) { Destroy(currentEquipmentObject); currentEquipmentObject = null; _currentEquipableItem = null; return; } else { Destroy(currentEquipmentObject); currentEquipmentObject = null; _currentEquipableItem = null; currentEquipmentObject = Instantiate(equipable.Prefab, Camera.main.transform); _currentEquipableItem = equipable; } }
private void UpdateBackground() { int key = 1; foreach (Transform slot in transform) { // Get the respective item from inventory. EquipableItem item = inventory.GetItemAt(key); // Get the cooldown background. Image image = slot.Find("cooldown").GetComponent <Image>(); // If the item is still cooling down, show a gray background // with its size based on the cooldown time. if (item != null && inventory.getTimeUntilNextUse(item) > 0) { image.enabled = true; float ratio = inventory.getTimeUntilNextUse(item) / item.Cooldown; image.rectTransform.localScale = new Vector3(1, ratio, 1); image.sprite = cooldownBackground; } else { image.enabled = false; } key++; } }
public void ShowTooltips(EquipableItem item) { ItemName.text = item.ItemName; ItemSlot.text = item.equipmentType.ToString(); sb.Length = 0; AddStats(item.hpFlat, "Hp"); AddStats(item.hpPercent, "Hp %"); AddStats(item.hpRegenFlat, "Hp Regeneration"); AddStats(item.hpRegenPercent, "Hp Regeneration %"); AddStats(item.moveSpeed, "Movement Speed"); AddStats(item.armor, "Armor"); AddStats(item.fireResist, "Fire Resistance"); AddStats(item.waterResist, "Water Resistance"); AddStats(item.airResist, "Air Resistance"); AddStats(item.attackSpeed, "Attack Speed"); AddStats(item.castSpeed, "Cast Speed"); AddStats(item.globalDamage, "Damage %"); AddStats(item.physicalDmgFlat, "Physical Damage"); AddStats(item.physicalDmgPercent, "Physical Damage %"); AddStats(item.fireDamageFlat, "Fire Damage"); AddStats(item.waterDamageFlat, "Water Damage"); AddStats(item.airDamageFlat, "Air Damage"); AddStats(item.fireDamagePercent, "Fire Damage %"); AddStats(item.waterDamagePercent, "Water Damage %"); AddStats(item.airDamagePercent, "Air Damage %"); ItemStats.text = sb.ToString(); gameObject.SetActive(true); }
private void OnGrabAnimationFinished() { // Equip if (rightHand.name != "Name") { print("right hand equip"); rightHand.Instance.transform.parent = rightHand.pivotPoint; rightHand.Instance.transform.SetPositionAndRotation(rightHand.pivotPoint.position, rightHand.pivotPoint.rotation); } if (leftHand.name != "Name") { leftHand.Instance.transform.parent = leftHand.pivotPoint; leftHand.Instance.transform.SetPositionAndRotation(leftHand.pivotPoint.position, leftHand.pivotPoint.rotation); } // Unequip if (unequippedItem != null) { print("unequip"); unequippedItem.Instance.transform.parent = backPivot; unequippedItem.Instance.transform.SetPositionAndRotation(backPivot.position, backPivot.rotation); unequippedItem = null; } print(rightHand.name); }
private void ChangeAttackAnimation_OnRemoveEvent(EquipableItem obj) { Weapon temp; var targetWeapon = obj as Weapon; if (targetWeapon != null) { if (targetWeapon.EquipmentType == EquipmentType.MainHand) { temp = InventoryManager.Instance.equipmentPanel.GetSlot(EquipmentType.Shield).Item as Weapon; } else { temp = InventoryManager.Instance.equipmentPanel.GetSlot(EquipmentType.MainHand).Item as Weapon; } if (temp != null) { attackType = temp.attackType; } else { attackType = defaultAttackType; } } //Debug.Log("Change Attack animation OnRemoveEvent"); }
private void ChangeAttackAnimation_OnAddItemEvent(EquipableItem obj) { Weapon temp; var targetWeapon = obj as Weapon; if (targetWeapon != null) { if (targetWeapon.EquipmentType == EquipmentType.MainHand) { temp = InventoryManager.Instance.equipmentPanel.GetSlot(EquipmentType.Shield).Item as Weapon; } else { temp = InventoryManager.Instance.equipmentPanel.GetSlot(EquipmentType.MainHand).Item as Weapon; } if (temp != null) { attackType = AttackType.TwoWeapon; } else { attackType = targetWeapon.attackType; } } }
/* * One of the more important functions here. When in focus, this will be called * every frame with the stored input from InputTracking */ public override void HandleInput(PlayerAction action, string inputString) { switch (action) { case PlayerAction.DROP_ITEMS: Player.player.inventory.Drop(inspecting.position); ExitAllWindows(); break; case PlayerAction.EQUIP: EquipableItem toEquip = inspecting.held[0].equipable; if (toEquip != null && !toEquip.isEquipped) { UIController.singleton.OpenEquipmentEquip(inspecting); } else { //TODO: Console error of some sort? } break; case PlayerAction.UNEQUIP: EquipableItem equip = inspecting.held[0].equipable; if (equip != null && equip.isEquipped) { Player.player.equipment.UnequipItem(inspecting.position); //Faster method, doesn't need a search ExitAllWindows(); } break; } }
/* * public void OnDrag(PointerEventData eventData) * { * if (ContainsItem()) * { * // display dragged item icon at mouse position * charPanel.ShowDraggedItem(charPanel.items[index], index); * * // delete the dragged item * charPanel.items[index] = new Item(); * } * } */ bool EquipToSlot(EquipableItem draggedItem) { // * important // * slots index has the some order as // * weapon equip type enum's order if (index == (int)draggedItem.equipType) { // slot occupied if (ContainsItem()) { // swap old -> new item // give old item back to inventory Item tempItem = charPanel.items[index]; charPanel.items[index] = draggedItem; inventory.items[inventory.draggedItemSlotNum] = tempItem; draggedItem.ActiveItemEffect(); } // slot empty else { charPanel.items[index] = draggedItem; } //inventory.HideDraggedItem(); return(true); } Debug.Log("wrong slot!"); return(false); }
public void ShowUpdatedStats(EquipableItem item) { //Mirar si el pj tiene un objeto equipado en la casilla correspondiente //En caso afirmativo se deja como si no tuviera nada (usando variable a parte) CharacterStats statsCopy = null; if (selectedCharacter.currentEquipment.currentArmor != null && item.equipType.Equals(EquipType.Armor)) { EquipableItem currentArmor = selectedCharacter.currentEquipment.currentArmor; StatName statToDecrease = currentArmor.characterStat; statsCopy = ApplyValue(statToDecrease, selectedCharacter.charStats, -currentArmor.value); } if (selectedCharacter.currentEquipment.currentWeapon != null && item.equipType.Equals(EquipType.Weapon)) { EquipableItem currentWeapon = selectedCharacter.currentEquipment.currentWeapon; StatName statToDecrease = currentWeapon.characterStat; statsCopy = ApplyValue(statToDecrease, selectedCharacter.charStats, -currentWeapon.value); } //Se añade lo que se aplicaría y se muestra en el resultado actualizado if (statsCopy == null) { statsCopy = InitStatsCopy(selectedCharacter.charStats); } statsCopy = ApplyValue(item.characterStat, statsCopy, item.value); PrintUpdatedStats(statsCopy); }
public void MonsterToFloor(int index) { Inventory onFloor = Map.current.GetTile(monster.location).inventory; ItemStack stack = Items[index]; if (stack == null) { return; //Quick cutout } EquipableItem equip = stack.held[0].equipable; if (equip && equip.isEquipped) { //TODO: Figure out if we should abort the drop, or just unequip //For now, just unequip it equip.Unequip(); } foreach (Item i in stack.held) { i.Drop(); i.SetLocation(monster.location); } onFloor.Add(stack); RemoveAt(index); }
public void Equip(EquipableItem item) { if (Inventory.RemoveItem(item)) { EquipableItem previousItem; if (EquipmentPanel.AddItem(item, out previousItem)) { if (previousItem != null) { Inventory.AddItem(previousItem); previousItem.Unequip(this); statPanel.UpdateStatValues(); } item.Equip(this); statPanel.UpdateStatValues(); if (item.equipmentType == EquipmentType.Weapon) { string[] name = item.ItemName.Split(' '); if (name[0] == "Sword" || name[0] == "Staff" || name[0] == "Bow") { player.SwapWeapons(name[0]); } else { player.SwapWeapons(name[1]); } } } else { Inventory.AddItem(item); } } }
public void UnEquip(EquipableItem item) { if (!inventory.IsFull() && equipmentPanel.RemoveItem(item)) { inventory.AddItem(item); } }
private void Clear() { m_SelectedEquipment = null; for (int i = 0; i < m_PartyRoot.transform.childCount; ++i) { var cur = m_PartyRoot.transform.GetChild(i).gameObject; if (!m_DoNotDestroyList.Contains(cur)) { Destroy(cur); } } for (int i = 0; i < m_EquipmentRoot.transform.childCount; ++i) { var cur = m_EquipmentRoot.transform.GetChild(i).gameObject; if (!m_DoNotDestroyList.Contains(cur)) { Destroy(cur); } } for (int i = 0; i < m_ItemsRoot.transform.childCount; ++i) { var cur = m_ItemsRoot.transform.GetChild(i).gameObject; if (!m_DoNotDestroyList.Contains(cur)) { Destroy(cur); } } }
public bool RemoveItem(EquipableItem item, out List <Item> PreItems) { PreItems = null; var target = EquipmentSlots.FirstOrDefault(s => s.EquipmentType == item.EquipmentType); if (target.Item != null) { OnRemoveItemEvent?.Invoke(item); target.Amount = 0; target.Item = null; return(true); } //for (int i = 0; i < EquipmentSlots.Length; i++) //{ // if (EquipmentSlots[i].Item == item) // { // // CharacterScript.Instance.characterState.Remove(item.state); // //PlayerVisualScript.Instance.RemoveItemVisual(item); // OnRemoveItemEvent?.Invoke(item); // EquipmentSlots[i].Item = null; // return true; // } //} return(false); }
// Returns the strongest weapon in the inventory of a given type. public IItem GetStrongestWeapon(EquipableItem itemType) { IItem topPick = null; int topPickDamage = 0; foreach (KeyValuePair <int, int> itemPair in items) { IItem item = itemManager.GetItem(itemPair.Key); if (item.HasBehavior(ItemBehaviorType.EQUIPABLE)) { EquipableItemBehavior behavior = (EquipableItemBehavior)item.GetBehavior(ItemBehaviorType.EQUIPABLE); if (behavior.itemType == itemType) { if (behavior.item.Damage > topPickDamage) { topPick = item; } } } } return(topPick); }
public void Unequip(EquipableItem itemSlot) { if (!inventory.IsInvFull() && equipmentPanel.DeleteItem(itemSlot)) { itemSlot.Unequip(this); Inventory.instance.AddItem(itemSlot); } }
public void ShowUpdatedStats() { if (item == null) { item = (EquipableItem)ItemsList.items.Find(p => p.itemName.Equals(nameText.text)); } menuController.ShowUpdatedStats(item); }
public void OnPawnSelected(Pawn pawn) { if (m_SelectedEquipment != null) { m_Inventory.EquipTo(pawn, m_SelectedEquipment); m_SelectedEquipment = null; } }
public void SetupItemButton(EquipableItem receivedItem, GeneralUiManager ui) { item = receivedItem; uiManager = ui; itemName.text = item.itemName; itemPrice.text = item.price.ToString(); itemRef = new ItemReference(item.itemId, item.quantityHeld, item.itemType); }
public void SetSelectedArmor() { if (charArmorText.text != null && !charArmorText.text.Equals("")) { selectedItem = selectedCharacter.currentEquipment.currentArmor; StartCoroutine("SelectButton", equipPanelSelectedButton); } }
private void EquipItem(EquipableItem item) { UnequipItem(equippedItem); GetComponent <Animator>().SetTrigger("Grabbing"); equippedItem = item; }
//equip item to character public void EquipItem(EquipableItem itemToEquip) { gcReference.EquipInventoryItem(itemToEquip, actualCharacterToEquip); for (int cont = 0; cont < equipmentPanelButtons.Count; cont++) { SetEquipableItemToButton(equipmentPanelButtons[cont]); } }
//Method to Remove Weapon public void RemoveItem(EquipableItem item) { player.GetComponent <Player>().damage -= item.StrengthBonus; player.GetComponent <PlayerMovement>().movementSpeed -= item.AgilityBonus; items.RemoveAt(0); items.Insert(0, null); RefreshUI(); return; }
//Adding an item public void collectItem(EquipableItem item) { equipableItems.Add(item); }
//Removing an item public void removeItem(EquipableItem item) { equipableItems.Remove(item); }
public void add(WeaponSlot slot, EquipableItem item) { equippedWeapons.Add(slot, item); }