int __cdecl StExt_BuildItemsSellForm()
{
zCParser* par = zCParser::GetParser();
if (!player || !player->inventory2.GetContents())
{
DEBUG_MSG("StExt_BuildItemsSellForm - player seems not initialized!");
return False;
}
const int callBackFunc = par->GetIndex("StExt_BuildItemsSellForm_Loop");
if (callBackFunc == Invalid)
{
DEBUG_MSG("StExt_BuildItemsSellForm - func 'StExt_BuildItemsSellForm_Loop' not found!");
return False;
}
Array<int> excludedItems = {};
zCPar_Symbol* exludedItemsArr = par->GetSymbol("StExt_ItemsSellForm_ExcludedItems");
if (exludedItemsArr)
{
uint arrSize = exludedItemsArr->ele;
for (uint i = 0; i < arrSize; ++i)
{
int indx = par->GetIndex(exludedItemsArr->stringdata[i]);
if (indx != Invalid) excludedItems.InsertEnd(indx);
}
}
excludedItems.QuickSort();
int mainFlag = 0, flags = 0, allowGenerated = FALSE, priceMultRaw = 10;
par->GetParameter(priceMultRaw);
par->GetParameter(allowGenerated);
par->GetParameter(flags);
par->GetParameter(mainFlag);
const bool hasExcluded = !excludedItems.IsEmpty();
const float priceMult = ((priceMultRaw * 0.01f) < 0.01f) ? 0.01f : priceMultRaw * 0.01f;
zCListSort<oCItem>* it = player->inventory2.GetContents()->GetNextInList();
while (it)
{
oCItem* pItem = it->GetData();
if (pItem)
{
bool canSell = true;
if (canSell && pItem->HasFlag(ITM_FLAG_ACTIVE)) { canSell = false; }
if (canSell && HasFlag(pItem->hitp, bit_item_questitem)) { canSell = false; }
if (canSell && hasExcluded && excludedItems.HasEqualSorted(pItem->GetInstance())) { canSell = false; }
if (canSell && allowGenerated && IsExtendedItem(pItem)) { canSell = false; }
if (canSell && (mainFlag != 0) && !HasFlag(pItem->mainflag, mainFlag)) { canSell = false; }
if (canSell && (flags != 0) && !pItem->HasFlag(flags)) { canSell = false; }
if (canSell)
{
const int sellPrice = static_cast<int>(pItem->value * priceMult);
CraftInfoData craftData = CraftInfoData();
craftData.Price = sellPrice <= 0 ? 1 : sellPrice;
craftData.ResultInstance = pItem->GetInstanceName();
par->SetInstance("STEXT_CRAFTINFO", &craftData);
par->CallFunc(callBackFunc);
par->SetInstance("STEXT_CRAFTINFO", Null);
}
}
it = it->GetNextInList();
}