protected override void OnCalculate(InteractionParamHolder damageInfo, InteractionResult curResult, ContactResultInfo curContactResult) { Elements element = StepResult.VictimResult.DamageElement; BattleEntity victim = StepResult.VictimResult.Entity; //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 = StepResult.AttackerResult.Entity.EntityProperties.GetTotalElementOverride(victim); if (newElement.Element != Elements.Invalid) { /*NOTE: Idea for stacking weaknesses * (Ex. 1 Ice Power is 1 weakness, Ice Power + Ice Smash = 2 weaknesses) * * Ex. damage = 2 * player inflicts ice 2 times: ice power & ice smash * * ice_inflicted_times = 2 * if (enemy weak to ice) * damage += ice_inflicted_times * end * #damage = 4 */ //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) { StepResult.VictimResult.TotalDamage += newElement.OverrideCount; } StepResult.VictimResult.DamageElement = newElement.Element; } }
public static void ElementOverrideInteractionUT1() { BattleMario mario = new BattleMario(new MarioStats(1, 5, 50, 0, 0, EquipmentGlobals.BootLevels.Normal, EquipmentGlobals.HammerLevels.Normal)); Goomba goomba = new Goomba(); IcePowerBadge icePower = new IcePowerBadge(); icePower.Equip(mario); IcePowerBadge icePower2 = new IcePowerBadge(); icePower2.Equip(mario); goomba.EntityProperties.AddPhysAttribute(Enumerations.PhysicalAttributes.Fiery); goomba.EntityProperties.AddWeakness(Enumerations.Elements.Ice, new WeaknessHolder(WeaknessTypes.PlusDamage, 1)); Debug.Assert(goomba.EntityProperties.HasPhysAttributes(true, Enumerations.PhysicalAttributes.Fiery)); Debug.Assert(goomba.EntityProperties.HasWeakness(Enumerations.Elements.Ice)); ElementOverrideHolder overrideHolder = mario.EntityProperties.GetTotalElementOverride(goomba); Debug.Assert(overrideHolder.Element == Enumerations.Elements.Ice); Debug.Assert(overrideHolder.OverrideCount == 2); InteractionParamHolder param = new InteractionParamHolder(mario, goomba, 1, Enumerations.Elements.Ice, true, Enumerations.ContactTypes.TopDirect, null, Enumerations.DamageEffects.None, false, Enumerations.DefensiveMoveOverrides.None); InteractionResult interaction = Interactions.GetDamageInteraction(param); Debug.Assert(interaction.VictimResult.TotalDamage == 4); PrintInteractionResult(interaction); icePower.UnEquip(); icePower2.UnEquip(); ElementOverrideHolder overrideHolder2 = mario.EntityProperties.GetTotalElementOverride(goomba); Debug.Assert(overrideHolder2.Element == Enumerations.Elements.Invalid); }
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); }