#include "CardForm.h"


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

	Reload_AttrTable();
	//設定種族職業資訊
	if( FirstTime  == false )
		return;

	SqlDataReader* myReader;

	sqlCommand_Base->CommandText = "Select ID , Name from FightArg where Type = 0";
	myReader = sqlCommand_Base->ExecuteReader();

	CB_RefRace->Items->Add( (String*)"---" );
	while( myReader->Read())
	{
		String* Str =  myReader->GetString( 1 ) ;
		CB_RefRace->Items->Add(Str);
	}
	myReader->Close();

	BaseForm::OnActive();

}
void    CardForm::OnSelectObj( bool LockOk )
{
    _ObjDB.GameData.Classification = EM_ObjectClass_Item;
	_ObjDB.GameData.Item.Class = EM_Item_Card;
	_ObjDB.GameData.PricesType	= EM_ACPriceType_GameMoney;

	LB_AddpowerName->Text = SearchObjName( _ObjDB.GameData.Item.CardAddpower );
//    panel1->Enabled = LockOk;
	
	sqlCommand_Base->CommandText = String::Format( "Select Race ,Sex, Level from NPCObjectDB Where GUID = {0}", __box( _ObjDB.GameData.Item.CardOrgObjID ) );
	SqlDataReader* myReader= sqlCommand_Base->ExecuteReader();
	if( myReader->Read())
	{
		//String* Str =  myReader->GetString( 1 ) ;
		//CB_RefRace->Items->Add(Str);
		CB_RefRace->SelectedIndex = myReader->GetInt32( 0 ) +1;
		CB_RefSex->SelectedIndex = myReader->GetInt32( 1 ) +1;
		CB_RefLv->Text = String::Format( "{0}" , __box( myReader->GetInt32( 2 ) ) );
	}
	else
	{
		CB_RefRace->SelectedIndex = 0;
		CB_RefSex->SelectedIndex = 0;
		CB_RefLv->Text = "---";
	}
	myReader->Close();
}
//輸出時額外設定
void    CardForm::OnOutputObjSetting( DB_GameObjDbStruct* TempObj )
{
    TempObj->GameData.Classification = EM_ObjectClass_Item;
	TempObj->GameData.Item.Class = EM_Item_Card;
	TempObj->GameData.Item.ItemType = EM_ItemType_Normal;
//	TempObj->GameData.MaxHeap = 1;
	TempObj->GameData.Item.CastingTime = 2;
	TempObj->GameData.LiveTimeType = EM_ItemLiveTimeType_None;
	TempObj->GameData.Item.SelectBaseAttrCount = 0;
	TempObj->GameData.PricesType	= EM_ACPriceType_GameMoney;
	TempObj->GameData.Item.iFurnitureStorageSize = 0;
	TempObj->GameData.Item.Level = 1;
	TempObj->GameData.Item.BodyMaxCount = 0;

	memset( &TempObj->GameData.Limit , 0 , sizeof( TempObj->GameData.Limit ) );
	TempObj->GameData.Limit.Level = 1;
	

	TempObj->GameData.ItemEqType._Skill = 0;
	//設定拍賣類別
	TempObj->GameData.ACSearchType[0] = _DEF_ACSEARCHTYPE_CARD;
	TempObj->GameData.ACSearchType[1] = _DEF_ACSEARCHTYPE_EMPTY;
	TempObj->GameData.ACSearchType[2] = _DEF_ACSEARCHTYPE_EMPTY;

	//標準價計算
	if(		TempObj->GameData.Item.IsStandardCost 
		&&	TempObj->GameData.PricesType == EM_ACPriceType_GameMoney )
	{
		int RLv = TempObj->GameData.Item.ReferenceLv;
		if( RLv > 200 )
			RLv = 200;
		if( RLv <= 1 )
			RLv = 1;
		float	StandardCost = float( RoleDataEx::StandardCostTable[ RLv -1 ] ) /10;

		TempObj->GameData.Cost = StandardCost;
		//TempObj->GameData.Cost = DotNetStr::StringToInt( TB_StandardCost->Text );
	}
	TempObj->GameData.Mode.Sell = true;
	TempObj->GameData.Mode.PickupBound = false;
}

void    CardForm::OnTimeProc()
{
    
}
int     CardForm::ObjSize(  )
{
    GameObjDbStruct *P = NULL;
    int Size = sizeof( GameObjDbStruct ) - sizeof( P->Temp ) +  sizeof( P->Item ) + 3;
    Size = Size & 0xfffffC;
    return Size;
}
void    CardForm::OnValueChange()
{
    DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
    LB_CardOrgObj->Text = SearchObjName( TempObj->GameData.Item.CardOrgObjID ); 

	//-----------------------------------------------------
	//標準價計算
	int RLv = DotNetStr::StringToInt( TB_ReferenceLv->Text );
	if( RLv > 200 )
		RLv = 200;
	if( RLv <= 1 )
		RLv = 1;
	float	StandardCost = float( RoleDataEx::StandardCostTable[ RLv -1 ] ) /10;

	TB_StandardCost->Text = String::Format( "{0}" , __box( int( StandardCost+0.5 ) ) );	

	if(		TempObj->GameData.Item.IsStandardCost 
		&&	TempObj->GameData.PricesType == EM_ACPriceType_GameMoney )
	{
		TB_Cost->Enabled = false;
	}
	else
	{
		TB_Cost->Enabled = true;
	}
}


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

