#include "AddPowerForm.h"


using namespace ObjDataEdit;
//######################################################################################################
ReaderClass< DB_GameObjDbStruct >* AddPowerForm::ObjReader( )
{
	return GameObjDbStructEx::ObjReader_AddPower();
}
//主要需要繼承的涵式
void    AddPowerForm::OnActive()
{
	static bool FirstTime = true;
	Reload_AttrTable();
	//設定種族職業資訊
	if( FirstTime  == false )
		return;

	FirstTime = false;

	BaseForm::OnActive();

	CB_SetArmorType->SelectedIndex = 0;
	CB_SetWeaponType->SelectedIndex = 0;
	

	CB_AbilityList1->Items->Clear();
	CB_AbilityList2->Items->Clear();
	CB_AbilityList3->Items->Clear();
	CB_AbilityList4->Items->Clear();
	CB_AbilityList5->Items->Clear();

	for( int i = 0 ; i < EM_WearEqType_MaxCount ; i++ )
	{
		String* Str = GameObjDbStructEx::GetWearEqTypeENUMString( (WearEqTypeENUM)i );
		CB_AbilityList1->Items->Add( Str );
		CB_AbilityList2->Items->Add( Str );
		CB_AbilityList3->Items->Add( Str );
		CB_AbilityList4->Items->Add( Str );
		CB_AbilityList5->Items->Add( Str );
	}    
}
void    AddPowerForm::OnSelectObj( bool LockOk )
{
    _ObjDB.GameData.Classification = EM_ObjectClass_Attribute;
//    panel1->Enabled = LockOk;
}
//輸出時額外設定
void    AddPowerForm::OnOutputObjSetting( DB_GameObjDbStruct* TempObj )
{
    TempObj->GameData.Classification = EM_ObjectClass_Attribute;
	TempObj->GameData.Attirbute.AddPos.Level = 200;

	//NUD_Ability
	if( TempObj->GameData.Attirbute.IsStandardAbility )
	{
		int LV	 = TempObj->GameData.Attirbute.StandardAbility_Lv;
		for( int i = 0 ;i < 5 ; i++ )
			TempObj->GameData.Attirbute.Ability.EqTypeValue[i] = GetStandardAbilityValue( LV , TempObj->GameData.Attirbute.StandardAbility_ArgType[i] , TempObj->GameData.Attirbute.StandardAbility_Arg[i] );
	}
}


void    AddPowerForm::OnTimeProc()
{
    
}
int     AddPowerForm::ObjSize(  )
{
    GameObjDbStruct *P = NULL;
    int Size = sizeof( GameObjDbStruct ) - sizeof( P->Temp ) +  sizeof( P->Attirbute ) + 3;
    Size = Size & 0xfffffC;
    return Size;
}
void    AddPowerForm::OnValueChange()
{
    DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
    LB_Inc_Magic->Text = SearchObjName( TempObj->GameData.Attirbute.Inc_Magic ); 
	LB_EqTypeOnAttackMagicID->Text = SearchObjName( TempObj->GameData.Attirbute.Ability.OnAttackMagicID );  

	//NUD_Ability
	if( TempObj->GameData.Attirbute.IsStandardAbility )
	{
		tabControl1->SelectedIndex = 1;		
		int LV	 = TempObj->GameData.Attirbute.StandardAbility_Lv;

		NUD_Ability1->Value = GetStandardAbilityValue( LV , TempObj->GameData.Attirbute.StandardAbility_ArgType[0] , TempObj->GameData.Attirbute.StandardAbility_Arg[0] );
		NUD_Ability2->Value = GetStandardAbilityValue( LV , TempObj->GameData.Attirbute.StandardAbility_ArgType[1] , TempObj->GameData.Attirbute.StandardAbility_Arg[1] );
		NUD_Ability3->Value = GetStandardAbilityValue( LV , TempObj->GameData.Attirbute.StandardAbility_ArgType[2] , TempObj->GameData.Attirbute.StandardAbility_Arg[2] );
		NUD_Ability4->Value = GetStandardAbilityValue( LV , TempObj->GameData.Attirbute.StandardAbility_ArgType[3] , TempObj->GameData.Attirbute.StandardAbility_Arg[3] );
		NUD_Ability5->Value = GetStandardAbilityValue( LV , TempObj->GameData.Attirbute.StandardAbility_ArgType[4] , TempObj->GameData.Attirbute.StandardAbility_Arg[4] );
	}
	else
	{
		tabControl1->SelectedIndex = 0;		
	}
}
System::Void AddPowerForm::SetOtherClick(System::Object*  sender, System::EventArgs*  e) 
{
	for( int i = 0 ; i < CLB_OtherType->Items->Count ; i ++ )
	{
		CLB_OtherType->SetItemChecked( i , true );
	}
	ChangeFlag( CLB_OtherType  , NULL );

}
System::Void AddPowerForm::SetArmorClick(System::Object*  sender, System::EventArgs*  e) 
{

	switch( CB_SetArmorType->SelectedIndex )
	{
	case 0:	
		
		for( int i = 0 ; i < CLB_ArmorPos->Items->Count ; i ++ )
		{
			CLB_ArmorPos->SetItemChecked( i , true );
		}
		
		ChangeFlag( CLB_ArmorPos  , NULL );

		for( int i = 0 ; i < CLB_ArmorType->Items->Count ; i ++ )
		{
			CLB_ArmorType->SetItemChecked( i , true );
		}

		ChangeFlag( CLB_ArmorType  , NULL );

		break;
	case 1:	
		for( int i = 0 ; i < CLB_ArmorPos->Items->Count ; i ++ )
		{
			CLB_ArmorPos->SetItemChecked( i , false );
		}

		ChangeFlag( CLB_ArmorPos  , NULL );

		for( int i = 0 ; i < CLB_ArmorType->Items->Count ; i ++ )
		{
			CLB_ArmorType->SetItemChecked( i , false );
		}

		ChangeFlag( CLB_ArmorType  , NULL );

		break;
	}
}
System::Void AddPowerForm::SetWeaponClick(System::Object*  sender, System::EventArgs*  e) 
{
	switch( CB_SetWeaponType->SelectedIndex )
	{
	case 0://選擇全部類別
		for( int i = 0 ; i < CLB_WeaponType->Items->Count ; i ++ )
		{
			CLB_WeaponType->SetItemChecked( i , true );
		}
		CB_WeaponPos->SelectedIndex = 0;
		break;
	case 1://清除全部類別

		for( int i = 0 ; i < CLB_WeaponType->Items->Count ; i ++ )
		{
			CLB_WeaponType->SetItemChecked( i , false );
		}
		CB_WeaponPos->SelectedIndex = 0;
		break;

	case 2://近戰武器
		CB_WeaponPos->SelectedIndex = 0;

		CLB_WeaponType->SetItemChecked( 0 ,  true );	//拳套
		CLB_WeaponType->SetItemChecked( 1 ,  true );	//劍
		CLB_WeaponType->SetItemChecked( 2 ,  true );	//匕首
		CLB_WeaponType->SetItemChecked( 3 ,  true );	//槌棍棒
		CLB_WeaponType->SetItemChecked( 4 ,  true );	//權杖
		CLB_WeaponType->SetItemChecked( 5 ,  true );	//斧
		CLB_WeaponType->SetItemChecked( 6 ,  true );	//雙手斧
		CLB_WeaponType->SetItemChecked( 7 ,  true );	//雙手杖
		CLB_WeaponType->SetItemChecked( 8 ,  true );	//雙手劍
		CLB_WeaponType->SetItemChecked( 9 ,  true );	//雙手槌
		CLB_WeaponType->SetItemChecked( 10,  true );	//槍(長矛)
		CLB_WeaponType->SetItemChecked( 11, false );	//遠程武器 弓
		CLB_WeaponType->SetItemChecked( 12, false );	//遠程武器 十字弓
		CLB_WeaponType->SetItemChecked( 13, false );	//遠程武器 槍
		break;
	case 3://遠程武器
		CB_WeaponPos->SelectedIndex = 0;

		CLB_WeaponType->SetItemChecked( 0 , false );	//拳套
		CLB_WeaponType->SetItemChecked( 1 , false );	//劍
		CLB_WeaponType->SetItemChecked( 2 , false );	//匕首
		CLB_WeaponType->SetItemChecked( 3 , false );	//槌棍棒
		CLB_WeaponType->SetItemChecked( 4 , false );	//權杖
		CLB_WeaponType->SetItemChecked( 5 , false );	//斧
		CLB_WeaponType->SetItemChecked( 6 , false );	//雙手斧
		CLB_WeaponType->SetItemChecked( 7 , false );	//雙手杖
		CLB_WeaponType->SetItemChecked( 8 , false );	//雙手劍
		CLB_WeaponType->SetItemChecked( 9 , false );	//雙手槌
		CLB_WeaponType->SetItemChecked( 10, false );	//槍(長矛)
		CLB_WeaponType->SetItemChecked( 11, true  );	//遠程武器 弓
		CLB_WeaponType->SetItemChecked( 12, true  );	//遠程武器 十字弓
		CLB_WeaponType->SetItemChecked( 13, true  );	//遠程武器 槍
		break;
	case 4://雙手武器
		CB_WeaponPos->SelectedIndex = 0;

		CLB_WeaponType->SetItemChecked( 0 , true  );	//拳套
		CLB_WeaponType->SetItemChecked( 1 , false );	//劍
		CLB_WeaponType->SetItemChecked( 2 , false );	//匕首
		CLB_WeaponType->SetItemChecked( 3 , false );	//槌棍棒
		CLB_WeaponType->SetItemChecked( 4 , false );	//權杖
		CLB_WeaponType->SetItemChecked( 5 , false );	//斧
		CLB_WeaponType->SetItemChecked( 6 ,  true );	//雙手斧
		CLB_WeaponType->SetItemChecked( 7 ,  true );	//雙手杖
		CLB_WeaponType->SetItemChecked( 8 ,  true );	//雙手劍
		CLB_WeaponType->SetItemChecked( 9 ,  true );	//雙手槌
		CLB_WeaponType->SetItemChecked( 10,  true );	//槍(長矛)
		CLB_WeaponType->SetItemChecked( 11, false );	//遠程武器 弓
		CLB_WeaponType->SetItemChecked( 12, false );	//遠程武器 十字弓
		CLB_WeaponType->SetItemChecked( 13, false );	//遠程武器 槍
		break;
	case 5://單手武器
		CB_WeaponPos->SelectedIndex = 0;

		CLB_WeaponType->SetItemChecked( 0 , false );	//拳套
		CLB_WeaponType->SetItemChecked( 1 , true  );	//劍
		CLB_WeaponType->SetItemChecked( 2 , true  );	//匕首
		CLB_WeaponType->SetItemChecked( 3 , true  );	//槌棍棒
		CLB_WeaponType->SetItemChecked( 4 , true  );	//權杖
		CLB_WeaponType->SetItemChecked( 5 , true  );	//斧
		CLB_WeaponType->SetItemChecked( 6 , false );	//雙手斧
		CLB_WeaponType->SetItemChecked( 7 , false );	//雙手杖
		CLB_WeaponType->SetItemChecked( 8 , false );	//雙手劍
		CLB_WeaponType->SetItemChecked( 9 , false );	//雙手槌
		CLB_WeaponType->SetItemChecked( 10, false );	//槍(長矛)
		CLB_WeaponType->SetItemChecked( 11, false );	//遠程武器 弓
		CLB_WeaponType->SetItemChecked( 12, false );	//遠程武器 十字弓
		CLB_WeaponType->SetItemChecked( 13, false );	//遠程武器 槍
		break;
	case 6://法系武器
		CB_WeaponPos->SelectedIndex = 1;
		CLB_WeaponType->SetItemChecked( 0 , false );	//拳套
		CLB_WeaponType->SetItemChecked( 1 , true  );	//劍
		CLB_WeaponType->SetItemChecked( 2 , true  );	//匕首
		CLB_WeaponType->SetItemChecked( 3 , true  );	//槌棍棒
		CLB_WeaponType->SetItemChecked( 4 , true  );	//權杖
		CLB_WeaponType->SetItemChecked( 5 , false );	//斧
		CLB_WeaponType->SetItemChecked( 6 , false );	//雙手斧
		CLB_WeaponType->SetItemChecked( 7 , true  );	//雙手杖
		CLB_WeaponType->SetItemChecked( 8 , false );	//雙手劍
		CLB_WeaponType->SetItemChecked( 9 , false );	//雙手槌
		CLB_WeaponType->SetItemChecked( 10, false );	//槍(長矛)
		CLB_WeaponType->SetItemChecked( 11, false );	//遠程武器 弓
		CLB_WeaponType->SetItemChecked( 12, false );	//遠程武器 十字弓
		CLB_WeaponType->SetItemChecked( 13, false );	//遠程武器 槍
		break;
	}
	ChangeFlag( CLB_WeaponType  , NULL );
}


//######################################################################################################

System::Void AddPowerForm::AbilityType_SelectedIndexChange(System::Object*  sender, System::EventArgs*  e)
{

	TabControl* Box = static_cast<TabControl*>(sender);
	DB_GameObjDbStruct __pin *Data = &_ObjDB;

	if( (Box->SelectedIndex!= 0) ==  Data->GameData.Attirbute.IsStandardAbility )
		return;

	if( CheckModifyAndCheckOut() == false )
		return;

	if( CB_Lock->Checked == true )
		_ObjDB.IsModify = true;


	if( Box->SelectedIndex == 0 )
		Data->GameData.Attirbute.IsStandardAbility = false;
	else
		Data->GameData.Attirbute.IsStandardAbility = true;

	_OnValueChange = true;	
}