//o---------------------------------------------------------------------------o //| Function : void completeTrade( CItem *tradeWindowOne, CItem *tradeWindowTwo, bool tradeSuccess ) //| Date : February 2, 2006 //| Programmer : giwo //o---------------------------------------------------------------------------o //| Purpose : Handles everything necesarry to complete a trade //o---------------------------------------------------------------------------o void completeTrade( CItem *tradeWindowOne, CItem *tradeWindowTwo, bool tradeSuccess ) { CChar *p1 = FindItemOwner( tradeWindowOne ); CChar *p2 = FindItemOwner( tradeWindowTwo ); if( !ValidateObject( p1 ) || !ValidateObject( p2 ) ) return; CSocket *mSock = p1->GetSocket(); if( mSock != NULL ) { CPSecureTrading cpstOne( (*tradeWindowOne) ); cpstOne.Action( 1 ); mSock->Send( &cpstOne ); } CSocket *nSock = p2->GetSocket(); if( nSock != NULL ) { CPSecureTrading cpstTwo( (*tradeWindowTwo) ); cpstTwo.Action( 1 ); nSock->Send( &cpstTwo ); } CItem *i = NULL; CItem *bp1 = p1->GetPackItem(); CItem *bp2 = p2->GetPackItem(); if( ValidateObject( bp1 ) && ValidateObject( bp2 ) ) { CDataList< CItem * > *c1Cont = tradeWindowOne->GetContainsList(); for( i = c1Cont->First(); !c1Cont->Finished(); i = c1Cont->Next() ) { if( ValidateObject( i ) ) { if( tradeSuccess ) i->SetCont( bp2 ); else i->SetCont( bp1 ); i->PlaceInPack(); } } CDataList< CItem * > *c2Cont = tradeWindowTwo->GetContainsList(); for( i = c2Cont->First(); !c2Cont->Finished(); i = c2Cont->Next() ) { if( ValidateObject( i ) ) { if( tradeSuccess ) i->SetCont( bp1 ); else i->SetCont( bp2 ); i->PlaceInPack(); } } } tradeWindowOne->Delete(); tradeWindowTwo->Delete(); }
void sendTradeStatus( CItem *tradeWindowOne, CItem *tradeWindowTwo ) { CChar *p1 = FindItemOwner( tradeWindowOne ); CChar *p2 = FindItemOwner( tradeWindowTwo ); if( !ValidateObject( p1 ) || !ValidateObject( p2 ) ) return; CSocket *s1 = p1->GetSocket(); CSocket *s2 = p2->GetSocket(); if( s1 != NULL && s2 != NULL ) sendTradeStatus( s1, s2, tradeWindowOne, tradeWindowTwo ); }
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; }
//o---------------------------------------------------------------------------o //| Function - bool checkItemRange( CChar *mChar, CItem *i, UI16 distance ) //| Programmer - Unknown //o---------------------------------------------------------------------------o //| Purpose - Checks if an item is within reach //o---------------------------------------------------------------------------o bool checkItemRange( CChar *mChar, CItem *i ) { if( mChar->IsGM() || mChar->IsCounselor() ) return true; CBaseObject *itemOwner = i; bool checkRange = false; if( i->GetCont() != NULL ) // It's inside another container, we need root container to calculate distance { ObjectType objType = OT_CBO; CBaseObject *iOwner = FindItemOwner( i, objType ); if( iOwner != NULL ) itemOwner = iOwner; } if( itemOwner == mChar ) checkRange = true; else checkRange = objInRange( mChar, itemOwner, DIST_NEARBY ); return checkRange; }
//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; }