int p;
void buyaction(int s){	char clearmsg[8];	int clear, i, j;	int buyit[512];	int amount[512];	int layer[512];	int playergoldtotal;	int goldtotal;	int itemtotal;	int npc;	int soldout;	int p;	int tmpvalue=0; // Fixed for adv trade system -- Magius(CHE) 	CHARACTER cc=currchar[s];	P_CHAR pc_currchar = MAKE_CHARREF_LR(cc);	p=packitem(DEREF_P_CHAR(pc_currchar));	if (p==-1) return; //LB no player-pack - no buy action possible - and no crash too ;-)	npc=calcCharFromSer(buffer[s][3], buffer[s][4], buffer[s][5], buffer[s][6]);	if (npc <= 0) return;	clear=0;	goldtotal=0;	soldout=0;	itemtotal=(((256*(buffer[s][1]))+buffer[s][2])-8)/7;	if (itemtotal>256) return; //LB	for(i=0;i<itemtotal;i++)	{		layer[i]=buffer[s][8+(7*i)];		buyit[i]=calcItemFromSer(buffer[s][8+(7*i)+1], buffer[s][8+(7*i)+2],			buffer[s][8+(7*i)+3], buffer[s][8+(7*i)+4]);		amount[i]=(256*(buffer[s][8+(7*i)+5]))+buffer[s][8+(7*i)+6];		if (buyit[i]>-1)		{			items[buyit[i]].rank=10;			// Fixed for adv trade system -- Magius(CHE) 			tmpvalue=items[buyit[i]].value;			tmpvalue=calcValue(buyit[i], tmpvalue);			if (SrvParms->trade_system==1) tmpvalue=calcGoodValue(s,buyit[i],tmpvalue,0);			goldtotal=goldtotal+(amount[i]*tmpvalue);			// End Fix for adv trade system -- Magius(CHE) 		}	}	bool useBank;	useBank = (goldtotal >= SrvParms->CheckBank );	if( useBank )		playergoldtotal = GetBankCount( DEREF_P_CHAR(pc_currchar), 0x0EED );	else		playergoldtotal = pc_currchar->CountGold();	if ((playergoldtotal>=goldtotal)||(pc_currchar->isGM()))	{		for (i=0;i<itemtotal;i++)		{			if (buyit[i]>-1)			{				if (items[buyit[i]].amount<amount[i])				{					soldout=1;				}			}		}		if (soldout)		{			npctalk(s, npc, "Alas, I no longer have all those goods in stock. Let me know if there is something else thou wouldst buy.",0);			clear=1;		}		else		{			if (pc_currchar->isGM())			{				sprintf((char*)temp, "Here you are, %s. Someone as special as thee will receive my wares for free of course.", pc_currchar->name);			}			else			{				if(useBank)				{					sprintf((char*)temp, "Here you are, %s. %d gold coin%s will be deducted from your bank account.  I thank thee for thy business.",					pc_currchar->name, goldtotal, (goldtotal==1) ? "" : "s");				    goldsfx(s, goldtotal);				}			    else				{				    sprintf((char*)temp, "Here you are, %s.  That will be %d gold coin%s.  I thank thee for thy business.",					pc_currchar->name, goldtotal, (goldtotal==1) ? "" : "s");				    goldsfx(s, goldtotal);	// Dupois, SFX for gold movement. Added Oct 08, 1998				}			}			npctalkall(npc, (char*)temp,0);			npcaction(npc,0x20);		// bow (Duke, 17.3.2001)			clear=1;			if( !(pc_currchar->isGM() ) ) 			{				if( useBank )					DeleBankItem( DEREF_P_CHAR(pc_currchar), 0x0EED, 0, goldtotal );				else					delequan( DEREF_P_CHAR(pc_currchar), 0x0EED, goldtotal, NULL );			}			for (i=0;i<itemtotal;i++)			{				P_ITEM pi = MAKE_ITEM_REF(buyit[i]);				if (pi != NULL)				{					if (pi->amount>amount[i])					{						if (pi->pileable)						{							Commands->DupeItem(s, buyit[i], amount[i]);						}						else						{							for (j=0;j<amount[i];j++)							{								Commands->DupeItem(s, buyit[i], 1);							}						}						pi->amount-=amount[i];						pi->restock+=amount[i];					}					else					{						switch(layer[i])						{						case 0x1A:							if (pi->pileable)							{								Commands->DupeItem(s, buyit[i], amount[i]);							}							else							{								for (j=0;j<amount[i];j++)								{									Commands->DupeItem(s, buyit[i], 1);								}							}							pi->amount=pi->amount-amount[i];							pi->restock=pi->restock+amount[i];							break;						case 0x1B:							if (pi->pileable)							{								pi->SetContSerial(items[p].serial);								RefreshItem(buyit[i]);//AntiChrist							}							else							{								for (j=0;j<amount[i]-1;j++)								{									Commands->DupeItem(s, buyit[i], 1);								}								pi->SetContSerial(items[p].serial);								pi->amount=1;								RefreshItem(buyit[i]);//AntiChrist							}							break;						default:							clConsole.send("ERROR: Fallout of switch statement without default. wolfpack.cpp, buyaction()\n"); //Morrolan						}					}				}			}		}	}	else	{		npctalkall(npc, "Alas, thou dost not possess sufficient gold for this purchase!",0);	}	if (clear)	{		clearmsg[0]=0x3B;		clearmsg[1]=0x00;		clearmsg[2]=0x08;		clearmsg[3]=buffer[s][3];		clearmsg[4]=buffer[s][4];		clearmsg[5]=buffer[s][5];		clearmsg[6]=buffer[s][6];		clearmsg[7]=0x00;		Xsend(s, clearmsg, 8);	}	Weight->NewCalc(DEREF_P_CHAR(pc_currchar));	// Ison 2-20-99	statwindow(s, DEREF_P_CHAR(pc_currchar));}