Guest User

Untitled

a guest
Feb 27th, 2016
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.82 KB | None | 0 0
  1. class X2Effect_ApplyWeaponDamage_CoverDR extends X2Effect_ApplyWeaponDamage;
  2.  
  3. simulated protected function OnEffectAdded(const out EffectAppliedData ApplyEffectParameters, XComGameState_BaseObject kNewTargetState, XComGameState NewGameState, XComGameState_Effect NewEffectState)
  4. {
  5. local Damageable kNewTargetDamageableState;
  6. local int iDamage, iMitigated, NewRupture, NewShred, TotalToKill;
  7. local XComGameState_Unit TargetUnit;
  8. local XComGameState_Item SourceWeapon;
  9. local array<X2WeaponUpgradeTemplate> WeaponUpgradeTemplates;
  10. local X2WeaponUpgradeTemplate WeaponUpgradeTemplate;
  11. local array<Name> AppliedDamageTypes;
  12. local int bAmmoBypassesShields;
  13. local bool bDoesDamageIgnoreShields;
  14.  
  15. local XComGameState_Unit Shooter;
  16. local XComGameState_Ability Ability;
  17. local XComGameStateHistory History;
  18. local GameRulesCache_VisibilityInfo VisInfo;
  19. local XComGameState_Unit FakeUnitForBlastLocation;
  20.  
  21. local Vector HitLocation;
  22. local int HitLocationCount, HitLocationIndex;
  23. local array<vector> HitLocationsArray;
  24. local float AbilityRadius, Distance;
  25. local TTile BlastLocationTile;
  26. local XComGameStateContext_Ability AbilityContext;
  27.  
  28. kNewTargetDamageableState = Damageable(kNewTargetState);
  29. if( kNewTargetDamageableState != none )
  30. {
  31. AppliedDamageTypes = DamageTypes;
  32. iDamage = CalculateDamageAmount(ApplyEffectParameters, iMitigated, NewRupture, NewShred, AppliedDamageTypes, bAmmoBypassesShields);
  33. bDoesDamageIgnoreShields = (bAmmoBypassesShields > 0) || bBypassShields;
  34.  
  35.  
  36. //CoverDR Modifications
  37. Ability = XComGameState_Ability(NewGameState.GetGameStateForObjectID(ApplyEffectParameters.AbilityStateObjectRef.ObjectID));
  38. History = `XCOMHISTORY;
  39. Shooter = XComGameState_Unit(History.GetGameStateForObjectID( Ability.OwnerStateObject.ObjectID ));
  40. TargetUnit = XComGameState_Unit(kNewTargetState);
  41. SourceWeapon = Ability.GetSourceWeapon();
  42. AbilityContext = XComGameStateContext_Ability(NewGameState.GetContext());
  43.  
  44. //Find blast center to determine if cover from nade
  45. HitLocationsArray = AbilityContext.InputContext.TargetLocations;
  46. HitLocationCount = HitLocationsArray.Length;
  47.  
  48. //For now just using last hit location, better to find centerpoint or divide damage by number of points and do cover calc in each
  49. for( HitLocationIndex = 0; HitLocationIndex < HitLocationCount; ++HitLocationIndex )
  50. {
  51. HitLocation = HitLocationsArray[HitLocationIndex];
  52. }
  53.  
  54. BlastLocationTile = `XWORLD.GetTileCoordinatesFromPosition(HitLocation);
  55. FakeUnitForBlastLocation.SetVisibilityLocation(BlastLocationTile);
  56.  
  57. `Log("Ability:"@Ability@ "Shooter"@Shooter@"TargetUnit"@TargetUnit@"SourceWeapon:"@SourceWeapon@"HitLocation"@HitLocation@"FakeHitlocationUnitTile:"@FakeUnitForBlastLocation.TileLocation.x@" "@FakeUnitForBlastLocation.TileLocation.y@" "@FakeUnitForBlastLocation.TileLocation.z@"Shooter Tile"@Shooter.TileLocation.x@" "@Shooter.TileLocation.y@" "@Shooter.TileLocation.z@"Target Tile"@TargetUnit.TileLocation.x@" "@TargetUnit.TileLocation.y@" "@TargetUnit.TileLocation.z@"Blast Location Tile"@BlastLocationTile.x@" "@BlastLocationTile.y@" "@BlastLocationTile.z);
  58. //if nade, or if blast location tile != target location to test for indirect weapons?
  59. FakeUnitForBlastLocation = XComGameState_Unit(History.GetGameStateForObjectID( Shooter.ObjectID ));
  60. FakeUnitForBlastLocation.SetVisibilityLocation(BlastLocationTile);
  61.  
  62. `Log("Ability:"@Ability@ "Shooter"@Shooter@"TargetUnit"@TargetUnit@"SourceWeapon:"@SourceWeapon@"HitLocation"@HitLocation@"FakeHitlocationUnitTile:"@FakeUnitForBlastLocation.TileLocation.x@" "@FakeUnitForBlastLocation.TileLocation.y@" "@FakeUnitForBlastLocation.TileLocation.z@"Shooter Tile"@Shooter.TileLocation.x@" "@Shooter.TileLocation.y@" "@Shooter.TileLocation.z@"Target Tile"@TargetUnit.TileLocation.x@" "@TargetUnit.TileLocation.y@" "@TargetUnit.TileLocation.z@"Blast Location Tile"@BlastLocationTile.x@" "@BlastLocationTile.y@" "@BlastLocationTile.z);
  63. //After calling SetVisibilityLocation it seems to be changing the location, but GetVisibilityInfo is still treating cover as if it was the shooters position...
  64.  
  65. // Skip units that dont take cover, like sectopods
  66. if (TargetUnit.CanTakeCover())
  67. {
  68. // Populate visInfo, and make sure the target is in line-of-sight of the shooter
  69. // if (`TACTICALRULES.VisibilityMgr.GetVisibilityInfo(Shooter.ObjectID, TargetUnit.ObjectID, VisInfo))
  70.  
  71. if (`TACTICALRULES.VisibilityMgr.GetVisibilityInfo(FakeUnitForBlastLocation.ObjectID, TargetUnit.ObjectID, VisInfo))
  72. {
  73. // Switch based on cover type
  74. switch( VisInfo.TargetCover )
  75. {
  76. case CT_MidLevel: // half cover
  77.  
  78. iDamage -= 5;
  79. iMitigated = 5; // Damage lowered by 1 if target in half cover
  80.  
  81. break;
  82. case CT_Standing: // full cover
  83.  
  84. iDamage -= 8;
  85. iMitigated = 5; // Damage lowered by 2 if target in half cover
  86.  
  87. break;
  88. default:
  89.  
  90. // if you want something to happen on nocover put it here
  91.  
  92. break;
  93. }
  94. }
  95. }
  96.  
  97. // Damage cannot be lower than 1, this is consistent with how armor works in game
  98. if(iDamage <= 0) iDamage = 1;
  99.  
  100.  
  101.  
  102. if ((iDamage == 0) && (iMitigated == 0) && (NewRupture == 0) && (NewShred == 0))
  103. {
  104. // No damage is being dealt
  105. return;
  106. }
  107.  
  108. if (bAllowFreeKill)
  109. {
  110. // check to see if the damage ought to kill them and if not, roll for a free kill
  111. TargetUnit = XComGameState_Unit(kNewTargetState);
  112. if (TargetUnit != none)
  113. {
  114. TotalToKill = TargetUnit.GetCurrentStat(eStat_HP) + TargetUnit.GetCurrentStat(eStat_ShieldHP);
  115. if (TotalToKill > iDamage)
  116. {
  117. SourceWeapon = XComGameState_Item(`XCOMHISTORY.GetGameStateForObjectID(ApplyEffectParameters.ItemStateObjectRef.ObjectID));
  118. if (SourceWeapon != none)
  119. {
  120. WeaponUpgradeTemplates = SourceWeapon.GetMyWeaponUpgradeTemplates();
  121. foreach WeaponUpgradeTemplates(WeaponUpgradeTemplate)
  122. {
  123. if (WeaponUpgradeTemplate.FreeKillFn != none && WeaponUpgradeTemplate.FreeKillFn(WeaponUpgradeTemplate, TargetUnit))
  124. {
  125. TargetUnit.TakeEffectDamage(self, TotalToKill, 0, NewShred, ApplyEffectParameters, NewGameState, false, false, true, AppliedDamageTypes);
  126. if (TargetUnit.IsAlive())
  127. {
  128. `RedScreen("Somehow free kill upgrade failed to kill the target! -jbouscher @gameplay");
  129. }
  130. else
  131. {
  132. TargetUnit.DamageResults[TargetUnit.DamageResults.Length - 1].bFreeKill = true;
  133. }
  134. return;
  135. }
  136. }
  137. }
  138. }
  139. }
  140. }
  141.  
  142. if (NewRupture > 0)
  143. {
  144. kNewTargetDamageableState.AddRupturedValue(NewRupture);
  145. }
  146.  
  147. kNewTargetDamageableState.TakeEffectDamage(self, iDamage, iMitigated, NewShred, ApplyEffectParameters, NewGameState, false, true, bDoesDamageIgnoreShields, AppliedDamageTypes);
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment