class InitiateCyberwareExplosionEffector extends Effector
{
	var m_maxRangeAddition : Float;
	var m_attackRecord : weak< Attack_Record >;

	protected override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		super.Initialize( record, game, parentRecord );
		m_maxRangeAddition = TDB.GetFloat( record + T".maxRangeAddition" );
		m_attackRecord = TDB.GetAttackRecord( TweakDBInterface.GetForeignKeyDefault( record + T".attackRecord" ) );
	}

	protected override function ActionOn( owner : GameObject )
	{
		RepeatedAction( owner );
	}

	protected override function RepeatedAction( owner : GameObject )
	{
		var attack : Attack_GameEffect;
		var attackEffect : EffectInstance;
		var attackContext : AttackInitContext;
		var statMods : array< gameStatModifierData >;
		var explosionRadius : Float;
		var impulseRadius : Float;
		var i : Int32;
		var equippedCyberwareCount : Int32;
		var maxCyberwareCount : Int32;
		var equipmentAreas : array< gamedataEquipmentArea >;
		var equipmentSystemPlayerData : EquipmentSystemPlayerData;
		equippedCyberwareCount = 0;
		maxCyberwareCount = 0;
		equipmentSystemPlayerData = EquipmentSystem.GetData( owner );
		equipmentAreas = equipmentSystemPlayerData.GetAllCyberwareEquipmentAreas();
		for( i = 0; i < equipmentAreas.Size(); i += 1 )
		{
			maxCyberwareCount += equipmentSystemPlayerData.GetNumberOfSlots( equipmentAreas[ i ] );
			equippedCyberwareCount += equipmentSystemPlayerData.GetNumberOfItemsInEquipmentArea( equipmentAreas[ i ] );
		}
		if( maxCyberwareCount == 0 )
		{
			return;
		}
		explosionRadius = TDB.GetFloat( T"weapons.E3_grenade.damageRadius" ) + ( ( ( ( Float )( equippedCyberwareCount ) ) / ( ( Float )( maxCyberwareCount ) ) ) * m_maxRangeAddition );
		impulseRadius = TDB.GetFloat( T"weapons.E3_grenade.physicalImpulseRadius" ) + ( ( ( ( Float )( equippedCyberwareCount ) ) / ( ( Float )( maxCyberwareCount ) ) ) * m_maxRangeAddition );
		attackContext.record = m_attackRecord;
		attackContext.instigator = owner;
		attackContext.source = owner;
		attack = ( ( Attack_GameEffect )( IAttack.Create( attackContext ) ) );
		attackEffect = attack.PrepareAttack( owner );
		attack.GetStatModList( statMods );
		EffectData.SetFloat( attackEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.range, explosionRadius );
		EffectData.SetFloat( attackEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.radius, explosionRadius );
		EffectData.SetVector( attackEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.position, owner.GetWorldPosition() );
		EffectData.SetVariant( attackEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.attack, ( ( IAttack )( attack ) ) );
		EffectData.SetVariant( attackEffect.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.attackStatModList, statMods );
		attack.StartAttack();
		CombatGadgetHelper.SpawnPhysicalImpulse( owner, impulseRadius );
		GameObject.PlayMetadataEvent( owner, 'exploded' );
		GameInstance.GetAudioSystem( owner.GetGame() ).PlayShockwave( 'explosion', owner.GetWorldPosition() );
		GameObjectEffectHelper.StartEffectEvent( owner, 'cyberware_explosion', false );
		if( !( StatusEffectHelper.HasStatusEffectWithTagConst( owner, 'BerserkBuff' ) ) )
		{
			GameObjectEffectHelper.StartEffectEvent( owner, 'screen_scanning', false );
		}
	}

}

