AlphaDragon
Sorceror
Hello, to give you a brief idea what was going on. Tried to add an item into auction but for some reason it wouldn't go. Trying to see why and what is going on I commented out the catch part of auctiontarget.cs file and this is the crash I ended up with. I guess the catch is a way for the server not to crash. but by doing it I wasn't sure what is going on and why the item is not going into auction. Any assistance would help. To me the way the catch works. it hides or stops the system from crashing. but doesn't tell me why or what is the problem.
NewAuctionGump.cs
AuctionSystem.cs
AuctionTarget.cs
Code:
RunUO Version 2.1, Build 5288.32340
Operating System: Microsoft Windows NT 6.1.7601 Service Pack 1
.NET Framework: 2.0.50727.5477
Time: 6/26/2014 12:44:56 AM
Mobiles: 41591
Items: 242589
Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Arya.Auction.NewAuctionGump.AddItemCentered(Int32 x, Int32 y, Int32 w, Int32 h, Int32 itemID, Gump gump) in c:\Run-UO-Svn\Scripts\Customs\PERSONALY ADDED\ACTIVE\NPC\Auction System\Gumps\NewAuctionGump.cs:line 37
at Arya.Auction.NewAuctionGump.MakeGump() in c:\Run-UO-Svn\Scripts\Customs\PERSONALY ADDED\ACTIVE\NPC\Auction System\Gumps\NewAuctionGump.cs:line 55
at Arya.Auction.NewAuctionGump..ctor(Mobile user, AuctionItem auction) in c:\Run-UO-Svn\Scripts\Customs\PERSONALY ADDED\ACTIVE\NPC\Auction System\Gumps\NewAuctionGump.cs:line 32
at Arya.Auction.AuctionSystem.OnNewAuctionTarget(Mobile from, Object targeted) in c:\Run-UO-Svn\Scripts\Customs\PERSONALY ADDED\ACTIVE\NPC\Auction System\AuctionSystem.cs:line 314
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at Arya.Auction.AuctionTarget.OnTarget(Mobile from, Object targeted) in c:\Run-UO-Svn\Scripts\Customs\PERSONALY ADDED\ACTIVE\NPC\Auction System\AuctionTarget.cs:line 31
at Server.Targeting.Target.Invoke(Mobile from, Object targeted)
at Server.Network.PacketHandlers.TargetResponse(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)
NewAuctionGump.cs
Code:
#region AuthorHeader
//
// Auction version 2.1, by Xanthos and Arya
//
// Based on original ideas and code by Arya
//
#endregion AuthorHeader
using System;
using System.Collections;
using System.Globalization;
using Server;
using Server.Items;
using Server.Gumps;
using Server.Misc;
using Xanthos.Utilities;
namespace Arya.Auction
{
/// <summary>
/// Configuration for a new auction
/// </summary>
public class NewAuctionGump : Gump
{
private Mobile m_User;
private AuctionItem m_Auction;
public NewAuctionGump( Mobile user, AuctionItem auction ) : base( 100, 100 )
{
user.CloseGump( typeof( NewAuctionGump ) );
m_User = user;
m_Auction = auction;
MakeGump();
}
public static void AddItemCentered(int x, int y, int w, int h, int itemID, Gump gump)
{
Rectangle2D r = ItemBounds.Table[itemID];
gump.AddItem(x + ((w - r.Width) / 2) - r.X, y + ((h - r.Height) / 2) - r.Y, itemID);
}
private void MakeGump()
{
Closable = false;
Disposable = true;
Dragable = true;
Resizable = false;
AddPage(0);
AddBackground( 0, 0, 502, 370, 9270 );
AddImageTiled(4, 4, 492, 362, 2524);
AddImageTiled(5, 5, 490, 360, 2624);
AddAlphaRegion(5, 5, 490, 360);
// Auction item goes here
AddItemCentered( 5, 5, 155, 155, m_Auction.Item.ItemID, this );
AddImageTiled(159, 5, 20, 184, 2524);
AddImageTiled(5, 169, 255, 20, 2524);
AddImageTiled(160, 5, 335, 355, 2624);
AddImageTiled(5, 170, 155, 195, 2624);
AddAlphaRegion(160, 5, 335, 360);
AddAlphaRegion(5, 170, 155, 195);
AddLabel(250, 10, 33, AuctionSystem.ST[ 100 ] );
// Starting bid: text 0
AddLabel(170, 35, 88, AuctionSystem.ST[ 68 ] );
AddImageTiled(254, 34, 72, 22, 2524);
AddImageTiled(255, 35, 70, 20, 2624);
AddAlphaRegion(255, 35, 70, 20);
AddTextEntry(255, 35, 70, 20, 273, 0, m_Auction.MinBid.ToString( "#,0" ) );
// Reserve: text 1
AddLabel(345, 35, 88, AuctionSystem.ST[ 69 ] );
AddImageTiled(414, 34, 72, 22, 2524);
AddImageTiled(415, 35, 70, 20, 2624);
AddAlphaRegion(415, 35, 70, 20);
AddTextEntry(415, 35, 70, 20, 273, 1, "");
//AddTextEntry(415, 35, 70, 20, 273, 1, m_Auction.Reserve.ToString( "#,0" ) );
// Days duration: text 2
AddLabel(170, 60, 88, AuctionSystem.ST[ 101 ] );
AddImageTiled(254, 59, 32, 22, 2524);
AddImageTiled(255, 60, 30, 20, 2624);
AddAlphaRegion(255, 60, 30, 20);
AddTextEntry(255, 60, 30, 20, 273, 2, m_Auction.Duration.TotalDays.ToString() );
AddLabel(290, 60, 88, AuctionSystem.ST[ 102 ] );
// Item name: text 3
AddLabel(170, 85, 88, AuctionSystem.ST[ 50 ] );
AddImageTiled(254, 84, 232, 22, 2524);
AddImageTiled(255, 85, 230, 20, 2624);
AddAlphaRegion(255, 85, 230, 20);
AddTextEntry(255, 85, 230, 20, 273, 3, m_Auction.ItemName );
// Buy now: Check 0, Text 6
//AddCheck(165, 110, 2152, 2153, true, 0);
AddCheck(165, 110, 2474, 2153, true, 0);
AddLabel( 200, 115, 88, AuctionSystem.ST[ 208 ] );
AddImageTiled( 329, 114, 157, 22, 2524 );
AddImageTiled( 330, 115, 155, 20, 2624 );
AddAlphaRegion( 330, 115, 155, 20 );
AddTextEntry( 330, 115, 155, 20, 273, 6, "" );
// Description: text 4
AddLabel(170, 140, 88, AuctionSystem.ST[ 103 ] );
AddImageTiled(169, 159, 317, 92, 2524);
AddImageTiled(170, 160, 315, 90, 2624);
AddAlphaRegion(170, 160, 315, 90);
AddTextEntry(170, 160, 315, 90, 273, 4, m_Auction.Description);
// Web link: text 5
AddLabel(170, 255, 88, AuctionSystem.ST[ 104 ] );
AddImageTiled(224, 274, 262, 22, 2524);
AddLabel(170, 275, 88, @"http://");
AddImageTiled(225, 275, 260, 20, 2624);
AddAlphaRegion(225, 275, 260, 20);
AddTextEntry(225, 275, 260, 20, 273, 5, m_Auction.WebLink );
// Help area
AddImageTiled(9, 174, 152, 187, 2524);
AddImageTiled(10, 175, 150, 185, 2624);
AddAlphaRegion(10, 175, 150, 185);
AddHtml( 10, 175, 150, 185, AuctionSystem.ST[ 105 ] , (bool)false, (bool)true);
// OK Button: button 1
AddButton(170, 305, 4023, 4024, 1, GumpButtonType.Reply, 0);
AddLabel(210, 300, 33, AuctionSystem.ST[ 106 ] );
AddLabel(210, 315, 33, AuctionSystem.ST[107]);
// Cancel button: button 0
AddButton(170, 335, 4020, 4020, 0, GumpButtonType.Reply, 0);
AddLabel(210, 335, 88, AuctionSystem.ST[ 108 ] );
}
public override void OnResponse(Server.Network.NetState sender, RelayInfo info)
{
if ( ! AuctionSystem.Running )
{
sender.Mobile.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 15 ] );
m_Auction.Cancel();
return;
}
int buttonid = info.ButtonID;
//right click
if (buttonid == 0)
{
m_Auction.Cancel();
m_User.SendGump(new AuctionGump(m_User));
return;
}
if (buttonid > 1)
{
m_User.SendMessage("Invalid option. Please try again.");
return;
}
bool allowBuyNow = info.Switches.Length > 0; // Just one switch
String errormessage = "";
switch ( info.ButtonID )
{
case 0: // Cancel the auction
m_Auction.Cancel();
m_User.SendGump(new AuctionGump(m_User));
break;
case 1: // Commit the auction
// Collect information
int minbid = 100; // text 0
int reserve = minbid; // text 1
int days = 7; // text 2
string name = m_Auction.ItemName;// text 3
string description = " "; // text 4
string weblink = " "; // text 5
int buynow = 0; // text 6
// The 3D client sucks
string[] tr = new string[ 7 ];
foreach( TextRelay t in info.TextEntries )
{
try
{
tr[t.EntryID] = t.Text;
}
catch (Exception e)
{
errormessage = e.Message;
}
}
try { minbid = (int) uint.Parse( tr[ 0 ], NumberStyles.AllowThousands ); }
catch {}
try { reserve = (int)uint.Parse(tr[1], NumberStyles.AllowThousands); }
catch { }
try { days = (int) uint.Parse( tr[ 2 ] ); }
catch {}
try { buynow = (int) uint.Parse( tr[ 6 ], NumberStyles.AllowThousands ); }
catch {}
if (buynow < 1)
{
allowBuyNow = false;
}
if ( tr[ 3 ] != null )
{
if (NameVerification.Validate(tr[3], 2, 40, true, true, true, 2, NameVerification.Empty))
{
string[] disallowed = ProfanityProtection.Disallowed;
for (int i = 0; i < disallowed.Length; i++)
{
if (tr[3].IndexOf(disallowed[i]) != -1)
{
m_User.SendLocalizedMessage(1072622); // That name isn't very polite.
goto case 0; // Pretty much cancel the auction
}
}
}
else
{
name = tr[3];
}
name = tr[3];
}
if ( tr[ 4 ] != null )
{
if (NameVerification.Validate(tr[4], 0, 100, true, true, true, 2, NameVerification.Empty))
{
string[] disallowed = ProfanityProtection.Disallowed;
for (int i = 0; i < disallowed.Length; i++)
{
if (tr[4].IndexOf(disallowed[i]) != -1)
{
m_User.SendLocalizedMessage(1072622); // That name isn't very polite.
goto case 0; // Pretty much cancel the auction
}
}
}
else
{
description = tr[4];
//name = tr[3];
}
description = tr[ 4 ];
}
if ( tr[ 5 ] != null )
{
weblink = tr[ 5 ];
}
bool ok = true;
if ( minbid < 1 )
{
m_User.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 109 ] );
ok = false;
}
if (reserve < 1)
{
reserve = minbid;
}
if ( reserve < minbid )
{
reserve = minbid;
m_User.SendMessage( 214, AuctionSystem.ST[ 110 ] );
ok = false;
}
if ( days < AuctionSystem.MinAuctionDays && m_User.AccessLevel < AccessLevel.GameMaster || days < 1 )
{
m_User.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 111 ] , AuctionSystem.MinAuctionDays );
ok = false;
}
if ( days > AuctionSystem.MaxAuctionDays && m_User.AccessLevel < AccessLevel.GameMaster )
{
m_User.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 112 ] , AuctionSystem.MaxAuctionDays );
ok = false;
}
if ( name.Length == 0 )
{
m_User.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 113 ] );
ok = false;
}
if ( minbid * AuctionConfig.MaxReserveMultiplier < reserve && m_User.AccessLevel < AccessLevel.GameMaster )
{
m_User.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 114 ] );
ok = false;
}
if ( allowBuyNow && buynow < reserve )
{
m_User.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 209 ] );
ok = false;
}
if ( ok && AuctionConfig.CostOfAuction > 0.0 )
{
int toPay = 0;
if ( AuctionConfig.CostOfAuction <= 1.0 )
toPay = (int) ( Math.Max( minbid, reserve ) * AuctionConfig.CostOfAuction );
else
toPay = (int) AuctionConfig.CostOfAuction;
if ( toPay > 0 )
{
if (Server.Mobiles.Banker.Withdraw(m_User, toPay))
{
m_User.SendMessage(AuctionConfig.MessageHue, AuctionSystem.ST[228], toPay);
}
else
{
m_User.SendMessage(AuctionConfig.MessageHue, AuctionSystem.ST[229], toPay);
goto case 0; // Pretty much cancel the auction
}
}
}
m_Auction.MinBid = minbid;
m_Auction.Reserve = reserve;
m_Auction.ItemName = name;
m_Auction.Duration = TimeSpan.FromDays( days );
m_Auction.Description = description;
m_Auction.WebLink = weblink;
m_Auction.BuyNow = allowBuyNow ? buynow : 0;
if ( ok && AuctionSystem.Running )
{
World.Broadcast(0x35, true, "A {0} just became available on [Myauction for {1}", m_Auction.ItemName, minbid);
m_Auction.Confirm();
m_User.SendGump( new AuctionViewGump( m_User, m_Auction, new AuctionGumpCallback( AuctionCallback ) ) );
}
else if ( AuctionSystem.Running )
{
m_User.SendGump( new NewAuctionGump( m_User, m_Auction ) );
}
else
{
m_User.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 115 ] );
}
break;
}
}
private static void AuctionCallback( Mobile user )
{
user.SendGump( new AuctionGump( user ) );
}
}
}
AuctionSystem.cs
Code:
#region AuthorHeader
//
// Auction version 2.1, by Xanthos and Arya
//
// Based on original ideas and code by Arya
//
#endregion AuthorHeader
using System;
using System.Collections;
using System.Reflection;
using System.IO;
using Server;
using Server.Items;
using Server.Accounting;
using Server.Mobiles;
using Joeku;
namespace Arya.Auction
{
/// <summary>
/// The main auction system process
/// </summary>
public class AuctionSystem
{
#region Variables
/// <summary>
/// The auction control stone
/// </summary>
private static AuctionControl m_ControlStone;
/// <summary>
/// Text provider for the auction system
/// </summary>
private static StringTable m_StringTable;
#endregion
#region Properties
/// <summary>
/// Gets the String Table for the auction system
/// </summary>
public static StringTable ST
{
get
{
if ( m_StringTable == null )
m_StringTable = new StringTable();
return m_StringTable;
}
}
/// <summary>
/// Gets or sets the auction control stone
/// </summary>
public static AuctionControl ControlStone
{
get { return m_ControlStone; }
set { m_ControlStone = value; }
}
/// <summary>
/// Gets the listing of the current auctions
/// </summary>
public static ArrayList Auctions
{
get
{
if ( m_ControlStone != null )
{
return m_ControlStone.Auctions;
}
else
{
return null;
}
}
}
/// <summary>
/// Gets the listing of pending auctions (ended but reserve not met)
/// </summary>
public static ArrayList Pending
{
get
{
if ( m_ControlStone != null )
{
return m_ControlStone.Pending;
}
else
{
return null;
}
}
}
/// <summary>
/// Get the max number of auctions for a single account
/// </summary>
private static int MaxAuctions
{
get
{
if ( m_ControlStone == null )
return 0;
else
return m_ControlStone.MaxAuctionsParAccount;
}
}
/// <summary>
/// Gets the min number of days an auction can last
/// </summary>
public static int MinAuctionDays
{
get { return m_ControlStone.MinAuctionDays; }
}
/// <summary>
/// Gets the max number of days an auction can last
/// </summary>
public static int MaxAuctionDays
{
get { return m_ControlStone.MaxAuctionDays; }
}
/// <summary>
/// States whether the auction system is functional or not
/// </summary>
public static bool Running
{
get { return m_ControlStone != null; }
}
#endregion
#region Auction Managment
/// <summary>
/// Adds an auction into the system
/// </summary>
/// <param name="auction">The new auction entry</param>
public static void Add( AuctionItem auction )
{
// Put the item into the control stone
auction.Item.Internalize();
m_ControlStone.AddItem( auction.Item );
//auction.Item.Parent = m_ControlStone;
auction.Item.Visible = true;
Auctions.Add( auction );
m_ControlStone.InvalidateProperties();
}
/// <summary>
/// Requests the start of a new auction
/// </summary>
/// <param name="m">The mobile requesting the auction</param>
public static void AuctionRequest( Mobile mobile )
{
if ( CanAuction( mobile ) )
{
mobile.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 191 ] );
mobile.CloseAllGumps();
if (mobile.AccessLevel >= AccessLevel.Counselor)
Joeku.ToolbarHelper.SendToolbar(mobile);
// mobile.CloseGump(typeof(AuctionGump));
// mobile.CloseGump(typeof(AuctionNoticeGump));
// mobile.CloseGump(typeof(AuctionControlGump));
// mobile.CloseGump(typeof(AuctionMessageGump));
// mobile.CloseGump(typeof(AuctionSortGump));
// mobile.CloseGump(typeof(MyAuctionGump));
// mobile.CloseGump(typeof(AuctionDeliveryGump));
// mobile.CloseGump(typeof(AuctionAdminGump));
// mobile.CloseGump(typeof(CreatureDeliveryGump));
// mobile.CloseGump(typeof(DeleteAuctionGump));
// mobile.CloseGump(typeof(AuctionViewGump));
// mobile.CloseGump(typeof(NewAuctionGump));
// mobile.CloseGump(typeof(AuctionSearchGump));
// mobile.CloseGump(typeof(AuctionListing));
mobile.Target = new AuctionTarget( new AuctionTargetCallback( OnNewAuctionTarget ), -1, false );
}
else
{
mobile.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 192 ], AuctionSystem.MaxAuctions );
mobile.SendGump( new AuctionGump( mobile ) );
}
}
private static void OnCreatureAuction( Mobile from, BaseCreature creature )
{
MobileStatuette ms = MobileStatuette.Create( from, creature );
if ( ms == null )
{
from.Target = new AuctionTarget( new AuctionTargetCallback( OnNewAuctionTarget ), -1, false );
}
/*
* Pets are auctioned within an item (MobileStatuette)
*
* The item's name is the type of the pet, the hue corresponds to the pet
* and the item id is retrieved from the shrink table.
*
*/
AuctionItem auction = new AuctionItem( ms, from );
from.SendGump( new NewAuctionGump( from, auction ) );
}
private static void OnNewAuctionTarget( Mobile from, object targeted )
{
Item item = targeted as Item;
BaseCreature bc = targeted as BaseCreature;
if ( item == null && ! AuctionConfig.AllowPetsAuction )
{
// Can't auction pets and target it invalid
from.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 193 ] );
from.Target = new AuctionTarget( new AuctionTargetCallback( OnNewAuctionTarget ), -1, false );
return;
}
if ( bc != null )
{
// Auctioning a pet
OnCreatureAuction( from, bc );
return;
}
if ( !CheckItem( item ) )
{
from.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 194 ] );
from.Target = new AuctionTarget( new AuctionTargetCallback( OnNewAuctionTarget ), -1, false );
return;
}
if ( !CheckIdentified( item ) )
{
from.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 195 ] );
from.Target = new AuctionTarget( new AuctionTargetCallback( OnNewAuctionTarget ), -1, false );
return;
}
//Uncomment if you use the ItemId skill & want things attributes displayed
//
// if (item is BaseWeapon)
// ((BaseWeapon)item).Identified = true;
// else if (item is BaseArmor)
// ((BaseArmor)item).Identified = true;
// else if (item is BaseClothing)
// ((BaseClothing)item).Identified = true;
// else if (item is BaseJewel)
// ((BaseJewel)item).Identified = true;
if ( !item.Movable )
{
from.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 205 ] );
from.Target = new AuctionTarget( new AuctionTargetCallback( OnNewAuctionTarget ), -1, false );
return;
}
bool ok = true;
if ( item is Container )
{
foreach( Item sub in item.Items )
{
if ( !CheckItem( sub ) )
{
from.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 196 ] );
ok = false;
break;
}
if ( ! sub.Movable )
{
from.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 205 ] );
ok = false;
break;
}
if ( sub is Container && sub.Items.Count > 0 )
{
ok = false;
from.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 197 ] );
break;
}
}
}
if ( ! ( item.IsChildOf( from.Backpack ) || item.IsChildOf( from.BankBox ) ) )
{
from.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 198 ] );
ok = false;
}
if ( ! ok )
{
from.Target = new AuctionTarget( new AuctionTargetCallback( OnNewAuctionTarget ), -1, false );
}
else
{
// Item ok, start auction creation
AuctionItem auction = new AuctionItem( item, from );
from.SendGump( new NewAuctionGump( from, auction ) );
}
}
/// <summary>
/// Verifies if an item can be sold through the auction
/// </summary>
/// <param name="item">The item being sold</param>
/// <returns>True if the item is allowed</returns>
private static bool CheckItem( Item item )
{
foreach( Type t in AuctionConfig.ForbiddenTypes )
{
if ( t == item.GetType() )
{
return false;
}
}
return true;
}
/// <summary>
/// This check is intended for non-AOS only. It verifies whether the item has an Identified
/// property and in that case it it's set to true.
/// </summary>
/// <param name="item">The item being evaluated</param>
/// <remarks>This method always returns true if Core.AOS is set to true.</remarks>
/// <returns>True if the item can be auctioned, false otherwise</returns>
private static bool CheckIdentified( Item item )
{
if ( Core.AOS )
return true;
PropertyInfo prop = item.GetType().GetProperty( "Identified" ); // Do not translate this!
if ( prop == null )
return true;
bool identified = true;
try
{
identified = (bool) prop.GetValue( item, null );
}
catch {} // Possibly there's an Identified property whose value is not bool - allow auction of this
if ( identified && item.Items.Count > 0 )
{
foreach( Item child in item.Items )
{
if ( ! CheckIdentified( child ) )
{
identified = false;
Console.WriteLine( "SMASH" );
break;
}
}
}
return identified;
}
/// <summary>
/// Removes the auction system from the server. All auctions will end unsuccesfully.
/// </summary>
/// <param name="m">The mobile terminating the system</param>
public static void ForceDelete( Mobile m )
{
Console.WriteLine( "Auction system terminated on {0} at {1} by {2} ({3}, Account: {4})", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), m.Name, m.Serial, ( m.Account as Account ).Username );
while ( Auctions.Count > 0 || Pending.Count > 0 )
{
while ( Auctions.Count > 0 )
{
( Auctions[ 0 ] as AuctionItem ).ForceEnd();
}
while ( Pending.Count > 0 )
{
( Pending[ 0 ] as AuctionItem ).ForceEnd();
}
}
ControlStone.ForceDelete();
ControlStone = null;
}
/// <summary>
/// Finds an auction through its id
/// </summary>
/// <param name="id">The GUID identifying the auction</param>
/// <returns>An AuctionItem object if the speicifies auction is still in the system</returns>
public static AuctionItem Find( Guid id )
{
if ( !Running )
return null;
foreach( AuctionItem item in Pending )
{
if ( item.ID == id )
return item;
}
foreach( AuctionItem item in Auctions )
{
if ( item.ID == id )
return item;
}
return null;
}
/// <summary>
/// Gets the auctions created by a player
/// </summary>
/// <param name="m">The player requesting the auctions</param>
public static ArrayList GetAuctions( Mobile m )
{
ArrayList auctions = new ArrayList();
try
{
foreach( AuctionItem auction in Auctions )
{
if ( auction.Owner == m || ( auction.Owner != null && m.Account.Equals( auction.Owner.Account ) ) )
{
auctions.Add( auction );
}
}
}
catch{}
return auctions;
}
/// <summary>
/// Gets the list of auctions a mobile has bids on
/// </summary>
public static ArrayList GetBids( Mobile m )
{
ArrayList bids = new ArrayList();
try
{
foreach( AuctionItem auction in Auctions )
{
if ( auction.MobileHasBids( m ) )
{
bids.Add( auction );
}
}
}
catch {}
return bids;
}
/// <summary>
/// Gets the list of pendencies for a mobile
/// </summary>
public static ArrayList GetPendencies( Mobile m )
{
ArrayList list = new ArrayList();
try
{
foreach( AuctionItem auction in Pending )
{
if ( auction.Owner == m || ( auction.Owner != null && m.Account.Equals( auction.Owner.Account ) ) )
{
list.Add( auction );
}
else if ( auction.HighestBid.Mobile == m || ( auction.HighestBid.Mobile != null && m.Account.Equals( auction.HighestBid.Mobile.Account ) ) )
{
list.Add( auction );
}
}
}
catch {}
return list;
}
#endregion
#region Checks
/// <summary>
/// Verifies if a mobile can create a new auction
/// </summary>
/// <param name="m">The mobile trying to create an auction</param>
/// <returns>True if allowed</returns>
public static bool CanAuction( Mobile m )
{
if ( m.AccessLevel >= AccessLevel.GameMaster ) // Staff can always auction
return true;
int count = 0;
foreach( AuctionItem auction in Auctions )
{
if ( auction.Account == ( m.Account as Account ) )
{
count++;
}
}
return count < MaxAuctions;
}
#endregion
#region Scheduling
public static void Initialize()
{
try
{
if ( Running )
{
VerifyIntegrity();
VerifyAuctions();
VerifyPendencies();
}
}
catch ( Exception err )
{
m_ControlStone = null;
Console.WriteLine( "An error occurred when initializing the Auction System. The system has been temporarily disabled." );
Console.WriteLine( "Error details: {0}", err.ToString() );
}
}
public static void OnDeadlineReached()
{
if ( ! Running )
return;
VerifyAuctions();
VerifyPendencies();
}
/// <summary>
/// Verifies whether any pets in current auctions have been deleted
/// </summary>
private static void VerifyIntegrity()
{
foreach( AuctionItem auction in Auctions )
auction.VeirfyIntergrity();
}
/// <summary>
/// Verifies current auctions ending the ones that expired
/// </summary>
public static void VerifyAuctions()
{
lock ( World.Items )
{
lock ( World.Mobiles )
{
if ( ! Running )
return;
ArrayList list = new ArrayList();
ArrayList invalid = new ArrayList();
foreach( AuctionItem auction in Auctions )
{
if ( auction.Item == null || ( auction.Creature && auction.Pet == null ) )
invalid.Add( auction );
else if ( auction.Expired )
list.Add( auction );
}
foreach( AuctionItem inv in invalid )
{
inv.EndInvalid();
}
foreach( AuctionItem expired in list )
{
expired.End( null );
}
}
}
}
/// <summary>
/// Verifies pending auctions ending the ones that expired
/// </summary>
public static void VerifyPendencies()
{
lock ( World.Items )
{
lock ( World.Mobiles )
{
if ( !Running )
return;
ArrayList list = new ArrayList();
foreach( AuctionItem auction in Pending )
{
if ( auction.PendingExpired )
list.Add( auction );
}
foreach( AuctionItem expired in list )
{
expired.PendingTimeOut();
}
}
}
}
/// <summary>
/// Disables the system until the next reboot
/// </summary>
public static void Disable()
{
m_ControlStone = null;
AuctionScheduler.Stop();
}
#endregion
/// <summary>
/// Outputs all relevant auction data to a text file
/// </summary>
public static void ProfileAuctions()
{
World.Broadcast(0x35, true, "{0}", DateTime.Now.ToLongDateString());
World.Broadcast(0x35, true, "{0}", DateTime.Now.ToShortTimeString());
World.Broadcast(0x35, true, "{0} Running Auctions", Auctions.Count);
World.Broadcast(0x35, true, "{0} Pending Auctions", Pending.Count);
World.Broadcast(0x35, true, "Next Deadline : {0} at {1}", AuctionScheduler.Deadline.ToShortDateString(), AuctionScheduler.Deadline.ToShortTimeString());
string file = Path.Combine( Core.BaseDirectory, "AuctionProfile.txt" );
try
{
StreamWriter sw = new StreamWriter( file, false );
sw.WriteLine( "Auction System Profile" );
sw.WriteLine( "{0}", DateTime.Now.ToLongDateString() );
sw.WriteLine( "{0}", DateTime.Now.ToShortTimeString() );
sw.WriteLine( "{0} Running Auctions", Auctions.Count );
sw.WriteLine( "{0} Pending Auctions", Pending.Count );
sw.WriteLine( "Next Deadline : {0} at {1}", AuctionScheduler.Deadline.ToShortDateString(), AuctionScheduler.Deadline.ToShortTimeString() );
sw.WriteLine();
sw.WriteLine( "Auctions List" );
sw.WriteLine();
ArrayList auctions = new ArrayList( Auctions );
foreach( AuctionItem a in auctions )
{
if ( a.Item != null )
{
a.Item.Location = m_ControlStone.Location;
//a.Item.Map = m_ControlStone.Map;
a.Item.Internalize();
m_ControlStone.AddItem( a.Item );
}
}
foreach( AuctionItem a in auctions )
{
a.Profile( sw );
}
sw.WriteLine( "Pending Auctions List" );
sw.WriteLine();
ArrayList pending = new ArrayList( Pending );
foreach( AuctionItem p in pending )
{
p.Profile( sw );
}
sw.WriteLine( "End of profile" );
sw.Close();
}
catch ( Exception err )
{
Console.WriteLine( "Couldn't output auction profile. Error: {0}", err.ToString() );
}
}
}
}
AuctionTarget.cs
Code:
#region AuthorHeader
//
// Auction version 2.1, by Xanthos and Arya
//
// Based on original ideas and code by Arya
//
#endregion AuthorHeader
using System;
using Server;
using Server.Targeting;
namespace Arya.Auction
{
/// <summary>
/// General purpose target used by the auction system
/// </summary>
public class AuctionTarget : Target
{
private AuctionTargetCallback m_Callback;
public AuctionTarget( AuctionTargetCallback callback, int range, bool allowground ) : base( range, allowground, TargetFlags.None )
{
m_Callback = callback;
}
protected override void OnTarget(Mobile from, object targeted)
{
// try
// {
m_Callback.DynamicInvoke( new object[] { from, targeted } );
// }
// catch
// {
// Console.WriteLine( "The auction system cannot access the cliloc.enu file. Please review the system instructions for proper installation" );
// }
}
protected override void OnTargetCancel(Mobile from, TargetCancelType cancelType)
{
if ( AuctionSystem.Running )
{
from.SendGump( new AuctionGump( from ) );
}
}
}
}