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

cPortal.cpp 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 cPortal.cpp
  19. * Implements functionality for portals.
  20. *
  21. * This class is referenced whenever a portal is created, used, or assessed.
  22. * Inherits from the cObject class.
  23. */
  24. #include "Client.h"
  25. #include "MasterServer.h"
  26. #include "Object.h"
  27. #include "WorldManager.h"
  28. /***************
  29. * constructors
  30. **************/
  31. /**
  32. * Handles the creation of portals.
  33. *
  34. * Called whenever a portal object should be initialized.
  35. */
  36. cPortal::cPortal( DWORD dwGUID, DWORD dwColor, cLocation *Loc, cLocation *destLoc, char *szName, char *szDescription, DWORD dwLowerRestrict, DWORD dwHigherRestrict )
  37. {
  38. SetLocation(Loc);
  39. SetDestination(destLoc);
  40. m_dwGUID = dwGUID;
  41. m_strName.assign( szName );
  42. m_strDescription.assign( szDescription );
  43. m_dwLowerRestriction = dwLowerRestrict;
  44. m_dwHigherRestriction = dwHigherRestrict;
  45. m_fStatic = TRUE;
  46. m_wPortalMode = 3084; // Will add special case code later, for now all are Auto Use Portals
  47. // Object Flags appear to be Static
  48. m_dwObjectsFlag1 = 0x00010080;
  49. m_dwObjectsFlag2 = 0x00040014;
  50. switch(dwColor)
  51. {
  52. case 17:
  53. m_dwModel = 1490; // 0x05D2
  54. break;
  55. case 1:
  56. m_dwModel = 1491;
  57. break;
  58. case 4:
  59. m_dwModel = 1492;
  60. break;
  61. case 6:
  62. m_dwModel = 1493; // 0x05D5
  63. break;
  64. case 3:
  65. m_dwModel = 1494;
  66. break;
  67. case 5:
  68. m_dwModel = 435; // 0x01B3
  69. break;
  70. case 2:
  71. m_dwModel = 1780;
  72. break;
  73. default:
  74. m_dwModel = 435;
  75. }
  76. m_wModel = 1032;
  77. m_wIcon = 4203;
  78. m_wAnimConfig = 0x3;
  79. }
  80. /**********
  81. * methods
  82. *********/
  83. /**
  84. * Handles the message sent for the creation of portals in the world.
  85. *
  86. * This function is called whenever a portal should be created in the world for a client.
  87. *
  88. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  89. */
  90. cMessage cPortal::CreatePacket()
  91. {
  92. cMessage cmCreate;
  93. unsigned char bUnknown[] = {
  94. 0x00, 0x00, // Animation type 0 - 1
  95. 0x3D, 0x00, // Starting Stance 2 - 3
  96. 0x00, 0xF0, 0x99, 0x02, // Unknown - Flag 0x00000002 in it 4 - 7
  97. };
  98. cmCreate << 0xF745L
  99. << m_dwGUID
  100. << BYTE( 0x11 )
  101. << BYTE( 0 ) // Special Portals Might have 1
  102. << BYTE( 0 )
  103. << BYTE( 0 );
  104. //If Portal has a Palette Change will be 0xFF(-255)
  105. // cmCreate << WORD(0xFF);
  106. DWORD dwFlags = 0x00018003L; // Appears to be fixed for all Portal Types
  107. cmCreate << dwFlags;
  108. cmCreate << WORD( m_wPortalMode );
  109. // This changes (so far only 2 variations occur)
  110. // 0x3076 - House Portals (Click to Use?)
  111. // 0x3084 - Normal Portals
  112. cmCreate << WORD( 0x0000 ); // wUnknown1 Always 0x0000
  113. // MASK 0x00010000 unknown Bytes - Starting Animation
  114. cmCreate << 0x08L;
  115. cmCreate.pasteData(bUnknown,sizeof(bUnknown));
  116. cmCreate << 0x0L; // wUnknown_1 Always 0x0000
  117. // MASK 0x00008000 - Location
  118. if ( !m_fIsOwned )
  119. cmCreate.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  120. // MASK 0x00000002 Animation Set
  121. DWORD dwAnimC = 0x09000000L + m_wAnimConfig;
  122. // Always 0x9000003 Will still do it this way incase we find a variant
  123. cmCreate << dwAnimC;
  124. // MASK 0x00000001 ModelNumber
  125. DWORD dwModel = 0x02000000L + m_dwModel; // Set on object create based on Database info
  126. cmCreate << dwModel;
  127. // SeaGreens
  128. WORD wNuminteracts = 0x0;
  129. WORD wNumbubbles = 0x0;
  130. WORD wNumJumps = 0x0;
  131. WORD wNumOverrides = 0x0;
  132. WORD wUnkFlag8 = 0x0;
  133. WORD wUnkFlag10 = 0x0;
  134. cmCreate << WORD(70) // m_wPositionSequence
  135. << wNuminteracts
  136. << wNumbubbles
  137. << wNumJumps
  138. << WORD(0x0000) // m_wNumPortals
  139. << WORD(0x0001) // m_wNumAnims
  140. << wNumOverrides
  141. << wUnkFlag8
  142. << m_wNumLogins
  143. << wUnkFlag10;
  144. DWORD dwFlags2 = 0x00800030;
  145. // This changes (so far only 2 variations occur)
  146. // 0x02800030 for House Portals
  147. // 0x00800030 for Normal Portals
  148. cmCreate << dwFlags2
  149. << m_strName.c_str( )
  150. << WORD(m_wModel) // Varies based on Portal Color
  151. << WORD(0x106B); // Icon is static value all portals
  152. //DWORD dwObjectFlags1 = 0x80L;
  153. cmCreate << m_dwObjectsFlag1;
  154. //DWORD dwObjectFlags2 = 0x1014L;
  155. cmCreate << m_dwObjectsFlag2 ;
  156. // Masked against dwFlags2
  157. // Mask 0x0010 dwUnknown_v2
  158. // Always 32
  159. cmCreate << DWORD(0x20);
  160. // Mask 0x0020 - unknown_v3 Approach Distance
  161. cmCreate << float(-0.1);
  162. // Mask 0x00800000 - unknown_v6
  163. // Always 4
  164. cmCreate << BYTE(0x04);
  165. this->item_type = 1000;
  166. return cmCreate;
  167. }
  168. /**
  169. * Handles the actions of portal objects.
  170. *
  171. * This function is called whenever a portal is used or should perform an action.
  172. */
  173. void cPortal::Action(cClient *who)
  174. {
  175. if(m_dwHigherRestriction !=0 && who->m_pcAvatar->m_cStats.m_dwLevel > m_dwHigherRestriction )
  176. {
  177. cMasterServer::ServerMessage(ColorBlue,NULL,"You are to powerful to use this portal!");
  178. }
  179. else if (who->m_pcAvatar->m_cStats.m_dwLevel < m_dwLowerRestriction)
  180. {
  181. cMasterServer::ServerMessage(ColorBlue,NULL,"You are to weak to use this portal!");
  182. }
  183. else
  184. {
  185. cWorldManager::TeleportAvatar( who, m_cDestination );
  186. }
  187. cMessage cmActionComplete;
  188. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  189. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  190. }
  191. /**
  192. * Handles the assessment of portal objects.
  193. *
  194. * This function is called whenever a portal is assessed by a client.
  195. *
  196. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  197. */
  198. void cPortal::Assess(cClient *pcAssesser)
  199. {
  200. cMessage cmAssess;
  201. DWORD flags = 0x00000009;
  202. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L << m_dwGUID;
  203. //Cubem0j0: Check for level restrictions on this portal
  204. if( m_dwLowerRestriction > 0)
  205. {
  206. cmAssess << flags
  207. << 0x01L //Success = 0x01, Failure = 0x00
  208. << WORD(0x0003) //Total number of DWORDS
  209. << WORD(0x0010) //Unknown
  210. << 0x56L //Min Level
  211. << DWORD(this->m_dwLowerRestriction)
  212. << 0x57L //Max Level
  213. << DWORD(this->m_dwHigherRestriction)
  214. << 0x6FL //Portal Restriction flags
  215. << 0x01L // ?
  216. << WORD(0x0002) //Count (as above) total number of DWORDS
  217. << WORD(0x0008) //Unknown
  218. << 0x10L //Long Description (for portals we use the name)
  219. << this->m_strName.c_str()
  220. << 0x26L //Destination:
  221. << this->m_strDescription.c_str();
  222. }
  223. else
  224. {
  225. cmAssess << flags
  226. << 0x01L //Success = 0x01, Failure = 0x00
  227. << WORD(0x0001) //Total number of DWORDS
  228. << WORD(0x0010) //Unknown
  229. << 0x6FL //Portal Restriction flags
  230. << 0x01L // ?
  231. << WORD(0x0002) //Count (as above) total number of DWORDS
  232. << WORD(0x0008) //Unknown
  233. << 0x10L //Long Description (for portals we use the name)
  234. << this->m_strName.c_str()
  235. << 0x26L //Destination:
  236. << this->m_strDescription.c_str();
  237. }
  238. pcAssesser->AddPacket(WORLD_SERVER, cmAssess,4);
  239. cMessage cmActionComplete;
  240. cmActionComplete << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID( ) << ++pcAssesser->m_dwF7B0Sequence << 0x01C7L << 0L;
  241. pcAssesser->AddPacket(WORLD_SERVER,cmActionComplete,4);
  242. }