
#pragma		warning (disable:4244)
#pragma		warning (disable:4786)

#include "RoleAttr.h"



FixFightArgumentStruct   RoleValueData::FixArg;                         //固定參數表
FightArgumentStruct      RoleValueData::RaceArg[_MAX_RACE_COUNT_];      //種族參數表
FightArgumentStruct      RoleValueData::VocArg[_MAX_VOCATION_COUNT_];   //職業參數表
FightArgumentStruct      RoleValueData::SexArg[_MAX_SEX_COUNT_];        //性別參數表

EqWearSkillStruct RoleValueData::JobWearSkill[ _MAX_VOCATION_COUNT_ ];		//每個職頁所會的裝備能力

float    RoleValueData::BaseStrTB[_MAX_RACE_COUNT_][_MAX_VOCATION_COUNT_][_MAX_SEX_COUNT_][ _MAX_LEVEL_+1 ];
float    RoleValueData::BaseStaTB[_MAX_RACE_COUNT_][_MAX_VOCATION_COUNT_][_MAX_SEX_COUNT_][ _MAX_LEVEL_+1 ];
float    RoleValueData::BaseIntTB[_MAX_RACE_COUNT_][_MAX_VOCATION_COUNT_][_MAX_SEX_COUNT_][ _MAX_LEVEL_+1 ];
float    RoleValueData::BaseMndTB[_MAX_RACE_COUNT_][_MAX_VOCATION_COUNT_][_MAX_SEX_COUNT_][ _MAX_LEVEL_+1 ];
float    RoleValueData::BaseAgiTB[_MAX_RACE_COUNT_][_MAX_VOCATION_COUNT_][_MAX_SEX_COUNT_][ _MAX_LEVEL_+1 ];
float    RoleValueData::BaseHPTB[_MAX_RACE_COUNT_][_MAX_VOCATION_COUNT_][_MAX_SEX_COUNT_][ _MAX_LEVEL_+1 ];
float    RoleValueData::BaseMPTB[_MAX_RACE_COUNT_][_MAX_VOCATION_COUNT_][_MAX_SEX_COUNT_][ _MAX_LEVEL_+1 ];

float    RoleValueData::BaseDefAbrTB[ Def_Base_TB_Total_Unit_ ];
float    RoleValueData::BaseMDefAbrTB[ Def_Base_TB_Total_Unit_ ];
float    RoleValueData::BaseMPowTB[ Def_Base_TB_Total_Unit_ ];

int      RoleValueData::PointCost[ 200 ];

int      RoleValueData::SkillValueBase[ _MAX_LEVEL_][ _MAX_SKILLVALUE_BASETYPE];
int      RoleValueData::JobSkillValue[ _MAX_SKILLVALUE_TYPE ][ _MAX_VOCATION_COUNT_ ];

int		 RoleValueData::WeaponBaseDelayTime[ _MAX_SKILLVALUE_TYPE ];							//各種武器的基本延遲時間
float	 RoleValueData::WeaponBaseDmg[ _MAX_SKILLVALUE_TYPE ];									//各種武器的基本傷害比( 要乘上該等極GM的傷害 )
vector<ResistArgumentStruct>		RoleValueData::ResistArgList;									//抗性數值表
//----------------------------------------------------------------------	
// 一般函式
//----------------------------------------------------------------------	
//重設此角色的 Table 資料
void	RoleValueData::ReSetTable( )
{
	//memset( &Bas , 0 , sizeof( Bas) );
    int i; 
    for( i = 0 ; i < 100 ; i ++ )
    {
        Arg.Arg[i]		= RaceArg[ Race ].Arg[i] + VocArg[ Voc	   ].Arg[i] + SexArg[ Sex].Arg[i];
		Arg_Sub.Arg[i]	= RaceArg[ Race ].Arg[i] + VocArg[ Voc_Sub ].Arg[i] + SexArg[ Sex].Arg[i];
    }

    if( Voc_Sub == EM_Vocation_None )
    {
        Bas.BaseStr = BaseStrTB[Race][Voc][Sex][Level];
        Bas.BaseSta = BaseStaTB[Race][Voc][Sex][Level];
        Bas.BaseInt = BaseIntTB[Race][Voc][Sex][Level];
        Bas.BaseMnd = BaseMndTB[Race][Voc][Sex][Level];
        Bas.BaseAgi = BaseAgiTB[Race][Voc][Sex][Level];
        Bas.BaseHP  = BaseHPTB[Race][Voc][Sex] [Level];
        Bas.BaseMP  = BaseMPTB[Race][Voc][Sex] [Level];
    }
    else
    {
        Bas.BaseStr = BaseStrTB[Race][Voc][Sex][Level] + BaseStrTB[Race][Voc_Sub][Sex][ Level_Sub ] / 10 ;
        Bas.BaseSta = BaseStaTB[Race][Voc][Sex][Level] + BaseStaTB[Race][Voc_Sub][Sex][ Level_Sub ] / 10;
        Bas.BaseInt = BaseIntTB[Race][Voc][Sex][Level] + BaseIntTB[Race][Voc_Sub][Sex][ Level_Sub ] / 10 ;
        Bas.BaseMnd = BaseMndTB[Race][Voc][Sex][Level] + BaseMndTB[Race][Voc_Sub][Sex][ Level_Sub ] / 10 ;
        Bas.BaseAgi = BaseAgiTB[Race][Voc][Sex][Level] + BaseAgiTB[Race][Voc_Sub][Sex][ Level_Sub ] / 10 ;
        Bas.BaseHP  = BaseHPTB[Race][Voc][Sex] [Level] + BaseHPTB[Race][Voc_Sub][Sex][ Level_Sub ] / 10 ;
        Bas.BaseMP  = BaseMPTB[Race][Voc][Sex] [Level] + BaseMPTB[Race][Voc_Sub][Sex][ Level_Sub ] / 10 ;
    }
    
    for( i = 0 ; i < _MAX_SKILL_COUNT_ ; i++ )
    {
        int SkillType = JobSkillValue[i][Voc];
        MaxSkillValue.Skill[i] = SkillValueBase[ Level ][ SkillType ];
    }
	
}
//先計算裝備能力
void	RoleValueData::CalWearSkill()
{
	Fin.WearSkill	= _EqWearSkill();
}

//初始化所有的裝備或法術產生的暫時效果
void	RoleValueData::Init_MidValue( )
{
    memset( &Mid , 0 , sizeof( Mid ) );
//    IsMainAttack = true;
//    IsSecAttack  = false;
	MainWeaponType = EM_Weapon_Unarmed;
	SecWeaponType = EM_Weapon_None;
	Effect._Value = 0;
	AssistMagicSetting._Type = 0;
	MainAttackRange = 20;
	SecAttackRange = 0;
}

//全部重新計算
void    RoleValueData::Calculate( )
{
	//清除法術效果
	//Effect._Value	= 0;


    Fin.STR         = _STR();
    Fin.STA         = _STA();
    Fin.INT         = _INT();
    Fin.MND         = _MND();
    Fin.AGI         = _AGI();
    Fin.LUK         = _LUK();

    Fin.MaxHP       = _MaxHP();	        // 體力
    Fin.MaxMP       = _MaxMP();	        // 魔力
    Fin.MaxSP       = _MaxSP();	        // 
	Fin.MaxSP_Sub   = _MaxSP_Sub();	    // 

    Fin.ATK         = _ATK();			// 攻擊
    Fin.DEF         = _DEF();			// 防禦

    Fin.MDEF        = _MDEF();	        // 防禦
    Fin.MATK        = _MATK();	        // 攻擊

    Fin.HitRate     = _HitRate();		// 命中
    Fin.DodgeRate   = _DodgeRate();     // 閃避

    Fin.CriticalHit = _CriticalHit();
	Fin.CriticalHitPower = _CriticalHitPower();

	Fin.MagicCriticalHit = _MagicCriticalHit();
	Fin.MagicCriticalHitPower = _MagicCriticalHitPower();

    Fin.Main_CriticalHit = _Main_CriticalHit();
    Fin.Sec_CriticalHit = _Sec_CriticalHit();
    Fin.ParryRate   = _ParryRate();

    Fin.ReHP        = _ReHP();
    Fin.ReMP        = _ReMP();


    Fin.Main_ATKSpeed_Per = _Main_ATKSpeed_Per();
    Fin.Sec_ATKSpeed_Per  = _Sec_ATKSpeed_Per();

	Fin.MoveSpeed   = _MoveSpeed();

    Fin.DMG         = _DMG();

    Fin.MPow         = _MPow();           //魔法增強率
    Fin.MAbr         = _MAbr();           //魔法防禦吸收率
    Fin.Abr          = _Abr();            //防禦吸收率
    Fin.AB           = _AB();             //防禦吸收點數
	Fin.ManaDecrease = _ManaDecrease();

    Fin.Main_DMG    = _MainDMG();
    Fin.Sec_DMG		= _SecDMG();
	Fin.Main_HitRate= _Main_HitRate();		// 命中
	Fin.Sec_HitRate = _Sec_HitRate();		// 命中
	Fin.WearSkill	= _EqWearSkill();

    for( int i = 0 ; i < EM_MagicResist_MAXCOUNT ; i++ )
    {
		Fin.Resist._ArrList[i] =	Mid.Body[ EM_WearEqType_AllResist ] 
		+	Mid.Body[ EM_WearEqType_Resist_Earth + i ] 
		+	Bas.Resist._ArrList[i];
    }

	//計算SkillValue
	_SkillValueCal();
	//Fin.SkillValue = *SkillValue;
}

//----------------------------------------------------------------------	
//各項數值簡易算式
//----------------------------------------------------------------------	
float	RoleValueData::_STR()
{
    return Ability->STR + Bas.BaseStr + Mid.Body[ EM_WearEqType_STR ] + Mid.Body[ EM_WearEqType_AllState ] ;
}
float	RoleValueData::_STA()
{
    return Ability->STA + Bas.BaseSta + + Mid.Body[ EM_WearEqType_STA ] + Mid.Body[ EM_WearEqType_AllState ];
}
float	RoleValueData::_INT()
{
    return Ability->INT + Bas.BaseInt + + Mid.Body[ EM_WearEqType_INT ] + Mid.Body[ EM_WearEqType_AllState ];
}
float	RoleValueData::_MND()
{
    return Ability->MND + Bas.BaseMnd + + Mid.Body[ EM_WearEqType_MND ] + Mid.Body[ EM_WearEqType_AllState ];
}
float	RoleValueData::_AGI()
{
    return Ability->AGI + Bas.BaseAgi + + Mid.Body[ EM_WearEqType_AGI ] + Mid.Body[ EM_WearEqType_AllState ];
}
float	RoleValueData::_LUK()
{
    return 0;
}
float	RoleValueData::_MaxHP( )
{
    //return Bas.BaseHP + Mid.MaxHP + _STR() * Arg.HpStrArg+ _STA() * Arg.HpStaArg;
    return Bas.BaseHP + Fin.STR * Arg.HpStrArg+ Fin.STA * Arg.HpStaArg + Mid.Body[ EM_WearEqType_MaxHP ];
}
float	RoleValueData::_MaxMP( )
{
    //return Bas.BaseMP + Mid.MaxMP + _INT() * Arg.MPIntArg + _MND() * Arg.MpMndArg;
    return Bas.BaseMP + Fin.INT * Arg.MPIntArg + Fin.MND * Arg.MpMndArg + Mid.Body[ EM_WearEqType_MaxMP ];;
}
float	RoleValueData::_MaxSP( )
{
    return Arg.MaxSP;
}
float	RoleValueData::_MaxSP_Sub( )
{
	return Arg_Sub.MaxSP;
}


float	RoleValueData::_ATK( )
{
    //return Mid.ATK + _STR()* Arg.AtkStrArg + _INT() * Arg.AtkIntArg + _AGI() * Arg.AtkAgiArg;
    return Fin.STR* Arg.AtkStrArg + Fin.INT * Arg.AtkIntArg + Fin.AGI * Arg.AtkAgiArg  + Mid.Body[ EM_WearEqType_ATK ];
}

float	RoleValueData::_DEF( )
{
	float AddDef = 0;

	AddDef =  Mid.Def[ EM_Armor_HeavyArmed  ] * Mid.Body[ EM_WearEqType_DEF_HeavyArmed ]
			+ Mid.Def[ EM_Armor_LightArmed	] * Mid.Body[ EM_WearEqType_DEF_LightArmed ]
			+ Mid.Def[ EM_Armor_Leather		] * Mid.Body[ EM_WearEqType_DEF_Leather	 ]
			+ Mid.Def[ EM_Armor_Clothes		] * Mid.Body[ EM_WearEqType_DEF_Clothes	 ]
			+ Mid.Def[ EM_Armor_Robe		] * Mid.Body[ EM_WearEqType_DEF_Robe	 ]
			+ Mid.Def[ EM_Armor_Shield		] * Mid.Body[ EM_WearEqType_DEF_Shield	 ];

    return Fin.STA * Arg.DefArg + Mid.Body[ EM_WearEqType_DEF ] + AddDef;
}

float	RoleValueData::_MDEF( )
{
    //return Mid.MDEF + _MND() * Arg.MDefArg;
    return Fin.MND * Arg.MDefArg + Mid.Body[ EM_WearEqType_MDEF ];
}
float	RoleValueData::_MATK( )
{
    return  Fin.INT * Arg.MAtkArg + Mid.Body[ EM_WearEqType_MATK ];
}

float	RoleValueData::_HitRate( )
{
    float Ret = FixArg.BaseHitRate +  Fin.AGI * FixArg.HitArg + Level * FixArg.HitLvArg + Mid.Body[ EM_WearEqType_HitRate ];
//    if( Ret < 30 )
//        Ret = 30;
    return Ret;
}
float	RoleValueData::_DodgeRate( )
{
    float Ret = FixArg.BaseDogRate +  Fin.AGI * FixArg.DogArg + Level * FixArg.DogLVArg + Mid.Body[ EM_WearEqType_DodgeRate ];
    if( Ret > 80 )
        Ret = 80;
    return Ret;
}

float	RoleValueData::_CriticalHit( )
{
    return Mid.Body[ EM_WearEqType_CritRate ] + FixArg.BaseCritHit ;
}

float	RoleValueData::_CriticalHitPower( )
{
	return Mid.Body[ EM_WearEqType_CritPower ] + FixArg.BaseCritPower;
}

float	RoleValueData::_MagicCriticalHit( )
{
	return Mid.Body[ EM_WearEqType_MagicCritRate ] + FixArg.BaseMagicCritHit;
}

float	RoleValueData::_MagicCriticalHitPower( )
{
	return Mid.Body[ EM_WearEqType_MagicCritPower ] + FixArg.BaseMagicCritPower;
}


float	RoleValueData::_Main_CriticalHit( )
{
    return Mid.Body[ EM_WearEqType_CritRate ] + Mid.Main_CriticalHit;
}

float	RoleValueData::_Sec_CriticalHit( )
{
    return Mid.Body[ EM_WearEqType_CritRate ] + Mid.Sec_CriticalHit;
}

float	RoleValueData::_ParryRate( )
{
    return Mid.Body[ EM_WearEqType_ParryRate ];
}

float	RoleValueData::_ReHP( )
{
    return Arg.BaseReHP + Fin.STA * Arg.ReHpArg + Mid.Body[ EM_WearEqType_ReHP ]; 
}
float	RoleValueData::_ReMP( )
{
    return Arg.BaseReMP + Fin.MND * Arg.ReMpArg + Mid.Body[ EM_WearEqType_ReMP ];
}
/*
float	RoleValueData::_ReSP( )
{
    return 10 + Mid.Body[ EM_WearEqType_ReSP ];	
}
*/
float 	RoleValueData::_Main_ATKSpeed_Per( )
{
	if( MainWeaponType == EM_Weapon_None )
		return _BASE_ATTACK_SPEED_;

	float AtkSpeed_Per = Mid.Body[ EM_WearEqType_AtkSpeed ] + 100;

	switch( MainWeaponType )
	{
	case EM_Weapon_Unarmed:	
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Unarmed ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
    case EM_Weapon_Blade:        
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Blade ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
    case EM_Weapon_Dagger:       
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Dagger ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
    case EM_Weapon_Wand:         
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Wand ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
    case EM_Weapon_Axe:          
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Axe ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
    case EM_Weapon_Bludgeon:     
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Bludgeon ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
    case EM_Weapon_Claymore:     
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Claymore ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
    case EM_Weapon_Staff:        
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Staff ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
    case EM_Weapon_2H_Axe:       
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_2H_Axe ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
    case EM_Weapon_2H_Hammer:    
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_2H_Hammer ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
	case EM_Weapon_Polearm:		
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Polearm ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
/*	case EM_Weapon_Bow:			
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Unarmed ];
		break;
	case EM_Weapon_CossBow:		
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Unarmed ];
		break;
	case EM_Weapon_Gun:			
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Unarmed ];
		break;*/
	}

    return ( ( AtkSpeed_Per ) /100 * WeaponBaseDelayTime[ MainWeaponType ] );
}

float 	RoleValueData::_Sec_ATKSpeed_Per( )
{
	if( SecWeaponType == EM_Weapon_None )
		return _BASE_ATTACK_SPEED_;

	float AtkSpeed_Per = Mid.Body[ EM_WearEqType_AtkSpeed ] + 100;

	switch( SecWeaponType )
	{
	case EM_Weapon_Unarmed:	
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Unarmed ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
	case EM_Weapon_Blade:        
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Blade ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
	case EM_Weapon_Dagger:       
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Dagger ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
	case EM_Weapon_Wand:         
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Wand ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
	case EM_Weapon_Axe:          
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Axe ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
	case EM_Weapon_Bludgeon:     
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Bludgeon ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
	case EM_Weapon_Claymore:     
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Claymore ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
	case EM_Weapon_Staff:        
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Staff ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
	case EM_Weapon_2H_Axe:       
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_2H_Axe ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
	case EM_Weapon_2H_Hammer:    
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_2H_Hammer ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
	case EM_Weapon_Polearm:		
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Polearm ] + Mid.Body[ EM_WearEqType_AttackSpeed_AllWeapon ];
		break;
/*	case EM_Weapon_Bow:			
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Unarmed ];
		break;
	case EM_Weapon_CossBow:		
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Unarmed ];
		break;
	case EM_Weapon_Gun:			
		AtkSpeed_Per += Mid.Body[ EM_WearEqType_AttackSpeed_Unarmed ];*/
		break;
	}

	return ( ( AtkSpeed_Per ) /100 * WeaponBaseDelayTime[ SecWeaponType ] );
}


float RoleValueData::_MoveSpeed( )
{
    return _BASE_MOVE_SPEED_ * (  ( Mid.Body[ EM_WearEqType_MoveSpeed ] + Bas.MoveSpeed_Per ) / 100  );
}

float   RoleValueData::_DMG( )
{
    return Fin.ATK / FixArg.DmgAtkArg + Mid.Body[ EM_WearEqType_DMG ];
}

float   RoleValueData::_MPow()           //魔法增強率
{
    int Value = int(Fin.MATK / FixArg.MagPowUnit);
    if( Value < 0 )
        Value = 0;
    if( Value >= Def_Base_TB_Total_Unit_ )
        Value = Def_Base_TB_Total_Unit_-1;
    return BaseMPowTB[ Value ] + Mid.Body[ EM_WearEqType_MagicPow_AllMagic ];
}
float   RoleValueData::_MAbr()           //魔法防禦吸收率
{
    int Value = int(Fin.MDEF / FixArg.MagUnit);
    if( Value < 0 )
        Value = 0;
    if( Value >= Def_Base_TB_Total_Unit_ )
        Value = Def_Base_TB_Total_Unit_-1;
    return BaseMDefAbrTB[ Value ];
}
float   RoleValueData::_Abr()            //防禦吸收率
{
    int Value = int(Fin.DEF / FixArg.DefUnit);
    if( Value < 0 )
        Value = 0;
    if( Value >= Def_Base_TB_Total_Unit_ )
        Value = Def_Base_TB_Total_Unit_-1;

    return BaseDefAbrTB[ Value ] ;
}
float   RoleValueData::_AB()             //防禦吸收點數
{
    return Fin.DEF/ FixArg.DefDmgRate;
}

float	RoleValueData::_ManaDecrease()
{
	if( Mid.Body[ EM_WearEqType_ManaDecrease ] > 50 )
		return 50;

	return Mid.Body[ EM_WearEqType_ManaDecrease ];
}

float   RoleValueData::_MainDMG()
{
	float DmgRate = 100 + Mid.Main_DMG_Per ;
	switch( MainWeaponType )
	{
	case EM_Weapon_Unarmed:	
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Unarmed ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Blade:        
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Blade ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Dagger:       
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Dagger ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Wand:         
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Wand ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Axe:          
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Axe ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Bludgeon:     
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Bludgeon ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Claymore:     
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Claymore ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Staff:        
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Staff ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_2H_Axe:       
		DmgRate += Mid.Body[ EM_WearEqType_DMG_2H_Axe ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_2H_Hammer:    
		DmgRate += Mid.Body[ EM_WearEqType_DMG_2H_Hammer ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Polearm:		
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Polearm ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
/*	case EM_Weapon_Bow:			
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Unarmed ];
		break;
	case EM_Weapon_CossBow:		
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Unarmed ];
		break;
	case EM_Weapon_Gun:			
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Unarmed ];
		break;*/
	}

    return ( Fin.DMG + Mid.Main_DMG * ( DmgRate ) / 100 );
}
float   RoleValueData::_SecDMG()
{
	float DmgRate = 100 + Mid.Sec_DMG_Per +  Mid.Body[ EM_WearEqType_SecHand_DMG_Per ];
	switch( SecWeaponType )
	{
	case EM_Weapon_Unarmed:	
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Unarmed ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Blade:        
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Blade ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Dagger:       
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Dagger ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Wand:         
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Wand ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Axe:          
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Axe ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Bludgeon:     
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Bludgeon ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Claymore:     
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Claymore ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Staff:        
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Staff ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_2H_Axe:       
		DmgRate += Mid.Body[ EM_WearEqType_DMG_2H_Axe ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_2H_Hammer:    
		DmgRate += Mid.Body[ EM_WearEqType_DMG_2H_Hammer ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
	case EM_Weapon_Polearm:		
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Polearm ] + Mid.Body[ EM_WearEqType_DMG_AllWeapon ];
		break;
		/*	case EM_Weapon_Bow:			
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Unarmed ];
		break;
		case EM_Weapon_CossBow:		
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Unarmed ];
		break;
		case EM_Weapon_Gun:			
		DmgRate += Mid.Body[ EM_WearEqType_DMG_Unarmed ];
		break;*/
	}

	return ( Fin.DMG + Mid.Sec_DMG * ( DmgRate ) / 100 );
 //   return Fin.DMG / 2 + Mid.Sec_DMG;
}

float	RoleValueData::_Main_HitRate()
{
	float Rate = Fin.HitRate + Mid.Main_HitRate;
	if( Rate <= 20 )
		Rate = 20;
	return Rate;
}
float	RoleValueData::_Sec_HitRate()
{
	float Rate = Fin.HitRate + Mid.Sec_HitRate - FixArg.Miss_SecHand + Mid.Body[ EM_WearEqType_SecHand_HitRate ];
	if( Rate <= 30 )
		Rate = 30;

	return Rate;
}
EqWearSkillStruct RoleValueData::_EqWearSkill()
{
	return JobWearSkill[ Voc ] ;
}


//----------------------------------------------------------------------
//	全域資料
//----------------------------------------------------------------------
bool	RoleValueData::InitTable( char* Path )
{
    return true;
}
void RoleValueData::CalBaseTB( )
{
	/*
	float	TempRace[ _MAX_LEVEL_+1 ];
	float	TempJob[ _MAX_LEVEL_+1 ];
	float	TempSex[ _MAX_LEVEL_+1 ];
*/

    int R , V , S , L;
    float Rate;
	float Arg;
	float ArgBase;
    for ( R = 0 ; R < _MAX_RACE_COUNT_ ; R++ )
        for( V = 0 ; V < _MAX_VOCATION_COUNT_ ; V++ )
            for( S = 0 ; S < _MAX_SEX_COUNT_; S++ )
            {
				BaseStrTB[ R ][ V ][ S ][ 1 ] = RaceArg[R].BStrLv1 + VocArg[V].BStrLv1 + SexArg[S].BStrLv1;
				Arg		= RaceArg[R].StrArg + VocArg[V].StrArg + SexArg[S].StrArg;
				ArgBase = RaceArg[R].BStrArg + VocArg[V].BStrArg + SexArg[S].BStrArg;

				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					BaseStrTB[ R ][ V ][ S ][ L ] = BaseStrTB[ R ][ V ][ S ][ L -1 ] * ( 1 + Arg  )  + ArgBase; 
				}


				BaseStaTB[ R ][ V ][ S ][ 1 ] = RaceArg[R].BStaLv1 + VocArg[V].BStaLv1 + SexArg[S].BStaLv1;
				Arg		= RaceArg[R].StaArg + VocArg[V].StaArg + SexArg[S].StaArg;
				ArgBase = RaceArg[R].BStaArg + VocArg[V].BStaArg + SexArg[S].BStaArg;
			

				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					BaseStaTB[ R ][ V ][ S ][ L ] = BaseStaTB[ R ][ V ][ S ][ L -1 ] * ( 1 + Arg  )  + ArgBase; 
				}

				BaseIntTB[ R ][ V ][ S ][ 1 ] = RaceArg[R].BIntLv1 + VocArg[V].BIntLv1 + SexArg[S].BIntLv1;
				Arg		= RaceArg[R].IntArg + VocArg[V].IntArg + SexArg[S].IntArg;
				ArgBase = RaceArg[R].BIntArg + VocArg[V].BIntArg + SexArg[S].BIntArg;


				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					BaseIntTB[ R ][ V ][ S ][ L ] = BaseIntTB[ R ][ V ][ S ][ L -1 ] * ( 1 + Arg  )  + ArgBase; 
				}

				BaseMndTB[ R ][ V ][ S ][ 1 ] = RaceArg[R].BMndLv1 + VocArg[V].BMndLv1 + SexArg[S].BMndLv1;
				Arg		= RaceArg[R].MndArg + VocArg[V].MndArg + SexArg[S].MndArg;
				ArgBase = RaceArg[R].BMndArg + VocArg[V].BMndArg + SexArg[S].BMndArg;


				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					BaseMndTB[ R ][ V ][ S ][ L ] = BaseMndTB[ R ][ V ][ S ][ L -1 ] * ( 1 + Arg  )  + ArgBase; 
				}

				BaseAgiTB[ R ][ V ][ S ][ 1 ] = RaceArg[R].BAgiLv1 + VocArg[V].BAgiLv1 + SexArg[S].BAgiLv1;
				Arg		= RaceArg[R].AgiArg + VocArg[V].AgiArg + SexArg[S].AgiArg;
				ArgBase = RaceArg[R].BAgiArg + VocArg[V].BAgiArg + SexArg[S].BAgiArg;


				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					BaseAgiTB[ R ][ V ][ S ][ L ] = BaseAgiTB[ R ][ V ][ S ][ L -1 ] * ( 1 + Arg  )  + ArgBase; 
				}

				BaseHPTB[ R ][ V ][ S ][ 1 ] = RaceArg[R].BHpLv1 + VocArg[V].BHpLv1 + SexArg[S].BHpLv1;
				Arg		= RaceArg[R].HPArg + VocArg[V].HPArg + SexArg[S].HPArg;
				ArgBase = RaceArg[R].BHpArg + VocArg[V].BHpArg + SexArg[S].BHpArg;


				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					BaseHPTB[ R ][ V ][ S ][ L ] = BaseHPTB[ R ][ V ][ S ][ L -1 ] * ( 1 + Arg  )  + ArgBase; 
				}

				BaseMPTB[ R ][ V ][ S ][ 1 ] = RaceArg[R].BMpLv1 + VocArg[V].BMpLv1 + SexArg[S].BMpLv1;
				Arg		= RaceArg[R].MPArg + VocArg[V].MPArg + SexArg[S].MPArg;
				ArgBase = RaceArg[R].BMpArg + VocArg[V].BMpArg + SexArg[S].BMpArg;


				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					BaseMPTB[ R ][ V ][ S ][ L ] = BaseMPTB[ R ][ V ][ S ][ L -1 ] * ( 1 + Arg  )  + ArgBase; 
				}
			
/*
				TempRace[ 1 ] = RaceArg[R].BStaLv1;
				TempJob[ 1 ]  = VocArg[V].BStaLv1;
				TempSex[ 1 ]  = SexArg[S].BStaLv1;
				BaseStaTB[ R ][ V ][ S ][ 1 ] = TempRace[ 1 ] + TempJob[ 1 ] + TempSex[ 1 ]; 

				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					TempRace[ L ] = TempRace[ L -1 ] * ( 1 + RaceArg[R].StaArg)+ RaceArg[R].BStaArg ; 
					TempJob[ L ]  = TempJob [ L -1 ] * ( 1 + VocArg[V].StaArg )+ VocArg[V].BStaArg  ; 
					TempSex[ L ]  = TempSex [ L -1 ] * ( 1 + SexArg[S].StaArg )+ SexArg[S].BStaArg  ; 
					BaseStaTB[ R ][ V ][ S ][ L ] = TempRace[ L ] + TempJob[ L ] + TempSex[ L ]; 
				}

				TempRace[ 1 ] = RaceArg[R].BIntLv1;
				TempJob[ 1 ]  = VocArg[V].BIntLv1;
				TempSex[ 1 ]  = SexArg[S].BIntLv1;
				BaseIntTB[ R ][ V ][ S ][ 1 ] = TempRace[ 1 ] + TempJob[ 1 ] + TempSex[ 1 ]; 

				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					TempRace[ L ] = TempRace[ L -1 ] * ( 1 + RaceArg[R].IntArg )+ RaceArg[R].BIntArg ; 
					TempJob[ L ]  = TempJob [ L -1 ] * ( 1 + VocArg[V].IntArg  )+ VocArg[V].BIntArg  ;  
					TempSex[ L ]  = TempSex [ L -1 ] * ( 1 + SexArg[S].IntArg  )+ SexArg[S].BIntArg  ; 
					BaseIntTB[ R ][ V ][ S ][ L ] = TempRace[ L ] + TempJob[ L ] + TempSex[ L ]; 
				}

				TempRace[ 1 ] = RaceArg[R].BMndLv1;
				TempJob[ 1 ]  = VocArg[V].BMndLv1;
				TempSex[ 1 ]  = SexArg[S].BMndLv1;
				BaseMndTB[ R ][ V ][ S ][ 1 ] = TempRace[ 1 ] + TempJob[ 1 ] + TempSex[ 1 ]; 

				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					TempRace[ L ] = TempRace[ L -1 ] * ( 1 + RaceArg[R].MndArg )+ RaceArg[R].BMndArg; 
					TempJob[ L ]  = TempJob [ L -1 ] * ( 1 + VocArg[V].MndArg  )+ VocArg[V].BMndArg ;
					TempSex[ L ]  = TempSex [ L -1 ] * ( 1 + SexArg[S].MndArg  )+ SexArg[S].BMndArg ;
					BaseMndTB[ R ][ V ][ S ][ L ] = TempRace[ L ] + TempJob[ L ] + TempSex[ L ]; 
				}

				TempRace[ 1 ] = RaceArg[R].BAgiLv1;
				TempJob[ 1 ]  = VocArg[V].BAgiLv1;
				TempSex[ 1 ]  = SexArg[S].BAgiLv1;
				BaseAgiTB[ R ][ V ][ S ][ 1 ] = TempRace[ 1 ] + TempJob[ 1 ] + TempSex[ 1 ]; 

				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					TempRace[ L ] = TempRace[ L -1 ] * ( 1 + RaceArg[R].AgiArg )+ RaceArg[R].BAgiArg; 
					TempJob[ L ]  = TempJob [ L -1 ] * ( 1 + VocArg[V].AgiArg  )+ VocArg[V].BAgiArg ;
					TempSex[ L ]  = TempSex [ L -1 ] * ( 1 + SexArg[S].AgiArg  )+ SexArg[S].BAgiArg ;
					BaseAgiTB[ R ][ V ][ S ][ L ] = TempRace[ L ] + TempJob[ L ] + TempSex[ L ]; 
				}

				TempRace[ 1 ] = RaceArg[R].BHpLv1;
				TempJob[ 1 ]  = VocArg[V].BHpLv1;
				TempSex[ 1 ]  = SexArg[S].BHpLv1;
				BaseHPTB[ R ][ V ][ S ][ 1 ] = TempRace[ 1 ] + TempJob[ 1 ] + TempSex[ 1 ]; 

				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					TempRace[ L ] = TempRace[ L -1 ] * ( 1 + RaceArg[R].HPArg) + RaceArg[R].BHpArg; 
					TempJob[ L ]  = TempJob [ L -1 ] * ( 1 + VocArg[V].HPArg ) + VocArg[V].BHpArg ;
					TempSex[ L ]  = TempSex [ L -1 ] * ( 1 + SexArg[S].HPArg ) + SexArg[S].BHpArg ;
					BaseHPTB[ R ][ V ][ S ][ L ] = TempRace[ L ] + TempJob[ L ] + TempSex[ L ]; 
				}

				TempRace[ 1 ] = RaceArg[R].BMpLv1;
				TempJob[ 1 ]  = VocArg[V].BMpLv1;
				TempSex[ 1 ]  = SexArg[S].BMpLv1;
				BaseMPTB[ R ][ V ][ S ][ 1 ] = TempRace[ 1 ] + TempJob[ 1 ] + TempSex[ 1 ]; 

				for( L = 2 ; L <= _MAX_LEVEL_ ; L ++ ) 
				{
					TempRace[ L ] = TempRace[ L -1 ] * ( 1 + RaceArg[R].MPArg )+ RaceArg[R].BMpArg ; 
					TempJob[ L ]  = TempJob [ L -1 ] * ( 1 + VocArg[V].MPArg  )+ VocArg[V].BMpArg  ;
					TempSex[ L ]  = TempSex [ L -1 ] * ( 1 + SexArg[S].MPArg  )+ SexArg[S].BMpArg  ;
					BaseMPTB[ R ][ V ][ S ][ L ] = TempRace[ L ] + TempJob[ L ] + TempSex[ L ]; 
				}
				*/
            }


    BaseDefAbrTB [ 0 ] = FixArg.BAbr;
    BaseMDefAbrTB[ 0 ] = FixArg.BMagAbr;
    BaseMPowTB   [ 0 ] = FixArg.BMagPow;

    Rate = FixArg.AbrArg;
    for( L = 1 ; L < Def_Base_TB_Total_Unit_ ; L ++ ) 
        BaseDefAbrTB[ L ] =  BaseDefAbrTB[ L-1 ] + ( FixArg.MaxAbr - BaseDefAbrTB[ L-1 ] )* Rate ;


    Rate = FixArg.MagAbrArg;
    for( L = 1 ; L < Def_Base_TB_Total_Unit_ ; L ++ ) 
        BaseMDefAbrTB[ L ] =  BaseMDefAbrTB[ L-1 ] + ( FixArg.MaxMagAbr - BaseMDefAbrTB[ L-1 ] )* Rate ;


    Rate = FixArg.MagPowArg;
    for( L = 1 ; L < Def_Base_TB_Total_Unit_ ; L ++ ) 
        BaseMPowTB[ L ] =  BaseMPowTB[ L-1 ] + ( FixArg.MaxMagPow - BaseMPowTB[ L-1 ] )* Rate ;




    for( L = 1 ; L < 200 ; L++ )
    {
        if( L < 30 )
            PointCost[ L ] = PointCost[ L-1 ] + 2;
        else if( L < 50 )
            PointCost[ L ] = PointCost[ L-1 ] + 3;
        else
            PointCost[ L ] = PointCost[ L-1 ] + 4;
    }
}

//計算物理傷害　被防禦修正
float	RoleValueData::CalWeaponDMG( float DMG )
{
	float Value = ( DMG - Fin.AB ) * ( 1 - Fin.Abr );
	return __max( 1 , int(Value) );
}


//計算法術傷害　被魔防修正
float	RoleValueData::CalMagicDMG( float DMG )
{
	float Value = ( DMG ) * ( 1 - Fin.MAbr );
	return __max( 1 , int(Value) );
}

float	RoleValueData::MainAtkDamage( ATTACK_DMGTYPE_ENUM DmgType )
{

    float Value = ( Fin.Main_DMG - Target->Fin.AB ) * ( 1 - Target->Fin.Abr );

    float Ret	  =__max( 1 , Value ) ;

    switch( DmgType )
    {
	case EM_ATTACK_DMGTYPE_MISS:		    //MISS
		return 0;
	case EM_ATTACK_DMGTYPE_DODGE:		    //DODGE
		return 0;
	case EM_ATTACK_DMGTYPE_HALF:		    //被隔檔
		return Ret/2+1;
	case EM_ATTACK_DMGTYPE_NORMAL:			//一般
		return Ret;
	case EM_ATTACK_DMGTYPE_DOUBLE:			//會心一擊
		return Fin.Main_DMG * Fin.CriticalHitPower;
	case EM_ATTACK_DMGTYPE_HITBACK:         //反擊
		return Ret;
	case EM_ATTACK_DMGTYPE_NO_EFFECT:		//沒效果
		return 0;
    }

    return 1;	
}

float	RoleValueData::SecAtkDamage( ATTACK_DMGTYPE_ENUM DmgType )
{

	float DMG = Fin.Sec_DMG * FixArg.Dmg_SecHand;

    float Value = ( DMG - Target->Fin.AB ) * ( 1 - Target->Fin.Abr );

    float Ret	  =__max( 1 , Value ) ;

	switch( DmgType )
	{
	case EM_ATTACK_DMGTYPE_MISS:		    //MISS
		return 0;
	case EM_ATTACK_DMGTYPE_DODGE:		    //DODGE
		return 0;
	case EM_ATTACK_DMGTYPE_HALF:		    //被隔檔
		return Ret/2+1;
	case EM_ATTACK_DMGTYPE_NORMAL:			//一般
		return Ret;
	case EM_ATTACK_DMGTYPE_DOUBLE:			//會心一擊
		return DMG * Fin.CriticalHitPower;
	case EM_ATTACK_DMGTYPE_HITBACK:         //反擊
		return Ret;
	case EM_ATTACK_DMGTYPE_NO_EFFECT:		//沒效果
		return 0;
	}
    return 1;	
}

//取得法術抗性值對應的 處理的類別
ResistArgType_ENUM	RoleValueData::GetResistType( int ResistValue )
{
	ResistArgumentStruct*	ResistInfo;

	if( ResistArgList.size() == 0 )
		return EM_ResistArgType_Power100;


	if( (unsigned)ResistValue >= ResistArgList.size() )
	{
		ResistInfo = &ResistArgList.back();
	}
	else
	{
		ResistInfo = &ResistArgList[ResistValue];
	}

	int	RandValue = rand() % 100;

	for( int i = 0 ; i < EM_ResistArgType_Power_MaxCount ; i++ )
	{
		if( RandValue < ResistInfo->PowerList[i] )
			return (ResistArgType_ENUM)i;
	}

	return EM_ResistArgType_Power100;
}

void	RoleValueData::_SkillValueCal()
{
	//Fin.SkillValue = *SkillValue;
	for( int i = 0 ; i < EM_SkillValueType_MaxCount ; i++ )
	{
		Fin.SkillValue.Skill[i] = __min( SkillValue->Skill[i] , MaxSkillValue.Skill[i] );
	}


	for( int i = 0 ; i < EM_SkillValueType_MaxCount ; i++ )
	{
		Fin.SkillValue.Skill[i] += Mid.Body[ EM_WearEqType_SkillValue_Unarmed + i ] ;
	}
}