class ModifyDamageWithCyberwareCountEffector extends ModifyDamageEffector
{
	var m_minPlayerHealthPercentage : Float;
	var m_playerIncomingDamageMultiplier : Float;
	var m_playerMaxIncomingDamage : Float;
	var m_damageBuffAmount : Float;
	var m_damageBuffRarity : Float;
	var m_playVFXOnHitTargets : CName;
	var m_statusEffectRecord : weak< StatusEffect_Record >;

	protected override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		super.Initialize( record, game, parentRecord );
		m_minPlayerHealthPercentage = TDB.GetFloat( record + T".minPlayerHealthPercentage" ) / 100.0;
		m_playerIncomingDamageMultiplier = TDB.GetFloat( record + T".playerIncomingDamageMultiplier" );
		m_playerMaxIncomingDamage = TDB.GetFloat( record + T".playerMaxIncomingDamage" );
		m_damageBuffAmount = TDB.GetFloat( record + T".damageBuffAmount" );
		m_damageBuffRarity = TDB.GetFloat( record + T".damageBuffRarity" );
		m_playVFXOnHitTargets = TDB.GetCName( record + T".playVFXOnHitTargets" );
		m_statusEffectRecord = TDB.GetStatusEffectRecord( TweakDBInterface.GetForeignKeyDefault( record + T".statusEffectRecord" ) );
	}

	protected override function RepeatedAction( owner : GameObject )
	{
		var i : Int32;
		var hitEvent : gameHitEvent;
		var equippedCyberwareCount : Int32;
		var maxCyberwareCount : Int32;
		var equippedCyberwareRarity : Float;
		var equipmentAreas : array< gamedataEquipmentArea >;
		var equipmentSystemPlayerData : EquipmentSystemPlayerData;
		var attackdamage : Float;
		var health : Float;
		var maxHealth : Float;
		var minAllowedHealth : Float;
		var calculatedDamageMultiplier : Float;
		var breakEffectLoopEvent : entBreakEffectLoopEvent;
		var currentCyberware : ItemID;
		var currentCyberwareData : weak< gameItemData >;
		equippedCyberwareCount = 0;
		maxCyberwareCount = 0;
		equippedCyberwareRarity = 0.0;
		hitEvent = GetHitEvent();
		if( !( hitEvent ) )
		{
			return;
		}
		equipmentSystemPlayerData = EquipmentSystem.GetData( owner );
		equipmentAreas = equipmentSystemPlayerData.GetAllCyberwareEquipmentAreas();
		for( i = 0; i < equipmentAreas.Size(); i += 1 )
		{
			maxCyberwareCount += equipmentSystemPlayerData.GetNumberOfSlots( equipmentAreas[ i ], true );
			equippedCyberwareCount += equipmentSystemPlayerData.GetNumberOfItemsInEquipmentArea( equipmentAreas[ i ] );
			currentCyberware = equipmentSystemPlayerData.GetActiveItem( equipmentAreas[ i ] );
			currentCyberwareData = RPGManager.GetItemData( owner.GetGame(), owner, currentCyberware );
			equippedCyberwareRarity += RPGManager.ItemQualityEnumToValue( RPGManager.GetItemDataQuality( currentCyberwareData ) );
			if( RPGManager.IsItemIconic( currentCyberwareData ) )
			{
				equippedCyberwareRarity += 1.0;
			}
		}
		if( maxCyberwareCount == 0 )
		{
			return;
		}
		calculatedDamageMultiplier = 1.0;
		calculatedDamageMultiplier *= ( 1.0 + ( ( m_damageBuffAmount * ( ( Float )( equippedCyberwareCount ) ) ) / ( ( Float )( maxCyberwareCount ) ) ) );
		calculatedDamageMultiplier *= ( 1.0 + ( equippedCyberwareRarity * m_damageBuffRarity ) );
		if( hitEvent.target == owner )
		{
			calculatedDamageMultiplier *= m_playerIncomingDamageMultiplier;
		}
		hitEvent.attackComputed.MultAttackValue( calculatedDamageMultiplier );
		if( hitEvent.target == owner )
		{
			attackdamage = hitEvent.attackComputed.GetTotalAttackValue( gamedataStatPoolType.Health );
			health = GameInstance.GetStatPoolsSystem( owner.GetGame() ).GetStatPoolValue( owner.GetEntityID(), gamedataStatPoolType.Health, false );
			maxHealth = GameInstance.GetStatPoolsSystem( owner.GetGame() ).GetStatPoolMaxPointValue( owner.GetEntityID(), gamedataStatPoolType.Health );
			minAllowedHealth = MaxF( maxHealth * m_minPlayerHealthPercentage, health - ( maxHealth * m_playerMaxIncomingDamage ) );
			if( ( attackdamage > 0.0 ) && ( ( health - attackdamage ) < minAllowedHealth ) )
			{
				if( health > minAllowedHealth )
				{
					hitEvent.attackComputed.MultAttackValue( ( health - minAllowedHealth ) / attackdamage );
				}
				else
				{
					hitEvent.attackComputed.MultAttackValue( 0.0 );
				}
			}
		}
		else if( ( ( ScriptedPuppet )( hitEvent.target ) ) && GameObject.GetAttitudeBetween( hitEvent.target, hitEvent.attackData.GetInstigator() ) != EAIAttitude.AIA_Friendly )
		{
			if( IsNameValid( m_playVFXOnHitTargets ) )
			{
				GameObjectEffectHelper.StartEffectEvent( hitEvent.target, m_playVFXOnHitTargets );
				breakEffectLoopEvent = new entBreakEffectLoopEvent;
				breakEffectLoopEvent.effectName = m_playVFXOnHitTargets;
				GameInstance.GetDelaySystem( owner.GetGame() ).DelayEvent( hitEvent.target, breakEffectLoopEvent, 2.5 );
			}
			StatusEffectHelper.ApplyStatusEffect( hitEvent.target, m_statusEffectRecord.GetID(), GameObject.GetTDBID( owner ) );
		}
	}

}

