stoneharry

Untitled

Aug 1st, 2013
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.06 KB | None | 0 0
  1. #include "StdAfx.h"
  2.  
  3. // Table format
  4. const char* gServerPlayedCreatureFormat = "uccccccccuuuuuuuuuuuuuu";
  5. // Table storage
  6. SERVER_DECL SQLStorage< ServerPlayedCharacter, HashMapStorageContainer<ServerPlayedCharacter> > ServerPlayedNpcStorage;
  7. stdext::hash_set<uint32> mirrorImagePacketHookSet;
  8.  
  9. static uint32 RaceDisplayMap[P_NUM_RACES * 2 + 2] =
  10. {
  11.     0U, 0U, 49U, 50U, 51U, 52U, 53U, 54U, 55U, 56U, 57U, 58U, 59U,
  12.     60U, 1563U, 1564U, 1478U, 1479U, 6894U, 6895U, 15476U, 15475U,
  13.     16125U, 16126U, 16981U, 16980U, 17402U, 17403U, 17576U,
  14.     17577U, 17578U, 17579U, 21685U, 21686U, 21780U,21780U,21963U,
  15.     21964U, 26316U, 26317U, 26871U, 26872U, 26873U, 26874U
  16. }; // maps the race index/gender in the DB to the actual display ID
  17.  
  18. void LoadServerPlayedNPCFromDB(TaskList& tl)
  19. {
  20.     tl.AddTask( new Task( new CallbackP2<SQLStorage< ServerPlayedCharacter, HashMapStorageContainer<ServerPlayedCharacter> >, const char *, const char *>(&ServerPlayedNpcStorage, &SQLStorage<ServerPlayedCharacter, HashMapStorageContainer<ServerPlayedCharacter> >::Load,  "server_played_character", gServerPlayedCreatureFormat) ) );
  21. }
  22.  
  23. void UnitLoadMiDisplayInfo(Unit* pUnit)
  24. {
  25.     ServerPlayedCharacter* infoSpc = ServerPlayedNpcStorage.LookupEntry(pUnit->GetEntry());
  26.     if (!infoSpc)
  27.         return;
  28.  
  29.     if (infoSpc->raceId > (uint8)P_NUM_RACES)
  30.     {
  31.         std::cout << "Server-Player NPC with entry ID " << infoSpc->entry
  32.                   << " used an invalid race id: " << infoSpc->raceId << std::endl;
  33.         infoSpc->raceId = 0;
  34.     }
  35.     infoSpc->gender &= 0x1;
  36.     pUnit->SetDisplayId( RaceDisplayMap[(infoSpc->raceId << 1) | infoSpc->gender] );
  37.     pUnit->setRace(infoSpc->raceId);
  38.     pUnit->setGender(infoSpc->gender);
  39.     mirrorImagePacketHookSet.insert(pUnit->GetEntry());
  40.     pUnit->SetUInt32Value(UNIT_FIELD_FLAGS_2, pUnit->GetUInt32Value(UNIT_FIELD_FLAGS_2) | UNIT_FLAG2_MIRROR_IMAGE);
  41. }
  42.  
  43. WorldPacket MirrorImagePacketHook(Unit* pUnit)
  44. {
  45.     ServerPlayedCharacter* infoSpc = ServerPlayedNpcStorage.LookupEntry(pUnit->GetEntry());
  46.     ARCEMU_ASSERT(infoSpc != 0);
  47.  
  48.     WorldPacket data(SMSG_MIRRORIMAGE_DATA, 68);
  49.     data << pUnit->GetGUID();
  50.     data << RaceDisplayMap[(infoSpc->raceId << 1) | infoSpc->gender];
  51.     data << infoSpc->raceId;
  52.     data << infoSpc->gender;
  53.     if (infoSpc->classId == 10 || infoSpc->classId > 11)
  54.     {
  55.         std::cout << "Server-Played NPC with entry ID " << infoSpc->entry
  56.                   << " used an invalid class id: " << infoSpc->classId << std::endl;
  57.         infoSpc->classId = 0;
  58.     }
  59.     data << infoSpc->classId;
  60.     data << infoSpc->skinId;
  61.     data << infoSpc->faceId;
  62.     data << infoSpc->hairStyleId;
  63.     data << infoSpc->hairColorId;
  64.     data << infoSpc->facialHairId;
  65.     data << static_cast<uint32>(0);
  66.  
  67.     for (uint8 i = 0; i < NUM_ITEM_SLOTS - 3; i++)
  68.     {
  69.         data << infoSpc->itemId[i];
  70.     }
  71.  
  72.     pUnit->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID, infoSpc->itemId[ITEM_SLOT_MAINHAND]);
  73.     pUnit->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 0x1, infoSpc->itemId[ITEM_SLOT_OFFHAND]);
  74.     pUnit->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 0x2, infoSpc->itemId[ITEM_SLOT_RANGED]);
  75.  
  76.     return data;
  77. }
  78.  
  79. void ServerPlayedNPCCleanup(void)
  80. {
  81.     ServerPlayedNpcStorage.Cleanup();
  82. }
Advertisement
Add Comment
Please, Sign In to add comment