class WeaponTraining extends InteractiveDevice
{
	default m_controllerTypeName = 'WeaponTrainingController';
	[ customEditor = "TweakDBGroupInheritance;RPGActionRewards.ProficiencyReward" ]
	protected editable var m_rewardRecord : TweakDBID;
	protected const editable var m_weaponTypes : array< gamedataItemType >;
	protected editable var m_limitOfHits : Int32;
	default m_limitOfHits = 30;
	protected var m_amountOfHits : Int32;

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		super.OnRequestComponents( ri );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		super.OnTakeControl( ri );
		m_controller = ( ( WeaponTrainingController )( EntityResolveComponentsInterface.GetComponent( ri, 'controller' ) ) );
	}

	protected event OnHitEvent( hit : gameHitEvent )
	{
		var attackData : AttackData;
		var weaponRecord : weak< Item_Record >;
		attackData = hit.attackData;
		if( attackData.GetInstigator().IsPlayer() && !( hit.target.IsPlayer() ) )
		{
			weaponRecord = TweakDBInterface.GetItemRecord( ItemID.GetTDBID( attackData.GetWeapon().GetItemID() ) );
			if( ( ( m_amountOfHits < m_limitOfHits ) && MatchWeaponItemType( weaponRecord.ItemType().Type() ) ) && TDBID.IsValid( m_rewardRecord ) )
			{
				AwardRewardXP( attackData.GetInstigator(), hit.target.GetEntityID() );
				m_amountOfHits += 1;
			}
		}
	}

	protected function MatchWeaponItemType( type : gamedataItemType ) : Bool
	{
		var i : Int32;
		for( i = 0; i < m_weaponTypes.Size(); i += 1 )
		{
			if( m_weaponTypes[ i ] == type )
			{
				return true;
			}
		}
		return false;
	}

	protected function AwardRewardXP( instigator : weak< GameObject >, target : EntityID )
	{
		var rewardRecord : RewardBase_Record;
		var quantityMods : array< weak< StatModifier_Record > >;
		var expArr : array< weak< XPPoints_Record > >;
		var expType : gamedataProficiencyType;
		var expValue : Float;
		var hitModifier : Float;
		var i : Int32;
		rewardRecord = TweakDBInterface.GetRewardBaseRecord( m_rewardRecord );
		rewardRecord.Experience( expArr );
		hitModifier = 1.0 - ( ( ( Float )( m_amountOfHits ) ) / ( ( ( Float )( m_limitOfHits ) ) + 1.0 ) );
		for( i = 0; i < expArr.Size(); i += 1 )
		{
			quantityMods.Clear();
			expArr[ i ].QuantityModifiers( quantityMods );
			expValue = RPGManager.CalculateStatModifiers( quantityMods, GetGame(), instigator, target );
			expType = expArr[ i ].Type().Type();
			RPGManager.AwardXP( GetGame(), expValue * hitModifier, expType );
		}
	}

	protected const override function HasAnyDirectInteractionActive() : Bool
	{
		return true;
	}

	public const override function DeterminGameplayRole() : EGameplayRole
	{
		return EGameplayRole.GenericRole;
	}

}

class WeaponTrainingController extends ScriptableDeviceComponent
{

	public const override function GetPS() : GameComponentPS
	{
		return GetBasePS();
	}

}

