#pragma once

#include <string>
#include <vector>
#include <map>
#include "NetCli_Party.h"

using namespace std;

enum PartyStateInfo
{
	ePartyState_Solo		= 0,			// 沒有隊伍
	ePartyState_Receive,					// 受到邀請
	ePartyState_Leader,						// 隊伍領隊
	ePartyState_Member,						// 隊伍成員
};

struct PartyMemberInfo
{
	int			memberId;
	union
	{
		int		GItemID;					// -1 代表下線狀態
		struct
		{
			short   ItemID;
			short   ZoneID;
		};
	};
	int			DBID;
	int			hp;
	int			maxHp;
	int			mp;
	int			maxMp;
	int			sp;
	int			maxSp;
	float		x, y, z;
	string		name;
};

struct PartyAssignItem
{	
	int				itemVersion;			// 物品鍵值(KEY WORD),用以判別處理項目
	ItemFieldStruct	item;					// 物品資料
	vector<int>		loot;					// 有權獲得物品玩家
};

enum LootItemStatus
{
	eLootItem_Wait					= 0,
	eLootItem_Roll,
	eLootItem_Done,
};

struct PartyRollItem
{
	int				itemVersion;			// 物品鍵值(KEY WORD),用以判別處理項目
	ItemFieldStruct	item;					// 物品資料
	LootItemStatus	status;					// 處理狀況(0未處理, 1等待投擲中, 2等待刪除)
};

class NetCli_PartyChild : public NetCli_Party
{
public:
	static	PartyBaseInfoStruct				s_info;
	static	vector<PartyMemberInfo>			s_member;
	static	vector<PartyAssignItem>			s_assignItem;
	static	vector<PartyRollItem>			s_rollItem;
	static	PartyStateInfo					s_state;
	static	string							s_leaderName;
	static	int								s_leaderIndex;
	static	map<int, PartyMemberInfo>		s_tempMember;

	static	bool _Init();
	static	bool _Release();
	static	PartyBaseInfoStruct&			GetPartyInfo()					{ return s_info; }
	static	PartyMemberInfo*				GetPartyMember(int index);
	static	const char*						GetPartyLeaderName()			{ return s_leaderName.c_str(); }
	static	int								GetPartyLeaderIndex()			{ return s_leaderIndex; }
	static	PartyStateInfo					GetPartyState()					{ return s_state; }
	static	void							UpdateLeaderInfo();
	static	void							SetPartyMemberHPMPSP(int DBID, int hp, int mp, int sp);
	static	void							SetPartyMemberMaxHPMPSP(int DBID, int maxHp, int maxMp, int maxSp);
	static	void							SetPartyMemberPosition(int DBID, int zoneId, float x, float y, float z);
	static	void							ClearPartyInfo();
	static	int								InviteToParty(const char* name);
	static	int								InviteAnswerState(bool isAccept);
	static	int								PromoteToLeader(const char* name);
	static	int								SetLootMethod(PartyItemShareENUM mode, const char* name=NULL);
	static	int								SetLootThreshold(int quality);
	static	int								KickMember(const char* name);
	static	const char*						FindMemberName(int DBID);
	static	bool							InParty(const char* name);

	// Item
	static	void							AddRollItem(PartyRollItem& rollItem);
	static	void							DeleteRollItem(int DBID, int itemVersion);
	static	void							ClearRollItem();
	static	PartyRollItem*					GetRollItem(int itemVersion);
	static	void							AddAssignItem(PartyAssignItem& assignItem);
	static	void							DeleteAssignItem(int itemVersion);
	static	void							ClearAssignItem();
	static	PartyAssignItem*				GetAssignItem(int itemVersion);	
	static	const char*						GetAssignItemMember(int itemVersion, int index);
	static	int								AssignTo(int itemVersion, int index);
	static	bool							IsAssigner();

	virtual void R_Invite		( char* LeaderName );
	virtual void R_PartyBaseInfo( PartyBaseInfoStruct& Info );
	virtual void R_AddMember	( PartyMemberInfoStruct& Member );
	virtual void R_DelMember	( PartyMemberInfoStruct& Member );
	virtual void R_FixMember	( PartyMemberInfoStruct& Member );

	virtual void R_PartyTreasure( int ItemVersion , PartyItemShareENUM LootType , ItemFieldStruct& Item ,	StaticVector< int , _MAX_PARTY_COUNT_  >&  LootDBID );
	virtual void R_PartyTreasureLoot( int ItemVersion ,	int DBID , int LootValue );
	virtual void R_GiveItemInfo( int DBID , ItemFieldStruct& Item , int ItemVersion );
};

