public void AddItemToSlot(TopDownItemObject item) { item.slotOfThisItem = this; itemInSlot = item; itemIcon.sprite = item.itemIcon; itemIcon.enabled = true; }
public void SetTooltip(TopDownItemObject item) { if (item != null) { if (item.damageModifier != 0) { TopDownUIManager.instance.itemTooltip.GetComponent <TopDownUIItemTooltip>().itemNameTxt.text = item.itemName + " +" + item.damageModifier; } else if (item.armorModifier != 0) { TopDownUIManager.instance.itemTooltip.GetComponent <TopDownUIItemTooltip>().itemNameTxt.text = item.itemName + " +" + item.armorModifier; } else { TopDownUIManager.instance.itemTooltip.GetComponent <TopDownUIItemTooltip>().itemNameTxt.text = item.itemName; } /*TopDownUIManager.instance.itemTooltip.GetComponent<TopDownUIItemTooltip>().itemStatsTxt.text = "Strength +" + item.strengthModifier + * "\nDexterity +" + item.dexterityModifier + * "\nConstitution +" + item.constitutionModifier + * "\nWillpower +" + item.willpowerModifier;*/ TopDownUIManager.instance.itemTooltip.GetComponent <TopDownUIItemTooltip>().itemDescrTxt.text = item.itemDescription; if (TopDownUIManager.instance.itemTooltip.GetComponent <CanvasGroup>().alpha == 0f) { TopDownUIManager.instance.itemTooltip.GetComponent <CanvasGroup>().alpha = 1f; } TopDownUIManager.instance.itemTooltip.GetComponent <TopDownUIItemTooltip>().slotType = slotType; } }
private void OnEnable() { td_target = (TopDownItemObject)target; if (TopDownIcon == null) { TopDownIcon = Resources.Load("TopDownIcon") as Texture; } }
public void RemovePointModifiers(TopDownItemObject item) { if (gameObject.tag == "Player") { armorPointsValue -= item.armorModifier; damagePointsValue -= item.damageModifier; //strength and others also //Than update UI TopDownCharacterManager.instance.controllingCharacter.GetComponent <TopDownCharacterCard>().characterInventory.armorPointsTxt.text = "AP: " + armorPointsValue.ToString(); TopDownCharacterManager.instance.controllingCharacter.GetComponent <TopDownCharacterCard>().characterInventory.damagePointsTxt.text = "DP: " + damagePointsValue.ToString(); return; } }
public void AddItemJustAsset(TopDownItemObject item) { if (items.Count >= itemSpace) { Debug.Log("No more room in the inventory."); } else { for (int i = 0; i < slots.Length; i++) { if (slots[i].itemInSlot == null) { items.Add(item); slots[i].AddItemToSlot(item); return; } } } }
public void Update() { if (holdingItemSlot.GetComponent <CanvasGroup>().alpha == 1f) { Vector2 tmp = Input.mousePosition; Vector2 namePos = new Vector2(tmp.x + holdingSlotOffset.x, tmp.y + holdingSlotOffset.y); holdingItemSlot.transform.position = namePos; } if (previousSlot != null) { if (TopDownUIManager.instance.checkUi.IsPointerOverUIObject() == false) { if (Input.GetKeyDown(TopDownInputManager.instance.interactKey)) { if (previousSlot.slotType == SlotType.Inventory) { slots[0].ClearSlot(previousSlot); holdingItem = null; holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = null; holdingItemSlot.GetComponent <CanvasGroup>().alpha = 0f; previousSlot = null; StartCoroutine(ClickedOutOfUiTimer()); //PLAY DESTROY ITEM SOUND } else if (previousSlot.slotType == SlotType.Quickslot) { previousSlot.GetComponent <TopDownUIQuickSlot>().originalSlot.slottedInQuick = null; slots[0].ClearSlot(previousSlot); holdingItem = null; holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = null; holdingItemSlot.GetComponent <CanvasGroup>().alpha = 0f; previousSlot = null; StartCoroutine(ClickedOutOfUiTimer()); } } } } }
private void Start() { td_CharacterCard = gameObject.GetComponent <TopDownCharacterCard>(); td_Inventory = TopDownUIInventory.instance; td_characterManager = TopDownCharacterManager.instance; if (td_Inventory != null) { if (td_characterManager != null) { for (int character = 0; character < td_characterManager.activeCharacters.Count; character++) { if (td_characterManager.activeCharacters[character] == GetComponent <TopDownControllerMain>()) { if (itemsToPlaceInInventory.Length > 0) { for (int i = 0; i < itemsToPlaceInInventory.Length; i++) { td_Inventory.AddItemJustAsset(itemsToPlaceInInventory[i]); itemsInInventory.Add(itemsToPlaceInInventory[i]); } itemsToPlaceInInventory = null; } } } if (itemsToEquip.Length > 0) { for (int i = 0; i < itemsToEquip.Length; i++) { TopDownItemObject tmp = itemsToEquip[i]; if (td_CharacterCard.characterInventory != null) { td_Inventory.AddItemJustAsset(itemsToEquip[i]); itemsToEquip[i].slotOfThisItem.UseSlottedItem(); td_CharacterCard.characterInventory.equipmentSlots[(int)itemsToEquip[i].itemType].ClearSlot(itemsToEquip[i].slotOfThisItem); td_CharacterCard.characterInventory.equipmentSlots[(int)itemsToEquip[i].itemType].AddItemToSlot(tmp); } else { td_CharacterCard.equipmentManager.EquipItemForNpc(itemsToEquip[i]); itemsEquipped.Add(itemsToEquip[i]); } } } } else { if (itemsToPlaceInInventory.Length > 0) { for (int i = 0; i < itemsToPlaceInInventory.Length; i++) { td_Inventory.AddItemJustAsset(itemsToPlaceInInventory[i]); itemsInInventory.Add(itemsToPlaceInInventory[i]); } } if (itemsToEquip.Length > 0) { for (int i = 0; i < itemsToEquip.Length; i++) { TopDownItemObject tmp = itemsToEquip[i]; if (td_CharacterCard.characterInventory != null) { td_Inventory.AddItemJustAsset(itemsToEquip[i]); itemsToEquip[i].slotOfThisItem.UseSlottedItem(); td_CharacterCard.characterInventory.equipmentSlots[(int)itemsToEquip[i].itemType].ClearSlot(itemsToEquip[i].slotOfThisItem); td_CharacterCard.characterInventory.equipmentSlots[(int)itemsToEquip[i].itemType].AddItemToSlot(tmp); } else { td_CharacterCard.equipmentManager.EquipItemForNpc(itemsToEquip[i]); itemsEquipped.Add(itemsToEquip[i]); } } } } } else { this.enabled = false; } }
/// <summary> /// Used when we want to add new character to our party. /// </summary> /// <param name="newCharacter"></param> public void AddCharacterToParty(GameObject newCharacter) { if (activeCharacters.Count < 4) { for (int i = 0; i < characterButtonsUi.Length; i++) { if (characterButtonsUi[i].occupied == false) { activeCharacters.Add(newCharacter.GetComponent <TopDownControllerMain>()); characterButtonsUi[i].characterInSlot = newCharacter.GetComponent <TopDownControllerMain>(); characterButtonsUi[i].SetCharacterUI(); newCharacter.GetComponent <TopDownCharacterCard>().td_characterIndex = i; newCharacter.GetComponent <TopDownCharacterCard>().characterInventory = td_Inventory.charEquipmentSlots[i]; newCharacter.GetComponent <TopDownCharacterCard>().characterInventory.SetUpInventory(newCharacter.GetComponent <TopDownCharacterCard>()); newCharacter.GetComponent <TopDownCharacterCard>().UpdatePortrait(); //With this method we are adding equipment to usable equipment manager and inventory from npc if (td_Inventory.currentEquipmentSlots != null && td_Inventory.currentEquipmentManager != null) //We want to do this only if this is not our first cha { TopDownCharacterEquipmentSlots lastSlots = td_Inventory.currentEquipmentSlots; TopDownEquipmentManager lastManager = td_Inventory.currentEquipmentManager; lastManager.gameObject.GetComponent <TopDownCharacterCard>().characterInventory.gameObject.SetActive(false); td_Inventory.currentEquipmentSlots = newCharacter.GetComponent <TopDownCharacterCard>().characterInventory; td_Inventory.currentEquipmentManager = newCharacter.GetComponent <TopDownCharacterCard>().equipmentManager; //Check if NPC has equipment on himself, so we can add it to character inventory window. if (newCharacter.GetComponent <TopDownStartupItemsSetup>()) { TopDownStartupItemsSetup startUpItems = newCharacter.GetComponent <TopDownStartupItemsSetup>(); if (startUpItems.itemsEquipped.Count > 0) { for (int s = 0; s < startUpItems.itemsEquipped.Count; s++) { TopDownItemObject tmp = startUpItems.itemsEquipped[s]; td_Inventory.AddItemJustAsset(startUpItems.itemsEquipped[s]); newCharacter.GetComponent <TopDownCharacterCard>().characterInventory.equipmentSlots[(int)startUpItems.itemsEquipped[s].itemType].ClearSlot(startUpItems.itemsEquipped[s].slotOfThisItem); newCharacter.GetComponent <TopDownCharacterCard>().characterInventory.equipmentSlots[(int)startUpItems.itemsEquipped[s].itemType].AddItemToSlot(tmp); } } if (startUpItems.itemsToPlaceInInventory.Length > 0) { for (int inv = 0; inv < startUpItems.itemsToPlaceInInventory.Length; inv++) { td_Inventory.AddItemJustAsset(startUpItems.itemsToPlaceInInventory[inv]); startUpItems.itemsInInventory.Add(startUpItems.itemsToPlaceInInventory[inv]); } startUpItems.itemsToPlaceInInventory = null; } } td_Inventory.currentEquipmentSlots = lastSlots; td_Inventory.currentEquipmentManager = lastManager; lastManager.gameObject.GetComponent <TopDownCharacterCard>().characterInventory.gameObject.SetActive(true); newCharacter.GetComponent <TopDownCharacterCard>().characterInventory.armorPointsTxt.text = "AP: " + newCharacter.GetComponent <TopDownEquipmentManager>().armorPointsValue.ToString(); newCharacter.GetComponent <TopDownCharacterCard>().characterInventory.damagePointsTxt.text = "DP: " + newCharacter.GetComponent <TopDownEquipmentManager>().damagePointsValue.ToString(); newCharacter.GetComponent <TopDownCharacterCard>().characterInventory.gameObject.SetActive(false); } if (controllingCharacter == null) { controllingCharacter = newCharacter; controllingCharacter.GetComponent <TopDownControllerInteract>().enabled = true; if (controllingCharacter.GetComponent <TopDownCharacterCard>().inventoryCamera != null) { controllingCharacter.GetComponent <TopDownCharacterCard>().inventoryCamera.SetActive(true); } TopDownUIInventory.instance.currentEquipmentManager = newCharacter.GetComponent <TopDownEquipmentManager>(); TopDownUIInventory.instance.currentEquipmentSlots = newCharacter.GetComponent <TopDownCharacterCard>().characterInventory; } else { newCharacter.GetComponent <TopDownCharacterCard>().SetAiActive(); } newCharacter.tag = "Player"; if (characterCamera.td_Target == null) { characterCamera.td_Target = newCharacter.transform; } characterButtonsUi[i].occupied = true; return; } } } else { Debug.Log("No more room in party. We already have max number(4) of character."); } }
public void OnPointerClick(PointerEventData eventData) { main = TopDownCharacterManager.instance.controllingCharacter.GetComponent <TopDownControllerMain>(); if (main.tdcm_animator.GetBool("TargetInFront") == false) //We should be able to use slots only when out of combat { if (eventData.button == PointerEventData.InputButton.Right) { if (itemInSlot != null && inventory.holdingItem == null) { if (GetComponent <TopDownUIItemSlot>().slotType != SlotType.Quickslot) { if (itemInSlot.isItem == true) { //If item we are trying to equip is two handed or ranged weapon, we want to check if there is a shield equipped and to deequip it if (itemInSlot.weaponHoldingType == WeaponHoldingType.TwoHanded || itemInSlot.weaponType == WeaponType.Ranged) { if (inventory.currentEquipmentSlots.equipmentSlots[3].itemInSlot) { inventory.currentEquipmentSlots.equipmentSlots[3].UseSlottedItem(); //print(inventory.currentEquipmentManager.gameObject.name); inventory.MoveItemToInventory(inventory.currentEquipmentSlots.equipmentSlots[3]); ClearSlot(inventory.currentEquipmentSlots.equipmentSlots[3]); } } //If item we are trying to equip is shield, we want to check if there is a two handed weapon equipped and to deequip it if (itemInSlot.itemType == ItemType.Shield) { if (inventory.currentEquipmentSlots.equipmentSlots[2].itemInSlot != null && (inventory.currentEquipmentSlots.equipmentSlots[2].itemInSlot.weaponHoldingType == WeaponHoldingType.TwoHanded || inventory.currentEquipmentSlots.equipmentSlots[2].itemInSlot.weaponType == WeaponType.Ranged)) { inventory.currentEquipmentSlots.equipmentSlots[2].UseSlottedItem(); //print(inventory.currentEquipmentManager.gameObject.name); inventory.MoveItemToInventory(inventory.currentEquipmentSlots.equipmentSlots[2]); ClearSlot(inventory.currentEquipmentSlots.equipmentSlots[2]); } } if (inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType] != null) { if (inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].itemInSlot == null) { //Debug.Log("No item equiped."); UseSlottedItem(); //print(inventory.currentEquipmentManager.gameObject.name); inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].AddItemToSlot(itemInSlot); if (slottedInQuick != null) { inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].slottedInQuick = slottedInQuick; slottedInQuick = null; } inventory.RemoveItem(itemInSlot); } else if (inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].itemInSlot == itemInSlot) { //Debug.Log("This item is equiped."); UseSlottedItem(); //print(inventory.currentEquipmentManager.gameObject.name); inventory.MoveItemToInventory(inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType]); inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].AddItemToSlot(itemInSlot); } else if (inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].itemInSlot != itemInSlot) { //Debug.Log("Other item is equiped."); inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].UseSlottedItem(); //print(inventory.currentEquipmentManager.gameObject.name); inventory.MoveItemToInventory(inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType]); inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].AddItemToSlot(itemInSlot); UseSlottedItem(); //print(inventory.currentEquipmentManager.gameObject.name); inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].AddItemToSlot(itemInSlot); if (slottedInQuick != null) { inventory.currentEquipmentSlots.equipmentSlots[(int)itemInSlot.itemType].slottedInQuick = slottedInQuick; slottedInQuick = null; } inventory.RemoveItem(itemInSlot); } } ClearSlot(this); /*if (TopDownAudioManager.instance.inventoryItemUseAudio != null) { * Instantiate(TopDownAudioManager.instance.inventoryItemUseAudio, Vector3.zero, Quaternion.identity); * }*/ } else //If this is scroll we want different behaviour { if (TopDownAudioManager.instance.spellUseAudio != null) { Instantiate(TopDownAudioManager.instance.spellUseAudio, Vector3.zero, Quaternion.identity); } TopDownCharacterManager.instance.controllingCharacter.GetComponent <TopDownRpgSpellcaster>().activeSpell = itemInSlot; TopDownCharacterManager.instance.controllingCharacter.GetComponent <TopDownRpgSpellcaster>().spellItemSlot = this; TopDownCharacterManager.instance.controllingCharacter.GetComponent <TopDownRpgSpellcaster>().castingSpell = true; if (TopDownUIManager.instance.charInfoPanel.inventoryActive) { if (TopDownUIManager.instance.inventory.GetComponent <CanvasGroup>().alpha > 0) { TopDownUIManager.instance.SetUIState(TopDownUIManager.instance.inventory); TopDownUIManager.instance.charInfoPanel.inventoryActive = false; } } if (TopDownUIManager.instance.charInfoPanel.questLogActive) { if (TopDownUIManager.instance.questLog.GetComponent <CanvasGroup>().alpha > 0) { TopDownUIManager.instance.SetUIState(TopDownUIManager.instance.questLog); TopDownUIManager.instance.charInfoPanel.inventoryActive = true; } } } } } } else if (eventData.button == PointerEventData.InputButton.Left) { if (inventory.holdingItem != null) { if (GetComponent <TopDownUIItemSlot>().slotType == SlotType.Equipment) //Is the slot we clicked on of Equipment type { if (GetComponent <TopDownUIEquipmentSlot>().equipmentType == inventory.holdingItem.itemType) //Is the item we are holding of the same type as the Equipment Slot (so we do not equip helm on weapon etc...) { if (GetComponent <TopDownUIEquipmentSlot>().itemInSlot != inventory.holdingItem && GetComponent <TopDownUIEquipmentSlot>() != inventory.previousSlot) //We do not want to swap the same item //If item we are trying to equip is two handed weapon, we want to check if there is a shield equipped and to deequip it { if (inventory.holdingItem.weaponHoldingType == WeaponHoldingType.TwoHanded) { if (inventory.currentEquipmentSlots.equipmentSlots[3].itemInSlot != null) { inventory.currentEquipmentSlots.equipmentSlots[3].UseSlottedItem(); inventory.MoveItemToInventory(inventory.currentEquipmentSlots.equipmentSlots[3]); ClearSlot(inventory.currentEquipmentSlots.equipmentSlots[3]); } } //If item we are trying to equip is shield, we want to check if there is a two handed weapon equipped and to deequip it if (inventory.holdingItem.itemType == ItemType.Shield) { if (inventory.currentEquipmentSlots.equipmentSlots[2].itemInSlot != null && inventory.currentEquipmentSlots.equipmentSlots[2].itemInSlot.weaponHoldingType == WeaponHoldingType.TwoHanded) { inventory.currentEquipmentSlots.equipmentSlots[2].UseSlottedItem(); inventory.MoveItemToInventory(inventory.currentEquipmentSlots.equipmentSlots[2]); ClearSlot(inventory.currentEquipmentSlots.equipmentSlots[2]); } } TopDownItemObject tmpItem = inventory.currentEquipmentManager.currentEquipment[(int)inventory.holdingItem.itemType]; if (inventory.previousSlot.slottedInQuick != null) //If item we are holding is slotted in Quick Slot, we want to keep the same Quick Slot reference { slottedInQuick = inventory.previousSlot.slottedInQuick; inventory.previousSlot.slottedInQuick = null; } ClearSlot(inventory.previousSlot); //Clear previous Slot inventory.previousSlot = null; if (itemInSlot != null) { inventory.currentEquipmentManager.UnequipItem(itemInSlot); } AddItemToSlot(inventory.holdingItem); UseSlottedItem(); if (tmpItem != null) { inventory.holdingItem = tmpItem; inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = inventory.holdingItem.itemIcon; } else { inventory.holdingItem = null; inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = null; inventory.holdingItemSlot.GetComponent <CanvasGroup>().alpha = 0f; } } else { inventory.holdingItem = null; inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = null; inventory.holdingItemSlot.GetComponent <CanvasGroup>().alpha = 0f; } } else { //Debug.Log("This is NOT the same equipment type"); } } else if (GetComponent <TopDownUIItemSlot>().slotType == SlotType.Inventory) { if (itemInSlot == null) { if (inventory.previousSlot != null) { if (inventory.currentEquipmentManager.currentEquipment[(int)inventory.previousSlot.itemInSlot.itemType] == inventory.previousSlot.itemInSlot) { inventory.previousSlot.itemInSlot.UnuseItem(); } if (inventory.previousSlot.slottedInQuick != null) { inventory.previousSlot.slottedInQuick.originalSlot = this; slottedInQuick = inventory.previousSlot.slottedInQuick; inventory.previousSlot.slottedInQuick = null; } ClearSlot(inventory.previousSlot); inventory.previousSlot = null; } AddItemToSlot(inventory.holdingItem); inventory.holdingItem = null; inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = null; inventory.holdingItemSlot.GetComponent <CanvasGroup>().alpha = 0f; } else { if (itemInSlot == inventory.holdingItem && GetComponent <TopDownUIItemSlot>() == inventory.previousSlot) //This is the same item, remove holding item (we must check if it is the same slot, because we can have multiple same items in inventory) { inventory.holdingItem = null; inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = null; inventory.holdingItemSlot.GetComponent <CanvasGroup>().alpha = 0f; } else { if (inventory.previousSlot != null) { if (inventory.previousSlot.slottedInQuick != null) { inventory.previousSlot.slottedInQuick.originalSlot = this; slottedInQuick = inventory.previousSlot.slottedInQuick; inventory.previousSlot.slottedInQuick = null; } TopDownItemObject tmpItemToGrab = itemInSlot; ClearSlot(inventory.previousSlot); inventory.previousSlot = null; AddItemToSlot(inventory.holdingItem); inventory.holdingItem = tmpItemToGrab; inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = tmpItemToGrab.itemIcon; inventory.holdingItemSlot.GetComponent <CanvasGroup>().alpha = 1f; ClearTooltip(); } /* * TopDownItemObject tmpItem = inventory.holdingItem; * * if (inventory.previousSlot != null) { * if (inventory.currentEquipmentManager.currentEquipment[(int)inventory.previousSlot.itemInSlot.itemType] == inventory.previousSlot.itemInSlot) { * inventory.previousSlot.itemInSlot.UnuseItem(); * } * if (inventory.previousSlot.slottedInQuick != null) { * inventory.previousSlot.slottedInQuick.originalSlot = this; * slottedInQuick = inventory.previousSlot.slottedInQuick; * inventory.previousSlot.slottedInQuick = null; * } * ClearSlot(inventory.previousSlot); * inventory.previousSlot = null; * } * * GrabItemInSlot(); * * AddItemToSlot(tmpItem); */ } } } else if (GetComponent <TopDownUIItemSlot>().slotType == SlotType.Quickslot) { if (GetComponent <TopDownUIQuickSlot>().originalSlot != null) { GetComponent <TopDownUIQuickSlot>().originalSlot.slottedInQuick = null; } ClearSlot(this); AddItemToSlot(inventory.holdingItem); if (inventory.previousSlot.slotType != SlotType.Quickslot) { if (inventory.previousSlot.slottedInQuick == null) { inventory.previousSlot.slottedInQuick = GetComponent <TopDownUIQuickSlot>(); } else { if (inventory.previousSlot.slottedInQuick != this) { inventory.previousSlot.slottedInQuick.originalSlot = null; ClearSlot(inventory.previousSlot.slottedInQuick); inventory.previousSlot.slottedInQuick = GetComponent <TopDownUIQuickSlot>(); } } GetComponent <TopDownUIQuickSlot>().originalSlot = inventory.previousSlot; } else { ClearSlot(inventory.previousSlot); GetComponent <TopDownUIQuickSlot>().originalSlot = inventory.previousSlot.GetComponent <TopDownUIQuickSlot>().originalSlot; inventory.previousSlot.GetComponent <TopDownUIQuickSlot>().originalSlot.slottedInQuick = GetComponent <TopDownUIQuickSlot>(); inventory.previousSlot.GetComponent <TopDownUIQuickSlot>().originalSlot = null; } inventory.holdingItem = null; inventory.holdingItemSlot.GetComponent <TopDownUIHoldingItemSlot>().itemIconImage.sprite = null; inventory.holdingItemSlot.GetComponent <CanvasGroup>().alpha = 0f; } } else { if (itemInSlot != null) { GrabItemInSlot(); } } } } }
public void RemoveItem(TopDownItemObject item) { items.Remove(item); }
public IEnumerator CastSpell() { if (spellItemSlot != null) { if (spellItemSlot.slottedInQuick != null) { spellItemSlot.slottedInQuick.ClearSlot(spellItemSlot.slottedInQuick); spellItemSlot.slottedInQuick = null; } spellItemSlot.ClearSlot(spellItemSlot); } animator.Play(activeSpell.castingSpellAnimation); yield return(new WaitForSeconds(activeSpell.animationTriggerTime)); if (activeSpell.spellCastSfx != null) { Instantiate(activeSpell.spellCastSfx, Vector3.zero, Quaternion.identity); } if (activeSpell.spellType == SpellType.CastOnEnemy) { GameObject fx = Instantiate(activeSpell.spellFx as GameObject); fx.transform.SetParent(transform); fx.transform.localPosition = new Vector3(0f, gameObject.GetComponent <CapsuleCollider>().center.y, 0f); fx.transform.SetParent(null); fx.GetComponent <Rigidbody>().velocity = (target.transform.position - transform.position).normalized * speed; if (fx.GetComponent <TopDownRpgSpellCollision>() == null) { TopDownRpgSpellCollision spellCol = fx.AddComponent <TopDownRpgSpellCollision>(); spellCol.thisSpell = activeSpell; spellCol.thisSpellType = activeSpell.spellType; } } else if (activeSpell.spellType == SpellType.CastOnAlly) { GameObject fx = Instantiate(activeSpell.spellFx as GameObject); fx.transform.SetParent(transform); fx.transform.localPosition = new Vector3(0f, gameObject.GetComponent <CapsuleCollider>().center.y, 0f); fx.transform.SetParent(null); fx.GetComponent <Rigidbody>().velocity = (target.transform.position - transform.position).normalized * speed; if (fx.GetComponent <TopDownRpgSpellCollision>() == null) { TopDownRpgSpellCollision spellCol = fx.AddComponent <TopDownRpgSpellCollision>(); spellCol.thisSpell = activeSpell; spellCol.thisSpellType = activeSpell.spellType; } } castingSpell = false; tdcInteract.RemoveFocus(); previousTarget = target; target = null; tdcCard.energy -= activeSpell.castingCost; activeSpell = null; spellItemSlot = null; }
public void UnequipItem(TopDownItemObject item) { if (TopDownAudioManager.instance.inventoryItemUseAudio != null) { Instantiate(TopDownAudioManager.instance.inventoryItemUseAudio, Vector3.zero, Quaternion.identity); } RemovePointModifiers(item); int slotIndex = (int)item.itemType; currentEquipment[slotIndex] = null; weaponTypeUsed = WeaponType.NoWeapon; weaponHoldingType = WeaponHoldingType.None; if (item.itemType == ItemType.Weapon) { if (item.weaponType == WeaponType.Melee) { if (weaponHolsterMountPoint.childCount > 0) { foreach (Transform itemGo in weaponHolsterMountPoint) { Destroy(itemGo.gameObject); } } } else if (item.weaponType == WeaponType.Ranged) { if (shieldHolsterMountPoint.childCount > 0) { foreach (Transform itemGo in shieldHolsterMountPoint) { Destroy(itemGo.gameObject); } } } } else if (item.itemType == ItemType.Shield) { if (shieldHolsterMountPoint.childCount > 0) { foreach (Transform itemGo in shieldHolsterMountPoint) { Destroy(itemGo.gameObject); } } } else { if (characterEquipmentType == CharacterEquipementType.EnableMesh) { for (int i = 0; i < itemsOnCharacter.Length; i++) { if (item.itemSkinnedMeshName == itemsOnCharacter[i].name) { itemsOnCharacter[i].gameObject.SetActive(false); } } } else if (characterEquipmentType == CharacterEquipementType.InstantiateMesh) { if (item.itemType == ItemType.Chest) { Destroy(headInstantiatedModel); headInstantiatedModel = null; } else if (item.itemType == ItemType.Head) { Destroy(headInstantiatedModel); headInstantiatedModel = null; } else if (item.itemType == ItemType.Legs) { Destroy(leggsLInstantiatedModel); Destroy(leggsRInstantiatedModel); leggsLInstantiatedModel = null; leggsRInstantiatedModel = null; } else if (item.itemType == ItemType.Hands) { Destroy(handsLInstantiatedModel); Destroy(handsRInstantiatedModel); handsLInstantiatedModel = null; handsRInstantiatedModel = null; } else if (item.itemType == ItemType.Neck) { Destroy(neckInstantiatedModel); neckInstantiatedModel = null; } } else if (characterEquipmentType == CharacterEquipementType.ReplaceMesh) { if (item.itemType == ItemType.Chest) { bodyMesh.sharedMesh = defaultBodyMesh; } else if (item.itemType == ItemType.Head) { helmMesh.sharedMesh = null; } else if (item.itemType == ItemType.Legs) { leggsMesh.sharedMesh = defaultLeggsMesh; } else if (item.itemType == ItemType.Hands) { handsMesh.sharedMesh = defaultHandsMesh; } else if (item.itemType == ItemType.Neck) { neckMesh.sharedMesh = null; } } } for (int i = 0; i < TopDownUIInventory.instance.slots.Length; i++) { if (TopDownUIInventory.instance.slots[i].itemInSlot == item) { //TopDownUIInventory.instance.slots[i].GetComponent<Image>().color = TopDownUIInventory.instance.slots[i].normalSlotColor; } } if (TopDownUIManager.instance.characterPortraitType == CharacterPortraitType.Runtime) { GetComponent <TopDownCharacterCard>().UpdatePortrait(); } }
public void EquipItemForNpc(TopDownItemObject item) { int slotIndex = (int)item.itemType; currentEquipment[slotIndex] = item; if (item.itemType == ItemType.Weapon) { if (item.weaponType == WeaponType.Melee) { if (item.itemGameObject != null) { GameObject itemGo = Instantiate(item.itemGameObject) as GameObject; for (int i = 0; i < itemGo.transform.childCount; i++) { itemGo.transform.GetChild(i).gameObject.layer = gameObject.layer; } itemGo.transform.SetParent(weaponHolsterMountPoint); itemGo.transform.localPosition = Vector3.zero; itemGo.transform.localEulerAngles = Vector3.zero; } } else if (item.weaponType == WeaponType.Ranged) { if (item.itemGameObject != null) { GameObject itemGo = Instantiate(item.itemGameObject) as GameObject; for (int i = 0; i < itemGo.transform.childCount; i++) { itemGo.transform.GetChild(i).gameObject.layer = gameObject.layer; } itemGo.transform.SetParent(shieldHolsterMountPoint); itemGo.transform.localPosition = Vector3.zero; itemGo.transform.localEulerAngles = Vector3.zero; } } weaponTypeUsed = item.weaponType; weaponHoldingType = item.weaponHoldingType; } else if (item.itemType == ItemType.Shield) { if (item.itemGameObject != null) { GameObject itemGo = Instantiate(item.itemGameObject) as GameObject; for (int i = 0; i < itemGo.transform.childCount; i++) { itemGo.transform.GetChild(i).gameObject.layer = gameObject.layer; } itemGo.transform.SetParent(shieldHolsterMountPoint); itemGo.transform.localPosition = Vector3.zero; itemGo.transform.localEulerAngles = Vector3.zero; } } if (characterEquipmentType == CharacterEquipementType.EnableMesh) { for (int i = 0; i < itemsOnCharacter.Length; i++) { if (item.itemSkinnedMeshName == itemsOnCharacter[i].name) { itemsOnCharacter[i].enabled = true; } } } else if (characterEquipmentType == CharacterEquipementType.ReplaceMesh) { if (item.itemType == ItemType.Chest) { bodyMesh.sharedMesh = item.itemMesh; } else if (item.itemType == ItemType.Head) { helmMesh.sharedMesh = item.itemMesh; } else if (item.itemType == ItemType.Legs) { leggsMesh.sharedMesh = item.itemMesh; } else if (item.itemType == ItemType.Hands) { handsMesh.sharedMesh = item.itemMesh; } else if (item.itemType == ItemType.Neck) { neckMesh.sharedMesh = item.itemMesh; } } AddPointModifiers(item); }
public void EquipItem(TopDownItemObject item) { int slotIndex = (int)item.itemType; /*if (currentEquipment[slotIndex] != null) { * for (int i = 0; i < TopDownUIInventory.instance.slots.Length; i++) { * if (TopDownUIInventory.instance.slots[i].itemInSlot == currentEquipment[slotIndex]) { * TopDownUIInventory.instance.slots[i].GetComponent<Image>().color = TopDownUIInventory.instance.slots[i].normalSlotColor; * } * } * }*/ currentEquipment[slotIndex] = item; //Instantiate weapon model as weapon mount points child if (item.itemType == ItemType.Weapon) { if (item.weaponType == WeaponType.Melee) { if (item.itemGameObject != null) { GameObject itemGo = Instantiate(item.itemGameObject) as GameObject; for (int i = 0; i < itemGo.transform.childCount; i++) { itemGo.transform.GetChild(i).gameObject.layer = gameObject.layer; } itemGo.transform.SetParent(weaponHolsterMountPoint); itemGo.transform.localPosition = Vector3.zero; itemGo.transform.localEulerAngles = Vector3.zero; } } else if (item.weaponType == WeaponType.Ranged) { if (item.itemGameObject != null) { GameObject itemGo = Instantiate(item.itemGameObject) as GameObject; for (int i = 0; i < itemGo.transform.childCount; i++) { itemGo.transform.GetChild(i).gameObject.layer = gameObject.layer; } itemGo.transform.SetParent(shieldHolsterMountPoint); itemGo.transform.localPosition = Vector3.zero; itemGo.transform.localEulerAngles = Vector3.zero; } } weaponTypeUsed = item.weaponType; weaponHoldingType = item.weaponHoldingType; } else if (item.itemType == ItemType.Shield) { if (item.itemGameObject != null) { GameObject itemGo = Instantiate(item.itemGameObject) as GameObject; for (int i = 0; i < itemGo.transform.childCount; i++) { itemGo.transform.GetChild(i).gameObject.layer = gameObject.layer; } itemGo.transform.SetParent(shieldHolsterMountPoint); itemGo.transform.localPosition = Vector3.zero; itemGo.transform.localEulerAngles = Vector3.zero; } } else { if (characterEquipmentType == CharacterEquipementType.EnableMesh) { for (int i = 0; i < itemsOnCharacter.Length; i++) { if (item.itemSkinnedMeshName == itemsOnCharacter[i].name) { itemsOnCharacter[i].gameObject.SetActive(true); } } } else if (characterEquipmentType == CharacterEquipementType.InstantiateMesh) { if (item.itemGameObject != null) { if (item.itemType == ItemType.Chest) { GameObject itemGo = Instantiate(item.itemGameObject) as GameObject; for (int i = 0; i < itemGo.transform.childCount; i++) { itemGo.transform.GetChild(i).gameObject.layer = gameObject.layer; } itemGo.transform.SetParent(bodyTransform); bodyInstantiatedModel = itemGo; itemGo.transform.localPosition = Vector3.zero; itemGo.transform.localEulerAngles = Vector3.zero; } else if (item.itemType == ItemType.Head) { GameObject itemGo = Instantiate(item.itemGameObject) as GameObject; for (int i = 0; i < itemGo.transform.childCount; i++) { itemGo.transform.GetChild(i).gameObject.layer = gameObject.layer; } itemGo.transform.SetParent(headTransform); headInstantiatedModel = itemGo; itemGo.transform.localPosition = Vector3.zero; itemGo.transform.localEulerAngles = Vector3.zero; } else if (item.itemType == ItemType.Legs) { } else if (item.itemType == ItemType.Hands) { } else if (item.itemType == ItemType.Neck) { GameObject itemGo = Instantiate(item.itemGameObject) as GameObject; for (int i = 0; i < itemGo.transform.childCount; i++) { itemGo.transform.GetChild(i).gameObject.layer = gameObject.layer; } itemGo.transform.SetParent(neckTransform); neckInstantiatedModel = itemGo; itemGo.transform.localPosition = Vector3.zero; itemGo.transform.localEulerAngles = Vector3.zero; } } } else if (characterEquipmentType == CharacterEquipementType.ReplaceMesh) { if (item.itemType == ItemType.Chest) { bodyMesh.sharedMesh = item.itemMesh; } else if (item.itemType == ItemType.Head) { helmMesh.sharedMesh = item.itemMesh; } else if (item.itemType == ItemType.Legs) { leggsMesh.sharedMesh = item.itemMesh; } else if (item.itemType == ItemType.Hands) { handsMesh.sharedMesh = item.itemMesh; } else if (item.itemType == ItemType.Neck) { neckMesh.sharedMesh = item.itemMesh; } } } /*for (int i = 0; i < TopDownUIInventory.instance.slots.Length; i++) { * if (TopDownUIInventory.instance.slots[i].itemInSlot == item) { * TopDownUIInventory.instance.slots[i].GetComponent<Image>().color = TopDownUIInventory.instance.slots[i].equipedSlotColor; * } * }*/ if (TopDownAudioManager.instance.inventoryItemUseAudio != null) { Instantiate(TopDownAudioManager.instance.inventoryItemUseAudio, Vector3.zero, Quaternion.identity); } AddPointModifiers(item); if (gameObject.tag != "NPC") { if (TopDownUIManager.instance.characterPortraitType == CharacterPortraitType.Runtime) { GetComponent <TopDownCharacterCard>().UpdatePortrait(); } } }