Advertisement
shiremct

Reaper Conditional Stats Bonus Effect

Sep 22nd, 2019
1,799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class X2Effect_WOTC_APA_ShadowConditionalBonuses extends X2Effect_PersistentStatChange;
  2.  
  3.  
  4. function RegisterForEvents(XComGameState_Effect EffectGameState)
  5. {
  6.     local XComGameState_Unit UnitState;
  7.     local X2EventManager EventMgr;
  8.     local Object ListenerObj;
  9.  
  10.     EventMgr = `XEVENTMGR;
  11.  
  12.     UnitState = XComGameState_Unit(`XCOMHISTORY.GetGameStateForObjectID(EffectGameState.ApplyEffectParameters.TargetStateObjectRef.ObjectID));
  13.  
  14.     ListenerObj = EffectGameState;
  15.  
  16.     // Register to tick after EVERY action.
  17.     EventMgr.RegisterForEvent(ListenerObj, 'AbilityActivated', UpdateEffects, ELD_OnStateSubmitted, 20, UnitState,, EffectGameState);
  18.     EventMgr.RegisterForEvent(ListenerObj, 'WOTC_APA_IncrementShadowTick', UpdateEffects, ELD_OnStateSubmitted, 20, UnitState,, EffectGameState);
  19.     EventMgr.RegisterForEvent(ListenerObj, 'UnitConcealmentEntered', UpdateEffects, ELD_OnStateSubmitted, 20, UnitState,, EffectGameState);
  20.     EventMgr.RegisterForEvent(ListenerObj, 'UnitConcealmentBroken', RemoveEffects, ELD_OnStateSubmitted, 20, UnitState,, EffectGameState);
  21. }
  22.  
  23.  
  24. static function EventListenerReturn UpdateEffects(Object EventData, Object EventSource, XComGameState GameState, Name EventID, Object CallbackData)
  25. {
  26.     local XComGameState_Unit            UnitState, PreviousUnitState, NewUnitState;
  27.     local XComGameState_Effect          EffectState, NewEffectState;
  28.     local XComGameState                 NewGameState;
  29.     local StatChange                    NewStatChange;
  30.     local UnitValue                     ShadowStacksValue, PreviousShadowStacksValue;
  31.     local int                           iValue;
  32.  
  33.     EffectState = XComGameState_Effect(CallbackData);
  34.     if (EffectState == none)
  35.         return ELR_NoInterrupt;
  36.  
  37.     UnitState = XComGameState_Unit(`XCOMHISTORY.GetGameStateForObjectID(EffectState.ApplyEffectParameters.TargetStateObjectRef.ObjectID));
  38.  
  39.     if (!UnitState.IsConcealed())
  40.         return ELR_NoInterrupt;
  41.  
  42.     PreviousUnitState = XComGameState_Unit(`XCOMHISTORY.GetPreviousGameStateForObject(UnitState));
  43.     UnitState.GetUnitValue(class'X2Ability_WOTC_APA_ReaperAbilitySet'.default.SHADOW_STACK_CURRENT_NAME, ShadowStacksValue);
  44.     PreviousUnitState.GetUnitValue(class'X2Ability_WOTC_APA_ReaperAbilitySet'.default.SHADOW_STACK_CURRENT_NAME, PreviousShadowStacksValue);
  45.    
  46.     if (ShadowStacksValue.fValue == PreviousShadowStacksValue.fValue)
  47.         return ELR_NoInterrupt;
  48.  
  49.     NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Conditional Stat Change");
  50.     NewUnitState = XComGameState_Unit(NewGameState.ModifyStateObject(class'XComGameState_Unit', UnitState.ObjectID));
  51.     NewUnitState.UnApplyEffectFromStats(EffectState, NewGameState);
  52.  
  53.     EffectState.StatChanges.Length = 0;
  54.     NewEffectState = XComGameState_Effect(NewGameState.ModifyStateObject(class'XComGameState_Effect', EffectState.ObjectID));
  55.     NewStatChange.StatType = eStat_DetectionModifier;
  56.     NewStatChange.StatAmount = (ShadowStacksValue.fValue * class'X2Ability_WOTC_APA_ReaperAbilitySet'.default.SHADOW_STACK_DETECTION_BONUS);
  57.     NewStatChange.ModOp = MODOP_Addition;
  58.     NewEffectState.StatChanges.AddItem(NewStatChange);
  59.  
  60.     if (UnitState.AffectedByEffectNames.Find('WOTC_APA_Hound') != -1)
  61.     {
  62.         if (ShadowStacksValue.fValue >= class'X2Ability_WOTC_APA_ReaperAbilitySet'.default.SHADOW_VALUE_THRESHOLD_I)
  63.             iValue = class'X2Ability_WOTC_APA_ReaperAbilitySet'.default.HOUND_MOBILITY_BONUS_I;
  64.  
  65.         if (ShadowStacksValue.fValue >= class'X2Ability_WOTC_APA_ReaperAbilitySet'.default.SHADOW_VALUE_THRESHOLD_II)
  66.             iValue = class'X2Ability_WOTC_APA_ReaperAbilitySet'.default.HOUND_MOBILITY_BONUS_II;
  67.  
  68.         if (ShadowStacksValue.fValue >= class'X2Ability_WOTC_APA_ReaperAbilitySet'.default.SHADOW_VALUE_THRESHOLD_III)
  69.             iValue = class'X2Ability_WOTC_APA_ReaperAbilitySet'.default.HOUND_MOBILITY_BONUS_III;
  70.  
  71.         NewStatChange.StatType = eStat_Mobility;
  72.         NewStatChange.StatAmount = iValue;
  73.         NewStatChange.ModOp = MODOP_Addition;
  74.         NewEffectState.StatChanges.AddItem(NewStatChange);
  75.     }
  76.  
  77.     NewUnitState.ApplyEffectToStats(NewEffectState, NewGameState);
  78.     `GAMERULES.SubmitGameState(NewGameState);
  79.    
  80.     return ELR_NoInterrupt;
  81. }
  82.  
  83.  
  84. static function EventListenerReturn RemoveEffects(Object EventData, Object EventSource, XComGameState GameState, Name EventID, Object CallbackData)
  85. {
  86.     local XComGameState_Unit            UnitState, NewUnitState;
  87.     local XComGameState_Effect          EffectState, NewEffectState;
  88.     local XComGameState                 NewGameState;
  89.  
  90.     EffectState = XComGameState_Effect(CallbackData);
  91.     if (EffectState == none)
  92.         return ELR_NoInterrupt;
  93.        
  94.     UnitState = XComGameState_Unit(`XCOMHISTORY.GetGameStateForObjectID(EffectState.ApplyEffectParameters.TargetStateObjectRef.ObjectID));
  95.     NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Conditional Stat Change");
  96.     NewUnitState = XComGameState_Unit(NewGameState.ModifyStateObject(class'XComGameState_Unit', UnitState.ObjectID));
  97.    
  98.     NewUnitState.UnApplyEffectFromStats(EffectState, NewGameState);
  99.     `GAMERULES.SubmitGameState(NewGameState);
  100.    
  101.     return ELR_NoInterrupt;
  102. }
  103.  
  104.  
  105. function GetToHitModifiers(XComGameState_Effect EffectState, XComGameState_Unit Attacker, XComGameState_Unit Target, XComGameState_Ability AbilityState, class<X2AbilityToHitCalc> ToHitType, bool bMelee, bool bFlanking, bool bIndirectFire, out array<ShotModifierInfo> ShotModifiers)
  106. {
  107.     local XComGameState_Item    SourceWeapon;
  108.     local ShotModifierInfo      ShotInfo;
  109.     local UnitValue             ShadowStacksValue;
  110.     local int                   BonusAmount;
  111.  
  112.     if (Target.IsImpaired(false) || Target.IsBurning() || Target.IsPanicked())
  113.         return;
  114.  
  115.     SourceWeapon = AbilityState.GetSourceWeapon();
  116.     if (SourceWeapon != none && !bIndirectFire)
  117.     {
  118.         Attacker.GetUnitValue(class'X2Ability_WOTC_APA_ReaperAbilitySet'.default.SHADOW_STACK_CURRENT_NAME, ShadowStacksValue);
  119.         BonusAmount = class'X2Ability_WOTC_APA_ReaperAbilitySet'.default.SHADOW_STACK_CRIT_CHANCE_BONUS * ShadowStacksValue.fValue;
  120.  
  121.         if (BonusAmount > 0)
  122.         {
  123.             ShotInfo.ModType = eHit_Crit;
  124.             ShotInfo.Reason = FriendlyName;
  125.             ShotInfo.Value = BonusAmount;
  126.             ShotModifiers.AddItem(ShotInfo);
  127.         }
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement