//this method provides a direct access object property list for a specified object public static DirectObjectPropertyList GetDirectPropertyList(object obj) { //fetch the object property list for this object ObjectPropertyList opl = null; if (obj is Item) { Item item = (Item)obj; opl = new ObjectPropertyList(item); item.GetProperties(opl); } else if (obj is Mobile) { Mobile mobile = (Mobile)obj; opl = new ObjectPropertyList(mobile); mobile.GetProperties(opl); } if (opl == null) { //if there was a problem with this process, just return null return(null); } return(new DirectObjectPropertyList(opl)); }
public static string ResolveName(this Item item, ClilocLNG lng = ClilocLNG.ENU, bool setIfNull = false) { if (item == null) { return(String.Empty); } var opl = item.PropertyList; if (opl == null) { opl = new ObjectPropertyList(item); item.GetProperties(opl); } var label = opl.GetHeader(); if (!String.IsNullOrEmpty(label)) { label = label.Replace("\t", " ").Replace("\u0009", " ").Replace("<br>", "\n").Replace("<BR>", "\n"); } if (!String.IsNullOrEmpty(label)) { var idx = label.IndexOf('\n'); if (idx >= 0) { label = label.Substring(0, label.Length - idx); } label = label.StripHtml(false); label = label.Trim(); idx = 0; while (idx < label.Length) { if (Char.IsNumber(label, idx)) { ++idx; } else if (Char.IsPunctuation(label, idx) && idx + 1 < label.Length && Char.IsNumber(label, idx + 1)) { ++idx; } else { break; } } if (idx > 0) { label = label.Substring(idx); label = label.Trim(); } } if (String.IsNullOrWhiteSpace(label) && item.Name != null) { label = item.Name; } if (String.IsNullOrWhiteSpace(label) && item.DefaultName != null) { label = item.DefaultName; } if (String.IsNullOrWhiteSpace(label) && item.LabelNumber > 0) { label = lng.GetString(item.LabelNumber); } if (String.IsNullOrWhiteSpace(label) && TileData.ItemTable.InBounds(item.ItemID)) { label = TileData.ItemTable[item.ItemID].Name; } if (String.IsNullOrWhiteSpace(label)) { label = item.GetType().Name.SpaceWords(); } if (!String.IsNullOrEmpty(label)) { label = label.StripExcessWhiteSpace().Trim(); } return(setIfNull ? (item.Name = label) : label); }
/// <summary> /// Gets an html formatted string with all the properies for the item /// </summary> /// <returns>A string object containing the html structure corresponding to the item properties</returns> private static string GetItemProperties( Item item ) { if ( item == null || item.PropertyList == null ) { return AuctionSystem.ST[ 78 ]; } if ( Core.AOS ) { #region AoS ObjectPropertyList plist = new ObjectPropertyList( item ); item.GetProperties( plist ); byte[] data = plist.UnderlyingStream.UnderlyingStream.ToArray(); ArrayList list = new ArrayList(); int index = 15; // First localization number index while ( true ) { uint number = 0; if ( index + 4 >= data.Length ) { break; } number = (uint) ( data[ index++ ] << 24 | data[ index++ ] << 16 | data[ index++ ] << 8 | data[ index++ ] ); ushort length = 0; if ( index + 2 > data.Length ) { break; } length = (ushort) ( data[ index++ ] << 8 | data[ index++ ] ); // Read the string int end = index + length; if ( end >= data.Length ) { end = data.Length - 1; } System.Text.StringBuilder s = new System.Text.StringBuilder(); while ( index + 2 <= end + 1 ) { short next = (short) ( data[ index++ ] | data[ index++ ] << 8 ); if ( next == 0 ) break; s.Append( System.Text.Encoding.Unicode.GetString( BitConverter.GetBytes( next ) ) ); } list.Add( ComputeProperty( (int) number, s.ToString() ) ); } System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append( "<basefont color=#FFFFFF><p>" ); foreach( string prop in list ) { sb.AppendFormat( "{0}<br>", prop ); } return sb.ToString(); #endregion } else { #region Non AoS StringBuilder sb = new StringBuilder(); sb.Append( "<basefont color=#FFFFFF><p>" ); // Get the item name if ( item.Name != null && item.Name.Length > 0 ) { sb.AppendFormat( "{0}<br>", item.Name ); } else { sb.AppendFormat( "{0}<br>", Capitalize( m_StringList.Table[ item.LabelNumber ] as string ) ); } // Amount if ( item.Amount > 1 ) { sb.AppendFormat( AuctionSystem.ST[ 152 ] , item.Amount.ToString("#,0" ) ); } // Loot type if ( item.LootType != LootType.Regular ) { sb.AppendFormat( "{0}<br>", item.LootType.ToString() ); } if ( item is IUsesRemaining ) { sb.AppendFormat( AuctionSystem.ST[ 153 ] , ( item as IUsesRemaining ).UsesRemaining ); } // Manage item types if ( item is BaseWand ) { #region Wands BaseWand bw = item as BaseWand; sb.AppendFormat( AuctionSystem.ST[ 154 ] , bw.Effect.ToString() ); sb.AppendFormat( AuctionSystem.ST[ 155 ] , bw.Charges ); #endregion } else if ( item is BaseArmor ) { #region Armor BaseArmor ba = item as BaseArmor; if ( ba.PlayerConstructed ) { if ( ba.Crafter != null ) { sb.AppendFormat( AuctionSystem.ST[ 156 ] , ba.Crafter.Name ); } sb.AppendFormat( AuctionSystem.ST[ 157 ] , ba.Resource.ToString() ); } sb.AppendFormat( AuctionSystem.ST[ 158 ] , ba.Quality.ToString() ); sb.AppendFormat( AuctionSystem.ST[ 159 ] , ba.HitPoints, ba.MaxHitPoints ); if ( ba.Durability != ArmorDurabilityLevel.Regular ) { sb.AppendFormat( AuctionSystem.ST[ 160 ] , ba.Durability.ToString() ); } if ( ba.ProtectionLevel != ArmorProtectionLevel.Regular ) { sb.AppendFormat( AuctionSystem.ST[ 161 ] , ba.ProtectionLevel.ToString() ); } #endregion } else if ( item is BaseWeapon ) { #region Weapons BaseWeapon bw = item as BaseWeapon; if ( bw.PlayerConstructed ) { if ( bw.Crafter != null ) { sb.AppendFormat( AuctionSystem.ST[ 156 ] , bw.Crafter.Name ); } sb.AppendFormat( AuctionSystem.ST[ 157 ] , bw.Resource.ToString() ); } sb.AppendFormat( AuctionSystem.ST[ 158 ] , bw.Quality.ToString() ); sb.AppendFormat( AuctionSystem.ST[ 159 ], bw.HitPoints, bw.MaxHitPoints ); if ( bw.PoisonCharges > 0 ) { sb.AppendFormat( AuctionSystem.ST[ 162 ] , bw.PoisonCharges, bw.Poison.ToString() ); } if ( item is BaseRanged ) { sb.AppendFormat( AuctionSystem.ST[ 163 ] , bw.MaxRange.ToString() ); } if ( bw.DamageLevel != WeaponDamageLevel.Regular ) { sb.AppendFormat( AuctionSystem.ST[ 164 ] , bw.DamageLevel.ToString() ); } if ( bw.DurabilityLevel != WeaponDurabilityLevel.Regular ) { sb.AppendFormat( AuctionSystem.ST[ 160 ] , bw.DurabilityLevel.ToString() ); } if ( bw.AccuracyLevel != WeaponAccuracyLevel.Regular ) { if ( bw.AccuracyLevel == WeaponAccuracyLevel.Accurate ) { sb.AppendFormat( AuctionSystem.ST[ 165 ] ); } else { sb.AppendFormat( AuctionSystem.ST[ 166 ] , bw.AccuracyLevel.ToString() ); } } if ( bw.Slayer != SlayerName.None ) { sb.AppendFormat( AuctionSystem.ST[ 167 ] , bw.Slayer.ToString() ); } #endregion } else if ( item is TreasureMap ) { #region Treasure Map TreasureMap tm = item as TreasureMap; sb.AppendFormat( AuctionSystem.ST[ 168 ] , tm.ChestMap ); #endregion } else if ( item is Spellbook ) { #region Spellbook Spellbook sp = item as Spellbook; sb.AppendFormat( AuctionSystem.ST[ 169 ] , sp.SpellCount ); #endregion } else if ( item is PotionKeg ) { #region Potion Keg PotionKeg pk = item as PotionKeg; int number; if ( pk.Held <= 0 ) number = 502246; // The keg is empty. else if ( pk.Held < 5 ) number = 502248; // The keg is nearly empty. else if ( pk.Held < 20 ) number = 502249; // The keg is not very full. else if ( pk.Held < 30 ) number = 502250; // The keg is about one quarter full. else if ( pk.Held < 40 ) number = 502251; // The keg is about one third full. else if ( pk.Held < 47 ) number = 502252; // The keg is almost half full. else if ( pk.Held < 54 ) number = 502254; // The keg is approximately half full. else if ( pk.Held < 70 ) number = 502253; // The keg is more than half full. else if ( pk.Held < 80 ) number = 502255; // The keg is about three quarters full. else if ( pk.Held < 96 ) number = 502256; // The keg is very full. else if ( pk.Held < 100 ) number = 502257; // The liquid is almost to the top of the keg. else number = 502258; // The keg is completely full. sb.AppendFormat( Capitalize( m_StringList.Table[ number ] as string ) ); #endregion } return sb.ToString(); #endregion } }
private void AddItemPropertyTooltip( Item item ) { item.GetProperties( new ObjectPropertyListTooltip( this ) ); }
public static string GetItemName(Item item) { if (StringList == null || item.Name != null) return item.Name; ObjectPropertyList opl = new ObjectPropertyList(item); item.GetProperties(opl); if (opl == null) { //if there was a problem with this process, just return null return null; } //since the object property list is based on a packet object, the property info is packed away in a packet format byte[] data = opl.UnderlyingStream.UnderlyingStream.ToArray(); int index = 15; // First localization number index string basestring = null; //reset the number property uint number = 0; //if there's not enough room for another record, quit if (index + 4 >= data.Length) { return null; } //read number property from the packet data number = (uint)(data[index++] << 24 | data[index++] << 16 | data[index++] << 8 | data[index++]); //reset the length property ushort length = 0; //if there's not enough room for another record, quit if (index + 2 > data.Length) { return null; } //read length property from the packet data length = (ushort)(data[index++] << 8 | data[index++]); //determine the location of the end of the string int end = index + length; //truncate if necessary if (end >= data.Length) { end = data.Length - 1; } //read the string into a StringBuilder object StringBuilder s = new StringBuilder(); while (index + 2 <= end + 1) { short next = (short)(data[index++] | data[index++] << 8); if (next == 0) break; s.Append(Encoding.Unicode.GetString(BitConverter.GetBytes(next))); } basestring = StringList.GetString((int)number); string args = s.ToString(); if (args == null || args == String.Empty) { return basestring; } string[] parms = args.Split('\t'); try { if (parms.Length > 1) { for (int i = 0; i < parms.Length; i++) { parms[i] = parms[i].Trim(' '); if (parms[i].IndexOf("#") == 0) { parms[i] = StringList.GetString(Convert.ToInt32(parms[i].Substring(1, parms[i].Length - 1))); } } } else if (parms.Length == 1 && parms[0].IndexOf("#") == 0) { parms[0] = StringList.GetString(Convert.ToInt32(args.Substring(1, parms[0].Length - 1))); } } catch { return null; } Ultima.StringEntry entry = StringList.GetEntry((int)number); if (entry != null) { return entry.Format(parms); } return basestring; }