Guest User

Untitled

a guest
Jul 16th, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.73 KB | None | 0 0
  1. void Object::BuildValuesUpdate(uint8 updatetype, ByteBuffer * data, UpdateMask *updateMask, Player *target) const
  2. {
  3.     if (!target)
  4.         return;
  5.  
  6.     bool IsActivateToQuest = false;
  7.     if (updatetype == UPDATETYPE_CREATE_OBJECT || updatetype == UPDATETYPE_CREATE_OBJECT2)
  8.     {
  9.         if (isType(TYPEMASK_GAMEOBJECT) && !((GameObject*)this)->IsTransport())
  10.         {
  11.             if (((GameObject*)this)->ActivateToQuest(target) || target->isGameMaster())
  12.                 IsActivateToQuest = true;
  13.  
  14.             updateMask->SetBit(GAMEOBJECT_DYN_FLAGS);
  15.  
  16.             if (GetUInt32Value(GAMEOBJECT_ARTKIT))
  17.                 updateMask->SetBit(GAMEOBJECT_ARTKIT);
  18.         }
  19.     }
  20.     else                                                    //case UPDATETYPE_VALUES
  21.     {
  22.         if (isType(TYPEMASK_GAMEOBJECT) && !((GameObject*)this)->IsTransport())
  23.         {
  24.             if (((GameObject*)this)->ActivateToQuest(target) || target->isGameMaster())
  25.             {
  26.                 IsActivateToQuest = true;
  27.             }
  28.             updateMask->SetBit(GAMEOBJECT_DYN_FLAGS);
  29.             updateMask->SetBit(GAMEOBJECT_ANIMPROGRESS);
  30.         }
  31.     }
  32.  
  33.     ASSERT(updateMask && updateMask->GetCount() == m_valuesCount);
  34.  
  35.     *data << (uint8)updateMask->GetBlockCount();
  36.     data->append(updateMask->GetMask(), updateMask->GetLength());
  37.  
  38.     // 2 specialized loops for speed optimization in non-unit case
  39.     if (isType(TYPEMASK_UNIT))                               // unit (creature/player) case
  40.     {
  41.         for (uint16 index = 0; index < m_valuesCount; index ++)
  42.         {
  43.             if (updateMask->GetBit(index))
  44.             {
  45.                 // remove custom flag before send
  46.                 if (index == UNIT_NPC_FLAGS)
  47.                     *data << uint32(m_uint32Values[ index ] & ~(UNIT_NPC_FLAG_GUARD | UNIT_NPC_FLAG_OUTDOORPVP));
  48.                 // FIXME: Some values at server stored in float format but must be sent to client in uint32 format
  49.                 else if (index >= UNIT_FIELD_BASEATTACKTIME && index <= UNIT_FIELD_RANGEDATTACKTIME)
  50.                 {
  51.                     // convert from float to uint32 and send
  52.                     *data << uint32(m_floatValues[ index ] < 0 ? 0 : m_floatValues[ index ]);
  53.                 }
  54.                 // there are some float values which may be negative or can't get negative due to other checks
  55.                 else if (index >= UNIT_FIELD_NEGSTAT0   && index <= UNIT_FIELD_NEGSTAT4 ||
  56.                     index >= UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE  && index <= (UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE + 6) ||
  57.                     index >= UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE  && index <= (UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE + 6) ||
  58.                     index >= UNIT_FIELD_POSSTAT0   && index <= UNIT_FIELD_POSSTAT4)
  59.                 {
  60.                     *data << uint32(m_floatValues[ index ]);
  61.                 }
  62.                 // Gamemasters should be always able to select units - remove not selectable flag
  63.                 else if (index == UNIT_FIELD_FLAGS && target->isGameMaster())
  64.                 {
  65.                     *data << (m_uint32Values[ index ] & ~UNIT_FLAG_NOT_SELECTABLE);
  66.                 }
  67.                 // use modelid_a if not gm, _h if gm for CREATURE_FLAG_EXTRA_TRIGGER creatures
  68.                 else if (index == UNIT_FIELD_DISPLAYID && GetTypeId() == TYPEID_UNIT)
  69.                 {
  70.                     const CreatureInfo* cinfo = ((Creature*)this)->GetCreatureInfo();
  71.                     if (cinfo->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER)
  72.                     {
  73.                         if (target->isGameMaster())
  74.                         {
  75.                             if (cinfo->Modelid_A2)
  76.                                 *data << cinfo->Modelid_A1;
  77.                             else
  78.                                 *data << 17519; // world invisible trigger's model
  79.                         }
  80.                         else
  81.                         {
  82.                             if (cinfo->Modelid_A2)
  83.                                 *data << cinfo->Modelid_A2;
  84.                             else
  85.                                 *data << 11686; // world invisible trigger's model
  86.                         }
  87.                     }
  88.                     else
  89.                         *data << m_uint32Values[ index ];
  90.                 }
  91.                 // hide lootable animation for unallowed players
  92.                 else if (index == UNIT_DYNAMIC_FLAGS && GetTypeId() == TYPEID_UNIT)
  93.                 {
  94.                     if (!target->isAllowedToLoot((Creature*)this))
  95.                         *data << (m_uint32Values[ index ] & ~UNIT_DYNFLAG_LOOTABLE);
  96.                     else
  97.                         *data << (m_uint32Values[ index ] & ~UNIT_DYNFLAG_OTHER_TAGGER);
  98.                 }
  99.                 // FG: pretend that OTHER players in own group are friendly ("blue")
  100.                 else if (index == UNIT_FIELD_BYTES_2 || index == UNIT_FIELD_FACTIONTEMPLATE)
  101.                 {
  102.                 bool ch = false;
  103.                     if (target->GetTypeId() == TYPEID_PLAYER && GetTypeId() == TYPEID_PLAYER && target != this)
  104.                     {
  105.                     if (target->IsInSameGroupWith((Player*)this) || target->IsInSameRaidWith((Player*)this))
  106.                     {
  107.                         if (index == UNIT_FIELD_BYTES_2)
  108.                         {
  109.                             DEBUG_LOG("-- VALUES_UPDATE: Sending '%s' the blue-group-fix from '%s' (flag)", target->GetName(), ((Player*)this)->GetName());
  110.                             *data << (m_uint32Values[ index ] & ((UNIT_BYTE2_FLAG_SANCTUARY | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5) << 8)); // this flag is at uint8 offset 1 !!
  111.  
  112.                             ch = true;
  113.                         }
  114.                         else if (index == UNIT_FIELD_FACTIONTEMPLATE)
  115.                         {
  116.                             FactionTemplateEntry const *ft1, *ft2;
  117.                             ft1 = ((Player*)this)->getFactionTemplateEntry();
  118.                             ft2 = ((Player*)target)->getFactionTemplateEntry();
  119.                             if (ft1 && ft2 && !ft1->IsFriendlyTo(*ft2))
  120.                             {
  121.                                 uint32 faction = ((Player*)target)->getFaction(); // pretend that all other HOSTILE players have own faction, to allow follow, heal, rezz (trade wont work)
  122.                                 DEBUG_LOG("-- VALUES_UPDATE: Sending '%s' the blue-group-fix from '%s' (faction %u)", target->GetName(), ((Player*)this)->GetName(), faction);
  123.                                 *data << uint32(faction);
  124.                                 ch = true;
  125.                             }
  126.                         }
  127.                     }
  128.                     }
  129.                     if (!ch)
  130.                         *data << m_uint32Values[ index ];
  131.                 }
  132.                 else
  133.                 {
  134.                     // send in current format (float as float, uint32 as uint32)
  135.                     *data << m_uint32Values[ index ];
  136.                 }
  137.             }
  138.         }
  139.     }
  140.     else if (isType(TYPEMASK_GAMEOBJECT))                    // gameobject case
  141.     {
  142.         for (uint16 index = 0; index < m_valuesCount; index ++)
  143.         {
  144.             if (updateMask->GetBit(index))
  145.             {
  146.                 // send in current format (float as float, uint32 as uint32)
  147.                 if (index == GAMEOBJECT_DYN_FLAGS)
  148.                 {
  149.                     if (IsActivateToQuest)
  150.                     {
  151.                         switch (((GameObject*)this)->GetGoType())
  152.                         {
  153.                             case GAMEOBJECT_TYPE_CHEST:
  154.                             case GAMEOBJECT_TYPE_GOOBER:
  155.                                 *data << uint16(GO_DYNFLAG_LO_ACTIVATE | GO_DYNFLAG_LO_SPARKLE);
  156.                                 *data << uint16(-1);
  157.                                 break;
  158.                             default:
  159.                                 *data << uint32(0);         // unknown. not happen.
  160.                                 break;
  161.                         }
  162.                     }
  163.                     else
  164.                         *data << uint32(0);                 // disable quest object
  165.                 }
  166.                 else
  167.                     *data << m_uint32Values[ index ];       // other cases
  168.             }
  169.         }
  170.     }
  171.     else                                                    // other objects case (no special index checks)
  172.     {
  173.         for (uint16 index = 0; index < m_valuesCount; index ++)
  174.         {
  175.             if (updateMask->GetBit(index))
  176.             {
  177.                 // send in current format (float as float, uint32 as uint32)
  178.                 *data << m_uint32Values[ index ];
  179.             }
  180.         }
  181.     }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment