Пример #1
0
//o--------------------------------------------------------------------------o
//|	Function		-	SI32 CWeight::calcWeight( CItem *pack )
//|	Date			-	2/23/2003
//|	Developers		-	Zane
//|	Organization	-	UOX3 DevTeam
//o--------------------------------------------------------------------------o
//|	Description		-	Calculate the total weight of a pack based upon all items inside,
//|							their amounts, etc. This function should never need to be called
//|							but is available for bruteforce weight updating
//o--------------------------------------------------------------------------o
SI32 CWeight::calcWeight( CItem *pack )
{
    SI32 totalWeight = 0;
    SI32 contWeight = 0;

    CDataList< CItem * > *pCont = pack->GetContainsList();
    for( CItem *i = pCont->First(); !pCont->Finished(); i = pCont->Next() )
    {
        if( !ValidateObject( i ) )
            continue;

        if( i->IsContType() )	// Item is a container
        {
            CTile& tile = Map->SeekTile( i->GetID() );
            contWeight = static_cast<SI32>( tile.Weight() * 100);	// Add the weight of the container
            contWeight += calcWeight( i );	// Find and add the weight of the items in the container
            i->SetWeight( contWeight, false );		// Also update the weight property of the container
            totalWeight += contWeight;
            if( totalWeight >= MAX_WEIGHT )
                return MAX_WEIGHT;
        }
        else
        {
            if( !calcAddWeight( i, totalWeight ) )
                return MAX_WEIGHT;
        }
    }
    return totalWeight;
}
Пример #2
0
//o---------------------------------------------------------------------------o
//|   Function   : void restockNPC(CChar *i, bool stockAll)
//|   Date       : Unknown
//|   Programmer : UOX3 DevTeam
//o---------------------------------------------------------------------------o
//|   Purpose    : Restock NPC Vendors
//o---------------------------------------------------------------------------o
void restockNPC(CChar& i, bool stockAll)
{
    if (!i.IsShop())
        return; // if we aren't a shopkeeper, why bother?

    CItem *ci = i.GetItemAtLayer(IL_SELLCONTAINER);
    if (ValidateObject(ci))
    {
        CDataList< CItem * > *ciCont = ci->GetContainsList();
        for (CItem *c = ciCont->First(); !ciCont->Finished(); c = ciCont->Next())
            if (ValidateObject(c))
            {
                if (stockAll)
                {
                    c->IncAmount(c->GetRestock());
                    c->SetRestock(0);
                }
                else if (c->GetRestock())
                {
                    UI16 stockAmt = UOX_MIN(c->GetRestock(), static_cast<UI16>((c->GetRestock() / 2) + 1));
                    c->IncAmount(stockAmt);
                    c->SetRestock(c->GetRestock() - stockAmt);
                }

                if (cwmWorldState->ServerData()->TradeSystemStatus()) 
                {
                    CTownRegion *tReg = calcRegionFromXY(i.GetX(), i.GetY(), i.WorldNumber());
                    Items->StoreItemRandomValue(c, tReg);
                }
            }
    }
}
Пример #3
0
bool clearTradesFunctor( CBaseObject *a, UI32 &b, void *extraData )
{
	bool retVal = true;
	if( ValidateObject( a ) && a->CanBeObjType( OT_ITEM ) )
	{
		// Body of the functor goes here
		CItem *i = static_cast< CItem * >(a);
		if( ValidateObject( i ) )
		{
			if( i->GetType() == IT_TRADEWINDOW )
			{
				CChar *k = FindItemOwner( i );
				if( ValidateObject( k ) )
				{
					CItem *p = k->GetPackItem();
					if( ValidateObject( p ) )
					{
						CDataList< CItem * > *iCont = i->GetContainsList();
						for( CItem *j = iCont->First(); !iCont->Finished(); j = iCont->Next() )
						{
							if( ValidateObject( j ) )
								j->SetCont( p );
						}
					}
				}
				i->Delete();
				++b;	// let's track how many we cleared
			}
		}
	}
	return retVal;
}
Пример #4
0
void Scope(const char *title, std::vector<double> &values)
{
	const CColor col1 ( 200,  40,  20 );

	CDataList plot;
	
	CData *dat = new CData;
	try
	{
		dat->SetSignalName(title);
		dat->SetDrawingOptions(col1);
		dat->Read(values);
		plot.Add(dat);

		plot.Show(-500, 500);
	} catch (const char *) {};
}
Пример #5
0
void QuickSort(CDataList<Keytype, Infotype>& L, const int left, const int right)
{
	if (left < right)
	{
		int pivotpos = L.Partition(left, right);
		QuickSort(L, left, pivotpos - 1);
		QuickSort(L, pivotpos + 1, right);
	}
}
Пример #6
0
CDataList::CDataList(CDataList& dataList)
{
	m_csName = dataList.GetName();
	m_csDefault = dataList.GetDefault();
	m_DataList.AddTail(&dataList.GetData());
}
Пример #7
0
//o---------------------------------------------------------------------------o
//|   Function   : void sellItem(CSocket *mSock)
//|   Date       : Unknown
//|   Programmer : UOX3 DevTeam
//o---------------------------------------------------------------------------o
//|   Purpose    : Player sells an item to the vendor
//o---------------------------------------------------------------------------o
bool CPISellItem::Handle(void)
{
    if (tSock->GetByte(8) != 0)
    {
        CChar *mChar = tSock->CurrcharObj();
        CChar *n = calcCharObjFromSer(tSock->GetDWord(3));
        if (!ValidateObject(n) || !ValidateObject(mChar))
            return true;

        CItem *buyPack = n->GetItemAtLayer(IL_BUYCONTAINER);
        CItem *boughtPack = n->GetItemAtLayer(IL_BOUGHTCONTAINER);
        CItem *sellPack = n->GetItemAtLayer(IL_SELLCONTAINER);
        if (!ValidateObject(buyPack) || !ValidateObject(sellPack) || !ValidateObject(boughtPack))
            return true;

        CItem *j = NULL, *k = NULL, *l = NULL;
        UI16 amt = 0, maxsell = 0;
        UI08 i = 0;
        UI32 totgold = 0, value = 0;
        for (i = 0; i < tSock->GetByte(8); ++i)
        {
            j = calcItemObjFromSer(tSock->GetDWord(9 + (6*i)));
            amt = tSock->GetWord(13 + (6*i));
            maxsell += amt;
        }

        if (maxsell > cwmWorldState->ServerData()->SellMaxItemsStatus())
        {
            n->TextMessage(NULL, 1342, TALK, false, mChar->GetName().c_str(), cwmWorldState->ServerData()->SellMaxItemsStatus());
            return true;
        }

        for (i = 0; i < tSock->GetByte(8); ++i)
        {
            j = calcItemObjFromSer(tSock->GetDWord(9 + (6*i)));
            amt = tSock->GetWord(13 + (6*i));
            if (ValidateObject(j))
            {
                if (j->GetAmount() < amt || FindItemOwner(j) != mChar)
                {
                    n->TextMessage(NULL, 1343, TALK, false);
                    return true;
                }

                // Check if onSellToVendor JS event is present for each item being sold
                // If true, and a value of "false" has been returned from the script, halt the sale
                UI16 targTrig = j->GetScriptTrigger();
                cScript *toExecute = JSMapping->GetScript(targTrig);
                if (toExecute != NULL)
                    if (toExecute->OnSellToVendor(tSock, n, j))
                        return true;

                CItem *join = NULL;
                CDataList<CItem *> *pCont = boughtPack->GetContainsList();
                for (k = pCont->First(); !pCont->Finished(); k = pCont->Next())
                    if (ValidateObject(k))
                        if (k->GetID() == j->GetID() && j->GetType() == k->GetType())
                            join = k;

                pCont = buyPack->GetContainsList();
                for (k = pCont->First(); !pCont->Finished(); k = pCont->Next())
                    if (ValidateObject(k))
                        if (k->GetID() == j->GetID() && j->GetType() == k->GetType())
                            value = calcValue(j, k->GetSellValue());

                // If an object already exist in the boughtPack that this one can be joined to...
                if (ValidateObject(join))
                {
                    join->IncAmount(amt);
                    join->SetRestock(join->GetRestock() - amt);
                    l = join;

                    totgold += (amt * value);
                    if (j->GetAmount() == amt)
                        j->Delete();
                    else
                        j->IncAmount(-amt);
                }
                else
                {
                    //Otherwise, move this item to the vendor's boughtPack
                    totgold += (amt * value);

                    if (j->GetAmount() != amt) 
                    {
                        l = Items->DupeItem(tSock, j, amt);
                        j->SetAmount(j->GetAmount() - amt);
                    }
                    else
                        l = j;

                    if (ValidateObject(l))
                        l->SetCont(boughtPack);
                }

                if (l)
                {
                    cScript *toGrab = JSMapping->GetScript(l->GetScriptTrigger());
                    if (toGrab != NULL)
                        toGrab->OnSoldToVendor(tSock, n, l);
                }
            }
        }

        Effects->goldSound(tSock, totgold);
        while (totgold > MAX_STACK)
        {
            Items->CreateScriptItem(tSock, mChar, "0x0EED", MAX_STACK, OT_ITEM, true);
            totgold -= MAX_STACK;
        }

        if (totgold > 0)
            Items->CreateScriptItem(tSock, mChar, "0x0EED", totgold, OT_ITEM, true);
    }
    
    CPBuyItem clrSend;
    clrSend.Serial(tSock->GetDWord(3));
    tSock->Send(&clrSend);
    return true;
}