void DamageDoneOnHero(BattleHero hero, int damage) { AttackEffect attackEffect = m_AttackEffecPool.GetItem(); attackEffect.transform.position = hero.transform.position; attackEffect.RegulateSize(hero.GetComponent <RectTransform>()); attackEffect.gameObject.SetActive(true); StringBuilder builder = new StringBuilder(AttributeChange.HEALTH_DECREASE_TEXT); builder.Replace("{DECREASE}", damage.ToString()); AttributeChange attributeChange = AttribueChangeEffectPool.GetItem(); attributeChange.PrepareForActivation(hero.transform, false, builder.ToString()); attributeChange.gameObject.SetActive(true); if (!hero.IsEnemy) { CurrentFightSettings.selectedAllyHeroIndex = FindHeroIndex(m_PlayerHeroes, hero); } EventMessenger.NotifyEvent(SaveEvents.SAVE_GAME_STATE); bool isDead = hero.TakeDamage(damage); }
// For UseButton's On_Click() event. Deducts the item from party stash and // applies the effect to the hero. public void Click_UseButton() { // Only proceed if a valid choice is currently selected if (selection == null) { return; } // Reference item InvItem item = partyStash.Contents[(int)selection]; // Display error message if a non-consumable was selected (this should not happen) if (item.Slot != EquipSlots.none) { Debug.Log("Cannot use a non-consumable"); } // Check for full health, send message if so int hp = hero.HP; int hpMax = hero.HPMax; if (hp == hpMax && item.Type == InvType.Potion && item.Subtype == InvSubtype.Health) { previousMessage = messageText.text; messageText.text = "You are already at full health."; messageTimer.Run(); return; } // Check for full MP, send message if so int mp = hero.MP; int mpMax = hero.MPMax; if (mp == mpMax && item.Type == InvType.Potion && item.Subtype == InvSubtype.Mana) { previousMessage = messageText.text; messageText.text = "You are already at full mana."; messageTimer.Run(); return; } // Apply the effects of a potion or tome switch (item.Type) { case InvType.Potion: AudioManager.PlaySound(AudioClipName.UsePotion); int healing; switch (item.Subtype) { #region Use_Health_Pot case InvSubtype.Health: switch (item.Name) { case InvNames.Potion_Health_Tiny: healing = 25; break; case InvNames.Potion_Health_Small: healing = 75; break; case InvNames.Potion_Health_Medium: healing = 250; break; case InvNames.Potion_Health_Large: healing = 600; break; case InvNames.Potion_Health_Huge: healing = 2000; break; case InvNames.Potion_Health_Epic: healing = 100000; break; default: healing = 25; break; } if (hp + healing > hpMax) { healing = hpMax - hp; } //hp += healing; hero.TakeDamage(-healing);; break; // no call to DisplayDamage or TurnOver here, otherwise same as BattleInventoryMonitor #endregion Use_Health_Pot #region Use_Mana_Potion case InvSubtype.Mana: switch (item.Name) { case InvNames.Potion_Mana_Tiny: healing = 10; break; case InvNames.Potion_Mana_Small: healing = 20; break; case InvNames.Potion_Mana_Medium: healing = 50; break; case InvNames.Potion_Mana_Large: healing = 125; break; case InvNames.Potion_Mana_Huge: healing = 250; break; case InvNames.Potion_Mana_Epic: healing = 100000; break; default: healing = 10; break; } if (mp + healing > mpMax) { healing = mpMax - mp; } //hp += healing; hero.TakeMPDamage(-healing);; break; // no call to DisplayDamage or TurnOver here, otherwise same as BattleInventoryMonitor #endregion Use_Mana_Pot } break; case InvType.Tome: AudioManager.PlaySound(AudioClipName.UseTome); // Since a tome has BattleStats, it can be equipped. There is nothing to unequip. hero.BStats.Equip((item as InvEqItem).BStats); // If max hp or mp changed, increase current by a similar amount if (item.Subtype == InvSubtype.Health) { hero.TakeDamage(-(item as InvEqItem).BStats.BaseHPMax); } if (item.Subtype == InvSubtype.Mana) { hero.TakeDamage(-(item as InvEqItem).BStats.BaseMPMax); } break; } // Remove the used item from the party inventory partyStash.RemoveInvItem(item.Name, 1); // Refresh the grid, since index for each item may have changed. PopulateGrid(); }