Skip to content

Commit

Permalink
Merge branch 'master' into 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 ca6b912 + c825d50 commit 0e09316
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 24 deletions.
5 changes: 5 additions & 0 deletions src/AttributeSystem/AggregateType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ public enum AggregateType
/// Adds the value to the final value.
/// </summary>
AddFinal,

/// <summary>
/// Adds only the highest available value to the raw base value (jewelry element resistance).
/// </summary>
Maximum,
}
4 changes: 3 additions & 1 deletion src/AttributeSystem/ComposableAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ private float GetAndCacheValue()
var rawValues = this.Elements.Where(e => e.AggregateType == AggregateType.AddRaw).Sum(e => e.Value);
var multiValues = this.Elements.Where(e => e.AggregateType == AggregateType.Multiplicate).Select(e => e.Value).Concat(Enumerable.Repeat(1.0F, 1)).Aggregate((a, b) => a * b);
var finalValues = this.Elements.Where(e => e.AggregateType == AggregateType.AddFinal).Sum(e => e.Value);
var maxValues = this.Elements.Where(e => e.AggregateType == AggregateType.Maximum).MaxBy(e => e.Value)?.Value ?? 0;
rawValues += maxValues;

if (multiValues == 0 && this.Elements.All(e => e.AggregateType != AggregateType.Multiplicate))
{
Expand All @@ -75,7 +77,7 @@ private float GetAndCacheValue()
// nothing to do
}

this._cachedValue = (rawValues * multiValues + finalValues);
this._cachedValue = (rawValues * multiValues) + finalValues;

return this._cachedValue.Value;
}
Expand Down
7 changes: 4 additions & 3 deletions src/GameLogic/InventoryStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace MUnique.OpenMU.GameLogic;
using MUnique.OpenMU.GameLogic.Attributes;
using MUnique.OpenMU.GameLogic.Views.World;
using MUnique.OpenMU.PlugIns;
using static OpenMU.DataModel.InventoryConstants;
using static MUnique.OpenMU.DataModel.InventoryConstants;

/// <summary>
/// The storage of an inventory of a player, which also contains equippable slots. This class also manages the powerups which get created by equipped items.
Expand Down Expand Up @@ -166,8 +166,9 @@ await this._player.ForEachWorldObserverAsync<IAppearanceChangedPlugIn>(
this._player.Attributes.ItemPowerUps.Add(item, factory.GetPowerUps(item, this._player.Attributes).ToList());

// reset player equipped ammunition amount
if (this.EquippedAmmunitionItem is { } ammoItem) {
this._player.Attributes[Stats.AmmunitionAmount] = (float) ammoItem.Durability;
if (this.EquippedAmmunitionItem is { } ammoItem)
{
this._player.Attributes[Stats.AmmunitionAmount] = (float)ammoItem.Durability;
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/GameLogic/ItemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,25 @@ public static bool IsShield(this Item item)
return item.Definition?.Group == ShieldItemGroup;
}

/// <summary>
/// Determines whether this item is a jewelry (pendant or ring) item.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>
/// <c>true</c> if the specified item is jewelry; otherwise, <c>false</c>.
/// </returns>
public static bool IsJewelry(this Item item)
{
return item.ItemSlot >= InventoryConstants.PendantSlot && item.ItemSlot <= InventoryConstants.Ring2Slot;
}

/// <summary>
/// Determines whether this instance is a is weapon which deals physical damage.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="minimumDmg">The minimum physical damage of the weapon.</param>
/// <returns>
/// <c>true</c> if this instance is a is weapon which deals physical damage; otherwise, <c>false</c>.
/// <c>true</c> if this instance is a weapon which deals physical damage; otherwise, <c>false</c>.
/// </returns>
public static bool IsPhysicalWeapon(this Item item, [NotNullWhen(true)] out float? minimumDmg)
{
Expand All @@ -144,7 +156,7 @@ public static bool IsPhysicalWeapon(this Item item, [NotNullWhen(true)] out floa
/// <param name="item">The item.</param>
/// <param name="staffRise">The staff rise percentage of the weapon.</param>
/// <returns>
/// <c>true</c> if this instance is a is weapon which deals wizardry damage; otherwise, <c>false</c>.
/// <c>true</c> if this instance is a weapon which deals wizardry damage; otherwise, <c>false</c>.
/// </returns>
public static bool IsWizardryWeapon(this Item item, [NotNullWhen(true)] out float? staffRise)
{
Expand Down
18 changes: 13 additions & 5 deletions src/GameLogic/ItemPowerUpFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,20 @@ private IEnumerable<PowerUpWrapper> GetBasePowerUpWrappers(Item item, AttributeS
attribute.ThrowNotInitializedProperty(attribute.BaseValueElement is null, nameof(attribute.BaseValueElement));
attribute.ThrowNotInitializedProperty(attribute.TargetAttribute is null, nameof(attribute.TargetAttribute));

yield return new PowerUpWrapper(attribute.BaseValueElement, attribute.TargetAttribute, attributeHolder);
var levelBonusElmt = (attribute.BonusPerLevelTable?.BonusPerLevel ?? Enumerable.Empty<LevelBonus>())
.FirstOrDefault(bonus => bonus.Level == item.Level)?
.GetAdditionalValueElement(attribute.AggregateType);

var levelBonus = (attribute.BonusPerLevelTable?.BonusPerLevel ?? Enumerable.Empty<LevelBonus>()).FirstOrDefault(bonus => bonus.Level == item.Level);
if (levelBonus is not null)
if (levelBonusElmt is null)
{
yield return new PowerUpWrapper(levelBonus.GetAdditionalValueElement(attribute.AggregateType), attribute.TargetAttribute, attributeHolder);
yield return new PowerUpWrapper(attribute.BaseValueElement, attribute.TargetAttribute, attributeHolder);
}
else
{
yield return new PowerUpWrapper(
new CombinedElement(attribute.BaseValueElement, levelBonusElmt),
attribute.TargetAttribute,
attributeHolder);
}
}

Expand Down Expand Up @@ -253,7 +261,7 @@ private IEnumerable<PowerUpWrapper> CreateExcellentAndAncientBasePowerUpWrappers
var baseDropLevel = item.Definition!.DropLevel;
var ancientDropLevel = item.Definition!.CalculateDropLevel(true, false, 0);

if (InventoryConstants.IsDefenseItemSlot(item.ItemSlot))
if (InventoryConstants.IsDefenseItemSlot(item.ItemSlot) && !item.IsJewelry())
{
var baseDefense = (int)(item.Definition?.BasePowerUpAttributes.FirstOrDefault(a => a.TargetAttribute == Stats.DefenseBase)?.BaseValue ?? 0);
var additionalDefense = (baseDefense * 12 / baseDropLevel) + (baseDropLevel / 5) + 4;
Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/Initialization/Items/OptionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ public static ItemOptionDefinition ExcellentPhysicalAttackOptions(this GameConfi
/// <returns>The excellent wizardry attack options.</returns>
public static ItemOptionDefinition ExcellentWizardryAttackOptions(this GameConfiguration gameConfiguration)
{
return gameConfiguration.ItemOptions.First(o => o.Name == ExcellentOptions.PhysicalAttackOptionsName);
return gameConfiguration.ItemOptions.First(o => o.Name == ExcellentOptions.WizardryAttackOptionsName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// <copyright file="FixWingsDmgRatesUpdatePlugIn075.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

namespace MUnique.OpenMU.Persistence.Initialization.Updates;

using System.Runtime.InteropServices;
using MUnique.OpenMU.AttributeSystem;
using MUnique.OpenMU.PlugIns;

/// <summary>
/// This update fixes the wings damage absorption and increase bonus level tables values for a <see cref="CombinedElement"/> (sum) calculation, instead of a compound calculation
/// for version 075.
/// </summary>
[PlugIn(PlugInName, PlugInDescription)]
[Guid("3821267A-9C37-40E5-B023-BAB1A8E4DAB7")]
public class FixWingsDmgRatesUpdatePlugIn075 : FixWingsDmgRatesUpdatePlugInBase
{
/// <inheritdoc />
public override string DataInitializationKey => Version075.DataInitialization.Id;

/// <inheritdoc />
public override UpdateVersion Version => UpdateVersion.FixWingsDmgRatesPlugIn075;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// <copyright file="FixWingsDmgRatesUpdatePlugIn095d.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

namespace MUnique.OpenMU.Persistence.Initialization.Updates;

using System.Runtime.InteropServices;
using MUnique.OpenMU.AttributeSystem;
using MUnique.OpenMU.PlugIns;

/// <summary>
/// This update fixes the wings damage absorption and increase bonus level tables values for a <see cref="CombinedElement"/> (sum) calculation, instead of a compound calculation
/// for version 095d.
/// </summary>
[PlugIn(PlugInName, PlugInDescription)]
[Guid("F45FA4D0-B19B-48E2-9592-A37F3B36348A")]
public class FixWingsDmgRatesUpdatePlugIn095D : FixWingsDmgRatesUpdatePlugInBase
{
/// <inheritdoc />
public override string DataInitializationKey => Version095d.DataInitialization.Id;

/// <inheritdoc />
public override UpdateVersion Version => UpdateVersion.FixWingsDmgRatesPlugIn095d;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// <copyright file="FixWingsDmgRatesUpdatePlugInBase.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

namespace MUnique.OpenMU.Persistence.Initialization.Updates;

using MUnique.OpenMU.AttributeSystem;
using MUnique.OpenMU.DataModel.Configuration;

/// <summary>
/// This update fixes the wings damage absorption and increase bonus level tables values for a <see cref="CombinedElement"/> (sum) calculation, instead of a compound calculation.
/// </summary>
public abstract class FixWingsDmgRatesUpdatePlugInBase : UpdatePlugInBase
{
/// <summary>
/// The plug in name.
/// </summary>
internal const string PlugInName = "Fix Wings Damage Rates";

/// <summary>
/// The plug in description.
/// </summary>
internal const string PlugInDescription = "This update fixes the wings damage absorption and increase bonus level tables values.";

/// <inheritdoc />
public override string Name => PlugInName;

/// <inheritdoc />
public override string Description => PlugInDescription;

/// <inheritdoc />
public override bool IsMandatory => true;

/// <inheritdoc />
public override DateTime CreatedAt => new(2023, 10, 8, 16, 0, 0, DateTimeKind.Utc);

/// <inheritdoc />
protected override async ValueTask ApplyAsync(IContext context, GameConfiguration gameConfiguration)
{
string dmgAbsorbCommonName = "Wing absorb";
string dmgIncreaseCommonName = "Damage Increase (1st and 3rd Wings)";
string dmgIncrease2ndWingsName = "Damage Increase (2nd Wings)";

string[] wingDmgTableNames = [dmgAbsorbCommonName, dmgIncrease2ndWingsName, dmgIncreaseCommonName];

foreach (var tableName in wingDmgTableNames)
{
var bonusEntries = gameConfiguration.ItemLevelBonusTables.FirstOrDefault(ilbt => ilbt.Name == tableName)?.BonusPerLevel;

if (bonusEntries is not null)
{
foreach (var bonusEntry in bonusEntries)
{
bonusEntry.AdditionalValue -= 1.0f;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// <copyright file="FixWingsDmgRatesUpdatePlugInSeason6.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

namespace MUnique.OpenMU.Persistence.Initialization.Updates;

using System.Runtime.InteropServices;
using MUnique.OpenMU.AttributeSystem;
using MUnique.OpenMU.PlugIns;

/// <summary>
/// This update fixes the wings damage absorption and increase bonus level tables values for a <see cref="CombinedElement"/> (sum) calculation, instead of a compound calculation
/// for season 6.
/// </summary>
[PlugIn(PlugInName, PlugInDescription)]
[Guid("03F49890-CB0E-40B7-A590-174BBA1962F4")]
public class FixWingsDmgRatesUpdatePlugInSeason6 : FixWingsDmgRatesUpdatePlugInBase
{
/// <inheritdoc />
public override string DataInitializationKey => VersionSeasonSix.DataInitialization.Id;

/// <inheritdoc />
public override UpdateVersion Version => UpdateVersion.FixWingsDmgRatesPlugInSeason6;
}
15 changes: 15 additions & 0 deletions src/Persistence/Initialization/Updates/UpdateVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,19 @@ public enum UpdateVersion
/// The version of the <see cref="FixMaxManaAndAbilityJewelryOptionsUpdateSeason6"/>.
/// </summary>
FixMaxManaAndAbilityJewelryOptionsSeason6 = 31,

/// <summary>
/// The version of the <see cref="FixWingsDmgRatesUpdatePlugIn075"/>.
/// </summary>
FixWingsDmgRatesPlugIn075 = 32,

/// <summary>
/// The version of the <see cref="FixWingsDmgRatesUpdatePlugIn095D"/>.
/// </summary>
FixWingsDmgRatesPlugIn095d = 33,

/// <summary>
/// The version of the <see cref="FixWingsDmgRatesUpdatePlugInSeason6"/>.
/// </summary>
FixWingsDmgRatesPlugInSeason6 = 34,
}
7 changes: 5 additions & 2 deletions src/Persistence/Initialization/Version075/Items/Jewelery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace MUnique.OpenMU.Persistence.Initialization.Version075.Items;

using MUnique.OpenMU.AttributeSystem;
using MUnique.OpenMU.DataModel.Attributes;
using MUnique.OpenMU.DataModel.Configuration;
using MUnique.OpenMU.DataModel.Configuration.Items;
using MUnique.OpenMU.GameLogic.Attributes;
Expand All @@ -29,6 +28,9 @@ public Jewelery(IContext context, GameConfiguration gameConfiguration)
{
}

/// <inheritdoc/>
protected override int MaximumOptionLevel => 3;

/// <inheritdoc/>
public sealed override void Initialize()
{
Expand Down Expand Up @@ -162,8 +164,9 @@ protected ItemDefinition CreateJewelery(byte number, int slot, bool dropsFromMon

if (resistanceAttribute != null)
{
var powerUp = this.CreateItemBasePowerUpDefinition(resistanceAttribute, 0.1f, AggregateType.AddRaw);
var powerUp = this.CreateItemBasePowerUpDefinition(resistanceAttribute, 0.1f, AggregateType.Maximum);
powerUp.BonusPerLevelTable = this._resistancesBonusTable;
item.BasePowerUpAttributes.Add(powerUp);
}

foreach (var characterClass in this.GameConfiguration.CharacterClasses)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private ItemDefinition CreateWing(byte number, byte width, byte height, string n

if (damageIncreaseInitial > 0)
{
var powerUp = this.CreateItemBasePowerUpDefinition(Stats.AttackDamageIncrease, 1f + damageIncreaseInitial / 100f, AggregateType.Multiplicate);
var powerUp = this.CreateItemBasePowerUpDefinition(Stats.AttackDamageIncrease, 1f + (damageIncreaseInitial / 100f), AggregateType.Multiplicate);
powerUp.BonusPerLevelTable = damageIncreasePerLevel;
wing.BasePowerUpAttributes.Add(powerUp);
}
Expand Down
15 changes: 6 additions & 9 deletions src/Persistence/Initialization/WingsInitializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ protected ItemLevelBonusTable CreateAbsorbBonusPerLevel()
{
IEnumerable<float> Generate()
{
yield return 1f;
for (int level = 1; level <= this.MaximumItemLevel; level++)
for (int level = 0; level <= this.MaximumItemLevel; level++)
{
yield return 1f - (0.02f * level);
yield return -0.02f * level;
}
}

Expand All @@ -95,10 +94,9 @@ protected ItemLevelBonusTable CreateDamageIncreaseBonusPerLevelFirstAndThirdWing
{
IEnumerable<float> Generate()
{
yield return 1f;
for (int level = 1; level <= this.MaximumItemLevel; level++)
for (int level = 0; level <= this.MaximumItemLevel; level++)
{
yield return 1f + (0.02f * level);
yield return 0.02f * level;
}
}

Expand All @@ -109,10 +107,9 @@ protected ItemLevelBonusTable CreateDamageIncreaseBonusPerLevelSecondWings()
{
IEnumerable<float> Generate()
{
yield return 1;
for (int level = 1; level <= this.MaximumItemLevel; level++)
for (int level = 0; level <= this.MaximumItemLevel; level++)
{
yield return 1 + (0.01f * level);
yield return 0.01f * level;
}
}

Expand Down

0 comments on commit 0e09316

Please sign in to comment.