1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Xantho's Auction

Discussion in 'Script Support' started by IanE, Jan 17, 2014.

  1. IanE
    Offline

    IanE Member

    Joined:
    Dec 27, 2013
    Messages:
    220
    Likes Received:
    16
    Publish Number:
    54
    I am trying to get Xantho's Auction to work and this is the error I am getting.
    Code (C#):
    1.  + Custom Systems/Xanthos/Auction System/AuctionItem.cs:
    2.     CS0246: Line 226: The type or namespace name 'StringList' could not be found
    3. (are you missing a using directive or an assembly reference?)
    Here is the Script.
    Code (C#):
    1. #region AuthorHeader
    2. //
    3. // Auction version 2.1, by Xanthos and Arya
    4. //
    5. // Based on original ideas and code by Arya
    6. //
    7. #endregion AuthorHeader
    8. using System;
    9. using System.Collections;
    10. using System.Collections.Generic;
    11. using System.IO;
    12. using System.Text.RegularExpressions;
    13. using OpenUO.Ultima;
    14. using System.Text;
    15. using Server;
    16. using Server.Network;
    17. using Server.Accounting;
    18. using Server.Items;
    19. using Server.Mobiles;
    20. using Xanthos.Utilities;
    21. using Xanthos.Interfaces;
    22.  
    23. namespace Arya.Auction
    24. {
    25.     /// <summary>
    26.     /// Defines situations for pending situations
    27.     /// </summary>
    28.     public enum AuctionPendency : byte
    29.     {
    30.         /// <summary>
    31.         /// The user still has to make a decision
    32.         /// </summary>
    33.         Pending = 0,
    34.         /// <summary>
    35.         /// The user OKs the auction
    36.         /// </summary>
    37.         Accepted = 1,
    38.         /// <summary>
    39.         /// The user didn't accept the auction
    40.         /// </summary>
    41.         NotAccepted = 2
    42.     }
    43.  
    44.     /// <summary>
    45.     /// Defines what happens with the auction item if the auction is ended by the staff
    46.     /// </summary>
    47.     public enum ItemFate
    48.     {
    49.         /// <summary>
    50.         /// The item is returned to the owner
    51.         /// </summary>
    52.         ReturnToOwner,
    53.         /// <summary>
    54.         /// The item is taken by the staff
    55.         /// </summary>
    56.         ReturnToStaff,
    57.         /// <summary>
    58.         /// The item is deleted
    59.         /// </summary>
    60.         Delete
    61.     }
    62.  
    63.     /// <summary>
    64.     /// Specifies the type of message that should be dispatched for the buyer or the owner
    65.     /// </summary>
    66.     public enum AuctionMessage : byte
    67.     {
    68.         /// <summary>
    69.         /// No message should be dispatched
    70.         /// </summary>
    71.         None = 0,
    72.         /// <summary>
    73.         /// An information message should be dispatched
    74.         /// </summary>
    75.         Information = 1,
    76.         /// <summary>
    77.         /// A feedback message should be dispatched
    78.         /// </summary>
    79.         Response = 2
    80.     }
    81.  
    82.     /// <summary>
    83.     /// An auction entry, holds all the information about a single auction process
    84.     /// </summary>
    85.     public class AuctionItem
    86.     {
    87.         #region ItemInfo class
    88.  
    89.         public class ItemInfo
    90.         {
    91.             private string m_Name;
    92.             private Item m_Item;
    93.             private string m_Props;
    94.  
    95.             public string Name
    96.             {
    97.                 get
    98.                 {
    99.                     if ( m_Item != null )
    100.                         return m_Name;
    101.                     else
    102.                         return "N/A";
    103.                 }
    104.             }
    105.  
    106.             public Item Item
    107.             {
    108.                 get { return m_Item; }
    109.             }
    110.  
    111.             public string Properties
    112.             {
    113.                 get
    114.                 {
    115.                     if ( m_Item != null )
    116.                         return m_Props;
    117.                     else
    118.                         return AuctionSystem.ST[ 146 ];
    119.                 }
    120.             }
    121.  
    122.             public ItemInfo( Item item )
    123.             {
    124.                 m_Item = item;
    125.  
    126.                 if ( item.Name != null )
    127.                     m_Name = item.Name;
    128.                 else
    129.                     m_Name = m_StringList.Table[ item.LabelNumber ] as string;
    130.  
    131.                 if ( item.Amount > 1 )
    132.                 {
    133.                     m_Name = string.Format( "{0} {1}", item.Amount.ToString("#,0" ), m_Name );
    134.                 }
    135.  
    136.                 if ( item is MobileStatuette )
    137.                 {
    138.                     m_Props = GetCreatureProperties( ( item as MobileStatuette ).ShrunkenPet );
    139.                 }
    140.                 else
    141.                 {
    142.                     m_Props = AuctionItem.GetItemProperties( item );
    143.                 }
    144.             }
    145.  
    146.             private static string GetCreatureProperties( BaseCreature creature )
    147.             {
    148.                 StringBuilder sb = new StringBuilder();
    149.  
    150.                 sb.Append( "<basefont color=#FFFFFF>" );
    151.  
    152.                 if ( creature.Name != null )
    153.                 {
    154.                     sb.AppendFormat( "Name : {0}<br", creature.Name );
    155.                 }
    156.  
    157.                 sb.AppendFormat( AuctionSystem.ST[ 147 ] , creature.ControlSlots );
    158.                 sb.AppendFormat( AuctionSystem.ST[ 148 ], creature.IsBondable ? "Yes" : "No" );
    159.                 sb.AppendFormat( AuctionSystem.ST[ 149 ] , creature.Str );
    160.                 sb.AppendFormat( AuctionSystem.ST[ 150 ] , creature.Dex );
    161.                 sb.AppendFormat( AuctionSystem.ST[ 151 ] , creature.Int );
    162.  
    163.                 int index = 0;
    164.                 Server.Skill skill = null;
    165.  
    166.                 while ( ( skill = creature.Skills[ index++ ] ) != null )
    167.                 {
    168.                     if ( skill.Value > 0 )
    169.                     {
    170.                         sb.AppendFormat( "{0} : {1}<br>", skill.Name, skill.Value );
    171.                     }
    172.                 }
    173.  
    174.                 return sb.ToString();
    175.             }
    176.  
    177.             private ItemInfo()
    178.             {
    179.             }
    180.  
    181.             public void Serialize( GenericWriter writer )
    182.             {
    183.                 // Version 1
    184.                 // Version 0
    185.                 writer.Write( m_Name );
    186.                 writer.Write( m_Item );
    187.                 writer.Write( m_Props );
    188.             }
    189.  
    190.             public static ItemInfo Deserialize( GenericReader reader, int version )
    191.             {
    192.                 ItemInfo item = new ItemInfo();
    193.  
    194.                 switch ( version )
    195.                 {
    196.                     case 1:
    197.                     case 0:
    198.                         item.m_Name = reader.ReadString();
    199.                         item.m_Item = reader.ReadItem();
    200.                         item.m_Props = reader.ReadString();
    201.                         break;
    202.                 }
    203.  
    204.                 return item;
    205.             }
    206.  
    207.             /// <summary>
    208.             /// Verifies if the mobile referenced by this item is still valid
    209.             /// </summary>
    210.             public void VeirfyIntegrity()
    211.             {
    212.                 IShrinkItem shrinkItem = m_Item as IShrinkItem;
    213.  
    214.                 if ( null != shrinkItem && null == shrinkItem.ShrunkenPet )
    215.                 {
    216.                     m_Item.Delete();
    217.                     m_Item = null; // This will make this item invalid
    218.                 }
    219.             }
    220.         }
    221.  
    222.         #endregion
    223.  
    224.         #region Item Properties
    225.  
    226.         private static StringList m_StringList;
    227.  
    228.         static AuctionItem()
    229.         {
    230.             Console.WriteLine( "AuctionItem.cs: AuctionItem(): DEBUG: Beginning AuctionItem()" );
    231.  
    232.             string clilocFolder = null;
    233.  
    234.             if ( AuctionConfig.ClilocLocation != null && AuctionConfig.ClilocLocation != "" )  // TESTING by Alari - 4/20/2008
    235.             {
    236.                 Console.WriteLine( "AuctionItem.cs: AuctionItem(): DEBUG: AuctionConfig.ClilocLocation NOT null! Value: \"{0}\"", AuctionConfig.ClilocLocation );
    237.                 clilocFolder = Path.GetDirectoryName( AuctionConfig.ClilocLocation );
    238.                 Ultima.Client.Directories.Insert(0, clilocFolder);
    239.                 Console.WriteLine( "AuctionItem.cs: AuctionItem(): DEBUG: clilocFolder set to {0}", clilocFolder );
    240.                
    241.             }
    242.             else  // TESTING by Alari - 4:20 AM 4/19/2007
    243.             {
    244.                 Console.WriteLine( "AuctionItem.cs: AuctionItem(): DEBUG: AuctionConfig.ClilocLocation is NULL, proceeding with auto-detection..." );
    245.                 clilocFolder = Core.FindDataFile( "cliloc.enu" );
    246.                 if ( clilocFolder != null )
    247.                 {
    248.                     Ultima.Client.Directories.Insert( 0, clilocFolder );
    249.                     Console.WriteLine( "AuctionItem.cs: AuctionItem(): DEBUG: Cliloc detection worked! {0}", clilocFolder );
    250.                 }
    251.                 else
    252.                 {
    253.                     Console.WriteLine( "AuctionItem.cs: AuctionItem(): DEBUG: Cliloc detection failed." );
    254.                 }
    255.             }
    256.  
    257.             m_StringList = new StringList( "ENU" );
    258.  
    259.             if ( clilocFolder != null )
    260.             {
    261.                 Ultima.Client.Directories.RemoveAt( 0 );
    262.             }
    263.         }
    264.  
    265.         /// <summary>
    266.         /// Gets an html formatted string with all the properies for the item
    267.         /// </summary>
    268.         /// <returns>A string object containing the html structure corresponding to the item properties</returns>
    269.         private static string GetItemProperties( Item item )
    270.         {
    271.             if ( item == null || item.PropertyList == null )
    272.             {
    273.                 return AuctionSystem.ST[ 78 ];
    274.             }
    275.  
    276.             if ( Core.AOS )
    277.             {
    278.                 #region AoS
    279.                 ObjectPropertyList plist = new ObjectPropertyList( item );
    280.                 item.GetProperties( plist );
    281.  
    282.                 byte[] data = plist.UnderlyingStream.UnderlyingStream.ToArray();
    283.                 ArrayList list = new ArrayList();
    284.  
    285.                 int index = 15; // First localization number index
    286.  
    287.                 while ( true )
    288.                 {
    289.                     uint number = 0;
    290.  
    291.                     if ( index + 4 >= data.Length )
    292.                     {
    293.                         break;
    294.                     }
    295.  
    296.                     number = (uint) ( data[ index++ ] << 24 | data[ index++ ] << 16 | data[ index++ ] << 8 | data[ index++ ] );
    297.                     ushort length = 0;
    298.  
    299.                     if ( index + 2 > data.Length )
    300.                     {
    301.                         break;
    302.                     }
    303.  
    304.                     length = (ushort) ( data[ index++ ] << 8 | data[ index++ ] );
    305.  
    306.                     // Read the string
    307.                     int end = index + length;
    308.  
    309.                     if ( end >= data.Length )
    310.                     {
    311.                         end = data.Length - 1;
    312.                     }
    313.  
    314.                     System.Text.StringBuilder s = new System.Text.StringBuilder();
    315.                     while ( index + 2 <= end + 1 )
    316.                     {
    317.                         short next = (short) ( data[ index++ ] | data[ index++ ] << 8 );
    318.  
    319.                         if ( next == 0 )
    320.                             break;
    321.  
    322.                         s.Append( System.Text.Encoding.Unicode.GetString( BitConverter.GetBytes( next ) ) );
    323.                     }
    324.  
    325.                     list.Add( ComputeProperty( (int) number, s.ToString() ) );
    326.                 }
    327.  
    328.                 System.Text.StringBuilder sb = new System.Text.StringBuilder();
    329.                 sb.Append( "<basefont color=#FFFFFF><p>" );
    330.  
    331.                 foreach( string prop in list )
    332.                 {
    333.                     sb.AppendFormat( "{0}<br>", prop );
    334.                 }
    335.  
    336.                 return sb.ToString();
    337.                 #endregion
    338.             }
    339.             else
    340.             {
    341.                 #region Non AoS
    342.                 StringBuilder sb = new StringBuilder();
    343.                 sb.Append( "<basefont color=#FFFFFF><p>" );
    344.  
    345.                 // Get the item name
    346.                 if ( item.Name != null && item.Name.Length > 0 )
    347.                 {
    348.                     sb.AppendFormat( "{0}<br>", item.Name );
    349.                 }
    350.                 else
    351.                 {
    352.                     sb.AppendFormat( "{0}<br>", Capitalize( m_StringList.Table[ item.LabelNumber ] as string ) );
    353.                 }
    354.  
    355.                 // Amount
    356.                 if ( item.Amount > 1 )
    357.                 {
    358.                     sb.AppendFormat( AuctionSystem.ST[ 152 ] , item.Amount.ToString("#,0" ) );
    359.                 }
    360.  
    361.                 // Loot type
    362.                 if ( item.LootType != LootType.Regular )
    363.                 {
    364.                     sb.AppendFormat( "{0}<br>", item.LootType.ToString() );
    365.                 }
    366.  
    367.                 if ( item is IUsesRemaining )
    368.                 {
    369.                     sb.AppendFormat( AuctionSystem.ST[ 153 ] , ( item as IUsesRemaining ).UsesRemaining );
    370.                 }
    371.  
    372.                 // Manage item types
    373.  
    374.                 if ( item is BaseWand )
    375.                 {
    376.                     #region Wands
    377.                     BaseWand bw = item as BaseWand;
    378.                     sb.AppendFormat( AuctionSystem.ST[ 154 ] , bw.Effect.ToString() );
    379.                     sb.AppendFormat( AuctionSystem.ST[ 155 ] , bw.Charges );
    380.                     #endregion
    381.                 }
    382.                 else if ( item is BaseArmor )
    383.                 {
    384.                     #region Armor
    385.                     BaseArmor ba = item as BaseArmor;
    386.  
    387.                     if ( ba.PlayerConstructed )
    388.                     {
    389.                         if ( ba.Crafter != null )
    390.                         {
    391.                             sb.AppendFormat( AuctionSystem.ST[ 156 ] , ba.Crafter.Name );
    392.                         }
    393.                         sb.AppendFormat( AuctionSystem.ST[ 157 ] , ba.Resource.ToString() );
    394.                     }
    395.  
    396.                     sb.AppendFormat( AuctionSystem.ST[ 158 ] , ba.Quality.ToString() );
    397.                     sb.AppendFormat( AuctionSystem.ST[ 159 ] , ba.HitPoints, ba.MaxHitPoints );
    398.  
    399.                     if ( ba.Durability != ArmorDurabilityLevel.Regular )
    400.                     {
    401.                         sb.AppendFormat( AuctionSystem.ST[ 160 ] , ba.Durability.ToString() );
    402.                     }
    403.  
    404.                     if ( ba.ProtectionLevel != ArmorProtectionLevel.Regular )
    405.                     {
    406.                         sb.AppendFormat( AuctionSystem.ST[ 161 ] , ba.ProtectionLevel.ToString() );
    407.                     }
    408.                     #endregion
    409.                 }
    410.                 else if ( item is BaseWeapon )
    411.                 {
    412.                     #region Weapons
    413.                     BaseWeapon bw = item as BaseWeapon;
    414.  
    415.                     if ( bw.PlayerConstructed )
    416.                     {
    417.                         if ( bw.Crafter != null )
    418.                         {
    419.                             sb.AppendFormat( AuctionSystem.ST[ 156 ] , bw.Crafter.Name );
    420.                         }
    421.                         sb.AppendFormat( AuctionSystem.ST[ 157 ] , bw.Resource.ToString() );
    422.                     }
    423.  
    424.                     sb.AppendFormat( AuctionSystem.ST[ 158 ] , bw.Quality.ToString() );
    425.                     sb.AppendFormat( AuctionSystem.ST[ 159 ], bw.HitPoints, bw.MaxHitPoints );
    426.  
    427.                     if ( bw.PoisonCharges > 0 )
    428.                     {
    429.                         sb.AppendFormat( AuctionSystem.ST[ 162 ] , bw.PoisonCharges, bw.Poison.ToString() );
    430.                     }
    431.  
    432.                     if ( item is BaseRanged )
    433.                     {
    434.                         sb.AppendFormat( AuctionSystem.ST[ 163 ] , bw.MaxRange.ToString() );
    435.                     }
    436.  
    437.                     if ( bw.DamageLevel != WeaponDamageLevel.Regular )
    438.                     {
    439.                         sb.AppendFormat( AuctionSystem.ST[ 164 ] , bw.DamageLevel.ToString() );
    440.                     }
    441.  
    442.                     if ( bw.DurabilityLevel != WeaponDurabilityLevel.Regular )
    443.                     {
    444.                         sb.AppendFormat( AuctionSystem.ST[ 160 ] , bw.DurabilityLevel.ToString() );
    445.                     }
    446.  
    447.                     if ( bw.AccuracyLevel != WeaponAccuracyLevel.Regular )
    448.                     {
    449.                         if ( bw.AccuracyLevel == WeaponAccuracyLevel.Accurate )
    450.                         {
    451.                             sb.AppendFormat( AuctionSystem.ST[ 165 ] );
    452.                         }
    453.                         else
    454.                         {
    455.                             sb.AppendFormat( AuctionSystem.ST[ 166 ] , bw.AccuracyLevel.ToString() );
    456.                         }
    457.                     }
    458.  
    459.                     if ( bw.Slayer != SlayerName.None )
    460.                     {
    461.                         sb.AppendFormat( AuctionSystem.ST[ 167 ] , bw.Slayer.ToString() );
    462.                     }
    463.                     #endregion
    464.                 }
    465.                 else if ( item is TreasureMap )
    466.                 {
    467.                     #region Treasure Map
    468.                     TreasureMap tm = item as TreasureMap;
    469.                     sb.AppendFormat( AuctionSystem.ST[ 168 ] , tm.ChestMap );
    470.                     #endregion
    471.                 }
    472.                 else if ( item is Spellbook )
    473.                 {
    474.                     #region Spellbook
    475.                     Spellbook sp = item as Spellbook;
    476.                     sb.AppendFormat( AuctionSystem.ST[ 169 ] , sp.SpellCount );
    477.                     #endregion
    478.                 }
    479.                 else if ( item is PotionKeg )
    480.                 {
    481.                     #region Potion Keg
    482.                     PotionKeg pk = item as PotionKeg;
    483.  
    484.                     int number;
    485.  
    486.                     if ( pk.Held <= 0 )
    487.                         number = 502246; // The keg is empty.
    488.                     else if ( pk.Held < 5 )
    489.                         number = 502248; // The keg is nearly empty.
    490.                     else if ( pk.Held < 20 )
    491.                         number = 502249; // The keg is not very full.
    492.                     else if ( pk.Held < 30 )
    493.                         number = 502250; // The keg is about one quarter full.
    494.                     else if ( pk.Held < 40 )
    495.                         number = 502251; // The keg is about one third full.
    496.                     else if ( pk.Held < 47 )
    497.                         number = 502252; // The keg is almost half full.
    498.                     else if ( pk.Held < 54 )
    499.                         number = 502254; // The keg is approximately half full.
    500.                     else if ( pk.Held < 70 )
    501.                         number = 502253; // The keg is more than half full.
    502.                     else if ( pk.Held < 80 )
    503.                         number = 502255; // The keg is about three quarters full.
    504.                     else if ( pk.Held < 96 )
    505.                         number = 502256; // The keg is very full.
    506.                     else if ( pk.Held < 100 )
    507.                         number = 502257; // The liquid is almost to the top of the keg.
    508.                     else
    509.                         number = 502258; // The keg is completely full.
    510.  
    511.                     sb.AppendFormat( Capitalize( m_StringList.Table[ number ] as string ) );
    512.                     #endregion
    513.                 }
    514.  
    515.                 return sb.ToString();
    516.  
    517.                 #endregion
    518.             }
    519.         }
    520.  
    521.         /// <summary>
    522.         /// Capitalizes each word in a string
    523.         /// </summary>
    524.         /// <param name="property">The input string</param>
    525.         /// <returns>The output string </returns>
    526.         private static string Capitalize( string property )
    527.         {
    528.  
    529.             string[] parts = property.Split( ' ' );
    530.             StringBuilder sb = new StringBuilder();
    531.  
    532.             for ( int i = 0; i < parts.Length; i++ )
    533.             {
    534.                 string part = parts[ i ];
    535.  
    536.                 if ( part.Length == 0 )
    537.                 {
    538.                     continue;
    539.                 }
    540.  
    541.                 char c = char.ToUpper( part[ 0 ] );
    542.  
    543.                 part = part.Substring( 1 );
    544.                 sb.AppendFormat( "{0}{1}", string.Concat( c, part ), i < parts.Length - 1 ? " " : "" );
    545.             }
    546.  
    547.             return sb.ToString();
    548.         }
    549.  
    550.         /// <summary>
    551.         /// Converts a localization number and its arguments to a valid string
    552.         /// </summary>
    553.         /// <param name="number">The localization number of the label</param>
    554.         /// <param name="arguments">The arguments for the label</param>
    555.         /// <returns>The translated string</returns>
    556.         private static string ComputeProperty( int number, string arguments )
    557.         {
    558.             string prop = m_StringList.Table[ number ] as string;
    559.  
    560.             if ( prop == null )
    561.             {
    562.                 return AuctionSystem.ST[ 170 ] ;
    563.             }
    564.  
    565.             if ( arguments == null || arguments.Length == 0 )
    566.             {
    567.                 return Capitalize( prop );
    568.             }
    569.  
    570.             string[] args = arguments.Split( '\t' );
    571.             Regex reg = new Regex( @"~\d+\w*~", RegexOptions.None );
    572.             MatchCollection matches = reg.Matches( prop, 0 );
    573.  
    574.             if ( matches.Count == args.Length )
    575.             {
    576.                 // Valid
    577.                 for ( int i = 0; i < matches.Count; i++ )
    578.                 {
    579.                     if ( args[ i ].StartsWith( "#" ) )
    580.                     {
    581.                         int loc = -1;
    582.  
    583.                         try
    584.                         {
    585.                             loc = int.Parse( args[ i ].Substring( 1 ) );
    586.                         }
    587.                         catch {}
    588.  
    589.                         if ( loc != -1 )
    590.                         {
    591.                             args[ i ] = m_StringList.Table[ loc ] as string;
    592.                         }
    593.                     }
    594.  
    595.                     Match m = matches [ i ];
    596.  
    597.                     prop = prop.Replace( m.Value, args[ i ] );
    598.                 }
    599.  
    600.                 return Capitalize( prop );
    601.             }
    602.             else
    603.             {
    604.                 return AuctionSystem.ST[ 171 ] ;
    605.             }
    606.         }
    607.  
    608.         #endregion
    609.  
    610.         #region Variables
    611.  
    612.         private Item m_Item;
    613.         private Mobile m_Owner;
    614.         private DateTime m_StartTime;
    615.         private DateTime m_EndTime;
    616.         private TimeSpan m_Duration = TimeSpan.FromDays( 7 );
    617.         private int m_MinBid = 100;
    618.         private int m_Reserve = 100;
    619.         private string m_Description = "";
    620.         private ArrayList m_Bids;
    621.         private string m_WebLink = "";
    622.         private string m_ItemName;
    623.         private bool m_Pending;
    624.         private ItemInfo[] m_Items;
    625.         private Guid m_ID;
    626.         private AuctionPendency m_OwnerPendency = AuctionPendency.Pending;
    627.         private AuctionPendency m_BuyerPendency = AuctionPendency.Pending;
    628.         private AuctionMessage m_OwnerMessage = AuctionMessage.None;
    629.         private AuctionMessage m_BuyerMessage = AuctionMessage.None;
    630.         private DateTime m_PendingEnd;
    631.         private int m_BuyNow = 0;
    632.  
    633.         #region Props
    634.  
    635.         [ CommandProperty( AccessLevel.Administrator ) ]
    636.             /// <summary>
    637.             /// States whether this auction allows the buy now feature
    638.             /// </summary>
    639.         public bool AllowBuyNow
    640.         {
    641.             get { return m_BuyNow > 0; }
    642.         }
    643.  
    644.         [ CommandProperty( AccessLevel.Administrator ) ]
    645.             /// <summary>
    646.             /// Gets the buy now value
    647.             /// </summary>
    648.         public int BuyNow
    649.         {
    650.             get { return m_BuyNow; }
    651.             set { m_BuyNow = value; }
    652.         }
    653.  
    654.         [ CommandProperty( AccessLevel.Administrator ) ]
    655.             /// <summary>
    656.             /// Gets the date and time corrsponding to the moment when the pending situation will automatically end
    657.             /// </summary>
    658.         public DateTime PendingEnd
    659.         {
    660.             get { return m_PendingEnd; }
    661.         }
    662.  
    663.         [ CommandProperty( AccessLevel.Administrator ) ]
    664.             /// <summary>
    665.             /// Gets the item being sold at the auction
    666.             /// </summary>
    667.         public Item Item
    668.         {
    669.             get { return m_Item; }
    670.         }
    671.  
    672.         [ CommandProperty( AccessLevel.Administrator ) ]
    673.             /// <summary>
    674.             /// Gets the owner of the item
    675.             /// </summary>
    676.         public Mobile Owner
    677.         {
    678.             get { return m_Owner; }
    679.         }
    680.  
    681.         [ CommandProperty( AccessLevel.Administrator ) ]
    682.             /// <summary>
    683.             /// Gets the starting time for this auction
    684.             /// </summary>
    685.         public DateTime StartTime
    686.         {
    687.             get { return m_StartTime; }
    688.         }
    689.  
    690.         [ CommandProperty( AccessLevel.Administrator ) ]
    691.             /// <summary>
    692.             /// Gets the end time for this auction
    693.             /// </summary>
    694.         public DateTime EndTime
    695.         {
    696.             get { return m_EndTime; }
    697.         }
    698.  
    699.         /// <summary>
    700.         /// Gets the running length of the auction for this item
    701.         /// </summary>
    702.         public TimeSpan Duration
    703.         {
    704.             get { return m_Duration; }
    705.             set
    706.             {
    707.                 try
    708.                 {
    709.                     m_Duration = value;
    710.                 }
    711.                 catch
    712.                 {
    713.                     m_Duration = TimeSpan.Zero;
    714.                 }
    715.             }
    716.         }
    717.  
    718.         [ CommandProperty( AccessLevel.Administrator ) ]
    719.             /// <summary>
    720.             /// Gets the time to live left for this auction
    721.             /// </summary>
    722.         public TimeSpan TimeLeft
    723.         {
    724.             get
    725.             {
    726.                 return m_EndTime - DateTime.Now;
    727.             }
    728.         }
    729.  
    730.         /// <summary>
    731.         /// Gets or sets the minimum bid allowed for this item
    732.         /// </summary>
    733.         public int MinBid
    734.         {
    735.             get { return m_MinBid; }
    736.             set { m_MinBid = value; }
    737.         }
    738.  
    739.         /// <summary>
    740.         /// Gets or sets the reserve price for the item
    741.         /// </summary>
    742.         public int Reserve
    743.         {
    744.             get { return m_Reserve; }
    745.             set { m_Reserve = value; }
    746.         }
    747.  
    748.         [ CommandProperty( AccessLevel.Administrator ) ]
    749.             /// <summary>
    750.             /// Gets or sets the description for this item
    751.             /// </summary>
    752.         public string Description
    753.         {
    754.             get { return m_Description; }
    755.             set { m_Description = value; }
    756.         }
    757.  
    758.         [ CommandProperty( AccessLevel.Administrator ) ]
    759.             /// <summary>
    760.             /// A web link associated with this auction item
    761.             /// </summary>
    762.         public string WebLink
    763.         {
    764.             get { return m_WebLink; }
    765.             set
    766.             {
    767.                 if ( value != null && value.Length > 0 )
    768.                 {
    769.                     if ( value.ToLower().StartsWith( "http://" ) && value.Length > 7 )
    770.                     {
    771.                         value = value.Substring( 7 );
    772.                     }
    773.                 }
    774.  
    775.                 m_WebLink = value;
    776.             }
    777.         }
    778.  
    779.         /// <summary>
    780.         /// Gets or sets the list of existing bids
    781.         /// </summary>
    782.         public ArrayList Bids
    783.         {
    784.             get { return m_Bids; }
    785.             set { m_Bids = value; }
    786.         }
    787.  
    788.         [ CommandProperty( AccessLevel.Administrator ) ]
    789.             /// <summary>
    790.             /// Gets the account that's selling this item
    791.             /// </summary>
    792.         public Account Account
    793.         {
    794.             get
    795.             {
    796.                 if ( m_Owner != null && m_Owner.Account != null )
    797.                 {
    798.                     return m_Owner.Account as Account;
    799.                 }
    800.                 else
    801.                 {
    802.                     return null;
    803.                 }
    804.             }
    805.         }
    806.  
    807.         [ CommandProperty( AccessLevel.Administrator ) ]
    808.             /// <summary>
    809.             /// Gets or sets the name of the item being sold
    810.             /// </summary>
    811.         public string ItemName
    812.         {
    813.             get { return m_ItemName; }
    814.             set { m_ItemName = value; }
    815.         }
    816.  
    817.         [ CommandProperty( AccessLevel.Administrator ) ]
    818.             /// <summary>
    819.             /// True if the auction is over but the reserve hasn't been met and the owner still haven't decided
    820.             /// if to sell the item or not. This value makes no sense before the auction is over.
    821.             /// </summary>
    822.         public bool Pending
    823.         {
    824.             get { return m_Pending; }
    825.         }
    826.  
    827.         /// <summary>
    828.         /// Gets the definitions of the items sold
    829.         /// </summary>
    830.         public ItemInfo[] Items
    831.         {
    832.             get { return m_Items; }
    833.         }
    834.  
    835.         [ CommandProperty( AccessLevel.Administrator ) ]
    836.             /// <summary>
    837.             /// Gets the number of items sold
    838.             /// </summary>
    839.         public int ItemCount
    840.         {
    841.             get { return m_Items.Length; }
    842.         }
    843.  
    844.         [ CommandProperty( AccessLevel.Administrator ) ]
    845.             /// <summary>
    846.             /// Gets the unique ID of this auction
    847.             /// </summary>
    848.         public Guid ID
    849.         {
    850.             get { return m_ID; }
    851.         }
    852.  
    853.         #endregion
    854.  
    855.         #endregion
    856.  
    857.         #region Serialization
    858.  
    859.         /// <summary>
    860.         /// Saves the auction item into the world file
    861.         /// </summary>
    862.         /// <param name="writer"></param>
    863.         public void Serialize( GenericWriter writer )
    864.         {
    865.             // Version 1
    866.             writer.Write( m_BuyNow );
    867.  
    868.             // Version 0
    869.             writer.Write( m_Owner );
    870.             writer.Write( m_StartTime );
    871.             writer.Write( m_Duration );
    872.             writer.Write( m_MinBid );
    873.             writer.Write( m_Reserve );
    874.             writer.Write( m_Duration );
    875.             writer.Write( m_Description );
    876.             writer.Write( m_WebLink );
    877.             writer.Write( m_Pending );
    878.             writer.Write( m_ItemName );
    879.             writer.Write( m_Item );
    880.             writer.Write( m_ID.ToString() );
    881.             writer.WriteDeltaTime( m_EndTime );
    882.             writer.Write( (byte) m_OwnerPendency );
    883.             writer.Write( (byte) m_BuyerPendency );
    884.             writer.Write( (byte) m_OwnerMessage );
    885.             writer.Write( (byte) m_BuyerMessage );
    886.             writer.WriteDeltaTime( m_PendingEnd );
    887.  
    888.             writer.Write( m_Items.Length );
    889.             // Items
    890.             foreach( ItemInfo ii in m_Items )
    891.             {
    892.                 ii.Serialize( writer );
    893.             }
    894.  
    895.             // Bids
    896.             writer.Write( m_Bids.Count );
    897.             foreach( Bid bid in m_Bids )
    898.             {
    899.                 bid.Serialize( writer );
    900.             }
    901.         }
    902.  
    903.         /// <summary>
    904.         /// Loads an AuctionItem
    905.         /// </summary>
    906.         /// <returns>An AuctionItem</returns>
    907.         public static AuctionItem Deserialize( GenericReader reader, int version )
    908.         {
    909.             AuctionItem auction = new AuctionItem();
    910.  
    911.             switch ( version )
    912.             {
    913.                 case 1:
    914.                     auction.m_BuyNow = reader.ReadInt();
    915.                     goto case 0;
    916.  
    917.                 case 0:
    918.                     auction.m_Owner = reader.ReadMobile();
    919.                     auction.m_StartTime = reader.ReadDateTime();
    920.                     auction.m_Duration = reader.ReadTimeSpan();
    921.                     auction.m_MinBid = reader.ReadInt();
    922.                     auction.m_Reserve = reader.ReadInt();
    923.                     auction.m_Duration = reader.ReadTimeSpan();
    924.                     auction.m_Description = reader.ReadString();
    925.                     auction.m_WebLink = reader.ReadString();
    926.                     auction.m_Pending = reader.ReadBool();
    927.                     auction.m_ItemName = reader.ReadString();
    928.                     auction.m_Item = reader.ReadItem();
    929.                     auction.m_ID = new Guid( reader.ReadString() );
    930.                     auction.m_EndTime = reader.ReadDeltaTime();
    931.                     auction.m_OwnerPendency = (AuctionPendency) reader.ReadByte();
    932.                     auction.m_BuyerPendency = (AuctionPendency) reader.ReadByte();
    933.                     auction.m_OwnerMessage = (AuctionMessage) reader.ReadByte();
    934.                     auction.m_BuyerMessage = (AuctionMessage) reader.ReadByte();
    935.                     auction.m_PendingEnd = reader.ReadDeltaTime();
    936.  
    937.                     int count = reader.ReadInt();
    938.                     auction.m_Items = new ItemInfo[ count ];
    939.  
    940.                     for ( int i = 0; i < count; i++ )
    941.                     {
    942.                         auction.m_Items[ i ] = ItemInfo.Deserialize( reader, version );
    943.                     }
    944.  
    945.                     count = reader.ReadInt();
    946.  
    947.                     for ( int i = 0; i < count; i++ )
    948.                     {
    949.                         auction.Bids.Add( Bid.Deserialize( reader, version ) );
    950.                     }
    951.                     break;
    952.             }
    953.  
    954.             return auction;
    955.         }
    956.  
    957.         #endregion
    958.  
    959.         #region Properties
    960.  
    961.         [ CommandProperty( AccessLevel.Administrator ) ]
    962.             /// <summary>
    963.             /// Gets the minimum increment required for the auction
    964.             /// </summary>
    965.         public int BidIncrement
    966.         {
    967.             get
    968.             {
    969.                 if ( m_MinBid <= 100 )
    970.                     return 50; //return 10;
    971.  
    972.                 if (m_MinBid <= 250)
    973.                     return 75;
    974.  
    975.                 if ( m_MinBid <= 500 )
    976.                     return 100; //return 20;
    977.  
    978.                 if (m_MinBid <= 750)
    979.                     return 200;
    980.  
    981.                 if ( m_MinBid <= 1000 )
    982.                     return 300; //return 50;
    983.  
    984.                 if (m_MinBid <= 2500)
    985.                     return 400;
    986.  
    987.                 if ( m_MinBid <= 5000 )
    988.                     return 500; //return 100;
    989.  
    990.                 if (m_MinBid <= 7500)
    991.                     return 600;
    992.  
    993.                 if ( m_MinBid <= 10000 )
    994.                     return 700; //return 200;
    995.  
    996.                 if (m_MinBid <= 15000)
    997.                     return 800;
    998.  
    999.                 if ( m_MinBid <= 20000 )
    1000.                     return 1000; //return 250;
    1001.  
    1002.                 if (m_MinBid <= 30000)
    1003.                     return 1500;
    1004.  
    1005.                 if (m_MinBid <= 40000)
    1006.                     return 2000;
    1007.  
    1008.                 if ( m_MinBid <= 50000 )
    1009.                     return 3000; //return 500;
    1010.  
    1011.                 return 4000;
    1012.             }
    1013.         }
    1014.  
    1015.         [ CommandProperty( AccessLevel.Administrator ) ]
    1016.             /// <summary>
    1017.             /// States whether an item has at least one bid
    1018.             /// </summary>
    1019.         public bool HasBids
    1020.         {
    1021.             get { return m_Bids.Count > 0; }
    1022.         }
    1023.  
    1024.         /// <summary>
    1025.         /// Gets the highest bid for this item
    1026.         /// </summary>
    1027.         public Bid HighestBid
    1028.         {
    1029.             get
    1030.             {
    1031.                 if ( m_Bids.Count > 0 )
    1032.                     return m_Bids[ 0 ] as Bid;
    1033.                 else
    1034.                     return null;
    1035.             }
    1036.         }
    1037.  
    1038.         [ CommandProperty( AccessLevel.Administrator ) ]
    1039.         public Mobile HighestBidder
    1040.         {
    1041.             get
    1042.             {
    1043.                 if ( m_Bids.Count > 0 )
    1044.                     return ( m_Bids[ 0 ] as Bid ).Mobile;
    1045.                 else
    1046.                     return null;
    1047.             }
    1048.         }
    1049.  
    1050.         [ CommandProperty( AccessLevel.Administrator ) ]
    1051.         public int HighestBidValue
    1052.         {
    1053.             get
    1054.             {
    1055.                 if ( m_Bids.Count > 0 )
    1056.                     return ( m_Bids[ 0 ] as Bid ).Amount;
    1057.                 else return 0;
    1058.             }
    1059.         }
    1060.  
    1061.         [ CommandProperty( AccessLevel.Administrator ) ]
    1062.             /// <summary>
    1063.             /// States whether the reserve has been met for this item
    1064.             /// </summary>
    1065.         public bool ReserveMet
    1066.         {
    1067.             get { return HighestBid != null && HighestBid.Amount >= m_Reserve; }
    1068.         }
    1069.  
    1070.         [ CommandProperty( AccessLevel.Administrator ) ]
    1071.             /// <summary>
    1072.             /// States whether this auction has expired
    1073.             /// </summary>
    1074.         public bool Expired
    1075.         {
    1076.             get { return DateTime.Now > m_EndTime; }
    1077.         }
    1078.  
    1079.         /// <summary>
    1080.         /// Gets the minimum bid that a player can place
    1081.         /// </summary>
    1082.         public int MinNewBid
    1083.         {
    1084.             get
    1085.             {
    1086.                 if ( HighestBid != null )
    1087.                     return HighestBid.Amount;
    1088.                 else
    1089.                     return m_MinBid;
    1090.             }
    1091.         }
    1092.  
    1093.         [ CommandProperty( AccessLevel.Administrator ) ]
    1094.             /// <summary>
    1095.             /// Gets the next deadline required by this auction
    1096.             /// </summary>
    1097.         public DateTime Deadline
    1098.         {
    1099.             get
    1100.             {
    1101.                 if ( ! Expired )
    1102.                 {
    1103.                     return m_EndTime;
    1104.                 }
    1105.                 else if ( m_Pending )
    1106.                 {
    1107.                     return m_PendingEnd;
    1108.                 }
    1109.                 else
    1110.                 {
    1111.                     return DateTime.MaxValue;
    1112.                 }
    1113.             }
    1114.         }
    1115.  
    1116.         [ CommandProperty( AccessLevel.Administrator ) ]
    1117.             /// <summary>
    1118.             /// Specifies if the pending period has timed out
    1119.             /// </summary>
    1120.         public bool PendingExpired
    1121.         {
    1122.             get
    1123.             {
    1124.                 return DateTime.Now >= m_PendingEnd;
    1125.             }
    1126.         }
    1127.  
    1128.         [ CommandProperty( AccessLevel.Administrator ) ]
    1129.             /// <summary>
    1130.             /// Gets the time left before the pending period expired
    1131.             /// </summary>
    1132.         public TimeSpan PendingTimeLeft
    1133.         {
    1134.             get { return m_PendingEnd - DateTime.Now; }
    1135.         }
    1136.  
    1137.         [ CommandProperty( AccessLevel.Administrator ) ]
    1138.             /// <summary>
    1139.             /// States whether this auction is selling a pet
    1140.             /// </summary>
    1141.         public bool Creature
    1142.         {
    1143.             get { return m_Item is MobileStatuette; }
    1144.         }
    1145.  
    1146.         [ CommandProperty( AccessLevel.Administrator ) ]
    1147.             /// <summary>
    1148.             /// Gets the BaseCreature sold through this auction. This will be null when selling an item.
    1149.             /// </summary>
    1150.         public BaseCreature Pet
    1151.         {
    1152.             get
    1153.             {
    1154.                 if ( Creature )
    1155.                 {
    1156.                     return ((MobileStatuette)m_Item).ShrunkenPet;
    1157.                 }
    1158.  
    1159.                 return null;
    1160.             }
    1161.         }
    1162.  
    1163.         #endregion
    1164.  
    1165.         /// <summary>
    1166.         /// Creates a new AuctionItem
    1167.         /// </summary>
    1168.         /// <param name="item">The item being sold</param>
    1169.         /// <param name="owner">The owner of the item</param>
    1170.         public AuctionItem( Item item, Mobile owner )
    1171.         {
    1172.             m_ID = Guid.NewGuid();
    1173.             m_Item = item;
    1174.             m_Owner = owner;
    1175.             m_Bids = new ArrayList();
    1176.  
    1177.             if ( ! Creature )
    1178.             {
    1179.                 m_Item.Visible = false;
    1180.                 m_Owner.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 172 ] );
    1181.             }
    1182.  
    1183.             // Item name
    1184.             if ( m_Item.Name != null && m_Item.Name.Length > 0 )
    1185.             {
    1186.                 m_ItemName = m_Item.Name;
    1187.             }
    1188.             else
    1189.             {
    1190.                 m_ItemName = m_StringList.Table[ m_Item.LabelNumber ] as string;
    1191.             }
    1192.  
    1193.             if ( m_Item.Amount > 1 )
    1194.             {
    1195.                 m_ItemName = string.Format( "{0} {1}", m_Item.Amount.ToString("#,0" ), m_ItemName );
    1196.             }
    1197.         }
    1198.  
    1199.         /// <summary>
    1200.         /// Creates an AuctionItem - for use in deserialization
    1201.         /// </summary>
    1202.         private AuctionItem()
    1203.         {
    1204.             m_Bids = new ArrayList();
    1205.         }
    1206.  
    1207.         [ System.Runtime.CompilerServices.IndexerName( "SoldItem" ) ]
    1208.             /// <summary>
    1209.             /// Gets the item info corresponding to the index value
    1210.             /// </summary>
    1211.         public ItemInfo this[int index]
    1212.         {
    1213.             get
    1214.             {
    1215.                 if ( index > -1 && index < m_Items.Length )
    1216.                 {
    1217.                     return m_Items[ index ];
    1218.                 }
    1219.                 else
    1220.                 {
    1221.                     return null;
    1222.                 }
    1223.             }
    1224.         }
    1225.  
    1226.         /// <summary>
    1227.         /// Confirms the auction item and adds it into the system
    1228.         /// </summary>
    1229.         public void Confirm()
    1230.         {
    1231.             m_StartTime = DateTime.Now;
    1232.             m_EndTime = m_StartTime + m_Duration;
    1233.  
    1234.             if ( Creature && Pet != null )
    1235.             {
    1236.                 Pet.ControlTarget = null;
    1237.                 Pet.ControlOrder = OrderType.Stay;
    1238.                 Pet.Internalize();
    1239.  
    1240.                 Pet.SetControlMaster( null );
    1241.                 Pet.SummonMaster = null;
    1242.             }
    1243.  
    1244.             // Calculate all the ItemInfo
    1245.             if ( m_Item is Container && m_Item.Items.Count > 0 )
    1246.             {
    1247.                 // Container with items
    1248.                 m_Items = new ItemInfo[ m_Item.Items.Count ];
    1249.  
    1250.                 for ( int i = 0; i < m_Items.Length; i++ )
    1251.                 {
    1252.                     m_Items[ i ] = new ItemInfo( m_Item.Items[ i ] as Item );
    1253.                 }
    1254.             }
    1255.             else
    1256.             {
    1257.                 m_Items = new ItemInfo[ 1 ];
    1258.  
    1259.                 m_Items[ 0 ] = new ItemInfo( m_Item );
    1260.             }
    1261.  
    1262.             AuctionSystem.Add( this );
    1263.             AuctionScheduler.UpdateDeadline( m_EndTime );
    1264.  
    1265.             AuctionLog.WriteNewAuction( this );
    1266.         }
    1267.  
    1268.         /// <summary>
    1269.         /// Cancels the new auction and returns the item to the owner
    1270.         /// </summary>
    1271.         public void Cancel()
    1272.         {
    1273.             if ( !Creature )
    1274.             {
    1275.                 m_Item.Visible = true;
    1276.                 m_Owner.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 173 ] );
    1277.             }
    1278.             else
    1279.             {
    1280.                 ( m_Item as MobileStatuette ).GiveCreatureTo( m_Owner );
    1281.                 m_Owner.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 174 ] );
    1282.             }
    1283.         }
    1284.  
    1285.         /// <summary>
    1286.         /// Sends the associated web link to a mobile
    1287.         /// </summary>
    1288.         /// <param name="m">The mobile that should receive the web link</param>
    1289.         public void SendLinkTo( Mobile m )
    1290.         {
    1291.             if ( m != null && m.NetState != null )
    1292.             {
    1293.                 if ( m_WebLink != null && m_WebLink.Length > 0 )
    1294.                 {
    1295.                     m.LaunchBrowser( string.Format( "http://{0}", m_WebLink ) );
    1296.                 }
    1297.             }
    1298.         }
    1299.  
    1300.         /// <summary>
    1301.         /// Verifies if a mobile can place a bid on this item
    1302.         /// </summary>
    1303.         /// <param name="m">The Mobile trying to bid</param>
    1304.         /// <returns>True if the mobile is allowed to bid</returns>
    1305.         public bool CanBid( Mobile m )
    1306.         {
    1307.             if ( m.AccessLevel > AccessLevel.Player )
    1308.                 return false; // Staff shoudln't bid. This will also give the bids view to staff members.
    1309.  
    1310.             if ( this.Account == ( m.Account as Account ) ) // Same account as auctioneer
    1311.                 return false;
    1312.  
    1313.             if ( Creature )
    1314.             {
    1315.                 return ( Pet != null && Pet.CanBeControlledBy( m ) );
    1316.             }
    1317.  
    1318.             return true;
    1319.         }
    1320.  
    1321.         /// <summary>
    1322.         /// Verifies if a mobile is the owner of this auction (checks accounts)
    1323.         /// </summary>
    1324.         /// <param name="m">The mobile being checked</param>
    1325.         /// <returns>True if the mobile is the owner of the auction</returns>
    1326.         public bool IsOwner( Mobile m )
    1327.         {
    1328.             return ( this.Account == ( m.Account as Account ) );
    1329.         }
    1330.  
    1331.         /// <summary>
    1332.         /// Places a new bid
    1333.         /// </summary>
    1334.         /// <param name="from">The Mobile bidding</param>
    1335.         /// <param name="amount">The bid amount</param>
    1336.         /// <returns>True if the bid has been added and accepted</returns>
    1337.         public bool PlaceBid( Mobile from, int amount )
    1338.         {
    1339.             if ( ! CanBid( from ) )
    1340.                 return false;
    1341.  
    1342.             if ( HighestBid != null )
    1343.             {
    1344.                 if ( amount <= HighestBid.Amount )
    1345.                 {
    1346.                     from.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 176 ] );
    1347.                     return false;
    1348.                 }
    1349.             }
    1350.             else if ( amount < m_MinBid )
    1351.             {
    1352.                 from.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 177 ] );
    1353.                 return false;
    1354.             }
    1355.  
    1356.             int delta = 0;
    1357.  
    1358.             if ( HighestBid != null )
    1359.                 delta = amount - HighestBid.Amount;
    1360.             else
    1361.                 delta = amount - m_MinBid;
    1362.  
    1363.             if (BidIncrement > delta && HasBids)
    1364.             {
    1365.                 from.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 204 ], BidIncrement );
    1366.                 return false;
    1367.             }
    1368.  
    1369.             // Ok, do bid
    1370.             Bid bid = Bid.CreateBid( from, amount );
    1371.  
    1372.             if ( bid != null )
    1373.             {
    1374.                 if ( HighestBid != null )
    1375.                 {
    1376.                     HighestBid.Outbid( this ); // Return money to previous highest bidder
    1377.                 }
    1378.  
    1379.                 World.Broadcast(0x35, true, "A {0} just recieved a {1} bid on [Myauction ", m_ItemName, amount);
    1380.                          
    1381.                 m_Bids.Insert( 0, bid );
    1382.                 AuctionLog.WriteBid( this );
    1383.  
    1384.                 // Check for auction extension
    1385.                 if ( AuctionConfig.LateBidExtention > TimeSpan.Zero )
    1386.                 {
    1387.                     TimeSpan timeLeft = m_EndTime - DateTime.Now;
    1388.  
    1389.                     if ( timeLeft < TimeSpan.FromMinutes( 5.0 ) )
    1390.                     {
    1391.                         m_EndTime += AuctionConfig.LateBidExtention;
    1392.                         bid.Mobile.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 230 ] );
    1393.                     }
    1394.                 }
    1395.             }
    1396.  
    1397.             return bid != null;
    1398.         }
    1399.  
    1400.         /// <summary>
    1401.         /// Forces the end of the auction when the item or creature has been deleted
    1402.         /// </summary>
    1403.         public void EndInvalid()
    1404.         {
    1405.             AuctionSystem.Auctions.Remove( this );
    1406.  
    1407.             if ( HighestBid != null )
    1408.             {
    1409.                 AuctionGoldCheck gold = new AuctionGoldCheck( this, AuctionResult.ItemDeleted );
    1410.                 GiveItemTo( HighestBid.Mobile, gold );
    1411.             }
    1412.  
    1413.             // The item has been deleted, no need to return it to the owner.
    1414.             // If it's a statuette, delete it
    1415.             if ( Creature && m_Item != null )
    1416.             {
    1417.                 m_Item.Delete();
    1418.             }
    1419.  
    1420.             AuctionLog.WriteEnd( this, AuctionResult.ItemDeleted, null, null );
    1421.  
    1422.             // Over.
    1423.         }
    1424.  
    1425.         /// <summary>
    1426.         /// Forces the end of the auction and removes it from the system
    1427.         /// </summary>
    1428.         /// <param name="m">The staff member deleting the auction</param>
    1429.         /// <param name="itemfate">Specifies what should occur with the item</param>
    1430.         public void StaffDelete( Mobile m, ItemFate itemfate )
    1431.         {
    1432.             if ( AuctionSystem.Auctions.Contains( this ) )
    1433.                 AuctionSystem.Auctions.Remove( this );
    1434.             else if ( AuctionSystem.Pending.Contains( this ) )
    1435.                 AuctionSystem.Pending.Remove( this );
    1436.  
    1437.             if ( HighestBid != null )
    1438.             {
    1439.                 AuctionGoldCheck gold = new AuctionGoldCheck( this, AuctionResult.StaffRemoved );
    1440.                 GiveItemTo( HighestBid.Mobile, gold );
    1441.             }
    1442.  
    1443.             AuctionItemCheck check = new AuctionItemCheck( this, AuctionResult.StaffRemoved );
    1444.             string comments = null;
    1445.  
    1446.             switch( itemfate )
    1447.             {
    1448.                 case ItemFate.Delete :
    1449.  
    1450.                     check.Delete();
    1451.                     comments = "The item has been deleted";
    1452.                     break;
    1453.  
    1454.                 case ItemFate.ReturnToOwner:
    1455.  
    1456.                     GiveItemTo( m_Owner, check );
    1457.                     comments = "The item has been returned to the owner";
    1458.                     break;
    1459.  
    1460.                 case ItemFate.ReturnToStaff:
    1461.  
    1462.                     GiveItemTo( m, check );
    1463.                     comments = "The item has been claimed by the staff";
    1464.                     break;
    1465.             }
    1466.  
    1467.             AuctionLog.WriteEnd( this, AuctionResult.StaffRemoved, m, comments );
    1468.  
    1469.             // OVer.
    1470.         }
    1471.  
    1472.         /// <summary>
    1473.         /// Ends the auction.
    1474.         /// This function is called by the auction system during its natural flow
    1475.         /// </summary>
    1476.         /// <param name="m">The Mobile eventually forcing the ending</param>
    1477.         public void End( Mobile m )
    1478.         {
    1479.             AuctionSystem.Auctions.Remove( this );
    1480.  
    1481.             if ( HighestBid == null )
    1482.             {
    1483.                 // No bids, simply return the item
    1484.                 AuctionCheck item = new AuctionItemCheck( this, AuctionResult.NoBids );
    1485.                 GiveItemTo( m_Owner, item );
    1486.  
    1487.                 // Over, this auction no longer exists
    1488.                 AuctionLog.WriteEnd( this, AuctionResult.NoBids, m, null );
    1489.             }
    1490.             else
    1491.             {
    1492.                 // Verify that all items still exist too, otherwise make it pending
    1493.                 if ( IsValid() && ReserveMet )
    1494.                 {
    1495.                     // Auction has been succesful
    1496.                     AuctionCheck item = new AuctionItemCheck( this, AuctionResult.Succesful );
    1497.                     GiveItemTo( HighestBid.Mobile, item );
    1498.  
    1499.                     AuctionCheck gold = new AuctionGoldCheck( this, AuctionResult.Succesful );
    1500.                     GiveItemTo( m_Owner, gold );
    1501.  
    1502.                     // Over, this auction no longer exists m_Auction.ItemName
    1503.                     AuctionLog.WriteEnd(this, AuctionResult.Succesful, m, null);
    1504.  
    1505.                     if (HighestBid != null)
    1506.                     {
    1507.                         World.Broadcast(95, true, "{0} just sold for {1} gold with {2} bids", this.ItemName, HighestBid.Amount, Bids.Count);
    1508.                     }
    1509.                 }
    1510.                 else
    1511.                 {
    1512.                     // Reserve hasn't been met or auction isn't valid, this auction is pending
    1513.                     m_Pending = true;
    1514.                     m_PendingEnd = DateTime.Now + TimeSpan.FromDays( AuctionConfig.DaysForConfirmation );
    1515.                     AuctionSystem.Pending.Add( this );
    1516.  
    1517.                     DoOwnerMessage();
    1518.                     DoBuyerMessage();
    1519.  
    1520.                     Mobile owner = GetOnlineMobile( m_Owner );
    1521.                     Mobile buyer = GetOnlineMobile( HighestBid.Mobile );
    1522.  
    1523.                     SendMessage( owner );
    1524.                     SendMessage( buyer );
    1525.  
    1526.                     AuctionScheduler.UpdateDeadline( m_PendingEnd );
    1527.  
    1528.                     AuctionLog.WritePending( this, ReserveMet ? "Item deleted" : "Reserve not met" );
    1529.                 }
    1530.             }
    1531.         }
    1532.  
    1533.         /// <summary>
    1534.         /// Gets the online mobile belonging to a mobile's account
    1535.         /// </summary>
    1536.         private Mobile GetOnlineMobile( Mobile m )
    1537.         {
    1538.             if ( m == null || m.Account == null )
    1539.                 return null;
    1540.  
    1541.             if ( m.NetState != null )
    1542.                 return m;
    1543.  
    1544.             Account acc = m.Account as Account;
    1545.  
    1546.             for ( int i = 0; i < 5; i++ )
    1547.             {
    1548.                 Mobile mob = acc[ i ];
    1549.  
    1550.                 if ( mob != null && mob.NetState != null )
    1551.                 {
    1552.                     return mob;
    1553.                 }
    1554.             }
    1555.  
    1556.             return null;
    1557.         }
    1558.  
    1559.         /// <summary>
    1560.         /// Ends the auction.
    1561.         /// This function is called when the system is being disbanded and all auctions must be forced close
    1562.         /// The item will be returned to the original owner, and the highest bidder will receive the money back
    1563.         /// </summary>
    1564.         public void ForceEnd()
    1565.         {
    1566.             AuctionSystem.Auctions.Remove( this );
    1567.  
    1568.             // Turn the item into a deed and give it to the auction owner
    1569.             AuctionCheck item = new AuctionItemCheck( this, AuctionResult.SystemStopped );
    1570.  
    1571.             if ( item != null )
    1572.                 GiveItemTo( m_Owner, item ); // This in case the item has been wiped or whatever
    1573.  
    1574.             if ( HighestBid != null )
    1575.             {
    1576.                 HighestBid.AuctionCanceled( this );
    1577.             }
    1578.  
    1579.             AuctionLog.WriteEnd( this, AuctionResult.SystemStopped, null, null );
    1580.         }
    1581.  
    1582.         /// <summary>
    1583.         /// This function will put an item in a player's backpack, and if full put it inside their bank.
    1584.         /// If the mobile is null, this will delete the item.
    1585.         /// </summary>
    1586.         /// <param name="m">The mobile receiving the item</param>
    1587.         /// <param name="item">The item being given</param>
    1588.         private static void GiveItemTo( Mobile m, Item item )
    1589.         {
    1590.             if ( m == null || item == null )
    1591.             {
    1592.                 if ( item != null )
    1593.                     item.Delete();
    1594.  
    1595.                 return;
    1596.             }
    1597.  
    1598.             if ( m.Backpack == null || !m.Backpack.TryDropItem( m, item, false ) )
    1599.             {
    1600.                 if ( m.BankBox != null )
    1601.                 {
    1602.                     m.BankBox.AddItem( item );
    1603.                 }
    1604.                 else
    1605.                 {
    1606.                     item.Delete(); // Sucks to be you
    1607.                 }
    1608.             }
    1609.         }
    1610.  
    1611.         /// <summary>
    1612.         /// Verifies if all the items being sold through this auction still exist
    1613.         /// </summary>
    1614.         /// <returns>True if all the items still exist</returns>
    1615.         public bool IsValid()
    1616.         {
    1617.             bool valid = true;
    1618.  
    1619.             foreach( ItemInfo info in m_Items )
    1620.             {
    1621.                 if ( info.Item == null )
    1622.                     valid = false;
    1623.             }
    1624.  
    1625.             return valid;
    1626.         }
    1627.  
    1628.         /// <summary>
    1629.         /// Defines what kind of message the auction owner should receive. Doesn't send any messages.
    1630.         /// </summary>
    1631.         public void DoOwnerMessage()
    1632.         {
    1633.             if ( m_Owner == null || m_Owner.Account == null )
    1634.             {
    1635.                 // If owner deleted the character, accept the auction by default
    1636.                 m_OwnerPendency = AuctionPendency.Accepted;
    1637.             }
    1638.             else if ( !IsValid() && ReserveMet )
    1639.             {
    1640.                 // Assume the owner will sell even if invalid when reserve is met
    1641.                 m_OwnerPendency = AuctionPendency.Accepted;
    1642.             }
    1643.             else if ( !ReserveMet )
    1644.             {
    1645.                 m_OwnerPendency = AuctionPendency.Pending;
    1646.                 m_OwnerMessage = AuctionMessage.Response; // This is always reserve not met for the owner
    1647.             }
    1648.             else if ( !IsValid() )
    1649.             {
    1650.                 m_OwnerPendency = AuctionPendency.Accepted;
    1651.                 m_OwnerMessage = AuctionMessage.Information; // This is always about validty for the owner
    1652.             }
    1653.         }
    1654.  
    1655.         /// <summary>
    1656.         /// Defines what kind of message the buyer should receive. Doesn't send any messages.
    1657.         /// </summary>
    1658.         public void DoBuyerMessage()
    1659.         {
    1660.             if ( HighestBid.Mobile == null || HighestBid.Mobile.Account == null )
    1661.             {
    1662.                 // Buyer deleted the character, accept the auction by default
    1663.                 m_BuyerPendency = AuctionPendency.Accepted;
    1664.             }
    1665.             else if ( ! IsValid() )
    1666.             {
    1667.                 // Send the buyer a message about missing items in the auction
    1668.                 m_BuyerMessage = AuctionMessage.Response;
    1669.                 m_BuyerPendency = AuctionPendency.Pending;
    1670.             }
    1671.             else if ( !ReserveMet )
    1672.             {
    1673.                 // Assume the buyer will buy even if the reserve hasn't been met
    1674.                 m_BuyerPendency = AuctionPendency.Accepted;
    1675.                 // Send the buyer a message to inform them of the reserve issue
    1676.                 m_BuyerMessage = AuctionMessage.Information;
    1677.             }
    1678.         }
    1679.  
    1680.         /// <summary>
    1681.         /// Validates the pending status of the auction. This method should be called whenever a pendency
    1682.         /// value is changed. If the auction has been validated, it will finalize items and remove the auction from the system.
    1683.         /// This is the only method that should be used to finalize a pending auction.
    1684.         /// </summary>
    1685.         public void Validate()
    1686.         {
    1687.             if ( ! AuctionSystem.Pending.Contains( this ) )
    1688.                 return;
    1689.  
    1690.             if ( m_OwnerPendency == AuctionPendency.Accepted && m_BuyerPendency == AuctionPendency.Accepted )
    1691.             {
    1692.                 // Both parts confirmed the auction
    1693.                 m_Pending = false;
    1694.                 AuctionSystem.Pending.Remove( this );
    1695.  
    1696.                 AuctionCheck item = new AuctionItemCheck( this, AuctionResult.PendingAccepted );
    1697.                 AuctionCheck gold = new AuctionGoldCheck( this, AuctionResult.PendingAccepted );
    1698.  
    1699.                 if ( item != null )
    1700.                 {
    1701.                     GiveItemTo( HighestBid.Mobile, item ); // Item to buyer
    1702.                 }
    1703.  
    1704.                 GiveItemTo( m_Owner, gold ); // Gold to owner
    1705.  
    1706.                 // Over, this auction no longer exists
    1707.                 AuctionLog.WriteEnd( this, AuctionResult.PendingAccepted, null, null );
    1708.             }
    1709.             else if ( m_OwnerPendency == AuctionPendency.NotAccepted || m_BuyerPendency == AuctionPendency.NotAccepted )
    1710.             {
    1711.                 // At least one part refused
    1712.                 m_Pending = false;
    1713.                 AuctionSystem.Pending.Remove( this );
    1714.  
    1715.                 AuctionCheck item = new AuctionItemCheck( this, AuctionResult.PendingRefused );
    1716.                 AuctionCheck gold = new AuctionGoldCheck( this, AuctionResult.PendingRefused );
    1717.  
    1718.                 if ( item != null )
    1719.                 {
    1720.                     GiveItemTo( m_Owner, item ); // Give item back to owner
    1721.                 }
    1722.  
    1723.                 GiveItemTo( HighestBid.Mobile, gold ); // Give gold to highest bidder
    1724.  
    1725.                 // Over, this auction no longer exists
    1726.                 AuctionLog.WriteEnd( this, AuctionResult.PendingRefused, null, null );
    1727.             }
    1728.         }
    1729.  
    1730.         /// <summary>
    1731.         /// Sends any message this auction might have in store for a given mobile
    1732.         /// </summary>
    1733.         /// <param name="to">The Mobile logging into the server</param>
    1734.         public void SendMessage( Mobile to )
    1735.         {
    1736.             if ( ! m_Pending || to == null )
    1737.                 return;
    1738.  
    1739.             if ( to == m_Owner || ( m_Owner != null && to.Account.Equals( m_Owner.Account ) ) )
    1740.             {
    1741.                 // This is the owner loggin in
    1742.                 if ( this.m_OwnerMessage != AuctionMessage.None )
    1743.                 {
    1744.                     // Owner needs a message
    1745.                     if ( m_OwnerMessage == AuctionMessage.Information )
    1746.                     {
    1747.                         // Send information message about validity condition
    1748.                         AuctionMessaging.SendInvalidMessageToOwner( this );
    1749.                     }
    1750.                     else if ( m_OwnerMessage == AuctionMessage.Response )
    1751.                     {
    1752.                         // Send reserve not met confirmation request
    1753.                         AuctionMessaging.SendReserveMessageToOwner( this );
    1754.                     }
    1755.                 }
    1756.             }
    1757.             else if ( to == HighestBid.Mobile || ( HighestBid.Mobile != null && to.Account.Equals( HighestBid.Mobile.Account ) ) )
    1758.             {
    1759.                 // This is the buyer logging in
    1760.                 if ( m_BuyerMessage != AuctionMessage.None )
    1761.                 {
    1762.                     // Buyer should receive a message
    1763.                     if ( m_BuyerMessage == AuctionMessage.Information )
    1764.                     {
    1765.                         // Send message about reserve not met condition
    1766.                         AuctionMessaging.SendReserveMessageToBuyer( this );
    1767.                     }
    1768.                     else if ( m_BuyerMessage == AuctionMessage.Response )
    1769.                     {
    1770.                         // Send request to confirm invalid items auction
    1771.                         AuctionMessaging.SendInvalidMessageToBuyer( this );
    1772.                     }
    1773.                 }
    1774.             }
    1775.         }
    1776.  
    1777.         /// <summary>
    1778.         /// Confirms an information message
    1779.         /// </summary>
    1780.         /// <param name="owner">True if the message was sent to the owner, false if to the buyer</param>
    1781.         public void ConfirmInformationMessage( bool owner )
    1782.         {
    1783.             if ( owner )
    1784.             {
    1785.                 // Owner
    1786.                 m_OwnerMessage = AuctionMessage.None; // Don't resent
    1787.             }
    1788.             else
    1789.             {
    1790.                 // Buyer
    1791.                 m_BuyerMessage = AuctionMessage.None;
    1792.             }
    1793.         }
    1794.  
    1795.         /// <summary>
    1796.         /// Gives a response to a message
    1797.         /// </summary>
    1798.         /// <param name="owner">True if the message was sent to the owner, false if to the buyer</param>
    1799.         /// <param name="ok">The response to the message</param>
    1800.         public void ConfirmResponseMessage( bool owner, bool ok )
    1801.         {
    1802.             if ( owner )
    1803.             {
    1804.                 if ( ok )
    1805.                 {
    1806.                     m_OwnerPendency = AuctionPendency.Accepted;
    1807.                 }
    1808.                 else
    1809.                 {
    1810.                     m_OwnerPendency = AuctionPendency.NotAccepted;
    1811.                 }
    1812.             }
    1813.             else
    1814.             {
    1815.                 if ( ok )
    1816.                 {
    1817.                     m_BuyerPendency = AuctionPendency.Accepted;
    1818.                 }
    1819.                 else
    1820.                 {
    1821.                     m_BuyerPendency = AuctionPendency.NotAccepted;
    1822.                 }
    1823.             }
    1824.  
    1825.             Validate();
    1826.         }
    1827.  
    1828.         /// <summary>
    1829.         /// The pending period has timed out and the auction must end unsuccesfully
    1830.         /// </summary>
    1831.         public void PendingTimeOut()
    1832.         {
    1833.             AuctionSystem.Pending.Remove( this );
    1834.  
    1835.             m_OwnerPendency = AuctionPendency.NotAccepted;
    1836.             m_BuyerPendency = AuctionPendency.NotAccepted;
    1837.             m_OwnerMessage = AuctionMessage.None;
    1838.             m_BuyerMessage = AuctionMessage.None;
    1839.  
    1840.             AuctionCheck item = new AuctionItemCheck( this, AuctionResult.PendingTimedOut );
    1841.             AuctionCheck gold = new AuctionGoldCheck( this, AuctionResult.PendingTimedOut );
    1842.  
    1843.             if ( item != null )
    1844.                 GiveItemTo( m_Owner, item );
    1845.             GiveItemTo( HighestBid.Mobile, gold );
    1846.  
    1847.             // Over, this auction no longer exists
    1848.             AuctionLog.WriteEnd( this, AuctionResult.PendingTimedOut, null, null );
    1849.         }
    1850.  
    1851.         /// <summary>
    1852.         /// Verifies is a mobile has bid on this auction
    1853.         /// </summary>
    1854.         public bool MobileHasBids( Mobile m )
    1855.         {
    1856.             ArrayList bids = new ArrayList( m_Bids );
    1857.  
    1858.             foreach( Bid bid in bids )
    1859.             {
    1860.                 if ( bid.Mobile == m )
    1861.                     return true;
    1862.             }
    1863.  
    1864.             return false;
    1865.         }
    1866.  
    1867.         /// <summary>
    1868.         /// Outputs relevant information about this auction
    1869.         /// </summary>
    1870.         public void Profile( StreamWriter writer )
    1871.         {
    1872.             writer.WriteLine( "ID : {0}", m_ID );
    1873.             writer.WriteLine( "Name : {0}", m_ItemName );
    1874.  
    1875.             if ( m_Owner != null && m_Owner.Account != null )
    1876.                 writer.WriteLine( "Owner : {0} [ Account {1} - Serial {2} ]",
    1877.                     m_Owner.Name,
    1878.                     ( m_Owner.Account as Account ).Username,
    1879.                     m_Owner.Serial );
    1880.             else
    1881.                 writer.WriteLine( "Owner : no longer existing" );
    1882.  
    1883.             writer.WriteLine( "Starting bid: {0}", m_MinBid );
    1884.             writer.WriteLine( "Reserve : {0}", m_Reserve );
    1885.  
    1886.             writer.WriteLine( "Created on {0} at {1}", m_StartTime.ToShortDateString(), m_StartTime.ToShortTimeString() );
    1887.             writer.WriteLine( "Duration: {0}", m_Duration.ToString() );
    1888.             writer.WriteLine( "End Time: {0} at {1}", m_EndTime.ToShortDateString(), m_EndTime.ToShortTimeString() );
    1889.  
    1890.             writer.WriteLine( "Expired : {0}", Expired.ToString() );
    1891.             writer.WriteLine( "Pending : {0}", Pending.ToString() );
    1892.             writer.WriteLine( "Next Deadline : {0} at {1}", Deadline.ToShortDateString(), Deadline.ToShortTimeString() );
    1893.  
    1894.             writer.WriteLine();
    1895.  
    1896.             if ( Creature )
    1897.             {
    1898.                 writer.WriteLine( "** This auction is selling a pet" );
    1899.  
    1900.                 // Pet
    1901.                 if ( m_Item != null && Pet != null )
    1902.                 {
    1903.                     writer.WriteLine( "Creature: {0}", Pet.Serial );
    1904.                     writer.WriteLine( "Statuette : {0}", m_Item.Serial );
    1905.                     writer.WriteLine( "Type : {0}", m_Item.Name );
    1906.                 }
    1907.                 else
    1908.                 {
    1909.                     writer.WriteLine( "Pet deleted, this auction is invalid" );
    1910.                 }
    1911.             }
    1912.             else
    1913.             {
    1914.                 // Items
    1915.                 writer.WriteLine( "{0} Items", m_Items.Length );
    1916.  
    1917.                 foreach( ItemInfo item in m_Items )
    1918.                 {
    1919.                     writer.Write( "- {0}", item.Name );
    1920.  
    1921.                     if ( item.Item != null )
    1922.                         writer.WriteLine( " [{0}]", item.Item.Serial );
    1923.                     else
    1924.                         writer.WriteLine( " [Deleted]" );
    1925.                 }
    1926.             }
    1927.  
    1928.             writer.WriteLine();
    1929.             writer.WriteLine( "{0} Bids", m_Bids.Count );
    1930.  
    1931.             foreach ( Bid bid in m_Bids )
    1932.             {
    1933.                 bid.Profile( writer );
    1934.             }
    1935.  
    1936.             writer.WriteLine();
    1937.         }
    1938.  
    1939.         /// <summary>
    1940.         /// Attempts to buy now
    1941.         /// </summary>
    1942.         /// <param name="m">The user trying to purchase</param>
    1943.         /// <returns>True if the item has been sold</returns>
    1944.         public bool DoBuyNow( Mobile m )
    1945.         {
    1946.             if ( !Banker.Withdraw( m, m_BuyNow ) )
    1947.             {
    1948.                 m.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 211 ] );
    1949.                 return false;
    1950.             }
    1951.  
    1952.             AuctionSystem.Auctions.Remove( this );
    1953.  
    1954.             if ( HighestBid != null )
    1955.             {
    1956.                 HighestBid.Outbid( this );
    1957.             }
    1958.  
    1959.             // Simulate bid
    1960.             Bid bid = new Bid( m, BuyNow );
    1961.             m_Bids.Insert( 0, bid );
    1962.  
    1963.             AuctionGoldCheck gold = new AuctionGoldCheck( this, AuctionResult.BuyNow );
    1964.             AuctionItemCheck item = new AuctionItemCheck( this, AuctionResult.BuyNow );
    1965.  
    1966.             GiveItemTo( m, item );
    1967.             GiveItemTo( m_Owner, gold );
    1968.  
    1969.             // Over.
    1970.             AuctionLog.WriteEnd( this, AuctionResult.BuyNow, m, null );
    1971.  
    1972.             return true;
    1973.         }
    1974.  
    1975.         /// <summary>
    1976.         /// Verifies if the eventual pets in this auction are gone
    1977.         /// </summary>
    1978.         public void VeirfyIntergrity()
    1979.         {
    1980.             foreach( ItemInfo ii in this.m_Items )
    1981.                 ii.VeirfyIntegrity();
    1982.         }
    1983.     }
    1984. }
     
  2. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    That error is because the 'StringList' it's looking for is from the old Ultima.dll that was replaced by OpenUO in favor for the newer client file support.

    I'm sure OpenUO has some kind of support for reading the Clilocs built into it but I haven't looked into OpenUO at all. Will have to dig around in it and get back to you on that one. There are a couple alternatives still if not.
     
    • Informative Informative x 1
  3. IanE
    Offline

    IanE Member

    Joined:
    Dec 27, 2013
    Messages:
    220
    Likes Received:
    16
    Ok Thank You.

    What is OpenUO?
     
  4. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    Those dll files you asked about earlier :). OpenUO is used to read the client files to extract info from them.
     
  5. IanE
    Offline

    IanE Member

    Joined:
    Dec 27, 2013
    Messages:
    220
    Likes Received:
    16
    Oh ok, haha....I certainly don't know anything about dll files :(
     
  6. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    Yeah I'm not having any luck reading the clilocs with OpenUO. Maybe @Insanity or @Vorspire can shed some light on how to? I tried messing with the ClilocFactory in OpenUOSDK as well as some of the Adapters straight from the dll file but I seem to not be using them right. OpenUO needs documentation :)
     
  7. Vorspire
    Offline

    Vorspire Vita-Nex: Core
    Admin ServUO Developer

    Joined:
    Jul 29, 2013
    Messages:
    901
    Likes Received:
    165
    Well, since I wrote the clilocs adapter for OpenUO, I think I can shed some light on it.


    You create a new instance of the cliloc factory.
    Then create a new instance of the Container (IContainer) provided by OpenUO.
    Then create a new instance of the cliloc adapter and register the factory type with the container.
    Then you can use the factory to retrieve cliloc info.

    I'll write in more detail at some point, it's late right now :)

    OpenUO is quite hard to get started with, gives me a slight headache remembering the correct logic to instantiate a new factory/adapter, lol.
     
    • Like Like x 2
  8. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    Yeah I directed the question towards you because I seen you made the commit for the clillocs ;)

    I'll play around with your instructions above. At least I have a starting point now. Just looking at it made no sense to me on what all was needed for it. I get that 'slight headache' too lol.
     
  9. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    @Vorspire a proper example would be really nice when you get the time. I tried following what you said above but all I can do is bang my head on my keyboard.

    That aside, I was able to load cliloc info using OpenUO doing this:
    Code (C#):
    1. ClientLocalizations clientLocalizations = new ClientLocalizations();
    2. clientLocalizations.Load(new FileInfo(OpenUOSDK.ClientDataPath + @"\Cliloc.enu"));
    3. string clilocInfo = clientLocalizations.Lookup(myItem.LabelNumber).Text;
    Now correct me if I'm wrong but couldn't I just create a static copy of ClientLocaliztions somewhere and reuse it for getting the clilocs like this? Seems like a much shorter route than creating all the above methods.
     
  10. IanE
    Offline

    IanE Member

    Joined:
    Dec 27, 2013
    Messages:
    220
    Likes Received:
    16
    Is there any information anywhere about what clilocs are and what they do and how to use them? I am lost at the moment on all of this stuff.

    Thanks for all of the help @Kalamus and @Vorspire !!
     
  11. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    Clilocs are client files that store a bunch of text based on a number value. The client and server communicate using the number so less info is transfered and then use that number to look up the text.

    Xanthos Auction System you are trying to use is using this info to get item names based off their cliloc number.
     
    • Like Like x 1
    • Informative Informative x 1
  12. IanE
    Offline

    IanE Member

    Joined:
    Dec 27, 2013
    Messages:
    220
    Likes Received:
    16
    Oh WOW that is intense! I guess learning it is just something that I will have to do soon, would downloading the OpenUO help me learn it any?
     
  13. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    Well it's not something that is used a lot for normal scripting needs. I'm sure Xanthos Auciton system could be redone in a different way that doesn't involve reading the clilocs and letting the client handle it instead. I don't know anything about the auction system though and don't plan to rewrite it. Just trying to come up with a simple fix to resolve the way it's setup now ;)

    If you are interested in looking into OpenUO the source can be found here https://github.com/fdsprod/OpenUO
     
  14. IanE
    Offline

    IanE Member

    Joined:
    Dec 27, 2013
    Messages:
    220
    Likes Received:
    16
    Ahh I see, well I do eventually plan on being able to learn how to use the clilocs and what not, but for now I am just trying to learn C# to at least be able to fix/merge non-working scripts to ServUO for my shard.

    I was downloading it as you posted it, I am looking through it now and I am just lost haha!

    Thanks!
    IanE
     
  15. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    Haha don't feel bad. I'm totally lost with it too. Just seems to go over my head with what's trying to go on there. So far my only luck is what I posted above, bypassing all the crazy stuff I don't understand and going straight for the class that handles the work I need.
     
  16. IanE
    Offline

    IanE Member

    Joined:
    Dec 27, 2013
    Messages:
    220
    Likes Received:
    16
    HAHA yeah, it's not in super need of attention, I already have it Running on my RunUO core. I just came over to ServUO recently, and it seems to be better, just more things to learn. I will eventually have my whole server ServUO!
     
  17. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    @IanE try this file I attached. I updated the code you posted at the top of the thread with my fix above. Should fix the auction system for you. Just let me know how it works out after you do some testing as I don't use that system.
     

    Attached Files:

    • Two Thumbs Up Two Thumbs Up x 1
  18. IanE
    Offline

    IanE Member

    Joined:
    Dec 27, 2013
    Messages:
    220
    Likes Received:
    16
    That may have worked, I get this when I put that in and debug in Visual Studio
    Code (C#):
    1.         public void GrabItems( bool ignoreNoteriety )
    2.         {
    3.             ArrayList items = new ArrayList();
    4.             bool rejected = false;
    5.             bool lootAdded = false;
    6.  
    7.             Emote( "*Rummages through items on the ground.*" );
    8.  
    9.             foreach ( Item item in GetItemsInRange( 2 ) )
    10.             {
    11.                 if ( item.Movable )
    12.                     items.Add( item );
    13.                 else if ( item is Corpse )
    14.                 {    // Either criminally loot any corpses or loot only corpses that we have rights to
    15.                     if ( ignoreNoteriety || NotorietyHandlers.CorpseNotoriety( this, (Corpse)item ) != Notoriety.Innocent )
    16.                     {
    17.                         Emote( "*Rummages through items in a corpse.*" );
    18.                         foreach ( Item corpseItem in ((Corpse)item).Items )
    19.                             items.Add( corpseItem );
    20.                     }
    21.                 }
    22.             }
    23.             foreach ( Item item in items )
    24.             {
    25.                 if ( !Backpack.CheckHold( this, item, false, true ) )
    26.                     rejected = true;
    27.                 else
    28.                 {
    29.                     bool isRejected;
    30.                     LRReason reason;
    31.  
    32.                     NextActionTime = DateTime.Now;
    33.                     Lift( item, item.Amount, out isRejected, out reason );
    34.  
    35.                     if ( !isRejected )
    36.                     {
    37.                         Drop( this, Point3D.Zero );
    38.                         lootAdded = true;
    39.                     }
    40.                     else
    41.                     {
    42.                         rejected = true;
    43.                     }
    44.                 }
    45.             }
    46.             if ( lootAdded )
    47.                 PlaySound( 0x2E6 ); //drop gold sound
    48.             if ( rejected )
    49.                 Say( "I could not pick up all of the items." );
    50.         }
    Thanks a ton!
     
  19. Ravenwolfe
    Offline

    Moderator ServUO Developer

    Joined:
    Sep 7, 2013
    Messages:
    1,152
    Likes Received:
    124
    Change:

    NextActionTime = DateTime.Now;

    To:

    NextActionTime = Core.TickCount;
     
    • Winner Winner x 1
  20. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    I'm confused. The auction system works? The Mercenary error is from my update or is that just another problem you are having with another script?
     
Similar Threads: Xantho's Auction
Forum Title Date
Custom Releases Xanthos Auction System [ fixed for newer ServUo Repos ] Oct 13, 2017
Custom Releases Auction board Jun 27, 2017
Script Support Arya auction system crash May 1, 2017
Custom Releases Auction System for small Player base Server Mar 25, 2017
Script Support Arya's Auction System Jan 12, 2017
Archived Bug Reports Auction Safe Deed bugs Jan 3, 2017