#include "Global.h"

#include "NPCForm.h"


using namespace ObjDataEdit;

ReaderClass< DB_GameObjDbStruct >* NPCForm::ObjReader( )
{
	return GameObjDbStructEx::ObjReader_NPC( );
}


Void NPCForm::RandCreate(System::Object *  sender, System::EventArgs *  e)
{
    int StrR;
    int StaR;
    int IntR;
    int MndR;
    int AgiR;
    int Lv = _ObjDB.GameData.NPC.Level;

    StrR = rand()%( Lv / 5 + 1 );
    StaR = rand()%( Lv / 5 + 1 );
    IntR = rand()%( Lv / 5 + 1 );
    MndR = rand()%( Lv / 5 + 1 );
    AgiR = rand()%( Lv / 5 + 1 );

    switch( rand() % 10 )
    {
    case 0:
        StrR = rand()%( Lv + 1 );
        break;
    case 1:
        StaR = rand()%( Lv + 1 );
        break;
    case 2:
        IntR = rand()%( Lv + 1 );
        break;
    case 3:
        MndR = rand()%( Lv + 1 );
        break;
    case 4:
        AgiR = rand()%( Lv + 1 );
        break;
    case 5:
    case 6:
    case 7:
    case 8:
    case 9:
        StrR = rand()%( Lv / 2 + 1 );
        StaR = rand()%( Lv / 2 + 1 );
        IntR = rand()%( Lv / 2 + 1 );
        MndR = rand()%( Lv / 2 + 1 );
        AgiR = rand()%( Lv / 2 + 1 );
        break;
    }

    NUD_STR->Value = StrR;
    NUD_STA->Value = StaR;
    NUD_INT->Value = IntR;
    NUD_MND->Value = MndR;
    NUD_AGI->Value = AgiR;

}

void NPCForm::ReSetInValue( )
{
	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;

    RoleValueData* Value = &(Global::ValueCal);
	Value->Init_BaseEQValue();
	Value->Init_MidValue();

    //資料更新
    Value->Ability = &Global::Ability;

    Value->Race    = (Race_ENUM)_ObjDB.GameData.NPC.Race;
    Value->Voc     = (Voc_ENUM) _ObjDB.GameData.NPC.Vocation;
	Value->Voc_Sub = (Voc_ENUM) (_ObjDB.GameData.NPC.Vocation_Sub -1 );
    Value->Sex     = (Sex_ENUM) _ObjDB.GameData.NPC.Sex; 
    Value->Level	 = _ObjDB.GameData.NPC.Level;
	Value->Level_Sub = _ObjDB.GameData.NPC.Level;
    Value->Ability->STR = _ObjDB.GameData.NPC.STR;
    Value->Ability->STA = _ObjDB.GameData.NPC.STA;
    Value->Ability->INT = _ObjDB.GameData.NPC.INT;
    Value->Ability->MND = _ObjDB.GameData.NPC.MND;
    Value->Ability->AGI = _ObjDB.GameData.NPC.AGI;

	Value->SkillValue = &Value->MaxSkillValue;

	GameObjectWearEqStruct	Ability = TempObj->GameData.NPC.Ability;

	if( TempObj->GameData.NPC.IsAbilityStandard )
	{
		for( int i = 0 ; i < 10 ; i ++ )
		{
			Ability.EqTypeValue[i] += TempObj->GameData.NPC.DEqTypeValue[i];
		}
	}

    Value->ReSetTable( );
	Value->AddAbility_Buff( &(Ability) , 1 );
//	Value->AddAbility( &(TempObj->GameData.NPC.Ability[1]) );

    Value->Calculate( );

    int STR = max( 0 , int(Value->Ability->STR ));
    int STA = max( 0 , int(Value->Ability->STA ));
    int INT = max( 0 , int(Value->Ability->INT ));
    int MND = max( 0 , int(Value->Ability->MND ));
    int AGI = max( 0 , int(Value->Ability->AGI ));

    int Extra = _ObjDB.GameData.NPC.Level //* 3  
        - int(STR) 
        - int(STA) 
        - int(INT) 
        - int(MND) 
        - int(AGI) ;

    EDExtra->Text = String::Format( "{0}", __box(Extra) );

    StrP1->Text = String::Format( "{0}", __box(int(Value->Ability->STR) ));
    StaP1->Text = String::Format( "{0}", __box(int(Value->Ability->STA) ));
    IntP1->Text = String::Format( "{0}", __box(int(Value->Ability->INT) ));
    MndP1->Text = String::Format( "{0}", __box(int(Value->Ability->MND) ));
    AgiP1->Text = String::Format( "{0}", __box(int(Value->Ability->AGI) ));

    StrB1->Text = String::Format( "{0}", __box(int(Value->Bas.BaseStr) ));
    StaB1->Text = String::Format( "{0}", __box(int(Value->Bas.BaseSta) ));
    IntB1->Text = String::Format( "{0}", __box(int(Value->Bas.BaseInt) ));
    MndB1->Text = String::Format( "{0}", __box(int(Value->Bas.BaseMnd) ));
    AgiB1->Text = String::Format( "{0}", __box(int(Value->Bas.BaseAgi) ));

    StrT1->Text = String::Format( "{0}", __box(int(Value->Fin.STR) ));
    StaT1->Text = String::Format( "{0}", __box(int(Value->Fin.STA) ));
    IntT1->Text = String::Format( "{0}", __box(int(Value->Fin.INT) ));
    MndT1->Text = String::Format( "{0}", __box(int(Value->Fin.MND) ));
    AgiT1->Text = String::Format( "{0}", __box(int(Value->Fin.AGI) ));

    MaxHp->Text = String::Format( "{0}", __box(int(Value->Fin.MaxHP) ));
    MaxMp->Text = String::Format( "{0}", __box(int(Value->Fin.MaxMP) ));
    ATK->Text   = String::Format( "{0}", __box(int(Value->Fin.ATK) ));
    DMG->Text   = String::Format( "{0}", __box(int(Value->Fin.Main_DMG) ));
    DEF->Text   = String::Format( "{0}", __box(int(Value->Fin.DEF) ));
//    ABR->Text   = String::Format( "{0}", __box(int(Value->Fin.Abr*100) ));
//    AB->Text    = String::Format( "{0}", __box(int(Value->Fin.AB) ));
    HitRate->Text   = String::Format( "{0}", __box(int(Value->Fin.HitRate) ));
    Dodge->Text = String::Format( "{0}", __box(int(Value->Fin.DodgeRate) ));
    ReHp->Text  = String::Format( "{0}", __box(int(Value->Fin.ReHP) ));
    ReMP->Text  = String::Format( "{0}", __box(int(Value->Fin.ReMP) ));
    MAtk->Text  = String::Format( "{0}", __box(int(Value->Fin.MATK) ));
    MDef->Text  = String::Format( "{0}", __box(int(Value->Fin.MDEF) ));
	tb_AtkSpeed->Text  = String::Format( "{0:0.00}", __box(Value->Fin.Main_ATKSpeed ));

}

void NPCForm::ReSetDropItem( )
{
    DB_GameObjDbStruct __pin * TempObj = &_ObjDB;

    //ItemDropStruct DropItem[ _MAX_DROPITEM_COUNT_ ];
    /*
    if( memcmp( &DropItem , TempObj->GameData.NPC.DropItem , sizeof( DropItem ) ) == 0 )
        return;
*/
    //memcpy(  &DropItem , TempObj->GameData.NPC.DropItem , sizeof( DropItem ) );

	ItemDropStruct* DropItem = TempObj->GameData.NPC.DropItem;

    char Buf[256];
    sprintf( Buf , "%.3f%%" , float( DropItem[0].Rate ) / 1000 );
    DropRate1_Ex->Text = Buf;
    sprintf( Buf , "%.3f%%" , float( DropItem[1].Rate ) / 1000 );
    DropRate2_Ex->Text = Buf;
    sprintf( Buf , "%.3f%%" , float( DropItem[2].Rate ) / 1000 );
    DropRate3_Ex->Text = Buf;
    sprintf( Buf , "%.3f%%" , float( DropItem[3].Rate ) / 1000 );
    DropRate4_Ex->Text = Buf;
    sprintf( Buf , "%.3f%%" , float( DropItem[4].Rate ) / 1000 );
    DropRate5_Ex->Text = Buf;
    sprintf( Buf , "%.3f%%" , float( DropItem[5].Rate ) / 1000 );
    DropRate6_Ex->Text = Buf;
    sprintf( Buf , "%.3f%%" , float( DropItem[6].Rate ) / 1000 );
    DropRate7_Ex->Text = Buf;
    sprintf( Buf , "%.3f%%" , float( DropItem[7].Rate ) / 1000 );
    DropRate8_Ex->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropItem[8].Rate ) / 1000 );
	DropRate9_Ex->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropItem[9].Rate ) / 1000 );
	DropRate10_Ex->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropItem[10].Rate ) / 1000 );
	DropRate11_Ex->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropItem[11].Rate ) / 1000 );
	DropRate12_Ex->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropItem[12].Rate ) / 1000 );
	DropRate13_Ex->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropItem[13].Rate ) / 1000 );
	DropRate14_Ex->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropItem[14].Rate ) / 1000 );
	DropRate15_Ex->Text = Buf;


    DropName1->Text = SearchObjName( DropItem[0].OrgID );
    DropName2->Text = SearchObjName( DropItem[1].OrgID );
    DropName3->Text = SearchObjName( DropItem[2].OrgID );
    DropName4->Text = SearchObjName( DropItem[3].OrgID );
    DropName5->Text = SearchObjName( DropItem[4].OrgID );
    DropName6->Text = SearchObjName( DropItem[5].OrgID );
    DropName7->Text = SearchObjName( DropItem[6].OrgID );
    DropName8->Text = SearchObjName( DropItem[7].OrgID );
	DropName9->Text = SearchObjName( DropItem[8].OrgID );
	DropName10->Text = SearchObjName( DropItem[9].OrgID );
	DropName11->Text = SearchObjName( DropItem[10].OrgID );
	DropName12->Text = SearchObjName( DropItem[11].OrgID );
	DropName13->Text = SearchObjName( DropItem[12].OrgID );
	DropName14->Text = SearchObjName( DropItem[13].OrgID );
	DropName15->Text = SearchObjName( DropItem[14].OrgID );


	ItemDropStruct* DropAbility = TempObj->GameData.NPC.DropItemAbility;
	sprintf( Buf , "%.3f%%" , float( DropAbility[0].Rate ) / 1000 );
	DropAbilityEx1->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropAbility[1].Rate ) / 1000 );
	DropAbilityEx2->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropAbility[2].Rate ) / 1000 );
	DropAbilityEx3->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropAbility[3].Rate ) / 1000 );
	DropAbilityEx4->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropAbility[4].Rate ) / 1000 );
	DropAbilityEx5->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( DropAbility[5].Rate ) / 1000 );
	DropAbilityEx6->Text = Buf;

	DropAbilityName1->Text = SearchObjName( DropAbility[0].OrgID );
	DropAbilityName2->Text = SearchObjName( DropAbility[1].OrgID );
	DropAbilityName3->Text = SearchObjName( DropAbility[2].OrgID );
	DropAbilityName4->Text = SearchObjName( DropAbility[3].OrgID );
	DropAbilityName5->Text = SearchObjName( DropAbility[4].OrgID );
	DropAbilityName6->Text = SearchObjName( DropAbility[5].OrgID );


}

void NPCForm::ReSetMagic( )
{
    DB_GameObjDbStruct __pin * TempObj = &_ObjDB;


    LB_SpellMagic1->Text     = SearchObjName( TempObj->GameData.NPC.Spell[0].MagicID );
    LB_SpellMagic2->Text     = SearchObjName( TempObj->GameData.NPC.Spell[1].MagicID );
    LB_SpellMagic3->Text     = SearchObjName( TempObj->GameData.NPC.Spell[2].MagicID );
    LB_SpellMagic4->Text     = SearchObjName( TempObj->GameData.NPC.Spell[3].MagicID );
    LB_SpellMagic5->Text     = SearchObjName( TempObj->GameData.NPC.Spell[4].MagicID );
    LB_SpellMagic6->Text     = SearchObjName( TempObj->GameData.NPC.Spell[5].MagicID );
    LB_SpellMagic7->Text     = SearchObjName( TempObj->GameData.NPC.Spell[6].MagicID );
    LB_SpellMagic8->Text     = SearchObjName( TempObj->GameData.NPC.Spell[7].MagicID );
    

}
void    NPCForm::ReSetWearEQ( )
{
    DB_GameObjDbStruct __pin * TempObj = &_ObjDB;
    static int MainEQ[_MAX_NPC_EQSEL_COUNT_] = { -1,-1,-1,-1,-1 };
    static int SecEQ[_MAX_NPC_EQSEL_COUNT_] = { -1,-1,-1,-1,-1 };
/*
    if(     memcmp( MainEQ , TempObj->GameData.NPC.MainHandEQ , sizeof( MainEQ ) ) == 0 
        &&  memcmp( SecEQ  , TempObj->GameData.NPC.SecHandEQ  , sizeof( SecEQ ) ) == 0    )
        return;
*/
    memcpy( MainEQ , TempObj->GameData.NPC.MainHandEQ , sizeof( MainEQ ) );
    memcpy( SecEQ  , TempObj->GameData.NPC.SecHandEQ  , sizeof( SecEQ )  );

    MainHandEq1->Text = SearchObjName( MainEQ[0] );
    MainHandEq2->Text = SearchObjName( MainEQ[1] );
    MainHandEq3->Text = SearchObjName( MainEQ[2] );
    MainHandEq4->Text = SearchObjName( MainEQ[3] );
    MainHandEq5->Text = SearchObjName( MainEQ[4] );

    SecHandEq1->Text = SearchObjName( SecEQ[0] );
    SecHandEq2->Text = SearchObjName( SecEQ[1] );
    SecHandEq3->Text = SearchObjName( SecEQ[2] );
    SecHandEq4->Text = SearchObjName( SecEQ[3] );
    SecHandEq5->Text = SearchObjName( SecEQ[4] );

	BowEQ->Text = SearchObjName( TempObj->GameData.NPC.BowEQ );
	LB_OrnamentEQ->Text = SearchObjName( TempObj->GameData.NPC.OrnamentEQ );
}

void    NPCForm::OnOutputObjSetting( DB_GameObjDbStruct* TempObj )
{
    TempObj->GameData.Classification = EM_ObjectClass_NPC;

	if( NpcResistInfoList->size()  == 0 )
		return;

	if( TempObj->GameData.NPC.DB_ResistID >=  (int)NpcResistInfoList->size() )
	{
		TempObj->GameData.NPC.DB_ResistID = 0;
	}

	if( TempObj->GameData.NPC.ZoneID_Bk != -1 )
		TempObj->GameData.NPC.ZoneID = TempObj->GameData.NPC.ZoneID_Bk;

	NpcResistBaseInfoStruct& NpcResistTemp = (*NpcResistInfoList)[ TempObj->GameData.NPC.DB_ResistID ];
	TempObj->GameData.NPC.ResistType = NpcResistTemp.Type;
	TempObj->GameData.NPC.Resist	 = NpcResistTemp.Resist;
	TempObj->GameData.NPC.Vocation_Sub -= 1;
//	TempObj->GameData.NPC.Ability[1].OnAttackMagicID = 0;
//	TempObj->GameData.NPC.Ability[1].OnAttackMagicRank = 0;
//	TempObj->GameData.NPC.Ability[1].OnAttackMagicRate = 0;
	TempObj->GameData.NPC.Effect._Value[0] = TempObj->GameData.NPC.Effect._Value[0] ^ 0xffffffff;
	TempObj->GameData.NPC.Effect._Value[1] = 0;

	TempObj->GameData.NPC.KillGroupID--;
	

//	ZeroMemory( TempObj->GameData.NPC.pQuestLink, sizeof( TempObj->GameData.NPC.pQuestLink ) );

	for( int i = 0 ; i < _MAX_NPC_AVOID_MAGIC_TYPE_COUNT_ ; i++ )
	{
		
		TempObj->GameData.NPC.AvoidMagicType[i] = (GameObjectMagicTypeENUM)(TempObj->GameData.NPC.AvoidMagicType[i]-1);
	}

	//////////////////////////////////////////////////////////////////////////
	//ｎｐｃ能力標準化
	//////////////////////////////////////////////////////////////////////////
	NPCAbilityNormalize( TempObj );

	if( TempObj->GameData.NPC.IsAbilityStandard )
	{
		for( int i = 0 ; i < 10 ; i++ )
			TempObj->GameData.NPC.Ability.EqTypeValue[i] += TempObj->GameData.NPC.DEqTypeValue[i];
	}
	//////////////////////////////////////////////////////////////////////////
	if( TempObj->GameData.NPC.IsShowNpcPos == false )
	{
		TempObj->GameData.NPC.ZoneID = -1;
		TempObj->GameData.NPC.X = 0;
		TempObj->GameData.NPC.Y = 0;
		TempObj->GameData.NPC.Z = 0;
	}


	TempObj->GameData.NPC.iTagID	= TempObj->TagID;

	ZeroMemory( TempObj->GameData.NPC.iQuestLinkObj, sizeof( TempObj->GameData.NPC.iQuestLinkObj ) );

	// 設定連結關希
	map< int, set< int > >::iterator it = _mapQuestLink->find( TempObj->GameData.GUID );
	if( it != _mapQuestLink->end() )
	{
		int iCount = 0;
		for( set< int >::iterator itQuest = it->second.begin(); itQuest != it->second.end(); itQuest++ )
		{
			if( iCount < _MAX_QUESTLINK_COUNT )
			{
				TempObj->GameData.NPC.iQuestLinkObj[ iCount ] = *itQuest;
				iCount++;
			}
		}
	}

//	AfterUpdateObj(TempObj);
}

void	NPCForm::NPCAbilityNormalize( DB_GameObjDbStruct* TempObj )
{
	//DB_GameObjDbStruct __pin * TempObj = &_ObjDB;

	//////////////////////////////////////////////////////////////////////////
	//ｎｐｃ能力標準化
	//////////////////////////////////////////////////////////////////////////
	if( TempObj->GameData.NPC.IsAbilityStandard )
	{
		TempObj->GameData.NPC.Ability.EqType[0] = (WearEqTypeENUM)CB_AbilityList11->SelectedIndex;
		TempObj->GameData.NPC.Ability.EqType[1] = (WearEqTypeENUM)CB_AbilityList12->SelectedIndex;
		TempObj->GameData.NPC.Ability.EqType[2] = (WearEqTypeENUM)CB_AbilityList13->SelectedIndex;
		TempObj->GameData.NPC.Ability.EqType[3] = (WearEqTypeENUM)CB_AbilityList14->SelectedIndex;
		TempObj->GameData.NPC.Ability.EqType[4] = (WearEqTypeENUM)CB_AbilityList15->SelectedIndex;
		TempObj->GameData.NPC.Ability.EqType[5] = (WearEqTypeENUM)CB_AbilityList16->SelectedIndex;
		TempObj->GameData.NPC.Ability.EqType[6] = (WearEqTypeENUM)CB_AbilityList17->SelectedIndex;
		TempObj->GameData.NPC.Ability.EqType[7] = (WearEqTypeENUM)CB_AbilityList18->SelectedIndex;
		TempObj->GameData.NPC.Ability.EqType[8] = (WearEqTypeENUM)CB_AbilityList19->SelectedIndex;
		TempObj->GameData.NPC.Ability.EqType[9] = (WearEqTypeENUM)CB_AbilityList20->SelectedIndex;


		unsigned Type = TempObj->GameData.NPC.AbilityValue[0];
		unsigned LV  =  TempObj->GameData.NPC.AbilityValue[1] + TempObj->GameData.NPC.Level;

		if( Type < Global::NpcStrongArg.size() )
		{
			if( LV >= Global::NpcStrongArg[Type].Arg.size() )
				LV = Global::NpcStrongArg[Type].Arg.size() - 1;

			if( LV < Global::NpcStrongArg[Type].Arg.size() )
			{
				NPCStrongArgBase& Arg = Global::NpcStrongArg[Type].Arg[ LV ];

				for( int j = 0 ; j < 10 ; j++ )
				{
					TempObj->GameData.NPC.Ability.EqTypeValue[j] = Arg.Value[ j];
				}
			}
		}
	}
}

void    NPCForm::OnValueChange()
{
	DB_GameObjDbStruct __pin * TempObj = &_ObjDB;

	//////////////////////////////////////////////////////////////////////////
	//ｎｐｃ能力標準化
	//////////////////////////////////////////////////////////////////////////
	NPCAbilityNormalize( TempObj );
	//////////////////////////////////////////////////////////////////////////
	//設定是否用標準計算
	if( TempObj->GameData.NPC.IsAbilityStandard )
	{
		tabControl2->SelectedIndex = 1;
		//數值記算
		int Type = TempObj->GameData.NPC.AbilityValue[0];
		int LV  =  TempObj->GameData.NPC.AbilityValue[1] + TempObj->GameData.NPC.Level;

		if( Type < (int)Global::NpcStrongArg.size() && Type >= 0 )
		{
			if( LV < 0 )
				LV = 0;
			if( LV >= (int)Global::NpcStrongArg[Type].Arg.size() )
				LV = Global::NpcStrongArg[Type].Arg.size() - 1;

			if( LV >= 0 )
			{
				NPCStrongArgBase& Arg = Global::NpcStrongArg[Type].Arg[ LV ];
				NumUD_AbilityValue1->Value = Arg.Value[0];
				NumUD_AbilityValue2->Value = Arg.Value[1];
				NumUD_AbilityValue3->Value = Arg.Value[2];
				NumUD_AbilityValue4->Value = Arg.Value[3];
				NumUD_AbilityValue5->Value = Arg.Value[4];
				NumUD_AbilityValue6->Value = Arg.Value[5];
				NumUD_AbilityValue7->Value = Arg.Value[6];
				NumUD_AbilityValue8->Value = Arg.Value[7];
				NumUD_AbilityValue9->Value = Arg.Value[8];
				NumUD_AbilityValue10->Value = Arg.Value[9];
			}
		}
	}
	else
	{
		tabControl2->SelectedIndex = 0;
	}
	//////////////////////////////////////////////////////////////////////////

    ReSetInValue();
    ReSetDropItem();
    ReSetWearEQ();
    ReSetMagic( );

	//設定抗性
	if( NpcResistInfoList->size()  == 0 )
		return;

	if( TempObj->GameData.NPC.DB_ResistID >=  (int)NpcResistInfoList->size() )
	{
		TempObj->GameData.NPC.DB_ResistID = 0;
	}
	NpcResistBaseInfoStruct& NpcResistTemp = (*NpcResistInfoList)[ TempObj->GameData.NPC.DB_ResistID ];
	TempObj->GameData.NPC.ResistType = NpcResistTemp.Type;
	TempObj->GameData.NPC.Resist	 = NpcResistTemp.Resist;

	switch( NpcResistTemp.Type )
	{
	case EM_MagicResist_Earth:   
		TB_ResistType->Text = "地";
		break;
	case EM_MagicResist_Water:
		TB_ResistType->Text = "水";
		break;
	case EM_MagicResist_Fire:
		TB_ResistType->Text = "火";
		break;
	case EM_MagicResist_Wind:     
		TB_ResistType->Text = "風";
		break;
	case EM_MagicResist_Light:    
		TB_ResistType->Text = "光";
		break;
	case EM_MagicResist_Darkness:
		TB_ResistType->Text = "暗";
		break;
	}
	
	TB_Resist_Earth->Text	 = String::Format( "{0}" , __box( NpcResistTemp.Resist.Earth ) );
	TB_Resist_Water->Text	 = String::Format( "{0}" , __box( NpcResistTemp.Resist.Water ) );
	TB_Resist_Fire->Text	 = String::Format( "{0}" , __box( NpcResistTemp.Resist.Fire ) );
	TB_Resist_Wind->Text	 = String::Format( "{0}" , __box( NpcResistTemp.Resist.Wind ) );
	TB_Resist_Light->Text	 = String::Format( "{0}" , __box( NpcResistTemp.Resist.Light ) );
	TB_Resist_Darkness->Text = String::Format( "{0}" , __box( NpcResistTemp.Resist.Darkness ) );


	char Buf[256];
	sprintf( Buf , "%.3f%%" , float( TempObj->GameData.NPC.StealItem[0].Rate ) / 1000 );
	LB_StealRate1->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( TempObj->GameData.NPC.StealItem[1].Rate ) / 1000 );
	LB_StealRate2->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( TempObj->GameData.NPC.StealItem[2].Rate ) / 1000 );
	LB_StealRate3->Text = Buf;


	LB_StealItemName1->Text = SearchObjName( TempObj->GameData.NPC.StealItem[0].OrgID );
	LB_StealItemName2->Text = SearchObjName( TempObj->GameData.NPC.StealItem[1].OrgID );
	LB_StealItemName3->Text = SearchObjName( TempObj->GameData.NPC.StealItem[2].OrgID );


	sprintf( Buf , "%.3f%%" , float( TempObj->GameData.NPC.RaiseChangeRate[0]) / 1000 );
	LB_RaiseChangeRate1->Text = Buf;
	sprintf( Buf , "%.3f%%" , float( TempObj->GameData.NPC.RaiseChangeRate[1]) / 1000 );
	LB_RaiseChangeRate2->Text = Buf;


	LB_RaiseChangeNPCID1->Text = SearchObjName( TempObj->GameData.NPC.RaiseChangeNPCID[0] );
	LB_RaiseChangeNPCID2->Text = SearchObjName( TempObj->GameData.NPC.RaiseChangeNPCID[1] );


	//////////////////////////////////////////////////////////////////////////
	float TotalCost = 0;
	//價值計算
	for( int i = 0 ; i < _MAX_DROPITEM_COUNT_ ; i++ )
	{
		ItemDropStruct& Item = TempObj->GameData.NPC.DropItem[i];

		TotalCost = TotalCost + SearchObjCost( Item.OrgID ) * float( Item.Rate / 100000.0f );
	}

	int		RefernceCost =  0;
	int		LV = _ObjDB.GameData.NPC.Level;
	if( _ObjDB.GameData.NPC.Sex < EM_Sex_BigMonster )
	{
		RefernceCost = Global::MonsterMoney[ LV ][0] + Global::MonsterMoney[ LV ][1] / 2 ;
	}
	else
	{
		RefernceCost = Global::MonsterMoney[ LV ][0] + Global::MonsterMoney[ LV ][2] / 2 ;
	}
	RefernceCost*=3;
	int MonsterCost = int( TotalCost ) + _ObjDB.GameData.NPC.DropMoney_Base + _ObjDB.GameData.NPC.DropMoney_Rand/2;

	TB_MonstorCost->Text	= String::Format( "{0}" , __box( MonsterCost ) );
	TB_ReferenceCost->Text	= String::Format( "{0}/{1}" , __box( RefernceCost - MonsterCost ) , __box( RefernceCost ) );


}

void    NPCForm::OnActive()
{
    static bool FirstTime = true;

    Reload_AttrTable();

	//讀取怪物金錢表
	sqlCommand_Base->CommandText = "Select GUID , Base , Rand , Top_Rand from Table_MonsterMoney";
	SqlDataReader* myReader = sqlCommand_Base->ExecuteReader();

	while( myReader->Read())
	{
		int GUID = myReader->GetInt32( 0 );
		int Base = myReader->GetInt32( 1 );
		int Rand = myReader->GetInt32( 2 );
		int Top_Rand = myReader->GetInt32( 3 );

		Global::MonsterMoney[ GUID ][0] = Base;
		Global::MonsterMoney[ GUID ][1] = Rand;
		Global::MonsterMoney[ GUID ][2] = Top_Rand;
	}
	myReader->Close();

	//////////////////////////////////////////////////////////////////////////
	// 載入NPC標準值參數
	Global::NpcStrongArg.clear();
	NPCStrongArgStruct TempNPCStrongArg;
	NPCStrongArgBase TempArgBase;
	sqlCommand_Base->CommandText = "SELECT Name, Type, Lv, DMG, ATKRate, DEFRate, MDEFRate, AttackSpeed,MaxHPRate, MaxMPRate, ParryRate ,CritialRate ,DodgeRate  FROM Table_NPCStandardStrong";
	myReader = sqlCommand_Base->ExecuteReader();

	while( myReader->Read() )
	{          
		String* Name		= myReader->GetString(0);
		int		Type		= myReader->GetInt32(1);
		int		Lv			= myReader->GetInt32(2);
		TempArgBase.DMG			= myReader->GetInt32(3);
		TempArgBase.ATKRate		= myReader->GetInt32(4);
		TempArgBase.DEFRate		= myReader->GetInt32(5); 
		TempArgBase.MDEFRate	= myReader->GetInt32(6);
		TempArgBase.AttackSpeed	= myReader->GetInt32(7);
		TempArgBase.MaxHPRate	= myReader->GetInt32(8);
		TempArgBase.MaxMPRate	= myReader->GetInt32(9);
		TempArgBase.ParryRate	= myReader->GetInt32(10);
		TempArgBase.CriticalRate	= myReader->GetInt32(11);
		TempArgBase.DodgeRate	= myReader->GetInt32(12);

		while( Type >= (int)Global::NpcStrongArg.size() )
		{
			Global::NpcStrongArg.push_back( TempNPCStrongArg );
		}
		while( Lv >= (int)Global::NpcStrongArg[Type].Arg.size() )
		{
			Global::NpcStrongArg[Type].Arg.push_back( TempArgBase );
		}
		Global::NpcStrongArg[Type].Arg[Lv] = TempArgBase;
		Global::NpcStrongArg[Type].Type = Type;
		Global::NpcStrongArg[Type].Name = DotNetStr::StringToChar( Name );

	}
	myReader->Close();

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

	BaseForm::OnActive();

	FirstTime = false;

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

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

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

	CBox_VocationSub->Items->Clear();
	CBox_VocationSub->Items->Add( S"無" );
    while( myReader->Read())
    {
        String* Str =  myReader->GetString( 1 ) ;
        CBox_Vocation->Items->Add(Str);
		CBox_VocationSub->Items->Add(Str);
    }
    myReader->Close();

    for( int i = 1 ; i <= 200 ; i++ )
    {
        String* Str = String::Format( "{0}", __box( i ) );
        comboBox5->Items->Add(Str);
    }

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


    String* Str = "0 無";
    CB_Zone1->Items->Add(Str);
    CB_Zone2->Items->Add(Str);
    CB_Zone3->Items->Add(Str);

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

        Str = String::Format( "{0} {1}", __box( Value ) , Str );
        CB_Zone1->Items->Add(Str);
        CB_Zone2->Items->Add(Str);
        CB_Zone3->Items->Add(Str);
    }
    myReader->Close();

	//索敵範圍
    sqlCommand_Base->CommandText = "Select ID , Name from Table_String Where Type = '索敵範圍' ORDER BY  ID";
    myReader = sqlCommand_Base->ExecuteReader();
    CB_SearchRange->Items->Clear();
    while( myReader->Read() )
    {                
        int     Value =  myReader->GetInt32( 0 );
        String* Str   =  myReader->GetString( 1 );

        CB_SearchRange->Items->Add( Str );
    }

    myReader->Close();

    sqlCommand_Base->CommandText = "Select ID , Name from Table_String Where Type = '移動速度' ORDER BY  ID";
    myReader = sqlCommand_Base->ExecuteReader();
    CB_MoveSpeed->Items->Clear();
    while( myReader->Read() )
    {                
        int     Value =  myReader->GetInt32( 0 );
        String* Str   =  myReader->GetString( 1 );

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

	sqlCommand_Base->CommandText = "Select ID , Name from Table_String Where Type = '殺死計數' ORDER BY  ID";
	myReader = sqlCommand_Base->ExecuteReader();
	CB_KillGroup->Items->Clear();
	CB_KillGroup->Items->Add( S"----" );
	while( myReader->Read() )
	{                
		int     Value =  myReader->GetInt32( 0 );
		String* Str   =  myReader->GetString( 1 );

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

	//取得NPC抗性資料
	//*NpcResistInfo
	NpcResistBaseInfoStruct	NpcResistTemp;
	sqlCommand_Base->CommandText = "SELECT Name, ResistBase, Earth, Water, Fire, Wind, Light, Darkness FROM Table_NpcResistList";
	myReader = sqlCommand_Base->ExecuteReader();

	NpcResistInfoList->clear();
	CB_ResistID->Items->Clear();
	while( myReader->Read() )
	{                
		String* Str   =  myReader->GetString( 0 );
		CB_ResistID->Items->Add( Str );
		
		strcpy( NpcResistTemp.Name , DotNetStr::StringToChar( Str ).c_str() );

		Str = myReader->GetString( 1 ); 
			
		if( Str->Compare( Str , "地" ) == 0  )
			NpcResistTemp.Type = EM_MagicResist_Earth;
		else if( Str->Compare( Str , "水" ) == 0  )
			NpcResistTemp.Type = EM_MagicResist_Water;
		else if( Str->Compare( Str , "火" ) == 0  )
			NpcResistTemp.Type = EM_MagicResist_Fire;
		else if( Str->Compare( Str , "風" ) == 0  )
			NpcResistTemp.Type = EM_MagicResist_Wind;
		else if( Str->Compare( Str , "光" ) == 0  )
			NpcResistTemp.Type = EM_MagicResist_Light;
		else if( Str->Compare( Str , "暗" ) == 0  )
			NpcResistTemp.Type = EM_MagicResist_Darkness;
		else
			NpcResistTemp.Type = EM_MagicResist_None;

		NpcResistTemp.Resist.Earth		= float( myReader->GetInt32( 2 ) );
		NpcResistTemp.Resist.Water		= float( myReader->GetInt32( 3 ) );
		NpcResistTemp.Resist.Fire		= float( myReader->GetInt32( 4 ) );
		NpcResistTemp.Resist.Wind		= float( myReader->GetInt32( 5 ) );
		NpcResistTemp.Resist.Light		= float( myReader->GetInt32( 6 ) );
		NpcResistTemp.Resist.Darkness	= float( myReader->GetInt32( 7 ) );
		NpcResistInfoList->push_back( NpcResistTemp );
	}
	myReader->Close();



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

		CB_AvoidMagicType1->Items->Add( Str );
		CB_AvoidMagicType2->Items->Add( Str );
		CB_AvoidMagicType3->Items->Add( Str );
		CB_AvoidMagicType4->Items->Add( Str );
		CB_AvoidMagicType5->Items->Add( Str );
	}
	myReader->Close();

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

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

	
	CB_SearchGroupID->Items->Clear();
	sqlCommand_Base->CommandText = "Select ID , Name from Table_String Where Type = '企劃搜尋群組' ORDER BY  ID";
	myReader = sqlCommand_Base->ExecuteReader();
	while( myReader->Read() )
	{                
		int     Value =  myReader->GetInt32( 0 );
		String* Str   =  myReader->GetString( 1 );

		CB_SearchGroupID->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();
	CB_AbilityList6->Items->Clear();
	CB_AbilityList7->Items->Clear();
	CB_AbilityList8->Items->Clear();
	CB_AbilityList9->Items->Clear();
	CB_AbilityList10->Items->Clear();
	CB_AbilityList11->Items->Clear();
	CB_AbilityList12->Items->Clear();
	CB_AbilityList13->Items->Clear();
	CB_AbilityList14->Items->Clear();
	CB_AbilityList15->Items->Clear();
	CB_AbilityList16->Items->Clear();
	CB_AbilityList17->Items->Clear();
	CB_AbilityList18->Items->Clear();
	CB_AbilityList19->Items->Clear();
	CB_AbilityList20->Items->Clear();

	CB_AbilityListEx1->Items->Clear();
	CB_AbilityListEx2->Items->Clear();
	CB_AbilityListEx3->Items->Clear();
	CB_AbilityListEx4->Items->Clear();
	CB_AbilityListEx5->Items->Clear();
	CB_AbilityListEx6->Items->Clear();
	CB_AbilityListEx7->Items->Clear();
	CB_AbilityListEx8->Items->Clear();
	CB_AbilityListEx9->Items->Clear();
	CB_AbilityListEx10->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 );
		CB_AbilityList6->Items->Add( Str );
		CB_AbilityList7->Items->Add( Str );
		CB_AbilityList8->Items->Add( Str );
		CB_AbilityList9->Items->Add( Str );
		CB_AbilityList10->Items->Add( Str );
		CB_AbilityList11->Items->Add( Str );
		CB_AbilityList12->Items->Add( Str );
		CB_AbilityList13->Items->Add( Str );
		CB_AbilityList14->Items->Add( Str );
		CB_AbilityList15->Items->Add( Str );
		CB_AbilityList16->Items->Add( Str );
		CB_AbilityList17->Items->Add( Str );
		CB_AbilityList18->Items->Add( Str );
		CB_AbilityList19->Items->Add( Str );
		CB_AbilityList20->Items->Add( Str );

		CB_AbilityListEx1->Items->Add( Str );
		CB_AbilityListEx2->Items->Add( Str );
		CB_AbilityListEx3->Items->Add( Str );
		CB_AbilityListEx4->Items->Add( Str );
		CB_AbilityListEx5->Items->Add( Str );
		CB_AbilityListEx6->Items->Add( Str );
		CB_AbilityListEx7->Items->Add( Str );
		CB_AbilityListEx8->Items->Add( Str );
		CB_AbilityListEx9->Items->Add( Str );
		CB_AbilityListEx10->Items->Add( Str );
	}  

	//////////////////////////////////////////////////////////////////////////
	//設定標準屬性的類型
	CB_AbilityList11->SelectedIndex = EM_WearEqType_DMG;
	CB_AbilityList12->SelectedIndex = EM_WearEqType_ATK_Per;
	CB_AbilityList13->SelectedIndex = EM_WearEqType_DEF_Per;
	CB_AbilityList14->SelectedIndex = EM_WearEqType_MDEF_Rate;
	CB_AbilityList15->SelectedIndex = EM_WearEqType_AtkSpeed;
	CB_AbilityList16->SelectedIndex = EM_WearEqType_MaxHP_Rate;
	CB_AbilityList17->SelectedIndex = EM_WearEqType_MaxMP_Rate;
	CB_AbilityList18->SelectedIndex = EM_WearEqType_ParryRate;
	CB_AbilityList19->SelectedIndex = EM_WearEqType_CritRate;
	CB_AbilityList20->SelectedIndex = EM_WearEqType_DodgePoint;
	//////////////////////////////////////////////////////////////////////////
	CB_AbilityType->Items->Clear();
	for( unsigned i = 0 ; i < Global::NpcStrongArg.size() ; i++ )
	{
		String* Str = Global::NpcStrongArg[i].Name.c_str();
		CB_AbilityType->Items->Add( Str );
	}
	//////////////////////////////////////////////////////////////////////////
	CB_CheckCarryLuaPoint->Items->Clear();
	for( unsigned int i = 0 ; i < Global::PointEnumName.size() ; i++ )
	{
		String* Str =  Global::PointEnumName[i].c_str();

		CB_CheckCarryLuaPoint->Items->Add(Str);
	}

}



void NPCForm::OnSelectObj( bool LockOk )
{
    _ObjDB.GameData.Classification = EM_ObjectClass_NPC;
/*
	//設定抗性
	if( NpcResistInfoList->size()  == 0 )
		return;

	if( _ObjDB->GameData.NPC.DB_ResistID >=  NpcResistInfoList->size() )
	{
		_ObjDB->GameData.NPC.DB_ResistID = 0;
	}
	NpcResistBaseInfoStruct& NpcResistTemp = (*NpcResistInfoList)[ _ObjDB->GameData.NPC.DB_ResistID ];
	_ObjDB->GameData.NPC.ResistType = NpcResistTemp.Type;
	_ObjDB->GameData.NPC.Resist		= NpcResistTemp.Resist;
	*/
}

int     NPCForm::ObjSize(  )
{
    GameObjDbStruct *P = NULL;
    int Size = sizeof( GameObjDbStruct ) - sizeof( P->Temp ) +  sizeof( P->NPC ) + 3;
    Size = Size & 0xfffffC;
    return Size;
}

System::Void NPCForm::MonsterMoney_Click(System::Object*  sender, System::EventArgs*  e)
{
	int LV = _ObjDB.GameData.NPC.Level;
	numericUpDown1->Value = Global::MonsterMoney[ LV ][0];
	if( _ObjDB.GameData.NPC.Sex < EM_Sex_BigMonster )
	{
		numericUpDown2->Value = Global::MonsterMoney[ LV ][1];
	}
	else
		numericUpDown2->Value = Global::MonsterMoney[ LV ][2];
}

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

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

/*	ReaderClass< DB_GameObjDbStruct >*      Reader = ObjReader( );
	String* Tag = static_cast<String*>(Box->Tag);

	Reader->Write( Data , DotNetStr::StringToChar( Tag ) , Box->SelectedIndex );
	*/
	if( (Box->SelectedIndex!= 0) ==  Data->GameData.NPC.IsAbilityStandard )
		return;

	if( CheckModifyAndCheckOut() == false )
		return;

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


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

	
	_OnValueChange = true;	

}
System::Void NPCForm::FixAllNPCPosClick(System::Object*  sender, System::EventArgs*  e)
{

	SqlDataReader*	myReader;

	int X , Y , Z , ZoneID;
	for( int i = 0 ; i < (int)_ObjList->size() ; i++ )
	{
		int GUID = (*_ObjList)[i].GUID;
		sqlCommandGlobalDB->CommandText = String::Format( "SELECT TOP (1) ZoneID, X, Y, Z FROM NPCData WHERE (OrgObjID = {0} AND IsDelflag = 0  )" , __box( GUID ) );
		myReader = sqlCommandGlobalDB->ExecuteReader();
		if( myReader->Read() )
		{
			ZoneID = myReader->GetInt32( 0 );
			X = int( myReader->GetFloat( 1 ) );
			Y = int( myReader->GetFloat( 2 ) );
			Z = int( myReader->GetFloat( 3 ) );					
		}
		else
		{
			X = 0;
			Y = 0;
			Z = 0;
			ZoneID = -1;
		}
		myReader->Close();

		sqlCommand_Base->CommandText = String::Concat( String::Format( "UPDATE NPCObjectDB SET ZoneID = {0},X={1},Y={2}", __box(ZoneID) , __box(X) , __box(Y) )
									 , String::Format( ",Z={0} WHERE GUID={1}", __box(Z) , __box(GUID) ) );
		sqlCommand_Base->ExecuteReader()->Close();

	}
}

void	NPCForm::AfterUpdateObj( DB_GameObjDbStruct* TempObj )
{
	char	Buf[2048];
	
	sqlCommand_Base1->CommandText = String::Format( "DELETE NPCObjectValueDB WHERE OrgObjID={0}" , __box( TempObj->GameData.GUID) );
	sqlCommand_Base1->ExecuteReader()->Close();
	//////////////////////////////////////////////////////////////////////////
	RoleValueData* Value = &(Global::ValueCal);
	Value->Init_BaseEQValue();
	Value->Init_MidValue();

	//資料更新
	Value->Ability = &Global::Ability;

	Value->Race    = (Race_ENUM)_ObjDB.GameData.NPC.Race;
	Value->Voc     = (Voc_ENUM) _ObjDB.GameData.NPC.Vocation;
	Value->Voc_Sub = (Voc_ENUM) (_ObjDB.GameData.NPC.Vocation_Sub -1 );
	Value->Sex     = (Sex_ENUM) _ObjDB.GameData.NPC.Sex; 
	Value->Level	 = _ObjDB.GameData.NPC.Level;
	Value->Level_Sub = _ObjDB.GameData.NPC.Level;
	Value->Ability->STR = _ObjDB.GameData.NPC.STR;
	Value->Ability->STA = _ObjDB.GameData.NPC.STA;
	Value->Ability->INT = _ObjDB.GameData.NPC.INT;
	Value->Ability->MND = _ObjDB.GameData.NPC.MND;
	Value->Ability->AGI = _ObjDB.GameData.NPC.AGI;

	Value->SkillValue = &Value->MaxSkillValue;

	GameObjectWearEqStruct	Ability = TempObj->GameData.NPC.Ability;

	if( TempObj->GameData.NPC.IsAbilityStandard )
	{
		for( int i = 0 ; i < 10 ; i ++ )
		{
			Ability.EqTypeValue[i] += TempObj->GameData.NPC.DEqTypeValue[i];
		}
	}

	Value->ReSetTable( );
	Value->AddAbility_Buff( &(Ability) , 1 );
	Value->Calculate( );

	//////////////////////////////////////////////////////////////////////////
	NpcResistBaseInfoStruct& NpcResistTemp = (*NpcResistInfoList)[ TempObj->GameData.NPC.DB_ResistID ];
	//////////////////////////////////////////////////////////////////////////
	sprintf( Buf , "INSERT NPCObjectValueDB(OrgObjID,MaxHP,MaxMP,ATK,DMG,DEF,MATK,MDEF,ResEarth,ResWater,ResFire,ResWind,ResLight,ResDark) VALUES(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)"
				 , TempObj->GameData.GUID 
				 , int(Value->Fin.MaxHP)
				 , int(Value->Fin.MaxMP)
				 , int(Value->Fin.ATK)
				 , int(Value->Fin.DMG)
				 , int(Value->Fin.DEF)
				 , int(Value->Fin.MATK)
				 , int(Value->Fin.MDEF)
				 , int(Value->Fin.MaxHP)
				 , int(NpcResistTemp.Resist.Earth)
				 , int(NpcResistTemp.Resist.Water)
				 , int(NpcResistTemp.Resist.Fire)
				 , int(NpcResistTemp.Resist.Wind)
				 , int(NpcResistTemp.Resist.Light)
				 , int(NpcResistTemp.Resist.Darkness) );

	sqlCommand_Base1->CommandText = new String( Buf );
	sqlCommand_Base1->ExecuteReader()->Close();
}