Skip to content

Commit

Permalink
Merge pull request #501 from ze-dom/feature/max_item_option_level_drop
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-n authored Oct 18, 2024
2 parents c825d50 + 0e09316 commit fd9fbf8
Show file tree
Hide file tree
Showing 12 changed files with 5,072 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/DataModel/Configuration/GameConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public partial class GameConfiguration
/// </summary>
public TimeSpan ItemDropDuration { get; set; }

/// <summary>
/// Gets or sets the maximum droppable item option level.
/// </summary>
public byte MaximumItemOptionLevelDrop { get; set; }

/// <summary>
/// Gets or sets the accumulated damage which needs to be done to decrease <see cref="Item.Durability"/> of a defending item by 1.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/DataModel/Configuration/Items/ItemOptionTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class ItemOptionTypes
/// <summary>
/// Gets the luck option type.
/// </summary>
public static ItemOptionType Luck { get; } = new () { Name = "Luck (Critical Damage Chance 10%)", Id = new Guid("{3E3E9BE8-4E16-4F27-A7CF-986D48454D76}") };
public static ItemOptionType Luck { get; } = new () { Name = "Luck (Critical Damage Chance 5%)", Id = new Guid("{3E3E9BE8-4E16-4F27-A7CF-986D48454D76}") };

/// <summary>
/// Gets the standard option option type.
Expand Down
7 changes: 6 additions & 1 deletion src/GameLogic/DefaultDropGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class DefaultDropGenerator : IDropGenerator

private readonly AsyncLock _lock = new();

private readonly byte _maxItemOptionLevelDrop;

private readonly IList<ItemDefinition> _ancientItems;

private readonly IList<ItemDefinition> _droppableItems;
Expand All @@ -41,6 +43,7 @@ public class DefaultDropGenerator : IDropGenerator
public DefaultDropGenerator(GameConfiguration config, IRandomizer randomizer)
{
this._randomizer = randomizer;
this._maxItemOptionLevelDrop = config.MaximumItemOptionLevelDrop < 1 || config.MaximumItemOptionLevelDrop > 4 ? (byte)3 : config.MaximumItemOptionLevelDrop;
this._droppableItems = config.Items.Where(i => i.DropsFromMonsters).ToList();
this._ancientItems = this._droppableItems.Where(
i => i.PossibleItemSetGroups.Any(
Expand Down Expand Up @@ -319,7 +322,9 @@ private void ApplyOption(Item item, ItemOptionDefinition option)
var itemOptionLink = new ItemOptionLink
{
ItemOption = newOption,
Level = newOption?.LevelDependentOptions.Select(l => l.Level).SelectRandom() ?? 0,
Level = newOption?.LevelDependentOptions.Select(ldo => ldo.Level)
.Concat(newOption.LevelDependentOptions.Count > 0 ? [1] : []) // For base def/dmg opts level 1 is not an ItemOptionOfLevel entry
.Distinct().Where(l => l <= this._maxItemOptionLevelDrop).SelectRandom() ?? 0,
};
item.ItemOptions.Add(itemOptionLink);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public enum ItemFailResult
DecreaseOptionByOne,

/// <summary>
/// Decreases the option by one level, or removes the option if the level would reach 0.
/// Removes the option.
/// </summary>
DecreaseOptionByOneOrRemove,
RemoveOption,
}

/// <summary>
Expand Down Expand Up @@ -104,13 +104,8 @@ private void HandleFailedUpgrade(Item item, ItemOptionLink itemOption)
case ItemFailResult.DecreaseOptionByOne:
itemOption.Level = Math.Max(itemOption.Level - 1, 1);
break;
case ItemFailResult.DecreaseOptionByOneOrRemove:
itemOption.Level -= 1;
if (itemOption.Level == 0)
{
item.ItemOptions.Remove(itemOption);
}

case ItemFailResult.RemoveOption:
item.ItemOptions.Remove(itemOption);
break;
case ItemFailResult.SetOptionToLevelOne:
itemOption.Level = 1;
Expand Down Expand Up @@ -142,7 +137,9 @@ private bool TryAddItemOption(Item item, IContext persistenceContext)
var optionLink = persistenceContext.CreateNew<ItemOptionLink>();
optionLink.ItemOption = possibleOptions.SelectRandom()!;
optionLink.Level = optionLink.ItemOption.LevelDependentOptions.Any()
? optionLink.ItemOption.LevelDependentOptions.Min(l => l.Level)
? optionLink.ItemOption.LevelDependentOptions.Select(ldo => ldo.Level)
.Concat(this.Configuration.OptionType == ItemOptionTypes.Option ? [1] : []) // For base def/dmg opts level 1 is not an ItemOptionOfLevel entry
.Min()
: 1;
item.ItemOptions.Add(optionLink);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LifeJewelConsumeHandlerPlugIn : ItemUpgradeConsumeHandlerPlugIn
/// Initializes a new instance of the <see cref="LifeJewelConsumeHandlerPlugIn" /> class.
/// </summary>
public LifeJewelConsumeHandlerPlugIn()
: base(new ItemUpgradeConfiguration(ItemOptionTypes.Option, true, true, 0.5, ItemFailResult.DecreaseOptionByOneOrRemove))
: base(new ItemUpgradeConfiguration(ItemOptionTypes.Option, true, true, 0.5, ItemFailResult.RemoveOption))
{
}

Expand Down
Loading

0 comments on commit fd9fbf8

Please sign in to comment.