Advertisement
Guest User

Untitled

a guest
Jan 4th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Grimy_AbilityCost_Reload extends X2AbilityCost_ActionPoints;
  2.  
  3. var name BonusType;
  4. var name BonusPassive;
  5.  
  6. simulated function name CanAfford(XComGameState_Ability kAbility, XComGameState_Unit ActivatingUnit)
  7. {
  8.     local XComGameState_Unit kUnit;
  9.     local name Availability;
  10.     local int i, PointCheck, PointSum;
  11.    
  12.     kUnit = ActivatingUnit;
  13.     `assert(kUnit != none);
  14.  
  15.     Availability = 'AA_CannotAfford_ActionPoints';
  16.        
  17.     PointCheck = GetPointCost(kAbility, kUnit);
  18.     PointSum = 0;
  19.     for (i = 0; i < AllowedTypes.Length; ++i)
  20.     {
  21.         PointSum += kUnit.NumActionPoints(AllowedTypes[i]);
  22.     }
  23.     if ( kUnit.FindAbility(BonusPassive).ObjectID > 0 ) {
  24.         PointSum += kUnit.NumActionPoints(BonusType);
  25.     }
  26.  
  27.     if( PointSum >= PointCheck )
  28.     {
  29.         Availability = 'AA_Success';
  30.     }
  31.  
  32.     return Availability;
  33. }
  34.  
  35. simulated function ApplyCost(XComGameStateContext_Ability AbilityContext, XComGameState_Ability kAbility, XComGameState_BaseObject AffectState, XComGameState_Item AffectWeapon, XComGameState NewGameState)
  36. {
  37.     local XComGameState_Unit ModifiedUnitState;
  38.     local int i, j, iPointsConsumed, iPointsToTake, PathIndex, FarthestTile;
  39.     local array<name> TempTypes;
  40.  
  41.     ModifiedUnitState = XComGameState_Unit(AffectState);
  42.  
  43.     TempTypes = AllowedTypes;
  44.     if ( ModifiedUnitState.FindAbility(BonusPassive).ObjectID > 0 ) {
  45.         TempTypes.AddItem(BonusType);
  46.     }
  47.  
  48.     if (bFreeCost || ModifiedUnitState.GetMyTemplate().bIsCosmetic || (`CHEATMGR != none && `CHEATMGR.bUnlimitedActions))
  49.         return;
  50.  
  51.     //Deduct the appropriate number of action points
  52.     if( ConsumeAllPoints(kAbility, ModifiedUnitState) )
  53.     {
  54.         iPointsConsumed = ModifiedUnitState.NumAllActionPoints();
  55.         ModifiedUnitState.ActionPoints.Length = 0;     
  56.     }
  57.     else
  58.     {
  59.         AbilityContext.PostBuildVisualizationFn.AddItem(kAbility.DidNotConsumeAll_PostBuildVisualization);
  60.  
  61.         if (bMoveCost)
  62.         {
  63.             PathIndex = AbilityContext.GetMovePathIndex(ModifiedUnitState.ObjectID);
  64.             iPointsToTake = 1;
  65.            
  66.             for(i = AbilityContext.InputContext.MovementPaths[PathIndex].MovementTiles.Length - 1; i >= 0; --i)
  67.             {
  68.                 if(AbilityContext.InputContext.MovementPaths[PathIndex].MovementTiles[i] == ModifiedUnitState.TileLocation)
  69.                 {
  70.                     FarthestTile = i;
  71.                     break;
  72.                 }
  73.             }
  74.             for (i = 0; i < AbilityContext.InputContext.MovementPaths[PathIndex].CostIncreases.Length; ++i)
  75.             {
  76.                 if (AbilityContext.InputContext.MovementPaths[PathIndex].CostIncreases[i] <= FarthestTile)
  77.                     iPointsToTake++;
  78.             }
  79.         }
  80.         else
  81.         {
  82.             iPointsToTake = GetPointCost(kAbility, ModifiedUnitState);
  83.         }
  84.         //  Assume that AllowedTypes is built with the most specific point types at the end, which we should
  85.         //  consume before more general types. e.g. Consume "reflex" if that is allowed before "standard" if that is also allowed.
  86.         //  If this isn't good enough we may want to provide a specific way of ordering the priority for action point consumption.
  87.         for (i = TempTypes.Length - 1; i >= 0 && iPointsConsumed < iPointsToTake; --i)
  88.         {
  89.             for (j = ModifiedUnitState.ActionPoints.Length - 1; j >= 0 && iPointsConsumed < iPointsToTake; --j)
  90.             {
  91.                 if (ModifiedUnitState.ActionPoints[j] == TempTypes[i])
  92.                 {
  93.                     ModifiedUnitState.ActionPoints.Remove(j, 1);
  94.                     iPointsConsumed++;
  95.                 }
  96.             }
  97.         }
  98.     }
  99. }
  100.  
  101. simulated function bool ConsumeAllPoints(XComGameState_Ability AbilityState, XComGameState_Unit AbilityOwner)
  102. {
  103.     local int i;
  104.     local bool bConsumeAll;
  105.  
  106.     bConsumeAll = bConsumeAllPoints;
  107.     if ( AbilityOwner.FindAbility(BonusPassive).ObjectID > 0 ) {
  108.         bConsumeAll = false;
  109.     }
  110.  
  111.     if ( bConsumeAll )
  112.     {
  113.         for (i = 0; i < DoNotConsumeAllEffects.Length; ++i)
  114.         {
  115.             if (AbilityOwner.IsUnitAffectedByEffectName(DoNotConsumeAllEffects[i]))
  116.                 return false;
  117.         }
  118.         for (i = 0; i < DoNotConsumeAllSoldierAbilities.Length; ++i)
  119.         {
  120.             if (AbilityOwner.HasSoldierAbility(DoNotConsumeAllSoldierAbilities[i]))
  121.                 return false;
  122.         }
  123.     }
  124.  
  125.     return bConsumeAll;
  126. }
  127.  
  128. DefaultProperties
  129. {
  130.     iNumPoints=1
  131.     bConsumeAllPoints = false
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement