Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Maple2.File.Ingest/MapperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public static Dictionary<int, IReadOnlyDictionary<int, ItemOption>> ToDictionary
}

var option = new ItemOption(
MultiplyFactor: entry.multiply_factor,
MultiplyFactor: entry.multiply_factor == 0 ? 1 : entry.multiply_factor,
NumPick: new ItemOption.Range<int>(entry.optionNumPick[0], entry.optionNumPick[1]),
Entries: optionEntries.ToArray());
if (results[entry.code].ContainsKey(entry.grade)) {
Expand Down
5 changes: 4 additions & 1 deletion Maple2.Model/Game/Item/ItemStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ public class Option {
public readonly Dictionary<BasicAttribute, BasicOption> Basic;
public readonly Dictionary<SpecialAttribute, SpecialOption> Special;

public readonly float MultiplyFactor;

public int Count => Basic.Count + Special.Count;

public Option(Dictionary<BasicAttribute, BasicOption>? basicOption = null, Dictionary<SpecialAttribute, SpecialOption>? specialOption = null) {
public Option(Dictionary<BasicAttribute, BasicOption>? basicOption = null, Dictionary<SpecialAttribute, SpecialOption>? specialOption = null, float multiplyFactor = 1) {
Basic = basicOption ?? new Dictionary<BasicAttribute, BasicOption>();
Special = specialOption ?? new Dictionary<SpecialAttribute, SpecialOption>();
MultiplyFactor = multiplyFactor;
}

public override string ToString() {
Expand Down
8 changes: 5 additions & 3 deletions Maple2.Server.Game/Commands/ItemCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ public ItemCommand(GameSession session, ItemMetadataStorage itemStorage) : base(
var amount = new Option<int>(["--amount", "-a"], () => 1, "Amount of the item.");
var rarity = new Option<int>(["--rarity", "-r"], () => 1, "Rarity of the item.");
var drop = new Option<bool>(["--drop"], "Drop item instead of adding to inventory");
var rollMax = new Option<bool>(["--roll-max"], () => false, "Max roll stats.");

AddArgument(id);
AddOption(amount);
AddOption(rarity);
AddOption(drop);
this.SetHandler<InvocationContext, int, int, int, bool>(Handle, id, amount, rarity, drop);
AddOption(rollMax);
this.SetHandler<InvocationContext, int, int, int, bool, bool>(Handle, id, amount, rarity, drop, rollMax);
}

private void Handle(InvocationContext ctx, int itemId, int amount, int rarity, bool drop) {
private void Handle(InvocationContext ctx, int itemId, int amount, int rarity, bool drop, bool rollMax) {
try {
rarity = Math.Clamp(rarity, 1, MAX_RARITY);
Item? item = session.Field.ItemDrop.CreateItem(itemId, rarity);
Item? item = session.Field.ItemDrop.CreateItem(itemId, rarity, rollMax: rollMax);
if (item == null) {
ctx.Console.Error.WriteLine($"Invalid Item: {itemId}");
return;
Expand Down
4 changes: 2 additions & 2 deletions Maple2.Server.Game/Manager/Items/ItemDropManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private bool IsItemJobRecommended(int itemId, JobCode job) {
return itemMetadata.Limit.JobRecommends.Contains(job) || itemMetadata.Limit.JobRecommends.Contains(JobCode.None);
}

public Item? CreateItem(int itemId, int rarity = -1, int amount = 1) {
public Item? CreateItem(int itemId, int rarity = -1, int amount = 1, bool rollMax = false) {
if (!field.ItemMetadata.TryGet(itemId, out ItemMetadata? itemMetadata)) {
return null;
}
Expand All @@ -304,7 +304,7 @@ private bool IsItemJobRecommended(int itemId, JobCode job) {
}

var item = new Item(itemMetadata, rarity, amount);
item.Stats = field.ItemStatsCalc.GetStats(item);
item.Stats = field.ItemStatsCalc.GetStats(item, rollMax);
item.Socket = field.ItemStatsCalc.GetSockets(item);

if (item.Appearance != null) {
Expand Down
22 changes: 11 additions & 11 deletions Maple2.Server.Game/Util/ItemStatsCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public sealed class ItemStatsCalculator {
// ReSharper restore All
#endregion

public ItemStats? GetStats(Item item) {
public ItemStats? GetStats(Item item, bool rollMax = false) {
if (item.Metadata.Option == null) {
return null;
}
Expand All @@ -36,7 +36,7 @@ public sealed class ItemStatsCalculator {
}

if (GetRandomOption(item, out ItemStats.Option? option)) {
RandomizeValues(item.Type, ref option);
RandomizeValues(item.Type, ref option, rollMax);
stats[ItemStats.Type.Random] = option;
}

Expand Down Expand Up @@ -106,30 +106,30 @@ public bool UpdateRandomOption(ref Item item, params LockOption[] presets) {
}

// TODO: These should technically be weighted towards the lower end.
public bool RandomizeValues(in ItemType type, ref ItemStats.Option option) {
public bool RandomizeValues(in ItemType type, ref ItemStats.Option option, bool rollMax = false) {
ItemEquipVariationTable? table = GetVariationTable(type);
if (table == null) {
return false;
}

foreach (BasicAttribute attribute in option.Basic.Keys) {
int index = Random.Shared.Next(2, 18);
int index = rollMax ? 17 : Random.Shared.Next(2, 18);
Comment thread
AngeloTadeucci marked this conversation as resolved.
if (table.Values.TryGetValue(attribute, out int[]? values)) {
int value = values.ElementAtOrDefault(index);
option.Basic[attribute] = new BasicOption(value);
option.Basic[attribute] = new BasicOption((int) (value * option.MultiplyFactor));
Comment thread
AngeloTadeucci marked this conversation as resolved.
} else if (table.Rates.TryGetValue(attribute, out float[]? rates)) {
float rate = rates.ElementAtOrDefault(index);
option.Basic[attribute] = new BasicOption(rate);
option.Basic[attribute] = new BasicOption(rate * option.MultiplyFactor);
}
}
foreach (SpecialAttribute attribute in option.Special.Keys) {
int index = Random.Shared.Next(2, 18);
int index = rollMax ? 17 : Random.Shared.Next(2, 18);
if (table.SpecialValues.TryGetValue(attribute, out int[]? values)) {
int value = values.ElementAtOrDefault(index);
option.Special[attribute] = new SpecialOption(0f, value);
option.Special[attribute] = new SpecialOption(0f, value * option.MultiplyFactor);
} else if (table.SpecialRates.TryGetValue(attribute, out float[]? rates)) {
float rate = rates.ElementAtOrDefault(index);
option.Special[attribute] = new SpecialOption(rate);
option.Special[attribute] = new SpecialOption(rate * option.MultiplyFactor);
}
}

Expand Down Expand Up @@ -251,7 +251,7 @@ private static ItemStats.Option RandomItemOption(ItemOption option, int count =

int total = count < 0 ? Random.Shared.Next(option.NumPick.Min, option.NumPick.Max + 1) : count;
if (total == 0) {
return new ItemStats.Option(statResult, specialResult);
return new ItemStats.Option(statResult, specialResult, multiplyFactor: option.MultiplyFactor);
}
// Ensures that there are enough options to choose.
total = Math.Min(total, option.Entries.Length);
Expand All @@ -276,7 +276,7 @@ private static ItemStats.Option RandomItemOption(ItemOption option, int count =
}
}

return new ItemStats.Option(statResult, specialResult);
return new ItemStats.Option(statResult, specialResult, multiplyFactor: option.MultiplyFactor);

// Helper function
bool AddResult(ItemOption.Entry entry, IDictionary<BasicAttribute, BasicOption> statDict, IDictionary<SpecialAttribute, SpecialOption> specialDict) {
Expand Down