class ChaosWeaponCustomEffector extends Effector
{
	var m_effectorOwnerID : EntityID;
	var m_target : StatsObjectID;
	var m_record : TweakDBID;
	var m_applicationTarget : CName;
	var m_modGroupID : Uint64;

	protected override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		m_record = TweakDBInterface.GetApplyStatGroupEffectorRecord( record ).StatGroup().GetID();
		m_applicationTarget = TweakDBInterface.GetCName( record + T".applicationTarget", '' );
	}

	protected virtual function ProcessEffector( owner : GameObject )
	{
		var ss : StatsSystem;
		m_effectorOwnerID = owner.GetEntityID();
		ss = GameInstance.GetStatsSystem( owner.GetGame() );
		if( !( GetApplicationTargetAsStatsObjectID( owner, m_applicationTarget, m_target ) ) )
		{
			return;
		}
		ss.RemoveModifierGroup( m_target, m_modGroupID );
		ss.UndefineModifierGroup( m_modGroupID );
		m_modGroupID = TDBID.ToNumber( m_record );
		ss.DefineModifierGroupFromRecord( m_modGroupID, m_record );
		ss.ApplyModifierGroup( m_target, m_modGroupID );
	}

	protected override function Uninitialize( game : GameInstance )
	{
		RemoveModifierGroup( game );
	}

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

	private function RemoveModifierGroup( gameInstance : GameInstance )
	{
		var ss : StatsSystem;
		if( !( StatsObjectID.IsDefined( m_target ) ) || !( EntityID.IsDefined( m_effectorOwnerID ) ) )
		{
			return;
		}
		ss = GameInstance.GetStatsSystem( gameInstance );
		ss.RemoveModifierGroup( m_target, m_modGroupID );
		ss.UndefineModifierGroup( m_modGroupID );
	}

}

class ChaosWeaponDamageTypeEffector extends ChaosWeaponCustomEffector
{
	var m_damageTypeModGroups : array< TweakDBID >;

	protected override function Initialize( record : TweakDBID, game : GameInstance, parentRecord : TweakDBID )
	{
		m_applicationTarget = TweakDBInterface.GetCName( record + T".applicationTarget", '' );
		m_damageTypeModGroups.PushBack( T"Items.ChaosPhysical" );
		m_damageTypeModGroups.PushBack( T"Items.ChaosThermal" );
		m_damageTypeModGroups.PushBack( T"Items.ChaosElectric" );
		m_damageTypeModGroups.PushBack( T"Items.ChaosChemical" );
	}

	protected override function ProcessEffector( owner : GameObject )
	{
		var ss : StatsSystem;
		var randIndex : Int32;
		m_effectorOwnerID = owner.GetEntityID();
		ss = GameInstance.GetStatsSystem( owner.GetGame() );
		if( !( GetApplicationTargetAsStatsObjectID( owner, m_applicationTarget, m_target ) ) )
		{
			return;
		}
		ss.RemoveModifierGroup( m_target, m_modGroupID );
		ss.UndefineModifierGroup( m_modGroupID );
		randIndex = RandRange( 0, m_damageTypeModGroups.Size() );
		m_modGroupID = TDBID.ToNumber( m_damageTypeModGroups[ randIndex ] );
		ss.DefineModifierGroupFromRecord( m_modGroupID, m_damageTypeModGroups[ randIndex ] );
		ss.ApplyModifierGroup( m_target, m_modGroupID );
	}

}

