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

cWorldObject.cpp 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 cWorldObject.cpp
  19. * World objects are defined as objects with which avatars can interact, but not pick up.
  20. * This class is referenced whenever a world object is created, used, or assessed.
  21. * Inherits from the cObject class.
  22. *
  23. * Author: Cubem0j0
  24. */
  25. #include "Object.h"
  26. #include "MasterServer.h"
  27. #include "WorldManager.h"
  28. #include "CommandParser.h"
  29. /***************
  30. * constructors
  31. **************/
  32. /**
  33. * Handles the creation of world objects (town signs, wells, etc).
  34. *
  35. * Called whenever a world object should be initialized.
  36. */
  37. cWorldObject::cWorldObject(WORD type, DWORD dwGUID, cLocation *pcLoc, char *szName, char *szDesc)
  38. {
  39. SetLocation(pcLoc);
  40. m_dwGUID = dwGUID;
  41. m_strName.assign( szName );
  42. m_strDescription.assign( szDesc );
  43. m_dwModel = type;
  44. m_fStatic = TRUE;
  45. }
  46. /**********
  47. * methods
  48. *********/
  49. /**
  50. * Handles the message sent for the creation of world objects in the world.
  51. *
  52. * This function is called whenever a world object should be created in the world for a client.
  53. *
  54. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  55. */
  56. cMessage cWorldObject::CreatePacket()
  57. {
  58. DWORD dwFlags;
  59. cMessage cmCreate;
  60. cmCreate << 0xF745L
  61. << m_dwGUID
  62. << BYTE( 0x11 )
  63. << BYTE( 0 )
  64. << BYTE( 0 )
  65. << BYTE( 0 );
  66. dwFlags = 0x00028001L;
  67. WORD wPortalMode = 0x0408;
  68. cmCreate << dwFlags;
  69. cmCreate << WORD( wPortalMode );
  70. cmCreate << WORD( 0x8005 ); // wUnknown_1
  71. // MASK 0x00020000 unknown
  72. cmCreate << 0x65L;
  73. // MASK 0x00008000 - Location
  74. if ( !m_fIsOwned )
  75. cmCreate.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  76. // MASK 0x00000001 ModelNumber
  77. DWORD dwModel = 0x02000000L + m_dwModel;
  78. cmCreate << dwModel;
  79. // SeaGreens
  80. WORD wNuminteracts = 0x0;
  81. WORD wNumbubbles = 0x0;
  82. WORD wNumJumps = 0x0;
  83. WORD wNumOverrides = 0x0;
  84. WORD wUnkFlag8 = 0x0;
  85. WORD wUnkFlag10 = 0x0;
  86. cmCreate << m_wPositionSequence
  87. << m_wNumAnims //wNuminteracts
  88. << wNumbubbles
  89. << wNumJumps
  90. << m_wNumPortals
  91. << m_wNumAnims
  92. << wNumOverrides
  93. << wUnkFlag8
  94. << m_wNumLogins
  95. << wUnkFlag10;
  96. switch(iObjectType)
  97. {
  98. case 0:
  99. {
  100. DWORD dwFlags2 = 0x00200018;
  101. cmCreate << dwFlags2 << m_strName.c_str( ) << WORD(m_wModel) << WORD(m_wIcon);
  102. DWORD dwObjectFlags1 = 0x80L;
  103. cmCreate << dwObjectFlags1;
  104. DWORD dwObjectFlags2 = 0x80L;
  105. cmCreate << dwObjectFlags2;
  106. // Masked against dwFlags2
  107. //Mask 0x0008 - Value
  108. cmCreate << DWORD(0x00);
  109. // Mask 0x0010 dwUnknown_v2
  110. cmCreate << DWORD(0x20);
  111. // Mask 0x00200000 - Burden
  112. cmCreate << WORD(0x0040);
  113. }
  114. break;
  115. case 1:
  116. {
  117. DWORD dwFlags2 = 0x00200018;
  118. cmCreate << dwFlags2 << m_strName.c_str( ) << WORD(m_wModel) << WORD(m_wIcon);
  119. DWORD dwObjectFlags1 = 0x80L;
  120. cmCreate << dwObjectFlags1;
  121. DWORD dwObjectFlags2 = 0x14L;
  122. cmCreate << dwObjectFlags2;
  123. // Masked against dwFlags2
  124. //Mask 0x0008 - Value
  125. cmCreate << DWORD(0x00);
  126. // Mask 0x0010 dwUnknown_v2
  127. cmCreate << DWORD(0x20);
  128. // Mask 0x00200000 - Burden
  129. cmCreate << WORD(0x0040);
  130. }
  131. break;
  132. case 2:
  133. {
  134. DWORD dwFlags2 = 0x00600038;
  135. cmCreate << dwFlags2 << m_strName.c_str( ) << WORD(m_wModel) << WORD(m_wIcon);
  136. DWORD dwObjectFlags1 = 0x00400000;
  137. cmCreate << dwObjectFlags1;
  138. DWORD dwObjectFlags2 = 0x14L;
  139. cmCreate << dwObjectFlags2;
  140. // Masked against dwFlags2
  141. //Mask 0x0008 - Value
  142. cmCreate << DWORD(0x00);
  143. // Mask 0x0010 dwUnknown_v2
  144. cmCreate << DWORD(0x20);
  145. // Mask 0x0020 Approach distance
  146. cmCreate << float(3.0);
  147. // Mask 0x00200000 - Burden
  148. cmCreate << WORD(0x0040);
  149. // Mask 0x00400000 - Spell
  150. cmCreate << WORD(0x049F);
  151. }
  152. break;
  153. default:
  154. {
  155. DWORD dwFlags2 = 0x00200018;
  156. cmCreate << dwFlags2 << m_strName.c_str( ) << WORD(m_wModel) << WORD(m_wIcon);
  157. DWORD dwObjectFlags1 = 0x80L;
  158. cmCreate << dwObjectFlags1;
  159. DWORD dwObjectFlags2 = 0x14L;
  160. cmCreate << dwObjectFlags2;
  161. // Masked against dwFlags2
  162. //Mask 0x0008 - Value
  163. cmCreate << DWORD(0x00);
  164. // Mask 0x0010 dwUnknown_v2
  165. cmCreate << DWORD(0x20);
  166. // Mask 0x00200000 - Burden
  167. cmCreate << WORD(0x0040);
  168. }
  169. break;
  170. }
  171. return cmCreate;
  172. }
  173. /**
  174. * Handles the actions of world objects.
  175. *
  176. * This function is called whenever a world object is used or should perform an action.
  177. */
  178. void cWorldObject::Action(cClient *who)
  179. {
  180. switch(iObjectType)
  181. {
  182. case 1:
  183. {
  184. break;
  185. }
  186. case 2:
  187. {
  188. int updated_stats;
  189. int change = who->m_pcAvatar->GetTotalStamina();
  190. int ret_amount;
  191. int iRand = rand();
  192. iRand = (4 % 8 );
  193. //Update Stamina
  194. cMessage cmEat = who->m_pcAvatar->UpdateStamina(iRand,updated_stats);
  195. who->AddPacket( WORLD_SERVER,cmEat,4);
  196. if ( updated_stats > change )
  197. ret_amount = 0;
  198. else
  199. ret_amount = iRand;
  200. cMessage cmCast;
  201. cmCast << 0xF750L << who->m_pcAvatar->GetGUID() << DWORD(0x80);
  202. cMessage cParticle = who->m_pcAvatar->Particle(34);
  203. cWorldManager::SendToAllInFocus( who->m_pcAvatar->m_Location, cParticle, 3 );
  204. cMasterServer::ServerMessage(ColorBlue,who,"%s casts Revitalize I on you restoring %d points of Stamina.",this->m_strName.c_str(),ret_amount);
  205. who->AddPacket(WORLD_SERVER,cmCast,3);
  206. //Action Complete
  207. cMessage cmActionComplete;
  208. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  209. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  210. break;
  211. }
  212. }
  213. }
  214. /**
  215. * Handles the assessment of world objects.
  216. *
  217. * This function is called whenever a world objects is assessed by a client.
  218. *
  219. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  220. */
  221. void cWorldObject::Assess(cClient *pcAssesser)
  222. {
  223. cMessage cmAssess;
  224. //Fill out basic header
  225. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L;
  226. cmAssess << m_dwGUID << 0x8L << 1L << WORD(0x01) << WORD(0x0) << WORD(0x10) << "This is a life stone. When you die, you resurrect here. SO DON'T DIE!!!";
  227. pcAssesser->AddPacket(WORLD_SERVER,cmAssess,4);
  228. }