00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #ifndef __ALLEGIANCES_H
00024 #define __ALLEGIANCES_H
00025
00026 #pragma warning(disable:4786) //warning: identifier was truncated to '255' characters in the browser information
00027 #include <map>
00028
00029
00030 #include "Avatar.h"
00031 #include "Shared.h"
00032
00033 struct Member
00034 {
00035
00036 DWORD m_dwGUID;
00037 std::string m_szName;
00038 bool m_online;
00039 BYTE m_bGender;
00040 BYTE m_bRace;
00041 BYTE m_bRank;
00042 WORD m_wLeadership;
00043 WORD m_wLoyalty;
00044 DWORD m_dwPatron;
00045 DWORD m_dwVassals[MAX_VASSALS];
00046 DWORD m_dwFollowers;
00047 float m_avgIGSworn;
00048 float m_avgRTSworn;
00049 DWORD m_passupXP;
00050 DWORD m_pendingXP;
00051
00052
00053 DWORD m_dwLevel;
00054 ULONG m_timeBirth;
00055 ULONG m_timeRLSwear;
00056 ULONG m_timeIGTotal;
00057 ULONG m_timeIGSwear;
00058 };
00059
00060 class cAllegiance
00061 {
00062 friend class cMasterServer;
00063
00064 public:
00065 cAllegiance();
00066 ~cAllegiance();
00067
00068 void LoadAllegiance (DWORD ID, DWORD leaderGUID, char name[40], char MOTD[255]);
00069 void CreateAllegiance ( DWORD leaderGUID );
00070 void Disband ( );
00071
00072 typedef std::map<DWORD, Member> MemberList;
00073
00074 Member* FindMember ( DWORD memberGUID ) { return &this->members.find(memberGUID)->second; }
00075
00076 static cAllegiance* GetAllegianceByID ( DWORD AllegianceID );
00077 DWORD GetID() { return m_ID; }
00078 DWORD GetLeader() { return m_LeaderGUID; }
00079 DWORD GetSize() { return m_Size; }
00080 std::string GetName() { return m_Name.c_str(); }
00081 std::string GetMOTD() { return m_MOTD.c_str(); }
00082
00083 static void SetLeader ( DWORD allegianceID, DWORD leaderGUID );
00084 static bool AddNewMember ( DWORD dwAvatarGUID, DWORD dwPatronGUID, DWORD oldAllegianceID, DWORD newAllegianceID );
00085 static bool AddRemMember ( Member* member, DWORD oldAllegianceID, DWORD newAllegianceID );
00086 static bool RemMember ( DWORD dwRemMemberGUID, DWORD oldAllegianceID, bool isDisbanding=false );
00087 static bool SwitchMonarchAndVassals ( Member* member, DWORD oldAllegianceID, DWORD newAllegianceID );
00088 static bool SwitchNonMonarchVassals ( Member* member, DWORD oldAllegianceID, DWORD newAllegianceID );
00089
00090 void InsertMember ( Member member, DWORD dwPatronGUID );
00091 void EraseMember ( Member* member );
00092 void EraseMember ( DWORD dwMemberGUID );
00093
00094 bool AddDirectVassal ( Member* memPatron, Member* memVassal );
00095 bool AddDirectVassal ( DWORD dwPatronGUID, DWORD dwVassalGUID );
00096 bool RemDirectVassal ( Member* memVassal );
00097 bool RemDirectVassal ( DWORD dwVassalGUID );
00098
00099 void SetMOTD ( std::string motd );
00100
00101 std::string GetMemberName ( Member* member ) { return member->m_szName.c_str(); }
00102 std::string GetMemberName ( DWORD dwMemberGUID ) { Member* member = FindMember(dwMemberGUID); return member->m_szName.c_str(); }
00103
00104 int GetVassalCount ( Member* member );
00105 int GetVassalCount ( DWORD dwMemberGUID );
00106 int GetFollowerCount ( Member* member );
00107 int GetFollowerCount ( DWORD dwMemberGUID );
00108
00109 static void UpdatePlayerAllegID ( Member* member, DWORD newAllegianceID );
00110 static void UpdatePlayerAllegID ( DWORD dwPlayerGUID, DWORD newAllegianceID );
00111 void UpdateFollowers ( Member* member, int numFollowers );
00112 void UpdateFollowers ( DWORD dwMemberGUID, int numFollowers );
00113 void UpdateRank ( Member* member );
00114 void UpdateRank ( DWORD dwMemberGUID );
00115
00116 void VassalPassupXP ( Member* memVassal, UINT64 experience, bool isGrandVassal=false );
00117 void UpdateGeneratedXP ( Member* member, UINT64 experience );
00118 void UpdateEarnedXP ( Member* member, UINT64 experience );
00119 UINT64 CalcVassalGeneratedXP ( Member* memVassal, UINT64 experience, bool isGrandPatron=false );
00120 UINT64 CalcPatronReceivedXP ( Member* memPatron, UINT64 experience, bool isGrandPatron=false );
00121 void UpdateAverageSwornTimeOfVassals ( Member* memPatron );
00122 float CalcVassalFactor ( int numVassals );
00123
00124 cMessage GetAllegianceInfo ( DWORD avatarGUID );
00125
00126 static void LoadMembersFromDB ( cAllegiance* aAllegiance );
00127
00128 static void UpdateAvatarAllegIDDB ( DWORD dwGUID, DWORD allegianceID );
00129 static void UpdateMemberAllegIDDB ( DWORD dwGUID, DWORD allegianceID );
00130 static void UpdateAvatarRecordDB ( DWORD dwAvatarGUID );
00131 static void AddMemberRecordDB ( DWORD allegianceID, DWORD dwAvatarGUID, DWORD dwPatronGUID );
00132 static void DeleteMemberRecordDB ( DWORD allegianceID, DWORD dwMemberGUID );
00133 static void UpdateMemberRecordDB ( Member* member );
00134 static void UpdateMemberXPPassupDB ( DWORD memberGUID, UINT64 passedXP );
00135 static void UpdateMemberXPPendingDB ( DWORD memberGUID, UINT64 pendingXP );
00136 static void UpdateMemberFollowersDB ( DWORD memberGUID, int numFollowers );
00137 static void UpdateMemberRankDB ( DWORD memberGUID, int rank );
00138 static void UpdateMemberPatronDB ( DWORD memberGUID, DWORD patronGUID );
00139
00140 MemberList members;
00141
00142 protected:
00143 DWORD m_ID;
00144 std::string m_Name;
00145 DWORD m_LeaderGUID;
00146 std::string m_MOTD;
00147 int m_Size;
00148 ULONG m_CreationTime;
00149 };
00150
00151 #endif // #ifndef __ALLEGIANCES_H