|
| 1 | +using Obsidian.API.Inventory; |
| 2 | + |
| 3 | +namespace Obsidian.API; |
| 4 | + |
| 5 | +/// <summary> |
| 6 | +/// Represents a trade entry offered by a villager or wandering trader. |
| 7 | +/// </summary> |
| 8 | +public sealed record TradeEntry : INetworkSerializable<TradeEntry> |
| 9 | +{ |
| 10 | + /// <summary> |
| 11 | + /// The first input item of the trade. The required count of the first input is the "base price" of the trade. |
| 12 | + /// The final price = base + floor(base * <see cref="Multiplier"/> * <see cref="Demand"/>) + <see cref="Discount"/>. |
| 13 | + /// </summary> |
| 14 | + public TradeItem FirstInput { get; set; } |
| 15 | + |
| 16 | + /// <summary> |
| 17 | + /// The output item of the trade. |
| 18 | + /// </summary> |
| 19 | + public ItemStack Output { get; set; } |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// The second input item of the trade. The required count of the second input is not affected by discount |
| 23 | + /// or demand. |
| 24 | + /// </summary> |
| 25 | + public TradeItem SecondInput { get; set; } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Whether the trade is disabled. |
| 29 | + /// </summary> |
| 30 | + public bool IsDisabled { get; set; } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Number of times the trade has been used. |
| 34 | + /// </summary> |
| 35 | + public int UsedCount { get; set; } |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// The maximum number of times the trade can be used before it becomes disabled. |
| 39 | + /// </summary> |
| 40 | + public int MaxCount { get; set; } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Number of XPs the villager will earn after each trade. |
| 44 | + /// </summary> |
| 45 | + public int XP { get; set; } |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// Used in calculating the final price. Can be zero or negative. |
| 49 | + /// </summary> |
| 50 | + public int Discount { get; set; } |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Used in calculating the final price. Can be low (0.05) or high (0.2). |
| 54 | + /// </summary> |
| 55 | + public float Multiplier { get; set; } |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Used in calculating the final price. Negative values are treated as zero. |
| 59 | + /// </summary> |
| 60 | + public int Demand { get; set; } |
| 61 | + |
| 62 | + public static void Write(TradeEntry value, INetStreamWriter writer) |
| 63 | + { |
| 64 | + TradeItem.Write(value.FirstInput, writer); |
| 65 | + writer.WriteItemStack(value.Output); |
| 66 | + TradeItem.Write(value.SecondInput, writer); |
| 67 | + writer.WriteBoolean(value.IsDisabled); |
| 68 | + writer.WriteInt(value.UsedCount); |
| 69 | + writer.WriteInt(value.MaxCount); |
| 70 | + writer.WriteInt(value.XP); |
| 71 | + writer.WriteInt(value.Discount); |
| 72 | + writer.WriteFloat(value.Multiplier); |
| 73 | + writer.WriteInt(value.Demand); |
| 74 | + } |
| 75 | + |
| 76 | + // No need to implement |
| 77 | + public static TradeEntry Read(INetStreamReader reader) => throw new NotImplementedException(); |
| 78 | +} |
0 commit comments