#ifndef	__ROLEBASEDEF_H_
#define __ROLEBASEDEF_H_
#pragma	warning (disable:4786)
#pragma warning (disable:4949)
#include "RoleBaseInc.h"
#include <time.h>
#include "MyTypeDef.h"
#include "SmallObj/StaticString.h"
#include "SmallObj/StaticFlag.h"

#pragma unmanaged

#define _DEF_BASE_CLOCL_UNIT_		10          //基本處理的時間
#define	_MAX_LOCALOBJECT_COUNT_		6000        //區域最多物件總量

//帳號最大Size
#define _MAX_ACCOUNT_SIZE_			32			//帳號長度
#define _MAX_CREATETIME_SIZE_		28			//時間字串長度
#define _MAX_NAMERECORD_SIZE_		_MAX_OBJ_NAME_STR_SIZE_			//角色名稱長度
#define _MAX_ROLE_COUNT_			5			//角色數量
#define _MAX_ZONENAME_SIZE_			32			//角色名稱長度
#define	_MAX_LUA_FUNTIONNAMESIZE_	32			//劇情名稱最大字串
#define _MAX_HATELIST_SIZE_			15			//最大可紀錄仇恨名單
#define _MAX_TRADE_ITEM_COUNT_		25
#define _MAX_FRIENDLIST_NOTE_		200			//好友名單註解
#define _MAX_FRIENDLIST_COUNT_		100			//好友最大量

#define	_MAX_BASE_ARG_COUNT_		30			//最多基本參數各數
#define	_MAX_EFFECTMAGIC_COUNT_		16			//身上最多有多少輔助法術

#define _MAX_MONEY_COUNT_           999999999	//金錢上限
#define Def_MONEY_OBJID_            200000      //金錢物件號碼

#define _BASE_ATTACK_SPEED_         15			//基本攻擊速度
#define _BASE_MOVE_SPEED_           40			//基本移動速度

#define _MAX_ROLE_TOUCH_RANGE_		40			// 所有系統觸碰最大範圍
#define _MAX_ROLE_TOUCH_MAXRANGE_	50			// 觸發劇情後, 脫離距離
#define	_TIME_QUEST_CLICKTOGETITEM	5000		// 點擊任務物品所需要的時間

#define _MAX_PARTY_COUNT_			6			//隊伍人數上限
#define _MAX_PARTY_SHARE_RANGE_		1000		//隊伍分享範圍

#define _MAX_SHARE_COLDOWN_COUNT_	30			//共用coldonw上限
//-------------------------------------------------------------------------------------
//		 各種裝備欄位的上限數量
//-------------------------------------------------------------------------------------
#define _MAX_BODY_COUNT_			100			//身上物品最多有多少
#define _MAX_GIVESYSTEM_COUNT_		10			//給予系統最多有多少
#define _MAX_TEMP_COUNT_			10			//暫存區域最多有多少(當系統給予時所儲存的地方)
#define _MAX_BUFF_COUNT_			16			//最多可以上的Buff數量
#define _MAX_REFINE_BUFF_COUNT_		20			//生產Coldown最大值設定		

#define _MAX_TITLE_FLAG_COUNT_		256	
#define _MAX_FLAG_COUNT_			1024	
//-----------------------------------------------------------------------------------------
//數值名稱列舉
//-----------------------------------------------------------------------------------------
enum	RoleValueName_ENUM
{
	EM_RoleValue_HP	= 0		    ,
	EM_RoleValue_MP			    ,
	EM_RoleValue_RACE			,
	EM_RoleValue_VOC  		    ,
	EM_RoleValue_SEX			,
	EM_RoleValue_EXP			,
	EM_RoleValue_LV			    ,

	EM_RoleValue_X			    ,
	EM_RoleValue_Y			    ,
	EM_RoleValue_Z			    ,
	EM_RoleValue_Dir		    ,

    EM_RoleValue_STR            ,
    EM_RoleValue_STA            ,
    EM_RoleValue_INT            ,
    EM_RoleValue_MND            ,
    EM_RoleValue_AGI            ,

    EM_RoleValue_Point          ,
    EM_RoleValue_SkillPoint     ,

    EM_RoleValue_SP			    ,
    EM_RoleValue_Famous         ,

    EM_RoleValue_MaxHP		    ,
    EM_RoleValue_MaxMP		    ,
    EM_RoleValue_MaxSP		    ,

    EM_RoleValue_VOC_SUB	    ,
    EM_RoleValue_LV_SUB		    ,

    EM_RoleValue_ThisLVExp	    ,

    


    EM_RoleValue_NormalMagic    = 500 ,   //法術( EM_RoleValue_NormalMagic 至 + _MAX_NormalSkill_COUNT_
    EM_RoleValue_SPMagic        = 550 ,   //法術( EM_RoleValue_NormalMagic 至 + _MAX_SPSkill_COUNT_

    EM_RoleValue_KeyItemOn      = 600,
    EM_RoleValue_KeyItemOff     ,

	EM_RoleValue_SkillValue		= 700 , 
    //---------------------------------------------------------------------------------------
    //劇情需要的數值        
    //---------------------------------------------------------------------------------------
    EM_RoleValue_IsNPC          = 7000,
    EM_RoleValue_IsPlayer       ,
    EM_RoleValue_OrgID          ,
	EM_RoleValue_AttackTargetID ,
	EM_RoleValue_PID			,
	EM_RoleValue_IsWalk			,


    //---------------------------------------------------------------------------------------
    EM_RoleValueName_EM_FORCE_DWORD   = 0x7fffffff, 

	//(...各像技能)
};
//----------------------------------------------------------------------------------
// 角色管理等級
//----------------------------------------------------------------------------------
enum	ManagementENUM
{
	EM_Management_Nornal		= 0,	//一般玩家

	EM_Management_GameService	=10	,	//遊戲服務者
	EM_Management_GameMaster	,		//遊戲管理者
	EM_Management_BigGM			,		//大GM
	EM_Management_GameCreator	,		//遊戲設計者
};
//----------------------------------------------------------------------------------
// 狀態列舉 (有限狀態機) AI處理列舉
//----------------------------------------------------------------------------------
//例:
// AI1 : Normal -> Spell assist -> Search Enemy -> Attack Enemy  -> Normal
//                                              -> Move          -> Normal
//       under attack -> Attack <-> spell Cure , Atk 
//                    
enum	ActionTypeENUM
{
    EM_ActionType_NORMAL		= 0	,
    EM_ActionType_MOVE			    ,
    EM_ActionType_SEARCHENEMY       ,
    EM_ActionType_ESCAPE            ,
    EM_ActionType_UNDERATTACK       ,
    EM_ActionType_ATTACK            ,
	EM_ActionType_DEAD              ,

    EM_ActionTypeEM_FORCE_DWORD   = 0x7fffffff, 
};
//-------------------------------------------------------------------------------------
//位置資料定義
struct PlayerPosStruct
{
	int	X , Y , Z;
	int Dir;
	int ProcTime;
	PlayerPosStruct()
	{ memset( this , 0 , sizeof(PlayerPosStruct) ); }
};
//-------------------------------------------------------------------------------------
//裝備資料列舉
enum	ItemState_ENUM
{
	EM_ItemState_CliDisabled  = -1          ,
    EM_ItemState_NONE       = 0             ,

    EM_USE_ITEM		        = 0x1000		,	//使用的物品(設定物品使用中)
    EM_USE_SELSELL          = 0x1001		,	//選擇要賣出的

	EM_RECIPE_RESOURCE	    = 0x1100		,	//配方資源索定

    EM_VENDOR_ONSELL1	    = 0x2000		,	//放至於拍賣欄位
    EM_VENDOR_ONSELL2						,
    EM_VENDOR_ONSELL3						,
    EM_VENDOR_ONSELL4						,
    EM_VENDOR_ONSELL5						,
    EM_VENDOR_ONSELL6						,
    EM_VENDOR_ONSELL7						,
    EM_VENDOR_ONSELL8						,

	EM_TRADE_ITEM1	        = 0x3000		,
	EM_TRADE_ITEM2							,
	EM_TRADE_ITEM3							,
	EM_TRADE_ITEM4							,
	EM_TRADE_ITEM5							,
	EM_TRADE_ITEM6							,
	EM_TRADE_ITEM7							,
	EM_TRADE_ITEM8							,
	EM_TRADE_ITEM9							,
	EM_TRADE_ITEM10							,
	EM_TRADE_ITEM11							,
	EM_TRADE_ITEM12							,
	EM_TRADE_ITEM13							,
	EM_TRADE_ITEM14							,
	EM_TRADE_ITEM15							,
	EM_TRADE_ITEM16							,
	EM_TRADE_ITEM17							,
	EM_TRADE_ITEM18							,
	EM_TRADE_ITEM19							,
	EM_TRADE_ITEM20							,
	EM_TRADE_ITEM21							,
	EM_TRADE_ITEM22							,
	EM_TRADE_ITEM23							,
	EM_TRADE_ITEM24							,			  
	EM_TRADE_ITEM25							,

    EM_ItemState_ENUM_FORCE_DWORD   = 0x7fffffff, 

};
//-------------------------------------------------------------------------------------
enum	ItemStateMode_ENUM
{
	EM_ItemStateMode_PickupSoulBound		,		//撿取綁定
	EM_ItemStateMode_None					,		//一般物品
	EM_ItemStateMode_EQSoulBound			,		//裝備過
	EM_ItemStateMode_SoulBound				,		//裝備後綁定(尚未綁定)
	
};
//-------------------------------------------------------------------------------------
struct	ItemStateModeStruct
{
	union
	{
		int				_Mode;
		struct
		{
			//永久狀態
			//物品資料
			bool	Trade				:1;			//可交易
			bool    EQSoulBound			:1;         //裝備禁制
			bool	Reserve2			:1;			//保留
			bool	Reserve3			:1;
			bool	Reserve4			:1;
			bool	Reserve5			:1;
			bool	Reserve6			:1;
			bool	Reserve7			:1;

			bool	Reserve8_15			:8;

			//(暫時狀態)
			bool	EQCannotEquipment	:1;			// true 裝備不可穿(不過目前穿在身上) false 一般狀態
		};
	};

	ItemStateMode_ENUM Mode()
	{
		return (ItemStateMode_ENUM)(_Mode & 0x11);
	}
};
//-------------------------------------------------------------------------------------
//物品欄位定義
// if OrgObjID == 0 代表這個欄位是空的
struct ItemFieldStruct
{
	int				OrgObjID;					//物件樣版的ID

    int             Serial;						//序號 辨識物品是否有拷貝
    int             CreateTime;                 //CreateTime;
	int				Count;						//數量
	int				RuneVolume;					//符文容量

	int 			Durable;					//目前耐久度
    ItemState_ENUM  Pos;                        //所在位置狀態
    int             Inherent;                   //天生附加能力
    int             Rune[4];                    //符石

	ItemStateModeStruct	Mode;					//物品狀態

	void Init()
	{
		memset( this , 0 , sizeof(*this));
	}

	bool operator == ( const ItemFieldStruct& P ) const
	{
        //部份檢查
        if(     OrgObjID    == P.OrgObjID 
            &&  Serial      == P.Serial    
            &&  CreateTime  == P.CreateTime 
            &&  Count       == P.Count      )
            return true;

        return false;
	};

	bool operator != ( const ItemFieldStruct& P ) const
	{
		//部份檢查
		if(     OrgObjID    == P.OrgObjID 
			&&  Serial      == P.Serial    
			&&  CreateTime  == P.CreateTime 
			&&  Count       == P.Count      )
			return false;

		return true;
	};  
	
	bool IsEmpty()
	{   
        if( this == NULL )
            return true;

		return OrgObjID == 0 ;
	}

};
//-------------------------------------------------------------------------------------
//賣出物品暫存結構
struct SellItemFieldStruct
{
	ItemFieldStruct Item;
	int				Money;			//賣出的錢

	bool operator == ( const SellItemFieldStruct& P ) const
	{
		//部份檢查
		if(     Item    == P.Item 
			&&  Money   == P.Money    )
			return true;

		return false;
	};
};
//-------------------------------------------------------------------------------------
enum	PET_ACTION_ENUM
{
    EM_PET_NONE		    ,   // 目前沒命令
    EM_PET_STOP		    ,
    EM_PET_FOLLOW		,
    EM_PET_ATTACK		,
    EM_PET_ATTACKOFF	,
    EM_PET_PROTECT	    ,
    EM_PET_GUARD		,

    EM_PET_PROC_STATE_ENUM_FORCE_DWORD   = 0x7fffffff, 
};
struct PetStruct
{
    PET_ACTION_ENUM		Action;		//目前執行的行為
    int					PetID;		//寵物號碼
    int					TargetID;	//處理的目標
   
    PetStruct()
    {
        Init();
    }

    void Init()
    {
        PetID = -1;
        TargetID = -1;
    }
};
//-------------------------------------------------------------------------------------
struct		RoleTableStruct
{
    union
    {
        float	Skill[_MAX_SKILL_COUNT_];
        struct
        {
            float		BeatPro;			
            float		BladePro;		
            float		SwordPro;		
            float		AxeHammerPro;
            float		StickPro;		
            float		PikePro;			
            float		RodPro;			
            float		DaggerPro;		
            float		EctPro;			
            float		BowPro;			
            float		RefinePro;		
            float		MeditationPro;	
        };
    };
    int MaxExp;
};
//-------------------------------------------------------------------------------------
enum	MAGIC_PROC_STATE_ENUM
{
	EM_MAGIC_PROC_STATE_NORMAL				    ,	//一般非施法狀態
	EM_MAGIC_PROC_STATE_PERPARE				    ,	//準備施法中
	EM_MAGIC_PROC_STATE_SHOOT					,	//射出
	EM_MAGIC_PROC_STATE_SPELL				    ,	//施法中
	EM_MAGIC_PROC_STATE_INTERRUPT				,	//施法中斷
	EM_MAGIC_PROC_STATE_ENDSPELL				,	//施法剛結束
    EM_MAGIC_PROC_STATE_EM_FORCE_DWORD   = 0x7fffffff, 
};
//-------------------------------------------------------------------------------------
/*
enum	MAGIC_VALUE_TYPE_ENUM
{
	EM_MAGIC_VALUE_NONE			,	//不始用
	EM_MAGIC_VALUE_REPLACE		,	//取代
	EM_MAGIC_VALUE_ADD			,	//加上
	EM_MAGIC_VALUE_MUL			,	//乘
};
//-------------------------------------------------------------------------------------
//法術劇情數值設定
struct  MagicScriptValueStruct
{
	float					Value;
	MAGIC_VALUE_TYPE_ENUM	Type;		
};
*/
//-------------------------------------------------------------------------------------
//施法的狀態資訊
struct MagicProcInfo
{
	int						SerialID;			//法術序號

	MAGIC_PROC_STATE_ENUM	State;
	Int32					TargetID;			//目標
	Int32					MagicCollectID;		//法術集合ID
	
	Int32					ProcTime;			//執行時間

	float					BeginX;				//開始施法的位置
	float					BeginZ;				//開始施法的位置

	float					TargetX;			//目標位置x
	float					TargetY;			//目標位置y
	float					TargetZ;			//目標位置z

    Int32					UseItem;			//使用的物品
	short					UseItemPos;			//物品的位置
    short                   UseItemType;        // 0 身體 1 銀行 2 EQ


	//-------------------------------------------
	bool					IsSpellCheckOK;		//可以施法 
	bool					IsSuccess;			//施法成功

	int						SpellCount;			//還要施展幾次
	int						NextSpellTime;		//下次施展的時間

	//-------------------------------------------
	//法術主體可設定數值
	bool					MagicEnabled[8];	//那些法術為Enabled ( 初始全開 劇情可控制 )
	float					Coldown;
	MagicSpellCostTypeENUM	CostType;
	float					CostValue;
	MagicSpellNeedTypeENUM	NeedType;
	float					NeedValue;
	//法術單體設定數值
	float					SpellTime;			//施法時間
	float					HitRate;			//命中率(Shooting Average)
	float					Power;				//法術威力
	float					EffectTime;			//影響時間


	//設定法術序號
	int SetSerialID()
	{
		static int ID = 0;
		SerialID = ID++;
		return SerialID;
	}

	void Init()
	{
		memset( this , 0 , sizeof(*this) );
		for( int i = 0 ; i < 8 ; i ++ )
			MagicEnabled[i] = true;
	
	}

	void InitMagicEnabled()
	{
		for( int i = 0 ; i < 8 ; i ++ )
			MagicEnabled[i] = true;
	}


	bool CheckInterrupt( float x , float z)
	{
		if(	State != EM_MAGIC_PROC_STATE_PERPARE )
			return false;

		if(		abs( int( x - BeginX ) ) > 10 
			||	abs( int( z - BeginZ ) ) > 10 )
		{
			State = EM_MAGIC_PROC_STATE_INTERRUPT;
			return true;
		}

		return false;
	};

	void ClsUseItem()
	{
		UseItem		= 0;
		UseItemPos	= -1;
        UseItemType	= -1;
	};
		
	
};
//-------------------------------------------------------------------------------------
//身體與銀行資料
struct ItemStruct
{
    ItemFieldStruct     Item[ _MAX_BODY_COUNT_];
    int                 Count;
    int                 Money;

    void Init()
    {
        memset( this , 0 , sizeof(*this) );
    }
};
//-------------------------------------------------------------------------------------
enum    EQWearPosENUM
{
    EM_EQWearPos_None       = -1 , 
    EM_EQWearPos_Head       ,//0
    EM_EQWearPos_Gloves	    ,//1
    EM_EQWearPos_Shoes		,//2
    EM_EQWearPos_Clothes	,//3
    EM_EQWearPos_Pants		,//4
    EM_EQWearPos_Back		,//5
    EM_EQWearPos_Belt		,//6
    EM_EQWearPos_Shoulder	,//7
    EM_EQWearPos_Necklace   ,//8
    EM_EQWearPos_Ammo       ,//9
    EM_EQWearPos_Ring1      ,//10
    EM_EQWearPos_Ring2      ,//11
    EM_EQWearPos_Earring1   ,//12
    EM_EQWearPos_Earring2   ,//13
    EM_EQWearPos_MainHand	,//14
    EM_EQWearPos_SecondHand ,//15
	EM_EQWearPos_Manufactory,//16

	EM_EQWearPos_MaxCount	,

    EM_EQWearPosENUM_FORCE_DWORD   = 0x7fffffff, 
};
//-------------------------------------------------------------------------------------
struct EQStruct
{
	union
	{
        ItemFieldStruct Item[ EM_EQWearPos_MaxCount ];
        
        
		struct 
		{
			ItemFieldStruct Head			;//頭
			ItemFieldStruct Gloves	    	;//手套
			ItemFieldStruct Shoes			;//鞋子
			ItemFieldStruct Clothes		    ;//上衣
			ItemFieldStruct Pants			;//褲子
			ItemFieldStruct Back			;//背部
			ItemFieldStruct Belt			;//腰帶
            ItemFieldStruct Shoulder		;//肩甲
            ItemFieldStruct Necklace        ;//項鍊
            ItemFieldStruct Ammo            ;//彈藥

            ItemFieldStruct Ring1;          ;//戒子
            ItemFieldStruct Ring2;          ;
            ItemFieldStruct Earring1        ;//耳飾	
            ItemFieldStruct Earring2        ;			

            ItemFieldStruct MainHand		;//主手
            ItemFieldStruct SecondHand		;//副手

			ItemFieldStruct Manufacture    ;//生產製造欄位
		};
	};

	void	Init()
	{
		memset( &Item , 0 , sizeof(Item) );
	};
};
//-------------------------------------------------------------------------------------
//目前行為模式資料
//-------------------------------------------------------------------------------------

struct		RoleActionStruct
{
	union
	{
		UInt32		_Action;
        struct      
        {
            short   _LowAction;
            short   _HiAction;
        };
		struct
		{
            //前16改變不送資料
			bool	Reserve_Move	:1;		//移動
			bool	Attack			:1;		//攻擊
			bool	Reserve_Spell	:1;		//施法
			bool	Follow	        :1;		//跟隨
            bool    Login	        :1;		//第一次登入
            bool    Reserve5        :1;
            bool    Reserve6        :1;
            bool    Reserve7        :1;
            bool    Reserve8_15     :8;

			bool	Dead			:1;		//死亡
			bool	Walk			:1;		//跑步or走路
            bool    Trade           :1;     //交易中
            bool    AttackMode      :1;     //攻擊中(Cli的攻擊狀態)
			bool	Shop			:1;
			bool	Bank			:1;
			bool	Sit				:1;
		};
	};
};
//-------------------------------------------------------------------------------------
//角色顯像資料
//-------------------------------------------------------------------------------------
struct PlayerGraphStruct
{
	int					                    OrgObjID;						//物件原始ID
    StaticString< _MAX_NAMERECORD_SIZE_ >   Name;
	ObjectModeStruct                    	Mode;   
	int		                                MaxHP;
	int		                                MaxMP;
	int		                                MaxSP;
	int		                                HP;
	int		                                MP;
	int		                                SP;
	float	                                MoveSpeed;
	float			                    	ModelRate;						//模型大小比例
	int				                    	Level;							//物件等級
    int                                     NpcQuestID;
    short                                   TouchPlot_Range;
    short                                   RangePlot_Range;
    RoleActionStruct		                Action;			                //目前的行動狀態

};
//-------------------------------------------------------------------------------------
//角色位置資料定意
//-------------------------------------------------------------------------------------
struct RolePosStruct
{
    float   X , Y , Z ;
    float   Dir;
};
//-------------------------------------------------------------------------------------
//角色數值資料
//-------------------------------------------------------------------------------------
struct BaseAbilityStruct
{
	int		EXP;
	int		Level;

	int		Point;				//可配置點數
	int		SkillPoint;			//可配置技能點數

    int 	STR;			    // 力量
    int 	STA;			    // 耐力
    int 	MND;			    // 智慧
    int     INT;                // 聰明
    int 	AGI;			    // 敏捷

//    int     MagicPoint[ _MAX_NormalSkill_COUNT_ ];       //此職業的法術配點
};
//-------------------------------------------------------------------------------------
// 目前所會法術結構
//-------------------------------------------------------------------------------------
struct SkillStruct
{
    union
    {
        int AllSkill[ _MAX_SPSkill_COUNT_+_MAX_NormalSkill_COUNT_+_MAX_NormalSkill_COUNT_ ];
        struct
        {
            int SP [ _MAX_SPSkill_COUNT_ ];				//職業專屬技能
            int MainJob[ _MAX_NormalSkill_COUNT_ ] ;	//主職一般技能
            int	SubJob[ _MAX_NormalSkill_COUNT_ ];		//副職一般技能
        };
    };   
};
//-------------------------------------------------------------------------------------
//npc移動模式
/*
enum    NPC_MOVETYPE_ENUM
{
    EM_NPC_MOVETYPE_NORMAL  = 0     ,   //一般
    EM_NPC_MOVETYPE_FOLLOW          ,   //緊跟目標
    EM_NPC_MOVETYPE_ATK_FOLLOW      ,   //追擊
    EM_NPC_MOVETYPE_ESCAPE          ,   //逃跑
    EM_NPC_MOVETYPE_KEEP_DISTANCE   ,   //保持一定距離(遠程武器攻擊範圍)
    EM_NPC_MOVETYPE_RANDOM_MOVE     ,   //亂移動

};
*/
//-------------------------------------------------------------------------------------
enum CampID_ENUM
{
	EM_CampID_Unknow	= -1,
	EM_CampID_Player	= 0	,
	EM_CampID_Monster		,
	EM_CampID_Guard			,
	EM_CampID_Thief			,
	EM_CampID_Other4		,
	EM_CampID_Other5		,
	EM_CampID_Other6		,
	EM_CampID_Other7		,
	EM_CampID_Other8		,
	EM_CampID_Other9		,
	EM_CampID_Other10		,
	EM_CampID_Other11		,
	EM_CampID_Other12		,
	EM_CampID_Other13		,
	EM_CampID_Other14		,
};

//AI 資料結構
struct  NPC_AI_Struct
{
    ActionTypeENUM		ActionType;		    //行為模式
    ActionTypeENUM		LActionType;	    //行為模式

	int		TargetID;				//攻擊或跟隨目標
	int		LTargetID;				//最後一次攻擊的目標(用來檢測是否目標有更換)
	UInt32	NextAtkTime;			//下一次可攻擊時間
    int     AttackCount;            //攻擊累積次數

    //時間以0.1秒為單位
    int     AddAtkTime;
    int     NextMainAtk;            //下一次主手攻擊
    int     NextSecAtk;             //下一次副手攻擊

    int     AttackID;               //攻擊者的ID

	CampID_ENUM		CampID;			//所屬陣營
};
//-------------------------------------------------------------------------------------
//怪物被打到的資訊
//(仇恨資料)
struct  NPCHateStruct
{
	int		DBID;
	int		ItemID;
	int		HitPoint;
	int		HatePoint;
	int		TempHatePoint;

    void Init()
    {
        DBID        = -1;
        ItemID      = -1;
        HitPoint    = 0;
        HatePoint   = 0;
		TempHatePoint = 0;
    };

	int TotalHatePoint()
	{
		return HatePoint + TempHatePoint;
	}
};
//-------------------------------------------------------------------------------------
//怪物仇恨資訊 ， 怪物 ai 使用
struct NPCHateList
{
    StaticVector< NPCHateStruct , _MAX_HATELIST_SIZE_ >     Hate;
	Int32       MaxHitPoint;					//最大攻擊力
	
	void Init( )
	{
        MaxHitPoint = 0;
        Hate.Clear();
		//memset( this , -1 , sizeof(*this) );
	}

    NPCHateStruct*     GetMaxHit( )                  //找出打血最多的人
    {
        int MaxHit = -1;
        int MaxHitID = -1;
        for( int i = 0 ; i < Hate.Size() ; i++ )
        {
            if( Hate[i].HitPoint > MaxHit )
            {
                MaxHit   = Hate[i].HitPoint;
                MaxHitID = i;
            }
        }

        if( MaxHitID == -1 )
            return NULL;
        
        return &Hate[ MaxHitID ];
    
    }
    
};
//-------------------------------------------------------------------------------------
// 需定時處理的事件
//( 某部份資料有變動 )
//-------------------------------------------------------------------------------------
struct		RoleUpdateEvent
{
	union
	{
		UInt32		_Event;
		struct
		{
			bool	Bank			:1;		
			bool	Body			:1;		
			bool	Eq				:1;
            bool    Money           :1;
			bool	Recalculate		:1;
			bool	ExpChange		:1;
			bool	LvChange		:1;		//Save
            bool	ReSetTalbe		:1;
            bool    Trade           :1;
            bool    HPMPSP          :1;
            bool    MoveSpeed       :1;

			//--------------------------
			bool	SkillPointChange:1;
			bool	FriendListModify:1;		//自己的資訊有改變要通知Chat 並轉通知Client
			bool	SkillKeyItemChange:1;	//技能書類型的重要物品改變
        };
	};
	bool	CheckResetItemInfo()
	{
		return Bank|Body|Eq;
	}
};
//-------------------------------------------------------------------------------------
//		容貌結構
//-------------------------------------------------------------------------------------
struct LookStruct
{
    int FaceID;
    int HairID;
    int HairColor;
    int BodyColor;

    LookStruct()
    {
        memset( this , 0 , sizeof(*this) );
    }

    bool IsEmpty()
    {
        return ( FaceID == 0 && HairID == 0 && HairColor ==0 && BodyColor == 0 );
    }
};
//-------------------------------------------------------------------------------------
//兩人交易結構
struct TradeStruct
{
	int	                Money;
    int					TargetID;	//交易目標
	
	bool	            SelectOK;	//物品選則OK
	bool	            FinalOK;	//交易成立


	TradeStruct()
	{
		Init();
	};

	void Init()
	{
		memset( this, 0 , sizeof(*this));
	};
};
//-------------------------------------------------------------------------------------
struct ShopStateStruct
{
    int     TargetID;
    int     ShopObjID;          //販賣物品的物件
    int     ItemCount[30];

    StaticString< _MAX_LUA_FUNTIONNAMESIZE_> ShopClosePlot;	    //商店關閉時執行的劇情

    void Init()
    {
        memset( this , 0 , sizeof(*this) );
    }

};
//-------------------------------------------------------------------------------------
//可被偷竊資訊
struct StealStruct
{
	ItemFieldStruct	Item;	//可被偷竊的物品
	int	ItemSuccessRate;	//成功的機率

	int	Money;				//可被偷竊的金錢
	int	MondySuccessRate;	//成功的機率
};
//-------------------------------------------------------------------------------------
//使用中的物品
struct UseItemStruct
{
    short                 Pos;
    short                 Type;

	UseItemStruct()
	{
		Init();
	};

	void Init()
	{
        Pos = -1;
	};
};
//-------------------------------------------------------------------------------------
//攻擊模式列舉
enum	ATTACK_MODE_ENUM
{
	EM_ATTACKMODE_LEFTHAND	= 0	,	
	EM_ATTACKMODE_RIGHTHAND		,	
	EM_ATTACKMODE_BOTHHAND		,	
	EM_ATTACKMODE_NONE			,
    EM_ATTACK_MODE_EM_FORCE_DWORD   = 0x7fffffff, 
};
//-------------------------------------------------------------------------------------
//攻擊砍殺類型列舉
enum	ATTACK_DMGTYPE_ENUM
{
	EM_ATTACK_DMGTYPE_MISS,			    //MISS
    EM_ATTACK_DMGTYPE_DODGE,		    //DODGE
	EM_ATTACK_DMGTYPE_HALF,			    //被隔檔
	EM_ATTACK_DMGTYPE_NORMAL,			//一般
	EM_ATTACK_DMGTYPE_DOUBLE,			//會心一擊
	EM_ATTACK_DMGTYPE_TRIPLE,			//必殺一擊
	EM_ATTACK_DMGTYPE_HITBACK,          //反擊
	EM_ATTACK_DMGTYPE_NO_EFFECT,		//沒效果
	EM_ATTACK_DMGTYPE_ABSORB,			//吸收
    EM_ATTACK_DMGTYPE_EM_FORCE_DWORD   = 0x7fffffff, 
};
//-------------------------------------------------------------------------------------
//攻擊主副手列舉
enum AttackHandTypeENUM
{
	EM_AttackHandType_None		,
	EM_AttackHandType_Main		,
	EM_AttackHandType_Second	,
};
//-------------------------------------------------------------------------------------
//Local Server 的基本資訊
struct	LocalServerBaseDBInfoStruct
{
	int		ItemVersion;				//目前物品的序號(0 - 9999999) 只有不可堆疊的物品有序號
	int		Tax;						//稅率	
	int		TaxIncoming;				//稅收

	LocalServerBaseDBInfoStruct()
	{
		ItemVersion = 0;
		Tax = 0;
		TaxIncoming = 0;
	}
};
//-------------------------------------------------------------------------------------
#define		_MAX_PARTY_COUNT_		6
//party 成員結構
struct	PartyMemberStruct
{
	int		DBID;		//資料庫ID
	int		LocalID;	//區域ID
	int		ZoneID;

    StaticString< _MAX_NAMERECORD_SIZE_ > Name;

	bool	IsEmpty()
	{
        if( this == NULL )
            return true;

		return ( DBID == 0 );
	}
};

//Party結構資料
struct	PartyStruct
{
	Int16	Count;				//成員人數
	Int32	PartyID;			//隊伍ID
	Int32	LeaderDBID;			//隊長的資料庫ID
	
//	PartyMemberStruct Member[ _MAX_PARTY_COUNT_ ];
  	StaticVector< PartyMemberStruct , _MAX_PARTY_COUNT_ > Member;
/*
	void	Init()
	{
		memset( this , 0 , sizeof(*this) );
		PartyID	= -1;
	};

	bool	IsEmpty() 
	{
		return ( PartyID == -1 );
	};
*/
};
//-------------------------------------------------------------------------------------
struct NPC_RandomMoveStruct
{
	bool				Enable;		//亂數移動致能	
	int					Active;		//亂數移動激活數 (一秒檢查一次 設定執行機率 % )

    int 				CountDown;	//發動倒數 記錄要走到的時間

	float				CenterX;	//移動範圍中心點X
	float				CenterZ;	//移動範圍中心點Z
	float				MaxRange;	//最遠移動範圍
	
	float				Dist;		//移動距離平均值

	NPC_RandomMoveStruct()
	{
		Init();
	};

	void Init()
	{
		Enable		 = false;
		Active		 = 10;
		CenterX      = -1;	    //移動範圍中心點X
		CenterZ      = -1;	    //移動範圍中心點Z
		MaxRange     = 500;	    //最遠移動範圍
	    
		CountDown    = 0;	    //發動倒數

		Dist         = 100;	    //移動距離平均值
		
	};
};
//-------------------------------------------------------------------------------------
enum	NPC_MoveTypeENUM
{
	EM_NPC_MoveType_None		,//不設定用之前的
	EM_NPC_MoveType_Walk		,//走路 
	EM_NPC_MoveType_Run			,//跑部
	EM_NPC_MoveType_Rand		,//走路或跑步
};


//NPC定點移動
struct NPC_MoveBaseStruct
{
	float				X , Y , Z;		//移動位置	
	float				Dir;			//面向
	float				Range;			//移動偏差距離
	NPC_MoveTypeENUM	MoveType;		//移動方式
	int					WaitTime_Base;	//基本等待時間(秒)
	int					WaitTime_Rand;	//亂數等待時間(秒)
										//等待時間 = Base + Rand( )
	int					ActionType;		//動作ID ( -1 忽略)
};

struct DB_NPC_MoveBaseStruct
{
	int		ZoneID;		//區域ID
	int		NPCDBID;	//NPCDBID
	int		IndexID;	//位置
	NPC_MoveBaseStruct Base;
};

//-------------------------------------------------------------------------------------
// 系統管理相關資訊
//-------------------------------------------------------------------------------------
struct SysManageInfoStruct
{
    int						SaveSerial;					//儲存順序號碼
    union
    {
        int     GUID;
        struct
        {
            short   ItemID;            
            short   ZoneID;
        };
    };

    union
    {   //擁有者id
        int     OwnerGUID;
        struct
        {
            short   OwnerItemID;            
            short   OwnerZoneID;
        };
    };

    int                     WorldGUID;                  //所有代表同一個物件的物件有相同的 ID

    int						SockID;						//封包收送Id
    int                     ProxyID;                    //處理的Proxy
    int                     SecRoomID;
    int						SecX,SecZ;					//所在分割區的位置
    long					CreateTime;					//物件產生的時間
    int						LoginProtect;				//登入保護，怪物剛產生與角色剛登入時怪物不會主動攻擊
    int                     MirrorCount;                //此物件是否有Mirror的物件,有多少個
    int                     LGUID;
    int                     ChangeZoneTime;             // 0 才可換區

    union
    {
        int                 _DebugFlag;
        struct
        {
            bool	LuaDebugMsg	    	:1;

        };
    };

    void Init()
    {
        SaveSerial  = 0;
        GUID        = -1;
        SockID      = -1;
        OwnerGUID   = -1;
        SecRoomID   = -1;
        SecX        = -1;
        SecZ        = -1;
        WorldGUID   = -1;
        LGUID       = -1;
        LoginProtect= 15;
        MirrorCount = 0;
        ChangeZoneTime = 0;
        _DebugFlag  = 0;

        _time32( (long *)(&CreateTime) );
        
    }
};
//-------------------------------------------------------------------------------------
// 路徑處理相關資訊
//-------------------------------------------------------------------------------------
enum	ClientMoveTypeENUM
{
	EM_ClientMoveType_Normal	,
	EM_ClientMoveType_Jump		,
};

struct	PathProcStruct
{
    int			AddeDelay;				//因為特殊事件產生的移動暫停
    int			ProcDelay;				//可以處理移動剩下的時間
    float		Dx , Dy , Dz;			//移動向量
    float		Tx , Ty , Tz;			//npc目標

	float		RetX , RetY , RetZ;		//戰鬥後要退回的位置

    UInt32      LastMoveTime;           //最後移動的時間

	ClientMoveTypeENUM	MoveType;		//記錄玩家移動的方式
	//----------------------------------------------------------
	//(用來檢查是否有加速)
	float		CliX , CliY , CliZ;		//Cli端最後一次送出的位置
	float		CalMoveLen;				//移動總計
	UInt32		CliLastMoveTime;
	//----------------------------------------------------------
	int			LockTargetPosX , LockTargetPosZ;	//目標位置鎖定
	//----------------------------------------------------------
};
//-------------------------------------------------------------------------------------
//登入定時處理的事件資訊
//-------------------------------------------------------------------------------------
struct SimpleSchedularInfo
{
    int      SearchEnemyID;
    int      MoveID;
    int      AiID;
    int      AttackID;
    int      SpellMagicID;
};
//-------------------------------------------------------------------------------------
enum SmallGameTypeEnum
{
    EM_SmallGameType_None       = 0 ,
    EM_SmallGameType_WaitJoint      ,
    EM_SmallGameType_Big2           ,
};
struct  SmallGameInfoStruct
{
    SmallGameTypeEnum GameType;              //表示smallgame ok

     
//    int     TradeMoney;         //轉出去的金錢
};
//-------------------------------------------------------------------------------------
//資料庫物品欄位資訊
struct DB_ItemFieldStruct
{
	int	DBID;
	int FieldID;
	int	FieldType;

	ItemFieldStruct Info;
};
//-------------------------------------------------------------------------------------
//角色屬性
struct DB_AbilityStruct
{
	int	DBID;
	int	Job;

	BaseAbilityStruct Info;
};


//-------------------------------------------------------------------------------------
// 任務結構
#define _MAX_QUEST_COUNT_				20			// 角色最多可以接的 Quest 數量
#define _MAX_QUEST_FLAG_COUNT_			2048		// 角色目前完成 Quest 的數量, 目前最多設定 2048
#define _MAX_QUEST_KILLKIND_COUNT_		5			// 每一個 Quest 指定打倒目標的種類
#define _MAX_QUEST_CLICKIND_COUNT_		5

enum EM_QUESTCHECK_RESULT
{
	EM_QUESTCHECK_RESULT_OK				= 0,
	EM_QUESTCHECK_RESULT_NOTEXIST		,	// NPC 不存在
	EM_QUESTCHECK_RESULT_TOOFAR			,	// 距離 Quest NPC 太遠
	EM_QUESTCHECK_RESULT_FULL			,	// Clinet 所擁有的 Quest 清單已滿
	EM_QUESTCHECK_RESULT_NOTLIST		,	// Clinet 所擁有的 Quest 清單上並沒有該項 Quest
	EM_QUESTCHECK_RESULT_NOTOK			,	// 檢查完成條件時發現尚未完成
};


struct QuestStruct
{
	struct QuestInfo
	{
		int		iQuestID;
		int		iMode;

	} QuestLog[ _MAX_QUEST_COUNT_ ];		// Client 身上有的 Quest 清單

	StaticFlag<_MAX_QUEST_FLAG_COUNT_>			QuestHistory;						// 目前最多 2048 個 Quest , 用來紀錄那些 Quest 已完成
	BYTE 										iQuestKillCount[_MAX_QUEST_COUNT_][_MAX_QUEST_KILLKIND_COUNT_];
																					// 紀錄目前任務, 宰殺紀錄  20 Quest, 3 Kind
};

struct QuestKillStruct
{
	int		iKillObj		[ _MAX_QUEST_KILLKIND_COUNT_ ];	// 指定打倒目標的樣版代號
	int		iKillVal		[ _MAX_QUEST_KILLKIND_COUNT_ ];	// 指定打倒目標的數量
	float	fDropPercent	[ _MAX_QUEST_KILLKIND_COUNT_ ];	// 打倒指定目標掉落機率
	int		iDropItem		[ _MAX_QUEST_KILLKIND_COUNT_ ];	// 掉落物品
	int		iDropItemVal	[ _MAX_QUEST_KILLKIND_COUNT_ ];	// 掉落物品數量
};

struct QuestClickStruct
{
	int		iClickObj		[ _MAX_QUEST_CLICKIND_COUNT_ ];
	float	fProcPercent	[ _MAX_QUEST_CLICKIND_COUNT_ ];
	int		iDropItem		[ _MAX_QUEST_KILLKIND_COUNT_ ];	// 掉落物品
	int		iDropItemVal	[ _MAX_QUEST_KILLKIND_COUNT_ ];	// 掉落物品數量
};

/*
struct QuestTempDataStruct
{
	BYTE				QuestKillCount;
	BYTE				QuestKillIndexTable		[ _MAX_QUEST_COUNT_ ];	// 紀錄是第幾個 QuestField 有打倒計數	
	QuestKillStruct		QuestKill				[ _MAX_QUEST_COUNT_ ];

	BYTE				QuestCollectCount;
	BYTE				QuestCollectIndexTable	[ _MAX_QUEST_COUNT_ ];
	QuestClickStruct	QuestCollect			[ _MAX_QUEST_COUNT_ ];

	int					iQuestResult;
};
*/

// 採礦, 取得任務物件時排程給予物品的紀錄
struct CastingData
{
	int iEventHandle;
	int iGUID;
	int iQuestID;
	int iClickObj;
	int iClickObjID;
	int iClickGetObj;
	int iClickGetObjCount;
};
//-------------------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
//			公會資料設定
//////////////////////////////////////////////////////////////////////////
//公會功能設定
struct GuildManageSettingStruct
{
	union
	{
		int		Type;
		struct  
		{
			bool	Invite			: 1;	//招收
			bool	AdjustRank		: 1;	//調整階級
			bool	SetGuildNote	: 1;	//設定公告
			bool	Kick			: 1;	//踢除會員
			bool	AdjustGroup		: 1;	//調整群組
			bool	EditMemberNote	: 1;	//設定成員註解
			bool	PostMessage		: 1;	//留言
			bool	ManageMessage	: 1;	//留言板管理
		};
	};
};
//-------------------------------------------------------------------------------------
//公會等級
enum  GuildRankENUM
{
	EM_GuildRank_0			,
	EM_GuildRank_1			,
	EM_GuildRank_2			,
	EM_GuildRank_3			,
	EM_GuildRank_4			,
	EM_GuildRank_5			,
	EM_GuildRank_6			,
	EM_GuildRank_7			,
	EM_GuildRank_8			,
	EM_GuildRank_Leader		,

	EM_GuildRank_Count		,

};
//-------------------------------------------------------------------------------------
struct GuildStruct;

//公會成員資料
struct GuildMemberStruct
{
	GuildStruct*			Guild;				//公會資料聯結

	int						GuildID;
	StaticString< _MAX_NAMERECORD_SIZE_ >   MemberName;
	int						MemberDBID;
	GuildRankENUM			Rank;				//角色公會等級
	int						GroupID;			//所在群組
	StaticString< 256 >   	SelfNote;			//自己註解
	StaticString< 256 >   	LeaderNote;			//會長的註解
	int						RankTime;			//就職時間
	bool					IsNeedSave;			//如果資料有更動則會為 true
	bool					IsOnline;

	Voc_ENUM				Voc;
	Voc_ENUM				Voc_Sub;
	Sex_ENUM				Sex;
	int						LV;
	int						LV_Sub;
	
	GuildMemberStruct()
	{
		memset( this , 0 , sizeof(*this) );
	}
};
//-------------------------------------------------------------------------------------
//公會Rank 資料
struct GuildRankBaseInfoStruct
{
	GuildManageSettingStruct				Setting;
	StaticString< _MAX_NAMERECORD_SIZE_ >   RankName;	//名稱
};

//-------------------------------------------------------------------------------------
#define		_MAX_GUILD_GROUP_COUNT_	10
//公會結構
struct GuildBaseStruct
{
	int		GuildID;									//公會ID
	StaticString< _MAX_NAMERECORD_SIZE_ >   GuildName;	//公會名稱
	StaticString< _MAX_NAMERECORD_SIZE_ >   LeaderName;	//會長名稱
	int		LeaderDBID;
	bool	IsRecruit;									//是否招生
	bool	IsReady;									//是否正式成立
	bool	IsNeedSave;									//如果資料有更動則會為 true
	int		Medal;										//徽章
	StaticString< 512 >   Note;							//公告
	StaticString< 512 >   Introduce;					//公會介紹

	int		RankCount;									//公會階層數
	GuildRankBaseInfoStruct	Rank[ EM_GuildRank_Count ];						//每個等級的權限 與名稱
	StaticString< _MAX_NAMERECORD_SIZE_ >   Group[_MAX_GUILD_GROUP_COUNT_];	//群組名稱
	

	void Init()
	{
		memset( this , 0 , sizeof(*this) );
	}
};
//-------------------------------------------------------------------------------------
//留言版狀態
struct GuildBoardModeStruct
{
	union
	{
		int		_Type;
		struct  
		{
			bool	Top : 1;	//置頂
			bool	Del : 1;	//被刪除
		};
	};

};

//公會留言板
struct GuildBoardStruct
{
	int						GUID;		//序號
	int						GuildID;	//公會ID
	GuildBoardModeStruct	Type;		//狀態
	StaticString< 128 >		Title;		//標題
	StaticString< 512 >		Message;	//訊息
	int						Time;		//發表時間
	StaticString< _MAX_NAMERECORD_SIZE_ >   PlayerName;	    //發表人
};

//////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------
//法術Buff資料
struct BuffBaseStruct
{
    int     OwnerID;
    int     BuffID;         //魔法ID
    int     Time;           //剩下時間(秒)
	float	Power;			//威力
	int		Point;			//點數( 魔法盾可擋點數 or 次數)

	GameObjDbStruct*	Magic;	
};
//-------------------------------------------------------------------------------------
//法術Buff資料
struct RefineBuffStruct
{
	int RecipeID;
	int	Coldown;
};
//-------------------------------------------------------------------------------------
//角色資料貝份,用來更新周圍環境資訊
struct RoleBackupInfo
{
    //數值
    int     MaxHP;
    int     MaxMP;
    int     MaxSP;
    int     MaxSP_Sub;
    int     HP;
    int     MP;
    int     SP;
	int		SP_Sub;

	int		MoveSpeed;

    //跳或掉落起始
    bool    StartJump;
    float   Y;
};
//-------------------------------------------------------------------------------------
#define DEF_MAX_COLDOWN_COUNT_JOB_	20
#define DEF_MAX_COLDOWN_COUNT_EQ_	15
#define DEF_MAX_COLDOWN_COUNT_ITEM_	30
#define DEF_MAX_COLDOWN_COUNT_ALL	( DEF_MAX_COLDOWN_COUNT_JOB_ + DEF_MAX_COLDOWN_COUNT_EQ_ + DEF_MAX_COLDOWN_COUNT_ITEM_ + 1 )
#define DEF_COLDOWN_ALL_POS			0
#define DEF_COLDOWN_JOB_POS			1
#define DEF_COLDOWN_EQ_POS			( DEF_COLDOWN_JOB_POS + DEF_MAX_COLDOWN_COUNT_JOB_ )
#define DEF_COLDOWN_ITEM_POS		( DEF_COLDOWN_EQ_POS + DEF_MAX_COLDOWN_COUNT_EQ_ )
//所有法術Coldown
struct MagicColdownStruct
{
	union
	{
		int	All[ DEF_MAX_COLDOWN_COUNT_ALL];
		struct  
		{
			int	AllMagic;								//下次可失法的時間 (所有法術)
			int	Job	[ DEF_MAX_COLDOWN_COUNT_JOB_  ];	
			int	Eq	[ DEF_MAX_COLDOWN_COUNT_EQ_   ];	
			int	Item[ DEF_MAX_COLDOWN_COUNT_ITEM_ ];
		};
	};

	//需要更新時間的位置
	StaticVector< char , DEF_MAX_COLDOWN_COUNT_ALL > NeedUpdatePos;

	void Init()
	{
		memset( this , 0 , sizeof(*this) );
	}
};
//-------------------------------------------------------------------------------------
//好友名單
struct BaseFriendStruct
{
	bool		IsSave;
	StaticString< _MAX_NAMERECORD_SIZE_ >   Name;	    //角色名稱
	StaticString< _MAX_NAMERECORD_SIZE_ >   Group;	    //資料夾名稱
	StaticString< _MAX_FRIENDLIST_NOTE_ >   Note;	    //對朋友的註解

	bool IsEmpty()
	{
		return ( Name.Size() == 0 );
	}
	void Clear()
	{
		memset( this , 0 , sizeof(*this) );
	}
};

struct FriendListStruct 
{
	StaticString< _MAX_FRIENDLIST_NOTE_ >   Note;	    //自己註解
	BaseFriendStruct						FriendList[ _MAX_FRIENDLIST_COUNT_ ];		//好有名單
	StaticString< _MAX_NAMERECORD_SIZE_ >   BadFriendList[ _MAX_FRIENDLIST_COUNT_ ];	//黑名單    

	bool	ModifyFriend( char* Name  , char* Group , char* Note )
	{
		int	i;
		if( Name[0] == 0 )
			return  false;
		
		for( i = 0 ; i < _MAX_FRIENDLIST_COUNT_ ; i++ )
		{		
			if( strcmp( FriendList[i].Name.Begin() , Name ) == 0 )
			{
				FriendList[i].Group = Group;
				FriendList[i].Note	= Note;
				return true;
			}
			
		}

		return false;
	}

	bool	AddFriend( char* Name  , char* Group , char* Note )
	{
		int	i;
		//看名稱是否有重覆
		for( i = 0 ; i < _MAX_FRIENDLIST_COUNT_ ; i++ )
		{
			if( strcmp( FriendList[i].Name.Begin() , Name ) == 0 )
				return false;
		}

		for( i = 0 ; i < _MAX_FRIENDLIST_COUNT_ ; i++ )
		{
			if( FriendList[i].IsEmpty() )
			{
				FriendList[i].Name  = Name;
				FriendList[i].Group = Group;
				FriendList[i].Note	= Note;
				return true;
			}		
		}
		return false;
	}

	bool	DelFriend( char* Name )
	{
		int	i;
		//看名稱是否有重覆
		for( i = 0 ; i < _MAX_FRIENDLIST_COUNT_ ; i++ )
		{
			if( strcmp( FriendList[i].Name.Begin() , Name ) == 0 )
			{
				FriendList[i].Clear();
				
				for( int j = i; j < ( _MAX_FRIENDLIST_COUNT_-1); j++ )
				{
					FriendList[j] = FriendList[( j+1 )];					
				}
				FriendList[ ( _MAX_FRIENDLIST_COUNT_ - 1 ) ].Clear();				
				
				return true;
			}
		}

		return false;
	}

	bool AddBadFriend( char* Name )
	{
		int	i;
		//看名稱是否有重覆
		for( i = 0 ; i < _MAX_FRIENDLIST_COUNT_ ; i++ )
		{
			if( strcmp( BadFriendList[i].Begin() , Name ) == 0 )
				return false;
		}

		for( i = 0 ; i < _MAX_FRIENDLIST_COUNT_ ; i++ )
		{
			if( BadFriendList[i].Size() == 0 )
			{
				BadFriendList[i] = Name;
				return true;
			}		
		}
		return false;
	}

	bool DelBadFriend( char* Name )
	{
		int	i;
		//看名稱是否有重覆
		for( i = 0 ; i < _MAX_FRIENDLIST_COUNT_ ; i++ )
		{
			if( strcmp( BadFriendList[i].Begin() , Name ) == 0 )
			{
				BadFriendList[i].Clear();
				return true;
			}
		}

		return false;
	}
};


//-------------------------------------------------------------------------------------
//好友名單 (資料庫存取用)
struct DB_BaseFriendStruct
{
	int DBID;
	int FieldID;
	BaseFriendStruct Info;
};
//-------------------------------------------------------------------------------------
//所有線上玩家基本資料(送網路封包使用)
struct OnlinePlayerInfoStruct
{
	StaticString< _MAX_NAMERECORD_SIZE_ >   Account;    //帳號
	StaticString< _MAX_NAMERECORD_SIZE_ >   Name;	    //角色名稱	
	int				DBID;
	int				SockID;		//封包收送Id
	int     		ProxyID;    //處理的Proxy

//	int				GuildID;	//公會 ID
	union
	{
		struct
		{
			short   ItemID;            
			short   ZoneID;
		};
		int				GUID;							// 區域物件ID
	};

	Voc_ENUM		Voc;
	Voc_ENUM		Voc_Sub;
	Sex_ENUM		Sex;
	LookStruct		Look;
	int				LV;
	int				LV_Sub;

};
//-------------------------------------------------------------------------------------
//公會資料結構
struct GuildStruct
{
	GuildBaseStruct					Base;
	vector<GuildMemberStruct*>		Member;

	vector<GuildBoardStruct*>		BoardAll;		//所有的留言
	vector<GuildBoardStruct*>		BoardList;		//最新的60筆資料



	GuildStruct()
	{
		Base.Init();
	};
	void ClearMemory()
	{
		for( int i = 0 ; i < (int)Member.size() ; i++ )
		{
			delete Member[i];
		}
		Member.clear();

		for( unsigned i = 0 ; i < BoardAll.size() ; i++ )
		{
			delete BoardAll[i];
		}
		BoardAll.clear();
		BoardList.clear();

	};

	//處理置頂
	bool	MessageSetTop( int MessageID , bool Flag )
	{

		if( Flag == true )
		{	//設為Top
			int TopCount = 0;
			for( unsigned i = 0 ; i < BoardList.size() ; i++ )
			{
				GuildBoardStruct* Msg = BoardList[i];
				if( Msg->Type.Top == true )
					TopCount++;

				if( MessageID != Msg->GUID )
					continue;

				if( Msg->Type.Top == true )
					return true;

				Msg->Type.Top = true;
				BoardList.erase( BoardList.begin() + i );
				BoardList.insert( BoardList.begin() + TopCount , Msg );
				return true;
			}

		}
		else
		{
			int TopCount = 0;
			GuildBoardStruct* Msg = NULL;
			int	MsgPos = -1;
			for( unsigned i = 0 ; i < BoardList.size() ; i++ )
			{
				GuildBoardStruct* TempMsg = BoardList[i];

				if( TempMsg->Type.Top == false )
					break;

				TopCount++;
				
				if( MessageID != TempMsg->GUID )
					continue;

				Msg = TempMsg;
				MsgPos = i;
			}

			if( Msg != NULL )
			{
				Msg->Type.Top = false;
				BoardList.erase( BoardList.begin() + MsgPos );
				BoardList.insert( BoardList.begin() + TopCount , Msg );
				return true;
			}
		}
		return true;
	}

	
};
//-------------------------------------------------------------------------------------
struct MailBaseInfoStruct
{
	ItemFieldStruct		Item;	//資料簡查
	int		Money;

	bool	IsSendMoney;		//true 寄送金錢 false 獲到付款
	bool	IsSystem;			//是否為系統信件
	bool	IsRead;
	bool	IsSendBack;			//是否為退回信件

	StaticString <_MAX_NAMERECORD_SIZE_>	OrgSendName;
	StaticString <_MAX_NAMERECORD_SIZE_>	OrgTargetName;

	StaticString <_MAX_NAMERECORD_SIZE_>	Title;
	int		LiveTime;				//生存時間( 單位(分鐘) )
};
//-------------------------------------------------------------------------------------
//Mail 資料結構
struct DB_MailStruct
{
	int		GUID;
	int		ItemGUID;
	int		OwnerDBID;
	int		OrgSendDBID;			//原始送件者
	
	MailBaseInfoStruct	MailBase;
	StaticString <2048>	Content;
	


	void Init()
	{
		GUID = -1;
		ItemGUID = -1;
		OwnerDBID = -1;
		OrgSendDBID = -1;			
		Content.Clear();
	};

	DB_MailStruct()
	{
		Init();
	};
};
//--------------------------------------------------------------------------------------------
enum	ACItemStateENUM
{
	EM_ACItemState_Normal	,
	EM_ACItemState_BuyOut	,
	EM_ACItemState_Cancel	,
};
struct DB_ACItemStruct
{
	int		GUID;					//在AC的資料庫ID
	StaticString <_MAX_NAMERECORD_SIZE_>	SellerName;		//賣方名字
	StaticString <_MAX_NAMERECORD_SIZE_>	BuyerName;		//買方名字

	int		NowPrices;
	int		BuyOutPrices;
	int		BuyerDBID;
	int		SellerDBID;
	int		LiveTime;				//可生存時間
	int		ItemLevel;				//物品等級

	ItemFieldStruct		Item;		//賣的東西
	StaticString <_MAX_NAMERECORD_SIZE_>	ItemName;		//物品名稱
	int		ItemType[3];			//物品分類
	int		Rare;

	SexFlagStruct				SexType;			//性別				
	RaceFlagStruct				RaceType;			//種族			
	VocationFlagStruct			JobType;			//職業
	EqWearSkillStruct			EQType;				//裝備類形
	
	ACItemStateENUM	State;
};
//--------------------------------------------------------------------------------------------
struct  DB_ACItemHistoryStruct
{
	int		GUID;
	StaticString <_MAX_NAMERECORD_SIZE_>	SellerName;		//賣方名字
	StaticString <_MAX_NAMERECORD_SIZE_>	BuyerName;		//買方名字

	int		Date;	//賣出時間
	int		Prices;
	int		BuyerDBID;
	int		SellerDBID;

	ItemFieldStruct		Item;	//賣的東西
};
//-------------------------------------------------------------------------------------
#pragma managed
#endif
