// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // namespace MUnique.OpenMU.DataModel.Entities; using System.Globalization; using MUnique.OpenMU.Annotations; using MUnique.OpenMU.DataModel.Configuration.Items; using MUnique.OpenMU.DataModel.Properties; /// /// The item. /// [Cloneable] public partial class Item { /// /// Gets or sets the item slot in the . /// public byte ItemSlot { get; set; } /// /// Gets or sets the item definition. /// [Required] public virtual ItemDefinition? Definition { get; set; } /// /// Gets or sets the currently remaining durability. /// public double Durability { get; set; } /// /// Gets or sets the level of the item. /// public byte Level { get; set; } /// /// Gets or sets a value indicating whether this item instance provides the weapon skill while being equipped. /// public bool HasSkill { get; set; } /// /// Gets or sets the item options. /// [MemberOfAggregate] public virtual ICollection ItemOptions { get; protected set; } = null!; /// /// Gets or sets the applied item set groups (Ancient Set). /// public virtual ICollection ItemSetGroups { get; protected set; } = null!; /// /// Gets or sets the socket count. This limits the amount of socket options in the . /// public int SocketCount { get; set; } /// /// Gets or sets the price which was set by the player for his personal store. /// public int? StorePrice { get; set; } /// /// Gets or sets the pet experience. /// Only applies, if this item is actually a trainable pet. /// public int PetExperience { get; set; } /// /// Assigns the values of another item to this item. /// /// The other item. public void AssignValues(Item otherItem) { this.Definition = otherItem.Definition; this.Durability = otherItem.Durability; this.Level = otherItem.Level; this.HasSkill = otherItem.HasSkill; this.SocketCount = otherItem.SocketCount; this.PetExperience = otherItem.PetExperience; if (otherItem.ItemOptions != null && otherItem.ItemOptions.Any()) { this.ItemOptions.Clear(); foreach (var option in otherItem.ItemOptions) { this.ItemOptions.Add(this.CloneItemOptionLink(option)); } } if (otherItem.ItemSetGroups != null && otherItem.ItemSetGroups.Any()) { this.ItemSetGroups.Clear(); foreach (var setGroup in otherItem.ItemSetGroups) { this.ItemSetGroups.Add(setGroup); } } } /// public override string ToString() { var stringBuilder = new StringBuilder(); stringBuilder.Append("Slot ").Append(this.ItemSlot).Append(": "); if (this.ItemOptions.Any(o => o.ItemOption?.OptionType == ItemOptionTypes.Excellent)) { stringBuilder.Append("Excellent "); } var ancientSet = this.ItemSetGroups.FirstOrDefault(s => s.AncientSetDiscriminator != 0)?.ItemSetGroup; if (ancientSet != null) { stringBuilder.Append(ancientSet.Name).Append(" "); } var itemName = this.Definition?.GetNameForLevel(this.Level); stringBuilder.Append(itemName); if (this.Level > 0) { stringBuilder.Append("+").Append(this.Level); } foreach (var option in this.ItemOptions .Where(o => o.ItemOption?.OptionType != ItemOptionTypes.Luck) .OrderBy(o => o.ItemOption?.OptionType == ItemOptionTypes.Option)) { var levelOption = option.ItemOption?.LevelDependentOptions.FirstOrDefault(o => o.Level == (option.ItemOption.LevelType == LevelType.ItemLevel ? this.Level : option.Level)); var powerUpDefinition = levelOption?.PowerUpDefinition ?? option.ItemOption?.PowerUpDefinition; if (powerUpDefinition is not null) { stringBuilder.Append("+").Append(powerUpDefinition); } } if (this.HasSkill) { stringBuilder.Append("+Skill"); } if (this.ItemOptions.Any(opt => opt.ItemOption?.OptionType == ItemOptionTypes.Luck)) { stringBuilder.Append("+Luck"); } if (this.SocketCount > 0) { stringBuilder.Append("+").Append(this.SocketCount).Append("S"); } return stringBuilder.ToString(); } /// /// Returns a string that represents this item, using the specified culture for localization. /// /// The culture to use for localization. /// The localized string. public string ToString(CultureInfo culture) { using var cultureHelper = CultureHelper.SetTemporaryCulture(culture); var stringBuilder = new StringBuilder(); stringBuilder.Append(Resources.Slot).Append(" ").Append(this.ItemSlot).Append(": "); if (this.ItemOptions.Any(o => o.ItemOption?.OptionType == ItemOptionTypes.Excellent)) { stringBuilder.Append(Resources.Excellent).Append(" "); } var ancientSet = this.ItemSetGroups.FirstOrDefault(s => s.AncientSetDiscriminator != 0)?.ItemSetGroup; if (ancientSet != null) { stringBuilder.Append(ancientSet.Name.ToString()).Append(" "); } var itemName = this.Definition?.GetNameForLevel(this.Level); stringBuilder.Append(itemName); if (this.Level > 0) { stringBuilder.Append("+").Append(this.Level); } foreach (var option in this.ItemOptions .Where(o => o.ItemOption?.OptionType != ItemOptionTypes.Luck) .OrderBy(o => o.ItemOption?.OptionType == ItemOptionTypes.Option)) { var levelOption = option.ItemOption?.LevelDependentOptions.FirstOrDefault(o => o.Level == (option.ItemOption.LevelType == LevelType.ItemLevel ? this.Level : option.Level)); var powerUpDefinition = levelOption?.PowerUpDefinition ?? option.ItemOption?.PowerUpDefinition; if (powerUpDefinition is not null) { stringBuilder.Append("+").Append(powerUpDefinition); } } if (this.HasSkill) { stringBuilder.Append("+").Append(Resources.Skill); } if (this.ItemOptions.Any(opt => opt.ItemOption?.OptionType == ItemOptionTypes.Luck)) { stringBuilder.Append("+").Append(Resources.Luck); } if (this.SocketCount > 0) { stringBuilder.Append("+").Append(this.SocketCount).Append(Resources.SocketAbbreviation); } return stringBuilder.ToString(); } /// /// Clones the item option link. /// /// The link. /// The cloned item option link. protected virtual ItemOptionLink CloneItemOptionLink(ItemOptionLink link) { return link.Clone(); } }