예제 #1
0
파일: vendor.cpp 프로젝트: Kitiara/UOX3
//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);
                }
            }
    }
}
예제 #2
0
파일: trade.cpp 프로젝트: bholtsclaw/uox3
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;
}
예제 #3
0
파일: vendor.cpp 프로젝트: Kitiara/UOX3
//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;
}