Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29692
Modified Files:
ChangeLog items.cpp items.h pythonscript.cpp pythonscript.h
trade.cpp trade.h
Log Message:
vendor code.
Index: items.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/items.h,v
retrieving revision 1.216
retrieving revision 1.217
diff -C2 -d -r1.216 -r1.217
*** items.h 14 Sep 2004 23:03:16 -0000 1.216
--- items.h 22 Sep 2004 05:34:47 -0000 1.217
***************
*** 315,318 ****
--- 315,319 ----
void toBackpack( P_CHAR pChar );
void showName( cUOSocket* socket );
+ unsigned int getSellPrice(P_CHAR vendor);
void setMagic( uchar data )
Index: trade.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/trade.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** trade.cpp 22 Sep 2004 04:09:31 -0000 1.12
--- trade.cpp 22 Sep 2004 05:34:47 -0000 1.13
***************
*** 320,326 ****
continue;
! if ( ( *it )->id() == pItem->id() && ( *it )->color() == pItem->color() &&
! // (*it)->amount() >= pItem->amount() &&
! ( *it )->scriptList() == pItem->scriptList() )
{
found = true;
--- 320,324 ----
continue;
! if ( ( *it )->baseid() == pItem->baseid() && ( *it )->scriptList() == pItem->scriptList() )
{
found = true;
***************
*** 337,343 ****
// now look for the item in the player's pack
! sContent = pPack->content();
! if ( find_if( sContent.begin(), sContent.end(), bind2nd( MatchItemAndSerial(), pItem->serial() ) ) == sContent.end() )
! {
socket->sysMessage( tr( "Invalid item sold." ) );
socket->send( &clearBuy );
--- 335,339 ----
// now look for the item in the player's pack
! if (pItem->container() != pPack) {
socket->sysMessage( tr( "Invalid item sold." ) );
socket->send( &clearBuy );
***************
*** 345,349 ****
}
! totalValue += amount * pItem->sellprice();
items.insert( make_pair( pItem->serial(), amount ) );
--- 341,353 ----
}
! unsigned int sellprice = pItem->getSellPrice(pVendor);
!
! if (!sellprice) {
! socket->sysMessage( tr( "Invalid item sold." ) );
! socket->send( &clearBuy );
! return;
! }
!
! totalValue += amount * sellprice;
items.insert( make_pair( pItem->serial(), amount ) );
***************
*** 385,520 ****
pChar->giveGold( totalValue, false );
}
- P_ITEM Trade::startTrade( P_CHAR pPlayer, P_CHAR pChar )
- {
- /* if( !pChar || !pChar->socket() || !pPlayer || !pPlayer->socket() )
- return NULL;
- // Create a trade-container for both players
- // 0x2AF8 on Layer 0x1F
- SERIAL box1,box2;
- // One for our player
- P_ITEM tCont = cItem::createFromScript( "2af8" );
- tCont->setLayer( 0x1f );
- // tCont->setContSerial( pPlayer->serial() );
- tCont->setOwner( pPlayer );
- tCont->tags.set( "tradepartner", cVariant( pChar->serial() ) );
- tCont->update( pPlayer->socket() );
- tCont->update( pChar->socket() );
- box1 = tCont->serial();
- // One for the tradepartner
- tCont = tCont->dupe();
- tCont->setLayer( 0x1f );
- // tCont->setContSerial( pChar->serial() );
- tCont->setOwner( pChar );
- tCont->tags.set( "tradepartner", cVariant( pPlayer->serial() ) );
- tCont->update( pPlayer->socket() );
- tCont->update( pChar->socket() );
- box2 = tCont->serial();
- // Now send the both secure trading packets
- cUOTxTrade trade;
- // To us
- trade.setPartner( pChar->serial() );
- trade.setBox1( box1 );
- trade.setBox2( box2 );
- trade.setName( pChar->name.latin1() );
- pPlayer->socket()->send( &trade );
- // To the other
- trade.setPartner( pPlayer->serial() );
- trade.setBox1( box2 );
- trade.setBox2( box1 );
- trade.setName( pPlayer->name.latin1() );
- pChar->socket()->send( &trade );
- return FindItemBySerial( box1 );*/
- return 0;
- }
-
- P_ITEM Trade::tradestart( cUOSocket* s, P_CHAR pc_i )
- {
- /* P_CHAR pc_currchar = currchar[s];
- unsigned char msg[90];
- P_ITEM pi_bps = pc_currchar->getBackpack();
- P_ITEM pi_bpi = pc_i->getBackpack();
- UOXSOCKET s2 = calcSocketFromChar(pc_i);
- if (pi_bps == NULL) //LB
- {
- sysmessage(s, "Time to buy a backpack!");
- sysmessage(s2, "%s doesnt have a backpack!", pc_currchar->name.latin1());
- return 0;
- }
- if (pi_bpi == NULL)
- {
- sysmessage(s2, "Time to buy a backpack!");
- sysmessage(s, "%s doesnt have a backpack!", pc_i->name.latin1());
- return 0;
- }
- P_ITEM pi_ps = Items->SpawnItem(s2, pc_currchar, 1, "#", 0, 0x1E, 0x5E, 0, 0, 0);
- if(pi_ps == NULL)
- return 0;
- pi_ps->pos = Coord_cl(26, 0, 0);
- // pi_ps->setContSerial(pc_currchar->serial());
- pi_ps->setLayer( 0 );
- pi_ps->setType( 1 );
- pi_ps->setDye(0);
- // sendbpitem(s, pi_ps);
- // if (s2 != INVALID_UOXSOCKET)
- // sendbpitem(s2, pi_ps);
- P_ITEM pi_pi = Items->SpawnItem(s2,pc_i,1,"#",0,0x1E,0x5E,0,0,0);
- if (pi_pi == NULL)
- return 0;
- pi_pi->pos = Coord_cl(26, 0, 0);
- // pi_pi->setContSerial(pc_i->serial());
- pi_pi->setLayer( 0 );
- pi_pi->setType( 1 );
- pi_pi->setDye(0);
- // sendbpitem(s, pi_pi);
- // if (s2 != INVALID_UOXSOCKET)
- // sendbpitem(s2, pi_pi);
- pi_pi->setMoreb1( static_cast<unsigned char>((pi_ps->serial()&0xFF000000)>>24) );
- pi_pi->setMoreb2( static_cast<unsigned char>((pi_ps->serial()&0x00FF0000)>>16) );
- pi_pi->setMoreb3( static_cast<unsigned char>((pi_ps->serial()&0x0000FF00)>>8) );
- pi_pi->setMoreb4( static_cast<unsigned char>((pi_ps->serial()&0x000000FF)) );
- pi_ps->setMore1( static_cast<unsigned char>((pi_pi->serial()&0xFF000000)>>24) );
- pi_ps->setMore2( static_cast<unsigned char>((pi_pi->serial()&0x00FF0000)>>16) );
- pi_ps->setMore3( static_cast<unsigned char>((pi_pi->serial()&0x0000FF00)>>8) );
- pi_ps->setMore4( static_cast<unsigned char>((pi_pi->serial()&0x000000FF)) );
- pi_ps->setMoreZ(0);
- pi_pi->setMoreZ(0);
- msg[0] = 0x6F; // Header Byte
- msg[1] = 0; // Size
- msg[2] = 47; // Size
- msg[3] = 0; // Initiate
- LongToCharPtr(pc_i->serial(),msg+4);
- LongToCharPtr(pi_ps->serial(),msg+8);
- LongToCharPtr(pi_pi->serial(),msg+12);
- msg[16]=1;
- strcpy((char*)&(msg[17]), pc_i->name.latin1());
- Xsend(s, msg, 47);
- if (s2 != INVALID_UOXSOCKET)
- {
- msg[0]=0x6F; // Header Byte
- msg[1]=0; // Size
- msg[2]=47; // Size
- msg[3]=0; // Initiate
- LongToCharPtr(pc_currchar->serial(),msg+4);
- LongToCharPtr(pi_pi->serial(),msg+8);
- LongToCharPtr(pi_ps->serial(),msg+12);
- msg[16]=1;
- strcpy((char*)&(msg[17]), pc_currchar->name.latin1());
- Xsend(s2, msg, 47);
- } */
- return 0;
- }
-
- void Trade::clearalltrades()
- {
- }
-
- void Trade::trademsg( int s )
- {
- }
-
- void Trade::dotrade( P_ITEM cont1, P_ITEM cont2 )
- {
- }
}
--- 389,394 ----
pChar->giveGold( totalValue, false );
+ socket->sendStatWindow(); // Update Gold
}
}
Index: ChangeLog
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/ChangeLog,v
retrieving revision 1.73
retrieving revision 1.74
diff -C2 -d -r1.73 -r1.74
*** ChangeLog 22 Sep 2004 04:09:31 -0000 1.73
--- ChangeLog 22 Sep 2004 05:34:46 -0000 1.74
***************
*** 46,49 ****
--- 46,51 ----
- Fixed a bug with multis that would be put into themselves if moved.
- Fixed a crashbug related to vendors.
+ - Added the ability to dynamically determine the sell value of an item using the
+ onGetSellPrice event.
Wolfpack 12.9.10 Beta (10. September 2004)
Index: pythonscript.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/pythonscript.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** pythonscript.h 4 Sep 2004 21:20:07 -0000 1.40
--- pythonscript.h 22 Sep 2004 05:34:47 -0000 1.41
***************
*** 86,89 ****
--- 86,90 ----
EVENT_SPAWN,
EVENT_UPDATEDATABASE,
+ EVENT_GETSELLPRICE,
EVENT_COUNT,
};
Index: items.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/items.cpp,v
retrieving revision 1.450
retrieving revision 1.451
diff -C2 -d -r1.450 -r1.451
*** items.cpp 19 Sep 2004 16:25:36 -0000 1.450
--- items.cpp 22 Sep 2004 05:34:46 -0000 1.451
***************
*** 2342,2343 ****
--- 2342,2387 ----
return pos_;
}
+
+ unsigned int cItem::getSellPrice(P_CHAR pVendor) {
+ unsigned int sellprice = this->sellprice();
+ bool fromItem = false;
+ bool itemCanHandle = canHandleEvent(EVENT_GETSELLPRICE);
+ bool npcCanHandle = pVendor->canHandleEvent(EVENT_GETSELLPRICE);
+ PyObject *args = 0;
+
+ if (itemCanHandle || npcCanHandle) {
+ args = Py_BuildValue("(NN)", getPyObject(), pVendor->getPyObject());
+ }
+
+ if (itemCanHandle) {
+ PyObject *result = callEvent(EVENT_GETSELLPRICE, args);
+ if (result) {
+ if (PyInt_CheckExact(result)) {
+ sellprice = PyInt_AsLong(result);
+ fromItem = true;
+ } else if (PyLong_CheckExact(result)) {
+ sellprice = PyLong_AsLong(result);
+ fromItem = true;
+ }
+ }
+ Py_XDECREF(result);
+ }
+
+ if (npcCanHandle && !fromItem) {
+ PyObject *result = pVendor->callEvent(EVENT_GETSELLPRICE, args);
+ if (result) {
+ if (PyInt_CheckExact(result)) {
+ sellprice = PyInt_AsLong(result);
+ fromItem = true;
+ } else if (PyLong_CheckExact(result)) {
+ sellprice = PyLong_AsLong(result);
+ fromItem = true;
+ }
+ }
+ Py_XDECREF(result);
+ }
+
+ Py_XDECREF(args);
+
+ return sellprice;
+ }
Index: pythonscript.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/pythonscript.cpp,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** pythonscript.cpp 4 Sep 2004 21:20:07 -0000 1.48
--- pythonscript.cpp 22 Sep 2004 05:34:47 -0000 1.49
***************
*** 519,522 ****
--- 519,533 ----
"onUpdateDatabase",
+ /*
+ \event onGetSellPrice
+ \param item The item being checked.
+ \param vendor The vendor buying the item. This could be None.
+ \return None if your event does not know the price. An integer
+ value otherwise.
+ \condition This event is triggered to get the sellprice for an item.
+ It's triggered for the item, then for the npc and then for the global hook.
+ */
+ "onGetSellPrice",
+
0
};
Index: trade.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/trade.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** trade.h 2 Jun 2004 15:04:07 -0000 1.3
--- trade.h 22 Sep 2004 05:34:47 -0000 1.4
***************
*** 39,51 ****
namespace Trade
{
- P_ITEM startTrade( P_CHAR pPlayer, P_CHAR pChar );
-
void buyAction( cUOSocket* socket, cUORxBuy* packet );
void sellAction( cUOSocket* socket, cUORxSell* packet );
-
- P_ITEM tradestart( cUOSocket* s, P_CHAR pc_i );
- void clearalltrades();
- void trademsg( int s );
- void dotrade( P_ITEM cont1, P_ITEM cont2 );
};
--- 39,44 ----
|