Clone of UAS2 @ https://github.com/drudgedance/uas2

Allegiance.cpp 54KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  1. /*
  2. * This file is part of UAS2.
  3. *
  4. * UAS2 is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * UAS2 is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with UASv1; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /* Special thanks to Zerot for the "old" experience calculator (http://rain.prohosting.com/obp/calc.html) */
  18. /* Special thanks to Xerxes of Thistledown for the "new" experience passing formulas */
  19. /**
  20. * @file Allegiance.cpp
  21. * Implements general functionality for allegiances (hierarchical character alliances/monarchies/guilds).
  22. *
  23. * TODO: Separate static and non-static (instance-based) functions.
  24. * (Static functions should probably be in an allegiance manager file.)
  25. */
  26. #include "Allegiance.h"
  27. #include "Client.h"
  28. #include "Database.h"
  29. #include "MasterServer.h"
  30. #include "WorldManager.h"
  31. cAllegiance::cAllegiance()
  32. {
  33. m_ID = 0;
  34. m_Name = "";
  35. m_LeaderGUID = 0;
  36. m_MOTD = "";
  37. m_Size = 0;
  38. m_CreationTime = 0;
  39. }
  40. cAllegiance::~cAllegiance()
  41. {
  42. }
  43. void cAllegiance::LoadAllegiance(DWORD ID, DWORD leaderGUID, char name[40], char MOTD[255])
  44. {
  45. m_ID = ID;
  46. m_LeaderGUID = leaderGUID;
  47. m_Name = name;
  48. m_MOTD = MOTD;
  49. m_Size = 0;
  50. m_CreationTime = 0;
  51. cMasterServer::m_AllegianceList.push_back( this );
  52. }
  53. void cAllegiance::CreateAllegiance(DWORD leaderGUID)
  54. {
  55. // m_ID = cWorldManager::NewID_Allegiance();
  56. m_ID = leaderGUID;
  57. m_Name = "";
  58. m_LeaderGUID = leaderGUID;
  59. m_MOTD = "";
  60. m_Size = 0;
  61. m_CreationTime = time (NULL);
  62. char szCommand[1024];
  63. RETCODE retcode;
  64. sprintf( szCommand, "INSERT INTO `allegiance` ( `AllegianceID`, `Name`, `LeaderGUID`, `MOTD`, `CreationTime` ) VALUES (%lu, '%s', %lu, '%s', %lu);",m_ID, "", m_LeaderGUID, "", time (NULL));
  65. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  66. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  67. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  68. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  69. cMasterServer::m_AllegianceList.push_back( this );
  70. }
  71. cAllegiance* cAllegiance::GetAllegianceByID(DWORD AllegianceID)
  72. {
  73. for ( std::vector<cAllegiance *>::iterator itr = cMasterServer::m_AllegianceList.begin() ; itr != cMasterServer::m_AllegianceList.end() ; ++itr )
  74. {
  75. if ((*itr)->GetID() == AllegianceID)
  76. {
  77. return *itr;
  78. }
  79. }
  80. return NULL;
  81. }
  82. /**
  83. * Loads the allegiance's members into memory.
  84. *
  85. * This function is called when the server is started.
  86. * Loading this information at server boot reduces the impact of experience passing.
  87. *
  88. * Allegiance members are loaded into a map with their GUID as key.
  89. * Each member is a struct containing pertinent allegiance information.
  90. */
  91. void cAllegiance::LoadMembersFromDB(cAllegiance* aAllegiance)
  92. {
  93. char szCommand[200];
  94. RETCODE retcode;
  95. DWORD dwGUID;
  96. char szName[75];
  97. BYTE bGender;
  98. BYTE bRace;
  99. BYTE bRank;
  100. WORD wLoyalty;
  101. WORD wLeadership;
  102. UINT64 dwPassupXP;
  103. UINT64 dwPendingXP;
  104. DWORD dwPatron;
  105. DWORD dwFollowers;
  106. UINT64 dtSwornRL;
  107. UINT64 dtSwornIG;
  108. // DWORD dwVassals;
  109. DWORD dwLevel;
  110. INT64 dtBirth;
  111. sprintf( szCommand, "SELECT * FROM `allegiance_members` WHERE `AllegianceID` = '%lu'", aAllegiance->m_ID);
  112. int iCol = 3;
  113. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  114. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  115. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwGUID, sizeof( DWORD ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  116. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szName, sizeof( szName ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  117. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bGender, sizeof( BYTE ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  118. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bRace, sizeof( BYTE ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  119. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bRank, sizeof( BYTE ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  120. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wLoyalty, sizeof( BYTE ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  121. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wLeadership, sizeof( BYTE ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  122. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwPassupXP, sizeof( UINT64 ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  123. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwPendingXP, sizeof( UINT64 ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  124. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwPatron, sizeof( UINT64 ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  125. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwFollowers, sizeof( UINT64 ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  126. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dtSwornRL, sizeof( UINT64 ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  127. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dtSwornIG, sizeof( UINT64 ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  128. // retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwVassals, sizeof( DWORD ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  129. // load members into the allegiance's "member map"
  130. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  131. {
  132. Member newMember;
  133. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas) //ensure that the vassal record is cleared
  134. newMember.m_dwVassals[iVas] = 0;
  135. newMember.m_dwGUID = dwGUID;
  136. newMember.m_szName.assign(szName);
  137. newMember.m_online = false;
  138. newMember.m_bGender = bGender;
  139. newMember.m_bRace = bRace;
  140. newMember.m_bRank = bRank;
  141. newMember.m_wLoyalty = wLoyalty;
  142. newMember.m_wLeadership = wLeadership;
  143. newMember.m_dwPatron = dwPatron;
  144. newMember.m_dwFollowers = dwFollowers;
  145. newMember.m_passupXP = dwPassupXP;
  146. newMember.m_pendingXP = dwPendingXP;
  147. newMember.m_timeRLSwear = dtSwornRL;
  148. newMember.m_timeIGSwear = dtSwornIG;
  149. //aAllegiance->members.push_back(newMember);
  150. aAllegiance->members.insert(MemberList::value_type(newMember.m_dwGUID, newMember));
  151. aAllegiance->m_Size++;
  152. }
  153. // load members' levels and time of births into the allegiance's "member map"
  154. std::map<DWORD, Member>::iterator itMembers;
  155. for ( itMembers = aAllegiance->members.begin() ; itMembers != aAllegiance->members.end() ; ++itMembers )
  156. {
  157. sprintf( szCommand, "SELECT `Level`,`Birth` FROM `avatar` WHERE `AvatarGUID` = '%lu'", itMembers->second.m_dwGUID);
  158. int iCol = 1;
  159. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  160. retcode = SQLExecute( cDatabase::m_hStmt );
  161. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwLevel, sizeof( DWORD ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  162. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dtBirth, sizeof( UINT64 ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  163. retcode = SQLFetch( cDatabase::m_hStmt );
  164. itMembers->second.m_dwLevel = dwLevel;
  165. itMembers->second.m_timeBirth = dtBirth;
  166. itMembers->second.m_timeIGTotal = 0; //TODO
  167. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  168. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  169. // determine patron/vassal relationships
  170. if (itMembers->second.m_dwGUID != aAllegiance->m_LeaderGUID) // if the member is not the monarch
  171. {
  172. // add the member to his/her patron's vassal list.
  173. Member* memPatron = &aAllegiance->members.find(itMembers->second.m_dwPatron)->second;
  174. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  175. {
  176. if (memPatron->m_dwVassals[iVas] == 0)
  177. {
  178. memPatron->m_dwVassals[iVas] = itMembers->first;
  179. break;
  180. }
  181. }
  182. }
  183. }
  184. }
  185. /**
  186. * Inserts a member into the allegiance.
  187. *
  188. * The function is used when a player should be inserted into an allegiance.
  189. *
  190. * @param member - The member record object for the member that should be inserted.
  191. * @param dwPatronGUID - The GUID of the new member's patron.
  192. */
  193. void cAllegiance::InsertMember(Member member, DWORD dwPatronGUID)
  194. {
  195. members.insert(MemberList::value_type(member.m_dwGUID, member));// insert the member into the allegiance
  196. m_Size += member.m_dwFollowers + 1; // update the allegiance size
  197. AddDirectVassal(dwPatronGUID, member.m_dwGUID); // add the vassal to the patron's vassal list
  198. }
  199. /**
  200. * Erases a member from the allegiance.
  201. *
  202. * The function is used when a player should be deleted from an allegiance.
  203. *
  204. * @param member - A pointer to the member record that should be deleted.
  205. */
  206. void cAllegiance::EraseMember(Member* member)
  207. {
  208. RemDirectVassal(member->m_dwGUID); // remove the vassal from the patron's vassal list
  209. m_Size -= member->m_dwFollowers + 1;// update the allegiance size
  210. members.erase(member->m_dwGUID); // erase the member from the allegiance
  211. }
  212. /**
  213. * Erases a member from the allegiance.
  214. *
  215. * The function is used when a player should be deleted from an allegiance.
  216. *
  217. * @param dwMemberGUID - The GUID of the player whose member record should be deleted.
  218. */
  219. void cAllegiance::EraseMember(DWORD dwMemberGUID)
  220. {
  221. Member* member = FindMember(dwMemberGUID);
  222. RemDirectVassal(dwMemberGUID); // remove the vassal from the patron's vassal list
  223. m_Size -= member->m_dwFollowers + 1;// update the allegiance size
  224. members.erase(dwMemberGUID); // erase the member from the allegiance
  225. }
  226. /**
  227. * Adds a player (and any vassals under him/her) to an allegiance.
  228. *
  229. * The function is used when a player pledges allegiance to a member of an allegiance.
  230. * Each follower of that member should also be added to the allegiance.
  231. * The "old" allegiance to which these members belonged should be deleted if the pledged member was the monarch.
  232. *
  233. * @param dwAvatarGUID - The GUID of the player to add.
  234. * @param dwPatronGUID - The GUID of the new patron of the player to add.
  235. * @param oldAllegianceID - The ID of player's former allegiance, if any.
  236. * @param newAllegianceID - The ID of player's new allegiance.
  237. */
  238. bool cAllegiance::AddNewMember(DWORD dwAvatarGUID, DWORD dwPatronGUID, DWORD oldAllegianceID, DWORD newAllegianceID)
  239. {
  240. cAllegiance* oldAllegiance = GetAllegianceByID(oldAllegianceID);
  241. cAllegiance* newAllegiance = GetAllegianceByID(newAllegianceID);
  242. if (oldAllegiance && newAllegiance)
  243. { // already a member of an allegiance
  244. // if the player is already a member of an allegiance, he/she was the monarch
  245. // merge the player and his/her followers into the new allegiance
  246. Member* oldMember = oldAllegiance->FindMember(dwAvatarGUID);
  247. SwitchMonarchAndVassals(oldMember, oldAllegiance->GetID(), newAllegiance->GetID());
  248. Member* newMember = newAllegiance->FindMember(dwAvatarGUID);
  249. // add the vassal to the patron's vassal list (also adjusts the patron's follower count and rank)
  250. newAllegiance->AddDirectVassal(dwPatronGUID, dwAvatarGUID);
  251. newMember->m_dwPatron = dwPatronGUID;
  252. UpdateMemberPatronDB(dwAvatarGUID, dwPatronGUID);
  253. return true;
  254. }
  255. else
  256. { // not already a member of an allegiance
  257. cAvatar* pcAvatar;
  258. if (newAllegiance) // the patron has an allegiance
  259. pcAvatar = cClient::FindAvatar(dwAvatarGUID);
  260. else // the patron does not have an allegiance
  261. pcAvatar = cClient::FindAvatar(dwPatronGUID);
  262. //pcAvatar = cClient::FindAvatar(dwAvatarGUID);
  263. if (pcAvatar)
  264. {
  265. Member newMember;
  266. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas) // ensure that the vassal record is cleared
  267. newMember.m_dwVassals[iVas] = 0;
  268. newMember.m_dwGUID = pcAvatar->GetGUID();
  269. newMember.m_szName.assign(pcAvatar->Name());
  270. newMember.m_online = true;
  271. if (pcAvatar->GetGender() == 0)
  272. newMember.m_bGender = 2;
  273. else
  274. newMember.m_bGender = 1;
  275. newMember.m_bRace = pcAvatar->GetRace() + 1;
  276. newMember.m_bRank = 1;
  277. newMember.m_wLoyalty = pcAvatar->GetTotalLoyalty();
  278. newMember.m_wLeadership = pcAvatar->GetTotalLeadership();
  279. newMember.m_dwPatron = dwPatronGUID;
  280. newMember.m_dwFollowers = 0;
  281. newMember.m_passupXP = 0;
  282. newMember.m_pendingXP = 0;
  283. newMember.m_timeRLSwear = time(NULL);
  284. newMember.m_timeIGSwear = 0;
  285. if (!newAllegiance)
  286. { // the patron does not have an allegiance; create one
  287. // create an allegiance
  288. cAllegiance* newAllegiance = new cAllegiance();
  289. newAllegiance->CreateAllegiance(dwPatronGUID);
  290. // add the patron
  291. newAllegiance->InsertMember(newMember, 0);
  292. // add the new member record
  293. AddMemberRecordDB(newAllegiance->GetID(), dwPatronGUID, 0);
  294. // add the vassal by recursing to this function
  295. AddNewMember(dwAvatarGUID, dwPatronGUID, oldAllegianceID, newAllegiance->GetID());
  296. // update the patron's allegiance ID in memory
  297. pcAvatar->m_dwAllegianceID = newAllegiance->GetID();
  298. // update the patron's allegiance ID in the database
  299. UpdateAvatarAllegIDDB(pcAvatar->GetGUID(), newAllegiance->GetID());
  300. }
  301. else
  302. { // the patron has an allegiance; add the sworn member to it
  303. newAllegiance->InsertMember(newMember, dwPatronGUID);
  304. // add the new member record
  305. AddMemberRecordDB(newAllegiance->GetID(), pcAvatar->GetGUID(), dwPatronGUID);
  306. // update the avatar's allegiance ID in memory
  307. pcAvatar->m_dwAllegianceID = newAllegiance->GetID();
  308. // update the avatar's allegiance ID in the database
  309. UpdateAvatarAllegIDDB(pcAvatar->GetGUID(), newAllegiance->GetID());
  310. }
  311. return true;
  312. }
  313. }
  314. return false;
  315. }
  316. /**
  317. * Adds a removed player (and all of his/her followers) to a new allegiance.
  318. *
  319. * The player and the vassals under the player switching are switched.
  320. *
  321. * @param member - The member whose allegiance should be switched.
  322. * @param oldAllegianceID - The ID of the member's former allegiance.
  323. * @param newAllegianceID - The ID of the member's new allegiance.
  324. */
  325. bool cAllegiance::AddRemMember(Member* member, DWORD oldAllegianceID, DWORD newAllegianceID)
  326. {
  327. cAllegiance* oldAllegiance = GetAllegianceByID(oldAllegianceID);
  328. cAllegiance* newAllegiance = GetAllegianceByID(newAllegianceID);
  329. // Member* member = this->Find(memberGUID);
  330. if (oldAllegiance && newAllegiance)
  331. {
  332. member->m_dwPatron = 0;
  333. newAllegiance->InsertMember((*member), 0);
  334. UpdatePlayerAllegID(member->m_dwGUID, newAllegianceID);
  335. SwitchNonMonarchVassals(member, oldAllegianceID, newAllegianceID);
  336. UpdateMemberPatronDB(member->m_dwGUID, 0);
  337. return true;
  338. }
  339. return false;
  340. }
  341. /**
  342. * Removes a player (and any vassals under him/her) from an allegiance.
  343. *
  344. * The function is used when a player breaks or is kicked/booted/banned from the allegiance.
  345. * Each follower of that member should also be removed from the allegiance.
  346. *
  347. * @param dwRemMemberGUID - The GUID of the player to remove.
  348. * @param isDisbanding - A boolean value representing whether to disband the allegiance.
  349. */
  350. bool cAllegiance::RemMember(DWORD dwRemMemberGUID, DWORD oldAllegianceID, bool isDisbanding)
  351. {
  352. cAllegiance* oldAllegiance = GetAllegianceByID(oldAllegianceID);
  353. Member* member = oldAllegiance->FindMember(dwRemMemberGUID);
  354. if (member)
  355. {
  356. Member* memPatron = oldAllegiance->FindMember(member->m_dwPatron);
  357. if (oldAllegiance->GetVassalCount(member) > 0)
  358. { // has followers; therefore, monarch of a new allegiance
  359. oldAllegiance->RemDirectVassal(member->m_dwGUID); // remove the vassal from the patron's vassal list
  360. cAllegiance* newAllegiance = new cAllegiance();
  361. newAllegiance->CreateAllegiance(dwRemMemberGUID);
  362. newAllegiance->AddRemMember(member, oldAllegianceID, newAllegiance->GetID());
  363. oldAllegiance->m_Size -= member->m_dwFollowers + 1; // update the allegiance size
  364. oldAllegiance->members.erase(member->m_dwGUID); // erase the member from the allegiance
  365. }
  366. else
  367. { // no longer in an allegiance
  368. UpdatePlayerAllegID(dwRemMemberGUID, 0);
  369. oldAllegiance->EraseMember(member);
  370. }
  371. if (isDisbanding)
  372. {
  373. oldAllegiance->Disband();
  374. }
  375. else
  376. {
  377. if (memPatron)
  378. {
  379. if (memPatron->m_dwGUID == oldAllegiance->GetLeader())
  380. { // the patron was the monarch
  381. if (oldAllegiance->GetVassalCount(memPatron) == 0)
  382. { // the patron's/monarch's only vassal was removed
  383. RemMember(memPatron->m_dwGUID, oldAllegianceID, true);
  384. }
  385. }
  386. }
  387. }
  388. return true;
  389. }
  390. return false;
  391. }
  392. /**
  393. * Switches a player's (and all of his/her followers') allegiance.
  394. *
  395. * It is prefered over the non-monarch implementation, as it iterates rather than searches through the member map.
  396. *
  397. * @param member - The monach whose allegiance should be switched.
  398. * @param oldAllegianceID - The ID of the monarch's former allegiance.
  399. * @param newAllegianceID - The ID of the allegiance to which the monarch and his/her followers should be switched.
  400. */
  401. bool cAllegiance::SwitchMonarchAndVassals(Member* member, DWORD oldAllegianceID, DWORD newAllegianceID)
  402. {
  403. cAllegiance* oldAllegiance = GetAllegianceByID(oldAllegianceID);
  404. cAllegiance* newAllegiance = GetAllegianceByID(newAllegianceID);
  405. // Member* member = this->Find(memberGUID);
  406. if (oldAllegiance && newAllegiance)
  407. {
  408. int switchedMembers = 0;
  409. //this->members.insert(curAllegiance->members.begin(),curAllegiance->members.end());
  410. std::map<DWORD, Member>::iterator itrMember;
  411. for ( itrMember = oldAllegiance->members.begin() ; itrMember != oldAllegiance->members.end() ; )
  412. {
  413. newAllegiance->members.insert(MemberList::value_type(itrMember->first, itrMember->second));
  414. UpdatePlayerAllegID(itrMember->first, newAllegianceID);
  415. switchedMembers++;
  416. oldAllegiance->members.erase(itrMember++);
  417. }
  418. newAllegiance->m_Size += switchedMembers; //update the new allegiance's member count
  419. oldAllegiance->Disband(); // delete the former allegiance object
  420. return true;
  421. }
  422. return false;
  423. }
  424. /**
  425. * Switches a player's followers' allegiance.
  426. *
  427. * Only the vassals under the player switching are switched.
  428. *
  429. * @param member - The member whose allegiance should be switched.
  430. * @param oldAllegianceID - The ID of the member's former allegiance.
  431. * @param newAllegianceID - The ID of the member's new allegiance.
  432. */
  433. bool cAllegiance::SwitchNonMonarchVassals(Member* member, DWORD oldAllegianceID, DWORD newAllegianceID)
  434. {
  435. cAllegiance* oldAllegiance = GetAllegianceByID(oldAllegianceID);
  436. cAllegiance* newAllegiance = GetAllegianceByID(newAllegianceID);
  437. // Member* member = this->Find(memberGUID);
  438. if (oldAllegiance && newAllegiance)
  439. {
  440. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  441. {
  442. if (member->m_dwVassals[iVas] != 0)
  443. {
  444. Member* memVassal = oldAllegiance->FindMember(member->m_dwVassals[iVas]);
  445. newAllegiance->members.insert(MemberList::value_type(memVassal->m_dwGUID, (*memVassal)));
  446. UpdatePlayerAllegID(memVassal, newAllegianceID);
  447. SwitchNonMonarchVassals(memVassal, oldAllegianceID, newAllegianceID);// recurse to this function
  448. oldAllegiance->members.erase(oldAllegiance->members.find(memVassal->m_dwGUID)); // erase the member from the old allegiance
  449. }
  450. }
  451. return true;
  452. }
  453. return false;
  454. }
  455. /**
  456. * Adds a vassal to the patron's vassal list.
  457. *
  458. * The patron's follower count and rank are both recaluated.
  459. *
  460. * @param memPatron - A pointer to the member record of the patron.
  461. * @param memVassal - A pointer to the member record of the vassal to add to his/her patron's vassal list.
  462. */
  463. bool cAllegiance::AddDirectVassal(Member* memPatron, Member* memVassal)
  464. {
  465. if (memPatron)
  466. {
  467. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  468. {
  469. if (memPatron->m_dwVassals[iVas] == 0)
  470. {
  471. memPatron->m_dwVassals[iVas] = memVassal->m_dwGUID;
  472. UpdateFollowers(memPatron, memVassal->m_dwFollowers + 1);
  473. UpdateRank(memPatron);
  474. return true;
  475. }
  476. }
  477. }
  478. return false;
  479. }
  480. /**
  481. * Adds a vassal to the patron's vassal list.
  482. *
  483. * The patron's follower count and rank are both recaluated.
  484. *
  485. * @param memPatron - The GUID of the patron.
  486. * @param memVassal - The GUID of the vassal to add to his/her patron's vassal list.
  487. */
  488. bool cAllegiance::AddDirectVassal(DWORD dwPatronGUID, DWORD dwVassalGUID)
  489. {
  490. Member* memPatron = FindMember(dwPatronGUID);
  491. Member* memVassal = FindMember(dwVassalGUID);
  492. if (memPatron)
  493. {
  494. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  495. {
  496. if (memPatron->m_dwVassals[iVas] == 0)
  497. {
  498. memPatron->m_dwVassals[iVas] = dwVassalGUID;
  499. UpdateFollowers(memPatron, memVassal->m_dwFollowers + 1);
  500. UpdateRank(memPatron);
  501. return true;
  502. }
  503. }
  504. }
  505. return false;
  506. }
  507. /**
  508. * Removes a vassal from the patron's vassal list.
  509. *
  510. * The patron's follower count and rank are both recaluated.
  511. *
  512. * @param memVassal - A pointer to the member record of the vassal to remove from his/her patron's vassal list.
  513. */
  514. bool cAllegiance::RemDirectVassal(Member* memVassal)
  515. {
  516. Member* memPatron = FindMember(memVassal->m_dwPatron);
  517. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  518. {
  519. if (memPatron->m_dwVassals[iVas] == memVassal->m_dwGUID)
  520. {
  521. memPatron->m_dwVassals[iVas] = 0;
  522. UpdateFollowers(memPatron, -(memVassal->m_dwFollowers + 1));
  523. UpdateRank(memPatron);
  524. return true;
  525. }
  526. }
  527. return false;
  528. }
  529. /**
  530. * Removes a vassal from the patron's vassal list.
  531. *
  532. * The patron's follower count and rank are both recaluated.
  533. *
  534. * @param memVassal - The GUID of the vassal to remove from his/her patron's vassal list.
  535. */
  536. bool cAllegiance::RemDirectVassal(DWORD dwVassalGUID)
  537. {
  538. Member* memVassal = FindMember(dwVassalGUID);
  539. Member* memPatron = FindMember(memVassal->m_dwPatron);
  540. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  541. {
  542. if (memPatron->m_dwVassals[iVas] == memVassal->m_dwGUID)
  543. {
  544. memPatron->m_dwVassals[iVas] = 0;
  545. UpdateFollowers(memPatron, -(memVassal->m_dwFollowers + 1));
  546. UpdateRank(memPatron);
  547. return true;
  548. }
  549. }
  550. return false;
  551. }
  552. /**
  553. * Caclulates the number of direct vassals sworn to a given character.
  554. *
  555. * @param memPatron - A pointer to the member record of the member whose direct vassals should be calculated.
  556. *
  557. * @return int - The number of direct vassals.
  558. */
  559. int cAllegiance::GetVassalCount(Member* memPatron)
  560. {
  561. int vassalCount = 0;
  562. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  563. {
  564. if (memPatron->m_dwVassals[iVas] != 0)
  565. {
  566. vassalCount++;
  567. }
  568. }
  569. return vassalCount;
  570. }
  571. /**
  572. * Calculates the number of direct vassals sworn to a given character.
  573. *
  574. * @param dwPatronGUID - The GUID of the member whose direct vassals should be calculated.
  575. *
  576. * @return int - The number of direct vassals.
  577. */
  578. int cAllegiance::GetVassalCount(DWORD dwPatronGUID)
  579. {
  580. int vassalCount = 0;
  581. Member* memPatron = FindMember(dwPatronGUID);
  582. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  583. {
  584. if (memPatron->m_dwVassals[iVas] != 0)
  585. {
  586. vassalCount++;
  587. }
  588. }
  589. return vassalCount;
  590. }
  591. /**
  592. * Calculates the number of followers under a given character.
  593. *
  594. * @param memPatron - A pointer to the member record of the member whose followers should be calculated.
  595. *
  596. * @return int - The number of followers.
  597. */
  598. int cAllegiance::GetFollowerCount(Member* member)
  599. {
  600. int followerCount = 0;
  601. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  602. {
  603. if (member->m_dwVassals[iVas] != 0)
  604. {
  605. followerCount += 1; // add the vassal to the follower count
  606. Member* memVassal = FindMember(member->m_dwVassals[iVas]);
  607. followerCount += GetFollowerCount(memVassal); //add the vassal's followers to the follower count
  608. }
  609. }
  610. return followerCount;
  611. }
  612. /**
  613. * Calculates the number of followers under a given character.
  614. *
  615. * @param dwPatronGUID - The GUID of the member whose followers should be calculated.
  616. *
  617. * @return int - The number of followers.
  618. */
  619. int cAllegiance::GetFollowerCount(DWORD dwMemberGUID)
  620. {
  621. int followerCount = 0;
  622. Member* member = FindMember(dwMemberGUID);
  623. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  624. {
  625. if (member->m_dwVassals[iVas] != 0)
  626. {
  627. followerCount += 1; // add the vassal to the follower count
  628. Member* memVassal = FindMember(member->m_dwVassals[iVas]);
  629. followerCount += GetFollowerCount(memVassal->m_dwGUID);//add the vassal's followers to the follower count
  630. }
  631. }
  632. return followerCount;
  633. }
  634. /**
  635. * Updates the allegiance ID for a player.
  636. *
  637. * The function is used to update a player's allegiance ID when he/she joins an allegiance or his/her allegiance is switched.
  638. *
  639. * @param member - A pointer to the member record of the player whose allegiance ID should be changed.
  640. * @param newAllegianceID - The player's new allegiance ID.
  641. */
  642. void cAllegiance::UpdatePlayerAllegID(Member* member, DWORD newAllegianceID)
  643. {
  644. if (member)
  645. {
  646. // update each logged-in avatar's allegiance ID in memory
  647. cAvatar* aAvatar = cClient::FindAvatar(member->m_dwGUID);
  648. if (aAvatar)
  649. aAvatar->SetAllegianceID(newAllegianceID);
  650. // update each avatar's allegiance ID in the database
  651. UpdateAvatarAllegIDDB(member->m_dwGUID, newAllegianceID);
  652. if (newAllegianceID == 0)
  653. DeleteMemberRecordDB(newAllegianceID, member->m_dwGUID);
  654. else
  655. UpdateMemberAllegIDDB(member->m_dwGUID, newAllegianceID);
  656. }
  657. }
  658. /**
  659. * Updates the allegiance ID for a player.
  660. *
  661. * The function is used to update a player's allegiance ID when he/she joins an allegiance or his/her allegiance is switched.
  662. *
  663. * @param dwPlayerGUID - The GUID of the player whose allegiance ID should be changed.
  664. * @param newAllegianceID - The player's new allegiance ID.
  665. */
  666. void cAllegiance::UpdatePlayerAllegID(DWORD dwPlayerGUID, DWORD newAllegianceID)
  667. {
  668. // update each logged-in avatar's allegiance ID in memory
  669. cAvatar* aAvatar = cClient::FindAvatar(dwPlayerGUID);
  670. if (aAvatar)
  671. aAvatar->SetAllegianceID(newAllegianceID);
  672. // update each avatar's allegiance ID in the database
  673. UpdateAvatarAllegIDDB(dwPlayerGUID, newAllegianceID);
  674. if (newAllegianceID == 0)
  675. DeleteMemberRecordDB(newAllegianceID, dwPlayerGUID);
  676. else
  677. UpdateMemberAllegIDDB(dwPlayerGUID, newAllegianceID);
  678. }
  679. /**
  680. * Updates the follower count for a branch of the allegiance tree.
  681. *
  682. * The function is used to update the tree when a member is added or removed.
  683. * Each follower of that member must be added/removed to/from the follower count for each allegiance member higher in the tree.
  684. *
  685. * @param member - A pointer to the member record of the base member from whom to start.
  686. * @param numFollowers - The number of followers added or removed.
  687. */
  688. void cAllegiance::UpdateFollowers(Member* member, int numFollowers)
  689. {
  690. if (member)
  691. {
  692. member->m_dwFollowers += numFollowers;
  693. // update the allegiance member database record
  694. UpdateMemberFollowersDB(member->m_dwGUID, member->m_dwFollowers);
  695. if (member->m_dwGUID != m_LeaderGUID)
  696. {
  697. Member* memPatron = FindMember(member->m_dwPatron);
  698. UpdateFollowers(memPatron, numFollowers);
  699. }
  700. }
  701. }
  702. /**
  703. * Updates the follower count for a branch of the allegiance tree.
  704. *
  705. * The function is used to update the tree when a member is added or removed.
  706. * Each follower of that member must be added/removed to/from the follower count for each allegiance member higher in the tree.
  707. *
  708. * @param memberGUID - The GUID of the base member from whom to start.
  709. * @param numFollowers - The number of followers added or removed.
  710. */
  711. void cAllegiance::UpdateFollowers(DWORD dwMemberGUID, int numFollowers)
  712. {
  713. Member* member = FindMember(dwMemberGUID);
  714. if (member)
  715. {
  716. member->m_dwFollowers += numFollowers;
  717. // update the allegiance member database record
  718. UpdateMemberFollowersDB(member->m_dwGUID, member->m_dwFollowers);
  719. if (member->m_dwGUID != m_LeaderGUID)
  720. {
  721. UpdateFollowers(member->m_dwPatron, numFollowers);
  722. }
  723. }
  724. }
  725. /**
  726. * Updates the rank of a member.
  727. *
  728. * A patron's rank is equal to the rank of the highest vassal or one higher than the two highest vassals of equal rank, whichever is greater.
  729. * A patron's rank may change if he/she gains/loses a vassal, or if a vassal's rank changes.
  730. * If a member's rank has changed, his/her patron's rank is also recalculated.
  731. * The minimum rank is 1.
  732. *
  733. * @param member - A pointer to the member record of the base member/patron from whom to start.
  734. */
  735. void cAllegiance::UpdateRank(Member* member)
  736. {
  737. int newRank = 1;
  738. int rankCount = 0;
  739. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  740. {
  741. if (member->m_dwVassals[iVas] != 0)
  742. {
  743. Member* memVassal = FindMember(member->m_dwVassals[iVas]);
  744. if (memVassal->m_bRank > newRank)
  745. {
  746. newRank = memVassal->m_bRank;
  747. rankCount = 1;
  748. }
  749. else if (memVassal->m_bRank == newRank)
  750. {
  751. rankCount++;
  752. }
  753. }
  754. }
  755. if (rankCount >= 2) // if two vassals have the same rank
  756. {
  757. //add one to the rank
  758. newRank = newRank + 1;
  759. }
  760. if (newRank > MAX_RANK)
  761. {
  762. newRank = MAX_RANK;
  763. }
  764. if (newRank != member->m_bRank) // if the new rank is different from the old rank
  765. {
  766. // update the member's rank, and the rank of his/her patron
  767. member->m_bRank = newRank;
  768. // update the allegiance member database record
  769. UpdateMemberRankDB(member->m_dwGUID, member->m_bRank);
  770. if (member->m_dwGUID != this->GetLeader())
  771. UpdateRank(member->m_dwPatron);
  772. }
  773. }
  774. /**
  775. * Updates the rank of a member.
  776. *
  777. * A patron's rank is equal to the rank of the highest vassal or one higher than the two highest vassals of equal rank, whichever is greater.
  778. * A patron's rank may change if he/she gains/loses a vassal, or if a vassal's rank changes.
  779. * If a member's rank has changed, his/her patron's rank is also recalculated.
  780. * The minimum rank is 1.
  781. *
  782. * @param memberGUID - The GUID of the base member/patron from whom to start.
  783. */
  784. void cAllegiance::UpdateRank(DWORD dwMemberGUID)
  785. {
  786. Member* member = FindMember(dwMemberGUID);
  787. int newRank = 1;
  788. int rankCount = 0;
  789. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  790. {
  791. if (member->m_dwVassals[iVas] != 0)
  792. {
  793. Member* memVassal = FindMember(member->m_dwVassals[iVas]);
  794. if (memVassal->m_bRank > newRank)
  795. {
  796. newRank = memVassal->m_bRank;
  797. rankCount = 1;
  798. }
  799. else if (memVassal->m_bRank == newRank)
  800. {
  801. rankCount++;
  802. }
  803. }
  804. }
  805. if (rankCount >= 2) // if two vassals have the same rank
  806. {
  807. //add one to the rank
  808. newRank = newRank + 1;
  809. }
  810. if (newRank > MAX_RANK)
  811. {
  812. newRank = MAX_RANK;
  813. }
  814. if (newRank != member->m_bRank) // if the new rank is different from the old rank
  815. { // update the member's rank, and the rank of his/her patron
  816. member->m_bRank = newRank;
  817. // update the allegiance member database record
  818. UpdateMemberRankDB(member->m_dwGUID, member->m_bRank);
  819. if (member->m_dwGUID != this->GetLeader())
  820. UpdateRank(member->m_dwPatron);
  821. }
  822. }
  823. /*
  824. Allegiance Experience Pass-up
  825. "OLD" FORMULA:
  826. (Pre "The Madness of Men" event - February 24, 2004)
  827. The XP pass-up formula based upon Zerot's Experience Calculator.
  828. The pass-up XP from vassal to patron is calculated as follows:
  829. Generated % - % XP to patron of vassal's earned (hunting) XP.
  830. Received % - % XP that patron will receive from his vassal's generated XP.
  831. Passup % - % XP actually received by patron from vassal's earned (hunting) XP.
  832. Generated % = 8.9 + (2 * 3.5 * (ALoy / 100))
  833. Received % = 68 + (.35 * ALdr) (max 1.25)
  834. Passup % = Generated % * Received % / 100.0
  835. where,
  836. ALoy = Adjusted Loyalty = BLoy + ((IG / 240) * BLoy)
  837. BLoy = Buffed Loyalty
  838. IG = actual in-game time sworn to patron in hours (720 max)
  839. ALdr = Adjusted Leadership (163 max) = BLrd + (((7.5 * V) / 100) * BLrd) + ((IG2 / 1200) * BLrd)
  840. BLrd = Buffed Leadership
  841. V = vassal factor ((7.5 * vassals) / 100) (.90 max)
  842. IG2 = average in-game time sworn to patron for all vassals in hours (240 max)
  843. ---------------------
  844. The pass-up from grand vassal to grand patron is calculated as follows:
  845. Generated2 % - % XP to patron of vassal's pass-up (grand vassal) XP.
  846. Received2 % - % XP that patron will receive from his vassal's generated XP.
  847. Passup2 % - % XP actually received by patron from vassal's pass-up (grand vassal) XP.
  848. Generated2 % = 45 + (.15 * ALoy)
  849. Received2 % = 68 + (.35 * ALdr) (max 1.25)
  850. Passup2 % = Generated2 % * Received2 % / 100.0
  851. where,
  852. ALoy = Adjusted Loyalty = BLoy + ((IG / 240) * BLoy)
  853. BLoy = Buffed Loyalty
  854. IG = actual in-game time sworn to patron in hours (720 max)
  855. ALdr = Adjusted Leadership (163 max) = BLrd + (((7.5 * V) / 100) * BLrd) + ((IG2 / 1200) * BLrd)
  856. BLrd = Buffed Leadership
  857. V = vassal factor ((7.5 * vassals) / 100) (.90 max)
  858. IG2 = average in-game time sworn to patron for all vassals in hours (240 max)
  859. ------------------------------------------
  860. "NEW" FORMULA:
  861. (Post "The Madness of Men" event - February 24, 2004)
  862. The XP pass-up formula of Xerxes of Thistledown.
  863. The pass-up XP from vassal to patron is calculated as follows:
  864. NOTE: Extensive testing has been done over a period of 4 months to verify these results.
  865. Generated % - % XP to patron of vassal's earned (hunting) XP.
  866. Received % - % XP that patron will receive from his vassal's generated XP.
  867. Passup % - % XP actually received by patron from vassal's earned (hunting) XP.
  868. Generated % = 50.0 + 22.5 * (BLoy / 291) * (1.0 + (RT/730) * (IG/720))
  869. Received % = 50.0 + 22.5 * (BLdr / 291) * (1.0 + V * (RT2/730) * (IG2/720))
  870. Passup % = Generated % * Received % / 100.0
  871. where,
  872. BLoy = Buffed Loyalty (291 max)
  873. BLdr = Buffed Leadership (291 max)
  874. RT = actual real time sworn to patron in days (730 max)
  875. IG = actual in-game time sworn to patron in hours (720 max)
  876. RT2 = average real time sworn to patron for all vassals in days (730 max)
  877. IG2 = average in-game time sworn to patron for all vassals in hours (720 max)
  878. V = vassal factor (1 = 0.25, 2 = 0.50, 3 = 0.75, 4+ = 1.00) (1.0 max)
  879. The Generated % is what is reported on the allegiance panel.
  880. ---------------------
  881. The pass-up from grand vassal to grand patron is calculated as follows:
  882. NOTE: While, I have done very little testing on grand vassal XP Passup, I would speculate that the equation is similar to vassal Passup:
  883. Generated2 % - % XP to patron of vassal's pass-up (grand vassal) XP.
  884. Received2 % - % XP that patron will receive from his vassal's generated XP.
  885. Passup2 % - % XP actually received by patron from vassal's pass-up (grand vassal) XP.
  886. Generated2 % = 16.0 + 8.0 * (BLoy / 291) * (1.0 + (RT/730) * (IG/720))
  887. Received2 % = 16.0 + 8.0 * (BLdr / 291) * (1.0 + V * (RT2/730) * (IG2/720))
  888. Passup2 % = Generated2 % * Received2 % / 100.0
  889. where,
  890. BLoy = Buffed Loyalty (291 max)
  891. BLdr = Buffed Leadership (291 max)
  892. RT = actual real time sworn to patron in days (730 max)
  893. IG = actual in-game time sworn to patron in hours (720 max)
  894. RT2 = average real time sworn to patron for all vassals in days (730 max)
  895. IG2 = average in-game time sworn to patron for all vassals in hours (720 max)
  896. V = vassal factor (1 = 0.25, 2 = 0.50, 3 = 0.75, 4+ = 1.00) (1.0 max)
  897. Passup % * Passup2 % / 100.0 would be the %-tage the grand patron receives from a grand vassal's earned (hunting) XP.
  898. */
  899. /**
  900. * Calculates the percentage of experience passed up from a vassal.
  901. *
  902. * @param memVassal - A pointer to the member record of the vassal to use for the calculations.
  903. * @param experience - The amount of experience from which to calculate pass-up.
  904. * @param isGrandVassal - Is a grand vassal (a non-originator of the experience).
  905. */
  906. void cAllegiance::VassalPassupXP(Member* memVassal, UINT64 experience, bool isGrandVassal)
  907. {
  908. // find the patron's allegiance record
  909. if (memVassal->m_dwPatron != NULL)
  910. {
  911. Member* memPatron = FindMember(memVassal->m_dwPatron);
  912. UINT64 generatedXP, receivedXP;
  913. generatedXP = PASSED_XP_MULT * CalcVassalGeneratedXP(memVassal, experience, isGrandVassal);
  914. UpdateGeneratedXP(memVassal,generatedXP);
  915. receivedXP = RECEIVED_XP_MULT * CalcPatronReceivedXP(memPatron, generatedXP, isGrandVassal);
  916. UpdateEarnedXP(memPatron,receivedXP);
  917. if (receivedXP > 0)
  918. {
  919. if (memPatron->m_dwGUID != this->m_LeaderGUID) // if not the monarch
  920. {
  921. VassalPassupXP(memPatron, receivedXP, true);// further experience pass-up; recurse to this function
  922. }
  923. }
  924. }
  925. }
  926. /**
  927. * Updates the member's generated experience.
  928. *
  929. *
  930. * @param member - A pointer to the member record of the member whose generated experience should be updated.
  931. * @param experience - The amount of experience generated.
  932. */
  933. void cAllegiance::UpdateGeneratedXP(Member* member, UINT64 experience)
  934. {
  935. if (experience > 0)
  936. {
  937. member->m_passupXP += experience;
  938. // update the allegiance member database record
  939. UpdateMemberXPPassupDB(member->m_dwGUID, member->m_passupXP);
  940. }
  941. }
  942. /**
  943. * Updates the member's earned experience.
  944. *
  945. * The member may be logged-on or logged-off:
  946. * If the member is logged-on, the experience is added directly to the avatar's unassigned experience.
  947. * If the member is logged-off, the experience is added to the avatar's pending experience.
  948. *
  949. * @param member - A pointer to the member record of the member whose experience should be updated.
  950. * @param experience - The amount of experience earned.
  951. */
  952. void cAllegiance::UpdateEarnedXP(Member* member, UINT64 experience)
  953. {
  954. if (experience > 0)
  955. {
  956. if (member->m_online)
  957. {
  958. cClient *pcClient = cClient::FindClient( member->m_dwGUID );
  959. if (pcClient)
  960. {
  961. pcClient->m_pcAvatar->UpdateUnassignedExp(experience);
  962. }
  963. }
  964. else
  965. {
  966. member->m_pendingXP += experience;
  967. // update the allegiance member database record
  968. UpdateMemberXPPendingDB(member->m_dwGUID, member->m_pendingXP);
  969. }
  970. }
  971. }
  972. /**
  973. * Calculates the percentage of experience passed up from a vassal.
  974. *
  975. * Generated % - % XP to patron of vassal's Earned (hunting) XP
  976. *
  977. * Old Vassal Generated % = 8.9 + (2 * 3.5 * (ALoy / 100))
  978. * New Vassal Generated % = 50.0 + 22.5 * (BLoy / 291) * (1.0 + (RT/730) * (IG/720))
  979. * Old Grand Vassal Generated % = 45 + (.15 * ALoy)
  980. * New Grand Vassal Generated % = 16.0 + 8.0 * (BLoy / 291) * (1.0 + (RT/730) * (IG/720))
  981. *
  982. * Variables:
  983. * ALoy = Adjusted Loyalty = BLoy + ((IG / 240) * BLoy)
  984. * BLoy = Buffed Loyalty (291 max)
  985. * RT = actual real-time sworn to patron in days (730 max)
  986. * IG = actual in-game time sworn to patron in hours (720 max)
  987. *
  988. * @param memVassal - A pointer to the member record of the vassal to use for the calculations.
  989. *
  990. * @return UINT - The amount of experience generated.
  991. */
  992. UINT64 cAllegiance::CalcVassalGeneratedXP(Member* memVassal, UINT64 passedXP, bool isGrandVassal)
  993. {
  994. time_t curtime;
  995. curtime = time (NULL); // the current time
  996. int bufLoyalty = memVassal->m_wLoyalty;
  997. float igSwornTimeDays = (memVassal->m_timeIGTotal - memVassal->m_timeIGSwear) / 86400;
  998. if (OLD_PASSUP)
  999. {
  1000. // units are in days: 240 hours = 10 days
  1001. if (igSwornTimeDays > 10) igSwornTimeDays = 10;
  1002. int aLoyalty = bufLoyalty + ((igSwornTimeDays / 10) * bufLoyalty);
  1003. if (isGrandVassal)
  1004. {
  1005. if (aLoyalty > 200) aLoyalty = 200;
  1006. return (INT64)passedXP * (float)((45 + (.15 * aLoyalty)) / 100);
  1007. }
  1008. else
  1009. {
  1010. return (INT64)passedXP * (float)((8.9 + (2 * 3.5 * (aLoyalty / 100))) / 100);
  1011. }
  1012. }
  1013. else
  1014. {
  1015. float rtSwornTimeDays = (curtime - memVassal->m_timeRLSwear) / 86400;
  1016. if (rtSwornTimeDays > 730) rtSwornTimeDays = 730;
  1017. if (igSwornTimeDays > 720) igSwornTimeDays = 720;
  1018. if (isGrandVassal)
  1019. return (INT64)passedXP * (float)((16.0 + 8.0 * (bufLoyalty / 291) * (1.0 + (rtSwornTimeDays/730) * (igSwornTimeDays/720))) / 100.0);
  1020. else
  1021. return (INT64)passedXP * (float)((50.0 + 22.5 * (bufLoyalty / 291) * (1.0 + (rtSwornTimeDays/730) * (igSwornTimeDays/720))) / 100.0);
  1022. }
  1023. }
  1024. /**
  1025. * Calculates the percentage of experience received by a grand patron.
  1026. *
  1027. * Received % - % XP that patron will receive from his vassal's Generated XP.
  1028. *
  1029. * Old Patron Received % = 68 + (.35 * ALdr) (max 1.25)
  1030. * New Patron Received % = 50.0 + 22.5 * (BLdr / 291) * (1.0 + V * (RT2/730) * (IG2/720))
  1031. * Old Grand Patron Received % = 68 + (.35 * ALdr) (max 1.25)
  1032. * New Grand Patron Received % = 16.0 + 8.0 * (BLdr / 291) * (1.0 + V * (RT2/730) * (IG2/720))
  1033. *
  1034. * Variables:
  1035. * ALdr = Adjusted Leadership (163 max) = BLrd + (((7.5 * V) / 100) * BLrd) + ((IG2 / 1200) * BLrd)
  1036. * BLdr = Buffed Leadership (291 max)
  1037. * RT2 = average real-time sworn to patron for all vassals in days (730 max)
  1038. * IG2 = average in-game time sworn to patron for all vassals in hours (720 max)
  1039. * V = vassal factor
  1040. * Old: number of vassals
  1041. * New: (1 = 0.25, 2 = 0.50, 3 = 0.75, 4+ = 1.00) (1.0 max)
  1042. *
  1043. * @param memPatron - A pointer to the member record of the patron to use for the calculations.
  1044. *
  1045. * @return UIN - The amount of experience received.
  1046. */
  1047. UINT64 cAllegiance::CalcPatronReceivedXP(Member* memPatron, UINT64 receivedXP, bool isGrandPatron)
  1048. {
  1049. int bufLeadership = memPatron->m_wLeadership;
  1050. float avgIGSwornTime = memPatron->m_avgRTSworn / 86400;
  1051. float vassalFactor = CalcVassalFactor(GetVassalCount(memPatron));
  1052. if (OLD_PASSUP)
  1053. {
  1054. if (avgIGSwornTime > 240) avgIGSwornTime = 240;
  1055. int aLeadership = bufLeadership + (((7.5 * vassalFactor) / 100) * bufLeadership) + ((avgIGSwornTime / 1200) * bufLeadership);
  1056. float receivedPercent = (68 + (.35 * aLeadership)) / 100;
  1057. if (receivedPercent > 1.25)
  1058. receivedPercent = 1.25;
  1059. return ((INT64)receivedXP * receivedPercent);
  1060. }
  1061. else
  1062. {
  1063. float avgRTSwornTime = memPatron->m_avgIGSworn / 86400;
  1064. if (avgRTSwornTime > 730) avgRTSwornTime = 730;
  1065. if (avgIGSwornTime > 720) avgIGSwornTime = 720;
  1066. if(isGrandPatron)
  1067. return (INT64)receivedXP * (float)((16.0 + 8.0 * (bufLeadership / 291) * (1.0 + vassalFactor * (avgRTSwornTime/730) * (avgIGSwornTime/720))) / 100.0);
  1068. else
  1069. return (INT64)receivedXP * (float)((50.0 + 22.5 * (bufLeadership / 291) * (1.0 + vassalFactor * (avgRTSwornTime/730) * (avgIGSwornTime/720))) / 100.0);
  1070. }
  1071. }
  1072. /**
  1073. * Calculates the average sworn time for a patron's vassals and updates the patron's member record.
  1074. *
  1075. * This function calculates both the average in-game and average real-time sworn time for a patron's vassals.
  1076. * These values are used in the calculation of vassal experience pass-up to a patron.
  1077. *
  1078. * @param memPatron - A pointer to the member record of the patron to use for the calculations.
  1079. */
  1080. void cAllegiance::UpdateAverageSwornTimeOfVassals(Member* memPatron)
  1081. {
  1082. time_t curtime;
  1083. curtime = time (NULL); //the current time
  1084. int numVassals = 0;
  1085. float totalSwornTimeIG = 0;
  1086. float totalSwornTimeRT = 0;
  1087. // find each vassal's allegiance record
  1088. for (int iVas = 0; iVas < MAX_VASSALS; ++iVas)
  1089. {
  1090. if (memPatron->m_dwVassals[iVas] != 0)
  1091. {
  1092. Member* memVassal = FindMember(memPatron->m_dwVassals[iVas]);
  1093. totalSwornTimeIG += memVassal->m_timeIGTotal - memVassal->m_timeIGSwear;
  1094. totalSwornTimeRT += curtime - memVassal->m_timeRLSwear;
  1095. numVassals++;
  1096. }
  1097. }
  1098. memPatron->m_avgIGSworn = totalSwornTimeIG / numVassals; // average in-game sworn time of vassals
  1099. memPatron->m_avgRTSworn = totalSwornTimeRT / numVassals; // average real-time sworn time of vassals
  1100. }
  1101. /**
  1102. * Calculates the vassal factor based upon a patron's number of vassals.
  1103. *
  1104. * Used in the calculation of patron-received experience.
  1105. *
  1106. * @param numVassals - The number of vassals sworn to a given patron.
  1107. *
  1108. * @return float - The vassal factor.
  1109. */
  1110. float cAllegiance::CalcVassalFactor(int numVassals)
  1111. {
  1112. if (OLD_PASSUP)
  1113. {
  1114. return numVassals;
  1115. }
  1116. else
  1117. {
  1118. if (numVassals >= 4)
  1119. return 1;
  1120. else if (numVassals == 3)
  1121. return .75;
  1122. else if (numVassals == 2)
  1123. return .50;
  1124. else if (numVassals == 1)
  1125. return .25;
  1126. else
  1127. return 0;
  1128. }
  1129. }
  1130. /* Allegiance Database Updates */
  1131. void cAllegiance::Disband()
  1132. {
  1133. std::map<DWORD, Member>::iterator itrMember;
  1134. for ( itrMember = this->members.begin() ; itrMember != this->members.end() ; ++itrMember )
  1135. {
  1136. // update logged-in avatar's allegiance ID in memory
  1137. cAvatar* aAvatar = cClient::FindAvatar(itrMember->first);
  1138. if (aAvatar)
  1139. aAvatar->m_dwAllegianceID = 0;
  1140. // update each avatar's allegiance ID in the database
  1141. UpdateAvatarAllegIDDB(itrMember->first, 0);
  1142. }
  1143. char szCommand[512];
  1144. RETCODE retcode;
  1145. sprintf( szCommand, "DELETE FROM `allegiance` WHERE AllegianceID = %lu;",m_ID);
  1146. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1147. retcode = SQLExecute( cDatabase::m_hStmt );
  1148. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1149. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1150. sprintf( szCommand, "DELETE FROM `allegiance_members` WHERE AllegianceID = %lu;",m_ID);
  1151. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1152. retcode = SQLExecute( cDatabase::m_hStmt );
  1153. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1154. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1155. members.clear();
  1156. delete this;
  1157. }
  1158. void cAllegiance::UpdateAvatarAllegIDDB(DWORD dwGUID, DWORD allegianceID)
  1159. {
  1160. char szCommand[512];
  1161. RETCODE retcode;
  1162. sprintf( szCommand, "UPDATE `avatar` SET `AllegianceID` = %lu WHERE AvatarGUID = %lu;",allegianceID, dwGUID);
  1163. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1164. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1165. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1166. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1167. }
  1168. void cAllegiance::UpdateMemberAllegIDDB(DWORD dwGUID, DWORD allegianceID)
  1169. {
  1170. char szCommand[512];
  1171. RETCODE retcode;
  1172. sprintf( szCommand, "UPDATE `allegiance_members` SET `AllegianceID` = %lu WHERE MemberGUID = %lu;",allegianceID, dwGUID);
  1173. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1174. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1175. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1176. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1177. }
  1178. void cAllegiance::UpdateAvatarRecordDB(DWORD dwAvatarGUID)
  1179. {
  1180. cAvatar* pcAvatar = cClient::FindAvatar(dwAvatarGUID);
  1181. char szCommand[512];
  1182. RETCODE retcode;
  1183. sprintf( szCommand, "UPDATE `allegiance_members` SET `Loyalty` = %d, `Leadership` = %d WHERE MemberGUID = %lu;",pcAvatar->GetTotalLoyalty(),pcAvatar->GetTotalLeadership(),pcAvatar->GetGUID());
  1184. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1185. retcode = SQLExecute( cDatabase::m_hStmt );
  1186. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1187. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1188. }
  1189. void cAllegiance::AddMemberRecordDB(DWORD allegianceID, DWORD dwMemberGUID, DWORD dwPatronGUID)
  1190. {
  1191. cAllegiance* aAllegiance = GetAllegianceByID(allegianceID);
  1192. Member* member = aAllegiance->FindMember(dwMemberGUID);
  1193. char szCommand[1024];
  1194. RETCODE retcode;
  1195. sprintf( szCommand, "INSERT INTO `allegiance_members` ( `AllegianceID`, `MemberGUID`, `MemberName`, `Gender`, `Race`, `Rank`, `Loyalty`, `Leadership`, `XP_Passup`, `XP_Pending`, `Patron`, `Followers`, `TimeSwornRL`, `TimeSwornIG` ) VALUES (%lu, %lu, '%s', %d, %d, %d, %d, %d, %lu, %lu, %lu, %d, %lu, %lu);",allegianceID, member->m_dwGUID, member->m_szName.c_str(), member->m_bGender, member->m_bRace, member->m_bRank, member->m_wLoyalty, member->m_wLeadership, 0, 0, dwPatronGUID, 0, time (NULL), 0);
  1196. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1197. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1198. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1199. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1200. }
  1201. void cAllegiance::DeleteMemberRecordDB(DWORD allegianceID, DWORD dwMemberGUID)
  1202. {
  1203. char szCommand[512];
  1204. RETCODE retcode;
  1205. sprintf( szCommand, "DELETE FROM `allegiance_members` WHERE MemberGUID = %lu AND AllegianceID = %lu;",dwMemberGUID, allegianceID);
  1206. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1207. retcode = SQLExecute( cDatabase::m_hStmt );
  1208. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1209. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1210. }
  1211. void cAllegiance::UpdateMemberRecordDB(Member* member)
  1212. {
  1213. char szCommand[512];
  1214. RETCODE retcode;
  1215. sprintf( szCommand, "UPDATE `allegiance_members` SET `XP_Passup` = %lu, `XP_Pending` = %lu WHERE MemberGUID = %lu;",member->m_passupXP,member->m_pendingXP,member->m_dwGUID);
  1216. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1217. retcode = SQLExecute( cDatabase::m_hStmt );
  1218. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1219. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1220. }
  1221. void cAllegiance::UpdateMemberXPPassupDB(DWORD memberGUID, UINT64 passedXP)
  1222. {
  1223. char szCommand[512];
  1224. RETCODE retcode;
  1225. sprintf( szCommand, "UPDATE `allegiance_members` SET `XP_Passup` = %lu WHERE MemberGUID = %lu;",(DWORD)passedXP, memberGUID);
  1226. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1227. retcode = SQLExecute( cDatabase::m_hStmt );
  1228. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1229. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1230. }
  1231. void cAllegiance::UpdateMemberXPPendingDB(DWORD memberGUID, UINT64 pendingXP)
  1232. {
  1233. char szCommand[512];
  1234. RETCODE retcode;
  1235. sprintf( szCommand, "UPDATE `allegiance_members` SET `XP_Pending` = %lu WHERE MemberGUID = %lu;",(DWORD)pendingXP, memberGUID);
  1236. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1237. retcode = SQLExecute( cDatabase::m_hStmt );
  1238. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1239. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1240. }
  1241. void cAllegiance::UpdateMemberFollowersDB(DWORD memberGUID, int numFollowers)
  1242. {
  1243. char szCommand[512];
  1244. RETCODE retcode;
  1245. sprintf( szCommand, "UPDATE `allegiance_members` SET `Followers` = %d WHERE MemberGUID = %lu;", numFollowers, memberGUID);
  1246. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1247. retcode = SQLExecute( cDatabase::m_hStmt );
  1248. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1249. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1250. }
  1251. void cAllegiance::UpdateMemberRankDB(DWORD memberGUID, int rank)
  1252. {
  1253. char szCommand[512];
  1254. RETCODE retcode;
  1255. sprintf( szCommand, "UPDATE `allegiance_members` SET `Rank` = %d WHERE MemberGUID = %lu;", rank, memberGUID);
  1256. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1257. retcode = SQLExecute( cDatabase::m_hStmt );
  1258. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1259. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1260. }
  1261. void cAllegiance::UpdateMemberPatronDB(DWORD memberGUID, DWORD patronGUID)
  1262. {
  1263. char szCommand[512];
  1264. RETCODE retcode;
  1265. sprintf( szCommand, "UPDATE `allegiance_members` SET `Patron` = %lu WHERE MemberGUID = %lu;", patronGUID, memberGUID);
  1266. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1267. retcode = SQLExecute( cDatabase::m_hStmt );
  1268. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1269. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1270. }