Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Object::BuildValuesUpdate(uint8 updatetype, ByteBuffer * data, UpdateMask *updateMask, Player *target) const
- {
- if (!target)
- return;
- bool IsActivateToQuest = false;
- if (updatetype == UPDATETYPE_CREATE_OBJECT || updatetype == UPDATETYPE_CREATE_OBJECT2)
- {
- if (isType(TYPEMASK_GAMEOBJECT) && !((GameObject*)this)->IsTransport())
- {
- if (((GameObject*)this)->ActivateToQuest(target) || target->isGameMaster())
- IsActivateToQuest = true;
- updateMask->SetBit(GAMEOBJECT_DYN_FLAGS);
- if (GetUInt32Value(GAMEOBJECT_ARTKIT))
- updateMask->SetBit(GAMEOBJECT_ARTKIT);
- }
- }
- else //case UPDATETYPE_VALUES
- {
- if (isType(TYPEMASK_GAMEOBJECT) && !((GameObject*)this)->IsTransport())
- {
- if (((GameObject*)this)->ActivateToQuest(target) || target->isGameMaster())
- {
- IsActivateToQuest = true;
- }
- updateMask->SetBit(GAMEOBJECT_DYN_FLAGS);
- updateMask->SetBit(GAMEOBJECT_ANIMPROGRESS);
- }
- }
- ASSERT(updateMask && updateMask->GetCount() == m_valuesCount);
- *data << (uint8)updateMask->GetBlockCount();
- data->append(updateMask->GetMask(), updateMask->GetLength());
- // 2 specialized loops for speed optimization in non-unit case
- if (isType(TYPEMASK_UNIT)) // unit (creature/player) case
- {
- for (uint16 index = 0; index < m_valuesCount; index ++)
- {
- if (updateMask->GetBit(index))
- {
- // remove custom flag before send
- if (index == UNIT_NPC_FLAGS)
- *data << uint32(m_uint32Values[ index ] & ~(UNIT_NPC_FLAG_GUARD | UNIT_NPC_FLAG_OUTDOORPVP));
- // FIXME: Some values at server stored in float format but must be sent to client in uint32 format
- else if (index >= UNIT_FIELD_BASEATTACKTIME && index <= UNIT_FIELD_RANGEDATTACKTIME)
- {
- // convert from float to uint32 and send
- *data << uint32(m_floatValues[ index ] < 0 ? 0 : m_floatValues[ index ]);
- }
- // there are some float values which may be negative or can't get negative due to other checks
- else if (index >= UNIT_FIELD_NEGSTAT0 && index <= UNIT_FIELD_NEGSTAT4 ||
- index >= UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE && index <= (UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE + 6) ||
- index >= UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE && index <= (UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE + 6) ||
- index >= UNIT_FIELD_POSSTAT0 && index <= UNIT_FIELD_POSSTAT4)
- {
- *data << uint32(m_floatValues[ index ]);
- }
- // Gamemasters should be always able to select units - remove not selectable flag
- else if (index == UNIT_FIELD_FLAGS && target->isGameMaster())
- {
- *data << (m_uint32Values[ index ] & ~UNIT_FLAG_NOT_SELECTABLE);
- }
- // use modelid_a if not gm, _h if gm for CREATURE_FLAG_EXTRA_TRIGGER creatures
- else if (index == UNIT_FIELD_DISPLAYID && GetTypeId() == TYPEID_UNIT)
- {
- const CreatureInfo* cinfo = ((Creature*)this)->GetCreatureInfo();
- if (cinfo->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER)
- {
- if (target->isGameMaster())
- {
- if (cinfo->Modelid_A2)
- *data << cinfo->Modelid_A1;
- else
- *data << 17519; // world invisible trigger's model
- }
- else
- {
- if (cinfo->Modelid_A2)
- *data << cinfo->Modelid_A2;
- else
- *data << 11686; // world invisible trigger's model
- }
- }
- else
- *data << m_uint32Values[ index ];
- }
- // hide lootable animation for unallowed players
- else if (index == UNIT_DYNAMIC_FLAGS && GetTypeId() == TYPEID_UNIT)
- {
- if (!target->isAllowedToLoot((Creature*)this))
- *data << (m_uint32Values[ index ] & ~UNIT_DYNFLAG_LOOTABLE);
- else
- *data << (m_uint32Values[ index ] & ~UNIT_DYNFLAG_OTHER_TAGGER);
- }
- // FG: pretend that OTHER players in own group are friendly ("blue")
- else if (index == UNIT_FIELD_BYTES_2 || index == UNIT_FIELD_FACTIONTEMPLATE)
- {
- bool ch = false;
- if (target->GetTypeId() == TYPEID_PLAYER && GetTypeId() == TYPEID_PLAYER && target != this)
- {
- if (target->IsInSameGroupWith((Player*)this) || target->IsInSameRaidWith((Player*)this))
- {
- if (index == UNIT_FIELD_BYTES_2)
- {
- DEBUG_LOG("-- VALUES_UPDATE: Sending '%s' the blue-group-fix from '%s' (flag)", target->GetName(), ((Player*)this)->GetName());
- *data << (m_uint32Values[ index ] & ((UNIT_BYTE2_FLAG_SANCTUARY | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5) << 8)); // this flag is at uint8 offset 1 !!
- ch = true;
- }
- else if (index == UNIT_FIELD_FACTIONTEMPLATE)
- {
- FactionTemplateEntry const *ft1, *ft2;
- ft1 = ((Player*)this)->getFactionTemplateEntry();
- ft2 = ((Player*)target)->getFactionTemplateEntry();
- if (ft1 && ft2 && !ft1->IsFriendlyTo(*ft2))
- {
- uint32 faction = ((Player*)target)->getFaction(); // pretend that all other HOSTILE players have own faction, to allow follow, heal, rezz (trade wont work)
- DEBUG_LOG("-- VALUES_UPDATE: Sending '%s' the blue-group-fix from '%s' (faction %u)", target->GetName(), ((Player*)this)->GetName(), faction);
- *data << uint32(faction);
- ch = true;
- }
- }
- }
- }
- if (!ch)
- *data << m_uint32Values[ index ];
- }
- else
- {
- // send in current format (float as float, uint32 as uint32)
- *data << m_uint32Values[ index ];
- }
- }
- }
- }
- else if (isType(TYPEMASK_GAMEOBJECT)) // gameobject case
- {
- for (uint16 index = 0; index < m_valuesCount; index ++)
- {
- if (updateMask->GetBit(index))
- {
- // send in current format (float as float, uint32 as uint32)
- if (index == GAMEOBJECT_DYN_FLAGS)
- {
- if (IsActivateToQuest)
- {
- switch (((GameObject*)this)->GetGoType())
- {
- case GAMEOBJECT_TYPE_CHEST:
- case GAMEOBJECT_TYPE_GOOBER:
- *data << uint16(GO_DYNFLAG_LO_ACTIVATE | GO_DYNFLAG_LO_SPARKLE);
- *data << uint16(-1);
- break;
- default:
- *data << uint32(0); // unknown. not happen.
- break;
- }
- }
- else
- *data << uint32(0); // disable quest object
- }
- else
- *data << m_uint32Values[ index ]; // other cases
- }
- }
- }
- else // other objects case (no special index checks)
- {
- for (uint16 index = 0; index < m_valuesCount; index ++)
- {
- if (updateMask->GetBit(index))
- {
- // send in current format (float as float, uint32 as uint32)
- *data << m_uint32Values[ index ];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment