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

cBooks.cpp 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. /**
  18. * @file cBooks.cpp
  19. * Implements functionality for books.
  20. *
  21. * This class is referenced whenever a book is created, used, or assessed.
  22. * Inherits from the cObject class.
  23. */
  24. #include "avatar.h"
  25. #include "object.h"
  26. #include "cItemModels.h"
  27. #include "client.h"
  28. #include "WorldManager.h"
  29. #include "MasterServer.h"
  30. /**
  31. * Handles the message sent for the creation of books in the world.
  32. *
  33. * This function is called whenever a book should be created in the world for a client.
  34. *
  35. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  36. */
  37. cMessage cBooks::CreatePacket( )
  38. {
  39. cMessage cmReturn;
  40. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  41. cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  42. if( pcModel )
  43. {
  44. cmReturn << 0xF745L << m_dwGUID << BYTE(0x11); //0x11 is a constant
  45. cmReturn << pcModel->m_bPaletteChange
  46. << pcModel->m_bTextureChange
  47. << pcModel->m_bModelChange;
  48. // The Model Vectors
  49. if ( pcModel->m_bPaletteChange != 0)
  50. {
  51. for (int i = 0; i < pcModel->m_bPaletteChange; i++)
  52. {
  53. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorPal[i],sizeof(pcModel->m_vectorPal[i]));
  54. }
  55. }
  56. if (pcModel->m_bPaletteChange != 0)
  57. {
  58. //Cubem0j0: Test code for armor only.
  59. cmReturn << WORD( 0x0C50 );
  60. }
  61. if ( pcModel->m_bTextureChange != 0)
  62. {
  63. for (int i = 0; i < pcModel->m_bTextureChange; i++)
  64. {
  65. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorTex[i],sizeof(pcModel->m_vectorTex[i]));
  66. }
  67. }
  68. if ( pcModel->m_bModelChange != 0)
  69. {
  70. for (int i = 0; i < pcModel->m_bModelChange; i++)
  71. {
  72. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorMod[i],sizeof(pcModel->m_vectorMod[i]));
  73. }
  74. }
  75. }
  76. cmReturn.pasteAlign(4);
  77. cmReturn << pcModel->m_dwFlags1 << 0x414L << 0x65L;
  78. // MASK 0x00008000 -- Location
  79. if ( !m_fIsOwned )
  80. cmReturn.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  81. // MASK 0x00000800 -- Sound Set
  82. DWORD dwSoundSet = 0x20000000L + pcModel->m_wSoundSet;
  83. cmReturn << dwSoundSet;
  84. // MASK 0x00001000 -- Particle Effects (unknown_blue)
  85. cmReturn << 0x34000000 + pcModel->m_dwUnknown_Blue;
  86. // MASK 0x00000001 -- ModelNumber
  87. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  88. cmReturn << dwModel;
  89. // SeaGreens
  90. WORD wNuminteracts = 0x0;
  91. WORD wNumbubbles = 0x0;
  92. WORD wNumJumps = 0x0;
  93. WORD wNumOverrides = 0x0;
  94. WORD wUnkFlag8 = 0x0;
  95. WORD wUnkFlag10 = 0x0;
  96. cmReturn << m_wPositionSequence
  97. << m_wNumAnims //wNuminteracts
  98. << wNumbubbles
  99. << wNumJumps
  100. << m_wNumPortals
  101. << m_wNumAnims
  102. << wNumOverrides
  103. << wUnkFlag8
  104. << m_wNumLogins
  105. << wUnkFlag10;
  106. cmReturn << pcModel->m_dwFlags2; // Object Flags
  107. cmReturn << Name( ); // Object's Name
  108. cmReturn << pcModel->m_wModel; // Object's Model
  109. cmReturn << pcModel->m_wIcon; // Object's Icon
  110. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  111. cmReturn << pcModel->m_dwObjectFlags2; // Object Flags
  112. // Masked against dwFlags2
  113. if(pcModel->m_dwFlags2 & 0x00000008)
  114. cmReturn << pcModel->m_dwValue;
  115. // Mask 0x0010 dwUnknown_v2
  116. if(pcModel->m_dwFlags2 & 0x00000010)
  117. cmReturn << DWORD(0x00000008);
  118. // Mask 0x00200000 - Burden
  119. if(pcModel->m_dwFlags2 & 0x00200000)
  120. cmReturn << pcModel->m_wBurden;
  121. cmReturn << WORD(0x0000);
  122. return cmReturn;
  123. }
  124. /**
  125. * Handles the message sent for the creation of books in a container.
  126. *
  127. * This function is called whenever a book should be created in the inventory of another object.
  128. *
  129. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  130. */
  131. cMessage cBooks::CreatePacketContainer(DWORD Container,DWORD ItemModelID)
  132. {
  133. cMessage cmReturn;
  134. cItemModels *pcModel = cItemModels::FindModel( ItemModelID );
  135. cObject *pcObject = cWorldManager::FindObject( m_dwGUID );
  136. if( pcModel )
  137. {
  138. cmReturn << 0xF745L << m_dwGUID << BYTE(0x11); //0x11 is a constant
  139. cmReturn << pcModel->m_bPaletteChange
  140. << pcModel->m_bTextureChange
  141. << pcModel->m_bModelChange;
  142. // The Model Vectors
  143. if ( pcModel->m_bPaletteChange != 0)
  144. {
  145. for (int i = 0; i < pcModel->m_bPaletteChange; i++)
  146. {
  147. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorPal[i],sizeof(pcModel->m_vectorPal[i]));
  148. }
  149. }
  150. if (pcModel->m_bPaletteChange != 0)
  151. {
  152. //Cubem0j0: Test code for armor only.
  153. cmReturn << WORD( 0x0C50 );
  154. }
  155. if ( pcModel->m_bTextureChange != 0)
  156. {
  157. for (int i = 0; i < pcModel->m_bTextureChange; i++)
  158. {
  159. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorTex[i],sizeof(pcModel->m_vectorTex[i]));
  160. }
  161. }
  162. if ( pcModel->m_bModelChange != 0)
  163. {
  164. for (int i = 0; i < pcModel->m_bModelChange; i++)
  165. {
  166. cmReturn.pasteData((UCHAR*)&pcModel->m_vectorMod[i],sizeof(pcModel->m_vectorMod[i]));
  167. }
  168. }
  169. }
  170. cmReturn.pasteAlign(4);
  171. cmReturn << pcModel->m_dwFlags1 << 0x414L << 0x65L;
  172. // MASK 0x00000800 -- Sound Set
  173. DWORD dwSoundSet = 0x20000000L + pcModel->m_wSoundSet;
  174. cmReturn << dwSoundSet;
  175. // MASK 0x00001000 -- Particle Effects (unknown_blue)
  176. cmReturn << 0x34000000 + pcModel->m_dwUnknown_Blue;
  177. // MASK 0x00000001 -- ModelNumber
  178. DWORD dwModel = 0x02000000L + pcModel->m_dwModelNumber;
  179. cmReturn << dwModel;
  180. // SeaGreens
  181. WORD wNuminteracts = 0x0;
  182. WORD wNumbubbles = 0x0;
  183. WORD wNumJumps = 0x0;
  184. WORD wNumOverrides = 0x0;
  185. WORD wUnkFlag8 = 0x0;
  186. WORD wUnkFlag10 = 0x0;
  187. cmReturn << m_wPositionSequence
  188. << m_wNumAnims //wNuminteracts
  189. << wNumbubbles
  190. << wNumJumps
  191. << m_wNumPortals
  192. << m_wNumAnims
  193. << wNumOverrides
  194. << wUnkFlag8
  195. << m_wNumLogins
  196. << wUnkFlag10;
  197. cmReturn << pcModel->m_dwFlags2; // Object Flags
  198. cmReturn << Name( ); // Object's Name
  199. cmReturn << pcModel->m_wModel; // Object's Model
  200. cmReturn << pcModel->m_wIcon; // Object's Icon
  201. cmReturn << pcModel->m_dwObjectFlags1; // Object Flags
  202. cmReturn << pcModel->m_dwObjectFlags2; // Object Flags
  203. // Masked against dwFlags2
  204. if(pcModel->m_dwFlags2 & 0x00000008)
  205. cmReturn << pcModel->m_dwValue;
  206. // Mask 0x0010 dwUnknown_v2
  207. if(pcModel->m_dwFlags2 & 0x00000010)
  208. cmReturn << DWORD(0x00000008);
  209. // Mask 0x00000020
  210. //if(pcModel->m_dwFlags2 & 0x00000020)
  211. // cmReturn << float(3.0);
  212. if(pcModel->m_dwFlags2 & 0x00004000)
  213. cmReturn << Container;
  214. // Mask 0x00200000 - Burden
  215. if(pcModel->m_dwFlags2 & 0x00200000)
  216. cmReturn << pcModel->m_wBurden;
  217. cmReturn << WORD(0x0000);
  218. return cmReturn;
  219. }
  220. /**
  221. * Handles the actions of book objects.
  222. *
  223. * This function is called whenever book is used or should perform an action.
  224. * k109: This is the table of contents message. Reading the pages function is below
  225. */
  226. void cBooks::Action(cClient *who)
  227. {
  228. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  229. char password[100] = "beer good";
  230. cMessage cmRead;
  231. cmRead << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x00B4L
  232. << m_dwGUID << pcModel->m_TotalPages << pcModel->m_ContentPages << 0x03E8L << pcModel->m_UsedPages;
  233. for(int i = 0; i < pcModel->m_TotalPages; i++)
  234. {
  235. cmRead << 0xFFFFFFFF << pcModel->m_Title.c_str() << pcModel->m_Author.c_str() << WORD(0x0002) << WORD(0xFFFF) << 0x0L << 0x0L;
  236. }
  237. /*
  238. << m_dwGUID << pcModel->m_TotalPages << pcModel->m_ContentPages << 0x03E8L << pcModel->m_UsedPages << 0xFFFFFFFF << pcModel->m_Title.c_str() << pcModel->m_Author.c_str() << 0x00000000
  239. */
  240. cmRead << pcModel->m_Comment.c_str() << who->m_pcAvatar->GetGUID() << pcModel->m_CommentAuthor.c_str();
  241. who->AddPacket(WORLD_SERVER,cmRead,4);
  242. //Action Complete
  243. cMessage cmActionComplete;
  244. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  245. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  246. }
  247. void cBooks::Read(cClient *who, DWORD GUID, DWORD PageNumber)
  248. {
  249. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  250. char Password[100] = "Password is cheese";
  251. //char Booktext[512] = "Hail, traveler, welcome to Dereth! Your adventure awaits you. Your first task is to find the Greeter, who will train you in your new skills.\n\nTo enter the Training Academy, WALK INTO THE SPINNING PURPLE PORTAL.\n\nTo move, use the arrow keys to the left of the numeric keypad, or the keys surrounding the S key. To use objects or talk to non-player characters (NPCs), double-click on them.";
  252. cMessage Read;
  253. Read << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x00B8L
  254. << GUID << PageNumber << 0xFFFFFFFF << 0x0L << Password << WORD(0x0002) << WORD(0xFFFF) << 0x1L << 0x0L << pcModel->m_Pages[PageNumber].textPages.c_str();
  255. who->AddPacket(WORLD_SERVER,Read,4);
  256. cMasterServer::ServerMessage(ColorBlue,NULL,"PageNumber: %d",PageNumber);
  257. //Action Complete
  258. cMessage cmActionComplete;
  259. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  260. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  261. }
  262. /**
  263. * Handles the assessment of book objects.
  264. *
  265. * This function is called whenever a book is assessed by a client.
  266. *
  267. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  268. */
  269. void cBooks::Assess( cClient *pcAssesser )
  270. {
  271. cItemModels *pcModel = cItemModels::FindModel( m_dwItemModelID );
  272. cMessage cmAssess;
  273. DWORD flags = 0x00000009;
  274. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L << m_dwGUID
  275. << flags
  276. << 0x01L //Success = 0x01, Failure = 0x00
  277. << WORD(0x0004)
  278. << WORD(0x0010)
  279. << 0x13L
  280. << pcModel->m_dwValue
  281. << 0x05L
  282. << DWORD(pcModel->m_wBurden)
  283. << 0xAEL
  284. << pcModel->m_UsedPages
  285. << 0xAFL
  286. << pcModel->m_TotalPages
  287. << WORD(0x0001)
  288. << WORD(0x0008)
  289. << 0x10L
  290. << pcModel->m_strDescription.c_str();
  291. pcAssesser->AddPacket(WORLD_SERVER, cmAssess,4);
  292. cMessage cmActionComplete;
  293. cmActionComplete << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID( ) << ++pcAssesser->m_dwF7B0Sequence << 0x01C7L << 0L;
  294. pcAssesser->AddPacket(WORLD_SERVER,cmActionComplete,4);
  295. }