Skip to content

Commit

Permalink
Merge pull request #415 from Niter88/Niter88/reset-by-character-class
Browse files Browse the repository at this point in the history
ADD reset points can be configured by character class
  • Loading branch information
sven-n authored Jun 9, 2024
2 parents 3ac0828 + 5ecc45a commit c3823e4
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/GameLogic/Attributes/Stats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,11 @@ public class Stats
/// </summary>
public static AttributeDefinition IsVip { get; } = new(new Guid("195474D6-59A2-4033-9C30-8628ECC0097E"), "Is VIP", "The flag, if an account is a VIP.");

/// <summary>
/// Gets the attribute for the number of points this class will receive for reset, overwrites the default <see cref="Resets.ResetConfiguration.PointsPerReset"/> value.
/// </summary>
public static AttributeDefinition PointsPerReset { get; } = new(new Guid("a34f4f57-b364-4cdb-9989-64cedd2cd831"), "Points Per Reset", "The number of points the player will receive for reset, overwrites the default 'PointsPerReset' value of the reset configuration.");

/// <summary>
/// Gets the attributes which are regenerated in an interval.
/// </summary>
Expand Down
13 changes: 12 additions & 1 deletion src/GameLogic/Resets/ResetCharacterAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private async ValueTask<bool> TryConsumeMoneyAsync(ResetConfiguration configurat

private void UpdateStats(ResetConfiguration configuration)
{
var calculatedPointsPerReset = configuration.PointsPerReset;
var calculatedPointsPerReset = this.GetResetPoints(configuration);
if (configuration.MultiplyPointsByResetCount)
{
calculatedPointsPerReset *= this.GetResetCount();
Expand All @@ -140,6 +140,17 @@ private void UpdateStats(ResetConfiguration configuration)
this._player.SelectedCharacter!.LevelUpPoints = Math.Max(0, calculatedPointsPerReset);
}

private int GetResetPoints(ResetConfiguration configuration)
{
var pointsPerReset = (int)this._player.Attributes![Stats.PointsPerReset];
if (pointsPerReset == 0)
{
pointsPerReset = configuration.PointsPerReset;
}

return pointsPerReset;
}

private async ValueTask MoveHomeAsync()
{
var homeMapDef = this._player.SelectedCharacter!.CharacterClass!.HomeMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// <copyright file="AddPointsPerResetAttributePlugIn.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;
using System.Runtime.InteropServices;
using MUnique.OpenMU.AttributeSystem;

using MUnique.OpenMU.DataModel.Configuration;
using MUnique.OpenMU.GameLogic.Attributes;
using MUnique.OpenMU.PlugIns;

/// <summary>
/// This update adds the <see cref="Stats.PointsPerReset"/>.
/// </summary>
[PlugIn(PlugInName, PlugInDescription)]
[Guid("6011A1B8-7FA5-48EB-935D-EEAF83017799")]
public class AddPointsPerResetAttributePlugIn : UpdatePlugInBase
{
/// <summary>
/// The plug in name.
/// </summary>
internal const string PlugInName = "Adds attribute PointsPerReset";

/// <summary>
/// The plug in description.
/// </summary>
internal const string PlugInDescription = "This update adds the attribute PointsPerReset.";

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

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

/// <inheritdoc />
public override UpdateVersion Version => UpdateVersion.AddPointsPerResetByClassAttribute;

/// <inheritdoc />
public override string DataInitializationKey => VersionSeasonSix.DataInitialization.Id;

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

/// <inheritdoc />
public override DateTime CreatedAt => new(2024, 06, 09, 13, 30, 0, DateTimeKind.Utc);

/// <inheritdoc />
protected override async ValueTask ApplyAsync(IContext context, GameConfiguration gameConfiguration)
{
var attribute = Stats.PointsPerReset;
var persistentAttribute = context.CreateNew<AttributeDefinition>(attribute.Id, attribute.Designation, attribute.Description);
gameConfiguration.Attributes.Add(persistentAttribute);
}
}
5 changes: 5 additions & 0 deletions src/Persistence/Initialization/Updates/UpdateVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ public enum UpdateVersion
/// The version of the <see cref="InfinityArrowSkillOnQuestCompletionPlugIn"/>.
/// </summary>
InfinityArrowSkillOnQuestCompletion = 15,

/// <summary>
/// The version of the <see cref="AddPointsPerResetAttributePlugIn"/>.
/// </summary>
AddPointsPerResetByClassAttribute = 16
}

0 comments on commit c3823e4

Please sign in to comment.