Skip to content
Open
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
6 changes: 6 additions & 0 deletions src/DataModel/Configuration/GameConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public partial class GameConfiguration
/// </summary>
public bool PreventExperienceOverflow { get; set; }

/// <summary>
/// Gets or sets the money drop rate of the game.
/// This multiplier is applied to all money drops, allowing independent control from the experience rate.
/// </summary>
public float MoneyDropRate { get; set; }

/// <summary>
/// Gets or sets the minimum monster level which are required to be killed
/// in order to gain master experience for master character classes.
Expand Down
5 changes: 4 additions & 1 deletion src/GameLogic/DefaultDropGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ public class DefaultDropGenerator : IDropGenerator

private readonly IList<ItemDefinition>?[] _droppableItemsPerMonsterLevel = new IList<ItemDefinition>?[byte.MaxValue + 1];

private readonly GameConfiguration _config;

/// <summary>
/// Initializes a new instance of the <see cref="DefaultDropGenerator" /> class.
/// </summary>
/// <param name="config">The configuration.</param>
/// <param name="randomizer">The randomizer.</param>
public DefaultDropGenerator(GameConfiguration config, IRandomizer randomizer)
{
this._config = config;
this._randomizer = randomizer;
this._maxItemOptionLevelDrop = config.MaximumItemOptionLevelDrop < 1 || config.MaximumItemOptionLevelDrop > 4 ? (byte)3 : config.MaximumItemOptionLevelDrop;
this._droppableItems = config.Items.Where(i => i.DropsFromMonsters).ToList();
Expand Down Expand Up @@ -449,7 +452,7 @@ private void AddRandomExcOptions(Item item)
case SpecialItemType.SocketItem:
return this.GenerateRandomItem((int)monster[Stats.Level], true);
case SpecialItemType.Money:
droppedMoney = (uint)(gainedExperience + BaseMoneyDrop);
droppedMoney = (uint)((gainedExperience + BaseMoneyDrop) * this._config.MoneyDropRate);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

A negative MoneyDropRate could lead to undefined behavior when casting the resulting negative float to uint. It's safer to ensure the value is not negative before casting. This will prevent potential issues, such as dropping a very large amount of money due to how negative floats are converted to unsigned integers.

                droppedMoney = (uint)Math.Max(0, (gainedExperience + BaseMoneyDrop) * this._config.MoneyDropRate);

return null;
default:
// none
Expand Down
Loading