public void UnWearItem(CharacterEquipmentSlot from, ContainerSlot to) { from.Item = to.Container.containerItems[to.id]; to.Container.containerItems[to.id] = draggingItem; }
public void TakeDamage(float damageAmount, GameObject damageOwner) { this.damageOwner = damageOwner; if (IsDead()) { return; } // Get base stats for defense defenseBuff = (int)GetComponent <BaseStats>().GetDefense(); CharacterEquipmentSlot charEquipmentSlots = GetComponent <CharacterEquipmentSlot>(); int armorRate = 0; if (charEquipmentSlots != null) { armorRate = (int)charEquipmentSlots.GetArmorBonus(); } defenseBuff += (int)armorRate; // Influenced by char stats as well // If we are defending, consult the equipped weapon or shield to check how much damage it should absorb using its defenseRate property if (GetComponent <Battler>().IsDefending()) { // Assume we don't have a shield equipped, use weapon defenseBuff += (int)GetComponent <WeaponManager>().weaponSlots[0].currentWeapon.defenseRate; } // Finally, update the damage we will receive float damage = Mathf.Clamp(damageAmount - defenseBuff, 0, maxHealthPoints); currentHealthPoints = Mathf.Max(currentHealthPoints - damage, 0); UpdateHealthSlider(); // Now evaluate result if (currentHealthPoints > 0f) { AI_Core_V3 ai = GetComponent <AI_Core_V3>(); // Non-player case if (ai != null) { ai.SetState(AGENT_STATE.TAKING_DAMAGE); } else { GetComponent <Battler>().TakeDamage(); } } else { // Award experience to Playero nly if (damageOwner.gameObject.tag == "Player") { // Reward target with experience points damageOwner.GetComponent <BaseStats>().IncreaseExperience( GetComponent <Battler>().GetRewardExperience() ); } Die(); OnDieEvent.Invoke(); // Remove strafe from player PlayerController playerController = damageOwner.GetComponent <PlayerController>(); if (playerController != null) { playerController.Strafe(false); } } }
public void WearItem(ContainerSlot from, CharacterEquipmentSlot to) { if (from != null && to != null) { if (from.Container.containerItems[from.id].ItemType == to.equipmentPart || ((from.Container.containerItems[from.id].ItemType == ItemType.ONEHAND_WEAPON || from.Container.containerItems[from.id].ItemType == ItemType.TWOHAND_WEAPON)) && to.equipmentPart == ItemType.WEAPON) { if (from.Container.containerItems[from.id].ItemType == ItemType.TWOHAND_WEAPON) { CharacterEquipmentSlot shield = Array.Find(eqSlots, slot => (slot.equipmentPart == ItemType.SHIELD)); if (shield.Item.ItemType == ItemType.NULL) { from.Container.containerItems[from.id] = to.Item; to.Item = draggingItem; characterEquipment.RecalculateStats(); this.HideToolTip(); } else { if (from.Container.AddItemToContainer(shield.Item.ItemId, 1)) { from.Container.containerItems[from.id] = to.Item; to.Item = draggingItem; shield.Item = new Item(); characterEquipment.RecalculateStats(); this.HideToolTip(); } else { Debug.Log("Inventory is full."); } } } else if (from.Container.containerItems[from.id].ItemType == ItemType.SHIELD) { CharacterEquipmentSlot mainHand = Array.Find(eqSlots, slot => (slot.equipmentPart == ItemType.WEAPON)); if (mainHand.Item.ItemType == ItemType.NULL || mainHand.Item.ItemType == ItemType.ONEHAND_WEAPON) { from.Container.containerItems[from.id] = to.Item; to.Item = draggingItem; characterEquipment.RecalculateStats(); this.HideToolTip(); } else { if (from.Container.AddItemToContainer(mainHand.Item.ItemId, 1)) { from.Container.containerItems[from.id] = to.Item; to.Item = draggingItem; mainHand.Item = new Item(); characterEquipment.RecalculateStats(); this.HideToolTip(); } else { Debug.Log("Inventory is full."); } } } else { from.Container.containerItems[from.id] = to.Item; to.Item = draggingItem; characterEquipment.RecalculateStats(); this.HideToolTip(); } } } else if (from != null && to == null) { CharacterEquipmentSlot eqSlot; if (from.Container.containerItems[from.id].ItemType == ItemType.ONEHAND_WEAPON || from.Container.containerItems[from.id].ItemType == ItemType.TWOHAND_WEAPON) { eqSlot = Array.Find(eqSlots, slot => (slot.equipmentPart == ItemType.WEAPON)); } else { eqSlot = Array.Find(eqSlots, slot => (slot.equipmentPart == from.Container.containerItems[from.id].ItemType)); } this.WearItem(from, eqSlot); return; } }