예제 #1
0
void Corpse::DeleteFromDB()
{
    //delete corpse from db when its not needed anymore
    char sql[256];

    snprintf(sql, 256, "DELETE FROM corpses WHERE guid=%u", (unsigned int)GetLowGUID());
    CharacterDatabase.Execute(sql);
}
예제 #2
0
void Corpse::SaveToDB()
{
    //save corpse to DB
    std::stringstream ss;
    ss << "DELETE FROM corpses WHERE guid = " << GetLowGUID();
    CharacterDatabase.Execute(ss.str().c_str());

    ss.rdbuf()->str("");
    ss << "INSERT INTO corpses (guid, positionX, positionY, positionZ, orientation, zoneId, mapId, data, instanceId) VALUES ("
        << GetLowGUID() << ", '" << GetPositionX() << "', '" << GetPositionY() << "', '" << GetPositionZ() << "', '" << GetOrientation() << "', '" << GetZoneId() << "', '" << GetMapId() << "', '";

    for (uint16 i = 0; i < m_valuesCount; i++)
        ss << GetUInt32Value(i) << " ";

    ss << "', " << GetInstanceID() << " )";

    CharacterDatabase.Execute(ss.str().c_str());
}
예제 #3
0
파일: GameObject.cpp 프로젝트: Chero/abcwow
void GameObject::OnRemoveInRangeObject(Object* pObj)
{
	Object::OnRemoveInRangeObject(pObj);
	if(m_summonedGo && m_summoner == pObj)
	{
		for(int i = 0; i < 4; i++)
			if (m_summoner->m_ObjectSlots[i] == GetLowGUID())
				m_summoner->m_ObjectSlots[i] = 0;

		m_summoner = 0;
		ExpireAndDelete();
	}
}
예제 #4
0
파일: GameObject.cpp 프로젝트: Chero/abcwow
GameObject::~GameObject()
{
	sEventMgr.RemoveEvents(this);
	if(m_ritualmembers) {
		delete[] m_ritualmembers;
		m_ritualmembers = NULL;
	}

	uint32 guid = GetUInt32Value(OBJECT_FIELD_CREATED_BY);
	if(guid)
	{
		Player *plr = objmgr.GetPlayer(guid);
		if(plr && plr->GetSummonedObject() == this)
			plr->SetSummonedObject(NULL);

		if(plr == m_summoner)
			m_summoner = 0;
	}

	if(m_respawnCell!=NULL)
		m_respawnCell->_respawnObjects.erase(this);

	if (m_summonedGo && m_summoner)
		for(int i = 0; i < 4; i++)
			if (m_summoner->m_ObjectSlots[i] == GetLowGUID())
				m_summoner->m_ObjectSlots[i] = 0;

	if( m_battleground != NULL && m_battleground->GetType() == BATTLEGROUND_ARATHI_BASIN )
	{
		if( bannerslot >= 0 && static_cast<ArathiBasin*>(m_battleground)->m_controlPoints[bannerslot] == this )
			static_cast<ArathiBasin*>(m_battleground)->m_controlPoints[bannerslot] = NULL;

		if( bannerauraslot >= 0 && static_cast<ArathiBasin*>(m_battleground)->m_controlPointAuras[bannerauraslot] == this )
			static_cast<ArathiBasin*>(m_battleground)->m_controlPointAuras[bannerauraslot] = NULL;
	}
}
예제 #5
0
/*Loot type MUST be
1-corpse, go
2-skinning/herbalism/minning
3-Fishing
*/
void Player::SendLoot(uint64 guid,uint8 loot_type, uint32 mapid)
{
	Group * m_Group = m_playerInfo->m_Group;

	if( !IsInWorld() )
		return;

	Loot * pLoot = NULL;
	uint32 guidtype = GET_TYPE_FROM_GUID(guid);
	
	int8 loot_method;

	if( m_Group != NULL )
		loot_method = m_Group->GetMethod();
	else
		loot_method = PARTY_LOOT_FFA;

	if(guidtype == HIGHGUID_TYPE_UNIT)
	{
		Creature* pCreature = GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid));
		if(!pCreature)return;
		pLoot=&pCreature->loot;
		m_currentLoot = pCreature->GetGUID();
		
	}else if(guidtype == HIGHGUID_TYPE_GAMEOBJECT)
	{
		GameObject* pGO = GetMapMgr()->GetGameObject(GET_LOWGUID_PART(guid));
		if(!pGO)return;
		pGO->SetByte(GAMEOBJECT_BYTES_1, 0,0);
		pLoot=&pGO->loot;
		m_currentLoot = pGO->GetGUID();
	}
	else if((guidtype == HIGHGUID_TYPE_PLAYER) )
	{
		Player *p=GetMapMgr()->GetPlayer((uint32)guid);
		if(!p)return;
		pLoot=&p->loot;
		m_currentLoot = p->GetGUID();
	}
	else if( (guidtype == HIGHGUID_TYPE_CORPSE))
	{
		Corpse *pCorpse = objmgr.GetCorpse((uint32)guid);
		if(!pCorpse)return;
		pLoot=&pCorpse->loot;
		m_currentLoot = pCorpse->GetGUID();
	}
	else if( (guidtype == HIGHGUID_TYPE_ITEM) )
	{
		Item *pItem = GetItemInterface()->GetItemByGUID(guid);
		if(!pItem)
			return;
		pLoot = pItem->loot;
		m_currentLoot = pItem->GetGUID();
	}

	if(!pLoot)
	{
		// something whack happened.. damn cheaters..
		return;
	}

	// add to looter set
	pLoot->looters.insert( GetLowGUID() );

	WorldPacket data, data2(32);
	data.SetOpcode( SMSG_LOOT_RESPONSE );


	m_lootGuid = guid;


	data << uint64( guid );
	data << uint8( loot_type );//loot_type;
	data << uint32( pLoot->gold );
	data << uint8( 0 ); //loot size reserve


	std::vector<__LootItem>::iterator iter=pLoot->items.begin();
	uint32 count= 0;
	uint8 slottype = 0;

	for(uint32 x= 0;iter!=pLoot->items.end();iter++,x++)
	{
		if (iter->iItemsCount == 0)
			continue;

		LooterSet::iterator itr = iter->has_looted.find(GetLowGUID());
		if (iter->has_looted.end() != itr)
			continue;

		ItemPrototype* itemProto =iter->item.itemproto;
		if (!itemProto)
			continue;

		// check if it's on ML if so only quest items and ffa loot should be shown based on mob
		if ( loot_method == PARTY_LOOT_MASTER && m_Group && m_Group->GetLooter() != m_playerInfo )
			// pass on all ffa_loot and the grey / white items
			if ( !iter->ffa_loot && !(itemProto->Quality < m_Group->GetThreshold()) )
				continue;

		//quest items check. type 4/5
		//quest items that don't start quests.
        if((itemProto->Bonding == ITEM_BIND_QUEST) && !(itemProto->QuestId) && !HasQuestForItem(itemProto->ItemId))
            continue;
        if((itemProto->Bonding == ITEM_BIND_QUEST2) && !(itemProto->QuestId) && !HasQuestForItem(itemProto->ItemId))
            continue;

        //quest items that start quests need special check to avoid drops all the time.
        if((itemProto->Bonding == ITEM_BIND_QUEST) && (itemProto->QuestId) && GetQuestLogForEntry(itemProto->QuestId))
            continue;
        if((itemProto->Bonding == ITEM_BIND_QUEST2) && (itemProto->QuestId) && GetQuestLogForEntry(itemProto->QuestId))
            continue;

        if((itemProto->Bonding == ITEM_BIND_QUEST) && (itemProto->QuestId) && HasFinishedQuest(itemProto->QuestId))
            continue;
        if((itemProto->Bonding == ITEM_BIND_QUEST2) && (itemProto->QuestId) && HasFinishedQuest(itemProto->QuestId))
            continue;

        //check for starting item quests that need questlines.
        if((itemProto->QuestId && itemProto->Bonding != ITEM_BIND_QUEST && itemProto->Bonding != ITEM_BIND_QUEST2))
        {
            bool HasRequiredQuests = true;
            Quest * pQuest = QuestStorage.LookupEntry(itemProto->QuestId);
            if(pQuest)
            {
				uint32 finishedCount = 0;

                //check if its a questline.
                for(uint32 i = 0; i < pQuest->count_requiredquests; i++)
                {
                    if(pQuest->required_quests[i])
                    {
                        if(!HasFinishedQuest(pQuest->required_quests[i]) || GetQuestLogForEntry(pQuest->required_quests[i]))
                        {
							if (!(pQuest->quest_flags & QUEST_FLAG_ONLY_ONE_REQUIRED)) {
								HasRequiredQuests = false;
								break;
							}
						}
						else
						{
							finishedCount++;
						}
                    }
                }

				if (pQuest->quest_flags & QUEST_FLAG_ONLY_ONE_REQUIRED) {
					if (finishedCount == 0) continue;
				} else {
	                if(!HasRequiredQuests)
    	                continue;
				}
            }
        }

		slottype = 0;
		if(m_Group != NULL && loot_type < 2)
		{
			switch(loot_method)
			{
			case PARTY_LOOT_MASTER:
				slottype = 2;
				break;
			case PARTY_LOOT_GROUP:
			case PARTY_LOOT_RR:
			case PARTY_LOOT_NBG:
				slottype = 1;
				break;
			default:
				slottype = 0;
				break;
			}
			// only quality items are distributed
			if(itemProto->Quality < m_Group->GetThreshold())
			{
				slottype = 0;
			}

			// if all people passed anyone can loot it? :P
			if(iter->passed)
				slottype = 0;					// All players passed on the loot

			//if it is ffa loot and not an masterlooter
			if(iter->ffa_loot)
				slottype = 0;
		}

		data << uint8( x );
		data << uint32( itemProto->ItemId );
		data << uint32( iter->iItemsCount );//nr of items of this type
		data << uint32( iter->item.displayid );

        if(iter->iRandomSuffix)
		{
			data << uint32( Item::GenerateRandomSuffixFactor( itemProto ) );
			data << uint32( -int32( iter->iRandomSuffix->id ) );
		}
		else if(iter->iRandomProperty)
		{
			data << uint32( 0 );
			data << uint32( iter->iRandomProperty->ID );
		}
		else
		{
			data << uint32( 0 );
			data << uint32( 0 );
		}

		data << slottype;   // "still being rolled for" flag

		if(slottype == 1)
		{
			if(iter->roll == NULL && !iter->passed)
			{
				int32 ipid = 0;
				uint32 factor= 0;
				if(iter->iRandomProperty)
					ipid=iter->iRandomProperty->ID;
				else if(iter->iRandomSuffix)
				{
					ipid = -int32(iter->iRandomSuffix->id);
					factor=Item::GenerateRandomSuffixFactor(iter->item.itemproto);
				}

				if(iter->item.itemproto)
				{
					iter->roll = new LootRoll(60000, (m_Group != NULL ? m_Group->MemberCount() : 1),  guid, x, itemProto->ItemId, factor, uint32(ipid), GetMapMgr());

					data2.Initialize(SMSG_LOOT_START_ROLL);
					data2 << guid;
					data2 << uint32( mapid );
					data2 << uint32( x );
					data2 << uint32( itemProto->ItemId );
					data2 << uint32( factor );
					if(iter->iRandomProperty)
						data2 << uint32(iter->iRandomProperty->ID);
					else if(iter->iRandomSuffix)
						data2 << uint32( ipid );
					else
						data2 << uint32( 0 );

					data2 << uint32( iter->iItemsCount );
					data2 << uint32( 60000 );	// countdown
					data2 << uint8( 7 );		// some sort of flags that require research
				}

				Group * pGroup = m_playerInfo->m_Group;
				if(pGroup)
				{
					pGroup->Lock();
					for(uint32 i = 0; i < pGroup->GetSubGroupCount(); ++i)
					{
						for(GroupMembersSet::iterator itr2 = pGroup->GetSubGroup(i)->GetGroupMembersBegin(); itr2 != pGroup->GetSubGroup(i)->GetGroupMembersEnd(); ++itr2)
						{

                            PlayerInfo *pinfo = *itr2;

							if( pinfo->m_loggedInPlayer && pinfo->m_loggedInPlayer->GetItemInterface()->CanReceiveItem( itemProto, iter->iItemsCount ) == 0 )
							{
								if( pinfo->m_loggedInPlayer->m_passOnLoot )
									iter->roll->PlayerRolled( pinfo->m_loggedInPlayer, 3 );		// passed
								else
									pinfo->m_loggedInPlayer->SendPacket( &data2 );
							}
						}
					}
					pGroup->Unlock();
				}
				else
				{
					m_session->SendPacket(&data2);
				}
			}
		}
		count++;
	}
	data.wpos(13);
	data << uint8( count );

	m_session->SendPacket(&data);

	SetFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_LOOTING );
}
예제 #6
0
파일: Item.cpp 프로젝트: WowDevs/Sandshroud
void Item::LoadFromDB(Field* fields, Player* plr, bool light )
{
    int32 count;
    uint32 itemid = fields[2].GetUInt32(), random_prop = fields[9].GetUInt32(), random_suffix = fields[10].GetUInt32();
    m_itemProto = ItemPrototypeStorage.LookupEntry( itemid );

    ASSERT( m_itemProto );

    if(m_itemProto->LockId > 1)
        locked = true;
    else
        locked = false;

    SetUInt32Value( OBJECT_FIELD_ENTRY, itemid );
    m_owner = plr;

    wrapped_item_id=fields[3].GetUInt32();
    m_uint32Values[ITEM_FIELD_GIFTCREATOR] = fields[4].GetUInt32();
    m_uint32Values[ITEM_FIELD_CREATOR] = fields[5].GetUInt32();

    count = fields[6].GetUInt32();
    if(m_itemProto->MaxCount > 0 && count > m_itemProto->MaxCount)
        count = m_itemProto->MaxCount;
    SetUInt32Value( ITEM_FIELD_STACK_COUNT, count);

    // Again another for that did not indent to make it do anything for more than
    // one iteration x == 0 was the only one executed
    for( uint32 x = 0; x < 5; x++ )
    {
        if( m_itemProto->Spells[x].Id )
        {
            SetUInt32Value( ITEM_FIELD_SPELL_CHARGES + x , fields[7].GetUInt32() );
            break;
        }
    }

    SetUInt32Value( ITEM_FIELD_FLAGS, fields[8].GetUInt32() );
    Bind(ITEM_BIND_ON_PICKUP); // Check if we need to bind our shit.

    if( random_prop )
        SetRandomProperty( random_prop );
    else if( random_suffix )
        SetRandomSuffix( random_suffix );

    SetTextID( fields[11].GetUInt32() );

    SetUInt32Value( ITEM_FIELD_MAXDURABILITY, m_itemProto->MaxDurability );
    SetUInt32Value( ITEM_FIELD_DURABILITY, fields[12].GetUInt32() );

    if( light )
        return;

    string enchant_field = fields[15].GetString();
    vector< string > enchants = StrSplit( enchant_field, ";" );
    uint32 enchant_id;
    EnchantEntry* entry;
    uint32 time_left;
    uint32 enchslot;
    uint32 dummy = 0;

    for( vector<string>::iterator itr = enchants.begin(); itr != enchants.end(); itr++ )
    {
        if( sscanf( (*itr).c_str(), "%u,%u,%u,%u", (unsigned int*)&enchant_id, (unsigned int*)&time_left, (unsigned int*)&enchslot, (unsigned int*)&dummy) > 3 )
        {
            entry = dbcEnchant.LookupEntry( enchant_id );
            if( entry && entry->Id == enchant_id )
            {
                AddEnchantment( entry, time_left, ( time_left == 0 ), false, false, enchslot, 0, ((dummy > 0) ? true : false) );
                //(enchslot != 2) ? false : true, false);
            }
        }
    }

    string gem_field = fields[16].GetString();
    for( uint8 k = 0; k < 3; k++ )
        sscanf( gem_field.c_str(), GemReadFormat[k], &Gems[k]);

    ApplyRandomProperties( false );

    Charter* charter = guildmgr.GetCharterByItemGuid(GetLowGUID());
    if(charter != NULL)
    {
        SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1, charter->GetID());

        // Charter stuff
        if(m_uint32Values[OBJECT_FIELD_ENTRY] == ITEM_ENTRY_GUILD_CHARTER)
        {
            SetUInt32Value( ITEM_FIELD_STACK_COUNT, 1 );
            SetUInt32Value( ITEM_FIELD_PROPERTY_SEED, 57813883 );
            if( plr->m_playerInfo->charterId[CHARTER_TYPE_GUILD] )
                SetUInt32Value( ITEM_FIELD_ENCHANTMENT_1_1, plr->m_playerInfo->charterId[CHARTER_TYPE_GUILD] );
        }

        if( m_uint32Values[OBJECT_FIELD_ENTRY] == ARENA_TEAM_CHARTER_2v2 )
        {
            SetUInt32Value( ITEM_FIELD_STACK_COUNT, 1 );
            SetUInt32Value( ITEM_FIELD_PROPERTY_SEED, 57813883 );
            if( plr->m_playerInfo->charterId[CHARTER_TYPE_ARENA_2V2] )
                SetUInt32Value( ITEM_FIELD_ENCHANTMENT_1_1, plr->m_playerInfo->charterId[CHARTER_TYPE_ARENA_2V2] );
        }

        if( m_uint32Values[OBJECT_FIELD_ENTRY] == ARENA_TEAM_CHARTER_3v3 )
        {
            SetUInt32Value( ITEM_FIELD_STACK_COUNT, 1 );
            SetUInt32Value( ITEM_FIELD_PROPERTY_SEED, 57813883 );
            if( plr->m_playerInfo->charterId[CHARTER_TYPE_ARENA_3V3] )
                SetUInt32Value( ITEM_FIELD_ENCHANTMENT_1_1, plr->m_playerInfo->charterId[CHARTER_TYPE_ARENA_3V3] );
        }

        if( m_uint32Values[OBJECT_FIELD_ENTRY] == ARENA_TEAM_CHARTER_5v5 )
        {
            SetUInt32Value( ITEM_FIELD_STACK_COUNT, 1 );
            SetUInt32Value( ITEM_FIELD_PROPERTY_SEED, 57813883 );
            if( plr->m_playerInfo->charterId[CHARTER_TYPE_ARENA_5V5] )
                SetUInt32Value( ITEM_FIELD_ENCHANTMENT_1_1, plr->m_playerInfo->charterId[CHARTER_TYPE_ARENA_5V5] );
        }
    }
}
예제 #7
0
파일: Item.cpp 프로젝트: lev1976g/easywow
void Item::SaveToDB(int8 containerslot, int8 slot, bool firstsave, QueryBuffer* buf)
{
    if (!m_isDirty && !firstsave)
        return;

    uint64 GiftCreatorGUID = GetGiftCreatorGUID();
    uint64 CreatorGUID = GetCreatorGUID();

    std::stringstream ss;

    ss << "DELETE FROM playeritems WHERE guid = " << GetLowGUID() << ";";

    if (firstsave)
        CharacterDatabase.WaitExecute(ss.str().c_str());
    else
    {
        if (buf == NULL)
            CharacterDatabase.Execute(ss.str().c_str());
        else
            buf->AddQueryNA(ss.str().c_str());
    }

    ss.rdbuf()->str("");

    uint64 ownerGUID = GetOwnerGUID();

    ss << "INSERT INTO playeritems VALUES(";

    ss << (Arcemu::Util::GUID_LOPART(ownerGUID)) << ",";
    ss << GetLowGUID() << ",";
    ss << GetEntry() << ",";
    ss << wrapped_item_id << ",";
    ss << (Arcemu::Util::GUID_LOPART(GiftCreatorGUID)) << ",";
    ss << (Arcemu::Util::GUID_LOPART(CreatorGUID)) << ",";

    ss << GetStackCount() << ",";
    ss << int32(GetChargesLeft()) << ",";
    ss << uint32(m_uint32Values[ITEM_FIELD_FLAGS]) << ",";
    ss << random_prop << ", " << random_suffix << ", ";
    ss << 0 << ",";
    ss << GetDurability() << ",";
    ss << static_cast<int>(containerslot) << ",";
    ss << static_cast<int>(slot) << ",'";

    // Pack together enchantment fields
    if (Enchantments.size() > 0)
    {
        EnchantmentMap::iterator itr = Enchantments.begin();
        for (; itr != Enchantments.end(); ++itr)
        {
            if (itr->second.RemoveAtLogout)
                continue;

            uint32 elapsed_duration = uint32(UNIXTIME - itr->second.ApplyTime);
            int32 remaining_duration = itr->second.Duration - elapsed_duration;
            if (remaining_duration < 0)
                remaining_duration = 0;

            if (itr->second.Enchantment && (remaining_duration > 5 || itr->second.Duration == 0))
            {
                ss << itr->second.Enchantment->Id << ",";
                ss << remaining_duration << ",";
                ss << itr->second.Slot << ";";
            }
        }
    }
    ss << "','";
    ss << ItemExpiresOn << "','";

    ////////////////////////////////////////////////// Refund stuff /////////////////////////////////

    // Check if the owner is instantiated. When sending mail he/she obviously will not be :P
    if (this->GetOwner() != NULL)
    {
        std::pair< time_t, uint32 > refundentry;

        refundentry.first = 0;
        refundentry.second = 0;

        refundentry = this->GetOwner()->GetItemInterface()->LookupRefundable(this->GetGUID());

        ss << uint32(refundentry.first) << "','";
        ss << uint32(refundentry.second);
    }
    else
    {
        ss << uint32(0) << "','";
        ss << uint32(0);
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////
    ss << "','";
    ss << text;
    ss << "')";

    if (firstsave)
        CharacterDatabase.WaitExecute(ss.str().c_str());
    else
    {
        if (buf == NULL)
            CharacterDatabase.Execute(ss.str().c_str());
        else
            buf->AddQueryNA(ss.str().c_str());
    }

    m_isDirty = false;
}