Go Back   RunUO - Ultima Online Emulation > RunUO > RunUO Post Archive

RunUO Post Archive The Archvie

Reply
 
Thread Tools Display Modes
Old 01-11-2005, 09:49 PM   #1 (permalink)
Newbie
 
Join Date: Dec 2004
Location: UK
Age: 44
Posts: 10
Send a message via Yahoo to jpmythic
Exclamation PlayerVendor.cs (Safety in Checks and Balances)

While I was changing the PlayerVendors to a Commission Based
system I noticed a lack of proper checks when attempting to GiveGold()
to the Player on demand....

So I modified the function to make sure no errors occurred during the
transaction to Convert Gold Held to Bank Checks:

PlayerVendor.cs

(Edit: My BAD, almost forgot to check for <=0 after Deducting the Fee)

Code:
		
public void GiveGold( Mobile from )
{
      //Mythic Debug
      //Deduct Fee before Test/Dropping checks
      if( m_HoldGold > 0 )
      {
	int curFee = ChargePerDay;
	if( curFee > BankAccount )
	{
	      m_HoldGold -= (curFee - BankAccount);
	      BankAccount += (curFee - BankAccount);
	}
      }

      if ( m_HoldGold > 0 )
     {
	Item item = null;
	Container bankBox = from.BankBox;
	Container pack = from.Backpack;
	bool dropCheck;
	
	//Mythic DEBUG
	//Lets just do ALL the GOLD Held
	do
	{
		if ( m_HoldGold < 100000 )
		{
			if ( m_HoldGold < 5000 )	
                                                     item = new Gold( m_HoldGold );
			else						     item = new BankCheck( m_HoldGold );
			if( item != null )	
                                                     m_HoldGold = 0;
			else
			{
			     SayTo( from, "Banking Error, transaction cancelled. Contact a GM" );
			     break;
			}
		}
		else
		{
			item = new BankCheck( 100000 );
			if( item != null )	m_HoldGold -= 100000;
			else
			{
		  	      SayTo( from, "Banking Error, transaction cancelled. Contact a GM" );
			      break;
			}
		}
		if ( item != null )
		{
			dropCheck = false;
			if( bankBox != null )				dropCheck = bankBox.TryDropItem( from, item, true );
			if( !dropCheck && pack != null )	dropCheck = pack.TryDropItem( from, item, true );
			if( !dropCheck )					item.MoveToWorld( from.Location, from.Map );
		}
		item = null;
	}while (m_HoldGold > 0 );
	SayTo( from, "All the gold I was holding, less any fees due, has been converted to checks" ); // All the gold I have been carrying for you has been deposited into your bank account.
	}
	else
	{
		SayTo( from, 503215 ); // I am holding no gold for you.
	}
}
You can ignore the [ curFee ] part as that is involved in the Commission system.

Mythic
jpmythic is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5