#include "MineForm.h"
#include <stdio.h>
using namespace ObjDataEdit;
//######################################################################################################
//主要需要繼承的涵式
ReaderClass< DB_GameObjDbStruct >* MineForm::ObjReader( )
{
	return GameObjDbStructEx::ObjReader_Mine( );
}
void    MineForm::OnActive()
{
    static bool FirstTime = true;

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

	BaseForm::OnActive();

    FirstTime = false;

    SqlDataReader* myReader;

    sqlCommand_Base->CommandText = "Select GUID , Name from Table_ZoneDB";
    myReader = sqlCommand_Base->ExecuteReader();
    CB_Zone1->Items->Clear();
    CB_Zone2->Items->Clear();
    CB_Zone3->Items->Clear();

    System::Object* AddItem[] = new System::Object*[1];
    String* Str = "0 無";
    AddItem[0] = Str;
    CB_Zone1->Items->AddRange(AddItem);
    CB_Zone2->Items->AddRange(AddItem);
    CB_Zone3->Items->AddRange(AddItem);

    while( myReader->Read())
    {                
        int     Value =  myReader->GetInt32( 0 );
        String* Str   =  myReader->GetString( 1 );

        Str = String::Format( "{0} {1}", __box( Value ) , Str );
        System::Object* AddItem[] = new System::Object*[1];
        AddItem[0] = Str;
        CB_Zone1->Items->AddRange(AddItem);
        CB_Zone2->Items->AddRange(AddItem);
        CB_Zone3->Items->AddRange(AddItem);
    }
    myReader->Close();
}
void    MineForm::OnSelectObj( bool LockOk )
{
    _ObjDB.GameData.Classification = EM_ObjectClass_Mine;
//    panel1->Enabled = LockOk;
}
//輸出時額外設定
void    MineForm::OnOutputObjSetting( DB_GameObjDbStruct* TempObj )
{
    TempObj->GameData.Classification = EM_ObjectClass_Mine;
}
void    MineForm::OnTimeProc( )
{
    DB_GameObjDbStruct __pin * TempObj = &_ObjDB;

    if( _IsValueChange == false )
        return;

    _IsValueChange = false;

    char Buf[256];

	// 一般採集物品
	//-----------------------------------------------------------------------------------
		sprintf( Buf , "%.2f%%" , float( TempObj->GameData.Mine.GetItemRate[0] ) / 100 );
		LB_ItemRate1->Text = Buf;
		sprintf( Buf , "%.2f%%" , float( TempObj->GameData.Mine.GetItemRate[1] ) / 100 );
		LB_ItemRate2->Text = Buf;
		sprintf( Buf , "%.2f%%" , float( TempObj->GameData.Mine.GetItemRate[2] ) / 100 );
		LB_ItemRate3->Text = Buf;
		sprintf( Buf , "%.2f%%" , float( TempObj->GameData.Mine.GetItemRate[3] ) / 100 );
		LB_ItemRate4->Text = Buf;
		sprintf( Buf , "%.2f%%" , float( TempObj->GameData.Mine.GetItemRate[4] ) / 100 );
		LB_ItemRate5->Text = Buf;
		sprintf( Buf , "%.2f%%" , float( TempObj->GameData.Mine.GetItemRate[5] ) / 100 );
		LB_ItemRate6->Text = Buf;
		sprintf( Buf , "%.2f%%" , float( TempObj->GameData.Mine.GetItemRate[6] ) / 100 );
		LB_ItemRate7->Text = Buf;

		// 總機率
		int iTotalRate = 0;
		for( int i = 0; i < 5; i++ )
		{
			iTotalRate += TempObj->GameData.Mine.GetItemRate[ i ];
		}
		sprintf( Buf , "%.2f%%" , float( iTotalRate ) / 100 );
		LB_ItemRateTotal->Text = Buf;

	// 檢查日產量
	//----------------------------------------------------------------------------------------
		if( TempObj->GameData.MaxWorldCount == 0 )
		{
			strcpy( Buf, "無上限" );
		}
		else
		{
			sprintf( Buf, "%.2f" , (float)86400 / (float)TempObj->GameData.GenerateRate );
		}

		LB_DailyGenerateRate->Text = Buf;

		LB_Item1->Text		= SearchObjName( TempObj->GameData.Mine.GetItem[0] );
		LB_Item2->Text		= SearchObjName( TempObj->GameData.Mine.GetItem[1] );
		LB_Item3->Text		= SearchObjName( TempObj->GameData.Mine.GetItem[2] );
		LB_Item4->Text		= SearchObjName( TempObj->GameData.Mine.GetItem[3] );
		LB_Item5->Text		= SearchObjName( TempObj->GameData.Mine.GetItem[4] );
		LB_Item6->Text		= SearchObjName( TempObj->GameData.Mine.GetItem[5] );
		LB_Item7->Text		= SearchObjName( TempObj->GameData.Mine.GetItem[6] );
		LB_FLAGNAME->Text	= SearchObjName( TempObj->GameData.Mine.iFlagID );


	// 重生物件, 物件名稱
	//----------------------------------------------------------------------------------------
		labelgenobj1->Text	= SearchObjName( TempObj->GameData.Mine.iGenerateObj[0] );
		labelgenobj2->Text	= SearchObjName( TempObj->GameData.Mine.iGenerateObj[1] );
		labelgenobj3->Text	= SearchObjName( TempObj->GameData.Mine.iGenerateObj[2] );
		labelgenobj4->Text	= SearchObjName( TempObj->GameData.Mine.iGenerateObj[3] );
		labelgenobj5->Text	= SearchObjName( TempObj->GameData.Mine.iGenerateObj[4] );


		sprintf( Buf , "%.2f%%" , float( TempObj->GameData.Mine.iGenerateObjRate[0] ) / 100 );
		labelgenobjrate1->Text = Buf;
		sprintf( Buf , "%.2f%%" , float( TempObj->GameData.Mine.iGenerateObjRate[1] ) / 100 );
		labelgenobjrate2->Text = Buf;
		sprintf( Buf , "%.2f%%" , float( TempObj->GameData.Mine.iGenerateObjRate[2] ) / 100 );
		labelgenobjrate3->Text = Buf;
		sprintf( Buf , "%.2f%%" , float( TempObj->GameData.Mine.iGenerateObjRate[3] ) / 100 );
		labelgenobjrate4->Text = Buf;
		sprintf( Buf , "%.2f%%" , float( TempObj->GameData.Mine.iGenerateObjRate[4] ) / 100 );
		labelgenobjrate5->Text = Buf;

		// 總機率
		{
			int iTotalRate = 0;
			for( int i = 0; i < 5; i++ )
			{
				iTotalRate += TempObj->GameData.Mine.iGenerateObjRate[ i ];
			}
			sprintf( Buf , "%.2f%%" , float( iTotalRate ) / 100 );
			labelgenobjratetotal->Text = Buf;
		}


	// 挖完消失的提示
	//----------------------------------------------------------------------------------------
		if( TempObj->GameData.Mine.CreateType == 0 )
		{
			sprintf( Buf , "單位產生率(秒)" );
			label19->Text					= Buf;
			label6->Visible					= true;
			LB_DailyGenerateRate->Visible	= true;
			label37->Visible				= true;
			CB_MaxGenerate->Visible			= true;
		}
		else
		{
			sprintf( Buf , "重生時間(秒)" );
			label19->Text					= Buf;
			label6->Visible					= false;
			LB_DailyGenerateRate->Visible	= false;
			label37->Visible				= false;
			CB_MaxGenerate->Visible			= false;
		}




		
}
void    MineForm::OnValueChange()
{
    _IsValueChange = true;
}

int     MineForm::ObjSize(  )
{
    //int Size = sizeof( GameObjDbStruct );    
	GameObjDbStruct *P = NULL;
	int Size = sizeof( GameObjDbStruct ) - sizeof( P->Temp ) +  sizeof( P->Mine ) + 3;
	Size = Size & 0xfffffC;

	return Size;
    return Size;
}
//######################################################################################################