Skip to content

How to use an item to full hp

kytooooo edited this page Jun 30, 2019 · 3 revisions

Please debug the project "NFItemBagPlugin" to know the item management system.


bool NFItemModule::AfterInit()
{

	m_pKernelModule->AddClassCallBack(NFrame::Player::ThisName(), this, &NFItemModule::OnClassObjectEvent);
	CheckConfig();

	//////////////////////////////////////////////////////////////////////////
	// add msg handler
	if (!m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_ITEM_OBJECT, this, &NFItemModule::OnClientUseItem)) { return false; }
	if (!m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_PICK_ITEM, this, &NFItemModule::OnClientPickItem)) { return false; }


	return true;
}



bool NFItemModule::UseItem(const NFGUID & self, const std::string & strItemID, const NFGUID & xTargetID, const NFVector3& vector)
{
	int nCount = 1;
	if (!m_pElementModule->ExistElement(strItemID) || !m_pKernelModule->GetObject(xTargetID))
	{
		return false;
	}

	if (!ConsumeDataItemProperty(self, strItemID))
	{
		return false;
	}

	if (!m_pPackModule->DeleteItem(self, strItemID, nCount))
	{
		return false;
	}

	NFMsg::EItemType eItemType = (NFMsg::EItemType)m_pElementModule->GetPropertyInt(strItemID, NFrame::Item::ItemType());
	NF_SHARE_PTR<NFIItemConsumeocessModule> pConsumeProcessModule = m_pItemConsumeManagerModule->GetConsumeModule(eItemType);
	if (!pConsumeProcessModule)
	{
		return false;
	}

	switch (eItemType)
	{
	case NFMsg::EItemType::EIT_EQUIP:
	case NFMsg::EItemType::EIT_GEM:
	case NFMsg::EItemType::EIT_SCROLL:
	{
		if (pConsumeProcessModule->ConsumeLegal(self, strItemID, NFDataList(), vector) == 0)
		{
			pConsumeProcessModule->ConsumeProcess(self, strItemID, NFDataList(), vector);
		}
	}
	break;
	case NFMsg::EItemType::EIT_SUPPLY:
	{
		NFDataList xTarget;
		xTarget.AddObject(xTargetID);
		xTarget.AddString(strItemID);	//this is Item Config ID
		xTarget.AddInt(nCount);	//this is Item Count to Consume

		if (pConsumeProcessModule->ConsumeLegal(self, strItemID, xTarget, vector) == 0)
		{
			pConsumeProcessModule->ConsumeProcess(self, strItemID, xTarget, vector);
		}
	}
	break;
	break;
	default:
		break;
	}

	/*	AddItemEffectDataProperty(self, xTargetID, strItemID);

	const std::string& strAwardPackID = m_pElementModule->GetPropertyString(strItemID, "AwardData");
	if (!strAwardPackID.empty())
	{
	DoAwardPack( self, strAwardPackID);
	}
	*/
	return false;
}