shiremct

X2Effect_WOTC_APA_Class_BonusDamage

Jan 15th, 2021
823
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. class X2Effect_WOTC_APA_Class_BonusDamage extends X2Effect_Persistent;
  3.  
  4. var int     BonusDmg;
  5. var float   fBonusDmgMultiplier;
  6.  
  7. var int     BonusCritDmg;
  8. var float   fBonusCritDmgMultiplier;
  9.  
  10. var bool    bCritReplacesBonus;
  11.  
  12. var int     ArmorPierce;
  13.  
  14. var bool    bApplyToPrimary;
  15. var bool    bApplyToSecondary;
  16. var bool    bApplyToHeavyWeapon;
  17. var bool    bApplyToOther;
  18.  
  19. var bool    bExcludeIndirect;
  20. var bool    bOnlyIndirect;
  21.  
  22. var array<X2Condition>  BonusDamageConditions;
  23. var array<name>         ValidAbilities;
  24. var array<name>         ExcludedAbilities;
  25.  
  26.  
  27. function int GetAttackingDamageModifier(XComGameState_Effect EffectState, XComGameState_Unit Attacker, Damageable TargetDamageable, XComGameState_Ability AbilityState, const out EffectAppliedData AppliedData, const int CurrentDamage, optional XComGameState NewGameState)
  28. {
  29.     local XComGameState_Item                SlotItem;
  30.     local bool                              bSourceIsSlotItem;
  31.     local X2Effect_ApplyWeaponDamage        DamageEffect;
  32.     local X2AbilityToHitCalc_StandardAim    StandardHit;
  33.     local float                             fBonusDamage;
  34.  
  35.     // Do not apply to actions dealing no damage
  36.     if (!class'XComGameStateContext_Ability'.static.IsHitResultHit(AppliedData.AbilityResultContext.HitResult) || CurrentDamage == 0)
  37.         return 0;
  38.  
  39.     // Only apply when the damage effect is applying the weapon's base damage
  40.     if (NewGameState != none)
  41.     {
  42.         DamageEffect = X2Effect_ApplyWeaponDamage(class'X2Effect'.static.GetX2Effect(AppliedData.EffectRef));
  43.         if (DamageEffect == none || DamageEffect.bIgnoreBaseDamage)
  44.         {
  45.             return 0;
  46.     }   }
  47.  
  48.     // Check Valid Abilities
  49.     if (ValidAbilities.Length > 0)
  50.     {
  51.         if (ValidAbilities.Find(AbilityState.GetMyTemplateName()) == Index_None)
  52.             return 0;
  53.     }
  54.  
  55.     // Check Excluded Abilities
  56.     if (ExcludedAbilities.Length > 0)
  57.     {
  58.         if (ExcludedAbilities.Find(AbilityState.GetMyTemplateName()) != Index_None)
  59.             return 0;
  60.     }
  61.  
  62.     // Check Primary Weapon
  63.     SlotItem = Attacker.GetItemInSlot(eInvSlot_PrimaryWeapon);
  64.     if (AbilityState.SourceWeapon == SlotItem.GetReference())
  65.     {
  66.         bSourceIsSlotItem = true;
  67.         if (!bApplyToPrimary)
  68.         {
  69.             return 0;
  70.     }   }
  71.  
  72.     // Check Secondary Weapon
  73.     SlotItem = Attacker.GetItemInSlot(eInvSlot_SecondaryWeapon);
  74.     if (AbilityState.SourceWeapon == SlotItem.GetReference())
  75.     {
  76.         bSourceIsSlotItem = true;
  77.         if (!bApplyToSecondary)
  78.         {
  79.             return 0;
  80.     }   }
  81.  
  82.     // Check Heavy Weapon
  83.     SlotItem = Attacker.GetItemInSlot(eInvSlot_HeavyWeapon);
  84.     if (AbilityState.SourceWeapon == SlotItem.GetReference())
  85.     {
  86.         bSourceIsSlotItem = true;
  87.         if (!bApplyToHeavyWeapon)
  88.         {
  89.             return 0;
  90.     }   }
  91.  
  92.     // Check Other Items
  93.     if (!bSourceIsSlotItem && !bApplyToOther)
  94.         return 0;
  95.  
  96.     // Check for Indirect Attacks
  97.     StandardHit = X2AbilityToHitCalc_StandardAim(AbilityState.GetMyTemplate().AbilityToHitCalc);
  98.     if (bExcludeIndirect && StandardHit.bIndirectFire)
  99.         return 0;
  100.  
  101.     if (bOnlyIndirect && !StandardHit.bIndirectFire)
  102.         return 0;
  103.  
  104.     // Evaluate any conditions
  105.     if (!ValidateConditions(Attacker, XComGameState_BaseObject(TargetDamageable), AbilityState))
  106.         return 0;
  107.  
  108.  
  109.     if (BonusDmg != 0 || fBonusDmgMultiplier != 0)
  110.     {
  111.         if (AppliedData.AbilityResultContext.HitResult != eHit_Crit || !bCritReplacesBonus)
  112.         {
  113.             if (fBonusDmgMultiplier != 0)
  114.                 fBonusDamage = CurrentDamage * (fBonusDmgMultiplier - 1);
  115.  
  116.             if (BonusDmg != 0)
  117.                 fBonusDamage += BonusDmg;
  118.     }   }
  119.  
  120.     if (BonusCritDmg != 0 || fBonusCritDmgMultiplier != 0)
  121.     {
  122.         if (AppliedData.AbilityResultContext.HitResult == eHit_Crit)
  123.         {
  124.             if (fBonusCritDmgMultiplier != 0)
  125.             {
  126.                 if (fBonusDamage == 0)
  127.                 {
  128.                     fBonusDamage = CurrentDamage;
  129.                 }
  130.  
  131.                 if (fBonusCritDmgMultiplier >= 1)
  132.                 {
  133.                     fBonusDamage = CurrentDamage * (fBonusCritDmgMultiplier - 1);
  134.                 }
  135.                 else
  136.                 {
  137.                     fBonusDamage = CurrentDamage * (1 - fBonusCritDmgMultiplier);
  138.                 }
  139.             }
  140.  
  141.             if (BonusCritDmg != 0)
  142.                 fBonusDamage += BonusCritDmg;
  143.     }   }
  144.  
  145.     return round(fBonusDamage);
  146. }
  147.  
  148.  
  149. function int GetExtraArmorPiercing(XComGameState_Effect EffectState, XComGameState_Unit Attacker, Damageable TargetDamageable, XComGameState_Ability AbilityState, const out EffectAppliedData AppliedData)
  150. {
  151.     local XComGameState_Item                SlotItem;
  152.     local bool                              bSourceIsSlotItem;
  153.     local X2Effect_ApplyWeaponDamage        DamageEffect;
  154.     local X2AbilityToHitCalc_StandardAim    StandardHit;
  155.  
  156.     // Exit if no ArmorPierce set
  157.     if (ArmorPierce == 0)
  158.         return 0;
  159.    
  160.     // Only apply when the damage effect is applying the weapon's base damage
  161.     DamageEffect = X2Effect_ApplyWeaponDamage(class'X2Effect'.static.GetX2Effect(AppliedData.EffectRef));
  162.     if (DamageEffect == none || DamageEffect.bIgnoreBaseDamage)
  163.         return 0;
  164.  
  165.     // Check Valid Abilities
  166.     if (ValidAbilities.Length > 0)
  167.     {
  168.         if (ValidAbilities.Find(AbilityState.GetMyTemplateName()) == Index_None)
  169.             return 0;
  170.     }
  171.  
  172.     // Check Excluded Abilities
  173.     if (ExcludedAbilities.Length > 0)
  174.     {
  175.         if (ExcludedAbilities.Find(AbilityState.GetMyTemplateName()) != Index_None)
  176.             return 0;
  177.     }
  178.  
  179.     // Check Primary Weapon
  180.     SlotItem = Attacker.GetItemInSlot(eInvSlot_PrimaryWeapon);
  181.     if (AbilityState.SourceWeapon == SlotItem.GetReference())
  182.     {
  183.         bSourceIsSlotItem = true;
  184.         if (!bApplyToPrimary)
  185.         {
  186.             return 0;
  187.     }   }
  188.  
  189.     // Check Secondary Weapon
  190.     SlotItem = Attacker.GetItemInSlot(eInvSlot_SecondaryWeapon);
  191.     if (AbilityState.SourceWeapon == SlotItem.GetReference())
  192.     {
  193.         bSourceIsSlotItem = true;
  194.         if (!bApplyToSecondary)
  195.         {
  196.             return 0;
  197.     }   }
  198.  
  199.     // Check Heavy Weapon
  200.     SlotItem = Attacker.GetItemInSlot(eInvSlot_HeavyWeapon);
  201.     if (AbilityState.SourceWeapon == SlotItem.GetReference())
  202.     {
  203.         bSourceIsSlotItem = true;
  204.         if (!bApplyToHeavyWeapon)
  205.         {
  206.             return 0;
  207.     }   }
  208.  
  209.     // Check Other Items
  210.     if (!bSourceIsSlotItem && !bApplyToOther)
  211.         return 0;
  212.  
  213.     // Check for Indirect Attacks
  214.     StandardHit = X2AbilityToHitCalc_StandardAim(AbilityState.GetMyTemplate().AbilityToHitCalc);
  215.     if (bExcludeIndirect && StandardHit.bIndirectFire)
  216.         return 0;
  217.  
  218.     if (bOnlyIndirect && !StandardHit.bIndirectFire)
  219.         return 0;
  220.  
  221.     // Evaluate any conditions
  222.     if (!ValidateConditions(Attacker, XComGameState_BaseObject(TargetDamageable), AbilityState))
  223.         return 0;
  224.  
  225.     return ArmorPierce;
  226. }
  227.  
  228.  
  229. private function bool ValidateConditions(XComGameState_Unit Attacker, XComGameState_BaseObject TargetObject, XComGameState_Ability AbilityState)
  230. {
  231.     local int   Index;
  232.     local name  AvailableCode;
  233.  
  234.     if (BonusDamageConditions.Length > 0)
  235.     {
  236.         for (Index = 0; Index < BonusDamageConditions.Length; ++Index)
  237.         {
  238.             AvailableCode = BonusDamageConditions[Index].MeetsCondition(TargetObject);
  239.             if (AvailableCode != 'AA_Success')
  240.                 return false;
  241.  
  242.             AvailableCode = BonusDamageConditions[Index].MeetsConditionWithSource(TargetObject, Attacker);
  243.             if (AvailableCode != 'AA_Success')
  244.                 return false;
  245.  
  246.             AvailableCode = BonusDamageConditions[Index].AbilityMeetsCondition(AbilityState, TargetObject);
  247.             if (AvailableCode != 'AA_Success')
  248.                 return false;
  249.     }   }
  250.  
  251.     return true;
  252. }
  253.  
  254.  
  255.  
  256. defaultproperties
  257. {
  258.     bApplyToPrimary = true
  259.     bDisplayInSpecialDamageMessageUI = true
  260. }
RAW Paste Data