protected override void OnCalculate(InteractionParamHolder damageInfo, InteractionResult curResult, ContactResultInfo curContactResult) { //The unscaled damage the Attacker dealt to the Victim //This will be the Payback damage dealt from a Defensive Action if one that deals damage has been performed int unscaledAttackerDamage = StepResult.AttackerResult.TotalDamage; int damageDealt = unscaledAttackerDamage; PaybackHolder paybackHolder = StepContactResultInfo.Paybackholder; //Get the damage done to the Attacker, factoring in Weaknesses/Resistances ElementDamageResultHolder attackerElementDamage = GetElementalDamage(StepResult.AttackerResult.Entity, paybackHolder.Element, damageDealt); //Get Payback damage - Payback damage is calculated after everything else //However, it does NOT factor in Double Pain or Last Stand, hence why we use the unscaled Victim damage int paybackDamage = paybackHolder.GetPaybackDamage(attackerElementDamage.Damage); //If Constant Payback, the constant damage value will be returned as the Payback damage //Therefore, update the final Payback damage value to factor in Weaknesses/Resistances using the constant Payback damage //Ex. This causes an enemy with a +1 Weakness to Fire to be dealt 2 damage instead of 1 for a Constant 1 Fire Payback if (paybackHolder.PaybackType == PaybackTypes.Constant) { paybackDamage = GetElementalDamage(StepResult.AttackerResult.Entity, paybackHolder.Element, paybackDamage).Damage; } //Fill out the rest of the Attacker information since we have it //Payback damage is always direct, piercing, and guaranteed to hit StepResult.AttackerResult.TotalDamage = paybackDamage; StepResult.AttackerResult.DamageElement = paybackHolder.Element; StepResult.AttackerResult.ElementResult = attackerElementDamage.InteractionResult; StepResult.AttackerResult.ContactType = ContactTypes.TopDirect; StepResult.AttackerResult.Piercing = true; StepResult.AttackerResult.StatusesInflicted = paybackHolder.StatusesInflicted; StepResult.AttackerResult.Hit = true; }
protected override void OnCalculate(InteractionParamHolder damageInfo, InteractionResult curResult, ContactResultInfo curContactResult) { ElementDamageResultHolder victimElementDamage = GetElementalDamage(StepResult.VictimResult.Entity, StepResult.VictimResult.DamageElement, StepResult.VictimResult.TotalDamage); StepResult.VictimResult.ElementResult = victimElementDamage.InteractionResult; StepResult.VictimResult.TotalDamage = victimElementDamage.Damage; }
/// <summary> /// Calculates the result of elemental damage on a BattleEntity, based on its weaknesses and resistances to that Element. /// </summary> /// <param name="victim">The BattleEntity being damaged.</param> /// <param name="element">The element the entity is attacked with.</param> /// <param name="damage">The initial damage of the attack.</param> /// <returns>An ElementDamageHolder stating the result and final damage dealt to this entity.</returns> private static ElementDamageResultHolder GetElementalDamage(BattleEntity victim, Elements element, int damage) { ElementDamageResultHolder elementDamageResult = new ElementDamageResultHolder(ElementInteractionResult.Damage, damage); //NOTE: If an entity is both resistant and weak to a particular element, they cancel out. //I decided to go with this approach because it's the simplest for this situation, which //doesn't seem desirable to begin with but could be interesting in its application WeaknessHolder weakness = victim.EntityProperties.GetWeakness(element); ResistanceHolder resistance = victim.EntityProperties.GetResistance(element); //If there's both a weakness and resistance, return if (weakness.WeaknessType != WeaknessTypes.None && resistance.ResistanceType != ResistanceTypes.None) { return(elementDamageResult); } //Handle weaknesses if (weakness.WeaknessType == WeaknessTypes.PlusDamage) { elementDamageResult.Damage += weakness.Value; } else if (weakness.WeaknessType == WeaknessTypes.KO) { elementDamageResult.InteractionResult = ElementInteractionResult.KO; } //Handle resistances if (resistance.ResistanceType == ResistanceTypes.MinusDamage) { elementDamageResult.Damage -= resistance.Value; } else if (resistance.ResistanceType == ResistanceTypes.NoDamage) { elementDamageResult.Damage = BattleGlobals.MinDamage; } else if (resistance.ResistanceType == ResistanceTypes.Heal) { elementDamageResult.InteractionResult = ElementInteractionResult.Heal; } return(elementDamageResult); }
public static InteractionResult GetDamageInteractionOld(InteractionParamHolder interactionParam) { InteractionResult finalInteractionResult = new InteractionResult(); BattleEntity attacker = interactionParam.Attacker; BattleEntity victim = interactionParam.Victim; ContactTypes contactType = interactionParam.ContactType; Elements element = interactionParam.DamagingElement; StatusChanceHolder[] statuses = interactionParam.Statuses; int damage = interactionParam.Damage; bool piercing = interactionParam.Piercing; //Get contact results ContactResultInfo contactResultInfo = victim.EntityProperties.GetContactResult(attacker, contactType); ContactResult contactResult = contactResultInfo.ContactResult; //Retrieve an overridden type of Elemental damage to inflict based on the Victim's PhysicalAttributes //(Ex. The Ice Power Badge only deals Ice damage to Fiery entities) ElementOverrideHolder newElement = attacker.EntityProperties.GetTotalElementOverride(victim); if (newElement.Element != Elements.Invalid) { //Add the number of element overrides to the damage if the element used already exists as an override and the victim has a Weakness //to the Element. This allows Badges such as Ice Power to deal more damage if used in conjunction with attacks //that deal the same type of damage (Ex. Ice Power and Ice Smash deal 2 additional damage total rather than 1). //If any new knowledge is discovered to improve this, this will be changed //Ice Power is the only Badge of its kind across the first two PM games that does anything like this if (element == newElement.Element && victim.EntityProperties.HasWeakness(element) == true) { damage += newElement.OverrideCount; } element = newElement.Element; } /*Get the total damage dealt to the Victim. The amount of Full or Half Payback damage dealt to the Attacker * uses the resulting damage value from this because Payback uses the total damage that would be dealt to the Victim. * This occurs before factoring in elemental resistances/weaknesses from the Attacker*/ ElementDamageResultHolder victimElementDamage = GetElementalDamage(victim, element, damage); int unscaledVictimDamage = victimElementDamage.Damage; //Subtract damage reduction (P-Up, D-Down and P-Down, D-Up Badges) unscaledVictimDamage -= victim.BattleStats.DamageReduction; //Check if the attack hit. If not, then don't consider defensive actions bool attackHit = interactionParam.CantMiss == true ? true : attacker.AttemptHitEntity(victim); //Defense added from Damage Dodge Badges upon a successful Guard int damageDodgeDefense = 0; //Defensive actions take priority. If the attack didn't hit, don't check for defensive actions BattleGlobals.DefensiveActionHolder?victimDefenseData = null; if (attackHit == true) { victimDefenseData = victim.GetDefensiveActionResult(unscaledVictimDamage, statuses, interactionParam.DamageEffect); } if (victimDefenseData.HasValue == true) { unscaledVictimDamage = victimDefenseData.Value.Damage; statuses = victimDefenseData.Value.Statuses; //If the Defensive action dealt damage and the contact was direct //the Defensive action has caused a Failure for the Attacker (Ex. Superguarding) if ((contactType == ContactTypes.TopDirect || contactType == ContactTypes.SideDirect) && victimDefenseData.Value.ElementHolder.HasValue == true) { contactResult = ContactResult.Failure; } //Factor in the additional Guard defense for all DefensiveActions (for now, at least) damageDodgeDefense = victim.GetEquippedBadgeCount(BadgeGlobals.BadgeTypes.DamageDodge); } //Subtract Defense on non-piercing damage if (piercing == false) { int totalDefense = victim.BattleStats.TotalDefense + damageDodgeDefense; unscaledVictimDamage -= totalDefense; } int scaledVictimDamage = unscaledVictimDamage; //Factor in Double Pain for the Victim scaledVictimDamage *= (1 + victim.GetEquippedBadgeCount(BadgeGlobals.BadgeTypes.DoublePain)); //Factor in Last Stand for the Victim, if the Victim is in Danger or Peril if (victim.IsInDanger == true) { //PM rounds down, whereas TTYD rounds up. We're going with the latter //TTYD always ceilings the value (Ex. 3.2 turns to 4) int lastStandDivider = (1 + victim.GetEquippedBadgeCount(BadgeGlobals.BadgeTypes.LastStand)); scaledVictimDamage = (int)Math.Ceiling(scaledVictimDamage / (float)lastStandDivider); } /*If the Victim is Invincible, ignore all damage and Status Effects * If the Attacker is Invincible, ignore all Payback damage and Status Effects * * It won't ignore the Payback's effects automatically; that has to be done manually by adding * contact exceptions or something else*/ //Clamp Victim damage scaledVictimDamage = UtilityGlobals.Clamp(scaledVictimDamage, BattleGlobals.MinDamage, BattleGlobals.MaxDamage); #region Victim Damage Dealt //Calculating damage dealt to the Victim if (contactResult == ContactResult.Success || contactResult == ContactResult.PartialSuccess) { //Get the Status Effects to inflict on the Victim StatusChanceHolder[] victimInflictedStatuses = GetFilteredInflictedStatuses(victim, statuses); //Check if the Victim is Invincible. If so, ignore all damage and Status Effects if (victim.EntityProperties.GetAdditionalProperty <bool>(AdditionalProperty.Invincible) == true) { scaledVictimDamage = 0; victimElementDamage.InteractionResult = ElementInteractionResult.Damage; victimInflictedStatuses = null; } finalInteractionResult.VictimResult = new InteractionHolder(victim, scaledVictimDamage, element, victimElementDamage.InteractionResult, contactType, piercing, victimInflictedStatuses, attackHit, DamageEffects.None); } #endregion #region Attacker Damage Dealt //Calculating damage dealt to the Attacker if (contactResult == ContactResult.Failure || contactResult == ContactResult.PartialSuccess) { //The damage the Attacker dealt to the Victim int damageDealt = unscaledVictimDamage; PaybackHolder paybackHolder = contactResultInfo.Paybackholder; //Override the PaybackHolder with a Defensive Action's results, if any if (victimDefenseData.HasValue == true && victimDefenseData.Value.ElementHolder.HasValue == true) { damageDealt = victimDefenseData.Value.ElementHolder.Value.Damage; paybackHolder = new PaybackHolder(PaybackTypes.Constant, victimDefenseData.Value.ElementHolder.Value.Element, damageDealt); } //Get the damage done to the Attacker, factoring in Weaknesses/Resistances ElementDamageResultHolder attackerElementDamage = GetElementalDamage(attacker, paybackHolder.Element, damageDealt); //Get Payback damage - Payback damage is calculated after everything else, including Constant Payback. //However, it does NOT factor in Double Pain or any sort of Defense modifiers. int paybackDamage = paybackHolder.GetPaybackDamage(attackerElementDamage.Damage); //If Constant Payback, update the damage value to use the element if (paybackHolder.PaybackType == PaybackTypes.Constant) { paybackDamage = GetElementalDamage(attacker, paybackHolder.Element, paybackDamage).Damage; } //Clamp Attacker damage attackerElementDamage.Damage = UtilityGlobals.Clamp(paybackDamage, BattleGlobals.MinDamage, BattleGlobals.MaxDamage); //Get the Status Effects to inflict StatusChanceHolder[] attackerInflictedStatuses = GetFilteredInflictedStatuses(attacker, paybackHolder.StatusesInflicted); //Check if the Attacker is Invincible. If so, ignore all damage and Status Effects if (attacker.EntityProperties.GetAdditionalProperty <bool>(AdditionalProperty.Invincible) == true) { attackerElementDamage.Damage = 0; attackerElementDamage.InteractionResult = ElementInteractionResult.Damage; attackerInflictedStatuses = null; } finalInteractionResult.AttackerResult = new InteractionHolder(attacker, attackerElementDamage.Damage, paybackHolder.Element, attackerElementDamage.InteractionResult, ContactTypes.None, true, attackerInflictedStatuses, true, DamageEffects.None); } #endregion return(finalInteractionResult); }