Beispiel #1
0
bool Item::LoadFromDB(uint32 guid, uint64 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);
	SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f);

	ItemPrototype const* proto = GetProto();
	if (!proto)
		return false;

	// set owner (not if item is only loaded for gbank/auction/mail
	if (owner_guid != 0)
		SetOwnerGUID(owner_guid);

	bool need_save = false; // need explicit save data at load fixes
	SetUInt64Value(ITEM_FIELD_CREATOR,
			MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER));
	SetUInt64Value(ITEM_FIELD_GIFTCREATOR,
			MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER));
	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, abs(proto->Duration));
		need_save = true;
	}

	Tokens 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_FLAG_SOULBOUND, false);
		need_save = true;
	}

	std::string enchants = fields[6].GetString();
	//_LoadIntoDataField(enchants.c_str(), ITEM_FIELD_ENCHANTMENT_1_1, MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET);
	{
		// NOTE:
		// in the recent update of reforge system, definition of EnchantmentSlot has been changed,
		// and MAX_ENCHANTMENT_SLOT has been changed from 13 to 14,
		// which makes enchantments column of item_instance table incompatible with previous version.
		// in this case we will load only first 9 enchantment slots (0-8, for permanent, temporary, sockets, bonus, prismatic and reforge)
		// and ignore the remaining ones (9-13, for random properties).
		// which means item random properties will be lost after this update.
		// after player logging in and saving the inventory, enchantments column will be properly updated.

		uint32 count = MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET;
		Tokens tokens(enchants, ' ', count);

		if (tokens.size() < MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET)
			count = REFORGE_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET;

		for (uint32 index = 0; index < count; ++index)
			m_uint32Values[ITEM_FIELD_ENCHANTMENT_1_1 + index] =
					index < tokens.size() ? atol(tokens[index]) : 0;
	}
	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);
	if (durability > proto->MaxDurability) {
		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_UPDATE_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;
}
Beispiel #2
0
bool Item::LoadFromDB(uint32 guid, uint64 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 != 0)
        SetOwnerGUID(owner_guid);

    bool need_save = false;                                 // need explicit save data at load fixes
    SetUInt64Value(ITEM_FIELD_CREATOR, MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER));
    SetUInt64Value(ITEM_FIELD_GIFTCREATOR, MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER));
    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_FLAG_SOULBOUND, false);
        need_save = true;
    }

    std::string enchants = fields[6].GetString();
    _LoadIntoDataField(enchants.c_str(), 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);
    if (durability > proto->MaxDurability)
    {
        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;
}
Beispiel #3
0
bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result, 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);
    SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f);

    ItemPrototype const* proto = GetProto();
    if (!proto)
        return false;

    if (!result)
    {
        sLog.outError("Item (GUID: %u owner: %u) not found in table `item_instance`, can't load. ", guid, GUID_LOPART(owner_guid));
        return false;
    }

    // set owner (not if item is only loaded for gbank/auction/mail
    if (owner_guid != 0)
        SetOwnerGUID(owner_guid);

    Field *fields = result->Fetch();
    bool need_save = false;                                 // need explicit save data at load fixes
    SetUInt64Value(ITEM_FIELD_CREATOR, MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER));
    SetUInt64Value(ITEM_FIELD_GIFTCREATOR, MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER));
    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, abs(proto->Duration));
        need_save = true;
    }

    Tokens tokens = StrSplit(fields[4].GetCppString(), " ");
    if (tokens.size() == MAX_ITEM_PROTO_SPELLS)
        for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
            SetSpellCharges(i, atoi(tokens[i].c_str()));

    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_FLAGS_BINDED, 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].GetInt32());
    // recalculate suffix factor
    if (GetItemRandomPropertyId() < 0)
        UpdateItemSuffixFactor();

    uint32 durability = fields[8].GetUInt32();
    SetUInt32Value(ITEM_FIELD_DURABILITY, durability);
    // update max durability (and durability) if need
    SetUInt32Value(ITEM_FIELD_MAXDURABILITY, proto->MaxDurability);
    if (durability > proto->MaxDurability)
    {
        SetUInt32Value(ITEM_FIELD_DURABILITY, proto->MaxDurability);
        need_save = true;
    }

    SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, fields[9].GetUInt32());
    SetText(fields[10].GetCppString());

    if (need_save)                                           // normal item changed state set not work at loading
    {
        std::ostringstream ss;
        ss << "UPDATE item_instance SET duration = " << GetUInt32Value(ITEM_FIELD_DURABILITY)
            << ", flags = " << GetUInt32Value(ITEM_FIELD_FLAGS)
            << ", durability = " << GetUInt32Value(ITEM_FIELD_DURABILITY)
            << " WHERE guid = " << guid;

        CharacterDatabase.Execute(ss.str().c_str());
    }

    return true;
}