bool Bag::Create(ObjectGuid::LowType guidlow, uint32 itemid, Player const* owner) { ItemTemplate const* itemProto = sObjectMgr->GetItemTemplate(itemid); if (!itemProto || itemProto->ContainerSlots > MAX_BAG_SIZE) return false; Object::_Create(guidlow, 0, HighGuid::Container); SetEntry(itemid); SetObjectScale(1.0f); if (owner) { SetGuidValue(ITEM_FIELD_OWNER, owner->GetGUID()); SetGuidValue(ITEM_FIELD_CONTAINED, owner->GetGUID()); } SetUInt32Value(ITEM_FIELD_MAXDURABILITY, itemProto->MaxDurability); SetUInt32Value(ITEM_FIELD_DURABILITY, itemProto->MaxDurability); SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1); // Setting the number of Slots the Container has SetUInt32Value(CONTAINER_FIELD_NUM_SLOTS, itemProto->ContainerSlots); // Cleaning 20 slots for (uint8 i = 0; i < MAX_BAG_SIZE; ++i) { SetGuidValue(CONTAINER_FIELD_SLOT_1 + (i*2), ObjectGuid::Empty); m_bagslot[i] = nullptr; } return true; }
bool Item::Create(uint32 guidlow, uint32 itemid, Player const* owner) { Object::_Create(guidlow, 0, HIGHGUID_ITEM); SetEntry(itemid); SetObjectScale(DEFAULT_OBJECT_SCALE); SetGuidValue(ITEM_FIELD_OWNER, owner ? owner->GetObjectGuid() : ObjectGuid()); SetGuidValue(ITEM_FIELD_CONTAINED, ObjectGuid()); ItemPrototype const* itemProto = ObjectMgr::GetItemPrototype(itemid); if (!itemProto) return false; SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1); SetUInt32Value(ITEM_FIELD_MAXDURABILITY, itemProto->MaxDurability); SetUInt32Value(ITEM_FIELD_DURABILITY, itemProto->MaxDurability); for (int i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) SetSpellCharges(i,itemProto->Spells[i].SpellCharges); SetUInt32Value(ITEM_FIELD_DURATION, itemProto->Duration); return true; }
bool Item::Create(uint32 guidlow, uint32 itemid, Player const* owner) { Object::_Create(guidlow, 0, HIGHGUID_ITEM); SetEntry(itemid); SetObjectScale(1.0f); if (owner) { SetGuidValue(ITEM_FIELD_OWNER, owner->GetGUID()); SetGuidValue(ITEM_FIELD_CONTAINED, owner->GetGUID()); } ItemTemplate const* itemProto = sObjectMgr->GetItemTemplate(itemid); if (!itemProto) return false; SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1); SetUInt32Value(ITEM_FIELD_MAXDURABILITY, itemProto->MaxDurability); SetUInt32Value(ITEM_FIELD_DURABILITY, itemProto->MaxDurability); for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) SetSpellCharges(i, itemProto->Spells[i].SpellCharges); SetUInt32Value(ITEM_FIELD_DURATION, itemProto->Duration); SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, 0); return true; }
bool Bag::Create(uint32 guidlow, uint32 itemid, Player const* owner) { ItemPrototype const* itemProto = ObjectMgr::GetItemPrototype(itemid); if (!itemProto || itemProto->ContainerSlots > MAX_BAG_SIZE) return false; Object::_Create(guidlow, 0, HIGHGUID_CONTAINER); SetEntry(itemid); SetObjectScale(DEFAULT_OBJECT_SCALE); SetGuidValue(ITEM_FIELD_OWNER, owner ? owner->GetObjectGuid() : ObjectGuid()); SetGuidValue(ITEM_FIELD_CONTAINED, owner ? owner->GetObjectGuid() : ObjectGuid()); SetUInt32Value(ITEM_FIELD_MAXDURABILITY, itemProto->MaxDurability); SetUInt32Value(ITEM_FIELD_DURABILITY, itemProto->MaxDurability); SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1); // Setting the number of Slots the Container has SetUInt32Value(CONTAINER_FIELD_NUM_SLOTS, itemProto->ContainerSlots); // Cleaning 20 slots for (uint8 i = 0; i < MAX_BAG_SIZE; ++i) { SetGuidValue(CONTAINER_FIELD_SLOT_1 + (i * 2), ObjectGuid()); m_bagslot[i] = NULL; } return true; }
void FGuidStructCustomization::HandleGuidActionClicked( EPropertyEditorGuidActions::Type Action ) { if (Action == EPropertyEditorGuidActions::Generate) { SetGuidValue(FGuid::NewGuid()); } else if (Action == EPropertyEditorGuidActions::Invalidate) { SetGuidValue(FGuid()); } }
bool Corpse::Create(ObjectGuid::LowType guidlow, Player* owner) { ASSERT(owner); Relocate(owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ(), owner->GetOrientation()); if (!IsPositionValid()) { TC_LOG_ERROR("entities.player", "Corpse (guidlow " UI64FMTD ", owner %s) not created. Suggested coordinates isn't valid (X: %f Y: %f)", guidlow, owner->GetName().c_str(), owner->GetPositionX(), owner->GetPositionY()); return false; } //we need to assign owner's map for corpse //in other way we will get a crash in Corpse::SaveToDB() SetMap(owner->GetMap()); Object::_Create(ObjectGuid::Create<HighGuid::Corpse>(GetMapId(), 0, guidlow)); SetPhaseMask(owner->GetPhaseMask(), false); SetObjectScale(1); SetGuidValue(CORPSE_FIELD_OWNER, owner->GetGUID()); _gridCoord = Trinity::ComputeGridCoord(GetPositionX(), GetPositionY()); CopyPhaseFrom(owner); return true; }
bool Corpse::Create(uint32 guidlow, Player* owner) { ASSERT(owner); Relocate(owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ(), owner->GetOrientation()); if (!IsPositionValid()) { TC_LOG_ERROR("entities.player", "Corpse (guidlow %d, owner %s) not created. Suggested coordinates isn't valid (X: %f Y: %f)", guidlow, owner->GetName().c_str(), owner->GetPositionX(), owner->GetPositionY()); return false; } //we need to assign owner's map for corpse //in other way we will get a crash in Corpse::SaveToDB() SetMap(owner->GetMap()); WorldObject::_Create(guidlow, HIGHGUID_CORPSE, owner->GetPhaseMask()); SetObjectScale(1); SetGuidValue(CORPSE_FIELD_OWNER, owner->GetGUID()); _gridCoord = Tournament::ComputeGridCoord(GetPositionX(), GetPositionY()); return true; }
bool Corpse::Create(uint32 guidlow, Player* owner) { MANGOS_ASSERT(owner); WorldObject::_Create(guidlow, HIGHGUID_CORPSE); Relocate(owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ(), owner->GetOrientation()); // we need to assign owner's map for corpse // in other way we will get a crash in Corpse::SaveToDB() SetMap(owner->GetMap()); if (!IsPositionValid()) { sLog.outError("Corpse (guidlow %d, owner %s) not created. Suggested coordinates isn't valid (X: %f Y: %f)", guidlow, owner->GetName(), owner->GetPositionX(), owner->GetPositionY()); return false; } SetObjectScale(DEFAULT_OBJECT_SCALE); SetFloatValue(CORPSE_FIELD_POS_X, GetPositionX()); SetFloatValue(CORPSE_FIELD_POS_Y, GetPositionY()); SetFloatValue(CORPSE_FIELD_POS_Z, GetPositionZ()); SetFloatValue(CORPSE_FIELD_FACING, GetOrientation()); SetGuidValue(CORPSE_FIELD_OWNER, owner->GetObjectGuid()); m_grid = MaNGOS::ComputeGridPair(GetPositionX(), GetPositionY()); return true; }
bool AreaTrigger::CreateAreaTrigger(uint32 guidlow, uint32 triggerEntry, Unit* caster, SpellInfo const* spell, Position const& pos, float radius, uint32 duration) { SetMap(caster->GetMap()); Relocate(pos); if (!IsPositionValid()) { sLog->outError("misc", "AreaTrigger (spell %u) not created. Invalid coordinates (X: %f Y: %f)", spell->Id, GetPositionX(), GetPositionY()); return false; } WorldObject::_Create(guidlow, HIGHGUID_AREATRIGGER, caster->GetPhaseMask()); SetEntry(triggerEntry); SetDuration(duration ? duration : spell->GetDuration()); SetObjectScale(1); SetGuidValue(AREATRIGGER_FIELD_CASTER, caster->GetGUID128()); SetUInt32Value(AREATRIGGER_FIELD_SPELL_ID, spell->Id); SetUInt32Value(AREATRIGGER_FIELD_SPELL_VISUAL_ID, spell->SpellVisual[0]); SetUInt32Value(AREATRIGGER_FIELD_DURATION, spell->GetDuration()); SetFloatValue(AREATRIGGER_FIELD_EXPLICIT_SCALE, 1.f); _radius = radius; if (!GetMap()->AddToMap(this)) return false; return true; }
bool Corpse::Create(ObjectGuid::LowType guidlow, Player* owner) { ASSERT(owner); Relocate(owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ(), owner->GetOrientation()); if (!IsPositionValid()) { TC_LOG_ERROR("entities.player", "Corpse (guidlow " UI64FMTD ", owner %s) not created. Suggested coordinates isn't valid (X: %f Y: %f)", guidlow, owner->GetName().c_str(), owner->GetPositionX(), owner->GetPositionY()); return false; } Object::_Create(ObjectGuid::Create<HighGuid::Corpse>(GetMapId(), 0, guidlow)); SetPhaseMask(owner->GetPhaseMask(), false); SetObjectScale(1.0f); SetGuidValue(CORPSE_FIELD_OWNER, owner->GetGUID()); _cellCoord = Trinity::ComputeCellCoord(GetPositionX(), GetPositionY()); CopyPhaseFrom(owner); return true; }
bool DynamicObject::Create(uint32 guidlow, Unit* caster, uint32 spellId, SpellEffectIndex effIndex, float x, float y, float z, int32 duration, float radius, DynamicObjectType type) { WorldObject::_Create(ObjectGuid(HIGHGUID_DYNAMICOBJECT, guidlow), caster->GetPhaseMask()); Relocate(WorldLocation(caster->GetMapId(), x, y, z, 0.0f, caster->GetPhaseMask(), caster->GetInstanceId())); SetMap(caster->GetMap()); if (!IsPositionValid()) { sLog.outError("DynamicObject (spell %u eff %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)", spellId, effIndex, GetPositionX(), GetPositionY()); return false; } SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId); if (!spellProto) { sLog.outError("DynamicObject (spell %u) not created. Spell not exist!", spellId); return false; } SetEntry(spellId); SetObjectScale(DEFAULT_OBJECT_SCALE); if (type == DYNAMIC_OBJECT_RAID_MARKER) { MANGOS_ASSERT(caster->GetTypeId() == TYPEID_PLAYER && ((Player*)caster)->GetGroup() && "DYNAMIC_OBJECT_RAID_MARKER must only be casted by players and that are in group."); SetGuidValue(DYNAMICOBJECT_CASTER, ((Player*)caster)->GetGroup()->GetObjectGuid()); } else SetGuidValue(DYNAMICOBJECT_CASTER, caster->GetObjectGuid()); SetUInt32Value(DYNAMICOBJECT_BYTES, spellProto->GetSpellVisual() | (type << 28)); SetUInt32Value(DYNAMICOBJECT_SPELLID, spellId); SetFloatValue(DYNAMICOBJECT_RADIUS, radius); SetUInt32Value(DYNAMICOBJECT_CASTTIME, WorldTimer::getMSTime()); // new 2.4.0 m_aliveDuration = duration; m_radius = radius; m_effIndex = effIndex; m_spellId = spellId; m_positive = IsPositiveEffect(spellProto, m_effIndex); return true; }
void FGuidStructCustomization::HandleTextBoxTextCommited( const FText& NewText, ETextCommit::Type CommitInfo ) { FGuid ParsedGuid; if (FGuid::Parse(NewText.ToString(), ParsedGuid)) { SetGuidValue(ParsedGuid); } }
void Bag::RemoveItem(uint8 slot) { MANGOS_ASSERT(slot < MAX_BAG_SIZE); if (m_bagslot[slot]) { m_bagslot[slot]->SetContainer(NULL); } m_bagslot[slot] = NULL; SetGuidValue(CONTAINER_FIELD_SLOT_1 + (slot * 2), ObjectGuid()); }
void Bag::RemoveItem(uint8 slot, bool /*update*/) { ASSERT(slot < MAX_BAG_SIZE); if (m_bagslot[slot]) m_bagslot[slot]->SetContainer(NULL); m_bagslot[slot] = NULL; SetGuidValue(CONTAINER_FIELD_SLOT_1 + (slot * 2), ObjectGuid::Empty); }
void Bag::RemoveItem(uint8 slot, bool /*update*/) { MANGOS_ASSERT(slot < MAX_BAG_SIZE); if (m_bagslot[slot]) m_bagslot[slot]->SetContainer(nullptr); m_bagslot[slot] = nullptr; SetGuidValue(CONTAINER_FIELD_SLOT_1 + (slot * 2), ObjectGuid()); }
bool Corpse::LoadFromDB(uint32 lowguid, Field *fields) { // 0 1 2 3 4 5 6 7 8 //result = CharacterDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map,data,time,corpse_type,instance FROM corpse WHERE guid = '%u'",lowguid); float positionX = fields[0].GetFloat(); float positionY = fields[1].GetFloat(); float positionZ = fields[2].GetFloat(); float ort = fields[3].GetFloat(); uint32 mapid = fields[4].GetUInt32(); Object::_Create(lowguid, 0, HIGHGUID_CORPSE); if(!LoadValues( fields[5].GetString() )) { sLog.outError("Corpse #%d have broken data in `data` field. Can't be loaded.", lowguid); return false; } m_time = time_t(fields[6].GetUInt64()); m_type = CorpseType(fields[7].GetUInt32()); if(m_type >= MAX_CORPSE_TYPE) { sLog.outError("Corpse (guidlow %d, owner %d) have wrong corpse type, not load.",GetGUIDLow(),GUID_LOPART(GetOwnerGUID())); return false; } uint32 instanceid = fields[8].GetUInt32(); ObjectGuid guid = ObjectGuid(HIGHGUID_CORPSE, lowguid); // overwrite possible wrong/corrupted guid SetGuidValue(OBJECT_FIELD_GUID, guid); SetObjectScale(DEFAULT_OBJECT_SCALE); // place SetLocationInstanceId(instanceid); SetLocationMapId(mapid); Relocate(positionX, positionY, positionZ, ort); if(!IsPositionValid()) { sLog.outError("Corpse (guidlow %d, owner %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)", GetGUIDLow(), GUID_LOPART(GetOwnerGUID()), GetPositionX(), GetPositionY()); return false; } m_grid = MaNGOS::ComputeGridPair(GetPositionX(), GetPositionY()); return true; }
bool DynamicObject::Create(uint32 guidlow, Unit* caster, uint32 spellId, SpellEffectIndex effIndex, float x, float y, float z, int32 duration, float radius, DynamicObjectType type) { WorldObject::_Create(guidlow, HIGHGUID_DYNAMICOBJECT); SetMap(caster->GetMap()); Relocate(x, y, z, 0); if (!IsPositionValid()) { sLog.outError("DynamicObject (spell %u eff %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)", spellId, effIndex, GetPositionX(), GetPositionY()); return false; } SetEntry(spellId); SetObjectScale(DEFAULT_OBJECT_SCALE); SetGuidValue(DYNAMICOBJECT_CASTER, caster->GetObjectGuid()); /* Bytes field, so it's really 4 bit fields. These flags are unknown, but we do know that 0x00000001 is set for most. Farsight for example, does not have this flag, instead it has 0x80000002. Flags are set dynamically with some conditions, so one spell may have different flags set, depending on those conditions. The size of the visual may be controlled to some degree with these flags. uint32 bytes = 0x00000000; bytes |= 0x01; bytes |= 0x00 << 8; bytes |= 0x00 << 16; bytes |= 0x00 << 24; */ SetByteValue(DYNAMICOBJECT_BYTES, 0, type); SetUInt32Value(DYNAMICOBJECT_SPELLID, spellId); SetFloatValue(DYNAMICOBJECT_RADIUS, radius); SetFloatValue(DYNAMICOBJECT_POS_X, x); SetFloatValue(DYNAMICOBJECT_POS_Y, y); SetFloatValue(DYNAMICOBJECT_POS_Z, z); SetUInt32Value(DYNAMICOBJECT_CASTTIME, WorldTimer::getMSTime()); // new 2.4.0 SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId); if (!spellProto) { sLog.outError("DynamicObject (spell %u) not created. Spell not exist!", spellId); return false; } m_aliveDuration = duration; m_radius = radius; m_effIndex = effIndex; m_spellId = spellId; m_positive = IsPositiveEffect(spellProto, m_effIndex); return true; }
bool DynamicObject::CreateDynamicObject(ObjectGuid::LowType guidlow, Unit* caster, uint32 spellId, Position const& pos, float radius, DynamicObjectType type) { SetMap(caster->GetMap()); Relocate(pos); if (!IsPositionValid()) { TC_LOG_ERROR("misc", "DynamicObject (spell %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)", spellId, GetPositionX(), GetPositionY()); return false; } WorldObject::_Create(guidlow, HighGuid::DynamicObject, caster->GetPhaseMask()); SetEntry(spellId); SetObjectScale(1); SetGuidValue(DYNAMICOBJECT_CASTER, caster->GetGUID()); // The lower word of DYNAMICOBJECT_BYTES must be 0x0001. This value means that the visual radius will be overriden // by client for most of the "ground patch" visual effect spells and a few "skyfall" ones like Hurricane. // If any other value is used, the client will _always_ use the radius provided in DYNAMICOBJECT_RADIUS, but // precompensation is necessary (eg radius *= 2) for many spells. Anyway, blizz sends 0x0001 for all the spells // I saw sniffed... SetByteValue(DYNAMICOBJECT_BYTES, 0, type); SetUInt32Value(DYNAMICOBJECT_SPELLID, spellId); SetFloatValue(DYNAMICOBJECT_RADIUS, radius); SetUInt32Value(DYNAMICOBJECT_CASTTIME, GameTime::GetGameTimeMS()); if (IsWorldObject()) setActive(true); //must before add to map to be put in world container Transport* transport = caster->GetTransport(); if (transport) { float x, y, z, o; pos.GetPosition(x, y, z, o); transport->CalculatePassengerOffset(x, y, z, &o); m_movementInfo.transport.pos.Relocate(x, y, z, o); // This object must be added to transport before adding to map for the client to properly display it transport->AddPassenger(this); } if (!GetMap()->AddToMap(this)) { // Returning false will cause the object to be deleted - remove from transport if (transport) transport->RemovePassenger(this); return false; } return true; }
void Bag::StoreItem(uint8 slot, Item* pItem, bool /*update*/) { ASSERT(slot < MAX_BAG_SIZE); if (pItem && pItem->GetGUID() != this->GetGUID()) { m_bagslot[slot] = pItem; SetGuidValue(CONTAINER_FIELD_SLOTS + (slot * 4), pItem->GetGUID128()); pItem->SetGuidValue(ITEM_FIELD_CONTAINED_IN, GetGUID()); pItem->SetGuidValue(ITEM_FIELD_OWNER, GetOwnerGUID()); pItem->SetContainer(this); pItem->SetSlot(slot); } }
void Bag::StoreItem(uint8 slot, Item* pItem, bool /*update*/) { MANGOS_ASSERT(slot < MAX_BAG_SIZE); if (pItem) { m_bagslot[slot] = pItem; SetGuidValue(CONTAINER_FIELD_SLOT_1 + (slot * 2), pItem->GetObjectGuid()); pItem->SetGuidValue(ITEM_FIELD_CONTAINED, GetObjectGuid()); pItem->SetGuidValue(ITEM_FIELD_OWNER, GetOwnerGuid()); pItem->SetContainer(this); pItem->SetSlot(slot); } }
bool DynamicObject::CreateDynamicObject(ObjectGuid::LowType guidlow, Unit* caster, SpellInfo const* spell, Position const& pos, float radius, DynamicObjectType type, uint32 spellXSpellVisualId) { _spellXSpellVisualId = spellXSpellVisualId; SetMap(caster->GetMap()); Relocate(pos); if (!IsPositionValid()) { TC_LOG_ERROR("misc", "DynamicObject (spell %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)", spell->Id, GetPositionX(), GetPositionY()); return false; } WorldObject::_Create(ObjectGuid::Create<HighGuid::DynamicObject>(GetMapId(), spell->Id, guidlow)); SetPhaseMask(caster->GetPhaseMask(), false); SetEntry(spell->Id); SetObjectScale(1.0f); SetGuidValue(DYNAMICOBJECT_CASTER, caster->GetGUID()); SetUInt32Value(DYNAMICOBJECT_TYPE, type); SetUInt32Value(DYNAMICOBJECT_SPELL_X_SPELL_VISUAL_ID, spellXSpellVisualId); SetUInt32Value(DYNAMICOBJECT_SPELLID, spell->Id); SetFloatValue(DYNAMICOBJECT_RADIUS, radius); SetUInt32Value(DYNAMICOBJECT_CASTTIME, getMSTime()); if (IsWorldObject()) setActive(true); //must before add to map to be put in world container Transport* transport = caster->GetTransport(); if (transport) { float x, y, z, o; pos.GetPosition(x, y, z, o); transport->CalculatePassengerOffset(x, y, z, &o); m_movementInfo.transport.pos.Relocate(x, y, z, o); // This object must be added to transport before adding to map for the client to properly display it transport->AddPassenger(this); } if (!GetMap()->AddToMap(this)) { // Returning false will cause the object to be deleted - remove from transport if (transport) transport->RemovePassenger(this); return false; } return true; }
bool Bag::LoadFromDB(uint32 guidLow, Field* fields, ObjectGuid ownerGuid) { if (!Item::LoadFromDB(guidLow, fields, ownerGuid)) return false; // cleanup bag content related item value fields (its will be filled correctly from `character_inventory`) for (int i = 0; i < MAX_BAG_SIZE; ++i) { SetGuidValue(CONTAINER_FIELD_SLOT_1 + (i * 2), ObjectGuid()); delete m_bagslot[i]; m_bagslot[i] = nullptr; } return true; }
bool Bag::LoadFromDB(uint32 guid, ObjectGuid owner_guid, Field* fields, uint32 entry) { if (!Item::LoadFromDB(guid, owner_guid, fields, entry)) return false; ItemTemplate const* itemProto = GetTemplate(); // checked in Item::LoadFromDB SetUInt32Value(CONTAINER_FIELD_NUM_SLOTS, itemProto->ContainerSlots); // cleanup bag content related item value fields (its will be filled correctly from `character_inventory`) for (uint8 i = 0; i < MAX_BAG_SIZE; ++i) { SetGuidValue(CONTAINER_FIELD_SLOT_1 + (i * 2), ObjectGuid::Empty); delete m_bagslot[i]; m_bagslot[i] = NULL; } return true; }
bool Corpse::LoadCorpseFromDB(uint32 guid, Field* fields) { // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // SELECT posX, posY, posZ, orientation, mapId, displayId, itemCache, bytes1, bytes2, guildId, flags, dynFlags, time, corpseType, instanceId, phaseMask, corpseGuid, guid FROM corpse WHERE corpseType <> 0 uint32 ownerGuid = fields[17].GetUInt32(); float posX = fields[0].GetFloat(); float posY = fields[1].GetFloat(); float posZ = fields[2].GetFloat(); float o = fields[3].GetFloat(); uint32 mapId = fields[4].GetUInt16(); Object::_Create(guid, 0, HIGHGUID_CORPSE); SetObjectScale(1.0f); SetUInt32Value(CORPSE_FIELD_DISPLAY_ID, fields[5].GetUInt32()); _LoadIntoDataField(fields[6].GetCString(), CORPSE_FIELD_ITEM, EQUIPMENT_SLOT_END); SetUInt32Value(CORPSE_FIELD_BYTES_1, fields[7].GetUInt32()); SetUInt32Value(CORPSE_FIELD_BYTES_2, fields[8].GetUInt32()); SetUInt32Value(CORPSE_FIELD_GUILD, fields[9].GetUInt32()); SetUInt32Value(CORPSE_FIELD_FLAGS, fields[10].GetUInt8()); SetUInt32Value(CORPSE_FIELD_DYNAMIC_FLAGS, fields[11].GetUInt8()); SetGuidValue(CORPSE_FIELD_OWNER, ObjectGuid(HIGHGUID_PLAYER, ownerGuid)); m_time = time_t(fields[12].GetUInt32()); uint32 instanceId = fields[14].GetUInt32(); uint32 phaseMask = fields[15].GetUInt32(); // place SetLocationInstanceId(instanceId); SetLocationMapId(mapId); SetPhaseMask(phaseMask, false); Relocate(posX, posY, posZ, o); if (!IsPositionValid()) { TC_LOG_ERROR("entities.player", "Corpse (%s, owner: %s) is not created, given coordinates are not valid (X: %f, Y: %f, Z: %f)", GetGUID().ToString().c_str(), GetOwnerGUID().ToString().c_str(), posX, posY, posZ); return false; } _gridCoord = Tournament::ComputeGridCoord(GetPositionX(), GetPositionY()); return true; }
bool Corpse::LoadCorpseFromDB(ObjectGuid::LowType guid, Field* fields) { // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // SELECT posX, posY, posZ, orientation, mapId, displayId, itemCache, bytes1, bytes2, flags, dynFlags, time, corpseType, instanceId, guid FROM corpse WHERE mapId = ? AND instanceId = ? float posX = fields[0].GetFloat(); float posY = fields[1].GetFloat(); float posZ = fields[2].GetFloat(); float o = fields[3].GetFloat(); uint32 mapId = fields[4].GetUInt16(); Object::_Create(ObjectGuid::Create<HighGuid::Corpse>(mapId, 0, guid)); SetObjectScale(1.0f); SetUInt32Value(CORPSE_FIELD_DISPLAY_ID, fields[5].GetUInt32()); _LoadIntoDataField(fields[6].GetCString(), CORPSE_FIELD_ITEM, EQUIPMENT_SLOT_END); SetUInt32Value(CORPSE_FIELD_BYTES_1, fields[7].GetUInt32()); SetUInt32Value(CORPSE_FIELD_BYTES_2, fields[8].GetUInt32()); SetUInt32Value(CORPSE_FIELD_FLAGS, fields[9].GetUInt8()); SetUInt32Value(CORPSE_FIELD_DYNAMIC_FLAGS, fields[10].GetUInt8()); SetGuidValue(CORPSE_FIELD_OWNER, ObjectGuid::Create<HighGuid::Player>(fields[14].GetUInt64())); m_time = time_t(fields[11].GetUInt32()); uint32 instanceId = fields[13].GetUInt32(); // place SetLocationInstanceId(instanceId); SetLocationMapId(mapId); Relocate(posX, posY, posZ, o); if (!IsPositionValid()) { TC_LOG_ERROR("entities.player", "Corpse (%s, owner: %s) is not created, given coordinates are not valid (X: %f, Y: %f, Z: %f)", GetGUID().ToString().c_str(), GetOwnerGUID().ToString().c_str(), posX, posY, posZ); return false; } _cellCoord = Trinity::ComputeCellCoord(GetPositionX(), GetPositionY()); return true; }
bool DynamicObject::Create(uint32 guidlow, Unit* caster, uint32 spellId, SpellEffectIndex effIndex, float x, float y, float z, int32 duration, float radius, DynamicObjectType type) { WorldObject::_Create(guidlow, GUIDTYPE_DYNAMICOBJECT, caster->GetPhaseMask()); SetMap(caster->GetMap()); Relocate(x, y, z, 0); if (!IsPositionValid()) { sLog.outError("DynamicObject (spell %u eff %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)", spellId, effIndex, GetPositionX(), GetPositionY()); return false; } SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId); if (!spellProto) { sLog.outError("DynamicObject (spell %u) not created. Spell not exist!", spellId); return false; } SetEntry(spellId); SetObjectScale(DEFAULT_OBJECT_SCALE); SetGuidValue(DYNAMICOBJECT_CASTER, caster->GetObjectGuid()); SetUInt32Value(DYNAMICOBJECT_BYTES, spellProto->SpellVisual[0] | (type << 28)); SetUInt32Value(DYNAMICOBJECT_SPELLID, spellId); SetFloatValue(DYNAMICOBJECT_RADIUS, radius); SetUInt32Value(DYNAMICOBJECT_CASTTIME, WorldTimer::getMSTime()); // new 2.4.0 m_aliveDuration = duration; m_radius = radius; m_effIndex = effIndex; m_spellId = spellId; m_positive = IsPositiveEffect(spellProto, m_effIndex); return true; }
bool Item::LoadFromDB(uint32 guidLow, Field* fields, ObjectGuid ownerGuid) { // create item before any checks for store correct guid // and allow use "FSetState(ITEM_REMOVED); SaveToDB();" for deleting item from DB Object::_Create(ObjectGuid(HIGHGUID_ITEM, guidLow)); if (!LoadValues(fields[0].GetString())) { sLog.outError("Item::LoadFromDB: %s have broken data in `data` field. Can't be loaded.", GetGuidStr().c_str()); return false; } SetText(fields[1].GetCppString()); bool needSave = false; // need explicit save data at load fixes // overwrite possible wrong/corrupted guid ObjectGuid new_item_guid = ObjectGuid(HIGHGUID_ITEM, guidLow); if (GetGuidValue(OBJECT_FIELD_GUID) != new_item_guid) { SetGuidValue(OBJECT_FIELD_GUID, new_item_guid); needSave = true; } ItemPrototype const* proto = GetProto(); if (!proto) return false; // update max durability (and durability) if need if (proto->MaxDurability != GetUInt32Value(ITEM_FIELD_MAXDURABILITY)) { SetUInt32Value(ITEM_FIELD_MAXDURABILITY, proto->MaxDurability); if (GetUInt32Value(ITEM_FIELD_DURABILITY) > proto->MaxDurability) SetUInt32Value(ITEM_FIELD_DURABILITY, proto->MaxDurability); needSave = true; } // recalculate suffix factor if (GetItemRandomPropertyId() < 0) { if (UpdateItemSuffixFactor()) needSave = true; } // Remove bind flag for items vs NO_BIND set if (IsSoulBound() && proto->Bonding == NO_BIND) { ApplyModFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_BINDED, false); needSave = true; } // update duration if need, and remove if not need if ((proto->Duration == 0) != (GetUInt32Value(ITEM_FIELD_DURATION) == 0)) { SetUInt32Value(ITEM_FIELD_DURATION, proto->Duration); needSave = true; } // set correct owner if (ownerGuid && GetOwnerGuid() != ownerGuid) { SetOwnerGuid(ownerGuid); needSave = true; } // set correct wrapped state if (HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED)) { // wrapped item must be wrapper (used version that not stackable) if (!(proto->Flags & ITEM_FLAG_WRAPPER) || GetMaxStackCount() > 1) { RemoveFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED); needSave = true; // also cleanup for sure gift table DeleteGiftsFromDB(); } } if (needSave) // normal item changed state set not work at loading { std::ostringstream ss; for (uint16 i = 0; i < m_valuesCount; ++i) ss << GetUInt32Value(i) << " "; static SqlStatementID updItem; SqlStatement stmt = CharacterDatabase.CreateStatement(updItem, "UPDATE item_instance SET owner_guid = ?, data = ? WHERE guid = ?"); stmt.PExecute(GetOwnerGuid().GetCounter(), ss.str().c_str(), guidLow); } return true; }
bool AreaTrigger::Create(uint32 spellMiscId, Unit* caster, Unit* target, SpellInfo const* spell, Position const& pos, int32 duration, uint32 spellXSpellVisualId, ObjectGuid const& castId, AuraEffect const* aurEff) { _targetGuid = target ? target->GetGUID() : ObjectGuid::Empty; _aurEff = aurEff; SetMap(caster->GetMap()); Relocate(pos); if (!IsPositionValid()) { TC_LOG_ERROR("entities.areatrigger", "AreaTrigger (spellMiscId %u) not created. Invalid coordinates (X: %f Y: %f)", spellMiscId, GetPositionX(), GetPositionY()); return false; } _areaTriggerMiscTemplate = sAreaTriggerDataStore->GetAreaTriggerMiscTemplate(spellMiscId); if (!_areaTriggerMiscTemplate) { TC_LOG_ERROR("entities.areatrigger", "AreaTrigger (spellMiscId %u) not created. Invalid areatrigger miscid (%u)", spellMiscId, spellMiscId); return false; } Object::_Create(ObjectGuid::Create<HighGuid::AreaTrigger>(GetMapId(), GetTemplate()->Id, caster->GetMap()->GenerateLowGuid<HighGuid::AreaTrigger>())); SetEntry(GetTemplate()->Id); SetDuration(duration); SetObjectScale(1.0f); SetGuidValue(AREATRIGGER_CASTER, caster->GetGUID()); SetGuidValue(AREATRIGGER_CREATING_EFFECT_GUID, castId); SetUInt32Value(AREATRIGGER_SPELLID, spell->Id); SetUInt32Value(AREATRIGGER_SPELL_FOR_VISUALS, spell->Id); SetUInt32Value(AREATRIGGER_SPELL_X_SPELL_VISUAL_ID, spellXSpellVisualId); SetUInt32Value(AREATRIGGER_TIME_TO_TARGET_SCALE, GetMiscTemplate()->TimeToTargetScale != 0 ? GetMiscTemplate()->TimeToTargetScale : GetUInt32Value(AREATRIGGER_DURATION)); SetFloatValue(AREATRIGGER_BOUNDS_RADIUS_2D, GetTemplate()->MaxSearchRadius); SetUInt32Value(AREATRIGGER_DECAL_PROPERTIES_ID, GetMiscTemplate()->DecalPropertiesId); for (uint8 scaleCurveIndex = 0; scaleCurveIndex < MAX_AREATRIGGER_SCALE; ++scaleCurveIndex) if (GetMiscTemplate()->ExtraScale.Data.Raw[scaleCurveIndex]) SetUInt32Value(AREATRIGGER_EXTRA_SCALE_CURVE + scaleCurveIndex, GetMiscTemplate()->ExtraScale.Data.Raw[scaleCurveIndex]); PhasingHandler::InheritPhaseShift(this, caster); if (target && GetTemplate()->HasFlag(AREATRIGGER_FLAG_HAS_ATTACHED)) { m_movementInfo.transport.guid = target->GetGUID(); } UpdateShape(); uint32 timeToTarget = GetMiscTemplate()->TimeToTarget != 0 ? GetMiscTemplate()->TimeToTarget : GetUInt32Value(AREATRIGGER_DURATION); if (GetTemplate()->HasFlag(AREATRIGGER_FLAG_HAS_CIRCULAR_MOVEMENT)) { AreaTriggerCircularMovementInfo cmi = GetMiscTemplate()->CircularMovementInfo; if (target && GetTemplate()->HasFlag(AREATRIGGER_FLAG_HAS_ATTACHED)) cmi.PathTarget = target->GetGUID(); else cmi.Center = pos; InitCircularMovement(cmi, timeToTarget); } else if (GetMiscTemplate()->HasSplines()) { InitSplineOffsets(GetMiscTemplate()->SplinePoints, timeToTarget); } // movement on transport of areatriggers on unit is handled by themself Transport* transport = m_movementInfo.transport.guid.IsEmpty() ? caster->GetTransport() : nullptr; if (transport) { float x, y, z, o; pos.GetPosition(x, y, z, o); transport->CalculatePassengerOffset(x, y, z, &o); m_movementInfo.transport.pos.Relocate(x, y, z, o); // This object must be added to transport before adding to map for the client to properly display it transport->AddPassenger(this); } AI_Initialize(); // Relocate areatriggers with circular movement again if (HasCircularMovement()) Relocate(CalculateCircularMovementPosition()); if (!GetMap()->AddToMap(this)) { // Returning false will cause the object to be deleted - remove from transport if (transport) transport->RemovePassenger(this); return false; } caster->_RegisterAreaTrigger(this); _ai->OnCreate(); return true; }
bool Corpse::LoadFromDB(uint32 lowguid, Field* fields) { //// 0 1 2 3 4 5 6 // QueryResult *result = CharacterDatabase.Query("SELECT corpse.guid, player, corpse.position_x, corpse.position_y, corpse.position_z, corpse.orientation, corpse.map," //// 7 8 9 10 11 12 13 14 15 16 17 18 // "time, corpse_type, instance, phaseMask, gender, race, class, playerBytes, playerBytes2, equipmentCache, guildId, playerFlags FROM corpse" uint32 playerLowGuid = fields[1].GetUInt32(); float positionX = fields[2].GetFloat(); float positionY = fields[3].GetFloat(); float positionZ = fields[4].GetFloat(); float orientation = fields[5].GetFloat(); uint32 mapid = fields[6].GetUInt32(); Object::_Create(lowguid, 0, HIGHGUID_CORPSE); m_time = time_t(fields[7].GetUInt64()); m_type = CorpseType(fields[8].GetUInt32()); if (m_type >= MAX_CORPSE_TYPE) { sLog.outError("%s Owner %s have wrong corpse type (%i), not load.", GetGuidStr().c_str(), GetOwnerGuid().GetString().c_str(), m_type); return false; } uint32 instanceid = fields[9].GetUInt32(); uint32 phaseMask = fields[10].GetUInt32(); uint8 gender = fields[11].GetUInt8(); uint8 race = fields[12].GetUInt8(); uint8 _class = fields[13].GetUInt8(); uint32 playerBytes = fields[14].GetUInt32(); uint32 playerBytes2 = fields[15].GetUInt32(); uint32 guildId = fields[17].GetUInt32(); uint32 playerFlags = fields[18].GetUInt32(); ObjectGuid guid = ObjectGuid(HIGHGUID_CORPSE, lowguid); ObjectGuid playerGuid = ObjectGuid(HIGHGUID_PLAYER, playerLowGuid); // overwrite possible wrong/corrupted guid SetGuidValue(OBJECT_FIELD_GUID, guid); SetOwnerGuid(playerGuid); SetObjectScale(DEFAULT_OBJECT_SCALE); PlayerInfo const* info = sObjectMgr.GetPlayerInfo(race, _class); if (!info) { sLog.outError("Player %u has incorrect race/class pair.", GetGUIDLow()); return false; } SetUInt32Value(CORPSE_FIELD_DISPLAY_ID, gender == GENDER_FEMALE ? info->displayId_f : info->displayId_m); // Load equipment Tokens data = StrSplit(fields[16].GetCppString(), " "); for (uint8 slot = 0; slot < EQUIPMENT_SLOT_END; ++slot) { uint32 visualbase = slot * 2; uint32 item_id = GetUInt32ValueFromArray(data, visualbase); const ItemPrototype* proto = ObjectMgr::GetItemPrototype(item_id); if (!proto) { SetUInt32Value(CORPSE_FIELD_ITEM + slot, 0); continue; } SetUInt32Value(CORPSE_FIELD_ITEM + slot, proto->DisplayInfoID | (proto->InventoryType << 24)); } uint8 skin = (uint8)(playerBytes); uint8 face = (uint8)(playerBytes >> 8); uint8 hairstyle = (uint8)(playerBytes >> 16); uint8 haircolor = (uint8)(playerBytes >> 24); uint8 facialhair = (uint8)(playerBytes2); SetUInt32Value(CORPSE_FIELD_BYTES_1, ((0x00) | (race << 8) | (gender << 16) | (skin << 24))); SetUInt32Value(CORPSE_FIELD_BYTES_2, ((face) | (hairstyle << 8) | (haircolor << 16) | (facialhair << 24))); SetUInt32Value(CORPSE_FIELD_GUILD, guildId); uint32 flags = CORPSE_FLAG_UNK2; if (playerFlags & PLAYER_FLAGS_HIDE_HELM) flags |= CORPSE_FLAG_HIDE_HELM; if (playerFlags & PLAYER_FLAGS_HIDE_CLOAK) flags |= CORPSE_FLAG_HIDE_CLOAK; SetUInt32Value(CORPSE_FIELD_FLAGS, flags); // no need to mark corpse as lootable, because corpses are not saved in battle grounds // place SetLocationInstanceId(instanceid); SetLocationMapId(mapid); SetPhaseMask(phaseMask, false); Relocate(positionX, positionY, positionZ, orientation); if (!IsPositionValid()) { sLog.outError("%s Owner %s not created. Suggested coordinates isn't valid (X: %f Y: %f)", GetGuidStr().c_str(), GetOwnerGuid().GetString().c_str(), GetPositionX(), GetPositionY()); return false; } m_grid = MaNGOS::ComputeGridPair(GetPositionX(), GetPositionY()); return true; }
bool Item::LoadFromDB(ObjectGuid::LowType guid, ObjectGuid owner_guid, Field* fields, uint32 entry) { // 0 1 2 3 4 5 6 7 8 9 10 //result = CharacterDatabase.PQuery("SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text FROM item_instance WHERE guid = '%u'", guid); // create item before any checks for store correct guid // and allow use "FSetState(ITEM_REMOVED); SaveToDB();" for deleting item from DB Object::_Create(guid, 0, HighGuid::Item); // Set entry, MUST be before proto check SetEntry(entry); SetObjectScale(1.0f); ItemTemplate const* proto = GetTemplate(); if (!proto) return false; // set owner (not if item is only loaded for gbank/auction/mail if (owner_guid) SetOwnerGUID(owner_guid); bool need_save = false; // need explicit save data at load fixes SetGuidValue(ITEM_FIELD_CREATOR, ObjectGuid(HighGuid::Player, fields[0].GetUInt32())); SetGuidValue(ITEM_FIELD_GIFTCREATOR, ObjectGuid(HighGuid::Player, fields[1].GetUInt32())); SetCount(fields[2].GetUInt32()); uint32 duration = fields[3].GetUInt32(); SetUInt32Value(ITEM_FIELD_DURATION, duration); // update duration if need, and remove if not need if ((proto->Duration == 0) != (duration == 0)) { SetUInt32Value(ITEM_FIELD_DURATION, proto->Duration); need_save = true; } Tokenizer tokens(fields[4].GetString(), ' ', MAX_ITEM_PROTO_SPELLS); if (tokens.size() == MAX_ITEM_PROTO_SPELLS) for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) SetSpellCharges(i, atoi(tokens[i])); SetUInt32Value(ITEM_FIELD_FLAGS, fields[5].GetUInt32()); // Remove bind flag for items vs NO_BIND set if (IsSoulBound() && proto->Bonding == NO_BIND) { ApplyModFlag(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_SOULBOUND, false); need_save = true; } _LoadIntoDataField(fields[6].GetString(), ITEM_FIELD_ENCHANTMENT_1_1, MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET); SetInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID, fields[7].GetInt16()); // recalculate suffix factor if (GetItemRandomPropertyId() < 0) UpdateItemSuffixFactor(); uint32 durability = fields[8].GetUInt16(); SetUInt32Value(ITEM_FIELD_DURABILITY, durability); // update max durability (and durability) if need SetUInt32Value(ITEM_FIELD_MAXDURABILITY, proto->MaxDurability); // do not overwrite durability for wrapped items if (durability > proto->MaxDurability && !HasFlag(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_WRAPPED)) { SetUInt32Value(ITEM_FIELD_DURABILITY, proto->MaxDurability); need_save = true; } SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, fields[9].GetUInt32()); SetText(fields[10].GetString()); if (need_save) // normal item changed state set not work at loading { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ITEM_INSTANCE_ON_LOAD); stmt->setUInt32(0, GetUInt32Value(ITEM_FIELD_DURATION)); stmt->setUInt32(1, GetUInt32Value(ITEM_FIELD_FLAGS)); stmt->setUInt32(2, GetUInt32Value(ITEM_FIELD_DURABILITY)); stmt->setUInt32(3, guid); CharacterDatabase.Execute(stmt); } return true; }