class PowerUpCyberwareEffector extends Effector
{
	var m_targetEquipArea : gamedataEquipmentArea;
	var m_targetEquipSlotIndex : Int32;
	var m_playerData : weak< EquipmentSystemPlayerData >;
	var m_owner : weak< GameObject >;

	protected override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		m_targetEquipArea = ( ( gamedataEquipmentArea )( ( ( Int32 )( EnumValueFromString( "gamedataEquipmentArea", TweakDBInterface.GetString( record + T".targetEquipArea", "" ) ) ) ) ) );
		m_targetEquipSlotIndex = TweakDBInterface.GetInt( record + T".targetEquipSlotIndex", 0 );
	}

	protected override function Uninitialize( game : GameInstance )
	{
		var sideUpgradeItem : Item_Record;
		var itemID : ItemID;
		itemID = m_playerData.GetItemInEquipSlot( m_targetEquipArea, m_targetEquipSlotIndex );
		if( ItemID.IsValid( itemID ) && !( RPGManager.CyberwareHasSideUpgrade( itemID, sideUpgradeItem ) ) )
		{
			GameInstance.GetTransactionSystem( game ).RemoveItem( m_owner, itemID, 1 );
		}
	}

	protected export override function ActionOn( owner : GameObject )
	{
		m_owner = owner;
		m_playerData = EquipmentSystem.GetData( owner );
		PowerUpCyberwareInSlot( owner, m_targetEquipArea, m_targetEquipSlotIndex );
	}

	public static function PowerUpCyberwareInSlot( owner : GameObject, targetEquipArea : gamedataEquipmentArea, targetEquipSlotIndex : Int32 )
	{
		var sideUpgradeItem : Item_Record;
		var replaceEquipmentRequest : ReplaceEquipmentRequest;
		var originalItemID : ItemID;
		var newStatsShardItemID : ItemID;
		var oldStatsShardData : InnerItemData;
		var statsShardSlotTDBID : TweakDBID;
		originalItemID = EquipmentSystem.GetData( owner ).GetItemInEquipSlot( targetEquipArea, targetEquipSlotIndex );
		if( !( ItemID.IsValid( originalItemID ) ) )
		{
			return;
		}
		statsShardSlotTDBID = T"AttachmentSlots.StatsShardSlot";
		GameInstance.GetTransactionSystem( owner.GetGame() ).GetItemData( owner, originalItemID ).GetItemPart( oldStatsShardData, statsShardSlotTDBID );
		if( PlayerDevelopmentSystem.GetData( owner ).IsNewPerkBought( gamedataNewPerkType.Tech_Central_Milestone_3 ) < 3 )
		{
			return;
		}
		if( ItemID.IsValid( originalItemID ) && RPGManager.CyberwareHasSideUpgrade( originalItemID, sideUpgradeItem ) )
		{
			replaceEquipmentRequest = new ReplaceEquipmentRequest;
			replaceEquipmentRequest.owner = owner;
			replaceEquipmentRequest.slotIndex = targetEquipSlotIndex;
			replaceEquipmentRequest.itemID = ItemID.FromTDBID( sideUpgradeItem.GetID() );
			replaceEquipmentRequest.addToInventory = true;
			replaceEquipmentRequest.removeOldItem = false;
			replaceEquipmentRequest.transferInstalledParts = true;
			newStatsShardItemID = ItemID.DuplicateRandomSeedWithOffset( InnerItemData.GetItemID( oldStatsShardData ), InnerItemData.GetStaticData( oldStatsShardData ).GetRecordID(), 0 );
			replaceEquipmentRequest.customPartToGenerateID = newStatsShardItemID;
			EquipmentSystem.GetInstance( owner ).QueueRequest( replaceEquipmentRequest );
		}
	}

}

