-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement mob reward loading, managers, and drops while kill monster (#…
…88) * Add mobreward interfaces * Add mobreward template loading, implement mobrewardmanager * Add mob reward handling
- Loading branch information
Showing
17 changed files
with
305 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/Rewards/MobReward.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Rewards; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Rewards; | ||
|
||
public record MobReward( | ||
int ID | ||
) : IMobReward | ||
{ | ||
public int? ItemID { get; init; } | ||
|
||
public int? Money { get; init; } | ||
|
||
public int? NumberMin { get; init; } | ||
public int? NumberMax { get; init; } | ||
|
||
public int? ReqQuest { get; init; } | ||
|
||
public int? ReqLevelMin { get; init; } | ||
public int? ReqLevelMax { get; init; } | ||
|
||
public int? ReqMobLevelMin { get; init; } | ||
public int? ReqMobLevelMax { get; init; } | ||
|
||
public DateTime? DateStart { get; init; } | ||
public DateTime? DateEnd { get; init; } | ||
} |
28 changes: 28 additions & 0 deletions
28
src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/Rewards/MobRewardPoolManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections.Immutable; | ||
using Edelstein.Common.Utilities.Repositories; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.Mob; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Rewards; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.User; | ||
using Edelstein.Protocol.Gameplay.Game.Rewards; | ||
using Edelstein.Protocol.Utilities.Repositories; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Rewards; | ||
|
||
public class MobRewardPoolManager : | ||
Repository<int, IRewardPool<IMobReward>>, | ||
IMobRewardPoolManager | ||
{ | ||
public IRepository<int, IMobReward> Global { get; } = new Repository<int, IMobReward>(); | ||
|
||
public async Task<ICollection<IMobReward>> CalculateRewards(IFieldUser user, IFieldMob mob) | ||
{ | ||
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.ToImmutableArray(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/Rewards/MobRewardPoolManagerInit.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Edelstein.Common.Gameplay.Game.Objects.Mob.Templates; | ||
using Edelstein.Common.Gameplay.Game.Rewards; | ||
using Edelstein.Protocol.Gameplay.Contracts; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Rewards; | ||
using Edelstein.Protocol.Utilities.Pipelines; | ||
using Edelstein.Protocol.Utilities.Templates; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Rewards; | ||
|
||
public class MobRewardPoolManagerInit : IPipelinePlug<StageStart> | ||
{ | ||
private readonly ITemplateManager<MobRewardPoolTemplate> _templates; | ||
private readonly IMobRewardPoolManager _manager; | ||
|
||
public MobRewardPoolManagerInit( | ||
ITemplateManager<MobRewardPoolTemplate> templates, | ||
IMobRewardPoolManager manager | ||
) | ||
{ | ||
_templates = templates; | ||
_manager = manager; | ||
} | ||
|
||
public async Task Handle(IPipelineContext ctx, StageStart message) | ||
{ | ||
foreach (var rewards in await _templates.RetrieveAll()) | ||
{ | ||
var pool = new RewardPool<IMobReward>(rewards.ID); | ||
foreach (var item in rewards.Items) | ||
await pool.Insert(item); | ||
await _manager.Insert(pool); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/Templates/MobRewardPoolTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Collections.Immutable; | ||
using Duey.Abstractions; | ||
using Edelstein.Common.Gameplay.Game.Objects.NPC.Templates; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.NPC; | ||
using Edelstein.Protocol.Utilities.Templates; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Templates; | ||
|
||
public class MobRewardPoolTemplate : ITemplate | ||
{ | ||
public int ID { get; } | ||
public ICollection<MobRewardTemplate> Items { get; } | ||
|
||
public MobRewardPoolTemplate(int id, IDataNode property) | ||
{ | ||
ID = id; | ||
Items = property.Children | ||
.Select(p => new MobRewardTemplate(Convert.ToInt32(p.Name), p.Cache())) | ||
.ToImmutableArray(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ommon/Edelstein.Common.Gameplay.Game/Objects/Mob/Templates/MobRewardPoolTemplateLoader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Duey.Abstractions; | ||
using Edelstein.Common.Gameplay.Game.Objects.NPC.Templates; | ||
using Edelstein.Common.Utilities.Templates; | ||
using Edelstein.Protocol.Utilities.Templates; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Templates; | ||
|
||
public class MobRewardPoolTemplateLoader : ITemplateLoader | ||
{ | ||
private readonly IDataNamespace _data; | ||
private readonly ITemplateManager<MobRewardPoolTemplate> _manager; | ||
|
||
public MobRewardPoolTemplateLoader(IDataNamespace data, ITemplateManager<MobRewardPoolTemplate> manager) | ||
{ | ||
_data = data; | ||
_manager = manager; | ||
} | ||
|
||
public async Task<int> Load() | ||
{ | ||
await Task.WhenAll(_data.ResolvePath("Server/Reward.img")?.Children | ||
.Select(async n => | ||
{ | ||
var id = Convert.ToInt32(n.Name); | ||
await _manager.Insert(new TemplateProviderEager<MobRewardPoolTemplate>( | ||
id, | ||
new MobRewardPoolTemplate(id, n.Cache()) | ||
)); | ||
}) ?? Array.Empty<Task>()); | ||
|
||
return _manager.Count; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/Templates/MobRewardTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Duey.Abstractions; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Rewards; | ||
using Edelstein.Protocol.Utilities.Templates; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Objects.Mob.Templates; | ||
|
||
public class MobRewardTemplate : ITemplate, IMobReward | ||
{ | ||
public int ID { get; } | ||
|
||
public int? ItemID { get; } | ||
|
||
public int? Money { get; } | ||
|
||
public int? NumberMin { get; } | ||
public int? NumberMax { get; } | ||
|
||
public int? ReqQuest { get; } | ||
|
||
public int? ReqLevelMin { get; } | ||
public int? ReqLevelMax { get; } | ||
|
||
public int? ReqMobLevelMin { get; } | ||
public int? ReqMobLevelMax { get; } | ||
|
||
public DateTime? DateStart { get; } | ||
public DateTime? DateEnd { get; } | ||
|
||
public MobRewardTemplate(int id, IDataNode property) | ||
{ | ||
ID = id; | ||
|
||
ItemID = property.ResolveInt("item"); | ||
|
||
Money = property.ResolveInt("money"); | ||
|
||
NumberMin = property.ResolveInt("min"); | ||
NumberMax = property.ResolveInt("max"); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/common/Edelstein.Common.Gameplay.Game/Rewards/RewardPool.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Edelstein.Common.Utilities.Repositories; | ||
using Edelstein.Protocol.Gameplay.Game.Rewards; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Rewards; | ||
|
||
public class RewardPool<TReward> : | ||
Repository<int, TReward>, | ||
IRewardPool<TReward> | ||
where TReward : IReward | ||
{ | ||
public int ID { get; } | ||
|
||
public RewardPool(int id) => ID = id; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/common/Edelstein.Common.Gameplay.Game/Rewards/RewardPoolManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Edelstein.Common.Utilities.Repositories; | ||
using Edelstein.Protocol.Gameplay.Game.Rewards; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Rewards; | ||
|
||
public class RewardPoolManager<TReward> : | ||
Repository<int, IRewardPool<TReward>>, | ||
IRewardPoolManager<TReward> | ||
where TReward : IReward | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/protocol/Edelstein.Protocol.Gameplay.Game/Objects/Mob/Rewards/IMobReward.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Edelstein.Protocol.Gameplay.Game.Rewards; | ||
|
||
namespace Edelstein.Protocol.Gameplay.Game.Objects.Mob.Rewards; | ||
|
||
public interface IMobReward : IReward | ||
{ | ||
int? ItemID { get; } | ||
|
||
int? Money { get; } | ||
|
||
int? NumberMin { get; } | ||
int? NumberMax { get; } | ||
|
||
int? ReqQuest { get; } | ||
|
||
int? ReqLevelMin { get; } | ||
int? ReqLevelMax { get; } | ||
|
||
int? ReqMobLevelMin { get; } | ||
int? ReqMobLevelMax { get; } | ||
|
||
DateTime? DateStart { get; } | ||
DateTime? DateEnd { get; } | ||
} |
12 changes: 12 additions & 0 deletions
12
src/protocol/Edelstein.Protocol.Gameplay.Game/Objects/Mob/Rewards/IMobRewardPoolManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Edelstein.Protocol.Gameplay.Game.Objects.User; | ||
using Edelstein.Protocol.Gameplay.Game.Rewards; | ||
using Edelstein.Protocol.Utilities.Repositories; | ||
|
||
namespace Edelstein.Protocol.Gameplay.Game.Objects.Mob.Rewards; | ||
|
||
public interface IMobRewardPoolManager : IRewardPoolManager<IMobReward> | ||
{ | ||
IRepository<int, IMobReward> Global { get; } | ||
|
||
Task<ICollection<IMobReward>> CalculateRewards(IFieldUser user, IFieldMob mob); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/protocol/Edelstein.Protocol.Gameplay.Game/Rewards/IReward.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using Edelstein.Protocol.Utilities.Repositories; | ||
|
||
namespace Edelstein.Protocol.Gameplay.Game.Rewards; | ||
|
||
public interface IReward : IIdentifiable<int> | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
src/protocol/Edelstein.Protocol.Gameplay.Game/Rewards/IRewardPool.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Edelstein.Protocol.Utilities.Repositories; | ||
|
||
namespace Edelstein.Protocol.Gameplay.Game.Rewards; | ||
|
||
public interface IRewardPool<TReward> : | ||
IIdentifiable<int>, | ||
IRepository<int, TReward> | ||
where TReward : IReward | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
src/protocol/Edelstein.Protocol.Gameplay.Game/Rewards/IRewardPoolManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Edelstein.Protocol.Utilities.Repositories; | ||
|
||
namespace Edelstein.Protocol.Gameplay.Game.Rewards; | ||
|
||
public interface IRewardPoolManager<TReward> : | ||
IRepository<int, IRewardPool<TReward>> | ||
where TReward : IReward | ||
{ | ||
} |