#include "MagicBaseForm.h"
using namespace ObjDataEdit;

//######################################################################################################
//主要需要繼承的涵式
ReaderClass< DB_GameObjDbStruct >* MagicBaseForm::ObjReader( )
{
	return GameObjDbStructEx::ObjReader_MagicBase( );
}
void    MagicBaseForm::OnActive()
{
	static bool FirstTime = true;

	Reload_AttrTable();

	if( FirstTime  == false )
		return;

	BaseForm::OnActive();

	FirstTime = false;

	SqlDataReader* myReader;

	sqlCommand_Base->CommandText = "Select ID , Name from Table_String Where Type = '輔助類型' ORDER BY  ID";
	myReader = sqlCommand_Base->ExecuteReader();
	CB_MagicAssistType->Items->Clear();
	CB_MagicAssistType->Items->Add( S"無" );
	while( myReader->Read() )
	{                
		int     Value =  myReader->GetInt32( 0 );
		String* Str   =  myReader->GetString( 1 );

		CB_MagicAssistType->Items->Add( Str );
	}
	myReader->Close();


	sqlCommand_Base->CommandText = "Select ID , Name from Table_String Where Type = '法術群組' ORDER BY  ID";
	myReader = sqlCommand_Base->ExecuteReader();
	CB_MagicGroup->Items->Clear();
	CB_MagicGroup->Items->Add( S"無" );
	while( myReader->Read() )
	{                
		int     Value =  myReader->GetInt32( 0 );
		String* Str   =  myReader->GetString( 1 );

		CB_MagicGroup->Items->Add( Str );
	}
	myReader->Close();

	CLB_GroupSetEx->Items->Clear();
	CLB_ClearGroupSet->Items->Clear();
	sqlCommand_Base->CommandText = "Select ID , Name from Table_String Where Type = '法術群組Ex' ORDER BY  ID";
	myReader = sqlCommand_Base->ExecuteReader();
	while( myReader->Read() )
	{                
		int     Value =  myReader->GetInt32( 0 );
		String* Str   =  myReader->GetString( 1 );

		CLB_GroupSetEx->Items->Add( Str );
		CLB_ClearGroupSet->Items->Add( Str );
	}
	myReader->Close();


	sqlCommand_Base->CommandText = "Select ID , Name from Table_String Where Type = '招喚群組' ORDER BY  ID";
	myReader = sqlCommand_Base->ExecuteReader();
	CB_SCGroupID->Items->Clear();	
	CB_SCGroupID->Items->Add( S"不分類" );
	while( myReader->Read() )
	{                
		int     Value =  myReader->GetInt32( 0 );
		String* Str   =  myReader->GetString( 1 );

		CB_SCGroupID->Items->Add( Str );
	}
	myReader->Close();


	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 );
	} 

	//////////////////////////////////////////////////////////////////////////
	sqlCommand_Base->CommandText = "Select ID , Name from Table_String Where Type = '寵物技能類型' ORDER BY  ID";
	myReader = sqlCommand_Base->ExecuteReader();
	CB_SCSkillType0->Items->Clear();	
	CB_SCSkillType1->Items->Clear();	
	CB_SCSkillType2->Items->Clear();	
	CB_SCSkillType0->Items->Add( S"無" );
	CB_SCSkillType1->Items->Add( S"無" );
	CB_SCSkillType2->Items->Add( S"無" );
	while( myReader->Read() )
	{                
		int     Value =  myReader->GetInt32( 0 );
		String* Str   =  myReader->GetString( 1 );

		CB_SCSkillType0->Items->Add( Str );
		CB_SCSkillType1->Items->Add( Str );
		CB_SCSkillType2->Items->Add( Str );
	}
	myReader->Close();

//CB_BuffTimeDesc_Type
	sqlCommand_Base->CommandText = "Select ID , Name from Table_String Where Type = 'Buff效用遞減' ORDER BY  ID";
	myReader = sqlCommand_Base->ExecuteReader();
	CB_BuffTimeDesc_Type->Items->Clear();	
	CB_BuffTimeDesc_Type->Items->Add( S"無" );
	while( myReader->Read() )
	{                
		int     Value =  myReader->GetInt32( 0 );
		String* Str   =  myReader->GetString( 1 );

		CB_BuffTimeDesc_Type->Items->Add( Str );
	}
	myReader->Close();

	/*
	//取基本等級Power值
	sqlCommand_Base->CommandText = "Select BaseMagicPower , MagicPowerGrowRate From Table_Exp ORDER BY LV";
	myReader = sqlCommand_Base->ExecuteReader();
	Global::BaseMagicPower.clear();
	Global::MagicPowerGrowRate.clear();
	while( myReader->Read() )
	{                
		int     Power =  myReader->GetFloat( 0 );
		float	GrowRate =  myReader->GetFloat( 1 ) * 100;
		Global::BaseMagicPower.push_back( Power );
		Global::MagicPowerGrowRate.push_back( GrowRate );
	}
	myReader->Close();
*/
	sqlCommand_Base->CommandText = "Select ID , Name from Table_String Where Type = 'MotionChange' ORDER BY  ID";
	myReader = sqlCommand_Base->ExecuteReader();
	CB_ChangeMotionType1->Items->Clear();
	CB_ChangeMotionType2->Items->Clear();
	CB_ChangeMotionType3->Items->Clear();
	CB_ChangeMotionType4->Items->Clear();
	while( myReader->Read() )
	{                
		int     Value =  myReader->GetInt32( 0 );
		String* Str   =  myReader->GetString( 1 );

		CB_ChangeMotionType1->Items->Add( Str );
		CB_ChangeMotionType2->Items->Add( Str );
		CB_ChangeMotionType3->Items->Add( Str );
		CB_ChangeMotionType4->Items->Add( Str );
	}
	myReader->Close();
}
void    MagicBaseForm::OnSelectObj( bool LockOk )
{
    _ObjDB.GameData.Classification = EM_ObjectClass_MagicBase;
//    panel1->Enabled = LockOk;
}
void    MagicBaseForm::OnOutputObjSetting( DB_GameObjDbStruct* TempObj )
{
    TempObj->GameData.Classification = EM_ObjectClass_MagicBase;

	TempObj->GameData.MagicBase.SummonCreature.SkillType[0]--;
	TempObj->GameData.MagicBase.SummonCreature.SkillType[1]--;
	TempObj->GameData.MagicBase.SummonCreature.SkillType[2]--;

	if( TempObj->GameData.MagicBase.Setting.DotMagic == false )
	{
		TempObj->GameData.MagicBase.DotMagic.Init();
	}
	if( TempObj->GameData.MagicBase.Setting.FaceOffMagic == false )
	{
		TempObj->GameData.MagicBase.FaceOffID = 0;
	}
	if( TempObj->GameData.MagicBase.Setting.ContinueMagic == false )
	{
		TempObj->GameData.MagicBase.OnTimeMagic_Magic = 0;
		TempObj->GameData.MagicBase.OnTimeMagic_Time  = 0;
	}
	if( TempObj->GameData.MagicBase.Effect.Ride == false )
	{
		TempObj->GameData.MagicBase.RideID = 0;
	}

	TempObj->GameData.MagicBase.AssistType = (GameObjectMagicTypeENUM)(TempObj->GameData.MagicBase.AssistType - 1 );
	TempObj->GameData.MagicBase.MagicType = (MagicResistENUM)(TempObj->GameData.MagicBase.MagicType - 1 );
	TempObj->GameData.MagicBase.PhyAttackType = (PhyResistTypeENUM)(TempObj->GameData.MagicBase.PhyAttackType -1);

	if( TempObj->GameData.MagicBase.MagicFunc != EM_MAGICFUN_HPMP )
	{
		TempObj->GameData.MagicBase.SpecialAction._Type = 0;
	}

//	if( TempObj->GameData.MagicBase.ClearTime.Random == true )
//		TempObj->GameData.MagicBase.Setting.ShowBuffTime = false;

	//////////////////////////////////////////////////////////////////////////
//	ObjectModeStruct	Mode;
//	Mode._Mode = 0;

	/*
	if( (TempObj->GameData.MagicBase.ItemRunPlot.Mode._Mode & 0x1) == 0x1 )
		Mode.Mark  = true;
	if( (TempObj->GameData.MagicBase.ItemRunPlot.Mode._Mode & 0x2) == 0x2 )
		Mode.Fight = true;
	if( (TempObj->GameData.MagicBase.ItemRunPlot.Mode._Mode & 0x4) == 0x4 )
		Mode.HideName = true;
	if( (TempObj->GameData.MagicBase.ItemRunPlot.Mode._Mode & 0x8) == 0x8 )
		Mode.EnemyHide = true;
	*/
/*
	if( (TempObj->GameData.MagicBase.ItemRunPlot.Mode & 0x1) == 0x1 )
		Mode.Mark  = true;
	if( (TempObj->GameData.MagicBase.ItemRunPlot.Mode & 0x2) == 0x2 )
		Mode.Fight = true;
	if( (TempObj->GameData.MagicBase.ItemRunPlot.Mode & 0x4) == 0x4 )
		Mode.HideName = true;
	if( (TempObj->GameData.MagicBase.ItemRunPlot.Mode & 0x8) == 0x8 )
		Mode.EnemyHide = true;
*/

	//TempObj->GameData.MagicBase.ItemRunPlot.Mode._Mode = Mode._Mode;
//	TempObj->GameData.MagicBase.ItemRunPlot.Mode = Mode._Mode;
	//////////w////////////////////////////////////////////////////////////////

	if( TempObj->GameData.MagicBase.IsStandard_Attack )
	{
		int		Lv = TempObj->GameData.MagicBase.RefPowerLv_Attack -1 ;
		if( Lv <= 0  )
			Lv = 0;
		if( Lv >= Global::BaseMagicPower.size() )
			Lv = Global::BaseMagicPower.size() -1;

		TempObj->GameData.MagicBase.Attack.DmgPower = Global::BaseMagicPower[Lv*0.5]* TempObj->GameData.MagicBase.RefPowerRate_Attack;
		TempObj->GameData.MagicBase.Attack.DmgPower_SkillLVArg = Global::MagicPowerGrowRate[Lv] ;
	}
/*
	for( int i = 5 ; i < Max_WearEqType_Count ; i++ )
	{
		TempObj->GameData.MagicBase.Ability.EqType[ i ] = EM_WearEqType_None;
		TempObj->GameData.MagicBase.Ability.EqTypeValue[ i ] = 0;
	}
*/
}
void    MagicBaseForm::OnTimeProc()
{

}

int     MagicBaseForm::ObjSize(  )
{
    GameObjDbStruct *P = NULL;
    int Size = sizeof( GameObjDbStruct ) - sizeof( P->Temp ) + sizeof( P->MagicBase ) + 3;
    Size = Size & 0xfffffC;
    return Size;
}
void    MagicBaseForm::OnValueChange()
{
	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;

	LB_OntimeMagicID->Text =  SearchObjName( TempObj->GameData.MagicBase.OnTimeMagic_Magic );
	LB_ChangeID->Text =  SearchObjName( TempObj->GameData.MagicBase.FaceOffID );
	LB_RideID->Text =  SearchObjName( TempObj->GameData.MagicBase.RideID );

	LB_EqTypeOnAttackMagicID->Text = SearchObjName( TempObj->GameData.MagicBase.Ability.OnAttackMagicID );  

//	if( TempObj->GameData.MagicBase.MagicFunc == EM_MAGICFUN_Assist )
//		groupBox2->Show();
//	else
//		groupBox2->Hide();

	if( TempObj->GameData.MagicBase.MagicFunc == EM_MAGICFUN_HPMP )
		groupBox4->Show();
	else
		groupBox4->Hide();

	if( TempObj->GameData.MagicBase.EffectType == EM_Magic_Magic )
	{
		CB_MagicType->Show();
		LB_MagicType->Show();
		CB_PhyType->Hide();
		LB_PhyType->Hide();

	}
	else
	{
		CB_PhyType->Show();
		LB_PhyType->Show();
		CB_MagicType->Hide();
		LB_MagicType->Hide();
	}


	if( TempObj->GameData.MagicBase.Setting.DotMagic == true )
		GB_DotMagic->Show();
	else
		GB_DotMagic->Hide();

	if( TempObj->GameData.MagicBase.Setting.FaceOffMagic == true )
		GB_FaceOff->Show();
	else
		GB_FaceOff->Hide();

	if( TempObj->GameData.MagicBase.Setting.ContinueMagic == true )
		GB_ContinueMagic->Show();
	else
		GB_ContinueMagic->Hide();

	if( TempObj->GameData.MagicBase.Setting.SpecialMagic == true )
	{
		LB_OnAttackMagic->Text =  SearchObjName( TempObj->GameData.MagicBase.OnAttackMagicID ); 
		LB_OnBuffTimeOutMagic->Text =  SearchObjName( TempObj->GameData.MagicBase.OnBuffTimeOutMagicID );
		LB_OnBuffTimeOutMagicEx->Text =  SearchObjName( TempObj->GameData.MagicBase.OnBuffTimeOutMagicIDEx );
		LB_OnAttackReboundMagic->Text =  SearchObjName( TempObj->GameData.MagicBase.OnAttackReboundMagicID );
		LB_OnMagicAttackReboundMagic->Text =  SearchObjName( TempObj->GameData.MagicBase.OnMagicAttackReboundMagicID );
		LB_OnDeadMagic->Text = SearchObjName( TempObj->GameData.MagicBase.OnDeadMagicID );
		LB_OnKillMagic->Text = SearchObjName( TempObj->GameData.MagicBase.OnKillMagicID );
		LB_OnSpecialMagic->Text = SearchObjName( TempObj->GameData.MagicBase.OnSpecialMagicID );

		GB_SpecialMagic->Show();
	}
	else
		GB_SpecialMagic->Hide();

	if( TempObj->GameData.MagicBase.Effect.Ride == true )
		GB_Ride->Show();
	else
		GB_Ride->Hide();

	if(		TempObj->GameData.MagicBase.Setting.OnPlayerAttackAddTime == true 
		||	TempObj->GameData.MagicBase.Setting.OnKillAddTime == true )
		GB_AddBuffTime->Show();
	else
		GB_AddBuffTime->Hide();

	if( TempObj->GameData.MagicBase.Effect.ChangeMotion == true )
		GB_ChangeMotion->Show();
	else
		GB_ChangeMotion->Hide();


	if( TempObj->GameData.MagicBase.Setting.MagicShield == true )
	{
		GB_MagicShield->Show();
	
		switch( TempObj->GameData.MagicBase.MagicShield.Type )
		{
		case EM_MagicShieldType_MP:			//MP抵消HP
			LB_MagicShieldPont->Hide();
			TB_MagicShieldPont->Hide();
			break;
		case EM_MagicShieldType_Times:		//抵消次數
			LB_MagicShieldPont->Text = S"次數";
			LB_MagicShieldPont->Show();
			TB_MagicShieldPont->Show();
			break;
		case EM_MagicShieldType_Point:		//抵消法數設定的點數
			LB_MagicShieldPont->Text = S"點數";
			LB_MagicShieldPont->Show();
			TB_MagicShieldPont->Show();
			break;
		case EM_MagicShieldType_Percent:	//抵消法數設定的點數
			LB_MagicShieldPont->Text = S"百分比";
			LB_MagicShieldPont->Show();
			TB_MagicShieldPont->Show();
			break;
		}
	}
	else
		GB_MagicShield->Hide();

	LB_MI_SummonObj->Text = SearchObjName( TempObj->GameData.MagicBase.ItemRunPlot.ObjID );
	LB_MI_UseMagic->Text = SearchObjName( TempObj->GameData.MagicBase.ItemRunPlot.UseMagic );
	LB_MI_OnDeadMagic->Text = SearchObjName( TempObj->GameData.MagicBase.ItemRunPlot.OnDeadMagic );	


	if( TempObj->GameData.MagicBase.Setting.BuffSkill == true )
	{
		LB_BuffSkill1->Text = SearchObjName( TempObj->GameData.MagicBase.BuffSkill[0] );
		LB_BuffSkill2->Text = SearchObjName( TempObj->GameData.MagicBase.BuffSkill[1] );
		LB_BuffSkill3->Text = SearchObjName( TempObj->GameData.MagicBase.BuffSkill[2] );
		LB_BuffSkill4->Text = SearchObjName( TempObj->GameData.MagicBase.BuffSkill[3] );
		LB_BuffSkill5->Text = SearchObjName( TempObj->GameData.MagicBase.BuffSkill[4] );
		LB_BuffSkill6->Text = SearchObjName( TempObj->GameData.MagicBase.BuffSkill[5] );

		GB_BuffSkill->Show();
	}
	else
	{
		GB_BuffSkill->Hide();
	}
/*
	LB_SC_SummonObjName->Text = SearchObjName( TempObj->GameData.MagicBase.SummonCreature.ObjID );
	LB_SC_SkillKeyItem1->Text = SearchObjName( TempObj->GameData.MagicBase.SummonCreature.Skill[0].KeyItemID );
	LB_SC_SkillKeyItem2->Text = SearchObjName( TempObj->GameData.MagicBase.SummonCreature.Skill[1].KeyItemID );
	LB_SC_SkillKeyItem3->Text = SearchObjName( TempObj->GameData.MagicBase.SummonCreature.Skill[2].KeyItemID );
	LB_SC_SkillKeyItem4->Text = SearchObjName( TempObj->GameData.MagicBase.SummonCreature.Skill[3].KeyItemID );
	LB_SC_SkillKeyItem5->Text = SearchObjName( TempObj->GameData.MagicBase.SummonCreature.Skill[4].KeyItemID );

	LB_SC_SkillID1->Text = SearchObjName( TempObj->GameData.MagicBase.SummonCreature.Skill[0].SkillID );
	LB_SC_SkillID2->Text = SearchObjName( TempObj->GameData.MagicBase.SummonCreature.Skill[1].SkillID );
	LB_SC_SkillID3->Text = SearchObjName( TempObj->GameData.MagicBase.SummonCreature.Skill[2].SkillID );
	LB_SC_SkillID4->Text = SearchObjName( TempObj->GameData.MagicBase.SummonCreature.Skill[3].SkillID );
	LB_SC_SkillID5->Text = SearchObjName( TempObj->GameData.MagicBase.SummonCreature.Skill[4].SkillID );
*/

	if( TempObj->GameData.MagicBase.IsStandard_Attack == true )
	{
		Panel_AttackStandard->Show();
		Panel_AttackNormal->Hide();

		int		Lv = TempObj->GameData.MagicBase.RefPowerLv_Attack -1 ;
		if( Lv <= 0  )
			Lv = 0;
		if( Lv >= Global::BaseMagicPower.size() )
			Lv = Global::BaseMagicPower.size() -1;

		TB_AttackPower->Text = String::Format( "{0}" , __box( Global::BaseMagicPower[Lv*0.5]* TempObj->GameData.MagicBase.RefPowerRate_Attack ) );
		TB_AttackGrowRate->Text = String::Format( "{0}" , __box( Global::MagicPowerGrowRate[Lv] ) );
	}
	else
	{
		Panel_AttackStandard->Hide();
		Panel_AttackNormal->Show();
	}

	if( TempObj->GameData.MagicBase.SummonCreature.Type == EM_MagicSummonCreatureType_Pet )
	{
		LB_SCGroupID->Hide();
		CB_SCGroupID->Hide();
	}
	else
	{
		LB_SCGroupID->Show();
		CB_SCGroupID->Show();
	}
}
//######################################################################################################
System::Void MagicBaseForm::ColdownClassChange(System::Object*  sender, System::EventArgs*  e) 
{/*
	int ClassID = CB_ColdownClass->SelectedIndex;
	int TypeID = CB_ColdownType->SelectedIndex;

	CB_ColdownType->Items->Clear();

	switch( ClassID )
	{
	case EM_MagicColdownClass_None	:		//沒有
		CB_ColdownType->Items->Add( S"無" );
		break;
	case EM_MagicColdownClass_Job	:		//職業類型
		CB_ColdownType->Items->Add( S"大絕-1" );
		CB_ColdownType->Items->Add( S"大絕-2" );
		CB_ColdownType->Items->Add( S"大絕-3" );
		CB_ColdownType->Items->Add( S"瞬發 攻擊-1" );
		CB_ColdownType->Items->Add( S"一般 攻擊-2" );
		CB_ColdownType->Items->Add( S"瞬發 加血-3" );
		CB_ColdownType->Items->Add( S"緩回 加血-4" );
		CB_ColdownType->Items->Add( S"一般-5" );
		CB_ColdownType->Items->Add( S"一般-6" );
		CB_ColdownType->Items->Add( S"一般-7" );
		CB_ColdownType->Items->Add( S"一般-8" );
		CB_ColdownType->Items->Add( S"一般-9" );
		CB_ColdownType->Items->Add( S"一般-10" );
		break;
	case EM_MagicColdownClass_EQ	:		//裝備類型
		CB_ColdownType->Items->Add( S"頭" );
		CB_ColdownType->Items->Add( S"手套" );
		CB_ColdownType->Items->Add( S"鞋子" );
		CB_ColdownType->Items->Add( S"上衣" );
		CB_ColdownType->Items->Add( S"褲子" );
		CB_ColdownType->Items->Add( S"背部" );
		CB_ColdownType->Items->Add( S"腰帶" );
		CB_ColdownType->Items->Add( S"肩甲" );
		CB_ColdownType->Items->Add( S"項鍊" );
		CB_ColdownType->Items->Add( S"戒子" );
		CB_ColdownType->Items->Add( S"耳飾" );
		CB_ColdownType->Items->Add( S"武器" );

		break;
	case EM_MagicColdownClass_Item	:		//物品類型
		CB_ColdownType->Items->Add( S"食物-1" );
		CB_ColdownType->Items->Add( S"食物-2" );
		CB_ColdownType->Items->Add( S"食物-3" );
		CB_ColdownType->Items->Add( S"藥水-1" );
		CB_ColdownType->Items->Add( S"藥水-2" );
		CB_ColdownType->Items->Add( S"藥水-3" );
		CB_ColdownType->Items->Add( S"其他" );
		break;
	}
	if( CB_ColdownType->Items->Count > TypeID )
		CB_ColdownType->SelectedIndex = TypeID;
	else
		CB_ColdownType->SelectedIndex = 0;
	GetIndex_SelectedIndexChanged( sender , e );
	*/
}

