Exemple #1
0
	bool Accept(ExtraContainerChanges::EntryData* pEntryData) {
		if (pEntryData) {
			// quick check - needs an extendData or can't be equipped
			ExtraContainerChanges::ExtendDataList* pExtendList = pEntryData->extendData;
			if (pExtendList && m_matcher.Matches(pEntryData->type)) { 
				SInt32 n = 0;
				ExtraDataList* pExtraDataList = pExtendList->GetNthItem(n);
				while (pExtraDataList) {
					if (pExtraDataList->HasType(kExtraData_Worn) || pExtraDataList->HasType(kExtraData_WornLeft)) {
						m_found.pForm = pEntryData->type;
						m_found.pExtraData = pExtraDataList;
						return false;
					}
					n++;
					pExtraDataList = pExtendList->GetNthItem(n);
				}
			}
		}
		return true;
	}
// Assumes there is only one such Item in the container
TESForm * SetFirstItemWithHealthAndOwnershipByRefID(TESObjectREFR* thisObj, UInt32 refID, SInt32 NumItems, float Health, TESForm* pOwner, UInt32 Rank)
{
	if (!thisObj) return NULL;
	if ((Health == -1.0) && (pOwner == NULL) && (Rank == 0)) return NULL; // Nothing to modify!

	ExtraContainerChanges* pXContainerChanges = static_cast<ExtraContainerChanges*>(thisObj->extraDataList.GetByType(kExtraData_ContainerChanges));
	if (!pXContainerChanges)
		return AddItemHealthPercentOwner(thisObj, refID, NumItems, Health, pOwner, Rank);

	if (!pXContainerChanges->GetEntryDataList())
		return AddItemHealthPercentOwner(thisObj, refID, NumItems, Health, pOwner, Rank);
	ExtraContainerInfo info(pXContainerChanges->GetEntryDataList());

	ExtraContainerChanges::EntryData* pEntryData = info.GetRefID(refID);
	if (!pEntryData)
		return AddItemHealthPercentOwner(thisObj, refID, NumItems, Health, pOwner, Rank);

	ExtraContainerChanges::ExtendDataList* pExtendList = pEntryData->extendData;
	if (!pExtendList) 
		return AddItemHealthPercentOwner(thisObj, refID, NumItems, Health, pOwner, Rank);

	if (!pEntryData) 
		return AddItemHealthPercentOwner(thisObj, refID, NumItems, Health, pOwner, Rank);

	bool Done = false;
	TESHealthForm* pHealth = DYNAMIC_CAST(thisObj->baseForm, TESForm, TESHealthForm);
	ExtraHealth* pXHealth = NULL;
	ExtraOwnership* pXOwner = NULL;
	ExtraRank* pXRank = NULL;
	ExtraCount* pXCount = NULL;
	ExtraDataList* pExtraDataList = NULL;

	pEntryData->countDelta = NumItems;
	SInt32 n = 0;
	pExtraDataList = pExtendList->GetNthItem(n); // Only one will be set, the first one 
	pXHealth = (ExtraHealth*)pExtraDataList->GetByType(kExtraData_Health);
	pXCount = (ExtraCount*)pExtraDataList->GetByType(kExtraData_Count);
	pXOwner  = (ExtraOwnership*)pExtraDataList->GetByType(kExtraData_Ownership);
	pXRank  = (ExtraRank*)pExtraDataList->GetByType(kExtraData_Rank);
	if (!pXHealth) {
		if (Health != -1.0) {
			pXHealth = ExtraHealth::Create();
			if (!pExtraDataList->Add(pXHealth))
				FormHeap_Free(pXHealth);
			else
				pXHealth->health = Health;
		}
	}
	else
		if (Health != -1.0)
			if (Health==pHealth->health)
				pExtraDataList->Remove(pXHealth);
			else
				pXHealth->health = Health;
	if (!pXOwner) {
		if (pOwner) {
			pXOwner = ExtraOwnership::Create();
			if (!pExtraDataList->Add(pXOwner))
				FormHeap_Free(pXOwner);
			else
				pXOwner->owner = pOwner;
		}
	}
	else
		if (pOwner)
			pXOwner->owner = pOwner;
		else
			pExtraDataList->Remove(pXOwner);
	if (!pXRank) {
		if (Rank) {
			pXRank = ExtraRank::Create();
			if (!pExtraDataList->Add(pXRank))
				FormHeap_Free(pXRank);
			else
				pXRank->rank = Rank;
		}
	}
	else
		if (Rank)
			pXRank->rank = Rank;
		else
			pExtraDataList->Remove(pXRank);

	if (pXCount)
		pXCount->count = NumItems;
	
	return pEntryData->type;
}