Skip to content

Commit

Permalink
Add mob reward proc calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Dec 7, 2023
1 parent faaa95f commit 4e8f98e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Rewards;

public record MobReward(
int ID
int ID,
double Proc = 1.0
) : IMobReward
{
public int? ItemID { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ public class MobRewardPoolManager :

public async Task<ICollection<IMobReward>> CalculateRewards(IFieldUser user, IFieldMob mob)
{
var random = new Random();
var pool = await Retrieve(mob.Template.ID);
var items = new List<IMobReward>();

if (pool != null)
items.AddRange(await pool.RetrieveAll());
items.AddRange(await Global.RetrieveAll());

return items
return
(pool != null
? await pool.RetrieveAll()
: new List<IMobReward>())
.Concat(await Global.RetrieveAll())
.Where(r =>
{
// TODO filters

return random.NextSingle() <= r.Proc;
})
.OrderBy(i => Random.Shared.Next())
.ToImmutableArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class MobRewardTemplate : ITemplate, IMobReward
public DateTime? DateStart { get; }
public DateTime? DateEnd { get; }

public double Proc { get; }

public MobRewardTemplate(int id, IDataNode property)
{
ID = id;
Expand All @@ -36,5 +38,7 @@ public MobRewardTemplate(int id, IDataNode property)

NumberMin = property.ResolveInt("min");
NumberMax = property.ResolveInt("max");

Proc = property.ResolveDouble("prob") ?? 1.0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public interface IMobReward : IReward

DateTime? DateStart { get; }
DateTime? DateEnd { get; }

double Proc { get; }
}

0 comments on commit 4e8f98e

Please sign in to comment.