Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class X2Effect_ApplyWeaponDamage_CoverDR extends X2Effect_ApplyWeaponDamage;
- simulated protected function OnEffectAdded(const out EffectAppliedData ApplyEffectParameters, XComGameState_BaseObject kNewTargetState, XComGameState NewGameState, XComGameState_Effect NewEffectState)
- {
- local Damageable kNewTargetDamageableState;
- local int iDamage, iMitigated, NewRupture, NewShred, TotalToKill;
- local XComGameState_Unit TargetUnit;
- local XComGameState_Item SourceWeapon;
- local array<X2WeaponUpgradeTemplate> WeaponUpgradeTemplates;
- local X2WeaponUpgradeTemplate WeaponUpgradeTemplate;
- local array<Name> AppliedDamageTypes;
- local int bAmmoBypassesShields;
- local bool bDoesDamageIgnoreShields;
- local XComGameState_Unit Shooter;
- local XComGameState_Ability Ability;
- local XComGameStateHistory History;
- local GameRulesCache_VisibilityInfo VisInfo;
- local XComGameState_Unit FakeUnitForBlastLocation;
- local Vector HitLocation;
- local int HitLocationCount, HitLocationIndex;
- local array<vector> HitLocationsArray;
- local float AbilityRadius, Distance;
- local TTile BlastLocationTile;
- local XComGameStateContext_Ability AbilityContext;
- kNewTargetDamageableState = Damageable(kNewTargetState);
- if( kNewTargetDamageableState != none )
- {
- AppliedDamageTypes = DamageTypes;
- iDamage = CalculateDamageAmount(ApplyEffectParameters, iMitigated, NewRupture, NewShred, AppliedDamageTypes, bAmmoBypassesShields);
- bDoesDamageIgnoreShields = (bAmmoBypassesShields > 0) || bBypassShields;
- //CoverDR Modifications
- Ability = XComGameState_Ability(NewGameState.GetGameStateForObjectID(ApplyEffectParameters.AbilityStateObjectRef.ObjectID));
- History = `XCOMHISTORY;
- Shooter = XComGameState_Unit(History.GetGameStateForObjectID( Ability.OwnerStateObject.ObjectID ));
- TargetUnit = XComGameState_Unit(kNewTargetState);
- SourceWeapon = Ability.GetSourceWeapon();
- AbilityContext = XComGameStateContext_Ability(NewGameState.GetContext());
- //Find blast center to determine if cover from nade
- HitLocationsArray = AbilityContext.InputContext.TargetLocations;
- HitLocationCount = HitLocationsArray.Length;
- //For now just using last hit location, better to find centerpoint or divide damage by number of points and do cover calc in each
- for( HitLocationIndex = 0; HitLocationIndex < HitLocationCount; ++HitLocationIndex )
- {
- HitLocation = HitLocationsArray[HitLocationIndex];
- }
- BlastLocationTile = `XWORLD.GetTileCoordinatesFromPosition(HitLocation);
- FakeUnitForBlastLocation.SetVisibilityLocation(BlastLocationTile);
- `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);
- //if nade, or if blast location tile != target location to test for indirect weapons?
- FakeUnitForBlastLocation = XComGameState_Unit(History.GetGameStateForObjectID( Shooter.ObjectID ));
- FakeUnitForBlastLocation.SetVisibilityLocation(BlastLocationTile);
- `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);
- //After calling SetVisibilityLocation it seems to be changing the location, but GetVisibilityInfo is still treating cover as if it was the shooters position...
- // Skip units that dont take cover, like sectopods
- if (TargetUnit.CanTakeCover())
- {
- // Populate visInfo, and make sure the target is in line-of-sight of the shooter
- // if (`TACTICALRULES.VisibilityMgr.GetVisibilityInfo(Shooter.ObjectID, TargetUnit.ObjectID, VisInfo))
- if (`TACTICALRULES.VisibilityMgr.GetVisibilityInfo(FakeUnitForBlastLocation.ObjectID, TargetUnit.ObjectID, VisInfo))
- {
- // Switch based on cover type
- switch( VisInfo.TargetCover )
- {
- case CT_MidLevel: // half cover
- iDamage -= 5;
- iMitigated = 5; // Damage lowered by 1 if target in half cover
- break;
- case CT_Standing: // full cover
- iDamage -= 8;
- iMitigated = 5; // Damage lowered by 2 if target in half cover
- break;
- default:
- // if you want something to happen on nocover put it here
- break;
- }
- }
- }
- // Damage cannot be lower than 1, this is consistent with how armor works in game
- if(iDamage <= 0) iDamage = 1;
- if ((iDamage == 0) && (iMitigated == 0) && (NewRupture == 0) && (NewShred == 0))
- {
- // No damage is being dealt
- return;
- }
- if (bAllowFreeKill)
- {
- // check to see if the damage ought to kill them and if not, roll for a free kill
- TargetUnit = XComGameState_Unit(kNewTargetState);
- if (TargetUnit != none)
- {
- TotalToKill = TargetUnit.GetCurrentStat(eStat_HP) + TargetUnit.GetCurrentStat(eStat_ShieldHP);
- if (TotalToKill > iDamage)
- {
- SourceWeapon = XComGameState_Item(`XCOMHISTORY.GetGameStateForObjectID(ApplyEffectParameters.ItemStateObjectRef.ObjectID));
- if (SourceWeapon != none)
- {
- WeaponUpgradeTemplates = SourceWeapon.GetMyWeaponUpgradeTemplates();
- foreach WeaponUpgradeTemplates(WeaponUpgradeTemplate)
- {
- if (WeaponUpgradeTemplate.FreeKillFn != none && WeaponUpgradeTemplate.FreeKillFn(WeaponUpgradeTemplate, TargetUnit))
- {
- TargetUnit.TakeEffectDamage(self, TotalToKill, 0, NewShred, ApplyEffectParameters, NewGameState, false, false, true, AppliedDamageTypes);
- if (TargetUnit.IsAlive())
- {
- `RedScreen("Somehow free kill upgrade failed to kill the target! -jbouscher @gameplay");
- }
- else
- {
- TargetUnit.DamageResults[TargetUnit.DamageResults.Length - 1].bFreeKill = true;
- }
- return;
- }
- }
- }
- }
- }
- }
- if (NewRupture > 0)
- {
- kNewTargetDamageableState.AddRupturedValue(NewRupture);
- }
- kNewTargetDamageableState.TakeEffectDamage(self, iDamage, iMitigated, NewShred, ApplyEffectParameters, NewGameState, false, true, bDoesDamageIgnoreShields, AppliedDamageTypes);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment